| Contents | Index |
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 Viewing Virtual Worlds) or the MATLAB interface (described in this section). You can then play back these animations offline, in other words, independent of the MATLAB, Simulink, or Simulink 3D Animation products. You might want to generate such files for presentations, to distribute simulation results, or to generate archives.
Note Optimally, use the Simulink 3D Animation viewer (Viewing Virtual Worlds) to record animations of virtual worlds associated with Simulink models. This method ensures that all necessary virtual world and vrfigure properties are properly set to record simulations. The Simulink 3D Animation viewer is the recommended interface to record animations. If you are working with virtual scenes controlled from MATLAB, you can still record virtual scenes through the MATLAB interface. |
You can save the virtual world offline animation data in the following formats:
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. If you make any navigation movements in the Simulink 3D Animation viewer while recording the animation, the Simulink 3D Animation software does not save any of these movements.
2-D Audio Video Interleave (AVI) file — The Simulink 3D Animation software writes animation data into an .avi file. The Simulink 3D Animation software uses 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.
You can use MATLAB to either manually record an animation or schedule a preset time interval for recording. For details, see:
By default, the Simulink 3D Animation software records animations in a file named according to the following format:
%f_anim_%n.<extension>
This format creates a unique filename each time you record the animation. The Simulink 3D Animation software places the file in the current folder. %f and %n are tokens, where %f is replaced with the name of the virtual world associated with the model and %n is a number that is incremented each time you record an animation for the same virtual world. If you do not change the default filename, for example, if the name of the virtual world file is vrplanets and you record the simulation for the first time, the animation file is:
vrplanets_anim_1.wrl
If you run and record the simulation a second time, the animation filename is vrplanets_anim_2.wrl.
Create multiple file names with time or date stamps, with a unique file created at each run.
You can use a number of tokens to customize the automated generation of animation files. This section describes how to use these tokens to create varying animation filenames. The following tokens are the same for .wrl and .avi files.
| Token | Description |
|---|---|
| %d | The full path to the world VRML file replaces this token in the filename string and creates files in directories relative to the virtual world file location. For example, the format %d/animdir/animfile.avi saves the animation into the animdir subfolder of the folder containing the virtual world VRML file. This token is most helpful if you want to ensure that the virtual world file and animation file are in the same folder. |
| %D | The current day in the month replaces this token in the filename string. For example, the format %f_anim_%D.wrl saves the animation to vrplanets_anim_29.wrl for the 29th day of the month. |
| %f | The virtual world filename replaces this token in the filename string and creates files whose root names are the same as those of the virtual world. For example, the format %f_anim_%D.wrl saves the animation to vrplanets_anim_29.wrl. This token might be useful if you use different virtual worlds for one model. |
| %h | The current hour replaces this token in the filename string. For example, the format %f_anim_%h.wrl saves the animation to vrplanets_anim_14.wrl for any time between 14:00 and 15:00. |
| %m | The current minute replaces this token in the filename string. For example, the format %f_anim_%h%m.wrl saves the animation to vrplanets_anim_1434.wrl for a start record time of 14:34. |
| %M | The current month replaces this token in the filename string. For example, the format %f_anim_%M.wrl saves the animation to vrplanets_anim_4.wrl for a start record time in April. |
| %n | The current incremental number replaces this token in the filename string and creates rolling numbered filenames such that subsequent runs of the model simulation create incrementally numbered filenames. This feature allows you to run a Simulink model multiple times but create a unique file at each run. For example, the format %f_anim_%n.wrl saves the animation to vrplanets_anim_1.wrl on the first run, vrplanets_anim_2.wrl on the second run, and so forth. This token is useful if you expect to create files of different parts of the model simulation. |
| %s | The current second replaces this token in the filename string. For example, the format %f_anim_%h%m%s.wrl saves the animation to vrplanets_anim_150430.wrl for a start record time of 15:04:30. |
| %Y | The current four-digit year replaces this token in the filename string. For example, the format %f_anim_%Y.wrl saves the animation to vrplanets_anim_2005.wrl for the year 2005. |
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. You create and record the animation file by interactively starting and stopping the recording from the MATLAB Command Window.
This procedure uses the vrplanets demo. It describes how to create a VRML animation filename with the default name format.
Run the Simulink model for vrplanets. In the MATLAB window, type
vrplanets
The Simulink model appears. Also by default, the Simulink 3D Animation viewer for that model is loaded and becomes active. If the viewer does not appear, double-click the Simulink® 3D Animation block in the Simulink model.
To work with the virtual world associated with vrplanets from the MATLAB interface, retrieve the virtual world handle. Use the vrwhos command. Type
vrwhos
If the result shows that only one vrworld object is in the workspace, assign its handle directly to a variable. Type
myworld = vrwho;
If multiple virtual worlds are listed, you must select which of these virtual worlds you want to manipulate. To select the virtual world, you can use indexing or a selection method using a string comparison of virtual world descriptions. For the indexing method, type
worlds = vrwho; myworld = worlds(1);
For the string comparison method, type
worlds = vrwho;
myworld =
worlds(strcmp('Planets',get(worlds,'Description')));
To have the Simulink 3D Animation software manually record the animation, set the RecordMode property to manual. Type
set(myworld,'RecordMode','manual');
Direct the Simulink 3D Animation software to record the animation to a VRML format file. Type
set(myworld,'Record3D','on');
Run the Simulink model. From the Simulation menu, select Normal, then click Start. Alternatively, if you are using the Simulink 3D Animation default viewer, you can run the Simulink model with one of the following from the viewer.
From the menu bar, select the Simulation menu Start option to start or stop the simulation.
From the toolbar, click Start/pause/continue simulation to start the simulation.
From the keyboard, press Ctrl+T to start the simulation.
As the simulation runs, start recording the animation by setting the virtual world Recording property. Type
set(myworld,'Recording','on');
This turns on the recording state.
When you want to stop the recording operation, type
set(myworld,'Recording','off');
The Simulink 3D Animation software stops recording the animation. The Simulink 3D Animation software creates the file vrplanets_anim_1.wrl in the current working folder. If the simulation stops before you stop recording, the recording operation stops and creates the animation file.
Stop the simulation. You can use one of the following from the viewer.
From the menu bar, select the Simulation menu Stop option to stop the simulation.
From the toolbar, click Stop simulation to stop the simulation.
From the keyboard, press Ctrl+T to stop the simulation.
You do not need to manually stop the recording before stopping the simulation. If you do not manually stop the recording, the recording operation does not stop and create the animation file when the simulation stops.
Close and delete the objects if you do not want to continue using them.
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. You create and record the animation file by interactively starting and stopping the recording from the MATLAB Command Window.
This procedure uses the vrplanets demo. It describes how to create an .avi animation filename with the default name format.
Run the Simulink model for vrplanets. In the MATLAB window, type
vrplanets
The Simulink model appears. Also by default, the Simulink 3D Animation viewer for that model is loaded and becomes active. If the viewer does not appear, double-click the Simulink® 3D Animation block in the Simulink model.
To work with the virtual world associated with vrplanets from the MATLAB interface, retrieve the virtual world handle. Use the vrwhos command. Type
vrwhos
If the result indicates that only one vrworld object is in the workspace, assign its handle directly to a variable. Type
myworld = vrwho;
If multiple virtual worlds are listed, you must select which of these virtual worlds you want to manipulate. To select the virtual world, you can use indexing or a selection method using a string comparison of virtual world descriptions. For the indexing method, type
worlds = vrwho; myworld = worlds(1);
For the string comparison method, type
worlds = vrwho;
myworld =
worlds(strcmp('Planets',get(worlds,'Description')));
If the description string is unique, myworld is assigned the correct virtual world.
To retrieve the handle to the currently displayed the Simulink 3D Animation viewer figure, type
f=get(myworld,'Figures')
To have the software manually record the animation, set the RecordMode property to manual. Type
set(myworld,'RecordMode','manual');
Direct the Simulink 3D Animation software to record the animation as a .avi format file. Type
set(f,'Record2D','on');
Disable the navigation panel. The navigation panel appears at the bottom of the virtual scene view. You might want to turn off this panel for a cleaner view of the virtual scene. Type
set(f,'NavPanel','none');
Run the Simulink model. From the Simulation menu, select Normal, then click Start. Alternatively, if you are using the Simulink 3D Animation default viewer, you can run the Simulink model with one of the following from the viewer:
From the menu bar, select the Simulation menu Start option to start or stop the simulation.
From the toolbar, click Start/pause/continue simulation to start the simulation.
From the keyboard, press Ctrl+T to start the simulation.
As the simulation runs, start recording the animation by setting the virtual world Recording property. Type
set(myworld,'Recording','on');
This turns on the recording state.
To stop the recording operation, type
set(myworld,'Recording','off');
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.
Stop the simulation. You can use one of the following from the viewer.
From the menu bar, select the Simulation menu Stop option to stop the simulation.
From the toolbar, click Stop simulation to stop the simulation.
From the keyboard, press Ctrl+T to stop the simulation.
You do not need to manually stop the simulation. If you do not manually stop the recording, the recording operation does not stop and create the animation file until the simulation stops.
If you want to enable the Navigation Panel again, type
set(f,'NavPanel','halfbar');
Close and delete the objects if you do not want to continue using them.
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. One second of the recorded animation time corresponds to one second of Simulink time.
This procedure uses the vrplanets demo. It describes how to create a VRML animation filename with the default name format.
Run the Simulink model for vrplanets. In the MATLAB window, type
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 Simulink® 3D Animation block in the Simulink model.
To work with the virtual world associated with vrplanets from the MATLAB interface, retrieve the virtual world handle. Use the vrwhos command. Type
vrwhos
If the result indicates that only one vrworld object is in the workspace, assign its handle directly to a variable. Type
myworld = vrwho;
If multiple virtual worlds are listed, you must select which of these virtual worlds you want to manipulate. To select the virtual world, you can use indexing or a selection method using a string comparison of virtual world descriptions. For the indexing method, type
worlds = vrwho; myworld = worlds(1);
For the string comparison method, type
worlds = vrwho;
myworld =
worlds(strcmp('Planets',get(worlds,'Description')));
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');
Direct the Simulink 3D Animation software to record the animation in a VRML format file.
set(myworld,'Record3D','on');
Select the start and stop times during which you want to record the animation. For example, enter 5 as the start time and 15 as the stop time.
set(myworld,'RecordInterval',[5 15]);
Ensure that the recording start time value is not earlier than the start time of the Simulink model; the recording operation cannot start in this instance. If the stop time exceeds the stop time of the Simulink model, or if it is an out of bounds value such as a negative number, the recording operation stops when the simulation stops. Note that the recording can be slow.
Run the Simulink model. From the Simulation menu, select Normal, then click Start. Alternatively, if you are using the Simulink 3D Animation default viewer, you can run the Simulink model with one of the following from the viewer.
From the menu bar, select the Simulation menu Start option to start the simulation.
From the toolbar, click Start/pause/continue simulation to start the simulation.
From the keyboard, press Ctrl+T to start the simulation.
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.wrl in the current working folder when finished, where N is either 1 or more, depending on how many file iterations you have.
When you are done, stop the simulation. You can use one of the following from the viewer.
From the menu bar, select the Simulation menu Stop option to stop the simulation.
From the toolbar, click Stop simulation to stop the simulation.
From the keyboard, press Ctrl+T to stop the simulation.
Close and delete the objects if you do not want to continue using them.
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. One second of the recorded animation time corresponds to one second of Simulink time.
This procedure uses the vrplanets demo. It describes how to create an .avi animation filename with the default name format.
Run the Simulink model for vrplanets. In the MATLAB window, type
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 Simulink® 3D Animation block in the Simulink model.
To work with the virtual world associated with vrplanets from the MATLAB interface, retrieve the virtual world handle. Use the vrwhos command. Type
vrwhos
If the result indicates that only one vrworld object is in the workspace, assign its handle directly to a variable. Type
myworld = vrwho;
If multiple virtual worlds are listed, you must select which of these virtual worlds you want to manipulate. To select the virtual world, you can use indexing or a selection method using a string comparison of virtual world descriptions. For the indexing method, type
worlds = vrwho; myworld = worlds(1);
For the string comparison method, type
worlds = vrwho;
myworld =
worlds(strcmp('Planets',get(worlds,'Description')));
To retrieve the handle to the currently displayed Simulink 3D Animation viewer figure, type
f=get(myworld,'Figures')
To have the Simulink 3D Animation software manually record the animation, set the RecordMode property to manual. Type
set(myworld,'RecordMode','scheduled');
Direct the Simulink 3D Animation software to record the animation as an .avi format file. Type
set(f,'Record2D','on');
Select the start and stop times during which you want to record the animation. For example, enter 5 as the start time and 15 as the stop time.
set(myworld,'RecordInterval',[5 15]);
Ensure that the recording start time value is not earlier than the start time of the Simulink model; the recording operation cannot start in this instance. If the stop time exceeds the stop time of the Simulink model, or if it is an out of bounds value such as a negative number, the recording operation stops when the simulation stops. Note that the recording can be slow.
Disable the Navigation Panel. The Navigation Panel appears at the bottom of the virtual scene view. You might want to turn off this panel for a cleaner view of the virtual scene. Type
set(f,'NavPanel','none');
Ensure that the virtual reality figure window is the topmost window.
Run the Simulink model. From the Simulation menu, select Normal, then click Start. Alternatively, if you are using the Simulink 3D Animation default viewer, you can run the Simulink model with one of the following from the viewer:
From the menu bar, select the Simulation menu Start option to start the simulation.
From the toolbar, click Start/pause/continue simulation to start the simulation.
From the keyboard, press Ctrl+T to start the simulation.
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.
When you are done, stop the simulation. You can use one of the following from the viewer:
From the menu bar, select the Simulation menu Stop option to stop the simulation.
From the toolbar, click Stop simulation to stop the simulation.
From the keyboard, press Ctrl+T to stop the simulation.
If you want to enable the navigation panel again, type
set(f,'NavPanel','halfbar');
Close and delete the objects if you do not want to continue using them.
This topic assumes that you have a VRML or .avi animation file that you want to view. If you do not have an animation file, see Manual 3-D VRML Animation Recording or Scheduled 3-D VRML Animation Recording for descriptions of how to create one.
At the MATLAB window, type vrplay(filename), where filename is the name of your VRML file. This opens the Simulink® 3D Animation player and your file. Using the Simulink® 3D Animation player GUI, you can control the playback of your file.
As an example, play the animation file based on the vr_octavia demo by running vrplay('octavia_scene_anim.wrl').
vrplay works only with VRML animation files created using the Simulink 3D Animation VRML recording functionality.
Alternatively, you can view the VRML file in one of the following ways:
Double-click the VRML file. A VRML-enabled Web browser opens with the animation running. To view the resulting animation file, you must have a VRML-enabled Web browser installed on your system. Also, ensure that the .wrl extension is associated with the blaxxun Contact Web browser.
At the MATLAB window, type
w=vrview('vrplanets_anim_1.wrl');
set(w,'TimeSource','freerun');
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.
set(w,'TimeSource','external');
To close the viewer and delete the world, get the handle of the vrfigure object and close it, as follows:
f=get(w,'Figures') close(f); delete(w);
Or, to close all vrfigure objects and delete the world, type
vrclose delete(w);
Change folder to the one that contains the .avi animation file.
The program associated with .avi files in your system (for example, Windows Media® Player Media Player) opens for the .avi file. If your .avi file is not yet running, start it now from the application. The animation file runs.
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. Virtual worlds that are controlled completely from the MATLAB interface have no default, intuitive interpretation of time relation between MATLAB environment models and virtual scenes.
Note Many engineering time-dependent problems are modeled and solved in MATLAB. For those that have meaningful visual representation, you can create virtual reality models and animate their solutions. In addition, the offline animation time can represent any independent variable along which you can observe and visualize a model solution. Using offline animation files can bring the communication of such engineering problem resolutions to new levels. The Simulink 3D Animation demo vrheat (heat transfer visualization) is an example of a time-dependent problem modeled and solved in MATLAB. Its modified version, vrheat_anim, shows the use of the programming technique described in this topic. |
To record animation files for virtual worlds that are not associated with Simulink models, note the following guidelines. You should be an advanced Simulink 3D Animation user.
Retrieve the vrworld object handle of the virtual scene that you want to record.
To record 2-D animations,
Retrieve the corresponding vrfigure object. For 2-D animations, the Simulink 3D Animation software records exactly what you see in the viewer window. Because 2-D animations record exactly what you see in the Simulink 3D Animation viewer window, the properties that control 2-D file recording belong to vrfigure objects.
Set the Record2D vrfigure property.
To override default filenames for animation files, set the vrfigure Record2DFileName property.
To create 3-D animation files,
Retrieve the corresponding vrworld object.
Set the Record3D vrworld property.
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.
To specify that the virtual world time source is an external one, set the vrworld property TimeSource to external. This ensures that the MATLAB software controls the virtual world scene time. Type
set(virtual_world,'TimeSource', 'external')
To specify time values at which you want to save animation frames, iteratively set the vrworld Time property. Note that for a smoother animation, you should set the time at equal intervals, for example, every 5 seconds. Use a sequence like
set(virtual_world,'Time',time_value)
For example, to set the Time property for vrworld, w, with values increasing by 10, enter
set(w,'Time',10); set(w,'Time',20); set(w,'Time',30); set(w,'Time',40); set(w,'Time',50); set(w,'Time',60); set(w,'Time',70); set(w,'Time',80); set(w,'Time',90); set(w,'Time',100); set(w,'Time',110); set(w,'Time',120); set(w,'Time',130); set(w,'Time',140);
If you select a start time of 60 and a stop time of 120 (as described in Scheduled 3-D VRML Animation Recording), the Simulink 3D Animation software starts recording at 60 and stops at 120.
Because of the repetitive nature of the time interval setting, set the Time property in a loop from within a script or program.
After you set the vrworld Time property, set the virtual scene object properties as necessary. You should set these properties to values that correspond to the given time frame to achieve the desired animation effect.
In each time frame, issue the vrdrawnow command for scene changes. This command renders and updates the scene.
The following code fragment contains a typical loop that iteratively sets the Time property, changes a virtual scene object property, and calls vrdrawnow to render the scene:
for time=StartTime:Step:StopTime % advance the time in the virtual scene set(myworld,'Time',time); % here we change VRML nodes properties myworld.Car.translation = [ time*speed 0 0 ]; % render the changed position vrdrawnow; end
If you set the Time property at or outside the end boundary of RecordInterval, the Simulink 3D Animation software stops recording. You can then view the resulting animation file.
For a complete example of how to perform this kind of animation recording, refer to the Simulink 3D Animation vrheat_anim demo.
![]() | Using the MATLAB Interface | Build Virtual Reality Worlds | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |