com.sun.j3d.utils.geometry
Class NormalGenerator

java.lang.Object
  extended by com.sun.j3d.utils.geometry.NormalGenerator

public class NormalGenerator
extends java.lang.Object

The NormalGenerator utility will calculate and fill in the normals of a GeometryInfo object. The calculated normals are estimated based on an analysis of the indexed coordinate information. If your data isn't indexed, index lists will be created.

If two (or more) triangles in the model share the same coordinate index then the normal generator will attempt to generate one normal for the vertex, resulting in a "smooth" looking surface. If two coordinates don't have the same index then they will have two separate normals, even if they have the same position. This will result in a "crease" in your object. If you suspect that your data isn't properly indexed, call GeometryInfo.recomputeIndexes().

Of course, sometimes your model *has* a crease in it. That's what creaseAngle is. If two triangles' normals differ by more than creaseAngle, then the vertex will get two separate normals, creating a discontinuous crease in the model. This is perfect for the edge of a table or the corner of a cube, for instance.


Field Summary
private  int[] colorInds
           
private  int[] coordInds
           
private  double creaseAngle
           
private static int DEBUG
           
private  Vector3f[] facetNorms
           
private  GeometryInfo gi
           
private  int[] normalInds
           
private  int numTexSets
           
private  int[] stripCounts
           
private static long t1
           
private static long t2
           
private static long t3
           
private static long t4
           
private static long t5
           
private static long t6
           
private  java.util.ArrayList tally
           
private  int[][] texInds
           
private  Triangulator tr
           
 
Constructor Summary
NormalGenerator()
          Constructor.
NormalGenerator(double radians)
          Constructor.
 
Method Summary
private  void calculatefacetNorms()
           
private  void calculateVertexNormals(int maxShare)
           
(package private)  void convertBackToOldPrim(GeometryInfo geom, int oldPrim, int[] oldStripCounts)
          Used when the user calls the NormalGenerator and not the Stripifier or Triangulator.
private  void convertTriToFan(GeometryInfo geom, int[] oldStripCounts)
           
private  void convertTriToQuad(GeometryInfo geom)
           
private  void convertTriToStrip(GeometryInfo geom, int[] oldStripCounts)
           
private  int createHardEdges()
           
 void generateNormals(GeometryInfo geom)
          Generate normals for the GeometryInfo object.
 double getCreaseAngle()
          Returns the current value of the crease angle, in radians.
 void setCreaseAngle(double radians)
          Set the crease angle.
private  int[] triToFanIndices(int[] sc, int[] oldList, int numVerts)
           
private  int[] triToQuadIndices(int[] oldList)
           
private  int[] triToStripIndices(int[] sc, int[] oldList, int numVerts)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

creaseAngle

private double creaseAngle

facetNorms

private Vector3f[] facetNorms

tally

private java.util.ArrayList tally

gi

private GeometryInfo gi

coordInds

private int[] coordInds

normalInds

private int[] normalInds

colorInds

private int[] colorInds

texInds

private int[][] texInds

stripCounts

private int[] stripCounts

t1

private static long t1

t2

private static long t2

t3

private static long t3

t4

private static long t4

t5

private static long t5

t6

private static long t6

tr

private Triangulator tr

numTexSets

private int numTexSets

DEBUG

private static final int DEBUG
See Also:
Constant Field Values
Constructor Detail

NormalGenerator

public NormalGenerator(double radians)
Constructor. Construct a NormalGenerator object with creaseAngle set to the given value.


NormalGenerator

public NormalGenerator()
Constructor. Construct a NormalGenerator object with creaseAngle set to 44 degrees (0.767944871 radians).

Method Detail

calculatefacetNorms

private void calculatefacetNorms()

createHardEdges

private int createHardEdges()

calculateVertexNormals

private void calculateVertexNormals(int maxShare)

triToQuadIndices

private int[] triToQuadIndices(int[] oldList)

convertTriToQuad

private void convertTriToQuad(GeometryInfo geom)

triToFanIndices

private int[] triToFanIndices(int[] sc,
                              int[] oldList,
                              int numVerts)

convertTriToFan

private void convertTriToFan(GeometryInfo geom,
                             int[] oldStripCounts)

triToStripIndices

private int[] triToStripIndices(int[] sc,
                                int[] oldList,
                                int numVerts)

convertTriToStrip

private void convertTriToStrip(GeometryInfo geom,
                               int[] oldStripCounts)

convertBackToOldPrim

void convertBackToOldPrim(GeometryInfo geom,
                          int oldPrim,
                          int[] oldStripCounts)
Used when the user calls the NormalGenerator and not the Stripifier or Triangulator. We had to convert the user's data to indexed triangles before we could generate normals, so now we need to switch back to the original format.


generateNormals

public void generateNormals(GeometryInfo geom)
Generate normals for the GeometryInfo object. If the GeometryInfo object didn't previously contain indexed data, indexes are made by collapsing identical positions into a single index. Any normal information previously contained in the GeometryInfo object is lost. Strips and Fans are converted into individual triangles for Normal generation, but are stitched back together if GeometryInfo.getGeometryArray() (or getIndexedGeometryArray()) is called without stripifying first.


setCreaseAngle

public void setCreaseAngle(double radians)
Set the crease angle. If two triangles' normals differ by more than creaseAngle, then the vertex will get two separate normals, creating a discontinuous crease in the model. This is perfect for the edge of a table or the corner of a cube, for instance. Clamped to 0 <= creaseAngle <= PI. Optimizations are made for creaseAngle == 0 (facet normals) and creaseAngle == PI (smooth shading).


getCreaseAngle

public double getCreaseAngle()
Returns the current value of the crease angle, in radians.



Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.