Documentation Index
Fetch the complete documentation index at: https://mintlify.com/toxicity188/BetterModel/llms.txt
Use this file to discover all available pages before exploring further.
AnimationIterator is a sealed interface that provides iteration over animation keyframes with support for different playback modes.
Package
kr.toxicity.model.api.animation.AnimationIterator<T extends Timed>
Type Parameters
T - The type of keyframe (must implement Timed)
Methods
clear()
Resets the iterator to its initial state.
Since: 1.15.2
type()
Returns the loop type of this animation iterator.
Returns: The animation type
Since: 1.15.2
hasNext()
Inherited from Iterator<T>. Returns whether more keyframes are available.
next()
Inherited from Iterator<T>. Returns the next keyframe.
Type Enum
The AnimationIterator.Type enum defines animation playback behavior.
Enum Constants
PLAY_ONCE
Plays the animation once and then stops. Serialized as "once".
Since: 1.15.2
LOOP
Loops the animation continuously from start to finish. Serialized as "loop".
Since: 1.15.2
HOLD_ON_LAST
Plays the animation once and holds the last frame indefinitely. Serialized as "hold".
Since: 1.15.2
Type Methods
create(TimedStorage)
public abstract <T extends Timed> AnimationIterator<T> create(
@NotNull TimedStorage<T> keyframes
)
Creates a new iterator for the given keyframes based on this type.
Parameters:
keyframes - The keyframes to iterate over
Returns: A new animation iterator
Since: 1.15.2
Implementation Classes
The interface has three sealed implementations:
PlayOnce
Implementation for PLAY_ONCE type. Iterates through keyframes once, then returns false for hasNext().
Loop
Implementation for LOOP type. When reaching the end, resets to the first keyframe and continues infinitely.
HoldOnLast
Implementation for HOLD_ON_LAST type. After reaching the last keyframe, continues returning that frame indefinitely.
Usage Examples
Creating an Iterator
TimedStorage<AnimationProgress> keyframes = ...; // Your keyframes
AnimationIterator<AnimationProgress> iterator =
AnimationIterator.Type.LOOP.create(keyframes);
Iterating Through Keyframes
AnimationIterator<AnimationProgress> iterator =
AnimationIterator.Type.PLAY_ONCE.create(keyframes);
while (iterator.hasNext()) {
AnimationProgress frame = iterator.next();
// Apply frame to model
applyKeyframe(frame);
}
Looping Animation
AnimationIterator<AnimationProgress> loopIterator =
AnimationIterator.Type.LOOP.create(keyframes);
// Runs indefinitely
for (int i = 0; i < 1000; i++) {
AnimationProgress frame = loopIterator.next();
renderFrame(frame);
}
Hold on Last Frame
AnimationIterator<AnimationProgress> holdIterator =
AnimationIterator.Type.HOLD_ON_LAST.create(keyframes);
// Plays through once, then repeats last frame
for (int i = 0; i < keyframes.size() + 50; i++) {
AnimationProgress frame = holdIterator.next();
// First keyframes.size() frames are unique
// Remaining frames repeat the last keyframe
}
Resetting an Iterator
AnimationIterator<AnimationProgress> iterator =
AnimationIterator.Type.LOOP.create(keyframes);
// Use the iterator
for (int i = 0; i < 10; i++) {
iterator.next();
}
// Reset to beginning
iterator.clear();
// Now starts from first frame again
AnimationProgress first = iterator.next();
Checking Iterator Type
AnimationIterator<AnimationProgress> iterator = ...;
switch (iterator.type()) {
case PLAY_ONCE:
System.out.println("Animation will play once");
break;
case LOOP:
System.out.println("Animation will loop");
break;
case HOLD_ON_LAST:
System.out.println("Animation will hold on last frame");
break;
}
Using with AnimationModifier
// Create modifier with specific loop type
AnimationModifier modifier = AnimationModifier.builder()
.type(AnimationIterator.Type.LOOP)
.build();
// The type from modifier can be used to create iterator
AnimationIterator.Type type = modifier.type(AnimationIterator.Type.PLAY_ONCE);
AnimationIterator<AnimationProgress> iterator = type.create(keyframes);
JSON Serialization
The enum values serialize to JSON strings:
{
"animationType": "loop"
}
{
"animationType": "once"
}
{
"animationType": "hold"
}
See Also