Merge branch 'feature/nuke_load_clip_repre_colorspace' into feature/OP-1539_Flame-Loading-published-clips-back

This commit is contained in:
Jakub Jezek 2022-01-25 15:15:08 +01:00
commit 2655c98429
No known key found for this signature in database
GPG key ID: D8548FBF690B100A
3 changed files with 116 additions and 33 deletions

View file

@ -29,6 +29,10 @@ from .lib import (
maintained_selection
)
from .utils import (
colorspace_exists_on_node,
get_colorspace_list
)
__all__ = (
"file_extensions",
@ -54,4 +58,7 @@ __all__ = (
"update_container",
"maintained_selection",
"colorspace_exists_on_node",
"get_colorspace_list"
)

View file

@ -82,3 +82,50 @@ def bake_gizmos_recursively(in_group=None):
if node.Class() == "Group":
bake_gizmos_recursively(node)
def colorspace_exists_on_node(node, colorspace_name):
""" Check if colorspace exists on node
Look through all options in the colorpsace knob, and see if we have an
exact match to one of the items.
Args:
node (nuke.Node): nuke node object
colorspace_name (str): color profile name
Returns:
bool: True if exists
"""
try:
colorspace_knob = node['colorspace']
except ValueError:
# knob is not available on input node
return False
all_clrs = get_colorspace_list(colorspace_knob)
return colorspace_name in all_clrs
def get_colorspace_list(colorspace_knob):
"""Get available colorspace profile names
Args:
colorspace_knob (nuke.Knob): nuke knob object
Returns:
list: list of strings names of profiles
"""
all_clrs = list(colorspace_knob.values())
reduced_clrs = []
if not colorspace_knob.getFlag(nuke.STRIP_CASCADE_PREFIX):
return all_clrs
# strip colorspace with nested path
for clrs in all_clrs:
clrs = clrs.split('/')[-1]
reduced_clrs.append(clrs)
return reduced_clrs

View file

@ -9,7 +9,8 @@ from openpype.hosts.nuke.api.lib import (
from openpype.hosts.nuke.api import (
containerise,
update_container,
viewer_update_and_undo_stop
viewer_update_and_undo_stop,
colorspace_exists_on_node
)
from openpype.hosts.nuke.api import plugin
@ -66,11 +67,11 @@ class LoadClip(plugin.NukeLoader):
)
def load(self, context, name, namespace, options):
repre = context["representation"]
# reste container id so it is always unique for each instance
self.reset_container_id()
is_sequence = len(context["representation"]["files"]) > 1
is_sequence = len(repre["files"]) > 1
file = self.fname.replace("\\", "/")
@ -79,14 +80,13 @@ class LoadClip(plugin.NukeLoader):
version = context['version']
version_data = version.get("data", {})
repr_id = context["representation"]["_id"]
colorspace = version_data.get("colorspace")
iio_colorspace = get_imageio_input_colorspace(file)
repr_cont = context["representation"]["context"]
repre_id = repre["_id"]
repre_cont = repre["context"]
self.log.info("version_data: {}\n".format(version_data))
self.log.debug(
"Representation id `{}` ".format(repr_id))
"Representation id `{}` ".format(repre_id))
self.handle_start = version_data.get("handleStart", 0)
self.handle_end = version_data.get("handleEnd", 0)
@ -101,7 +101,7 @@ class LoadClip(plugin.NukeLoader):
first = 1
last = first + duration
elif "#" not in file:
frame = repr_cont.get("frame")
frame = repre_cont.get("frame")
assert frame, "Representation is not sequence"
padding = len(frame)
@ -113,10 +113,10 @@ class LoadClip(plugin.NukeLoader):
if not file:
self.log.warning(
"Representation id `{}` is failing to load".format(repr_id))
"Representation id `{}` is failing to load".format(repre_id))
return
read_name = self._get_node_name(context["representation"])
read_name = self._get_node_name(repre)
# Create the Loader with the filename path set
read_node = nuke.createNode(
@ -128,11 +128,8 @@ class LoadClip(plugin.NukeLoader):
with viewer_update_and_undo_stop():
read_node["file"].setValue(file)
# Set colorspace defined in version data
if colorspace:
read_node["colorspace"].setValue(str(colorspace))
elif iio_colorspace is not None:
read_node["colorspace"].setValue(iio_colorspace)
set_colorspace = self._set_colorspace(
read_node, version_data, repre["data"])
self._set_range_to_node(read_node, first, last, start_at_workfile)
@ -145,6 +142,13 @@ class LoadClip(plugin.NukeLoader):
for k in add_keys:
if k == 'version':
data_imprint.update({k: context["version"]['name']})
elif k == 'colorspace':
colorspace = repre["data"].get(k)
colorspace = colorspace or version_data.get(k)
data_imprint.update({
"db_colorspace": colorspace,
"set_colorspace": set_colorspace
})
else:
data_imprint.update(
{k: context["version"]['data'].get(k, str(None))})
@ -192,10 +196,13 @@ class LoadClip(plugin.NukeLoader):
"_id": representation["parent"]
})
version_data = version.get("data", {})
repr_id = representation["_id"]
colorspace = version_data.get("colorspace")
iio_colorspace = get_imageio_input_colorspace(file)
repr_cont = representation["context"]
repre_id = representation["_id"]
repre_cont = representation["context"]
# colorspace profile
colorspace = representation["data"].get("colorspace")
colorspace = colorspace or version_data.get("colorspace")
self.handle_start = version_data.get("handleStart", 0)
self.handle_end = version_data.get("handleEnd", 0)
@ -210,7 +217,7 @@ class LoadClip(plugin.NukeLoader):
first = 1
last = first + duration
elif "#" not in file:
frame = repr_cont.get("frame")
frame = repre_cont.get("frame")
assert frame, "Representation is not sequence"
padding = len(frame)
@ -218,7 +225,7 @@ class LoadClip(plugin.NukeLoader):
if not file:
self.log.warning(
"Representation id `{}` is failing to load".format(repr_id))
"Representation id `{}` is failing to load".format(repre_id))
return
read_name = self._get_node_name(representation)
@ -229,12 +236,9 @@ class LoadClip(plugin.NukeLoader):
# to avoid multiple undo steps for rest of process
# we will switch off undo-ing
with viewer_update_and_undo_stop():
# Set colorspace defined in version data
if colorspace:
read_node["colorspace"].setValue(str(colorspace))
elif iio_colorspace is not None:
read_node["colorspace"].setValue(iio_colorspace)
set_colorspace = self._set_colorspace(
read_node, version_data, representation["data"],
path=file)
self._set_range_to_node(read_node, first, last, start_at_workfile)
@ -243,7 +247,8 @@ class LoadClip(plugin.NukeLoader):
"frameStart": str(first),
"frameEnd": str(last),
"version": str(version.get("name")),
"colorspace": colorspace,
"db_colorspace": colorspace,
"set_colorspace": set_colorspace,
"source": version_data.get("source"),
"handleStart": str(self.handle_start),
"handleEnd": str(self.handle_end),
@ -365,14 +370,38 @@ class LoadClip(plugin.NukeLoader):
def _get_node_name(self, representation):
repr_cont = representation["context"]
repre_cont = representation["context"]
name_data = {
"asset": repr_cont["asset"],
"subset": repr_cont["subset"],
"asset": repre_cont["asset"],
"subset": repre_cont["subset"],
"representation": representation["name"],
"ext": repr_cont["representation"],
"ext": repre_cont["representation"],
"id": representation["_id"],
"class_name": self.__class__.__name__
}
return self.node_name_template.format(**name_data)
def _set_colorspace(self, node, version_data, repre_data, path=None):
output_color = None
path = path or self.fname.replace("\\", "/")
# get colorspace
colorspace = repre_data.get("colorspace")
colorspace = colorspace or version_data.get("colorspace")
# colorspace from `project_anatomy/imageio/nuke/regexInputs`
iio_colorspace = get_imageio_input_colorspace(path)
# Set colorspace defined in version data
if (
colorspace is not None
and colorspace_exists_on_node(
node, str(colorspace)) is not False
):
node["colorspace"].setValue(str(colorspace))
output_color = str(colorspace)
elif iio_colorspace is not None:
node["colorspace"].setValue(iio_colorspace)
output_color = iio_colorspace
return output_color