Docs/content_authoring_props.md
Creating a custom prop in CARLA is quick and straightforward. Follow these steps to import and use a custom asset as a prop inside a CARLA simulation.
Running the Unreal Engine editor is required for this process, therefore you need to build CARLA from source.
You may find ready-made 3D assets on sites such as TurboSquid or Sketchfab that suite your usecase (make sure to check that the license suits your intended use). Alternatively, if you are adept at 3D modelling, you may choose to model the object in a 3D modelling application such as Blender or Maya.
For this example, we download an asset from Sketchfab that has a creative commons license. First, import the asset into Blender to inspect it to ensure it suits our intended use. For this asset, a couple of modifications were required to prepare it for use in CARLA:
If the model is not already in FBX format or needed modification, export it as FBX from Blender or your preferred 3D application.
Now that we have an asset in FBX format, we can import it into the CARLA content library. Launch the CARLA Unreal Engine editor by running cmake --build Build --target launch in the root directory of the CARLA source code repository. Once the editor is open, navigate to an appropriate place in the content directories (Content/Carla/Static/Static in this example). Drag the FBX file into the content browser, import with the default options. Once the import is complete we can see our new prop as a static mesh in the content folder:
To register the asset as a prop and use it through the CARLA API, we need to include it in the configuration file .PropParameters.json in the ${CARLA_ROOT}/Unreal/CarlaUnreal/Content/Carla/Config directory. Add a new entry in this file matching the format of the existing entries, locating the static mesh file that you imported (you can double check the path by hovering over the imported asset in the content browser). Choose a memorable name for the asset and add it to the name field:
{
"Props": [
{
"name": "ATM",
"path": "/Game/Carla/Static/Static/SM_Atm.SM_Atm",
"size": "Medium"
},
...,
{
"name": "PoliceBarrier",
"path": "/Game/Carla/Static/Static/Police_barrier.Police_barrier",
"size": "Medium"
}
]
}
Start the CARLA simulation Unreal Engine editor with the play command. Once it is running, open a Python script or notebook. The new prop will be assigned the blueprint ID static.prop.policebarrier (i.e. static.prop.<name_lower_case>).
Filter for the name you entered in the name field in PropParameters.json in lower case and you will find a new blueprint ID for your new prop:
import carla
client = carla.Client()
world = client.get_world()
bp_lib = world.get_blueprint_library()
for bp in bp_lib.filter('*policebarrier*'):
print(bp.id)
This should return:
>>> static.prop.policebarrier
Now you can place your new prop in the simulation in the same way as native CARLA props:
barrier_bp = bp_lib.find('static.prop.policebarrier')
for spawn_loc in spawn_locations:
world.spawn_actor(barrier_bp, spawn_loc)
Once you have imported one or more props into CARLA using the previous steps, ensure you have saved everything in the Unreal Editor interface.You can then export a new CARLA package containing the new props using the following command:
cmake --build Build/Linux-Release/ --target package
When the export process is finished, the exported map package will be saved as a compressed archive:
.tar.gz archive in the ${CARLA_ROOT}/Build/Package directory.zip archive in the ${CARLA_ROOT}/Build/Package directoryStatic meshes already included in the CARLA content library can be nominated for use as props through the Python API using the static.prop.mesh blueprint. Locate the desired mesh in the CARLA content browser and take note of its path. For this example we will choose the Dodge Charger model from the /Game/Carla/Static/Car/4Wheeled/DodgeCharger/Parked directory.
We can use the following code to place the vehicle in the map as a prop:
# Set the path for the chosen static mesh
mesh_path = '/Game/Carla/Static/Car/4Wheeled/DodgeCharger/Parked/SM_ChargerParked.SM_ChargerParked'
spawn_point = carla.Transform(carla.Location(x=52.7, y=127.7, z=0), carla.Rotation())
# Use the static.prop.mesh bp and set the mesh_path attribute
parked_vehicle_bp = bp_lib.find('static.prop.mesh')
parked_vehicle_bp.set_attribute('mesh_path', mesh_path)
parked_vehicle = world.spawn_actor(mesh_bp, spawn_point)
This method works both with the built-from-source version of CARLA and also a package version of CARLA, as long as the package contains the nominated static mesh in the correct location.