com.jme.scene
Class Geometry

java.lang.Object
  extended by com.jme.scene.Spatial
      extended by com.jme.scene.Geometry
All Implemented Interfaces:
Savable, java.io.Serializable
Direct Known Subclasses:
Curve, Line, Point, QuadMesh, Text, TriMesh

public abstract class Geometry
extends Spatial
implements java.io.Serializable, Savable

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 collection of states and the data for a model. Subclasses define what the model data is.

Author:
Mark Powell, Joshua Slack
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.scene.Spatial
Spatial.CullHint, Spatial.LightCombineMode, Spatial.NormalsMode, Spatial.TextureCombineMode
 
Field Summary
protected  java.nio.FloatBuffer binormalBuf
          The geometry's per vertex normal information.
protected  BoundingVolume bound
          The local bounds of this Geometry object.
protected  boolean castsShadows
           
protected  java.nio.FloatBuffer colorBuf
          The geometry's per vertex color information.
protected static Vector3f compVect
          Static computation field
protected  ColorRGBA defaultColor
           
protected  int displayListID
          Non -1 values signal that drawing this scene should use the provided display list instead of drawing from the buffers.
protected  boolean enabled
           
protected  java.nio.FloatBuffer fogBuf
          The geometry's per vertex fog buffer depth values
protected  boolean hasDirtyVertices
           
protected  java.nio.FloatBuffer normBuf
          The geometry's per vertex normal information.
 RenderState[] states
          The compiled list of renderstates for this geometry, taking into account ancestors' states - updated with updateRenderStates()
protected  java.nio.FloatBuffer tangentBuf
          The geometry's per vertex color information.
protected  java.util.ArrayList<TexCoords> texBuf
          The geometry's per Texture per vertex texture coordinate information.
protected  VBOInfo vboInfo
          The geometry's VBO information.
protected  java.nio.FloatBuffer vertBuf
          The geometry's vertex information.
protected  int vertQuantity
          The number of vertexes in this geometry.
 
Fields inherited from class com.jme.scene.Spatial
cullHint, frustrumIntersects, geometricalControllers, isCollidable, lightCombineMode, localRotation, localScale, localTranslation, LOCKED_BOUNDS, LOCKED_BRANCH, LOCKED_MESH_DATA, LOCKED_NONE, LOCKED_SHADOWS, LOCKED_TRANSFORMS, lockedMode, name, normalsMode, parent, queueDistance, renderQueueMode, renderStateList, textureCombineMode, worldBound, worldRotation, worldScale, worldTranslation, zOrder
 
Constructor Summary
Geometry()
          Empty Constructor to be used internally only.
Geometry(java.lang.String name)
          Constructor instantiates a new Geometry object.
Geometry(java.lang.String name, java.nio.FloatBuffer vertex, java.nio.FloatBuffer normal, java.nio.FloatBuffer color, TexCoords coords)
          Constructor creates a new Geometry object.
 
Method Summary
 void addTextureCoordinates(TexCoords textureCoords)
           
 void addTextureCoordinates(TexCoords textureCoords, int coordSize)
           
protected  void applyRenderState(java.util.Stack<? extends RenderState>[] states)
          applyRenderState determines if a particular render state is set for this Geometry.
protected  void checkTextureCoordinates()
           
 void clearBuffers()
          Clears all vertex, normal, texture, and color buffers by setting them to null.
 void clearTextureBuffers()
           
 void copyTextureCoordinates(int fromIndex, int toIndex, float factor)
          copyTextureCoords copys the texture coordinates of a given texture unit to another location.
 void copyTextureCoordinates(int fromIndex, int toIndex, float[] factor)
          copyTextureCoords copys the texture coordinates of a given texture unit to another location.
 void draw(Renderer r)
          draw prepares the geometry for rendering to the display.
 void findPick(Ray ray, PickResults results)
          Check if this geom intersects the ray if yes add it to the results.
 java.nio.FloatBuffer getBinormalBuffer()
           
 java.nio.FloatBuffer getColorBuffer()
          getColorBufferfer retrieves the float buffer that contains this geometry's color information.
 ColorRGBA getDefaultColor()
          getDefaultColor returns the color used if no per vertex colors are specified.
 int getDisplayListID()
           
 java.nio.FloatBuffer getFogBuffer()
          The fog depth coord buffer
 LightState getLightState()
           
 BoundingVolume getModelBound()
          getModelBound retrieves the bounding object that contains the geometry's vertices.
 java.nio.FloatBuffer getNormalBuffer()
          getNormalBuffer retrieves this geometry's normal information as a float buffer.
 int getNumberOfUnits()
          getNumberOfUnits returns the number of texture units this geometry is currently using.
 java.nio.FloatBuffer getTangentBuffer()
           
 java.util.ArrayList<TexCoords> getTextureCoords()
          getTextureBuffers retrieves this geometry's texture information contained within a float buffer array.
 TexCoords getTextureCoords(int textureUnit)
          getTextureAsFloatBuffer retrieves the texture buffer of a given texture unit.
 int getTriangleCount()
           
 VBOInfo getVBOInfo()
           
 java.nio.FloatBuffer getVertexBuffer()
          getVertexBuffer returns the float buffer that contains this geometry's vertex information.
 int getVertexCount()
          returns the number of vertices contained in this geometry.
 java.nio.FloatBuffer getWorldCoords(java.nio.FloatBuffer store)
          getWorldCoords translates/rotates and scales the coordinates of this Geometry to world coordinates based on its world settings.
 java.nio.FloatBuffer getWorldNormals(java.nio.FloatBuffer store)
          getWorldNormals rotates the normals of this Geometry to world normals based on its world settings.
 boolean hasDirtyVertices()
           
 boolean isCastsShadows()
           
 void lockMeshes(Renderer r)
          Flags this spatial and those below it that any meshes in the specified scenegraph location or lower will not have changes in vertex, texcoord, normal or color data.
 void postdraw(Renderer r)
          Called after renderer finishes drawing this geometry.
 boolean predraw(Renderer r)
          Called just before renderer starts drawing this geometry.
 Vector3f randomVertex(Vector3f fill)
          randomVertex returns a random vertex from the list of vertices set to this geometry.
 void read(JMEImporter e)
           
 void reconstruct(java.nio.FloatBuffer vertices, java.nio.FloatBuffer normals, java.nio.FloatBuffer colors, TexCoords coords)
          reconstruct reinitializes the geometry with new data.
 void resizeTextureIds(int i)
           
 void rotateNormals(Quaternion rotate)
           
 void rotatePoints(Quaternion rotate)
           
 void scaleTextureCoordinates(int index, float factor)
           
 void scaleTextureCoordinates(int index, Vector2f factor)
           
 void setBinormalBuffer(java.nio.FloatBuffer binormalBuf)
           
 void setCastsShadows(boolean castsShadows)
           
 void setColorBuffer(java.nio.FloatBuffer colorBuf)
          setColorBuffer sets this geometry's colors via a float buffer consisting of groups of four floats: r,g,b and a.
 void setDefaultColor(ColorRGBA color)
          setDefaultColor sets the color to be used if no per vertex color buffer is set.
 void setDisplayListID(int displayListID)
           
 void setFogCoordBuffer(java.nio.FloatBuffer fogBuf)
          Set the fog coordinates buffer.
 void setHasDirtyVertices(boolean flag)
           
 void setLightState(LightState lightState)
           
 void setModelBound(BoundingVolume modelBound)
          setModelBound sets the bounding object for this geometry.
 void setNormalBuffer(java.nio.FloatBuffer normBuf)
          setNormalBuffer sets this geometry's normals via a float buffer consisting of groups of three floats: x,y and z.
 void setRandomColors()
          Sets every color of this geometry's color array to a random color.
 void setSolidColor(ColorRGBA color)
          setSolidColor sets the color array of this geometry to a single color.
 void setTangentBuffer(java.nio.FloatBuffer tangentBuf)
           
 void setTextureCoords(java.util.ArrayList<TexCoords> texBuf)
           
 void setTextureCoords(TexCoords coords)
          setTextureBuffer sets this geometry's textures (position 0) via a float buffer.
 void setTextureCoords(TexCoords coords, int unit)
          setTextureBuffer sets this geometry's textures at the position given via a float buffer.
 void setVBOInfo(VBOInfo info)
          Sets VBO info on this Geometry.
 void setVertexBuffer(java.nio.FloatBuffer vertBuf)
          setVertexBuffer sets this geometry's vertices via a float buffer consisting of groups of three floats: x,y and z.
 void setVertexCount(int vertQuantity)
           
 void sortLights()
          sorts the lights based on distance to geometry bounding volume
 void translatePoints(float x, float y, float z)
           
 void translatePoints(Vector3f amount)
           
 void unlockMeshes(Renderer r)
          Flags this spatial and those below it to allow for mesh updating (the default).
 void updateModelBound()
          updateBound recalculates the bounding object assigned to the geometry.
 void updateWorldBound()
          updateWorldBound updates the bounding volume that contains this geometry.
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.Spatial
addController, calculateCollisions, calculatePick, clearControllers, clearRenderState, clearRenderState, findCollisions, getClassTag, getController, getControllerCount, getControllers, getCullHint, getLastFrustumIntersection, getLightCombineMode, getLocalCullHint, getLocalLightCombineMode, getLocalNormalsMode, getLocalRenderQueueMode, getLocalRotation, getLocalScale, getLocalTextureCombineMode, getLocalToWorldMatrix, getLocalTranslation, getLocks, getName, getNormalsMode, getParent, getRenderQueueMode, getRenderState, getRenderState, getTextureCombineMode, getUserData, getWorldBound, getWorldRotation, getWorldScale, getWorldTranslation, getZOrder, hasAncestor, hasCollision, isCollidable, localToWorld, lock, lock, lockBounds, lockBranch, lockMeshes, lockShadows, lockTransforms, lookAt, onDraw, propagateBoundToRoot, propagateStatesFromRoot, removeController, removeController, removeFromParent, removeUserData, rotateUpTo, setCullHint, setIsCollidable, setLastFrustumIntersection, setLightCombineMode, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setLocalTranslation, setLocks, setLocks, setName, setNormalsMode, setParent, setRenderQueueMode, setRenderState, setTextureCombineMode, setUserData, setZOrder, setZOrder, toString, unlock, unlock, unlockBounds, unlockBranch, unlockMeshes, unlockShadows, unlockTransforms, updateGeometricState, updateRenderState, updateRenderState, updateWorldData, updateWorldRotation, updateWorldScale, updateWorldTranslation, updateWorldVectors, updateWorldVectors, worldToLocal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jme.util.export.Savable
getClassTag
 

