diff --git a/server_addon/nuke/client/ayon_nuke/api/lib.py b/server_addon/nuke/client/ayon_nuke/api/lib.py index 09dab4687a..905521255f 100644 --- a/server_addon/nuke/client/ayon_nuke/api/lib.py +++ b/server_addon/nuke/client/ayon_nuke/api/lib.py @@ -1,5 +1,4 @@ import os -from pprint import pformat import re import json import six @@ -37,6 +36,7 @@ get_current_host_name, get_current_project_name, get_current_folder_path, + get_current_task_name, AYON_INSTANCE_ID, AVALON_INSTANCE_ID, ) @@ -154,15 +154,9 @@ def set_node_data(node, knobname, data): """ # if exists then update data if knobname in node.knobs(): - log.debug("Updating knobname `{}` on node `{}`".format( - knobname, node.name() - )) update_node_data(node, knobname, data) return - log.debug("Creating knobname `{}` on node `{}`".format( - knobname, node.name() - )) # else create new knob_value = JSON_PREFIX + json.dumps(data) knob = nuke.String_Knob(knobname) @@ -513,11 +507,9 @@ def get_avalon_knob_data(node, prefix="avalon:", create=True): # check if the node is avalon tracked try: # check if data available on the node - test = node[DATA_GROUP_KEY].value() - log.debug("Only testing if data available: `{}`".format(test)) - except NameError as e: + _ = node[DATA_GROUP_KEY].value() + except NameError: # if it doesn't then create it - log.debug("Creating avalon knob: `{}`".format(e)) if create: node = set_avalon_knob_data(node) return get_avalon_knob_data(node) @@ -678,8 +670,6 @@ def get_imageio_node_setting(node_class, plugin_name, product_name): imageio_node = node break - log.debug("__ imageio_node: {}".format(imageio_node)) - if not imageio_node: return @@ -690,8 +680,6 @@ def get_imageio_node_setting(node_class, plugin_name, product_name): product_name, imageio_node["knobs"] ) - - log.info("ImageIO node: {}".format(imageio_node)) return imageio_node @@ -706,8 +694,6 @@ def get_imageio_node_override_setting( # find matching override node override_imageio_node = None for onode in override_nodes: - log.debug("__ onode: {}".format(onode)) - log.debug("__ productName: {}".format(product_name)) if node_class not in onode["nuke_node_class"]: continue @@ -727,7 +713,6 @@ def get_imageio_node_override_setting( override_imageio_node = onode break - log.debug("__ override_imageio_node: {}".format(override_imageio_node)) # add overrides to imageio_node if override_imageio_node: # get all knob names in imageio_node @@ -740,7 +725,6 @@ def get_imageio_node_override_setting( for knob in knobs_settings: # add missing knobs into imageio_node if oknob_name not in knob_names: - log.debug("_ adding knob: `{}`".format(oknob)) knobs_settings.append(oknob) knob_names.append(oknob_name) continue @@ -750,9 +734,6 @@ def get_imageio_node_override_setting( knob_type = knob["type"] # override matching knob name - log.debug( - "_ overriding knob: `{}` > `{}`".format(knob, oknob) - ) if not oknob_value: # remove original knob if no value found in oknob knobs_settings.remove(knob) @@ -923,7 +904,6 @@ def writes_version_sync(): new_version = "v" + str("{" + ":0>{}".format(padding) + "}").format( int(rootVersion) ) - log.debug("new_version: {}".format(new_version)) except Exception: return @@ -936,13 +916,11 @@ def writes_version_sync(): try: if avalon_knob_data["families"] not in ["render"]: - log.debug(avalon_knob_data["families"]) continue node_file = each["file"].value() node_version = "v" + get_version_from_path(node_file) - log.debug("node_version: {}".format(node_version)) node_new_file = node_file.replace(node_version, new_version) each["file"].setValue(node_new_file) @@ -1332,7 +1310,6 @@ def set_node_knobs_from_settings(node, knob_settings, **kwargs): kwargs (dict)[optional]: keys for formattable knob settings """ for knob in knob_settings: - log.debug("__ knob: {}".format(pformat(knob))) knob_name = knob["name"] if knob_name not in node.knobs(): continue @@ -1486,13 +1463,17 @@ def __init__(self, root_node=None, nodes=None, **kwargs): Context._project_entity = project_entity self._project_name = project_name self._folder_path = get_current_folder_path() + self._task_name = get_current_task_name() self._folder_entity = ayon_api.get_folder_by_path( project_name, self._folder_path ) self._root_node = root_node or nuke.root() self._nodes = self.get_nodes(nodes=nodes) - self.data = kwargs + context_data = get_template_data_with_names( + project_name, self._folder_path, self._task_name, "nuke" + ) + self.formatting_data = context_data def get_nodes(self, nodes=None, nodes_filter=None): @@ -1509,36 +1490,23 @@ def get_nodes(self, nodes=None, nodes_filter=None): for filter in nodes_filter: return [n for n in self._nodes if filter in n.Class()] - def set_viewers_colorspace(self, viewer_dict): + def set_viewers_colorspace(self, imageio_nuke): ''' Adds correct colorspace to viewer Arguments: - viewer_dict (dict): adjustments from presets + imageio_nuke (dict): nuke colorspace configurations ''' - if not isinstance(viewer_dict, dict): - msg = "set_viewers_colorspace(): argument should be dictionary" - log.error(msg) - nuke.message(msg) - return - filter_knobs = [ "viewerProcess", "wipe_position", "monitorOutOutputTransform" ] - - display, viewer = get_viewer_config_from_string( - viewer_dict["viewerProcess"] - ) - viewer_process = create_viewer_profile_string( - viewer, display, path_like=False + viewer_process = self._display_and_view_formatted( + imageio_nuke["viewer"] ) - display, viewer = get_viewer_config_from_string( - viewer_dict["output_transform"] - ) - output_transform = create_viewer_profile_string( - viewer, display, path_like=False + output_transform = self._display_and_view_formatted( + imageio_nuke["monitor"] ) erased_viewers = [] for v in nuke.allNodes(filter="Viewer"): @@ -1547,8 +1515,10 @@ def set_viewers_colorspace(self, viewer_dict): if viewer_process not in v["viewerProcess"].value(): copy_inputs = v.dependencies() - copy_knobs = {k: v[k].value() for k in v.knobs() - if k not in filter_knobs} + copy_knobs = { + k: v[k].value() for k in v.knobs() + if k not in filter_knobs + } # delete viewer with wrong settings erased_viewers.append(v["name"].value()) @@ -1574,6 +1544,21 @@ def set_viewers_colorspace(self, viewer_dict): "Attention! Viewer nodes {} were erased." "It had wrong color profile".format(erased_viewers)) + def _display_and_view_formatted(self, view_profile): + """ Format display and view profile string + + Args: + view_profile (dict): view and display profile + + Returns: + str: formatted display and view profile string + """ + display_view = create_viewer_profile_string( + view_profile["view"], view_profile["display"], path_like=False + ) + # format any template tokens used in the string + return StringTemplate(display_view).format_strict(self.formatting_data) + def set_root_colorspace(self, imageio_host): ''' Adds correct colorspace to root @@ -1590,12 +1575,12 @@ def set_root_colorspace(self, imageio_host): if not config_data: # no ocio config found and no custom path used if self._root_node["colorManagement"].value() \ - not in color_management: + not in color_management: self._root_node["colorManagement"].setValue(color_management) # second set ocio version if self._root_node["OCIO_config"].value() \ - not in native_ocio_config: + not in native_ocio_config: self._root_node["OCIO_config"].setValue(native_ocio_config) else: @@ -1623,21 +1608,25 @@ def set_root_colorspace(self, imageio_host): if correct_settings: self._set_ocio_config_path_to_workfile(config_data) + workfile_settings_output = {} # get monitor lut from settings respecting Nuke version differences monitor_lut_data = self._get_monitor_settings( workfile_settings["monitor_out_lut"], workfile_settings["monitor_lut"] ) - monitor_lut_data.update({ - "workingSpaceLUT": workfile_settings["working_space"], - "int8Lut": workfile_settings["int_8_lut"], - "int16Lut": workfile_settings["int_16_lut"], - "logLut": workfile_settings["log_lut"], - "floatLut": workfile_settings["float_lut"] - }) + workfile_settings_output.update(monitor_lut_data) + workfile_settings_output.update( + { + "workingSpaceLUT": workfile_settings["working_space"], + "int8Lut": workfile_settings["int_8_lut"], + "int16Lut": workfile_settings["int_16_lut"], + "logLut": workfile_settings["log_lut"], + "floatLut": workfile_settings["float_lut"], + } + ) # then set the rest - for knob, value_ in monitor_lut_data.items(): + for knob, value_ in workfile_settings_output.items(): # skip unfilled ocio config path # it will be dict in value if isinstance(value_, dict): @@ -1646,7 +1635,6 @@ def set_root_colorspace(self, imageio_host): if not value_: continue self._root_node[knob].setValue(str(value_)) - log.debug("nuke.root()['{}'] changed to: {}".format(knob, value_)) def _get_monitor_settings(self, viewer_lut, monitor_lut): """ Get monitor settings from viewer and monitor lut @@ -1889,8 +1877,6 @@ def set_writes_colorspace(self): elif node_data: nuke_imageio_writes = get_write_node_template_attr(node) - log.debug("nuke_imageio_writes: `{}`".format(nuke_imageio_writes)) - if not nuke_imageio_writes: return @@ -1938,7 +1924,6 @@ def set_reads_colorspace(self, read_clrs_inputs): "to": future } - log.debug(changes) if changes: msg = "Read nodes are not set to correct colorspace:\n\n" for nname, knobs in changes.items(): @@ -1972,7 +1957,7 @@ def set_colorspace(self): log.info("Setting colorspace to viewers...") try: - self.set_viewers_colorspace(nuke_colorspace["viewer"]) + self.set_viewers_colorspace(nuke_colorspace) except AttributeError as _error: msg = "Set Colorspace to viewer error: {}".format(_error) nuke.message(msg) @@ -2653,8 +2638,6 @@ def on_enable_dirmap(self): def dirmap_routine(self, source_path, destination_path): source_path = source_path.lower().replace(os.sep, '/') destination_path = destination_path.lower().replace(os.sep, '/') - log.debug("Map: {} with: {}->{}".format(self.file_name, - source_path, destination_path)) if platform.system().lower() == "windows": self.file_name = self.file_name.lower().replace( source_path, destination_path) diff --git a/server_addon/nuke/client/ayon_nuke/api/plugin.py b/server_addon/nuke/client/ayon_nuke/api/plugin.py index 4f05cd41b9..fc30f328c7 100644 --- a/server_addon/nuke/client/ayon_nuke/api/plugin.py +++ b/server_addon/nuke/client/ayon_nuke/api/plugin.py @@ -12,6 +12,7 @@ BoolDef, EnumDef ) +from ayon_core.lib import StringTemplate from ayon_core.pipeline import ( LoaderPlugin, CreatorError, @@ -38,7 +39,6 @@ set_node_data, get_node_data, get_view_process_node, - get_viewer_config_from_string, get_filenames_without_hash, link_knobs ) @@ -638,12 +638,15 @@ def get_imageio_baking_profile(self): from . import lib as opnlib nuke_imageio = opnlib.get_nuke_imageio_settings() - # TODO: this is only securing backward compatibility lets remove - # this once all projects's anatomy are updated to newer config - if "baking" in nuke_imageio.keys(): - return nuke_imageio["baking"]["viewerProcess"] + if nuke_imageio["baking_target"]["enabled"]: + return nuke_imageio["baking_target"] else: - return nuke_imageio["viewer"]["viewerProcess"] + # viewer is having display and view keys only and it is + # display_view type + return { + "type": "display_view", + "display_view": nuke_imageio["viewer"], + } class ExporterReviewLut(ExporterReview): @@ -790,6 +793,7 @@ def __init__(self, self.viewer_lut_raw = klass.viewer_lut_raw self.write_colorspace = instance.data["colorspace"] self.color_channels = instance.data["color_channels"] + self.formatting_data = instance.data["anatomyData"] self.name = name or "baked" self.ext = ext or "mov" @@ -837,7 +841,7 @@ def save_file(self): with maintained_selection(): self.log.info("Saving nodes as file... ") # create nk path - path = os.path.splitext(self.path)[0] + ".nk" + path = f"{os.path.splitext(self.path)[0]}.nk" # save file to the path if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) @@ -861,21 +865,20 @@ def generate_mov(self, farm=False, delete=True, **kwargs): bake_viewer_process = kwargs["bake_viewer_process"] bake_viewer_input_process_node = kwargs[ "bake_viewer_input_process"] - viewer_process_override = kwargs[ - "viewer_process_override"] - baking_view_profile = ( - viewer_process_override or self.get_imageio_baking_profile()) + baking_colorspace = self.get_imageio_baking_profile() + + colorspace_override = kwargs["colorspace_override"] + if colorspace_override["enabled"]: + baking_colorspace = colorspace_override fps = self.instance.context.data["fps"] - self.log.debug(">> baking_view_profile `{}`".format( - baking_view_profile)) + self.log.debug(f">> baking_view_profile `{baking_colorspace}`") add_custom_tags = kwargs.get("add_custom_tags", []) - self.log.info( - "__ add_custom_tags: `{0}`".format(add_custom_tags)) + self.log.info(f"__ add_custom_tags: `{add_custom_tags}`") product_name = self.instance.data["productName"] self._temp_nodes[product_name] = [] @@ -932,32 +935,64 @@ def generate_mov(self, farm=False, delete=True, **kwargs): if not self.viewer_lut_raw: # OCIODisplay - dag_node = nuke.createNode("OCIODisplay") - - # assign display - display, viewer = get_viewer_config_from_string( - str(baking_view_profile) - ) - if display: - dag_node["display"].setValue(display) - - # assign viewer - dag_node["view"].setValue(viewer) - - if config_data: - # convert display and view to colorspace - colorspace = get_display_view_colorspace_name( - config_path=config_data["path"], - display=display, - view=viewer + if baking_colorspace["type"] == "display_view": + display_view = baking_colorspace["display_view"] + + message = "OCIODisplay... '{}'" + node = nuke.createNode("OCIODisplay") + + # assign display and view + display = display_view["display"] + view = display_view["view"] + + # display could not be set in nuke_default config + if display: + # format display string with anatomy data + display = StringTemplate(display).format_strict( + self.formatting_data + ) + node["display"].setValue(display) + + # format view string with anatomy data + view = StringTemplate(view).format_strict( + self.formatting_data) + # assign viewer + node["view"].setValue(view) + + if config_data: + # convert display and view to colorspace + colorspace = get_display_view_colorspace_name( + config_path=config_data["path"], + display=display, view=view + ) + + # OCIOColorSpace + elif baking_colorspace["type"] == "colorspace": + baking_colorspace = baking_colorspace["colorspace"] + # format colorspace string with anatomy data + baking_colorspace = StringTemplate( + baking_colorspace).format_strict(self.formatting_data) + node = nuke.createNode("OCIOColorSpace") + message = "OCIOColorSpace... '{}'" + # no need to set input colorspace since it is driven by + # working colorspace + node["out_colorspace"].setValue(baking_colorspace) + colorspace = baking_colorspace + + else: + raise ValueError( + "Invalid baking color space type: " + f"{baking_colorspace['type']}" ) self._connect_to_above_nodes( - dag_node, product_name, "OCIODisplay... `{}`" + node, product_name, message ) + # Write node write_node = nuke.createNode("Write") - self.log.debug("Path: {}".format(self.path)) + self.log.debug(f"Path: {self.path}") + write_node["file"].setValue(str(self.path)) write_node["file_type"].setValue(str(self.ext)) write_node["channels"].setValue(str(self.color_channels)) @@ -981,12 +1016,11 @@ def generate_mov(self, farm=False, delete=True, **kwargs): self.log.info("`mov64_write_timecode` knob was not found") write_node["raw"].setValue(1) + # connect write_node.setInput(0, self.previous_node) self._temp_nodes[product_name].append(write_node) - self.log.debug("Write... `{}`".format( - self._temp_nodes[product_name]) - ) + self.log.debug(f"Write... `{self._temp_nodes[product_name]}`") # ---------- end nodes creation # ---------- render or save to nk @@ -1014,7 +1048,7 @@ def generate_mov(self, farm=False, delete=True, **kwargs): colorspace=colorspace, ) - self.log.debug("Representation... `{}`".format(self.data)) + self.log.debug(f"Representation... `{self.data}`") self.clean_nodes(product_name) nuke.scriptSave() diff --git a/server_addon/nuke/client/ayon_nuke/plugins/publish/extract_review_intermediates.py b/server_addon/nuke/client/ayon_nuke/plugins/publish/extract_review_intermediates.py index b7bb911347..48c9988c5b 100644 --- a/server_addon/nuke/client/ayon_nuke/plugins/publish/extract_review_intermediates.py +++ b/server_addon/nuke/client/ayon_nuke/plugins/publish/extract_review_intermediates.py @@ -28,29 +28,6 @@ class ExtractReviewIntermediates(publish.Extractor): viewer_lut_raw = None outputs = {} - @classmethod - def apply_settings(cls, project_settings): - """Apply the settings from the deprecated - ExtractReviewDataMov plugin for backwards compatibility - """ - nuke_publish = project_settings["nuke"]["publish"] - deprecated_setting = nuke_publish["ExtractReviewDataMov"] - current_setting = nuke_publish.get("ExtractReviewIntermediates") - if not deprecated_setting["enabled"] and ( - not current_setting["enabled"] - ): - cls.enabled = False - - if deprecated_setting["enabled"]: - # Use deprecated settings if they are still enabled - cls.viewer_lut_raw = deprecated_setting["viewer_lut_raw"] - cls.outputs = deprecated_setting["outputs"] - elif current_setting is None: - pass - elif current_setting["enabled"]: - cls.viewer_lut_raw = current_setting["viewer_lut_raw"] - cls.outputs = current_setting["outputs"] - def process(self, instance): # TODO 'families' should not be included for filtering of outputs families = set(instance.data["families"]) diff --git a/server_addon/nuke/client/ayon_nuke/version.py b/server_addon/nuke/client/ayon_nuke/version.py index 1130392592..2262afb410 100644 --- a/server_addon/nuke/client/ayon_nuke/version.py +++ b/server_addon/nuke/client/ayon_nuke/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- """Package declaring AYON addon 'nuke' version.""" -__version__ = "0.2.2" +__version__ = "0.2.3" diff --git a/server_addon/nuke/package.py b/server_addon/nuke/package.py index 9081205c44..7347d21b35 100644 --- a/server_addon/nuke/package.py +++ b/server_addon/nuke/package.py @@ -1,6 +1,6 @@ name = "nuke" title = "Nuke" -version = "0.2.2" +version = "0.2.3" client_dir = "ayon_nuke" diff --git a/server_addon/nuke/server/__init__.py b/server_addon/nuke/server/__init__.py index aeb5e36675..0806ea8e87 100644 --- a/server_addon/nuke/server/__init__.py +++ b/server_addon/nuke/server/__init__.py @@ -1,8 +1,12 @@ -from typing import Type +from typing import Type, Any from ayon_server.addons import BaseServerAddon -from .settings import NukeSettings, DEFAULT_VALUES +from .settings import ( + NukeSettings, + DEFAULT_VALUES, + convert_settings_overrides +) class NukeAddon(BaseServerAddon): @@ -11,3 +15,13 @@ class NukeAddon(BaseServerAddon): async def get_default_settings(self): settings_model_cls = self.get_settings_model() return settings_model_cls(**DEFAULT_VALUES) + + async def convert_settings_overrides( + self, + source_version: str, + overrides: dict[str, Any], + ) -> dict[str, Any]: + convert_settings_overrides(source_version, overrides) + # Use super conversion + return await super().convert_settings_overrides( + source_version, overrides) diff --git a/server_addon/nuke/server/settings/__init__.py b/server_addon/nuke/server/settings/__init__.py index 1e58865395..da79b947f7 100644 --- a/server_addon/nuke/server/settings/__init__.py +++ b/server_addon/nuke/server/settings/__init__.py @@ -2,9 +2,12 @@ NukeSettings, DEFAULT_VALUES, ) +from .conversion import convert_settings_overrides __all__ = ( "NukeSettings", "DEFAULT_VALUES", + + "convert_settings_overrides", ) diff --git a/server_addon/nuke/server/settings/common.py b/server_addon/nuke/server/settings/common.py index e0ee2b7b3d..2ddbc3ca26 100644 --- a/server_addon/nuke/server/settings/common.py +++ b/server_addon/nuke/server/settings/common.py @@ -133,3 +133,63 @@ class KnobModel(BaseSettingsModel): "", title="Expression" ) + + +colorspace_types_enum = [ + {"value": "colorspace", "label": "Use Colorspace"}, + {"value": "display_view", "label": "Use Display & View"}, +] + + +class DisplayAndViewProfileModel(BaseSettingsModel): + _layout = "expanded" + + display: str = SettingsField( + "", + title="Display", + description="What display to use", + ) + + view: str = SettingsField( + "", + title="View", + description=( + "What view to use. Anatomy context tokens can " + "be used to dynamically set the value." + ), + ) + + +class ColorspaceConfigurationModel(BaseSettingsModel): + _isGroup: bool = True + + enabled: bool = SettingsField( + False, + title="Enabled", + description=( + "Enable baking target (colorspace or display/view)." + ), + ) + + type: str = SettingsField( + "colorspace", + title="Target baking type", + description="Switch between different knob types", + enum_resolver=lambda: colorspace_types_enum, + conditionalEnum=True, + ) + + colorspace: str = SettingsField( + "", + title="Colorspace", + description=( + "What colorspace name to use. Anatomy context tokens can " + "be used to dynamically set the value." + ), + ) + + display_view: DisplayAndViewProfileModel = SettingsField( + title="Display & View", + description="What display & view to use", + default_factory=DisplayAndViewProfileModel, + ) diff --git a/server_addon/nuke/server/settings/conversion.py b/server_addon/nuke/server/settings/conversion.py new file mode 100644 index 0000000000..2e9e07e354 --- /dev/null +++ b/server_addon/nuke/server/settings/conversion.py @@ -0,0 +1,143 @@ +import re +from typing import Any + + +def _get_viewer_config_from_string(input_string): + """Convert string to display and viewer string + + Args: + input_string (str): string with viewer + + Raises: + IndexError: if more then one slash in input string + IndexError: if missing closing bracket + + Returns: + tuple[str]: display, viewer + """ + display = None + viewer = input_string + # check if () or / or \ in name + if "/" in viewer: + split = viewer.split("/") + + # rise if more then one column + if len(split) > 2: + raise IndexError( + "Viewer Input string is not correct. " + f"More then two `/` slashes! {input_string}" + ) + + viewer = split[1] + display = split[0] + elif "(" in viewer: + pattern = r"([\w\d\s\.\-]+).*[(](.*)[)]" + result_ = re.findall(pattern, viewer) + try: + result_ = result_.pop() + display = str(result_[1]).rstrip() + viewer = str(result_[0]).rstrip() + except IndexError as e: + raise IndexError( + "Viewer Input string is not correct. " + f"Missing bracket! {input_string}" + ) from e + + return (display, viewer) + + +def _convert_imageio_baking_0_2_3(overrides): + if "baking" not in overrides: + return + + baking_view_process = overrides["baking"].get("viewerProcess") + + if baking_view_process is None: + return + + display, view = _get_viewer_config_from_string(baking_view_process) + + overrides["baking_target"] = { + "enabled": True, + "type": "display_view", + "display_view": { + "display": display, + "view": view, + }, + } + + +def _convert_viewers_0_2_3(overrides): + if "viewer" not in overrides: + return + + viewer = overrides["viewer"] + + if "viewerProcess" in viewer: + viewer_process = viewer["viewerProcess"] + display, view = _get_viewer_config_from_string(viewer_process) + viewer.update({ + "display": display, + "view": view, + }) + if "output_transform" in viewer: + output_transform = viewer["output_transform"] + display, view = _get_viewer_config_from_string(output_transform) + overrides["monitor"] = { + "display": display, + "view": view, + } + + +def _convert_imageio_configs_0_2_3(overrides): + """Image IO settings had changed. + + 0.2.2. is the latest version using the old way. + """ + if "imageio" not in overrides: + return + + imageio_overrides = overrides["imageio"] + + _convert_imageio_baking_0_2_3(imageio_overrides) + _convert_viewers_0_2_3(imageio_overrides) + + +def _convert_extract_intermediate_files_0_2_3(publish_overrides): + """Extract intermediate files settings had changed. + + 0.2.2. is the latest version using the old way. + """ + # override can be either `display/view` or `view (display)` + if "ExtractReviewIntermediates" in publish_overrides: + extract_review_intermediates = publish_overrides[ + "ExtractReviewIntermediates"] + + for output in extract_review_intermediates.get("outputs", []): + if viewer_process_override := output.get("viewer_process_override"): + display, view = _get_viewer_config_from_string( + viewer_process_override) + + output["colorspace_override"] = { + "enabled": True, + "type": "display_view", + "display_view": { + "display": display, + "view": view, + }, + } + + +def _convert_publish_plugins(overrides): + if "publish" not in overrides: + return + _convert_extract_intermediate_files_0_2_3(overrides["publish"]) + + +def convert_settings_overrides( + source_version: str, + overrides: dict[str, Any], +) -> dict[str, Any]: + _convert_imageio_configs_0_2_3(overrides) + _convert_publish_plugins(overrides) + return overrides diff --git a/server_addon/nuke/server/settings/imageio.py b/server_addon/nuke/server/settings/imageio.py index 9cdb0bf1d7..34deb351ed 100644 --- a/server_addon/nuke/server/settings/imageio.py +++ b/server_addon/nuke/server/settings/imageio.py @@ -6,7 +6,10 @@ ensure_unique_names, ) -from .common import KnobModel +from .common import ( + KnobModel, + ColorspaceConfigurationModel, +) class NodesModel(BaseSettingsModel): @@ -52,6 +55,8 @@ def ensure_unique_names(cls, value): class NodesSetting(BaseSettingsModel): + _isGroup: bool = True + required_nodes: list[RequiredNodesModel] = SettingsField( title="Plugin required", default_factory=list @@ -83,6 +88,8 @@ def ocio_configs_switcher_enum(): class WorkfileColorspaceSettings(BaseSettingsModel): """Nuke workfile colorspace preset. """ + _isGroup: bool = True + color_management: Literal["Nuke", "OCIO"] = SettingsField( title="Color Management Workflow" ) @@ -125,6 +132,8 @@ class ReadColorspaceRulesItems(BaseSettingsModel): class RegexInputsModel(BaseSettingsModel): + _isGroup: bool = True + inputs: list[ReadColorspaceRulesItems] = SettingsField( default_factory=list, title="Inputs" @@ -132,15 +141,44 @@ class RegexInputsModel(BaseSettingsModel): class ViewProcessModel(BaseSettingsModel): - viewerProcess: str = SettingsField( - title="Viewer Process Name" + _isGroup: bool = True + + display: str = SettingsField( + "", + title="Display", + description="What display to use", ) - output_transform: str = SettingsField( - title="Output Transform" + view: str = SettingsField( + "", + title="View", + description=( + "What view to use. Anatomy context tokens can " + "be used to dynamically set the value." + ), + ) + + +class MonitorProcessModel(BaseSettingsModel): + _isGroup: bool = True + + display: str = SettingsField( + "", + title="Display", + description="What display to use", + ) + view: str = SettingsField( + "", + title="View", + description=( + "What view to use. Anatomy context tokens can " + "be used to dynamically set the value." + ), ) class ImageIOConfigModel(BaseSettingsModel): + _isGroup: bool = True + override_global_config: bool = SettingsField( False, title="Override global OCIO config" @@ -159,6 +197,8 @@ class ImageIOFileRuleModel(BaseSettingsModel): class ImageIOFileRulesModel(BaseSettingsModel): + _isGroup: bool = True + activate_host_rules: bool = SettingsField(False) rules: list[ImageIOFileRuleModel] = SettingsField( default_factory=list, @@ -173,14 +213,7 @@ def validate_unique_outputs(cls, value): class ImageIOSettings(BaseSettingsModel): """Nuke color management project settings. """ - _isGroup: bool = True - - """# TODO: enhance settings with host api: - to restructure settings for simplification. - now: nuke/imageio/viewer/viewerProcess - future: nuke/imageio/viewer - """ activate_host_color_management: bool = SettingsField( True, title="Enable Color Management") ocio_config: ImageIOConfigModel = SettingsField( @@ -197,18 +230,13 @@ class ImageIOSettings(BaseSettingsModel): description="""Viewer profile is used during Creation of new viewer node at knob viewerProcess""" ) - - """# TODO: enhance settings with host api: - to restructure settings for simplification. - - now: nuke/imageio/baking/viewerProcess - future: nuke/imageio/baking - """ - baking: ViewProcessModel = SettingsField( - default_factory=ViewProcessModel, - title="Baking", - description="""Baking profile is used during - publishing baked colorspace data at knob viewerProcess""" + monitor: MonitorProcessModel = SettingsField( + default_factory=MonitorProcessModel, + title="Monitor OUT" + ) + baking_target: ColorspaceConfigurationModel = SettingsField( + default_factory=ColorspaceConfigurationModel, + title="Baking Target Colorspace" ) workfile: WorkfileColorspaceSettings = SettingsField( @@ -231,13 +259,12 @@ class ImageIOSettings(BaseSettingsModel): DEFAULT_IMAGEIO_SETTINGS = { - "viewer": { - "viewerProcess": "ACES/sRGB", - "output_transform": "ACES/sRGB" - }, - "baking": { - "viewerProcess": "ACES/Rec.709", - "output_transform": "ACES/Rec.709" + "viewer": {"display": "ACES", "view": "sRGB"}, + "monitor": {"display": "ACES", "view": "Rec.709"}, + "baking_target": { + "enabled": True, + "type": "colorspace", + "colorspace": "Output - Rec.709", }, "workfile": { "color_management": "OCIO", @@ -248,170 +275,67 @@ class ImageIOSettings(BaseSettingsModel): "int_8_lut": "role_matte_paint", "int_16_lut": "role_texture_paint", "log_lut": "role_compositing_log", - "float_lut": "role_scene_linear" + "float_lut": "role_scene_linear", }, "nodes": { "required_nodes": [ { - "plugins": [ - "CreateWriteRender" - ], + "plugins": ["CreateWriteRender"], "nuke_node_class": "Write", "knobs": [ - { - "type": "text", - "name": "file_type", - "text": "exr" - }, - { - "type": "text", - "name": "datatype", - "text": "16 bit half" - }, - { - "type": "text", - "name": "compression", - "text": "Zip (1 scanline)" - }, - { - "type": "boolean", - "name": "autocrop", - "boolean": True - }, + {"type": "text", "name": "file_type", "text": "exr"}, + {"type": "text", "name": "datatype", "text": "16 bit half"}, + {"type": "text", "name": "compression", "text": "Zip (1 scanline)"}, + {"type": "boolean", "name": "autocrop", "boolean": True}, { "type": "color_gui", "name": "tile_color", - "color_gui": [ - 186, - 35, - 35 - ] - }, - { - "type": "text", - "name": "channels", - "text": "rgb" - }, - { - "type": "text", - "name": "colorspace", - "text": "scene_linear" + "color_gui": [186, 35, 35], }, - { - "type": "boolean", - "name": "create_directories", - "boolean": True - } - ] + {"type": "text", "name": "channels", "text": "rgb"}, + {"type": "text", "name": "colorspace", "text": "scene_linear"}, + {"type": "boolean", "name": "create_directories", "boolean": True}, + ], }, { - "plugins": [ - "CreateWritePrerender" - ], + "plugins": ["CreateWritePrerender"], "nuke_node_class": "Write", "knobs": [ - { - "type": "text", - "name": "file_type", - "text": "exr" - }, - { - "type": "text", - "name": "datatype", - "text": "16 bit half" - }, - { - "type": "text", - "name": "compression", - "text": "Zip (1 scanline)" - }, - { - "type": "boolean", - "name": "autocrop", - "boolean": True - }, + {"type": "text", "name": "file_type", "text": "exr"}, + {"type": "text", "name": "datatype", "text": "16 bit half"}, + {"type": "text", "name": "compression", "text": "Zip (1 scanline)"}, + {"type": "boolean", "name": "autocrop", "boolean": True}, { "type": "color_gui", "name": "tile_color", - "color_gui": [ - 171, - 171, - 10 - ] - }, - { - "type": "text", - "name": "channels", - "text": "rgb" - }, - { - "type": "text", - "name": "colorspace", - "text": "scene_linear" + "color_gui": [171, 171, 10], }, - { - "type": "boolean", - "name": "create_directories", - "boolean": True - } - ] + {"type": "text", "name": "channels", "text": "rgb"}, + {"type": "text", "name": "colorspace", "text": "scene_linear"}, + {"type": "boolean", "name": "create_directories", "boolean": True}, + ], }, { - "plugins": [ - "CreateWriteImage" - ], + "plugins": ["CreateWriteImage"], "nuke_node_class": "Write", "knobs": [ - { - "type": "text", - "name": "file_type", - "text": "tiff" - }, - { - "type": "text", - "name": "datatype", - "text": "16 bit" - }, - { - "type": "text", - "name": "compression", - "text": "Deflate" - }, + {"type": "text", "name": "file_type", "text": "tiff"}, + {"type": "text", "name": "datatype", "text": "16 bit"}, + {"type": "text", "name": "compression", "text": "Deflate"}, { "type": "color_gui", "name": "tile_color", - "color_gui": [ - 56, - 162, - 7 - ] + "color_gui": [56, 162, 7], }, - { - "type": "text", - "name": "channels", - "text": "rgb" - }, - { - "type": "text", - "name": "colorspace", - "text": "texture_paint" - }, - { - "type": "boolean", - "name": "create_directories", - "boolean": True - } - ] - } + {"type": "text", "name": "channels", "text": "rgb"}, + {"type": "text", "name": "colorspace", "text": "texture_paint"}, + {"type": "boolean", "name": "create_directories", "boolean": True}, + ], + }, ], - "override_nodes": [] + "override_nodes": [], }, "regex_inputs": { - "inputs": [ - { - "regex": "(beauty).*(?=.exr)", - "colorspace": "linear" - } - ] - } + "inputs": [{"regex": "(beauty).*(?=.exr)", "colorspace": "linear"}] + }, } diff --git a/server_addon/nuke/server/settings/publish_plugins.py b/server_addon/nuke/server/settings/publish_plugins.py index 6c37ecd37a..c52c9e9c84 100644 --- a/server_addon/nuke/server/settings/publish_plugins.py +++ b/server_addon/nuke/server/settings/publish_plugins.py @@ -5,7 +5,11 @@ ensure_unique_names, task_types_enum ) -from .common import KnobModel, validate_json_dict +from .common import ( + KnobModel, + ColorspaceConfigurationModel, + validate_json_dict, +) def nuke_render_publish_types_enum(): @@ -130,19 +134,22 @@ class IntermediateOutputModel(BaseSettingsModel): title="Filter", default_factory=BakingStreamFilterModel) read_raw: bool = SettingsField( False, - title="Read raw switch" - ) - viewer_process_override: str = SettingsField( - "", - title="Viewer process override" + title="Input read node RAW switch" ) bake_viewer_process: bool = SettingsField( True, - title="Bake viewer process" + title="Bake viewer process", + section="Baking target", + ) + colorspace_override: ColorspaceConfigurationModel = SettingsField( + title="Target baking colorspace override", + description="Override Baking target with colorspace or display/view", + default_factory=ColorspaceConfigurationModel ) bake_viewer_input_process: bool = SettingsField( True, - title="Bake viewer input process node (LUT)" + title="Bake viewer input process node (LUT)", + section="Baking additional", ) reformat_nodes_config: ReformatNodesConfigModel = SettingsField( default_factory=ReformatNodesConfigModel, @@ -155,18 +162,6 @@ class IntermediateOutputModel(BaseSettingsModel): title="Custom tags", default_factory=list) -class ExtractReviewDataMovModel(BaseSettingsModel): - """[deprecated] use Extract Review Data Baking - Streams instead. - """ - enabled: bool = SettingsField(title="Enabled") - viewer_lut_raw: bool = SettingsField(title="Viewer lut raw") - outputs: list[IntermediateOutputModel] = SettingsField( - default_factory=list, - title="Baking streams" - ) - - class ExtractReviewIntermediatesModel(BaseSettingsModel): enabled: bool = SettingsField(title="Enabled") viewer_lut_raw: bool = SettingsField(title="Viewer lut raw") @@ -259,10 +254,6 @@ class PublishPluginsModel(BaseSettingsModel): title="Extract Review Data Lut", default_factory=ExtractReviewDataLutModel ) - ExtractReviewDataMov: ExtractReviewDataMovModel = SettingsField( - title="Extract Review Data Mov", - default_factory=ExtractReviewDataMovModel - ) ExtractReviewIntermediates: ExtractReviewIntermediatesModel = ( SettingsField( title="Extract Review Intermediates", @@ -332,62 +323,6 @@ class PublishPluginsModel(BaseSettingsModel): "ExtractReviewDataLut": { "enabled": False }, - "ExtractReviewDataMov": { - "enabled": False, - "viewer_lut_raw": False, - "outputs": [ - { - "name": "baking", - "publish": False, - "filter": { - "task_types": [], - "product_types": [], - "product_names": [] - }, - "read_raw": False, - "viewer_process_override": "", - "bake_viewer_process": True, - "bake_viewer_input_process": True, - "reformat_nodes_config": { - "enabled": False, - "reposition_nodes": [ - { - "node_class": "Reformat", - "knobs": [ - { - "type": "text", - "name": "type", - "text": "to format" - }, - { - "type": "text", - "name": "format", - "text": "HD_1080" - }, - { - "type": "text", - "name": "filter", - "text": "Lanczos6" - }, - { - "type": "boolean", - "name": "black_outside", - "boolean": True - }, - { - "type": "boolean", - "name": "pbb", - "boolean": False - } - ] - } - ] - }, - "extension": "mov", - "add_custom_tags": [] - } - ] - }, "ExtractReviewIntermediates": { "enabled": True, "viewer_lut_raw": False, @@ -401,7 +336,15 @@ class PublishPluginsModel(BaseSettingsModel): "product_names": [] }, "read_raw": False, - "viewer_process_override": "", + "colorspace_override": { + "enabled": False, + "type": "colorspace", + "colorspace": "", + "display_view": { + "display": "", + "view": "" + } + }, "bake_viewer_process": True, "bake_viewer_input_process": True, "reformat_nodes_config": {