com.jme.scene
Class TriMesh

java.lang.Object
  extended by com.jme.scene.Spatial
      extended by com.jme.scene.Geometry
          extended by com.jme.scene.TriMesh
All Implemented Interfaces:
Savable, java.io.Serializable
Direct Known Subclasses:
AbstractBox, BezierMesh, Capsule, ClodMesh, ClothPatch, Cylinder, Disk, Dome, Extrusion, FontMesh, GeoSphere, Glyph3DMesh, JointMesh, OgreMesh, OrientedBox, PQTorus, ProjectedGrid, Pyramid, Quad, RegularPolyhedron, RoundedBox, ShadowVolume, SharedMesh, Sphere, Teapot, TerrainBlock, Torus, TrailMesh, Tube

public class TriMesh
extends Geometry
implements java.io.Serializable

TriMesh defines a geometry mesh. This mesh defines a three dimensional object via a collection of points, colors, normals and textures. The points are referenced via a indices array. This array instructs the renderer the order in which to draw the points, creating triangles based on the mode set.

Version:
$Id: TriMesh.java 4131 2009-03-19 20:15:28Z blaine.dev $
Author:
Mark Powell, Joshua Slack
See Also:
Serialized Form

Nested Class Summary
static class TriMesh.Mode
           
 
Nested classes/interfaces inherited from class com.jme.scene.Spatial
Spatial.CullHint, Spatial.LightCombineMode, Spatial.NormalsMode, Spatial.TextureCombineMode
 
Field Summary
protected  java.nio.IntBuffer indexBuffer
           
protected  TriMesh.Mode mode
           
protected  int 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
TriMesh()
          Empty Constructor to be used internally only.
TriMesh(java.lang.String name)
          Constructor instantiates a new TriMesh object.
TriMesh(java.lang.String name, java.nio.FloatBuffer vertices, java.nio.FloatBuffer normal, java.nio.FloatBuffer color, TexCoords coords, java.nio.IntBuffer indices)
          Constructor instantiates a new TriMesh object.
 
Method Summary
 void clearBuffers()
          Clears the buffers of this TriMesh.
 void draw(Renderer r)
          draw calls super to set the render state then passes itself to the renderer.
 void findCollisions(Spatial scene, CollisionResults results)
          determines if this TriMesh has made contact with the give scene.
 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 this trimesh that are being touched by the ray.
 java.nio.IntBuffer getIndexBuffer()
           
 int getMaxIndex()
           
 Triangle[] getMeshAsTriangles(Triangle[] tris)
           
 Vector3f[] getMeshAsTrianglesVertices(Vector3f[] verts)
          Return this mesh object as triangles.
 TriMesh.Mode getMode()
           
 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 contained in this mesh.
 int[] getTriangleIndices(int[] indices)
           
protected  int getVertIndex(int triangle, int point)
           
 boolean hasCollision(Spatial scene, boolean checkTriangles)
          determines if a collision between this trimesh and a given spatial occurs if it has true is returned, otherwise false is returned.
 boolean hasTriangleCollision(TriMesh toCheck)
          This function checks for intersection between this trimesh and the given one.
 Vector3f randomPointOnTriangles(Vector3f fill, Vector3f work)
          Returns a random point on the surface of a randomly selected triangle on the mesh
 void read(JMEImporter e)
           
protected  void recalcTriangleQuantity()
           
 void reconstruct(java.nio.FloatBuffer vertices, java.nio.FloatBuffer normal, java.nio.FloatBuffer color, TexCoords coords, java.nio.IntBuffer indices)
          Recreates the geometric information of this TriMesh from scratch.
 void setIndexBuffer(java.nio.IntBuffer indices)
           
 void setMode(TriMesh.Mode mode)
           
 void setTriangleQuantity(int triangleQuantity)
           
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.Geometry
addTextureCoordinates, addTextureCoordinates, applyRenderState, checkTextureCoordinates, clearTextureBuffers, copyTextureCoordinates, copyTextureCoordinates, findPick, getBinormalBuffer, getColorBuffer, getDefaultColor, getDisplayListID, getFogBuffer, getLightState, getModelBound, getNormalBuffer, getNumberOfUnits, getTangentBuffer, getTextureCoords, getTextureCoords, getVBOInfo, getVertexBuffer, getVertexCount, getWorldCoords, getWorldNormals, hasDirtyVertices, isCastsShadows, lockMeshes, postdraw, predraw, randomVertex, reconstruct, resizeTextureIds, rotateNormals, rotatePoints, scaleTextureCoordinates, scaleTextureCoordinates, setBinormalBuffer, setCastsShadows, setColorBuffer, setDefaultColor, setDisplayListID, setFogCoordBuffer, setHasDirtyVertices, setLightState, setModelBound, setNormalBuffer, setRandomColors, setSolidColor, setTangentBuffer, setTextureCoords, setTextureCoords, setTextureCoords, setVBOInfo, setVertexBuffer, setVertexCount, sortLights, translatePoints, translatePoints, unlockMeshes, updateModelBound, updateWorldBound
 
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
 

Field Detail

indexBuffer

protected transient java.nio.IntBuffer indexBuffer

mode

protected TriMesh.Mode mode

triangleQuantity

protected int triangleQuantity
Constructor Detail

TriMesh

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


TriMesh

public TriMesh(java.lang.String name)
Constructor instantiates a new TriMesh object.

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

TriMesh

public TriMesh(java.lang.String name,
               java.nio.FloatBuffer vertices,
               java.nio.FloatBuffer normal,
               java.nio.FloatBuffer color,
               TexCoords coords,
               java.nio.IntBuffer indices)
Constructor instantiates a new TriMesh object. Provided are the attributes that make up the mesh all attributes may be null, except for vertices and indices.

Parameters:
name - the name of the scene element. This is required for identification and comparision purposes.
vertices - the vertices of the geometry.
normal - the normals of the geometry.
color - the colors of the geometry.
coords - the texture coordinates of the mesh.
indices - the indices of the vertex array.
Method Detail

reconstruct

public void reconstruct(java.nio.FloatBuffer vertices,
                        java.nio.FloatBuffer normal,
                        java.nio.FloatBuffer color,
                        TexCoords coords,
                        java.nio.IntBuffer indices)
Recreates the geometric information of this TriMesh from scratch. The index and vertex array must not be null, but the others may be. Every 3 indices define an index in the vertices array that refrences a vertex of a triangle.

Parameters:
vertices - The vertex information for this TriMesh.
normal - The normal information for this TriMesh.
color - The color information for this TriMesh.
coords - The texture information for this TriMesh.
indices - The index information for this TriMesh.

setMode

public void setMode(TriMesh.Mode mode)

getMode

public TriMesh.Mode getMode()

getIndexBuffer

public java.nio.IntBuffer getIndexBuffer()

setIndexBuffer

public void setIndexBuffer(java.nio.IntBuffer indices)

recalcTriangleQuantity

protected void recalcTriangleQuantity()

getTriangleCount

public int getTriangleCount()
Returns the number of triangles contained in this mesh.

Overrides:
getTriangleCount in class Geometry

setTriangleQuantity

public void setTriangleQuantity(int triangleQuantity)

draw

public void draw(Renderer r)
draw calls super to set the render state then passes itself to the renderer. LOGIC: 1. If we're not RenderQueue calling draw goto 2, if we are, goto 3 2. If we are supposed to use queue, add to queue and RETURN, else 3 3. call super draw 4. tell renderer to draw me.

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

clearBuffers

public void clearBuffers()
Clears the buffers of this TriMesh. The buffers include its indexBuffer only.

Overrides:
clearBuffers in class Geometry

hasCollision

public boolean hasCollision(Spatial scene,
                            boolean checkTriangles)
determines if a collision between this trimesh and a given spatial occurs if it has true is returned, otherwise false is returned.

Specified by:
hasCollision in class Spatial
Parameters:
scene - the scene to test against.
checkTriangles - check for collisions on triangle accuracy level
Returns:
true if any collision were found

findCollisions

public void findCollisions(Spatial scene,
                           CollisionResults results)
determines if this TriMesh has made contact with the give scene. The scene is recursively transversed until a trimesh is found, at which time the two trimesh OBBTrees are then compared to find the triangles that hit.

Specified by:
findCollisions in class Spatial
Parameters:
scene - the scene to test against.
results - the results of the collisions.

hasTriangleCollision

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

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.

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.

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

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.

Parameters:
i -
vertices -

findTrianglePick

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

Parameters:
toTest - the ray to test. The direction of the ray must be normalized (length 1).
results - the indices to the triangles.

getMeshAsTrianglesVertices

public Vector3f[] getMeshAsTrianglesVertices(Vector3f[] verts)
Return this mesh object as triangles. Every 3 vertices returned compose a single triangle.

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

getVertIndex

protected int getVertIndex(int triangle,
                           int point)

getTriangleIndices

public int[] getTriangleIndices(int[] indices)

getMeshAsTriangles

public Triangle[] getMeshAsTriangles(Triangle[] tris)

getMaxIndex

public int getMaxIndex()

randomPointOnTriangles

public Vector3f randomPointOnTriangles(Vector3f fill,
                                       Vector3f work)
Returns a random point on the surface of a randomly selected triangle on the mesh

Parameters:
fill - The resulting selected point
work - Used in calculations to minimize memory creation overhead
Returns:
The resulting selected point

write

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

read

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