com.threed.jpct
Class GenericVertexController

java.lang.Object
  extended bycom.threed.jpct.GenericVertexController
All Implemented Interfaces:
IVertexController, java.io.Serializable

public abstract class GenericVertexController
extends java.lang.Object
implements IVertexController, java.io.Serializable

The GenericVertexController provides an abstract class that implements large portions of the IVertexController interface. Every implementation of a VertexController should extend this class rather than implementing IVertexController alone.
Don't use a GenericVertexController on meshes of objects that do use an OcTree unless you are sure that no vertex will cross its node's borders after it has been modified.
The GenericVertexController holds a copy of the actual mesh data, i.e. it doesn't get the data directly from the mesh everytime. While this is much faster, it makes the controller blind to changes to the mesh's vertex data that may happen behind its back (like using keyframe animations on an object that makes use of the mesh). Keep this in mind.

See Also:
IVertexController, Serialized Form

Field Summary
 
Fields inherited from interface com.threed.jpct.IVertexController
ALTER_SOURCE_MESH, PRESERVE_SOURCE_MESH
 
Constructor Summary
GenericVertexController()
           
 
Method Summary
 void cleanup()
          This is an empty implementation of cleanup().
 void destroy()
          This method will be called when the controller will be removed from a Mesh.
 SimpleVector[] getDestinationMesh()
          Returns the destination mesh's vertex data.
 SimpleVector[] getDestinationNormals()
          Returns the destination mesh's normals.
 int getMeshSize()
          Returns the size of the mesh.
 int[] getPolygonIDs(int vertex, int max)
          Returns the polygon IDs of the polygons that are using the vertex "number".
 SimpleVector[] getSourceMesh()
          Returns the source mesh's vertex data, i.e. the vertex-data that needs modification.
 SimpleVector[] getSourceNormals()
          Returns the source mesh's normals, i.e. the normals that need modification.
 float[][] getTangentVectors()
          If available, this will return the tangent vectors for the mesh.
 boolean init(Mesh mesh, boolean modify)
          Initialize the VertexController with a mesh to modify and a operating mode.
 void refreshMeshData()
          Refreshes the controller's data with the data taken directly from the Mesh.
 boolean setup()
          This is an empty implementation of setup().
 void updateMesh()
          Alters the actual Mesh to reflect the modifications that have been applied to the DestinationMesh- and DestinationNormals-arrays.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.threed.jpct.IVertexController
apply
 

Constructor Detail

GenericVertexController

public GenericVertexController()
Method Detail

init

public final boolean init(Mesh mesh,
                          boolean modify)
Description copied from interface: IVertexController
Initialize the VertexController with a mesh to modify and a operating mode. There is no need to call this method from inside an application.

Specified by:
init in interface IVertexController
Parameters:
mesh - the Mesh the controller should be assigned to
modify - the mode
Returns:
true, if the controller has been intialized correctly
See Also:
IVertexController.ALTER_SOURCE_MESH, IVertexController.PRESERVE_SOURCE_MESH

setup

public boolean setup()
This is an empty implementation of setup(). Overwrite it, if you intend to do some work here. Otherwise, leave it like it is.

Specified by:
setup in interface IVertexController
Returns:
true

getSourceMesh

public final SimpleVector[] getSourceMesh()
Description copied from interface: IVertexController
Returns the source mesh's vertex data, i.e. the vertex-data that needs modification. Every SimpleVector in this array represents a vertex in the mesh. However, there's no information which vertex exactly (because they don't have ids or something).
Read the data from this array, but don't modify it.

Specified by:
getSourceMesh in interface IVertexController
Returns:
the source mesh's vertices

getSourceNormals

public final SimpleVector[] getSourceNormals()
Description copied from interface: IVertexController
Returns the source mesh's normals, i.e. the normals that need modification. Every SimpleVector in this array represents a normal in the mesh. The normal at the specific index is the normal of the corresponding vertex in the SourceMesh-array.
Read the data from this array, but don't modify it.

Specified by:
getSourceNormals in interface IVertexController
Returns:
the source mesh's normals

getDestinationMesh

public final SimpleVector[] getDestinationMesh()
Description copied from interface: IVertexController
Returns the destination mesh's vertex data. The new vertices will be stored in these SimpleVectors. There's no need to replace the SimpleVectors in this array with new ones. Just set their x,y and z components to the new values.
Write into the SimpleVectors of this array, don't read from them.

Specified by:
getDestinationMesh in interface IVertexController
Returns:
the destination mesh's vertices

getDestinationNormals

public final SimpleVector[] getDestinationNormals()
Description copied from interface: IVertexController
Returns the destination mesh's normals. The new normals will be stored in these SimpleVectors. Calculating the vertex normal of a modified vertex is not always cheap. In some cases, one may get away with not modifying the normals at all. This will cause slightly wrong lighting, but eases the calculations.
Write into the SimpleVectors of this array, don't read from them.

Specified by:
getDestinationNormals in interface IVertexController
Returns:
the destination mesh's normals

getMeshSize

public final int getMeshSize()
Description copied from interface: IVertexController
Returns the size of the mesh. This is the length all SimpleVector-array returned by the methods above will have.

Specified by:
getMeshSize in interface IVertexController
Returns:
the size of the mesh

refreshMeshData

public void refreshMeshData()
Description copied from interface: IVertexController
Refreshes the controller's data with the data taken directly from the Mesh. This can be useful to reflect changes to the controller that have been applied to the mesh outside of the controller.

Specified by:
refreshMeshData in interface IVertexController

updateMesh

public final void updateMesh()
Alters the actual Mesh to reflect the modifications that have been applied to the DestinationMesh- and DestinationNormals-arrays. No need to call this method directly from an application. The GenericVertexController automatically takes care of an object's bounding box.

Specified by:
updateMesh in interface IVertexController

destroy

public final void destroy()
Description copied from interface: IVertexController
This method will be called when the controller will be removed from a Mesh. No need to call this method directly.

Specified by:
destroy in interface IVertexController
See Also:
Mesh.removeVertexController()

cleanup

public void cleanup()
This is an empty implementation of cleanup(). Overwrite it, if you intend to do some work here. Otherwise, leave it like it is.

Specified by:
cleanup in interface IVertexController
See Also:
Mesh.removeVertexController()

getPolygonIDs

public int[] getPolygonIDs(int vertex,
                           int max)
Description copied from interface: IVertexController
Returns the polygon IDs of the polygons that are using the vertex "number". This can be used to determine which vertices belong to a polygon, which could be useful in some VertexControllers. This should be done at setup time, not at runtime.

Specified by:
getPolygonIDs in interface IVertexController
Parameters:
vertex - the number of the vertex
max - the maximum of IDs to return
Returns:
the IDs

getTangentVectors

public float[][] getTangentVectors()
Description copied from interface: IVertexController
If available, this will return the tangent vectors for the mesh. For these vectors, there's no difference between source and destination. You can read from as well as write to this array.

Specified by:
getTangentVectors in interface IVertexController
Returns:
the tangent vectors or null, if none have been assigned