Blender scene -> .GLB -> Babylon with collisions workflow

Hello! Curios if i am missing something.

In blender i have created a couple of cubes - scaled, transformed, rotated, and applied different textures to different sides. After exporting to glb and importing to Babylon js “game” (or opening in https://sandbox.babylonjs.com/), i see that cubes are not single meshes anymore. Because different textures applied to different sides, each side is a separate simple mesh if it has different material. This makes it impossible to create a “box collider” for Cannon.js, since there is no “box mesh” anymore.

So the workflow in blender is really to create invisible cube meshes for each visible cube that has multiple materials for sides?

First picture is blender, you can see it’s three cubes in the scene tree.
Second picture is from babylon sandbox, can see two cubes are splitted into multiple meshes. (in the scene explorer)

I hope this problem is solved somehow, or there is a general workflow, how to make colliders out of boxes that aren’t connected into a single mesh, and also scaled, rotated, etc.


This is because the GLTF standard does not support multi-material meshes.
In GLTF, they will be split and stored as primitives corresponding to the number of materials.
The solution is to bake multiple materials into a single material so that they will not be split into multiple meshes.
Or create invisible cube proxies as box meshes for them.
You can also consider having your developers merge the meshes again programmatically after loading the model.

Thank you!

Is there a standard process how developers merge the meshes? How i imagine it:

  1. find all meshes with names ending with _primitiveX
  2. Group and combine them based on the first part of the name (ex Cube.001)
  3. Calculate AABB box
  4. Find corresponding transform node
  5. Apply rotation/scale/shift from transform node to AABB box

Might work for boxes, but i guess for cylinders/spheres more complicated?

  1. Your assumption about GLTF mesh merging is basically correct.
  2. You can try to obtain the bounding boxes of the split meshes separately and then calculate a new bounding box without merging the meshes, which is much simpler.
  3. For complex meshes, if you want more accurate collision detection while maintaining performance, you need to manually create multiple basic geometries as collision bodies.

Thanks a lot!