j3d.org Code

org.j3d.geom
Class GeometryGenerator

java.lang.Object
  extended by org.j3d.geom.GeometryGenerator
Direct Known Subclasses:
BezierGenerator, BoxGenerator, BSplineGenerator, ConeGenerator, CylinderGenerator, ElevationGridGenerator, FractalTerrainGenerator, MobiusGenerator, PatchGenerator, SphereGenerator, SpringGenerator, SuperShapeGenerator, TorusGenerator

public abstract class GeometryGenerator
extends java.lang.Object

Abstract base representation of geometry generator of box raw coordinate and geometry normals.

Curved surfaces would like to generate a smooth object most of the time. To do this, the normal values at each vertex are made to smooth the values for each set of faces that use that value (ie the effect is averaged between all the sharing faces). The typical approach to do this is to work with a value called creaseAngle. If the angle between two surfaces is less that the creaseAngle, a smoothed normal is generated. If greater, the normal is perpendicular to the face. If we are playing with different numbers of facets in an object, this gets rather annoying at times as some pieces may or may not be faceted. At the same time there is a performance hit for generating the normals as you have to check every face and build a lot of extra data before you start doing normal calculations.

This library takes a much simplified approach - let the geometry generator implementation decide. Our aim is for speed here and if we have to decide in a general fashion for every normal calculation, that could be a huge impact.

Obvious limitations to this are shapes like the cube or a near-degenerate cone that ends up as a pyramid. The smoothing of normals may be there, but no matter how hard you try, the differences between the face angles will just be too great.

Version:
$Revision: 1.6 $
Author:
Justin Couch

Constructor Summary
protected GeometryGenerator()
           
 
Method Summary
protected  javax.vecmath.Vector3f createFaceNormal(float[][] coords, int w, int p, int w1, int p1, int w2, int p2)
          Convenience method to create a normal for the given vertex coordinates and normal array and using a 2D array of coordinate values.
protected  javax.vecmath.Vector3f createFaceNormal(float[] coords, int p, int p1, int p2)
          Convenience method to create a normal for the given vertex coordinates and normal array.
protected  javax.vecmath.Vector3f createRadialNormal(float[] coords, int p)
          Create a normal based on the given vertex position, assuming that it is a point in space, relative to the origin.
protected  javax.vecmath.Vector3f createRadialNormal(float[] coords, int p, float[] origin, int originOffset)
          Create a normal based on the given vertex position, assuming that it is a point in space, relative to the given point.
abstract  void generate(GeometryData data)
          Generate a new set of geometry items based on the passed data.
abstract  int getVertexCount(GeometryData data)
          Get the number of vertices that this generator will create for the shape given in the definition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeometryGenerator

protected GeometryGenerator()
Method Detail

getVertexCount

public abstract int getVertexCount(GeometryData data)
                            throws UnsupportedTypeException
Get the number of vertices that this generator will create for the shape given in the definition.

Parameters:
data - The data to base the calculations on
Returns:
The vertex count for the object
Throws:
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested.

generate

public abstract void generate(GeometryData data)
                       throws UnsupportedTypeException,
                              InvalidArraySizeException
Generate a new set of geometry items based on the passed data. If the data does not contain the right minimum array lengths an exception will be generated. If the array reference is null, this will create arrays of the correct length and assign them to the return value.

Parameters:
data - The data to base the calculations on
Throws:
InvalidArraySizeException - The array is not big enough to contain the requested geometry
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested

createFaceNormal

protected javax.vecmath.Vector3f createFaceNormal(float[] coords,
                                                  int p,
                                                  int p1,
                                                  int p2)
Convenience method to create a normal for the given vertex coordinates and normal array. This performs a cross product of the two vectors described by the middle and two end points.

Parameters:
coords - The coordinate array to read values from
p - The index of the middle point
p1 - The index of the first point
p2 - The index of the second point
Returns:
A temporary value containing the normal value

createFaceNormal

protected javax.vecmath.Vector3f createFaceNormal(float[][] coords,
                                                  int w,
                                                  int p,
                                                  int w1,
                                                  int p1,
                                                  int w2,
                                                  int p2)
Convenience method to create a normal for the given vertex coordinates and normal array and using a 2D array of coordinate values. This performs a cross product of the two vectors described by the middle and two end points.

Parameters:
coords - The coordinate array to read values from
w - The reference into the first array dimension for p
p - The index of the middle point
w1 - The reference into the first array dimension for p1
p1 - The index of the first point
w2 - The reference into the first array dimension for p2
p2 - The index of the second point
Returns:
A temporary value containing the normal value

createRadialNormal

protected javax.vecmath.Vector3f createRadialNormal(float[] coords,
                                                    int p)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the origin. This will create a normal that points directly along the vector from the origin to the point.

Parameters:
coords - The coordinate array to read values from
p - The index of the point to calculate
Returns:
A temporary value containing the normal value

createRadialNormal

protected javax.vecmath.Vector3f createRadialNormal(float[] coords,
                                                    int p,
                                                    float[] origin,
                                                    int originOffset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the given point. This will create a normal that points directly along the vector from the given point to the coordinate.

Parameters:
coords - The coordinate array to read values from
p - The index of the point to calculate
origin - The origin to calculate relative to
originOffset - The offset into the origin array to use
Returns:
A temporary value containing the normal value

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org