From bccd6c669db6dbbf9901ea806780afaca62d5cb2 Mon Sep 17 00:00:00 2001
From: Julien Duroure <julien.duroure@gmail.com>
Date: Sun, 25 Sep 2022 16:56:06 +0200
Subject: [PATCH] glTF exporter: fix resolve uvmap index, using now correct
 mesh

---
 io_scene_gltf2/__init__.py                        |  2 +-
 .../exp/gltf2_blender_gather_texture_info.py      | 15 +++++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 07e4824a8..1eeb3e11d 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -4,7 +4,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin SchmithĂĽsen, Jim Eckerlein, and many external contributors',
-    "version": (3, 4, 18),
+    "version": (3, 4, 19),
     'blender': (3, 3, 0),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py
index 5fe2da329..01d261beb 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py
@@ -166,12 +166,15 @@ def __gather_texture_transform_and_tex_coord(primary_socket, export_settings):
     use_active_uvmap = True
     if node and node.type == 'UVMAP' and node.uv_map:
         # Try to gather map index.
-        for blender_mesh in bpy.data.meshes:
-            i = blender_mesh.uv_layers.find(node.uv_map)
-            if i >= 0:
-                texcoord_idx = i
-                use_active_uvmap = False
-                break
+        node_tree = node.id_data
+        for mesh in bpy.data.meshes:
+            for material in mesh.materials:
+                if material.node_tree == node_tree:
+                    i = mesh.uv_layers.find(node.uv_map)
+                    if i >= 0:
+                        texcoord_idx = i
+                        use_active_uvmap = False
+                        break
 
     return texture_transform, texcoord_idx or None, use_active_uvmap
 
-- 
GitLab