Class Node

All Implemented Interfaces:
Hintable, Savable
Direct Known Subclasses:
Arrow, AxisRods, BillboardNode, CameraNode, ParticleSystem, PassNode, QuadImposterNode, RenderedText, Skybox, Skybox, SwitchNode, Terrain, UIComponent, UIHud, WaterNode

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

    • _children

      protected final List<Spatial> _children
      This node's children.
  • Constructor Details

    • Node

      public Node()
      Constructs a new Spatial.
    • Node

      public Node(String name)
      Constructs a new Node with a given name.
      Parameters:
      name - the name of the node. This is required for identification purposes.
    • Node

      public Node(String name, List<Spatial> children)
      Constructs a new Node with a given name.
      Parameters:
      name - the name of the node. This is required for identification purposes.
      children - the list to use for storing children. Defaults to a synchronized ArrayList, but using this constructor, you can select a different kind of list.
  • Method Details

    • 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.
    • 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 index of the child to be attached.
      Returns:
      the number of children maintained by this node.
    • detachChild

      public int detachChild(Spatial child)
      detachChild removes a given child from the node's list. This child will no longe be maintained.
      Parameters:
      child - the child to remove.
      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 longe be maintained. Only the first child with a matching name is removed.
      Parameters:
      childName - the child to remove.
      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)
      Get the index of the specified spatial.
      Parameters:
      sp - spatial to retrieve index for.
      Returns:
      the index
    • getChildren

      public List<Spatial> getChildren()
      Returns all children to this node.
      Returns:
      a list containing all children to this node
    • swapChildren

      public void swapChildren(int index1, int index2)
      Swaps two children.
      Parameters:
      index1 - the index of the first child to swap
      index2 - the index of the second child to swap
    • updateChildren

      protected void updateChildren(double time)
      Description copied from class: Spatial
      Override to allow objects like Node to update their children.
      Overrides:
      updateChildren in class Spatial
      Parameters:
      time - The time in seconds between the last two consecutive frames (time per frame). See ReadOnlyTimer.getTimePerFrame()
    • 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.) If our children are Nodes, we will search their children as well.
      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.
    • getNumberOfChildren

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

      protected void propagateDirtyDown(EnumSet<DirtyType> dirtyTypes)
      Description copied from class: Spatial
      Propagate the dirty mark down the tree hierarchy.
      Overrides:
      propagateDirtyDown in class Spatial
      Parameters:
      dirtyTypes - the dirty types
    • updateWorldTransform

      public void updateWorldTransform(boolean recurse)
      Description copied from class: Spatial
      Updates the worldTransform.
      Overrides:
      updateWorldTransform in class Spatial
      Parameters:
      recurse - usually false when updating the tree. Set to true when you just want to update the world transforms for a branch without updating geometric state.
    • updateWorldRenderStates

      protected void updateWorldRenderStates(boolean recurse, RenderState.StateStack stack)
      Description copied from class: Spatial
      Called internally. Updates the render states of this Spatial. The stack contains parent render states.
      Overrides:
      updateWorldRenderStates in class Spatial
      Parameters:
      recurse - true to recurse down the scenegraph tree
      stack - The parent render states, or null if we are starting at this point in the scenegraph.
    • draw

      public void draw(Renderer r)
      draw calls the onDraw method for each child maintained by this node.
      Specified by:
      draw in class Spatial
      Parameters:
      r - the renderer to draw to.
      See Also:
    • updateWorldBound

      public void updateWorldBound(boolean recurse)
      updateWorldBound merges the bounds of all the children maintained by this node. This will allow for faster culling operations.
      Specified by:
      updateWorldBound in class Spatial
      Parameters:
      recurse - true to recurse down the scenegraph tree
      See Also:
    • acceptVisitor

      public void acceptVisitor(Visitor visitor, boolean preexecute)
      Description copied from class: Spatial
      Execute the given Visitor on this Spatial, and any Spatials managed by this Spatial as appropriate.
      Overrides:
      acceptVisitor in class Spatial
      Parameters:
      visitor - the Visitor object to use.
      preexecute - if true, we will visit this Spatial before any Spatials we manage (such as children of a Node.) If false, we will visit them first, then ourselves.
    • sortLights

      public void sortLights()
      Description copied from class: Spatial
      Sort the ligts on this spatial.
      Overrides:
      sortLights in class Spatial
    • makeCopy

      public Node makeCopy(boolean shareGeometricData)
      Description copied from class: Spatial
      Create a copy of this spatial.
      Overrides:
      makeCopy in class Spatial
      Parameters:
      shareGeometricData - if true, reuse any data fields describing the geometric shape of the spatial, as applicable.
      Returns:
      the copy as described.
    • makeInstanced

      public Node makeInstanced()
      Description copied from class: Spatial
      Creates and returns a new instance of this spatial. Used for instanced rendering. All instances visible on the screen will be drawn in one draw call. The new instance will share all data (meshData and renderStates) with the current mesh and all other instances created from this spatial.
      Overrides:
      makeInstanced in class Spatial
      Returns:
      an instanced copy of this node
    • getClassTag

      public Class<? extends Node> getClassTag()
      Specified by:
      getClassTag in interface Savable
      Overrides:
      getClassTag in class Spatial
      See Also:
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class Spatial
      Parameters:
      capsule - the capsule
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also:
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class Spatial
      Parameters:
      capsule - the input capsule
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also: