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

    1. Retrieve the corresponding vrfigure object. For 2-D animations, the Simulink 3D Animation software records exactly what you see in the viewer window. Because 2-D animations record exactly what you see in the Simulink 3D Animation Viewer window, the properties that control 2-D file recording belong to vrfigure objects.

    2. Set the Record2D vrfigure property.

    3. To override default filenames for animation files, set the vrfigure Record2DFileName property.

  • To create 3-D animation files,

    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.

  • 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 Recording with MATLAB), 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 example.

Was this topic helpful?