com.jme3.scene
Class BatchNode

java.lang.Object
  extended by com.jme3.scene.Spatial
      extended by com.jme3.scene.Node
          extended by com.jme3.scene.BatchNode
All Implemented Interfaces:
CloneableSmartAsset, Collidable, Savable, java.lang.Cloneable
Direct Known Subclasses:
SimpleBatchNode

public class BatchNode
extends Node
implements Savable

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 CullHint#Always to not render them. 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 normal or tangents or both looks a bit weird TODO more automagic (batch when needed in the updateLogicalState)


Nested Class Summary
protected  class BatchNode.Batch
           
 
Nested classes/interfaces inherited from class com.jme3.scene.Spatial
Spatial.BatchHint, Spatial.CullHint
 
Field Summary
protected  SafeArrayList<BatchNode.Batch> batches
          the list of geometry holding the batched meshes
protected  java.util.Map<Geometry,BatchNode.Batch> batchesByGeom
          a map storing he batches by geometry to quickly acces the batch when updating
 
Fields inherited from class com.jme3.scene.Node
children
 
Fields inherited from class com.jme3.scene.Spatial
batchHint, controls, cullHint, frustrumIntersects, key, localLights, localTransform, name, parent, queueBucket, queueDistance, refreshFlags, RF_BOUND, RF_LIGHTLIST, RF_TRANSFORM, shadowMode, userData, worldBound, worldLights, worldTransform
 
Constructor Summary
BatchNode()
          Construct a batchNode
BatchNode(java.lang.String name)
           
 
Method Summary
 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
protected  void doBatch()
           
 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
 int getOffsetIndex(Geometry batchedGeometry)
           
protected  Transform getTransforms(Geometry geom)
           
 void read(JmeImporter im)
           
 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
protected  void setNeedsFullRebatch(boolean needsFullRebatch)
           
 void updateGeometricState()
          updateGeometricState updates the lightlist, computes the world transforms, and computes the world bounds for this Spatial.
protected  void updateSubBatch(Geometry bg)
           
 void write(JmeExporter ex)
           
 
Methods inherited from class com.jme3.scene.Node
attachChild, attachChildAt, breadthFirstTraversal, clone, collideWith, deepClone, depthFirstTraversal, descendantMatches, descendantMatches, descendantMatches, detachAllChildren, detachChild, detachChildAt, detachChildNamed, getChild, getChild, getChildIndex, getChildren, getQuantity, getTriangleCount, getVertexCount, hasChild, setLightListRefresh, setLodLevel, setModelBound, setTransformRefresh, swapChildren, updateLogicalState, updateModelBound, updateWorldBound
 
Methods inherited from class com.jme3.scene.Spatial
addControl, addLight, breadthFirstTraversal, center, checkCulling, clone, getBatchHint, getControl, getControl, getCullHint, getKey, getLastFrustumIntersection, getLocalBatchHint, getLocalCullHint, getLocalLightList, getLocalQueueBucket, getLocalRotation, getLocalScale, getLocalShadowMode, getLocalToWorldMatrix, getLocalTransform, getLocalTranslation, getName, getNumControls, getParent, getQueueBucket, getShadowMode, getUserData, getUserDataKeys, getWorldBound, getWorldLightList, getWorldRotation, getWorldScale, getWorldTransform, getWorldTranslation, hasAncestor, localToWorld, lookAt, matches, move, move, removeControl, removeControl, removeFromParent, removeLight, rotate, rotate, rotateUpTo, runControlRender, scale, scale, setBatchHint, setBoundRefresh, setCullHint, setKey, setLastFrustumIntersection, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalScale, setLocalTransform, setLocalTranslation, setLocalTranslation, setName, setParent, setQueueBucket, setShadowMode, setUserData, toString, updateWorldLightList, updateWorldTransforms, worldToLocal
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

batches

protected SafeArrayList<BatchNode.Batch> batches
the list of geometry holding the batched meshes


batchesByGeom

protected java.util.Map<Geometry,BatchNode.Batch> batchesByGeom
a map storing he batches by geometry to quickly acces the batch when updating

Constructor Detail

BatchNode

public BatchNode()
Construct a batchNode


BatchNode

public BatchNode(java.lang.String name)
Method Detail

updateGeometricState

public void updateGeometricState()
Description copied from class: Spatial
updateGeometricState updates the lightlist, 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 Node
See Also:
Spatial.getWorldLightList(), Spatial.getWorldTransform(), Spatial.getWorldBound()

getTransforms

protected Transform getTransforms(Geometry geom)

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()

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:
setMaterial(com.jme3.material.Material)

write

public void write(JmeExporter ex)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class Node
Throws:
java.io.IOException

read

public void read(JmeImporter im)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class Node
Throws:
java.io.IOException

setNeedsFullRebatch

protected void setNeedsFullRebatch(boolean needsFullRebatch)

getOffsetIndex

public int getOffsetIndex(Geometry batchedGeometry)