mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Porting from OpenPype
This commit is contained in:
parent
df2c72cf2e
commit
723d7bbd7b
2 changed files with 98 additions and 42 deletions
|
|
@ -103,33 +103,42 @@ def colorspace_exists_on_node(node, colorspace_name):
|
|||
except ValueError:
|
||||
# knob is not available on input node
|
||||
return False
|
||||
all_clrs = get_colorspace_list(colorspace_knob)
|
||||
|
||||
return colorspace_name in all_clrs
|
||||
return colorspace_name in get_colorspace_list(colorspace_knob)
|
||||
|
||||
|
||||
def get_colorspace_list(colorspace_knob):
|
||||
"""Get available colorspace profile names
|
||||
|
||||
Because the values returned from colorspace_knob.values() do not correspond
|
||||
to the value returned from colorspace_knob.value(), and the extracted
|
||||
colorspace comes from using colorspace_knob.value(), we need to iterate
|
||||
through all values to get the correct value.
|
||||
|
||||
A code example of the above would be:
|
||||
|
||||
for count, value in enumerate(colorspace_knob.values()):
|
||||
colorspace_knob.setValue(count)
|
||||
print(colorspace_knob.value() in colorspace_knob.values())
|
||||
|
||||
Args:
|
||||
colorspace_knob (nuke.Knob): nuke knob object
|
||||
|
||||
Returns:
|
||||
list: list of strings names of profiles
|
||||
"""
|
||||
original_value = colorspace_knob.value()
|
||||
|
||||
all_clrs = list(colorspace_knob.values())
|
||||
reduced_clrs = []
|
||||
colorspaces = []
|
||||
|
||||
if not colorspace_knob.getFlag(nuke.STRIP_CASCADE_PREFIX):
|
||||
return all_clrs
|
||||
try:
|
||||
for count, _ in enumerate(colorspace_knob.values()):
|
||||
colorspace_knob.setValue(count)
|
||||
colorspaces.append(colorspace_knob.value())
|
||||
finally:
|
||||
colorspace_knob.setValue(original_value)
|
||||
|
||||
# strip colorspace with nested path
|
||||
for clrs in all_clrs:
|
||||
clrs = clrs.split('/')[-1]
|
||||
reduced_clrs.append(clrs)
|
||||
|
||||
return reduced_clrs
|
||||
return colorspaces
|
||||
|
||||
|
||||
def is_headless():
|
||||
|
|
|
|||
|
|
@ -101,7 +101,6 @@ class LoadClip(plugin.NukeLoader):
|
|||
|
||||
filepath = self.filepath_from_context(context)
|
||||
filepath = filepath.replace("\\", "/")
|
||||
self.log.debug("_ filepath: {}".format(filepath))
|
||||
|
||||
start_at_workfile = options.get(
|
||||
"start_at_workfile", self.options_defaults["start_at_workfile"])
|
||||
|
|
@ -154,8 +153,8 @@ class LoadClip(plugin.NukeLoader):
|
|||
with viewer_update_and_undo_stop():
|
||||
read_node["file"].setValue(filepath)
|
||||
|
||||
used_colorspace = self._set_colorspace(
|
||||
read_node, version_data, representation["data"], filepath)
|
||||
self.set_colorspace_to_node(
|
||||
read_node, filepath, version, representation)
|
||||
|
||||
self._set_range_to_node(read_node, first, last, start_at_workfile)
|
||||
|
||||
|
|
@ -180,8 +179,6 @@ class LoadClip(plugin.NukeLoader):
|
|||
colorspace = representation["data"].get(key)
|
||||
colorspace = colorspace or version_data.get(key)
|
||||
data_imprint["db_colorspace"] = colorspace
|
||||
if used_colorspace:
|
||||
data_imprint["used_colorspace"] = used_colorspace
|
||||
else:
|
||||
value_ = context["version"]['data'].get(
|
||||
key, str(None))
|
||||
|
|
@ -302,8 +299,8 @@ 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():
|
||||
used_colorspace = self._set_colorspace(
|
||||
read_node, version_data, representation["data"], filepath)
|
||||
self.set_colorspace_to_node(
|
||||
read_node, filepath, version_doc, representation)
|
||||
|
||||
self._set_range_to_node(read_node, first, last, start_at_workfile)
|
||||
|
||||
|
|
@ -320,10 +317,6 @@ class LoadClip(plugin.NukeLoader):
|
|||
"author": version_data.get("author")
|
||||
}
|
||||
|
||||
# add used colorspace if found any
|
||||
if used_colorspace:
|
||||
updated_dict["used_colorspace"] = used_colorspace
|
||||
|
||||
last_version_doc = get_last_version_by_subset_id(
|
||||
project_name, version_doc["parent"], fields=["_id"]
|
||||
)
|
||||
|
|
@ -350,6 +343,36 @@ class LoadClip(plugin.NukeLoader):
|
|||
|
||||
self.set_as_member(read_node)
|
||||
|
||||
def set_colorspace_to_node(
|
||||
self,
|
||||
read_node,
|
||||
filepath,
|
||||
version_doc,
|
||||
representation_doc,
|
||||
):
|
||||
"""Set colorspace to read node.
|
||||
|
||||
Sets colorspace with available names validation.
|
||||
|
||||
Args:
|
||||
read_node (nuke.Node): The nuke's read node
|
||||
filepath (str): file path
|
||||
version_doc (dict): version document
|
||||
representation_doc (dict): representation document
|
||||
|
||||
"""
|
||||
used_colorspace = self._get_colorspace_data(
|
||||
version_doc, representation_doc, filepath)
|
||||
|
||||
if (
|
||||
used_colorspace
|
||||
and colorspace_exists_on_node(read_node, used_colorspace)
|
||||
):
|
||||
self.log.info(f"Used colorspace: {used_colorspace}")
|
||||
read_node["colorspace"].setValue(used_colorspace)
|
||||
else:
|
||||
self.log.info("Colorspace not set...")
|
||||
|
||||
def remove(self, container):
|
||||
read_node = container["node"]
|
||||
assert read_node.Class() == "Read", "Must be Read"
|
||||
|
|
@ -450,25 +473,49 @@ class LoadClip(plugin.NukeLoader):
|
|||
|
||||
return self.node_name_template.format(**name_data)
|
||||
|
||||
def _set_colorspace(self, node, version_data, repre_data, path):
|
||||
output_color = None
|
||||
path = path.replace("\\", "/")
|
||||
# get colorspace
|
||||
colorspace = repre_data.get("colorspace")
|
||||
colorspace = colorspace or version_data.get("colorspace")
|
||||
def _get_colorspace_data(self, version_doc, representation_doc, filepath):
|
||||
"""Get colorspace data from version and representation documents
|
||||
|
||||
Args:
|
||||
version_doc (dict): version document
|
||||
representation_doc (dict): representation document
|
||||
filepath (str): file path
|
||||
|
||||
Returns:
|
||||
Any[str,None]: colorspace name or None
|
||||
"""
|
||||
# Get backward compatible colorspace key.
|
||||
colorspace = representation_doc["data"].get("colorspace")
|
||||
self.log.debug(
|
||||
f"Colorspace from representation colorspace: {colorspace}"
|
||||
)
|
||||
|
||||
# Get backward compatible version data key if colorspace is not found.
|
||||
colorspace = colorspace or version_doc["data"].get("colorspace")
|
||||
self.log.debug(f"Colorspace from version colorspace: {colorspace}")
|
||||
|
||||
# Get colorspace from representation colorspaceData if colorspace is
|
||||
# not found.
|
||||
colorspace_data = representation_doc["data"].get("colorspaceData", {})
|
||||
colorspace = colorspace or colorspace_data.get("colorspace")
|
||||
self.log.debug(
|
||||
f"Colorspace from representation colorspaceData: {colorspace}"
|
||||
)
|
||||
|
||||
print(f"Colorspace found: {colorspace}")
|
||||
|
||||
# check if any filerules are not applicable
|
||||
new_parsed_colorspace = get_imageio_file_rules_colorspace_from_filepath( # noqa
|
||||
filepath, "nuke", get_current_project_name()
|
||||
)
|
||||
self.log.debug(f"Colorspace new filerules: {new_parsed_colorspace}")
|
||||
|
||||
# colorspace from `project_settings/nuke/imageio/regexInputs`
|
||||
iio_colorspace = get_imageio_input_colorspace(path)
|
||||
old_parsed_colorspace = get_imageio_input_colorspace(filepath)
|
||||
self.log.debug(f"Colorspace old filerules: {old_parsed_colorspace}")
|
||||
|
||||
# Set colorspace defined in version data
|
||||
if (
|
||||
colorspace is not None
|
||||
and colorspace_exists_on_node(node, str(colorspace))
|
||||
):
|
||||
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
|
||||
return (
|
||||
new_parsed_colorspace
|
||||
or old_parsed_colorspace
|
||||
or colorspace
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue