mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 05:42:15 +01:00
publish instances update
This commit is contained in:
parent
f1d0c60c41
commit
13bcdb0959
3 changed files with 126 additions and 60 deletions
114
pype/nuke/lib.py
114
pype/nuke/lib.py
|
|
@ -81,57 +81,6 @@ def create_write_node(name, data):
|
|||
return instance
|
||||
|
||||
|
||||
def update_frame_range(start, end, root=None):
|
||||
"""Set Nuke script start and end frame range
|
||||
|
||||
Args:
|
||||
start (float, int): start frame
|
||||
end (float, int): end frame
|
||||
root (object, Optional): root object from nuke's script
|
||||
|
||||
Returns:
|
||||
None
|
||||
|
||||
"""
|
||||
|
||||
knobs = {
|
||||
"first_frame": start,
|
||||
"last_frame": end
|
||||
}
|
||||
|
||||
with avalon.nuke.viewer_update_and_undo_stop():
|
||||
for key, value in knobs.items():
|
||||
if root:
|
||||
root[key].setValue(value)
|
||||
else:
|
||||
nuke.root()[key].setValue(value)
|
||||
|
||||
|
||||
def get_additional_data(container):
|
||||
"""Get Nuke's related data for the container
|
||||
|
||||
Args:
|
||||
container(dict): the container found by the ls() function
|
||||
|
||||
Returns:
|
||||
dict
|
||||
"""
|
||||
|
||||
node = container["_tool"]
|
||||
tile_color = node['tile_color'].value()
|
||||
if tile_color is None:
|
||||
return {}
|
||||
|
||||
hex = '%08x' % tile_color
|
||||
rgba = [
|
||||
float(int(hex[0:2], 16)) / 255.0,
|
||||
float(int(hex[2:4], 16)) / 255.0,
|
||||
float(int(hex[4:6], 16)) / 255.0
|
||||
]
|
||||
|
||||
return {"color": QtGui.QColor().fromRgbF(rgba[0], rgba[1], rgba[2])}
|
||||
|
||||
|
||||
def set_viewers_colorspace(viewer):
|
||||
assert isinstance(viewer, dict), log.error(
|
||||
"set_viewers_colorspace(): argument should be dictionary")
|
||||
|
|
@ -217,3 +166,66 @@ def set_colorspace():
|
|||
except TypeError:
|
||||
log.error("Nuke is not in templates! \n\n\n"
|
||||
"contact your supervisor!")
|
||||
|
||||
|
||||
def get_avalon_knob_data(node):
|
||||
import toml
|
||||
try:
|
||||
data = toml.loads(node['avalon'].value())
|
||||
except:
|
||||
return None
|
||||
return data
|
||||
|
||||
# TODO: bellow functions are wip and needs to be check where they are used
|
||||
# ------------------------------------
|
||||
|
||||
|
||||
def update_frame_range(start, end, root=None):
|
||||
"""Set Nuke script start and end frame range
|
||||
|
||||
Args:
|
||||
start (float, int): start frame
|
||||
end (float, int): end frame
|
||||
root (object, Optional): root object from nuke's script
|
||||
|
||||
Returns:
|
||||
None
|
||||
|
||||
"""
|
||||
|
||||
knobs = {
|
||||
"first_frame": start,
|
||||
"last_frame": end
|
||||
}
|
||||
|
||||
with avalon.nuke.viewer_update_and_undo_stop():
|
||||
for key, value in knobs.items():
|
||||
if root:
|
||||
root[key].setValue(value)
|
||||
else:
|
||||
nuke.root()[key].setValue(value)
|
||||
|
||||
|
||||
def get_additional_data(container):
|
||||
"""Get Nuke's related data for the container
|
||||
|
||||
Args:
|
||||
container(dict): the container found by the ls() function
|
||||
|
||||
Returns:
|
||||
dict
|
||||
"""
|
||||
|
||||
node = container["_tool"]
|
||||
tile_color = node['tile_color'].value()
|
||||
if tile_color is None:
|
||||
return {}
|
||||
|
||||
hex = '%08x' % tile_color
|
||||
rgba = [
|
||||
float(int(hex[0:2], 16)) / 255.0,
|
||||
float(int(hex[2:4], 16)) / 255.0,
|
||||
float(int(hex[4:6], 16)) / 255.0
|
||||
]
|
||||
|
||||
return {"color": QtGui.QColor().fromRgbF(rgba[0], rgba[1], rgba[2])}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ class CollectNukeInstances(pyblish.api.ContextPlugin):
|
|||
label = "Collect Instances"
|
||||
hosts = ["nuke", "nukeassist"]
|
||||
|
||||
# targets = ["default", "process"]
|
||||
|
||||
def process(self, context):
|
||||
|
||||
# creating instances per write node
|
||||
|
|
@ -43,10 +41,12 @@ class CollectNukeInstances(pyblish.api.ContextPlugin):
|
|||
# Add collection
|
||||
collection = None
|
||||
path = nuke.filename(node)
|
||||
path += " [{0}-{1}]".format(str(first_frame), str(last_frame))
|
||||
path += " [{0}-{1}]".format(
|
||||
str(first_frame),
|
||||
str(last_frame)
|
||||
)
|
||||
collection = clique.parse(path)
|
||||
|
||||
subset = node.name()
|
||||
# Include start and end render frame in label
|
||||
label = "{subset} ({start}-{end})".format(subset=subset,
|
||||
start=int(first_frame),
|
||||
|
|
@ -62,23 +62,24 @@ class CollectNukeInstances(pyblish.api.ContextPlugin):
|
|||
knob.setValue(False)
|
||||
node.addKnob(knob)
|
||||
|
||||
|
||||
instance.data.update({
|
||||
"asset": os.environ["AVALON_ASSET"], # todo: not a constant
|
||||
"asset": os.environ["AVALON_ASSET"],
|
||||
"path": nuke.filename(node),
|
||||
"subset": subset,
|
||||
"outputDir": os.path.dirname(nuke.filename(node)),
|
||||
"ext": ext, # todo: should be redundant
|
||||
"label": label,
|
||||
"families": ["render.local"],
|
||||
"family": "write",
|
||||
"publish": node.knob("publish"),
|
||||
"collection": collection,
|
||||
"first_frame": first_frame,
|
||||
"last_frame": last_frame,
|
||||
"output_type": output_type
|
||||
})
|
||||
|
||||
def instanceToggled(instance, value):
|
||||
instance[0]["publish"].setValue(value)
|
||||
|
||||
instance.data["instanceToggled"] = instanceToggled
|
||||
|
||||
# Sort/grouped by family (preserving local index)
|
||||
context[:] = sorted(context, key=self.sort_by_family)
|
||||
|
||||
53
pype/plugins/nuke/publish/collect_instances.py
Normal file
53
pype/plugins/nuke/publish/collect_instances.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import os
|
||||
|
||||
import nuke
|
||||
import pyblish.api
|
||||
from pype.nuke.lib import get_avalon_knob_data
|
||||
|
||||
|
||||
@pyblish.api.log
|
||||
class CollectNukeInstances(pyblish.api.ContextPlugin):
|
||||
"""Collect all write nodes."""
|
||||
|
||||
order = pyblish.api.CollectorOrder
|
||||
label = "Collect Instances"
|
||||
hosts = ["nuke", "nukeassist"]
|
||||
|
||||
def process(self, context):
|
||||
|
||||
# creating instances per write node
|
||||
for node in nuke.allNodes():
|
||||
|
||||
if node["disable"].value():
|
||||
continue
|
||||
|
||||
# get data from avalon knob
|
||||
avalon_knob_data = get_avalon_knob_data(node)
|
||||
if not avalon_knob_data:
|
||||
continue
|
||||
subset = avalon_knob_data["subset"]
|
||||
|
||||
# Create instance
|
||||
instance = context.create_instance(subset)
|
||||
instance.add(node)
|
||||
|
||||
instance.data.update({
|
||||
"asset": os.environ["AVALON_ASSET"],
|
||||
"label": node.name(),
|
||||
"name": node.name(),
|
||||
"subset": subset,
|
||||
"families": [avalon_knob_data["families"]],
|
||||
"family": avalon_knob_data["family"],
|
||||
"publish": node.knob("publish").value()
|
||||
})
|
||||
self.log.info("collected instance: {}".format(instance.data))
|
||||
# Sort/grouped by family (preserving local index)
|
||||
context[:] = sorted(context, key=self.sort_by_family)
|
||||
|
||||
self.log.info("context: {}".format(context))
|
||||
|
||||
return context
|
||||
|
||||
def sort_by_family(self, instance):
|
||||
"""Sort by family"""
|
||||
return instance.data.get("families", instance.data.get("family"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue