Main Content

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.

Limitations

The Aero.VirtualRealityAnimation object is not available for Aerospace Toolbox Online.

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.
waitWait until animation is done playing

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.

Character vector | string

VRWorld

Returns the vrworld object associated with the animation object.

MATLAB array

VRWorldFilename

Specify the .wrl file for the vrworld.

Character vector | string

VRWorldOldFilename

Specify the old .wrl files for the vrworld.

MATLAB array

VRWorldTempFilename

Specify the temporary .wrl file for the animation object.

Character vector | 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. Time source must be a timeseries or timetable object.

double

TFinal

Specify end time, in seconds. Time source must be a timeseries or timetable object.

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.

Character vector | string

VideoCompression

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

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

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.

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

collapse all

This example shows how to

  • Record the simulation of a virtual reality animation object

  • 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 = '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();

% Wait for the animation to stop running before modifying the object.

h.wait();

% Verify that a file named astMotion_JPEG_VR.avi was created in the current folder.
% Disable recording to preserve the file.

h.VideoRecord = 'off';

Simulate flight data for four seconds.

Use the data to create an animation object.

h = Aero.Animation;

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 the FramesPerSecond and TimeScaling properties determines the time step of the simulation (TimeScaling/|FramesPerSecond|). These settings result in a time step of approximately 0.5 s.

Create and load a body for the animation object.

idx1 = createBody(h,'pa24-250_orange.ac','Ac3d');

Load simulated flight trajectory data (simdata).

load simdata;

Set the time series data for the body.

h.Bodies{1}.TimeSeriesSource = simdata;

Create a figure object for the animation object.

show(h);

Set up recording properties.

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

Play the animation from TStart to TFinal.

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

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

Wait

Wait for the animation to stop playing before the modifying the object.

wait(h);

Disable recording to preserve the file.

h.VideoRecord = 'off';

This example shows how to schedule a three second recording a 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 = '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();

% Wait for the animation to stop running before modifying the object.

h.wait();

% 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';

Version History

Introduced in R2007b