Bullet terrain - shape from a terrain model

Hello All,

How to better use bullet where the terrain would be a mesh? The collisions, as far as I see, can only use predefined shapes. The most “flexible” would be triangle mesh shape but I did not find how to create the shape from a model. Not sure if a large terrain would be efficient by creating a script to read a OBJ model and create triangles (using mesh.addTriangle§).

Gray scale terrain is not an option as it is hard to match a terrain texture mesh taking the same space than a heightfield shape.

Anyways… how you guys have work around that?
Thanks in advance,

You can build a BulletTriangleMesh from a Geom. You can find an example of this in the manual.

I would not worry about trying to optimize the terrain (via chunking it or otherwise) until you run into a performance problem. Just worry about getting things loaded and moving forward.

Thanks Moguty. Does the actor.getGeomNode() retuns the expected Geom type required for the BulletTriangleMesh().addGeom(geom) ?

That will give you a GeomNode, which contains Geom instances. You will need to use get_geoms() or get_geom() to get a Geom out of GeomNode. Something like this should work:

mesh = BulletTriangleMesh()
for geom in actor.getGeomNode().get_geoms():

Fantastic. I will try that tomorrow.
Thanks a lot

I kind of got what I wanted. But the character seems to move in the edge of the triangles.
Not sure if increasing the mesh density would be the correct thing to do. Code was a bit more complicated:

###### create terrain collisian shape
geomNodeCollection = self.environ.findAllMatches('**/+GeomNode')
for nodePath in geomNodeCollection:
  geomNode = nodePath.node()
  for i in range(geomNode.getNumGeoms()):
    geom = geomNode.getGeom(i)
shape = BulletTriangleMeshShape(mesh, dynamic=False)

Try resetting the node transformation first.


Although I had a similar problem with ODE. Does collision geometry meet visible? or what does the edge of the triangles mean?

Try adding shape.set_margin(0.0) Bullet has these magic margins and if your models are at the wrong scale these margins mess everything up, but don’t ask me what the right scale is, I’ve no idea.

Thanks guys… actually it seems that my BulletCharacterControllerNode has little friction and it slides on terrain triangle edges due gravity. I was not able to find how to change friction. Not sure if using wheel controller would provide a better control. I want my character to slide in some situations (icy slopes).

Short video. @0:30 the debug view shows the mesh (wire frames).

As a heads up, the Bullet kinematic character controller is terrible, and probably shouldn’t be used “for production.” It is very buggy and has issues like the ones you mention.

Thanks for the tip Moguri.