Main Content

Create World and Actor

This example shows how to create an actor in a virtual world to display in the Simulation 3D Viewer window using Simulink® or MATLAB®.

This process does not build an appearance for the actor, so the Simulation 3D Viewer does not render a visualization of the actor. For an example that shows how to build an appearance for an actor, see Build Actor from 3D Graphic Primitives.

Create Virtual World with Actor Using Simulink

You can use the Simulation 3D Actor block and Simulation 3D Scene Configuration block to create an actor in a virtual world and view it in the Simulation 3D Viewer window.

Open Model

Open the Simulink model.

open_system("CreateWorld");

Simulink model with Simulation 3D Actor block and Simulation 3D Scene Configuration block

Explore Model Components

The model includes a Simulation 3D Scene Configuration block and a Simulation 3D Actor block. The Simulation 3D Scene Configuration block implements a 3D simulation environment. Double-click the Simulation 3D Scene Configuration block to open the Block Parameters dialog box. Set a view in the scene with the Scene view parameter. You can also set a custom viewpoint with this parameter. You must include the configuration block when building Simulink models with Simulation 3D Actor blocks.

Block parameter dialog box of Simulation 3D Scene Configuration block

The Simulation 3D Actor block adds an actor to the virtual world. Double-click the Simulation 3D Actor block to open the Block Parameters dialog box. To create an actor before simulation starts, on the Main tab, set the Operation parameter to Create at setup. The block first creates an empty actor with the name specified in the Actor name parameter. You can use any name for the actor. Then, the block loads the source file, if any is present, and runs the Initialization script to build an appearance for the actor. For more details, see Operating Modes. For this example, the block does not build an appearance for the actor in the virtual world.

Parameters of Simulation 3D Actor block

Simulate Model

Simulate the model and view the virtual world in the Simulation 3D Viewer.

sim("CreateWorld");

Empty virtual world scene

Close Model

Close the Simulink model.

close_system("CreateWorld");

Create Virtual World with Actor Using MATLAB

You can use the sim3d.World and sim3d.Actor objects to create an actor in a virtual world and view it in the Simulation 3D Viewer window.

Create World

Create a world scene.

world = sim3d.World();

Create Actor

Add an actor to the world.

add(world,sim3d.Actor());

Run Simulation

Run a simulation set for 10 seconds with a sample time of 0.02 seconds.

run(world,0.02,10)

Empty virtual world scene

Delete World

Delete the world object.

delete(world);

See Also

| | | | |

Related Topics