Class ModelAnimation
- java.lang.Object
-
- com.google.ar.sceneform.animation.ModelAnimation
-
public class ModelAnimation extends java.lang.ObjectAn ModelAnimation is a reusable set of keyframe tracks which represent an animation.This class provides support for animating time positions on a targeted
AnimatableModelHere 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
AnimatorSetplaying 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 oneObjectAnimatorcoming fromModelAnimator.ofAnimation(AnimatableModel, ModelAnimation...)per action. And anAnimatorSetto 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 classModelAnimation.PropertyValuesHolderThis 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_POSITIONA Property wrapper around thefractionPositionfunctionality handled by thesetFractionPosition(float)andgetFractionPosition()methodsstatic android.util.Property<ModelAnimation,java.lang.Integer>FRAME_POSITIONA Property wrapper around theframePositionfunctionality handled by thesetFramePosition(int)andgetFramePosition()methodsstatic android.util.FloatProperty<ModelAnimation>TIME_POSITIONA Property wrapper around thetimePositionfunctionality 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 floatfractionToTime(float fraction, float duration)Get the elapsed time in seconds of a fraction positionstatic floatframeToTime(int frame, int frameRate)Get the elapsed time in seconds of a frame positionintgeIndex()Returns The Zero-based index of the targetanimationas defined in the originalAnimatableModelfloatgetDuration()Returns the duration of this animation in seconds.longgetDurationMillis()Returns the duration of this animation in milliseconds.floatgetFractionAtTime(float time)Get the fraction position at the elapsed time in seconds.floatgetFractionPosition()Get the fractional value at the current animation position.intgetFrameAtTime(float time)Get the frame position at the elapsed time in seconds.intgetFrameCount()Returns the total number of frames of this animation.intgetFramePosition()Get the current frame number at the current animation position.intgetFrameRate()Get the frames per second originally defined in theAnimatable.java.lang.StringgetName()Get the name of theanimationfloatgetTimeAtFraction(float fraction)Get the elapsed time in seconds of a fraction positionfloatgetTimeAtFrame(int frame)Get the elapsed time in seconds of a frame positionfloatgetTimePosition()Get the current time position in seconds at the current animation position.booleanisDirty()Internal usage for applying changes according to rendering update hierarchy.static longsecondsToMillis(float time)Convert time in seconds to time in millisvoidsetDirty(boolean isDirty)Set the state of this object properties to changed.voidsetFractionPosition(float fractionPosition)Sets the current position of (seeks) the animation to the specified fraction position.voidsetFramePosition(int frameNumber)Sets the current position of (seeks) the animation to the specified frame number according to thegetFrameRate().voidsetTimePosition(float timePosition)Sets the current position of (seeks) the animation to the specified time position in seconds.static floattimeToFraction(float time, float duration)Get the fraction position at the elapsed time in seconds.static inttimeToFrame(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 thetimePositionfunctionality handled by thesetTimePosition(float)andgetTimePosition()methods.
-
FRAME_POSITION
public static final android.util.Property<ModelAnimation,java.lang.Integer> FRAME_POSITION
A Property wrapper around theframePositionfunctionality handled by thesetFramePosition(int)andgetFramePosition()methods
-
FRACTION_POSITION
public static final android.util.Property<ModelAnimation,java.lang.Float> FRACTION_POSITION
A Property wrapper around thefractionPositionfunctionality 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 targetanimationas defined in the originalAnimatableModelduration- This originalAnimatableModeldurationframeRate- The frames per second defined in the original animation asset
-
-
Method Detail
-
geIndex
public int geIndex()
Returns The Zero-based index of the targetanimationas defined in the originalAnimatableModel
-
getName
public java.lang.String getName()
Get the name of theanimationThis 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
AnimatableModelthat 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 globalChoreographerframe 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 theAnimatableModelto 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
-
-