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 #3245 from pypeclub/feature/OP-3207_Nuke-multiple-…
Browse files Browse the repository at this point in the history
…baking-streams-with-correct-slate
  • Loading branch information
mkolar authored Jun 22, 2022
2 parents 710b499 + 8ac3ed7 commit 6cb50ad
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 199 deletions.
9 changes: 8 additions & 1 deletion openpype/hosts/nuke/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
update_container,
)
from .lib import (
maintained_selection
maintained_selection,
reset_selection,
get_view_process_node,
duplicate_node

)

from .utils import (
Expand Down Expand Up @@ -58,6 +62,9 @@
"update_container",

"maintained_selection",
"reset_selection",
"get_view_process_node",
"duplicate_node",

"colorspace_exists_on_node",
"get_colorspace_list"
Expand Down
71 changes: 68 additions & 3 deletions openpype/hosts/nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import six
import platform
import tempfile
import contextlib
from collections import OrderedDict

Expand Down Expand Up @@ -711,6 +712,20 @@ def get_imageio_input_colorspace(filename):
return preset_clrsp


def get_view_process_node():
reset_selection()

ipn_orig = None
for v in nuke.allNodes(filter="Viewer"):
ipn = v['input_process_node'].getValue()
if "VIEWER_INPUT" not in ipn:
ipn_orig = nuke.toNode(ipn)
ipn_orig.setSelected(True)

if ipn_orig:
return duplicate_node(ipn_orig)


def on_script_load():
''' Callback for ffmpeg support
'''
Expand Down Expand Up @@ -2374,6 +2389,8 @@ def process_workfile_builder():
env_value_to_bool,
get_custom_workfile_template
)
# to avoid looping of the callback, remove it!
nuke.removeOnCreate(process_workfile_builder, nodeClass="Root")

# get state from settings
workfile_builder = get_current_project_settings()["nuke"].get(
Expand Down Expand Up @@ -2429,9 +2446,6 @@ def process_workfile_builder():
if not openlv_on or not os.path.exists(last_workfile_path):
return

# to avoid looping of the callback, remove it!
nuke.removeOnCreate(process_workfile_builder, nodeClass="Root")

log.info("Opening last workfile...")
# open workfile
open_file(last_workfile_path)
Expand Down Expand Up @@ -2617,6 +2631,57 @@ def sync_module(cls):
return cls._sync_module


@contextlib.contextmanager
def _duplicate_node_temp():
"""Create a temp file where node is pasted during duplication.
This is to avoid using clipboard for node duplication.
"""

duplicate_node_temp_path = os.path.join(
tempfile.gettempdir(),
"openpype_nuke_duplicate_temp_{}".format(os.getpid())
)

# This can happen only if 'duplicate_node' would be
if os.path.exists(duplicate_node_temp_path):
log.warning((
"Temp file for node duplication already exists."
" Trying to remove {}"
).format(duplicate_node_temp_path))
os.remove(duplicate_node_temp_path)

try:
# Yield the path where node can be copied
yield duplicate_node_temp_path

finally:
# Remove the file at the end
os.remove(duplicate_node_temp_path)


def duplicate_node(node):
reset_selection()

# select required node for duplication
node.setSelected(True)

with _duplicate_node_temp() as filepath:
# copy selected to temp filepath
nuke.nodeCopy(filepath)

# reset selection
reset_selection()

# paste node and selection is on it only
dupli_node = nuke.nodePaste(filepath)

# reset selection
reset_selection()

return dupli_node


def dirmap_file_name_filter(file_name):
"""Nuke callback function with single full path argument.
Expand Down
41 changes: 5 additions & 36 deletions openpype/hosts/nuke/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
from .lib import (
Knobby,
check_subsetname_exists,
reset_selection,
maintained_selection,
set_avalon_knob_data,
add_publish_knob,
get_nuke_imageio_settings,
set_node_knobs_from_settings
set_node_knobs_from_settings,
get_view_process_node
)


Expand Down Expand Up @@ -216,37 +216,6 @@ def get_representation_data(self, tags=None, range=False):

self.data["representations"].append(repre)

def get_view_input_process_node(self):
"""
Will get any active view process.
Arguments:
self (class): in object definition
Returns:
nuke.Node: copy node of Input Process node
"""
reset_selection()
ipn_orig = None
for v in nuke.allNodes(filter="Viewer"):
ip = v["input_process"].getValue()
ipn = v["input_process_node"].getValue()
if "VIEWER_INPUT" not in ipn and ip:
ipn_orig = nuke.toNode(ipn)
ipn_orig.setSelected(True)

if ipn_orig:
# copy selected to clipboard
nuke.nodeCopy("%clipboard%")
# reset selection
reset_selection()
# paste node and selection is on it only
nuke.nodePaste("%clipboard%")
# assign to variable
ipn = nuke.selectedNode()

return ipn

def get_imageio_baking_profile(self):
from . import lib as opnlib
nuke_imageio = opnlib.get_nuke_imageio_settings()
Expand Down Expand Up @@ -311,7 +280,7 @@ def clean_nodes(self):
self._temp_nodes = []
self.log.info("Deleted nodes...")

def generate_lut(self):
def generate_lut(self, **kwargs):
bake_viewer_process = kwargs["bake_viewer_process"]
bake_viewer_input_process_node = kwargs[
"bake_viewer_input_process"]
Expand All @@ -329,7 +298,7 @@ def generate_lut(self):
if bake_viewer_process:
# Node View Process
if bake_viewer_input_process_node:
ipn = self.get_view_input_process_node()
ipn = get_view_process_node()
if ipn is not None:
# connect
ipn.setInput(0, self.previous_node)
Expand Down Expand Up @@ -511,7 +480,7 @@ def generate_mov(self, farm=False, **kwargs):
if bake_viewer_process:
if bake_viewer_input_process_node:
# View Process node
ipn = self.get_view_input_process_node()
ipn = get_view_process_node()
if ipn is not None:
# connect
ipn.setInput(0, self.previous_node)
Expand Down
11 changes: 10 additions & 1 deletion openpype/hosts/nuke/plugins/publish/extract_review_data_mov.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pprint import pformat
import re
import pyblish.api
import openpype
Expand Down Expand Up @@ -50,6 +51,8 @@ def process(self, instance):
with maintained_selection():
generated_repres = []
for o_name, o_data in self.outputs.items():
self.log.debug(
"o_name: {}, o_data: {}".format(o_name, pformat(o_data)))
f_families = o_data["filter"]["families"]
f_task_types = o_data["filter"]["task_types"]
f_subsets = o_data["filter"]["subsets"]
Expand Down Expand Up @@ -88,7 +91,13 @@ def process(self, instance):
# check if settings have more then one preset
# so we dont need to add outputName to representation
# in case there is only one preset
multiple_presets = bool(len(self.outputs.keys()) > 1)
multiple_presets = len(self.outputs.keys()) > 1

# adding bake presets to instance data for other plugins
if not instance.data.get("bakePresets"):
instance.data["bakePresets"] = {}
# add preset to bakePresets
instance.data["bakePresets"][o_name] = o_data

# create exporter instance
exporter = plugin.ExporterReviewMov(
Expand Down
Loading

0 comments on commit 6cb50ad

Please sign in to comment.