From f0f2dcaeefd79ea3e8ff940210920ce170d3afda Mon Sep 17 00:00:00 2001 From: HuZehua Date: Thu, 27 Jun 2024 17:25:56 +0800 Subject: [PATCH] Modify the accessor index in EXT_mesh_gpu_instancing, when removing unused accessors. --- lib/removeUnusedElements.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/removeUnusedElements.js b/lib/removeUnusedElements.js index 4b31186d..85af6090 100644 --- a/lib/removeUnusedElements.js +++ b/lib/removeUnusedElements.js @@ -142,6 +142,26 @@ Remove.accessor = function (gltf, accessorId) { } }); }); + + if (usesExtension(gltf, "EXT_mesh_gpu_instancing")) { + ForEach.node(gltf, function (node) { + if ( + defined(node.extensions) && + defined(node.extensions.EXT_mesh_gpu_instancing) + ) { + Object.keys(node.extensions.EXT_mesh_gpu_instancing.attributes).forEach( + function (key) { + const attributeAccessorId = + node.extensions.EXT_mesh_gpu_instancing.attributes[key]; + if (attributeAccessorId > accessorId) { + node.extensions.EXT_mesh_gpu_instancing.attributes[key] = + attributeAccessorId - 1; + } + }, + ); + } + }); + } }; Remove.buffer = function (gltf, bufferId) {