mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Moved camera abc extraction to separate class
This commit is contained in:
parent
1ceda4712a
commit
3f47ab0fb6
2 changed files with 81 additions and 29 deletions
|
|
@ -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()
|
||||
|
|
|
|||
73
openpype/hosts/blender/plugins/publish/extract_camera_abc.py
Normal file
73
openpype/hosts/blender/plugins/publish/extract_camera_abc.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue