Support of collections in Rig assets

This commit is contained in:
Simone Barbieri 2020-06-10 10:06:39 +01:00
parent 391aef5ba8
commit 7dbc94eda7
2 changed files with 10 additions and 20 deletions

View file

@ -31,22 +31,11 @@ class CreateRig(Creator):
# This links automatically the children meshes if they were not
# selected, and doesn't link them twice if they, insted,
# were manually selected by the user.
objects_to_link = set()
if (self.options or {}).get("useSelection"):
for obj in lib.get_selection():
objects_to_link.add(obj)
if obj.type == 'ARMATURE':
for subobj in obj.children:
objects_to_link.add(subobj)
for obj in objects_to_link:
collection.objects.link(obj)
for child in obj.users_collection[0].children:
collection.children.link(child)
collection.objects.link(obj)
return collection

View file

@ -40,6 +40,9 @@ class BlendRigLoader(pype.hosts.blender.plugin.AssetLoader):
elif obj.type == 'MESH':
bpy.data.meshes.remove(obj.data)
for child in bpy.data.collections[lib_container].children:
bpy.data.collections.remove(child)
bpy.data.collections.remove(bpy.data.collections[lib_container])
@staticmethod
@ -57,32 +60,30 @@ class BlendRigLoader(pype.hosts.blender.plugin.AssetLoader):
rig_container = scene.collection.children[lib_container].make_local()
meshes = [obj for obj in rig_container.objects if obj.type == 'MESH']
meshes = []
armatures = [
obj for obj in rig_container.objects if obj.type == 'ARMATURE']
objects_list = []
assert(len(armatures) == 1)
for child in rig_container.children:
child.make_local()
meshes.extend( child.objects )
# Link meshes first, then armatures.
# The armature is unparented for all the non-local meshes,
# when it is made local.
for obj in meshes + armatures:
obj = obj.make_local()
obj.data.make_local()
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})
if obj.type == 'ARMATURE' and action is not None:
obj.animation_data.action = action
objects_list.append(obj)