Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6249 from ynput/enhancement/AY-978_hiero-colorspa…
Browse files Browse the repository at this point in the history
…ce-settings-aligned-with-nuke

Hiero: colorspace settings aligned with nuke - AY-978
  • Loading branch information
jakubjezek001 authored Apr 9, 2024
2 parents e23b4f6 + cdb050a commit 7596ece
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 44 deletions.
4 changes: 3 additions & 1 deletion openpype/hosts/hiero/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from .lib import (
sync_avalon_data_to_workfile,
launch_workfiles_app,
selection_changed_timeline,
before_project_save,
apply_colorspace_project
)
from .tags import add_tags_to_workfile
from .menu import update_menu_task_label
Expand Down Expand Up @@ -42,6 +42,8 @@ def afterNewProjectCreated(event):
# reset workfiles startup not to open any more in session
os.environ["WORKFILES_STARTUP"] = "0"

apply_colorspace_project()


def beforeProjectLoad(event):
log.info("before project load event...")
Expand Down
89 changes: 75 additions & 14 deletions openpype/hosts/hiero/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def flatten(list_):


def get_current_project(remove_untitled=False):
projects = flatten(hiero.core.projects())
projects = hiero.core.projects()
if not remove_untitled:
return next(iter(projects))
return projects[0]

# if remove_untitled
for proj in projects:
Expand Down Expand Up @@ -243,8 +243,13 @@ def get_track_items(
# collect all available active sequence track items
if not return_list:
sequence = get_current_sequence(name=sequence_name)
# get all available tracks from sequence
tracks = list(sequence.audioTracks()) + list(sequence.videoTracks())

tracks = []
if sequence is not None:
# get all available tracks from sequence
tracks = list(sequence.audioTracks())
tracks += list(sequence.videoTracks())

# loop all tracks
for track in tracks:
if check_locked and track.isLocked():
Expand Down Expand Up @@ -1039,18 +1044,68 @@ def _set_hrox_project_knobs(doc, **knobs):


def apply_colorspace_project():
project_name = get_current_project_name()
# get path the the active projects
project = get_current_project(remove_untitled=True)
current_file = project.path()

# close the active project
project.close()

"""Apply colorspaces from settings.
Due to not being able to set the project settings through the Python API,
we need to do use some dubious code to find the widgets and set them. It is
possible to set the project settings without traversing through the widgets
but it involves reading the hrox files from disk with XML, so no in-memory
support. See https://community.foundry.com/discuss/topic/137771/change-a-project-s-default-color-transform-with-python # noqa
for more details.
"""
# get presets for hiero
project_name = get_current_project_name()
imageio = get_project_settings(project_name)["hiero"]["imageio"]
presets = imageio.get("workfile")

# Open Project Settings UI.
for act in hiero.ui.registeredActions():
if act.objectName() == "foundry.project.settings":
act.trigger()

# Find widgets from their sibling label.
labels = {
"Working Space:": "workingSpace",
"Viewer:": "viewerLut",
"Thumbnails:": "thumbnailLut",
"Monitor Out:": "monitorOutLut",
"8 Bit Files:": "eightBitLut",
"16 Bit Files:": "sixteenBitLut",
"Log Files:": "logLut",
"Floating Point Files:": "floatLut"
}
widgets = {x: None for x in labels.values()}

def _recursive_children(widget, labels, widgets):
children = widget.children()
for count, child in enumerate(children):
if isinstance(child, QtWidgets.QLabel):
if child.text() in labels.keys():
widgets[labels[child.text()]] = children[count + 1]
_recursive_children(child, labels, widgets)

app = QtWidgets.QApplication.instance()
title = "Project Settings"
for widget in app.topLevelWidgets():
if isinstance(widget, QtWidgets.QMainWindow):
if widget.windowTitle() != title:
continue
_recursive_children(widget, labels, widgets)
widget.close()

msg = "Setting value \"{}\" is not a valid option for \"{}\""
for key, widget in widgets.items():
options = [widget.itemText(i) for i in range(widget.count())]
setting_value = presets[key]
assert setting_value in options, msg.format(setting_value, key)
widget.setCurrentText(presets[key])

# This code block is for setting up project colorspaces for files on disk.
# Due to not having Python API access to set the project settings, the
# Foundry recommended way is to modify the hrox files on disk with XML. See
# this forum thread for more details;
# https://community.foundry.com/discuss/topic/137771/change-a-project-s-default-color-transform-with-python # noqa
'''
# backward compatibility layer
# TODO: remove this after some time
config_data = get_imageio_config(
Expand All @@ -1063,6 +1118,13 @@ def apply_colorspace_project():
"ocioConfigName": "custom"
})
# get path the the active projects
project = get_current_project()
current_file = project.path()
msg = "The project needs to be saved to disk to apply colorspace settings."
assert current_file, msg
# save the workfile as subversion "comment:_colorspaceChange"
split_current_file = os.path.splitext(current_file)
copy_current_file = current_file
Expand Down Expand Up @@ -1105,6 +1167,7 @@ def apply_colorspace_project():
# open the file as current project
hiero.core.openProject(copy_current_file)
'''


def apply_colorspace_clips():
Expand All @@ -1114,10 +1177,8 @@ def apply_colorspace_clips():

# get presets for hiero
imageio = get_project_settings(project_name)["hiero"]["imageio"]
from pprint import pprint

presets = imageio.get("regexInputs", {}).get("inputs", {})
pprint(presets)
for clip in clips:
clip_media_source_path = clip.mediaSource().firstpath()
clip_name = clip.name()
Expand Down
18 changes: 9 additions & 9 deletions openpype/settings/defaults/project_settings/hiero.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"rules": {}
},
"workfile": {
"ocioConfigName": "nuke-default",
"workingSpace": "linear",
"sixteenBitLut": "sRGB",
"eightBitLut": "sRGB",
"floatLut": "linear",
"logLut": "Cineon",
"viewerLut": "sRGB",
"thumbnailLut": "sRGB",
"monitorOutLut": "sRGB"
"ocioConfigName": "aces_1.2",
"workingSpace": "role_scene_linear",
"viewerLut": "ACES/sRGB",
"thumbnailLut": "ACES/sRGB",
"monitorOutLut": "ACES/sRGB",
"eightBitLut": "role_matte_paint",
"sixteenBitLut": "role_texture_paint",
"logLut": "role_compositing_log",
"floatLut": "role_scene_linear"
},
"regexInputs": {
"inputs": [
Expand Down
15 changes: 10 additions & 5 deletions openpype/settings/defaults/project_settings/nuke.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
"rules": {}
},
"viewer": {
"viewerProcess": "sRGB (default)"
"viewerProcess": "ACES/sRGB"
},
"baking": {
"viewerProcess": "rec709 (default)"
"viewerProcess": "ACES/Rec.709"
},
"workfile": {
"colorManagement": "OCIO",
"OCIO_config": "nuke-default",
"workingSpaceLUT": "scene_linear",
"monitorLut": "sRGB (default)"
"OCIO_config": "aces_1.2",
"workingSpaceLUT": "role_scene_linear",
"monitorLut": "ACES/sRGB",
"monitorOutLUT": "ACES/sRGB",
"int8Lut": "role_matte_paint",
"int16Lut": "role_texture_paint",
"logLut": "role_compositing_log",
"floatLut": "role_scene_linear"
},
"nodes": {
"requiredNodes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,38 @@
},
{
"type": "text",
"key": "sixteenBitLut",
"label": "16 Bit Files"
"key": "viewerLut",
"label": "Viewer"
},
{
"type": "text",
"key": "eightBitLut",
"label": "8 Bit Files"
"key": "thumbnailLut",
"label": "Thumbnails"
},
{
"type": "text",
"key": "floatLut",
"label": "Floating Point Files"
"key": "monitorOutLut",
"label": "Monitor"
},
{
"type": "text",
"key": "logLut",
"label": "Log Files"
"key": "eightBitLut",
"label": "8 Bit Files"
},
{
"type": "text",
"key": "viewerLut",
"label": "Viewer"
"key": "sixteenBitLut",
"label": "16 Bit Files"
},
{
"type": "text",
"key": "thumbnailLut",
"label": "Thumbnails"
"key": "logLut",
"label": "Log Files"
},
{
"type": "text",
"key": "monitorOutLut",
"label": "Monitor"
"key": "floatLut",
"label": "Floating Point Files"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,32 @@
{
"type": "text",
"key": "monitorLut",
"label": "monitor"
"label": "Thumbnails"
},
{
"type": "text",
"key": "monitorOutLUT",
"label": "Monitor Out"
},
{
"type": "text",
"key": "int8Lut",
"label": "8-bit files"
},
{
"type": "text",
"key": "int16Lut",
"label": "16-bit files"
},
{
"type": "text",
"key": "logLut",
"label": "log files"
},
{
"type": "text",
"key": "floatLut",
"label": "float files"
}
]
}
Expand Down

0 comments on commit 7596ece

Please sign in to comment.