findCollisions() and getTargetTris()

I have a problem with the collision detection. It just tells me the object but I don't get any triangles which I need to unstuck the cam once it ran into an object.



I use this code in the setup:



URL model=Client.class.getClassLoader().getResource("data/model/building.jme");

JmeBinaryReader jbr=new JmeBinaryReader();

try {

  jbr.setProperty("bound","box");

  jbr.setProperty("texurl",new URL(model.getProtocol()+":"+model.getPath()));

  scene=jbr.loadBinaryFormat(model.openStream());

} catch (IOException e) { }



scene.updateCollisionTree();



playerBounds = new Sphere("playerBounds",16,16,2);

playerBounds.setModelBound(new BoundingSphere());

playerBounds.updateModelBound();

TriangleCollisionResults cr = new TriangleCollisionResults();





and in the update() function:



cr.clear();

playerBounds.setLocalTranslation(cam.getLocation().add(0,-2,0));

playerBounds.findCollisions(scene, cr);





cr.getCollisionData(i).getTargetMesh() returns the objects but when I try to find out how far and where the intersection is I thought I get the triangles in cr.getCollisionData(i).getTargetTris() but this is always empty.



What am I doing wrong?

Just a quick note, try out jmetest.intersection.TestOBBTree  It uses triangle accurate intersection and you might be able to use that code as a starting point (if you didn't already :slight_smile: )

That's what I used more or less. The only difference I can see is that in the test it uses two nodes with one trimesh each.

I use a sphere and a loaded scene with a hierarchy of trimeshes which was created in Max3d and converted to jme format.

The bounding volumes is a sphere for the player and boxes for the scene. In the test there are two bounding boxes.



The test program is much simpler of course (that's what a tutorial should be) but I cannot see any more significant differences to my approach.



As I posted before I have a similar problem with ray intersection. This also returns the meshes but no triangles. For this problem I worked around using a ray intersection function for all triangles of the objects returned. I needed that anyway as I have to find the distance from the origin of the ray to the intersection point (height over terrain test).


Just for testing purposes, can you try BoundingBox for both?  Also, i assume you update your collision tree after you've got your model all setup?

Thanks so much, I forgot to call playerBounds.updateCollisionTree().

I did it only for the scene not the playerBounds.



Phew, one big problem is solved. Only the model loading is open now :wink: