I had this same problem, but I believe this is the issue.
Geometry's can have normals, but they are only associated with a vertex.   But when you use ray/segment collision, you get a collision point some where on the surface of a tri/quad etc. NOT the actual vertex.  So the PickIntersection does not have a normal because one does not exist AT THAT POINT in the GeometryArray, only at the vertex.  To get around this, we just wrote a quick routine that computed the normal from the tri's points which you can get back from the PickIntersection.

Point3d[] points = pick.getPrimitiveCoordinatesVW();

    static public void computeNormal( Point3d[] points, Vector3d normal )
    {
      vecA.sub( points[0], points[1] );
      vecB.sub( points[2], points[1] );
      vecA.normalize();
      vecB.normalize();
      normal.cross( vecB, vecA );
      normal.normalize();
    }

This worked great for us.
BTW, this is actually "more correct" in may cases because it computes the normal from the VW points of the GeometryArray.  If you used the actual normal in the Geometry, it would only be correct if the Geometry is never transformed.  If it is transformed, the normal in the GeometryArray would still return in it's local frame and not be the actual normal in the world frame.
I hope that helps!

Epelman Boris wrote:

Hi everybody!

I have a problem in getting normal when I pick the object.
The code that is use is:

            pickCanvas.setShapeLocation(x, y);

            Point3d eyePos = pickCanvas.getStartPosition();
            pickResult = pickCanvas.pickClosest();
            if (pickResult != null) {
              Shape3D sh = (Shape3D)pickResult.getNode(PickResult.SHAPE3D);

            PickIntersection pi = pickResult.getClosestIntersection(eyePos);

            Vector3f iNormal = null;
            iNormal = pi.getPointNormal();
            System.out.println("iNormal " + iNormal);

The normal is null here. My geometry does contain normals.
(BTW, rendering works fine on those objects).
Does somebody knows if I need to add something to the code
to retrieve normals, or it is a bug in PickIntersection?

Thanks,

Boris Epelman

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

--
___________________________________________________________

Shawn Kendall               Full Sail Real World Education
Course Director             3300 University BLVD
Real Time 3D for Gaming     Winter Park FL 32792
[EMAIL PROTECTED]       http://www.fullsail.com
___________________________________________________________
 

Reply via email to