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;
vData.applyToMesh(mesh);
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
multiMat.subMaterials.push(stdMat);
new BABYLON.SubMesh(matIndex, vertexStartIndex, vertexCount, startIndex, indexCount, mesh);
i++;
}
mesh.material = multiMat;
But this is taking a lot of time rendering the mesh and also at times it crashes the browser.
@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.
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.
@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.