Java Code Examples for com.jme3.animation.Animation#getTracks()

The following examples show how to use com.jme3.animation.Animation#getTracks() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimulationNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Computes the maximum frame and time for the animation. Different tracks
 * can have different lengths so here the maximum one is being found.
 * 
 * @param animation
 *            the animation
 * @return maximum frame and time of the animation
 */
private float[] computeAnimationTimeBoundaries(Animation animation) {
    int maxFrame = Integer.MIN_VALUE;
    float maxTime = Float.MIN_VALUE;
    for (Track track : animation.getTracks()) {
        if (track instanceof BoneTrack) {
            maxFrame = Math.max(maxFrame, ((BoneTrack) track).getTranslations().length);
            maxTime = Math.max(maxTime, ((BoneTrack) track).getTimes()[((BoneTrack) track).getTimes().length - 1]);
        } else if (track instanceof SpatialTrack) {
            maxFrame = Math.max(maxFrame, ((SpatialTrack) track).getTranslations().length);
            maxTime = Math.max(maxTime, ((SpatialTrack) track).getTimes()[((SpatialTrack) track).getTimes().length - 1]);
        } else {
            throw new IllegalStateException("Unsupported track type for simuation: " + track);
        }
    }
    return new float[] { maxFrame, maxTime };
}
 
Example 2
Source File: AnimationTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public boolean hasChildren(@NotNull final NodeTree<?> nodeTree) {

    final Animation element = getElement();
    final Track[] tracks = element.getTracks();

    return tracks != null && tracks.length > 0 && nodeTree instanceof ModelNodeTree;
}
 
Example 3
Source File: AnimationTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public @NotNull Array<TreeNode<?>> getChildren(@NotNull final NodeTree<?> nodeTree) {

    final Animation element = getElement();
    final Track[] tracks = element.getTracks();

    final Array<TreeNode<?>> result = ArrayFactory.newArray(TreeNode.class, tracks.length);
    ArrayUtils.forEach(tracks, track -> result.add(FACTORY_REGISTRY.createFor(track)));

    return result;
}
 
Example 4
Source File: AnimationUtils.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Extract an animation from a source animation.
 *
 * @param source     the source animation.
 * @param newName    the new name of a sub animation.
 * @param startFrame the start frame.
 * @param endFrame   the end frame.
 * @return the new sub animation.
 */
@FromAnyThread
public static @NotNull Animation extractAnimation(
        @NotNull Animation source,
        @NotNull String newName,
        int startFrame,
        int endFrame
) {

    var sourceTracks = source.getTracks();
    var firstSourceTrack = (BoneTrack) sourceTracks[0];
    var sourceTimes = firstSourceTrack.getTimes();

    var newLength = (source.getLength() / (float) sourceTimes.length) * (float) (endFrame - startFrame);
    var result = new Animation(newName, newLength);
    var newTracks = ArrayFactory.<Track>newArray(Track.class);

    for (var sourceTrack : sourceTracks) {
        if (sourceTrack instanceof BoneTrack) {
            newTracks.add(extractBoneTrack((BoneTrack) sourceTrack, startFrame, endFrame));
        }
    }

    result.setTracks(newTracks.toArray(Track.class));

    return result;
}
 
Example 5
Source File: AnimationUtils.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Get frame count of the animation.
 *
 * @param animation the animation.
 * @return the frame count or -1.
 */
@FromAnyThread
public static int getFrameCount(@NotNull Animation animation) {

    var min = Integer.MAX_VALUE;

    var tracks = animation.getTracks();
    for (var track : tracks) {
        if (track instanceof BoneTrack) {
            min = Math.min(min, ((BoneTrack) track).getTimes().length);
        }
    }

    return min == Integer.MAX_VALUE ? -1 : min;
}