> From: Allistair Crossley <[EMAIL PROTECTED]>
>
> I am really puzzled by a problem and would appreciate it if anyone could offer
any help with it.
>
> I create a TransformGroup as shown below and add a series of child
TransformGroups each of which has a Box Primitive as their child.
>
>        TG
>         ||
>       //  \\
>     TG  TG .....
>      ||     ||
>    Box Box
>
> I have used PickHighlightBehavior so that each Box on the rendered screen can
be chosen and highlighted.
>
> Now the logic of my program is such that each Box needs a unique ID. I wish to
be able to retrieve that unique ID (just an integer) when the user picks it.
>
> PickHighlightBehavior only retrieves the Shape3D that was picked and since the
Box class consists of 6 Shape3Ds comprising each face of the Box, I cannot
create a hashtable of Shape3D Boxes to unique ids and then do a match on the
picked with the hashtable.

The utilities create the Box as a TransformGroup with children for each of the
Shape3Ds.  Set the "enable pick reporting" capability on the TransformGroup to
get back the TG in the SceneGraph path for the pick.  Attach your ID by making a
hashtable of the TGs.

Even better, create a subclass of Box which add the id.  You can then cast the
node from the scene graph path to get your class.

        BoxID   yourBox; // this is your Box with ID subclass
        SceneGraphPath sgp; // this is the SGP returned by the pick
        // The SGP lists the chain of nodes from the picked node up the
        // scene graph to the locale where the scene graph is attached,
        // parent nodes along the way are listed in the SGP if they have the
        // allow pick reporting capability set.
        // For a pick on one of your boxes, sgp.nodeCount() will return
        // length of the "chain" of nodes in the SGP.
        // The Shape3D will be at sgp.getNode(sgp.nodeCount()-1), The BoxID will
        // be at sgp.getNode(sgp.nodeCount()-2):
        int nodeCount = sgp.nodeCount();
        if (nodeCount > 2) {
           Node test = sgp.getNode(nodeCount - 2);
           if (test instanceof BoxID) {
               yourBox = (BoxID) test;  // success
           }
        }

I may be off-by-one on my indicies to getNode(), but hopefully you get the idea.

Doug Gehringer
SunMicrosystems

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to