Main Content

Build Actor from Imported 3D File

This example shows how to build an actor from an imported 3D file using either Simulink® or MATLAB®.

If you have a custom actor defined in a supported 3D file, you can import the file. Supported file formats include:

  • MAT

  • STL

  • FBX

  • URDF

  • x3d

Build Actor from Imported 3D File Using Simulink

You can use Simulation 3D Actor block and Simulation 3D Scene Configuration block to create and build an actor in a virtual world from an imported 3D file.

Open Model

Open the Simulink model.

open_system("CreateActorFromImport");

Simulink model with Simulation 3D Actor block named rotor and a 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 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. For more details, see Operating Modes. Specify the STL file in the Path to source file parameter to import a 3D file. On the Transform tab, set the initial position and rotation of the actor in the virtual world.

The block parameter dialog box of the Simulation 3D Actor block named rotor shows parameters and the file name in the path to the source file.

Simulate Model

Simulate the model and view the actor in the Simulation 3D Viewer.

sim("CreateActorFromImport");

Imported 3D actor in the virtual world.

Close Model

Close the Simulink model.

close_system("CreateActorFromImport");

Build Actor from Imported 3D File using MATLAB

You can use the sim3d.World object and functions to create and view a virtual world. You can use the sim3d.Actor object and functions to create an actor in the virtual world and build an appearance for the actor from an imported 3D file. Use the load function of the sim3d.Actor object to import the file.

Create World

Create a world scene.

world = sim3d.World();

Build Actor from File

Use the load function to import a 3D file. This example uses an STL file.

rotor = sim3d.Actor('ActorName','Rotor1');
rotor.load('rotor.stl', 0.01*[1, 1, 1]);
rotor.Rotation = [0, pi/2, 0];
world.add(rotor);

Set Viewer Window Point of View

If you do not create a viewport, then the point of view is set to 0, 0, 0, and you can use the keyboard shortcuts and mouse controls to navigate in the Simulation 3D Viewer window.

For this example, use the createViewport function to create a viewport with a single field, Main, that contains a sim3d.sensors.MainCamera object.

viewport = createViewport(world);
viewport.Translation = [-0.5, 0, 0];

Run Animation

Run the animation set for 5 seconds with a sample time of 0.01 seconds.

run(world,0.01,5)

Imported 3D actor in the virtual world.

Delete World

Delete the world object.

delete(world)

See Also

| | | | | |

Related Topics