After I perform a rather large material update to an Object there is a considerable lag in the scene for any mousedown action. Does anyone know why?
The first time a material is rendered, its shaders are recompiled and any new textures are uploaded to the GPU. The textures, especially, may take a while.
The most straightforward fix is to render all materials once while your application is still loading, then they’ll be ready to use later.
WebGLRenderer.compile() might help in this context.
I’ve tried calling renderer.compile() right after I do my material update but it doesn’t change anything.
As for rendering all materials initially how would I do that when the material doesn’t belong to a mesh/object yet?
That should compile the materials, but it may not upload textures… I’m not sure.
You’d need to put the materials into the scene for that one step, even just on a temporary box mesh or something.
Correct, it does not^^.
I tried exactly that and switched the material to a placeholder object that is using the desired material but there is still that noticeable lag on mousedown.
You may need to either share a demo or run a profile to see what is happening during that lag time.