this was really great-  wanna thank you....
Peter.

Sivaram Ghorakavi wrote:

> Hi Peter,
>
> Here is a snippet of the code which I've done on VRML
> models.
>
> If u are using on any shapes that has setUserData()
> then getUserData() on the spahe assuming this is URL
> and use the applet context to load the link in new
> browser or in the instance of the browser.
>
> Add the instance of this PickURL class to the root
> and you are set...
>
> Best of Luck
> Sivaram.
>
> --- peter <[EMAIL PROTECTED]> wrote:
> > Hi,
> > could anybody help with this...I am trying to
> > associate
> > URL links with objects - say clicking on famous
> > ColorCube :)
> > to open new link. And one step further I'd like to
> > associate
> > one link for each face of the cube - if somebody's
> > done it
> > already I would appreciate a hint - small chunk of
> > code would
> > also be helpful....
> > thank you
> > Peter.
> >
> >
> ===========================================================================
> > 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".
> >
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com
>
>   ------------------------------------------------------------------------
> package cyberworld.helper;
>
> // Import needed Java classes.
> import java.applet.*;
> import java.net.URL;
> import java.util.*;
> import java.lang.reflect.*;
>
> // Import the Java 3D API.
> import javax.media.j3d.*;
>
> // Import the needed Java 3D utility classes.
> import com.sun.j3d.utils.behaviors.picking.*;
> import com.sun.j3d.utils.geometry.*;
>
> import com.sun.j3d.loaders.vrml97.impl.*;
>
> /**
>  * PickURL is used to associate an object that has been picked on
>  * a scene with a URL link.
>  *
>  */
> public class PickURL extends PickMouseBehavior
> {
>     protected AppletContext appletContext;
>     protected PickObject pickObject = null;
>
>         protected String urlString = null;
>         protected URL gotoURL = null;
>
>     /**
>      * Creates the PickURL object.
>      *
>      * @param canvas The drawing surface for this applet.
>      * @param root The root of the scenegraph in which picking is
>      *  to occur.
>      * @param bounds The schedule bounding region for this behavior.
>      *
>      */
>     public PickURL( Canvas3D canvas,
>                     BranchGroup root,
>                     Bounds bounds,
>                     AppletContext context )
>         {
>         // Pass needed info to parent.
>         super(canvas, root, bounds);
>
>         pickObject = new PickObject( canvas, root );
>
>                 setCapability( ALLOW_PICKABLE_READ |
>                                            ALLOW_PICKABLE_WRITE |
>                                            ALLOW_BOUNDS_READ |
>                                            ALLOW_BOUNDS_WRITE );
>
>         // Pass URL information
>         appletContext = context;
>     }
>
>     /**
>      * Callback called when a pick event has been detected.
>      * The specific Switch node child is determined and its URL.
>      *
>      * @param xPos Current mouse X position.
>      * @param yPos Current mouse Y position.
>      */
>     public void updateScene(int xPos, int yPos)
>     {
>         Logger.log("PickURL coordinates: x = "+xPos+", y = "+yPos);
>
>         // will set any urlString at this position
>         mouseClicked( xPos, yPos );
>         if ( urlString != null )
>         {
>                 try{
>                         gotoURL = new URL( urlString );
>                 }
>                 catch( Exception e ){
>                         Logger.log( e );
>                         gotoURL = null;
>                 }
>         }
>         if ( gotoURL != null )
>         {
>                     // Cause the browser to load the referenced URL
>                     // This applet only has a single URL passed, but could
>                     // support an entire list that is associated with
>                     // the Java 3D object picked.
>                     if (gotoURL != null)
>                        appletContext.showDocument(gotoURL,"_blank");
>         }
>     }
>     private void mouseClicked(int xPos, int yPos)
>         {
>                 javax.media.j3d.Node node = null;
>                 Object vs = null;
>                 Vector sv = (Vector)null;
>
>                 urlString = null;
>                 gotoURL = null;
>
>                 vs = null;
>                 sv = null;
>                 node = null;
>                 SceneGraphPath path = 
>pickObject.pickClosest(xPos,yPos,PickObject.USE_BOUNDS);
>             if ( path != null )
>             {
>                 for ( int i = 0; i < path.nodeCount(); i++ )
>                 {
>                         // Logger.log("Object index = "+i);
>                         node = path.getNode(i);
>                             Object o = node.getUserData();
>                             // Logger.log("User Data = "+o);
>                             if( o instanceof Vector && !((Vector)o).isEmpty() )
>                             {
>                                         // save the bottom most to preserve nesting
>                                         // note, the userData should be a vector
>                                         // of sensors for this group.
>                                         sv = (Vector)o;
>                                     // rare case
>                             }
>                             else if ( o instanceof SphereSensor )
>                             {
>                                         sv = new Vector();
>                                         sv.addElement(o);
>                                         node.setUserData(sv);
>                         }
>                 }
>                 if ( sv != null )
>                 {
>                             Enumeration e = sv.elements();
>                             while( e.hasMoreElements() )
>                             {
>                                 vs = (Object)e.nextElement();
>                                     if (vs instanceof Anchor)
>                                     {
>                                         MFString mfURL = 
>(MFString)(((Anchor)vs).getField("url"));
>                                         if ( mfURL != null )
>                                         {
>                                                 urlString = mfURL.get1Value(0);
>                                             Logger.log("URL = "+urlString);
>                                         }
>                                 }
>                             }
>                 }
>                 }
>
>                 /*****
>             path = pickObject.pickAllSorted( xPos, yPos );
>             if ( path != null )
>             {
>                 // Logger.log("SceneGraphPath.length = "+path.length);
>                 for ( int i = 0; i < path.length; i++ )
>                 {
>                                 vs = null;
>                                 sv = null;
>                                 node = null;
>
>                         // Logger.log("Picked Object = "+path[i]);
>                         for ( int j = 0; j < path[i].nodeCount(); j++ )
>                     {
>                         // Logger.log("Object index = "+i);
>                         node = path[i].getNode(j);
>                                     Object o = node.getUserData();
>                                     // Logger.log("User Data = "+o);
>                                     if( o instanceof Vector && 
>!((Vector)o).isEmpty() )
>                                     {
>                                                 // save the bottom most to preserve 
>nesting
>                                                 // note, the userData should be a 
>vector
>                                                 // of sensors for this group.
>                                                 sv = (Vector)o;
>                                             // rare case
>                                     }
>                                     else if ( o instanceof SphereSensor )
>                                     {
>                                                 sv = new Vector();
>                                                 sv.addElement(o);
>                                                 node.setUserData(sv);
>                                 }
>                     }
>                 }
>
>                 if ( sv != null )
>                 {
>                             Enumeration e = sv.elements();
>                             while( e.hasMoreElements() )
>                             {
>                                 vs = (Object)e.nextElement();
>                                     if (vs instanceof Anchor)
>                                     {
>                                         MFString mfURL = 
>(MFString)(((Anchor)vs).getField("url"));
>                                         if ( mfURL != null )
>                                         {
>                                                 urlString = mfURL.get1Value(0);
>                                             Logger.log("URL = "+urlString);
>                                         }
>                                 }
>                             }
>                 }
>             }
>             *****/
>         }
> }

===========================================================================
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