com.jme.scene
Class SharedMesh

java.lang.Object
  extended by com.jme.scene.Spatial
      extended by com.jme.scene.Geometry
          extended by com.jme.scene.TriMesh
              extended by com.jme.scene.SharedMesh
All Implemented Interfaces:
Savable, java.io.Serializable

public class SharedMesh
extends TriMesh

SharedMesh allows the sharing of data between multiple nodes. A provided TriMesh is used as the model for this node. This allows the user to place multiple copies of the same object throughout the scene without having to duplicate data. It should be known that any change to the provided target mesh will affect the appearance of this mesh, including animations. Secondly, the SharedMesh is read only. Any attempt to write to the mesh data via set* methods, will result in a warning being logged and nothing else. Any changes to the mesh should happened to the target mesh being shared.
If you plan to use collisions with a SharedMesh it is recommended that you disable the passing of updateCollisionTree calls to the target mesh. This is to prevent multiple calls to the target's updateCollisionTree method, from different shared meshes. Instead of this method being called from the scenegraph, you can now invoke it directly on the target mesh, thus ensuring it will only be invoked once.
Important: It is highly recommended that the Target mesh is NOT placed into the scenegraph, as its translation, rotation and scale are replaced by the shared meshes using it before they are rendered.
Note: Special thanks to Kevin Glass.

Version:
$id$
Author:
Mark Powell
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.scene.TriMesh
TriMesh.Mode
 
Nested classes/interfaces inherited from class com.jme.scene.Spatial
Spatial.CullHint, Spatial.LightCombineMode, Spatial.NormalsMode, Spatial.TextureCombineMode
 
Field Summary
 
Fields inherited from class com.jme.scene.TriMesh
indexBuffer, mode, triangleQuantity
 
Fields inherited from class com.jme.scene.Geometry
binormalBuf, bound, castsShadows, colorBuf, compVect, defaultColor, displayListID, enabled, fogBuf, hasDirtyVertices, normBuf, states, tangentBuf, texBuf, vboInfo, vertBuf, vertQuantity
 
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
SharedMesh()
           
SharedMesh(java.lang.String name, TriMesh target)
          Constructor creates a new SharedMesh object.
SharedMesh(TriMesh target)
          Constructor creates a new SharedMesh object.
 
