ScriptAnimationModel
(For high level concepts about how to use Lua to write scripted tasks, please see VR-Forces User's Guide.)
The DtScriptAnimationModel class refers to an animation model that can be used by a scripted task to animate an entity's movement. This class will be serialized to the simulation and might contain movement data if supplied by the developer.
Usage example:
local animation = ScriptAnimationModel(this)
animation:setClampType(5) -- ground clamp mode
for frame = 1,numFrames do
animation:addAnimationRow(1 / 5, 0, position, 0, 0, 0, 0)
velocity = velocity + acceleration / 25
position = position + velocity
end
mySubtaskId = vrf:startSubtask("animated-movement-task", { animation_model = animation, reference_heading = moveVector:getBearing()})
The local animation data will not contain data on the animation that is actively being run by the subtask. To find out what animation frame is currently being executed, you must get the SystemAttribute animation-frame. See the SystemAttribute documentation for more details.
Function List
| ScriptAnimationModel (entity) | Constructs a ScriptAnimationModel object for the given SimObject. |
| acceleration (frame) | Not applicable currently. |
| addAnimationRow (deltaTime, lateral-distance, range, altitude, headingOffset, pitchOffset, rollOffset) | Adds a new data row into the system. |
| animationFrame () | Returns the animation frame number. |
| animationModelFile () | Returns the current animation model file being used. |
| clampType () | Returns the clamp type of the animation model. |
| completionRule () | Returns the completion rule of the animation model. |
| elapsedAnimationTime () | Time in seconds that have passed |
| frameTime () | Returns the user-set frame time of the animation model . |
| isFinished () | Will Return true if animation is done. |
| location (frame) | Location3D of the object for given frame. |
| numAnimationFrames () | Returns number of animation frames. |
| orientation (frame, heading, pitch, roll) | Returns the topographic orientation at the given frame in three values. |
| reset () | Will Reset the animation to beginning |
| rotationalVelocity (frame) | Rotational velocity of object for give frame in radians/second |
| setAnimationFrame (frame) | Sets the current animation frame. |
| setAnimationModelFile (scriptObject) | Seeds the animation model with the animated movement object. |
| setClampType (clampType) | Sets how to clamp the entity in the animation model. |
| setCompletionRule (completionRule) | Sets how to complete the entity movement in the animation model. |
| setFrameTime (frameTime) | Sets the time for each frame to be the specified time, regardless of what the file says. |
| setTimeDeltaFromPreviousRow (row, deltaTime) | Sets the time for the row as delta time + the time from the previous row. |
| setTimeScale (timeScale) | Sets the time scale to apply to the animation model. |
| setTransitionSpeed (speed) | Sets the speed to use to transition into this animation. |
| speed (frame) | Gets the current speed in m/s for the specified frame |
| timeScale () | Returns the time scale of the animation model. |
| transitionSpeed () | Returns current transition speed. |
| velocity (frame) | Returns velocity vector3D in m/s for give frame |
Functions
- ScriptAnimationModel (entity)
-
Constructs a ScriptAnimationModel object for the given SimObject.
Parameters:
-
entity: A SimObject. Use "this".
Return value:
- A ScriptAnimationModel.
-
- acceleration (frame)
-
Not applicable currently. Will always return 0,0,0
Parameters:
-
frame: The frame number to get data for.
Return value:
- acceleration at given frame. Always 0,0,0 since scripted animation does not currently model acceleration between frames.
-
- addAnimationRow (deltaTime, lateral-distance, range, altitude, headingOffset, pitchOffset, rollOffset)
-
Adds a new data row into the system. The offsets are lateral distance, range and altitude distance from the entity's starting position. The orientation is heading, pitch, roll from the starting orientation. If no time is given the current frame time is used or the last two frames (if they exist) difference will be used as the delta for the new frame.
Parameters:
-
deltaTime: -
lateral-distance: -
range: -
altitude: -
headingOffset: -
pitchOffset: -
rollOffset:
Return value:
- The row number of the newly added row is returned.
-
- animationFrame ()
-
Returns the animation frame number.
Return value:
- the animation frame number.
- animationModelFile ()
-
Returns the current animation model file being used. Blank if no file.
Return value:
- filename of animation model file.
- clampType ()
-
Returns the clamp type of the animation model.
Return value:
- The clamp type of the model. Refer to Set Clamp Type for meaning of values.
- completionRule ()
-
Returns the completion rule of the animation model.
Return value:
- Completion rule of animation model. See Set Completion rule for values
- elapsedAnimationTime ()
-
Time in seconds that have passed
Return value:
- currently elapsed animation time.
- frameTime ()
-
Returns the user-set frame time of the animation model .
Return value:
- the user-set frame time of the animation model or the time between frame 0 and frame 1.
- isFinished ()
-
Will Return true if animation is done.
Return value:
- true if animation is finished.
- location (frame)
-
Location3D of the object for given frame.
Parameters:
-
frame: The frame number to get data for.
Return value:
- the location at the given frame.
-
- numAnimationFrames ()
-
Returns number of animation frames.
Return value:
- the number of animation frames.
- orientation (frame, heading, pitch, roll)
-
Returns the topographic orientation at the given frame in three values.
Parameters:
-
frame: The frame number to get data for. -
heading: -
pitch: -
roll:
Return values:
- Heading in radians.
- Pitch in radians.
- Roll in radians.
-
- reset ()
-
Will Reset the animation to beginning
Return value:
- state of animation model to initial settings.
- rotationalVelocity (frame)
-
Rotational velocity of object for give frame in radians/second
Parameters:
-
frame: The frame number to get data for.
Return value:
- rotational velocity at given frame.
-
- setAnimationFrame (frame)
-
Sets the current animation frame.
Parameters:
-
frame: The frame number to get data for.
-
- setAnimationModelFile (scriptObject)
-
Seeds the animation model with the animated movement object. Will also initialize with current entity information.
Parameters:
-
scriptObject:
-
- setClampType (clampType)
-
Sets how to clamp the entity in the animation model. Values are: 0 - As defined in animation model file 1 - Clamp to ground and clamp orientation 2 - Clamp to ground only 3 - Altitude specifies height above terrain 4 - Do no clamping 5 - Clamp if altitude offset is 0 6 - Use Face Cartesian coordinate system w/o clamping
Parameters:
-
clampType:
-
- setCompletionRule (completionRule)
-
Sets how to complete the entity movement in the animation model.
Parameters:
-
completionRule:
-
- setFrameTime (frameTime)
-
Sets the time for each frame to be the specified time, regardless of what the file says. To reset back to original time scale set to 0.
Parameters:
-
frameTime:
-
- setTimeDeltaFromPreviousRow (row, deltaTime)
-
Sets the time for the row as delta time + the time from the previous row. No other changes to other rows times are made.
Parameters:
-
row: -
deltaTime:
-
- setTimeScale (timeScale)
-
Sets the time scale to apply to the animation model. Default is 1.0.
Parameters:
-
timeScale:
-
- setTransitionSpeed (speed)
-
Sets the speed to use to transition into this animation. Will skip over frames until the desired speed is met, speeding up the animation to get to that point. Speed is in meters/second and is only used if the calculation animation frame is 0.
Parameters:
-
speed:
-
- speed (frame)
-
Gets the current speed in m/s for the specified frame
Parameters:
-
frame: The frame number to get data for.
Return value:
- the current speed (meters/second) at the given frame.
-
- timeScale ()
-
Returns the time scale of the animation model.
Return value:
- Time scale of model.
- transitionSpeed ()
- Returns current transition speed.
- velocity (frame)
-
Returns velocity vector3D in m/s for give frame
Parameters:
-
frame: The frame number to get data for.
Return value:
- velocity (local) at given frame.
-
