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");
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.
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.
Simulate Model
Simulate the model and view the virtual world in the Simulation 3D Viewer.
sim("CreateWorld");
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)
Delete World
Delete the world object.
delete(world);
See Also
sim3d.Actor
| sim3d.World
| add
| run
| Simulation 3D
Actor | Simulation 3D Scene
Configuration