Field Detail

bound

protected BoundingVolume bound
The local bounds of this Geometry object.


vertQuantity

protected int vertQuantity
The number of vertexes in this geometry.


colorBuf

protected transient java.nio.FloatBuffer colorBuf
The geometry's per vertex color information.


normBuf

protected transient java.nio.FloatBuffer normBuf
The geometry's per vertex normal information.


vertBuf

protected transient java.nio.FloatBuffer vertBuf
The geometry's vertex information.


texBuf

protected transient java.util.ArrayList<TexCoords> texBuf
The geometry's per Texture per vertex texture coordinate information.


tangentBuf

protected transient java.nio.FloatBuffer tangentBuf
The geometry's per vertex color information.


binormalBuf

protected transient java.nio.FloatBuffer binormalBuf
The geometry's per vertex normal information.


fogBuf

protected transient java.nio.FloatBuffer fogBuf
The geometry's per vertex fog buffer depth values


vboInfo

protected transient VBOInfo vboInfo
The geometry's VBO information.


enabled

protected boolean enabled

castsShadows

protected boolean castsShadows

hasDirtyVertices

protected boolean hasDirtyVertices

states

public RenderState[] states
The compiled list of renderstates for this geometry, taking into account ancestors' states - updated with updateRenderStates()


defaultColor

protected ColorRGBA defaultColor

displayListID

protected int displayListID
Non -1 values signal that drawing this scene should use the provided display list instead of drawing from the buffers.


compVect

protected static final Vector3f compVect
Static computation field

Constructor Detail

