Class InterleavedTriangleStripArray

java.lang.Object
  |
  +--javax.media.j3d.SceneGraphObject
        |
        +--javax.media.j3d.NodeComponent
              |
              +--javax.media.j3d.Geometry
                    |
                    +--javax.media.j3d.GeometryArray
                          |
                          +--javax.media.j3d.GeometryStripArray
                                |
                                +--javax.media.j3d.TriangleStripArray
                                      |
                                      +--InterleavedTriangleStripArray

public class InterleavedTriangleStripArray
extends javax.media.j3d.TriangleStripArray

This class is a specialization of the TriangleStripArray created to enhance performance of generating triangle strips. This is done by adding a generateNormals method to calculate, in place the normals for each vertex. This saves the overhead in processor time and memory required for using the NormalsGenerator object.

Author:
Mark Pendergast

Field Summary
private  int COLOR_OFFSET
           
private  int COORD_OFFSET
           
private  int FLOATSPERVERTEX
           
private  int NORMAL_OFFSET
           
private  int TEXTURE_OFFSET
           
 
Fields inherited from class javax.media.j3d.GeometryArray
ALLOW_COLOR_READ, ALLOW_COLOR_WRITE, ALLOW_COORDINATE_READ, ALLOW_COORDINATE_WRITE, ALLOW_COUNT_READ, ALLOW_COUNT_WRITE, ALLOW_FORMAT_READ, ALLOW_NORMAL_READ, ALLOW_NORMAL_WRITE, ALLOW_REF_DATA_READ, ALLOW_REF_DATA_WRITE, ALLOW_TEXCOORD_READ, ALLOW_TEXCOORD_WRITE, BY_REFERENCE, COLOR_3, COLOR_4, COORDINATES, INTERLEAVED, NORMALS, TEXTURE_COORDINATE_2, TEXTURE_COORDINATE_3
 
Fields inherited from class javax.media.j3d.Geometry
ALLOW_INTERSECT
 
Fields inherited from class javax.media.j3d.NodeComponent
 
Fields inherited from class javax.media.j3d.SceneGraphObject
 
Constructor Summary
InterleavedTriangleStripArray(int vertexCount, int vertexFormat, int[] stripVertexCounts)
           
 
Method Summary
static void averageNormals(double[][] normals, int nNormals, double[] avgNormal)
          This method calculates the average of a set of normals stored in an array of doubles.
 void calcNormalCCW(double[] normal, float[] vertexData, int v0, int v1, int v2)
          Calculate normal, assumes counter-clockwise order of vertices
 void calcNormalCW(double[] norm, float[] vertexData, int v0, int v1, int v2)
          Calculate normal, assumes clockwise order of vertices
 void generateNormals(boolean averageAdjacentColumns)
          Traverse interleaved vertex data and generate normal values.
 void normalize(float[] vertexData, int v)
          normalize (make length equal 1) vector from origin to normal
 
Methods inherited from class javax.media.j3d.TriangleStripArray
cloneNodeComponent
 
Methods inherited from class javax.media.j3d.GeometryStripArray
getNumStrips, getStripVertexCounts
 
Methods inherited from class javax.media.j3d.GeometryArray
getColor, getColor, getColor, getColor, getColor, getColor, getColorRef3b, getColorRef3f, getColorRef4b, getColorRef4f, getColorRefByte, getColorRefFloat, getColors, getColors, getColors, getColors, getColors, getColors, getCoordinate, getCoordinate, getCoordinate, getCoordinate, getCoordinates, getCoordinates, getCoordinates, getCoordinates, getCoordRef3d, getCoordRef3f, getCoordRefDouble, getCoordRefFloat, getInitialColorIndex, getInitialCoordIndex, getInitialNormalIndex, getInitialTexCoordIndex, getInitialVertexIndex, getInterleavedVertices, getNormal, getNormal, getNormalRef3f, getNormalRefFloat, getNormals, getNormals, getTexCoordRef2f, getTexCoordRef3f, getTexCoordRefFloat, getTexCoordSetCount, getTexCoordSetMap, getTexCoordSetMapLength, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getValidVertexCount, getVertexCount, getVertexFormat, setColor, setColor, setColor, setColor, setColor, setColor, setColorRef3b, setColorRef3f, setColorRef4b, setColorRef4f, setColorRefByte, setColorRefFloat, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setCoordinate, setCoordinate, setCoordinate, setCoordinate, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordRef3d, setCoordRef3f, setCoordRefDouble, setCoordRefFloat, setInitialColorIndex, setInitialCoordIndex, setInitialNormalIndex, setInitialTexCoordIndex, setInitialVertexIndex, setInterleavedVertices, setNormal, setNormal, setNormalRef3f, setNormalRefFloat, setNormals, setNormals, setNormals, setNormals, setTexCoordRef2f, setTexCoordRef3f, setTexCoordRefFloat, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setValidVertexCount, updateData
 
