com.threed.jpct
Class Mesh

java.lang.Object
  extended bycom.threed.jpct.Mesh
All Implemented Interfaces:
java.io.Serializable

public final class Mesh
extends java.lang.Object
implements java.io.Serializable

In a Mesh, jPCT stores the actual vertex and triangle information for an object. Mesh can't be instantiated directly. Meshes are shareable between objects. This means that more than one object may use the same instance of Mesh. This saves memory and is more cache-friendly. Meshes are also used for implementing keyframe animation.

See Also:
Object3D, Object3D.getMesh(), Object3D.cloneObject(), Animation, Serialized Form

Field Summary
static boolean COMPRESS
          The mesh will be compressed
static boolean DONT_COMPRESS
          The mesh won't be compressed
static int SERIALIZE_ALL
          normal serialization (default)
static int SERIALIZE_LOW_PRECISION
          float data will be saved as 16 bit precision. on the average ~0.3 percent of precision will be lost
static int SERIALIZE_VERTICES_ONLY
          Normals will not be serialized and will have to be recalculated during deserialization.
 
Method Summary
 void addVertexAttributes(VertexAttributes attrs)
          Adds some vertex attributes to this mesh.
 void applyVertexController()
          Executes the apply() method of the assigned VertexController and updates the mesh's vertex data with the new values generated by the controller.
 Mesh cloneMesh(boolean compressed)
          Returns a copy of this mesh.
 void compress()
          Compresses the mesh by removing unused information from it.
 float[] getBoundingBox()
          Returns the bounding box in object space of this mesh in a float array.
 int getTriangleCount()
          The number of triangles for this mesh.
 int getUniqueVertexCount()
          Returns the number of unique vertices.
 VertexAttributes[] getVertexAttributes()
          Returns an array with all the currently assigned vertex attributes.
 int getVertexCount()
          Returns the number of vertices this mesh consists of
 boolean isLocked()
          Returns if this mesh has been locked or not!
 void removeVertexController()
          Removes the VertexController from this mesh.
 void setLocked(boolean locked)
          Locks an object.
 void setSerializeMethod(int method)
          Sets the serialization method.
 boolean setVertexController(IVertexController controller, boolean modify)
          Sets the VertexController for this Mesh.
 void strip()
          Removes triangle information from this mesh.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPRESS

public static final boolean COMPRESS
The mesh will be compressed

See Also:
Constant Field Values

DONT_COMPRESS

public static final boolean DONT_COMPRESS
The mesh won't be compressed

See Also:
Constant Field Values

SERIALIZE_ALL

public static final int SERIALIZE_ALL
normal serialization (default)

See Also:
Constant Field Values

SERIALIZE_VERTICES_ONLY

public static final int SERIALIZE_VERTICES_ONLY
Normals will not be serialized and will have to be recalculated during deserialization. This saves a lot of space but increases load time.

See Also:
Constant Field Values

SERIALIZE_LOW_PRECISION

public static final int SERIALIZE_LOW_PRECISION
float data will be saved as 16 bit precision. on the average ~0.3 percent of precision will be lost

See Also:
Constant Field Values
Method Detail

setVertexController

public boolean setVertexController(IVertexController controller,
                                   boolean modify)
Sets the VertexController for this Mesh. A VertexController is the only way for an application to modify the vertex data of jPCT's meshes after build-time.
Usually, a custom VertexController extend the GenericVertexController the API provides. An instance can only be assigned to one mesh at a time.
This mesh should include vertex normals, i.e. it has to belong to an object for which build() has been called already. If that's not the case, jPCT will print out a warning message.

Parameters:
controller - the controller
modify - the mode, i.e. if the modifications are cumulative or not
Returns:
true, if everything went well
See Also:
IVertexController.ALTER_SOURCE_MESH, IVertexController.PRESERVE_SOURCE_MESH, IVertexController, GenericVertexController

applyVertexController

public void applyVertexController()
Executes the apply() method of the assigned VertexController and updates the mesh's vertex data with the new values generated by the controller.


removeVertexController

public void removeVertexController()
Removes the VertexController from this mesh. When doing so, the controller's destroy() method will be called.


strip

public void strip()
Removes triangle information from this mesh. This is useful to save some memory for meshes that are used for keyframing only (triangle information are not needed in that case). For any other meshes: Don't call this method. It will break your mesh!


compress

public void compress()
Compresses the mesh by removing unused information from it. When creating a mesh, it is usually not known how many unique vertices it may contain, so space is reserved for the extreme case that no vertex-sharing is possible within this mesh (the vertex sharing is something that jPCT automatically takes care of). The more vertices are sharable between the triangles of the mesh, the more space remains unused. compress() frees this space at the cost that no additional vertices can be added to the mesh after compressing it. If one is sure that this is not required, compressing a mesh can be helpful to save memory. Meshes of loaded MD2- and 3DS-models are compressed by default.

See Also:
Loader.loadMD2(java.lang.String, float), getVertexCount(), getUniqueVertexCount()

cloneMesh

public Mesh cloneMesh(boolean compressed)
Returns a copy of this mesh. A copy of a mesh can be used to take a mesh from an existing object and modify it without modifying the source mesh. With this, you can also use meshes from existing objects (not only temporary ones) as meshes for a keyframe animation [like: Animation.addKeyFrame(obj.getMesh().cloneMesh(...))]. Cloning a compressed mesh without letting cloneMesh compress it again will result in an uncompressed one (eats up more memory, but triangles may be added to such a mesh again).

Parameters:
compressed - indicates if compress() should by called after cloning the mesh or not
Returns:
a copy of this mesh
See Also:
COMPRESS, DONT_COMPRESS, compress()

getVertexCount

public int getVertexCount()
Returns the number of vertices this mesh consists of

Returns:
the number of vertices

getUniqueVertexCount

public int getUniqueVertexCount()
Returns the number of unique vertices. Unlike getVertexCount(), this number takes into account that vertices are shared between triangles whenever possible to lower geometry processing time. jPCT does only transform as many vertices as this number indicates.

Returns:
the number of unique vertices

getTriangleCount

public int getTriangleCount()
The number of triangles for this mesh.

Returns:
the number of triangles

getBoundingBox

public float[] getBoundingBox()
Returns the bounding box in object space of this mesh in a float array. Format is minX, maxX, minY, maxY, minZ, maxZ. Calculation is done everytime this method is being called, so don't call it without need.

Returns:
float[] the corners of the BB in object space

setLocked

public void setLocked(boolean locked)
Locks an object. A locked mesh can't and won't be stripped even if you call the corresponding methods. This can be used to strip Object3Ds that are sharing Meshes.

Parameters:
locked - should it be locked?

isLocked

public boolean isLocked()
Returns if this mesh has been locked or not!

Returns:
locked?

addVertexAttributes

public void addVertexAttributes(VertexAttributes attrs)
Adds some vertex attributes to this mesh. The instance of VertexAttributes' attribute count has to match the unique vertex count of this mesh. You can add multiple attributes.

Parameters:
attrs - the new attributes

getVertexAttributes

public VertexAttributes[] getVertexAttributes()
Returns an array with all the currently assigned vertex attributes.

Returns:
the attributes or null, if none has been assigned

setSerializeMethod

public void setSerializeMethod(int method)
Sets the serialization method. Can be used to decrease the size of a serialized Mesh at the cost of loading speed and/or accuracy.

Parameters:
method - Either SERIALIZE_ALL, DONT_SERIALIZE_NORMALS or SERIALIZE_LOW_PRECISION. Methods can be combined by using the or-operator.