Geometry by reference is a very slick way to have a dynamic object in
Java3d.  Perhaps by OpenGL standards it is not as flexible or as fast, but
it is pretty close.  The only drawback that I have found is that the
geometry is sent to the card every frame without using display lists, even
though technically java3d knows when you have made a change.  (Sun engineers
please correct me if I am wrong).

Basically geometry by reference and GeometryUpdater are different
techniques, although they are often used together.  Geometry by reference is
created by using the BY_REFERENCE flag when you create the GeometryArray.
Then you use the SetXxxxRefType commands (like SetCoordRefFloat) to tell
java3d to use your own array for the data.

Example:

      geom = new QuadArray(count*4,
          GeometryArray.COORDINATES | GeometryArray.BY_REFERENCE |
          GeometryArray.TEXTURE_COORDINATE_2 | GeometryArray.COLOR_4);

      geom.setCoordRefFloat(vertices);
      geom.setTexCoordRefFloat(0,texCoords);
      geom.setColorRefByte(colors);

      geom.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
      geom.setCapability(GeometryArray.ALLOW_COUNT_WRITE);

      geom.setValidVertexCount(0);

In the preceding example we are creating a quad array with a predefined
maximum number of vertices.  This is important because you will not be able
to change the maximum number of vertices easily.  The
geom.setCoordRefFloat() sets the array to be used for the coordinate
vertices to our own array.  This array would need to be 3 times maximum
vertices, since each vertice would have 3 floats in it.  This also holds
true for the other arrays, you need to allocated arrays which are precisely
the correct size to hold the maximum amount of vertices.

You also need to set the capabilities to change the valid vertex count and
to change the data contained in your arrays.  The valid vertex count defines
the maximum number of vertices that will be rendered, up to the maximum
number you specified when you built the geometry array.

You should only make changes to your arrays from within a class that
implements the GeometryUpdater interface.

Example:

public class ParticleSystem implements GeometryUpdater {

    ....lots of code...

   /**
    * External method to force an update of the geometry
    */
    public void updateData() {
        geom.updateData(this);
    }

   public void updateData(Geometry parm) {

      // if this is the first time we are writing a frame, then
      // set the age clock to now.

      if (idle) {
         idle = false;
         m_fTimeLastUpdate = getParticleTime();
      }

      float newTime = getParticleTime();
      if (newTime - m_fTimeLastUpdate == 0) return;

      // update the particle system's internal data

      update(getParticleTime());
      updateGeometry();
      if (debug) System.out.println("Particles = "+m_uParticlesAlive);
   }

}

In the above code snippet, we implement the GeometryUpdator class and write
the method updateData(Geometry parm).  We don't actually call this method
directly, but instead do this:

    public void updateData() {
        geom.updateData(this);
    }

This tells Java3d to update the geometry with the GeometryUpdater provided.
By calling the updateData() method from a behavior, we can cause the
geometry to be updated properly within the Java3d system.

Example behavior:

  public Behavior getUpdateBehavior() {
        Behavior runner = new Behavior()
        {
            WakeupOnElapsedFrames wakeup = new
WakeupOnElapsedFrames(0,false);
            public void initialize()
            {
                wakeupOn(wakeup);
            }

            public void processStimulus(java.util.Enumeration enumeration)
            {
                updateData();
                initialize();
            }
        };
        runner.setSchedulingBounds(new BoundingSphere(new
Point3d(0,0,0),100));
      return runner;
   }

So you can create a self updating Java3d object by creating a branch group
and putting a shape and a behavior into it.  The above behavior will update
the geometry every frame where the viewplatform is within 100 meters of the
center of your auto-upated system.

The code that actually updates the geometry can do so by directly accessing
the arrays you allocated and registered with Java3d.  Make sure you set the
valid vertex count to be equal to the number of vertices you have actually
filled in with data.

Dave Yazel

----- Original Message -----
From: Quoc Huynh <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 24, 2001 2:42 PM
Subject: [JAVA3D] Geometry By Reference


Hi All,

        Could someone explain in better detail than the API tutorial, on how
to
use Geometry by reference, the GeometryUpdater interface. etc...


cheers,


Q.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to