Search in sources :

Example 1 with NodeKeyframe

use of com.badlogic.gdx.graphics.g3d.model.NodeKeyframe in project libgdx by libgdx.

the class Model method loadAnimations.

protected void loadAnimations(Iterable<ModelAnimation> modelAnimations) {
    for (final ModelAnimation anim : modelAnimations) {
        Animation animation = new Animation();
        animation.id = anim.id;
        for (ModelNodeAnimation nanim : anim.nodeAnimations) {
            final Node node = getNode(nanim.nodeId);
            if (node == null)
                continue;
            NodeAnimation nodeAnim = new NodeAnimation();
            nodeAnim.node = node;
            if (nanim.translation != null) {
                nodeAnim.translation = new Array<NodeKeyframe<Vector3>>();
                nodeAnim.translation.ensureCapacity(nanim.translation.size);
                for (ModelNodeKeyframe<Vector3> kf : nanim.translation) {
                    if (kf.keytime > animation.duration)
                        animation.duration = kf.keytime;
                    nodeAnim.translation.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.translation : kf.value)));
                }
            }
            if (nanim.rotation != null) {
                nodeAnim.rotation = new Array<NodeKeyframe<Quaternion>>();
                nodeAnim.rotation.ensureCapacity(nanim.rotation.size);
                for (ModelNodeKeyframe<Quaternion> kf : nanim.rotation) {
                    if (kf.keytime > animation.duration)
                        animation.duration = kf.keytime;
                    nodeAnim.rotation.add(new NodeKeyframe<Quaternion>(kf.keytime, new Quaternion(kf.value == null ? node.rotation : kf.value)));
                }
            }
            if (nanim.scaling != null) {
                nodeAnim.scaling = new Array<NodeKeyframe<Vector3>>();
                nodeAnim.scaling.ensureCapacity(nanim.scaling.size);
                for (ModelNodeKeyframe<Vector3> kf : nanim.scaling) {
                    if (kf.keytime > animation.duration)
                        animation.duration = kf.keytime;
                    nodeAnim.scaling.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.scale : kf.value)));
                }
            }
            if ((nodeAnim.translation != null && nodeAnim.translation.size > 0) || (nodeAnim.rotation != null && nodeAnim.rotation.size > 0) || (nodeAnim.scaling != null && nodeAnim.scaling.size > 0))
                animation.nodeAnimations.add(nodeAnim);
        }
        if (animation.nodeAnimations.size > 0)
            animations.add(animation);
    }
}
Also used : NodeKeyframe(com.badlogic.gdx.graphics.g3d.model.NodeKeyframe) ModelNodeKeyframe(com.badlogic.gdx.graphics.g3d.model.data.ModelNodeKeyframe) Quaternion(com.badlogic.gdx.math.Quaternion) ModelAnimation(com.badlogic.gdx.graphics.g3d.model.data.ModelAnimation) ModelNode(com.badlogic.gdx.graphics.g3d.model.data.ModelNode) Node(com.badlogic.gdx.graphics.g3d.model.Node) Vector3(com.badlogic.gdx.math.Vector3) ModelAnimation(com.badlogic.gdx.graphics.g3d.model.data.ModelAnimation) NodeAnimation(com.badlogic.gdx.graphics.g3d.model.NodeAnimation) Animation(com.badlogic.gdx.graphics.g3d.model.Animation) ModelNodeAnimation(com.badlogic.gdx.graphics.g3d.model.data.ModelNodeAnimation) ModelNodeAnimation(com.badlogic.gdx.graphics.g3d.model.data.ModelNodeAnimation) NodeAnimation(com.badlogic.gdx.graphics.g3d.model.NodeAnimation) ModelNodeAnimation(com.badlogic.gdx.graphics.g3d.model.data.ModelNodeAnimation)

Example 2 with NodeKeyframe

use of com.badlogic.gdx.graphics.g3d.model.NodeKeyframe in project libgdx by libgdx.

the class ModelInstance method copyAnimations.

private void copyAnimations(final Iterable<Animation> source, boolean shareKeyframes) {
    for (final Animation anim : source) {
        Animation animation = new Animation();
        animation.id = anim.id;
        animation.duration = anim.duration;
        for (final NodeAnimation nanim : anim.nodeAnimations) {
            final Node node = getNode(nanim.node.id);
            if (node == null)
                continue;
            NodeAnimation nodeAnim = new NodeAnimation();
            nodeAnim.node = node;
            if (shareKeyframes) {
                nodeAnim.translation = nanim.translation;
                nodeAnim.rotation = nanim.rotation;
                nodeAnim.scaling = nanim.scaling;
            } else {
                if (nanim.translation != null) {
                    nodeAnim.translation = new Array<NodeKeyframe<Vector3>>();
                    for (final NodeKeyframe<Vector3> kf : nanim.translation) nodeAnim.translation.add(new NodeKeyframe<Vector3>(kf.keytime, kf.value));
                }
                if (nanim.rotation != null) {
                    nodeAnim.rotation = new Array<NodeKeyframe<Quaternion>>();
                    for (final NodeKeyframe<Quaternion> kf : nanim.rotation) nodeAnim.rotation.add(new NodeKeyframe<Quaternion>(kf.keytime, kf.value));
                }
                if (nanim.scaling != null) {
                    nodeAnim.scaling = new Array<NodeKeyframe<Vector3>>();
                    for (final NodeKeyframe<Vector3> kf : nanim.scaling) nodeAnim.scaling.add(new NodeKeyframe<Vector3>(kf.keytime, kf.value));
                }
            }
            if (nodeAnim.translation != null || nodeAnim.rotation != null || nodeAnim.scaling != null)
                animation.nodeAnimations.add(nodeAnim);
        }
        if (animation.nodeAnimations.size > 0)
            animations.add(animation);
    }
}
Also used : NodeKeyframe(com.badlogic.gdx.graphics.g3d.model.NodeKeyframe) Quaternion(com.badlogic.gdx.math.Quaternion) Node(com.badlogic.gdx.graphics.g3d.model.Node) Animation(com.badlogic.gdx.graphics.g3d.model.Animation) NodeAnimation(com.badlogic.gdx.graphics.g3d.model.NodeAnimation) Vector3(com.badlogic.gdx.math.Vector3) NodeAnimation(com.badlogic.gdx.graphics.g3d.model.NodeAnimation)

Example 3 with NodeKeyframe

use of com.badlogic.gdx.graphics.g3d.model.NodeKeyframe in project libgdx by libgdx.

the class BaseAnimationController method getScalingAtTime.

private static final Vector3 getScalingAtTime(final NodeAnimation nodeAnim, final float time, final Vector3 out) {
    if (nodeAnim.scaling == null)
        return out.set(nodeAnim.node.scale);
    if (nodeAnim.scaling.size == 1)
        return out.set(nodeAnim.scaling.get(0).value);
    int index = getFirstKeyframeIndexAtTime(nodeAnim.scaling, time);
    final NodeKeyframe firstKeyframe = nodeAnim.scaling.get(index);
    out.set((Vector3) firstKeyframe.value);
    if (++index < nodeAnim.scaling.size) {
        final NodeKeyframe<Vector3> secondKeyframe = nodeAnim.scaling.get(index);
        final float t = (time - firstKeyframe.keytime) / (secondKeyframe.keytime - firstKeyframe.keytime);
        out.lerp(secondKeyframe.value, t);
    }
    return out;
}
Also used : NodeKeyframe(com.badlogic.gdx.graphics.g3d.model.NodeKeyframe) Vector3(com.badlogic.gdx.math.Vector3)

Example 4 with NodeKeyframe

use of com.badlogic.gdx.graphics.g3d.model.NodeKeyframe in project libgdx by libgdx.

the class BaseAnimationController method getTranslationAtTime.

private static final Vector3 getTranslationAtTime(final NodeAnimation nodeAnim, final float time, final Vector3 out) {
    if (nodeAnim.translation == null)
        return out.set(nodeAnim.node.translation);
    if (nodeAnim.translation.size == 1)
        return out.set(nodeAnim.translation.get(0).value);
    int index = getFirstKeyframeIndexAtTime(nodeAnim.translation, time);
    final NodeKeyframe firstKeyframe = nodeAnim.translation.get(index);
    out.set((Vector3) firstKeyframe.value);
    if (++index < nodeAnim.translation.size) {
        final NodeKeyframe<Vector3> secondKeyframe = nodeAnim.translation.get(index);
        final float t = (time - firstKeyframe.keytime) / (secondKeyframe.keytime - firstKeyframe.keytime);
        out.lerp(secondKeyframe.value, t);
    }
    return out;
}
Also used : NodeKeyframe(com.badlogic.gdx.graphics.g3d.model.NodeKeyframe) Vector3(com.badlogic.gdx.math.Vector3)

Example 5 with NodeKeyframe

use of com.badlogic.gdx.graphics.g3d.model.NodeKeyframe in project libgdx by libgdx.

the class BaseAnimationController method getRotationAtTime.

private static final Quaternion getRotationAtTime(final NodeAnimation nodeAnim, final float time, final Quaternion out) {
    if (nodeAnim.rotation == null)
        return out.set(nodeAnim.node.rotation);
    if (nodeAnim.rotation.size == 1)
        return out.set(nodeAnim.rotation.get(0).value);
    int index = getFirstKeyframeIndexAtTime(nodeAnim.rotation, time);
    final NodeKeyframe firstKeyframe = nodeAnim.rotation.get(index);
    out.set((Quaternion) firstKeyframe.value);
    if (++index < nodeAnim.rotation.size) {
        final NodeKeyframe<Quaternion> secondKeyframe = nodeAnim.rotation.get(index);
        final float t = (time - firstKeyframe.keytime) / (secondKeyframe.keytime - firstKeyframe.keytime);
        out.slerp(secondKeyframe.value, t);
    }
    return out;
}
Also used : NodeKeyframe(com.badlogic.gdx.graphics.g3d.model.NodeKeyframe) Quaternion(com.badlogic.gdx.math.Quaternion)

Aggregations

NodeKeyframe (com.badlogic.gdx.graphics.g3d.model.NodeKeyframe)5 Vector3 (com.badlogic.gdx.math.Vector3)4 Quaternion (com.badlogic.gdx.math.Quaternion)3 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)2 Node (com.badlogic.gdx.graphics.g3d.model.Node)2 NodeAnimation (com.badlogic.gdx.graphics.g3d.model.NodeAnimation)2 ModelAnimation (com.badlogic.gdx.graphics.g3d.model.data.ModelAnimation)1 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)1 ModelNodeAnimation (com.badlogic.gdx.graphics.g3d.model.data.ModelNodeAnimation)1 ModelNodeKeyframe (com.badlogic.gdx.graphics.g3d.model.data.ModelNodeKeyframe)1