Skip to content

Commit

Permalink
Merge pull request #31 from ynput/bugfix/AY-7142_broken-vertical-alig…
Browse files Browse the repository at this point in the history
…nment-resource-distribution_30

Fixing distribution of otioClip attribute to plates
  • Loading branch information
jakubjezek001 authored Nov 20, 2024
2 parents f21915f + 036790d commit 83d8887
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 25 deletions.
101 changes: 85 additions & 16 deletions client/ayon_hiero/plugins/create/create_shot_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def register_callbacks(self):
self.create_context.add_value_changed_callback(self._on_value_change)

def _on_value_change(self, event):
if self.product_type != "plate":
return

for item in event["changes"]:
instance = item["instance"]
if (
Expand Down Expand Up @@ -275,6 +278,39 @@ class EditorialAudioInstanceCreator(_HieroInstanceClipCreatorBase):
product_type = "audio"
label = "Editorial Audio"

def get_product_name(
self,
project_name,
folder_entity,
task_entity,
variant,
host_name=None,
instance=None,
project_entity=None):
return f"{self.product_type}Main"

def get_attr_defs_for_instance(self, instance):

instance_attributes = [
TextDef(
"parentInstance",
label="Linked to",
disabled=True,
)
]

instance_attributes.extend(
[
BoolDef(
"review",
label="Review",
tooltip="Switch to reviewable instance",
default=False,
),
]
)
return instance_attributes


class CreateShotClip(plugin.HieroCreator):
"""Publishable clip"""
Expand Down Expand Up @@ -523,11 +559,15 @@ def create(self, subset_name, instance_data, pre_create_data):

sorted_selected_track_items.extend(unsorted_selected_track_items)

shot_creator_id = "io.ayon.creators.hiero.shot"
audio_creator_id = "io.ayon.creators.hiero.audio"
plate_creator_id = "io.ayon.creators.hiero.plate"

# detect enabled creators for review, plate and audio
all_creators = {
"io.ayon.creators.hiero.shot": True,
"io.ayon.creators.hiero.plate": True,
"io.ayon.creators.hiero.audio": pre_create_data.get("export_audio", False),
shot_creator_id: True,
plate_creator_id: True,
audio_creator_id: True,
}

instances = []
Expand Down Expand Up @@ -572,16 +612,25 @@ def create(self, subset_name, instance_data, pre_create_data):
shot_folder_path = _instance_data["folderPath"]
shot_instances = self.shot_instances.setdefault(
shot_folder_path, {})
shot_creator_id = "io.ayon.creators.hiero.shot"
all_creators["io.ayon.creators.hiero.shot"] = _instance_data.get(

# desable shot creator if heroTrack is not enabled
all_creators[shot_creator_id] = _instance_data.get(
"heroTrack", False)
# desable audio creator if audio is not enabled
all_creators[audio_creator_id] = (
_instance_data.get("heroTrack", False) and
pre_create_data.get("export_audio", False)
)

enabled_creators = tuple(
cre for cre, enabled in all_creators.items() if enabled
)
clip_instances = {}
for creator_id in enabled_creators:
creator = self.create_context.creators[creator_id]
sub_instance_data = copy.deepcopy(_instance_data)
creator_attributes = sub_instance_data.setdefault(
"creator_attributes", {})
shot_folder_path = sub_instance_data["folderPath"]

# Shot creation
Expand All @@ -602,41 +651,61 @@ def create(self, subset_name, instance_data, pre_create_data):
"handleStart": sub_instance_data["handleStart"],
"handleEnd": sub_instance_data["handleEnd"],
"frameStart": workfileFrameStart,
"frameEnd": (workfileFrameStart + track_item_duration),
"frameEnd": (
workfileFrameStart + track_item_duration),
"clipIn": track_item.timelineIn(),
"clipOut": track_item.timelineOut(),
"clipDuration": track_item_duration,
"sourceIn": track_item.sourceIn(),
"sourceOut": track_item.sourceOut(),
},
"label": (f"{sub_instance_data['folderPath']} shotMain"),
"label": (
f"{sub_instance_data['folderPath']} shotMain"),
}
)

# Plate, Audio
# insert parent instance data to allow
# metadata recollection as publish time.
else:
elif creator_id == plate_creator_id:
parenting_data = shot_instances[shot_creator_id]
sub_instance_data.update({
"parent_instance_id": parenting_data["instance_id"],
"label": (
f"{sub_instance_data['folderPath']} "
f"{sub_instance_data['productName']}"
),
"creator_attributes": {
"parentInstance": parenting_data["label"],
}
)
})

