From 1ceda4712a66d85396b868eb46871ad8e98533ee Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Mon, 24 Jul 2023 14:28:49 +0100 Subject: [PATCH 1/4] 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() From 3f47ab0fb6456b1858c84d255978dbde2d346c16 Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Mon, 24 Jul 2023 14:46:10 +0100 Subject: [PATCH 2/4] Moved camera abc extraction to separate class --- .../blender/plugins/publish/extract_abc.py | 37 ++-------- .../plugins/publish/extract_camera_abc.py | 73 +++++++++++++++++++ 2 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 openpype/hosts/blender/plugins/publish/extract_camera_abc.py diff --git a/openpype/hosts/blender/plugins/publish/extract_abc.py b/openpype/hosts/blender/plugins/publish/extract_abc.py index a2bff0c2f7..f4babc94d3 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", "camera"] + families = ["model", "pointcache"] optional = True def process(self, instance): @@ -31,33 +31,12 @@ class ExtractABC(publish.Extractor): selected = [] active = None - 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 + 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=active, selected=selected) @@ -67,7 +46,7 @@ class ExtractABC(publish.Extractor): bpy.ops.wm.alembic_export( filepath=filepath, selected=True, - flatten=flatten + flatten=False ) plugin.deselect_all() diff --git a/openpype/hosts/blender/plugins/publish/extract_camera_abc.py b/openpype/hosts/blender/plugins/publish/extract_camera_abc.py new file mode 100644 index 0000000000..a21a59b151 --- /dev/null +++ b/openpype/hosts/blender/plugins/publish/extract_camera_abc.py @@ -0,0 +1,73 @@ +import os + +import bpy + +from openpype.pipeline import publish +from openpype.hosts.blender.api import plugin +from openpype.hosts.blender.api.pipeline import AVALON_PROPERTY + + +class ExtractCameraABC(publish.Extractor): + """Extract camera as ABC.""" + + label = "Extract Camera (ABC)" + hosts = ["blender"] + families = ["camera"] + optional = True + + def process(self, instance): + # Define extract output file path + stagingdir = self.staging_dir(instance) + filename = f"{instance.name}.abc" + filepath = os.path.join(stagingdir, filename) + + context = bpy.context + + # Perform extraction + self.log.info("Performing extraction..") + + plugin.deselect_all() + + selected = [] + active = None + + 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) + + context = plugin.create_blender_context( + active=active, selected=selected) + + with bpy.context.temp_override(**context): + # We export the abc + bpy.ops.wm.alembic_export( + filepath=filepath, + selected=True, + flatten=True + ) + + plugin.deselect_all() + + if "representations" not in instance.data: + instance.data["representations"] = [] + + representation = { + 'name': 'abc', + 'ext': 'abc', + 'files': filename, + "stagingDir": stagingdir, + } + instance.data["representations"].append(representation) + + self.log.info("Extracted instance '%s' to: %s", + instance.name, representation) From 7e043501817b3ab6c0619d50875b1f8a4dd04619 Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Mon, 24 Jul 2023 14:48:04 +0100 Subject: [PATCH 3/4] Added setting for new extractor --- openpype/settings/defaults/project_settings/blender.json | 5 +++++ .../projects_schema/schemas/schema_blender_publish.json | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/openpype/settings/defaults/project_settings/blender.json b/openpype/settings/defaults/project_settings/blender.json index fb11e727b3..df865adeba 100644 --- a/openpype/settings/defaults/project_settings/blender.json +++ b/openpype/settings/defaults/project_settings/blender.json @@ -85,6 +85,11 @@ "optional": true, "active": true }, + "ExtractCameraABC": { + "enabled": true, + "optional": true, + "active": true + }, "ExtractLayout": { "enabled": true, "optional": true, diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_blender_publish.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_blender_publish.json index 1037519f57..d4cafcd62a 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_blender_publish.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_blender_publish.json @@ -107,6 +107,10 @@ "key": "ExtractCamera", "label": "Extract FBX Camera as FBX" }, + { + "key": "ExtractCameraABC", + "label": "Extract Camera as ABC" + }, { "key": "ExtractLayout", "label": "Extract Layout as JSON" @@ -174,4 +178,4 @@ ] } ] -} \ No newline at end of file +} From 225cbd2ffe3825c3b6ff46c6f31d96f47027b1e2 Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Mon, 24 Jul 2023 14:49:50 +0100 Subject: [PATCH 4/4] Minor changes to FBX camera extractor to improve clarity --- .../publish/{extract_camera.py => extract_camera_fbx.py} | 2 +- .../schemas/projects_schema/schemas/schema_blender_publish.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename openpype/hosts/blender/plugins/publish/{extract_camera.py => extract_camera_fbx.py} (98%) diff --git a/openpype/hosts/blender/plugins/publish/extract_camera.py b/openpype/hosts/blender/plugins/publish/extract_camera_fbx.py similarity index 98% rename from openpype/hosts/blender/plugins/publish/extract_camera.py rename to openpype/hosts/blender/plugins/publish/extract_camera_fbx.py index 9fd181825c..315994140e 100644 --- a/openpype/hosts/blender/plugins/publish/extract_camera.py +++ b/openpype/hosts/blender/plugins/publish/extract_camera_fbx.py @@ -9,7 +9,7 @@ from openpype.hosts.blender.api import plugin class ExtractCamera(publish.Extractor): """Extract as the camera as FBX.""" - label = "Extract Camera" + label = "Extract Camera (FBX)" hosts = ["blender"] families = ["camera"] optional = True diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_blender_publish.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_blender_publish.json index d4cafcd62a..2f0bf0a831 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_blender_publish.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_blender_publish.json @@ -105,7 +105,7 @@ }, { "key": "ExtractCamera", - "label": "Extract FBX Camera as FBX" + "label": "Extract Camera as FBX" }, { "key": "ExtractCameraABC",