Long time for shader compilation from glb file

I use SceneLoader.Append to import my glb file into scene. It contains many meshes with different materials, so their compilation takes a long time — from 1 sec on high end pc, up to 15 sec in Safari.
Is it possible to load all meshes with one default shader and compile scene shaders in background one by one?
Should I use class CustomLoadingPlugin implements ISceneLoaderPluginAsync or there are simplier way to make it?

430ms to compile shaders on pretty good PC

You could swap the material on load and then compile back the other ones by reassigning them one at a time ?

1 Like

How? Materials and meshes are in the loaded glb file, I use just Append to add all of them. How to seprate them?

You would need to manage a map of mesh/materials in the loading callback and then set it back yourself. I am guessing it might work

Yes, I thought the shaders are already compiled when callback calls. My bad =)
But in fact I really can remove shaders from meshes and back it when it needed.

const skipMeshShaders: string[] = [ /* ... */ ];
const meshesToLoadMaterials: Mesh[] = [];

this.scene.meshes.forEach(mesh => {
  if (mesh instanceof Mesh && mesh.material && !skipMeshShaders.includes(mesh.name)) {
    mesh.metadata = { material: mesh.material, ...mesh.metadata };
    mesh.material = null;
    meshesToLoadMaterials.push(mesh);
  }
});

And later mesh.material = mesh.metadata.material;.

@sebavan thanks!

1 Like