Merge pull request #4901 from BigRoy/enhancement/tray_publish_set_explicit_colorspace

This commit is contained in:
Milan Kolar 2023-06-28 16:58:59 +02:00 committed by GitHub
commit c9b9ca285e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 119 additions and 0 deletions

View file

@ -0,0 +1,66 @@
import pyblish.api
from openpype.pipeline import registered_host
from openpype.pipeline import publish
from openpype.lib import EnumDef
from openpype.pipeline import colorspace
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"]
colorspace_items = [
(None, "Don't override")
]
colorspace_attr_show = False
def process(self, instance):
values = self.get_attr_values_from_data(instance.data)
colorspace = values.get("colorspace", None)
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(
representation=repre,
context=context,
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 in config_items.keys()
))
cls.colorspace_attr_show = True
@classmethod
def get_attribute_defs(cls):
return [
EnumDef(
"colorspace",
cls.colorspace_items,
default="Don't override",
label="Override Colorspace",
hidden=not cls.colorspace_attr_show
)
]

View file

@ -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
)