jME3 picking?

What I'm really trying to do, is get the 3d point of the mouse, once it hits the terrain. (atm I'm moving the brush with ASDW :()

The following code sort of works, but it's "lagging", even though the FPS is still 1000+.

The reason: Seems like it "dropping" results most of the times, and only picks on certain places of the terrain mesh?

Also, why doesn't it return the geometry object picked?

Thanks in advance.

  • Mikkel

public static Geometry findClickedObject(int x, int y, Vector3f point) {
        Editor editor = Editor.getEditor();
        Vector3f worldCoords = editor.getCamera().getWorldCoordinates(new Vector2f(x, y), 1.0f);
        Vector3f camLoc = editor.getCamera().getLocation().clone();
        Vector3f rayDir = worldCoords.subtract(camLoc).normalizeLocal();
        Ray mouseRay = new Ray(camLoc, rayDir);
        System.out.println("MouseRay: " + mouseRay);
        return PickUtils.calculatePick(editor.getRootNode(), mouseRay, point);

   public static Geometry calculatePick(Node node, Ray mouseRay, Vector3f point) {
      try {
         node.collideWith(mouseRay, collisionResults);
      } catch(Exception e) {//Scene not initialized.
         return null;
      CollisionResult result = collisionResults.getClosestCollision();
      if(result != null) {
         return result.getGeometry(); //This is always null!??!
      } else {
         System.out.println("No results..");
      return null;