[Bf-extensions-cvs] [b629ab42] master: glTF importer: omit texture mapping & UVMap node when not needed

Julien Duroure noreply at git.blender.org
Sat Feb 22 08:16:28 CET 2020


Commit: b629ab427c4ee766bfae52f188287dd8ca767aae
Author: Julien Duroure
Date:   Sat Feb 22 08:16:03 2020 +0100
Branches: master
https://developer.blender.org/rBAb629ab427c4ee766bfae52f188287dd8ca767aae

glTF importer: omit texture mapping & UVMap node when not needed

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/imp/gltf2_blender_texture.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 0ea3e23f..2efef1d9 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 2, 22),
+    "version": (1, 2, 23),
     'blender': (2, 82, 7),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_texture.py b/io_scene_gltf2/blender/imp/gltf2_blender_texture.py
index e7ca60e6..678fd2af 100644
--- a/io_scene_gltf2/blender/imp/gltf2_blender_texture.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_texture.py
@@ -64,10 +64,16 @@ def texture(
     x -= 340
 
     # UV Transform (for KHR_texture_transform)
-    mapping = mh.node_tree.nodes.new('ShaderNodeMapping')
-    mapping.location = x - 160, y + 30
-    mapping.vector_type = 'POINT'
-    if tex_info.extensions and 'KHR_texture_transform' in tex_info.extensions:
+    needs_tex_transform = 'KHR_texture_transform' in (tex_info.extensions or {})
+    if needs_tex_transform:
+        mapping = mh.node_tree.nodes.new('ShaderNodeMapping')
+        mapping.location = x - 160, y + 30
+        mapping.vector_type = 'POINT'
+        # Outputs
+        mh.node_tree.links.new(uv_socket, mapping.outputs[0])
+        # Inputs
+        uv_socket = mapping.inputs[0]
+
         transform = tex_info.extensions['KHR_texture_transform']
         transform = texture_transform_gltf_to_blender(transform)
         mapping.inputs['Location'].default_value[0] = transform['offset'][0]
@@ -75,25 +81,21 @@ def texture(
         mapping.inputs['Rotation'].default_value[2] = transform['rotation']
         mapping.inputs['Scale'].default_value[0] = transform['scale'][0]
         mapping.inputs['Scale'].default_value[1] = transform['scale'][1]
-    # Outputs
-    mh.node_tree.links.new(uv_socket, mapping.outputs[0])
-    # Inputs
-    uv_socket = mapping.inputs[0]
 
-    x -= 260
+        x -= 260
 
     # UV Map
-    uv_map = mh.node_tree.nodes.new('ShaderNodeUVMap')
-    uv_map.location = x - 160, y - 70
-    # Get UVMap
     uv_idx = tex_info.tex_coord or 0
     try:
         uv_idx = tex_info.extensions['KHR_texture_transform']['texCoord']
     except Exception:
         pass
-    uv_map.uv_map = 'UVMap' if uv_idx == 0 else 'UVMap.%03d' % uv_idx
-    # Outputs
-    mh.node_tree.links.new(uv_socket, uv_map.outputs[0])
+    if uv_idx != 0 or needs_tex_transform:
+        uv_map = mh.node_tree.nodes.new('ShaderNodeUVMap')
+        uv_map.location = x - 160, y - 70
+        uv_map.uv_map = 'UVMap' if uv_idx == 0 else 'UVMap.%03d' % uv_idx
+        # Outputs
+        mh.node_tree.links.new(uv_socket, uv_map.outputs[0])
 
 def set_filtering(tex_img, pysampler):
     """Set the filtering/interpolation on an Image Texture from the glTf sampler."""



More information about the Bf-extensions-cvs mailing list