Search in sources :

Example 1 with Node

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

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

the class ModelInstance method invalidate.

/** Makes sure that each {@link NodePart} of the {@link Node} and its sub-nodes, doesn't reference a node outside this node
	 * tree and that all materials are listed in the {@link #materials} array. */
private void invalidate(Node node) {
    for (int i = 0, n = node.parts.size; i < n; ++i) {
        NodePart part = node.parts.get(i);
        ArrayMap<Node, Matrix4> bindPose = part.invBoneBindTransforms;
        if (bindPose != null) {
            for (int j = 0; j < bindPose.size; ++j) {
                bindPose.keys[j] = getNode(bindPose.keys[j].id);
            }
        }
        if (!materials.contains(part.material, true)) {
            final int midx = materials.indexOf(part.material, false);
            if (midx < 0)
                materials.add(part.material = part.material.copy());
            else
                part.material = materials.get(midx);
        }
    }
    for (int i = 0, n = node.getChildCount(); i < n; ++i) {
        invalidate(node.getChild(i));
    }
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 3 with Node

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

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

the class BaseAnimationController method applyNodeAnimationBlending.

private static final void applyNodeAnimationBlending(final NodeAnimation nodeAnim, final ObjectMap<Node, Transform> out, final Pool<Transform> pool, final float alpha, final float time) {
    final Node node = nodeAnim.node;
    node.isAnimated = true;
    final Transform transform = getNodeAnimationTransform(nodeAnim, time);
    Transform t = out.get(node, null);
    if (t != null) {
        if (alpha > 0.999999f)
            t.set(transform);
        else
            t.lerp(transform, alpha);
    } else {
        if (alpha > 0.999999f)
            out.put(node, pool.obtain().set(transform));
        else
            out.put(node, pool.obtain().set(node.translation, node.rotation, node.scale).lerp(transform, alpha));
    }
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node)

Example 5 with Node

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

the class ModelBuilder method createXYZCoordinates.

/** Convenience method to create a model with three orthonormal vectors shapes. The resources the Material might contain are not
	 * managed, use {@link Model#manageDisposable(Disposable)} to add those to the model.
	 * @param axisLength Length of each axis.
	 * @param capLength is the height of the cap in percentage, must be in (0,1)
	 * @param stemThickness is the percentage of stem diameter compared to cap diameter, must be in (0,1]
	 * @param divisions the amount of vertices used to generate the cap and stem ellipsoidal bases */
public Model createXYZCoordinates(float axisLength, float capLength, float stemThickness, int divisions, int primitiveType, Material material, long attributes) {
    begin();
    MeshPartBuilder partBuilder;
    Node node = node();
    partBuilder = part("xyz", primitiveType, attributes, material);
    partBuilder.setColor(Color.RED);
    partBuilder.arrow(0, 0, 0, axisLength, 0, 0, capLength, stemThickness, divisions);
    partBuilder.setColor(Color.GREEN);
    partBuilder.arrow(0, 0, 0, 0, axisLength, 0, capLength, stemThickness, divisions);
    partBuilder.setColor(Color.BLUE);
    partBuilder.arrow(0, 0, 0, 0, 0, axisLength, capLength, stemThickness, divisions);
    return end();
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node)

Aggregations

Node (com.badlogic.gdx.graphics.g3d.model.Node)23 Vector3 (com.badlogic.gdx.math.Vector3)6 NodePart (com.badlogic.gdx.graphics.g3d.model.NodePart)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 Model (com.badlogic.gdx.graphics.g3d.Model)3 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)3 NodeAnimation (com.badlogic.gdx.graphics.g3d.model.NodeAnimation)3 Material (com.badlogic.gdx.graphics.g3d.Material)2 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)2 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)2 NodeKeyframe (com.badlogic.gdx.graphics.g3d.model.NodeKeyframe)2 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)2 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)2 Quaternion (com.badlogic.gdx.math.Quaternion)2 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 Camera (com.badlogic.gdx.graphics.Camera)1 Texture (com.badlogic.gdx.graphics.Texture)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1