Triangle Picking

I’m doing triangle picking on a terrain page and wow, it misses a LOT of triangles, somewhere around 1 in 8, maybe more, being a non-math whiz and generally sucky at all things 3d, I probably won’t be able to help much with this. What I can say is that those triangles that are ignored for whatever reason are consistantly ignored, regardless of camera location/rotation. It seems like maybe some of the triangles in the mesh simply aren’t added into the OBBTree (trying to figure out how to check this now but I’m having a hard time understanding what’s going on).

I believe terrain page changes triangles as you move around, in order to display less triangles on parts of the terrain that are farther away. If this is the case, the triangle picking won’t work unless you update your OBB tree every frame which would be pretty slow. OBB tree picking isn’t really made for objects that can change geometry easily.

Does that make sense?

Are you using dynamic level of detail? Also, try turning on wireframe mode to get a good idea of what is hitting what.

I’m not using dynamic level of detail, which I could see having an influence on things. I spent a lot of time looking at the wireframe trying to determine a pattern to where triangles got missed. I also tried creating the terrain page with a flat height map to see if it had something to do with the angle of the triangle, but it had no effect. I haven’t tried to rebuild the OBBTree just for testing purposes, mostly because I’m asceert of changing the jme source files (even for simple stuff). I’m pretty confident it wouldn’t make a difference… though I can’t really rule out the possibility that which triangles failed to be picked might change.

This is exactly the problem I have, too. I have modified TestOBBPick, to display a TerrainBlock instead of the Maggie model, and have exactly the described symptoms. Clod is off, but still, TerrainBlock extends AreaClodMesh, obviously. So I quickly made a copy of TerrainBlock, whithout clod support, thus only extending TriMesh (using an exact copy and paste from the original TerrainBlock, with the clod portion commented out). The problem is just the same. In my experience, there are always at least two connected triangles not responsive to the picking. I made an illustration here:

The tris marked in an ugly pinkish color have failed to respond to the picking. The modified TestOBBPick file is here:

Hopefully, this will help somebody to sort this out.

EDIT: In my modified TestOBBPick, you can press F5 to rebuild the complete collision tree, from rootNode down. It won’t change anything for the picking problem, though.

As I had changed a little on the triangle picking local to world transformation to fix issues with non-uniform scaling, I updated this test and tried it again:

It seems this issue itself was resolved already. And it works fine with non-uniform scale, now, also.

Should this also fix jmephysics collisions with terrain meshes ? - have to do a test when i get home…