From f32d28612bfefd287e5af11cec779e153638b2b8 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 18 Jan 2023 16:53:06 +0100 Subject: [PATCH] nuke: implementing new ocio config schema --- openpype/hosts/nuke/api/lib.py | 80 ++++++++----------- .../defaults/project_settings/nuke.json | 1 - .../schemas/schema_nuke_imageio.json | 10 +-- 3 files changed, 37 insertions(+), 54 deletions(-) diff --git a/openpype/hosts/nuke/api/lib.py b/openpype/hosts/nuke/api/lib.py index 2fdf446357..19c78081bf 100644 --- a/openpype/hosts/nuke/api/lib.py +++ b/openpype/hosts/nuke/api/lib.py @@ -30,7 +30,6 @@ from openpype.lib import ( from openpype.settings import ( get_project_settings, - get_anatomy_settings, get_current_project_settings, ) from openpype.modules import ModulesManager @@ -44,6 +43,9 @@ from openpype.pipeline.context_tools import ( get_current_project_asset, get_custom_workfile_template_from_session ) +from openpype.pipeline.colorspace import ( + get_imageio_config +) from openpype.pipeline.workfile import BuildWorkfile from . import gizmo_menu @@ -562,14 +564,6 @@ def get_node_path(path, padding=4): def get_nuke_imageio_settings(): - project_imageio = get_project_settings( - Context.project_name)["nuke"]["imageio"] - - # backward compatibility for project started before 3.10 - # those are still having `__legacy__` knob types - if not project_imageio["enabled"]: - return get_anatomy_settings(Context.project_name)["imageio"]["nuke"] - return get_project_settings(Context.project_name)["nuke"]["imageio"] @@ -1880,59 +1874,55 @@ class WorkfileSettings(object): "Attention! Viewer nodes {} were erased." "It had wrong color profile".format(erased_viewers)) - def set_root_colorspace(self, root_dict): + def set_root_colorspace(self, nuke_colorspace): ''' Adds correct colorspace to root Arguments: - root_dict (dict): adjustmensts from presets + nuke_colorspace (dict): adjustmensts from presets ''' - if not isinstance(root_dict, dict): - msg = "set_root_colorspace(): argument should be dictionary" - log.error(msg) - nuke.message(msg) + workfile_settings = nuke_colorspace["workfile"] - log.debug(">> root_dict: {}".format(root_dict)) + # resolve config data if they are enabled in host + config_data = None + if nuke_colorspace.get("ocio_config", {}).get("enabled"): + # switch ocio config to custom config + workfile_settings["OCIO_config"] = "custom" + workfile_settings["colorManagement"] = "OCIO" + + # get resolved ocio config path + config_data = get_imageio_config( + legacy_io.active_project(), "nuke" + ) # first set OCIO if self._root_node["colorManagement"].value() \ - not in str(root_dict["colorManagement"]): + not in str(workfile_settings["colorManagement"]): self._root_node["colorManagement"].setValue( - str(root_dict["colorManagement"])) - log.debug("nuke.root()['{0}'] changed to: {1}".format( - "colorManagement", root_dict["colorManagement"])) - root_dict.pop("colorManagement") + str(workfile_settings["colorManagement"])) + + # we dont need the key anymore + workfile_settings.pop("colorManagement") # second set ocio version if self._root_node["OCIO_config"].value() \ - not in str(root_dict["OCIO_config"]): + not in str(workfile_settings["OCIO_config"]): self._root_node["OCIO_config"].setValue( - str(root_dict["OCIO_config"])) - log.debug("nuke.root()['{0}'] changed to: {1}".format( - "OCIO_config", root_dict["OCIO_config"])) - root_dict.pop("OCIO_config") + str(workfile_settings["OCIO_config"])) + + # we dont need the key anymore + workfile_settings.pop("OCIO_config") # third set ocio custom path - if root_dict.get("customOCIOConfigPath"): - unresolved_path = root_dict["customOCIOConfigPath"] - ocio_paths = unresolved_path[platform.system().lower()] - - resolved_path = None - for ocio_p in ocio_paths: - resolved_path = str(ocio_p).format(**os.environ) - if not os.path.exists(resolved_path): - continue - - if resolved_path: - self._root_node["customOCIOConfigPath"].setValue( - str(resolved_path).replace("\\", "/") - ) - log.debug("nuke.root()['{}'] changed to: {}".format( - "customOCIOConfigPath", resolved_path)) - root_dict.pop("customOCIOConfigPath") + if config_data: + self._root_node["customOCIOConfigPath"].setValue( + str(config_data["path"]).replace("\\", "/") + ) + # backward compatibility, remove in case it exists + workfile_settings.pop("customOCIOConfigPath") # then set the rest - for knob, value in root_dict.items(): + for knob, value in workfile_settings.items(): # skip unfilled ocio config path # it will be dict in value if isinstance(value, dict): @@ -2062,7 +2052,7 @@ class WorkfileSettings(object): log.info("Setting colorspace to workfile...") try: - self.set_root_colorspace(nuke_colorspace["workfile"]) + self.set_root_colorspace(nuke_colorspace) except AttributeError: msg = "set_colorspace(): missing `workfile` settings in template" nuke.message(msg) diff --git a/openpype/settings/defaults/project_settings/nuke.json b/openpype/settings/defaults/project_settings/nuke.json index cde216d53e..caec67d900 100644 --- a/openpype/settings/defaults/project_settings/nuke.json +++ b/openpype/settings/defaults/project_settings/nuke.json @@ -9,7 +9,6 @@ } }, "imageio": { - "enabled": false, "ocio_config": { "enabled": false, "filepath": [] diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_nuke_imageio.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_nuke_imageio.json index 906f7b43c1..1cd6f0e67f 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_nuke_imageio.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_nuke_imageio.json @@ -2,14 +2,12 @@ "key": "imageio", "type": "dict", "label": "Color Management (ImageIO)", - "checkbox_key": "enabled", "collapsible": true, "is_group": true, "children": [ { - "type": "boolean", - "key": "enabled", - "label": "Enabled" + "type": "label", + "label": "'Custom OCIO config path' has deprecated.
If you need to set custom config, just enable and add path into 'OCIO config'.
Anatomy keys are supported.." }, { "type": "schema", @@ -51,10 +49,6 @@ "label": "Workfile", "collapsible": false, "children": [ - { - "type": "label", - "label": "'customOCIOConfigPath' will be deprecated.
Please move values to : project_settings/{app}/imageio/ocio_config/filepath." - }, { "type": "form", "children": [