Merge pull request #5343 from ynput/enhancement/OP-5979_blender-extract-camera-alembic

This commit is contained in:
Simone Barbieri 2023-07-25 11:02:34 +01:00 committed by GitHub
commit a87fdd5173
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 15 deletions

View file

@ -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,25 @@ class ExtractABC(publish.Extractor):
plugin.deselect_all()
selected = []
asset_group = None
active = None
for obj in instance:
obj.select_set(True)
selected.append(obj)
# Set as active the asset group
if obj.get(AVALON_PROPERTY):
asset_group = obj
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=False
)
plugin.deselect_all()

View file

@ -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)

View file

@ -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

View file

@ -85,6 +85,11 @@
"optional": true,
"active": true
},
"ExtractCameraABC": {
"enabled": true,
"optional": true,
"active": true
},
"ExtractLayout": {
"enabled": true,
"optional": true,

View file

@ -105,7 +105,11 @@
},
{
"key": "ExtractCamera",
"label": "Extract FBX Camera as FBX"
"label": "Extract Camera as FBX"
},
{
"key": "ExtractCameraABC",
"label": "Extract Camera as ABC"
},
{
"key": "ExtractLayout",
@ -174,4 +178,4 @@
]
}
]
}
}