Geometry

public Geometry()
Empty Constructor to be used internally only.


Geometry

public Geometry(java.lang.String name)
Constructor instantiates a new Geometry object. This is the default object which has an empty vertex array. All other data is null.

Parameters:
name - the name of the scene element. This is required for identification and comparision purposes.

Geometry

public Geometry(java.lang.String name,
                java.nio.FloatBuffer vertex,
                java.nio.FloatBuffer normal,
                java.nio.FloatBuffer color,
                TexCoords coords)
Constructor creates a new Geometry object. During instantiation the geometry is set including vertex, normal, color and texture information.

Parameters:
name - the name of the scene element. This is required for identification and comparision purposes.
vertex - the points that make up the geometry.
normal - the normals of the geometry.
color - the color of each point of the geometry.
coords - the texture coordinates of the geometry (position 0.)
Method Detail

getVertexCount

public int getVertexCount()
returns the number of vertices contained in this geometry.

Specified by:
getVertexCount in class Spatial

setVertexCount

public void setVertexCount(int vertQuantity)

getTriangleCount

public int getTriangleCount()
Specified by:
getTriangleCount in class Spatial

reconstruct

public void reconstruct(java.nio.FloatBuffer vertices,
                        java.nio.FloatBuffer normals,
                        java.nio.FloatBuffer colors,
                        TexCoords coords)
reconstruct reinitializes the geometry with new data. This will reuse the geometry object.

Parameters:
vertices - the new vertices to use.
normals - the new normals to use.
colors - the new colors to use.
coords - the new texture coordinates to use (position 0).

setVBOInfo

public void setVBOInfo(VBOInfo info)
Sets VBO info on this Geometry.

Parameters:
info - the VBO info to set
See Also:
VBOInfo

getVBOInfo

public VBOInfo getVBOInfo()
Returns:
VBO info object
See Also:
VBOInfo

setSolidColor

public void setSolidColor(ColorRGBA color)
setSolidColor sets the color array of this geometry to a single color. For greater efficiency, try setting the the ColorBuffer to null and using DefaultColor instead.

Parameters:
color - the color to set.

setRandomColors

public void setRandomColors()
Sets every color of this geometry's color array to a random color.


getVertexBuffer

public java.nio.FloatBuffer getVertexBuffer()
getVertexBuffer returns the float buffer that contains this geometry's vertex information.

Returns:
the float buffer that contains this geometry's vertex information.

setVertexBuffer

public void setVertexBuffer(java.nio.FloatBuffer vertBuf)
setVertexBuffer sets this geometry's vertices via a float buffer consisting of groups of three floats: x,y and z.

Parameters:
vertBuf - the new vertex buffer.

setFogCoordBuffer

public void setFogCoordBuffer(java.nio.FloatBuffer fogBuf)
Set the fog coordinates buffer. This should have the vertex count entries

Parameters:
fogBuf - The fog buffer to use in this geometry

getFogBuffer

public java.nio.FloatBuffer getFogBuffer()
The fog depth coord buffer

Returns:
The per vertex depth values for fog coordinates

getNormalBuffer

public java.nio.FloatBuffer getNormalBuffer()
getNormalBuffer retrieves this geometry's normal information as a float buffer.

Returns:
the float buffer containing the geometry information.

setNormalBuffer

public void setNormalBuffer(java.nio.FloatBuffer normBuf)
setNormalBuffer sets this geometry's normals via a float buffer consisting of groups of three floats: x,y and z.

Parameters:
normBuf - the new normal buffer.

getColorBuffer

public java.nio.FloatBuffer getColorBuffer()
getColorBufferfer retrieves the float buffer that contains this geometry's color information.

Returns:
the buffer that contains this geometry's color information.

setColorBuffer

public void setColorBuffer(java.nio.FloatBuffer colorBuf)
setColorBuffer sets this geometry's colors via a float buffer consisting of groups of four floats: r,g,b and a.

Parameters:
colorBuf - the new color buffer.

copyTextureCoordinates

public void copyTextureCoordinates(int fromIndex,
                                   int toIndex,
                                   float factor)
