Pick location on custom model using a Ray - help!

I am at a total loss here, let me give you a little information about this.



Basically, I cast a ray from the mouse location to the groundMesh node, and get the location of the intersection with this code:


         mousePos.x = MouseInput.get().getXAbsolute();
         mousePos.y = MouseInput.get().getYAbsolute();
           Ray pickRay = new Ray();
           DisplaySystem display = DisplaySystem.getDisplaySystem();
           display.getWorldCoordinates(mousePos, 0, pickRay.getOrigin());
           display.getWorldCoordinates(mousePos, 1, pickRay.getDirection());
           pickRay.getDirection().subtractLocal(pickRay.getOrigin()).normalizeLocal();

            // Does the mouse's ray intersect the box's world bounds?
          pr =  new TrianglePickResults();
            pr.clear();
            pr.setCheckDistance(true);
            groundMesh.findPick(pickRay, pr);
           Vector3f loc = new Vector3f();
           Vector3f[] vertex = new Vector3f[3];
           boolean foundMeshHit = false;
           if(pr.getNumber() > 0) {
             TriMesh mesh = (TriMesh) pr.getPickData(0).getTargetMesh();
             for(int j=0; j<mesh.getTriangleCount(); j++) {
                 mesh.getTriangle(j, vertex);
                 foundMeshHit = (pickRay.intersectWhere(
                    vertex[0].addLocal(mesh.getWorldTranslation()),
                    vertex[1].addLocal(mesh.getWorldTranslation()),
                    vertex[2].addLocal(mesh.getWorldTranslation()), loc));   
                 if(foundMeshHit == true) {
                    System.out.println(loc);
                    //translate your object to loc                  
                      //System.out.println( "Loc: " + loc);
                      //loc.y = loc.y + .1f;
                    mouseFollowMesh.setLocalTranslation(loc);
                      mouseFollowMesh.updateGeometricState(tpf, true);
                      player2.lookAt(mouseFollowMesh.getLocalTranslation(), new Vector3f(0,1,0) );
                 }
                    
             
             }
           }


I then move a mouseFollowMesh (which is simply a small sphere) to the location to follow my mouse on the ground.
This worked just fine when my groundMesh was a Box, but now it is a custom 3d model, and the information I receive back is very weird. Let me lay it down for you:


every update frame, i receive back

pr.getNumber();
the correct TriMesh mesh;
and mesh.getTriangleCount();
but, if I put my mouse over any of the red zones in the attached picture, the mouseFollowMesh freezes on the last picked grey non-red zone and stays there until I pick back in the grey zone. the reason for this is because the location which is supposed to be returned from each triangle pick

                 if(foundMeshHit == true) {
                    System.out.println(loc);
                    //translate your object to loc                  
                      //System.out.println( "Loc: " + loc);
                      //loc.y = loc.y + .1f;
                    mouseFollowMesh.setLocalTranslation(loc);
                      mouseFollowMesh.updateGeometricState(tpf, true);
                      player2.lookAt(mouseFollowMesh.getLocalTranslation(), new Vector3f(0,1,0) );


isnt returned when i am picking in the red zones. (in the red zones the other information is returned) Why could this possibly be happening?

(about the picture, all the red areas are raised up, and the ones parallel to the Z axis are the only ones which can be picked, and on the northern most raised area, the pipe cannot be picked)

I have discovered a little more information, but I still need some help.



I did this test with a more simple .3ds model which had less groups. I was still getting the same problem with no explanation.



If I combined all the groups together into one group, this problem goes away. What would groups have to do with any of this?



I need help to make this work with multiple "groups", because texturing requires multiple groups.



Does anyone have any explanations?

ok - funny thing is, the problem is being caused when I call



groundMesh.setLocalScale(1000);



in which case, for some reason, it doesnt see the new scaled mesh and picks in empty space and sometimes not even on the object itself. How can I tell the mesh to 'refresh' to its new scale?

try something like this:


groundMesh.updateGeometricState(0,true)
groundMesh.updateWorldVectors();
groundMesh.updateWorldBound();



This is more quessed than known(!!!)