com.sun.j3d.utils.geometry
Class GeomBuffer

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

 class GeomBuffer
extends java.lang.Object

GeomBuffer allows OpenGL-like input of geometry data. It outputs Java 3D geometry array objects. This utility is to simplify porting of OpenGL programs to Java 3D.

Here is a sample code that use this utility to create some quads.

 
     GeomBuffer gbuf = new GeomBuffer(100);
     gbuf.begin(GeomBuffer.QUADS);

     for (int i = 0; i < 5; i++){
       gbuf.normal3d(0.0, 1.0, 0.0);
       gbuf.vertex3d(1.0, 1.0, 0.0);
 
       gbuf.normal3d(0.0, 1.0, 0.0);
       gbuf.vertex3d(0.0, 1.0, 0.0);
 
       gbuf.normal3d(0.0, 1.0, 0.0);
       gbuf.vertex3d(0.0, 0.0, 0.0);
 
       gbuf.normal3d(0.0, 1.0, 0.0);
       gbuf.vertex3d(1.0, 0.0, 0.0);
     }
     gbuf.end();
     Shape3D shape = new Shape3D(gbuf.getGeom(GeomBuffer.GENERATE_NORMALS));
 
Notice, that you only need to specify some upperbound on the number of points you'll use at the beginning (100 in this case).

Currently, you are limited to one primitive type per geom buffer. Future versions will add support for mixed primitive types.


Field Summary
(package private)  int currPrimCnt
           
(package private)  int[] currPrimEndVertex
           
(package private)  int[] currPrimStartVertex
           
(package private)  int[] currPrimType
           
(package private)  int currVertCnt
           
(package private) static int debug
           
private  int flags
           
(package private)  GeometryArray geometry
           
(package private)  Vector3f[] normals
           
(package private)  int numTexUnit
           
(package private)  int numTris
           
(package private)  int numVerts
           
(package private)  Point3f[] pts
           
(package private) static int QUAD_STRIP
           
(package private) static int QUADS
           
(package private)  TexCoord2f[] tcoords
           
(package private)  int[] texCoordSetMap
           
(package private) static int TRIANGLE_FAN
           
(package private) static int TRIANGLE_STRIP
           
(package private) static int TRIANGLES
           
 
Constructor Summary
GeomBuffer(int numVerts)
           
GeomBuffer(int numVerts, int numTexUnit)
          Creates a geometry buffer of given number of vertices
 
Method Summary
(package private)  void begin(int prim)
          Begins a new primitive given the primitive type.
(package private)  void end()
          End of primitive.
(package private)  GeometryArray getComputedGeometry()
          Returns the Java 3D geometry gotten from calling getGeom.
(package private)  GeometryArray getGeom(int format)
           
(package private)  int getNumTris()
           
(package private)  int getNumVerts()
           
(package private)  TexCoord2f[] getTexCoords()
           
(package private)  void normal3d(double x, double y, double z)
           
(package private)  void outVertex(Point3f[] dpts, Vector3f[] dnormals, TexCoord2f[] dtcoords, int dloc, Point3f[] spts, Vector3f[] snormals, TexCoord2f[] stcoords, int sloc)
           
private  GeometryArray processQuads()
           
private  GeometryArray processQuadStrips()
           
private  GeometryArray processTriangleFan()
           
private  GeometryArray processTriangles()
           
(package private)  void texCoord2d(double s, double t)
           
(package private)  void vertex3d(double x, double y, double z)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUAD_STRIP

static final int QUAD_STRIP
See Also:
Constant Field Values

TRIANGLES

static final int TRIANGLES
See Also:
Constant Field Values

QUADS

static final int QUADS
See Also:
Constant Field Values

TRIANGLE_FAN

static final int TRIANGLE_FAN
See Also:
Constant Field Values

TRIANGLE_STRIP

static final int TRIANGLE_STRIP
See Also:
Constant Field Values

flags

private int flags

pts

Point3f[] pts

normals

Vector3f[] normals

tcoords

TexCoord2f[] tcoords

currVertCnt

int currVertCnt

currPrimCnt

int currPrimCnt

currPrimType

int[] currPrimType

currPrimStartVertex

int[] currPrimStartVertex

currPrimEndVertex

int[] currPrimEndVertex

geometry

GeometryArray geometry

numVerts

int numVerts

numTris

int numTris

numTexUnit

int numTexUnit

texCoordSetMap

int[] texCoordSetMap

debug

static final int debug
See Also:
Constant Field Values
Constructor Detail

GeomBuffer

GeomBuffer(int numVerts,
           int numTexUnit)
Creates a geometry buffer of given number of vertices

Parameters:
numVerts - total number of vertices to allocate by this buffer. This is an upper bound estimate.

GeomBuffer

GeomBuffer(int numVerts)
Method Detail

getGeom

GeometryArray getGeom(int format)

begin

void begin(int prim)
Begins a new primitive given the primitive type.

Parameters:
prim - the primitive type (listed above).

end

void end()
End of primitive.


vertex3d

void vertex3d(double x,
              double y,
              double z)

normal3d

void normal3d(double x,
              double y,
              double z)

texCoord2d

void texCoord2d(double s,
                double t)

getTexCoords

TexCoord2f[] getTexCoords()

getComputedGeometry

GeometryArray getComputedGeometry()
Returns the Java 3D geometry gotten from calling getGeom.


getNumTris

int getNumTris()

getNumVerts

int getNumVerts()

processQuadStrips

private GeometryArray processQuadStrips()

processQuads

private GeometryArray processQuads()

processTriangles

private GeometryArray processTriangles()

processTriangleFan

private GeometryArray processTriangleFan()

outVertex

void outVertex(Point3f[] dpts,
               Vector3f[] dnormals,
               TexCoord2f[] dtcoords,
               int dloc,
               Point3f[] spts,
               Vector3f[] snormals,
               TexCoord2f[] stcoords,
               int sloc)


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