Load or import 3D file
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:
Build Actor from Imported 3D File Using Simulink
Open the Simulink model.
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.
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.
Simulate the model and view the actor in the Simulation 3D Viewer.
Close the Simulink model.
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 a world scene.
world = sim3d.World();
Build Actor from File
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.
viewport = createViewport(world); viewport.Translation = [-0.5, 0, 0];
Run the animation set for
5 seconds with a sample time of
Delete the world object.
actor — Actor class where 3D file is loaded
Actor class where the 3D file is loaded, specified as a
source — Name of location from where actor is loaded
Name of location from where actor is loaded, specified as a character array. The
source can be a file path or file name.
load supports these as sources.
surf (only 3D shapes based on polygons)
patch (only 3D shapes based on polygons)
scale — Scale applied to loaded model
real positive scalar
Overall scale applied to the entire loaded model, specified as a real positive scalar. Scale parameters of individual objects are not affected by using this parameter.
You can load STL files even with
that are not currently added to the World.
Introduced in R2022b