SimMechanics    

Creating Virtual Worlds for SimMechanics Models

The Virtual Reality Toolbox User's Guide and VRML books such as Marrin and Campbell [9] explain how to create virtual objects and assemble them into virtual worlds. This section highlights the special requirements to make a virtual world usable as a visualization for a SimMechanics model.

As you create a virtual world populated by virtual bodies, you must create each component body, then plan and implement the geometry of the machine's initial state. Doing this yourself is a major difference from the SimMechanics virtual reality visualization, where the bodies are created, placed, and oriented automatically. Use a VRML authoring tool that can read VRML as a native format to create and edit virtual reality .wrl files. If you are familiar with raw VRML source code, you can use a plain text editor or the MATLAB editor to edit the files.

You represent each body by a virtual object encoded in a .wrl file.You also create a master .wrl file to represent the virtual world that refers to body .wrl files, placing and orienting these body in the larger scene. You can define a body's position and orientation with respect to:

You can nest body references to other bodies in VRML hierarchies, but you must define at least one body's position and orientation with respect to the overall virtual world. Place and orient the bodies in their initial states, corresponding with the initial state of the SimMechanics simulation.

Each body's .wrl file contains a hierarchical tree starting with the Transform node. Among Transform's fields must be translation and rotation fields to specify the body's position and orientation in space. If a body is nested below another body, its position and orientation are defined with respect to the next body up the hierarchy.

Creating your own virtual world gives you great flexibility in representing your machine:

Example: Viewing Custom External VRML Files for the Conveyor Loader

The demo model mech_conveyor_vr is a modified version of the original conveyor model mech_conveyor and comes with external VRML files containing static renderings of the machine parts in their initial positions. This example uses the V-Realm Builder® VRML authoring tool in the Virtual Reality Toolbox to view the files.

  1. In the \toolbox\physmod\mech\mechdemos\ directory, open these files:
  2. Click the Test Mode button and view the complete machine in the Main view. Right-click in this window to configure the navigation. If the colors seem washed out, toggle off the headlight.

  1. These conveyor parts are more realistic than the equivalent ellipsoids or convex hulls available with the built-in SimMechanics virtual reality tool:

  1. On the left side of your VRML editor window, examine the node tree of convmech.wrl that refers to the six VRML files representing each component body:

  1. The hierarchy of body position and orientation references is flat in this model. Each body is separately referenced to the top level of the hierarchy, New World.

  1. Expand one of the nodes. Each body node has, among others, rotation and translation fields:

  1. The exception is the Pusher transform, which has only a translation field. In the SimMechanics model, the pusher only translates along one axis.


  Creating a Custom Machine Visualization Interfacing SimMechanics with Virtual Worlds