Aero.VirtualRealityAnimation

Construct virtual reality animation object

Syntax

h = Aero.VirtualRealityAnimation

Description

h = Aero.VirtualRealityAnimation constructs a virtual reality animation object. The animation object is returned to h. The animation object has the following methods and properties.

Constructor Summary

ConstructorDescription
VirtualRealityAnimationConstruct virtual reality animation object.

Method Summary

MethodDescription
addNodeAdd existing node to current virtual reality world.
addRouteAdd VRML ROUTE statement to virtual reality animation.
addViewpointAdd viewpoint for virtual reality animation.
deleteDestroy virtual reality animation object.
initializeCreate and populate virtual reality animation object.
nodeInfoCreate list of nodes associated with virtual reality animation object.
playAnimate virtual reality world for given position and angle in time series data.
removeNodeRemove node from virtual reality animation object.
removeViewpointRemove viewpoint node from virtual reality animation.
saveasSave virtual reality world associated with virtual reality animation object.
updateNodesSet new translation and rotation of moveable items in virtual reality animation.

Notes on Aero.VirtualRealityAnimation Methods

Aero.VirtualRealityAnimation methods that change the current virtual reality world use a temporary .wrl file to manage those changes. These methods include:

Be aware of the following behavior:

  • After the methods make the changes, they reinitialize the world, using the information stored in the temporary .wrl file.

  • When you delete the virtual reality animation object, this action deletes the temporary file.

  • Use the saveas method to save the temporary .wrl file.

  • These methods do not affect user-created .wrl files.

Property Summary

PropertyDescriptionValues
Name

Specify name of the animation object.

string

VRWorld

Returns the vrworld object associated with the animation object.

MATLAB array

VRWorldFilename

Specify the .wrl file for the vrworld.

string

VRWorldOldFilename

Specify the old .wrl files for the vrworld.

MATLAB array

VRWorldTempFilename

Specify the temporary .wrl file for the animation object.

string

VRFigure

Returns the vrfigure object associated with the animation object.

MATLAB array

Nodes

Specify the nodes that the animation object contains.

MATLAB array

Viewpoints

Specify the viewpoints that the animation object contains.

MATLAB array

TimeScaling

Specify the time scaling, in seconds.

double

TStart

Specify the recording start time, in seconds.

double

TFinal

Specify end time, in seconds.

double

TCurrent

Specify current time, in seconds.

double

FramesPerSecond

Specify rate, in frames per second.

double

ShowSaveWarning

Specify save warning display setting.

double

  • 0 — No warning is displayed.

  • Non-zero — Warning is displayed.

VideoFileName

Specify video recording file name.

string

VideoCompression

Specify video recording compression file type. For more information on video compression, see the VideoWriter class.

  • 'Archival'

    Create Motion JPEG 2000 format file with lossless compression.

  • 'Motion JPEG AVI'

    Create compressed AVI format file using Motion JPEG codec.

  • 'Motion JPEG 2000'

    Create compressed Motion JPEG 2000 format file.

  • 'MPEG-4'

    Create compressed MPEG-4 format file with H.264 encoding (Windows® 7 systems only).

  • 'Uncompressed AVI'

    Create uncompressed AVI format file with RGB24 video.

Aero.VideoProfileTypeEnum

Default: 'Archival'

VideoQuality

Specify video recording quality. For more information on video quality, see the Quality property of the VideoWriter class.

Value between 0 and 100.

double

Default: 75

VideoRecord

Enable video recording.

  • 'on'

    Enable video recording.

  • 'off'

    Disable video recording.

  • 'scheduled'

    Schedule video recording. Use this property with the VideoTStart and VideoTFinal properties.

string

Default: 'off'

VideoTStart

Specify video recording start time for scheduled recording.

Value between TStart and TFinal.

double

Default: NaN, which uses the value of TStart.

VideoTFinal

Specify video recording stop time for scheduled recording.

Value between TStart and TFinal.

double

Default: NaN, which uses the value of TFinal.

Examples

expand all

Record Virtual Reality Animation Object Simulation

Simulate and record flight data.

Create an animation object.

h = Aero.VirtualRealityAnimation;

Control the frame display rate.

h.FramesPerSecond = 10;

Configure the animation object to set the seconds of animation data per second time scaling (TimeScaling) property.

h.TimeScaling = 5;

The combination of FramesPerSecond and TimeScaling property determine the time step of the simulation. These settings result in a time step of approximately 0.5 s.

This code sets the .wrl file to use in the virtual reality animation.

h.VRWorldFilename = [matlabroot,'/toolbox/aero/astdemos/asttkoff.wrl'];

Copy the .wrl file to a temporary directory and set the world file name to the copied .wrl file.

copyfile(h.VRWorldFilename,[tempdir,'asttkoff.wrl'],'f');
h.VRWorldFilename = [tempdir,'asttkoff.wrl'];

Load the animation world described in the 'VRWorldFilename' field of the animation object.

h.initialize();

Set simulation timeseries data. takeoffData.mat contains logged simulated data. takeoffData is set up as a 'StructureWithTime', which is one of the default data formats.

load takeoffData
[~, idxPlane] = find(strcmp('Plane', h.nodeInfo));
h.Nodes{idxPlane}.TimeseriesSource = takeoffData;
h.Nodes{idxPlane}.TimeseriesSourceType = 'StructureWithTime';