Method Summary
 void clearBuffers()
          clearBuffers is not supported by SharedMesh
 void copyTextureCoordinates(int fromIndex, int toIndex, float factor)
          copyTextureCoords is not supported by SharedMesh.
 void draw(Renderer r)
          draw renders the target mesh, at the translation, rotation and scale of this shared mesh.
 void findTriangleCollision(TriMesh toCheck, java.util.ArrayList<java.lang.Integer> thisIndex, java.util.ArrayList<java.lang.Integer> otherIndex)
          This function finds all intersections between this trimesh and the checking one.
 void findTrianglePick(Ray toTest, java.util.ArrayList<java.lang.Integer> results)
          findTrianglePick determines the triangles of the target trimesh that are being touched by the ray.
 java.nio.FloatBuffer getBinormalBuffer()
           
 java.nio.FloatBuffer getColorBuffer()
          getColorBuffer retrieves the float buffer that contains the target geometry's color information.
 ColorRGBA getDefaultColor()
          getDefaultColor returns the color used if no per vertex colors are specified.
 java.nio.IntBuffer getIndexBuffer()
          getIndexAsBuffer retrieves the target's indices array as an IntBuffer.
 Vector3f[] getMeshAsTrianglesVertices(Vector3f[] verts)
          retrieves the mesh as triangle vertices of the target mesh.
 BoundingVolume getModelBound()
          returns the model bound of the target object.
 java.nio.FloatBuffer getNormalBuffer()
          getNormalBuffer retrieves the target geometry's normal information as a float buffer.
 java.nio.FloatBuffer getTangentBuffer()
           
 TriMesh getTarget()
          getTarget returns the mesh that is being shared by this object.
 java.util.ArrayList<TexCoords> getTextureCoords()
          getTextureBuffers retrieves the target geometry's texture information contained within a float buffer array.
 TexCoords getTextureCoords(int textureUnit)
          getTextureAsFloatBuffer retrieves the texture buffer of a given texture unit.
 void getTriangle(int i, int[] storage)
          Stores in the storage array the indices of triangle i.
 void getTriangle(int i, Vector3f[] vertices)
          Stores in the vertices array the vertex values of triangle i.
 int getTriangleCount()
          Returns the number of triangles the target TriMesh contains.
 VBOInfo getVBOInfo()
          getVBOInfo returns the target mesh's vbo info.
 java.nio.FloatBuffer getVertexBuffer()
          getVertexBuffer returns the float buffer that contains the target geometry's vertex information.
 int getVertexCount()
          Returns the number of vertexes defined in the target's Geometry object.
 boolean hasDirtyVertices()
           
 boolean hasTriangleCollision(TriMesh toCheck)
          This function checks for intersection between the target trimesh and the given one.
 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.
 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 textureCoords)
          reconstruct is not supported in SharedMesh.
 void setBinormalBuffer(java.nio.FloatBuffer binormalBuf)
           
 void setColorBuffer(java.nio.FloatBuffer buff)
          setColorBuffer is not supported by SharedMesh.
 void setIndexBuffer(java.nio.IntBuffer indices)
          setIndexBuffer is not supported by SharedMesh.
 void setModelBound(BoundingVolume modelBound)
          setModelBound sets the bounding object for this geometry.
 void setNormalBuffer(java.nio.FloatBuffer buff)
          setNormalBuffer is not supported by SharedMesh.
 void setRandomColors()
          setRandomColors is not supported by SharedMesh.
 void setSolidColor(ColorRGBA color)
          setSolidColor is not supported by SharedMesh.
 void setTangentBuffer(java.nio.FloatBuffer tangentBuf)
           
 void setTarget(TriMesh target)
          setTarget sets the shared data mesh.
 void setTextureCoords(TexCoords buff)
          setTextureBuffer is not supported by SharedMesh.
 void setTextureCoords(TexCoords buff, int position)
          setTextureBuffer not supported by SharedMesh
 void setVBOInfo(VBOInfo info)
          setVBOInfo is not supported in SharedMesh.
 void setVertexBuffer(java.nio.FloatBuffer buff)
          setVertexBuffer is not supported by SharedMesh.
 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.TriMesh
findCollisions, getMaxIndex, getMeshAsTriangles, getMode, getTriangleIndices, getVertIndex, hasCollision, randomPointOnTriangles, recalcTriangleQuantity, reconstruct, setMode, setTriangleQuantity
 
Methods inherited from class com.jme.scene.Geometry
addTextureCoordinates, addTextureCoordinates, applyRenderState, checkTextureCoordinates, clearTextureBuffers, copyTextureCoordinates, findPick, getDisplayListID, getFogBuffer, getLightState, getNumberOfUnits, getWorldCoords, getWorldNormals, isCastsShadows, postdraw, predraw, resizeTextureIds, rotateNormals, rotatePoints, scaleTextureCoordinates, scaleTextureCoordinates, setCastsShadows, setDefaultColor, setDisplayListID, setFogCoordBuffer, setHasDirtyVertices, setLightState, setTextureCoords, setVertexCount, sortLights, translatePoints, translatePoints, unlockMeshes
 
Methods inherited from class com.jme.scene.Spatial
addController, calculateCollisions, calculatePick, clearControllers, clearRenderState, clearRenderState, 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, 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
 

Constructor Detail

SharedMesh

public SharedMesh()

SharedMesh

public SharedMesh(TriMesh target)
Constructor creates a new SharedMesh object. Uses the name of the target.

Parameters:
target - the TriMesh to share the data.

SharedMesh

public SharedMesh(java.lang.String name,
                  TriMesh target)
Constructor creates a new SharedMesh object.

Parameters:
name - the name of this shared mesh.
target - the TriMesh to share the data.
Method Detail

setTarget

public void setTarget(TriMesh target)
setTarget sets the shared data mesh.

Parameters:
target - the TriMesh to share the data.

getTarget

public TriMesh getTarget()
getTarget returns the mesh that is being shared by this object.

Returns:
the mesh being shared.

reconstruct

public void reconstruct(java.nio.FloatBuffer vertices,
                        java.nio.FloatBuffer normals,
                        java.nio.FloatBuffer colors,
                        TexCoords textureCoords)
