load
Description
Examples
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");
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 Model
Simulate the model and view the actor in the Simulation 3D Viewer.
sim("CreateActorFromImport");
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)
Delete World
Delete the world object.
delete(world)
Input Arguments
actor
— Actor class where 3D file is loaded
sim3d.Actor
object
Actor class where the 3D file is loaded, specified as a sim3d.Actor
object.
source
— Name of location from where actor is loaded
character array
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.
File Formats
MAT
STL
FBX
URDF
x3d
MATLAB Objects
RigidBodyTree
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.
Tips
You can load STL files even with sim3d.Actor
objects
that are not currently added to the World.
Version History
Introduced in R2022b
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)