org.jmonkeyengine.tralala
Class MeshData

java.lang.Object
  extended by org.jmonkeyengine.tralala.MeshData

public final class MeshData
extends java.lang.Object

Immutable class that transforms the mesh. It is immutable to minimize get/set/construct array operations, and doesnt copy data unless it has to modify it. Since it is immutable remember to use the returned value, because the class internal state / method arguments dont change.


Field Summary
static int MAX_TEX_COORDS
           
 
Constructor Summary
MeshData(float[] vertexArray, float[] normalArray, float[][] uvArrays, short[] indexArray, float[] boneWeightArray, byte[] boneIndexArray, int maxNumOfWeights)
          Creates a mesh with the specified values.
MeshData(float[] vertexArray, float[] normalArray, float[] uvArray, short[] indexArray)
          Creates a mesh without animation, and only 1 tex coord.
MeshData(com.jme3.scene.Mesh mesh)
          creates MeshData from mesh
 
Method Summary
 MeshData compress()
          removes all unindexed vertex/normals/uvs.
 com.jme3.scene.Mesh createMesh()
           
 MeshData createSymmetricMesh(com.jme3.math.Vector3f planeOrigin, com.jme3.math.Vector3f planeNormal, float weldThreshold)
          Applies symmetry modifier to mesh, and creates a new mesh from the 2 submeshes.
 MeshData flipIndexes()
          Changes the order of indexes, e.g from 1,2,3 it becomes 3,2,1.
 MeshData flipU(int TexCoordNumber)
           
 MeshData flipV(int TexCoordNumber)
           
 java.util.LinkedHashSet<java.lang.Short> getAdjacentIndices(short index)
          For each triangle, when this index is refered in a triangle, the triangle indexes are returned.
 byte[] getBoneIndexArrayCopy()
           
 float[] getBoneWeightArrayCopy()
           
 void getBounds(com.jme3.math.Vector3f min, com.jme3.math.Vector3f max)
          Usage : Vector3f min = new Vector3f(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE); Vector3f max = new Vector3f(-Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE); getBounds(min,max);
 com.jme3.math.Vector3f getCenter()
           
 short getIndex(int i)
           
 short[] getIndexArrayCopy()
           
 com.jme3.math.Vector3f getNormal(int i)
           
 float[] getNormalArrayCopy()
           
 int getNumberOfIndexElements()
           
 int getNumberOfNormalElements()
           
 int getNumberOfUvElements(int TexCoordNumber)
           
 int getNumberOfVertexElements()
           
 com.jme3.math.Vector2f getUv(int i)
           
 com.jme3.math.Vector2f getUv(int i, int TexCoordNumber)
           
 float[] getUvArrayCopy(int TexCoordNumber)
           
 com.jme3.math.Vector3f getVertex(int i)
           
 float[] getVertexArrayCopy()
           
 MeshData merge(MeshData mesh2)
          Merges 2 meshes into 1.
 MeshData mirror(com.jme3.math.Vector3f planeOrigin, com.jme3.math.Vector3f planeNormal)
           
 MeshData moveUV(com.jme3.math.Vector2f uvMoveOffset, int TexCoordNumber)
           
 MeshData removeDuplicateData()
          Removes duplicate and unindexed vertex, uv, normals if it can.
 MeshData rotateUV(float uvRotateAngle, int TexCoordNumber)
           
 com.jme3.scene.Mesh save(com.jme3.scene.Mesh mesh)
          sets mesh to have the same data as this.
 MeshData scale(com.jme3.math.Vector3f size)
           
 MeshData scale(com.jme3.math.Vector3f size, com.jme3.math.Vector3f pivot)
           
 MeshData scaleUV(com.jme3.math.Vector2f uvScaleAmount, int TexCoordNumber)
           
 MeshData setBoneIndexArray(byte[] boneIndexArray)
           
 MeshData setBoneWeightArray(float[] boneWeightArray)
           
 MeshData setIndexArray(short[] indexArray)
           
 MeshData setNormalArray(float[] normalArray)
           
 MeshData setUvArray(float[] uvArray, int TexCoordNumber)
           
 MeshData setVertexArray(float[] vertexArray)
           
 MeshData switchUV(int TexCoordNumber)
          switches u with v.
 MeshData translate(com.jme3.math.Vector3f translate)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_TEX_COORDS

public static final int MAX_TEX_COORDS
See Also:
Constant Field Values
Constructor Detail

MeshData

public MeshData(float[] vertexArray,
                float[] normalArray,
                float[] uvArray,
                short[] indexArray)
Creates a mesh without animation, and only 1 tex coord.


MeshData

public MeshData(float[] vertexArray,
                float[] normalArray,
                float[][] uvArrays,
                short[] indexArray,
                float[] boneWeightArray,
                byte[] boneIndexArray,
                int maxNumOfWeights)
