From 14458ed1f13eb0b6a7fec547d170e94bda4f4aa4 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 25 Apr 2023 10:19:30 +0200 Subject: [PATCH 1/7] Allow user to set the colorspace explicitly instead of relying on Project Settings' file rules --- .../publish/collect_explicit_colorspace.py | 36 +++++++++++++ .../plugins/publish/validate_colorspace.py | 53 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py create mode 100644 openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py new file mode 100644 index 0000000000..fda789e9d5 --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -0,0 +1,36 @@ +import pyblish.api + +from openpype.pipeline import publish +from openpype.lib import TextDef + + +class CollectColorspace(pyblish.api.InstancePlugin, + publish.OpenPypePyblishPluginMixin, + publish.ColormanagedPyblishPluginMixin): + """Collect explicit user defined representation colorspaces""" + + label = "Choose representation colorspace" + order = pyblish.api.CollectorOrder + 0.49 + hosts = ["traypublisher"] + + def process(self, instance): + values = self.get_attr_values_from_data(instance.data) + colorspace = values.get("colorspace", None) + if not colorspace: + return + + context = instance.context + for repre in instance.data.get("representations", {}): + self.set_representation_colorspace( + representation=repre, + context=context, + colorspace=colorspace + ) + + @classmethod + def get_attribute_defs(cls): + return [ + TextDef("colorspace", + label="Override Colorspace", + placeholder="") + ] diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py new file mode 100644 index 0000000000..69cc7e5f1f --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -0,0 +1,53 @@ +import pyblish.api + +from openpype.pipeline import ( + publish, + PublishValidationError +) + +from openpype.pipeline.colorspace import ( + get_ocio_config_colorspaces +) + + +class ValidateColorspace(pyblish.api.InstancePlugin, + publish.OpenPypePyblishPluginMixin, + publish.ColormanagedPyblishPluginMixin): + """Validate representation colorspaces""" + + label = "Validate representation colorspace" + order = pyblish.api.ValidatorOrder + hosts = ["traypublisher"] + + def process(self, instance): + + config_colorspaces = {} # cache of colorspaces per config path + for repre in instance.data.get("representations", {}): + + colorspace_data = repre.get("colorspaceData", {}) + if not colorspace_data: + # Nothing to validate + continue + + config_path = colorspace_data["config"]["path"] + if config_path not in config_colorspaces: + colorspaces = get_ocio_config_colorspaces(config_path) + config_colorspaces[config_path] = set(colorspaces) + + colorspace = colorspace_data["colorspace"] + self.log.debug( + f"Validating representation '{repre['name']}' " + f"colorspace '{colorspace}'" + ) + if colorspace not in config_colorspaces[config_path]: + message = ( + f"Representation '{repre['name']}' colorspace " + f"'{colorspace}' does not exist in OCIO config: " + f"{config_path}" + ) + + raise PublishValidationError( + title="Representation colorspace", + message=message, + description=message + ) \ No newline at end of file From 7fe0728a0ab9076d283ba563184158addc9f98e9 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 25 Apr 2023 10:27:21 +0200 Subject: [PATCH 2/7] Add new line --- .../hosts/traypublisher/plugins/publish/validate_colorspace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py index 69cc7e5f1f..901defa1f3 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -50,4 +50,4 @@ class ValidateColorspace(pyblish.api.InstancePlugin, title="Representation colorspace", message=message, description=message - ) \ No newline at end of file + ) From 9752637b9e620002e05de3ca3d0c2b19c0d9b311 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 25 Apr 2023 10:27:38 +0200 Subject: [PATCH 3/7] Cosmetics --- .../traypublisher/plugins/publish/validate_colorspace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py index 901defa1f3..75b41cf606 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -11,8 +11,8 @@ from openpype.pipeline.colorspace import ( class ValidateColorspace(pyblish.api.InstancePlugin, - publish.OpenPypePyblishPluginMixin, - publish.ColormanagedPyblishPluginMixin): + publish.OpenPypePyblishPluginMixin, + publish.ColormanagedPyblishPluginMixin): """Validate representation colorspaces""" label = "Validate representation colorspace" From 2b1fe7abb65178b09d29fd503667a25112293256 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Mon, 26 Jun 2023 18:09:33 +0200 Subject: [PATCH 4/7] colorspace as enumerator form actual config --- .../publish/collect_explicit_colorspace.py | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index fda789e9d5..a36c3edbaa 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -1,7 +1,8 @@ import pyblish.api - +from openpype.pipeline import registered_host from openpype.pipeline import publish -from openpype.lib import TextDef +from openpype.lib import EnumDef +from openpype.pipeline import colorspace class CollectColorspace(pyblish.api.InstancePlugin, @@ -13,9 +14,14 @@ class CollectColorspace(pyblish.api.InstancePlugin, order = pyblish.api.CollectorOrder + 0.49 hosts = ["traypublisher"] + colorspace_items = [ + (None, "Don't override") + ] + def process(self, instance): values = self.get_attr_values_from_data(instance.data) colorspace = values.get("colorspace", None) + self.log.debug("colorspace: {}".format(colorspace)) if not colorspace: return @@ -27,10 +33,38 @@ class CollectColorspace(pyblish.api.InstancePlugin, colorspace=colorspace ) + @classmethod + def apply_settings(cls, project_settings): + host = registered_host() + host_name = host.name + project_name = host.get_current_project_name() + config_data = colorspace.get_imageio_config( + project_name, host_name, + project_settings=project_settings + ) + + if config_data: + filepath = config_data["path"] + config_items = colorspace.get_ocio_config_colorspaces(filepath) + cls.colorspace_items.extend(( + (name, name) + for name, family in config_items.items() + )) + else: + cls.colorspace_items.extend([ + ("sRGB", "sRGB"), + ("rec709", "rec709"), + ("ACES", "ACES"), + ("ACEScg", "ACEScg") + ]) + @classmethod def get_attribute_defs(cls): return [ - TextDef("colorspace", - label="Override Colorspace", - placeholder="") + EnumDef( + "colorspace", + cls.colorspace_items, + default="Don't override", + label="Override Colorspace" + ) ] From e38d28f21e6357e94447e60cf4d3e6ca10cc4d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Je=C5=BEek?= Date: Tue, 27 Jun 2023 13:31:40 +0200 Subject: [PATCH 5/7] Update openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py Co-authored-by: Roy Nieterau --- .../plugins/publish/collect_explicit_colorspace.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index a36c3edbaa..8ea373f43d 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -47,8 +47,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, filepath = config_data["path"] config_items = colorspace.get_ocio_config_colorspaces(filepath) cls.colorspace_items.extend(( - (name, name) - for name, family in config_items.items() + (name, name) for name in config_items.keys() )) else: cls.colorspace_items.extend([ From f4510fe571cbd473c705ab8b621b12c7c4f8faf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Je=C5=BEek?= Date: Tue, 27 Jun 2023 13:32:28 +0200 Subject: [PATCH 6/7] Update openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py Co-authored-by: Roy Nieterau --- .../plugins/publish/collect_explicit_colorspace.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index 8ea373f43d..8bab27d90a 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -21,10 +21,11 @@ class CollectColorspace(pyblish.api.InstancePlugin, def process(self, instance): values = self.get_attr_values_from_data(instance.data) colorspace = values.get("colorspace", None) - self.log.debug("colorspace: {}".format(colorspace)) - if not colorspace: + if colorspace is None: return + self.log.debug("Explicit colorspace set to: {}".format(colorspace)) + context = instance.context for repre in instance.data.get("representations", {}): self.set_representation_colorspace( From 9bb23f62ebc94b5dbf529aeb0fe97a286dd143fb Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 27 Jun 2023 13:40:50 +0200 Subject: [PATCH 7/7] removing ambiguous options --- .../plugins/publish/collect_explicit_colorspace.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index 8bab27d90a..eb7fbd87a0 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -17,6 +17,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, colorspace_items = [ (None, "Don't override") ] + colorspace_attr_show = False def process(self, instance): values = self.get_attr_values_from_data(instance.data) @@ -50,13 +51,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, cls.colorspace_items.extend(( (name, name) for name in config_items.keys() )) - else: - cls.colorspace_items.extend([ - ("sRGB", "sRGB"), - ("rec709", "rec709"), - ("ACES", "ACES"), - ("ACEScg", "ACEScg") - ]) + cls.colorspace_attr_show = True @classmethod def get_attribute_defs(cls): @@ -65,6 +60,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, "colorspace", cls.colorspace_items, default="Don't override", - label="Override Colorspace" + label="Override Colorspace", + hidden=not cls.colorspace_attr_show ) ]