Hi Joaquin,

   Try

(1) Use Java3D v1.2.1 or later if you are using v1.2
(2) pickCanvas.setMode(PickCanvas.GEOMETRY);
(3) pickCanvas.setTolerance(0);

See attach email from archive.

- Kelvin
-------------
Java 3D Team
Sun Microsystems Inc.
   
>X-Unix-From: [EMAIL PROTECTED]  Thu Apr 26 09:12:04 2001
>X-Accept-Language: en
>MIME-Version: 1.0
>Content-Transfer-Encoding: 8bit
>Date: Thu, 26 Apr 2001 17:51:29 +0200
>From: Joaquin Casillas Melendez <[EMAIL PROTECTED]>
>Subject: [JAVA3D] Picking order
>To: [EMAIL PROTECTED]
>
>Hello.
>
>I'm new to Java3D and I'm trying to do some stuff with picking
>mechanism. I've extended the MouseBehaviorApp example in order to add
>picking capabilities. I have two cubes with picking enabled, and when a
>cube is picked, it renders in wireframe mode. I've extended the
>PickMouseBehavior class. The updateScene method is like this:
>
> public void updateScene(int xpos, int ypos) {
>        PickResult pickResult[], pickNode;
>        Shape3D shape = null, theShape = null;
>
>        pickCanvas.setShapeLocation(xpos, ypos);
>
>        pickResult = pickCanvas.pickAllSorted();
>        if (pickResult != null) {
>            for(int i=0; i<pickResult.length; i++) {
>                pickNode = pickResult[i];
>                shape = (Shape3D) pickNode.getNode(pickNode.SHAPE3D);
>                if(shape!=null) {
>                    String name = (String) shape.getUserData();
>                    System.out.println("Picked " + name);
>                    if(i==0)
>                        theShape = shape;
>                }
>            }
>        }
>
>        if (oldShape != null){
>            oldShape.setAppearance(savedAppearance);
>        }
>        if (theShape != null) {
>            savedAppearance = theShape.getAppearance();
>            oldShape = theShape;
>            theShape.setAppearance(highlightAppearance);
>        }
>    }
>
>   When a cube is behind the other (always the same cube and partially
>showed) and you pick the nearest cube is the furthest cube which is
>selected. I've tried to browse search the mail archive but I can't
>establish a connection. Sorry for posting to the list before taking a
>look to the archives.
>
>Does anybody know the reason of this behaviour?
>
>Any help would be appreciated.
>
>Thanx.
>
>--
>-------------------------------------------------------------------------
>Joaqu�n Casillas Mel�ndez(Quino), R+D Engineer at iSOCO
>Intelligent Software Components, S.A. http://www.isoco.com
>Addr. iSOCOVal: Profesor Beltr�n B�guena, 4, oficina 305, 46009 Valencia
>Voice: +34 96 346 71 43 Fax: +34 96 348 28 94
>                                                        Powered by Linux!
>
>===========================================================================
>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".


Delete.
This is a system message.















--END+PSEUDO--

