Main Content

MATLAB Transition Workflow

Transition your code to the sim3d interface to complete these tasks.

Taskvr Functionalitysim3d Functionality3D Environment Description

Create world.

Load world.

world = vrworld('file.x3d');
open(world)
world = sim3d.World(Output=@OutputImpl);
load(world,'file.x3d');

Create the 3D environment using the sim3d.World class, and optionally use the Output argument to specify a user-defined local function. The output function updates the 3D environment data during simulation. The output function is included in the task to animate the actor and view 3D simulation.

The world object creates a default viewpoint to view the 3D environment.

Load the VRML file in the world object.

Access actors.
car = vrnode(world,'Automobile');
car = world.Actors.Automobile;
The actors in the scene are stored in a structure and can be accessed using the Actors property in sim3d.World object.
Edit actor properties.
car.translation = [3 0 0.25];
car.Translation = [3 0.25 0];

The default coordinate system of the 3D environment is the world coordinate system. For more information on coordinate systems, see Coordinate Systems in Simulink 3D Animation.

For more information on the sim3d.Actor object properties, see Properties.

View world.
view(world,'-internal');
view(world);

Open and display the 3D environment in the Simulation 3D Viewer window.

Animate actor and view 3D simulation.
for i=1:length(x1)
    car.translation = car.translation ...
 + [0.1 0 0.1];
    vrdrawnow;
    pause(0.1);
end
sampletime = 0.02;
stoptime = 2;
run(world,sampletime,stoptime);
function OutputImpl(world)
world.Actors.Automobile.Translation = ...
    world.Actors.Automobile.Translation ...
    + [0.1 0.1 0];
end

The run function performs these actions:

  • Opens and displays the 3D environment in the Simulation 3D Viewer window

  • Starts the co-simulation with the Unreal Engine®

The OutputImpl function sends data from MATLAB® to the Unreal Engine environment. The run function updates the 3D environment data at each time step of the simulation using the data from the output function.

See Also

|

Topics