Rendering 50k - 100k submeshes for babylon Mesh is taking time

I am trying to create a custom mesh with 50k - 100k submeshes and my code looks something like this,

var mesh = new BABYLON.Mesh(‘new-mesh’,scene);
var vData = new BABYLON.VertexData();
vData.positions = Array of positions;
vData.indices = Arrray of indices;
BABYLON.VertexData.ComputeNormals(postions, indices, normals);
vData.normals = normals;

var multiMat = new BABYLON.MultiMaterial(‘mat’, scene);

var i = 0;
var submeshesdatalength = 100000;
while( i < submeshesdatalength) {
var stdMat = new BABYLON.StandardMaterial(‘name’, scene);
//setting up material
new BABYLON.SubMesh(matIndex, vertexStartIndex, vertexCount, startIndex, indexCount, mesh);

mesh.material = multiMat;

But this is taking a lot of time rendering the mesh and also at times it crashes the browser.

This is way too much for what the web can handle unfortunately.

I wonder what use case would require that many ?

@sebavan well, the use case is something like this,
I want to create a custom mesh with say 50k - 100k faces and then we should be able to remove / restore an individual or group of faces with babylon point click events.

and we also want to assign different colors, opacity to each face of the mesh.

I would suggest in this case to use vertex color or a custom attribute with a custom shader so you can keep everything in one drawcall. Split by face will probably never work at scale.

1 Like

Or even instancing individual faces: Instances | Babylon.js Documentation (

1 Like

Splitting the mesh into individual facets using SPS might be worth a look.

@carolhmj I have tried this technique but it does not access to modify material of each instance and remove/ restore doesn’t work for me. Let me know if you have any reference code / playground that you can share with me.

@sebavan thanks for suggestion. also it would be great if you share some reference on building custom shader

@JohnK thanks for the suggestion. will try this one and update you

You can’t modify the material of each instance, but you can customize colors. The page I linked has reference code.

1 Like

@JohnK Solid Particle System did the job. Thanks for the help.