Main Content

add

Add actor to 3D environment

Since R2022b

    Description

    add(world,actor) adds any actor object specified by actor to the 3D environment world.

    example

    add(world,actor,parent) additionally updates the world scene graph by attaching actor to other actor object specified by parent.

    Examples

    collapse all

    This example shows how to create a 3D environment with an empty actor and view in the Simulation 3D Viewer window using MATLAB®. You can use the sim3d.World to create a world object and sim3d.Actor to create an empty actor object. You can then add the actor to the 3D environment and visualize the 3D environment in the Simulation 3D Viewer window. For an example that shows how to create a 3D environment with an actor using Simulink®, see Create World and Actor Using Simulink.

    This process does not build an appearance for the actor, so the Simulation 3D Viewer does not render a visualization of the actor. For an example that shows how to build an appearance for an empty actor, see Build Actor from 3D Graphic Primitives Using MATLAB.

    Create World

    Create a world object.

    world = sim3d.World();

    Create Actor

    Create an actor object. The sim3d.Actor object creates an empty actor without any visual meshes.

    actor = sim3d.Actor();

    Add the actor to the world.

    add(world,actor);

    Run Simulation

    Run a simulation set for 10 seconds with a sample time of 0.02 seconds.

    sampletime = 0.02;
    stoptime = 10;
    run(world,sampletime,stoptime);

    Empty virtual world scene

    Delete World

    Delete the world object.

    delete(world);

    Input Arguments

    collapse all

    World object that defines the 3D environment, specified as a sim3d.World object.

    Example: world = sim3d.World()

    Actor object, specified as a handle to the actor object. Use this argument to add any actor to the 3D environment specified by world and co-simulate with the 3D simulation engine.

    Example: actor = sim3d.Actor()

    Parent actor object, specified as a handle to the parent actor object. After you add an actor to the sim3d.World object, the default parent actor is the Scene Origin at (0,0,0). Use this argument to set any actor in the 3D environment as the parent actor of actor.

    Version History

    Introduced in R2022b