refactor: use uuid for collection loading

This commit is contained in:
Swann
2020-08-28 11:27:03 +02:00
parent 00d60be75b
commit f26c3b2606

View File

@ -47,27 +47,23 @@ class BlCollection(BlDatablock):
def _load_implementation(self, data, target): def _load_implementation(self, data, target):
loader = Loader() loader = Loader()
loader.load(target,data) loader.load(target,data)
# Load other meshes metadata
# target.name = data["name"]
# Objects # Objects
for object in data["objects"]: for object in data["objects"]:
object_ref = bpy.data.objects.get(object) object_ref = utils.find_from_attr('uuid', object, bpy.data.object)
if object_ref is None: if object_ref is None:
continue continue
elif object not in target.objects.keys():
if object not in target.objects.keys():
target.objects.link(object_ref) target.objects.link(object_ref)
for object in target.objects: for object in target.objects:
if object.name not in data["objects"]: if object.uuid not in data["objects"]:
target.objects.unlink(object) target.objects.unlink(object)
# Link childrens # Link childrens
for collection in data["children"]: for collection in data["children"]:
collection_ref = bpy.data.collections.get(collection) collection_ref = utils.find_from_attr('uuid', collection, bpy.data.collections)
if collection_ref is None: if collection_ref is None:
continue continue
@ -75,7 +71,7 @@ class BlCollection(BlDatablock):
target.children.link(collection_ref) target.children.link(collection_ref)
for collection in target.children: for collection in target.children:
if collection.name not in data["children"]: if collection.uuid not in data["children"]:
target.children.unlink(collection) target.children.unlink(collection)
def _dump_implementation(self, data, instance=None): def _dump_implementation(self, data, instance=None):
@ -93,7 +89,7 @@ class BlCollection(BlDatablock):
collection_objects = [] collection_objects = []
for object in instance.objects: for object in instance.objects:
if object not in collection_objects: if object not in collection_objects:
collection_objects.append(object.name) collection_objects.append(object.uuid)
data['objects'] = collection_objects data['objects'] = collection_objects
@ -101,7 +97,7 @@ class BlCollection(BlDatablock):
collection_children = [] collection_children = []
for child in instance.children: for child in instance.children:
if child not in collection_children: if child not in collection_children:
collection_children.append(child.name) collection_children.append(child.uuid)
data['children'] = collection_children data['children'] = collection_children