Possible bug in TrianglePickResults when changing radius of a mesh

Hi,

I am using JME1 and i have the following problem with mouse picking:

I have a sphere in my scene and whenever i change its radius, mouse picking using TrianglePickResults returns an INFINITY distance even if a click on the mesh.

This means that picking works perfect until i change the radius of the sphere (same things happen using a Cylinder instead of Sphere). I use a BoundingSphere for the sphere mesh and an OBB for the Cylinder.



I have noted that whenever i use TrianglePickResults then the distance equals INFINITY when the mouse has picked the bounding volume, not the mesh itself.



Each time a change the radius of my mesh (Sphere) i update the model bounds:

mesh.setData(center, zSamples, radialSamples, newRadius);
mesh.updateModelBound();



Code that checks for picking:

   public void onButton(int button, boolean pressed, int x, int y)
      {
         
         if(button == 0 && pressed == true)
         {
            pickList.clear();
            screenCoords.set(MouseInput.get().getXAbsolute(), MouseInput.get().getYAbsolute());

            Ray ray = getRayProjection();
            PickResults results = new TrianglePickResults();
            results.setCheckDistance(true);
            rootNode.findPick(ray, results);
            
            hits += results.getNumber();
            hitItems = "";
            if(results.getNumber() > 0)
            {
               for(int i = 0; i < results.getNumber(); i++)
               {

                  pickList.add(results.getPickData(i));
                  hitItems += results.getPickData(i).getTargetMesh().getParentGeom().getName() + " "
                        + results.getPickData(i).getDistance();
                  if(i != results.getNumber() - 1)
                  {
                     hitItems += ", ";
                  }
               }
               System.out.println("hits="+hitItems);
            }
            results.clear();
         }
      }
      




Code for getRayProjection():

Ray getRayProjection()
   {
      float cursorPosX = MouseInput.get().getXAbsolute();
      float cursorPosY = canvas.getHeight() - MouseInput.get().getYAbsolute();
                     
      Vector2f screenPosition = new Vector2f(cursorPosX, cursorPosY);            
      Vector3f cursorEndPosition = display.getWorldCoordinates(screenPosition, 1);
      Vector3f directionVector = cursorEndPosition.subtract(cam.getLocation());
      Ray ray = new Ray(cam.getLocation(), directionVector);
      ray.getDirection().normalizeLocal();
      
      return ray;
   }



Note that if i use BoundingPickResults instead of TrianglePickResults, then picking works fine even if i change the radius.
So i was wondering if this is a bug on TrianglePickResults...

If you change the mesh and want to do triangle-accurate picking on it, you must update the collision tree for that mesh. Use the CollisionTreeManager.update*** method.

Momoko_Fan said:

If you change the mesh and want to do triangle-accurate picking on it, you must update the collision tree for that mesh. Use the CollisionTreeManager.update*** method.


Thanks! Problem fixed.