Class ModelAnimation
- java.lang.Object
-
- com.google.ar.sceneform.animation.ModelAnimation
-
public class ModelAnimation extends java.lang.Object
An ModelAnimation is a reusable set of keyframe tracks which represent an animation.This class provides support for animating time positions on a targeted
AnimatableModel
Here are some use cases for animations :
-
On a very basic 3D model like a single infinite rotating sphere, you should not have to
use this class but probably instead just call
AnimatableModel#animate()
-
For a synchronised animation set like animating a cube and a sphere position and rotation at same
time or sequentially, please consider using an
AnimatorSet
playing aModelAnimator.ofAnimation(AnimatableModel, String...)
orModelAnimator.ofPropertyValuesHolder(AnimatableModel, android.animation.PropertyValuesHolder...)
-
If the mesh is a character, for example, there may be one ModelAnimation for a walkcycle, a
second for a jump, a third for sidestepping and so on.
Assuming a character object has a skeleton, one keyframe track could store the data for the position changes of the lower arm bone over time, a different track the data for the rotation changes of the same bone, a third the track position, rotation or scaling of another bone, and so on. It should be clear, that an ModelAnimation can act on lots of such tracks.
Assuming the model has morph targets (for example one morph target showing a friendly face and another showing an angry face), each track holds the information as to how the influence of a certain morph target changes during the performance of the clip. In this case you should manage oneObjectAnimator
coming fromModelAnimator.ofAnimation(AnimatableModel, ModelAnimation...)
per action. And anAnimatorSet
to play them sequentially or together.
-
On a very basic 3D model like a single infinite rotating sphere, you should not have to
use this class but probably instead just call
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ModelAnimation.PropertyValuesHolder
This class holds information about a property and the values that that property should take during an animation.
-
Field Summary
Fields Modifier and Type Field Description static android.util.Property<ModelAnimation,java.lang.Float>
FRACTION_POSITION
A Property wrapper around thefractionPosition
functionality handled by thesetFractionPosition(float)
andgetFractionPosition()
methodsstatic android.util.Property<ModelAnimation,java.lang.Integer>
FRAME_POSITION
A Property wrapper around theframePosition
functionality handled by thesetFramePosition(int)
andgetFramePosition()
methodsstatic android.util.FloatProperty<ModelAnimation>
TIME_POSITION
A Property wrapper around thetimePosition
functionality handled by thesetTimePosition(float)
andgetTimePosition()
methods.
-
Constructor Summary
Constructors Constructor Description ModelAnimation(AnimatableModel model, java.lang.String name, int index, float duration, int frameRate)
ModelAnimation constructed from anAnimator
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static float
fractionToTime(float fraction, float duration)
Get the elapsed time in seconds of a fraction positionstatic float
frameToTime(int frame, int frameRate)
Get the elapsed time in seconds of a frame positionint
geIndex()
Returns The Zero-based index of the targetanimation
as defined in the originalAnimatableModel
float
getDuration()
Returns the duration of this animation in seconds.long
getDurationMillis()
Returns the duration of this animation in milliseconds.float
getFractionAtTime(float time)
Get the fraction position at the elapsed time in seconds.float
getFractionPosition()
Get the fractional value at the current animation position.int
getFrameAtTime(float time)
Get the frame position at the elapsed time in seconds.int
getFrameCount()
Returns the total number of frames of this animation.int
getFramePosition()
Get the current frame number at the current animation position.int
getFrameRate()
Get the frames per second originally defined in theAnimatable
.java.lang.String
getName()
Get the name of theanimation
float
getTimeAtFraction(float fraction)
Get the elapsed time in seconds of a fraction positionfloat
getTimeAtFrame(int frame)
Get the elapsed time in seconds of a frame positionfloat
getTimePosition()
Get the current time position in seconds at the current animation position.boolean
isDirty()
Internal usage for applying changes according to rendering update hierarchy.static long
secondsToMillis(float time)
Convert time in seconds to time in millisvoid
setDirty(boolean isDirty)
Set the state of this object properties to changed.void
setFractionPosition(float fractionPosition)
Sets the current position of (seeks) the animation to the specified fraction position.void
setFramePosition(int frameNumber)
Sets the current position of (seeks) the animation to the specified frame number according to thegetFrameRate()
.void
setTimePosition(float timePosition)
Sets the current position of (seeks) the animation to the specified time position in seconds.static float
timeToFraction(float time, float duration)
Get the fraction position at the elapsed time in seconds.static int
timeToFrame(float time, int frameRate)
Get the frame position at the elapsed time in seconds.
-
-
-
Field Detail
-
TIME_POSITION
public static final android.util.FloatProperty<ModelAnimation> TIME_POSITION
A Property wrapper around thetimePosition
functionality handled by thesetTimePosition(float)
andgetTimePosition()
methods.
-
FRAME_POSITION
public static final android.util.Property<ModelAnimation,java.lang.Integer> FRAME_POSITION
A Property wrapper around theframePosition
functionality handled by thesetFramePosition(int)
andgetFramePosition()
methods
-
FRACTION_POSITION
public static final android.util.Property<ModelAnimation,java.lang.Float> FRACTION_POSITION
A Property wrapper around thefractionPosition
functionality handled by thesetFractionPosition(float)
andgetFractionPosition()
methods
-
-
Constructor Detail
-
ModelAnimation
public ModelAnimation(AnimatableModel model, java.lang.String name, int index, float duration, int frameRate)
ModelAnimation constructed from anAnimator
- Parameters:
name
- This name should corresponds to the one defined and exported in theAnimatableModel
.
Typically the action name defined in the 3D creation software.index
- Zero-based index of the targetanimation
as defined in the originalAnimatableModel
duration
- This originalAnimatableModel
durationframeRate
- The frames per second defined in the original animation asset
-
-
Method Detail
-
geIndex
public int geIndex()
Returns The Zero-based index of the targetanimation
as defined in the originalAnimatableModel
-
getName
public java.lang.String getName()
Get the name of theanimation
This name corresponds to the one defined and exported in the
AnimatableModel
.
Typically the Action names defined in the 3D creation software.- Returns:
- Weak reference to the string name of the
animation
, or theString.valueOf(animation.getIndex())
> if none was specified.
-
getDuration
public float getDuration()
Returns the duration of this animation in seconds.
-
getDurationMillis
public long getDurationMillis()
Returns the duration of this animation in milliseconds.
-
getFrameRate
public int getFrameRate()
Get the frames per second originally defined in theAnimatable
.- Returns:
- The number of frames refresh during one second
-
getFrameCount
public int getFrameCount()
Returns the total number of frames of this animation.
-
getTimePosition
public float getTimePosition()
Get the current time position in seconds at the current animation position.- Returns:
- timePosition Elapsed time of interest in seconds. Between 0 and
getDuration()
- See Also:
getDuration()
-
setTimePosition
public void setTimePosition(float timePosition)
Sets the current position of (seeks) the animation to the specified time position in seconds.This method will apply rotation, translation, and scale to the
AnimatableModel
that have been targeted.- Parameters:
timePosition
- Elapsed time of interest in seconds. Between 0 andgetDuration()
- See Also:
getDuration()
-
getFramePosition
public int getFramePosition()
Get the current frame number at the current animation position.- Returns:
- Frame number on the timeline. Between 0 and
getFrameCount()
- See Also:
getTimePosition()
,getFrameCount()
-
setFramePosition
public void setFramePosition(int frameNumber)
Sets the current position of (seeks) the animation to the specified frame number according to thegetFrameRate()
.- Parameters:
frameNumber
- Frame number in the timeline. Between 0 andgetFrameCount()
- See Also:
setTimePosition(float)
,getFrameCount()
-
getFractionPosition
public float getFractionPosition()
Get the fractional value at the current animation position.- Returns:
- The fractional (percent) position. Between 0 and 1
- See Also:
getTimePosition()
-
setFractionPosition
public void setFractionPosition(float fractionPosition)
Sets the current position of (seeks) the animation to the specified fraction position.- Parameters:
fractionPosition
- The fractional (percent) position. Between 0 and 1.- See Also:
setTimePosition(float)
-
isDirty
public boolean isDirty()
Internal usage for applying changes according to rendering update hierarchy.
Time position must be applied inside a globalChoreographer
frame callback to ensure that the transformations are applied in a hierarchical order.- Returns:
- true if changes has been made
-
setDirty
public void setDirty(boolean isDirty)
Set the state of this object properties to changed. And tell theAnimatableModel
to take care of it.
-
getTimeAtFrame
public float getTimeAtFrame(int frame)
Get the elapsed time in seconds of a frame position- Parameters:
frame
- Frame number on the timeline- Returns:
- Elapsed time of interest in seconds
-
getFrameAtTime
public int getFrameAtTime(float time)
Get the frame position at the elapsed time in seconds.- Parameters:
time
- Elapsed time of interest in seconds- Returns:
- The frame number at the specified time
-
getTimeAtFraction
public float getTimeAtFraction(float fraction)
Get the elapsed time in seconds of a fraction position- Parameters:
fraction
- The fractional (from 0 to 1) value of interest- Returns:
- Elapsed time at the specified fraction
-
getFractionAtTime
public float getFractionAtTime(float time)
Get the fraction position at the elapsed time in seconds.- Parameters:
time
- Elapsed time of interest in seconds.- Returns:
- The fractional (from 0 to 1) value at the specified time
-
frameToTime
public static float frameToTime(int frame, int frameRate)
Get the elapsed time in seconds of a frame position- Parameters:
frame
- Frame number on the timelineframeRate
- The frames per second of the animation- Returns:
- Elapsed time of interest in seconds
-
timeToFrame
public static int timeToFrame(float time, int frameRate)
Get the frame position at the elapsed time in seconds.- Parameters:
time
- Elapsed time of interest in seconds.frameRate
- The frames per second of the animation- Returns:
- The frame number at the specified time
-
fractionToTime
public static float fractionToTime(float fraction, float duration)
Get the elapsed time in seconds of a fraction position- Parameters:
fraction
- The fractional (from 0 to 1) value of interestduration
- Duration in seconds- Returns:
- Elapsed time at the specified fraction
-
timeToFraction
public static float timeToFraction(float time, float duration)
Get the fraction position at the elapsed time in seconds.- Parameters:
time
- Elapsed time of interest in seconds.duration
- Duration in seconds- Returns:
- The fractional (from 0 to 1) value at the specified time
-
secondsToMillis
public static long secondsToMillis(float time)
Convert time in seconds to time in millis- Parameters:
time
- Elapsed time of interest in seconds.- Returns:
- Elapsed time of interest in milliseconds
-
-