org.xith3d.utility.geometry
Class GeometryInfo

java.lang.Object
  extended by org.xith3d.utility.geometry.GeometryInfo
Direct Known Subclasses:
XithGeometryInfo

public class GeometryInfo
extends java.lang.Object

This class allows for optimalization of indexed geometry. In most cases it will be filled with GeometryCreator.fillGeometryInfo, processed and result geometry will be retrieved. Exact way for creating renderer-specific geometry should be implemented in subclasses of this class.


Field Summary
protected  int[] smoothGroups
           
protected  int state
           
protected static int STATE_MERGED
           
protected static int STATE_SPLIT
           
protected static int STATE_UNKNOWN
           
protected  int[] triangles
           
protected  org.xith3d.utility.geometry.VertexData[] vertices
           
 
Constructor Summary
GeometryInfo()
          Constructs new GeometryInfo
 
Method Summary
 int[] createContinousStrip()
          Create continous triangle strip with separate substrips connected by degenerate triangles.
 int getVertexCacheSize()
           
 void optimizeTrianglesForCache()
          This method reorders face indices to fit well into vertex cache of GPU.
 void recalculateFlatNormals()
          This method computes normal for each face in flat mode - every vertex is duplicated for each face and assigned separate normal belonging to this face.
 void recalculateSmoothGroupNormals()
          This method computes smoothened normals for each vertex.
 void setVertexCacheSize(int vertexCacheSize)
          This method sets size of vertex cache on gpu for which strips/triangle lists should be optimized.
 void unweldVertices()
          Duplicate vertex data for each face, so it is not shared between them.
 void weldVertices()
          Find vertices with same parameters and merge them into one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_UNKNOWN

protected static final int STATE_UNKNOWN
See Also:
Constant Field Values

STATE_SPLIT

protected static final int STATE_SPLIT
See Also:
Constant Field Values

STATE_MERGED

protected static final int STATE_MERGED
See Also:
Constant Field Values

vertices

protected org.xith3d.utility.geometry.VertexData[] vertices

triangles

protected int[] triangles

smoothGroups

protected int[] smoothGroups

state

protected int state
Constructor Detail

GeometryInfo

public GeometryInfo()
Constructs new GeometryInfo

Method Detail

recalculateFlatNormals

public void recalculateFlatNormals()
This method computes normal for each face in flat mode - every vertex is duplicated for each face and assigned separate normal belonging to this face. As side effect of this method, indices are 'split'. Merging them will probably not do much, as vertices with same coords will have different normals because of flat shading.


recalculateSmoothGroupNormals

public void recalculateSmoothGroupNormals()
This method computes smoothened normals for each vertex. Normal of each face from same smoothing group is averaged to compute value of vertex. This means that vertex will be duplicated if it belongs to faces belonging to more than one smooth group. After this operation, vertices will be mostly welded - unless there is a case where two neighbour faces from different smoothing group have same normal.


weldVertices

public void weldVertices()
Find vertices with same parameters and merge them into one. Allows sharing of data between faces, which is a requirement for performance benefit from GPU vertex cache.

See Also:
unweldVertices()

unweldVertices

public void unweldVertices()
Duplicate vertex data for each face, so it is not shared between them. Allows for allocating per-face normal (flat shading).

See Also:
weldVertices()

optimizeTrianglesForCache

public void optimizeTrianglesForCache()
This method reorders face indices to fit well into vertex cache of GPU. This operation is meaningful if you plan to use non-strip triangle array later - in other case, use one of strip generation methods, which are cache-aware by default. Note: this method destroys smoothGroups info and it cannot be recovered, as order of faces is changed. If you want to use smoothing group info for generating normals, you need to do it _before_ you call this method.

See Also:
setVertexCacheSize(int)

createContinousStrip

public int[] createContinousStrip()
Create continous triangle strip with separate substrips connected by degenerate triangles. Please note that unless vertices are welded before (explicitly by weldVertices or implictly by recalculateSmoothGroupNormals) stripification will not help with perfomance, as same vertex will have different index for different face.

Returns:
indices of triangle strip

getVertexCacheSize

public int getVertexCacheSize()
Returns:
the vertexCacheSize

setVertexCacheSize

public void setVertexCacheSize(int vertexCacheSize)
This method sets size of vertex cache on gpu for which strips/triangle lists should be optimized. This is the "actual" cache size, so 24 for GeForce3 and 16 for GeForce1/2 You may want to play around with this number to tweak performance. Default value: 16 In case of doubt it is better to underestimate size of cache. If you don't care about vertex cache and want strips as long as possible, put very high value here - but be warned, because stripification algorithm is O(n^2*m) [doublecheck - is it true?], where n is number of indices, and m is size of vertexCacheSize. On the other hand, with too small value, you will get too many small strips and cost of degenerate triangles will rise.

Parameters:
vertexCacheSize - The vertexCacheSize to set.