Login  Register

Re: how to transform objects not using Transform3D

Posted by philjord on Jul 26, 2022; 12:31pm
URL: https://forum.jogamp.org/how-to-transform-objects-not-using-Transform3D-tp4041515p4041799.html

Hi,
Yes it certainly took me a very long time of playing and experimenting to get a good handle on how by ref geometry updating should work.

It be honest Java3D is really aimed at being a high level scene graph so it's engineered to want user to use teh nodes of teh graph to work with 3d object renderering, so for example it would like a TransformGroup above a Shape3D to modify an object, rather than the geometry itself being modified. However OpenGL and other 3D driver want to be as bare bones as possible, nothing extra at all, everything in long linear buffers of bytes, all modified in place by Matrix maths.

But of course anyone with a fun 3D model has it full of morphing vertices to shows cool animations of sword fighting and cloth simulations, so obviously updateData and ByRef geometries are wanted.


>>> as all the lines get displayed properly regardless of how
This is because 3D driver don't really care about lines at all, and lines get drawn very badly with wildly different mechanism in all cases.
If you want visible surface determination and depth (z buffering) to work you need to render triangles.
So to that end you need to swap from LineArray to IndexedTriangleArray. The reason for indexed Triangle array is that each Tri you render shares vertices with many other triangles, so it's easiest to give in the same set of coords like you are now but also a list of indices to tell it the order of faces to build. each 3 indices represent 3 verts to turn into one tri, from your list of coords. Note that the triangle winding determine front facing so the indices are in an unexpected order.


>>>but couldn't find any methods for multiplying a Quat4f with a Matrix4f
The Trasnform3D object handles all of this for you, it encapsulate s affine transformation matrix and does all the work, so a Quat4f times a translation would be

Transform3D t1 = new Transform3D();
t1.set(new Vector3f(1,2,3));
Transform3D t2 = new Transform3D();
t2.set(new Quat4f(0,0,0,1));
t1.mul(t2);

then use t2 via transform(Point3f)


>>>I see that Text2D has 'setString' method,
Yes, this is the right thing to do, madly 3D drivers don't ever let you mix the 2D paint operations, they want all on screen render elements to be actual literal textures applied to geometries, so every 3D interface you've ever seen in a game is just a carefully draw texture of the correct font strings on a billboard quad at just the right distance form the camera to make it work. Possibly these days with programmable shaders they've got a better approach, but I'm not aware of it.

This example might help
https://github.com/philjord/java3d-examples/tree/master/src/main/java/org/jdesktop/j3d/examples/overlay2d


>>>Why does the following code change all three cubes and not only cube_one?
Because the updateData call is guaranteed to be called back later on the correct Thread (in this case the Java3D renderer thread) at a time when it is allowable to modify the geometry data (between rendering of frames).
As it happens the thread that's correct and the time that's correct is exactly the same for all 3 GeometryArrays because they are all compiled and running against the same Universe3D. It unlikely that you've have a lot of different Universe3D but if you did you'd probably want to update each Geometry in it's own callback.


I've run out of time tonight but here is the file with the points used to build triangles.
I've added add color info to these it make it easier to see whats what

notusingtransform3D.java