Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2020-06-16 22:35:01 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-06-16 22:35:01 +0300
commit5b4ed4e574ab7c595a88b0ca8af2ae6ba7e16390 (patch)
tree59f5808edf4e3362edc4d6a2fb63cd9dfe7bce40 /io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
parent09508f2dcf2a6af149b7817d9337333e9a0f2d4b (diff)
glTF importer: improve the layout of nodes in the material graph
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py')
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py74
1 files changed, 63 insertions, 11 deletions
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