>From tlchung@ha3mpk  Fri Jun 23 18:32:58 2000
Date: Fri, 23 Jun 2000 18:32:58 -0700 (PDT)
From: Kelvin Chung <tlchung@ha3mpk>
Subject: Re: [JAVA3D] Detecting the Picked Face of a Box ( bug? )
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
X-Mailer: dtmail 1.3.0 @(#)CDE Version 1.3.4p_5 SunOS 5.7 sun4u sparc
Mime-Version: 1.0
Content-Type: MULTIPART/mixed; BOUNDARY=Seige_of_Cranes_166_000
Content-Length: 8505
Status: RO
X-Status: $$$$
X-UID: 0000000001

--Seige_of_Cranes_166_000
Content-Type: TEXT/plain; charset=ISO-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-MD5: CTY4RisQje4qplosq+Ckrg==

Hi Victor,

     By default, pickCanvas used Shape Bounds for intersect so
it is not accurate. You should use

      pickCanvas.setMode(PickCanvas.GEOMETRY);
     =20
However there is a bug in the utility that when pickshape
other than pickRay is used (default is PickConeRay).=20

In PickTool.java=20

 private PickResult[] pickGeomAllSorted (PickShape pickShape)=20

will not try to compute the distance between pickShape and
the picked object. (bug 4347998 is filed for this).
To force the utilize use PickRay we must set tolerance to 0.

 pickCanvas.setTolerance(0);

However there is another bug that we must put this call before,

     pickCanvas.setShapeLocation(e);

(bug  4347996 is filed for this)


Attached is an example modify from your program to make this works.
Notice that when you rotate the Box to the other side,=20
you may select the BACK face instead of FRONT face because
BACK/FRONT/TOP ... is just a name for the six face of Box.

Thanks for your bug report.

- Kelvin
--------------
Java 3D Team=20
Sun Microsystems Inc.


   =20
>X-Unix-From: [EMAIL PROTECTED]  Fri Jun 23 00:48:30 2000
>X-Accept-Language: es,en
>MIME-Version: 1.0
>Date: Fri, 23 Jun 2000 09:46:04 +0200
>From: V=EDctor <[EMAIL PROTECTED]>
>Subject: Re: [JAVA3D] Detecting the Picked Face of a Box ( bug? )
>To: [EMAIL PROTECTED]
>
>We are trying detect face of a box. An example is attached.
>
>The example consist of an applet where the scenegraph is only a box.
>Clicks on canvas are captured and then we compare the shape3D returned
>with the different faces of the box, but wrong identification is done.
>
>Best Grettings.
>
>Kelvin Chung wrote:
>
>> Hi,
>>
>>    Can you please send a test case to us ?
>>
>> We'll take a look into this.
>>
>> Thanks.
>>
>> - Kelvin
>>
>> ---------
>> Java 3D Team
>> Sun Microsystems Inc.
>>
>> >X-Unix-From: [EMAIL PROTECTED]  Fri Jun 16 04:16:19 2000
>> >X-Accept-Language: es,en
>> >MIME-Version: 1.0
>> >Content-Transfer-Encoding: 7bit
>> >Date: Fri, 16 Jun 2000 13:15:17 +0200
>> >From: V=EDctor <[EMAIL PROTECTED]>
>> >Subject: [JAVA3D] Detecting the Picked Face of a Box ( bug? )
>> >To: [EMAIL PROTECTED]
>> >
>> >Hi all:
>> >
>> >We are trying to detect the selected face of a box by using PickCanvas
>> >and
>> >PickResult. But getNode(PickResult.SHAPE3D) return wrong information. I=
t
>> >
>> >return BACK face when FRONT was expected.
>> >
>> >Is this a bug?
>> >
>> >How can we detect selected face box?
>> >
>> >  PRISMAKER TEAM
>> >
>> >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
>> >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".
>>
>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
>> To unsubscribe, send email to [EMAIL PROTECTED] and include in the b=
ody
>> of the message "signoff JAVA3D-INTEREST".  For general help, send email =
to
>> [EMAIL PROTECTED] and include in the body of the message "help".

--Seige_of_Cranes_166_000
Content-Type: TEXT/plain; name="PickClosestBug.java"; charset=us-ascii; 
x-unix-mode=0644
Content-Description: PickClosestBug.java
Content-MD5: LFYE8IVOXx19f/fSDiCWtQ==

import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.PickShape;
import com.sun.j3d.utils.picking.PickResult;
import com.sun.j3d.utils.picking.PickCanvas;
import javax.vecmath.*;
import java.util.Enumeration;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.applet.MainFrame;
import java.applet.*;
import java.awt.event.MouseEvent;
import com.sun.j3d.utils.picking.behaviors.*;


public class PickClosestBug extends Applet  {

  BorderLayout borderLayout1 = new BorderLayout();
  private SimpleUniverse u;

  public PickClosestBug() {
    this.setLayout(borderLayout1);
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D c = new Canvas3D(config);
    c.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        canvas_mouseClicked(e);
      }
    });
    add("Center", c);
    u = new SimpleUniverse(c);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(createSceneGraph(c));
  }


  public BranchGroup createSceneGraph(Canvas3D canvas){
    TransformGroup objScale;
    BranchGroup objRoot1;
    TransformGroup objr;

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    BranchGroup objRoot = new BranchGroup();
    objRoot.setCapability(objRoot.ALLOW_CHILDREN_READ);
    objRoot.setCapability(objRoot.ALLOW_CHILDREN_EXTEND);
    objRoot.setCapability(objRoot.ALLOW_DETACH);
    objRoot.setCapability(objRoot.ENABLE_PICK_REPORTING);

    objScale = new TransformGroup();
    objScale.setCapability(objScale.ALLOW_CHILDREN_READ);
    objScale.setCapability(objScale.ALLOW_CHILDREN_EXTEND);
    objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.2);
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    Color3f eColor    = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor    = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f objColor  = new Color3f(0.4f, 0.1f, 0.4f);
    Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Box box = new Box(1.4f, 1.4f, 1.4f,
                      Primitive.ENABLE_GEOMETRY_PICKING|Primitive.GENERATE_NORMALS,
                      a, 1);

    Color3f lColor1   = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3d lPos1 =  new Vector3d(2.0, -1.0, -2.0);
    Vector3f lDirect1 = new Vector3f(lPos1);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDirect1);
    lgt1.setInfluencingBounds(bounds);

    Color3f lColor2   = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3d lPos2 =  new Vector3d(-2.0, 1.0, 2.0);
    Vector3f lDirect2 = new Vector3f(lPos2);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDirect2);
    lgt2.setInfluencingBounds(bounds);

    objScale.addChild(box);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    PickTranslateBehavior p1 = new PickTranslateBehavior(objRoot, canvas, bounds);
    objRoot.addChild(p1);

    PickRotateBehavior p2 = new PickRotateBehavior(objRoot, canvas, bounds);
    objRoot.addChild(p2);

    return objRoot;
  }


  void canvas_mouseClicked(MouseEvent e) {
     TransformGroup tg = null;
     Shape3D sh = null;
     Box box = null;

     PickCanvas pickCanvas = new PickCanvas(u.getCanvas(), u.getLocale());
     pickCanvas.setTolerance(0);
     pickCanvas.setShapeLocation(e);
     pickCanvas.setMode(PickCanvas.GEOMETRY);
     PickResult pr = pickCanvas.pickClosest();

     if ((pr != null)&&
         ((sh = (Shape3D) pr.getNode(PickResult.SHAPE3D)) != null)&&
         ((box = (Box) pr.getNode(PickResult.PRIMITIVE)) != null)){
             String mensaje = "";
             if (sh.equals(box.getShape(box.FRONT))) mensaje += "FRONT was clicked";
             if (sh.equals(box.getShape(box.BACK))) mensaje += "BACK was clicked";
             if (sh.equals(box.getShape(box.BOTTOM))) mensaje += "BOTTOM was clicked";
             if (sh.equals(box.getShape(box.LEFT))) mensaje += "LEFT was clicked";
             if (sh.equals(box.getShape(box.RIGHT))) mensaje += "RIGHT was clicked";
             if (sh.equals(box.getShape(box.TOP))) mensaje += "TOP was clicked";
             System.out.println(mensaje);
           }
  }

   public static void main(String[] args) {
        new MainFrame(new PickClosestBug(), 300, 256);
   }
}

--Seige_of_Cranes_166_000--



Reply via email to