Class Node


  • public class Node
    extends java.lang.Object
    A node is part of a hierarchy of Nodes in a Model. A Node encodes a transform relative to its parents. A Node can have child nodes. Optionally a node can specify a MeshPart and a Material to be applied to the mesh part.
    • Field Detail

      • id

        public java.lang.String id
        the id, may be null, FIXME is this unique?
      • inheritTransform

        public boolean inheritTransform
        Whether this node should inherit the transformation of its parent node, defaults to true. When this flag is false the value of globalTransform will be the same as the value of localTransform causing the transform to be independent of its parent transform.
      • isAnimated

        public boolean isAnimated
        Whether this node is currently being animated, if so the translation, rotation and scale values are not used.
      • translation

        public final Vector3 translation
        the translation, relative to the parent, not modified by animations
      • rotation

        public final Quaternion rotation
        the rotation, relative to the parent, not modified by animations
      • scale

        public final Vector3 scale
        the scale, relative to the parent, not modified by animations
      • localTransform

        public final Matrix4 localTransform
        the local transform, based on translation/rotation/scale (calculateLocalTransform()) or any applied animation
      • globalTransform

        public final Matrix4 globalTransform
        the global transform, product of local transform and transform of the parent node, calculated via calculateWorldTransform()
      • parent

        protected Node parent
    • Constructor Detail

      • Node

        public Node()
    • Method Detail

      • calculateLocalTransform

        public Matrix4 calculateLocalTransform()
        Calculates the local transform based on the translation, scale and rotation
        Returns:
        the local transform
      • calculateWorldTransform

        public Matrix4 calculateWorldTransform()
        Calculates the world transform; the product of local transform and the parent's world transform.
        Returns:
        the world transform
      • calculateTransforms

        public void calculateTransforms​(boolean recursive)
        Calculates the local and world transform of this node and optionally all its children.
        Parameters:
        recursive - whether to calculate the local/world transforms for children.
      • calculateBoneTransforms

        public void calculateBoneTransforms​(boolean recursive)
      • calculateBoundingBox

        public BoundingBox calculateBoundingBox​(BoundingBox out)
        Calculate the bounding box of this Node. This is a potential slow operation, it is advised to cache the result.
      • calculateBoundingBox

        public BoundingBox calculateBoundingBox​(BoundingBox out,
                                                boolean transform)
        Calculate the bounding box of this Node. This is a potential slow operation, it is advised to cache the result.
      • extendBoundingBox

        public BoundingBox extendBoundingBox​(BoundingBox out)
        Extends the bounding box with the bounds of this Node. This is a potential slow operation, it is advised to cache the result.
      • extendBoundingBox

        public BoundingBox extendBoundingBox​(BoundingBox out,
                                             boolean transform)
        Extends the bounding box with the bounds of this Node. This is a potential slow operation, it is advised to cache the result.
      • attachTo

        public <T extends Node> void attachTo​(T parent)
        Adds this node as child to specified parent Node, synonym for: parent.addChild(this)
        Parameters:
        parent - The Node to attach this Node to.
      • detach

        public void detach()
        Removes this node from its current parent, if any. Short for: this.getParent().removeChild(this)
      • hasChildren

        public boolean hasChildren()
        Returns:
        whether this Node has one or more children (true) or not (false)
      • getChildCount

        public int getChildCount()
        Returns:
        The number of child nodes that this Node current contains.
        See Also:
        getChild(int)
      • getChild

        public Node getChild​(int index)
        Parameters:
        index - The zero-based index of the child node to get, must be: 0 <= index < getChildCount().
        Returns:
        The child node at the specified index
      • getChild

        public Node getChild​(java.lang.String id,
                             boolean recursive,
                             boolean ignoreCase)
        Parameters:
        recursive - false to fetch a root child only, true to search the entire node tree for the specified node.
        Returns:
        The node with the specified id, or null if not found.
      • addChild

        public <T extends Node> int addChild​(T child)
        Adds the specified node as the currently last child of this node. If the node is already a child of another node, then it is removed from its current parent.
        Parameters:
        child - The Node to add as child of this Node
        Returns:
        the zero-based index of the child
      • addChildren

        public <T extends Node> int addChildren​(java.lang.Iterable<T> nodes)
        Adds the specified nodes as the currently last child of this node. If the node is already a child of another node, then it is removed from its current parent.
        Parameters:
        nodes - The Node to add as child of this Node
        Returns:
        the zero-based index of the first added child
      • insertChild

        public <T extends Node> int insertChild​(int index,
                                                T child)
        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 getChildCount() then the Node is added as the currently last child.
        Parameters:
        index - The zero-based index at which to add the child
        child - The Node to add as child of this Node
        Returns:
        the zero-based index of the child
      • insertChildren

        public <T extends Node> int insertChildren​(int index,
                                                   java.lang.Iterable<T> nodes)
        Insert the specified nodes as children 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 getChildCount() then the Node is added as the currently last child.
        Parameters:
        index - The zero-based index at which to add the child
        nodes - The nodes to add as child of this Node
        Returns:
        the zero-based index of the first inserted child
      • removeChild

        public <T extends Node> boolean removeChild​(T child)
        Removes the specified node as child of this node. On success, the child node will be not attached to any parent node (its getParent() method will return null). If the specified node currently isn't a child of this node then the removal is considered to be unsuccessful and the method will return false.
        Parameters:
        child - The child node to remove.
        Returns:
        Whether the removal was successful.
      • getChildren

        public java.lang.Iterable<Node> getChildren()
        Returns:
        An Iterable to all child nodes that this node contains.
      • getParent

        public Node getParent()
        Returns:
        The parent node that holds this node as child node, may be null.
      • hasParent

        public boolean hasParent()
        Returns:
        Whether (true) is this Node is a child node of another node or not (false).
      • copy

        public Node copy()
        Creates a nested copy of this Node, any child nodes are copied using this method as well. The parts are copied using the NodePart.copy() method. Note that that method copies the material and nodes (bones) by reference. If you intend to use the copy in a different node tree (e.g. a different Model or ModelInstance) then you will need to update these references afterwards. Override this method in your custom Node class to instantiate that class, in that case you should override the set(Node) method as well.
      • set

        protected Node set​(Node other)
        Creates a nested copy of this Node, any child nodes are copied using the copy() method. This will detach this node from its parent, but does not attach it to the parent of node being copied. The parts are copied using the NodePart.copy() method. Note that that method copies the material and nodes (bones) by reference. If you intend to use this node in a different node tree (e.g. a different Model or ModelInstance) then you will need to update these references afterwards. Override this method in your custom Node class to copy any additional fields you've added.
        Returns:
        This Node for chaining
      • getNode

        public static Node getNode​(Array<Node> nodes,
                                   java.lang.String id,
                                   boolean recursive,
                                   boolean ignoreCase)
        Helper method to recursive fetch a node from an array
        Parameters:
        recursive - false to fetch a root node only, true to search the entire node tree for the specified node.
        Returns:
        The node with the specified id, or null if not found.