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

Nuke render write targeting knob improvement #603

Merged
merged 6 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pype/hosts/nuke/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,24 +389,28 @@ def create_write_node(name, data, input=None, prenodes=None, review=True):
# imprinting group node
avalon.nuke.imprint(GN, data["avalon"])

divider = nuke.Text_Knob('')
GN.addKnob(divider)
# add divider
GN.addKnob(nuke.Text_Knob(''))

add_rendering_knobs(GN)

if review:
add_review_knob(GN)

# add divider
GN.addKnob(nuke.Text_Knob(''))

# Add linked knobs.
linked_knob_names = ["Render", "use_limit", "first", "last"]
for name in linked_knob_names:
link = nuke.Link_Knob(name)
link.makeLink(write_node.name(), name)
link.setName(name)
link.setFlag(0x1000)
GN.addKnob(link)

divider = nuke.Text_Knob('')
GN.addKnob(divider)
# add divider
GN.addKnob(nuke.Text_Knob(''))

# adding write to read button
add_button_write_to_read(GN)
Expand All @@ -431,13 +435,9 @@ def add_rendering_knobs(node):
node (obj): with added knobs
'''
if "render" not in node.knobs():
knob = nuke.Boolean_Knob("render", "Render")
knob = nuke.Enumeration_Knob("render", "Render", [
"Use existing frames", "Local", "On farm"])
knob.setFlag(0x1000)
knob.setValue(False)
node.addKnob(knob)
if "render_farm" not in node.knobs():
knob = nuke.Boolean_Knob("render_farm", "Render on Farm")
knob.setValue(False)
node.addKnob(knob)
return node

Expand Down
31 changes: 18 additions & 13 deletions pype/plugins/nuke/publish/collect_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,24 @@ def process(self, context):
# Add all nodes in group instances.
if node.Class() == "Group":
# only alter families for render family
if "write" == families_ak:
if node["render"].value():
self.log.info("flagged for render")
add_family = "{}.local".format("render")
# dealing with local/farm rendering
if node["render_farm"].value():
self.log.info("adding render farm family")
add_family = "{}.farm".format("render")
instance.data["transfer"] = False
families.append(add_family)
if "render" in families:
families.remove("render")
family = "write"
if "write" in families_ak:
target = node["render"].value()
if target == "Use existing frames":
# Local rendering
self.log.info("flagged for no render")
families.append("render")
elif target == "Local":
# Local rendering
self.log.info("flagged for local render")
families.append("{}.local".format("render"))
elif target == "On farm":
# Farm rendering
self.log.info("flagged for farm render")
instance.data["transfer"] = False
families.append("{}.farm".format("render"))
if "render" in families:
families.remove("render")
family = "write"

node.begin()
for i in nuke.allNodes():
Expand Down
31 changes: 0 additions & 31 deletions pype/plugins/nuke/publish/collect_legacy_write.py

This file was deleted.

154 changes: 88 additions & 66 deletions pype/plugins/nuke/publish/validate_write_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,103 @@
from avalon import api
import re
import pyblish.api
import pype.api
from avalon.nuke import get_avalon_knob_data

class RepairWriteLegacyAction(pyblish.api.Action):

label = "Repair"
icon = "wrench"
on = "failed"

def process(self, context, plugin):

# Get the errored instances
failed = []
for result in context.data["results"]:
if (result["error"] is not None and result["instance"] is not None
and result["instance"] not in failed):
failed.append(result["instance"])

# Apply pyblish.logic to get the instances for the plug-in
instances = pyblish.api.instances_by_plugin(failed, plugin)

for instance in instances:
if "Write" in instance[0].Class():
data = toml.loads(instance[0]["avalon"].value())
else:
data = get_avalon_knob_data(instance[0])

self.log.info(data)

data["xpos"] = instance[0].xpos()
data["ypos"] = instance[0].ypos()
data["input"] = instance[0].input(0)
data["publish"] = instance[0]["publish"].value()
data["render"] = instance[0]["render"].value()
data["render_farm"] = instance[0]["render_farm"].value()
data["review"] = instance[0]["review"].value()

# nuke.delete(instance[0])

task = os.environ["AVALON_TASK"]
sanitized_task = re.sub('[^0-9a-zA-Z]+', '', task)
subset_name = "render{}Main".format(
sanitized_task.capitalize())

Create_name = "CreateWriteRender"

creator_plugin = None
for Creator in api.discover(api.Creator):
if Creator.__name__ != Create_name:
continue

creator_plugin = Creator

# return api.create()
creator_plugin(data["subset"], data["asset"]).process()

node = nuke.toNode(data["subset"])
node.setXYpos(data["xpos"], data["ypos"])
node.setInput(0, data["input"])
node["publish"].setValue(data["publish"])
node["render"].setValue(data["render"])
node["render_farm"].setValue(data["render_farm"])
node["review"].setValue(data["review"])


class ValidateWriteLegacy(pyblish.api.InstancePlugin):
"""Validate legacy write nodes."""

order = pyblish.api.ValidatorOrder
optional = True
families = ["write.legacy"]
label = "Write Legacy"
families = ["write"]
label = "Validate Write Legacy"
hosts = ["nuke"]
actions = [RepairWriteLegacyAction]
actions = [pype.api.RepairAction]

def process(self, instance):

node = instance[0]
msg = "Clean up legacy write node \"{}\"".format(instance)
assert False, msg

if node.Class() not in ["Group", "Write"]:
return

# test avalon knobs
family_knobs = ["ak:family", "avalon:family"]
family_test = [k for k in node.knobs().keys() if k in family_knobs]
self.log.debug("_ family_test: {}".format(family_test))

# test if render in family test knob
# and only one item should be available
if len(family_test) == 1:
assert "render" in node[family_test[0]].value(), msg
else:
assert False, msg

# test if `file` knob in node, this way old
# non-group-node write could be detected
if "file" in node.knobs():
assert False, msg

# check if write node is having old render targeting
if "render_farm" in node.knobs():
assert False, msg

@classmethod
def repair(cls, instance):
node = instance[0]

if "Write" in node.Class():
data = toml.loads(node["avalon"].value())
else:
data = get_avalon_knob_data(node)

# collect reusable data
data["XYpos"] = (node.xpos(), node.ypos())
data["input"] = node.input(0)
data["publish"] = node["publish"].value()
data["render"] = node["render"].value()
data["render_farm"] = node["render_farm"].value()
data["review"] = node["review"].value()
data["use_limit"] = node["use_limit"].value()
data["first"] = node["first"].value()
data["last"] = node["last"].value()

family = data["family"]
cls.log.debug("_ orig node family: {}".format(family))

# define what family of write node should be recreated
if family == "render":
Create_name = "CreateWriteRender"
elif family == "prerender":
Create_name = "CreateWritePrerender"

# get appropriate plugin class
creator_plugin = None
for Creator in api.discover(api.Creator):
if Creator.__name__ != Create_name:
continue

creator_plugin = Creator

# delete the legaci write node
# nuke.delete(node)

# create write node with creator
new_node_name = data["subset"] + "_1"
creator_plugin(new_node_name, data["asset"]).process()

node = nuke.toNode(new_node_name)
node.setXYpos(*data["XYpos"])
node.setInput(0, data["input"])
node["publish"].setValue(data["publish"])
node["review"].setValue(data["review"])
node["use_limit"].setValue(data["use_limit"])
node["first"].setValue(data["first"])
node["last"].setValue(data["last"])

# recreate render targets
if data["render"]:
node["render"].setValue("Local")
if data["render_farm"]:
node["render"].setValue("On farm")