Use the example custom function vranimCustomTransform to correctly line up the position and rotation data with the surrounding objects in the virtual world. This code sets the coordinate transformation function for the virtual reality animation.

 h.Nodes{idxPlane}.CoordTransformFcn = @vranimCustomTransform;

Set up recording properties.

h.VideoRecord = 'on';
h.VideoQuality = 50;
h.VideoCompression = 'Motion JPEG AVI'
h.VideoFilename = 'astMotion_JPEG_VR';

Play the animation.

h.play();

Verify that a file named astMotion_JPEG_VR.avi was created in the current folder.

Disable recording to preserve the file.

h.VideoRecord = 'off';

Record Virtual Reality Animation for Four Seconds

Simulate flight data for four seconds.

Create an animation object.

h = Aero.VirtualRealityAnimation;

Control the frame display rate.

h.FramesPerSecond = 10;

Configure the animation object to set the seconds of animation data per second time scaling (TimeScaling) property.

h.TimeScaling = 5;

The combination of FramesPerSecond and TimeScaling properties determines the time step of the simulation. These settings result in a time step of approximately 0.5 s.

This code sets the .wrl file to use in the virtual reality animation.

h.VRWorldFilename = [matlabroot,'/toolbox/aero/astdemos/asttkoff.wrl'];

Copy the .wrl file to a temporary directory and set the world file name to the copied .wrl file.

copyfile(h.VRWorldFilename,[tempdir,'asttkoff.wrl'],'f');
h.VRWorldFilename = [tempdir,'asttkoff.wrl'];

Load the animation world described in the 'VRWorldFilename' field of the animation object.

h.initialize();

Set simulation timeseries data. takeoffData.mat contains logged simulated data. takeoffData is set up as a 'StructureWithTime', which is one of the default data formats.

load takeoffData
[~, idxPlane] = find(strcmp('Plane', h.nodeInfo));
h.Nodes{idxPlane}.TimeseriesSource = takeoffData;
h.Nodes{idxPlane}.TimeseriesSourceType = 'StructureWithTime';

Use the example custom function vranimCustomTransform to correctly line up the position and rotation data with the surrounding objects in the virtual world. This code sets the coordinate transformation function for the virtual reality animation.

h.Nodes{idxPlane}.CoordTransformFcn = @vranimCustomTransform;

Set up recording properties.

h.VideoRecord = 'on';
h.VideoQuality = 50;
h.VideoCompression = 'Motion JPEG AVI'
h.VideoFilename = 'astMotion_JPEG';

Play the animation from TFinal to TStart.

h.TSTart = 1;
h.TFinal = 5;
h.play();

Verify that a file named astMotion_JPEG_VR.avi was created in the current folder. When you rerun the recording, notice that the play time is faster than when you record for the length of the simulation time.

Disable recording to preserve the file.

h.VideoRecord = 'off';

Schedule Three Second Recording of Simulation

Schedule three second recording of virtual reality object animation simulation.

Create an animation object.

h = Aero.VirtualRealityAnimation;

Control the frame display rate.

h.FramesPerSecond = 10;

Configure the animation object to set the seconds of animation data per second time scaling (TimeScaling) property.

h.TimeScaling = 5;

The combination of FramesPerSecond and TimeScaling properties determines the time step of the simulation. These settings result in a time step of approximately 0.5 s.

This code sets the .wrl file to use in the virtual reality animation.

h.VRWorldFilename = [matlabroot,'/toolbox/aero/astdemos/asttkoff.wrl'];

Copy the .wrl file to a temporary directory and set the world file name to the copied .wrl file.

copyfile(h.VRWorldFilename,[tempdir,'asttkoff.wrl'],'f');
h.VRWorldFilename = [tempdir,'asttkoff.wrl'];

Load the animation world described in the 'VRWorldFilename' field of the animation object.

h.initialize();

Set simulation timeseries data. takeoffData.mat contains logged simulated data. takeoffData is set up as a 'StructureWithTime', which is one of the default data formats.

load takeoffData
[~, idxPlane] = find(strcmp('Plane', h.nodeInfo));
h.Nodes{idxPlane}.TimeseriesSource = takeoffData;
h.Nodes{idxPlane}.TimeseriesSourceType = 'StructureWithTime';

Use the example custom function vranimCustomTransform to correctly line up the position and rotation data with the surrounding objects in the virtual world. This code sets the coordinate transformation function for the virtual reality animation.

h.Nodes{idxPlane}.CoordTransformFcn = @vranimCustomTransform;

Set up recording properties.

h.VideoQuality = 50;
h.VideoCompression = 'Motion JPEG AVI'
h.VideoFilename = 'astMotion_JPEG';

Set up simulation time from TFinal to TStart.

h.TSTart = 1;
h.TFinal = 5;

Set up to record between two and four seconds of the four second simulation.

h.VideoRecord='scheduled';
h.VideoTSTart = 2;
h.VideoTFinal = 4;

Play the animation.

h.play();

Verify that a file named astMotion_JPEG_VR.avi was created in the current folder. When you rerun the recording, notice that the play time is faster than when you record for the length of the simulation time.

Disable recording to preserve the file.

h.VideoRecord = 'off';
Was this topic helpful?