Creates a mesh with the specified values.


MeshData

public MeshData(com.jme3.scene.Mesh mesh)
creates MeshData from mesh

Method Detail

merge

public MeshData merge(MeshData mesh2)
Merges 2 meshes into 1. The second's mesh indexes change to point to their new position (after mesh1's array).

Parameters:
shareSkeleton - if the resulting mesh will have the skeleton of mesh1, (or mesh2 if mesh1 skeleton is null).

mirror

public MeshData mirror(com.jme3.math.Vector3f planeOrigin,
                       com.jme3.math.Vector3f planeNormal)
Parameters:
planeOrigin - the planeOrigin e.g (0,0,0)
planeNormal - the planeNormal is a vector that points upward from the plane e.g Vector3f.UNIT_Z

createSymmetricMesh

public MeshData createSymmetricMesh(com.jme3.math.Vector3f planeOrigin,
                                    com.jme3.math.Vector3f planeNormal,
                                    float weldThreshold)
Applies symmetry modifier to mesh, and creates a new mesh from the 2 submeshes.

Parameters:
planeOrigin - the planeOrigin e.g (0,0,0)
planeNormal - the planeNormal is a vector that points upward from the plane e.g Vector3f.UNIT_Z
weldThreshold - how much to smooth the vertices near the plane suggested amount from 0.001 until 0.1. Set it to negative number to disable welding.

scale

public MeshData scale(com.jme3.math.Vector3f size)

scale

public MeshData scale(com.jme3.math.Vector3f size,
                      com.jme3.math.Vector3f pivot)

translate

public MeshData translate(com.jme3.math.Vector3f translate)

getBounds

public void getBounds(com.jme3.math.Vector3f min,
                      com.jme3.math.Vector3f max)
Usage : Vector3f min = new Vector3f(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE); Vector3f max = new Vector3f(-Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE); getBounds(min,max);


getCenter

public com.jme3.math.Vector3f getCenter()

flipIndexes

public MeshData flipIndexes()
Changes the order of indexes, e.g from 1,2,3 it becomes 3,2,1. This will allow an invisible mesh to be seen.


flipU

public MeshData flipU(int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

flipV

public MeshData flipV(int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

moveUV

public MeshData moveUV(com.jme3.math.Vector2f uvMoveOffset,
                       int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

rotateUV

public MeshData rotateUV(float uvRotateAngle,
                         int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

scaleUV

public MeshData scaleUV(com.jme3.math.Vector2f uvScaleAmount,
                        int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

switchUV

public MeshData switchUV(int TexCoordNumber)
switches u with v.

Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

save

public com.jme3.scene.Mesh save(com.jme3.scene.Mesh mesh)
sets mesh to have the same data as this.


removeDuplicateData

public MeshData removeDuplicateData()
Removes duplicate and unindexed vertex, uv, normals if it can. lossless


compress

public MeshData compress()
removes all unindexed vertex/normals/uvs. lossless The indexes change to match the new structure.


getAdjacentIndices

public java.util.LinkedHashSet<java.lang.Short> getAdjacentIndices(short index)
For each triangle, when this index is refered in a triangle, the triangle indexes are returned.


createMesh

public com.jme3.scene.Mesh createMesh()

setIndexArray

public MeshData setIndexArray(short[] indexArray)

setNormalArray

public MeshData setNormalArray(float[] normalArray)

setUvArray

public MeshData setUvArray(float[] uvArray,
                           int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

setVertexArray

public MeshData setVertexArray(float[] vertexArray)

setBoneWeightArray

public MeshData setBoneWeightArray(float[] boneWeightArray)

setBoneIndexArray

public MeshData setBoneIndexArray(byte[] boneIndexArray)

getVertex

public com.jme3.math.Vector3f getVertex(int i)

getNormal

public com.jme3.math.Vector3f getNormal(int i)

getUv

public com.jme3.math.Vector2f getUv(int i)

getUv

public com.jme3.math.Vector2f getUv(int i,
                                    int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

getIndex

public short getIndex(int i)

getNumberOfVertexElements

public int getNumberOfVertexElements()

getNumberOfNormalElements

public int getNumberOfNormalElements()

getNumberOfUvElements

public int getNumberOfUvElements(int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

getNumberOfIndexElements

public int getNumberOfIndexElements()

getVertexArrayCopy

public float[] getVertexArrayCopy()

getNormalArrayCopy

public float[] getNormalArrayCopy()

getUvArrayCopy

public float[] getUvArrayCopy(int TexCoordNumber)
Parameters:
TexCoordNumber - which array of tex coords to affect. Usual choice : 0

getIndexArrayCopy

public short[] getIndexArrayCopy()

getBoneWeightArrayCopy

public float[] getBoneWeightArrayCopy()

getBoneIndexArrayCopy

public byte[] getBoneIndexArrayCopy()