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:
java.io.Serializable
Direct Known Subclasses:
BezierMesh, Box, ClodMesh, ClothPatch, CompositeMesh, Cylinder, Disk, Dome, EmptyTriMesh, Hexagon, JointMesh, Octahedron, OrientedBox, PQTorus, Pyramid, Quad, Sphere, Torus, WaterSurface

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 on every three points.

Version:
$Id: TriMesh.java,v 1.37 2004/11/30 00:32:05 mojomonkey Exp $
Author:
Mark Powell
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.jme.scene.Spatial
defaultStateList, queueDistance
 
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, Vector3f[] vertices, Vector3f[] normal, ColorRGBA[] color, Vector2f[] texture, int[] 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 drawBounds(Renderer r)
          drawBounds 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 thisIndex, java.util.ArrayList otherIndex)
          This function finds all intersections between this trimesh and the checking one.
 void findTrianglePick(Ray toTest, java.util.ArrayList results)
          findTrianglePick determines the triangles of this trimesh that are being touched by the ray.
 Matrix3f findWorldRotMat()
          This function is ONLY to be used by the intersection testing code.
 java.nio.IntBuffer getIndexAsBuffer()
          getIndexAsBuffer retrieves the indices array as an IntBuffer.
 int[] getIndices()
          getIndices retrieves the indices into the vertex array.
 Vector3f[] getMeshAsTriangles()
          Return this mesh object as triangles.
 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 getTriangleQuantity()
          Returns the number of triangles this TriMesh contains.
 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.
 Spatial putClone(Spatial store, CloneCreator properties)
          sets the attributes of this TriMesh into a given spatial.
 void reconstruct(Vector3f[] vertices, Vector3f[] normal, ColorRGBA[] color, Vector2f[] texture, int[] indices)
          Recreates the geometric information of this TriMesh from scratch.
 void setIndexBuffer(java.nio.IntBuffer toSet)
          Sets this geometry's index buffer as a refrence to the passed IntBuffer.
 void setIndices(int[] indices)
          setIndices sets the index array for this TriMesh.
 void updateCollisionTree()
          This function creates a collision tree from the TriMesh's current information.
 void updateIndexBuffer()
          setIndexBuffers creates the IntBuffer that contains the indices array.
 
Methods inherited from class com.jme.scene.Geometry
applyStates, copyTextureCoords, findPick, getAllTextures, getCloneID, getColorAsFloatBuffer, getColors, getModelBound, getNormalAsFloatBuffer, getNormals, getNumberOfUnits, getTextureAsFloatBuffer, getTextureAsFloatBuffer, getTextures, getTextures, getVBOColorID, getVBONormalID, getVBOTextureID, getVBOVertexID, getVerticeAsFloatBuffer, getVertices, getVertQuantity, isVBOColorEnabled, isVBONormalEnabled, isVBOTextureEnabled, isVBOVertexEnabled, randomVertice, reconstruct, setAllTextures, setColor, setColors, setForceView, setModelBound, setNormal, setNormals, setRandomColors, setSolidColor, setTexture, setTexture, setTextureCoord, setTextures, setTextures, setVBOColorEnabled, setVBOColorID, setVBONormalEnabled, setVBONormalID, setVBOTextureEnabled, setVBOTextureID, setVBOVertexEnabled, setVBOVertexID, setVertex, setVertices, updateColorBuffer, updateModelBound, updateNormalBuffer, updateTextureBuffer, updateTextureBuffer, updateVertexBuffer, updateWorldBound
 
Methods inherited from class com.jme.scene.Spatial
addController, applyDefaultStates, calculateCollisions, calculatePick, clearCurrentState, clearCurrentStates, clearRenderState, getController, getControllers, getCurrentState, getLastFrustumIntersection, getLightCombineMode, getLocalRotation, getLocalScale, getLocalTranslation, getName, getParent, getRenderQueueMode, getRenderStateList, getTextureCombineMode, getWorldBound, getWorldRotation, getWorldScale, getWorldTranslation, getZOrder, isForceCulled, isForceView, onDraw, onDrawBounds, propagateBoundToRoot, removeController, setForceCull, setLightCombineMode, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setName, setParent, setRenderQueueMode, setRenderState, setTextureCombineMode, setWorldBound, setZOrder, toString, updateGeometricState, updateRenderState
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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,
               Vector3f[] vertices,
               Vector3f[] normal,
               ColorRGBA[] color,
               Vector2f[] texture,
               int[] 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.
texture - the texture coordinates of the mesh.
indices - the indices of the vertex array.
Method Detail

reconstruct

public void reconstruct(Vector3f[] vertices,
                        Vector3f[] normal,
                        ColorRGBA[] color,
                        Vector2f[] texture,
                        int[] 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.
texture - The texture information for this TriMesh.
indices - The index information for this TriMesh.
See Also:
Geometry.reconstruct(com.jme.math.Vector3f[], com.jme.math.Vector3f[], com.jme.renderer.ColorRGBA[], com.jme.math.Vector2f[])

getIndices

public int[] getIndices()
getIndices retrieves the indices into the vertex array.

Returns:
the indices into the vertex array.

getIndexAsBuffer

public java.nio.IntBuffer getIndexAsBuffer()
getIndexAsBuffer retrieves the indices array as an IntBuffer.

Returns:
the indices 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

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 -

getTriangleQuantity

public int getTriangleQuantity()
Returns the number of triangles this TriMesh contains.

Returns:
The current number of triangles.

setIndices

public void setIndices(int[] indices)
setIndices sets the index array for this TriMesh.

Parameters:
indices - the index array.

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)

drawBounds

public void drawBounds(Renderer r)
drawBounds calls super to set the render state then passes itself to the renderer.

Overrides:
drawBounds in class Geometry
Parameters:
r - the renderer to display

updateIndexBuffer

public void updateIndexBuffer()
setIndexBuffers creates the IntBuffer that contains the indices array.


clearBuffers

public void clearBuffers()
Clears the buffers of this TriMesh. The buffers include its indexBuffer, and all Geometry buffers.

Overrides:
clearBuffers in class Geometry

setIndexBuffer

public void setIndexBuffer(java.nio.IntBuffer toSet)
Sets this geometry's index buffer as a refrence to the passed IntBuffer. Incorrectly built IntBuffers can have undefined results. Use with care.

Parameters:
toSet - The IntBuffer to set this geometry's index buffer to

updateCollisionTree

public void updateCollisionTree()
This function creates a collision tree from the TriMesh's current information. If the information changes, the tree needs to be updated.

Overrides:
updateCollisionTree in class Spatial

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

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 thisIndex,
                                  java.util.ArrayList 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.

findTrianglePick

public void findTrianglePick(Ray toTest,
                             java.util.ArrayList 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.
results - the indices to the triangles.

findWorldRotMat

public Matrix3f findWorldRotMat()
This function is ONLY to be used by the intersection testing code. It should not be called by users. It returns a matrix3f representation of the mesh's world rotation.

Returns:
This mesh's world rotation.

putClone

public Spatial putClone(Spatial store,
                        CloneCreator properties)
sets the attributes of this TriMesh into a given spatial. What is to be stored is contained in the properties parameter.

Overrides:
putClone in class Geometry
Parameters:
store - the Spatial to clone to.
properties - the CloneCreator object that defines what is to be cloned.

getMeshAsTriangles

public Vector3f[] getMeshAsTriangles()
Return this mesh object as triangles. Every 3 vertices returned compose single triangle. Vertices are returned by reference for efficiency, so it is required that they won't be modified by caller.

Returns:
view of current mesh as group of triangle vertices