mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 13:24:54 +01:00
Merge pull request #4901 from BigRoy/enhancement/tray_publish_set_explicit_colorspace
This commit is contained in:
commit
c9b9ca285e
2 changed files with 119 additions and 0 deletions
|
|
@ -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
|
||||
)
|
||||
]
|
||||
|
|
@ -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
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue