mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 22:02:15 +01:00
fix(nks): refactoring code to better shape
This commit is contained in:
parent
9eb7dc3d15
commit
eb02919301
1 changed files with 63 additions and 81 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import pyblish.api
|
||||
import hiero.core
|
||||
import re
|
||||
|
||||
|
||||
class CollectVideoTracksLuts(pyblish.api.InstancePlugin):
|
||||
"""Collect video tracks effects into context."""
|
||||
|
||||
|
|
@ -15,15 +15,57 @@ class CollectVideoTracksLuts(pyblish.api.InstancePlugin):
|
|||
|
||||
# taking active sequence
|
||||
subset = instance.data["subset"]
|
||||
sequence = instance.context.data['activeSequence']
|
||||
effects_on_tracks = instance.context.data.get("subTrackUsedTracks")
|
||||
sub_track_items = instance.context.data.get("subTrackItems")
|
||||
track = instance.data["track"]
|
||||
track_effects = instance.context.data.get("trackEffects", {})
|
||||
track_index = instance.data["trackIndex"]
|
||||
effects = instance.data["effects"]
|
||||
|
||||
# creating context attribute
|
||||
self.effects = {"assignTo": subset, "effects": dict()}
|
||||
|
||||
for sitem in effects:
|
||||
self.add_effect(instance, track_index, sitem)
|
||||
|
||||
for t_index, sitems in track_effects.items():
|
||||
for sitem in sitems:
|
||||
if not t_index > track_index:
|
||||
continue
|
||||
self.log.debug(">> sitem: `{}`".format(sitem))
|
||||
self.add_effect(instance, t_index, sitem)
|
||||
|
||||
instance.data["effectTrackItems"] = self.effects
|
||||
|
||||
if len(instance.data.get("effectTrackItems", {}).keys()) > 0:
|
||||
instance.data["families"] += ["lut"]
|
||||
self.log.debug("effects.keys: {}".format(instance.data.get("effectTrackItems", {}).keys()))
|
||||
self.log.debug("effects: {}".format(instance.data.get("effectTrackItems", {})))
|
||||
|
||||
def add_effect(self, instance, track_index, item):
|
||||
track = item.parentTrack().name()
|
||||
# node serialization
|
||||
node = item.node()
|
||||
node_serialized = self.node_serialisation(instance, node)
|
||||
|
||||
# collect timelineIn/Out
|
||||
effect_t_in = int(item.timelineIn())
|
||||
effect_t_out = int(item.timelineOut())
|
||||
|
||||
node_name = item.name()
|
||||
node_class = re.sub(r"\d+", "", node_name)
|
||||
|
||||
self.effects["effects"].update({node_name: {
|
||||
"class": node_class,
|
||||
"timelineIn": effect_t_in,
|
||||
"timelineOut": effect_t_out,
|
||||
"subTrackIndex": item.subTrackIndex(),
|
||||
"trackIndex": track_index,
|
||||
"track": track,
|
||||
"node": node_serialized
|
||||
}})
|
||||
|
||||
def node_serialisation(self, instance, node):
|
||||
node_serialized = {}
|
||||
timeline_in_h = instance.data["clipInH"]
|
||||
timeline_out_h = instance.data["clipOutH"]
|
||||
timeline_in = instance.data["clipIn"]
|
||||
timeline_out = instance.data["clipOut"]
|
||||
|
||||
# adding ignoring knob keys
|
||||
_ignoring_keys = ['invert_mask', 'help', 'mask',
|
||||
|
|
@ -33,81 +75,21 @@ class CollectVideoTracksLuts(pyblish.api.InstancePlugin):
|
|||
'postage_stamp_frame', 'maskChannel', 'export_cc',
|
||||
'select_cccid', 'mix', 'version']
|
||||
|
||||
# creating context attribute
|
||||
effects = {"assignTo": subset, "effects": dict()}
|
||||
|
||||
for subtrack_item in sub_track_items:
|
||||
sub_track = subtrack_item.parentTrack().name()
|
||||
|
||||
# ignore anything not EffectTrackItem
|
||||
if not isinstance(subtrack_item, hiero.core.EffectTrackItem):
|
||||
continue
|
||||
et_item = subtrack_item
|
||||
|
||||
# ignore item if not enabled
|
||||
if not et_item.isEnabled():
|
||||
# loop trough all knobs and collect not ignored
|
||||
# and any with any value
|
||||
for knob in node.knobs().keys():
|
||||
# skip nodes in ignore keys
|
||||
if knob in _ignoring_keys:
|
||||
continue
|
||||
|
||||
node = et_item.node()
|
||||
node_serialized = {}
|
||||
# loop trough all knobs and collect not ignored
|
||||
# and any with any value
|
||||
for knob in node.knobs().keys():
|
||||
# skip nodes in ignore keys
|
||||
if knob in _ignoring_keys:
|
||||
continue
|
||||
# get animation if node is animated
|
||||
if node[knob].isAnimated():
|
||||
# grab animation including handles
|
||||
knob_anim = [node[knob].getValueAt(i)
|
||||
for i in range(timeline_in_h, timeline_out_h + 1)]
|
||||
|
||||
# get animation if node is animated
|
||||
if node[knob].isAnimated():
|
||||
# grab animation including handles
|
||||
knob_anim = [node[knob].getValueAt(i)
|
||||
for i in range(timeline_in_h, timeline_out_h + 1)]
|
||||
node_serialized[knob] = knob_anim
|
||||
else:
|
||||
node_serialized[knob] = node[knob].value()
|
||||
|
||||
node_serialized[knob] = knob_anim
|
||||
else:
|
||||
node_serialized[knob] = node[knob].value()
|
||||
|
||||
# pick track index from subTrackItem
|
||||
pick_sub_track = [indx for indx, vt
|
||||
in enumerate(sequence.videoTracks())
|
||||
if vt.name() in sub_track]
|
||||
# pick track index from trackItem
|
||||
pick_track = [indx for indx, vt in enumerate(sequence.videoTracks())
|
||||
if vt.name() in track]
|
||||
# collect timelineIn/Out
|
||||
effect_t_in = int(et_item.timelineIn())
|
||||
effect_t_out = int(et_item.timelineOut())
|
||||
|
||||
# controle if parent track has video trackItems
|
||||
items_check = et_item.parent().items()
|
||||
|
||||
node_name = et_item.name()
|
||||
node_class = re.sub(r"\d+", "", node_name)
|
||||
# filter out all track items under any track with effects
|
||||
# also filter out track item bellow
|
||||
if (pick_track[0] in effects_on_tracks) and (pick_sub_track[0] >= pick_track[0]):
|
||||
if (effect_t_in == timeline_in) and (effect_t_out == timeline_out):
|
||||
effects["effects"].update({node_name: {
|
||||
"class": node_class,
|
||||
"timelineIn": effect_t_in,
|
||||
"timelineOut": effect_t_out,
|
||||
"subTrackIndex": et_item.subTrackIndex(),
|
||||
"trackIndex": pick_track[0],
|
||||
"node": node_serialized
|
||||
}})
|
||||
# for subTrackItem on track without any trackItems
|
||||
elif len(items_check) == 0:
|
||||
effects["effects"].update({node_name: {
|
||||
"class": node_class,
|
||||
"timelineIn": effect_t_in,
|
||||
"timelineOut": effect_t_out,
|
||||
"subTrackIndex": et_item.subTrackIndex(),
|
||||
"trackIndex": pick_track[0],
|
||||
"node": node_serialized
|
||||
}})
|
||||
|
||||
instance.data["effectTrackItems"] = effects
|
||||
if len(instance.data.get("effectTrackItems", {}).keys()) > 0:
|
||||
instance.data["families"] += ["lut"]
|
||||
self.log.debug("effects.keys: {}".format(instance.data.get("effectTrackItems", {}).keys()))
|
||||
self.log.debug("effects: {}".format(instance.data.get("effectTrackItems", {})))
|
||||
return node_serialized
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue