Class Geometry

java.lang.Object
com.jme3.scene.Spatial
com.jme3.scene.Geometry
All Implemented Interfaces:
HasLocalTransform, CloneableSmartAsset, Collidable, Savable, JmeCloneable, Cloneable
Direct Known Subclasses:
InstancedGeometry, ParticleEmitter, Picture, TerrainPatch

public class Geometry extends Spatial
Geometry defines a leaf node of the scene graph. The leaf node contains the geometric data for rendering objects. It manages all rendering information such as a Material object to define how the surface should be shaded and the Mesh data to contain the actual geometry.
  • Field Details

    • SAVABLE_VERSION

      public static final int SAVABLE_VERSION
      See Also:
    • mesh

      protected Mesh mesh
    • lodLevel

      protected transient int lodLevel
    • material

      protected Material material
    • ignoreTransform

      protected boolean ignoreTransform
      When true, the geometry's transform will not be applied.
    • cachedWorldMat

      protected transient Matrix4f cachedWorldMat
    • groupNode

      protected GeometryGroupNode groupNode
      Specifies which GeometryGroupNode this Geometry is managed by.
    • startIndex

      protected int startIndex
      The start index of this Geometry's inside the GeometryGroupNode.
  • Constructor Details

    • Geometry

      public Geometry()
      Instantiate a Geometry with no name, no mesh, and no material. The mesh and material must be set prior to rendering.
    • Geometry

      public Geometry(String name)
      Create a geometry node without any mesh data. Both the mesh and the material are null, the geometry cannot be rendered until those are set.
      Parameters:
      name - The name of this geometry
    • Geometry

      public Geometry(String name, Mesh mesh)
      Create a geometry node with mesh data. The material of the geometry is null, it cannot be rendered until it is set.
      Parameters:
      name - The name of this geometry
      mesh - The mesh data for this geometry
  • Method Details

    • checkCulling

      public boolean checkCulling(Camera cam)
      Description copied from class: Spatial
      checkCulling checks the spatial with the camera to see if it should be culled.

      This method is called by the renderer. Usually it should not be called directly.

      Overrides:
      checkCulling in class Spatial
      Parameters:
      cam - The camera to check against.
      Returns:
      true if inside or intersecting camera frustum (should be rendered), false if outside.
    • isIgnoreTransform

      public boolean isIgnoreTransform()
      Returns:
      If ignoreTransform mode is set.
      See Also:
    • setIgnoreTransform

      public void setIgnoreTransform(boolean ignoreTransform)
      Parameters:
      ignoreTransform - If true, the geometry's transform will not be applied.
    • setLodLevel

      public void setLodLevel(int lod)
      Sets the LOD level to use when rendering the mesh of this geometry. Level 0 indicates that the default index buffer should be used, levels [1, LodLevels + 1] represent the levels set on the mesh with Mesh.setLodLevels(com.jme3.scene.VertexBuffer[]).
      Overrides:
      setLodLevel in class Spatial
      Parameters:
      lod - The lod level to set
    • getLodLevel

      public int getLodLevel()
      Returns the LOD level set with setLodLevel(int).
      Returns:
      the LOD level set
    • getVertexCount

      public int getVertexCount()
      Returns this geometry's mesh vertex count.
      Specified by:
      getVertexCount in class Spatial
      Returns:
      this geometry's mesh vertex count.
      See Also:
    • getTriangleCount

      public int getTriangleCount()
      Returns this geometry's mesh triangle count.
      Specified by:
      getTriangleCount in class Spatial
      Returns:
      this geometry's mesh triangle count.
      See Also:
    • setMesh

      public void setMesh(Mesh mesh)
      Sets the mesh to use for this geometry when rendering.
      Parameters:
      mesh - the mesh to use for this geometry
      Throws:
      IllegalArgumentException - If mesh is null
    • getMesh

      public Mesh getMesh()
      Returns the mesh to use for this geometry
      Returns:
      the mesh to use for this geometry
      See Also:
    • setMaterial

      public void setMaterial(Material material)
      Sets the material to use for this geometry.
      Overrides:
      setMaterial in class Spatial
      Parameters:
      material - the material to use for this geometry
    • getMaterial

      public Material getMaterial()
      Returns the material that is used for this geometry.
      Returns:
      the material that is used for this geometry
      See Also:
    • getModelBound

      public BoundingVolume getModelBound()
      Returns:
      The bounding volume of the mesh, in model space.
    • updateModelBound

      public void updateModelBound()
      Updates the bounding volume of the mesh. Should be called when the mesh has been modified.
      Specified by:
      updateModelBound in class Spatial
    • updateWorldBound

      protected void updateWorldBound()
      updateWorldBound updates the bounding volume that contains this geometry. The location of the geometry is based on the location of all this node's parents.
      Overrides:
      updateWorldBound in class Spatial
      See Also:
    • updateWorldTransforms

      protected void updateWorldTransforms()
      Description copied from class: Spatial
      Should only be called from updateGeometricState(). In most cases should not be subclassed.
      Overrides:
      updateWorldTransforms in class Spatial
    • updateWorldLightList

      protected void updateWorldLightList()
      Overrides:
      updateWorldLightList in class Spatial
    • associateWithGroupNode

      public void associateWithGroupNode(GeometryGroupNode node, int startIndex)
      Associate this Geometry with a GeometryGroupNode. Should only be called by the parent GeometryGroupNode.
      Parameters:
      node - Which GeometryGroupNode to associate with.
      startIndex - The starting index of this geometry in the group.
    • unassociateFromGroupNode

      public void unassociateFromGroupNode()
      Removes the GeometryGroupNode association from this Geometry. Should only be called by the parent GeometryGroupNode.
    • removeFromParent

      public boolean removeFromParent()
      Description copied from class: Spatial
      removeFromParent removes this Spatial from its parent.
      Overrides:
      removeFromParent in class Spatial
      Returns:
      true if it has a parent and performed the remove.
    • setParent

      protected void setParent(Node parent)
      Description copied from class: Spatial
      Called by Node.attachChild(Spatial) and Node.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.
    • computeWorldMatrix

      public void computeWorldMatrix()
      Recomputes the matrix returned by getWorldMatrix(). This will require a localized transform update for this geometry.
    • getWorldMatrix

      public Matrix4f getWorldMatrix()
      A matrix that transforms the mesh from model space to world space. This matrix is computed based on the world transform of this geometry. In order to receive updated values, you must call computeWorldMatrix() before using this method.
      Returns:
      Matrix to transform from local space to world space
    • setModelBound

      public void setModelBound(BoundingVolume modelBound)
      Sets the model bound to use for this geometry. This alters the bound used on the mesh as well via Mesh.setBound(com.jme3.bounding.BoundingVolume) and forces the world bounding volume to be recomputed.
      Specified by:
      setModelBound in class Spatial
      Parameters:
      modelBound - The model bound 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
    • 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
    • isGrouped

      public boolean isGrouped()
      Determine whether this Geometry is managed by a GeometryGroupNode or not.
      Returns:
      True if managed by a GeometryGroupNode.
    • isBatched

      @Deprecated public boolean isBatched()
      Deprecated.
      Use isGrouped() instead.
      Returns:
      true if managed by a GeometryGroupNode
    • clone

      public Geometry clone(boolean cloneMaterial)
      This version of clone is a shallow clone, in other words, the same mesh is referenced as the original geometry. Exception: if the mesh is marked as being a software animated mesh, (bind pose is set) then the positions and normals are deep copied.
      Overrides:
      clone in class Spatial
      Parameters:
      cloneMaterial - 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:
    • clone

      public Geometry clone()
      This version of clone is a shallow clone, in other words, the same mesh is referenced as the original geometry. Exception: if the mesh is marked as being a software animated mesh, (bind pose is set) then the positions and normals are deep copied.
      Specified by:
      clone in interface CloneableSmartAsset
      Overrides:
      clone in class Spatial
      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()
      Create a deep clone of the geometry. This creates an identical copy of the mesh with the vertex buffer data duplicated.
      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.
    • setMorphState

      public void setMorphState(float[] state)
    • setMorphState

      public void setMorphState(String morphTarget, float state)
      Set the state of the morph with the given name. If the name of the morph is not found, no state will be set.
      Parameters:
      morphTarget - The name of the morph to set the state of
      state - The state to set the morph to
    • isDirtyMorph

      public boolean isDirtyMorph()
      returns true if the morph state has changed on the last frame.
      Returns:
      true if changed, otherwise false
    • setDirtyMorph

      public void setDirtyMorph(boolean dirtyMorph)
      Setting this to true will stop this geometry morph buffer to be updated, unless the morph state changes
      Parameters:
      dirtyMorph - true→prevent updating, false→allow updating
    • getMorphState

      public float[] getMorphState()
      returns the morph state of this Geometry. Used internally by the MorphControl.
      Returns:
      an array
    • getMorphState

      public float getMorphState(String morphTarget)
      Get the state of a morph
      Parameters:
      morphTarget - the name of the morph to get the state of
      Returns:
      the state of the morph, or -1 if the morph is not found
    • getNbSimultaneousGPUMorph

      public int getNbSimultaneousGPUMorph()
      Return the number of morph targets that can be handled on the GPU simultaneously for this geometry. Note that it depends on the material set on this geometry. This number is computed and set by the MorphControl, so it might be available only after the first frame. Else it's set to -1.
      Returns:
      the number of simultaneous morph targets handled on the GPU
    • setNbSimultaneousGPUMorph

      public void setNbSimultaneousGPUMorph(int nbSimultaneousGPUMorph)
      Sets the number of morph targets that can be handled on the GPU simultaneously for this geometry. Note that it depends on the material set on this geometry. This number is computed and set by the MorphControl, so it might be available only after the first frame. Else it's set to -1. WARNING: setting this manually might crash the shader compilation if set too high. Do it at your own risk.
      Parameters:
      nbSimultaneousGPUMorph - the number of simultaneous morph targets to be handled on the GPU.
    • getFallbackMorphTarget

      public MorphTarget getFallbackMorphTarget()
    • setFallbackMorphTarget

      public void setFallbackMorphTarget(MorphTarget fallbackMorphTarget)
    • write

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

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