Main Content

Build Actor from 3D Graphic Primitives Using Simulink

This example shows how to build an actor from a 3D graphic primitive using Simulink®. You can use the createShape function to build an appearance for the actor using predefined 3D graphic primitives, including box, cylinder, plane, and sphere.

You can use Simulation 3D Actor block and Simulation 3D Scene Configuration block to create a 3D environment with an actor. You can build the appearance of the actor from a 3D graphic primitive and set a view in the scene to view the actor in the Simulation 3D Viewer window.

To build an actor from a 3D graphic primitive using MATLAB®, see Build Actor from 3D Graphic Primitives Using MATLAB.

Open Model

Open the Simulink model.

open_system("CreateActorFrom3DGraphic");

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

Explore Model Components

The model includes a Simulation 3D Actor block and a Simulation 3D Scene Configuration 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 3D environment. 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. For more details, see Operating Modes. The Initialization script builds a cylinder shape for the actor using the createShape function. Set the size and use the Properties of the actor object to set the color of the cylinder in the Initialization script text box. On the Transform tab, you can also set the Initial position, Initial rotation and Actor scale of the actor.

The block parameter dialog box of the Simulation 3D Actor block shows parameters and the initialization script.

Simulate Model

Simulate the model and view the 3D environment with cylinder shape actor in the Simulation 3D Viewer.

sim("CreateActorFrom3DGraphic");

Cylinder actor in the virtual world.

Close Model

Close the Simulink model.

close_system("CreateActorFrom3DGraphic");

See Also

|

Related Topics