Dear Java3D community,

Recently I had to fight against the getBounds() routine of the Node class
that forced me to implement my own version.

The problem is that I absolutely need the maximum and minimum coordinates
of a loaded VRML object. To load the object I use the Xj3D package taken
from the cvs around the 10 October 2000. If I ask for the bounds of the
loaded object I get a BoundingSphere. Converting the Bounds in an object
with:
Bounds b = object.getBounds() ;
BoundingBox bbox = new BoundingBox(b) ;

is not working good at all because the created box is surrounding not only
the object but also the bounding  sphere itself resulting in a bigger
size.  I understand that it's not possible to know where a bound is coming
from and make the previous piece of code work, I would have implemented it
like this myself :-)
I also understand that there is not reason to prefer the return of a Box
instead of a Sphere for the .getBounds() method; what is best depends on
the shape of the objet.

So I decided to write a deepscan-first-recursive-geometry-analizer
routine to get the coordinates I need.
The function takes as input a node and the results are the "lower" and
"upper" points of the desired BoundingBox.

To make this the routine recursively scan the scenegraph. When a Shape3D
object is found the Geometry is retrieved and analyzed.
To achieve this I use of the "instanceof" method to know
wich subtype of the Geometry class I'm dealing with. Depending from this
type different actions are taken.

Problem 1. If in future releases new Geometry subtypes will be added, the
routine will need to be updated. Are there good reasons to think that
there will _never_ be another Geometry subtype? The obvious answer seems
to be not, but... :-)

Problem 2. I don't know how to deal with the Raster and CompressedGeometry
classes because of lack of knowledge and time. So the routine works god
for my case but is incomplete.


Conclusion. I leave this little piece of code to the community, I guess it
can be nice to put it on j3d.org or something similar. Also maybe someone
might want to finish the routine supporting the Raster and
CompressedGeometry types and share it with the others.


Suggestion: Do you think is it possible with the current design supply
the Node class with a method like "int .getBestBoundingType()" returning
an index of the  bound type returned by .getBounds()?


regards,
Fabrizio Nunnari


--
http://digilander.iol.it/fnunnari

   Fabrizio Nunnari <[EMAIL PROTECTED]>
 -Student at Computer Science Department of Turin (Italy)-
Voodoo Chile of DeGeNeRaTiOn  for the Amiga scene --> Coder

Navidad.exe

Reply via email to