diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-05-07 10:59:14 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-05-07 10:59:14 +0300 |
commit | 447abeb9be69dcef24ea9c47bb2bde4488f9cb83 (patch) | |
tree | 1bb1318fb212e1371febde3e5410e1bc15efda86 /io_scene_gltf2/blender | |
parent | ae8d56888683894676f924232b1f66c879c8a82c (diff) |
glTF exporter: image texture: manage rough without metal, metal without rough
Diffstat (limited to 'io_scene_gltf2/blender')
4 files changed, 39 insertions, 11 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py index 85985e41..8550610f 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py @@ -168,7 +168,7 @@ def __get_image_data(sockets_or_slots, export_settings) -> gltf2_blender_image.E composed_image[2] = image[source_channel] elif socket.name == 'Roughness': composed_image[1] = image[source_channel] - elif socket.name == 'Occlusion' and len(sockets_or_slots) > 2: + elif socket.name == 'Occlusion' and len(sockets_or_slots) > 1 and sockets_or_slots[1] is not None: composed_image[0] = image[source_channel] else: composed_image.update(image) 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 1242c08d..1eccdeeb 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py @@ -165,15 +165,28 @@ def __gather_orm_texture(blender_material, export_settings): metallic_socket = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Metallic") roughness_socket = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Roughness") - if metallic_socket is None or roughness_socket is None\ - or not __has_image_node_from_socket(metallic_socket)\ - or not __has_image_node_from_socket(roughness_socket): + + hasMetal = metallic_socket is not None and __has_image_node_from_socket(metallic_socket) + hasRough = roughness_socket is not None and __has_image_node_from_socket(roughness_socket) + + if not hasMetal and not hasRough: metallic_roughness = gltf2_blender_get.get_socket_or_texture_slot_old(blender_material, "MetallicRoughness") if metallic_roughness is None or not __has_image_node_from_socket(metallic_roughness): return None - return (occlusion, metallic_roughness, metallic_roughness) + result = (occlusion, metallic_roughness) + elif not hasMetal: + result = (occlusion, roughness_socket) + elif not hasRough: + result = (occlusion, metallic_socket) + else: + result = (occlusion, roughness_socket, metallic_socket) + + # Double-check this will past the filter in texture_info (otherwise there are different resolutions or other problems). + info = gltf2_blender_gather_texture_info.gather_texture_info(result, export_settings) + if info is None: + return None - return (occlusion, roughness_socket, metallic_socket) + return result def __gather_occlusion_texture(blender_material, orm_texture, export_settings): if orm_texture is not None: 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 ffbf9914..26ef0f0a 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 @@ -130,11 +130,18 @@ def __gather_metallic_roughness_texture(blender_material, orm_texture, export_se metallic_socket = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Metallic") roughness_socket = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Roughness") - if metallic_socket is None and roughness_socket is None: - metallic_roughness = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "MetallicRoughness") - if metallic_roughness is None: - metallic_roughness = gltf2_blender_get.get_socket_or_texture_slot_old(blender_material, "MetallicRoughness") + hasMetal = metallic_socket is not None and __has_image_node_from_socket(metallic_socket) + hasRough = roughness_socket is not None and __has_image_node_from_socket(roughness_socket) + + if not hasMetal and not hasRough: + metallic_roughness = gltf2_blender_get.get_socket_or_texture_slot_old(blender_material, "MetallicRoughness") + if metallic_roughness is None or not __has_image_node_from_socket(metallic_roughness): + return None texture_input = (metallic_roughness,) + elif not hasMetal: + texture_input = (roughness_socket,) + elif not hasRough: + texture_input = (metallic_socket,) else: texture_input = (metallic_socket, roughness_socket) @@ -149,3 +156,11 @@ def __gather_roughness_factor(blender_material, export_settings): return roughness_socket.default_value return None +def __has_image_node_from_socket(socket): + result = gltf2_blender_search_node_tree.from_socket( + socket, + gltf2_blender_search_node_tree.FilterByType(bpy.types.ShaderNodeTexImage)) + if not result: + return False + return True + diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py index 06cfaaed..354ddf2c 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py @@ -57,7 +57,7 @@ def __filter_texture_info(blender_shader_sockets_or_texture_slots, export_settin if any(any(a != b for a, b in zip(__get_tex_from_socket(elem).shader_node.image.size, resolution)) for elem in blender_shader_sockets_or_texture_slots): def format_image(image_node): - return "{} ({}x{})".format(image_node.name, image_node.image.size[0], image_node.image.size[1]) + return "{} ({}x{})".format(image_node.image.name, image_node.image.size[0], image_node.image.size[1]) images = [format_image(__get_tex_from_socket(elem).shader_node) for elem in blender_shader_sockets_or_texture_slots] |