From 48c8d6c23010fc73d62f44e366901f08680d08da Mon Sep 17 00:00:00 2001 From: Julien Duroure <julien.duroure@gmail.com> Date: Fri, 10 Jul 2020 12:55:01 +0200 Subject: [PATCH] glTF export: Fix T78754: export alpha scalar value (not coming from texture) --- io_scene_gltf2/__init__.py | 2 +- ...f2_blender_gather_materials_pbr_metallic_roughness.py | 7 +++++-- .../blender/imp/gltf2_blender_pbrMetallicRoughness.py | 9 +++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 2e19cbeb8..211839f80 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, 29), + "version": (1, 3, 30), 'blender': (2, 90, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py index 544937992..7913d175a 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py @@ -47,6 +47,9 @@ def __filter_pbr_material(blender_material, export_settings): def __gather_base_color_factor(blender_material, export_settings): + alpha_socket = gltf2_blender_get.get_socket(blender_material, "Alpha") + alpha = alpha_socket.default_value if alpha_socket is not None and not alpha_socket.is_linked else 1.0 + base_color_socket = gltf2_blender_get.get_socket(blender_material, "Base Color") if base_color_socket is None: base_color_socket = gltf2_blender_get.get_socket(blender_material, "BaseColor") @@ -57,7 +60,7 @@ def __gather_base_color_factor(blender_material, export_settings): if not isinstance(base_color_socket, bpy.types.NodeSocket): return None if not base_color_socket.is_linked: - return list(base_color_socket.default_value) + return list(base_color_socket.default_value)[:3] + [alpha] texture_node = __get_tex_from_socket(base_color_socket) if texture_node is None: @@ -85,7 +88,7 @@ def __gather_base_color_factor(blender_material, export_settings): .format(multiply_node.name)) return None - return list(factor_socket.default_value) + return list(factor_socket.default_value)[:3] + [alpha] def __gather_base_color_texture(blender_material, export_settings): diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py index 00bd08d22..deb9e301e 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py @@ -233,7 +233,7 @@ def base_color( base_color_factor = [1, 1, 1, 1] if base_color_texture is None and not mh.vertex_color: - color_socket.default_value = base_color_factor + color_socket.default_value = base_color_factor[:3] + [1] if alpha_socket is not None: alpha_socket.default_value = base_color_factor[3] return @@ -242,10 +242,7 @@ def base_color( needs_color_factor = base_color_factor[:3] != [1, 1, 1] needs_alpha_factor = base_color_factor[3] != 1.0 and alpha_socket is not None if needs_color_factor or needs_alpha_factor: - # For now, always create the color factor node because the exporter - # reads the alpha value from here. Can get rid of "or needs_alpha_factor" - # when it learns to understand the alpha socket. - if needs_color_factor or needs_alpha_factor: + if needs_color_factor: node = mh.node_tree.nodes.new('ShaderNodeMixRGB') node.label = 'Color Factor' node.location = x - 140, y @@ -255,7 +252,7 @@ def base_color( # Inputs node.inputs['Fac'].default_value = 1.0 color_socket = node.inputs['Color1'] - node.inputs['Color2'].default_value = base_color_factor + node.inputs['Color2'].default_value = base_color_factor[:3] + [1] if needs_alpha_factor: node = mh.node_tree.nodes.new('ShaderNodeMath') -- GitLab