adding frame collector and optional frame data from asset entity collector

This commit is contained in:
Kayla Man 2023-07-06 17:52:58 +08:00
parent 5b735c70f5
commit 803236c9c5
5 changed files with 89 additions and 87 deletions

View file

@ -0,0 +1,39 @@
import pyblish.api
from openpype.pipeline import OptionalPyblishPluginMixin
class CollectFrameDataFromAssetEntity(pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin):
"""Collect Frame Range data From Asset Entity
"""
order = pyblish.api.CollectorOrder + 0.3
label = "Collect Frame Data From Asset Entity"
families = ["plate", "pointcache",
"vdbcache", "online",
"render"]
hosts = ["traypublisher"]
optional = True
def process(self, instance):
if not self.is_active(instance.data):
return
missing_keys = []
for key in (
"fps",
"frameStart",
"frameEnd",
"handleStart",
"handleEnd"
):
if key not in instance.data:
missing_keys.append(key)
key_sets = []
for key in missing_keys:
asset_data = instance.data["assetEntity"]["data"]
if key in asset_data:
instance.data[key] = asset_data[key]
key_sets.append(key)
if key_sets:
self.log.debug(f"Frame range data {key_sets} "
"has been collected from asset entity.")

View file

@ -1,85 +0,0 @@
import pyblish.api
import clique
from openpype.pipeline import publish
from openpype.lib import BoolDef
class CollectFrameRangeData(pyblish.api.InstancePlugin,
publish.OpenPypePyblishPluginMixin):
"""Collect Frame Range data.
"""
order = pyblish.api.CollectorOrder + 0.491
label = "Collect Frame Range Data"
families = ["plate", "pointcache",
"vdbcache", "online",
"render"]
hosts = ["traypublisher"]
def process(self, instance):
repres = instance.data.get("representations")
asset_data = None
if repres:
first_repre = repres[0]
if "ext" not in first_repre:
self.log.warning("Cannot find file extension"
" in representation data")
return
files = first_repre["files"]
collections, remainder = clique.assemble(files)
if not collections:
# No sequences detected and we can't retrieve
# frame range
self.log.debug(
"No sequences detected in the representation data."
" Skipping collecting frame range data.")
return
collection = collections[0]
repres_frames = list(collection.indexes)
asset_data = {
"frameStart": repres_frames[0],
"frameEnd": repres_frames[-1],
}
else:
self.log.info(
"No representation data. Using Asset Entity data instead")
asset_doc = instance.data.get("assetEntity")
attr_values = self.get_attr_values_from_data(instance.data)
if attr_values.get("setAssetFrameRange", True):
if instance.data.get("frameStart") is not None or not asset_doc: # noqa
self.log.debug("Instance has no asset entity set."
" Skipping collecting frame range data.")
return
self.log.debug(
"Falling back to collect frame range"
" data from set asset entity.")
asset_data = asset_doc["data"]
else:
self.log.debug("Skipping collecting frame range data.")
return
key_sets = []
for key in (
"fps",
"frameStart",
"frameEnd",
"handleStart",
"handleEnd"
):
if key not in instance.data and key in asset_data:
instance.data[key] = asset_data[key]
key_sets.append(key)
self.log.debug(f"Frame range data {key_sets} "
"has been collected from asset entity.")
@classmethod
def get_attribute_defs(cls):
return [
BoolDef("setAssetFrameRange",
label="Set Asset Frame Range",
default=False),
]

View file

@ -0,0 +1,48 @@
import pyblish.api
import clique
class CollectSequenceFrameData(pyblish.api.InstancePlugin):
"""Collect Sequence Frame Data
"""
order = pyblish.api.CollectorOrder + 0.2
label = "Collect Sequence Frame Data"
families = ["plate", "pointcache",
"vdbcache", "online",
"render"]
hosts = ["traypublisher"]
def process(self, instance):
frame_data = self.get_frame_data_from_repre_sequence(instance)
for key, value in frame_data.items():
if key not in instance.data :
instance.data[key] = value
self.log.debug(f"Frame range data {key} has been collected ")
def get_frame_data_from_repre_sequence(self, instance):
repres = instance.data.get("representations")
if repres:
first_repre = repres[0]
if "ext" not in first_repre:
self.log.warning("Cannot find file extension"
" in representation data")
return
files = first_repre["files"]
collections, remainder = clique.assemble(files)
if not collections:
# No sequences detected and we can't retrieve
# frame range
self.log.debug(
"No sequences detected in the representation data."
" Skipping collecting frame range data.")
return
collection = collections[0]
repres_frames = list(collection.indexes)
return {
"frameStart": repres_frames[0],
"frameEnd": repres_frames[-1],
}

View file

@ -329,7 +329,7 @@
}
},
"publish": {
"CollectFrameRangeData": {
"CollectFrameDataFromAssetEntity": {
"enabled": true,
"optional": true,
"active": true

View file

@ -350,7 +350,7 @@
"name": "template_validate_plugin",
"template_data": [
{
"key": "CollectFrameRangeData",
"key": "CollectFrameDataFromAssetEntity",
"label": "Collect frame range from asset entity"
},
{