I'm not sure how far you've investigated so far, nor what your end goal is exactly so I'll give you some pointers and we can go from there.
Firstly, as far as I'm aware intersection points are all you an get out of Java3D collision, and in fact most (all?) physics colliders. I don't recall anything handing a line equation back as a result ( presumably in some sort of z = mx+ny + c style vector3f).
The com.sun.j3d.utils.pickfast.PickTool from j3dutils project will return PickResult out of any scene branch for a given ray, cone, cylinder or segment, but NOT shape.
So although this is a start it probably isn't what you need without extension.
It does show how the BranchGroups have utility methods for picking that end up using the PickInfo methods for picking and eventually arrive at the various intersect* methods of GeometryArrayRetained which is exactly the sort of intersection code you want.
However because you can't add new PickShapes the only way to use this for geometry/geometry would be to build a bounding polytope shape from one of your geometries.
So if you are examining a single geometry versus the rest of your scene graph this is probably a fine way to do it. If you want a general purpose all geometries against each other, you'd need to use the collision behaviors then for each wake up do a more detailed PickResult via a bounding polytope for one of them.
Note for any of the above you need to set the java3d picking system to use GEOMETRY not BOUNDS and set the various capabilities on each Node, which is easiest to do using the J3dUtils PickTool.setCapabilities() method.
Finally, in my code I mainly want mouse picking from the Canvas3D so I use the com.sun.j3d.utils.pickfast package which does the job very well.
For general physics-like work I use the excellent JBullet http://jbullet.advel.cz/ which is really very good, but might be a large hammer if all you want is intersection data.
Hope this gives you some pointers, please have a look at the various areas I mentioned then get back to us with more detail on what you need done.
Thanks for the detailed reply Phil.
What I'm trying to do is to find the intersection line/curve between two mesh and draw them.
So I don't need the equation of the line, a series of intersection points will do fine.
The J3D collision behavior, does it detect collision based on bounding boxes or exact geometry? If all it does is use bounding boxes then it's useless to me because my meshes are near each other so their bounds are always in collision.
I think I will use the PickTool as you suggested, the pickSegment in particular. I can convert a triangle mesh into 3 line segments, then use pickSegment to check if at least 2 of those line segments intersect with another mesh. If so, draw a line between those 2 intersection points. It won't be perfect, but probably sufficient.
Now I have to decide if I should use PickTool at all. It might be faster if I implement my own lineSegment+Triangle check code because j3D because PickTool does a whole bunch of extra things that I don't need such as: sub-primitive picked (that is, the point, line, triangle or quad), the closest vertex to the center of the pick shape, and the intersection's normal, color and texture coordinates.
Also PickTool seem to require ALLOW_GEOMETRY_READ, ALLOW_FORMAT_READ, ALLOW_COUNT_READ, and ALLOW_COORDINATE_READ plus the ALLOW_COORDINATE_INDEX_READ. All these would be not necessary in my own implementation since I already have access to coordinates array and I wonder if these capabilities would slow down rendering.
The collision behavior can be set to USE_GEOMETRY using the speedHint, which as you say is the only useful options, the bounds are almost always to course too be wanted.
I agree the PickTool does more than you need, and if you want to run a bunch of collision it probably won't be maximum speed.
If you do do your own intersection code, don't forget to run a gross comparison using the bounds first then the fine grain using the geometry data.
If you are using 1.6 then you don't need to set the *_READ capabilities as at some point in Java3D's history a default read capabilities got shoved in, possibly just as it was being made open source, so most read capabilites are turned on by default. This has killed the biggest advantage of a retained mode scene graph, the compilation of branches. So turning them on will have no impact on performance. In 1.7 where this is a flag to not use them by default, in cases where scene graphs are simple you can get amazing performance improvements. But that's not relevant here.
This has killed the biggest advantage of a retained
mode scene graph, the compilation of branches. So turning them on will have
no impact on performance. In 1.7 where this is a flag to not use them by
default, in cases where scene graphs are simple you can get amazing
performance improvements. But that's not relevant here.
I always wondered how the meshes are retained differently based on these flags and exactly what improvements are achieved by using them. Can you point me to any documentation that explains various retained mode optimizations? Do you have any benchmark testing results that show the magnitude of improvements?
But it basically automatically bakes in transformations and merges geometries into big fat geometries that share attributes.
For a fairly complex scenegraph like you might get in a game it can make a huge difference. My Morrowind port went from 1fps to about 6fps once I got compilation going, for a complex scene.
Running on a slow RT like AndroidRT it makes more difference than a good JIT like the sun JRE.
However I haven't actually spent time to get a repeatable and consistent benchmark out for it.