mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
Merge pull request #4234 from pypeclub/feature/blender-workfile_loader
Blender: Workfile Loader
This commit is contained in:
commit
6d2e862af5
1 changed files with 82 additions and 0 deletions
82
openpype/hosts/blender/plugins/load/import_workfile.py
Normal file
82
openpype/hosts/blender/plugins/load/import_workfile.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import bpy
|
||||
|
||||
from openpype.hosts.blender.api import plugin
|
||||
|
||||
|
||||
def append_workfile(context, fname, do_import):
|
||||
asset = context['asset']['name']
|
||||
subset = context['subset']['name']
|
||||
|
||||
group_name = plugin.asset_name(asset, subset)
|
||||
|
||||
# We need to preserve the original names of the scenes, otherwise,
|
||||
# if there are duplicate names in the current workfile, the imported
|
||||
# scenes will be renamed by Blender to avoid conflicts.
|
||||
original_scene_names = []
|
||||
|
||||
with bpy.data.libraries.load(fname) as (data_from, data_to):
|
||||
for attr in dir(data_to):
|
||||
if attr == "scenes":
|
||||
for scene in data_from.scenes:
|
||||
original_scene_names.append(scene)
|
||||
setattr(data_to, attr, getattr(data_from, attr))
|
||||
|
||||
current_scene = bpy.context.scene
|
||||
|
||||
for scene, s_name in zip(data_to.scenes, original_scene_names):
|
||||
scene.name = f"{group_name}_{s_name}"
|
||||
if do_import:
|
||||
collection = bpy.data.collections.new(f"{group_name}_{s_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)
|
||||
|
||||
|
||||
class AppendBlendLoader(plugin.AssetLoader):
|
||||
"""Append workfile in Blender (unmanaged)
|
||||
|
||||
Warning:
|
||||
The loaded content will be unmanaged and is *not* visible in the
|
||||
scene inventory. It's purely intended to merge content into your scene
|
||||
so you could also use it as a new base.
|
||||
"""
|
||||
|
||||
representations = ["blend"]
|
||||
families = ["*"]
|
||||
|
||||
label = "Append Workfile"
|
||||
order = 9
|
||||
icon = "arrow-circle-down"
|
||||
color = "#775555"
|
||||
|
||||
def load(self, context, name=None, namespace=None, data=None):
|
||||
append_workfile(context, self.fname, False)
|
||||
|
||||
# We do not containerize imported content, it remains unmanaged
|
||||
return
|
||||
|
||||
|
||||
class ImportBlendLoader(plugin.AssetLoader):
|
||||
"""Import workfile in the current Blender scene (unmanaged)
|
||||
|
||||
Warning:
|
||||
The loaded content will be unmanaged and is *not* visible in the
|
||||
scene inventory. It's purely intended to merge content into your scene
|
||||
so you could also use it as a new base.
|
||||
"""
|
||||
|
||||
representations = ["blend"]
|
||||
families = ["*"]
|
||||
|
||||
label = "Import Workfile"
|
||||
order = 9
|
||||
icon = "arrow-circle-down"
|
||||
color = "#775555"
|
||||
|
||||
def load(self, context, name=None, namespace=None, data=None):
|
||||
append_workfile(context, self.fname, True)
|
||||
|
||||
# We do not containerize imported content, it remains unmanaged
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue