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;
}
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();
}
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;
}
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);
}
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);
}
}
}
}
Aggregations