(JME3) createMeshCompoundShape() results in invisible displaced collision shape


I was having problems (after modifying a Box mesh) that the resulting mesh was not colliding.

After some play I found that it was colliding but was displaced, was colliding in another place instead where the PhysicsNode was placed.

I thought it could be related to the position the collision was being calculated at, so I create a backup of the current position; move it to 0,0,0; modify the collision shape; move it back to backup position, and it worked! but seems to be a bug… I added the lines marked with //@ to prevent it.

            PhysicsNode phys = (PhysicsNode)geom.getParent();

            Node nodeParent = phys.getParent();

            Vector3f posBkp = phys.getLocalTranslation().clone(); //@

            phys.setLocalTranslation(0,0,0); //@ this prevents a bug when calculating collision mesh


            CompoundCollisionShape newShape = CollisionShapeFactory.createMeshCompoundShape((Node)phys); //I have changed the mesh already


            phys.updateModelBound(); //if I dont call this and "look up" the mesh disappears…

            phys.setLocalTranslation(posBkp); //@


PS.: I dont really know when to call updateModelBound(), updateGeometricState() and updatePhysicsState()… I just try and test and change order, and after and before attachChild() til things seem to be working… The examples I find seem to follow no specific rule. It would be cool some javadoc saying when to call them :D.

There is a doc in the wiki about updateGeometricState in jme3. Basically you dont have to call them unless you want to read values from your spatial when its not attached to the scenegraph.

About your collision shape, you can call attachDebugShape(assetManager) on your physics node to make the collision shape visible, maybe then it becomes more apparent whats wrong.



bookmarked thx!

mmm… the debugShape seems to be a scaled model just over the real one? nice :).

Good to highlight ray cast picking object!

ok, I did add debugShape, and now I see the strange result! see the screenshot (I shot some green balls on it, making use of the collision bug so the balls get inside of the shape). The real mesh has no collision now as it is displaced!

I played a bit…

My guess is that the collisionshape is having its localtranslation setup as much as the physicsnode already has it, so we have the collision set at twice the distance from 0,0,0!

To make it sure, I added this code


to reposition the debugShape and it did with precision! see the 2nd screenshot, I guessed and shot the greenballs at where it should be displaced. So, unfortunately, the collision shape didnt come with the debugShape mesh…

PS.: Btw, when I do this: nodeParent.detachChild(phys); the DebugShapeNode is also detached! I had to detach the debugshape prior to that code. I need to detach when I do a second mesh modification, to attach a new debugshape.

EDIT: about the collision bug, there is getPhysicsSpace().setAccuracy(); and also setCcdMotionThreshold() and setCcdSweptSphereRadius() that seem more precise;

mmm… I must admit that it is not a bug at all !!!

I got the self mesh (that was already translated) and used it to create a new collision shape, so that is absolutely correct to have the collision translated…

So my question changes to:

if there is a way to update the collision shape?

instead of having to set a new one?

teique said:

So my question changes to:
if there is a way to update the collision shape?
instead of having to set a new one?

No. Its a different collisionshape, so you have to create it first and then set it.