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#
- Open vehicle mesh in 3D modeling software such as Blender or Maya.
- 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.
- Create a simple mesh from the main body mesh and name it collider. This needs to be less than 256 polygons.
- Name the body mesh 'Body'.
- Separate wheel meshes and name them FrontRightWheel, FrontLeftWheel, RearLeftWheel, RearRightWheel.
- Center pivots on each wheel mesh z forward.
- 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.
- 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#
- Launch SVL Simulator from the Unity Editor (as described here).
- Open any scene to work in or create a new one.
- Create a folder for the new vehicle Assets/External/Vehicles/YourNewEgoVehicle/.
- Create two folders in this new folder Assets/External/Vehicles/YourNewEgoVehicle/Models/Materials/.
- Import the vehicle .fbx in Assets/External/Vehicles/YourNewEgoVehicle/Models.
- In the Unity mesh importer, toggle off all animations, rigs.
- Export materials and textures into Assets/External/Vehicles/YourNewEgoVehicle/Models/Materials.
- Convert all LightsGroup mesh materials shaders to Shader Graphs/VehicleLightsShader. You may need to adjust the emission color.
- Rename the LightsGroup mesh materials to HeadLightsMat, LeftIndicatorMat, RightIndicatorMat, ReverseIndicatorMat, BrakeLightsMat.
Setup the Vehicle top#
- Create a new empty root game object for your vehicle and give it a name. YourNewEgoVehicle
- Reset transform. Unity can place the game object at random places so it is best to have the object at origin.
- Place vehicle meshes as a child of the root game object. Be sure that it is at local position origin.
- Drag YourNewEgoVehicle from the inspector panel into the project panel in Assets/External/Vehicles/YourNewEgoVehicle.
- 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.
- Toggle off the mesh renderer Unity component for the Collider mesh. Add a mesh collider and toggle convex.
- 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.
- 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.
- Unpack Jaguar2015XE prefab completely. We will use the needed components from this vehicle.
- Move the WheelColliderHolder object to the new vehicle as a child of the parent object.
- Move HeadLights, BrakeLights, IndicatorsLeft, IndicatorsRight, IndicatorsReverse and InteriorLights holder objects as a child of the new vehicle parent object.
- Copy all Unity components from the root object of the Jaguar2015XE to the root object of your new vehicle.
- 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.
- Do this for every component.
- Delete the Jaguar2015XE from the scene, it is no longer needed. DO NOT SAVE CHANGES in the Jaguar2015XE
- Reset transforms for WheelColliderHolder, HeadLights, BrakeLights, IndicatorsLeft, IndicatorsRight, IndicatorsReverse and InteriorLights objects so they align to the new vehicle.
- Align each wheel collider object to each wheel and align lights to the new vehicle light meshes.
- Create an empty object called BaseLink as a child of the root object of the new vehicle.
- Move BaseLink so it aligns with the center of the back axle of the new vehicle.
- Apply the component BaseLink to the BaseLink object.
- NOTE Not in video. Drag the BaseLink object to the BaseLink public reference in the VehicleSMI component.
- 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#
- Duplicate the High and Low beam textures in the Jaguar2015XE and place in Assets/External/Vehicles/YourNewEgoVehicle/Models/Materials.
- Rename the prefix to the name of your vehicle, e.g., YourNewEgoVehicleHeadLightHighBeamCookie.
- NOTE Be sure the texture in set to 256 compression in the texture settings.
- Drag the textures into the VehicleActions.cs public references in the inspector panel on the new vehicle.
- Apply changes to the vehicle prefab.
Final Steps top#
- Set the vehicle root and all child objects to the Agent layer.
- Set the vehicle root to the Player tag
- Apply changes to the vehicle prefab.
- Open Simulator -> Build... menu at the top of the Unity editor
- Be sure you have both Windows and Linux support to make asset bundles.
- Check the new vehicle and press build.
- When completed, in the root of the repo, YourNewEgoVehicle bundle will be in Simulator/AssetBundles/Vehicles/
- Run simulator, open Library -> Vehicles tab in WebUI and select
Add New
. - Drag the new bundle into the target area to upload the vehicle or select from file folders.
- Set the vehicle details.
- Create a new sensor configuration.
- Publish the NewEgoVehicle.
Congratulations! You have successfully added a new ego vehicle! It can now be used with any simulation you create.