Main Content

Interact with 3D Simulation Environment

Simulink® 3D Animation™ provides an interface to a simulation environment that is visualized using the Unreal Engine® from Epic Games®. Within this environment, you can create a 3D environment with actors. An actor is any object in the 3D environment that can move and rotate to support 3D transformations. Build actors and view the 3D environment in the Simulation 3D Viewer through the MATLAB® and Simulink interfaces of the Simulink 3D Animation.

In MATLAB, use the sim3d.World object and functions to create and view a 3D environment. The sim3d.Actor object and functions create actor objects and builds appearance for actor in 3D environment.

In Simulink, use the Simulation 3D Scene Configuration block to implement the 3D simulation environment and view the 3D environment. The Simulation 3D Actor block creates actor objects and builds appearance for actor in 3D environment.

The Simulation 3D Viewer window displays the 3D environment. You can interact with the actors and the 3D environment during simulation or when the simulation is paused. To interact with the 3D environment during simulation, the software provides these two interactive modes.

You can use keyboard shortcuts and mouse control to view and navigate in the 3D environment. For more information on the keyboard shortcuts and mouse control, see Navigate in 3D Environment.

For an example showing how to create a 3D environment, build an actor, and view the 3D environment using MATLAB, see Build Actor from 3D Graphic Primitives Using MATLAB. For a Simulink example, see Build Actor from 3D Graphic Primitives Using Simulink.

Simulation 3D Viewer Interface

Simulation 3D Viewer interface enables you to interact with the actors and the 3D environment. During simulation, right-click the actor or the 3D environment to display a context menu that lists options to interact with the corresponding actor or 3D environment. You can also double-click anywhere in the world or an actor to zoom in with a best fit-to-screen view and attach the virtual camera to the actor.

Note

You can only access the user interface in the Simulation 3D Viewer window to interact with the actors created using the sim3d.Actor object or the Simulation 3D Actor block.

Interact with Actor

During simulation, right-click the actor to display the context menu for actor and world.

Actor with context menu.

The table summarizes the options in the context menu.

Actor OptionDescription

Quick Actions

To set these properties, select them from the list.

  • Gravity

  • Physics

  • Collisions

Note

To experience the effects of gravity you must select Physics property.

Edit Properties

Open the Actor Editor to view or modify actor properties during simulation.

Right-click the actor and select Properties to display the Actor Editor on the right side of the Simulation 3D Viewer. The Actor Editor displays the actor name and its properties. You can edit the actor properties using the sliders and check boxes. For the slider to work, pause on the box to display a double-headed arrow, then click and drag to change the value. Alternatively, you can also click the box to set the property value. For more details on actor properties, see Properties of sim3d.Actor.

Actor editor user interface with actor properties.

Standard Views

List the standard views of the actor.

  • Left

  • Right

  • Front

  • Back

  • Top

  • Bottom

  • Perspective

Show Actor Origin

Display the axes of the default coordinate system at world origin.

Hide Actor Origin

Hide the coordinate axes of the actor.

Send to Console

Display the actor properties in the MATLAB Command Window.

Save as MAT file

Save the actor properties in a MAT file.

Remove

Remove actor from the 3D environment. To add the actor back to the 3D environment, run the simulation again.

Interact with 3D Environment

During simulation, right-click the 3D environment to display the context menu for the world.

Actor in 3D environment with context menu of world.

The table lists the options for 3D environment.

World OptionDescription

Show Actor Hierarchy

Open the Actor Hierarchy to view the hierarchical structure of the actors in the 3D environment during simulation. You can double-click on the actor name to display the perspective view of the actor and attach the virtual camera to the actor. You can also right-click on the actor name to display the context menu for actor and world.

Actor hierarchy with names of all actors in the 3D environment

Standard Views

List the standard views of the 3D environment.

  • Left

  • Right

  • Front

  • Back

  • Top

  • Bottom

  • Perspective

Custom Views

List the views created to view the 3D environment.

Show World Origin

Display the axes of the default coordinate system at world origin.

Hide All Origins

Hide the coordinate axes of all actors and world origin.

Save as MAT file

Save the 3D environment as a MAT file, including all the actors in the world.

Programmatic Interaction

You can interact with the simulation programmatically to investigate system behavior in the 3D environment. In MATLAB, you can create 3D simulations and issue commands during the simulation to control and interact with the simulation. To get started in creating 3D simulations using MATLAB, see Create 3D Simulation Using MATLAB. For more examples on creating 3D simulations, see Create 3D Simulations in Unreal Engine Environment.

To interact with a simulation programmatically, you can either set the stopTime in the run function to inf or set the EnablePacing property of sim3d.World object to true or 1. When you co-simulate, you can enter commands in the MATLAB Command Window. You can also use the view function to investigate the 3D environment before starting the co-simulation with the 3D simulation engine.

You can enter these commands to interact with the co-simulation:

  • Control the co-simulation using pause and resume functions.

  • Enable pacing using the EnablePacing and PacingRate properties of the sim3d.World object.

  • Set or modify properties of the actors in the 3D environment.

  • Create new actors in the 3D environment using the actor objects listed in Actors, and add the actors to the 3D environment using the add function.

  • Create a custom view in the 3D environment using the createViewport function, and set any view using the setView function.

  • End the co-simulation using the close function.

See Also

| | |

Related Topics