Guillaume,
I'm not familiar with the loader but you should be able to set the bits if
you can 'climb down the tree'. Before the objects are added to the scene
you are allowed to change the capabilities. If the loader gives you a
BranchGroup you add to the scene or if you provide one as a 'root' node
then you can do this. Just don't add the BranchGroup to the scene (give it
a parent that is live or add it to a locale) until you've called this
method on it.
void makeIntersectableRecursive(Node node)
{
if(node instanceof Shape3D) {
Shape3D shape = (Shape3D)node;
shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
shape.getGeometry().setCapability(Geometry.ALLOW_INTERSECT);
}
if(node instanceof Group) {
Group parent = (Group)node;
parent.setCapability(Group.ALLOW_CHILDREN_READ);
for(int i=0;i<parent.numChildren();i++)
makeIntersectableRecursive(parent.getChild(i));
}
}
At 04:33 PM 3/9/99 -0500, Guillaume Bilodeau wrote:
>Hi,
>
> This is all very nice, but there's an element that makes my problem
particular
>and harder to solve: all the objects are loaded from a VRML file using a
VRML97
>loader. All the Shape3D's geometry objects don't have the ALLOW_INTERSECT
>capability bit set (and it seems that I can't set it), so none will report a
>pick using geometry.
>
> If I were creating the objects and adding them to the universe
"manually", all
>your solutions would be perfect. Unfortunately... :)
>
>
>> Great! I had overlooked the Shape3D.intersect method. This is the key!
>> Once you have the picked Shape3D just intersect a ray generated from the
>> mouse x,y with the shape, which gives you the distance. Use the ray origin
>> and vector scaled by this distance. This makes it very easy...
>>
>> Shape3D pick(Canvas3D canvas, BranchGroup rootBranchGroup, int x, int y,
>> Point3d pickedPoint)
>> {
>> PickObject po = new PickObject(canvas, rootBranchGroup);
>> SceneGraphPath sgp = po.pickClosest(x, y, PickObject.USE_GEOMETRY);
>> if(sgp!=null) {
>> PickRay ray = (PickRay)po.generatePickRay(x,y);
>> double distance[] = new double[1];
>> Vector3d rayvect = new Vector3d();
>> for( int i=sgp.nodeCount()-1 ; i>=0 ; i-- ) {
>> if(sgp.getNode(i) instanceof Shape3D) {
>> Shape3D pickedShape = (Shape3D)sgp.getNode(i);
>> if(pickedShape.intersect(sgp, ray, distance)) {
>> ray.get(pickedPoint, rayvect);
>> rayvect.scale(distance[0]);
>> pickedPoint.add(rayvect);
>> return pickedShape;
>> }
>> }
>> }
>> }
>> return null;
>> }
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/