Simulink® 3D Animation™ User's Guide
Simulink® 3D Animation™ User's Guide
User’s Guide
R2014a
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
August 2001 First printing New for Version 2.0 (Release 12.1)
July 2002 Second printing Revised for Version 3.0 (Release 13)
October 2002 Online only Revised for Version 3.1 (Release 13)
June 2004 Third printing Revised for Version 4.0 (Release 14)
October 2004 Fourth printing Revised for Version 4.0.1 (Release 14SP1)
March 2005 Online only Revised for Version 4.1 (Release 14SP2)
April 2005 Online only Revised for Version 4.2 (Release 14SP2+)
September 2005 Online only Minor revision for Version 4.2.1 (Release 14SP3)
March 2006 Online only Revised for Version 4.3 (Release 2006a)
September 2006 Online only Revised for Version 4.4 (Release 2006b)
March 2007 Online only Revised for Version 4.5 (Release 2007a)
September 2007 Online only Revised for Version 4.6 (Release 2007b)
March 2008 Online only Revised for Version 4.7 (Release 2008a)
October 2008 Online only Revised for Version 4.8 (Release 2008b)
March 2009 Online only Revised for Version 5.0 (Release 2009a)
March 2010 Online only Revised for Version 5.1.1 (Release 2010a)
September 2010 Online only Revised for Version 5.2 (Release 2010b)
April 2011 Online only Revised for Version 5.3 (Release 2011a)
September 2011 Online only Revised for Version 6.0 (Release 2011b)
March 2012 Online only Revised for Version 6.1 (Release 2012a)
September 2012 Online only Revised for Version 6.2 (Release 2012b)
March 2013 Online only Revised for Version 6.3 (Release 2013a)
September 2013 Online only Revised for Version 7.0 (Release 2013b)
March 2014 Online only Revised for Version 7.1 (Release 2014a)
Contents
Getting Started
1
Simulink 3D Animation Product Description . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
v
Installation
2
Install Blaxxun Contact on Host Computer . . . . . . . . . . 2-2
Known Issue with the Blaxxun Contact Plug-In . . . . . . . . . 2-4
Change the Default Network Security Setting . . . . . . . . . . 2-4
TCP/IP Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
vi Contents
Simulink Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35
MATLAB Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-40
Simulink Interface
3
Virtual World Connection to a Model . . . . . . . . . . . . . . . . 3-2
Add a Simulink 3D Animation Block . . . . . . . . . . . . . . . . . . 3-2
Changing the Virtual World Associated with a Simulink
Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
MATLAB Interface
4
Create vrworld Object for a Virtual World . . . . . . . . . . . 4-2
vii
Open a Virtual World with MATLAB . . . . . . . . . . . . . . . . . 4-4
viii Contents
Build Virtual Reality Worlds
5
VRML Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Editors for Virtual Worlds . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
ix
VRML Nodes, Library Objects, and Templates . . . . . . . . . . 6-3
x Contents
Viewing Virtual Worlds
7
VRML Viewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Host and Remote Viewing . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
Comparison of Viewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
Legacy Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5
Viewpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-32
xi
Navigate Through Viewpoints . . . . . . . . . . . . . . . . . . . . . . 7-38
xii Contents
Navigate a Virtual World . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-65
Movement Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-65
Navigate Through Viewpoints . . . . . . . . . . . . . . . . . . . . . . . 7-66
xiii
View Virtual Worlds Remotely with Orbisnap . . . . . . . . 8-16
Glossary
xiv Contents
1
Getting Started
Key Features
• Simulink blocks and MATLAB apps and functions for connecting models to
virtual reality worlds
• 3D World Editor for authoring 3D worlds
• Viewers for 3D model visualization
• Video recording and animation playback
• Visualization of real-time simulations
• Remote access to simulations via standalone viewers or web browsers
• Interaction with 3D views via a joystick, space mouse, or other hardware
device
1-2
Expected Background
Expected Background
To help you effectively read and use this guide, here is a brief description of
the chapters and a suggested reading path. As a general rule, you can assume
that Simulink 3D Animation software on the Apple Mac OS X platform works
as described for the UNIX®/Linux® platforms.
• MATLAB product, to write scripts and functions with MATLAB code, and
to use functions with the command-line interface
• Simulink and Stateflow® charts products to create models as block
diagrams and simulate those models
• VRML, to create or otherwise provide virtual worlds or three-dimensional
scenes to connect to Simulink or MATLAB software
1-3
1 Getting Started
As you refine your visualization, you often perform some of these tasks
iteratively.
1-4
Build Virtual Worlds to Visualize Dynamic Simulations
You build and view the virtual reality world models using VRML (Virtual
Reality Modeling Language).
In addition to the installed VRML editor, 3D World Editor, you can configure
your environment to use:
In addition to the installed Simulink 3D Animation viewer, you can use one of
these viewers to display your virtual reality worlds:
To help decide which VRML editor and viewer to use, see “VRML Editors”
on page 5-2 and “VRML Viewers” on page 7-3. For more information about
installing a VRML editor or VRML viewer, see “Install VRML Viewer”.
Use joystick and space mouse input devices to provide input for dynamic
simulation visualizations.
TCP/IP Connection
The Simulink 3D Animation product uses a TCP/IP connection to a VR
client for communicating with the Simulink 3D Animation Viewer, as well
for connecting to VRML-enabled Web browser. You can verify the TCP/IP
connection between the host and client computers by using the ping command
1-5
1 Getting Started
from a command-line prompt. If there are problems, you must first fix the
TCP/IP protocol settings according to the documentation for your operating
system.
If you see an error like this, set the LD_LIBRARY_PATH environment variable.
setenv LD_LIBRARY_PATH
matlabroot/sys/opengl/lib/<PLATFORM>:$LD_LIBRARY_PATH
setenv LD_LIBRARY_PATH
matlabroot/sys/opengl/lib/<PLATFORM>
In both cases, <PLATFORM> is the UNIX platform you are working in.
1-6
Build Virtual Worlds to Visualize Dynamic Simulations
For more an overview of VRML and details about supported VRML features,
see “Virtual Reality Modeling Language (VRML)” on page 1-11.
As you add VRML nodes with the 3D World Editor, you can use the viewer
pane to see the virtual world that you are creating.
• Simulink model
• SimMechanics model
• MATLAB virtual world object
Simulink
The Simulink 3D Animation library provides blocks to directly connect
Simulink signals with virtual worlds. This connection lets you visualize your
model as a three-dimensional animation.
You can implement most of the software features with Simulink blocks. Once
you include these blocks in a Simulink diagram, you can select a virtual world
and connect Simulink signals to the virtual world. The software automatically
scans a virtual world for available VRML nodes that the Simulink software
can drive.
All the VRML node properties are listed in a hierarchical tree-style viewer.
You select the degrees of freedom to control from within the Simulink
interface. After you close a Block Parameters dialog box, the Simulink
software updates the block with the inputs and outputs corresponding
to selected nodes in the virtual world. After connecting these inputs to
appropriate Simulink signals, you can view the simulation with a VRML
viewer.
1-7
1 Getting Started
SimMechanics
You can use the Simulink 3D Animation product to view the behavior of a
model created with the SimMechanics software. First, you build a model of a
machine in the Simulink interface using SimMechanics blocks. Then, create a
detailed picture of your machine in a virtual world, connect this world to the
SimMechanics body sensor outputs, and view the behavior of the bodies in
a VRML viewer.
MATLAB
Simulink 3D Animation software provides a flexible MATLAB interface to
virtual reality worlds. After creating MATLAB objects and associating them
with a virtual world, you can control the virtual world by using functions
and methods.
From the MATLAB software, you can set positions and properties of VRML
objects, create callbacks from graphical interfaces, and map data to virtual
objects. You can also view the world with a VRML viewer, determine its
structure, and assign new values to all available nodes and their fields.
The software includes functions for retrieving and changing the virtual
world properties and for saving the VRML files corresponding to the actual
structure of a virtual world.
For details about interacting between MATLAB and virtual reality worlds,
see “MATLAB Interaction”.
1-8
Build Virtual Worlds to Visualize Dynamic Simulations
While running a simulation, you can change the positions and properties in
a virtual world.
1-9
1 Getting Started
product (for example, creating, opening, and closing a vrworld object). Then
use the MATLAB Compiler product.
1-10
Virtual Reality Modeling Language (VRML)
VRML History
The Virtual Reality Modeling Language (VRML) is the language you use to
display three-dimensional objects with a VRML viewer.
Since people started to publish their documents on the World Wide Web
(WWW), there has been an effort to enhance the content of Web pages with
advanced three-dimensional graphics and interaction with those graphics.
The term Virtual Reality Markup Language (VRML) was first used by Tim
Berners-Lee at a European Web conference in 1994 when he talked about a
need for a 3-D Web standard. Soon afterward, an active group of artists and
engineers formed around a mailing list called www-vrml. They changed the
name of the standard to Virtual Reality Modeling Language to emphasize
the role of graphics. The result of their effort was to produce the VRML
1 specification. As a basis for this specification, they used a subset of the
Inventor file format from Silicon Graphics.
1-11
1 Getting Started
VRML Support
The Virtual Reality Modeling Language (VRML) is an ISO standard that is
open, text-based, and uses a WWW-oriented format. You use VRML to define
a virtual world that you can display with a VRML viewer and connect to a
Simulink model.
1-12
Virtual Reality Modeling Language (VRML)
The software analyzes the structure of the virtual world, determines what
signals are available, and makes them available from the MATLAB and
Simulink environment.
The software includes functions for retrieving and changing virtual world
properties.
VRML Compatibility
The Simulink 3D Animation product currently supports most features of
VRML97, with the following limitations:
• The Simulink 3D Animation server ignores the VRML Script node, but it
passes the node to the VRML Viewer. This allows you to run VRML scripts
on the viewer side. You cannot run them on the Simulink 3D Animation
server.
• The Simulink 3D Animation Viewer does not support the Sound node. (The
Blaxxun Contact viewer does.)
• In keeping with the VRML97 specification, the Simulink 3D Animation
Viewer ignores BMP files. As a result, VRML scene textures might not
display properly in the Simulink 3D Animation Viewer. To properly display
scene textures, replace all BMP texture files in a VRML scene with PNG,
1-13
1 Getting Started
JPG, or GIF equivalents. Note that Blaxxun Contact supports BMP files in
addition to the standard VRML texture file formats.
1-14
Virtual Reality Modeling Language (VRML)
The VRML coordinate system is different from the MATLAB and Aerospace
Blockset™ coordinate systems. VRML uses the world coordinate system in
which the y-axis points upward and the z-axis places objects nearer or farther
from the front of the screen. It is important to realize this fact in situations
involving the interaction of these different coordinate systems. SimMechanics
uses the same coordinate system as VRML.
Rotation angles — In VRML, rotation angles are defined using the right-hand
rule. Imagine your right hand holding an axis while your thumb points in the
direction of the axis toward its positive end. Your four remaining fingers
point in a counterclockwise direction. This counterclockwise direction is the
positive rotation angle of an object moving around that axis.
Child objects — In the hierarchical structure of a VRML file, the position and
orientation of child objects are specified relative to the parent object. The
parent object has its local coordinate space defined by its own position and
orientation. Moving the parent object also moves the child objects relative
to the parent object.
Measurement units — All lengths and distances are measured in meters, and
all angles are measured in radians.
1-15
1 Getting Started
This section introduces VRML. For more information, see the VRML97
Reference. This reference is available online at http://www.web3d.org.
Many specialized VRML books can help you understand VRML concepts and
create your own virtual worlds. For more information about the VRML, refer
to an appropriate third-party VRML book.
Each node contains a list of fields that hold values defining parameters for
its function.
Nodes can be placed in the top level of a tree or as children of other nodes in
the tree hierarchy. When you change a value in the field of a certain node, all
nodes in its subtree are affected. This feature allows you to define relative
positions inside complicated compound objects.
1-16
Virtual Reality Modeling Language (VRML)
You can mark every node with a specific name by using the keyword DEF in
the VRML scene code. For example, the statement DEF MyNodeName Box sets
the name for this box node to MyNodeName. You can access the fields of only
those nodes that you name in a virtual world
In the following example of a simple VRML file, two graphical objects are
modeled in a 3-D scene: A floor is represented by a flat box with a red ball
above it. The VRML file is a readable text file that you can write in any text
editor.
The first line is the VRML header line. Every VRML file must start with this
header line. It indicates that this is a VRML 2 file and that the text objects
in the file are encoded according to the UTF8 standard. You use the number
sign (#) to comment VRML worlds. Everything on a line after the # sign is
ignored by a VRML viewer, with the exception of the first header line.
1-17
1 Getting Started
Most of the box properties are left at their default values – distance from the
center of the coordinate system, material, color, and so on. Only the name
Floor and the dimensions are assigned to the box. To be able to control the
position and other properties of the ball, it is defined as a child node of a
Transform type node. Here, the default unit sphere is assigned a red color
and a position 10 m above the floor. In addition, the virtual world title is used
by VRML viewers to distinguish between virtual worlds. A suitable initial
viewpoint is defined in the virtual world VRML file.
When displayed in a VRML viewer, the floor and red ball look like this:
1-18
Virtual Reality World and Dynamic System Examples
vrbounce
A Simulink window opens with the block diagram for the model. By
default, a virtual world also opens in the Simulink 3D Animation Viewer or
your VRML-enabled Web browser. If you close the virtual world window,
double-click the VR Sink block to display it again.
Note If the viewer does not open, double-click the VR Sink block in
the Simulink model. In the Simulink 3D Animation Viewer, from the
Simulation menu, click Block Parameters. A Block Parameters dialog
box opens. The Open VRML viewer automatically check box should be
selected by default. When you double-click the VR Sink block, this selection
enables the virtual world window to open.
A simulation starts running, and the virtual world is animated using signal
data from the simulation.
1-19
1 Getting Started
The following table lists the Simulink examples provided with the Simulink
3D Animation product. Descriptions of the examples follow the table.
Simulink
Coder™ VR VR Space
Example Ready Sink Source Joystick Mouse
vrbounce X X
vrcrane_joystick X X
vrcrane_panel X X
vrcrane_traj X X
vrlights X X
vrmaglev X X
vrmaglev_rtwin X X
vrmanipul X X
vrmanipul_global X X
vrmemb1 X X
vrmorph X X
vr_octavia X X
vr_octavia_2cars X
vr_octavia_graphs X
vr_octavia_mirror X
vr_octavia_video X
vrdemo_panel X X
vrpend X X
vrplanets X X
vrtkoff X X
vrtkoff_trace X
vrtkoff_hud X
1-20
Virtual Reality World and Dynamic System Examples
1-21
1 Getting Started
For details on how the crane model hierarchy and scripting logic is
implemented, see the associated commented VRML file portal_crane.wrl.
The control panel contains a pushbutton, switch button, toggle switch, and
a 2-D setpoint selection area. Outputs of these elements are read into a
Simulink model and subsequently displayed using standard sinks, or used as
inputs of blocks that control back some objects in the virtual world.
Pushbutton, switch button, and toggle switches have the state outputs, which
are of boolean type. Their values are displayed using the Scope.
Two outputs of the 2D setpoint area are used to achieve the following
behavior. The value of the "SetPoint_Changed" eventOut is continuously
updated when the pointer is over the sensor area. This value is triggered
by the second output - "isActive" that is true only on clicking the pointer
button. Triggered value - coordinates of the active point on the sensor plane
are displayed using the XY Graph and sent back to the virtual world in two
1-22
Virtual Reality World and Dynamic System Examples
ways: as a position of green cone marker and as text that the VR Text Output
block displays on the control panel.
A crane magnet attaches the load box, moves it to a different location, then
releases the box and returns to the initial position. This effect is achieved
using an additional, geometrically identical shadow object that is placed as
an independent object outside of the crane objects hierarchy. At any given
time, only one of the Load or Shadow objects is displayed, using two VRML
Switch nodes connected by the ROUTE statement.
After the crane moves the load to a new position, at the time of the load
release, a VRMLScript script assigns the new shadow object position
according to the current Load position. The Shadow object becomes visible.
Because it is independent from the rest of the crane moving parts hierarchy,
it stays at its position as the crane moves away.
1-23
1 Getting Started
To achieve a dragging effect, use the VRML PlaneSensor attached to the ball
geometry with its output restricted to <0,1> in the vertical coordinate and
processed by the VR Sensor Reader block. The vrextin S-function provides
the data connection.
For more details on how to read values from virtual worlds programmatically,
see “Working with VRML Sensors” on page 3-25.
After enabling the remote view in the VR Sink block dialog box, you can
control the Simulink model even from another (remote) client computer.
This control can be useful for distributing the computing power between a
real-time Simulink model running on one machine and the rendering of a
virtual reality world on another machine.
To work with this model, use as powerful a machine as possible or split the
computing and rendering over two machines.
1-24
Virtual Reality World and Dynamic System Examples
space mouse input for manipulating objects in a virtual world. You must have
a space mouse input to run this example.
A space mouse is an input device with six degrees of freedom. It is useful for
navigating and manipulating objects in a virtual world. A space mouse is also
suitable as a general input device for Simulink models. You can use a space
mouse for higher performance applications and user comfort. Space mouse
input is supported through the Space Mouse Input block, which is included in
the Simulink 3D Animation block library for the Simulink environment.
The Space Mouse Input block can operate in three modes to cover the most
typical uses of such a device in a three-dimensional context:
• Speeds
• Positions
• Viewpoint coordinates
1-25
1 Getting Started
The VR Source block supports using global coordinates for objects in a virtual
world. For each Transform in the scene, the tree view in the VR Source block
parameter dialog box displays the Extensions branch. In that branch, you
can select translation_abs and rotation_abs fields. Fields with the _abs
suffix contain the object’s global coordinates. The fields without the _abs
suffix input their data into Simulink model object’s local coordinates (relative
to their parent objects in model hierarchy).
The VR Source block in the VRML tree on the left captures global coordinates
of all objects important for load manipulation:
1-26
Virtual Reality World and Dynamic System Examples
Based on having the global coordinates of all of the important objects, you can
implement a simple manipulator control logic.
1-27
1 Getting Started
1-28
Virtual Reality World and Dynamic System Examples
When the pointing device in the VRML viewer moves over an active
TouchSensor area, the cursor shape changes. The triggering logic in this
model is set to apply the new set point value with a left mouse button click.
1-29
1 Getting Started
Several viewpoints are defined in the virtual world, both static and attached to
an observer on Earth. You can see that the planet bodies are not represented
as perfect spheres. Using the VRML Sphere graphic primitive, which is
rendered this way, simplified the model. If you want to make the planets
more realistic, you could use the more complex IndexedFaceSet node type.
The example sends the text to a virtual world using the VR Text Output
block. This block formats the input vector using the format string defined in
1-30
Virtual Reality World and Dynamic System Examples
its mask (see sprintf for more information) and sends the resulting string to
the 'string' field of the associated VRML text node in the scene.
1-31
1 Getting Started
vrml()
Moving Morphing Function Space
Example Objects Objects Text Recording Use Mouse
vrcar X
vrheat X X
vrheat_anim X X X
vrmemb X X X
vrterrain_simple X
vrtkoff_spacemouse X X
vrcar
1-32
Virtual Reality World and Dynamic System Examples
At the end of this example, you can preserve the virtual world object in the
MATLAB workspace, then save the resulting scene to a corresponding VRML
file or carry out other subsequent operations on it.
You can control the offline animation recording mechanism by setting the
relevant vrworld and vrfigure object properties. You should use the
Simulink 3D Animation Viewer to record animations. However, direct control
of the recording is also possible.
This example uses the heat distribution data from the vrheat example to
create an animation file. You can later distribute this animation file to be
independently viewed by others. For this kind of visualization, where the
static geometry represented by VRML IndexedFaceSet is colored based on
the simulation of some physical phenomenon, it is suitable to create 2-D
.avi animation files. The software uses the avifile function to record 2-D
animation exactly as it appears in the viewer figure.
There are several methods you can use to record animations. In this example,
we use the scheduled recording. When scheduled recording is active, a time
1-33
1 Getting Started
frame is recorded into the animation file with each setting of the virtual world
Time property. Recording is completed when you set the scene time at the end
or outside the predefined recording interval.
When using the Simulink 3D Animation MATLAB interface, you set the scene
time as desired. This is typically from the point of view of the simulated
phenomenon equidistant times. This is the most important difference from
recording the animations for virtual worlds that are associated with Simulink
models, where scene time corresponds directly to the Simulink time.
The scene time can represent any independent quantity along which you want
to animate the computed solution.
At the end of this example, the resulting file vrheat_anim.avi remains in the
working folder for later use.
After starting the example, you see a control panel with two sliders and three
check boxes. Use the sliders to rotate and zoom the membrane while you use
the check boxes to determine the axis to rotate around.
1-34
Virtual Reality World and Dynamic System Examples
In the VRML scene, notice the text object. It is a child of the VRML Billboard
node. You can configure this node so that its local z-axis turns to point to the
viewer at all times. This can be useful for modeling virtual control panels
and head-up displays (HUDs).
As a source of terrain data, the South San Francisco DEM model (included
in the Mapping Toolbox™ software) has been used. A simple Boeing® 747®
model is included in the scene to show the technique of creating virtual worlds
from several sources on-the-fly.
1-35
1 Getting Started
1-36
2
Installation
The Simulink 3D Animation product provides the files you need for
installation on both your host computer and client computer.
Note Support for the Blaxxun Contact viewer will be removed in a future
release. Consider using one of the other VRML viewers described in “VRML
Viewers” on page 7-3.
Note The Blaxxun Contact installer installs the plug-in for the current
default browser only. If you change the default browser, you need to complete
the install procedure a second time. The Blaxxun Contact installation
executable files are located at C:\matlabroot\toolbox\sl3d\blaxxun.
Version 4.4 of the Blaxxun Contact VRML plug-in is distributed with the
software. The following procedure describes how to install the plug-in.
If you have the MATLAB Web Server installed on your machine, make
sure that you stop the Web Server before you install the Blaxxun Contact
plug-in. Also, verify that you are connected to the Internet before starting
this installation procedure:
2-2
Install Blaxxun Contact® on Host Computer
The Blaxxun Contact installer starts running and displays the following
dialog box.
vrinstall
-check
2-3
2 Installation
VRML
viewer: not installed
If you are using Internet Explorer 5.5 or later, you must manually change
a network security setting before you can use Blaxxun Contact 4.4 with
Simulink 3D Animation Version 3.0 or later. Upgrading your version of the
Blaxxun Contact plug-in does not resolve this problem.
The Blaxxun Contact VRML plug-in does not work reliably on Microsoft®
Windows 7 platforms.
2-4
Install Blaxxun Contact® on Host Computer
6 Scroll down until you see Microsoft VM. The first subheading is Java
permissions.
7 Select Custom.
The Java Custom Settings button appears in the lower left of the
Security Settings dialog box.
10 Scan the main headings and subheadings (marked with a lock icon) until
you see Run Unsigned Content.
13 Click OK.
You are asked if you want to change the security settings for this zone.
15 Select Yes.
2-5
2 Installation
TCP/IP Connection
The client computer communicates with the host computer over TCP/IP, and
it displays the virtual world using a VR client. In this case, the VR client
is a VRML-enabled Web browser. You can verify the TCP/IP connection
between the host and client computers by using the ping command from a
command-line prompt. If there are problems, you must first fix the TCP/IP
protocol settings according to the documentation for your operating system.
2-6
Set the Default Viewer
The following procedure describes how to set the viewer to the Simulink 3D
Animation Viewer or the Web browser. It assumes that you are working with
a PC platform. If you want to use the legacy Simulink 3D Animation Viewer,
see “Legacy Simulink® 3D Animation™ Viewer” on page 7-69.
vrinstall -check
VRML
viewer: installed VRML editor: installed
vrgetpref
ans =
DataTypeBool: 'logical'
DataTypeInt32: 'double'
DataTypeFloat: 'double'
DefaultCanvasNavPanel: 'none'
DefaultCanvasUnits: 'normalized'
DefaultEditorPosition: [325 216 763 901]
DefaultEditorTriad: 'bottomleft'
2-7
2 Installation
DefaultFigureAntialiasing: 'on'
DefaultFigureCaptureFileFormat: 'tif'
DefaultFigureCaptureFileName: '%f_anim_%n.tif'
DefaultFigureDeleteFcn: ''
DefaultFigureLighting: 'on'
DefaultFigureMaxTextureSize: 'auto'
DefaultFigureNavPanel: 'halfbar'
DefaultFigureNavZones: 'off'
DefaultFigurePosition: [5 92 576 380]
DefaultFigureRecord2DCompressMethod: 'auto'
DefaultFigureRecord2DCompressQuality: 75
DefaultFigureRecord2DFileName: '%f_anim_%n.avi'
DefaultFigureRecord2DFPS: 15
DefaultFigureStatusBar: 'on'
DefaultFigureTextures: 'on'
DefaultFigureToolBar: 'on'
DefaultFigureTransparency: 'on'
DefaultFigureTriad: 'none'
DefaultFigureWireframe: 'off'
DefaultViewer: 'internal'
DefaultWorldRecord3DFileName: '%f_anim_%n.wrl'
DefaultWorldRecordMode: 'manual'
DefaultWorldRecordInterval: [0 0]
DefaultWorldRemoteView: 'off'
DefaultWorldTimeSource: 'external'
Editor: '*BUILTIN'
EditorSavePosition: 'on'
HttpPort: 8123
TransportBuffer: 5
TransportTimeout: 20
VrPort: 8124
vrplanets
2-8
Set the Default Viewer
The Planets example is loaded and the virtual world is displayed in the
Simulink 3D Animation Viewer.
vrsetpref('DefaultViewer','web')
vrplanets
2-9
2 Installation
The Planets example is loaded and the virtual world is displayed in your
Web browser.
vrsetpref('DefaultViewer','factory')
2-10
Set the Default Viewer
2-11
2 Installation
Installing the VRML editor writes a key to the Microsoft Windows registry,
making extra V-Realm Builder library files available for you to use, and it
associates the Edit button in Simulink 3D Animation blocks with this editor:
vrinstall
-install editor
or type
vrinstall('-install','editor')
3 Type
vrinstall
-check
2-12
Install V-Realm Editor on Host Computer
Note You cannot access the V-Realm Builder documentation from the Web.
If you are reading this page on the Web, then you need to open the MATLAB
Help browser and navigate to the V-Realm Builder documentation.
To access V-Realm Builder help from the MATLAB Help browser, click
V-Realm Builder help.
You can view the V-Realm Builder help even if you have not installed
V-Realm Builder.
2-13
2 Installation
The default VRML editor is the 3D World Editor. You can change your
environment to use another editor. You can use the MATLAB Preferences
menu or the MATLAB command line.
2-14
Set the Default Editor
You can use the VRML Editor preference to select another editor: the
V-Realm Builder, the MATLAB editor, or a third-party VRML editor or text
editor. To use a third-party editor, select the Custom option. In the text box
that appears, enter the path to the editor.
2-15
2 Installation
vrgetpref('Editor')
2 The default is the 3D World Editor (*BUILTIN). To change the editor, use
the vrsetpref command, specifying the editor that you want. For example,
to change to the V-Realm editor, type:
vrsetpref('Editor', '*VREALM')
Tip The vredit command opens the 3D World Editor, regardless of the
default editor preference setting.
2-16
Set Simulink® 3D Animation™ Preferences
2-17
2 Installation
The Simulink 3D Animation Preferences dialog box opens in the right pane.
2-18
Set Simulink® 3D Animation™ Preferences
3 Set the preferences that you want. See the following table for the
preferences that you can change. Click OK to save the settings.
2-19
2 Installation
2-20
Set Simulink® 3D Animation™ Preferences
2-21
2 Installation
Canvas Preferences
The Simulink 3D Animation preferences include a Navigation panel
preference. The canvas preferences apply to the 3D World Editor, Simulink
3D Animation Viewer, and Simulink 3D Animation Web Viewer.
2-22
Set Simulink® 3D Animation™ Preferences
Figure Preferences
The Simulink 3D Animation figure has a number of preferences:
4 Set the preferences as desired. See the following table for the rendering
preferences you can change. Click OK to save the settings.
2-23
2 Installation
2-24
Set Simulink® 3D Animation™ Preferences
5 Set the preferences as desired. See the following table for the rendering
preferences you can change. Click OK to save the settings.
2-25
2 Installation
2-26
Set Simulink® 3D Animation™ Preferences
The Simulink 3D Animation Preferences dialog box opens in the right pane.
5 Set the preferences as desired. See the following table for the rendering
preferences you can change. Click OK to save the settings.
2-27
2 Installation
2-28
Set Simulink® 3D Animation™ Preferences
5 Set the preferences that you want. See the following table for the rendering
preferences that you can change. Click OK to save the settings.
2-29
2 Installation
2-30
Set Simulink® 3D Animation™ Preferences
4 Set the preferences as desired. See the following table for the rendering
preferences you can change. Click OK to save the settings.
2-31
2 Installation
1 On the Windows task bar, click Start, point to MATLAB, and then click
the uninstaller.
Note The Blaxxun Contact plug-in is not uninstalled during the Simulink
3D Animation software removal.
2-32
Uninstall Blaxxun Contact® from Host Computer
1 From the Windows task bar, click Start, point to Settings, and click
Control Panel.
2-33
2 Installation
Section Overview
In most configurations, you do not need to install a viewer on a client computer
because you can perform all the tasks on a host computer. However, if you
have very large models that consume considerable computational resources,
you might want to use a client computer to run and view the virtual world.
The client computer must have a VRML97 plug-in with External Authoring
Interface (EAR) support. This means that your client computer must be a
PC platform with the Blaxxun Contact plug-in. Only the Blaxxun Contact
software is supported.
• Copy the file blaxxuncontact44.exe from your host computer to the client
computer. This file is located at C:\matlabroot\toolbox\sl3d\blaxxun.
2-34
Test the Viewer Installation
Section Overview
The Simulink 3D Animation product includes several Simulink models with
the associated virtual worlds. These models are examples of what you can do
with this software. You can use one of these examples to test the installation
of the VRML viewer.
Simulink Testing
Before you can run this example, you have to install the MATLAB, Simulink,
and Simulink 3D Animation products as follows:
vrpend
A Simulink window opens with the model for an inverted pendulum. This
model, which you can view in three dimensions with the software, has an
interactive set point and trajectory graph.
2-35
2 Installation
2-36
Test the Viewer Installation
2-37
2 Installation
The pendulum set point, represented by the green cone, moves to a new
location. Next, the path is drawn on the trajectory graph, and then the
pendulum itself moves to the new location.
5 From the Stipend mode list, choose Mouse, then click OK.
2-38
Test the Viewer Installation
You can now use the trajectory graph as a 2-D input device to set the
position of the pendulum.
6 Move the mouse pointer into the graph area and click.
The set point (red circle) for the pendulum position moves to a new location.
The trajectory for the pendulum is displayed in the graph as a blue line.
2-39
2 Installation
8 Close the Simulink 3D Animation Viewer and close the Simulink window.
You can try other examples in “Simulink Interface Examples” on page 1-19, or
you can start working on your own projects.
MATLAB Testing
This model, which can be viewed in three dimensions with the software, has a
MATLAB interface to control the figure in a VRML viewer window.
vrmemb
2-40
Test the Viewer Installation
2 Use the viewer controls to move within the virtual world, or use the example
dialog box to rotate the membrane. Note that sometimes the Simulink 3D
Animation example dialog box is hidden behind the viewer window.
2-41
2 Installation
2-42
3
Simulink Interface
The Simulink 3D Animation product works with both the MATLAB and the
Simulink products. However, the Simulink interface is the preferred way
of working with the software. It is more straightforward to use and all the
features are easily accessible through a graphical interface.
After you create a virtual world and a Simulink model, you can connect the
two with Simulink 3D Animation blocks. The example in this procedure
simulates a plane taking off and lets you view it in a virtual world.
Note The examples in this topic are based on the Simulink 3D Animation
default viewer. If you choose to use the Blaxxun Contact VRML plug-in to
view virtual worlds, you must start and stop the model simulation from the
Simulink window. You cannot start and stop the model simulation from the
Blaxxun Contact VRML plug-in.
vrtut2
3-2
Virtual World Connection to a Model
2 From the Simulation menu, select Mode > Normal, then click
Simulation > Run.
vrlib
4 From the Library window, drag and drop the VR Sink block to the
Simulink diagram. The VR Sink block writes data from the Simulink model
to the virtual world. You can then close the Library: vrlib window.
Now you are ready to select a virtual world for the visualization of your
simulation. A simple virtual world with a runway and a plane is in the
VRML file vrtkoff.wrl, located in the vrdemos folder.
3-3
3 Simulink® Interface
6 In the Description text box, enter a brief description of the model. This
description appears on the list of available worlds served by the Simulink
3D Animation server. For example, type
7 At the Source File text box, click the Browse button. The Select World
dialog box opens. Find the folder matlabroot\toolbox\sl3d\sl3ddemos.
Select the file vrtkoff.wrl and click Open.
A VRML tree appears on the right side, showing the structure of the
associated virtual reality scene.
3-4
Virtual World Connection to a Model
The Plane Transform tree expands. Now you can see what characteristics
of the plane can be driven from the Simulink interface. This model
computes the position and the pitch of the plane.
The selected fields are marked with checks. These fields represent the
position (translation) and the pitch (rotation) of the plane.
12 Click OK.
In the Simulink diagram, the VR Sink block is updated with two inputs.
3-5
3 Simulink® Interface
13 In the Simulink model, connect the line going to the Scope block labeled
Display Pitch to the Plane rotation input.
The second input is Plane translation. This input describes the plane’s
position in the virtual world. This position consists of three coordinates, x,
y, z. The connected vector must have three values. In this example, the
runway is in the x-z plane (see the VR Signal Expander block). The y-axis
defines the altitude of the plane.
14 In the Simulink model, connect the line going to the Scope block labeled
Display Position to the Plane translation input.
After you connect the signals and remove the Scope blocks, your model
should look similar to the figure shown.
3-6
Virtual World Connection to a Model
Note When you next open the model, the associated virtual scene opens
automatically. This behavior occurs even if the Simulink 3D Animation
block associated with the virtual scene is in a subsystem of the model.
3-7
3 Simulink® Interface
A plane, moving right to left, starts down the runway and takes off into
the air.
After you associate a virtual world with a Simulink model, you can select
another virtual world or change signals connected to the virtual world. This
procedure assumes that you have connected the vrtut2 Simulink model with
a virtual world. See “Add a Simulink® 3D Animation™ Block” on page 3-2.
3-8
Virtual World Connection to a Model
3 At the Source File text box, click the Browse button. The Select World
dialog box opens. Find the folder matlabroot\toolbox\sl3d\sl3ddemos.
Select the file vrtkoff2.wrl, and click Open.
A VRML tree appears on the right side. The Simulink software associates a
new virtual world with the model.
The Plane Transform tree expands. Now you can see what characteristics
of the plane you can drive from the Simulink interface. This model
computes the position.
6 In the Plane Transform tree, select the translation field check box. Clear
the rotation field check box. Click OK.
The VR Sink block is updated and changes to just one input, the Plane
translation. The Virtual Reality block is ready to use with the new
parameters defined.
7 Verify that the correct output is connected to your VR Sink block. The
output from the VR Signal Expander should be connected to the single
input.
3-9
3 Simulink® Interface
3-10
Open a Viewer Window
Multiple instances of the viewer can exist on your screen. A viewer appears
each time you select the File menu New Window option in the Simulink 3D
Animation Viewer. This feature is particularly useful if you want to view one
scene from many different viewpoints at the same time.
If you close the viewer window, you might want to reopen it. In the Simulink
model window, double-click the VR Sink block.
3-11
3 Simulink® Interface
vrtut1
A VRML viewer also opens with a 3-D model of the virtual world associated
with the model.
3-12
Display Virtual World and Start Simulation
3 Use the Simulink 3D Animation Viewer controls to move the camera within
this virtual world while the simulation is running. For more information
on the Simulink 3D Animation Viewer controls, see “Simulink® 3D
Animation™ Viewer” on page 7-6.
3-13
3 Simulink® Interface
Alternatively, you can view a virtual world in your Web browser by selecting
an open virtual world from a list in your Web browser. You can display
the HTML page that contains this list by connecting to the Simulink 3D
Animation host. This is the computer on which the Simulink 3D Animation
software is currently running. You do not need a VRML-enabled Web browser
to display this page.
Note that a virtual world appears on this list in your Web browser only if the
vrworld Description property contains a string. If this property is empty
for a virtual world, that world is not accessible from the remote host. The
simplest way to set a world description is to define the virtual world VRML
file WorldInfo node and fill in the title field for that node. You can set up
the WorldInfo node to look like the following:
WorldInfo {
The vrworld object uses the title string in the VRML file for the
Description property of the vrworld object. You can change this property
with the Simulink 3D Animation MATLAB interface (vrworld/set).
vrbounce
3-14
View Virtual World on Host Computer
2 Open your VRML-enabled Web browser. In the address line of the browser,
type
http://localhost:8123
Note To connect to the main HTML page from a client computer, type
http://hostname:8123, where hostname is the name of the computer on
which the Simulink 3D Animation software is currently running.
The main HTML page for the Simulink 3D Animation product lists the
currently available (active) virtual worlds. In this example, the VR
Bouncing Ball virtual world appears as a link.
3-15
3 Simulink® Interface
3-16
View Virtual World on Host Computer
From the main HTML page, you can select one of the listed available worlds
or click the reload link to update the status of the virtual worlds supported
by the software. This page does not require the VRML capabilities from the
browser; it is a standard HTML page. Nevertheless, when you click one of
the virtual world links in the list, the browser has to be VRML-enabled to
display the virtual world correctly and to communicate with the Simulink
3D Animation product.
3-17
3 Simulink® Interface
vrtut1
3-18
View Virtual World Remotely
2 Double-click the VR Sink block. This block is in the right part of the model
window.
A VRML viewer also opens with a 3-D model of the virtual world associated
with the model.
3-19
3 Simulink® Interface
Note This option allows any computer connected to the network to view
your model. You should never select this box when you want your model to
be private or confidential.
5 Click OK.
http://192.168.0.1:8123
3-20
View Virtual World Remotely
ifconfig device_name
Click OK. An IP Configuration dialog box opens with a list of your IP,
mask, and gateway addresses.
Alternatively, for Windows platforms, you can open a DOS shell and type
ipconfig.
The Web browser displays the main Simulink 3D Animation HTML page.
Only one virtual world is in the list because you have only one Simulink
model open.
3-21
3 Simulink® Interface
The Web browser displays a 3-D model of the virtual world associated
with the model.
3-22
View Virtual World Remotely
On the client computer, the animation of the scene reflects the process
simulated in the Simulink diagram on the host computer.
You can tune communication between the host and the client computer by
setting the Sample time and Transport buffer size parameters.
9 Use the Web browser controls to move within this virtual world while the
simulation is running.
3-23
3 Simulink® Interface
3-24
Working with VRML Sensors
Virtual reality scenes can contain sensors, nodes able to generate events and
output values depending on time, user navigation, and actions and distance
changes in the scene. These nodes add interactivity to the virtual world.
You can use Simulink 3D Animation functions to read sensor field values
into simulation models and control simulation based on the user interaction
with the virtual scene.
Sensors Description
CylinderSensor Maps pointer motion (for example, a mouse or wand) into
a rotation on an invisible cylinder that is aligned with
the y-axis of the local coordinate system.
PlaneSensor Maps pointing device motion into two-dimensional
translation in a plane parallel to the z=0 plane of the
local coordinate system.
ProximitySensor Generates events when the viewer enters, exits, and
moves within a region in space (defined by a box).
SphereSensor Maps pointing device motion into spherical rotation
about the origin of the local coordinate system.
TimeSensor Generates events as time passes.
3-25
3 Simulink® Interface
Sensors Description
TouchSensor Tracks the location and state of the pointing device and
detects when you point at geometry contained by the
TouchSensor node parent group.
VisibilitySensor Detects visibility changes of a rectangular box as you
navigate the world.
Interactive Mode
Interactive mode allows clients to modify a remote virtual world via events
from sensor nodes defined in the virtual world. Interactive mode is useful
when a virtual world includes a sensor.
Interactive mode is disabled by default on clients. You can enable (or later
disable) interactive mode on a client via context menu in the Web Viewer or
by pressing the I key shortcut.
You can disable interactive mode for a particular virtual world on the host
computer. For details, see the ClientUpdates property, using vrworld/get
or vrworld/set.
3-26
Working with VRML Sensors
new setpoint for the ball position controller. You can read the sensor output
value into a MATLAB variable setpoint with the following:
To use the setpoint value in a Simulink model, you can write an S-function
or an MATLAB Function block that reads the sensor output periodically.
For an example of such an S-function:
The parameters defined in the mask supply the sample time, virtual world,
and the node/field to read.
• Instead of setting its own block outputs, the vrextin S-function sets the
value of the adjacent Constant block value_holder. This setting makes the
3-27
3 Simulink® Interface
• You can use this method to input information from all VRML node fields
of the type exposedField or eventOut, not only a Sensor eventOut field.
See VRML Data Class Types for more information about VRML Data
class types.
• For fields of class exposedField, you can use an alternate name using
the field name with the suffix, _changed. For example, translation and
translation_changed are alternate names for requesting the translation
field value of the above Grab_Sensor node.
3-28
VR Source Block Input to Simulink® Models
For an example of how to use the VR Sink block, see Magnetic Levitation
Model.
3-29
3 Simulink® Interface
3-30
4
MATLAB Interface
Note The Simulink interface and the MATLAB interface share the same
virtual world objects. This enables you to use the MATLAB interface to
change the properties of vrworld objects originally created by Simulink with
Simulink 3D Animation blocks.
After you create a virtual world, you can create a vrworld object. This
procedure uses the virtual world vrmount.wrl as an example.
4-2
Create vrworld Object for a Virtual World
myworld = vrworld('vrmount.wrl')
myworld =
vrworld object: 1-by-1
2 Type
vrwhos
The vrworld object myworld is associated with the virtual world vrmount.wrl.
You can think of the variable myworld as a handle to the vrworld object
stored in the MATLAB workspace.
Your next step is to open a virtual world using the vrworld object. See “Open
a Virtual World with MATLAB” on page 4-4.
4-3
4 MATLAB® Interface
After you create a vrworld object, you can open the virtual world by using
the vrworld object associated with that virtual world. This procedure uses
the vrworld object myworld associated with the virtual world vrmount.wrl as
an example:
open(myworld);
2 Type
view(myworld)
The viewer that is set as the default viewer displays the virtual scene.
This is typically the Simulink 3D Animation Viewer unless you have a
different viewer set.
4-4
Open a Virtual World with MATLAB®
http://localhost:8123
The browser displays the Simulink 3D Animation HTML page with a link
to My first virtual world. The number 8123 is the default Simulink
3D Animation port number. If you set a different port number on your
system, enter that number in place of 8123 and restart MATLAB. For more
information on the Simulink 3D Animation HTML page, see “View Virtual
World on Host Computer” on page 3-14.
3 If the Web browser has the VRML plug-in installed, in the browser window,
click My first virtual world.
For more information on changing your default viewer, see “Set the Default
Viewer” on page 2-7.
4-5
4 MATLAB® Interface
An object of type vrworld contains nodes named in the VRML file using the
DEF statement. These nodes are of type vrnode. For more information, see
vrworld and vrnode functions.
After you open a vrworld object, you can get a list of available nodes in
the virtual world. This procedure uses the vrworld object myworld and the
virtual world vrmount.wrl as an example. To create the myworld, see “Create
vrworld Object for a Virtual World” on page 4-2.
nodes(myworld);
The MATLAB Command Window displays a list of the vrnode objects and
their fields that are accessible from the Simulink 3D Animation software.
2 Type
4-6
Interact with a Virtual World with MATLAB®
mynodes =
3 Type
whos
Now you can get node characteristics and set new values for certain node
properties. For example, you can change the position of the automobile by
using Automobile, which is the fourth node in the virtual world.
fields(myworld.Automobile)
4-7
4 MATLAB® Interface
or
fields(mynodes(10));
-----------------------------------------------------------
addChildren eventIn MFNode off
removeChildren eventIn MFNode off
children exposedField MFNode off
center exposedField SFVec3f off
rotation exposedField SFRotation off
scale exposedField SFVec3f off
scaleOrientation exposedField SFRotation off
translation exposedField SFVec3f off
bboxCenter field SFVec3f off
bboxSize field SFVec3f off
The Automobile node is of type Transform. This VRML node allows you
to change its position by changing its translation field values. From the
list, you can see that translation requires three values, representing
the [x y z] coordinates of the object.
5 Type
view(myworld)
Your default viewer opens and displays the virtual world vrmount.wrl.
6 Move the MATLAB window and the browser window side by side so you
can view both at the same time. In the MATLAB Command Window, type
The MATLAB sets a new position for the Automobile node, and you can
observe that the car is repositioned in the VRML browser window.
4-8
Interact with a Virtual World with MATLAB®
You can change the node fields listed by using the function vrnode/setfield.
Note The dot notation is the preferred method for accessing nodes.
4-9
4 MATLAB® Interface
close(myworld);
delete(myworld);
Note Closing and deleting a virtual world does not delete the vrworld object
handle myworld from the MATLAB workspace.
4-10
Animation Recording
Animation Recording
In this section...
“Recording Formats” on page 4-11
“Manual and Scheduled Animation Recording” on page 4-12
Note If you are working with virtual scenes controlled from MATLAB,
you can record virtual scenes through the MATLAB interface. Optimally,
use the Simulink 3D Animation Viewer to record animations of virtual
worlds associated with Simulink models. This method ensures that all
necessary virtual world and vrfigure properties are properly set to record
simulations. For details, see “Record Offline Animations with the Simulink®
3D Animation™ Viewer” on page 7-42.
Recording Formats
You can save the virtual world offline animation data in the following formats:
4-11
4 MATLAB® Interface
Note If you distribute VRML animation files, be sure to also distribute all
the inlined object and texture files referenced in the original VRML world
file.
Note While recording 2-D .avi animation data, always ensure that the
Simulink 3D Animation Viewer is the topmost window and fully visible.
Graphics acceleration limitations might prevent the proper recording of
2-D animation otherwise.
4-12
File Name Tokens
%f_anim_%n.<extension>
This format creates a unique file name each time you capture a frame or record
the animation. For details, see “Define File Name Tokens” on page 4-14.
4-13
4 MATLAB® Interface
%f_anim_%n.<extension>
This format creates a unique file name each time you capture a frame or
record the animation. %f and %n are tokens. %f is replaced with the name
of the virtual world associated with the model and %n is a number that
increments each time you record a simulation for the same virtual world.
If you do not change the default file name, for example, if the name of the
virtual world file is vrplanets and you record a simulation for the first time,
the animation file is
vrplanets_anim_1.wrl
If you record the simulation a second time, the animation file name is
vrplanets_anim_2.wrl. In the case of frame captures, capturing another
frame of the scene increments the number.
• Create files whose root names are the same as those of the virtual world.
This option is useful if you use different virtual worlds for one model.
• Create files in directories relative to the virtual world location. This option
is useful if you want to ensure that the virtual world file and frame capture
or animation file are in the same folder.
4-14
Define File Name Tokens
• Create rolling numbered file names such that subsequent frame captures
or runs of the model simulation create incrementally numbered file names.
This is useful if you expect to create files of different parts of the model
simulation. This feature allows you to capture a frame or run a Simulink
model multiple times, but create a unique file each time.
• Create multiple file names with time or date stamps, with a unique file
created each time.
See “File Name Tokens” on page 4-16 for a summary of the file name tokens.
4-15
4 MATLAB® Interface
Token Description
%d The full path to the world VRML file replaces this token in
the file name string and creates files in directories relative
to the virtual world file location. For example, the format
%d/animdir/%f_anim_%n.avi saves the animation in the animdir
subfolder of the folder containing the virtual world VRML file. It
creates the animdir subfolder if one does not exist. This token
is most helpful if you want to ensure that the virtual world file
and animation file are in the same folder.
%D The current day in the month replaces this token in the file
name string. For example, the format %f_anim_%D.wrl saves
the animation to vrplanets_anim_29.wrl for the 29th day of
the month.
%f The virtual world file name replaces this token in the file name
string. For example, the format %f_anim_%D.wrl saves the
animation to vrplanets_anim_29.wrl.
%h The current hour replaces this token in the file name string. For
example, the format %f_anim_%h.wrl saves the animation to
vrplanets_anim_14.wrl for any time between 14:00 and 15:00.
%m The current minute replaces this token in the file name string.
For example, the format %f_anim_%h%m.wrl saves the animation
to vrplanets_anim_1434.wrl for a start record time of 14:34.
%M The current month replaces this token in the file name string.
For example, the format %f_anim_%M.wrl saves the animation to
vrplanets_anim_4.wrl for a start record time in April.
%s The current second replaces this token in the file name string. For
example, the format %f_anim_%h%m%s.wrl saves the animation to
vrplanets_anim_150430.wrl for a start record time of 15:04:30.
4-16
File Name Tokens
Token Description
%n The current incremental number replaces this token in the
file name string. Each subsequent frame capture or run of the
simulation increments the number. For example, the format
%f_anim_%n.wrl saves the animation to vrplanets_anim_1.wrl
on the first run, vrplanets_anim_2.wrl on the second run, and
so forth.
%Y The current four-digit year replaces this token in the file name
string. For example, the format %f_anim_%Y.wrl saves the
animation to vrplanets_anim_2005.wrl for the year 2005.
4-17
4 MATLAB® Interface
1 Run the Simulink model for vrplanets. In the MATLAB window, type
vrplanets
2 To work with the virtual world associated with vrplanets from the
MATLAB interface, retrieve the virtual world handle. Use the vrwhos
command. Type
vrwhos
If the result shows that only one vrworld object is in the workspace, assign
its handle directly to a variable. Type
myworld = vrwho;
If multiple virtual worlds are listed, you must select which of these virtual
worlds you want to manipulate. To select the virtual world, you can use
indexing or a selection method using a string comparison of virtual world
descriptions. For the indexing method, type
worlds = vrwho;
myworld = worlds(1);
4-18
Manual 3-D VRML Recording with MATLAB®
worlds = vrwho;
myworld =
worlds(strcmp('Planets',get(worlds,'Description')));
set(myworld,'RecordMode','manual');
set(myworld,'Record3D','on');
5 Run the Simulink model. From the Simulation menu, select Mode >
Normal, then click Simulation > Run. Alternatively, if you are using the
Simulink 3D Animation default viewer, you can run the Simulink model
with one of the following from the viewer.
• From the menu bar, select the Simulation menu Start option to start
or stop the simulation.
• From the toolbar, click Start/pause/continue simulation to start the
simulation.
• From the keyboard, press Ctrl+T to start the simulation.
6 As the simulation runs, start recording the animation by setting the virtual
world Recording property. Type
set(myworld,'Recording','on');
set(myworld,'Recording','off');
4-19
4 MATLAB® Interface
in the current working folder. If the simulation stops before you stop
recording, the recording operation stops and creates the animation file.
8 Stop the simulation. You can use one of the following from the viewer.
• From the menu bar, select the Simulation menu Stop option to stop
the simulation.
• From the toolbar, click Stop simulation to stop the simulation.
• From the keyboard, press Ctrl+T to stop the simulation.
You do not need to manually stop the recording before stopping the
simulation. If you do not manually stop the recording, the recording
operation does not stop and create the animation file when the simulation
stops.
9 Close and delete the objects if you do not want to continue using them.
4-20
Manual 2-D AVI Recording with MATLAB®
1 Run the Simulink model for vrplanets. In the MATLAB window, type
vrplanets
2 To work with the virtual world associated with vrplanets from the
MATLAB interface, retrieve the virtual world handle. Use the vrwhos
command. Type
vrwhos
3 If the result indicates that only one vrworld object is in the workspace,
assign its handle directly to a variable. Type
myworld = vrwho;
If multiple virtual worlds are listed, you must select which of these virtual
worlds you want to manipulate. To select the virtual world, you can use
indexing or a selection method using a string comparison of virtual world
descriptions. For the indexing method, type
worlds = vrwho;
myworld = worlds(1);
4-21
4 MATLAB® Interface
worlds = vrwho;
myworld =
worlds(strcmp('Planets',get(worlds,'Description')));
f=get(myworld,'Figures')
5 To have the software manually record the animation, set the RecordMode
property to manual. Type
set(myworld,'RecordMode','manual');
set(f,'Record2D','on');
7 Disable the navigation panel. The navigation panel appears at the bottom
of the virtual scene view. You might want to turn off this panel for a
cleaner view of the virtual scene. Type
set(f,'NavPanel','none');
8 Run the Simulink model. From the Simulation menu, select Mode >
Normal, then click Simulation > Run. Alternatively, if you are using the
Simulink 3D Animation default viewer, you can run the Simulink model
with one of the following from the viewer:
• From the menu bar, select the Simulation menu Start option to start
or stop the simulation.
• From the toolbar, click Start/pause/continue simulation to start the
simulation.
• From the keyboard, press Ctrl+T to start the simulation.
4-22
Manual 2-D AVI Recording with MATLAB®
9 As the simulation runs, start recording the animation by setting the virtual
world Recording property. Type
set(myworld,'Recording','on');
set(myworld,'Recording','off');
11 Stop the simulation. You can use one of the following from the viewer.
• From the menu bar, select the Simulation menu Stop option to stop
the simulation.
• From the toolbar, click Stop simulation to stop the simulation.
• From the keyboard, press Ctrl+T to stop the simulation.
You do not need to manually stop the simulation. If you do not manually
stop the recording, the recording operation does not stop and create the
animation file until the simulation stops.
set(f,'NavPanel','halfbar');
13 Close and delete the objects if you do not want to continue using them.
4-23
4 MATLAB® Interface
1 Run the Simulink model for vrplanets. In the MATLAB window, type
vrplanets
2 To work with the virtual world associated with vrplanets from the
MATLAB interface, retrieve the virtual world handle. Use the vrwhos
command. Type
vrwhos
3 If the result indicates that only one vrworld object is in the workspace,
assign its handle directly to a variable. Type
myworld = vrwho;
If multiple virtual worlds are listed, you must select which of these virtual
worlds you want to manipulate. To select the virtual world, you can use
indexing or a selection method using a string comparison of virtual world
descriptions. For the indexing method, type
worlds = vrwho;
myworld = worlds(1);
4-24
Scheduled 3-D VRML Recording with MATLAB®
worlds = vrwho;
myworld =
worlds(strcmp('Planets',get(worlds,'Description')));
set(myworld,'RecordMode','scheduled');
set(myworld,'Record3D','on');
6 Select the start and stop times during which you want to record the
animation. For example, enter 5 as the start time and 15 as the stop time.
set(myworld,'RecordInterval',[5 15]);
Ensure that the recording start time value is not earlier than the start time
of the Simulink model; the recording operation cannot start in this instance.
If the stop time exceeds the stop time of the Simulink model, or if it is an
out of bounds value such as a negative number, the recording operation
stops when the simulation stops. Note that the recording can be slow.
7 Run the Simulink model. From the Simulation menu, select Mode >
Normal, then click Simulation > Run. Alternatively, if you are using the
Simulink 3D Animation default viewer, you can run the Simulink model
with one of the following from the viewer.
• From the menu bar, select the Simulation menu Start option to start
the simulation.
• From the toolbar, click Start/pause/continue simulation to start the
simulation.
• From the keyboard, press Ctrl+T to start the simulation.
4-25
4 MATLAB® Interface
8 When you are done, stop the simulation. You can use one of the following
from the viewer.
• From the menu bar, select the Simulation menu Stop option to stop
the simulation.
• From the toolbar, click Stop simulation to stop the simulation.
• From the keyboard, press Ctrl+T to stop the simulation.
9 Close and delete the objects if you do not want to continue using them.
4-26
Scheduled 2-D AVI Recording with MATLAB®
1 Run the Simulink model for vrplanets. In the MATLAB window, type
vrplanets
2 To work with the virtual world associated with vrplanets from the
MATLAB interface, retrieve the virtual world handle. Use the vrwhos
command. Type
vrwhos
If the result indicates that only one vrworld object is in the workspace,
assign its handle directly to a variable. Type
myworld = vrwho;
If multiple virtual worlds are listed, you must select which of these virtual
worlds you want to manipulate. To select the virtual world, you can use
indexing or a selection method using a string comparison of virtual world
descriptions. For the indexing method, type
worlds = vrwho;
myworld = worlds(1);
4-27
4 MATLAB® Interface
worlds = vrwho;
myworld =
worlds(strcmp('Planets',get(worlds,'Description')));
f=get(myworld,'Figures')
set(myworld,'RecordMode','scheduled');
set(f,'Record2D','on');
6 Select the start and stop times during which you want to record the
animation. For example, enter 5 as the start time and 15 as the stop time.
set(myworld,'RecordInterval',[5 15]);
Ensure that the recording start time value is not earlier than the start time
of the Simulink model; the recording operation cannot start in this instance.
If the stop time exceeds the stop time of the Simulink model, or if it is an
out of bounds value such as a negative number, the recording operation
stops when the simulation stops. Note that the recording can be slow.
7 Disable the Navigation Panel. The Navigation Panel appears at the bottom
of the virtual scene view. You might want to turn off this panel for a
cleaner view of the virtual scene. Type
set(f,'NavPanel','none');
8 Ensure that the virtual reality figure window is the topmost window.
4-28
Scheduled 2-D AVI Recording with MATLAB®
9 Run the Simulink model. From the Simulation menu, select Mode >
Normal, then click Simulation > Run. Alternatively, if you are using the
Simulink 3D Animation default viewer, you can run the Simulink model
with one of the following from the viewer:
• From the menu bar, select the Simulation menu Start option to start
the simulation.
• From the toolbar, click Start/pause/continue simulation to start the
simulation.
• From the keyboard, press Ctrl+T to start the simulation.
10 When you are done, stop the simulation. You can use one of the following
from the viewer:
• From the menu bar, select the Simulation menu Stop option to stop
the simulation.
• From the toolbar, click Stop simulation to stop the simulation.
• From the keyboard, press Ctrl+T to stop the simulation.
set(f,'NavPanel','halfbar');
12 Close and delete the objects if you do not want to continue using them.
4-29
4 MATLAB® Interface
To record animation files for virtual worlds that are not associated with
Simulink models, note the following guidelines. You should be an advanced
Simulink 3D Animation user.
• Retrieve the vrworld object handle of the virtual scene that you want to
record.
• To record 2-D animations,
1 Retrieve the corresponding vrfigure object. For 2-D animations, the
Simulink 3D Animation software records exactly what you see in the
viewer window. Because 2-D animations record exactly what you see in
the Simulink 3D Animation Viewer window, the properties that control
2-D file recording belong to vrfigure objects.
2 Set the Record2D vrfigure property.
4-30
Record Animations for Unconnected Virtual Worlds
set(virtual_world,'TimeSource', 'external')
set(virtual_world,'Time',time_value)
For example, to set the Time property for vrworld, w, with values increasing
by 10, enter
set(w,'Time',10);
set(w,'Time',20);
set(w,'Time',30);
set(w,'Time',40);
set(w,'Time',50);
set(w,'Time',60);
set(w,'Time',70);
set(w,'Time',80);
set(w,'Time',90);
set(w,'Time',100);
4-31
4 MATLAB® Interface
set(w,'Time',110);
set(w,'Time',120);
set(w,'Time',130);
set(w,'Time',140);
If you select a start time of 60 and a stop time of 120 (as described in
“Scheduled 3-D VRML Recording with MATLAB” on page 4-24), the
Simulink 3D Animation software starts recording at 60 and stops at 120.
Because of the repetitive nature of the time interval setting, set the Time
property in a loop from within a script or program.
• After you set the vrworld Time property, set the virtual scene object
properties as necessary. You should set these properties to values that
correspond to the given time frame to achieve the desired animation effect.
• In each time frame, issue the vrdrawnow command for scene changes. This
command renders and updates the scene.
The following code fragment contains a typical loop that iteratively sets the
Time property, changes a virtual scene object property, and calls vrdrawnow to
render the scene:
for time=StartTime:Step:StopTime
% advance the time in the virtual scene
set(myworld,'Time',time);
% here we change VRML nodes properties
myworld.Car.translation = [ time*speed 0 0 ];
% render the changed position
vrdrawnow;
end
If you set the Time property at or outside the end boundary of RecordInterval,
the Simulink 3D Animation software stops recording. You can then view
the resulting animation file.
4-32
Play Animation Files
w=vrview('vrplanets_anim_1.wrl');
4-33
4 MATLAB® Interface
set(w,'TimeSource','freerun');
set(w,'TimeSource','external');
To close the viewer and delete the world, get the handle of the vrfigure
object and close it, as follows:
f=get(w,'Figures')
close(f);
delete(w);
Or, to close all vrfigure objects and delete the world, type
vrclose
delete(w);
• Double-click the AVI animation file. The program associated with .avi
files in your system (for example, Windows Media® Player Media Player)
opens for the .avi file. If your .avi file is not yet running, start it now
from the application. The animation file runs.
• Use the MATLAB VideoReader function.
4-34
5
The Simulink 3D Animation product includes tools that you can use to edit
and create VRML virtual worlds. A basic understanding of these tools and
how to use them will help you to get started quickly.
VRML Editors
For a description of the tools to view virtual worlds, see “View Dynamic
System Simulations”.
As you create a virtual world, you can use different editors for different
phases of the process. Choose the editor that best meets your needs.
Many people prefer to create simple virtual worlds using MATLAB Editor or
other text editor. For more information, see “Text Editors” on page 5-3.
The primary way to create a virtual world is with a 3-D editing tool. These
tools allow you to create complex virtual worlds without a deep understanding
of the VRML language. These 3-D editing tools offer the power and versatility
for creating many types of practical and technical models. For example, you
can import 3-D objects from some CAD packages to make the authoring
process easier and more efficient.
The Simulink 3D Animation software includes the 3D World Editor, which you
can use on all supported platforms for Simulink 3D Animation. The 3D World
Editor is the default VRML editor for Simulink 3D Animation. For details
about specifying a VRML editor, see “Set the Default Editor” on page 2-14.
For Windows platforms, you can also use Ligos V-Realm Builder software
to create and edit VRML code. For information on using V-Realm Builder
software with the Simulink 3D Animation product, see “Ligos V-Realm
Builder” on page 5-6.
5-2
VRML Editors
Text Editors
A VRML file uses a standard text format that you can read with any text
editor. Reading the VRML code in a text editor is useful for debugging and
for directly changing VRML code, as well as for automated processing of the
code. If you use the correct VRML syntax, you can use the MATLAB Editor or
any common text editor to create virtual worlds.
Consider using a text editor to work on a VRML virtual world when you
want to:
5-3
5 Build Virtual Reality Worlds
General 3-D editing tools target specific types of work. For example, they can
target visual art, animation, games, or technical applications. They offer
different working environments depending on the application area for which
they are designed. Some of these general 3-D editing tools are very powerful,
expensive, and complex to learn, but others are relatively inexpensive and
might satisfy your specific needs.
The graphical user interfaces for many of the commercial general 3-D editors
use features typical of the native VRML editing tools. For example, in
addition to displaying 3-D scenes in various graphical ways, they also offer
hierarchical tree styles that provide an overview of the model structure and a
shortcut to node definitions.
• “3D World Editor” on page 6-2, which works on all platforms supported
for Simulink 3D Animation product
• The “Ligos V-Realm Builder” on page 5-6, which works on Windows
platforms only
3D World Editor
The 3D World Editor is installed as part of the Simulink 3D Animation
installation. It is the default VRML editor.
5-4
VRML Editors
• Tree structure pane — View the hierarchy for the virtual world that
you are editing. The 3D World Editor lists the nodes and their properties
according to their respective VRML node types. You can change the nesting
levels of certain nodes to modify the virtual world. In the tree viewer, give
the nodes unique names.
5-5
5 Build Virtual Reality Worlds
• Virtual world display pane — Observe the virtual world as you create
it. The 3D World Editor renders inlined objects (grouped objects). It uses
the same renderer as the Simulink 3D Animation viewer. Using the same
renderer for the editor and the viewer provides consistent navigation and
display throughout the development process.
• Object property edit pane — Change values for node items.
For details, see “Build and Connect a Virtual World” on page 5-7 and “3D
World Editor” on page 6-2.
The V-Realm Builder application is a flexible, graphically oriented tool for 3-D
editing. It provides similar functionality as the 3D World Editor.
The V-Realm Builder offers these features that the 3D World Editor does not:
• Provides dialog boxes for editing properties, which can be less streamlined
than the 3D World Editor object properties edit pane
• Does not always render virtual worlds the same way as the viewer
• Does not support rendering inlined objects
For more information about the V-Realm Editor, see “V-Realm Builder Help”
on page 2-13.
5-6
Build and Connect a Virtual World
Introduction
The example in this section shows you how to create a simple virtual world
using the 3D World Editor. The example does not show everything that
you can do with the editor, but it does show you how to perform some basic
tasks to get started.
This example assumes that you have set your default editor to be the 3D
World Editor. For details, see “Set the Default Viewer” on page 2-7.
This example describes the steps to build a slightly simplified version of the
virtual world that you see if you enter the following command in the MATLAB
command window:
edit(vrworld('vrdeform.wrl'))
5-7
5 Build Virtual Reality Worlds
The following table lists the positions and dimensions of the objects that you
create for this example.
5-8
Build and Connect a Virtual World
decreased by a factor from 1 to 0.4, and the y and z dimensions are expanded
so that the volume of the deformed sphere-ellipsoid remains constant.
Additional blocks in the model supply the correctly sized vectors to the
Simulink 3D Animation block. The simulation stops when the sphere is
deformed to 0.4 times its original size in the x direction.
Your first task is to open a Simulink model and add a Simulink 3D Animation
block to your model.
a At the top of the page that opens, select Open this Example.
5-9
5 Build Virtual Reality Worlds
vrtut3
vrlib
5 From the Library window, drag and drop the VR Sink block to the Simulink
diagram. You can then close the Library Browser window.
Your next task is to create a virtual world that you will associate with the VR
Sink block. See “Open a New Virtual World” on page 5-11.
5-10
Build and Connect a Virtual World
This procedure opens a new virtual world, in which you add nodes for
visualizing the signals of the model vrtut3. The connection between the
virtual world and the Simulink model requires that the model includes a
VR Sink block, as described in “Add a Simulink® 3D Animation™ Block”
on page 5-9.
1 Start the 3D World Editor with an empty virtual world. From the MATLAB
Toolstrip, in the Apps tab, in the Simulation Graphics and Reporting
section, click 3D World Editor.
2 You can save the virtual world at any point. Save the virtual world as
vrtut3.wrl in the same working folder where your vrtut3 file resides.
Do not close the 3D World Editor.
Your next two tasks create a virtual world to use with the vrtut3 model:
Create Boxes
Defining virtual world objects involves defining a hierarchy of nodes. This
example shows how to define Transform nodes under the ROOT node, with
each Transform node including a hierarchy of children, Shape, Appearance,
Geometry, and specific shape (in this case, a Box) nodes.
1 In the tree in the left pane, click ROOT (the topmost item).
5-11
5 Build Virtual Reality Worlds
3 This Transform node is for the B1 box. To name the Transform node:
5-12
Build and Connect a Virtual World
5-13
5 Build Virtual Reality Worlds
With all the nodes expanded, the 3D World Editor now displays a box in
the virtual world display pane.
5-14
Build and Connect a Virtual World
5-15
5 Build Virtual Reality Worlds
5-16
Build and Connect a Virtual World
a Under the ROOT node, add a Transform node (see step 2) and name it
B2 (see step 3).
b Copy the Shape node. Under the B1 Transform node, right-click the
Shape node in the B1 Transform node and select the Copy menu item.
c Paste the copied Shape node into the B2 Transform node. Under the B2
Transform node), right-click the children node and select the Paste
Node > Paste menu item.
With the B1 node collapsed and the B2 node expanded, the 3D World
Editor looks like the following graphic.
11 Move the box that you just created to the left by changing the translation
property of the B2(Transform) node. In the object properties edit pane,
set the first column to -3 and leave the second and third columns set to 0.
5-17
5 Build Virtual Reality Worlds
Create a Sphere
Your next task is to add a sphere between the two boxes. This section assumes
you have completed the tasks described in “Add VRML Nodes” on page 5-11.
1 To make it easier to focus the tree structure pane on the nodes that you
want to add, collapse the B1(Transform) and B2(Transform) nodes.
Add a Sphere library object using the following sequence of menu selections.
5-18
Build and Connect a Virtual World
From the list of Component Library folders, select the Shapes folder, and
then select the Sphere.wrl file.
With the S Transform node fully expanded and the other Transform nodes
collapsed, the 3D World Editor looks like the following graphic.
5 To make the sphere blue, under the Material node, select the
diffuseColor property. In the object properties edit pane, change the
first column value to 0.2, the second column to 1, and the third column to 1.
5-19
5 Build Virtual Reality Worlds
Your next task is to connect the model outputs to the Simulink 3D Animation
block in your Simulink model. See “Link to a Simulink Model” on page 5-20.
5-20
Build and Connect a Virtual World
This check box specifies that a viewer for the virtual world starts when you
run the model.
7 In the tree structure pane of the dialog box, select the B1 translation, B2
translation, and S scale check boxes as the nodes you want to connect to
your model signals. Click OK to close the dialog box.
5-21
5 Build Virtual Reality Worlds
In your default viewer, you see a 3-D animation of the scene. Using the
viewer controls, you can observe the action from various points.
When the width of the sphere is reduced to 0.4 of its original size, the
simulation stops running.
5-22
Build and Connect a Virtual World
This example shows you how to create and use a very simple virtual reality
model. Using the same method, you can create more complex models for
solving the particular problems that you face.
5-23
5 Build Virtual Reality Worlds
Section Overview
VRML data types are used by VRML nodes to define objects and types of data
that can appear in the VRML node fields and events.
This section explains these VRML field data types and VRML data class types.
For a detailed description of the VRML fields, refer to the VRML97 Standard.
Simulink 3D Animation
VRML Type Description Type
SFBool Boolean value true or false. logical
SFFloat 32–bit, floating-point value. single
SFInt32 32–bit, signed-integer int32
value.
SFTime Absolute or relative time double
value.
5-24
VRML Data Types
Simulink 3D Animation
VRML Type Description Type
SFVec2f Vector of two floating-point Single array (1-by-2)
values that you usually
use for 2-D coordinates.
For example, texture
coordinates.
SFVec3f Vector of three Single array (1-by-3)
floating-point values that
you usually use for 3-D
coordinates.
SFColor Vector of three Single array (1-by-3)
floating-point values
you use for RGB color
specification.
SFRotation Vector of four floating-point Single array (1-by-4)
values you use for
specifying rotation
coordinates (x, y, z) of
an axis plus rotation angle
around that axis.
SFImage Two-dimensional array uint8 array (n-by-m-by-3)
represented by a sequence
of floating-point numbers.
SFString String in UTF-8 encoding. char
Compatible with ASCII,
allowing you to use
Unicode® characters.
SFNode Container for a VRML vrnode
node.
MFFloat Array of SFFloat values. Single array (n-by-1)
MFInt32 Array of SFInt32 values. int32 array (n-by-1)
MFVec2f Array of SFVec2f values. Single array (n-by-2)
MFVec3f Array of SFvec3f values. Single array (n-by-3)
5-25
5 Build Virtual Reality Worlds
Simulink 3D Animation
VRML Type Description Type
MFColor Array of SFColor values. Single array (n-by-3)
MFRotation Array of SFRotation Single array (n-by-4)
values.
MFString Array of SFString values. char array (n-by-1)
MFNode Array of SFNode values. vrnode
The Simulink 3D Animation software can work with various MATLAB data
types, converting them if necessary:
• The inputs for the setfield function (and its dot notation form) and VR
Sink and VR Source blocks, accept all meaningful data types on input. Both
convert the data types into natural VRML types as necessary. The data
types include logicals, signed and unsigned integers, singles, and doubles.
• The getfield function (and its dot notation form) return their natural data
types according to the table above.
Property Description
DataTypeBool Specifies the boolean data type for vrnode/setfield
and vrnode/getfield. Valid values are 'logical' and
'char'. If set to 'logical', the VRML boolean data
type is returned as a logical value. If set to 'char', the
VRML boolean data type is returned 'on' or 'off'.
DataTypeInt32 Specifies the int32 data type for vrnode/setfield
and vrnode/getfield. Valid values are 'int32' and
'double'. If set to 'int32', the VRML int32 data type
is returned as int32. If set to 'double', the VRML
int32 data type is returned as 'double'.
DataTypeFloat Specifies the float data type for vrnode/setfield
and vrnode/getfield. Valid values are 'single' and
5-26
VRML Data Types
Property Description
eventIn
Usually, eventIn events correspond to a field in the node. Node fields are
not accessible from outside the node. The only way you can change them is
by having a corresponding eventIn.
Some nodes have eventIn events that do not correspond to any field of that
node, but provide additional functionality for it. For example, the Transform
node has an addChildren eventIn. When this event is received, the child
nodes that are passed are added to the list of children of a given transform.
You use this class type for fields that are exposed to other objects.
eventOut
This event is sent whenever the value of a corresponding node field that
allows sending events changes its value.
5-27
5 Build Virtual Reality Worlds
You use this class type for fields that have this functionality.
field
A field can be set to a particular value in the VRML file. Generally, the field
is private to the node and its value can be changed only if its node receives
a corresponding eventIn. It is important to understand that the field itself
cannot be changed on the fly by other nodes or via the external authoring
interface.
You use this class type for fields that are not exposed and do not have the
eventOut functionality.
exposedField
This is a powerful VRML data class that serves many purposes. You use this
class type for fields that have both eventIn and eventOut functionality. The
alternative name of the corresponding eventIn is always the field name with
a set_ prefix. The name of the eventOut is always the field name with a
_changed suffix.
The exposedField class is accessible to scripts, whereas the field class is not.
5-28
Simulink® 3D Animation™ Textures
5-29
5 Build Virtual Reality Worlds
Section Overview
When you work with models of dynamic systems, it is often necessary to
visualize them in a three-dimensional virtual reality environment. As most of
the 3D designs in companies are created using CAD tools, users need to be
able to convert these designs into forms that can be used with Simulink or
SimMechanics models and applications based on the MATLAB software.
This section describes how to adapt existing CAD designs for visualization
using the Simulink 3D Animation software.
This section assumes that the reader has a moderate knowledge of the
Simulink 3D Animation product. For VRML-specific information, such as the
description of VRML nodes and their fields, refer to the VRML97 standard.
You can use the 3D World Editor to import STL and Physical Modeling XML
files directly into a VRML scene. You can integrate content from those files
into a virtual world, converting the structure into VRML.
5-30
Using CAD Models with the Simulink® 3D Animation™ Product
1 In the 3D World Editor, select the Root node or an MFNode node (usually
the children node of a Transform or Group node).
2 From the Nodes > Import From menu item, select either STL File or
Physical Modeling XML File.
Tip Alternatively, you can right-click the Root node or an MFNode node and
use the Import From menu item. However, to insert the new node in the
middle of a node list, after the selected node (both at the main level or
inside a MFNode node, use the Nodes > Import From menu path.
Note To import a Physical Modeling XML file, the target folder must
be writable.
Results
Importing an STL file creates a Transform node containing a Shape node with
IndexedFaceSet geometry that represents the original STL shape. The new
Transform is created either at the main level of the scene hierarchy (at the
end of the file), or as a child of a selected grouping node.
Importing a Physical Modeling XML file creates an individual VRML file for
each STL file that is referenced from that XML file. The created VRML files
are stored in the folder where the edited VRML file is located.
In the edited VRML file, the newly created Transform contains hierarchical
structure Transforms that correspond to the structure of objects described in
the XML file. Individual VRML shape files in this structure are referenced
using Inline nodes.
5-31
5 Build Virtual Reality Worlds
Note When importing a Physical Modeling XML file into a new, unsaved
VRML model, children VRML files are created in the current working folder.
If you save the file into a different folder, move the referenced VRML files to
the new location.
When exporting CAD models into the VRML format, several options can be
set to customize the output. These include options specific to the export filters
or are general CAD file properties (consult your CAD system documentation
for specific details on how to set these properties). The most typical and useful
properties are the following:
If your CAD tool allows only VRML1 export, you can use the Ligos V-Realm
Builder application, a native VRML scene editor supplied with the Simulink
3D Animation software, to convert models from VRML1 to VRML97. Simply
5-32
Using CAD Models with the Simulink® 3D Animation™ Product
open a VRML1 file and resave it in V-Realm so that the file is automatically
saved in the VRML97 format.
Note All references to the general abbreviation, VRML, refer to the VRML97
standard.
5-33
5 Build Virtual Reality Worlds
VRML viewers are made to measure using dimensions that are comparable to
the dimensions of people, to achieve the immersion effect of virtual reality.
Viewers assume that the author prepared the scene so that it can be walked
through or examined by a virtual visitor to the scene (sometimes called the
Avatar), whose physical dimensions are used in calculations for purposes
like collision detection, near-object clipping, or terrain following. You can
5-34
Using CAD Models with the Simulink® 3D Animation™ Product
• +x points right
• +y points up
• +z points out of the screen
To avoid transforming object axes into the VRML system later on, export CAD
models using an identical coordinate system whenever possible. If your CAD
tool uses a different coordinate system, and it does not allow you to change it
for the exported objects, make sure to note the difference between the systems
so that you can implement axes transformations in your model later.
Also, make a note of the orientation of the parts in the coordinate system. For
instance, if a vehicle model is exported so that it points towards the +x axis on
a road in the virtual world, then the road should also point towards the +x
direction, and the model of vehicle dynamics should also use the x coordinate.
When the CAD tool allows you to animate parts and assemblies, reset their
positions to the initial state before the export.
Assembly Hierarchy
How assembly of parts are exported depends on the structure of the model,
which usually comes in two forms:
• All parts are independent from each other, or objects in the scene are
independent from each other at the same level of the scene hierarchy. The
exported VRML file has a flat structure, with all part coordinates defined
in global coordinates.
5-35
5 Build Virtual Reality Worlds
• Parts follow some kind of hierarchy defined in the CAD tool. The exported
VRML file will use this hierarchy via the VRML Transform-children
mechanism, to create a nested structure. In this case, part coordinates are
usually defined in the part’s parent local coordinate system.
For example, a robot can be exported with the following object hierarchy, in
which each part’s coordinates are defined in the parent’s local coordinate
system:
rotating support — arm — wrist — hand — tool
So when the rotating support moves, all other parts are usually designed
to move with it.
The hierarchy of the VRML file must correspond to the coordinates used in
the dynamic model of the assembly as follows:
5-36
Using CAD Models with the Simulink® 3D Animation™ Product
If the pendulum dynamics model uses global coordinates for all moving parts,
the VRML model has a flat structure as shown in the following figure.
5-37
5 Build Virtual Reality Worlds
If the pendulum dynamics model uses local coordinates for moving parts,
the corresponding VRML model has a nested structure, as shown in the
following figure.
5-38
Using CAD Models with the Simulink® 3D Animation™ Product
Some third-party tools allow you to export each part of the assembly into
separate VRML files. All parts are then referenced in one main file using the
VRML Inline mechanism. Referencing in this manner is the recommended
way to work with assemblies, as the main file is small in size and easy to
understand and modify.
5-39
5 Build Virtual Reality Worlds
Transform {
children [
Inline {
url ["robot_arm1.wrl"]
}
]
}
To set the initial location of the entire assembly in the virtual world, it is a
good practice to wrap all parts of the assembly with an additional Transform
node.
5-40
Using CAD Models with the Simulink® 3D Animation™ Product
These object names are used in the Simulink 3D Animation functions and in
the user interface such as the descriptions of inputs to the VR Sink block.
Therefore, it is good practice to give the parts descriptive names to help you
manage the orientation in the object hierarchy.
These modifications can be done using a text editor, V-Realm, or any other
VRML editor:
1 Add the WorldInfo node with a scene title (used as the virtual world
description in the Simulink 3D Animation software).
2 Add the NavigationInfo node defining the scene default navigation speed
and avatar size that ensures correct display of the object from near and
far distances.
5-41
5 Build Virtual Reality Worlds
5 Add lights to the scene in order to illuminate it. Although VRML viewers
always have a “headlight” available, it is good practice to define lights in
the scene so that it looks the same for every user, according to the scene
author’s preferences. The most useful type of VRML light to illuminate a
whole scene is the DirectionalLight node. It is often practical to use
a combination of several such lights to illuminate objects from several
directions.
6 Add scene surroundings. This step is not crucial for the visualization of
interactions between parts in a machine assembly, but is very important
for the visualization of simulations, such as those for aircraft and vehicle
dynamics, where the position of one object relative to the scene in which it
operates is important.
For example, if you want to visualize vehicle dynamics, you would place a
virtual car on a virtual road. Both objects need to be to scale (the length
units in the car and road models must match), and the car must be placed
in an appropriate position relative to the road. You achieve proper car
scaling, placement, and orientation in the scene by defining corresponding
fields of the main object’s Transform node mentioned in “Wrap Shape
Objects with Transforms” on page 5-40.
5-42
Using CAD Models with the Simulink® 3D Animation™ Product
rotations, etc.) to establish a live data connection between the model and
the virtual world.
1 From the vrlib library, insert a VR Sink block into your Simulink model.
2 Double-click the VR Sink block to open the block parameters dialog, where
you can define the virtual world. Enter the name of the scene’s VRML file
in Source file, or click Browse to select the file interactively. Click Apply
to load the selected VRML scene.
4 In VRML Tree in the right side of the dialog box, expand the main object’s
Transform branch, and, in the scene object hierarchy, locate all parts you
want to control from Simulink according to their names as given in “Add
DEF Names” on page 5-40. Each part is represented by named Transform
nodes, and you select the check box next to its rotation and position fields.
These selections tell the VR Sink block that you want to control the rotation
and position of these parts. You can also select other properties of virtual
world objects, such as color, but rotations and positions are the ones most
frequently controlled.
5-43
5 Build Virtual Reality Worlds
5 Click OK. For each selected field, the VR Sink block creates an input port.
Increase the VR Sink block size as appropriate to the number of input ports.
After the VR Sink block is associated with a virtual world, you can double-click
it to open the Simulink 3D Animation viewer. Block parameters are available
through the menu Simulation > Block Properties in the viewer.
The user has to match the coordinate system used by the Simulink model to
that of the virtual world. If the two systems are not identical, some kind
of axes transformation is necessary.
While object positions are usually available in the form required by VRML
(Cartesian coordinates), rotations usually have to be converted from some
other representation. In many cases, object rotations are defined using the
rotation matrix representation. For converting such rotations into the VRML
format, use the Rotation Matrix to VRML Rotation block found in the Utilities
sublibrary of vrlib.
The objects’ positions and rotations are treated differently depending on the
virtual world hierarchy:
5-44
Using CAD Models with the Simulink® 3D Animation™ Product
• When all parts in Simulink model follow hierarchical relations, and the
virtual world has a nested structure, use the following positions and
rotations.
Initial Conditions
A Simulink model’s initial conditions must correspond to the initial object’s
positions and rotations defined in the virtual world. Otherwise, the object
controlled from Simulink would “jump” from the position defined in the
VRML file to the position dictated by the Simulink software at the start of the
simulation. You can compensate for this offset either in the VRML file (by
defining an another level of nested Transform around the controlled object)
5-45
5 Build Virtual Reality Worlds
or in the Simulink model by adding the object’s initial position to the model
calculations before sending to the VR Sink block.
You should align the Simulink model’s initial conditions with the virtual
world’s object positions, while maintaining the correct position of the object
relative to the surrounding scene. To do so, you may need to adjust the
position of the object’s surroundings (e.g., move the road position so that the
car at position [0 0 0] stays on the road, with the wheels neither sinking
nor floating above the road surface).
To simplify the modeling in such cases, you can use the VR Placeholder and
VR Expander blocks of the Simulink 3D Animation library.
5-46
Using CAD Models with the Simulink® 3D Animation™ Product
SimMechanics Models
You can use the Simulink 3D Animation product to view the behavior of a
model created with the SimMechanics software. First, you build a model of a
machine in the Simulink interface using SimMechanics blocks. Then, create a
detailed picture of your machine in a virtual world, connect this world to the
SimMechanics body sensor outputs, and view the behavior of the bodies in
a VRML viewer.
• When the virtual world has a flat structure of independent objects, you can
obtain the positions and rotations of machine parts using Body Sensor
blocks connected to appropriate coordinate systems attached to the bodies,
with positions and rotations defined using global coordinates. In most
cases, it is appropriate to connect the sensor to a body coordinate system
with origin at [0 0 0] and with an initial rotation matrix defined as the
identity matrix, [1 0 0; 0 1 0, 0 0 1], in the global coordinate.
5-47
5 Build Virtual Reality Worlds
• When the virtual world has a hierarchical structure of nested objects, the
body positions and rotations can be obtained using Body Sensor blocks with
output set to use local body coordinates. In some special cases (e.g., when
two bodies are connected through a revolving joint), it is possible to get the
angle between the objects using a Joint Sensor block.
To export CATIA parts or products to the VRML format, in the CATIA dialog
box, select File > Save as and select VRML in the Save as type list.
When exporting products, the CATIA software creates one compound VRML
file that contains all the parts of the product.
5-48
Using CAD Models with the Simulink® 3D Animation™ Product
Occasionally, you might need to export each part of the assembly hierarchy
into a separate VRML file. You can do this in the CATIA environment as
follows:
2 Create the main model VRML file manually, with Inline references to
the part files.
You can also define a different coordinate system. To do this, create an axis
system within the current geometrical set. Doing so sets this new system
as a reference system that you can use to export the VRML virtual world.
Consider creating such an axis system so that it corresponds to the VRML
coordinate system. This makes all the coordinates and orientations of objects
compatible with other objects you combine into VRML virtual worlds.
Level of Detail
The level of detail of the exported VRML file (accuracy of
the tessellation mesh of objects) corresponds to the setting of
CATIA general visualization mesh. In the CATIA menu, select
5-49
5 Build Virtual Reality Worlds
Tools > Options > General > Display > Performances. In the resulting
dialog, select the 3D Accuracy options to control the visualization mesh detail.
You can achieve best results by using the proportional method of tessellation
(arcs are substituted by line segments based on their relative, not absolute,
accuracy). This method works for models regardless their dimensions.
For maximum accuracy of the exported VRML model, set the slider at the
rightmost position. If the resulting file is too complex to be handled effectively
with VRML rendering tools, experiment with this accuracy setting. You want
to find the setting that gives you the smallest possible VRML model, but
it must still be visually acceptable.
5-50
Using CAD Models with the Simulink® 3D Animation™ Product
Some of these additional nodes can be empty. Many CATIA model properties
do not have equivalents in the VRML language. Each part transform contains
a hierarchy of nested transforms, groups and shapes that correspond to the
part internal structure. Some of these elements have synthetic DEF names
(for example, _0161DC70). For the most part, you will only need to work with
the main transforms that represent each part.
5-51
5 Build Virtual Reality Worlds
The left tree view illustrates the overall structure of the model.
1 The CATIA software saves the general model information in the WorldInfo,
NavigationInfo, and Background nodes.
2 The software exports the default CATIA viewpoints (it does not export
user-defined viewpoints).
• CrankAssembly1
• CylinderSleeve1
5-52
Using CAD Models with the Simulink® 3D Animation™ Product
• PistonAssembly1
• CrankshaftAssembly1
The export does not preserve the CATProduct and CATPart names. You can
identify these objects in the VRML file in the tree view and in the text mode.
In the figure, the contents of the part transforms are collapsed so that only
the top-level objects are visible for clarity. After four transforms representing
CATParts, the export adds an empty Group node at the place where CATIA
Constraints are defined. You can delete such empty nodes from the VRML
model.
When you have VRML files created with the CATIA software, take into
account the following known features for further use with the Simulink 3D
Animation software:
5-53
5 Build Virtual Reality Worlds
5-54
Using CAD Models with the Simulink® 3D Animation™ Product
Do not adjust parts in the scene that you do not want to control from the
MATLAB environment.
• Scaling of VRML Objects
To convert CATProduct size from millimeters to meters (VRML default
units), the CATIA software wraps the transform corresponding to the
CATProduct with an additional transform. In this transform, the scale field
is defined. The preceding example illustrates this.
If you have a small object, or an object that you must place into an overall
virtual world, adjust this scale.
If you leave the VRML object scale in the default state, the local part
coordinates are still in millimeters. Remember this fact when controlling
these parts from the MATLAB or Simulink environment. If your MATLAB
or Simulink model units are meters, scale each part individually to achieve
5-55
5 Build Virtual Reality Worlds
correct results. You can do this by deleting the scale field from the top level
transform, and adding it to each individual part transform. For example,
Transform {
children [
DEF CylinderAssembly1 Transform {
children [
DEF CrankAssembly1 Transform {
scale 0.001 0.001 0.001
..
}
5-56
6
3D World Editor
In this section...
“Supported Platforms” on page 6-2
“Use with Other Editors” on page 6-2
“VRML Support” on page 6-2
“VRML Nodes, Library Objects, and Templates” on page 6-3
For an example that shows how to see the 3D World Editor to create a virtual
world, see “Build and Connect a Virtual World” on page 5-7.
Supported Platforms
The 3D World Editor works on all supported platforms
for the Simulink 3D Animation product. For details, see
http://www.mathworks.com/products/3d-animation/requirements.html.
Choose an editor that best meets your needs. For a description of the benefits
and limitations of different types of editors, see “VRML Editors” on page 5-2.
VRML Support
The primary file format for the 3D World Editor is VRML.
The 3D World Editor supports all VRML97 types and language elements,
except as noted in this section.
6-2
3D World Editor
PixelTexture Nodes
You cannot create or edit PixelTexture node image contents. Existing
PixelTexture node image contents are fully preserved
• Assemble VRML nodes to create a virtual world. You can add nodes that
specify many aspects of a virtual world, such as:
- Appearance (for example, font style, color, and material)
- Navigation information (for example, navigation mode and headlights)
- Geometry (for example, boxes, text, and elevation grids)
- Groups (for example, transforms)
- Interpolators
- Light
- Sensors
• Select objects from a set of supplied libraries or from custom libraries for:
- Components (for example, geometric objects, backgrounds, aircraft,
vehicles, landscapes, and architecture)
- Materials
- Textures
• Use a supplied template as a starting point for a virtual world
6-3
6 Using the 3D World Editor
A template file name displayed in the 3D World Editor always starts with
Template:.
Edit the file to adapt the template world for your application. To save your
changes, use the File > Save As option. You cannot overwrite an existing
template file.
You can create your own template files. Store them in a different folder than
that used for template files provided with Simulink 3D Animation.
In virtual worlds that you create, you can reference nodes, such as texture
files, that appear in the template files provided with Simulink 3D Animation.
6-4
Open the 3D World Editor
Note You can also use the V-Realm Editor. For more information, see
“V-Realm Builder Help” on page 2-13.
edit(vrworld(''))
• Regardless of Default Editor preference setting, you can use , use the
vredit command, without arguments.
• From within the 3D World Editor, select either File > Newor File > New
From Template. If there is already a file open in the 3D World Editor,
these options open a new instance of the editor. Multiple instances of the
6-5
6 Using the 3D World Editor
editor makes it easier to work on multiple virtual worlds at the same time
and to copy and paste from one virtual world to another.
• From the MATLAB Current Folder panel, right-click a VRML file and
from the context menu, select Edit
• If 3D World Editor is your default VRML editor, start it from the MATLAB
command line using the edit command. For example:
edit(vrworld('myVRMLfile.wrl'))
• Regardless of what your default VRML editor is, from the MATLAB
command line, use the vredit command with the name of the VRML file.
For example:
vredit('membrane.wrl')
• From within the 3D World Editor, select File > Open. If a file is already
open in the 3D World Editor, this option opens a new instance of the editor.
• For the default location, select Position. Then specify the pixel location
for the lower-left corner, the width, and the height (for example, [96 120
862 960]).
• To open the 3D World Editor in the same location where you exited it,
select Save position on exit.
You can specify whether the 3D World Editor starts up either with the default
virtual world display layout or with the layout as it was when you exited
it previously. The saved layout includes settings for the view, viewpoints,
navigation, and rendering. Simulink 3D Animation saves the layout on a per
VRML file basis for up to eight files.
6-6
Open the 3D World Editor
By default, the virtual world opens with the layout saved at exit.
To have the virtual world open using the default layout, clear the
Preferences > Simulink 3D Animation > Editor > Preserve Layout
per VRML File check box.
6-7
6 Using the 3D World Editor
• Tree structure pane — View the hierarchy for the virtual world that
you are editing.
• Virtual world display pane — Observe the virtual world as you create it.
• Object property edit pane — Change values for node items.
6-8
3D World Editor Panes
Use the tree structure pane interactively create graphical VRML elements
and to view of all the VRML structure elements present in the virtual world.
These structure elements are called nodes. The 3D World Editor lists the
nodes and their properties according to their respective VRML node types. In
the tree viewer, you give the nodes unique names.
Use the object properties edit pane to edit a selected property or add a
comment to a selected node or property.
eventIn
eventOut
exposedField
ROUTE
USE
6-9
6 Using the 3D World Editor
For a step-by-step tutorial about building a virtual world using the 3D World
Editor, see “Build and Connect a Virtual World” on page 5-7.
3 Under the ROOT node, add a Transform node in the virtual world for each
object that you want to share properties with other object in that same
Transform node.
children
Shape
appearance
Appearance
material
Material
texture
textureTransform
Geometry
Box
5 Use the object properties edit pane to change default property values
to create the effects that you want.
6-10
Create a Virtual World
7 In the virtual world display pane, use the context menu to specify
display characteristics, such as:
• View characteristics (for example, zooming and a navigation panel)
• Viewpoints
• Navigation characteristics (for example, methods (such as fly or walk)
and speed)
• Rendering techniques (for example, antialiasing, lighting, and
transparency)
6-11
6 Using the 3D World Editor
Basic Editing
In this section...
“Add Objects” on page 6-12
“Copy and Paste a Node” on page 6-14
“Edit Object Properties” on page 6-15
“Document a Virtual World Using Comments” on page 6-15
“Expand and Collapse Nodes” on page 6-16
“Wrap Nodes as Children of Another Node” on page 6-16
“Remove Nodes” on page 6-17
“Save and Export Virtual World Files” on page 6-18
“Edit VRML Scripts” on page 6-18
These topics describes how to use the 3D World Editor for common tasks
involved in creating a virtual world.
For information about opening a file in the editor, see “Open the 3D World
Editor” on page 6-5.
For a step-by-step tutorial, see “Build and Connect a Virtual World” on page
5-7.
Add Objects
Add virtual world objects by adding nodes in the tree structure pane. The
hierarchy of nodes controls the scope to which node properties apply.
Note Nodes must have unique names to work in the Simulink 3D Animation
product.
6-12
Basic Editing
Approach Procedure
Use the Nodes menu
1 In the tree structure pane, select the parent
node for the object that you want to add.
The node that you add gets added to different locations in the hierarchy,
depending on the node that you select to begin the process of adding a node.
6-13
6 Using the 3D World Editor
You can paste the copied node as either an explicit text copy (Paste) or as a
referenced copy (Paste As Reference).
1 In the tree structure pane, select the node that you want to copy.
6-14
Basic Editing
– Right-click the parent node and select Paste Node, and then select
Paste or Paste As Reference.
The tree structure pane shows the current property values, which reflect
your edits.
When you enter a numeric field value in the 3D World Editor, you can use
MATLAB expressions and MATLAB variables. For example, to convert
an angle from degrees to radians, enter a MATLAB expression such as
25*pi/180.
1 Navigate to the position in the scene where you want the viewpoint.
6-15
6 Using the 3D World Editor
Comments do not appear in the virtual world. They appear in the VRML file,
next to the given node or property, on lines that begin with #.
To expand or collapse all nodes in one step, select Tree > Expand All or
Tree > Collapse All.
Alternative approaches for expanding the subtree for a node that you select in
the tree structure pane are:
1 Select the nodes. You can use the Shift key to select contiguous nodes, and
the CTRL key to select discontiguous nodes.
2 Right-click the selected nodes and from the context menu, select Wrap By.
As an alternative, on the 3D World Editor menu bar, select Nodes > Wrap
By.
6-16
Basic Editing
3 From the list of nodes, select the node in which you want to wrap the
selected nodes.
Remove Nodes
To delete one or more nodes, select the nodes and use one of these methods:
From the Edit menu, you can also delete a specific child node or all the
children nodes of a selected parent node, without deleting the parent node.
To cut a node and save it to the clipboard, select the node and use one of
these techniques:
6-17
6 Using the 3D World Editor
If you use the Save option, the 3D World Editor renames the previous version
of the file by appending .bak after the .wrl extension.
If you use the Save As option, the 3D World Editor saves the file using the
new name that you specify. The file is saved in a form that is supported by
the Simulink 3D Animation Viewer and 3D World Editor (for example, the
saved file preserves links to the library texture files).
Use the File > Export menu item to export a fully VRML97–compliant file
for use:
For exported files, the 3D World Editor copies referenced inlined VRML
files and texture files to the <filename>_files folder. It modifies
the corresponding URLs for those files, so that they point to the
<filename>_files folder.
2 Select the appropriate kind of script, using the Node > Add > Common >
Script menu.
6-18
Basic Editing
To edit a url node, click the node and edit the URL code in the Object
property edit pane.
6-19
6 Using the 3D World Editor
3 In the Geometries Optimization Preview dialog box, use the slider or enter
a value in the Polygon reduction factor field to set the polygon reduction
factor. A value of 0 performs the maximum reduction, and a value of 1
performs no reduction.
4 Click OK.
6-20
Virtual World Navigation in 3D World Editor
Basic Navigation
Use the virtual world display pane to visualize the virtual world as you
create it.
To save these navigation settings in a virtual world file, you must define the
navigation properties in a NavigationInfo node.
To navigate in the virtual world, left-click in the pane. The cursor changes to
a white cross hair. Moving the cursor changes the orientation of the virtual
world.
6-21
6 Using the 3D World Editor
To hide the triad for a virtual world, or to change the location of the triad
in the virtual world display pane, right-click in the pane and select the
appropriate option from the View > Triad menu.
2 In the Preferences dialog box left pane, select Simulink 3D Animation >
3D World Editor > Triad.
View Panes
You can view the virtual world in one pane, two horizontal panes, two vertical
panes, or four panes.
For example, if you select View Pane > Grid View, the 3D World Editor
displays four view panes:
6-22
Virtual World Navigation in 3D World Editor
When the grid view panes are open, if you change the view pane option, the
3D World Editor displays the following view panes from the grid view.
To change the relative size of a panes, select one of the gray borders for a
view pane and drag the cursor.
To delete a pane when there are multiple panes, click the dot in the border
between view panes.
You can control the navigation of each pane independently. For example, you
can set viewpoints, manipulate the triad, and specify rendering techniques
independently for each pane. The navigation panel in the active pane is blue.
For example:
6-23
6 Using the 3D World Editor
Pivot Point
In Examine mode, you can use a pivot point for rotating a virtual world
around a point, using a mouse.
The default pivot point is 0,0,0 (world coordinates). To set a new pivot point,
hold CRTL and double-click the spot where you want the pivot point.
6-24
3D World Editor Library
These library objects supplement the default empty nodes available via the
Nodes menu or the Insert From context menu item. The library objects are
predefined with specific nodes and property settings to represent common
virtual world effects. For example, from the Component sublibrary, you can
choose from several vehicle objects, such as a van or pickup truck.
After you add a library object to a virtual world, you can modify its nodes
and properties.
1 Select the parent node under which you want to insert the library object.
The set of objects displayed depends on the parent node that you select. For
example, if you select a child node under a Transform node, you can choose
among Component sublibrary objects.
3 Follow the folder paths to find the object that you want to insert.
6-25
6 Using the 3D World Editor
You can also insert VRML objects from other locations, using the Insert
From > Other Location menu item.
• The first Transform node of the file that you select from another location is
inserted in place into the tree view of the virtual world that you are editing.
• If you want to insert a whole VRML file into the virtual world that you are
editing, use the Nodes > Inline VRML file menu option.
Before you add a custom library object from a location other than from the
3D World Editor object library, see “Guidelines for Using Custom Objects”
on page 6-26.
If you create VRML objects to use with the 3D World Editor, create your
own folder for storing the custom objects. Avoid using the 3D World Editor
library folder to ensure that you can:
• Edit the custom library object in the library folder; the 3D World Editor
library folders are generally read-only.
• Update to a future version of the Simulink 3D Animation product without
compatibility issues relating to mixing custom objects with the 3D World
Editor objects.
6-26
7
7-2
VRML Viewers
VRML Viewers
In this section...
“Host and Remote Viewing” on page 7-3
“Sound” on page 7-4
“Comparison of Viewers” on page 7-4
“Legacy Viewer” on page 7-5
After you create a virtual world in VRML (as described in “Build Virtual
Reality Worlds”), you can visualize that virtual world with a VRML viewer or
VRML-enabled Web browser.
To view a virtual world on a client computer, which does not need to have
Simulink 3D Animation installed, you can use the Web Viewer, Orbisnap, or
7-3
7 Viewing Virtual Worlds
Blaxxun Contact. For remote viewing, MathWorks recommends that you use
the Web Viewer or Orbisnap.
Sound
The Blaxxun Contact VRML plug-in is required for sound. Other Web viewers
may allow for sound playback, but are not officially supported. To add sound
to a virtual world, you can include the MATLAB sound command in your
model or in a MATLAB script.
Comparison of Viewers
Feature Simulink 3D Simulink 3D Orbisnap Blaxxun
Animation AnimationWeb Contact
Viewer Viewer
Platforms Windows, Windows, Windows, Windows
Macintosh, and Macintosh, and Macintosh, and
Linux Linux Linux
Note The
Blaxxun Contact
plug-in does not
work reliably
on Microsoft
Windows 7
platforms.
7-4
VRML Viewers
Legacy Viewer
The Simulink 3D Animation product includes a legacy viewer, which is still
supported for compatibility. In general, use the Simulink 3D Animation
Viewer or other supported viewers instead of the legacy viewer. For
information about the legacy viewer, see “Legacy Simulink® 3D Animation™
Viewer” on page 7-69.
7-5
7 Viewing Virtual Worlds
This section uses the vrpend, vrplanets, and vrtut1 examples to illustrate
the viewer features:
7-6
Simulink® 3D Animation™ Viewer
vrpend
The Simulink 3D Animation viewer displays the virtual scene. The top of
the viewer contains a menu bar and toolbar. By default, the Simulink
3D Animation viewer displays the virtual scene with a navigation panel
at the bottom. These three areas of the viewer give you alternate ways to
work with the virtual scene.
7-7
7 Viewing Virtual Worlds
Note The Simulink 3D Animation viewer settings are saved when you
save your model file.
7-8
Simulink® 3D Animation™ Viewer
• Treat the viewer window like a MATLAB figure. This ability enables you
to perform MATLAB figure actions such as dock the viewer window in
the MATLAB window. For example:
7-9
7 Viewing Virtual Worlds
1 In the Simulink Editor, double-click the VR Sink block to open the Simulink
3D Animation Viewer.
4 Click OK.
7-10
Simulate with the Simulink® 3D Animation™ Viewer
• From the menu bar, select the Simulation menu Start or Stop option.
• From the toolbar, click Start/pause/continue simulation or Stop
simulation.
• From the keyboard, press Ctrl+T to toggle between starting or stopping
the simulation.
Note The Ctrl+T operation is available only if you started the viewer from
a Simulink model. If you start the viewer through the MATLAB interface,
no Simulink model is associated with the viewer. You cannot start and stop
the simulation in this case.
7-11
7 Viewing Virtual Worlds
You can turn the antialiasing of the scene on or off. Antialiasing applies to
the textures of a world. Antialiasing is a technique that attempts to smooth
the appearance of jagged lines. These jagged lines are the result of a printer
or monitor’s not having enough resolution to represent a line smoothly. When
Antialiasing is on, the jagged lines are surrounded by shades of gray or color.
Therefore, the lines appear smoother rather than jagged.
The following figure depicts the vrplanets example View on Earth viewpoint
with Antialiasing on. To better display the effects of antialiasing, turn
Headlight on. You can turn antialiasing on or off to observe the differences.
7-12
Specify Rendering Techniques
You can turn the camera headlight and the lighting of the scene on or off.
When Headlight is off, the camera does not emit light. Consequently, the
scene can appear dark. For example, the following figure depicts the vrpend
example with Headlight on.
7-13
7 Viewing Virtual Worlds
Note It is helpful to define enough lighting within the virtual scene so that it
is lit regardless of the Headlight setting.
When Lighting is off, the virtual world appears as if lit in all directions. The
Simulink 3D Animation viewer does not compute and render all the lighting
effects at the surfaces of the objects. Shadows disappear and the scene loses
some of its 3-D quality. The following is the vrpend example with Lighting
off.
7-14
Specify Rendering Techniques
7-15
7 Viewing Virtual Worlds
7-16
Specify Rendering Techniques
If Textures is on, objects have texture in the virtual scene. The following is
the vrplanets example with Textures on.
7-17
7 Viewing Virtual Worlds
If Textures is off, objects do not have texture in the virtual scene. The
following is the vrplanets example with Textures off.
7-18
Specify Rendering Techniques
You can specify the maximum size of a texture used in rendering the vrfigure
object. This option gives you a list of texture sizes to choose from. See the
vrfigure MaxTextureSize property for further details.
7-19
7 Viewing Virtual Worlds
Basic Navigation
You can navigate around a virtual scene using the menu bar, toolbar,
navigation panel, mouse, and keyboard. The vrbounce example illustrates
the several key features of the viewer.
Navigation Panel — The center navigation wheel and two curved buttons
on either side allow you to move about in the scene. Experiment by moving
backward and forward and side to side until you become comfortable with
the controls.
Navigation view — You can change the camera position. From the menu
bar, select the Navigation menu Straighten Up option. Alternatively, from
the toolbar, you can click the Straighten Up control, or on the keyboard, you
can press F9. This option resets the camera so that it points straight ahead.
7-20
Navigate Using the Simulink® 3D Animation™ Viewer
• From the menu bar, select the Navigation menu Method option.
This option provides three choices: Walk, Examine, or Fly. See “Mouse
Navigation” on page 7-26.
• From the toolbar, select the drop-down list that displays the navigation
options Walk, Examine, and Fly.
7-21
7 Viewing Virtual Worlds
Navigation zones — You can view the navigation zones for a scene through
the menu bar or keyboard.
From the menu bar, select the View menu Navigation Zones option. The
virtual scene changes as the navigation zones are toggled on and appear in
the virtual scene. Alternatively, on the keyboard, press the F7 key.
The vrbounce example with Method set to Fly has three navigation zones.
Navigation Panel
The Simulink 3D Animation viewer navigation panel has navigation controls
for some of the more commonly used navigation operations available from
the menu bar.
7-22
Navigate Using the Simulink® 3D Animation™ Viewer
Navigation
wheel
Full-screen Slide Slide
mode left right Wireframe
Headlight
Minimize
Help
panel
Previous Next
Walk /Examine /Fly
Default
viewpoint
If you have multiple viewers open, the navigation panel in the active viewer
is blue.
• Click the red x control on the left side of the navigation panel.
• Select View > Navigation Panel > Minimized
The minimized navigation panel appears as an icon in the lower right corner
of the viewer.
7-23
7 Viewing Virtual Worlds
To display the navigation panel again, click the Show Panel left arrow on
the minimized navigation panel icon.
The minimized navigation panel is blue for the active viewer and gray for
the inactive viewers.
7-24
Navigate Using the Simulink® 3D Animation™ Viewer
7-25
7 Viewing Virtual Worlds
Mouse Navigation
The following table summarizes the behavior associated with the movement
modes and navigation zones when you use your mouse to navigate through a
virtual world. Turn the navigation zones on and experiment by clicking and
dragging your mouse in the different zones of a virtual world.
Movement
Mode Zone and Description
Walk Outer — Click and drag the mouse up, down, left, or
right to slide the camera in any of these directions in
a single plane.
Inner — Click and drag the mouse up and down to
move forward and backward. Drag the mouse left and
right to turn left or right.
Examine Outer — Click and drag the mouse up and down to
move forward and backward. Drag the mouse left and
right to slide left or right.
Inner — Click and drag the mouse to rotate the
viewpoint around the origin of the scene.
Fly Outer — Click and drag the mouse to tilt the view
either left or right.
7-26
Navigate Using the Simulink® 3D Animation™ Viewer
Movement
Mode Zone and Description
If your virtual world contains sensors, these sensors take precedence over
mouse navigation at the sensor’s location. For more information, see “Sensors
Effect on Navigation” on page 7-28.
Control Menu
Access the control menu by right-clicking in the viewer window. You can use
the control menu to specify a predefined viewpoint or change the appearance
of the control panel. You can also control the navigation method, speed,
and rendering of the virtual world. For more information about navigation
methods, see “Navigate Using the Simulink® 3D Animation™ Viewer” on
page 7-20. For more information about rendering, see “Specify Rendering
Techniques” on page 7-12.
7-27
7 Viewing Virtual Worlds
Note Your navigation speed controls the distance that you move with each
keystroke. It does not affect rendering speed.
Consider setting a higher speed for large scenes and a slower speed for more
controlled navigation in smaller scenes.
To change the default navigation speed for a virtual scene, modify the speed
field of the NavigationInfo node in the scene VRML file. For further details,
see the VRML97 standard.
vrpend
The Inverted Pendulum example starts, and the viewer displays the
following scene.
7-28
Navigate Using the Simulink® 3D Animation™ Viewer
2 In the Simulink Editor window, from the Simulation menu, choose Run.
3 Click inside and outside the sensor area of the viewer window. The sensor
takes precedence over navigation with the left mouse button. The shape of
your pointer changes when it is located over the sensor area.
If the sensor covers the entire navigable area, mouse navigation is effectively
disabled. In this case, use the control panel or the keyboard to move about
the scene. For a three-button mouse or a mouse with a clickable wheel, you
can always use the middle button or the wheel to move about the scene. The
middle mouse button and wheel do not trigger sensors within the virtual
world.
7-29
7 Viewing Virtual Worlds
To display a triad in the viewer, or to change the location of the triad, use one
of the following approaches:
• Right-click in the virtual world. Select the appropriate option from the
View > Triad menu.
• In the viewer menu bar, select the appropriate option from the View >
Triad menu.
7-30
Navigate Using the Simulink® 3D Animation™ Viewer
2 In the Preferences dialog box, select Simulink 3D Animation > Figure >
Triad.
Pivot Point
In Examine mode, you can use a pivot point for rotating a virtual world
around a point, using a mouse.
To set the pivot point in a virtual world, hold CRTL and double-click the
spot where you want the pivot point.
7-31
7 Viewing Virtual Worlds
Viewpoints
Visitors to your virtual world are navigating in an environment you create
for them, using navigation methods allowed by the viewer (Walk, Examine,
Fly). Besides this, it is useful to set up in the world several locations, places
of interest you want to point the visitors to. These locations are called
viewpoints. Users can browse through them, carrying out a guided tour you
prepared for them, gaining the visual information you consider important in
your model.
When entering a world, user is placed at the first Viewpoint node encountered
in the file. It is especially important to define this viewpoint carefully as the
most interesting entry point - default viewpoint.
Each virtual world has as many viewpoints as you define for it. You can
define viewpoints in the virtual world through your chosen editor or through
the Simulink 3D Animation viewer.
Defined viewpoints can be static - created usually at the top level of the
virtual world object hierarchy or as children of static objects (Transforms),
or dynamic - created as children of moving objects (objects driven from
MATLAB/Simulink) or linked to them using the VRML ROUTE mechanism.
This allows you to create interesting effects like view at the driving range
from the driver’s seat etc. You or visitors to a virtual world navigate through
the virtual world environment using the Simulink 3D Animation viewer
navigation methods Walk, Examine, Fly, and None. In addition to these
navigation methods, a virtual world creator can set up points of interest,
known as viewpoints, in the virtual world. You can use viewpoints to guide
visitors through the virtual world and to emphasize important points.
When a visitor first enters a virtual world, he or she is defaulted to the default
viewpoint. This is the first Viewpoint node in the virtual world file. Define
the virtual world default viewpoint carefully; it should be the most interesting
entry point to the virtual world.
Each virtual world has as many viewpoints as you define for it. You can
define viewpoints in the virtual world through your chosen editor or through
the Simulink 3D Animation viewer.
7-32
Viewpoints
• Static -- Created typically at the top level of the virtual world object
hierarchy. You can also create these viewpoints as children of static objects
(Transforms).
• Dynamic -- Created as children of moving objects (objects controlled from
MATLAB or Simulink) or linked to moving objects with the VRML ROUTE
mechanism. Dynamic viewpoints allow you to create interesting views such
as from the driver’s seat at a racing course.
7-33
7 Viewing Virtual Worlds
Reset Viewpoints
You can reset your position in a scene to initial default or current viewpoint
position through the menu bar, toolbar, navigation panel, or keyboard
shortcut keys.
• From the menu bar, use the Viewpoints menu Return to viewpoint
option to return to the initial position of the current viewpoint.
Alternatively, from the toolbar, select Return to viewpoint button to
return to the initial position of the current viewpoint.
• From the navigation panel, click the Go to default viewpoint control to
return to the default viewpoint of the virtual world. Alternatively, from the
menu bar, use the Viewpoints menu Go to Default Viewpoint option to
return to the default viewpoint of the virtual world.
• From the keyboard:
- Press the Esc key to return to the default viewpoint of the virtual world.
- Press the Home key to return to the initial position of the current
viewpoint.
Define Viewpoints
You can add new viewpoints to the virtual world through the menu bar or
toolbar. You can start the simulation before creating viewpoints. This topic
assumes that the model is not currently running.
vrplanets
7-34
Define and Reset Viewpoints
In the Simulink 3D Animation viewer, the default viewpoint for this model
is View from top.
6 In the Name box, enter a unique and descriptive name for the viewpoint.
8 Select the Jump to new viewpoint immediately check box to make the
new viewpoint become the current viewpoint for the viewer. If you do not
7-35
7 Viewing Virtual Worlds
select this check box, you still create a new viewpoint, but you remain
bound to the current viewpoint, not to the new viewpoint.
9 Click OK.
10 From the File menu, click Save As to save the file with the new viewpoint.
If you do not save the file, the new viewpoint will be lost during simulation.
11 From the Simulation menu, click Start. Observe the motion of the planets
from the new, static viewpoint.
13 Repeat steps 2 to 6.
Note If the current viewpoint is at the top hierarchy level in the virtual
world (one of the children of the root), the Placement field is grayed out.
In this case, it is only meaningful to create the new viewpoint as a static
one at the same top hierarchy level.
15 Select the Jump to new viewpoint immediately check box to make the
new viewpoint become the current viewpoint for the viewer. If you do not
select this check box, you still create a new viewpoint, but you remain
bound to the current viewpoint, not to the new viewpoint.
16 Click OK.
17 From the File menu, choose Save As to save the file with the new
viewpoint. If you do not save the file, the new viewpoint will be lost during
simulation.
7-36
Define and Reset Viewpoints
18 From the Simulation menu, choose Start. Observe that the relative
position between the new viewpoint and Earth remains the same. The new
viewpoint moves together with its parent object Earth transform.
7-37
7 Viewing Virtual Worlds
• From the menu bar, use the Viewpoints menu to move between
viewpoints. Use the Previous Viewpoint and Next Viewpoint options
to sequentially move up and down the list of existing viewpoints. To
move focus to a particular viewpoint, choose a viewpoint from the list of
viewpoints.
• From the toolbar, use the drop-down list of viewpoints to select a particular
viewpoint.
• From the navigation panel, use the Previous Viewpoint and Next
Viewpoint controls to sequentially move up and down the list of existing
viewpoints.
• From the keyboard, press Page Up and Page Down.
To reset a camera to the initial position of the current viewpoint, use one
of the methods listed in “Reset Viewpoints” on page 7-34. Resetting the
viewpoint is useful when you have been moving about the scene and need to
reorient yourself.
vrplanets
7-38
Navigate Through Viewpoints
3 Select the drop-down list on the leftmost side of the toolbar to see the list of
existing viewpoints from the toolbar. The status bar at the bottom of the
viewer displays the current viewpoint.
7-39
7 Viewing Virtual Worlds
When you add new viewpoints to the world, these lists are updated to reflect
the new viewpoints.
The current viewpoint is also displayed in the left pane of the status bar.
You manage and navigate through viewpoints from the menu bar, toolbar,
navigation panel, and keyboard. In particular, you can
7-40
Navigate Through Viewpoints
7-41
7 Viewing Virtual Worlds
Animation Recording
The Simulink 3D Animation software enables you to record animations of
virtual scenes that are controlled by the Simulink or MATLAB product. You
can record simulations using the Simulink 3D Animation Viewer. You can
then play back these animations offline, in other words, independent of the
MATLAB, Simulink, or Simulink 3D Animation products. You might want
to generate such files for presentations, to distribute simulation results, or
to generate archives.
7-42
Record Offline Animations with the Simulink® 3D Animation™ Viewer
Recording Formats
You can save the virtual world offline animation data in the following formats:
Note If you distribute VRML animation files, be sure to also distribute all
the inlined object and texture files referenced in the original VRML world
file.
Note While recording 2-D .avi animation data, always ensure that the
Simulink 3D Animation Viewer is the topmost window and fully visible.
Graphics acceleration limitations might prevent the proper recording of
2-D animation otherwise.
7-43
7 Viewing Virtual Worlds
File Names
By default, the Simulink 3D Animation Viewer records simulations or
captures virtual scene frames in a file named with the following format:
%f_anim_%n.<extension>
This format creates a unique file name each time you capture a frame or
record the animation. %f and %n are tokens. %f is replaced with the name
of the virtual world associated with the model and %n is a number that
increments each time you record a simulation for the same virtual world.
If you do not change the default file name, for example, if the name of the
virtual world file is vrplanets and you record a simulation for the first time,
the animation file is
vrplanets_anim_1.wrl
If you record the simulation a second time, the animation file name is
vrplanets_anim_2.wrl. In the case of frame captures, capturing another
frame of the scene increments the number.
• From the menu bar, choose the Simulation menu, Run option to start
recording the animation (select Stop to stop the recording).
• From the toolbar, click the Start/stop recording button to start or stop
recording the animation (select Stop to stop the recording). Alternatively,
you can use the Recording menu Start Recording and Stop Recording
options. From the keyboard, press Ctrl+R to toggle between starting or
stopping the animation recording.
7-44
Record Offline Animations with the Simulink® 3D Animation™ Viewer
• Stop the simulation or let the model simulate until the defined simulation
stop time.
Note If you stop the simulation while recording is enabled, the viewer
also stops recording the animation.
1 In the MATLAB Command Window, type the model name. For example:
vrplanets
3 Find the Recording section of the dialog. This is located under the Frame
Capture dialog.
The File text field becomes active and the default file name,
%f_anim_%n.wrl, appears in the text field.
7-45
7 Viewing Virtual Worlds
To save files to other file names, see “File Name Tokens” on page 4-16.
5 Click OK.
After you define an animation file, you can manually record simulations. See
“Start and Stop Animation Recording” on page 7-44. If you want to record
simulations on a schedule, see “Schedule Files for Recording” on page 7-49.
1 In the MATLAB Command Window, type the model name. For example:
vrplanets
7-46
Record Offline Animations with the Simulink® 3D Animation™ Viewer
3 Find the Recording section of the dialog box. This is located under the
Frame Capture dialog box.
The File text field and Compression selection area become active, and the
default file name, %f_anim_%n.avi, appears in the text field.
To save files to other file names, see “File Name Tokens” on page 4-16.
Set FPS to auto if you want to use the sample time of the associated VR
Sink block to make the file playback correspond to the model simulation
time.
7-47
7 Viewing Virtual Worlds
6 From the Compression list, select a compression method for the .avi
file. Because .avi files can become large, you might want to compress
the .avi file.
Choose from
• Autoselect — Allows the Simulink 3D Animation software to select the
most appropriate compression codec. This option allows you to specify
a quality setting that is a number between 0 and 100. Higher quality
numbers result in higher video quality and larger file sizes. Lower
quality numbers result in lower video quality and smaller file sizes.
• Lossless — Forces the Simulink 3D Animation software to compress
the animation file without loss of data. (Typically, the compression of
files sacrifices some data.)
• User Defined — Enables you to specify a particular compression codec.
This option allows you to specify a quality setting that is a number
between 0 and 100. Higher quality numbers result in higher video
quality and larger file sizes. Lower quality numbers result in lower video
quality and smaller file sizes. You need to specify an identification string
of a codec that your system supports.
• None — Prevents any compression for the animation file.
7-48
Record Offline Animations with the Simulink® 3D Animation™ Viewer
7 Disable the navigation panel. The navigation panel appears at the bottom
of the virtual scene view. You might want to turn off this panel for a cleaner
view of the virtual scene. Choose View > Navigation Panel > None.
You can re-enable the Navigation Panel (for example, choose View >
Navigation Panel > Halfbar) after you are finished recording the .avi
file.
8 Click OK.
After you define an animation file, you can record animations. See “Start and
Stop Animation Recording” on page 7-44. If you want to record animations on
a schedule, see “Schedule Files for Recording” on page 7-49.
1 In the MATLAB Command Window, type the model name. For example:
vrplanets
7-49
7 Viewing Virtual Worlds
The Start time and Stop time text fields are enabled.
4 Enter in Start time and Stop time the start and stop times during which
you want to record the animation. For example, enter 0 as the start time
and 100 as the stop time.
7-50
Record Offline Animations with the Simulink® 3D Animation™ Viewer
Ensure that the recording start time value is not earlier than the start
time of the Simulink model; the recording operation cannot start in this
instance. If the stop time exceeds the stop time of the Simulink model, or
if it is an out of bounds value such as a negative number, the recording
operation stops when the simulation stops.
Note You can also set the stop time before the start time. This allows
for a scenario where the simulation starts first and you manually start
recording. The recording then automatically stops at stop time and
automatically restarts at start time.
5 Click OK.
After you define the schedule, you can record simulations. See “Start and Stop
Animation Recording” on page 7-44.
Note You can override the recording schedule by starting or stopping the
recording interactively.
7-51
7 Viewing Virtual Worlds
w=vrview('vrplanets_anim_1.wrl');
set(w,'TimeSource','freerun');
set(w,'TimeSource','external');
To close the viewer and delete the world, get the handle of the vrfigure
object and close it, as follows:
f=get(w,'Figures')
close(f);
delete(w);
Or, to close all vrfigure objects and delete the world, type
vrclose
delete(w);
7-52
Configure Frame Capture Parameters
vrplanets
3 Find the Frame Capture section of the dialog. This is located at the top
of the dialog.
The file name %f_anim_%n.tif appears in the first text field, File.
5 In the File Format list, tif or png specify the graphic file format for the
captured frame. The default is tif. For this procedure, leave this format
setting at tif.
6 You can disable the navigation panel. The navigation panel appears at the
bottom of the virtual scene view. You might want to turn off this panel for
a cleaner view of the virtual scene. Choose View > Navigation Panel
> None.
You can re-enable the Navigation Panel (for example, choose View >
Navigation Panel > Halfbar) after you finish recording the .tif file.
7 Click OK.
7-53
7 Viewing Virtual Worlds
With this configuration, each subsequent capture of a scene in the same world
increments the file name number (%n) and saves it in a tif file.
7-54
Capture Frames
Capture Frames
The Simulink 3D Animation product allows you to save a frame snapshot
(capture) of the current Simulink 3D Animation viewer scene. You can save
this frame as either a TIF or PNG format file. You can later view this scene
offline (in other words, without the Simulink 3D Animation viewer). You can
treat this frame capture file like any other TIF or PNG file, such as print it,
include it in other files, and so forth.
You can capture frames of the virtual world from the Simulink 3D Animation
viewer through the menu bar, toolbar, or keyboard. This section assumes that
you have specified frame capture file formats.
• From the menu bar, choose Recording > Capture Frame to capture
a frame.
• From the toolbar, click the Capture a frame screenshot button to
capture a frame.
• From the keyboard, press Ctrl+I to capture a frame.
You can view the frame capture files using any tool that reads tif or png files,
including the MATLAB imread function. For example,
image(imread('vrplanets_anim_1.tif'))
7-55
7 Viewing Virtual Worlds
Note Because the Web Viewer accesses an HTML version of the virtual
world, you cannot use it to modify the virtual world (for example, to create
new viewpoints).
7-56
Open the Web Viewer
If the Simulink 3D Animation Viewer is the default viewer, you can open
that viewer from the Simulink Editor by double-clicking the VR Sink block.
2 On the computer from which you want to open the Web Viewer, open
an HTML5-enabled browser (supporting WebGL and WebSocket). The
browser must have Javascript enabled.
3 Connect to the local host HTTP port. To open the Web Viewer on:
7-57
7 Viewing Virtual Worlds
Note If you need to change the HTTP port (for example, if a firewall blocks
a port), set a different port number and restart MATLAB. To change the
HTTP port, in the MATLAB Home tab, in the Environment section, use
the Preferences > Simulink 3D Animation > HTTP Port> preference.
4 In the Web Viewer, from the list of open virtual worlds, select the one that
you want to view.
7-58
Navigate Using the Web Viewer
The supported navigation features depend on what Web browser you use. For
example, at the time R2013b was released, Firefox® was the only supported
Web browser that supports context menu options that are specific to Simulink
3D Animation, such as viewpoints options.
7-59
7 Viewing Virtual Worlds
Keyboard Shortcuts
Navigation Function Keyboard Shortcut
Straighten up and make the camera U
stand on the horizontal plane of its local
coordinates.
Toggle the headlight on and off. H
Toggle the navigation zones on and off. Z
Go to default viewpoint. Esc
Return to current viewpoint. R
Go to previous viewpoint. Page Up
Go to next viewpoint. Page Down
7-60
Navigate Using the Web Viewer
To access the preferences, from the MATLAB Toolstrip, in the Home tab, in
the Environment section, select Preferences > Simulink 3D Animation.
7-61
7 Viewing Virtual Worlds
Note Support for the Blaxxun Contact viewer will be removed in a future
release. Consider using one of the other VRML viewers described in “VRML
Viewers” on page 7-3.
When you open a VRML file with a Web browser, the Blaxxun Contact VRML
plug-in is used to display a virtual scene. A control panel is located at the
bottom of the scene.
7-62
Configure Blaxxun Contact®
You might want to test the various combinations possible on your system to
find an optimal configuration for the best performance in 3-D visualization.
In Direct3D® configuration, you can select the speed and quality on the fly
from the top level of the menu. You can, depending on the system capabilities,
select one of the options on the menu. For example, you can select High
Speed, High Quality, Hardware Acceleration, and MMX Speed.
In the OpenGL configuration, you can set similar rendering properties. From
the floating menu, choose Settings, and then choose Preferences.
7-63
7 Viewing Virtual Worlds
Control Menu
You use the control menu to review or select viewer settings and navigation
methods. To access the control menu, use the following procedure:
1 On the Control Panel, click the question mark, or place your mouse pointer
anywhere in the browser window, and then right-click.
2 From the menu, you can make changes to the navigational mode, graphic
quality, and graphic speed.
Depending on the complexity of the virtual world and the required speed and
rendering quality, you can choose the settings that best meet your needs.
7-64
Navigate Using Blaxxun Contact®
1 Place your mouse pointer over a virtual world, then right-click. A menu
appears.
A letter in the center of the dial indicates the current movement mode. For
example, in the preceding illustration, the large E stands for Examine mode.
Initially, you should use Examine mode, which is for examining objects
from various angles. You will find that the functions of the left/right button
controls in Examine mode are the easiest for beginners to master.
Movement Modes
The following table lists the movement modes.
7-65
7 Viewing Virtual Worlds
Movement
Mode Description
Walk Drag the mouse toward the top or the bottom of the
screen to move forward or backward, and drag toward
the left or right to turn left or right.
Slide Drag the mouse to move up, down, left, or right within
a plane that is perpendicular to your view.
Rotate Press the left mouse button to select a rotation point
within the scene. Then drag the mouse toward the top
or bottom to move forward or back, or drag the mouse
left or right to rotate around the fixed point.
Examine Press the left mouse button to select a rotation point
within the scene. Then drag the mouse up, down, left,
or right to rotate the object.
Fly Press the left mouse button to start flying. Drag the
mouse toward the top or bottom to rise or sink, and
drag left or right.
Pan Drag the mouse toward the top or bottom of the scene
to loop up and down, and drag left or right to turn left
or right.
Jump Place your mouse pointer over an object, then left-click.
Your view moves to that point.
You use the other two triangular buttons to browse forward and backward
through author-defined viewpoints of the virtual world. If the author does not
define other viewpoints, these buttons are inactive. The keyboard shortcuts
for the triangular buttons are the Page Up and Page Down keys.
7-66
Use Stereoscopic Vision
If you have installed the appropriate stereo driver, Blaxxun Contact supports
full screen stereo mode under Windows with most NVIDIA graphic cards. For
details, refer to the card manufacturer documentation.
If you want to tune the full screen mode resolution or color depth.
1 In the Blaxxun Contact window, place your mouse pointer over a virtual
world, then right-click.
A menu appears.
3 Choose Preferences.
Note that your system configuration can switch to stereoscopic full screen
mode only when using one of the Direct3D or OpenGL rendering engines. If
you are unable to switch to full screen stereo mode, try to install Blaxxun
Contact using another rendering engine. Typically, graphic card stereo drivers
provide testing applications to confirm the functionality of stereoscopic modes.
7-67
7 Viewing Virtual Worlds
The server is started when the software is loaded into the MATLAB interface.
This happens whenever you use a Simulink 3D Animation block in a Simulink
block diagram, or whenever you open a vrworld object in the MATLAB
interface. The HTTP server is shut down when you close all Simulink models
that contain Simulink 3D Animation blocks, or use the vrclear command.
When the HTTP server is running, your browser can see a list of available
virtual worlds at the following address, where 8123 is the default port number:
http://localhost:8123
Remote users can connect to the following address, where 8123 is the default
port number:
http://your_machine:8123
You can set the port number of the server in the Simulink 3D Animation
Preferences dialog box from the Simulink interface, or use vrsetpref in the
MATLAB Command Window.
Depending on the status of served vrworld objects, the list of available virtual
worlds can be empty.
7-68
Legacy Simulink® 3D Animation™ Viewer
Introduction
The Simulink 3D Animation viewer has a legacy viewer. This legacy viewer
is the former default viewer. For details about the differences between the
current viewer and the legacy viewer, see “Differences Between the Default
and Legacy Viewer” on page 7-71.
vrgetpref
ans =
DataTypeBool: 'logical'
DataTypeInt32: 'double'
DataTypeFloat: 'double'
DefaultCanvasNavPanel: 'none'
DefaultCanvasUnits: 'normalized'
DefaultFigureAntialiasing: 'off'
DefaultFigureCaptureFileFormat: 'tif'
DefaultFigureCaptureFileName: '%f_anim_%n.tif'
7-69
7 Viewing Virtual Worlds
DefaultFigureDeleteFcn: ''
DefaultFigureLighting: 'on'
DefaultFigureMaxTextureSize: 'auto'
DefaultFigureNavPanel: 'halfbar'
DefaultFigureNavZones: 'off'
DefaultFigurePosition: [5 92 576 380]
DefaultFigureRecord2DCompressMethod: 'auto'
DefaultFigureRecord2DCompressQuality: 75
DefaultFigureRecord2DFileName: '%f_anim_%n.avi'
DefaultFigureRecord2DFPS: 15
DefaultFigureStatusBar: 'on'
DefaultFigureTextures: 'on'
DefaultFigureToolBar: 'on'
DefaultFigureTransparency: 'on'
DefaultFigureWireframe: 'off'
DefaultViewer: 'internal'
DefaultWorldRecord3DFileName: '%f_anim_%n.wrl'
DefaultWorldRecordMode: 'manual'
DefaultWorldRecordInterval: [0 0]
DefaultWorldRemoteView: 'off'
DefaultWorldTimeSource: 'external'
Editor: [1x60 char]
HttpPort: 8123
TransportBuffer: 5
TransportTimeout: 20
VrPort: 8124
vrsetpref('DefaultViewer','internalv4')
vrplanets
7-70
Legacy Simulink® 3D Animation™ Viewer
The Planets example is loaded and the virtual scene is displayed using
the legacy viewer.
vrsetpref('DefaultViewer','internal')
• In the legacy viewer, you cannot dock the viewer window in the MATLAB
window.
7-71
7 Viewing Virtual Worlds
• In the legacy viewer, you cannot right-click in the viewer window to display
a context menu that contains the viewer commands.
• In the legacy viewer, you cannot combine multiple figures in several tiles
of a MATLAB figure.
The legacy and default viewer have minor visual differences, such as:
• In the legacy viewer, circles denote selected menu command options. In the
default viewer, checks denote selected menu command options.
• In the legacy viewer, the status bar has no border. In the default viewer,
the status bar has a border.
If you set the DefaultViewer property to 'internalv4', the File > New
Window command creates the new player window as in previous releases.
7-72
8
Simulink 3D Animation
Stand-Alone Viewer
Orbisnap Viewer
What is Orbisnap?
The Simulink 3D Animation product includes Orbisnap. Orbisnap is a free,
optional, stand-alone VRML97 viewer that does not require you to have
either the MATLAB or Simulink 3D Animation products running. You can
use Orbisnap to:
• View prerecorded WRL animation files. For example, you might want to
show prerecorded animation files in a meeting at which you do not have
access to the MATLAB or Simulink 3D Animation products.
• Remotely view, from a client machine, a virtual world loaded in a current
session of the Simulink 3D Animation product. For example, if you want
to visualize a virtual world active in a Simulink 3D Animation session
that is running on a computer in another part of the building, or across
the network. This functionality allows you to remotely view a simulation,
but not control it.
• View and navigate, but not simulate, a VRML world. You can navigate,
render, and otherwise visualize a VRML world without simulating it.
Orbisnap is multiplatform. You can run Orbisnap on any of the platforms that
the Simulink 3D Animation product supports. You do not need a MathWorks
license to run Orbisnap.
8-2
Install Orbisnap
Install Orbisnap
In this section...
“Section Overview” on page 8-3
“System Requirements” on page 8-3
“Copying Orbisnap to Another Location” on page 8-3
“Adding Shortcuts or Symbolic Links” on page 8-4
Section Overview
The collection of Orbisnap files includes the Orbisnap starter file,
Orbisnap executable file, and supporting files. These files are located
under the Simulink 3D Animation orbisnap folder (for example,
matlabroot\toolbox\sl3d\orbisnap\bin for the Windows platform). No
further installation is necessary, but you might want to copy the Orbisnap
files to another location or create shortcuts or symbolic links to the Orbisnap
starter file for convenience.
System Requirements
Orbisnap has the same hardware and software requirements as MATLAB.
It is a multiplatform product that can run on PC-compatible computers with
Windows or Linux. See the following page on the MathWorks Web site:
http://www.mathworks.com/products/matlab/requirements.html
8-3
8 Simulink® 3D Animation™ Stand-Alone Viewer
2 Copy all the files in the Orbisnap folder and its subdirectories. These
files are likely located in the Simulink 3D Animationorbisnap folder, for
example, matlabroot\toolbox\sl3d\orbisnap for the Windows platform.
8-4
Start Orbisnap
Start Orbisnap
You can start Orbisnap from any command line with the following:
orbisnap
orbisnap -f vr_filename
orbisnap -c hostname -w "vrworld" -t http -v vrport -q=end_time
orbisnap -t http -v vrport vr_filename_or_hostname -q=end_time
orbisnap -h
8-5
8 Simulink® 3D Animation™ Stand-Alone Viewer
8-6
Orbisnap Interface
Orbisnap Interface
In this section...
“Menu Bar” on page 8-8
“Toolbar” on page 8-9
“Navigation Panel” on page 8-9
8-7
8 Simulink® 3D Animation™ Stand-Alone Viewer
You cannot
Menu Bar
The Orbisnap menu bar has the following menus:
8-8
Orbisnap Interface
Toolbar
The Orbisnap toolbar has buttons for some of the more commonly used
operations available from the menu bar. These buttons include:
• Drop-down list that displays all the viewpoints in the virtual world
• Straighten up button
• Drop-down list that displays the navigation options Walk, Examine, and Fly
Navigation Panel
The Orbisnap navigation panel has navigation controls for some of the more
commonly used navigation operations available from the menu bar.
8-9
8 Simulink® 3D Animation™ Stand-Alone Viewer
8-10
Navigate Using Orbisnap
Navigation view — You can change the camera position. From the menu
bar, select the Navigation menu Straighten Up option. Alternatively,
you can click the Straighten Up control from the toolbar or press F9 on the
keyboard. This option resets the camera so that it points straight ahead.
• From the menu bar, select the Navigation menu Method option. This
option provides three choices, Walk, Examine, or Fly. See the table
Orbisnap Mouse Navigation on page 8-12.
• From the toolbar, select the drop-down menu that displays the navigation
options Walk, Examine, and Fly.
• From the navigation panel, click the W, E, or F buttons.
• From the keyboard, press Shift+W, Shift+E, or Shift+F.
Navigation zones — You can view the navigation zones for a virtual world
through the menu bar or keyboard.
From the menu bar, select the View menu Navigation Zones option. The
virtual world changes as the navigation zones are toggled on and appear in
the virtual world. Alternatively, from the keyboard, press the F7 key.
The following table summarizes the behavior associated with the movement
modes and navigation zones when you use your mouse to navigate through a
virtual world. Turn the navigation zones on and experiment by clicking and
dragging your mouse in the different zones of a virtual world.
8-11
8 Simulink® 3D Animation™ Stand-Alone Viewer
Movement
Mode Zone and Description
Walk Outer -- Click and drag the mouse up, down, left, or
right to slide the camera in any of these directions in
a single plane.
Inner -- Click and drag the mouse up and down to move
forward and backward. Drag the mouse left and right
to turn left or right.
Examine Outer -- Click and drag the mouse up and down to
move forward and backward. Drag the mouse left and
right to slide left or right.
Inner -- Click and drag the mouse to rotate the
viewpoint around the origin of the scene.
Fly Outer -- Click and drag the mouse to tilt the view either
left or right.
Inner -- Click and drag the mouse to pan the camera
up, down, left, or right within the scene.
Center -- Click and drag the mouse up and down to
move forward and backward. Move the mouse left or
right to turn in either of these directions.
If your virtual world contains sensors, these sensors take precedence over
mouse navigation at the sensor’s location. In this case, mouse navigation is
still possible through the right or middle mouse buttons.
Keyboard — You can also use the keyboard to navigate through a virtual
world. It can be faster and easier to issue a keyboard command, especially if
you want to move the camera repeatedly in a single direction. The following
table summarizes the keyboard commands and their associated navigation
functions. Note that the letters presented do not need to be capitalized to
perform their intended function.
8-12
Navigate Using Orbisnap
Keyboard
Command Navigation Function
Backspace Undo move.
F9 Straighten up and make the camera stand on the
horizontal plane of its local coordinates.
8-13
8 Simulink® 3D Animation™ Stand-Alone Viewer
Keyboard
Command Navigation Function
Alt+Left/Right Slide left and right.
Arrow
Ctrl+Left/Right/Up/ Pressing Ctrl alone acquires the examine lock
Down Arrow at the point of intersection between the line
perpendicular to the screen, coming through the
center of the Orbisnap window, and the closest
visible surface to the camera. Pressing the arrow
keys without releasing Ctrl rotates the viewpoint
about the acquired center point.
Shift+Alt+Left/Right Tilt the camera right and left.
Arrow
8-14
View Animations or Virtual Worlds with Orbisnap
3 Browse to the folder that contains the prerecorded WRL animation file
or virtual world you want to view.
4 Select the virtual world or prerecorded WRL file you want to view.
5 Click Open.
The file is displayed. If the file is an animation file, the simulation begins.
Using the menus, toolbar, and navigation panel, you can perform many of the
same operations on the virtual world that you can with the Simulink 3D
Animation Viewer. See “Orbisnap Interface” on page 8-7 for an overview of
the Orbisnap interface. See “Start Orbisnap” on page 8-5 for a description of
the Orbisnap command-line options.
8-15
8 Simulink® 3D Animation™ Stand-Alone Viewer
• Although you can visualize a virtual world from the Simulink 3D Animation
server in Orbisnap, any navigation or rendering in one viewer is not
reflected in the other. For example, any navigation you do on the virtual
world in Orbisnap is not reflected in the virtual world in the Simulink 3D
Animation <olink localinfo="sViewer, and vice versa.
• You cannot start or stop a simulation of the virtual world in Orbisnap. You
can see a simulation on Orbisnap only if the virtual world is simulated in
the Simulink 3D Animation server.
• The simulation might slow when you connect Orbisnap remotely to the
Simulink 3D Animation server.
8-16
View Virtual Worlds Remotely with Orbisnap
The Choose a world dialog is displayed. This dialog lists all the virtual
worlds that are currently active on the Simulink 3D Animation server.
If no virtual world has ever been opened in this session of the Simulink 3D
Animation server, Orbisnap displays a message. If you see this message,
contact your counterpart running the Simulink 3D Animation server to
better synchronize your activities. A virtual world must be fully active on
the Simulink 3D Animation server for Orbisnap to remotely access it.
8-17
8 Simulink® 3D Animation™ Stand-Alone Viewer
5 Click OK.
Using the menus, toolbar, and navigation panel, you can perform many of
the same operations on the virtual world that you can with the Simulink
3D Animation <olink localinfo="sViewer. See “Orbisnap Interface” on page
8-7. See “Start Orbisnap” on page 8-5 for a description of the Orbisnap
command-line options.
8-18
9
Description Takes two 3-by-1 vectors as input and returns their cross product.
9-2
Joystick Input
Description The Joystick Input block provides interaction between a Simulink model
and the virtual world associated with a Simulink 3D Animation block.
The Joystick Input block uses axes, buttons, and the point-of-view
selector, if present. You can use this block as you would use any other
Simulink source block. Its output ports reflect the status of the joystick
controls for axes and buttons.
The Joystick Input block also supports force-feedback devices.
When building a model using Real-Time Windows Target, use the
RTWin Joystick Input driver instead of the Joystick Input block.
Block
Parameters Joystick ID — The system ID assigned to the given joystick device.
Dialog You can find the properties of the joystick that is connected to the
Box system in the Game Controllers section of the system Control Panel.
Adjust I/O ports according to joystick capabilities — If you select
this check box, the Simulink 3D Animation software dynamically
9-3
Joystick Input
9-4
Joystick Input
9-5
Normalize Vector
Description Takes an input vector of any size and outputs the unit vector parallel
to it.
9-6
Rotation Between 2 Vectors
Description Takes input of two 3-by-1 vectors and returns a VRML rotation
(specified as a four-element vector defining axis and angle) that is
needed to transform the first input vector to the second input vector.
9-7
Rotation Matrix to VRML Rotation
Description Takes an input of a rotation matrix and outputs the axis/angle rotation
representation used for defining rotations in VRML. The rotation
matrix can be either a 9-element column vector or a 3-by-3 matrix
defined columnwise.
Rotation Matrix
A representation of a three-dimensional spherical rotation as a 3-by-3
real, orthogonal matrix R: RTR = RRT = I, where I is the 3-by-3 identity
and RT is the transpose of R.
9-8
Rotation Matrix to VRML Rotation
• You can form three independent rotation matrices R1, R2, R3, each
representing a single independent rotation. Then compose the full
rotation matrix R with respect to fixed coordinate axes as a product
of these three: R = R3*R2*R1. The three angles are Euler angles.
• You can represent R in terms of an axis-angle rotation n = (nx,ny,nz)
and θ with n*n = 1. The three independent angles are θ and the two
needed to orient n. Form the antisymmetric matrix:
⎛ 0 − nz ny ⎞
⎜ ⎟
Ĵ = ⎜ nz 0 − nx ⎟
⎜ −n nx 0 ⎟⎠
⎝ y
9-9
Space Mouse Input
Data Type The Space Mouse Input block outputs signals of type double.
Support
9-10
Space Mouse Input
Block
Parameters Port — Serial port to which the space mouse is connected. Possible
Dialog values are USB1...USB4 and COM1...COM4.
Box
Output Type — This field specifies how the inputs from the device
are transformed: 9-11
Space Mouse Input
9-12
Space Mouse Input
See Also
Manipulator with SpaceMouse
9-13
Viewpoint Direction to VRML Orientation
9-14
VR Placeholder
Description The VR Placeholder block sends out a special value that is interpreted
as “unspecified” by the VR Sink block. When this value appears on the
VR Sink input, whether as a single value or as an element of a vector,
the appropriate value in the virtual world stays unchanged. Use this
block to change only one value from a larger vector. For example, use
this block to change just one coordinate from a 3-D position.
The value output by the VR Placeholder block should not be modified
before being used in other VR blocks.
Block
Parameters Output Width — Length of the vector containing placeholder signal
Dialog values.
Box
9-15
VR Signal Expander
Purpose Expand input vectors into fully qualified VRML field vectors
Data Type A VR Signal Expander block accepts and outputs signals of type double.
Support
Block
Parameters Output width — How long the output vector should be.
Dialog
Output signal indices — Vector indicating the position at which the
Box
input signals appear at the output. The remaining positions are filled
with VR Placeholder signals.
9-16
VR Signal Expander
For example, suppose you want an input vector with two signals and an
output vector with four signals, with the first input signal in position 2
and the second input signal in position 4. In the Output width box,
enter 4 and in the Output signal indices box, enter [2,4]. The first
and third output signals are unspecified.
9-17
VR Sink
Description The VR Sink block writes values from its ports to virtual world fields
specified in the Block Parameters dialog box.
For an example of how to use the VR Sink block, see the Foucault
Pendulum Model with Virtual Reality Scene example.
The VR Sink block is equivalent to the VR To Video block, except that
the Show video output port parameter for the VR Sink block is
cleared by default.
The VR Sink block cannot be compiled by the Simulink Coder software,
but it can be used as a SimViewing device on the host computer.
Data Type A VR Sink block accepts all meaningful data types on input. The block
Support converts these data types to natural VRML types, as necessary. These
data types include logicals, many types of signed and unsigned integers,
9-18
VR Sink
singles, and doubles. The MATLAB and Simulink interfaces also accept
matrices. For further details, see “VRML Data Types” on page 5-24.
Block
Parameters Source file — VRML file name specifying the virtual world that
Dialog connects to this block. By default, the full path to the associated .wrl
Box file appears in this text box. If you enter only the file name in this box,
the software assumes that the .wrl file resides in the same folder as
the model file.
• Click the New to open an empty default VRML editor. When you
either enter a source file name or use the Browse button, the New
button becomes an Edit button.
9-19
VR Sink
• Click the Edit button to launch the default VRML editor with the
source file open.
• Click the View button to view the world in the Simulink 3D
Animation Viewer or a Web browser.
• Click the Reload button reloads the world after you change it.
9-20
VR Sink
Nodes that have names are marked with red arrows. You can access
them from the Simulink 3D Animation interface. Nodes without names,
but whose children are named, are also marked with red arrows. This
marking scheme makes it possible for you to find all accessible nodes by
traversing the tree using arrows. Other nodes have a blue dot before
their names.
Fields with values that you set have check boxes. Use these check boxes
to select the fields whose values you want the Simulink software to
update. For every field that you select, an input port is created in the
block. Input ports are assigned to the selected nodes and fields in the
order that corresponds to the VRML file.
Fields whose values cannot be written (because their parent nodes do
not have names, or because they are not of VRML data class eventIn or
exposedField) have an X-shaped icon.
Show node types — If you select this check box, node types are shown
in the VRML tree.
Show field types — If you select this check box, field types are shown
in the VRML tree.
9-21
VR Source
Description The VR Source provides access to virtual world fields, as chosen in the
Block Parameters dialog box as input signals during simulation.
The VR Source block supports several activities. For example, use the
VR Source block to:
For an example of how to use the VR Source block, see the Set the
Setpoint subsystem in the vrcrane_panel example.
You cannot use the Simulink Coder software to compile a model that
includes a VR Source block.
9-22
VR Source
Block
Parameters Source file — VRML file name specifying the virtual world that
Dialog connects to this block. By default, the full path to the associated .wrl
Box file appears in this text box. If you enter only the file name in this box,
the software assumes that the .wrl file resides in the same folder as
the model file.
• Click the New to open an empty default VRML editor. When you
either enter a source file name or use the Browse button, the New
button becomes an Edit button.
9-23
VR Source
• Click the Edit button to launch the default VRML editor with the
source file open.
• Click the View button to view the world in the Simulink 3D
Animation Viewer or a Web browser.
• Click the Reload button reloads the world after you change it.
9-24
VR Source
the only SFxxx field that can map to a variable-size signal. For details
about these data types, see “VRML Field Data Types” on page 5-24.
VRML Tree — This box shows the structure of the VRML file and the
virtual world itself.
Nodes that have names are marked with red arrows. You can access
them from the MATLAB interface. Nodes without names, but whose
children are named, are also marked with red arrows. This marking
scheme makes it possible for you to find all accessible nodes by
traversing the tree using arrows. Other nodes have a blue dot before
their names.
Fields with readable values have check boxes. Use these check boxes to
select the fields that you want the Simulink software to monitor and to
use to input values. For each field that you select in the VRML Tree
box, Simulink creates an output port in the VR Source block. Simulink
creates the output ports in the same order as the selected fields appear
in the VRML file.
Fields whose values cannot be read (because their parent nodes do not
have names, or because their values cannot be imported to Simulink)
have an X-shaped icon.
Show node types — If you select this check box, node types are shown
in the VRML tree.
Show field types — If you select this check box, field types are shown
in the VRML tree.
9-25
VR Text Output
Description The VR Text Output can display Simulink values of signal as text in
a VRML scene.
Text rendering is a demanding task for VRML viewers, so there is
generally be a decrease in rendering speed when outputting text. This
effect increases with the complexity of the text output. You can improve
the performance if you limit the output from the Simulink model to
only the values of signals that change (e.g., modeling captions) or use
more static-text nodes.
9-26
VR Text Output
Block
Parameters Associated VRML file — VRML file specifying the virtual world to
Dialog which text is output.
Box
Associated Text node — Text node within the virtual world to which
text is output.
9-27
VR Text Output
Format string — Format used for output text. This block uses
sprintf() to format the output strings. Like sprintf(), it works in
a vectorized fashion, where the format string is recycled through the
components of the input vector. This block does not support the %c
and %s conversion formats, as signals in the Simulink product cannot
have both characters and strings.
Sample time — Enter the sample time or -1 for inherited sample time.
Ensure that a viewer window is open during simulation — Select
this check box to ensure that the Simulink 3D Animation Viewer is
open during simulation.
9-28
VR To Video
Purpose Write data from Simulink model to virtual world (video output port
enabled)
Description This block is equivalent to the VR Sink block, except that its Show
video output port is selected by default.
See the VR Sink block for details.
9-29
VR Tracer
• General shape
• Line segments connecting object positions in every time step
• Axis-aligned triads for orienting the trajectory in the 3–D space
9-30
VR Tracer
Block Following is the Main pane of the VR Tracer block dialog box.
Parameters
Dialog
Box
9-31
VR Tracer
9-32
VR Tracer
• None
• Tetrahedron
• Pyramid
• Box
• Octahedron
• Sphere
9-33
VR Tracer
9-34
VR Tracer
9-35
VR Tracer
9-36
10
Functions — Alphabetical
List
figure
Syntax f = figure
f = figure([])
f = figure(world)
f = figure(world, 'PropertyName', propertyvalue, ...)
Description f = figure returns an empty figure object. This object does not have a
visual representation. All properties are empty.
f = figure([]) returns an empty vector of type figure.
f = figure(world) creates a new virtual reality figure. It shows the
specified world(s) and returns the figure object, f.
f = figure(world, 'PropertyName', propertyvalue, ...)
shows the specified world(s) with specified properties and returns the
figure object, f.
Creating a virtual figure object with this method creates and displays
the object in the figure window viewer (default viewer 'internalv5').
It ignores the value of the vrsetpref DefaultViewer property.
w=vrworld('membrane.wrl')
open(w);
f=vrfigure(w)
10-2
stl2vrml
Syntax stl2vrml(source)
stl2vrml(source,destination)
Description stl2vrml(source) Converts the STL file that you specify with source
to a VRML file.
Converts both ASCII and binary STL files. The resulting files are
VRML97 compliant, UTF-8 encoded text files.
VRML files have the same name as the source STL files, except that
the extension is .WRL instead of .STL. The stl2vrml function places the
VRML files into the current folder.
stl2vrml(source,destination) creates the converted VRML files in
the destination folder.
Tips • You can use the created assembly VRML files as templates for
creating virtual scenes in which you can work with objects of the
converted assemblies. To work with the scene effectively, edit the
scene as necessary. For example, consider whether you need to add
lights, viewpoints, and surrounding objects, modify part materials,
define navigation speeds, or make other additions and changes.
• The stl2vrml function converts individual STL files according to
the STL convention, which places parts in the global coordinate
system. If you specify a Physical Modeling XML file as the source,
the resulting VRML assembly file reflects the initial positions of the
parts defined in the XML file.
• If you use SolidWorks, then do not use spaces when naming
assemblies and components. Avoiding spaces in assembly and
component names ensures that the assembly VRML file has the same
tree structure as the related source in SolidWorks. You can then use
the vrphysmod function to process the assembly VRML file to obtain
a Simulink model with VRML visualization.
10-3
stl2vrml
Input source
Arguments The name of the source STL or Physical Modeling XML file. If source
is a Physical Modeling XML file, stl2vrml converts all STL files that
the XML file references. The stl2vrml function also creates a main
assembly VRML file that contains inline references to all converted
individual VRML files. All inlines are wrapped by transform nodes with
DEF names corresponding to the part names defined in their respective
STL source files.
Default: ''
destination
(Optional) Folder in which to create converted files. If the destination
folder does not exist, stl2vrml attempts to create the destination folder.
Default: ''
Examples These examples use STL files that SimMechanics product includes. If
you do not have the SimMechanics product installed, then substitute
another STL file .
Convert the STL file fourbar-Bar1-1.STL (which is in
matlab/toolbox/physmod/mech/mechdemos) to a VRML file and
place the resulting file in the current folder. The resulting VRML file
(fourbar-Bar1-1.wrl) has the same name as the source file, except
that it has a .wrl extension instead of a .stl extension.
stl2vrml('fourbar-Bar1-1.STL')
ls
. .. fourbar-Bar1-1.wrl
% Other files and folders in the current folder appear, as well
Convert the STL file fourbar-Bar2-1.STL to a VRML file and place the
resulting file in a folder called virtualworlds. The resulting VRML
file is in the destination folder that you specify.
mkdir('virtualworlds')
10-4
stl2vrml
stl2vrml('fourbar-Bar2-1.STL','virtualworlds')
cd virtualworlds
ls
. .. fourbar-Bar2-1.wrl
10-5
vrcadcleanup
Syntax vrcadcleanup('filename')
vrcadcleanup('filename', 'hint')
Argument Description
'solidworks' Assumes that the software is exporting the
original set of VRML files from SolidWorks. This
option adds or increments the numerical suffix
to the node names to match the part names that
exist in the corresponding physical modeling
XML file.
This function expects the input file structure to correspond to the typical
output of the specified CAD tools. The typical input file should contain:
• A structure of viewpoints and inline nodes (possibly contained in one
layer of transform nodes)
• One inline node for each part of the exported assembly
The function also performs the following:
• Upon output, discards any additional nodes, including transform
nodes, that do not contain inline nodes.
10-6
vrcadcleanup
Note If you call this function for a file that is not a product of a CAD
export filter, the output file might be corrupted.
vrcadcleanup('four_link.wrl');
10-7
vr.canvas
Syntax c = vr.canvas(vrworld)
c = vr.canvas(vrworld, parent)
c = vr.canvas(vrworld, parent, position)
c = vr.canvas(world, 'propertyName', propertyValue,...)
10-8
vr.canvas
10-9
vr.canvas
10-10
vr.canvas
10-11
vr.canvas
maximum possible
pixel size.
NavMode 'fly' | 'examine' Specifies the current
| 'walk' |'none' navigation mode.
Default: 'fly'
NavPanel Controls the
• 'none'
appearance of the
Panel is not visible. control panel in the
vr.canvas object.
• 'minimized'
Panel is
minimized.
• 'translucent'
Panel floats half
transparently
above the scene.
• 'opaque'
Panel floats above
the scene.
Default: 'none'
NavSpeed 'veryslow' | Specifies navigation
'slow' | 'normal' speed. Read/write.
| 'fast' |
'veryfast'
Default: 'normal'
NavZones 'off' | 'on' Toggles navigation
zones on/off.
Default: 'off'
Read/write.
10-12
vr.canvas
10-13
vr.canvas
Triad is shown in
bottom-left corner
• 'bottomright'
Triad is shown
in bottom-right
corner
• 'center'
Triad is shown in
the center
Default:
'bottomleft'
Units 'pixels' | Specifies the
'normalized' units to interpret
the Position
property. The
DefaultCanvasUnits
preference controls
the default for this
property. Read/write
Viewpoint String. Specifies the
vr.canvas object’s
If active viewpoint
active viewpoint.
does not have a name,
This value is an
value is empty.
empty string if the
active viewpoint
has no description.
Read/write.
Wireframe 'off' | 'on' Specifies whether
objects are drawn as
Default: 'off'
solids or wireframes.
Read/write.
10-14
vr.canvas
10-15
vr.canvas/capture
w = vrworld('vrlights');
open(w);
c = vr.canvas(w, gcf, [30 30 300 200]);
z=capture(c);
image(z);
10-16
vrclear
Syntax vrclear
vrclear('-force')
Description The vrclear function removes from memory all virtual worlds that are
closed and invalidates all vrworld objects related to them. This function
does not affect open virtual worlds. Open virtual worlds include those
loaded from the Simulink interface. You use this command to
• Ensure that the maximum amount of memory is freed before a
memory-consuming operation takes place.
• Perform a general cleanup of memory.
The vrclear('-force') command removes all virtual worlds from
memory, including worlds opened from the Simulink interface.
10-17
vrclose
Syntax vrclose
vrclose all
Description vrclose and vrclose all close all the open virtual reality figures.
vrpend
vrbounce
vrlights
vrclose
All the virtual reality figure windows disappear from the screen.
10-18
vrdir2ori
Syntax vrdir2ori(d)
vrdir2ori(d,options)
10-19
vrdrawnow
Syntax vrdrawnow
Description vrdrawnow removes from the queue pending changes to the virtual
world and makes these changes to the scene in the viewer.
Changes to the scene are normally queued and the views are updated
when
• The MATLAB software is idle for some time (no Simulink model is
running and no script is being executed).
• A Simulink step is finished.
10-20
vredit
Syntax w = vredit
w = vredit(filename)
Description w = vredit opens the 3D World Editor with an empty virtual world.
w = vredit(filename) opens a virtual world file in the 3D World
Editor, based on the specified filename. It returns the vrworld handle
of the virtual world.
vredit
myworld = vredit('membrane.wrl')
10-21
vrfigure
Syntax f = vrfigure(world)
f = vrfigure(world,position)
f = vrfigure
f = vrfigure([])
myworld = vrworld('vrmount.wrl');
10-22
vrfigure
open(myworld);
f = vrfigure(myworld);
10-23
vrfigure/capture
myworld = vrworld('vrmount.wrl')
open(myworld)
You can now view the virtual world in the Simulink 3D Animation
Viewer by typing
f = vrfigure(myworld)
Your viewer opens and displays the virtual scene. Next, create an RGB
image by typing
image_capture = capture(f);
image(image_capture)
10-24
vrfigure/capture
10-25
vrfigure/close
Syntax close(vrfigure_object)
10-26
vrfigure/get
Syntax get(vrfigure_object)
x = get(vrfigure_object, 'property_name')
10-27
vrfigure/get
10-28
vrfigure/get
10-29
vrfigure/get
10-30
vrfigure/get
10-31
vrfigure/get
myworld = vrworld('vrmount.wrl');
open(myworld)
f = vrfigure(myworld);
You can now get the object properties of the vrfigure object f:
get(f)
Antialiasing = 'off'
CameraBound = 'on'
CameraDirection = [0 0 -1]
CameraDirectionAbs = [0 -0.198669 -0.980067]
CameraPosition = [0 0 0]
CameraPositionAbs = [20 8 50]
CameraUpVector = [0 1 0]
CameraUpVectorAbs = [0 0.980067 -0.198669]
CaptureFileFormat = 'tif'
CaptureFileName = '%f_anim_%n.tif'
DeleteFcn = ''
Fullscreen = 'off'
Headlight = 'on'
Lighting = 'on'
MaxTextureSize = 4096
Name = 'VR Car in the Mountains'
NavMode = 'examine'
NavPanel = 'halfbar'
NavSpeed = 'normal'
10-32
vrfigure/get
NavZones = 'off'
Position = [5 92 576 380]
Record2D = 'off'
Record2DCompressMethod = 'auto'
Record2DCompressQuality = 75
Record2DFPS = 15
Record2DFileName = '%f_anim_%n.avi'
StatusBar = 'on'
Textures = 'on'
ToolBar = 'on'
Transparency = 'on'
Viewpoint = 'View 1 - Observer'
Wireframe = 'off'
World = vrworld object: 1-by-1
ZoomFactor = 1
10-33
vrfigure/isvalid
Syntax x = isvalid(vrfigure_object_vector)
Description This method detects whether the vrfigure handles are valid and
returns an array that contains a 1 where the vrfigure handles are
valid and returns a 0 where they are not.
10-34
vrfigure/set
10-35
vrfigure/set
10-36
vrfigure/set
10-37
vrfigure/set
10-38
vrfigure/set
myworld = vrworld('vrmount.wrl');
open(myworld)
f = vrfigure(myworld);
You can see that the name of the virtual world has changed in the
viewer.
10-39
vrfigure/set
10-40
vrgcbf
Syntax f = vrgcbf
10-41
vrgcf
Syntax h = vrgcf
Description h = vrgcf returns the handle of the current virtual reality figure. The
current virtual reality figure is the currently active virtual reality
figure window in which you can get and set the viewer properties. If no
virtual reality figure exists, the MATLAB software returns an empty
vrfigure object.
This method is most useful to query and set virtual reality figure
properties.
10-42
vrgetpref
Syntax x = vrgetpref
x = vrgetpref('preference_name')
x = vrgetpref('preference_name','factory')
x = vrgetpref('factory')
Preference Description
DataTypeBool Specifies the handling of the VRML
Bool data type for vrnode/setfield
and vrnode/getfield. Valid values
are 'logical' and 'char'. If set
to 'logical', the VRML Bool data
type is returned as a logical value.
If set to 'char', the Bool data type
10-43
vrgetpref
Preference Description
10-44
vrgetpref
Preference Description
DefaultCanvasNavPanel Controls the appearance of the
control panel in the vr.canvas
object. Values are:
• 'none'
Panel is not visible.
• 'minimized'
Panel appears as a minimized icon
in the right-hand corner of the
viewer.
• 'translucent'
Panel floats half transparently
above the scene.
• 'opaque'
Panel floats above the scene.
Default: 'none'
DefaultCanvasUnits Specifies default units for new
vr.canvas objects. See vr.canvas
for detailed description. Default is
'normalized'.
DefaultFigureAnti Determines whether antialiasing is
Aliasing used by default for new vrfigure
objects. This preference also applies
to new vr.canvas objects. Valid
values are 'off' and 'on'.
DefaultFigureCapture Specifies default file name for
FileName vr.capture files. See vrfigure/get
for detailed description. Default is
'%f_anim_%n.tif'.
10-45
vrgetpref
Preference Description
DefaultFigureDeleteFcn Specifies the default callback invoked
when closing a vrfigure object.
DefaultFigureLighting Specifies whether the lights are
rendered by default for new
vrfigure objects. This preference
also applies to new vr.canvas
objects. Valid values are 'off' and
'on'.
DefaultFigureMax Specifies the default maximum size
TextureSize of a texture used in rendering new
vrfigure objects. This preference
also applies to new vr.canvas
objects. Valid values are 'auto' and
32 <= x <= video card limit, where
x is a power of 2.
DefaultFigureNavPanel Specifies the default appearance
of the control panel in the viewer.
Valid values are 'opaque',
'translucent', 'none', 'halfbar',
'bar', and 'factory'. Default is
'halfbar'.
DefaultFigureNavZones Specifies whether the navigation
zone is on or off by default for new
vrfigure objects. This preference
also applies to new vr.canvas
objects. Valid values are 'off' and
'on'.
DefaultFigurePosition Sets the default initial position and
size of the Simulink 3D Animation
Viewer window. Valid value is a
vector of four doubles.
10-46
vrgetpref
Preference Description
DefaultFigureRecord2D Specifies the default compression
CompressMethod method for creating 2-D animation
files for new vrfigure objects. Valid
values are '', 'auto', 'lossless',
and 'codec_code'.
DefaultFigureRecord2D Specifies the default quality of 2-D
CompressQuality animation file compression for new
vrfigure objects. Valid values are
0-100.
DefaultFigureRecord2D Specifies the default 2-D offline
FileName animation file name for new
vrfigure objects.
DefaultFigureRecord2DFPS Specifies the default frames per
second playback speed.
To have the 2D AVI animation play
back at approximately the same
playback speed as the 3D VRML
animation, set this preference to
auto.
DefaultFigureStatusBar Specifies whether the status bar
appears by default at the bottom of
the Simulink 3D Animation Viewer
for new vrfigure objects. Valid
values are 'off' and 'on'.
DefaultFigureTextures Specifies whether textures should
be rendered by default for new
vrfigure objects. This preference
also applies to new vr.canvas
objects. See vrfigure/get for
detailed description. Default is 'on'.
10-47
vrgetpref
Preference Description
DefaultFigureToolBar Specifies whether the toolbar
appears by default on the Simulink
3D Animation Viewer for new
vrfigure objects. Valid values are
'off' and 'on'.
DefaultFigure Specifies whether or not
Transparency transparency information is taken
into account when rendering for new
vrfigure objects. This preference
also applies to new vr.canvas
objects. Valid values are 'off' and
'on'.
DefaultFigureWireframe Specifies whether objects are drawn
as solids or wireframes by default
for new vrfigure objects. This
preference also applies to new
vr.canvas objects. Valid values are
'off' and 'on'.
DefaultViewer Specifies which viewer is used to
view a virtual scene.
• 'internal'
Default Simulink 3D Animation
Viewer. This is the same as
setting the value to 'internalv5'
for all platforms except the Linux
platform.
• 'internalv4'
Legacy Simulink 3D Animation
Viewer.
• 'internalv5'
10-48
vrgetpref
Preference Description
10-49
vrgetpref
Preference Description
DefaultWorldTimeSource Specifies the default source of
the time for new vrworld objects.
Valid values are 'external' and
'freerun'.
Editor Path to the VRML editor. If this
path is empty, the MATLAB editor
is used.
EditorPreserveLayout Specifies whether the 3D World
Editor starts up with a saved version
of the layout of a virtual world when
you exited it or reverts to the default
layout. The layout of the virtual
world display pane includes settings
for the view, viewpoints, navigation,
and rendering. Valid values are
'off' and 'on'. The default is on
(use saved layout).
HttpPort IP port number used to access the
Simulink 3D Animation server over
the Web via HTTP. If you change
this preference, you must restart the
MATLAB software before the change
takes effect.
TransportBuffer Length of the transport buffer
(network packet overlay) for
communication between the
Simulink 3D Animation server and
its clients.
10-50
vrgetpref
Preference Description
TransportTimeout Amount of time the Simulink
3D Animation server waits for a
reply from the client. If there is
no response from the client, the
Simulink 3D Animation server
disconnects from the client.
VrPort IP port used for communication
between the Simulink 3D Animation
server and its clients. If you change
this preference, you must restart the
MATLAB software before the change
takes effect.
10-51
vrgetpref
10-52
vrgetpref
`%matlabroot\bin\win32\meditor.exe %file'
http://server.name:port_number
10-53
vrgetpref
10-54
vrinstall
Syntax vrinstall('action')
vrinstall action
vrinstall('action','component')
vrinstall action component
x = vrinstall('action', 'component')
Description You use this function to manage the installation of optional software
components related to the Simulink 3D Animation product. Currently
there are two such components: VRML plug-in and VRML editor.
10-55
vrinstall
Examples Install the VRML plug-in. This command starts the Blaxxun Contact
install program and installs the plug-in to your default Web browser.
10-56
vrjoystick
10-57
vrjoystick
Method Description
force force(joy, n, f) applies force feedback
to joystick axis n. The n parameter can be
a vector to affect multiple axes. f values
should be in range of -1 to 1, and the
number of elements in f should either
match the number of elements of n, or
f can be a scalar to be applied to all the
axes specified by n.
pov p = pov(joy, n) reads the status of
joystick POV (point of view) of control
number n. pov is usually returned in
degrees, with -1 meaning "not selected." n
can be a vector to return multiple POVs.
read [axes, buttons, povs] = read(joy)
reads the status of axes, buttons, and
POVs of the specified joystick. [axes,
buttons, povs] = read(joy, forces)
applies feedback forces, in addition, to a
force-feedback joystick.
10-58
vrlib
Syntax vrlib
Description The Simulink library for the Simulink 3D Animation product has a
number of blocks and utilities. You can access these blocks in one of
the following ways:
• In the MATLAB Command Window, type vrlib.
• From a Simulink block diagram, select the View menu, click Show
Library Browser.
• In the MATLAB Command Window, click the Simulink icon.
10-59
vrnode
Description mynode = vrnode creates an empty vrnode handle that does not
reference any node.
mynode = vrnode([]) creates an empty array of vrnode handles.
mynode = vrnode(vrworld_object,'node_name') creates a handle to
an existing named node in the virtual world.
mynode = vrnode(vrworld_object, 'node_name','node_type')
creates a new node called node_name of type node_type on the root of
the virtual world. It returns the handle to the newly created node.
10-60
vrnode
10-61
vrnode
10-62
vrnode/delete
Syntax delete(vrnode_object)
delete(n)
10-63
vrnode/fields
Syntax fields(vrnode_object)
x = fields(vrnode_object)
10-64
vrnode/get
Syntax get(vrnode_object)
x = get(vrnode_object)
x = get(vrnode_object, 'property_name')
10-65
vrnode/get
10-66
vrnode/getfield
Syntax getfield(vrnode_object)
x = getfield(vrnode_object)
x = getfield(vrnode_object,'fieldname')
Note The dot notation is the preferred method for accessing nodes.
10-67
vrnode/isvalid
Syntax x = isvalid(vrnode_object_vector)
Description This method returns an array that contains 1 when the elements of
vrnode_object_vector are valid vrnode objects, and 0 when they are
not.
The vrnode object is considered valid if the following conditions are met:
• The parent world of the node exists.
• The parent world of the node is open.
• The VRML node with the given vrnode handle exists in the parent
world.
10-68
vrnode/set
10-69
vrnode/set
10-70
vrnode/setfield
Syntax x = setfield(vrnode_object,'fieldname','fieldvalue')
Note The dot notation is the preferred method for accessing nodes.
For example:
vrnode_object.fieldname=fieldvalue;
10-71
vrnode/sync
Description The sync method controls whether the value of a VRML field is
synchronized.
When the field is marked 'on', the field value is updated every time it
is changed on the client computer. If the field is marked 'off', the host
computer ignores the changes on the client computer.
Synchronized fields add more traffic to the network line because the
value of the field must be resent by the client any time it is changed.
Because of this, you should mark for synchronization only the fields you
need to scan for changes made on clients (typically sensors). By default,
fields are not synchronized and their values reflect only settings from
MATLAB or the Simulink software.
Synchronization is meaningful only for readable fields. Readable fields
are of VRML data class eventOut and exposedField. You cannot
enable synchronization for eventIn or nonexposed fields.
10-72
vrori2dir
Syntax vrori2dir(r)
vrori2dir(r,options)
10-73
vrphysmod
Note The SolidWorks VRML export filter does not preserve part
instance names and the part order in the resulting VRML file.
Therefore, the association between such parts and the corresponding
bodies in the block diagram is not always an exact match. In such cases,
the function identifies nodes with partial matches and issues warnings.
To prevent these warnings, ensure that node DEF names in the VRML
file are identical to their corresponding bodies in the Simulink model
before running this function.
If you receive this warning and the set of VRML files does not originate
in the SolidWorks product, ignore the message. Other supported CAD
tools also generate part names with similar names, but preserve them
across different export formats.
10-74
vrphysmod
Examples To update the model four_link using the VRML file four_link.wrl:
vrphysmod('four_link.wrl', 'four_link');
vrphysmod('four_link.wrl', 'four_link/FOURLINK_ASM');
vrphysmod('four_link.wrl', gcs);
10-75
vrplay
Syntax vrplay
vrplay(filename)
x=vrplay(filename)
Description vrplay opens the 3D Animation Player, which you use to open and
play VRML animation files.
vrplay(filename) opens the 3D Animation Player and loads the
virtual world filename.
x=vrplay(filename) also returns a 3D Animation Player figure
handle.
vrplay works only with VRML animation files created using the
Simulink 3D Animation VRML recording functionality.
stop
play
step reverse step forward
fast forward
rewind
last jump
start loop
time indicator
10-76
vrplay
Keyboard The playback controls can also be accessed from the keyboard.
Support
Key Function
F, Page Down Fast forward
J Jump to time
L Loop
P Play/pause toggle
S Stop
R, Page Up Rewind
Right arrow key Step forward
Left arrow key Step reverse
Up arrow key First
Down arrow key Last
Examples To play the animation file based on the vr_octavia example, run
vrplay('octavia_scene_anim.wrl').
10-77
vrrotvec
Syntax r = vrrotvec(a,b)
r = vrrotvec(a,b,options)
10-78
vrrotmat2vec
Syntax r = vrrotmat2vec(m)
r = vrrotmat2vec(m,options)
10-79
vrrotvec2mat
Syntax m = vrrotvec2mat(r)
m = vrrotvec2mat(r,options)
10-80
vrsetpref
Preference Description
DataTypeBool Specifies the handling of the VRML
Bool data type for vrnode/setfield
and vrnode/getfield. Valid values
are 'logical' and 'char'. If set to
'logical', the VRML Bool data type
is returned as a logical value. If set to
'char', the Bool data type is returned
'on' or 'off'. Default is 'logical'.
DataTypeInt32 Specifies handling of the VRML Int32
data type for vrnode/setfield and
vrnode/getfield. Valid values are
'int32' and 'double'. If set to
'int32', the VRML Int32 data type is
returned as int32. If set to 'double',
the Int32 data type is returned as
'double'. Default is 'double'.
10-81
vrsetpref
Preference Description
DataTypeFloat Specifies the handling of the VRML
float data type for vrnode/setfield
and vrnode/getfield. Valid values
are 'single' and 'double'. If set to
'single', the VRML Float and Color
data types are returned as 'single'.
If set to 'double', the Float and
Color data types are returned as
'double'. Default is 'double'.
DefaultCanvasNavPanel Controls the appearance of the control
panel in the vr.canvas object. Values
are:
• 'none'
Panel is not visible.
• 'minimized'
Panel appears as a minimized icon
in the right-hand corner of the
viewer.
• 'translucent'
Panel floats half transparently
above the scene.
• 'opaque'
Panel floats above the scene.
Default: 'none'
DefaultCanvasUnits Specifies default units for new
vr.canvas objects. See vr.canvas
for detailed description. Default is
'normalized'.
10-82
vrsetpref
Preference Description
DefaultFigureAnti Determines whether antialiasing is
Aliasing used by default for new vrfigure
objects. This preference also applies to
new vr.canvas objects. Valid values
are 'off' and 'on'.
DefaultFigureCapture Specifies default file name for
FileName capturing viewer figures. See
vrfigure/get for detailed description.
Default is '%f_anim_%n.tif'.
DefaultFigureDeleteFcn Specifies the default callback invoked
when closing a vrfigure object.
DefaultFigureLighting Specifies whether the lights are
rendered by default for new vrfigure
objects. This preference also applies to
new vr.canvas objects. Valid values
are 'off' and 'on'.
DefaultFigureMax Specifies the default maximum size
TextureSize of a texture used in rendering new
vrfigure objects. This preference
also applies to new vr.canvas objects.
Valid values are 'auto' and 32 <= x
<= video card limit, where x is a power
of 2.
DefaultFigureNavPanel Specifies the default appearance of
the control panel in the viewer. Valid
values are 'opaque', 'translucent',
'none', 'halfbar', 'bar', and
'factory'. Default is 'halfbar'.
10-83
vrsetpref
Preference Description
DefaultFigureNavZones Specifies whether the navigation zone
is on or off by default for new vrfigure
objects. This preference also applies to
new vr.canvas objects. Valid values
are 'off' and 'on'.
DefaultFigurePosition Sets the default initial position and
size of the Simulink 3D Animation
Viewer window. Valid value is a vector
of four doubles.
DefaultFigureRecord2D Specifies the default compression
CompressMethod method for creating 2-D animation
files for new vrfigure objects. Valid
values are '', 'auto', 'lossless',
and 'codec_code'.
DefaultFigureRecord2D Specifies the default quality of 2-D
CompressQuality animation file compression for new
vrfigure objects. Valid values are
0-100.
DefaultFigureRecord2D Specifies the default 2-D offline
FileName animation file name for new vrfigure
objects.
DefaultFigureRecord2DFPS Specifies the default frames per second
playback speed.
To have the 2D AVI animation play
back at approximately the same
playback speed as the 3D VRML
animation, set this preference to auto.
DefaultFigureStatusBar Specifies whether the status bar
appears by default at the bottom of
the Simulink 3D Animation Viewer for
new vrfigure objects. Valid values
are 'off' and 'on'.
10-84
vrsetpref
Preference Description
DefaultFigureTextures Specifies whether textures should be
rendered by default for new vrfigure
objects. This preference also applies
to new vr.canvas objects. See
vrfigure/get for detailed description.
Default is 'on'.
DefaultFigureToolBar Specifies whether the toolbar appears
by default on the Simulink 3D
Animation Viewer for new vrfigure
objects. Valid values are 'off' and
'on'.
DefaultFigure Specifies whether or not transparency
Transparency information is taken into account when
rendering for new vrfigure objects.
This preference also applies to new
vr.canvas objects. Valid values are
'off' and 'on'.
DefaultFigureWireframe Specifies whether objects are drawn
as solids or wireframes by default for
new vrfigure objects. This preference
also applies to new vr.canvas objects.
Valid values are 'off' and 'on'.
10-85
vrsetpref
Preference Description
DefaultViewer Specifies which viewer is used to view
a virtual scene.
• 'internal'
Default Simulink 3D Animation
Viewer. This is the same as setting
the value to 'internalv5' for
all platforms except the Linux
platform.
• 'internalv4'
Legacy Simulink 3D Animation
Viewer.
• 'internalv5'
Viewer based on MATLAB figure
windows.
• 'web'
Web browser becomes viewer. This
is the current Web browser VRML
plug-in.
10-86
vrsetpref
Preference Description
DefaultWorldRecordMode Specifies the default animation
recording mode for new vrworld
objects. Valid values are 'manual' and
'scheduled'.
DefaultWorldRecord Specifies the default start and
Interval stop times for scheduled animation
recording for new vrworld objects.
Valid value is a vector of two doubles.
DefaultWorldRemoteView Specifies whether the virtual world is
enabled by default for remote viewing
for new vrworld objects. Valid values
are 'off' and 'on'.
DefaultWorldTimeSource Specifies the default source of the time
for new vrworld objects. Valid values
are 'external' and 'freerun'.
Editor Path to the VRML editor. If this path
is empty, the MATLAB editor is used.
EditorPreserveLayout Specifies whether the 3D World Editor
starts up with a saved version of the
layout of a virtual world when you
exited it or reverts to the default
layout. The layout of the virtual world
display pane includes settings for the
view, viewpoints, navigation, and
rendering. Valid values are 'off' and
'on'. The default is on (use saved
layout).
10-87
vrsetpref
Preference Description
HttpPort IP port number used to access the
Simulink 3D Animation server over
the Web via HTTP. If you change
this preference, you must restart the
MATLAB software before the change
takes effect.
TransportBuffer Length of the transport buffer (network
packet overlay) for communication
between the Simulink 3D Animation
server and its clients.
TransportTimeout Amount of time the Simulink 3D
Animation server waits for a reply
from the client. If there is no response
from the client, the Simulink 3D
Animation server disconnects from the
client.
VrPort IP port used for communication
between the Simulink 3D Animation
server and its clients. If you change
this preference, you must restart the
MATLAB software before the change
takes effect.
10-88
vrsetpref
10-89
vrsetpref
`%matlabroot\bin\win32\meditor.exe %file'
http://server.name:port_number
10-90
vrsetpref
10-91
vrspacemouse
Property Description
PositionSensitivity Mouse sensitivity for translations. Higher
values correspond to higher sensitivity.
RotationSensitivity Mouse sensitivity for rotations. Higher
values correspond to higher sensitivity.
DisableRotation Fixes the rotations at initial values,
allowing you to change positions only.
DisableTranslation Fixes the positions at the initial values,
allowing you to change rotations only.
DominantMode If this property is true, the mouse
accepts only the prevailing movement
and rotation and ignores the others. This
mode is very useful for beginners using
a space mouse.
UpperPositionLimit Position coordinates for the upper limit of
the mouse.
10-92
vrspacemouse
Property Description
LimitPosition Enables mouse position limits.
If false, the object ignores
the UpperPositionLimit and
LowerPositionLimit properties.
LowerPositionLimit Position coordinates for the lower limit of
the mouse.
NormalizeOutputAngle Determines whether the integrated
rotation angles should wrap on a full
circle (360°). This is not used when you
read the Output Type as Speed.
InitialPosition Initial condition for integrated
translations. This is not used when you
set the Output Type to Speed.
InitialRotation Initial condition for integrated rotations.
This is not used when you set the Output
Type to Speed.
10-93
vrspacemouse
Method Description
position p = position(mouse, n) reads the
position of space mouse axis number
n. n can be a vector to return positions
of multiple axes. Translations and
rotations are integrated. Outputs are the
position and orientation in the form of
roll/pitch/yaw angles.
speed s = speed(mouse, n) reads the speed
of space mouse axis number n. n can be
a vector to return the speeds of multiple
axes. No transformations are done.
Outputs are the translation and rotation
speeds.
viewpoint p = viewpoint(mouse) reads the space
mouse coordinates in VRML viewpoint
format. Translations and rotations are
integrated. Outputs are the position and
orientation in the form of an axis and
an angle. You can use these values as
viewpoint coordinates in VRML.
10-94
vrview
Purpose View virtual world using Simulink 3D Animation viewer or Web browser
Syntax vrview
x = vrview('filename')
x = vrview('filename','-internal')
x = vrview('filename','-web')
Description vrview opens the default Web browser and loads the Simulink 3D
Animation software Web page containing a list of virtual worlds
available for viewing.
x = vrview('filename') creates a virtual world associated with the
.wrl file, opens the virtual world, and displays it in the Simulink 3D
Animation Viewer or the Web browser depending on the value of the
DefaultViewer preference. The handle to the virtual world is returned.
x = vrview('filename','-internal') creates a virtual world
associated with the .wrl file, opens the virtual world, and displays it in
the Simulink 3D Animation Viewer.
x = vrview('filename','-web') creates a virtual world associated
with the .wrl file, opens the virtual world, and displays it in your Web
browser.
vrview('filename#viewpointname') specifies a default viewpoint.
10-95
vrwho
Syntax vrwho
x = vrwho
10-96
vrwhos
Syntax vrwhos
10-97
vrworld
Arguments filename String containing the name of the VRML file from
which the virtual world is loaded. If no file extension
is specified, the file extension .wrl is assumed.
'new' Argument to create a virtual world associated with
filename.
10-98
vrworld
10-99
vrworld/addexternproto
10-100
vrworld/close
Syntax close(vrworld_object)
Description This method changes the virtual world from an opened to a closed state:
• If the world was opened more than once, you must use an appropriate
number of close calls before the virtual world closes.
• If vrworld_object is a vector of vrworld objects, all associated
virtual worlds close.
• If the virtual world is already closed, close does nothing.
Opening and closing virtual worlds is a mechanism of memory
management. When the system needs more memory and the virtual
world is closed, you can discard its contents at any time.
Generally, you should close a virtual world when you no longer need it.
This allows you to reuse the memory it occupied. The vrworld objects
associated with this virtual world stay valid after it is closed, so the
virtual world can be opened again without creating a new vrworld
object.
10-101
vrworld/delete
Syntax delete(vrworld_object)
Description The delete method removes from memory the virtual world associated
with a vrworld object. The virtual world must be closed before you
can delete it.
Deleting a virtual world frees the virtual world from memory and
invalidates all existing vrworld objects associated with the virtual
world.
If vrworld_object is a vector of vrworld objects, all associated virtual
worlds are deleted.
You do not commonly use this method. One of the possible reasons to
use this method is to ensure that a large virtual world is removed from
memory before another memory-consuming operation starts.
10-102
vrworld/edit
Syntax edit(vrworld_object)
Description The edit method opens the VRML file associated with the vrworld
object in a VRML editor. The Editor preference specifies the VRML
editor to use. See vrsetpref for details on setting preferences.
The VRML editor saves any changes you make directly to a virtual
world file. If the virtual world is open,
• Use the save command in the VRML editor to save the changes to
a virtual world file. In the MATLAB interface, the changes appear
after you reload the virtual world.
• Use the save method in the MATLAB software to replace the
modified VRML file. Any changes you made in the editor are lost.
10-103
vrworld/get
Syntax get(vrworld_object)
x = get(vrworld_object)
x = get(vrworld_object, 'property_name')
10-104
vrworld/get
10-105
vrworld/get
10-106
vrworld/get
10-107
vrworld/isvalid
Syntax x = isvalid(vrworld_object)
10-108
vrworld/nodes
Description If you give an output argument, the method nodes returns a cell array
of the names of all available nodes in the world. If you do not give an
output argument, the list of nodes is displayed in the MATLAB window.
You can use the '-full' switch to obtain a detailed list that contains
not only the nodes, but also all their fields. This switch affects only the
output to the MATLAB Command Window.
The virtual world must be open for you to use this method.
10-109
vrworld/open
Syntax open(vrworld_object)
Description The open method opens the virtual world. When the virtual world is
opened for the first time, the virtual world internal representation is
created based on the associated VRML file.
If the input argument is an array of virtual world handles, all the
virtual worlds associated with those handles are opened.
The virtual world must be open for you to use it. You can close the
virtual world with the method close.
You can call the method open more than once, but you must use an
appropriate number of close calls before the virtual world returns to
a closed state.
myworld1 = vrworld('vrmount.wrl')
myworld2 = vrworld('vrpend.wrl')
10-110
vrworld/reload
Syntax reload(vrworld_object)
Description The reload method reloads the virtual world from the VRML file
associated with the vrworld object. If the input argument is an array
of virtual world handles, all the virtual worlds associated with those
handles are reloaded. The virtual world must be open for you to use
this method.
reload forces all the clients currently viewing the virtual world to
reload it. This is useful when there are changes to the VRML file.
10-111
vrworld/save
Description The save method saves the current virtual world to a VRML97 file. The
virtual world must be open for you to use this method.
The resulting file is a VRML97 compliant UTF-8 encoded text file.
Lines are indented using spaces. Line ends are encoded as CR-LF or LF
according to the local system default. Values are separated by spaces.
10-112
vrworld/set
Description You can change the values of the read/write virtual world properties.
The following are properties of vrworld objects. Names are not case
sensitive.
10-113
vrworld/set
10-114
vrworld/set
10-115
vrworld/view
Syntax view(vrworld_object)
x = view(vrworld_object)
x = view(vrworld_object,'-internal')
x = view(vrworld_object,'-web')
Description The view method opens the default VRML viewer on the host computer
and loads the virtual world associated with the vrworld object into
the viewer window. You specify the default VRML viewer using the
DefaultViewer preference. The virtual world must be open for you
to use this method.
x = view(vrworld_object) opens the default VRML viewer on the host
computer and loads the virtual world associated with the vrworld object
into the viewer window. If the Simulink 3D Animation Viewer is used,
view also returns the vrfigure handle of the viewer window. If a Web
browser is used, view returns an empty array of vrfigure handles.
x = view(vrworld_object,’-internal’) opens the virtual world in the
Simulink 3D Animation Viewer.
x = view(vrworld_object,’-web’) opens the virtual world in the Web
browser.
If the virtual world is disabled for viewing (that is, the View property
for the associated vrworld object is set to 'off'), the view method does
nothing.
10-116
Glossary
Glossary
simulation
The process of running a dynamic system in nonreal time to observe
its behavior.
virtual world
An imaginary world where you can navigate around objects in three
dimensions.
VRML
Virtual Reality Modeling Language. See “Virtual Reality Modeling
Language (VRML)” on page 1-11.
Glossary-1