copyTextureCoords copys the texture coordinates of a given texture unit to another location. If the texture unit is not valid, then the coordinates are ignored. Coords are multiplied by the given factor.

Parameters:
fromIndex - the coordinates to copy.
toIndex - the texture unit to set them to.
factor - a multiple to apply when copying

copyTextureCoordinates

public void copyTextureCoordinates(int fromIndex,
                                   int toIndex,
                                   float[] factor)
copyTextureCoords copys the texture coordinates of a given texture unit to another location. If the texture unit is not valid, then the coordinates are ignored. Coords are multiplied by the given factor.

Parameters:
fromIndex - the coordinates to copy.
toIndex - the texture unit to set them to.
factor - a multiple to apply when copying

getTextureCoords

public java.util.ArrayList<TexCoords> getTextureCoords()
getTextureBuffers retrieves this geometry's texture information contained within a float buffer array.

Returns:
the float buffers that contain this geometry's texture information.

getTextureCoords

public TexCoords getTextureCoords(int textureUnit)
getTextureAsFloatBuffer retrieves the texture buffer of a given texture unit.

Parameters:
textureUnit - the texture unit to check.
Returns:
the texture coordinates at the given texture unit.

setTextureCoords

public void setTextureCoords(TexCoords coords)
setTextureBuffer sets this geometry's textures (position 0) via a float buffer. This convenience method assumes we are setting coordinates for texture unit 0 and that there are 2 coordinate values per vertex.

Parameters:
coords - the new coords for unit 0.

setTextureCoords

public void setTextureCoords(TexCoords coords,
                             int unit)
setTextureBuffer sets this geometry's textures at the position given via a float buffer. This convenience method assumes that there are 2 coordinate values per vertex.

Parameters:
coords - the new coords.
unit - the texture unit we are providing coordinates for.

clearBuffers

public void clearBuffers()
Clears all vertex, normal, texture, and color buffers by setting them to null.


updateModelBound

public void updateModelBound()
updateBound recalculates the bounding object assigned to the geometry. This resets it parameters to adjust for any changes to the vertex information.

Specified by:
updateModelBound in class Spatial

setModelBound

public void setModelBound(BoundingVolume modelBound)
setModelBound sets the bounding object for this geometry.

Specified by:
setModelBound in class Spatial
Parameters:
modelBound - the bounding object for this geometry.

draw

public void draw(Renderer r)
draw prepares the geometry for rendering to the display. The renderstate is set and the subclass is responsible for rendering the actual data.

Specified by:
draw in class Spatial
Parameters:
r - the renderer that displays to the context.
See Also:
Spatial.draw(com.jme.renderer.Renderer)

updateWorldBound

public 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.

Specified by:
updateWorldBound in class Spatial
See Also:
Spatial.updateWorldBound()

applyRenderState

protected void applyRenderState(java.util.Stack<? extends RenderState>[] states)
applyRenderState determines if a particular render state is set for this Geometry. If not, the default state will be used.

Overrides:
applyRenderState in class Spatial
Parameters:
states - An array of stacks for each state.

sortLights

public void sortLights()
sorts the lights based on distance to geometry bounding volume

Overrides:
sortLights in class Spatial

randomVertex

public Vector3f randomVertex(Vector3f fill)
randomVertex returns a random vertex from the list of vertices set to this geometry. If there are no vertices set, null is returned.

Parameters:
fill - a Vector3f to fill with the results. If null, one is created. It is more efficient to pass in a nonnull vector.
Returns:
Vector3f a random vertex from the vertex list. Null is returned if the vertex list is not set.

findPick

public void findPick(Ray ray,
                     PickResults results)
Check if this geom intersects the ray if yes add it to the results.

Specified by:
findPick in class Spatial
Parameters:
ray - ray to check intersection with. The direction of the ray must be normalized (length 1).
results - result list

setDefaultColor

public void setDefaultColor(ColorRGBA color)
setDefaultColor sets the color to be used if no per vertex color buffer is set.

Parameters:
color -

getWorldCoords

public java.nio.FloatBuffer getWorldCoords(java.nio.FloatBuffer store)
getWorldCoords translates/rotates and scales the coordinates of this Geometry to world coordinates based on its world settings. The results are stored in the given FloatBuffer. If given FloatBuffer is null, one is created.

