From df7b8683716ff5bb2ab6b648ab22a62e2a555fd3 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 12 Jan 2024 18:32:42 +0800 Subject: [PATCH 1/6] bugfix the thumbnail error when publishing with emissive map & maps without RGB channel --- openpype/hosts/substancepainter/api/lib.py | 50 +++++++++++++++++++ .../publish/collect_textureset_images.py | 20 +++++--- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index 1cb480b552..f46426388b 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -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) diff --git a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py index 316f72509e..4c3398d5b4 100644 --- a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py +++ b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py @@ -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 From 72848657af4e52aa6d037fbf1f35c2b4548efeee Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 12 Jan 2024 18:44:18 +0800 Subject: [PATCH 2/6] hound shut --- openpype/hosts/substancepainter/api/lib.py | 6 ++++-- .../plugins/publish/collect_textureset_images.py | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index f46426388b..67229a75bf 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -656,7 +656,9 @@ def has_rgb_channel_in_texture_set(texture_set_name, map_identifier): 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) + 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( @@ -686,7 +688,7 @@ def texture_set_filtering(texture_set_same, template): """ texture_filter = {} channel_stack = substance_painter.textureset.Stack.from_name( - texture_set_same) + texture_set_same) has_emissive = channel_stack.has_channel( substance_painter.textureset.ChannelType.Emissive) map_identifier = strip_template(template) diff --git a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py index 4c3398d5b4..f535bfa2a6 100644 --- a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py +++ b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py @@ -44,9 +44,9 @@ class CollectTextureSet(pyblish.api.InstancePlugin): 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) + 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): From 6410f381f34625defa91250a8e529e47cb40a8a6 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 12 Jan 2024 18:45:40 +0800 Subject: [PATCH 3/6] hound shut --- .../plugins/publish/collect_textureset_images.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py index f535bfa2a6..9d6aa06872 100644 --- a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py +++ b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py @@ -43,10 +43,11 @@ class CollectTextureSet(pyblish.api.InstancePlugin): for template, outputs in template_maps.items(): 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) + 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): From 00eb748b4b64339b00799b5fa4c41ad42426f73c Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Sat, 13 Jan 2024 00:15:46 +0800 Subject: [PATCH 4/6] code tweaks on has_rgb_channel_in_texture_set function & add publish data into the imageinstance --- openpype/hosts/substancepainter/api/lib.py | 48 +++++-------------- .../publish/collect_textureset_images.py | 12 ++--- .../plugins/publish/validate_ouput_maps.py | 1 + 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index 67229a75bf..896cca79b0 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -653,45 +653,23 @@ def has_rgb_channel_in_texture_set(texture_set_name, map_identifier): map_identifier (str): Map identifier Returns: - colorspace_dict: A dictionary which stores the boolean - value of textures having RGB channels + bool: Whether the channel type identifier has RGB channel or not + in the texture stack. """ + + # 2D_View is always True as it exports all texture maps 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) + if map_identifier == "2D_View": + return True + channel_type = getattr( + substance_painter.textureset.ChannelType, map_identifier, None) + if channel_type is None: + return False + if not texture_stack.has_channel(channel_type): + return 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) + return texture_stack.get_channel(channel_type).is_color() diff --git a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py index 9d6aa06872..4468602392 100644 --- a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py +++ b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py @@ -41,13 +41,11 @@ 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(): - 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) + 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): diff --git a/openpype/hosts/substancepainter/plugins/publish/validate_ouput_maps.py b/openpype/hosts/substancepainter/plugins/publish/validate_ouput_maps.py index b57cf4c5a2..252683b6c8 100644 --- a/openpype/hosts/substancepainter/plugins/publish/validate_ouput_maps.py +++ b/openpype/hosts/substancepainter/plugins/publish/validate_ouput_maps.py @@ -80,6 +80,7 @@ class ValidateOutputMaps(pyblish.api.InstancePlugin): self.log.warning(f"Disabling texture instance: " f"{image_instance}") image_instance.data["active"] = False + image_instance.data["publish"] = False image_instance.data["integrate"] = False representation.setdefault("tags", []).append("delete") continue From 00ab2bc9f69916ab19ddd15d018dc38cba624991 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Sat, 13 Jan 2024 00:19:03 +0800 Subject: [PATCH 5/6] remove unused function --- .../plugins/publish/collect_textureset_images.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py index 4468602392..370e72f34b 100644 --- a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py +++ b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py @@ -8,8 +8,7 @@ import substance_painter.textureset from openpype.hosts.substancepainter.api.lib import ( get_parsed_export_maps, strip_template, - has_rgb_channel_in_texture_set, - texture_set_filtering + has_rgb_channel_in_texture_set ) from openpype.pipeline.create import get_subset_name from openpype.client import get_asset_by_name From 1ac89d2efa55792e11023419e3ac5914e7b57480 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Mon, 15 Jan 2024 19:17:12 +0800 Subject: [PATCH 6/6] restore some of the codes on lib and collect images --- openpype/hosts/substancepainter/api/lib.py | 30 ------------------- .../publish/collect_textureset_images.py | 8 ++--- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index 896cca79b0..1cb480b552 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -643,33 +643,3 @@ 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: - bool: Whether the channel type identifier has RGB channel or not - in the texture stack. - """ - - # 2D_View is always True as it exports all texture maps - texture_stack = ( - substance_painter.textureset.Stack.from_name(texture_set_name) - ) - # 2D_View is always True as it exports all texture maps - if map_identifier == "2D_View": - return True - - channel_type = getattr( - substance_painter.textureset.ChannelType, map_identifier, None) - if channel_type is None: - return False - if not texture_stack.has_channel(channel_type): - return False - - return texture_stack.get_channel(channel_type).is_color() diff --git a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py index 370e72f34b..316f72509e 100644 --- a/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py +++ b/openpype/hosts/substancepainter/plugins/publish/collect_textureset_images.py @@ -7,8 +7,7 @@ from openpype.pipeline import publish import substance_painter.textureset from openpype.hosts.substancepainter.api.lib import ( get_parsed_export_maps, - strip_template, - has_rgb_channel_in_texture_set + strip_template ) from openpype.pipeline.create import get_subset_name from openpype.client import get_asset_by_name @@ -79,6 +78,7 @@ 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,9 +132,7 @@ 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") - has_rgb_channel = has_rgb_channel_in_texture_set( - texture_set_name, map_identifier) - if colorspace and has_rgb_channel: + if colorspace: self.log.debug(f"{image_subset} colorspace: {colorspace}") image_instance.data["colorspace"] = colorspace