From 1ceda4712a66d85396b868eb46871ad8e98533ee Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Mon, 24 Jul 2023 14:28:49 +0100 Subject: [PATCH] Added support for camera in abc extractor --- .../blender/plugins/publish/extract_abc.py | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/openpype/hosts/blender/plugins/publish/extract_abc.py b/openpype/hosts/blender/plugins/publish/extract_abc.py index 1cab9d225b..a2bff0c2f7 100644 --- a/openpype/hosts/blender/plugins/publish/extract_abc.py +++ b/openpype/hosts/blender/plugins/publish/extract_abc.py @@ -12,7 +12,7 @@ class ExtractABC(publish.Extractor): label = "Extract ABC" hosts = ["blender"] - families = ["model", "pointcache"] + families = ["model", "pointcache", "camera"] optional = True def process(self, instance): @@ -22,8 +22,6 @@ class ExtractABC(publish.Extractor): filepath = os.path.join(stagingdir, filename) context = bpy.context - scene = context.scene - view_layer = context.view_layer # Perform extraction self.log.info("Performing extraction..") @@ -31,24 +29,46 @@ class ExtractABC(publish.Extractor): plugin.deselect_all() selected = [] - asset_group = None + active = None - for obj in instance: - obj.select_set(True) - selected.append(obj) - if obj.get(AVALON_PROPERTY): - asset_group = obj + flatten = False + + family = instance.data.get("family") + + if family == "camera": + asset_group = None + for obj in instance: + if obj.get(AVALON_PROPERTY): + asset_group = obj + break + assert asset_group, "No asset group found" + + # Need to cast to list because children is a tuple + selected = list(asset_group.children) + active = selected[0] + + for obj in selected: + obj.select_set(True) + + flatten = True + else: + for obj in instance: + obj.select_set(True) + selected.append(obj) + # Set as active the asset group + if obj.get(AVALON_PROPERTY): + active = obj context = plugin.create_blender_context( - active=asset_group, selected=selected) + active=active, selected=selected) - # We export the abc - bpy.ops.wm.alembic_export( - context, - filepath=filepath, - selected=True, - flatten=False - ) + with bpy.context.temp_override(**context): + # We export the abc + bpy.ops.wm.alembic_export( + filepath=filepath, + selected=True, + flatten=flatten + ) plugin.deselect_all()