Methods inherited from class javax.media.j3d.NodeComponent
cloneNodeComponent, duplicateNodeComponent, duplicateNodeComponent, getDuplicateOnCloneTree, setDuplicateOnCloneTree
 
Methods inherited from class javax.media.j3d.SceneGraphObject
clearCapability, duplicateSceneGraphObject, getCapability, getUserData, isCompiled, isLive, setCapability, setUserData, updateNodeReferences
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEXTURE_OFFSET

private int TEXTURE_OFFSET

COLOR_OFFSET

private int COLOR_OFFSET

NORMAL_OFFSET

private int NORMAL_OFFSET

COORD_OFFSET

private int COORD_OFFSET

FLOATSPERVERTEX

private int FLOATSPERVERTEX
Constructor Detail

InterleavedTriangleStripArray

public InterleavedTriangleStripArray(int vertexCount,
                                     int vertexFormat,
                                     int[] stripVertexCounts)
Parameters:
vertexCount - the number of vertex elements in this array
vertexFormat - a mask indicating which components are present in each vertex. This is specified as one or more individual flags that are bitwise "OR"ed together to describe the per-vertex data. The flags include: COORDINATES, to signal the inclusion of vertex positions--always present; NORMALS, to signal the inclusion of per vertex normals; one of COLOR_3, COLOR_4, to signal the inclusion of per vertex colors (without or with color information); and one of TEXTURE_COORDINATE_2 or TEXTURE_COORDINATE_3, to signal the inclusion of per-vertex texture coordinates 2D or 3D.
stripVertexCounts - - array that specifies the count of the number of vertices for each separate strip. The length of this array is the number of separate strips.
Throws:
java.lang.IllegalArgumentException - if vertexCount is less than 3 or the sum of all stripVertexCounts is not equal to vertexCount, or if the BY_REFERENCE and INTERLEAVED formats are not enabled
Method Detail

generateNormals

public void generateNormals(boolean averageAdjacentColumns)
Traverse interleaved vertex data and generate normal values.

Parameters:
averageAdjacentColumns - if true, then the algorithm assumes that the strips comprise a grid whereby adjacent strips have common vertices. The normals of the vertices are averaged to eliminate stripes.

calcNormalCW

public void calcNormalCW(double[] norm,
                         float[] vertexData,
                         int v0,
                         int v1,
                         int v2)
Calculate normal, assumes clockwise order of vertices

Parameters:
norm - reference to a double[3] array to receive the result
v0 - index of first vertex in interleaved data
v1 - index of middle vertex in interleaved data
v2 - index of last vertex in interleaved data

calcNormalCCW

public void calcNormalCCW(double[] normal,
                          float[] vertexData,
                          int v0,
                          int v1,
                          int v2)
Calculate normal, assumes counter-clockwise order of vertices

Parameters:
normal - reference to a double[3] array to receive the result
v0 - index of first coordinates in interleaved data
v1 - index of middle coordinates in interleaved data
v2 - index of last coordinates in interleaved data

averageNormals

public static void averageNormals(double[][] normals,
                                  int nNormals,
                                  double[] avgNormal)
This method calculates the average of a set of normals stored in an array of doubles.

Parameters:
normals - a an N by 3 double array holding vector normals to be averaged
nNormals - number of normals to average
avgNormal - destination for the averaged normal

normalize

public void normalize(float[] vertexData,
                      int v)
normalize (make length equal 1) vector from origin to normal

Parameters:
vertexData - interleaved array of floats
v - index into interleaved data of vertex data to be normalized.