Main Content

sim3d.World

Object used to define virtual reality world in Unreal Engine viewer

Since R2022b

    Description

    Use the sim3d.World object to create and define virtual reality worlds and run the cosimulation using Unreal Engine®.

    • Add or remove custom actors to or from the world. Only the actors added to the world object are displayed.

    • Store the virtual reality scene, the root sim3d.Actor object, and the hierarchical structure of all actors in the scene.

    • Optionally control the simulation logic by specifying custom functions. The output function passes data to the Unreal Engine to change actor properties in the engine.

    • Control the cosimulation between MATLAB® and the Unreal Engine.

    • Define the virtual world global coordinate system.

    • Control scene environment settings.

    • Control virtual world timing.

    Creation

    Description

    example

    world = sim3d.World() launches the default Unreal Engine executable in a new window with a default name.

    world = sim3d.World('Name',name) launches the Unreal Engine executable in a new window with the name specified.

    world = sim3d.World('RenderOffScreen',true) runs the cosimulation while running the Unreal Engine executable in the background.

    world = sim3d.World('Setup',@setupFcn) modifies the cosimulation by executing @setupFcn before setup. This custom function can be used to import additional data which required during simulation runtime.

    world = sim3d.World('Update',@updateFcn) modifies the cosimulation by executing @updateFcn at each simulation step. This custom function can be used to read data from the Unreal Engine.

    world = sim3d.World('Output',@outputFcn) modifies the cosimulation by executing @outputFcn at each simulation step. This custom function can be used to send data about the specified sim3d.Actor object to the Unreal Engine.

    world = sim3d.World('Release',@releaseFcn) modifies the cosimulation by executing @releaseFcn at each simulation step. This function can be used to delete additional data you may import during setup.

    Input Arguments

    expand all

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: World = sim3d.World('Name',world1)

    Name of the world, specified as a string.

    Path to executable file that the world runs, specified as a string.

    Option to run simulation in the background, specified as either 0(false) or 1(true).

    Custom update function that reads data about specified actors from Unreal Engine, specified as the handle to the user-defined function.

    Custom output function that returns information, such as transform and color, for the specified actors to the Unreal Engine, specified as the handle to the user-defined function. This allows Unreal® to control the simulation.

    Custom function that reads to run additional commands during setup, specified as the handle to the user defined function. This can be used to load data required for simulation.

    Custom release function that runs additional commands after simulation ends, specified as the handle to the user-defined function. This setting can be used to delete additional data imported for the setup.

    Properties

    expand all

    Name of the world, specified as a string.

    All actors in the world, specified as a structure whose fields are the names of the actors.

    Data specified by user that may be required during simulation runtime, specified as a structure.

    You can use UserData to store the data needed by the Update, Output, Setup, and Release custom functions. UserData ensures that the same data is accessible to all these functions.

    Perspective of the main camera, defined as a structure containing a single field, Main. Main contains a sim3d.sensors.MainCamera object with these properties:

    • Parent — Parent of actor object

    • Children — Children of actor object

    • ParentWorld — Handle to parent world

    • SensorIdentifier — Unique ID of the main camera, with data type uint32

    • Translation — Translation of the main camera relative to the parent vehicle, in meters

    • Rotation — Rotation of the sensor relative to the parent vehicle, in radians

    Event container for the handles for actors hit at a time step, specified as an array. After each time step, the event container resets to empty.

    Event container for the handles for actors that start overlapping at a time step, specified as an array. After each time step, the event container resets to empty.

    Event container for the handles for actors that end overlapping at a time step, specified as an array. After each time step, the event container resets to empty.

    Event container for the handles for actors that are interactively clicked at a time step, specified as an array. After each time step, the event container resets to empty.

    Object Functions

    createViewportCreate viewport for world
    addAdd actor to virtual reality world
    runRun cosimulation in virtual reality world
    removeRemove actor added to world or remove all actors in world

    Examples

    collapse all

    This example shows how to use the sim3d.World and sim3d.Actor objects to create an actor in a world scene to display in the Simulation 3D Viewer window. This process does not build an actor object appearance, preventing the Simulation 3D Viewer from rendering a visualization of the actor object. For an example building an appearance for an actor, see Build Actor from Mesh Data and Apply Texture.

    Create World

    Create a world scene.

    world = sim3d.World();

    Create Actor

    Add an actor to the world.

    add(world,sim3d.Actor());

    Run Simulation

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

    run(world,0.02,10)

    Delete World

    Delete the world object.

    delete(world);

    Version History

    Introduced in R2022b

    expand all