Main Content

Record Offline Animations

Animation Recording

The Simulink® 3D Animation™ software enables you to record animations of virtual scenes that the Simulink or MATLAB® product controls. 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 can 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:

  • 3D file — The Simulink 3D Animation software traces object movements and saves that data into a virtual world 3D file using standard interpolators. You can then view these files with the Simulink 3D Animation Viewer. 3-D 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 virtual world 3D animation files, distribute all the inlined object and texture files referenced in the original virtual world 3D 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 can 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.%e

This format creates a unique file name each time you capture a frame or record the animation. The file name uses the %f, %n, and %e tokens.

The %f token is replaced with the name of the virtual world associated with the model. The %n token is a number that increments each time that you record a simulation for the same virtual world. For example, if the name of the virtual world file is vrplanets.wrl 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.

The %e token represents the virtual world 3D file extension (.wrl, .x3d, or .x3dv) as the extension of the virtual world that drives the animation. By default, the %e token uses the file extension of the virtual world 3D file that drives the animation. The VR Sink and VR Source block Source file parameter specifies the file extension of the virtual world.

You can specify other file name tokens. For details, see 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 for recording the animation.

  • 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 3–D Animation Files

To create a 3-D animation files 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 3D 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 in 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.

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

    To use the sample time of the associated VR Sink block to make the file playback correspond to the model simulation time, set FPS to auto.

    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, to create an AVI file where one second of simulation time corresponds to one 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

    An FPS setting of 15 is used, even if you set FPS to auto:

    • For a virtual world not associated with a Simulink model.

    • If the sample time of the associated VR Sink block cannot be determined at simulation start time.

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

    Dialog box with Autoselect compression method highlighted.

    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 from 0 through 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 from 0 through 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. 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 can turn off this panel for a cleaner view of the virtual scene. Choose View > Navigation Panel > None.

    You can reenable 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.

  1. In the MATLAB Command Window, type the model name.

    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. The Record mode list is enabled only if you also select either or both of the Record to 3D 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 to allow 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.

See Also

Functions

Related Examples

More About