Search in sources :

Example 1 with Animation

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

the class Model method getAnimation.

/** @param id The ID of the animation to fetch.
	 * @param ignoreCase whether to use case sensitivity when comparing the animation id.
	 * @return The {@link Animation} with the specified id, or null if not available. */
public Animation getAnimation(final String id, boolean ignoreCase) {
    final int n = animations.size;
    Animation animation;
    if (ignoreCase) {
        for (int i = 0; i < n; i++) if ((animation = animations.get(i)).id.equalsIgnoreCase(id))
            return animation;
    } else {
        for (int i = 0; i < n; i++) if ((animation = animations.get(i)).id.equals(id))
            return animation;
    }
    return null;
}
Also used : 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)

Example 2 with Animation

use of com.badlogic.gdx.graphics.g3d.model.Animation 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 3 with Animation

use of com.badlogic.gdx.graphics.g3d.model.Animation 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 4 with Animation

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

the class Animation3DTest method onLoaded.

@Override
protected void onLoaded() {
    if (skydome == null) {
        skydome = new ModelInstance(assets.get("data/g3d/skydome.g3db", Model.class));
        floorModel.getMaterial("concrete").set(TextureAttribute.createDiffuse(assets.get("data/g3d/concrete.png", Texture.class)));
        floorModel.getMaterial("tree").set(TextureAttribute.createDiffuse(assets.get("data/tree.png", Texture.class)), new BlendingAttribute());
        instances.add(new ModelInstance(floorModel, "floor"));
        instances.add(tree = new ModelInstance(floorModel, "tree"));
        assets.load("data/g3d/knight.g3db", Model.class);
        loading = true;
    } else if (character == null) {
        character = new ModelInstance(assets.get("data/g3d/knight.g3db", Model.class));
        BoundingBox bbox = new BoundingBox();
        character.calculateBoundingBox(bbox);
        character.transform.setToRotation(Vector3.Y, 180).trn(0, -bbox.min.y, 0);
        instances.add(character);
        animation = new AnimationController(character);
        animation.animate("Idle", -1, 1f, null, 0.2f);
        status = idle;
        for (Animation anim : character.animations) Gdx.app.log("Test", anim.id);
        // Now attach the node of another model at the tip of this knights sword:
        ship = assets.get("data/g3d/ship.obj", Model.class).nodes.get(0).copy();
        ship.detach();
        // offset from the sword node to the tip of the sword, in rest pose
        ship.translation.x = 10f;
        ship.rotation.set(Vector3.Z, 90f);
        ship.scale.scl(5f);
        ship.parts.get(0).enabled = false;
        character.getNode("sword").addChild(ship);
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) Model(com.badlogic.gdx.graphics.g3d.Model) Animation(com.badlogic.gdx.graphics.g3d.model.Animation)

Example 5 with Animation

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

the class ShaderCollectionTest method switchAnimation.

protected void switchAnimation() {
    for (ObjectMap.Entry<ModelInstance, AnimationController> e : animationControllers.entries()) {
        int animIndex = 0;
        if (e.value.current != null) {
            for (int i = 0; i < e.key.animations.size; i++) {
                final Animation animation = e.key.animations.get(i);
                if (e.value.current.animation == animation) {
                    animIndex = i;
                    break;
                }
            }
        }
        animIndex = (animIndex + 1) % e.key.animations.size;
        e.value.animate(e.key.animations.get(animIndex).id, -1, 1f, null, 0.2f);
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ObjectMap(com.badlogic.gdx.utils.ObjectMap) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Animation(com.badlogic.gdx.graphics.g3d.model.Animation)

Aggregations

Animation (com.badlogic.gdx.graphics.g3d.model.Animation)10 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)4 NodeAnimation (com.badlogic.gdx.graphics.g3d.model.NodeAnimation)4 AnimationController (com.badlogic.gdx.graphics.g3d.utils.AnimationController)4 ObjectMap (com.badlogic.gdx.utils.ObjectMap)3 Node (com.badlogic.gdx.graphics.g3d.model.Node)2 NodeKeyframe (com.badlogic.gdx.graphics.g3d.model.NodeKeyframe)2 ModelAnimation (com.badlogic.gdx.graphics.g3d.model.data.ModelAnimation)2 ModelNodeAnimation (com.badlogic.gdx.graphics.g3d.model.data.ModelNodeAnimation)2 Quaternion (com.badlogic.gdx.math.Quaternion)2 Vector3 (com.badlogic.gdx.math.Vector3)2 Model (com.badlogic.gdx.graphics.g3d.Model)1 BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)1 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)1 ModelNodeKeyframe (com.badlogic.gdx.graphics.g3d.model.data.ModelNodeKeyframe)1 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)1 AnimationDesc (com.bladecoder.engine.anim.AnimationDesc)1