Parameters:
store - the FloatBuffer to store the results in, or null if you want one created.
Returns:
store or new FloatBuffer if store == null.

getWorldNormals

public java.nio.FloatBuffer getWorldNormals(java.nio.FloatBuffer store)
getWorldNormals rotates the normals of this Geometry to world normals based on its world settings. The results are stored in the given FloatBuffer. If given FloatBuffer is null, one is created.

Parameters:
store - the FloatBuffer to store the results in, or null if you want one created.
Returns:
store or new FloatBuffer if store == null.

getDisplayListID

public int getDisplayListID()

setDisplayListID

public void setDisplayListID(int displayListID)

setTextureCoords

public void setTextureCoords(java.util.ArrayList<TexCoords> texBuf)

clearTextureBuffers

public void clearTextureBuffers()

addTextureCoordinates

public void addTextureCoordinates(TexCoords textureCoords)

addTextureCoordinates

public void addTextureCoordinates(TexCoords textureCoords,
                                  int coordSize)

resizeTextureIds

public void resizeTextureIds(int i)

checkTextureCoordinates

protected void checkTextureCoordinates()

scaleTextureCoordinates

public void scaleTextureCoordinates(int index,
                                    float factor)

scaleTextureCoordinates

public void scaleTextureCoordinates(int index,
                                    Vector2f factor)

isCastsShadows

public boolean isCastsShadows()

setCastsShadows

public void setCastsShadows(boolean castsShadows)

getNumberOfUnits

public int getNumberOfUnits()
getNumberOfUnits returns the number of texture units this geometry is currently using.

Returns:
the number of texture units in use.

lockMeshes

public void lockMeshes(Renderer r)
Description copied from class: Spatial
Flags this spatial and those below it that any meshes in the specified scenegraph location or lower will not have changes in vertex, texcoord, normal or color data. This allows optimizations by the engine such as creating display lists from the data. Calling this method does not provide a guarentee that data changes will not be allowed or will/won't show up in the scene. It is merely a hint to the engine.

Overrides:
lockMeshes in class Spatial
Parameters:
r - A renderer to lock against.
See Also:
Spatial.unlockMeshes(Renderer)

unlockMeshes

public void unlockMeshes(Renderer r)
Description copied from class: Spatial
Flags this spatial and those below it to allow for mesh updating (the default). Generally this means that any display lists setup will be erased and released.

Overrides:
unlockMeshes in class Spatial
Parameters:
r - The renderer used to lock against.
See Also:
Spatial.lockMeshes(Renderer)

predraw

public boolean predraw(Renderer r)
Called just before renderer starts drawing this geometry. If it returns false, we'll skip rendering.


postdraw

public void postdraw(Renderer r)
Called after renderer finishes drawing this geometry.


translatePoints

public void translatePoints(float x,
                            float y,
                            float z)

translatePoints

public void translatePoints(Vector3f amount)

rotatePoints

public void rotatePoints(Quaternion rotate)

rotateNormals

public void rotateNormals(Quaternion rotate)

getDefaultColor

public ColorRGBA getDefaultColor()
getDefaultColor returns the color used if no per vertex colors are specified.

Returns:
default color

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class Spatial
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class Spatial
Throws:
java.io.IOException

getModelBound

public BoundingVolume getModelBound()
getModelBound retrieves the bounding object that contains the geometry's vertices.

Returns:
the bounding object for this geometry.

hasDirtyVertices

public boolean hasDirtyVertices()

setHasDirtyVertices

public void setHasDirtyVertices(boolean flag)

setTangentBuffer

public void setTangentBuffer(java.nio.FloatBuffer tangentBuf)

getTangentBuffer

public java.nio.FloatBuffer getTangentBuffer()

setBinormalBuffer

public void setBinormalBuffer(java.nio.FloatBuffer binormalBuf)

getBinormalBuffer

public java.nio.FloatBuffer getBinormalBuffer()

setLightState

public void setLightState(LightState lightState)

getLightState

public LightState getLightState()