Class BatchNode

All Implemented Interfaces:
HasLocalTransform, CloneableSmartAsset, Collidable, Savable, JmeCloneable, Cloneable
Direct Known Subclasses:
SimpleBatchNode

public class BatchNode extends GeometryGroupNode
BatchNode holds geometries that are a batched version of all the geometries that are in its sub scenegraph. There is one geometry per different material in the sub tree. The geometries are directly attached to the node in the scene graph. Usage is like any other node except you have to call the batch() method once all the geometries have been attached to the sub scene graph and their material set (see todo more automagic for further enhancements) All the geometries that have been batched are set to not be rendered - Spatial.CullHint is left intact. The sub geometries can be transformed as usual, their transforms are used to update the mesh of the geometryBatch. Sub geoms can be removed but it may be slower than the normal spatial removing Sub geoms can be added after the batch() method has been called but won't be batched and will just be rendered as normal geometries. To integrate them in the batch you have to call the batch() method again on the batchNode.

TODO more automagic (batch when needed in the updateLogicalState)

  • Field Details

  • Constructor Details

    • BatchNode

      public BatchNode()
      Construct a batchNode
    • BatchNode

      public BatchNode(String name)
  • Method Details

    • onTransformChange

      public void onTransformChange(Geometry geom)
      Description copied from class: GeometryGroupNode
      Called by geom to specify that its world transform has been changed.
      Specified by:
      onTransformChange in class GeometryGroupNode
      Parameters:
      geom - The Geometry whose transform changed.
    • onMaterialChange

      public void onMaterialChange(Geometry geom)
      Description copied from class: GeometryGroupNode
      Called by geom to specify that its material has been changed.
      Specified by:
      onMaterialChange in class GeometryGroupNode
      Parameters:
      geom - The Geometry whose material changed.
    • onMeshChange

      public void onMeshChange(Geometry geom)
      Description copied from class: GeometryGroupNode
      Called by geom to specify that its mesh has been changed. This is also called when the geometry's lod level changes.
      Specified by:
      onMeshChange in class GeometryGroupNode
      Parameters:
      geom - The Geometry whose mesh changed.
    • onGeometryUnassociated

      public void onGeometryUnassociated(Geometry geom)
      Description copied from class: GeometryGroupNode
      Called by geom to specify that it has been unassociated from its GeometryGroupNode. Unassociation occurs when the Geometry is detached from its parent Node.
      Specified by:
      onGeometryUnassociated in class GeometryGroupNode
      Parameters:
      geom - The Geometry which is being unassociated.
    • getTransformMatrix

      protected Matrix4f getTransformMatrix(Geometry g)
    • updateSubBatch

      protected void updateSubBatch(Geometry bg)
    • batch

      public void batch()
      Batch this batchNode every geometry of the sub scene graph of this node will be batched into a single mesh that will be rendered in one call
    • doBatch

      protected void doBatch()
    • detachChildAt

      public Spatial detachChildAt(int index)
      Description copied from class: Node
      detachChildAt removes a child at a given index. That child is returned for saving purposes.
      Overrides:
      detachChildAt in class Node
      Parameters:
      index - the index of the child to be removed.
      Returns:
      the child at the supplied index.
    • isBatch

      public final boolean isBatch(Spatial s)
    • setMaterial

      public void setMaterial(Material material)
      Sets the material to the all the batches of this BatchNode. Use setMaterial(Material material,int batchIndex) to set a material to a specific batch.
      Overrides:
      setMaterial in class Node
      Parameters:
      material - the material to use for this geometry
    • getMaterial

      public Material getMaterial()
      Returns the material that is used for the first batch of this BatchNode.

      Use getMaterial(Material material,int batchIndex) to get a material from a specific batch.

      Returns:
      the material that is used for the first batch of this BatchNode
      See Also:
    • setNeedsFullRebatch

      protected void setNeedsFullRebatch(boolean needsFullRebatch)
    • clone

      public Node clone(boolean cloneMaterials)
      Overrides:
      clone in class Node
      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:
    • 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 Node
      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.
    • collideWith

      public int collideWith(Collidable other, CollisionResults results)
      Description copied from interface: Collidable
      Check collision with another Collidable.
      Specified by:
      collideWith in interface Collidable
      Overrides:
      collideWith in class Node
      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