Class SceneGraphIterator

java.lang.Object
com.jme3.scene.SceneGraphIterator
All Implemented Interfaces:
Iterable<Spatial>, Iterator<Spatial>

public class SceneGraphIterator extends Object implements Iterable<Spatial>, Iterator<Spatial>
Iterates over the scene graph with the depth-first traversal method.

This method of scene traversal allows for more control of the iteration process than Spatial.depthFirstTraversal(com.jme3.scene.SceneGraphVisitor) because it implements Iterator (enabling it to be used in for-loops).

  • Constructor Details

    • SceneGraphIterator

      public SceneGraphIterator(Spatial main)
      Instantiates a new SceneGraphIterator instance that starts iterating at the given main spatial.
      Parameters:
      main - the main spatial to start iteration from
  • Method Details

    • iterator

      public Iterator<Spatial> iterator()
      Specified by:
      iterator in interface Iterable<Spatial>
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Spatial>
    • next

      public Spatial next()
      Specified by:
      next in interface Iterator<Spatial>
    • current

      public Spatial current()
      Gets the spatial the iterator is currently on.
      Returns:
      current spatial
    • ignoreChildren

      public void ignoreChildren()
      Makes this iterator ignore all children of the current spatial. The children of the current spatial will not be iterated through.
    • getDepth

      public int getDepth()
      Gets the current depth of the iterator.

      The depth is how far away from the main spatial the current spatial is. So, the main spatial's depth is 0, all its children's depths is 1, and all their children's depths is 2, etc.

      Returns:
      current depth, or distance from the main spatial.