geom right fitted using bullet [Solved]

Hello,

I am trying to use bullet (physic engine), and I encounter some problem around collision.

With ode, I use trimesh to have a box that fit my mesh the best.
Is there a way with bullet to have same behavior and how?

For the moment I use this code

visNP = loader.loadModel('fighter.egg')
		geomNodeCollection = visNP.findAllMatches('**/+GeomNode')
		mesh = BulletTriangleMesh()
		#~ mesh.addGeom(geom)
		for nodePath in geomNodeCollection.asList(): 
			geomNode = nodePath.node() 
			for i in range(geomNode.getNumGeoms()): 
				 geom = geomNode.getGeom(i) 
				 mesh.addGeom(geom) 
		shape = BulletTriangleMeshShape(mesh, dynamic=False)

		body = BulletRigidBodyNode('Bowl')
		self.bodyNP = self.worldNP.attachNewNode(body)
		self.bodyNP.node().addShape(shape)
		self.bodyNP.node().setMass(10.0)
		self.bodyNP.setPos(0, 0, 0)
		self.bodyNP.setCollideMask(BitMask32.allOn())
		self.bodyNP.node().setCcdMotionThreshold(1e-7);
		self.bodyNP.node().setCcdSweptSphereRadius(0.50);
		self.world.attachRigidBody(self.bodyNP.node())

		visNP.reparentTo(self.bodyNP)

But When my ship goes forward, and encounter an asteroid, my ship enters in the asteroid, and collide in the asteroid.

I don’t quite understand what you want to say here. A sceenshot with the debug renderer on (and visible geometry only in wireframe render mode) would help probably.

If you want a box - and not an arbitraty geometry - then you should use a box shape. Both in Bullet and ODE.

BulletTriangleMeshShape is usually used for static bodies, e. i. ground, static obstacles, rooms. You can use BulletTriangleMesh for dynamic bodies too, but then you have to create it this way:

BulletTriangleMeshShape(mesh, dynamic=True)

The Panda3D Bullet module will then create a different native Bullet shape type internally.
Usually it is better to use BulletConvexHullShape for all dynamic objects (ships, cars, asteroids, …).

Thank you for advice.
OK I change a bit what I’ve done

body = BulletRigidBodyNode('fighter')
geom = visNP.findAllMatches('**/+GeomNode').getPath(0).node().getGeom(0)
shape=BulletConvexHullShape()
shape.addGeom(geom)
body = BulletRigidBodyNode('fighter')
self.bodyNP = self.worldNP.attachNewNode(body)
self.bodyNP.node().addShape(shape)
self.bodyNP.node().setMass(1.0)
self.bodyNP.setPos(0, 0, 0)
		self.bodyNP.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(self.bodyNP.node())

visNP.reparentTo(self.bodyNP)

I’ve added debug tools to see debug framewire…
I see what’s wrong. The size of the shape doesn’t match with the model. My shape does at least the half of the size of my model.

I don’t know how to do to match the size of my model.
Do you have any clue to follow?

Thank you for your time.

There is probably a transform on the geom. do this and report the output:

visNP.ls()

ModelRoot fighter.egg
  PandaNode 
    GeomNode Fighter (1 geoms: S:(TextureAttrib)) T:m(scale 3.28084)
>Exit code: 1

OMG, I think it is right clear for me : scale 3.28084.

I opened the egg and find :

	<Transform> {
		<Matrix4> { 
			3.2808398950131235 0.0 0.0 0.0 
			0.0 3.2808398950131235 0.0 0.0 
			0.0 0.0 3.2808398950131235 0.0 
			0.0 0.0 0.0 1.0 
		}
	}

I removed it and it works perfect for now.

Thanks a lot

If average vertex spacing is about the same for all objects you could also use a different shape type which has constructors which supprt scaling:

BulletConvexPointCloudShape (Geom const geom, VBase3 scale)

Or try to scale the node itself:

self.bodyNP.setScale(3.28084)

But usually it is better not to use scale at all when using physics, so this is not recommended.