Class Node

All Implemented Interfaces:
HasLocalTransform, CloneableSmartAsset, Collidable, Savable, JmeCloneable, Cloneable
Direct Known Subclasses:
ArmatureDebugger, ArmatureNode, AssetLinkNode, AudioNode, BitmapText, CameraNode, GeometryGroupNode, LightNode, SkeletonDebugger, StatsView, TerrainQuad

public class Node extends Spatial
Node defines an internal node of a scene graph. The internal node maintains a collection of children and handles merging said children into a single bound to allow for very fast culling of multiple nodes. Node allows for any number of children to be attached.
  • Field Details

  • Constructor Details

    • Node

      public Node()
      Instantiate a Node with no name, no parent, and no children.
    • Node

      public Node(String name)
      Constructor instantiates a new Node with a default empty list for containing children.
      Parameters:
      name - the name of the scene element
  • Method Details

    • getQuantity

      public int getQuantity()
      getQuantity returns the number of children this node maintains.
      Returns:
      the number of children this node maintains.
    • setTransformRefresh

      protected void setTransformRefresh()
      Description copied from class: Spatial
      Indicate that the transform of this spatial has changed and that a refresh is required.
      Overrides:
      setTransformRefresh in class Spatial
    • setLightListRefresh

      protected void setLightListRefresh()
      Overrides:
      setLightListRefresh in class Spatial
    • setMatParamOverrideRefresh

      protected void setMatParamOverrideRefresh()
      Overrides:
      setMatParamOverrideRefresh in class Spatial
    • updateWorldBound

      protected void updateWorldBound()
      Description copied from class: Spatial
      Should be overridden by Node and Geometry.
      Overrides:
      updateWorldBound in class Spatial
    • setParent

      protected void setParent(Node parent)
      Description copied from class: Spatial
      Called by attachChild(Spatial) and detachChild(Spatial) - don't call directly. setParent sets the parent of this node.
      Overrides:
      setParent in class Spatial
      Parameters:
      parent - the parent of this node.
    • updateLogicalState

      public void updateLogicalState(float tpf)
      Description copied from class: Spatial
      updateLogicalState calls the update() method for all controls attached to this Spatial.
      Overrides:
      updateLogicalState in class Spatial
      Parameters:
      tpf - Time per frame.
      See Also:
    • updateGeometricState

      public void updateGeometricState()
      Description copied from class: Spatial
      updateGeometricState updates the light list, computes the world transforms, and computes the world bounds for this Spatial. Calling this when the Spatial is attached to a node will cause undefined results. User code should only call this method on Spatials having no parent.
      Overrides:
      updateGeometricState in class Spatial
      See Also:
    • getTriangleCount

      public int getTriangleCount()
      getTriangleCount returns the number of triangles contained in all sub-branches of this node that contain geometry.
      Specified by:
      getTriangleCount in class Spatial
      Returns:
      the triangle count of this branch.
    • getVertexCount

      public int getVertexCount()
      getVertexCount returns the number of vertices contained in all sub-branches of this node that contain geometry.
      Specified by:
      getVertexCount in class Spatial
      Returns:
      the vertex count of this branch.
    • attachChild

      public int attachChild(Spatial child)
      attachChild attaches a child to this node. This node becomes the child's parent. The current number of children maintained is returned.
      If the child already had a parent it is detached from that former parent.
      Parameters:
      child - the child to attach to this node.
      Returns:
      the number of children maintained by this node.
      Throws:
      IllegalArgumentException - if child is null.
    • attachChildAt

      public int attachChildAt(Spatial child, int index)
      attachChildAt attaches a child to this node at an index. This node becomes the child's parent. The current number of children maintained is returned.
      If the child already had a parent it is detached from that former parent.
      Parameters:
      child - the child to attach to this node.
      index - the position where the child should be attached
      Returns:
      the number of children maintained by this node.
      Throws:
      IllegalArgumentException - if child is null or this
    • detachChild

      public int detachChild(Spatial child)
      detachChild removes a given child from the node's list. This child will no longer be maintained.
      Parameters:
      child - the child to remove (not null)
      Returns:
      the index the child was at. -1 if the child was not in the list.
    • detachChildNamed

      public int detachChildNamed(String childName)
      detachChild removes a given child from the node's list. This child will no longer be maintained. Only the first child with a matching name is removed.
      Parameters:
      childName - the child to remove (not null)
      Returns:
      the index the child was at. -1 if the child was not in the list.
    • detachChildAt

      public Spatial detachChildAt(int index)
      detachChildAt removes a child at a given index. That child is returned for saving purposes.
      Parameters:
      index - the index of the child to be removed.
      Returns:
      the child at the supplied index.
    • detachAllChildren

      public void detachAllChildren()
      detachAllChildren removes all children attached to this node.
    • getChildIndex

      public int getChildIndex(Spatial sp)
      getChildIndex returns the index of the given spatial in this node's list of children.
      Parameters:
      sp - The spatial to look up
      Returns:
      The index of the spatial in the node's children, or -1 if the spatial is not attached to this node
    • swapChildren

      public void swapChildren(int index1, int index2)
      More efficient than e.g. detaching and attaching, as no updates are needed.
      Parameters:
      index1 - The index of the first child to swap
      index2 - The index of the second child to swap
    • getChild

      public Spatial getChild(int i)
      getChild returns a child at a given index.
      Parameters:
      i - the index to retrieve the child from.
      Returns:
      the child at a specified index.
    • getChild

      public Spatial getChild(String name)
      getChild returns the first child found with exactly the given name (case-sensitive). This method does a depth-first recursive search of all descendants of this node, it will return the first spatial found with a matching name.
      Parameters:
      name - the name of the child to retrieve. If null, we'll return null.
      Returns:
      the child if found, or null.
    • hasChild

      public boolean hasChild(Spatial spat)
      determines if the provided Spatial is contained in the children list of this node.
      Parameters:
      spat - the child object to look for.
      Returns:
      true if the object is contained, false otherwise.
    • getChildren

      public List<Spatial> getChildren()
      Returns all children to this node. Note that modifying that given list is not allowed.
      Returns:
      a list containing all children to this node
    • setMaterial

      public void setMaterial(Material mat)
      Description copied from class: Spatial
      Applies the given material to the Spatial, this will propagate the material down to the geometries in the scene graph.
      Overrides:
      setMaterial in class Spatial
      Parameters:
      mat - The material to set.
    • setLodLevel

      public void setLodLevel(int lod)
      Description copied from class: Spatial
      Sets the level of detail to use when rendering this Spatial, this call propagates to all geometries under this Spatial.
      Overrides:
      setLodLevel in class Spatial
      Parameters:
      lod - The lod level to set.
    • collideWith

      public int collideWith(Collidable other, CollisionResults results)
      Description copied from interface: Collidable
      Check collision with another Collidable.
      Parameters:
      other - The object to check collision against
      results - Will contain the list of CollisionResults.
      Returns:
      how many collisions were found between this and other
    • descendantMatches

      public <T extends Spatial> List<T> descendantMatches(Class<T> spatialSubclass, String nameRegex)
      Returns flat list of Spatials implementing the specified class AND with name matching the specified pattern.

      Note that we are matching the pattern, therefore the pattern must match the entire pattern (i.e. it behaves as if it is sandwiched between "^" and "$"). You can set regex modes, like case insensitivity, by using the (?X) or (?X:Y) constructs.

      By design, it is always safe to code loops like:

           for (Spatial spatial : node.descendantMatches(AClass.class, "regex"))
       

      "Descendants" does not include self, per the definition of the word. To test for descendants AND self, you must do a node.matches(aClass, aRegex) + node.descendantMatches(aClass, aRegex).

      Type Parameters:
      T - the type of Spatial returned
      Parameters:
      spatialSubclass - Subclass which matching Spatials must implement. Null causes all Spatials to qualify.
      nameRegex - Regular expression to match Spatial name against. Null causes all Names to qualify.
      Returns:
      Non-null, but possibly 0-element, list of matching Spatials (also Instances extending Spatials).
      See Also:
    • descendantMatches

      public <T extends Spatial> List<T> descendantMatches(Class<T> spatialSubclass)
      Convenience wrapper.
      Type Parameters:
      T - the type of Spatial returned
      Parameters:
      spatialSubclass - the type of Spatial returned, or null for all spatials
      Returns:
      a new list of pre-existing spatials (may be empty)
      See Also:
    • descendantMatches

      public <T extends Spatial> List<T> descendantMatches(String nameRegex)
      Convenience wrapper.
      Type Parameters:
      T - the type of Spatial returned
      Parameters:
      nameRegex - regular expression to match Spatial names against, or null for all spatials
      Returns:
      a new list of pre-existing spatials (may be empty)
      See Also:
    • clone

      public Node clone(boolean cloneMaterials)
      Overrides:
      clone in class Spatial
      Parameters:
      cloneMaterials - true to clone materials, false to share them
      Returns:
      A clone of this Spatial, the scene graph in its entirety is cloned and can be altered independently of the original scene graph. Note that meshes of geometries are not cloned explicitly, they are shared if static, or specially cloned if animated.
      See Also:
    • deepClone

      public Spatial deepClone()
      Overrides:
      deepClone in class Spatial
      Returns:
      Similar to Spatial.clone() except will create a deep clone of all geometries' meshes. Normally this method shouldn't be used. Instead, use Spatial.clone()
      See Also:
    • oldDeepClone

      public Spatial oldDeepClone()
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Called internally by com.jme3.util.clone.Cloner. Do not call directly.
      Specified by:
      cloneFields in interface JmeCloneable
      Overrides:
      cloneFields in class Spatial
      Parameters:
      cloner - The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.
      original - The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
    • write

      public void write(JmeExporter e) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class Spatial
      Throws:
      IOException
    • read

      public void read(JmeImporter importer) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class Spatial
      Throws:
      IOException
    • setModelBound

      public void setModelBound(BoundingVolume modelBound)
      Description copied from class: Spatial
      setModelBound sets the bounding object for this Spatial.
      Specified by:
      setModelBound in class Spatial
      Parameters:
      modelBound - the bounding object for this spatial.
    • updateModelBound

      public void updateModelBound()
      Description copied from class: Spatial
      updateModelBound recalculates the bounding object for this Spatial.
      Specified by:
      updateModelBound in class Spatial
    • depthFirstTraversal

      public void depthFirstTraversal(SceneGraphVisitor visitor, Spatial.DFSMode mode)
      Description copied from class: Spatial
      Visit each scene graph element ordered by DFS. There are two modes: pre order and post order.
      Specified by:
      depthFirstTraversal in class Spatial
      Parameters:
      visitor - the action to take for each visited Spatial
      mode - the traversal mode: pre order or post order
    • breadthFirstTraversal

      protected void breadthFirstTraversal(SceneGraphVisitor visitor, Queue<Spatial> queue)
      Specified by:
      breadthFirstTraversal in class Spatial