diff --git a/multi_user/bl_types/bl_datablock.py b/multi_user/bl_types/bl_datablock.py index 27d3f69..22ccb3a 100644 --- a/multi_user/bl_types/bl_datablock.py +++ b/multi_user/bl_types/bl_datablock.py @@ -113,7 +113,7 @@ class BlDatablock(ReplicatedDatablock): if instance and hasattr(instance, 'uuid'): instance.uuid = self.uuid - self.diff_method = DIFF_BINARY + # self.diff_method = DIFF_BINARY def resolve(self): datablock_ref = None diff --git a/multi_user/bl_types/bl_object.py b/multi_user/bl_types/bl_object.py index 6d82400..0414393 100644 --- a/multi_user/bl_types/bl_object.py +++ b/multi_user/bl_types/bl_object.py @@ -22,6 +22,7 @@ import bpy import mathutils from replication.exception import ContextError +from ..utils import get_datablock_from_uuid from .bl_datablock import BlDatablock from .dump_anything import Dumper, Loader from replication.exception import ReparentException @@ -32,6 +33,7 @@ def load_pose(target_bone, data): loader = Loader() loader.load(target_bone, data) + def find_data_from_name(name=None): instance = None if not name: @@ -65,10 +67,12 @@ def find_data_from_name(name=None): "Lightprobe replication only supported since 2.83. See https://developer.blender.org/D6396") return instance + def load_data(object, name): logging.info("loading data") pass + def _is_editmode(object: bpy.types.Object) -> bool: child_data = getattr(object, 'data', None) return (child_data and @@ -99,7 +103,12 @@ class BlObject(BlDatablock): # TODO: refactoring object_name = data.get("name") - object_data = find_data_from_name(data.get("data")) + data_uuid = data.get("data_uuid") + data_id = data.get("data") + + object_data = get_datablock_from_uuid( + data_uuid, + find_data_from_name(data_id)) #TODO: use resolve_from_id instance = bpy.data.objects.new(object_name, object_data) instance.uuid = self.uuid @@ -107,18 +116,21 @@ class BlObject(BlDatablock): def _load_implementation(self, data, target): loader = Loader() - + + data_uuid = data.get("data_uuid") + data_id = data.get("data") + if target.type != data['type']: raise ReparentException() - elif target.data.name != data['data']: - target.data = find_data_from_name(data['data']) + elif target.data.name != data_id: + target.data = get_datablock_from_uuid(data_uuid, find_data_from_name(data_id)) # vertex groups if 'vertex_groups' in data: target.vertex_groups.clear() for vg in data['vertex_groups']: - vertex_group = target.vertex_groups.new(name=vg['name']) - point_attr = 'vertices' if 'vertices' in vg else 'points' + vertex_group=target.vertex_groups.new(name = vg['name']) + point_attr='vertices' if 'vertices' in vg else 'points' for vert in vg[point_attr]: vertex_group.add( [vert['index']], vert['weight'], 'REPLACE') @@ -127,12 +139,12 @@ class BlObject(BlDatablock): if 'shape_keys' in data: target.shape_key_clear() - object_data = target.data + object_data=target.data # Create keys and load vertices coords for key_block in data['shape_keys']['key_blocks']: - key_data = data['shape_keys']['key_blocks'][key_block] - target.shape_key_add(name=key_block) + key_data=data['shape_keys']['key_blocks'][key_block] + target.shape_key_add(name = key_block) loader.load( target.data.shape_keys.key_blocks[key_block], key_data) @@ -198,7 +210,7 @@ class BlObject(BlDatablock): "name", "rotation_mode", "parent", - "data", + "data" "children", "library", "empty_display_type", @@ -223,7 +235,7 @@ class BlObject(BlDatablock): ] data = dumper.dump(instance) - + data['data_uuid'] = instance.data.uuid if self.is_library: return data diff --git a/multi_user/utils.py b/multi_user/utils.py index a71e772..7524d63 100644 --- a/multi_user/utils.py +++ b/multi_user/utils.py @@ -78,6 +78,14 @@ def resolve_from_id(id, optionnal_type=None): return root[id] return None +def get_datablock_from_uuid(uuid, default): + for category in dir(bpy.data): + root = getattr(bpy.data, category) + if isinstance(root, Iterable): + for item in root: + if getattr(item, 'uuid', None) == uuid: + return item + return default def get_preferences(): return bpy.context.preferences.addons[__package__].preferences