load
Description
Examples
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','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 (MAT file from MATLAB®)
STL (STereoLithography)
FBX (Autodesk® FilmBoX format)
URDF (Unified Robot Description File)
X3D (Extensible 3D)
VRML (Virtual Reality Modeling Language)
DAE COLLADA (Collada digital asset exchange)
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
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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)