KHR_materials_variants got lost during clone of mesh


i think i found a bug in the KHR_materials_variants class. We want to make use of the clone method of meshes to increase performance and memory usage. We are also making use of KHR_materials_variants. It seems that KHR_materials_variants are not correctly copied during the clone process.

I created a playground to prove this Bug report KHR_materials_variants missed during clone of mesh | Babylon.js Playground (

The clone is missing the variants. I also had a look at the KHR_materials_variants class.
For me it seems like it is at least planned that KHR_materials_variants are aswell copied.

As far as I understand the code in line

the if block with metadata === KHR_materials_variants._GetExtensionMetadata(root) will never be true, because the new mesh does not got the new metadata at this point. From my point of view it should be metadata !== KHR_materials_variants._GetExtensionMetadata(root).

Or am I doing something wrong with the clone call?

Hello @DavidG , how are you doing?

Thanks for finding that bug! I believe you are right on your assumptions.

I will just cc @sebavan so we can take a look, just to be 100% sure.

Hey @srzerbetto thanks for your fast reply. Im doing fine, hope you too.
Also debugged the code yesterday a little bit. Seems to me that also the “Find root to get metadata” part is actually not searching the metadata on the existing mesh but the cloned one. From my understanding it can never find the metadata there.

Will be fixed by Fix GLTF Variants Clone by sebavan · Pull Request #13481 · BabylonJS/Babylon.js · GitHub

1 Like

Thank you for this really fast response and fix, awesome!

1 Like