Simulink® 3D Animation™ User's Guide R2015a
How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 Simulink® 3D Animation™ User's Guide © COPYRIGHT 2001–2015 by HUMUSOFT s.r.o. and The MathWorks, Inc. The software described in this document is furnished under a license agreement.
Revision History August 2001 July 2002 October 2002 June 2004 October 2004 March 2005 April 2005 September 2005 First printing Second printing Online only Third printing Fourth printing Online only Online only Online only March 2006 September 2006 March 2007 September 2007 March 2008 October 2008 March 2009 March 2010 September 2010 April 2011 September 2011 March 2012 September 2012 March 2013 September 2013 March 2014 October 2014 March 2015 Online only Online only Online only Online only Online only
Contents 1 2 Getting Started Simulink 3D Animation Product Description . . . . . . . . . . . . Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-2 Expected Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Build Virtual Worlds to Visualize Dynamic Simulations . . . Virtual Reality World Models of Dynamic Systems . . . . . . . . Set up Your Working Environment . . . . . . . . . . . . . . . . . . . . Build a Virtual Reality World .
3 vi Contents Install V-Realm Editor on Host Computer . . . . . . . . . . . . . . . V-Realm Editor Installation (Windows) . . . . . . . . . . . . . . . . . V-Realm Builder Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 2-6 2-7 Set the Default Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Use Preferences to Set the Default Editor . . . . . . . . . . . . . . . Use MATLAB Commands to Set the Default Editor . . . . . . .
4 View Virtual World Remotely . . . . . . . . . . . . . . . . . . . . . . . . 3-16 Working with VRML Sensors . . . . . . . . . . . . . . . . . . . . . . . . . Add VRML Sensors to Virtual Worlds . . . . . . . . . . . . . . . . . Interactive Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Read VRML Sensor Values . . . . . . . . . . . . . . . . . . . . . . . . . 3-22 3-22 3-23 3-23 VR Source Block Input to Simulink Models . . . . . . . . . . . . .
5 Scheduled 2-D AVI Recording with MATLAB . . . . . . . . . . . 4-25 Record Animations for Unconnected Virtual Worlds . . . . . 4-28 Play Animation Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Play VRML Animation Files . . . . . . . . . . . . . . . . . . . . . . . . Play AVI Animation Files . . . . . . . . . . . . . . . . . . . . . . . . . . 4-31 4-31 4-32 Build Virtual Reality Worlds VRML Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 Using the 3D World Editor 3D World Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Supported Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Use with Other Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . VRML Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . VRML Nodes, Library Objects, and Templates . . . . . . . . . . . 6-2 6-2 6-2 6-2 6-3 Open the 3D World Editor . . . . . . . . . . . . . . . . . .
3D World Editor Library . . . . . . . . . . . 3D World Editor Library Objects . . . Add a Library Object . . . . . . . . . . . . Guidelines for Using Custom Objects 7 x Contents .................. .................. ................. ................. 6-24 6-24 6-24 6-25 Viewing Virtual Worlds VRML Viewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Host and Remote Viewing . . . . . . . . . . . . . . . . . . . . . . . . . . . Sound . . . . . . . . . . . . . . . . . . .
Define and Reset Viewpoints . . . . . . . . . . . . . . . . . . . . . . . . . Reset Viewpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Define Viewpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-30 7-30 7-30 Navigate Through Viewpoints . . . . . . . . . . . . . . . . . . . . . . . . 7-34 Record Offline Animations . . . . . . . . . . . . . . . . . . . . . . . . . . . Animation Recording . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8 xii Contents View a Virtual World in Stereoscopic Vision . . . . . . . . . . . . Enable Stereoscopic Vision . . . . . . . . . . . . . . . . . . . . . . . . . Control Stereoscopic Effects . . . . . . . . . . . . . . . . . . . . . . . . 7-62 7-62 7-63 Active Stereoscopic Vision Configuration . . . . . . . . . . . . . . Computer Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Graphics Cards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Display Devices . . . .
9 10 Blocks — Alphabetical List Functions — Alphabetical List Glossary xiii
1 Getting Started • “Simulink 3D Animation Product Description” on page 1-2 • “Expected Background” on page 1-3 • “Build Virtual Worlds to Visualize Dynamic Simulations” on page 1-4 • “Virtual Reality Modeling Language (VRML)” on page 1-10 • “Virtual Reality World and Dynamic System Examples” on page 1-18
1 Getting Started Simulink 3D Animation Product Description Animate, visualize, and interact with models in 3D Simulink 3D Animation provides apps for linking Simulink models and MATLAB® algorithms to 3D graphics objects. It lets you visualize and verify dynamic system behavior in a virtual reality environment. Objects are represented in the Virtual Reality Modeling Language (VRML), a standard 3D modeling language.
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.
1 Getting Started Build Virtual Worlds to Visualize Dynamic Simulations In this section...
Build Virtual Worlds to Visualize Dynamic Simulations Simulink, or SimMechanics. If your computer does not already have a graphics card with hardware 3-D acceleration, consider installing such a card to enhance graphics performance. You build and view the virtual reality world models using VRML (Virtual Reality Modeling Language).
1 Getting Started Invalid MEX-file 'matlab/toolbox/sl3d/sl3d/vrsfunc.mexglx': libGL.so: cannot open shared object file If you see an error like this, set the LD_LIBRARY_PATH environment variable.
Build Virtual Worlds to Visualize Dynamic Simulations • 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.
1 Getting Started 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.
Build Virtual Worlds to Visualize Dynamic Simulations Simulink 3D Animation software is running. This allows others to view an animated virtual world remotely. Multiple clients can connect to one server. See “Orbisnap Standalone Viewer”. • Use the MATLAB Compiler™ to take MATLAB files as input and generate redistributable, standalone applications that include Simulink 3D Animation functionality, including the Simulink 3D Animation Viewer.
1 Getting Started Virtual Reality Modeling Language (VRML) In this section... “VRML History” on page 1-10 “VRML Support” on page 1-11 “VRML Compatibility” on page 1-12 “VRML Coordinate System” on page 1-13 “VRML File Format” on page 1-14 VRML History The Virtual Reality Modeling Language (VRML) is the language you use to display threedimensional objects with a VRML viewer.
Virtual Reality Modeling Language (VRML) VRML97 represents an open and flexible platform for creating interactive threedimensional scenes (virtual worlds). As computers improve in computational power and graphic capability, and communication lines become faster, the use of 3-D graphics becomes more popular outside the traditional domain of art and games. There are now a number of VRML97-enabled browsers available on several platforms.
1 Getting Started The software analyzes the structure of the virtual world, determines what signals are available, and makes them available from the MATLAB and Simulink environment. Simulink 3D Animation software ensures that the changes made to a virtual world are reflected in the MATLAB and Simulink interfaces. If you change the viewpoint in your virtual world, this change occurs in the vrworld object properties in MATLAB and Simulink interfaces.
Virtual Reality Modeling Language (VRML) VRML Coordinate System 1-13
1 Getting Started 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.
Virtual Reality Modeling Language (VRML) gives you a good understanding of how the virtual world elements can be controlled using Simulink 3D Animation software. 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.
1 Getting Started # This is a comment line WorldInfo { title "Bouncing Ball" } Viewpoint { position 0 5 30 description "Side View" } DEF Floor Box { size 6 0.2 6 } DEF Ball Transform { translation 0 10 0 children Shape { appearance Appearance { material Material { diffuseColor 1 0 0 } } geometry Sphere { } } } The first line is the VRML header line. Every VRML file must start with this header line.
Virtual Reality Modeling Language (VRML) 1-17
1 Getting Started Virtual Reality World and Dynamic System Examples In this section... “Simulink Interface Examples” on page 1-18 “MATLAB Interface Examples” on page 1-30 Simulink Interface Examples For all the examples that have a Simulink model, use the following procedure to run the example and view the model: 1 In the MATLAB Command Window, enter the name of a Simulink model. For example, enter: vrbounce A Simulink window opens with the block diagram for the model.
Virtual Reality World and Dynamic System Examples The following table lists the Simulink examples provided with the Simulink 3D Animation product. Descriptions of the examples follow the table.
1 Getting Started Bouncing Ball Example (vrbounce) The vrbounce example represents a ball bouncing from a floor. The ball deforms as it hits the floor, keeping the volume of the ball constant. The deformation is achieved by modifying the scale field of the ball.
Virtual Reality World and Dynamic System Examples Portal Crane with Joystick Control (vrcrane_joystick) The vrcrane_joystick example illustrates how a Simulink model can interact with a virtual world. The portal crane dynamics are modeled in the Simulink interface and visualized in virtual reality. The model uses the Joystick Input block to control the setpoint. Joystick 3 axes control the setpoint position and button 1 starts the crane.
1 Getting Started Portal Crane with Predefined Trajectory Example (vrcrane_traj) The vrcrane_traj example is based on the vrcrane_joystick example, but instead of interactive control, it has a predefined load trajectory. The vrcrane_traj model illustrates a technique to create the visual impression of joining and splitting moving objects in the VRML world. A crane magnet attaches the load box, moves it to a different location, then releases the box and returns to the initial position.
Virtual Reality World and Dynamic System Examples For more details on how to read values from virtual worlds programmatically, see “Working with VRML Sensors”. Magnetic Levitation Model for Simulink Desktop Real-Time Example (vrmaglev_sldrt) In addition to the vrmaglev example, the vrmaglev_sldrt example works directly with the actual CE 152 scale model hardware in real time. This model to work with the HUMUSOFT MF 624 data acquisition board, and Simulink Coder and Simulink Desktop Real-Time™ software.
1 Getting Started The VRML model represents a nuclear hot chamber manipulator. It is manipulated by a simple Simulink model containing the Space Mouse Input block. This model uses all six degrees of freedom of the space mouse for manipulating the mechanical arm, and uses mouse button 1 to close the grip of the manipulator jaws. A space mouse is an input device with six degrees of freedom. It is useful for navigating and manipulating objects in a virtual world.
Virtual Reality World and Dynamic System Examples • Simple collision detection • Simulation of haptic effects 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.
1 Getting Started capability, you can perform massive color changes or morphing. This model morphs a cube into an octahedron and then changes it back to a cube. Vehicle Dynamics Visualization (vr_octavia) The vr_octavia example illustrates the benefits of the visualization of complex dynamic model in the virtual reality environment. It also shows the Simulink 3D Animation 3-D offline animation recording functionality.
Virtual Reality World and Dynamic System Examples objects. In this case, the virtual world displays three graphs that update at each major simulation time step. Vehicle Dynamics Visualization with Live Rear Mirror Image (vr_octavia_mirror) The vr_octavia_mirror example extends the vr_octavia example by showing the capability of the VR Sink block to process video stream on input. In the virtual world, a PixelTexture texture map is defined at the point of the vehicle left rear mirror.
1 Getting Started Inverted Pendulum Example (vrpend) The vrpend example illustrates the various ways a dynamic model in the Simulink interface can interact with a virtual reality scene. It is the model of a two-dimensional inverted pendulum controlled by a PID controller. What distinguishes this model from common inverted pendulum models are the methods for setting the set point. You visualize and interact with a virtual world by using a Trajectory Graph and VR Sink blocks.
Virtual Reality World and Dynamic System Examples Mutual gravity accelerations of the bodies are computed using Simulink matrix-type data support. Plane Takeoff Example (vrtkoff) The vrtkoff example represents a simplified aircraft taking off from a runway. Several viewpoints are defined in this model, both static and attached to the plane, allowing you to see the takeoff from various perspectives.
1 Getting Started MATLAB Interface Examples The following table lists the MATLAB interface examples provided with the software. Descriptions of the examples follow the table. MATLAB interface examples display virtual worlds in your default viewer. If your default is the Simulink 3D Animation Viewer, some buttons are unavailable. In particular, the simulation buttons for simulation and recording are unavailable.
Virtual Reality World and Dynamic System Examples of time-based temperature distribution in an L-shaped metal block is used. The data is then sent to the virtual world. This forms an animation with relatively large changes. This is a step-by-step example.
1 Getting Started 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. This is a step-by-step example.
Virtual Reality World and Dynamic System Examples This example requires the Mapping Toolbox software from MathWorks®. Plane Manipulation Using Space Mouse MATLAB Object This example illustrates how to use a space mouse using the MATLAB interface. After you start this example, a virtual world with an aircraft is displayed in the Simulink 3D Animation Viewer. You can navigate the plane in the scene using a space mouse input device. Press button 1 to place a marker at the current plane position.
2 Installation The Simulink 3D Animation product provides the files you need for installation on both your host computer and client computer.
2 Installation Set the Default Viewer If you install a VRML plug-in in your Web browser, it is possible to view virtual worlds with either the Simulink 3D Animation Viewer, legacy Simulink 3D Animation Viewer, or your Web browser. You determine the viewer used to display your scene using the vrsetpref and vrgetpref commands. (Alternatively, if you want to use the MATLAB File menu Preferences dialog box, see “Set Simulink 3D Animation Preferences” on page 2-11.
Set the Default Viewer DefaultFigureTextures: DefaultFigureToolBar: DefaultFigureTooltips: DefaultFigureTransparency: DefaultFigureTriad: DefaultFigureWireframe: DefaultViewer: DefaultWorldRecord3DFileName: DefaultWorldRecordMode: DefaultWorldRecordInterval: DefaultWorldRemoteView: DefaultWorldTimeSource: Editor: EditorPreserveLayout: EditorSavePosition: HttpPort: TransportBuffer: TransportTimeout: VrPort: 'on' 'on' 'on' 'on' 'none' 'off' 'internal' '%f_anim_%n.
2 Installation 2 Reset the Simulink 3D Animation Viewer as your default viewer by typing vrsetpref('DefaultViewer','factory') 3 In the Simulink 3D Animation Viewer for vrplanets, from the Simulation menu, select Block Parameters. A Parameters: VR Sink dialog box opens.
Set the Default Viewer The target of the View button is determined by the DefaultViewer property. If the DefaultViewer property is set to 'internal', clicking the View button opens the virtual world in the Simulink 3D Animation Viewer. If the DefaultViewer property is set to 'web', clicking the View button opens the virtual world in your Web browser.
2 Installation Install V-Realm Editor on Host Computer In this section... “V-Realm Editor Installation (Windows)” on page 2-6 “V-Realm Builder Help” on page 2-7 V-Realm Editor Installation (Windows) When you install the Simulink 3D Animation product, files are copied to your hard drive for the Ligos V-Realm Builder, which is an optional VRML editor available on Windows platforms. However, the installation is not complete.
Install V-Realm Editor on Host Computer V-Realm Builder Help 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 Installation Set the Default Editor In this section... “Use Preferences to Set the Default Editor” on page 2-8 “Use MATLAB Commands to Set the Default Editor” on page 2-9 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.
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 Installation 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.
Set Simulink 3D Animation Preferences Set Simulink 3D Animation Preferences In this section...
2 Installation Access the Preferences Dialog Box To access the Simulink 3D Animation preferences dialog box: 1 From the MATLAB Toolstrip, in the Home tab, in the Environment section, select Preferences. 2 In the Preferences dialog box left pane, select Simulink 3D Animation. The Simulink 3D Animation Preferences dialog box opens in the right pane.
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. Preference Value Description Bool 'logical' | 'char' Specifies the handling of the VRML Bool data type for vrnode/setfield and vrnode/getfield.
2 Installation Preference Value Default: 'logical' Description 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 VRML Viewer 'internal' | 'internalv4' | 'internalv5' |'web' Specifies which viewer is used to view a virtual world. The default Simulink 3D Animation Viewer is used when the preference is set to 'internal' or 'internalv5'. The legacy viewer is used when this preference is set to 'internalv4'.
Set Simulink 3D Animation Preferences Preference Value Description VRML Editor Built-in 3D World Editor | V-Realm Builder | MATLAB Editor | Custom Specifies which VRML editor to use. Path to the VRML editor. If this path is empty, the MATLAB editor is used. Numeric 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.
2 Installation Property Value Description Triad 'none' | 'top left' | 'top Specifies where in the virtual world display pane to locate a right' | 'bottom left' | triad of coordinate axes. 'bottom right' | 'center' Default: 'bottom left' Preserve Layout per VRML File 'off' | 'on' Default: 'on' Specifies 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.
Set Simulink 3D Animation Preferences Figure Preferences The Simulink 3D Animation figure has a number of preferences: • “Figure Rendering Preferences” on page 2-18 • “Figure 2-D Recording Preferences” on page 2-20 • “Figure Frame Capture Preferences” on page 2-22 Figure Appearance Preferences The figure appearance preferences apply to the 3D World Editor and Simulink 3D Animation Viewer. Some of these preferences also apply to Simulink 3D Animation Web Viewer, as noted below.
2 Installation Property Value Description Navigation zones 'off' | 'on' Specifies whether navigation zones are displayed. Default: 'on' Navigation panel 'off' | 'on' Default: 'on' Position Matrix with upper-right and lower-left corner position. Also applies to the Simulink 3D Animation Web Viewer. Specifies whether navigation panel is displayed. Specifies the default location of the figure window.
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. Property Value Description Antialiasing 'on' | 'off' Determines whether antialiasing is used when rendering scene. Antialiasing smooths textures by interpolating values between texture points.
2 Installation Property Value Description you enter is unsuitable, a warning might trigger. The software then automatically adjusts the property to the next smaller suitable value. Textures 'off' | 'on' Turns texture rendering on or off. Default: 'on' Transparency 'off' | 'on' Default: 'on' Wireframe 'off' | 'on' Default: 'off' Specifies whether or not transparency information is taken into account when rendering. Specifies whether objects are drawn as solids or wireframes.
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. Property Value Description 2-D animated file name String. Specifies the 2-D offline animation file name. The string can contain tokens that are replaced by the corresponding information when the animation recording takes place. For further details, see “File Name Tokens”. Default: '%f_anim_%n.
2 Installation Figure Frame Capture Preferences To access the virtual figure frame capture preferences: 1 From the MATLAB Toolstrip, in the Home tab, in the Environment section, select Preferences. 2 In the left pane of the Preferences dialog box, select Simulink 3D Animation. 3 In the left pane under Simulink 3D Animation, select Figure. The Simulink 3D Animation Figure Preferences dialog box opens in the right pane. 4 Select the Frame Capture tab.
Set Simulink 3D Animation Preferences Virtual World Preferences To access the virtual world preferences: 1 From the MATLAB Toolstrip, in the Home tab, in the Environment section, select Preferences. 2 In the left pane of the Preferences dialog box, select Simulink 3D Animation. 3 In the left pane under Simulink 3D Animation, select World. The Simulink 3D Animation World Preferences dialog box opens in the right pane.
2 Installation 4 Set the preferences as desired. See the following table for the rendering preferences you can change. Click OK to save the settings. Property Value Description Allowing viewing from the Internet 'off' | 'on' Remote access flag.
Set Simulink 3D Animation Preferences Property Value Default: 'off' Description remote viewing, it is set to 'on'; otherwise, it is set to 'off'. 3-D animated file name String. 3-D animation file name. The string can contain tokens that are replaced by the corresponding information when the animation recording takes place. For details, see “File Name Tokens”. Default: '%f_anim_%n.wrl' Recording mode 'manual' | 'scheduled' Animation recording mode.
2 Installation Uninstall V-Realm Builder Use the MathWorks uninstaller. Running this utility removes the Simulink 3D Animation and Ligos V-Realm Builder software from your system. It also restores your previous system configuration. 1 On the Windows task bar, click Start, point to MATLAB, and then click the uninstaller. The MathWorks uninstaller begins running. 2-26 2 Select the Simulink 3D Animation check box. 3 Follow the remaining uninstall instructions.
Test the Viewer Installation Test the Viewer Installation In this section... “Section Overview” on page 2-27 “Simulink Testing” on page 2-27 “MATLAB Testing” on page 2-32 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.
2 Installation The Simulink 3D Animation Viewer opens with a 3-D model of the pendulum.
Test the Viewer Installation 2 In the Simulink 3D Animation Viewer, from the Simulation menu, click Run. A Trajectory Graph window opens, and a simulation starts running.
2 Installation 3 In the Simulink 3D Animation Viewer, point to a position on the blue surface and left-click. 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. In the Simulink 3D Animation Viewer, you see the animated movement of the pendulum. Use the viewer controls to navigate through the virtual world, change the viewpoints, and move the set point.
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. 7 In the Simulink window, from the Simulation menu, click Stop. The trajectory for the pendulum is displayed in the graph as a blue line.
2 Installation 8 Close the Simulink 3D Animation Viewer and close the Simulink window. You can try other examples in “Simulink Interface Examples”, 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. Additional examples are listed in the table “MATLAB Interface Examples”.
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.
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.
3 Simulink Interface Virtual World Connection to a Model In this section... “Add a Simulink 3D Animation Block” on page 3-2 “Changing the Virtual World Associated with a Simulink Block” on page 3-8 Add a Simulink 3D Animation Block To visualize a dynamic system simulation, connect a Simulink block diagram to a virtual world. The example in this section explains how to display a simulated virtual world on a host computer. This is the recommended way to view associated virtual worlds on the host computer.
Virtual World Connection to a Model 2 From the Simulation menu, select Mode > Normal, then click Simulation > Run. Observe the results of the simulation in the scope windows. 3 In the MATLAB Command Window, type vrlib The Simulink 3D Animation library opens. 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.
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 VR Plane taking off 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. 8 Select the Open VRML Viewer automatically parameter.
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. 11 In the Plane (Transform) tree, select the translation and rotation fields. The selected fields are marked with checks. These fields represent the position (translation) and the pitch (rotation) of the plane. 12 Click OK.
3 Simulink Interface The first input is Plane rotation. The rotation is defined by a four-element vector. The first three numbers define the axis of rotation. In this example, it should be [1 0 0] for the x-axis (see the Pitch Axis of Rotation block in the model). The pitch of the plane is expressed by the rotation about the x-axis. The last number is the rotation angle around the x-axis, in radians.
Virtual World Connection to a Model 15 Double-click the VR Sink block in the Simulink model. Select the View button. A viewer window containing the plane's virtual world opens. 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. 16 In the Simulink 3D Animation Viewer, from the Simulation menu, click Run to run the simulation.
3 Simulink Interface Changing the Virtual World Associated with a Simulink Block On occasion, you might want to associate a different virtual world with a Simulink model or connect different signals. 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.
Virtual World Connection to a Model A VRML tree appears on the right side. The Simulink software associates a new virtual world with the model. 5 On the left of the Plane (Transform) node, click the + square. 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.
3 Simulink Interface Open a Viewer Window When you simulate a model that contains a VR Sink block, your default viewer opens and displays the virtual scene. For more information on setting your default viewer, see “Set the Default Viewer”. 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.
Display Virtual World and Start Simulation Display Virtual World and Start Simulation This example explains how to display a simulated virtual world using the Simulink 3D Animation Viewer on your host computer. This is the default and recommended method for viewing virtual worlds. A Simulink window opens with the model of a simple automobile.
3 Simulink Interface 2 In the Simulink 3D Animation Viewer, from the Simulation menu, click Run. The simulation starts. In the Simulink 3D Animation Viewer, a car moves along the mountain road. 3-12 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”. 4 In the Simulink 3D Animation Viewer, from the Simulation menu, click Stop.
View Virtual World on Host Computer View Virtual World on Host Computer Normally, you view a virtual world by double-clicking the VR Sink in the Simulink model. The virtual world opens in the Simulink 3D Animation Viewer or your VRMLenabled Web browser, depending on your DefaultViewer setting. For more information on setting your default viewer, see “Set the Default Viewer”. Alternatively, you can view a virtual world in your Web browser by selecting an open virtual world from a list in your Web browser.
3 Simulink Interface The following page is loaded and becomes active. 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 Click VR Bouncing Ball. The VR Bouncing Ball virtual world appears in your Web browser.
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 Simulink Interface View Virtual World Remotely The Simulink 3D Animation software allows you to simulate a process on a host computer while running the visualization of the process on a client computer. You view the virtual world on the client computer using a Web browser. This client computer is connected to the host computer through a network using the TCP/IP protocol. This means you need to know the name or IP address of the host computer you want to access from the client computer.
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 In the VRML viewer, select the Simulation menu Block Parameters option. A Parameters: VR Sink dialog box opens.
3 Simulink Interface 4 Select the Allow viewing from the Internet check box. 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. 6 On the client computer, open your VRML-enabled Web browser. In the Address line, enter the address and Simulink 3D Animation port number for the host computer running the Simulink software.
View Virtual World Remotely 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. 7 Click VR Car in the Mountains. The Web browser displays a 3-D model of the virtual world associated with the model.
3 Simulink Interface 8 On the host computer, in the Simulink window, from the Simulation menu, click Run. 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 3-20 Use the Web browser controls to move within this virtual world while the simulation is running.
View Virtual World Remotely 10 On the host computer, in the Simulink window, from the Simulation menu, click Stop. On the client computer, close the Web browser window.
3 Simulink Interface Working with VRML Sensors In this section... “Add VRML Sensors to Virtual Worlds” on page 3-22 “Interactive Mode” on page 3-23 “Read VRML Sensor Values” on page 3-23 Add VRML Sensors to Virtual Worlds This section describes how to interface a Simulink block diagram to sensors in a virtual reality scene. It also describes how to programmatically input signals from the virtual world into a simulation model.
Working with VRML Sensors Sensors Description 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.
3 Simulink Interface nh = vrnode(wh, 'Grab_Sensor'); % synchronize the translation field sync(nh, 'translation', 'on'); % 3 alternative ways to read the synchronized field value setpoint = getfield(nh, 'translation'); setpoint = nh.translation; setpoint = wh.Grab_Sensor.translation; 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.
Working with VRML Sensors ROUTE Grab_Sensor.translation_changed TO Ball.translation • 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.
3 Simulink Interface VR Source Block Input to Simulink Models The VR Source reads values from virtual world fields specified in the Block Parameters dialog box and inputs their values. Use the VR Source block to provide interactivity between a user navigating the virtual world and the Simulink model. The VR Source block registers user interactions with the virtual world and passes to the model values that can affect the simulation of the model.
Interact with Generated Code Interact with Generated Code You can have a virtual world that you create the Simulink 3D Animation product interact with code generated by the Simulink Coder product and compiled with a thirdparty C/C++ compiler in the Simulink Desktop Real-Time environment. To do so, use the Simulink External mode.
4 MATLAB Interface Although using the Simulink 3D Animation software with the Simulink interface is the preferred way of working with the Simulink 3D Animation software, you can also use the MATLAB interface. Enter commands directly in the MATLAB Command Window or use scripts to control virtual worlds.
4 MATLAB Interface Create vrworld Object for a Virtual World To connect MATLAB to a virtual world and to interact with that virtual world through the MATLAB command-line interface, you need to create vrworld and vrnode objects. A virtual world is defined by a VRML file with the extension .wrl. Note The Simulink interface and the MATLAB interface share the same virtual world objects.
Create vrworld Object for a Virtual World 1 Open MATLAB. In the MATLAB Command Window, type myworld = vrworld('vrmount.wrl') The MATLAB Command Window displays output like myworld = vrworld object: 1-by-1 VR Car in the Mountains (matlabroot/toolbox/sl3d/vrdemos/vrmount.wrl) 2 Type vrwhos The MATLAB Command Window displays the messages Closed, associated with 'C:matlabroot\toolbox\sl3d\sl3ddemos\vrmount.wrl'. Visible for local viewers. No clients are logged on.
4 MATLAB Interface Open a Virtual World with MATLAB Opening a virtual world lets you view the virtual world in a VRML viewer, scan its structure, and change virtual world properties from the MATLAB Command Window. 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.
Open a Virtual World with MATLAB 3 If the Web browser has the VRML plug-in installed, in the browser window, click My first virtual world. 4 Your default VRML-enabled Web browser displays the virtual world vrmount.wrl. Note If your Web browser is not VRML-enabled, clicking on a virtual world link such as My first virtual world results in a broken link message. The browser cannot display the virtual world. For more information on changing your default viewer, see “Set the Default Viewer” on page 2-2.
4 MATLAB Interface Interact with a Virtual World with MATLAB In the life cycle of a vrworld object you can set new values for all the available virtual world nodes and their fields using vrnode object methods. This way, you can change and control the degrees of freedom for the virtual world from within the MATLAB environment. 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.
Interact with a Virtual World with MATLAB mynodes = vrnode object: 13-by-1 Tunnel (Transform) [My first virtual world] Road (Shape) [My first virtual world] Bridge (Shape) [My first virtual world] River (Shape) [My first virtual world] ElevApp (Appearance) [My first virtual world] Canal (Shape) [My first virtual world] Wood (Group) [My first virtual world] Tree1 (Group) [My first virtual world] Wheel (Shape) [My first virtual world] Automobile (Transform) [My first virtual world] VPfollow (Viewpoint) [My f
4 MATLAB Interface ----------------------------------------------------------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.
Close and Delete a vrworld Object Close and Delete a vrworld Object After you are finished with a session, you must close all open virtual worlds and remove them from memory: 1 In the MATLAB Command Window, type close(myworld); delete(myworld); The virtual world representation of the vrworld object myworld is removed from memory. All possible connections to the viewer and browser are closed and the virtual world name is removed from the list of available worlds.
4 MATLAB Interface Animation Recording In this section... “Recording Formats” on page 4-10 “Manual and Scheduled Animation Recording” on page 4-11 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 through either the Simulink 3D Animation Viewer (described in “Simulink 3D Animation Viewer”) or the MATLAB interface.
Animation Recording vrfigure objects to record 2-D animation files. The recorded 2-D animation reflects exactly what you see in the viewer window. It includes any navigation movements you make during the recording. 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 MATLAB Interface File Name Tokens The Simulink 3D Animation software supports a variety of file naming formats using file tokens. By default, the Simulink 3D Animation Viewer captures virtual scene frames or records simulations in a file named with the following format: %f_anim_%n. 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-13.
Define File Name Tokens Define File Name Tokens In this section... “Default File Name Format” on page 4-13 “Uses for File Name Tokens” on page 4-13 Default File Name Format By default, the Simulink 3D Animation Viewer captures virtual scene frames or records simulations in a file named with the following format: %f_anim_%n. This format creates a unique file name each time you capture a frame or record the animation. %f and %n are tokens.
4 MATLAB Interface 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-15 for a summary of the file name tokens.
File Name Tokens File Name Tokens The following tokens are the same for frame capture (.tif or .png) or animation (.wrl and .avi) files. 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.
4 MATLAB Interface 4-16 Token Description %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.
Manual 3-D VRML Recording with MATLAB Manual 3-D VRML Recording with MATLAB This topic describes how to manually record a 3-D animation using the MATLAB interface for a virtual world that is associated with a Simulink model. In this example, the timing of the animation file derives from the simulation time. One second of the recorded animation time corresponds to one second of Simulink time.
4 MATLAB Interface 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.
Manual 2-D AVI Recording with MATLAB Manual 2-D AVI Recording with MATLAB This topic describes how to manually record a 2-D animation using the MATLAB interface for a virtual world that is associated with a Simulink model. In this example, the timing of the animation file derives from the simulation time. One second of the recorded animation time corresponds to one second of Simulink time.
4 MATLAB Interface If the description string is unique, myworld is assigned the correct virtual world. 4 To retrieve the handle to the currently displayed the Simulink 3D Animation Viewer figure, type f=get(myworld,'Figures') 5 To have the software manually record the animation, set the RecordMode property to manual. Type set(myworld,'RecordMode','manual'); 6 Direct the Simulink 3D Animation software to record the animation as a .avi format file.
Manual 2-D AVI Recording with MATLAB The Simulink 3D Animation software stops recording the animation. The Simulink 3D Animation software creates the file vrplanets_anim_1.avi in the current working folder. If the simulation stops before you stop recording, the recording operation stops and creates the animation file. 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.
4 MATLAB Interface Scheduled 3-D VRML Recording with MATLAB This topic describes how to schedule the recording of a 3-D animation using the MATLAB interface for a virtual world that is associated with a Simulink model. You control the animation file recording by presetting a time interval. The Simulink 3D Animation software records the animation during this interval in the simulation. In this example, the timing of the recorded animation file derives from the simulation time.
Scheduled 3-D VRML Recording with MATLAB 4 Direct the Simulink 3D Animation software to record the animation on a schedule by setting the RecordMode property to scheduled. Type set(myworld,'RecordMode','scheduled'); 5 Direct the Simulink 3D Animation software to record the animation in a VRML format file. 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.
4 MATLAB Interface • From the keyboard, press Ctrl+T to stop the simulation. 9 4-24 Close and delete the objects if you do not want to continue using them.
Scheduled 2-D AVI Recording with MATLAB Scheduled 2-D AVI Recording with MATLAB This topic describes how to schedule the recording of a 2-D animation using the MATLAB interface for a virtual world that is associated with a Simulink model. You control the animation file recording by presetting a time interval. The Simulink 3D Animation software records the animation during this interval in the simulation. In this example, the timing of the recorded animation file derives from the simulation time.
4 MATLAB Interface 3 To retrieve the handle to the currently displayed Simulink 3D Animation Viewer figure, type f=get(myworld,'Figures') 4 To have the Simulink 3D Animation software manually record the animation, set the RecordMode property to manual. Type set(myworld,'RecordMode','scheduled'); 5 Direct the Simulink 3D Animation software to record the animation as an .avi format file. Type set(f,'Record2D','on'); 6 Select the start and stop times during which you want to record the animation.
Scheduled 2-D AVI Recording with MATLAB The simulation runs. The Simulink 3D Animation software starts recording when the simulation time reaches the specified start time and creates the file vrplanets_anim_N.avi in the current working folder when finished, where N is either 1 or more, depending on how many file iterations you have. 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.
4 MATLAB Interface Record Animations for Unconnected Virtual Worlds This topic describes how to programmatically record animation files for virtual worlds that are not associated with Simulink models (in other words, from the MATLAB interface). In this instance, you must specify the relationship between the events that change the virtual world state and the time in the animation file. This requirement is different from virtual worlds associated with Simulink models.
Record Animations for Unconnected Virtual Worlds 1 Retrieve the corresponding vrworld object. 2 Set the Record3D vrworld property. 3 To override default filenames for animation files, set the vrworld Record3DFileName property. • Set the RecordMode vrworld object property to manual or scheduled. For optimal results, select scheduled. • If you select scheduled for RecordMode, be sure to also set the vrworld RecordInterval property to a desired time interval.
4 MATLAB Interface 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.
Play Animation Files Play Animation Files In this section... “Play VRML Animation Files” on page 4-31 “Play AVI Animation Files” on page 4-32 Play VRML Animation Files You can view VRML animation files using one of these approaches: • Open the 3D Animation Player from the MATLAB Toolstrip. To open the 3D Animation Player from the MATLAB Toolstrip, in the Apps tab, in the Simulation Graphics and Reporting section, click 3D Animation Player. Select or specify an a VRML animation file.
4 MATLAB Interface The vrview command displays the default Simulink 3D Animation Viewer for the animation file. Setting the TimeSource property of the set method to 'freerun' directs the viewer to advance its time independent of the MATLAB software.
5 Build Virtual Reality Worlds 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.
5 Build Virtual Reality Worlds VRML Editors Editors for Virtual Worlds There is more than one way to create a virtual world defined with VRML code. For example, you can use a text editor to write VRML code directly, or you can use a VRML editor to create a virtual world without knowing anything about the VRML language. However, you must understand the structure of a VRML scene to connect your virtual world to Simulink blocks and signals.
VRML Editors • “Native VRML Editors” on page 5-4 • “3D World Editor” on page 5-4 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.
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.
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. • Virtual world display pane — Observe the virtual world as you create it. The 3D World Editor renders inlined objects (grouped objects).
5 Build Virtual Reality Worlds Ligos V-Realm Builder The Ligos V-Realm Builder interface is available only for Windows operating systems. The V-Realm Builder application is a flexible, graphically oriented tool for 3-D editing. It provides similar functionality as the 3D World Editor.
Build and Connect a Virtual World Build and Connect a Virtual World In this section... “Introduction” on page 5-7 “Define the Problem” on page 5-7 “Add a Simulink 3D Animation Block” on page 5-9 “Open a New Virtual World” on page 5-10 “Add VRML Nodes” on page 5-11 “Link to a Simulink Model” on page 5-20 Introduction The example in this section shows you how to create a simple virtual world using the 3D World Editor.
5 Build Virtual Reality Worlds The following table lists the positions and dimensions of the objects that you create for this example. Object Center Position Dimensions B1 [3 0 0] [0.3 1 1] B2 [-3 0 0] [0.3 1 1] S [0 0 0] r = 0.9 The Simulink 3D Animation product includes the tutorial model vrtut3. This is a simplified model in which the deformation of an elastic sphere is simulated.
Build and Connect a Virtual World 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.
5 Build Virtual Reality Worlds 4 From the MATLAB Command Window, type vrlib The Simulink 3D Animation library opens. 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-10. Open a New Virtual World You must create a virtual world to connect to a Simulink model for visualizing signals.
Build and Connect a Virtual World • In the left pane, a VRML tree with only a ROOT node • In the right pane, an empty virtual world • In the bottom pane, an empty pane for editing objects 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.
5 Build Virtual Reality Worlds 4 5 5-12 a Right-click the Transform node. b Select the Edit Name menu item. c In the edit box to the left of the Transform node, type B1 . Add a Shape node: a Expand the B1 Transform node. b Select the children node. c Add a Shape node, using the following sequence of menu selections: Add an Appearance node for the Shape node: a Under the Shape node, select the appearance (SFNode) node.
Build and Connect a Virtual World 6 7 Add a Material node to the Appearance node: a Expand the (Appearance) node and select the material(SFNode) node. b Add a Material node, using the following sequence of menu selections. Add a Box node to the geometry node: a Select the geometry(SFNode) node of the (Shape) node. b Add a Box node, using the following sequence of menu selections.
5 Build Virtual Reality Worlds With all the nodes expanded, the 3D World Editor now displays a box in the virtual world display pane.
Build and Connect a Virtual World a Select the size property of the Box node. b In the object properties edit pane at the bottom of the 3D World Editor, enter 0.3 in the first column, and 1 in the second and third columns. c Click Apply. The box becomes smaller. 9 Move the box to the right by changing the translation(SFVec3f) property of the B1(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 Build Virtual Reality Worlds 10 Add a second box that is very similar to the first box. 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.
Build and Connect a Virtual World 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 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. 2 In the tree in the left pane, click ROOT node. 3 Add a Sphere node.
Build and Connect a Virtual World 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. 6 Save the virtual world file. 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 Build Virtual Reality Worlds Link to a Simulink Model After you create a virtual world and a Simulink model, and add a VR Sink block to your model, you can define the associations between the model signals and the virtual world. This procedure uses the model vrtut3 as an example. It assumes that you have opened the model and that you have added a VR Sink block, and that you have created a virtual world called vrtut3.wrl. See the tutorial starting with “Add a Simulink 3D Animation Block” on page 5-9.
Build and Connect a Virtual World 10 Double-click the VR Sink block. The viewer appears. 11 Select the Simulation menu Block Parameters option. Your default viewer opens and displays the virtual world. For more information on changing your default viewer, see “Set the Default Viewer”. 12 In the Parameters: VR Sink dialog box, click the View button.
5 Build Virtual Reality Worlds 13 In the Simulink window, from the Simulation menu, click Run. 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.
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 Build Virtual Reality Worlds VRML Data Types In this section... “Section Overview” on page 5-24 “VRML Field Data Types” on page 5-24 “VRML Data Class Types” on page 5-26 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.
VRML Data Types VRML Type Description Simulink 3D Animation Type SFColor Vector of three floating-point values you use for RGB color specification. Single array (1-by-3) SFRotation Vector of four floating-point values you use for specifying rotation coordinates (x, y, z) of an axis plus rotation angle around that axis. Single array (1-by-4) SFImage Two-dimensional array represented by a sequence of floating-point numbers. uint8 array (n-by-m-by-3) SFString String in UTF-8 encoding.
5 Build Virtual Reality Worlds To ensure backward compatibility with existing models and applications, use the Simulink 3D Animation vrsetpref function to define the data type support. Their names are as follows: 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.
VRML Data Types 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.
5 Build Virtual Reality Worlds Simulink 3D Animation Textures The following are texture file recommendations for Simulink 3D Animation models: • Where possible, scale source texture files to a size equal to a power of 2 in both dimensions. Doing so ensures optimal performance for the Simulink 3D Animation viewer. If you do not perform this scaling, the Simulink 3D Animation viewer might attempt to descale the image or create textures with undesired resolutions.
Add Sound to a Virtual World Add Sound to a Virtual World To add sound to a virtual world, use a VRML Sound node. You can include an AudioClip node in a Sound node. For an AudioClip node, use a mono or stereo WAV file in uncompressed PCM format. To listen to the sound, use a computer that supports sound. For details, see “Listen to Sound in a Virtual World”. Note: A stereo sound source retains its channel separation during playback.
5 Build Virtual Reality Worlds Using CAD Models with the Simulink 3D Animation Product In this section...
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.
5 Build Virtual Reality Worlds have VRML export filters, but there are conversion utilities available from third parties if the export filter is not directly available in the CAD tool. 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).
Using CAD Models with the Simulink 3D Animation Product Level of Detail Considerations CAD models are usually parametric models that use proprietary object rendering methods for use in various contexts. During VRML model export, the internal parametric model of the assembly is tessellated. In this process, the model surface is divided into triangular meshes, represented in VRML by the IndexedFaceSet nodes.
5 Build Virtual Reality Worlds aircraft operation in space). For such navigation to be successful, the scene's author must define the NavigationInfo parameters correctly. Coordinate System Used VRML uses a Cartesian coordinate system with axes defined so that: • +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.
Using CAD Models with the Simulink 3D Animation Product 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: • If all parts in the Simulink or SimMechanics model are defined in global coordinates, use a flat virtual world structure.
5 Build Virtual Reality Worlds 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.
Using CAD Models with the Simulink 3D Animation Product 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 Build Virtual Reality Worlds 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.
Using CAD Models with the Simulink 3D Animation Product • “Wrap Shape Objects with Transforms” on page 5-39 • “Add DEF Names” on page 5-39 Wrap Shape Objects with Transforms CAD tools export parts into VRML as individual shapes using various VRML object types (e.g., a VRML Shape node or the Inline mechanism). To control part positions and orientations, you need to wrap each such Shape or Inline node with a node that allows for the changing of these properties.
5 Build Virtual Reality Worlds DEF Robot_Arm1 Transform { children [ Inline { url ["robot_arm1.wrl"] } ] } 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. Note: Sometimes it is necessary to correct bugs introduced in the file by the CAD tool export filter.
Using CAD Models with the Simulink 3D Animation Product objects in the scene hierarchy. For an example of a viewpoint moving with the object, see the viewpoint Ride on the Plane in the Simulink 3D Animation vrtkoff.wrl example. 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.
5 Build Virtual Reality Worlds 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. 3 For smooth visualization of the movement, it is sometimes necessary to change the block's Sample time.
Using CAD Models with the Simulink 3D Animation Product 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: • When all parts in a Simulink model are defined in global coordinates, and the virtual world has a flat structure of independent objects, use the following positions and rotations.
5 Build Virtual Reality Worlds center of rotation to coincide with the joint connecting the hand and the tool in the hand’s local coordinates. In a hierarchical scene structure, when the parts are connected by revolving joints, it is easy to define the relative rotations between parts. The joint axis directly defines the VRML rotation axis, so constructing the [axis angle] four-element VRML rotation vector is trivial.
Using CAD Models with the Simulink 3D Animation Product a three-component vector in the VR Sink block. The remaining vector elements are filled with placeholder signals. Use of the VR Signal Expander block is also a possibility when defining rotations.
5 Build Virtual Reality Worlds 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.
Using CAD Models with the Simulink 3D Animation Product When exporting products, the CATIA software creates one compound VRML file that contains all the parts of the 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: 1 Save each part individually to a separate VRML file. 2 Create the main model VRML file manually, with Inline references to the part files.
5 Build Virtual Reality Worlds 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.
Using CAD Models with the Simulink 3D Animation Product 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. The following contains the VRML model of a cylinder assembly consisting of four parts: 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.
5 Build Virtual Reality Worlds • CylinderSleeve1 • 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.
Using CAD Models with the Simulink 3D Animation Product • The main Transform representing the CATIA product is always scaled by a factor of 0.001 (conversion from millimeters to meters), regardless of the units used in the CATIA document Adjusting Resulting VRML files Adjust exported VRML files to use the exported VRML models with the Simulink 3D Animation software.
5 Build Virtual Reality Worlds 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.
6 Using the 3D World Editor • “3D World Editor” on page 6-2 • “Open the 3D World Editor” on page 6-5 • “3D World Editor Panes” on page 6-7 • “Create a Virtual World” on page 6-9 • “Basic Editing” on page 6-11 • “Reduce Number of Polygons for Shapes” on page 6-19 • “Virtual World Navigation in 3D World Editor” on page 6-20 • “3D World Editor Library” on page 6-24
6 Using the 3D World Editor 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 The 3D World Editor is a native VRML editor. For an example that shows how to see the 3D World Editor to create a virtual world, see “Build and Connect a Virtual World”. Supported Platforms The 3D World Editor works on all supported platforms for the Simulink 3D Animation product.
3D World Editor For general VRML limitations relating to the Simulink 3D Animation software as a whole, see “VRML Compatibility”. PixelTexture Nodes You cannot create or edit PixelTexture node image contents. Existing PixelTexture node image contents are fully preserved VRML Nodes, Library Objects, and Templates Use the 3D World Editor to specify VRML to create 3-D virtual worlds that you can connect to a Simulink model. Use the 3D World Editor to: • Assemble VRML nodes to create a virtual world.
6 Using the 3D World Editor To access templates, use one of the following approaches: • Select File > New From Template. • Select the New File From Template button ( ). 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.
Open the 3D World Editor Open the 3D World Editor In this section... “3D World Editor Is the Default Editor” on page 6-5 “Open an Empty Virtual World” on page 6-5 “Open a Saved Virtual World” on page 6-6 “Preferences for 3D World Editor Startup” on page 6-6 3D World Editor Is the Default Editor When you install the Simulink 3D Animation product, the 3D World Editor is configured to be the default editor. For details about changing the default editor, see “Set the Default Editor”).
6 Using the 3D World Editor Open a Saved Virtual World Use one of these approaches to open a saved virtual world. • 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.
3D World Editor Panes 3D World Editor Panes The 3D World Editor provides three panes: • 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. Use the tree structure pane interactively create graphical VRML elements and to view of all the VRML structure elements present in the virtual world.
6 Using the 3D World Editor 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 virtual world display pane to display a graphical representation of a 3-D scene. Use the object properties edit pane to edit a selected property or add a comment to a selected node or property.
Create a Virtual World Create a Virtual World There are a number of tasks involved in creating a virtual world. You can use the 3D World Editor throughout the process of building a virtual world, and you can perform activities in many different ways. For a step-by-step tutorial about building a virtual world using the 3D World Editor, see “Build and Connect a Virtual World”. In general, the following is a common workflow for creating a virtual world using the 3D World Editor.
6 Using the 3D World Editor • You can use Orbisnap to view library objects to determine which objects you want to insert into the virtual world.
Basic Editing Basic Editing In this section...
6 Using the 3D World Editor Approach Use a context menu for a node Insert an object from a library Procedure 2 Select Nodes > Add. 3 Select appropriate submenus to add the node that you want. 1 In the tree structure pane, right-click the parent node for the object that you want to add. 2 Select the Add Node menu, and then select appropriate submenus to add the node that you want.
Basic Editing • An explicit text copy allows you to edit properties of that node, independently from the original node that you copied. • A referenced copy node appears with the term USE. Referenced copies streamline the tree structure pane display. Edits that you make to the original (referenced) node are applied to the copied node, ensuring that the two nodes remain exact copies of each other. To copy and paste a node: 1 In the tree structure pane, select the node that you want to copy.
6 Using the 3D World Editor Set Viewpoint Values in the 3D World Editor Based on Camera Position You can use the current camera position to interactively specify a viewpoint in the 3D World Editor. 1 Navigate to the position in the scene where you want the viewpoint. 2 In the tree structure pane, right-click a Viewpoint node. 3 Select Copy values from current camera. Specify a URL For objects that have a URL field, to specify a URL, select the node and use one of these approaches.
Basic Editing Document a Virtual World Using Comments To document a virtual world, in the object property edit pane, use the Comments tab for nodes and properties. Comments can help others understand the design of a virtual world. 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 #. Display Event Fields You can display eventIn and eventOut fields in the 3D World Editor tree pane.
6 Using the 3D World Editor Wrap Nodes as Children of Another Node To wrap contiguous nodes as children of another node: 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. 3 From the list of nodes, select the node in which you want to wrap the selected nodes.
Basic Editing • On the toolbar, click the scissors button. • Select Edit > Cut. • Right-click the node and select Cut. Save and Export Virtual World Files You can save your virtual world files as VRML (.wrl) files using the File > Save or File > Save As menu items. 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.
6 Using the 3D World Editor 2 Select the appropriate Add Interface Item menu option. The following is an example of a Script node in the Tree structure pane. For a url node, click the node and either specify the path to a JavaScript® file or enter the URL code in the Object property edit pane.
Reduce Number of Polygons for Shapes Reduce Number of Polygons for Shapes For a node that is, or includes, an IndexedFaceSet node, you can improve rendering speed by reducing the number of polygons in the IndexedFaceSet. Choose the polygon reduction factor that produces your desired balance of rendering performance and quality. To reduce the number of polygons: 1 Right-click an IndexedFaceSet node, or a node that includes one or more IndexedFaceSet nodes. 2 Select Optimize Child Geometries.
6 Using the 3D World Editor Virtual World Navigation in 3D World Editor In this section... “Specify Virtual World Rendering” on page 6-20 “Basic Navigation” on page 6-20 “Coordinate Axes Triad” on page 6-20 “View Panes” on page 6-21 “Pivot Point” on page 6-23 Specify Virtual World Rendering You can control the rendering used in the virtual world display pane of the 3D World Editor. Right-click in the virtual world display pane and set rendering options, such as antialiasing, lighting, and transparency.
Virtual World Navigation in 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. To change the default location or visibility of the triad: 1 From the MATLAB Toolstrip, in the Home tab, in the Environment section, select Preferences. 2 In the Preferences dialog box left pane, select Simulink 3D Animation > 3D World Editor > Triad.
6 Using the 3D World Editor You can also use toolbar buttons to set view panes: 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. New View Pane Option Grid View Panes Displayed Horizontal Split Left two panes Vertical Split Top two panes Single View Top left pane To change the relative size of a panes, select one of the gray borders for a view pane and drag the cursor.
Virtual World Navigation in 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 Using the 3D World Editor 3D World Editor Library In this section... “3D World Editor Library Objects” on page 6-24 “Add a Library Object” on page 6-24 “Guidelines for Using Custom Objects” on page 6-25 3D World Editor Library Objects The 3D World Editor includes a library of virtual world objects, which you can insert into a virtual world. The library consists of component, texture, and material objects.
3D World Editor Library • 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”.
7 Viewing Virtual Worlds • “VRML Viewers” on page 7-2 • “Simulink 3D Animation Viewer” on page 7-4 • “Open the Simulink 3D Animation Viewer” on page 7-8 • “Simulate with the Simulink 3D Animation Viewer” on page 7-9 • “Specify Rendering Techniques” on page 7-10 • “Navigate Using the Simulink 3D Animation Viewer” on page 7-18 • “Viewpoints” on page 7-28 • “Define and Reset Viewpoints” on page 7-30 • “Navigate Through Viewpoints” on page 7-34 • “Record Offline Animations” on page 7-38 • “Play Animations with
7 Viewing Virtual Worlds VRML Viewers In this section... “Host and Remote Viewing” on page 7-2 “Sound” on page 7-3 “Comparison of Viewers” on page 7-3 “Legacy Viewer” on page 7-3 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. The Simulink 3D Animation product includes three viewers.
VRML Viewers 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.
7 Viewing Virtual Worlds Simulink 3D Animation Viewer In this section... “What You Can Do with the Viewer” on page 7-4 “Viewer Uses MATLAB Figures” on page 7-6 “Set Viewer Appearance Preferences” on page 7-7 What You Can Do with the Viewer This section provides an overview of the features and controls of the viewer.
Simulink 3D Animation Viewer 1 Select a Simulink 3D Animation example and type that example’s name in the MATLAB Command Window. For example: vrpend The Simulink model is displayed. By default, the Simulink 3D Animation viewer for that model is loaded and becomes active. If the viewer is not displayed, double-click the VR Sink block in the Simulink model. 2 Inspect the viewer window. The Simulink 3D Animation viewer displays the virtual scene. The top of the viewer contains a menu bar and toolbar.
7 Viewing Virtual Worlds Note The Simulink 3D Animation viewer settings are saved when you save your model file. Viewer Uses MATLAB Figures The Simulink 3D Animation software contains a viewer as the default method for viewing virtual worlds. You can use this viewer on any supported operating system. This viewer uses MATLAB figures.
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: • Right-click in the viewer window to display a context menu that contains the viewer commands. For example: • Combine multiple virtual reality viewer figures in several tiles of a MATLAB figure.
7 Viewing Virtual Worlds Open the Simulink 3D Animation Viewer In this section... “Open from the VR Sink Block” on page 7-8 “Open from the Command Line” on page 7-8 Open from the VR Sink Block You can open the Simulink 3D Animation Viewer by double-clicking a VR Sink block in the Simulink Editor. You can configure a VR Sink block to automatically open the Simulink 3D Animation Viewer. 1 In the Simulink Editor, double-click the VR Sink block to open the Simulink 3D Animation Viewer.
Simulate with the Simulink 3D Animation Viewer Simulate with the Simulink 3D Animation Viewer You can start and stop simulations of the virtual world from the Simulink 3D Animation viewer through the menu bar, toolbar, or keyboard. • 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.
7 Viewing Virtual Worlds Specify Rendering Techniques You can change the rendering of the scene through the controls on the navigation panel or options on the rendering menu. The vrpend and vrplanets examples are used to show the viewer's functionality. 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.
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. The scene looks darker when Headlight is set to off.
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.
Specify Rendering Techniques If Transparency is off, transparent objects are rendered as solid objects.
7 Viewing Virtual Worlds Turning Wireframe on changes the scene's objects from solid to wireframe rendering. The following is the vrpend example with Wireframe on.
Specify Rendering Techniques If Textures is on, objects have texture in the virtual scene. The following is the vrplanets example with Textures on.
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.
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 class MaxTextureSize property for further details.
7 Viewing Virtual Worlds Navigate Using the Simulink 3D Animation Viewer In this section...
Navigate Using the Simulink 3D Animation Viewer Navigation methods — Navigation with the mouse depends on the navigation method that you select and the navigation zone that you are in when you first click and hold down the mouse button. You can set the navigation method using one of the following: • 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-23.
7 Viewing Virtual Worlds 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.
Navigate Using the Simulink 3D Animation Viewer If you have multiple viewers open, the navigation panel in the active viewer is blue. Minimize the Navigation Panel You can minimize the navigation panel using one of these approaches: • 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 Viewing Virtual Worlds Viewer Keyboard Shortcuts 7-22 Navigation Function Keyboard Shortcut Use full-screen mode. Ctrl+f Undo move. Backspace Start or stop recording. Ctrl+r Capture frame. Ctrl+i Start or stop simulation. Ctrl+t Straighten up and make the camera stand on the horizontal plane of its local coordinates. F9 Zoom in and out. +/- Toggle the headlight on and off. F6 Toggle the navigation zones on and off. F7 Toggle the wireframe option on and off.
Navigate Using the Simulink 3D Animation Viewer Navigation Function Keyboard Shortcut Pressing Ctrl alone acquires the examine lock at the point of intersection between the line perpendicular to the screen, coming through the center of the viewer window, and the closest visible surface to the camera. Pressing the arrow keys without releasing Ctrl rotates the viewpoint about the acquired center point. Ctrl+Left/Right/ Up/Down Arrow Tilt the camera right and left.
7 Viewing Virtual Worlds 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-24. 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.
Navigate Using the Simulink 3D Animation Viewer 2 In the Simulink Editor window, from the Simulation menu, choose Run. The example starts running. 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.
7 Viewing Virtual Worlds parallel with global x, y, and z coordinate axes. As you navigate in a virtual world, the triad display changes to reflect changes in orientation . 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.
Navigate Using the Simulink 3D Animation Viewer To set the pivot point in a virtual world, hold CRTL and double-click the spot where you want the pivot point. Note: On Macintosh platforms, use the command key instead of Ctrl.
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.
Viewpoints • 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 Viewing Virtual Worlds Define and Reset Viewpoints In this section... “Reset Viewpoints” on page 7-30 “Define Viewpoints” on page 7-30 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.
Define and Reset Viewpoints In the Simulink 3D Animation viewer, the default viewpoint for this model is View from top. 2 From the menu bar, choose the Viewpoints menu. 3 Choose View on Earth. 4 In the viewer window, navigate to a random position in the scene. 5 From the Viewpoints menu, choose Create Viewpoint. Alternatively, click Create viewpoint on the toolbar. The Create Viewpoint dialog box is displayed. 6 In the Name box, enter a unique and descriptive name for the viewpoint.
7 Viewing Virtual Worlds 13 Repeat steps 2 to 6. 14 In the Placement field, select Sibling of the current viewpoint. This option creates a new viewpoint at the same level in the virtual world object hierarchy as the child of the parent transform of the current viewpoint. The local coordinate system of the parent transform defines the new viewpoint coordinates. As a result, the new viewpoint moves with the parent transform.
Define and Reset Viewpoints 7-33
7 Viewing Virtual Worlds Navigate Through Viewpoints You can navigate through a virtual scene's viewpoints using the menu bar, toolbar, navigation panel, or keyboard shortcut keys. These navigation methods are inactive if the author has specified no or only one viewpoint in the virtual world. • 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.
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 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.
Navigate Through Viewpoints • Go to the virtual world's default viewpoint • Create and remove viewpoints • Navigate to an existing viewpoint 7-37
7 Viewing Virtual Worlds Record Offline Animations In this section...
Record Offline Animations • 3-D VRML file — The Simulink 3D Animation software traces object movements and saves that data into a VRML file using VRML97 standard interpolators. You can then view these files with the Simulink 3D Animation Viewer. 3-D VRML files typically use much less disk space than Audio Video Interleave (AVI) files.
7 Viewing Virtual Worlds 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.
Record Offline Animations 1 In the MATLAB Command Window, type the model name. For example: vrplanets The Simulink model is displayed. Also, by default, the Simulink 3D Animation viewer for that model is loaded and becomes active. If the viewer is not displayed, double-click the VR Sink block in the Simulink model. 2 From the Recording menu, choose Capture and Recording Parameters. The Capture and Recording Parameters dialog box is displayed. 3 Find the Recording section of the dialog.
7 Viewing Virtual Worlds Record Files in the Audio Video Interleave (AVI) Format To create a 2-D AVI format file from a Simulink model execution, set recording parameters. You can start the simulation before setting up the recording. 1 In the MATLAB Command Window, type the model name. For example: vrplanets The Simulink model is displayed. Also, by default, the Simulink 3D Animation viewer for that model is loaded and becomes active.
Record Offline Animations 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. For example, to record a Simulink simulation with 25 frames per second (of the simulation time), in the VR Sink block set Sample time to be 0.04. In that situation, if you want to create an AVI file where 1 second of simulation time corresponds to 1 second of AVI file playback time, set the FPS parameter to auto.
7 Viewing Virtual Worlds 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 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.
Record Offline Animations 3 From the Record mode list, choose Scheduled. 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 Viewing Virtual Worlds 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.
Play Animations with Simulink 3D Animation Viewer Play Animations with Simulink 3D Animation Viewer You can use the Simulink 3D Animation You can also use the Simulink 3D Animation Viewer to play animation files, using one of these approaches: At the MATLAB command line, use vrview. For example, enter: w=vrview('vrplanets_anim_1.wrl'); set(w,'TimeSource','freerun'); The vrview command displays the default Simulink 3D Animation Viewer for the animation file.
7 Viewing Virtual Worlds Configure Frame Capture Parameters This topic describes how to configure and capture a frame, using the vrplanets example as the example. 1 In the MATLAB Command Window, type vrplanets at the MATLAB command prompt. The Planets example starts. 2 From the Recording menu, choose Capture and Recording Parameters. The Capture and Recording Parameters dialog box is displayed. 3 Find the Frame Capture section of the dialog. This is located at the top of the dialog.
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.
7 Viewing Virtual Worlds Simulink 3D Animation Web Viewer Use the Simulink 3D Animation Web Viewer to access virtual worlds with an HTML5enabled Web browser. You can open a virtual world in Simulink 3D Animation on a host computer and then view it remotely in a Web browser on another computer. You do not need to install Simulink 3D Animation on the remote computer. The Web Viewer supplements the Simulink 3D Animation Viewer. It also supplements the Orbisnap viewer, which comes with Simulink 3D Animation.
Open the Web Viewer Open the Web Viewer In this section... “Set Up for Remote Viewing” on page 7-51 “Connect the Web Viewer” on page 7-51 Set Up for Remote Viewing To enable a user on a remote computer to use a Web browser to view a virtual world that is connected to a Simulink model: 1 In the Simulink 3D Animation Viewer, select Simulation > Block parameters > Allow viewing from the Internet.
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 7-52 In the Web Viewer, from the list of open virtual worlds, select the one that you want to view.
Navigate Using the Web Viewer Navigate Using the Web Viewer In this section... “Display and Navigation” on page 7-53 “Keyboard Shortcuts” on page 7-53 “Web Viewer Preferences” on page 7-54 Display and Navigation Most of the navigation features for the Web Viewer are the same as for the Simulink 3D Animation Viewer and the 3D World Editor Virtual world display pane. For details about Simulink 3D Animation Viewer navigation, see “Navigate Using the Simulink 3D Animation Viewer” on page 7-18.
7 Viewing Virtual Worlds Navigation Function Keyboard Shortcut Return to current viewpoint. R Go to previous viewpoint. Page Up Go to next viewpoint. Page Down Set the navigation method to Walk. W Set the navigation method to Examine. E Set the navigation method to Fly. F Move the camera forward and backward. Shift Up/Down Arrow Pan the camera up and down. Up/Down Arrow Pan the camera right and left. Left/Right Arrow, Shift +Left/Right Arrow Tilt the camera right and left.
Navigate Using the Web Viewer • Figure > Appearance > Navigation zones To access the preferences, from the MATLAB Toolstrip, in the Home tab, in the Environment section, select Preferences > Simulink 3D Animation.
7 Viewing Virtual Worlds Legacy Simulink 3D Animation Viewer In this section... “Introduction” on page 7-56 “Starting the Legacy Viewer” on page 7-56 “Differences Between the Default and Legacy Viewer” on page 7-58 “Differences When Setting the DefaultViewer Property to 'internalv4'” on page 7-59 Introduction The Simulink 3D Animation viewer has a legacy viewer. This legacy viewer is the former default viewer.
Legacy Simulink 3D Animation Viewer DefaultFigureMaxTextureSize: DefaultFigureNavPanel: DefaultFigureNavZones: DefaultFigurePosition: DefaultFigureRecord2DCompressMethod: DefaultFigureRecord2DCompressQuality: DefaultFigureRecord2DFileName: DefaultFigureRecord2DFPS: DefaultFigureStatusBar: DefaultFigureTextures: DefaultFigureToolBar: DefaultFigureTransparency: DefaultFigureWireframe: DefaultViewer: DefaultWorldRecord3DFileName: DefaultWorldRecordMode: DefaultWorldRecordInterval: DefaultWorldRemoteView: Defa
7 Viewing Virtual Worlds To revert to the original default viewer, type vrsetpref('DefaultViewer','internal') Differences Between the Default and Legacy Viewer The legacy viewer has the functionality and appearance of the default Simulink 3D Animation viewer: • In the legacy viewer, you cannot dock the viewer window in the MATLAB window. • In the legacy viewer, you cannot right-click in the viewer window to display a context menu that contains the viewer commands.
Legacy Simulink 3D Animation Viewer • 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.
7 Viewing Virtual Worlds Listen to Sound in a Virtual World In this section... “System Requirements for Sound” on page 7-60 “Listen to Sound” on page 7-60 If a virtual world contains a Sound node and your computer supports sound, then you can listen to the sound using these Simulink 3D Animation components: • Simulink 3D Animation Viewer • 3D Animation Player • vr.
Listen to Sound in a Virtual World For a vr.canvas object, to disable sound , set the Sound property to 'off'. To control volume, use your computer volume controls.
7 Viewing Virtual Worlds View a Virtual World in Stereoscopic Vision In this section... “Enable Stereoscopic Vision” on page 7-62 “Control Stereoscopic Effects” on page 7-63 You can view a virtual world using 3D effects, so that elements in the virtual world appear to come forward or back from the plane of the monitor. You can use stereoscopic vision with these Simulink 3D Animation components: • 3D World Editor • Simulink 3D Animation Viewer • 3D Animation Player • vr.
View a Virtual World in Stereoscopic Vision Control Stereoscopic Effects You can control the following stereoscopic effects interactively or using preferences. Stereo 3D Effect Description Keyboard Shortcut Figure > Rendering Preference Camera offset Distance between the two points of view (cameras) that produce the 3D effect. The higher the offset, the further apart the cameras are, and thus the deeper the 3D effect. Shift+K Stereo 3D Camera increases the Offset offset.
7 Viewing Virtual Worlds Active Stereoscopic Vision Configuration In this section... “Computer Platforms” on page 7-64 “Graphics Cards” on page 7-64 “Display Devices” on page 7-64 “Graphic Card Connection to Display Devices” on page 7-65 “Examples of Stereoscopic Vision Setups” on page 7-65 This section identifies system requirements for active stereoscopic vision configuration.
Active Stereoscopic Vision Configuration • 3D television set that displays 3D content. For stereoscopic vision, you typically use active shutter glasses or passive polarized glasses. • Auto-stereoscopic display (monitor, display containing pair of video projectors, etc.). Graphic Card Connection to Display Devices Connect 3D graphic cards to 3D display devices using an interface such as DVI, HDMI, or DisplayPort. HDMI 1.
8 Simulink 3D Animation Stand-Alone Viewer The Simulink 3D Animation stand-alone viewer, Orbisnap, allows you to visualize virtual worlds or prerecorded animation files without running the MATLAB or Simulink 3D Animation products.
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.
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).
8 Simulink 3D Animation Stand-Alone Viewer Adding Shortcuts or Symbolic Links For convenience, you can create a shortcut (Windows) or symbolic link (UNIX) to the Orbisnap starter file. • In Windows Explorer, right-click orbisnap.bat and select Properties. You can start Orbisnap from either the shortcut or the original starter file. • In UNIX, use the ln -s command to create a symbolic link to orbisnap.
Start Orbisnap Start Orbisnap You can start Orbisnap from any command line with the following: orbisnap orbisnap orbisnap orbisnap orbisnap -f vr_filename -c hostname -w "vrworld" -t http -v vrport -q=end_time -t http -v vrport vr_filename_or_hostname -q=end_time -h No arguments -- Starts the default Orbisnap. There is no loaded vrworld file and no connection to a Simulink 3D Animation server. -f vr_filename — (Optional) Orbisnap starts and loads the vrworld contained in vr_filename.
8 Simulink 3D Animation Stand-Alone Viewer Orbisnap Interface In this section... “Menu Bar” on page 8-8 “Toolbar” on page 8-9 “Navigation Panel” on page 8-9 Orbisnap, with a virtual world displayed, looks like this.
Orbisnap Interface Orbisnap provides much of the functionality of the Simulink 3D Animation Viewer.
8 Simulink 3D Animation Stand-Alone Viewer • Customize the Orbisnap window • Manage virtual world viewpoints • Manage scene rendering You cannot • Open an editor for the virtual world • Open another window for the virtual world • Simulate the world (start/stop the model) • Record or manage animation files Menu Bar The Orbisnap menu bar has the following menus: • File — General file operation options, including, • Open — Invokes a browser that you can use to browse to the virtual world you want to visuali
Orbisnap Interface • Navigation Panel — Controls the display of the navigation panel, including toggling it. • Triad — Shows red, green, and blue arrows that are parallel to the orientation of global x, y,and z coordinate axes. • Zoom In/Out — Zooms in or out of the world view. • Normal (100%) — Returns the zoom to normal (initial viewpoint setting). • Fullscreen Mode — Displays the viewer in full-screen mode. • Viewpoints — Manages the virtual world viewpoints. • Navigation — Manages scene navigation.
8 Simulink 3D Animation Stand-Alone Viewer • Hide panel — Toggles the navigation panel. • Full-screen mode— Uses the whole screen for Orbisnap. • Next/previous viewpoint — Left and right arrows toggles through the list of viewpoints. • Return to default viewpoint — Returns focus to original default viewpoint. • Slide left/right — Buttons to the left and right of the navigation wheel slide the view left or right. • Navigation wheel — Moves view in one of eight directions.
Navigate Using Orbisnap Navigate Using Orbisnap You can navigate around a virtual world using the menu bar, toolbar, navigation panel, mouse, and keyboard. Navigation view — You can change the camera position. From the menu bar, select the Navigation menu Straighten Up option. This option resets the camera so that it points straight ahead.
8 Simulink 3D Animation Stand-Alone Viewer Movement Mode Zone and Description 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.
Navigate Using Orbisnap Keyboard Command Navigation Function Esc Go to default viewpoint. Home Return to current viewpoint. Page Up, Page Down Move between preset viewpoints. F10 Toggle camera binding from the viewpoint. Shift+W Set the navigation method to Walk. Shift+E Set the navigation method to Examine. Shift+F Set the navigation method to Fly. Shift Up/Down Arrow Move the camera forward and backward. Up/Down Arrow Pan the camera up and down.
8 Simulink 3D Animation Stand-Alone Viewer View Animations or Virtual Worlds with Orbisnap This topic assumes that you have a prerecorded WRL animation file or an existing virtual world file. This procedure uses a file named vr_bounce_anim.wrl. 1 Start Orbisnap. For example, in Windows double-click orbisnap.bat in matlabroot\toolbox\sl3d\orbisnap\bin. This is an Orbisnap starter file that calls the Orbisnap executable. Orbisnap is displayed. 2 In Orbisnap, select File > Open.
View Virtual Worlds Remotely with Orbisnap View Virtual Worlds Remotely with Orbisnap To view virtual worlds from the Simulink 3D Animation server in Orbisnap, you must have • The MATLAB software running a Simulink 3D Animation server session • The version of the Simulink 3D Animation server to which you want to connect must be compatible with the Orbisnap version you are running. For example, you cannot connect Orbisnap to Simulink 3D Animation software Version 3.1.
8 Simulink 3D Animation Stand-Alone Viewer 3 Enter the IP address or hostname of the host computer running the Simulink 3D Animation server (127.0.0.1 by default). The HTTP port number is 8123 by default and the port number at which the Simulink 3D Animation server is listening is 8124 by default. The Choose a world dialog is displayed. This dialog lists all the virtual worlds that are currently active on the Simulink 3D Animation server.
View Virtual Worlds Remotely with Orbisnap 4 Select a virtual world. 5 Click OK. Orbisnap displays the selected virtual world of the remote Simulink 3D Animation server. 6 Navigate and render the virtual world as you want. 7 To close Orbisnap, select File > Close. 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 PAGE 304
9 Blocks — Alphabetical List
9 Blocks — Alphabetical List Cross Product Cross product of two 3-D vectors Library Simulink 3D Animation Description Takes two 3-by-1 vectors as input and returns their cross product.
Joystick Input Joystick Input Process input from asynchronous joystick device Library Simulink 3D Animation 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.
9 Blocks — Alphabetical List Block Parameters Dialog Box Joystick ID — The system ID assigned to the given joystick device. You can find the properties of the joystick that is connected to the 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 adjusts the ports to correspond to the capabilities of the connected joystick each time that you open the model.
Joystick Input Output Port Value Description Axes Vector of doubles in the range < -1; 1 > Outputs correspond to the current position of the joystick in the given axis. Values are normalized to range from -1 to 1. Buttons Vector of doubles 0 — Button released 1 — Button pressed Outputs correspond to the current status of joystick buttons.
9 Blocks — Alphabetical List Normalize Vector Unit vector parallel to input vector Library Simulink 3D Animation Description Takes an input vector of any size and outputs the unit vector parallel to it. Block Parameters Dialog Box Maximum modulus to treat vector as zero — The output is set to zeroes if the modulus of the input is equal to or lower than this value.
Rotation Between 2 Vectors Rotation Between 2 Vectors VRML rotation between two 3-D vectors Library Simulink 3D Animation Description Takes input of two 3-by-1 vectors and returns a VRML rotation (specified as a fourelement vector defining axis and angle) that is needed to transform the first input vector to the second input vector.
9 Blocks — Alphabetical List Rotation Matrix to VRML Rotation Convert rotation matrix into representation used in VRML Library Simulink 3D Animation 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 to VRML Rotation 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. Ê R11 Á R = Á R21 ÁR Ë 31 R12 R22 R32 R13 ˆ Ê Rxx ˜ Á R23 ˜ = Á Ryx Á R33 ˜¯ Á Rzx Ë Rxy Ryy Rzy Rxz ˆ ˜ Ryz ˜ ˜ Rzz ˜¯ In general, R requires three independent angles to specify the rotation fully. There are many ways to represent the three independent angles.
9 Blocks — Alphabetical List Space Mouse Input Process input from space mouse device Library Simulink 3D Animation Description A space mouse is a device similar to a joystick in purpose, but it also provides movement control with six degrees of freedom. This block reads the status of the space mouse and provides some commonly used transformations of the input. The Space Mouse Input block supports current models of 3–D navigation devices manufactured by 3Dconnexion (http://www.3dconnexion.com).
Space Mouse Input Block Parameters Dialog Box 9-11
9 Blocks — Alphabetical List Port — Serial port to which the space mouse is connected. Possible values are USB1...USB4 and COM1...COM4. Output Type — This field specifies how the inputs from the device are transformed: • Speed — No transformations are done. Outputs are translation and rotation speeds. • Position — Translations and rotations are integrated. Outputs are position and orientation in the form of roll/pitch/yaw angles. • Viewpoint coordinates — Translations and rotations are integrated.
Space Mouse Input Upper position limit — Position coordinates for the upper limit of the mouse.
9 Blocks — Alphabetical List Viewpoint Direction to VRML Orientation Convert viewpoint direction to VRML orientation Library Simulink 3D Animation Description Takes a viewpoint direction (3-by-1 vector) as input and outputs the corresponding VRML viewpoint orientation (four-element VRML rotation vector).
VR Placeholder VR Placeholder Send unspecified value to Simulink 3D Animation block Library Simulink 3D Animation 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.
9 Blocks — Alphabetical List Block Parameters Dialog Box Output Width — Length of the vector containing placeholder signal values.
VR Signal Expander VR Signal Expander Expand input vectors into fully qualified VRML field vectors Library Simulink 3D Animation Description The VR Signal Expander block creates a vector of predefined length, using some values from the input ports and filling the rest with placeholder signal values. Data Type Support A VR Signal Expander block accepts and outputs signals of type double.
9 Blocks — Alphabetical List Block Parameters Dialog Box Output width — How long the output vector should be. Output signal indices — Vector indicating the position at which the input signals appear at the output. The remaining positions are filled with VR Placeholder signals. 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.
VR Sink VR Sink Write data from Simulink model to virtual world Library Simulink 3D Animation 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.
9 Blocks — Alphabetical List Desktop Real-Time, some sink blocks and Sim Viewing Device blocks stay in Normal mode during simulation, receive data from the target, and display that data. For more information, see “Sim Viewing Devices in External Mode” in the Simulink documentation. Data Type Support A VR Sink block accepts all meaningful data types on input. The block converts these data types to natural VRML types, as necessary.
VR Sink Source file — VRML file name specifying the virtual world that connects to this block. By default, the full path to the associated .wrl 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 Blocks — Alphabetical List 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.
VR Source VR Source Read data from virtual world to Simulink model Library Simulink 3D Animation 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: • Provide interactivity between a user navigating the virtual world and the Simulink model. The VR Source block can register user interaction with the virtual world.
9 Blocks — Alphabetical List window opens with the same parameters that were saved, such as position, size, and navigation mode. When closing the viewer window, the Simulink software does not alert you if these properties have changed. You cannot use the Simulink Coder software to compile a model that includes a VR Source block. Data Type Support A VR Source block outputs signals of type double.
VR Source Source file — VRML file name specifying the virtual world that connects to this block. By default, the full path to the associated .wrl 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 Blocks — Alphabetical List SFxxx field that can map to a variable-size signal. For details about these data types, see “VRML Field Data Types”. Note: The signal dimensions of a variable-size output signal of a VR Source block must be the same size as, or smaller than, the initial state of the signal. 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.
VR Text Output VR Text Output Allows display of Simulink signal values as text in VRML scene Library Simulink 3D Animation 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.
9 Blocks — Alphabetical List Block Parameters Dialog Box Associated VRML file — VRML file specifying the virtual world to which text is output. Associated Text node — Text node within the virtual world to which text is output. Format string — Format used for output text. This block uses sprintf() to format the output strings.
VR Text Output 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 Blocks — Alphabetical List VR To Video Write data from Simulink model to virtual world (video output port enabled) Library Simulink 3D Animation 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.
VR Tracer VR Tracer Trace trajectory of object in associated virtual scene Library Simulink 3D Animation Description Trace the trajectory of an object in the associated virtual scene. This block creates marker nodes in regular time steps either as children of the specified parent node (Parent node parameter), or at the top level of scene hierarchy (root).
9 Blocks — Alphabetical List Block Parameters Dialog Box Following is the Main pane of the VR Tracer block dialog box.
VR Tracer 9-33
9 Blocks — Alphabetical List Following is the Marker Projections pane of the VR Tracer block dialog box. Associated VRML file — VRML file name specifying the associated virtual world. Parent node (leave empty for root) — Specify the location of the traced object in the scene hierarchy.
VR Tracer • Pyramid • Box • Octahedron • Sphere Connect markers with line segments — Select this check box to connect the traced object path with lines. Place a triad at each marker position — Select this check box to place a triad at each marker position. A triad helps you orient the object trajectory in the x-y-z plane. Marker scale — Specify a three-component vector that defines the scaling of predefined marker shapes and triads. This parameter allows accommodation for scenes of various sizes.
9 Blocks — Alphabetical List to project the position of the object. The coefficients are in the form ax+by+cz+d=0. For example, if you use the default plane equation coefficients to [0 1 0 0] for the vrtkoff_trace model, then after you simulate the model, the object positions project to the y=0 plane. Project positions to a point— Displays line segments from an object to a point to approximate the trajectory of the object. • None — (Default) No projection to a point.
10 Functions — Alphabetical List
10 Functions — Alphabetical List stl2vrml Convert STL files to VRML format 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 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.
10 Functions — Alphabetical List 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.
vrcadcleanup vrcadcleanup Clean up VRML file exported from CAD tools Syntax vrcadcleanup('filename') vrcadcleanup('filename', 'hint') Description vrcadcleanup('filename') copies the specified file to a backup file with the extension bak. It then modifies the VRML file exported from Pro/ENGINEER® or SolidWorks. This cleanup enables the Simulink 3D Animation software to use these files.
10 Functions — Alphabetical List The function also performs the following: • Upon output, discards any additional nodes, including transform nodes, that do not contain inline nodes. • Processes hierarchically organized assemblies, where inline files instead of part geometries contain additional groups of nested node inline nodes. In such subassembly files, copies all inline references to the main VRML file.
vr.canvas class vr.canvas class Create virtual reality canvas Description Create a virtual reality canvas. Construction virtualCanvas = vr.canvas(world) creates a virtual reality canvas showing the specified virtual world. virtualCanvas = vrfigure(world,parent) creates a virtual reality canvas in the specified parent figure or uipanel. A uipanel arranges user interface components into groups. By visually grouping related controls, panels can make the user interface easier to understand.
10 Functions — Alphabetical List parent — Figure or uipanel for displaying canvas figure object | uipanel object Figure or uipanel for displaying the canvas, specified as a MATLAB figure or uipanel object position — Canvas location and size vector with four elements Location and size of virtual canvas, specified as the vector, in the form [left bottom width height]. Specify measurements in pixels.
vr.canvas class Smooth textures using antialising, specified as 'on' or 'off'. Antialiasing smooths textures by interpolating values between texture points. 'CameraBound' — Camera movement with current viewpoint 'on' (default) | 'off' Camera movement with the current viewpoint, specified as 'on' or 'off'. 'CameraDirection' — Camera direction in the current viewpoint local coordinates vector of three doubles Camera direction in the current viewpoint local coordinates, specified as a vector of three doubles.
10 Functions — Alphabetical List Headlight from camera, specified as 'on' or 'off'. If you specify 'off', the camera does not emit light and the scene can appear dark. 'Lighting' — Lighting effect 'on' (default) | 'off' Lighting effect, specified as 'on' or 'off'. If you specify 'off', the camera does not emit light and the scene can appear dark.
vr.canvas class 'NavZones' — Display navigation zones 'off' (default) | 'on' Navigation zones display, specified as 'on' or 'off'. 'Position' — Canvas location and size vector with four doubles Location and size of virtual canvas, specified as the vector in the form [left bottom width height]. Specify measurements in pixels or normalized, based on the Units property setting. Element Description left Distance from the left edge of the primary display to the inner left edge of the canvas.
10 Functions — Alphabetical List Data Types: int32 'Stereo3DCameraOffset' — Distance of left and right camera for stereoscopic vision non-negative floating-point double-precision number Distance of left and right camera from parallax for stereoscopic vision, specified as a nonnegative floating-point double-precision number. Specifying a vr.utils.stereo3d object for the Stereo3D property also sets the Stereo3DCameraOffset and Stereo3DHIT properties and sets color filters for the left and right cameras.
vr.canvas class 'Units' — Units for Position property 'pixels' (default) | 'normalized' Units for Position property, specified as 'pixels' or 'normalized'. 'Viewpoint' — Active viewpoint of figure string Active viewpoint of a figure, specified as a string. If the active viewpoint has no description, use an empty string. 'Wireframe' — Wireframe display 'off' (default) | 'on' Wireframe display, specified as 'on' or 'off'.
10 Functions — Alphabetical List Camera movement with the current viewpoint, returned as 'on' or 'off'. CameraDirection — Camera direction in the current viewpoint local coordinates vector of three doubles Camera direction in the current viewpoint local coordinates, specified as a vector of three doubles. The doubles represent the x, y, and z vectors in current viewpoint local coordinates.
vr.canvas class ExaminePivotPoint — Pivot point about which camera rotates in examine navigation mode vector of three doubles Pivot point about which camera rotates in examine navigation mode, returned as a vector of three doubles in world coordinates. Headlight — Headlight from camera 'on' (default) | 'off' Headlight from camera, returned as 'on' or 'off'. If set to 'off', the camera does not emit light and the scene can appear dark.
10 Functions — Alphabetical List NavZones — Display navigation zones 'off' (default) | 'on' Navigation zones display, returned as 'on' or 'off'. Parent — Handle of parent of virtual reality canvas object double Handle of parent of virtual reality canvas object, represented by a double (read-only property). Position — Canvas location and size vector with four doubles Location and size of virtual canvas, returned as the vector in the form [left bottom width height].
vr.canvas class Stereoscopic vision mode, returned as 'off', 'anaglyph', 'active' or a vr.utils.stereo3d object. Specifying a vr.utils.stereo3d object sets the Stereo3D, Stereo3DCameraOffset, and Stereo3DHIT properties. Specifying a vr.utils.stereo3d object also sets color filters for the left and right cameras.
10 Functions — Alphabetical List Transparency effect, returned as 'on' or 'off'. Triad — Triad location 'bottomleft' (default) | 'bottomright' | 'center | 'topleft' | 'topright' | 'none' Triad location, returned as 'bottomleft', 'bottomright', 'center, 'topleft', 'topright', or 'none'. Units — Units for Position property 'pixels' (default) | 'normalized' Units for Position property, returned as 'pixels' or 'normalized'.
vr.canvas class Examples Create a Canvas That Displays in a Figure Create and open a vrworld object. myWorld = vrworld('vrlights.wrl'); open(myWorld); Create a figure to use as the parent of the canvas. fig = figure; Create a canvas. Use a figure as the parent and specify the position. myCanvas = vr.canvas(myWorld,'Parent'fig,'Units','normalized'...
10 Functions — Alphabetical List Create a Canvas in a Uipanel Create a figure. pf = figure; Create a uipanel in the figure and specify a title. pp1 = uipanel('Parent',pf); pp1.Title = 'Panel with Title'; Create and open a virtual world. w = vrworld('vrlights.
vr.canvas class Create a canvas in the uipanel. c = vr.canvas(w,pp1); Set Property Values of Canvas Set the camera direction, navigation mode, and stereoscopic vision properties of a canvas. Create and open a vrworld object. vrmountWorld = vrworld('vrmount.wrl'); open(vrmountWorld); Create a vr.utils.stereo3d object to use to specify stereoscopic vision properties.
10 Functions — Alphabetical List myStereo3D = vr.utils.stereo3d.ANAGLYPH_RED_CYAN; Create a canvas. Define non-default values for some properties. myCanvas = vr.canvas(vrmountWorld,'Antialiasing','on',... 'NavPanel','opaque','NavZones','on','Stereo3D',... myStereo3D,'Stereo3DCameraOffset',0.25,... 'Stereo3DHIT',0.
vr.canvas class • “Create vrworld Object for a Virtual World” • “MATLAB Interaction” • “View a Virtual World in Stereoscopic Vision” See Also vr.utils.
10 Functions — Alphabetical List capture Class: vr.canvas Capture virtual reality canvas image Syntax image_capture = capture(canvas) Description image_capture = capture(canvas) captures a virtual reality canvas into a TrueColor RGB image. You can display this image using the image command. Input Arguments canvas — Virtual reality canvas vr.canvas object Virtual reality canvas, specified as a vr.canvas object.
capture lights_world = vrworld('vrlights.wrl'); open(lights_world); Create a vr.canvas object for lights_world. c = vr.canvas(lights_world,gcf,[30 30 300 200]); Capture an image of the canvas. image_capture = capture(c); Display an RGB image of the canvas in a MATLAB figure window.
10 Functions — Alphabetical List vrclear Remove all closed virtual worlds from memory 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.
vrclose vrclose Close virtual reality figure windows Syntax vrclose vrclose all Description vrclose and vrclose all close all the open virtual reality figures. Examples Open a series of virtual reality figure windows by typing vrpend vrbounce vrlights Arrange the viewer windows so they are all visible. Type vrclose All the virtual reality figure windows disappear from the screen.
10 Functions — Alphabetical List vrdir2ori Convert viewpoint direction to orientation Syntax vrdir2ori(d) vrdir2ori(d,options) Description vrdir2ori(d) converts the viewpoint direction, specified by a vector of three elements, to an appropriate orientation (VRML rotation vector). vrdir2ori(d,options) converts the viewpoint direction with the default algorithm parameters replaced by values defined in options.
vrdrawnow vrdrawnow Update virtual world 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 Functions — Alphabetical List vredit Open 3D World Editor 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. Examples Open New Virtual World in 3D World Editor vredit Open Existing Virtual World in 3D World Editor Open the membrane virtual world in the 3D World Editor.
vrfigure class vrfigure class Create virtual reality figure Description Creates a virtual reality figure. To access vrfigure properties, use the vrfigure/get method. To change properties, use the vrfigure/set method. If you create a vrfigure object by specifying a virtual world, the virtual figure displays in the viewer specified in the vrsetpref DefaultViewer property. Construction virtual_figure = vrfigure(world) creates a virtual reality figure showing the specified virtual world.
10 Functions — Alphabetical List Position — Figure location and size vector with four elements Location and size of virtual figure, specified as the vector in the form [left bottom width height]. Specify measurements in pixels. Element Description left Distance from the left edge of the primary display to the inner left edge of the figure window. This value can be negative on systems that have more than one monitor.
vrfigure class capture close get isvalid set set Capture virtual reality figure image Close virtual reality figure Return property value of vrfigure object Check validity of vrfigure object handles Set property values of vrfigure object Set property values of vrfigure object Examples Create and Display a vrworld Object Create a vrworld object that is associated with the virtual world vrmount.wrl. Open and view the virtual world. myworld = vrworld('vrmount.
10 Functions — Alphabetical List 10-34 • “Create vrworld Object for a Virtual World” • “MATLAB Interaction” • “View a Virtual World in Stereoscopic Vision”
vrfigure class See Also vr.utils.stereo3d class | vr.
10 Functions — Alphabetical List capture Class: vrfigure Capture virtual reality figure image Syntax image_capture = capture(figure) Description image_capture = capture(figure) captures a virtual reality figure into a TrueColor RGB image. You can display this image using the image command. You can then print the figure. Input Arguments figure — Virtual reality figure vrfigure object Virtual reality figure, specified as a vrfigure object.
capture myworld = vrworld('vrmount.wrl'); open(myworld); View the virtual world in the Simulink 3D Animation Viewer. f = vrfigure(myworld); Create an RGB image of the figure. image_capture = capture(f); Display the RGB figure image in a MATLAB figure window.
10 Functions — Alphabetical List close Class: vrfigure Close virtual reality figure Syntax close(figure) Description close(figure) closes the virtual reality figure referenced by figure. If figure is a vector of vrfigure object handles, then the method closes multiple figures. Input Arguments figure — Virtual reality figure vrfigure object Virtual reality figure, specified as a vrfigure object. Examples Capture a Figure myworld = vrworld('vrpend.
close Introduced before R2006a 10-39
10 Functions — Alphabetical List get Class: vrfigure Return property value of vrfigure object Syntax get(figure) figureProp = get(figure,propertyName) Description get(figure) lists the values of all the properties of the vrfigure object. figureProp = get(figure,propertyName) returns the value of the specified property of the vrfigure object. Input Arguments figure — Virtual reality figure vrfigure object Virtual reality figure, specified as a vrfigure object.
get vrfigure Property Meaning CameraDirectionAbs Camera direction in the world coordinates. (read-only property). CameraPosition Camera position in the current viewpoint local coordinates. CameraPositionAbs Camera position in world coordinates (read-only property). CameraUpVector Camera up vector. CameraUpVectorAbs Camera up vector in world coordinates (read-only property). CaptureFileFormat File format for a captured frame file. CaptureFileName Frame capture file name.
10 Functions — Alphabetical List 10-42 vrfigure Property Meaning Record2DCompress Method Compression method for creating 2D animation files. See profile in the MATLAB VideoWriter documentation. Record2DCompress Quality Quality of 2-D animation file compression. See the MATLAB VideoWriter documentation. Record2DFileName Name of 2-D offline animation file. The string can contain tokens that animation recording replaces with information. See “File Name Tokens”.
get vrfigure Property Meaning World Virtual world that the figure displays (read-only property). ZoomFactor Camera zoom factor. Output Arguments figureProp — Virtual reality feature property string | vector Virtual reality feature property, returned as a string or vector. Examples Return All Property Values of a Figure Create a vrfigure object. myworld = vrworld('vrmount.wrl'); open(myworld); virtual_fig = vrfigure(myworld); Return the properties of the virtual figure virtual_fig.
10 Functions — Alphabetical List DeleteFcn: ExaminePivotPoint: Fullscreen: Headlight: Lighting: MaxTextureSize: Name: NavMode: NavPanel: NavSpeed: NavZones: Position: Record2D: Record2DCompressMethod: Record2DCompressQuality: Record2DFPS: Record2DFileName: Sound: StatusBar: Stereo3D: Stereo3DCameraOffset: Stereo3DHIT: Textures: ToolBar: Tooltips: Transparency: Triad: Viewpoint: Wireframe: World: ZoomFactor: '' [0 0 0] 'off' 'on' 'on' 'auto' 'VR Car in the Mountains' 'examine' 'halfbar' 'normal' 'off' [5
get VR Car in the Mountains • “MATLAB Interaction” • “Create vrworld Object for a Virtual World” • “View a Virtual World in Stereoscopic Vision” See Also vrfigure class | vr.utils.
10 Functions — Alphabetical List isvalid Class: vrfigure Check validity of vrfigure object handles Syntax valid_handles = isvalid(vrfigure_vector) Description valid_handles = isvalid(vrfigure_vector) detects whether the vrfigure handles are valid. Input Arguments figure_vector — Virtual reality figure vector array of vrfigure object handles Virtual reality figure vector, specified as a vrfigure object.
isvalid Examples Check Validity of Figure Handles Check whether the figure handles of the vrfigure object are valid. The first check shows that the figure handle is valid, but the second check shows that the handle is invalid because the figure is closed. myworld = vrview('vrpend.
10 Functions — Alphabetical List set Class: vrfigure Set property values of vrfigure object Syntax set(figure,PropertyName,Value,...,PropertyName,Value) Description set(figure,PropertyName,Value,...,PropertyName,Value) sets the values of the vrfigure properties specified by one or more PropertyName,Value pair arguments. Input Arguments figure — Virtual reality figure vrfigure object Virtual reality figure, specified as a vrfigure object.
set 'CameraBound' — Camera movement with current viewpoint 'on' (default) | 'off' Camera movement with the current viewpoint, specified as 'on' or 'off'. 'CameraDirection' — Camera direction in the current viewpoint local coordinates vector of three doubles Camera direction in the current viewpoint local coordinates, specified as a vector of three doubles. The doubles represent the x, y, and z vectors in the current viewpoint local coordinates.
10 Functions — Alphabetical List 'Fullscreen' — Fullscreen display of figure 'off' (default) | 'on' Fullscreen display of figure, specified as 'on' or 'off'. 'Headlight' — Headlight from camera 'on' (default) | 'off' Headlight from camera, specified as 'on' or 'off'. If you specify 'off', the camera does not emit light and the scene can appear dark. 'Lighting' — Lighting effect 'on' (default) | 'off' Lighting effect, specified as 'on' or 'off'.
set Navigation mode, specified as 'examine', 'fly', 'walk', or 'none'. See “Mouse Navigation”. 'NavPanel' — Navigation panel appearance 'none' (default) | 'halfbar' | 'bar' | 'opaque' | 'translucent' Navigation panel appearance, specified as 'none', 'halfbar', 'bar', 'opaque', or 'translucent'. 'Navspeed' — Navigation speed 'normal' (default) | 'slow' | 'veryslow' | 'fast' | 'veryfast' Navigation speed, specified as 'normal', 'slow', 'veryslow', 'fast', or 'veryfast'.
10 Functions — Alphabetical List Example: [230 250 570 510] Data Types: double 'Record2D' — 2-D offline animation file recording 'off' (default) | 'on' 2-D offline animation file recording, specified as 'on' or 'off'.
set Sound effects, specified as 'on' or 'off'. 'StatusBar' — Status bar display 'on' (default) | 'off' Status bar display, specified as 'on' or 'off'. 'Stereo3D' — Stereoscopic vision mode 'off' (default) | 'anaglyph' | 'active' | vr.utils.stereo3d object Stereoscopic vision mode, specified as 'off', 'anaglyph', 'active' or a vr.utils.stereo3d object. Specifying a vr.utils.stereo3d object sets the Stereo3D, Stereo3DCamaraOffset, and Stereo3DHIT properties. Specifying a vr.utils.
10 Functions — Alphabetical List 'Toolbar' — Toolbar display 'on' (default) | 'off' Toolbar display, specified as 'on' or 'off'. 'Tooltips' — Tooltips display 'on' (default) | 'off' Tooltips display, specified as 'on' or 'off'. 'Transparency' — Transparency effect 'on' (default) | 'off' Transparency effect, specified as 'on' or 'off'. 'Viewpoint' — Active viewpoint of figure string Active viewpoint of a figure, specified as a string. If the active viewpoint has no description, use an empty string.
set myworld = vrworld('vrmount.wrl'); open(myworld); virtual_fig = vrfigure(myworld); Create a vr.utils.stereo3d object to use to specify stereoscopic vision properties. myStereo3D = vr.utils.stereo3d.ANAGLYPH_RED_CYAN; Set the properties for a figure. set(virtual_fig,'CameraDirection',[0 1 0],'NavMode','fly',... 'Stereo3D',myStereo3D); View the figure properties. get(virtual_fig) get(virtual_fig) Antialiasing = 'on' CameraBound = 'on' CameraDirection = [0 1 0] CameraDirectionAbs = [0 0.980067 -0.
10 Functions — Alphabetical List Record2DFileName = '%f_anim_%n.avi' Sound = 'on' StatusBar = 'on' Stereo3D = 'anaglyph' Stereo3DCameraOffset = 0.
vrgcbf vrgcbf Current callback vrfigure object Syntax f = vrgcbf Description f = vrgcbf returns a vrfigure object representing the virtual reality figure that contains the callback currently being executed. When no virtual reality figure callbacks are executing, vrgcbf returns an empty array of vrfigure objects.
10 Functions — Alphabetical List vrgcf Handle for active virtual reality figure 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.
vrgetpref vrgetpref Values of Simulink 3D Animation preferences Syntax x = vrgetpref x = vrgetpref('preference_name') x = vrgetpref('preference_name','factory') x = vrgetpref('factory') Arguments preference_name Name of the preference to read. Description x = vrgetpref returns the values of all the Simulink 3D Animation preferences in a structure array. x = vrgetpref('preference_name') returns the value of the specified preference.
10 Functions — Alphabetical List 10-60 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.
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.
10 Functions — Alphabetical List Preference Description DefaultFigureMax TextureSize Specifies the default maximum size 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'.
vrgetpref Preference Description 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 get (vrfigure) for detailed description. Default is 'on'.
10 Functions — Alphabetical List 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.
vrgetpref Preference Description 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.
10 Functions — Alphabetical List The HttpPort, VrPort, and TransportBuffer preferences affect Web-based viewing of virtual worlds. DefaultFigurePosition and DefaultNavPanel affect the Simulink 3D Animation Viewer. DefaultFigureNavPanel — Controls the appearance of the navigation panel in the Simulink 3D Animation Viewer. For example, setting this value to 'translucent' causes the navigation panel to appear translucent.
vrgetpref %matlabroot Refers to the MATLAB root folder %file Refers to the VRML file name For instance, a possible value for the Editor preference is `%matlabroot\bin\win32\meditor.exe %file' If this preference is empty, the MATLAB editor is used. HttpPort -- Specifies the network port to be used for Web access. The port is given in the Web URL as follows: http://server.name:port_number The default value of this preference is 8123.
10 Functions — Alphabetical List vrifs2patch Convert VRML IndexedFaceSet nodes to MATLAB patches Syntax vrifs2patch(ifs) Description vrifs2patch(ifs) converts the ifs array of existing VRML IndexedFaceSet nodes to MATLAB patch objects. Note: This function converts only geometry and color data of the source IndexedFaceSet node. Examples Convert VRML IndexedFaceSet Nodes to MATLAB Patches This command converts three VRML IndexedFaceSet nodes to MATLAB patch objects.
vrifs2patch Convert the IndexedFaceSet a MATLAB patch and show it. set(vrfig1,'CameraUpVector',[0 0 -1]);figure('Name',... 'Resulting patch'); tp = vrifs2patch(w1.torushi.children.
10 Functions — Alphabetical List Change the patch color, show the axes grid, rotate the camera, and enable mouse rotation. tp.FaceColor = 'red'; axs = gca; axs.XGrid = 'on'; axs.YGrid = 'on'; axs.ZGrid = 'on'; camorbit(45, -20); rotate3d on Input Arguments ifs — VRML IndexedFaceSet nodes to convert array VRML IndexedFaceSet nodes, specified as an array.
vrifs2patch More About • “Introduction to Patch Objects” See Also patch | vrpatch2ifs Introduced in R2015a 10-71
10 Functions — Alphabetical List vrinstall Install and check Simulink 3D Animation components Syntax vrinstall('action') vrinstall action x = vrinstall('action') Arguments action Type of action for this function. Values are -interactive, selftest, -check, -install, and -uninstall. Description You use this function to install on Windows platforms the Ligos V-Realm Builder. The VRealm Builder is an optional VRML editor. For details, see “Install V-Realm Editor on Host Computer”.
vrinstall Action Value Description -install Installs optional components. This action requires you to specify the component name. -uninstall Uninstalls optional components. This option is currently available for the editor only. Note that this action does not remove the files for the editor from the installation folder. It removes the editor registry information. Examples Install the VRML editor. This command associates V-Realm Builder with the Edit button in the Block Parameters dialog boxes.
10 Functions — Alphabetical List vrjoystick Create joystick object Syntax joy = vrjoystick(id) joy = vrjoystick(id,'forcefeedback') Description joy = vrjoystick(id) creates a joystick object capable of interfacing with a joystick device. The id parameter is a one-based joystick ID. joy = vrjoystick(id,'forcefeedback') enables force feedback if the joystick supports this capability. Methods 10-74 Method Description axis a = axis(joy, n) reads the status of joystick with axis number n.
vrjoystick Method Description close close(joy) closes and invalidates the joystick object. The object cannot be used once it is closed. 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.
10 Functions — Alphabetical List vrlib Open Simulink block library for Simulink 3D Animation 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.
vrnode vrnode Create node or handle to existing node Syntax mynode = vrnode mynode = vrnode([]) mynode = vrnode(vrworld_object,'node_name') mynode = vrnode(vrworld_object, 'node_name','node_type') mynode = vrnode(vrworld_object, 'USE', othernode) mynode = vrnode(parent_node,'parent_field', 'node_name', 'node_type') mynode = vrnode(parent_node,'parent_field', 'USE', 'othernode') Arguments vrworld_object Name of a vrworld object representing a virtual world. node_name Name of the node.
10 Functions — Alphabetical List 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.
vrnode Method Description setfield Change field value of vrnode object sync Enable or disable synchronization of VRML fields with client See Also vrnode/delete | vrnode/get | vrworld | vrnode/getfield | vrnode/set | vrnode/setfield 10-79
10 Functions — Alphabetical List vrnode/delete Remove vrnode object Syntax delete(vrnode_object) delete(n) Arguments vrnode_object Name of a vrnode object. Description delete(vrnode_object) deletes the virtual world node. delete(n) deletes the vrnode object referenced by the vrnode handle n. If n is a vector of vrnode handles, multiple nodes are deleted. As soon as a node is deleted, it and all its child objects are removed from all clients connected to the virtual world.
vrnode/fields vrnode/fields VRML field summary of node object Syntax fields(vrnode_object) x = fields(vrnode_object) Arguments vrnode_object Name of a vrnode object representing the node to be queried. Description fields(vrnode_object) displays a list of VRML fields of the node associated with the vrnode object in the MATLAB Command Window. x = fields(vrnode_object) returns the VRML fields of the node associated with the vrnode object in a structure array.
10 Functions — Alphabetical List vrnode/get Property value of vrnode object Syntax get(vrnode_object) x = get(vrnode_object) x = get(vrnode_object, 'property_name') Arguments vrnode_object Name of a vrnode object representing the node to be queried. property_name Name of the property to be read. Description get(vrnode_object) lists all vrnode properties in the MATLAB Command Window.
vrnode/get Property Value Description Name String Name of the node. Type String VRML type of the node. The value is a string (for example, 'Transform', 'Shape'). World Handle Handle of the parent vrworld object. This is a vrworld object that represents the node's parent world.
10 Functions — Alphabetical List vrnode/getfield Field value of vrnode object Syntax getfield(vrnode_object) x = getfield(vrnode_object) x = getfield(vrnode_object,'fieldname') Arguments vrnode_object Name of a vrnode object representing the node to be queried. fieldname Name of the vrnode object field whose values you want to query. Description getfield(vrnode_object) displays all the field names and their current values for the respective VRML node.
vrnode/getfield See Also vrnode | vrnode/get | vrnode/set | vrnode/setfield 10-85
10 Functions — Alphabetical List vrnode/isvalid 1 if vrnode object is valid, 0 if not Syntax x = isvalid(vrnode_object_vector) Arguments vrnode_object_vector Name of an array of vrnode objects to be queried. 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.
vrnode/set vrnode/set Change property of virtual world node Syntax x = set(vrnode_object, 'property_name','property_value') Arguments vrnode_object Name of a vrnode object representing a node in the virtual world. property_name Name of a property. property_value Value of a property. Description x = set(vrnode_object, 'property_name','property_value') changes the specified property of the vrnode object to the specified value.
10 Functions — Alphabetical List Property Value Description World Handle Handle of the parent vrworld object. This is a vrworld object that represents the node's parent world. Read only. Currently, VRML nodes have no settable properties.
vrnode/setfield vrnode/setfield Change field value of vrnode object Syntax x = setfield(vrnode_object,'fieldname','fieldvalue') Arguments vrnode_object Name of a vrnode object representing the node to be changed. fieldname Name of the vrnode object VRML field whose values you want to set. fieldvalue Value of fieldname. Description x = setfield(vrnode_object,'fieldname','fieldvalue') changes the specified field of the vrnode object to the specified value.
10 Functions — Alphabetical List vrnode/sync Enable or disable synchronization of VRML fields with client Syntax sync(vrnode_object, 'field_name', 'action') Arguments vrnode_object Name of a vrnode object representing the node. field_name Name of the VRML field to be synchronized. action The action parameter determines what should be done: • 'on' enables synchronization of this field. • 'off' disables synchronization of this field.
vrnode/sync See Also vrnode | vrnode/get 10-91
10 Functions — Alphabetical List vrori2dir Convert viewpoint orientation to direction Syntax vrori2dir(r) vrori2dir(r,options) Description vrori2dir(r) converts the viewpoint orientation, specified by a rotation vector, r, to a direction the viewpoint points to. vrori2dir(r,options) converts the viewpoint orientation with the default algorithm parameters replaced by values defined in options.
vrpatch2ifs vrpatch2ifs Convert MATLAB patches to VRML IndexedFaceSet nodes Syntax node = vrpatch2ifs(patches,world) node = vrpatch2ifs(patches,shape) node = vrpatch2ifs(patches,parent) vrpatch2ifs(patches,ifs) Description node = vrpatch2ifs(patches,world) converts the patches array and saves the result into the vrnode array node. Each resulting IndexedFaceSet node in node is wrapped by the created Shape node residing in a root level of the world virtual world.
10 Functions — Alphabetical List Examples Convert MATLAB Patches to VRML IndexedFaceSet Nodes This command converts three MATLAB patches to VRML IndexedFaceSet nodes. Create surface using MATLAB peaks function. fig = figure('Name','Source peaks surface'); s = surf(peaks); Convert the peaks surface to a patch. peaksPatch = patch(surf2patch(s)); delete(s); shading interp; Create and open an empty virtual world.
vrpatch2ifs dv.position = [-1 15 30]; dv.orientation = [-0.38 -0.93 0 0.55]; setfield(dv,'set_bind',true); %#ok Convert the patch to an IndexedFaceSet nodes. The resulting nodes are created in the root level of supplied vrworld object) vrpatch2ifs(peaksPatch,w2); Show the result. vrfig2 = vrfigure(w2,'Name',... 'Virtual world containing resulting IndexedFaceSet node'); Input Arguments patches — MATLAB patches to convert array MATLAB patches, specified as an array.
10 Functions — Alphabetical List Virtual world that contains Shape nodes, specified as a vrworld object. parent — Parent grouping node vrnode object Parent grouping node, specified as a vrnode object. shape — Shape array array of Shape nodes Shape array, specified as an array of Shape nodes. ifs — VRML IndexedFaceSet nodes array VRML IndexedFaceSet nodes, specified as an array. Output Arguments node — Conversion result vrnode array Conversion result, returned as a vrnode array.
vrphysmod vrphysmod Add virtual reality visualization framework to block diagrams Syntax vrphysmod(vrmlfile, model) vrphysmod(vrmlfile, subsystem) Description vrphysmod(vrmlfile, model) or vrphysmod(vrmlfile, subsystem) updates the model or subsystem that the SimMechanics mech_import function generates. The model must be on the MATLAB path or already open prior to calling the vrphysmod function. As necessary, vrphysmod adds additional blocks to visualize the mechanical system in virtual reality.
10 Functions — Alphabetical List Examples To update the model four_link using the VRML file four_link.wrl: vrphysmod('four_link.wrl', 'four_link'); To update the subsystem four_link/FOURLINK_ASM using the VRML file four_link.wrl, ensure that the model that contains the subsystem is open, then: vrphysmod('four_link.wrl', 'four_link/FOURLINK_ASM'); To update the current system using the VRML file four_link.wrl: vrphysmod('four_link.
vrplay vrplay Play VRML animation file 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.
10 Functions — Alphabetical List stop step reverse rewind start play step forward fast forward last jump loop time indicator Setting the DefaultViewer property to internalv4 affects the behavior of the vrplay function. When you create additional vrplay windows using the File > New Window command, the window respects the current setting of the DefaultViewer property. By default, the File > New Window command creates the new player window implemented as a MATLAB figure.
vrplay Key Function 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 Functions — Alphabetical List vrrotvec Calculate rotation between two vectors Syntax r = vrrotvec(a,b) r = vrrotvec(a,b,options) Description r = vrrotvec(a,b) calculates a rotation needed to transform the 3D vector a to the 3D vector b. r = vrrotvec(a,b,options) calculates the rotation with the default algorithm parameters replaced by values defined in options.
vrrotmat2vec vrrotmat2vec Convert rotation from matrix to axis-angle representation Syntax r = vrrotmat2vec(m) r = vrrotmat2vec(m,options) Description r = vrrotmat2vec(m) returns an axis-angle representation of rotation defined by the rotation matrix m. r = vrrotmat2vec(m,options) converts the rotation with the default algorithm parameters replaced by values defined in options.
10 Functions — Alphabetical List vrrotvec2mat Convert rotation from axis-angle to matrix representation Syntax m = vrrotvec2mat(r) m = vrrotvec2mat(r,options) Description m = vrrotvec2mat(r) returns a matrix representation of the rotation defined by the axis-angle rotation vector, r. m = vrrotvec2mat(r,options) returns a matrix representation of rotation defined by the axis-angle rotation vector r, with the default algorithm parameters replaced by values defined in options.
vrsetpref vrsetpref Change Simulink 3D Animation preferences Syntax vrsetpref('preference_name', 'preference_value') vrsetpref('factory') Arguments preference_name Name of the preference. preference_value New value of the preference. Description This function sets the given Simulink 3D Animation preference to a given value. The following preferences are defined.
10 Functions — Alphabetical List Preference Description Int32 data type is returned as 'double'. Default is 'double'. 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'.
vrsetpref Preference Description DefaultFigureCapture FileName Specifies default file name for capturing viewer figures. See get (vrfigure) 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'.
10 Functions — Alphabetical List Preference Description 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. 10-108 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'.
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 Functions — Alphabetical List 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.
vrsetpref 3D Animation Viewer. Changes to the HttpPort or VrPort preferences take effect only after you restart the MATLAB software. DefaultFigureNavPanel — Controls the appearance of the navigation panel in the Simulink 3D Animation Viewer. For example, setting this value to 'translucent' causes the navigation panel to appear translucent.
10 Functions — Alphabetical List %file Refers to the VRML file name For instance, a possible value for the Editor preference is `%matlabroot\bin\win32\meditor.exe %file' If this preference is empty, the MATLAB editor is used. HttpPort -- Specifies the network port to be used for Web access. The port is given in the Web URL as follows: http://server.name:port_number The default value of this preference is 8123. TransportBuffer — Defines the size of the message window for client-server communication.
vrspacemouse vrspacemouse Create space mouse object Syntax mouse = vrspacemouse(id) Description mouse = vrspacemouse(id) creates a space mouse object capable of interfacing with a space mouse input device. The id parameter is a string that specifies the space mouse connection: COM1, COM2, COM3, COM4, USB1, USB2, USB3, or USB4. The vrspacemouse object has several properties that influence the behavior of the space mouse input device. The properties can be read or modified using dot notation (e.g., mouse.
10 Functions — Alphabetical List Property Description UpperPositionLimit Position coordinates for the upper limit of the mouse. 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.
vrspacemouse Method Description 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 Functions — Alphabetical List vr.utils.stereo3d class Stereoscopic vision settings for vr.canvas and vr.figure objects Description Specifies these stereoscopic vision properties: • Active, anaglyph, or no stereoscopic vision • Camera offset • Camera angle • Color filter for the left and right cameras • Horizontal image translation (HIT) Use a vr.utils.stereo3d object to set the Stereo3D, Stereo3DCameraOffset, and Stereo3DHIT stereoscopic vision properties of vrfigure and vr.canvas objects.
vr.utils.stereo3d class stereoVision = vr.utils.stereo3d.ANAGLYPH_RED_GREEN enables red-green anaglyph stereoscopic vision. stereoVision = vr.utils.stereo3d.ANAGLYPH_RED_BLUE enables red-blue anaglyph stereoscopic vision. stereoVision = vr.utils.stereo3d.ANAGLYPH_YELLOW_BLUE enables yellow-blue anaglyph stereoscopic vision. Output Arguments stereoVision — Stereoscopic vision settings for vr.canvas and vrfigure objects vr.utils.stereo3d object Stereoscopic vision settings for vr.
10 Functions — Alphabetical List Horizontal image translation, specified as either the predefined DEFAULT_HIT or as a floating-point number from 0 through 1, inclusive. The number of pixels for stereo 3D horizontal image translation (HIT) derives from this number. Horizontal image translation is the horizontal relationship of the two stereo images. By default, the background image is at zero and the foreground image appears to pop out from the monitor toward the person viewing the virtual world.
vr.utils.stereo3d class Stereoscopic vision mode. Read only. • STEREO3D_OFF — No stereoscopic vision. • STEREO3D_ACTIVE — Active stereoscopic vision. Stereoscopic vision uses quadbuffered rendering. You can use a graphics card driver to output stereoscopic vision. This mode allows active stereoscopic vision via shutter glasses. • STEREO3D_ANAGLYPH — Anaglyph stereoscopic vision. Stereoscopic vision is enabled using red-cyan anaglyph. Use appropriate anaglyph 3D glasses to see the effect.
10 Functions — Alphabetical List Examples Define and Apply Stereoscopic Vision Settings Create a virtual world. w = vrworld('octavia_scene'); open(w); c = vr.canvas(w); Specify stereoscopic vision settings. s3d = vr.utils.stereo3d.ANAGLYPH_RED_CYAN; s3d.CameraOffset = 0.05; s3d.CameraAngle = pi/128; Modify the red component of filter for the left camera. s3d.LeftCameraFilter(1:3) = s3d.LeftCameraFilter(1:3)... + [0.1 -0.05 -0.05]; Apply stereoscopic vision settings of vr.utils.
vrview vrview 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 .
10 Functions — Alphabetical List vrwho List virtual worlds in memory Syntax vrwho x = vrwho Description If you do not specify an output parameter, vrwho displays a list of virtual worlds in memory in the MATLAB Command Window. If you specify an output parameter, vrwho returns a vector of handles to existing vrworld objects, including those opened from the Simulink interface.
vrwhos vrwhos List details about virtual worlds in memory Syntax vrwhos Description vrwhos displays a list of virtual worlds currently in memory, with a description, in the MATLAB Command Window. The relation between vrwho and vrwhos is similar to the relation between who and whos.
10 Functions — Alphabetical List vrworld Create new vrworld object associated with virtual world Syntax myworld = vrworld(filename) myworld = vrworld(filename,'reuse') myworld = vrworld(filename, 'new') myworld = vrworld myworld = vrworld('') myworld = 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.
vrworld myworld = vrworld creates an invalid vrworld handle myworld = vrworld('') creates an empty vrworld object that is not associated with any VRML file myworld = vrworld([]) returns an empty array of returns an empty array of vrworld handles. A vrworld object identifies a virtual world in a way very similar to a handle. All functions that affect virtual worlds accept a vrworld object as an argument to identify the virtual world.
10 Functions — Alphabetical List Method Description reload Reload virtual world from VRML file save Write virtual world to VRML file set Change property values of vrworld object view View virtual world See Also vrworld/close | vrworld/delete | vrworld/open 10-126
vrworld/addexternproto vrworld/addexternproto Add externproto declaration to virtual world Syntax addexternproto(vrworld_object, protofile, protoname) addexternproto(vrworld_object, protofile, protoname, protodef) Arguments vrworld_object A vrworld object representing the virtual world. protofile String containing the name of the prototype file from which the EXTERNPROTO declaration is added. protoname String containing the name of the EXTERNPROTO declaration.
10 Functions — Alphabetical List in the virtual scene associated with vrworld_object. After you save the virtual world, these PROTO declarations no longer require a reference to the original file, protofile, that contains the EXTERNPROTO declarations.
vrworld/close vrworld/close Close virtual world Syntax close(vrworld_object) Arguments vrworld_object A vrworld object representing the virtual world. 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.
10 Functions — Alphabetical List close(myworld) See Also vrworld | vrworld/delete | vrworld/open 10-130
vrworld/delete vrworld/delete Remove virtual world from memory Syntax delete(vrworld_object) Arguments vrworld_object A vrworld object representing a virtual world. 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.
10 Functions — Alphabetical List vrworld/edit Open virtual world file in external VRML editor Syntax edit(vrworld_object) Arguments vrworld_object A vrworld object representing a virtual world. 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.
vrworld/get vrworld/get Property value of vrworld object Syntax get(vrworld_object) x = get(vrworld_object) x = get(vrworld_object, 'property_name') Arguments vrworld_object A vrworld object representing a virtual world. property_name Name of the property. Description get(vrworld_object) displays all the virtual world properties and their values. x = get(vrworld_object) returns an M-by-1 structure where the field names are the names of the virtual world properties.
10 Functions — Alphabetical List Property Value Description ClientUpdates 'off' | 'on' Client cannot or can update the virtual scene. Read/write. Default: 'on' Description String. Default: automatically taken from the VRML file property title Description of the virtual world as it appears on the main Web page. Read/write. Figures Vector of vrfigure objects Vector of handles to Simulink 3D Animation Viewer windows currently viewing the virtual world. Read only.
vrworld/get Property Value Description RecordInterval Vector of two doubles Start and stop times for scheduled animation recording. Corresponds to the virtual world object Time property. Read/ write. Default: [0 0] RemoteView 'off' | 'on' Default: 'off' Remote access flag. If the virtual world is enabled for remote viewing, it is set to 'on'; otherwise, it is set to 'off'. Read/ write. Time Double Current time in the virtual world. Read/ write.
10 Functions — Alphabetical List The RemoteView property is set to 'off' by default and can be set by the user. If it is set to 'on', all viewers can access the virtual world through the Web interface. If it is set to 'off', only host viewers can access it. The View property is set to 'on' by default and can be set by the user. When it is set to 'off', the virtual world is not accessible by the viewer. You rarely use this property.
vrworld/isvalid vrworld/isvalid 1 if vrworld object is valid, 0 if not Syntax x = isvalid(vrworld_object) Arguments vrworld_object A vrworld object representing a virtual world. Description A vrworld object is considered valid if its associated virtual world still exists. x = isvalid(vrworld_object) returns an array that contains a 1 when the elements of vrworld_object are valid vrworld objects, and returns a 0 when they are not. You use this method to check whether the vrworld object is still valid.
10 Functions — Alphabetical List vrworld/nodes List nodes available in virtual world Syntax nodes(vrworld_object, '-full') x = nodes(vrworld_object, '-full') Arguments vrworld_object A vrworld object representing a virtual world. '-full' Optional switch to obtain a detailed list of nodes and fields. Description If you give an output argument, the method nodes returns a cell array of the names of all available nodes in the world.
vrworld/open vrworld/open Open virtual world Syntax open(vrworld_object) Arguments vrworld_object A vrworld object representing a virtual world. 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.
10 Functions — Alphabetical List myworlds = [myworld1 myworld2]; open(myworlds) opens both of these virtual worlds.
vrworld/reload vrworld/reload Reload virtual world from VRML file Syntax reload(vrworld_object) Arguments vrworld_object A vrworld object representing a virtual world. 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.
10 Functions — Alphabetical List vrworld/save Write virtual world to VRML file Syntax save(vrworld_object,'vrml_file') save(vrworld_object,'vrml_file',export) Arguments vrworld_object vrworld object representing a virtual world vrml_file Name of VRML file for virtual world export Make an additional copy, specifying all resources relative to actual virtual world location. Set to true or false. Description The save method saves the current virtual world to a VRML97 file.
vrworld/set vrworld/set Change property values of vrworld object Syntax set(vrworld_object, 'property_name', property_value) Arguments vrworld_object Name of a vrworld object representing a virtual world. property_name Name of the property. property_value New value of the property. 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 Functions — Alphabetical List Property Value Description Nodes Vector of vrnode objects Vector of vrnode objects for all named nodes in the virtual world. Read only. Open 'off' | 'on' Indicates a closed or open virtual world. Read only. Default: 'off' Record3D 'off' | 'on' Default: 'off' Record3DFileName String. Default: '%f_anim_%n.wrl' Recording RecordMode 'off' | 'on' Enables 3-D animation recording. Read/ write. 3-D animation file name.
vrworld/set Property Value Description TimeSource 'external' | 'freerun' Source of the time for the virtual world. If set to 'external', time in the scene is controlled from the MATLAB interface (by setting the Time property) or the Simulink interface (simulation time). Default: 'external' If set to 'freerun', time in the scene advances independently based on the system timer. Read/write. 'off' | 'on' View Default: 'on' Indicates an unviewable or viewable virtual world. Read/write.
10 Functions — Alphabetical List vrworld/view View virtual world Syntax view(vrworld_object) x = view(vrworld_object) x = view(vrworld_object,'-internal') x = view(vrworld_object,'-web') Arguments vrworld_object A vrworld object representing a virtual world. 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.
vrworld/view Examples myworld = vrworld('vrpend.
Glossary simulation The process of running a dynamic system in nonreal time to observe its behavior. virtual figure object A handle to a Simulink 3D Animation viewer window. virtual node object A handle to a node in a virtual world that allows access to the node's properties. Virtual Reality Modeling Language The specification for displaying three-dimensional objects using a VRML viewer. virtual world An imaginary world where you can navigate around objects in three dimensions.