Build Actor from Imported 3D File Using MATLAB
This example shows how to build an actor from an imported 3D file using MATLAB®. If you have a custom actor defined in a supported 3D file, you can import the file. You can import 3D file formats including FBX, STL, and URDF.
To build an actor from an imported 3D file using Simulink®, see Build Actor from Imported 3D File Using Simulink.
You can use the sim3d.World
object and functions to create and view a 3D environment. You can use the sim3d.Actor
object and functions to create an actor in the 3D environment 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 3D Environment
Create a world object.
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='Rotor'); load(rotor,'rotor.stl', 0.01*[1 1 1]); rotor.Rotation = [0 pi/2 0]; add(world,rotor);
Set Viewer Window Point of View
If you do not create a viewport, then the default view is set 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.
viewport = createViewport(world,Translation=[-0.5 0 0]);
Run Animation
Run the animation set for 5
seconds with a sample time of 0.01
seconds.
sampletime = 0.01; stoptime = 5; run(world,sampletime,stoptime)
Delete World
Delete the world object.
delete(world)
See Also
sim3d.Actor
| sim3d.World
| createShape
| add
| run