How to use glb model with multi meshes/materials into a SPS (Solid Particle System)?

Hi, in my webapp, the user can upload a glb file, to be rendered as a particle in a SPS.

When the model has only one mesh with a single material, it’s working by getting the first child of the imported “__root__” element.

But when the model is more complex, with multiple meshes/materials, I couldn’t find out how to use it in the SPS.

See in the playground I’ve created: https://playground.babylonjs.com/#M6HVAX#6

  • If I try to add the “__root__” mesh direcly into the SPS and exception is thrown (“object null is not iterable”).
  • if I try to add the first mesh of the root in the SPS, only the first mesh is added, the childrens are not added to the SPS automatically
  • If I try to merge the childrens of “__root__” into a single mesh, the merged meshed seems to be ok, but when adding it on the SPS, it only works (in part, since the other materials are lost) when setting multiMaterials = false. If multiMaterials = true, the particle is not drawn.

So, is there a proper way to import a model from a file and use it in the SPS?

I’ve created 3 models with different structures to test (the urls are in in the playground), below the structure of the nodes as shown in the sandbox:

sample_multi_shapes_nested.glb

sample_multi_shapes.glb

sample_single_shape.glb

The short answer is you can not.

Longer answer is you could try to merge the meshes into one mesh before using it for the SPS.

Also due to the simplicity of your model, considering reexporting it as only one mesh might be the simplest.

1 Like

To add to this, two potential options to explore:

  1. As @sebavan said, get the multi-mesh objects to become one mesh BEFORE entering Babylon, say with a DCC tool such as Blender.

  2. You COULD also explore merging the meshes in Babylon itself
    Merging Meshes | Babylon.js Documentation. There are a couple of different methods for this, though it gets trickier to manage with multiple materials. Not impossible, just trickier.

Thanks for the clarification @sebavan!

We were already creating just low-poly models, with single mesh/material to be used in our app, but knowing that it’s not possible (or at least not without changing the models) to use “any/complex” model, we will consider this as a requirement.

Best regards!

1 Like