Skip to main content

GeometryInfo getCoordinates() vs. setCoordinates() ?

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2006-12-04

Hi, all:

Sorry for my stupid question but I've got to ask all of you a question...
I debugged into ObjectFile.class and try to understand how to use setCoordinates() and getCoordinates()...

After loading a 3D object from the file "a.obj", the debug information at the following line in file ObjectFile.class tells that
coordArray is of length 75,972

However, after "a.obj" has been loaded into a Scene "s" and I just use the following lines of code

BranchGroup bg = s.getSceneGroup();<br />
Shape3D obj3d = (Shape3D)bg.getChild(0);<br />
GeometryArray ga = (GeometryArray)obj3d.getGeometry();<br />
GeometryInfo gi = new GeometryInfo( ga );<br />
Point3f[] myCoordArray = gi.getCoordinates();

The length of myCoordArray is 183,947 .

It's strange that getCoordinates() and setCoordinates() of GeometryInfo are not a pair ?? Am I right?
Furthermore, how to update the coordinates (in .obj file, the "v" lines) in a Shape3D ?
I mean, if I loaded a .obj file, setCoordinates() will load 75,972 "v"s.
But, I would like to update these loaded coordinates with another 75,972 coordinates.
I thought I could make it just by another setCoordinates() of GeometryInfo, however, the loaded object displays wrongly.
Then, I tested why it's wrong by getCoordinates().
I found, although the original setCoordinates() only affords 75,972 coordinates,
after loading the object, getCoordinates() informs 183,947 coordinates.

Where am I wrong? And How to update those coordinates?

Thanks very much.

Best Regards

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-06-07


- '.obj-files' represent indexed geometry data.
- ObjectFile loader fills a GeometryInfo with the read vertices data and indices.
- GeometryInfo generates normals if needed and stripifies the data if desired.
- Finally non-indexed, referenced, and interleaved geometry data (TriangleArray or TriangleStripArray) will be created by calling 'gi.getGeometryArray(true, true, false)' which is used to build the returned Shape3D.
- "Where am I wrong?" : You compare the length of indexed (75,972) with non-indexed (183,947) coordinates. Non-indexed data arrays have a lot of redundant values, indexed don't.
- "How to update those coordinates?" : Give following code a try (not tested) and be careful concerning the type and length of your coords: float[] or Point3f[].

 BranchGroup bg = s.getSceneGroup();<br />
Shape3D obj3d = (Shape3D)bg.getChild(0);<br />
GeometryArray ga = (GeometryArray)obj3d.getGeometry();<br />
// Convert back into indexed geometry data<br />
GeometryInfo gi = new GeometryInfo(ga);<br />
gi.convertToIndexedTriangles();<br />
gi.setCoordinates(myOtherIndexedCoords);<br />
// Normal generation needed?<br />
// Retrieve the geometry data (choose: non-/indexed, byCopy/Ref, interleaved etc.)<br />
IndexedGeometryArray indexedGA = gi.getIndexedGeometryArray();<br />
Shape3D myOtherObj3d = new Shape3D(indexedGA, new Appearance());<br />

All details can be found in the GeometryInfo javadoc.