[Bf-extensions-cvs] [5a774a6d] master: glTF importer/exporter: Various fix for node tree (shader)

Julien Duroure noreply at git.blender.org
Mon Jan 9 11:38:18 CET 2023


Commit: 5a774a6dad4378f173ec7fdcdcd406048fcc9a29
Author: Julien Duroure
Date:   Mon Jan 9 11:38:14 2023 +0100
Branches: master
https://developer.blender.org/rBA5a774a6dad4378f173ec7fdcdcd406048fcc9a29

glTF importer/exporter: Various fix for node tree (shader)

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

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
M	io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
M	io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py
M	io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_specular.py
M	io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index a1b1a925..8235ae8a 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, 5, 12),
+    "version": (3, 5, 13),
     'blender': (3, 4, 0),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
index c0d17fd3..edbb1354 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
@@ -68,7 +68,7 @@ def gather_material(blender_material, active_uvmap_index, export_settings):
     base_material = gltf2_io.Material(
         alpha_cutoff=__gather_alpha_cutoff(blender_material, export_settings),
         alpha_mode=__gather_alpha_mode(blender_material, export_settings),
-        double_sided=__gather_double_sided(blender_material, export_settings),
+        double_sided=__gather_double_sided(blender_material, extensions, export_settings),
         emissive_factor=emissive_factor,
         emissive_texture=emissive_texture,
         extensions=extensions,
@@ -196,7 +196,12 @@ def __gather_alpha_mode(blender_material, export_settings):
     return None
 
 
-def __gather_double_sided(blender_material, export_settings):
+def __gather_double_sided(blender_material, extensions, export_settings):
+
+    # If user create a volume extension, we force double sided to False
+    if 'KHR_materials_volume' in extensions:
+        return False
+
     if not blender_material.use_backface_culling:
         return True
 
@@ -358,7 +363,7 @@ def __export_unlit(blender_material, active_uvmap_index, export_settings):
     base_material = gltf2_io.Material(
         alpha_cutoff=__gather_alpha_cutoff(blender_material, export_settings),
         alpha_mode=__gather_alpha_mode(blender_material, export_settings),
-        double_sided=__gather_double_sided(blender_material, export_settings),
+        double_sided=__gather_double_sided(blender_material, {}, export_settings),
         extensions={"KHR_materials_unlit": Extension("KHR_materials_unlit", {}, required=False)},
         extras=__gather_extras(blender_material, export_settings),
         name=__gather_name(blender_material, export_settings),
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
index 0af88f04..96cd8e50 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
@@ -73,12 +73,13 @@ def pbr_specular_glossiness(mh):
     )
 
     if mh.pymat.occlusion_texture is not None:
-        node = make_settings_node(mh)
-        node.location = (610, -1060)
+        if mh.settings_node is None:
+            mh.settings_node = make_settings_node(mh)
+            mh.settings_node.location = (610, -1060)
         occlusion(
             mh,
             location=(510, -970),
-            occlusion_socket=node.inputs['Occlusion'],
+            occlusion_socket=mh.settings_node.inputs['Occlusion'],
         )
 
 
@@ -123,7 +124,7 @@ def specular_glossiness(mh, location, specular_socket, roughness_socket):
             node.location = x - 140, y
             node.blend_type = 'MULTIPLY'
             # Outputs
-            mh.node_tree.links.new(specular_socket, node.outputs[0])
+            mh.node_tree.links.new(specular_socket, node.outputs[2])
             # Inputs
             node.inputs['Factor'].default_value = 1.0
             specular_socket = node.inputs[6]
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py
index 91c202eb..c16cc9fa 100644
--- a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py
@@ -46,7 +46,7 @@ def sheen(  mh,
             node.location = x_sheenColor - 140, y_sheenColor
             node.blend_type = 'MULTIPLY'
             # Outputs
-            mh.node_tree.links.new(sheenColor_socket, node.outputs[0])
+            mh.node_tree.links.new(sheenColor_socket, node.outputs[2])
             # Inputs
             node.inputs['Factor'].default_value = 1.0
             sheenColor_socket = node.inputs[6]
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_specular.py b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_specular.py
index 35afcc3e..80e46c27 100644
--- a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_specular.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_specular.py
@@ -341,7 +341,7 @@ def original_specular(  mh,
                 node.location = x_specularcolor - 140, y_specularcolor
                 node.blend_type = 'MULTIPLY'
                 # Outputs
-                mh.node_tree.links.new(original_specularcolor_socket, node.outputs[0])
+                mh.node_tree.links.new(original_specularcolor_socket, node.outputs[2])
                 # Inputs
                 node.inputs['Factor'].default_value = 1.0
                 original_specularcolor_socket = node.inputs[6]
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
index 679dd8b0..f9866764 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
@@ -64,11 +64,12 @@ def pbr_metallic_roughness(mh: MaterialHelper):
             need_volume_node = True
 
             # We also need glTF Material Output Node, to set thicknessFactor and thicknessTexture
-            mh.settings_node = make_settings_node(mh)
-            mh.settings_node.location = additional_location
-            mh.settings_node.width = 180
-            volume_location = additional_location
-            additional_location = additional_location[0], additional_location[1] - 150
+            if mh.settings_node is None:
+                mh.settings_node = make_settings_node(mh)
+                mh.settings_node.location = additional_location
+                mh.settings_node.width = 180
+                volume_location = additional_location
+                additional_location = additional_location[0], additional_location[1] - 150
 
     need_velvet_node = False
     if mh.pymat.extensions and 'KHR_materials_sheen' in mh.pymat.extensions:
@@ -322,7 +323,7 @@ def emission(mh: MaterialHelper, location, color_socket, strength_socket):
             node.location = x - 140, y
             node.blend_type = 'MULTIPLY'
             # Outputs
-            mh.node_tree.links.new(color_socket, node.outputs[0])
+            mh.node_tree.links.new(color_socket, node.outputs[2])
             # Inputs
             node.inputs['Factor'].default_value = 1.0
             color_socket = node.inputs[6]



More information about the Bf-extensions-cvs mailing list