[Bf-extensions-cvs] [5b4ed4e5] master: glTF importer: improve the layout of nodes in the material graph

Julien Duroure noreply at git.blender.org
Tue Jun 16 21:35:26 CEST 2020


Commit: 5b4ed4e574ab7c595a88b0ca8af2ae6ba7e16390
Author: Julien Duroure
Date:   Tue Jun 16 21:35:01 2020 +0200
Branches: master
https://developer.blender.org/rBA5b4ed4e574ab7c595a88b0ca8af2ae6ba7e16390

glTF importer: improve the layout of nodes in the material graph

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

M	io_scene_gltf2/__init__.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 130f7c1b..a7a4a84c 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, 3, 17),
+    "version": (1, 3, 18),
     'blender': (2, 90, 0),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
index 7e750e52..00bd08d2 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
@@ -56,58 +56,111 @@ def pbr_metallic_roughness(mh: MaterialHelper):
         make_alpha_socket=False,
     )
 
+    locs = calc_locations(mh)
+
     emission(
         mh,
-        location=(-200, 860),
+        location=locs['emission'],
         color_socket=pbr_node.inputs['Emission'],
     )
 
     base_color(
         mh,
-        location=(-200, 380),
+        location=locs['base_color'],
         color_socket=pbr_node.inputs['Base Color'],
         alpha_socket=pbr_node.inputs['Alpha'] if not mh.is_opaque() else None,
     )
 
     metallic_roughness(
         mh,
-        location=(-200, -100),
+        location=locs['metallic_roughness'],
         metallic_socket=pbr_node.inputs['Metallic'],
         roughness_socket=pbr_node.inputs['Roughness'],
     )
 
     normal(
         mh,
-        location=(-200, -580),
+        location=locs['normal'],
         normal_socket=pbr_node.inputs['Normal'],
     )
 
     if mh.pymat.occlusion_texture is not None:
-        node = make_settings_node(mh, location=(610, -1060))
+        node = make_settings_node(mh)
+        node.location = 40, -370
+        node.width = 180
         occlusion(
             mh,
-            location=(510, -970),
+            location=locs['occlusion'],
             occlusion_socket=node.inputs['Occlusion'],
         )
 
     clearcoat(
         mh,
-        location=(-200, -1060),
+        location=locs['clearcoat'],
         clearcoat_socket=pbr_node.inputs['Clearcoat'],
     )
 
     clearcoat_roughness(
         mh,
-        location=(-200, -1540),
+        location=locs['clearcoat_roughness'],
         roughness_socket=pbr_node.inputs['Clearcoat Roughness'],
     )
 
     clearcoat_normal(
         mh,
-        location=(-200, -2020),
+        location=locs['clearcoat_normal'],
         normal_socket=pbr_node.inputs['Clearcoat Normal'],
     )
 
+
+def calc_locations(mh):
+    """Calculate locations to place each bit of the node graph at."""
+    # Lay the blocks out top-to-bottom, aligned on the right
+    x = -200
+    y = 0
+    height = 460  # height of each block
+    locs = {}
+
+    try:
+        clearcoat_ext = mh.pymat.extensions['KHR_materials_clearcoat']
+    except Exception:
+        clearcoat_ext = {}
+
+    locs['base_color'] = (x, y)
+    if mh.pymat.pbr_metallic_roughness.base_color_texture is not None or mh.vertex_color:
+        y -= height
+    locs['metallic_roughness'] = (x, y)
+    if mh.pymat.pbr_metallic_roughness.metallic_roughness_texture is not None:
+        y -= height
+    locs['clearcoat'] = (x, y)
+    if 'clearcoatTexture' in clearcoat_ext:
+        y -= height
+    locs['clearcoat_roughness'] = (x, y)
+    if 'clearcoatRoughnessTexture' in clearcoat_ext:
+        y -= height
+    locs['emission'] = (x, y)
+    if mh.pymat.emissive_texture is not None:
+        y -= height
+    locs['normal'] = (x, y)
+    if mh.pymat.normal_texture is not None:
+        y -= height
+    locs['clearcoat_normal'] = (x, y)
+    if 'clearcoatNormalTexture' in clearcoat_ext:
+        y -= height
+    locs['occlusion'] = (x, y)
+    if mh.pymat.occlusion_texture is not None:
+        y -= height
+
+    # Center things
+    total_height = -y
+    y_offset = total_height / 2 - 20
+    for key in locs:
+        x, y = locs[key]
+        locs[key] = (x, y + y_offset)
+
+    return locs
+
+
 # These functions each create one piece of the node graph, slotting
 # their outputs into the given socket, or setting its default value.
 # location is roughly the upper-right corner of where to put nodes.
@@ -480,14 +533,13 @@ def make_output_nodes(
     return emission_socket, alpha_socket
 
 
-def make_settings_node(mh, location):
+def make_settings_node(mh):
     """
     Make a Group node with a hookup for Occlusion. No effect in Blender, but
     used to tell the exporter what the occlusion map should be.
     """
     node = mh.node_tree.nodes.new('ShaderNodeGroup')
     node.node_tree = get_settings_group()
-    node.location = location
     return node



More information about the Bf-extensions-cvs mailing list