/** 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)); } }
/** * Direction vector of an armature bone, in world coordinate system. * * @param nodeId Name of the bone * @param out Output vector * @return Output vector for chaining */ public Vector3 getBoneDirection(String nodeId, Vector3 out) { Node node = modelInstance.getNode(nodeId); Node endPointNode = (node.hasChildren()) ? node.getChild(0) : node; node.globalTransform.getTranslation(TMP_V1); endPointNode.globalTransform.getTranslation(TMP_V2); TMP_V1.sub(TMP_V2).scl(-1); modelInstance.transform.getRotation(TMP_Q); TMP_Q.transform(TMP_V1); return out.set(TMP_V1).nor(); }
/** 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)); } }
/** * @param bodyPart The rigid body which is to be synchronized with a node * @param node The node which is to be synchronized with a body */ private void addPart(btRigidBody bodyPart, Node node) { if (!bodyPartMap.containsKey(bodyPart)) { bodyPartMap.put(bodyPart, new RigidBodyNodeConnection()); } RigidBodyNodeConnection conn = bodyPartMap.get(bodyPart); conn.followNode = node; // Set the follow offset to the middle of the armature bone Vector3 offsetTranslation = new Vector3(); node.getChild(0).localTransform.getTranslation(offsetTranslation).scl(0.5f); conn.bodyNodeOffsets.put(node, offsetTranslation); if (!ragdollMappedNodes.contains(node, true)) { ragdollMappedNodes.add(node); } }
/** 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)); } }
/** * Midpoint of an armature bone, in world coordinate system. * * @param nodeId Name of the bone * @param out Output vector * @return Output vector for chaining */ public Vector3 getBoneMidpointWorldPosition(String nodeId, Vector3 out) { Node node = modelInstance.getNode(nodeId); Node endPointNode = (node.hasChildren()) ? node.getChild(0) : node; // Use global transform to account for model scaling node.globalTransform.getTranslation(TMP_V1); TMP_V3.set(TMP_V1); endPointNode.globalTransform.getTranslation(TMP_V2); TMP_V3.sub(TMP_V1.sub(TMP_V2).scl(0.5f)); modelInstance.transform.getRotation(TMP_Q, true).transform(TMP_V3); TMP_V3.add(getPosition()); return out.set(TMP_V3); } }
this.addPart(phyCmp.body, armature.getChild(partName, true, true));