diff --git a/openpype/plugins/publish/collect_frame_range_asset_entity.py b/openpype/plugins/publish/collect_frame_range_asset_entity.py new file mode 100644 index 0000000000..2f7570466c --- /dev/null +++ b/openpype/plugins/publish/collect_frame_range_asset_entity.py @@ -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.") diff --git a/openpype/plugins/publish/collect_frame_range_data.py b/openpype/plugins/publish/collect_frame_range_data.py deleted file mode 100644 index c25aacd7f3..0000000000 --- a/openpype/plugins/publish/collect_frame_range_data.py +++ /dev/null @@ -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), - ] diff --git a/openpype/plugins/publish/collect_sequence_frame_data.py b/openpype/plugins/publish/collect_sequence_frame_data.py new file mode 100644 index 0000000000..5b5c427d9e --- /dev/null +++ b/openpype/plugins/publish/collect_sequence_frame_data.py @@ -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], + } diff --git a/openpype/settings/defaults/project_settings/traypublisher.json b/openpype/settings/defaults/project_settings/traypublisher.json index b7a01e584b..dda958ebcd 100644 --- a/openpype/settings/defaults/project_settings/traypublisher.json +++ b/openpype/settings/defaults/project_settings/traypublisher.json @@ -329,7 +329,7 @@ } }, "publish": { - "CollectFrameRangeData": { + "CollectFrameDataFromAssetEntity": { "enabled": true, "optional": true, "active": true diff --git a/openpype/settings/entities/schemas/projects_schema/schema_project_traypublisher.json b/openpype/settings/entities/schemas/projects_schema/schema_project_traypublisher.json index 4a54c6b4b4..184fc657be 100644 --- a/openpype/settings/entities/schemas/projects_schema/schema_project_traypublisher.json +++ b/openpype/settings/entities/schemas/projects_schema/schema_project_traypublisher.json @@ -350,7 +350,7 @@ "name": "template_validate_plugin", "template_data": [ { - "key": "CollectFrameRangeData", + "key": "CollectFrameDataFromAssetEntity", "label": "Collect frame range from asset entity" }, {