TrianglePickResults doesn't always work


I want to pick an object on a per triangle basis but I can't get it working. Picking seems to be still using the bounding box of the object.

Neither the tutorials I found nor the users manual helped me so far, mostly because they seem to be outdated.

For example, one of them mentions to call the updateCollisionTree() method on a Sphere object (which AFAIK is a subclass of TriMesh).

However, this method doesn't seem exist (anymore).

I found one in CollisionTreeManager but calling that one didn't work either.

Could someone help me with this, possibly starting a more up-to-date tutorial?

Thanks for your help.


Maybe you can post the code where you do the trianglepicking. And have a look here (if you not

already have): jmetest.intersection.TrianglePickTest

That one helped me quite well…

Here's the helper method I use for picking:

  • pRootNode is the root of the subtree I want to pick
  • JmeCamera is basically a wrapper around the jME camera object
  • pPickPoint is the mouse location

public static List<PickData> pickGeometry(Spatial pRootNode, JmeCamera pCamera, Point pPickPoint, boolean pNearestOnly) {
        Vector2f tMousePosition = new Vector2f((float) pPickPoint.getX(),  pCamera.getCamera().getHeight() - (float) pPickPoint.getY());
        Vector3f tRayStart = pCamera.screenToWorld(tMousePosition, 0.0f);
        Vector3f tRayDirection = pCamera.screenToWorld(tMousePosition, 1.0f).subtract(tRayStart);
        Ray tPickRay = new Ray(tRayStart, tRayDirection);

        PickResults tResults = new TrianglePickResults();

        pRootNode.findPick(tPickRay, tResults);

        List<PickData> tPickResults = new ArrayList<PickData>();

        if(tResults.getNumber() > 0) {
            if(pNearestOnly) {
            } else {
               for(int tIndex = 0; tIndex < tResults.getNumber(); tIndex++) {

        return tPickResults;

The code for building the mesh and setting the render states is somewhat bloated, so I'll omit it here (unless you request it  ;)).
Basically I just build a TriMesh, set some states like ZBufferState etc. and the call:

tTriMesh.setModelBound(new OrientedBoundingBox());

After this tTriMesh is added to the object's root node which in turn is attached to the world root.

Well, the geometry is basically a flat ring of triangles.

With TrianglePickResults I'd expect the picking system to return the object only if I touch the ring (+/- some error).

However, I the ring is also picked if I touch the corners of the bounding box. I didn't visualize the pick ray, but from my other picks (with bounding box) it seems to be ok. I just moved the mouse and looked when the ring is picked and when it isn't and the pick shape seemed to be a rectangle around the ring.

I'll check it will my other geometry, too. Just in case the ring has some glitches (being flat for example).

Hmm, looks like it depends on where in the scenegraph it is added to.

If I add it to the world root it works, adding it to the controls root doesn't.

However, I can't spot any differences between both nodes.

Both are just initialized as new Node(…). The only difference (except the children) is that the world root has a lighting state.

Can you show us your whole class? I think that could help us to help you… :smiley:

Sorry for the delay, I was on vacation for a few days and just before that the forum didn't work.

I found some strange behaviour which might be a bug in the engine.

The setup could be described as follows:

I have a flat ring floating over a box. Both have a bounding box and are attached to the same root node.

(Look at my beautiful ASCII art  :D)

   / ooooo
  |o| ____|o|___
   oxxxxxx/  | |

Now, when I do a pick using TrianglePickResults it works if the ray hits the box within the ring's bounding box, i.e. the ring is only picked if the triangles are intersected by the ray (see the areas marked as  'x' ).

It doesn't work, however, if the ray would hit nothing except the ring's bounding box (for example inside the ring, but above the box). Then the ring would be returned as pick result, even if the triangles are not intersected (see areas marked as 'o' ).

(Hope it is clear, despite my illustration  ;))

When I have time I'll create a small scenario to test it.

Edit: since this is not a tutorial request anymore, it should maybe be moved to a more appropriate place.