Hi John,

>
> Thanks for the very fast reply.  Yes, I am using the Java 3D 1.3
> release.  The shapes are being loaded via our 3DS loader (Starfire
> Research) which reads sets of three vertices to form triangles and puts
> this data into a GeometryInfo(GeometryInfo.TRIANGLE_ARRAY) to generate
> normals and then pulls the geometry out to make the Shape3D via
> getGeometryArray().  If my understanding is correct there should never
> be more than one geometry per Shape3D.
>
So you are using TriangleArray Geometry. Yes, in this case there is
no multiple geometry per Shape3D.

> My guess at what is happening is that the "closest geometry" *is* being
> returned but that geometry/Shape3D does not actually have the closest
> intersection.  Perhaps the code is calculating "closest" based on the
> bounds center of that node?
>

Locale/BranchGroup pickAll() use the Bounds (instead of Geometry)
of Shape3D for picking. So it is possible that this one return
Shape3D that is not actually intersect. It is the utility PickTool
that do a second pass using Shape3D

   public boolean intersect(SceneGraphPath path,
                             PickRay pickRay,
                             double[] dist)

API and the actualy geometry for testing (not the Bounds). This core
API will find all the triangle that intersect with pickRay and
return the smallest one. Note that if dist = null the procedure
return as soon as there is one triangle intersect with pickRay,
otherwise the whole triangle list will be exam (slower.)

You should use the dist return by this procedure which PickTool
is already doing so.


> Since this is part of a rather large world (Pernica) I'm not sure there
> is a reasonable way for me to isolate this further.
>
> I took another look at the API for PickTool.pickClosest() and
> PickResult.  It's a bit confusing as I expect PickTool.pickClosest to
> return a single intersecting but it really returns a PickResult which
> includes multiple intersections. And PickResult.getIntersection(0) is
> NOT necessarily the closest intersection.
>

PickResult actually take into account multiple geometries under
the same Shape3D. So it is possible there are more than one
intersection, one for each geometry. However current multiple
geometry it is not support as mention earlier so PickResult just
return the first index.


> I think the PickTool documentation is confusing when it states "When
> using pickAllSorted or pickClosest methods, the picks will be sorted by
> the distance from the start point of the pick shape to the intersection
> point."  pickClosest does not return a sorted array, it returns a single
> PickResult (which contains many intersections).  And it's my fault for
> assuming the intersections are sorted by distance from the source of the
> pick.

PickClosest() will sort the distance first and return the first index.
Since at the end of pickGeomAllSorted() it actually did

     sortPickResults (npr, distance);

which use quickSort to arrange npr[] from near to far.

>
> From what you wrote it seems you are suggesting I should use "intersect"
> rather than using the picking tools?
>

I think it is a problem of using

  iPoint = pickIntersection.getPointCoordinatesVW();
  iPoint.y

for checking since it is not the same as dist
return by intersect() and use for sorting.

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


> Kelvin Chung wrote:
>
>>Hi John,
>>
>>     I'm assuming that you're using Java3D 1.3 release.
>>Try to check out the PickTool utilities source code
>>(bundle in the distribution) and see why the closest
>>Geometry is not return in your case. Note that there
>>is a limitation of utility PickTool
>>
>>4351579 - APIs issue : Shape3D intersect method -- multiple geometry support
>>
>>Also
>>
>>But if you're not using mutliple geometry in the same shape that's fine.
>>
>>The procedure that return closest distance in PickTool is
>>
>>  private PickResult pickGeomClosest(PickShape pickShape) {
>>        PickResult[] pr = pickGeomAllSorted(pickShape);
>>        if (pr == null) {
>>            return null;
>>        } else {
>>            return pr[0];
>>        }
>>     }
>>
>>where pickGeomAllSorted() will use core API
>>  BranchGroup/Locale pickAll()
>>to get a list of intersecting Shape3D in SceneGraphPath
>>
>>Then use core API Shape3D
>>
>>    public boolean intersect(SceneGraphPath path,
>>                             PickRay pickRay,
>>                             double[] dist)
>>to get the distance for each intersection and
>>return the smallest one.
>>
>>I guess there may be bug in the above API.
>>
>>Please let us know which type of Shape3D (Morph, OrientedShape)
>>and GeometryArray you are using since different combinations will
>>fall into different intersection routine. If you can identify
>>a set of Geometry which intersect() fail to return the correct
>>distance please send us the test case so we can fix it in time
>>for the next release.
>>
>>Thanks.
>>
>>- Kelvin
>>---------------------
>>Java 3D Team
>>Sun Microsystems Inc.
>>
>>John Wright wrote:
>>
>>>This is perhaps a bit of a vague report (and I'm sure Sun would request
>>>sample code), but in reviewing my terrain navigation code (because we
>>>were sometimes "falling through the ground") I noticed that
>>>PickTool.pickClosest doesn't always seem to pick the closest result.
>>>
>>>The documentation states:
>>>  "When using pickAllSorted or pickClosest methods, the picks will be
>>>sorted by the distance from the start point of the pick shape to the
>>>intersection point."
>>>
>>>What defines the "intersection point"?  If I hit a polygon (triangle)
>>>that is "sloped" it does seem to return the proper values for where I
>>>intersected that slope. (i.e. we can climb a "hill" that is a single
>>>polygon properly)
>>>
>>>Yet in writing some checking code I found that pickClosest sometimes
>>>returned more than one result and if I looked at the values of all
>>>results returned then SOMETIMES I found a value that was "closer" than
>>>the first (zero item) result returned.
>>>
>>>The relevant code is listed below.
>>>
>>>- John Wright
>>>Starfire Research
>>>
>>>Note: I'm picking straight "down" and thus hopefully the y value
>>>returned from the pick would actually correspond to the "closest"
>>>intersection.
>>>
>>>  public float checkHeight(float nx, float nz) {
>>>    pickTool = new PickTool(structureObjects);
>>>    pickTool.setMode(PickTool.GEOMETRY);
>>>    startRay = new Point3d((double) nx, (double) y+1.2+jumpHeight,
>>>(double) nz); // allow a 1.2 meter "climb"
>>>    rayVector = new Vector3d(0,-1.0,0);
>>>    pickTool.setShapeRay(startRay,rayVector);
>>>    pr = pickTool.pickClosest(); // pick result
>>>    if ( (pr != null) ) {
>>>      if (pr.numIntersections() > 0) {
>>>        for (int loop = 0; loop < pr.numIntersections(); loop++) {
>>>          if ( pr.getIntersection(loop) != null ) {
>>>            pickIntersection = pr.getIntersection(loop); // get the pick
>>>intersection
>>>            iPoint = pickIntersection.getPointCoordinatesVW(); //
>>>definitely should be VW!
>>>            tmpHeight = iPoint.y;
>>>            if ( tmpHeight > highestHeight) {
>>>              highestHeight = tmpHeight;
>>>            } // highest check
>>>          } // null check
>>>        } // checking for
>>>        return (float) highestHeight+jumpHeight;
>>>      } // end of pr.numIntersections
>>>    } // end if pr null
>>>    return y; // nothing below us!  Return what we came in with!
>>>  } // end of checkHeight
>>>
>>>===========================================================================
>>>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".
>>

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