/** Insert the specified node as child of this node at the specified index. If the node is already a child of another node, then * it is removed from its current parent. If the specified index is less than zero or equal or greater than * {@link #getChildCount()} then the Node is added as the currently last child. * @param index The zero-based index at which to add the child * @param child The Node to add as child of this Node * @return the zero-based index of the child */ public <T extends Node> int insertChild (int index, final T child) { for (Node p = this; p != null; p = p.getParent()) { if (p == child) throw new GdxRuntimeException("Cannot add a parent as a child"); } Node p = child.getParent(); if (p != null && !p.removeChild(child)) throw new GdxRuntimeException("Could not remove child from its current parent"); if (index < 0 || index >= children.size) { index = children.size; children.add(child); } else children.insert(index, child); child.parent = this; return index; }
/** Insert the specified node as child of this node at the specified index. If the node is already a child of another node, then * it is removed from its current parent. If the specified index is less than zero or equal or greater than * {@link #getChildCount()} then the Node is added as the currently last child. * @param index The zero-based index at which to add the child * @param child The Node to add as child of this Node * @return the zero-based index of the child */ public <T extends Node> int insertChild (int index, final T child) { for (Node p = this; p != null; p = p.getParent()) { if (p == child) throw new GdxRuntimeException("Cannot add a parent as a child"); } Node p = child.getParent(); if (p != null && !p.removeChild(child)) throw new GdxRuntimeException("Could not remove child from its current parent"); if (index < 0 || index >= children.size) { index = children.size; children.add(child); } else children.insert(index, child); child.parent = this; return index; }
/** @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(); }
/** Insert the specified node as child of this node at the specified index. If the node is already a child of another node, then * it is removed from its current parent. If the specified index is less than zero or equal or greater than * {@link #getChildCount()} then the Node is added as the currently last child. * @param index The zero-based index at which to add the child * @param child The Node to add as child of this Node * @return the zero-based index of the child */ public <T extends Node> int insertChild (int index, final T child) { for (Node p = this; p != null; p = p.getParent()) { if (p == child) throw new GdxRuntimeException("Cannot add a parent as a child"); } Node p = child.getParent(); if (p != null && !p.removeChild(child)) throw new GdxRuntimeException("Could not remove child from its current parent"); if (index < 0 || index >= children.size) { index = children.size; children.add(child); } else children.insert(index, child); child.parent = this; return index; }
/** @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(); }