bugfix the thumbnail error when publishing with emissive map & maps without RGB channel

This commit is contained in:
Kayla Man 2024-01-12 18:32:42 +08:00
parent 046154037b
commit df7b868371
2 changed files with 62 additions and 8 deletions

View file

@ -643,3 +643,53 @@ def prompt_new_file_with_mesh(mesh_filepath):
return
return project_mesh
def has_rgb_channel_in_texture_set(texture_set_name, map_identifier):
"""Function to check whether the texture has RGB channel.
Args:
texture_set_name (str): Name of Texture Set
map_identifier (str): Map identifier
Returns:
colorspace_dict: A dictionary which stores the boolean
value of textures having RGB channels
"""
texture_stack = substance_painter.textureset.Stack.from_name(texture_set_name)
# 2D_View is always True as it exports all texture maps
colorspace_dict = {"2D_View": True}
colorspace_dict["BaseColor"] = texture_stack.get_channel(
substance_painter.textureset.ChannelType.BaseColor).is_color()
colorspace_dict["Roughness"] = texture_stack.get_channel(
substance_painter.textureset.ChannelType.Roughness).is_color()
colorspace_dict["Metallic"] = texture_stack.get_channel(
substance_painter.textureset.ChannelType.Metallic).is_color()
colorspace_dict["Height"] = texture_stack.get_channel(
substance_painter.textureset.ChannelType.Height).is_color()
colorspace_dict["Normal"] = texture_stack.get_channel(
substance_painter.textureset.ChannelType.Normal).is_color()
return colorspace_dict.get(map_identifier, False)
def texture_set_filtering(texture_set_same, template):
"""Function to check whether some specific textures(e.g. Emissive)
are parts of the texture stack in Substance Painter
Args:
texture_set_same (str): Name of Texture Set
template (str): texture template name
Returns:
texture_filter: A dictionary which stores the boolean
value of whether the texture exist in the channel.
"""
texture_filter = {}
channel_stack = substance_painter.textureset.Stack.from_name(
texture_set_same)
has_emissive = channel_stack.has_channel(
substance_painter.textureset.ChannelType.Emissive)
map_identifier = strip_template(template)
if map_identifier == "Emissive":
texture_filter[map_identifier] = has_emissive
return texture_filter.get(map_identifier, True)

View file

@ -7,7 +7,9 @@ from openpype.pipeline import publish
import substance_painter.textureset
from openpype.hosts.substancepainter.api.lib import (
get_parsed_export_maps,
strip_template
strip_template,
has_rgb_channel_in_texture_set,
texture_set_filtering
)
from openpype.pipeline.create import get_subset_name
from openpype.client import get_asset_by_name
@ -39,11 +41,12 @@ class CollectTextureSet(pyblish.api.InstancePlugin):
for (texture_set_name, stack_name), template_maps in maps.items():
self.log.info(f"Processing {texture_set_name}/{stack_name}")
for template, outputs in template_maps.items():
self.log.info(f"Processing {template}")
self.create_image_instance(instance, template, outputs,
asset_doc=asset_doc,
texture_set_name=texture_set_name,
stack_name=stack_name)
if texture_set_filtering(texture_set_name, template):
self.log.info(f"Processing {template}")
self.create_image_instance(instance, template, outputs,
asset_doc=asset_doc,
texture_set_name=texture_set_name,
stack_name=stack_name)
def create_image_instance(self, instance, template, outputs,
asset_doc, texture_set_name, stack_name):
@ -78,7 +81,6 @@ class CollectTextureSet(pyblish.api.InstancePlugin):
# Always include the map identifier
map_identifier = strip_template(template)
suffix += f".{map_identifier}"
image_subset = get_subset_name(
# TODO: The family actually isn't 'texture' currently but for now
# this is only done so the subset name starts with 'texture'
@ -132,7 +134,9 @@ class CollectTextureSet(pyblish.api.InstancePlugin):
# Store color space with the instance
# Note: The extractor will assign it to the representation
colorspace = outputs[0].get("colorSpace")
if colorspace:
has_rgb_channel = has_rgb_channel_in_texture_set(
texture_set_name, map_identifier)
if colorspace and has_rgb_channel:
self.log.debug(f"{image_subset} colorspace: {colorspace}")
image_instance.data["colorspace"] = colorspace