# add reviewable source to plate if shot has it
creator_attributes["parentInstance"] = parenting_data[
"label"]
if sub_instance_data.get("reviewableSource"):
sub_instance_data["creator_attributes"].update({
creator_attributes.update({
"review": True,
"reviewableSource": sub_instance_data[
"reviewableSource"],
"review": True,
})

elif creator_id == audio_creator_id:
sub_instance_data["variant"] = "main"
sub_instance_data["productType"] = "audio"
sub_instance_data["productName"] = "audioMain"

parenting_data = shot_instances[shot_creator_id]
sub_instance_data.update(
{
"parent_instance_id": parenting_data["instance_id"],
"label": (
f"{sub_instance_data['folderPath']} "
f"{sub_instance_data['productName']}"
)
}
)
creator_attributes["parentInstance"] = parenting_data[
"label"]

if sub_instance_data.get("reviewableSource"):
creator_attributes["review"] = True

instance = creator.create(sub_instance_data, None)
instance.transient_data["track_item"] = track_item
self._add_instance_to_context(instance)
Expand Down
28 changes: 23 additions & 5 deletions client/ayon_hiero/plugins/publish/collect_audio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pyblish

from ayon_core.pipeline import PublishError
from ayon_hiero.api.otio import utils


class CollectAudio(pyblish.api.InstancePlugin):
"""Collect new audio."""
Expand All @@ -17,15 +20,30 @@ def process(self, instance):
# Retrieve instance data from parent instance shot instance.
parent_instance_id = instance.data["parent_instance_id"]
edit_shared_data = instance.context.data["editorialSharedData"]
instance.data.update(
edit_shared_data[parent_instance_id]
shot_instance_data = edit_shared_data[parent_instance_id]
instance.data.update(shot_instance_data)

# Adjust instance data from parent otio timeline.
otio_timeline = instance.context.data["otioTimeline"]
# Clip index has to be taken form hero shot data
# audio could be shorter but we need to get full length
otio_clip, _ = utils.get_marker_from_clip_index(
otio_timeline, shot_instance_data["shot_clip_index"]
)
if not otio_clip:
raise PublishError(
f"Could not retrieve otioClip for shot {instance}")

instance.data["otioClip"] = otio_clip

# solve reviewable options
review_switch = instance.data["creator_attributes"].get("review")

if instance.data.get("reviewTrack") is not None:
if review_switch is True:
instance.data["reviewAudio"] = True
instance.data.pop("reviewTrack")
instance.data.pop("review", None)

clip_src = instance.data["otioClip"].source_range
clip_src = otio_clip.source_range
clip_src_in = clip_src.start_time.to_frames()
clip_src_out = clip_src_in + clip_src.duration.to_frames()
instance.data.update({
Expand Down
14 changes: 14 additions & 0 deletions client/ayon_hiero/plugins/publish/collect_plates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pyblish

from ayon_core.pipeline import PublishError
from ayon_hiero.api.otio import utils


class CollectPlate(pyblish.api.InstancePlugin):
"""Collect new plates."""
Expand All @@ -16,6 +19,17 @@ def process(self, instance):
"""
instance.data["families"].append("clip")

# Adjust instance data from parent otio timeline.
otio_timeline = instance.context.data["otioTimeline"]
otio_clip, _ = utils.get_marker_from_clip_index(
otio_timeline, instance.data["clip_index"]
)
if not otio_clip:
raise PublishError(
f"Could not retrieve otioClip for shot {instance}")

instance.data["otioClip"] = otio_clip

# solve reviewable options
review_switch = instance.data["creator_attributes"].get(
"review")
Expand Down
14 changes: 10 additions & 4 deletions client/ayon_hiero/plugins/publish/collect_shots.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import pyblish

from ayon_core.pipeline import PublishError
from ayon_hiero.api import lib
from ayon_hiero.api.otio import utils

Expand All @@ -22,7 +23,6 @@ class CollectShot(pyblish.api.InstancePlugin):
"handleStart",
"handleEnd",
"item",
"otioClip",
"resolutionWidth",
"resolutionHeight",
"pixelAspect",
Expand Down Expand Up @@ -60,10 +60,15 @@ def _inject_editorial_shared_data(cls, instance):
if not context.data.get("editorialSharedData"):
context.data["editorialSharedData"] = {}

context.data["editorialSharedData"][instance_id] = {
edit_shared_data = context.data["editorialSharedData"].setdefault(
instance_id, {}
)
edit_shared_data.update({
key: value for key, value in instance.data.items()
if key in cls.SHARED_KEYS
}
})
# also add `shot_clip_index` to shared data for audio instance
edit_shared_data["shot_clip_index"] = instance.data["clip_index"]

def process(self, instance):
"""
Expand All @@ -78,7 +83,8 @@ def process(self, instance):
otio_timeline, instance.data["clip_index"]
)
if not otio_clip:
raise RuntimeError("Could not retrieve otioClip for shot %r", instance)
raise PublishError(
f"Could not retrieve otioClip for shot {instance}")

# Compute fps from creator attribute.
if instance.data['creator_attributes']["fps"] == "from_selection":
Expand Down

0 comments on commit 83d8887

Please sign in to comment.