How to Add a New Ego Vehicle#

This document describes how to create a new ego vehicle in the SVL Simulator.

Video top#

(Link) Adding a new ego vehicle in SVL Simulator.

Asset Preparation top#

  1. Open vehicle mesh in 3D modeling software such as Blender or Maya.
  2. Edit root node to origin z forward. Blender will need .fbx options changed to correct for different axis orientation. Unity is Z forward and Y up.
  3. Create a simple mesh from the main body mesh and name it collider. This needs to be less than 256 polygons.
  4. Name the body mesh 'Body'.
  5. Separate wheel meshes and name them FrontRightWheel, FrontLeftWheel, RearLeftWheel, RearRightWheel.
  6. Center pivots on each wheel mesh z forward.
  7. Create an empty node called 'LightsGroup' to hold all light emitting meshes, e.g., HeadLights, BrakeLights, RightTurnIndicator, LeftTurnIndicator, ReverseIndicator. These must be separate meshes with separate materials and named exactly the same.
  8. Export mesh as an .fbx. If you have applied textures and materials in the modeling software, check the embed media option so these files are included in the file and you can extract in Unity.

Getting Started top#

  1. Launch SVL Simulator from the Unity Editor (as described here).
  2. Open any scene to work in or create a new one.
  3. Create a folder for the new vehicle Assets/External/Vehicles/YourNewEgoVehicle/.
  4. Create two folders in this new folder Assets/External/Vehicles/YourNewEgoVehicle/Models/Materials/.
  5. Import the vehicle .fbx in Assets/External/Vehicles/YourNewEgoVehicle/Models.
  6. In the Unity mesh importer, toggle off all animations, rigs.
  7. Export materials and textures into Assets/External/Vehicles/YourNewEgoVehicle/Models/Materials.
  8. Convert all LightsGroup mesh materials shaders to Shader Graphs/VehicleLightsShader. You may need to adjust the emission color.
  9. Rename the LightsGroup mesh materials to HeadLightsMat, LeftIndicatorMat, RightIndicatorMat, ReverseIndicatorMat, BrakeLightsMat.

Setup the Vehicle top#

  1. Create a new empty root game object for your vehicle and give it a name. YourNewEgoVehicle
  2. Reset transform. Unity can place the game object at random places so it is best to have the object at origin.
  3. Place vehicle meshes as a child of the root game object. Be sure that it is at local position origin.
  4. Drag YourNewEgoVehicle from the inspector panel into the project panel in Assets/External/Vehicles/YourNewEgoVehicle.
  5. This creates a prefab in Unity. Now if you make changes to the mesh, it will stay separate so you won't need to remake the prefab.
  6. Toggle off the mesh renderer Unity component for the Collider mesh. Add a mesh collider and toggle convex.
  7. Add the Jaguar2015XE open source vehicle to existing ego vehicle prefab to the hierarchy. This makes it easy to copy components to the new vehicle.
  8. Make sure the new vehicle prefab is at origin and overlaps with the Jaguar2015XE vehicle. This makes it easy to align light objects and wheel colliders.
  9. Unpack Jaguar2015XE prefab completely. We will use the needed components from this vehicle.
  10. Move the WheelColliderHolder object to the new vehicle as a child of the parent object.
  11. Move HeadLights, BrakeLights, IndicatorsLeft, IndicatorsRight, IndicatorsReverse and InteriorLights holder objects as a child of the new vehicle parent object.
  12. Copy all Unity components from the root object of the Jaguar2015XE to the root object of your new vehicle.
  13. Right click on each component on the reference prefab root, right click to copy and then right click on the root of the new vehicle to paste component as new.
  14. Do this for every component.
  15. Delete the Jaguar2015XE from the scene, it is no longer needed. DO NOT SAVE CHANGES in the Jaguar2015XE
  16. Reset transforms for WheelColliderHolder, HeadLights, BrakeLights, IndicatorsLeft, IndicatorsRight, IndicatorsReverse and InteriorLights objects so they align to the new vehicle.
  17. Align each wheel collider object to each wheel and align lights to the new vehicle light meshes.
  18. Create an empty object called BaseLink as a child of the root object of the new vehicle.
  19. Move BaseLink so it aligns with the center of the back axle of the new vehicle.
  20. Apply the component BaseLink to the BaseLink object.
  21. NOTE Not in video. Drag the BaseLink object to the BaseLink public reference in the VehicleSMI component.
  22. NOTE Be sure you have a MeshCollider component on the Collider mesh, the Collision mesh renderer component disabled and the collider has convex enabled.

Apply the Correct References top#

We need to apply the correct references to the vehicle scripts since the public variables are still referencing the other vehicle:

Note: Be sure to click the Apply button in the Inspector after each component change. This saves the change to the prefab in the project. Check that no variable references are still bold after updating the references.

VehicleSMI.cs top#

For the VehicleSMI script, reference the following colliders and meshes in the Axles dropdown.

  • Reference the FL WheelCollider in Axles Element 0 (Left)
  • Reference the FR WheelCollider in Axles Element 0 (Right)
  • Reference the RL WheelCollider in Axles Element 1 (Left)
  • Reference the RR WheelCollider in Axles Element 1 (Right)
  • Reference the FrontLeftWheel wheel mesh in Axles Element 0 (Left Visuals)
  • Reference the FrontRightWheel wheel mesh in Axles Element 0 (Right Visuals)
  • Reference the RearLeftWheel wheel mesh in Axles Element 1 (Left Visuals)
  • Reference the RearRightWheel wheel mesh in Axles Element 1 (Right Visuals)

VehicleActions.cs top#

  1. Duplicate the High and Low beam textures in the Jaguar2015XE and place in Assets/External/Vehicles/YourNewEgoVehicle/Models/Materials.
  2. Rename the prefix to the name of your vehicle, e.g., YourNewEgoVehicleHeadLightHighBeamCookie.
  3. NOTE Be sure the texture in set to 256 compression in the texture settings.
  4. Drag the textures into the VehicleActions.cs public references in the inspector panel on the new vehicle.
  5. Apply changes to the vehicle prefab.

Final Steps top#

  1. Set the vehicle root and all child objects to the Agent layer.
  2. Set the vehicle root to the Player tag
  3. Apply changes to the vehicle prefab.
  4. Open Simulator -> Build... menu at the top of the Unity editor
  5. Be sure you have both Windows and Linux support to make asset bundles.
  6. Check the new vehicle and press build.
  7. When completed, in the root of the repo, YourNewEgoVehicle bundle will be in Simulator/AssetBundles/Vehicles/
  8. Run simulator, open Library -> Vehicles tab in WebUI and select Add New.
  9. Drag the new bundle into the target area to upload the vehicle or select from file folders.
  10. Set the vehicle details.
  11. Create a new sensor configuration.
  12. Publish the NewEgoVehicle.

Congratulations! You have successfully added a new ego vehicle! It can now be used with any simulation you create.