Skip to main content

Reset GeometryInfo in Shape3D without saving and reloading .obj ..

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
jiapei100
Offline
Joined: 2006-12-04

Hi, all:

This could be a silly question but I really need a help.... Urgent help please...

1) First, I'm able to load .obj file successfully. For instance, the current loaded .obj file "a.obj" looks like:

Quote:

v ... ... ...
v ... ... ...
............
vt ... ... ...
vt ... ... ...
............
f ... ... ...
f ... ... ...
............

In order to display "a.obj" on the screen, I have to load this "a.obj" by using
<br />
int flags = ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY | ObjectFile.RESIZE;<br />
ObjectFile f = new ObjectFile(flags, (float)(creaseAngle * Math.PI / 180.0));<br />
Scene s = f.load("a.obj");  // Exception is ignored here by me<br />
BranchGroup bg = s.getSceneGroup();<br />
Shape3D obj3d = (Shape3D)bg.getChild(0);<br />

Whenever I updated the values of "v" (let's just call it "updated-v"), I saved the data into another .obj file "b.obj".
(Note, values of "vt" and "f" are unchanged. )
In order to display it on the screen, I have to reload this "b.obj" by using

<br />
int flags = ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY | ObjectFile.RESIZE;<br />
ObjectFile f = new ObjectFile(flags, (float)(creaseAngle * Math.PI / 180.0));<br />
Scene s = f.load("b.obj");

again, which I think is a very silly way.
Because to save the data onto the hard-drive and reload the data from the hard-drive into the memory is very very time-consuming.

2) I'm guessing that I should be able to assign the "updated-v" values directly into the already-loaded Shape3D "obj3d".
Therefore, I tried the following:

GeometryArray ga = (GeometryArray)obj3d.getGeometry();<br />
GeometryInfo gi = new GeometryInfo( ga );<br />
gi.setCoordinates("updated-v");<br />
obj3d.setGeometry(gi.getGeometryArray());

However, there is something displayed, but the scaling is wrong, and the shape and texture is not what I expected.

I re-iterate it once again.
a) If I save "updated-v" into the "b.obj" directly and reload "b.obj", I can display the object correctly, with correct Shape3D, but this is too time-consuming.
b) If I just use the above 4 lines of codes as shown in 2), the object is displayed wrongly, wrong Shape3D for sure, and wrong scaling. Wrong displaying texture is probably due to the wrong Shape3D.

Can anybody please give me a hand on my difficulty?

Best Regards
JIA