Generating Triangle Mesh Shape from .bam model

Hello there,

I am trying to generate a BulletTriangleMeshShape from a .bam model file by using the following lines:

modelNP = loader.loadModel('path_to_model')
geom = modelNP.findAllMatches('**/+GeomNode').getPath(0).node().getGeom(0)
mesh = BulletTriangleMesh()
shape = BulletTriangleMeshShape(mesh, dynamic=False)

and then adding the shape to a BulletRigidBodyNode. When using a sample .egg file it works fine, however when I try to use a .bam file, the TriangleMesh does not match the model at all (I just get a large sphere enclosing my visual model).
In the C++ API reference of the GeomNode class i found several functions concerning the BamReader (i.e register_with_read_factory()), but the Python API reference of the GeomNode class does not mention .bam files at all.

Does the code snippet above not work with .bam files in general, did I do something wrong or is there another way of generating colllision shapes from .bam files?

Thanks a lot in advance!

Hi, welcome to the forums!

There is nothing in particular that should be different about .bam files in this case (which is why the documentation doesn’t mention it; GeomNodes loaded from a .bam file are not different in some important way).

What I note, though, is that you are only passing in the first Geom of the first GeomNode that it can find. Perhaps that just so happens to be a different one than the one you want, for the .bam file in question, and there are multiple Geoms in the model? Try calling modelNP.ls() and modelNP.analyze() to see what’s inside.

Try to combine the geometry, it will also reset the transformation.

modelNP.flattenStrong()

Note that even flattenStrong is not guaranteed to result in a single Geom object.

Sorry, I made a mistake, use:

 modelNP.flattenLight()

after loading and transformation to bake the geometry.

Thanks a lot, this worked perfectly!