Exact physic representation of aTriMesh


if I have a TriMesh and want to have exact physics howcan I do this?

I tried to create a boudningbox and deformit using computefrombatchesbut it does not affect the result in any way.

Is there a easy and fast way to do this which can be done during game?

BoundingBox box=new BoundingBox();

        ArrayList<TriangleBatch> bachties = new ArrayList<TriangleBatch>();

        for (int i=0;i<(((TriMesh) ((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0))).getBatchCount();i++)

        bachties.add(((TriMesh) ((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0)).getBatch(i));







I have loaded a jME file and got the trianglebatches.

Am I on the totally wrong way or is it maybe not possible to do this for more then 40 models effectivly?

Sue said:

Am I on the totally wrong way?

Yes :)

Simply create a physics node, call createMesh, and call copyFrom on the resulting PhysicsMesh.
Or you can call generateGeometry( true ) to generate geometries for a whole node with trimesh accuracy.

If you set useTrimesh = true in TestBasicRepresentation you can see trimesh collision in action.

PS. Beware: trimeshes are quite slow, obviously, as they can be really complex. Additionally ODE is not that stable with using dynamic trimeshes.

When I use the genGeometry(boolean) it really slows down, but when i use the code below everything starts flying around!

Today is not my brightest day so can you please enlighten me?

Do I have to use another dynamicNode as Child of dynNode[11] and add to this one the physicsMesh?

PhysicsMesh bound=dynNode[11].createMesh("ghostbound");

        bound.copyFrom(((TriMesh) ((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0)));





  1. You should never attach physics nodes to each other (if detected this results in an exception). Physics nodes (static and/or dynamic) should always be siblings regarding scenegraph hierarchy.
  2. Don't create a physics mesh yourself and call generateGeometry. You should either create the physics collision geometries yourself or call generate geometries.
  3. Scale your mesh/node before copying the mesh data - see javadoc  (btw I'm not sure scaling is working with trimesh at all, try without scale first)

Ok, but ih the tutorial you are attaching different physicNodes to each other like a dyn Node to a static one and a dynamic to another one togetthis strange ball with buckle.

If I do it this way and not use the trianglecollision it is even slower and somehowthe model does not match anymore the physics representation.

I used both ways of scaling with the same result. I even used an unscaled model but this one is so heavy it penetrates the floor ;) 

The penetration of other objects and their bounceyness can be adjusted using materials right?

dynNode[11].attachChild( ghostNode );

        System.out.println(((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0).getName()+" "+((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0).getType());

        PhysicsMesh bound=dynNode[11].createMesh("ghostbound");

        bound.copyFrom(((TriMesh) ((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0)));






Sue said:

Ok, but ih the tutorial you are attaching different physicNodes to each other like a dyn Node to a static one and a dynamic to another one togetthis strange ball with buckle.

No, you misinterpreted the code. A geometry is attached not a physics node.

Yes, materials could be used. Or you can simply set the mass instead of computing it.

Is it possible to encapsulate stuff or should physic nodes always be siblings?

Like a staticNode containing a model which contains some dynNodes which contain models?

Or should it be not designed that way?

ANother problem if I am not using a BoundingBox orSphere my Model starts to sink through the floor. I applied to the surrounding floor which is in a staticNode some material and to my Model and nothing changes.

And the Model and everything nover stops moving around.


room=(Node) ((Node) roomNode);







for (int i = 0; i < dynNode.length; i++) {

dynNode= getPhysicsSpace().createDynamicNode();


dynNode[0].attachChild( skullNode);

        //  skullNode.setLocalTranslation(new Vector3f(5,5,0));



        rootNode.attachChild( dynNode[0] );





        for (int i=0;i< bubbleNode.length; i++){

        dynNode[i+1].attachChild( bubbleNode );


            bubbleNode.setModelBound(new BoundingSphere());






        dynNode[11].attachChild( ghostNode );


        System.out.println(((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0).getName()+" "+((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0).getType());

        //PhysicsMesh bound=dynNode[11].createMesh("ghostbound");

        //TriMesh boundy=((TriMesh) ((Node)((Node)ghostNode.getChild(0)).getChild(0)).getChild(0));







Material ma=new Material();









        showPhysics = true;


Sue said:

Is it possible to encapsulate stuff or should physic nodes always be siblings?

yes, always.

re that sink-problem: probably your winding is flipped? Check if you can see your objects normally when you apply a cullstate with CS_BACK. Is your ground also a trimesh? Probably ODE does not handle this correctly then.

It is a room and everything there is a trimesh because I imported it via collada.

Oh, that will be way too slow. You'll have to wait some processor generations before you can simply compute all TriMeshes. You will have to approximate most of the dynamic things with some spheres, boxes, capsules etc. Also walls should be approximated by boxes.

Hmmm so setting around every wall and the floor a boundingbox should work?

As I have seen it collada creates a new Node which carries a Node which caries the textures and Trimeshes of myimported Model so setting around every trimesh a BouningBox should resolf the problems ODE has with Trimeshes?

I'm not sure we are talking about the same things. You have to use physics primitives - e.g. a PhysicsBox - to approximate your meshes. ODE does not see any trimesh data then, so it's obviously not slowed down by too much geometry data. But BoundingBox is primarily a thing for culling (and picking currently). These boudings are used by generateGeometry( false ) to generate physics geometries from it. If you want to do the latter using BoundingBoxes would be ok. But as there are no bounding capsules of bounding cylinders, etc., you cannot use all physics primitives this way.

Ok i got it :slight_smile:

It is still not working as I want it.

If I use these basic objects everything works quite well except for the fact that I am able to drag big objects through small spaces in my walls.

But if I use PhysicsMesh and copy the geometry from my  little complex object then my object tilts to the heavier side and penetrates the floor.

Is there a way to adjust the physicsboxes the way boundingboxes do?