From 7fcc7e19f3be0df8d366071dc7d0d87b1b3f1f34 Mon Sep 17 00:00:00 2001 From: nikitalita <69168929+nikitalita@users.noreply.github.com> Date: Thu, 31 Jul 2025 17:35:04 -0700 Subject: [PATCH] Dedupe images during GLTF Export --- modules/gltf/gltf_document.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index ec81503b48b..7dbe4ee9219 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -4339,9 +4339,12 @@ GLTFTextureIndex GLTFDocument::_set_texture(Ref p_state, Ref gltf_texture; gltf_texture.instantiate(); ERR_FAIL_COND_V(p_texture->get_image().is_null(), -1); - GLTFImageIndex gltf_src_image_i = p_state->images.size(); - p_state->images.push_back(p_texture); - p_state->source_images.push_back(p_texture->get_image()); + GLTFImageIndex gltf_src_image_i = p_state->images.find(p_texture); + if (gltf_src_image_i == -1) { + gltf_src_image_i = p_state->images.size(); + p_state->images.push_back(p_texture); + p_state->source_images.push_back(p_texture->get_image()); + } gltf_texture->set_src_image(gltf_src_image_i); gltf_texture->set_sampler(_set_sampler_for_mode(p_state, p_filter_mode, p_repeats)); GLTFTextureIndex gltf_texture_i = p_state->textures.size();