Main Content

plotSim3d

Plot driving scenario in Unreal Engine viewer

Since R2024a

Description

The plotSim3d function creates a high-fidelity 3-D plot for the driving scenario in an Unreal Engine® viewer. It also synchronizes the driving scenario to the 3-D plot which enables you to advance and visualize the complete scenario at every time-step.

You can control the mapping between the cuboid driving scenario actors and their corresponding high-fidelity 3-D display types in the Unreal Engine viewer. To control the mapping, you must specify the AssetType argument for each vehicle and other actor object in the driving scenario. If you do not specify the AssetType argument, then the plotSim3d function uses the default asset path mapping between the driving scenario actors and their corresponding 3-D display assets based on Class ID as illustrated in this table:

Driving Scenario Class IDDriving Scenario Actor Type3-D Display Asset
1CarSedan
2Box TruckBoxTruck
3BicycleBicyclist
4PedestrianMalePedestrian
5BarrierBarrier
All other class IDsAll other custom dynamic actorsCuboid

example

plotSim3d(scenario) creates a high-fidelity 3-D plot in Unreal Engine viewer with orthonormal or bird's-eye-view perspective, as seen from immediately above the driving scenario, scenario.

example

plotSim3d(scenario,ActorInFocus=actorID) creates a high-fidelity 3-D plot in Unreal Engine viewer from the perspective of the actor whose ID is specified by the name-value argument, ActorInFocus=actorID. The 3-D plot has an ego-centric projective perspective, where the view is positioned immediately behind the actor.

Examples

collapse all

This example shows how to use the plotSim3d function to visualize a driving scenario in an Unreal Engine viewer 3-D plot.

Create Driving Scenario and Specify Asset Types for Actors

Create a driving scenario.

scenario = drivingScenario(SampleTime=0.025);

Add two road segments.

roadCenters = [200.6 23.8 0; 51 24.2 0];
laneSpecification = lanespec([2 2],'Width',[4 3.6 3.6 3.6]);
rd1 = road(scenario,roadCenters,Lanes=laneSpecification,Name='Road');
 
roadCenters = [109.8 129.5 0; 110 -30 0];
laneSpecification = lanespec([2 2]);
rd2 = road(scenario,roadCenters,Lanes=laneSpecification,Name='Road1');

Add barriers on either sides of one of the roads. Specify the class ID as 5.

barrier(scenario,rd2,ClassID=5)
barrier(scenario,rd2,RoadEdge="left",ClassID=5)

Add the ego vehicle to the driving scenario. You can specify the AssetType argument to map the ego vehicle to a specific 3-D display type. For this example, specify the ego vehicle to be a muscle car. Add a trajectory for the ego vehicle by specifying the speed and waypoint values.

egoVehicle = vehicle(scenario,ClassID=1,Position=[115.14 -2.51 0.01],...
        Name='EgoVehicle',AssetType="MuscleCar");

waypoints = [115.14 -2.51 0.01; 115.07 19.06 0.01;
             115.07 24.4 0.01; 115.29 47.07 0.01];
speed = [8;8;8;8];
trajectory(egoVehicle,waypoints,speed);

Add a pedestrian to the scenario and specify the trajectory. For this example, specify the AssetType to be a female pedestrian.

pedestrian = actor(scenario,ClassID=4,Position=[100 35 0.1],...
                   Velocity=[1.3 0 0],Name='Pedestrian',AssetType="FemalePedestrian");
waypoints=[100 35; 110 35; 120 35];
speed = [1.5 1.5 1.5];
trajectory(pedestrian,waypoints,speed);

Add a bicyclist to the scenario and specify the trajectory. Specify the AssetType to be bicyclist.

bicycle = actor(scenario,ClassID=3,Position=[83.51 30.5 0.01],Name='Bicycle',AssetType="Bicyclist");
waypoints = [83.51 28.5 0.01; 86.91 27.6 0.01;
    92.82 26.17 0.01; 115 26.45 0.01];
speed = [5;5;5;5];
trajectory(bicycle, waypoints, speed);

Add a truck to the scenario and specify the trajectory. Specify the AssetType to be a box truck.

truck = vehicle(scenario,ClassID=2,...
        Position=[91.77 18.17 0.01],Name='Truck',AssetType="BoxTruck");
waypoints = [91.77 18.17 0.01;108.97 18.39 0.01;
    119.38 18.84 0.01;160.26 18.84 0.01];
speed = [14;14;14;14];
trajectory(truck, waypoints, speed);

Create 3-D Plot and Visualize Driving Scenario

Use the plotSim3d function to create a 3-D plot of the scenario in bird's-eye-view.

Unreal Engine 3-D viewer is not supported for Mac® platforms. Verify whether the device is a Mac platform.

if ismac
    error(['3D Simulation is not supported on Mac', char(174), ' platforms.']);
end
plotSim3d(scenario)

Alternatively, you can plot the scenario from the perspective of any actor in the scenario. Use the ActorInFocus name-value argument of the plotSim3d function and specify the desired actor ID. Plot the scenario from the perspective of the truck.

plotSim3d(scenario,ActorInFocus=truck.ActorID)

Plot the scenario from the perspective of the ego-vehicle.

plotSim3d(scenario,ActorInFocus=egoVehicle.ActorID)

Advance the scenario to completely plot the scenario at each time-step.

while advance(scenario)
    pause(0.01)
end

Input Arguments

collapse all

Driving scenario, specified as a drivingScenario object.

Unique ID of the actor, specified as a positive integer. For a given vehicle or non-vehicle actor object, you can get the actor ID using its ActorID property.

Version History

Introduced in R2024a