From 00eb748b4b64339b00799b5fa4c41ad42426f73c Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Sat, 13 Jan 2024 00:15:46 +0800 Subject: [PATCH] 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