Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2076 - rollback merging channels #2078

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def export_anisotropy(blender_material, export_settings):
anisotropy_texture, uvmap_info , udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
anisotropy_data['tex_socket'],
(anisotropy_data['tex_socket'],),
(),
export_settings,
)
anisotropy_extension['anisotropyTexture'] = anisotropy_texture
Expand All @@ -119,7 +118,6 @@ def export_anisotropy_from_grayscale_textures(blender_material, export_settings)
anisotropyTexture, uvmap_info, _, _ = gltf2_blender_gather_texture_info.gather_texture_info(
primary_socket,
sockets,
(),
export_settings,
filter_type='ANY')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def export_clearcoat(blender_material, export_settings):
clearcoat_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
clearcoat_socket,
clearcoat_roughness_slots,
(),
export_settings,
)
clearcoat_extension['clearcoatTexture'] = clearcoat_texture
Expand All @@ -77,7 +76,6 @@ def export_clearcoat(blender_material, export_settings):
clearcoat_roughness_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
clearcoat_roughness_socket,
clearcoat_roughness_slots,
(),
export_settings,
)
clearcoat_extension['clearcoatRoughnessTexture'] = clearcoat_roughness_texture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def export_emission_texture(blender_material, export_settings):
emissive = get_socket(blender_material, "Emissive")
if emissive.socket is None:
emissive = get_socket_from_gltf_material_node(blender_material, "Emissive")
emissive_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(emissive, (emissive,), (), export_settings)
emissive_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(emissive, (emissive,), export_settings)
return emissive_texture, {'emissiveTexture': uvmap_info}, {'emissiveTexture': udim_info} if len(udim_info.keys()) > 0 else {}

def export_emission_strength_extension(emissive_factor, export_settings):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def export_sheen(blender_material, export_settings):
original_sheenColor_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
sheenTint_socket,
(sheenTint_socket,),
(),
export_settings,
)
sheen_extension['sheenColorTexture'] = original_sheenColor_texture
Expand All @@ -84,7 +83,6 @@ def export_sheen(blender_material, export_settings):
original_sheenRoughness_texture, uvmap_info , udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
sheenRoughness_socket,
(sheenRoughness_socket,),
(),
export_settings,
)
sheen_extension['sheenRoughnessTexture'] = original_sheenRoughness_texture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def export_specular(blender_material, export_settings):
specular_texture, uvmap_info, udim_info, _ = gather_texture_info(
specular_socket,
(specular_socket,),
(),
export_settings,
)
specular_extension['specularTexture'] = specular_texture
Expand Down Expand Up @@ -98,7 +97,6 @@ def export_specular(blender_material, export_settings):
specularcolor_texture, uvmap_info, udim_info, _ = gather_texture_info(
speculartint_socket,
(speculartint_socket,),
(),
export_settings,
)
specular_extension['specularColorTexture'] = specularcolor_texture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def export_transmission(blender_material, export_settings):
combined_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
transmission_socket,
transmission_slots,
(),
export_settings,
)
if has_transmission_texture:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def export_volume(blender_material, export_settings):
combined_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
thickness_socket,
thickness_slots,
(),
export_settings,
)
if has_thickness_texture:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
@cached
def gather_image(
blender_shader_sockets: typing.Tuple[bpy.types.NodeSocket],
default_sockets: typing.Tuple[bpy.types.NodeSocket],
use_tile: bool,
export_settings):
if not __filter_image(blender_shader_sockets, export_settings):
return None, None, None, None

image_data, udim_image = __get_image_data(blender_shader_sockets, default_sockets, use_tile, export_settings)
image_data, udim_image = __get_image_data(blender_shader_sockets, use_tile, export_settings)

if udim_image is not None:
# We are in a UDIM case, so we return no image data
Expand Down Expand Up @@ -204,7 +203,7 @@ def __gather_uri(image_data, mime_type, name, export_settings):
return None, None


def __get_image_data(sockets, default_sockets, use_tile, export_settings) -> ExportImage:
def __get_image_data(sockets, use_tile, export_settings) -> ExportImage:
# For shared resources, such as images, we just store the portion of data that is needed in the glTF property
# in a helper class. During generation of the glTF in the exporter these will then be combined to actual binary
# resources.
Expand Down Expand Up @@ -246,22 +245,15 @@ def __get_image_data(sockets, default_sockets, use_tile, export_settings) -> Exp
# We are not in complex node setup, so we can try to get the image data from grayscale textures
return __get_image_data_grayscale_anisotropy(sockets, results, export_settings), None

return __get_image_data_mapping(sockets, default_sockets, results, use_tile, export_settings), None
return __get_image_data_mapping(sockets, results, use_tile, export_settings), None

def __get_image_data_mapping(sockets, default_sockets, results, use_tile, export_settings) -> ExportImage:
def __get_image_data_mapping(sockets, results, use_tile, export_settings) -> ExportImage:
"""
Simple mapping
Will fit for most of exported textures : RoughnessMetallic, Basecolor, normal, ...
"""
composed_image = ExportImage()

default_metallic = None
default_roughness = None
if "Metallic" in [s.name for s in default_sockets]:
default_metallic = [s for s in default_sockets if s.name == "Metallic"][0].default_value
if "Roughness" in [s.name for s in default_sockets]:
default_roughness = [s for s in default_sockets if s.name == "Roughness"][0].default_value

for result, socket in zip(results, sockets):
# Assume that user know what he does, and that channels/images are already combined correctly for pbr
# If not, we are going to keep only the first texture found
Expand Down Expand Up @@ -344,15 +336,9 @@ def __get_image_data_mapping(sockets, default_sockets, results, use_tile, export
# Since metal/roughness are always used together, make sure
# the other channel is filled.
if socket.socket.name == 'Metallic' and not composed_image.is_filled(Channel.G):
if default_roughness is not None:
composed_image.fill_with(Channel.G, default_roughness)
else:
composed_image.fill_white(Channel.G)
composed_image.fill_white(Channel.G)
elif socket.socket.name == 'Roughness' and not composed_image.is_filled(Channel.B):
if default_metallic is not None:
composed_image.fill_with(Channel.B, default_metallic)
else:
composed_image.fill_white(Channel.B)
composed_image.fill_white(Channel.B)
else:
# copy full image...eventually following sockets might overwrite things
if use_tile is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ def gather_material(blender_material, export_settings):
export_user_extensions('gather_material_hook', export_settings, mat_unlit, blender_material)
return mat_unlit, {"uv_info": uvmap_info, "vc_info": vc_info, "udim_info": udim_info}

orm_texture, default_sockets = __gather_orm_texture(blender_material, export_settings)
orm_texture = __gather_orm_texture(blender_material, export_settings)

emissive_factor = __gather_emissive_factor(blender_material, export_settings)
emissive_texture, uvmap_info_emissive, udim_info_emissive = __gather_emissive_texture(blender_material, export_settings)
extensions, uvmap_info_extensions, udim_info_extensions = __gather_extensions(blender_material, emissive_factor, export_settings)
normal_texture, uvmap_info_normal, udim_info_normal = __gather_normal_texture(blender_material, export_settings)
occlusion_texture, uvmap_info_occlusion, udim_occlusion = __gather_occlusion_texture(blender_material, orm_texture, default_sockets, export_settings)
occlusion_texture, uvmap_info_occlusion, udim_occlusion = __gather_occlusion_texture(blender_material, orm_texture, export_settings)
pbr_metallic_roughness, uvmap_info_pbr_metallic_roughness, vc_info, udim_info_prb_mr = __gather_pbr_metallic_roughness(blender_material, orm_texture, export_settings)

if any([i>1.0 for i in emissive_factor or []]) is True:
Expand Down Expand Up @@ -123,7 +123,7 @@ def gather_material(blender_material, export_settings):
continue

s = NodeSocket(node[0].outputs[0], node[1])
tex, uv_info_additional, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(s, (s,), (), export_settings)
tex, uv_info_additional, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(s, (s,), export_settings)
if tex is not None:
export_settings['exported_images'][node[0].image.name] = 1 # Fully used
uvmap_infos.update({'additional' + str(cpt_additional): uv_info_additional})
Expand Down Expand Up @@ -312,46 +312,42 @@ def __gather_orm_texture(blender_material, export_settings):
if occlusion.socket is None or not has_image_node_from_socket(occlusion, export_settings):
occlusion = get_socket_from_gltf_material_node(blender_material, "Occlusion")
if occlusion.socket is None or not has_image_node_from_socket(occlusion, export_settings):
return None, None
return None

metallic_socket = get_socket(blender_material, "Metallic")
roughness_socket = get_socket(blender_material, "Roughness")

hasMetal = metallic_socket.socket is not None and has_image_node_from_socket(metallic_socket, export_settings)
hasRough = roughness_socket.socket is not None and has_image_node_from_socket(roughness_socket, export_settings)

default_sockets = ()
# Warning: for default socket, do not use NodeSocket object, because it will break cache
# Using directlty the Blender socket object
if not hasMetal and not hasRough:
metallic_roughness = get_socket_from_gltf_material_node(blender_material, "MetallicRoughness")
if metallic_roughness.socket is None or not has_image_node_from_socket(metallic_roughness, export_settings):
return None, default_sockets
return None
result = (occlusion, metallic_roughness)
elif not hasMetal:
result = (occlusion, roughness_socket)
default_sockets = (metallic_socket.socket,)
elif not hasRough:
result = (occlusion, metallic_socket)
default_sockets = (roughness_socket.socket,)
else:
result = (occlusion, roughness_socket, metallic_socket)
default_sockets = ()

if not gltf2_blender_gather_texture_info.check_same_size_images(result, export_settings):
print_console("INFO",
"Occlusion and metal-roughness texture will be exported separately "
"(use same-sized images if you want them combined)")
return None, ()
return None

# Double-check this will past the filter in texture_info
info, _, _, _ = gltf2_blender_gather_texture_info.gather_texture_info(result[0], result, default_sockets, export_settings)
info, _, _, _ = gltf2_blender_gather_texture_info.gather_texture_info(result[0], result, export_settings)
if info is None:
return None, ()
return None

return result, default_sockets
return result

def __gather_occlusion_texture(blender_material, orm_texture, default_sockets, export_settings):
def __gather_occlusion_texture(blender_material, orm_texture, export_settings):
occlusion = get_socket(blender_material, "Occlusion")
if occlusion.socket is None:
occlusion = get_socket_from_gltf_material_node(blender_material, "Occlusion")
Expand All @@ -360,7 +356,6 @@ def __gather_occlusion_texture(blender_material, orm_texture, default_sockets, e
occlusion_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_material_occlusion_texture_info_class(
occlusion,
orm_texture or (occlusion,),
default_sockets,
export_settings)
return occlusion_texture, \
{"occlusionTexture" : uvmap_info}, {'occlusionTexture': udim_info } if len(udim_info.keys()) > 0 else {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __gather_base_color_texture(blender_material, export_settings):
if not inputs:
return None, {}, {}, None

tex, uvmap_info, udim_info, factor = gather_texture_info(inputs[0], inputs, (), export_settings)
tex, uvmap_info, udim_info, factor = gather_texture_info(inputs[0], inputs, export_settings)
return tex, {'baseColorTexture': uvmap_info}, {'baseColorTexture': udim_info} if len(udim_info.keys()) > 0 else {}, factor


Expand Down Expand Up @@ -150,7 +150,6 @@ def __gather_metallic_roughness_texture(blender_material, orm_texture, export_se
hasMetal = metallic_socket.socket is not None and has_image_node_from_socket(metallic_socket, export_settings)
hasRough = roughness_socket.socket is not None and has_image_node_from_socket(roughness_socket, export_settings)

default_sockets = ()
# Warning: for default socket, do not use NodeSocket object, because it will break cache
# Using directlty the Blender socket object
if not hasMetal and not hasRough:
Expand All @@ -159,18 +158,14 @@ def __gather_metallic_roughness_texture(blender_material, orm_texture, export_se
return None, {}, {}, None
elif not hasMetal:
texture_input = (roughness_socket,)
default_sockets = (metallic_socket.socket,)
elif not hasRough:
texture_input = (metallic_socket,)
default_sockets = (roughness_socket.socket,)
else:
texture_input = (metallic_socket, roughness_socket)
default_sockets = ()

tex, uvmap_info, udim_info, factor = gather_texture_info(
texture_input[0],
orm_texture or texture_input,
default_sockets,
export_settings,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def gather_base_color_texture(info, export_settings):
unlit_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
sockets[0],
sockets,
(),
export_settings,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
@cached
def gather_texture(
blender_shader_sockets: typing.Tuple[bpy.types.NodeSocket],
default_sockets,
use_tile: bool,
export_settings):
"""
Expand All @@ -44,7 +43,7 @@ def gather_texture(
if not __filter_texture(blender_shader_sockets, export_settings):
return None, None, False

source, webp_image, image_data, factor, udim_image = __gather_source(blender_shader_sockets, default_sockets, use_tile, export_settings)
source, webp_image, image_data, factor, udim_image = __gather_source(blender_shader_sockets, use_tile, export_settings)

exts, remove_source = __gather_extensions(blender_shader_sockets, source, webp_image, image_data, export_settings)

Expand Down Expand Up @@ -207,8 +206,8 @@ def __gather_sampler(blender_shader_sockets, export_settings):
export_settings)


def __gather_source(blender_shader_sockets, default_sockets, use_tile, export_settings):
source, image_data, factor, udim_image = gltf2_blender_gather_image.gather_image(blender_shader_sockets, default_sockets, use_tile, export_settings)
def __gather_source(blender_shader_sockets, use_tile, export_settings):
source, image_data, factor, udim_image = gltf2_blender_gather_image.gather_image(blender_shader_sockets, use_tile, export_settings)


if export_settings['gltf_keep_original_textures'] is False \
Expand Down
Loading