mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Alembic loader is now more consistent with loaders for other formats
This commit is contained in:
parent
b1b7eda2ac
commit
5e54d09ca1
1 changed files with 42 additions and 27 deletions
|
|
@ -7,7 +7,6 @@ from typing import Dict, List, Optional
|
|||
|
||||
from avalon import api, blender
|
||||
import bpy
|
||||
import openpype.api
|
||||
import openpype.hosts.blender.api.plugin as plugin
|
||||
|
||||
|
||||
|
|
@ -109,10 +108,6 @@ class BlendModelLoader(plugin.AssetLoader):
|
|||
self.__class__.__name__,
|
||||
)
|
||||
|
||||
print(lib_container)
|
||||
print(container)
|
||||
|
||||
|
||||
container_metadata = container.get(
|
||||
blender.pipeline.AVALON_PROPERTY)
|
||||
|
||||
|
|
@ -265,6 +260,41 @@ class CacheModelLoader(plugin.AssetLoader):
|
|||
icon = "code-fork"
|
||||
color = "orange"
|
||||
|
||||
def _process(self, libpath, container_name, parent_collection):
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
|
||||
view_layer = bpy.context.view_layer
|
||||
view_layer_collection = view_layer.active_layer_collection.collection
|
||||
|
||||
relative = bpy.context.preferences.filepaths.use_relative_paths
|
||||
bpy.ops.wm.alembic_import(
|
||||
filepath=libpath,
|
||||
relative_path=relative
|
||||
)
|
||||
|
||||
parent = parent_collection
|
||||
|
||||
if parent is None:
|
||||
parent = bpy.context.scene.collection
|
||||
|
||||
model_container = bpy.data.collections.new(container_name)
|
||||
parent.children.link(model_container)
|
||||
for obj in bpy.context.selected_objects:
|
||||
model_container.objects.link(obj)
|
||||
view_layer_collection.objects.unlink(obj)
|
||||
obj.name = f"{obj.name}:{container_name}"
|
||||
obj.data.name = f"{obj.data.name}:{container_name}"
|
||||
|
||||
if not obj.get(blender.pipeline.AVALON_PROPERTY):
|
||||
obj[blender.pipeline.AVALON_PROPERTY] = dict()
|
||||
|
||||
avalon_info = obj[blender.pipeline.AVALON_PROPERTY]
|
||||
avalon_info.update({"container_name": container_name})
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
|
||||
return model_container
|
||||
|
||||
def process_asset(
|
||||
self, context: dict, name: str, namespace: Optional[str] = None,
|
||||
options: Optional[Dict] = None
|
||||
|
|
@ -308,30 +338,15 @@ class CacheModelLoader(plugin.AssetLoader):
|
|||
container_metadata["libpath"] = libpath
|
||||
container_metadata["lib_container"] = lib_container
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
obj_container = self._process(
|
||||
libpath, container_name, None)
|
||||
|
||||
view_layer = bpy.context.view_layer
|
||||
view_layer_collection = view_layer.active_layer_collection.collection
|
||||
container_metadata["obj_container"] = obj_container
|
||||
|
||||
relative = bpy.context.preferences.filepaths.use_relative_paths
|
||||
bpy.ops.wm.alembic_import(
|
||||
filepath=libpath,
|
||||
relative_path=relative
|
||||
)
|
||||
# Save the list of objects in the metadata container
|
||||
container_metadata["objects"] = obj_container.all_objects
|
||||
|
||||
parent = bpy.data.collections.new(container_name)
|
||||
for obj in bpy.context.selected_objects:
|
||||
parent.objects.link(obj)
|
||||
view_layer_collection.objects.unlink(obj)
|
||||
obj.name = f"{obj.name}:{container_name}"
|
||||
obj.data.name = f"{obj.data.name}:{container_name}"
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
|
||||
scene = bpy.context.scene
|
||||
scene.collection.children.link(parent)
|
||||
|
||||
nodes = list(parent.objects)
|
||||
nodes.append(parent)
|
||||
nodes = list(container.objects)
|
||||
nodes.append(container)
|
||||
self[:] = nodes
|
||||
return nodes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue