I’m working on a lightmap based workflow where instanced meshes of a GLB share baked lightmaps each with its own UV coordinates in the lightmap atlas. As a first step, I wanted to get it working in playground, but for some reason the UV2Kind vertex buffers get shared between all the instances causing the same coordinates to be applied to them (see console log).
P.S. The x axis was flipped on the instance in spite of parenting the mesh to the same parent. I’ve hardcoded the flip on X here after parenting but not sure if that’s the right way of doing it. Would be nice to include this in the docs here: Instances | Babylon.js Documentation
Instances share the same vertex buffers than their master mesh, you can’t have different vertex buffers on a per instance basis. You will have to create regular meshes if you want to do this (use clone + makeGeometryUnique to make sure the mesh can use different vertex buffers):
Also, to avoid scaling X by -1, you should use mesh.parent = ... instead of mesh.setParent(...), because the latter is updating the mesh matrix in the process.
@Evgeni_Popov we are trying to limit the draw calls in our scene (currently > 200 which is causing FPS to drop. Our scene has many instances of the exact same GLB placed in different locations. Because it is in different locations each instance’s lightmap is stored in the same file with an offset). Cloning will help with the memory pressure but the draw calls wont be affected, right?
@Evgeni_Popov Is there a way to achieve this by using NME where the UV offsets per instance can be manipulated by the shader at run time? I also saw custom buffers, but they seem to only hold 1 value per instance. In my case, I’d like that value to be an offset.
I’m trying real hard not to redesign the scene by taking out the instances, but looks like I will be forced to do that unless I find a way to apply the lightmaps separately.