Search in sources :

Example 11 with Node

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

the class Model method loadNode.

protected Node loadNode(ModelNode modelNode) {
    Node node = new Node();
    node.id = modelNode.id;
    if (modelNode.translation != null)
        node.translation.set(modelNode.translation);
    if (modelNode.rotation != null)
        node.rotation.set(modelNode.rotation);
    if (modelNode.scale != null)
        node.scale.set(modelNode.scale);
    // FIXME create temporary maps for faster lookup?
    if (modelNode.parts != null) {
        for (ModelNodePart modelNodePart : modelNode.parts) {
            MeshPart meshPart = null;
            Material meshMaterial = null;
            if (modelNodePart.meshPartId != null) {
                for (MeshPart part : meshParts) {
                    if (modelNodePart.meshPartId.equals(part.id)) {
                        meshPart = part;
                        break;
                    }
                }
            }
            if (modelNodePart.materialId != null) {
                for (Material material : materials) {
                    if (modelNodePart.materialId.equals(material.id)) {
                        meshMaterial = material;
                        break;
                    }
                }
            }
            if (meshPart == null || meshMaterial == null)
                throw new GdxRuntimeException("Invalid node: " + node.id);
            if (meshPart != null && meshMaterial != null) {
                NodePart nodePart = new NodePart();
                nodePart.meshPart = meshPart;
                nodePart.material = meshMaterial;
                node.parts.add(nodePart);
                if (modelNodePart.bones != null)
                    nodePartBones.put(nodePart, modelNodePart.bones);
            }
        }
    }
    if (modelNode.children != null) {
        for (ModelNode child : modelNode.children) {
            node.addChild(loadNode(child));
        }
    }
    return node;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ModelNode(com.badlogic.gdx.graphics.g3d.model.data.ModelNode) Node(com.badlogic.gdx.graphics.g3d.model.Node) ModelNodePart(com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) ModelMeshPart(com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart) MeshPart(com.badlogic.gdx.graphics.g3d.model.MeshPart) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart) ModelNodePart(com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart) ModelNode(com.badlogic.gdx.graphics.g3d.model.data.ModelNode)

Example 12 with Node

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

the class ModelInstance method copyNodes.

private void copyNodes(Array<Node> nodes) {
    for (int i = 0, n = nodes.size; i < n; ++i) {
        final Node node = nodes.get(i);
        this.nodes.add(node.copy());
    }
    invalidate();
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node)

Example 13 with Node

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

the class BaseAnimationController method end.

/** End applying multiple animations to the instance and update it to reflect the changes. */
protected void end() {
    if (!applying)
        throw new GdxRuntimeException("You must call begin() first");
    for (Entry<Node, Transform> entry : transforms.entries()) {
        entry.value.toMatrix4(entry.key.localTransform);
        transformPool.free(entry.value);
    }
    transforms.clear();
    target.calculateTransforms();
    applying = false;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Node(com.badlogic.gdx.graphics.g3d.model.Node)

Example 14 with Node

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

the class BaseAnimationController method applyNodeAnimationDirectly.

private static final void applyNodeAnimationDirectly(final NodeAnimation nodeAnim, final float time) {
    final Node node = nodeAnim.node;
    node.isAnimated = true;
    final Transform transform = getNodeAnimationTransform(nodeAnim, time);
    transform.toMatrix4(node.localTransform);
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node)

Example 15 with Node

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

the class BaseAnimationController method applyAnimation.

/** Helper method to apply one animation to either an objectmap for blending or directly to the bones. */
protected static void applyAnimation(final ObjectMap<Node, Transform> out, final Pool<Transform> pool, final float alpha, final Animation animation, final float time) {
    if (out == null) {
        for (final NodeAnimation nodeAnim : animation.nodeAnimations) applyNodeAnimationDirectly(nodeAnim, time);
    } else {
        for (final Node node : out.keys()) node.isAnimated = false;
        for (final NodeAnimation nodeAnim : animation.nodeAnimations) applyNodeAnimationBlending(nodeAnim, out, pool, alpha, time);
        for (final ObjectMap.Entry<Node, Transform> e : out.entries()) {
            if (!e.key.isAnimated) {
                e.key.isAnimated = true;
                e.value.lerp(e.key.translation, e.key.rotation, e.key.scale, alpha);
            }
        }
    }
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Node(com.badlogic.gdx.graphics.g3d.model.Node) NodeAnimation(com.badlogic.gdx.graphics.g3d.model.NodeAnimation)

Aggregations

Node (com.badlogic.gdx.graphics.g3d.model.Node)21 Vector3 (com.badlogic.gdx.math.Vector3)5 NodePart (com.badlogic.gdx.graphics.g3d.model.NodePart)4 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 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)2 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