Record Offline Animations

Animation Recording

The Simulink® 3D Animation™ software enables you to record animations of virtual scenes that are controlled by the Simulink or MATLAB® product. You can record simulations using the Simulink 3D Animation Viewer. You can then play back these animations offline, in other words, independent of the MATLAB, Simulink, or Simulink 3D Animation products. You might want to generate such files for presentations, to distribute simulation results, or to generate archives.

    Note   Optimally, use the Simulink 3D Animation Viewer to record animations of virtual worlds associated with Simulink models. This method ensures that all necessary virtual world and vrfigure properties are properly set to record simulations. If you are working with virtual scenes controlled from MATLAB, you can record virtual scenes through the MATLAB interface. For details, see Animation Recording.

You can 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. For details, see Capture Frames.

Recording Formats

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.

      Note   If you distribute VRML animation files, be sure to also distribute all the inlined object and texture files referenced in the original VRML world file.

  • 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.

      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.

See the following topics:

File Names

By default, the Simulink 3D Animation Viewer records simulations or captures virtual scene frames in a file named with the following format:

%f_anim_%n.<extension>

This format creates a unique file name each time you capture a frame or record the animation. %f and %n are tokens. %f is replaced with the name of the virtual world associated with the model and %n is a number that increments each time you record a simulation for the same virtual world. If you do not change the default file name, for example, if the name of the virtual world file is vrplanets and you record a simulation for the first time, the animation file is

vrplanets_anim_1.wrl

If you record the simulation a second time, the animation file name is vrplanets_anim_2.wrl. In the case of frame captures, capturing another frame of the scene increments the number.

For details, see Define File Name Tokens.

Start and Stop Animation Recording

You can start or stop recording animations of the virtual world from the Simulink 3D Animation viewer through the menu bar, toolbar, or keyboard. This section assumes that you have specified animation files into which the animation is to be recorded.

  • From the menu bar, choose the Simulation menu, Run option to start recording the animation (select Stop to stop the recording).

  • From the toolbar, click the Start/stop recording button to start or stop recording the animation (select Stop to stop the recording). Alternatively, you can use the Recording menu Start Recording and Stop Recording options. From the keyboard, press Ctrl+R to toggle between starting or stopping the animation recording.

  • Stop the simulation or let the model simulate until the defined simulation stop time.

      Note   If you stop the simulation while recording is enabled, the viewer also stops recording the animation.

Play Animation Files

You can view animation files using the 3D Animation Player or vrplay. For details, see Play Animation Files.

Record Files in the VRML Format

To create a 3-D VRML 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. 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. This is located under the Frame Capture dialog.

  4. Select the Record to VRML file check box.

    The File text field becomes active and the default file name, %f_anim_%n.wrl, appears in the text field.

    To save files to other file names, see File Name Tokens.

  5. Click OK.

After you define an animation file, you can manually record simulations. See Start and Stop Animation Recording. If you want to record simulations on a schedule, see Schedule Files for Recording.

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. 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 box. This is located under the Frame Capture dialog box.

  4. Select the Record to AVI file check box.

    The File text field and Compression selection area become active, and the default file name, %f_anim_%n.avi, appears in the text field.

    To save files to other file names, see File Name Tokens.

  5. Set the FPS (Frames Per Second) to an appropriate value.

    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. Simulink 3D Animation saves the value 25 into the AVI file FPS parameter.

      Note:   For a virtual world not associated with a Simulink model, or if the sample time of the associated VR Sink block cannot be determined at simulation start time, an FPS setting of 15 is used, even if you set FPS to auto.

  6. From the Compression list, select a compression method for the .avi file. Because .avi files can become large, you might want to compress the .avi file.

    Choose from

    • Autoselect — Allows the Simulink 3D Animation software to select the most appropriate compression codec. This option allows you to specify a quality setting that is a number between 0 and 100. Higher quality numbers result in higher video quality and larger file sizes. Lower quality numbers result in lower video quality and smaller file sizes.

    • Lossless — Forces the Simulink 3D Animation software to compress the animation file without loss of data. (Typically, the compression of files sacrifices some data.)

    • User Defined — Enables you to specify a particular compression codec. This option allows you to specify a quality setting that is a number between 0 and 100. Higher quality numbers result in higher video quality and larger file sizes. Lower quality numbers result in lower video quality and smaller file sizes. You need to specify an identification string of a codec that your system supports.

    • None — Prevents any compression for the animation file.

  7. Disable the navigation panel. The navigation panel appears at the bottom of the virtual scene view. You might want to turn off this panel for a cleaner view of the virtual scene. Choose View > Navigation Panel > None.

    You can re-enable the Navigation Panel (for example, choose View > Navigation Panel > Halfbar) after you are finished recording the .avi file.

  8. Click OK.

After you define an animation file, you can record animations. See Start and Stop Animation Recording. If you want to record animations on a schedule, see Schedule Files for Recording.

Schedule Files for Recording

This topic describes how to schedule the recording of an animation using the MATLAB interface for a virtual world that is associated with a Simulink model. In this case, the timing in an animation file derives from the simulation time. One second of the recorded animation time corresponds to one second of Simulink time. To schedule the recording of an animation file, you preset the simulation time interval during which the animation recording occurs. This procedure uses the vrplanets example. It assumes that you have already configured the recording parameters for an animation file.

  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. In the Recording section, this dialog box contains the Record mode list. Note that the Record mode list is enabled only if you also select either or both of the Record to VRML and Record to AVI check boxes.

  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.

    Ensure that the recording start time value is not earlier than the start time of the Simulink model; the recording operation cannot start in this instance. If the stop time exceeds the stop time of the Simulink model, or if it is an out of bounds value such as a negative number, the recording operation stops when the simulation stops.

      Note:   You can also set the stop time before the start time. This allows for a scenario where the simulation starts first and you manually start recording. The recording then automatically stops at stop time and automatically restarts at start time.

  5. Click OK.

After you define the schedule, you can record simulations. See Start and Stop Animation Recording.

    Note   You can override the recording schedule by starting or stopping the recording interactively.

Was this topic helpful?