This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4128 from pypeclub/feature/blender-extract_alembi…
…c_animation Blender: Extract Alembic Animations
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
openpype/hosts/blender/plugins/publish/extract_abc_animation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import os | ||
|
||
import bpy | ||
|
||
from openpype.pipeline import publish | ||
from openpype.hosts.blender.api import plugin | ||
|
||
|
||
class ExtractAnimationABC(publish.Extractor): | ||
"""Extract as ABC.""" | ||
|
||
label = "Extract Animation ABC" | ||
hosts = ["blender"] | ||
families = ["animation"] | ||
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 = [] | ||
asset_group = None | ||
|
||
objects = [] | ||
for obj in instance: | ||
if isinstance(obj, bpy.types.Collection): | ||
for child in obj.all_objects: | ||
objects.append(child) | ||
for obj in objects: | ||
children = [o for o in bpy.data.objects if o.parent == obj] | ||
for child in children: | ||
objects.append(child) | ||
|
||
for obj in objects: | ||
obj.select_set(True) | ||
selected.append(obj) | ||
|
||
context = plugin.create_blender_context( | ||
active=asset_group, selected=selected) | ||
|
||
# We export the abc | ||
bpy.ops.wm.alembic_export( | ||
context, | ||
filepath=filepath, | ||
selected=True, | ||
flatten=False | ||
) | ||
|
||
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) |