mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-27 06:12:19 +01:00
Objects imported are stored in collections for each scene
This commit is contained in:
parent
c053762fed
commit
a0c60afb28
1 changed files with 29 additions and 6 deletions
|
|
@ -1,8 +1,20 @@
|
|||
from pathlib import Path
|
||||
|
||||
import bpy
|
||||
|
||||
from openpype.hosts.blender.api import plugin
|
||||
|
||||
|
||||
def get_unique_number(asset, subset):
|
||||
count = 1
|
||||
name = f"{asset}_{count:0>2}_{subset}"
|
||||
collection_names = [coll.name for coll in bpy.data.collections]
|
||||
while name in collection_names:
|
||||
count += 1
|
||||
name = f"{asset}_{count:0>2}_{subset}"
|
||||
return f"{count:0>2}"
|
||||
|
||||
|
||||
class AppendBlendLoader(plugin.AssetLoader):
|
||||
"""Append workfile in Blender (unmanaged)
|
||||
|
||||
|
|
@ -28,6 +40,7 @@ class AppendBlendLoader(plugin.AssetLoader):
|
|||
# We do not containerize imported content, it remains unmanaged
|
||||
return
|
||||
|
||||
|
||||
class ImportBlendLoader(plugin.AssetLoader):
|
||||
"""Import workfile in the current Blender scene (unmanaged)
|
||||
|
||||
|
|
@ -46,16 +59,26 @@ class ImportBlendLoader(plugin.AssetLoader):
|
|||
color = "#775555"
|
||||
|
||||
def load(self, context, name=None, namespace=None, data=None):
|
||||
asset = context['asset']['name']
|
||||
subset = context['subset']['name']
|
||||
|
||||
unique_number = get_unique_number(asset, subset)
|
||||
group_name = plugin.asset_name(asset, subset, unique_number)
|
||||
|
||||
with bpy.data.libraries.load(self.fname) as (data_from, data_to):
|
||||
for attr in dir(data_to):
|
||||
if attr == "scenes":
|
||||
continue
|
||||
setattr(data_to, attr, getattr(data_from, attr))
|
||||
|
||||
# Add objects to current scene
|
||||
scene = bpy.context.scene
|
||||
for obj in data_to.objects:
|
||||
scene.collection.objects.link(obj)
|
||||
current_scene = bpy.context.scene
|
||||
|
||||
for scene in data_to.scenes:
|
||||
# scene.name = group_name
|
||||
collection = bpy.data.collections.new(name=group_name)
|
||||
for obj in scene.objects:
|
||||
collection.objects.link(obj)
|
||||
current_scene.collection.children.link(collection)
|
||||
for coll in scene.collection.children:
|
||||
collection.children.link(coll)
|
||||
|
||||
# We do not containerize imported content, it remains unmanaged
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue