/** @param model The source {@link Model} * @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix. * @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain * @param recursive True to recursively search the Model's node tree, false to only search for a root node * @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true). * @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */ public ModelInstance (final Model model, final Matrix4 transform, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform, boolean shareKeyframes) { this.model = model; this.transform = transform == null ? new Matrix4() : transform; Node copy, node = model.getNode(nodeId, recursive); this.nodes.add(copy = node.copy()); if (mergeTransform) { this.transform.mul(parentTransform ? node.globalTransform : node.localTransform); copy.translation.set(0, 0, 0); copy.rotation.idt(); copy.scale.set(1, 1, 1); } else if (parentTransform && copy.hasParent()) this.transform.mul(node.getParent().globalTransform); invalidate(); copyAnimations(model.animations, shareKeyframes); calculateTransforms(); }
/** @param model The source {@link Model} * @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix. * @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain * @param recursive True to recursively search the Model's node tree, false to only search for a root node * @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true). * @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */ public ModelInstance (final Model model, final Matrix4 transform, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform, boolean shareKeyframes) { this.model = model; this.transform = transform == null ? new Matrix4() : transform; Node copy, node = model.getNode(nodeId, recursive); this.nodes.add(copy = node.copy()); if (mergeTransform) { this.transform.mul(parentTransform ? node.globalTransform : node.localTransform); copy.translation.set(0, 0, 0); copy.rotation.idt(); copy.scale.set(1, 1, 1); } else if (parentTransform && copy.hasParent()) this.transform.mul(node.getParent().globalTransform); invalidate(); copyAnimations(model.animations, shareKeyframes); calculateTransforms(); }
private void drawArmatureNodes(Node currentNode, Vector3 modelPos, Quaternion modelRot, Vector3 parentNodePos, Vector3 currentNodePos) { currentNode.globalTransform.getTranslation(currentNodePos); modelRot.transform(currentNodePos); currentNodePos.add(modelPos); drawVertex(currentNodePos, 0.02f, Color.GREEN); shapeRenderer.setColor(Color.YELLOW); if (currentNode.hasParent()) { shapeRenderer.line(parentNodePos, currentNodePos); } if (currentNode.hasChildren()) { float x = currentNodePos.x; float y = currentNodePos.y; float z = currentNodePos.z; for (Node child : currentNode.getChildren()) { drawArmatureNodes(child, modelPos, modelRot, currentNodePos, parentNodePos); currentNodePos.set(x, y, z); } } }
/** @param model The source {@link Model} * @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix. * @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain * @param recursive True to recursively search the Model's node tree, false to only search for a root node * @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true). * @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */ public ModelInstance (final Model model, final Matrix4 transform, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform, boolean shareKeyframes) { this.model = model; this.transform = transform == null ? new Matrix4() : transform; Node copy, node = model.getNode(nodeId, recursive); this.nodes.add(copy = node.copy()); if (mergeTransform) { this.transform.mul(parentTransform ? node.globalTransform : node.localTransform); copy.translation.set(0, 0, 0); copy.rotation.idt(); copy.scale.set(1, 1, 1); } else if (parentTransform && copy.hasParent()) this.transform.mul(node.getParent().globalTransform); invalidate(); copyAnimations(model.animations, shareKeyframes); calculateTransforms(); }