reconstruct is not supported in SharedMesh.

Overrides:
reconstruct in class Geometry
Parameters:
vertices - the new vertices to use.
normals - the new normals to use.
colors - the new colors to use.
textureCoords - the new texture coordinates to use (position 0).

setVBOInfo

public void setVBOInfo(VBOInfo info)
setVBOInfo is not supported in SharedMesh.

Overrides:
setVBOInfo in class Geometry
Parameters:
info - the VBO info to set
See Also:
VBOInfo

getVBOInfo

public VBOInfo getVBOInfo()
getVBOInfo returns the target mesh's vbo info.

Overrides:
getVBOInfo in class Geometry
Returns:
VBO info object
See Also:
VBOInfo

setSolidColor

public void setSolidColor(ColorRGBA color)
setSolidColor is not supported by SharedMesh.

Overrides:
setSolidColor in class Geometry
Parameters:
color - the color to set.

setRandomColors

public void setRandomColors()
setRandomColors is not supported by SharedMesh.

Overrides:
setRandomColors in class Geometry

getVertexBuffer

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

Overrides:
getVertexBuffer in class Geometry
Returns:
the float buffer that contains the target geometry's vertex information.

setVertexBuffer

public void setVertexBuffer(java.nio.FloatBuffer buff)
setVertexBuffer is not supported by SharedMesh.

Overrides:
setVertexBuffer in class Geometry
Parameters:
buff - the new vertex buffer.

getVertexCount

public int getVertexCount()
Returns the number of vertexes defined in the target's Geometry object.

Overrides:
getVertexCount in class Geometry
Returns:
The number of vertexes in the target Geometry object.

getNormalBuffer

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

Overrides:
getNormalBuffer in class Geometry
Returns:
the float buffer containing the target geometry information.

setNormalBuffer

public void setNormalBuffer(java.nio.FloatBuffer buff)
setNormalBuffer is not supported by SharedMesh.

Overrides:
setNormalBuffer in class Geometry
Parameters:
buff - the new normal buffer.

getColorBuffer

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

Overrides:
getColorBuffer in class Geometry
Returns:
the buffer that contains the target geometry's color information.

setColorBuffer

public void setColorBuffer(java.nio.FloatBuffer buff)
setColorBuffer is not supported by SharedMesh.

Overrides:
setColorBuffer in class Geometry
Parameters:
buff - the new color buffer.

getIndexBuffer

public java.nio.IntBuffer getIndexBuffer()
getIndexAsBuffer retrieves the target's indices array as an IntBuffer.

Overrides:
getIndexBuffer in class TriMesh
Returns:
the indices array as an IntBuffer.

setIndexBuffer

public void setIndexBuffer(java.nio.IntBuffer indices)
setIndexBuffer is not supported by SharedMesh.

Overrides:
setIndexBuffer in class TriMesh
Parameters:
indices - the index array as an IntBuffer.

getTriangle

public void getTriangle(int i,
                        int[] storage)
Stores in the storage array the indices of triangle i. If i is an invalid index, or if storage.length<3, then nothing happens

Overrides:
getTriangle in class TriMesh
Parameters:
i - The index of the triangle to get.
storage - The array that will hold the i's indexes.

getTriangle

public void getTriangle(int i,
                        Vector3f[] vertices)
Stores in the vertices array the vertex values of triangle i. If i is an invalid triangle index, nothing happens.

Overrides:
getTriangle in class TriMesh
Parameters:
i -
vertices -

getTriangleCount

public int getTriangleCount()
Returns the number of triangles the target TriMesh contains.

Overrides:
getTriangleCount in class TriMesh
Returns:
The current number of triangles.

copyTextureCoordinates

public void copyTextureCoordinates(int fromIndex,
                                   int toIndex,
                                   float factor)
copyTextureCoords is not supported by SharedMesh.

Overrides:
copyTextureCoordinates in class Geometry
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 the target geometry's texture information contained within a float buffer array.

Overrides:
getTextureCoords in class Geometry
Returns:
the float buffers that contain the target geometry's texture information.

getTextureCoords

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

Overrides:
getTextureCoords in class Geometry
Parameters:
textureUnit - the texture unit to check.
Returns:
the texture coordinates at the given texture unit.

getMeshAsTrianglesVertices

public Vector3f[] getMeshAsTrianglesVertices(Vector3f[] verts)
retrieves the mesh as triangle vertices of the target mesh.

Overrides:
getMeshAsTrianglesVertices in class TriMesh
Parameters:
verts - a storage array to place the results in
Returns:
view of current mesh as group of triangle vertices

clearBuffers

public void clearBuffers()
clearBuffers is not supported by SharedMesh

Overrides:
clearBuffers in class TriMesh

hasTriangleCollision

public boolean hasTriangleCollision(TriMesh toCheck)
This function checks for intersection between the target trimesh and the given one. On the first intersection, true is returned.

Overrides:
hasTriangleCollision in class TriMesh
Parameters:
toCheck - The intersection testing mesh.
Returns:
True if they intersect.

findTriangleCollision

public void findTriangleCollision(TriMesh toCheck,
                                  java.util.ArrayList<java.lang.Integer> thisIndex,
                                  java.util.ArrayList<java.lang.Integer> otherIndex)
This function finds all intersections between this trimesh and the checking one. The intersections are stored as Integer objects of Triangle indexes in each of the parameters.

Overrides:
findTriangleCollision in class TriMesh
Parameters:
toCheck - The TriMesh to check.
thisIndex - The array of triangle indexes intersecting in this mesh.
otherIndex - The array of triangle indexes intersecting in the given mesh.

findTrianglePick

public void findTrianglePick(Ray toTest,
                             java.util.ArrayList<java.lang.Integer> results)
findTrianglePick determines the triangles of the target trimesh that are being touched by the ray. The indices of the triangles are stored in the provided ArrayList.

Overrides:
findTrianglePick in class TriMesh
Parameters:
toTest - the ray to test.
results - the indices to the triangles.

write

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

read

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

randomVertex

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

Overrides:
randomVertex in class Geometry
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.
See Also:
Geometry.randomVertex(Vector3f)

setTextureCoords

public void setTextureCoords(TexCoords buff)
setTextureBuffer is not supported by SharedMesh.

Overrides:
setTextureCoords in class Geometry
Parameters:
buff - the new vertex buffer.

setTextureCoords

public void setTextureCoords(TexCoords buff,
                             int position)
setTextureBuffer not supported by SharedMesh

Overrides:
setTextureCoords in class Geometry
Parameters:
buff - the new vertex buffer.
position - the texture unit we are providing coordinates for.

setTangentBuffer

public void setTangentBuffer(java.nio.FloatBuffer tangentBuf)
Overrides:
setTangentBuffer in class Geometry

getTangentBuffer

public java.nio.FloatBuffer getTangentBuffer()
Overrides:
getTangentBuffer in class Geometry

setBinormalBuffer

public void setBinormalBuffer(java.nio.FloatBuffer binormalBuf)
Overrides:
setBinormalBuffer in class Geometry

getBinormalBuffer

public java.nio.FloatBuffer getBinormalBuffer()
Overrides:
getBinormalBuffer in class Geometry

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.

Overrides:
updateWorldBound in class Geometry
See Also:
Spatial.updateWorldBound()

setModelBound

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

Overrides:
setModelBound in class Geometry
Parameters:
modelBound - the bounding object for this geometry.

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.

Overrides:
updateModelBound in class Geometry

getModelBound

public BoundingVolume getModelBound()
returns the model bound of the target object.

Overrides:
getModelBound in class Geometry
Returns:
the bounding object for this geometry.

draw

public void draw(Renderer r)
draw renders the target mesh, at the translation, rotation and scale of this shared mesh.

Overrides:
draw in class TriMesh
Parameters:
r - the renderer to display
See Also:
Spatial.draw(com.jme.renderer.Renderer)

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 Geometry
Parameters:
r - A renderer to lock against.
See Also:
Spatial.unlockMeshes(Renderer)

hasDirtyVertices

public boolean hasDirtyVertices()
Overrides:
hasDirtyVertices in class Geometry

getDefaultColor

public ColorRGBA getDefaultColor()
Description copied from class: Geometry
getDefaultColor returns the color used if no per vertex colors are specified.

Overrides:
getDefaultColor in class Geometry
Returns:
default color