diff --git a/multi_user/bl_types/bl_volume.py b/multi_user/bl_types/bl_volume.py index 09cadec..cc7d28d 100644 --- a/multi_user/bl_types/bl_volume.py +++ b/multi_user/bl_types/bl_volume.py @@ -22,8 +22,9 @@ from pathlib import Path from .dump_anything import Loader, Dumper from replication.protocol import ReplicatedDatablock -from .bl_datablock import get_datablock_from_uuid +from .bl_datablock import get_datablock_from_uuid, resolve_datablock_from_uuid from .bl_material import dump_materials_slots, load_materials_slots +from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies class BlVolume(ReplicatedDatablock): bl_id = "volumes" @@ -32,22 +33,12 @@ class BlVolume(ReplicatedDatablock): bl_icon = 'VOLUME_DATA' bl_reload_parent = False - def load(data: dict, datablock: object): - loader = Loader() - loader.load(target, data) - loader.load(target.display, data['display']) - - # MATERIAL SLOTS - src_materials = data.get('materials', None) - if src_materials: - load_materials_slots(src_materials, target.materials) - + @staticmethod def construct(data: dict) -> object: return bpy.data.volumes.new(data["name"]) + @staticmethod def dump(datablock: object) -> dict: - assert(instance) - dumper = Dumper() dumper.depth = 1 dumper.exclude_filter = [ @@ -61,27 +52,53 @@ class BlVolume(ReplicatedDatablock): 'use_fake_user' ] - data = dumper.dump(instance) + data = dumper.dump(datablock) - data['display'] = dumper.dump(instance.display) + data['display'] = dumper.dump(datablock.display) # Fix material index - data['materials'] = dump_materials_slots(instance.materials) - + data['materials'] = dump_materials_slots(datablock.materials) + data['animation_data'] = dump_animation_data(datablock) return data + @staticmethod + def load(data: dict, datablock: object): + load_animation_data(datablock.get('animation_data'), datablock) + loader = Loader() + loader.load(datablock, data) + loader.load(datablock.display, data['display']) + + # MATERIAL SLOTS + src_materials = data.get('materials', None) + if src_materials: + load_materials_slots(src_materials, datablock.materials) + + @staticmethod + def resolve(data: dict) -> object: + uuid = data.get('uuid') + name = data.get('name') + datablock = resolve_datablock_from_uuid(uuid, bpy.data.volumes) + if datablock is None: + datablock = bpy.data.volumes.get(name) + + return datablock + + @staticmethod def resolve_deps(datablock: object) -> [object]: # TODO: resolve material deps = [] - external_vdb = Path(bpy.path.abspath(self.instance.filepath)) + external_vdb = Path(bpy.path.abspath(datablock.filepath)) if external_vdb.exists() and not external_vdb.is_dir(): deps.append(external_vdb) - for material in self.instance.materials: + for material in datablock.materials: if material: deps.append(material) + deps.extend(resolve_animation_dependencies(datablock)) + return deps - +_type = bpy.types.Volume +_class = BlVolume diff --git a/multi_user/bl_types/bl_world.py b/multi_user/bl_types/bl_world.py index af23eef..d55c20c 100644 --- a/multi_user/bl_types/bl_world.py +++ b/multi_user/bl_types/bl_world.py @@ -25,6 +25,9 @@ from .bl_material import (load_node_tree, dump_node_tree, get_node_tree_dependencies) +from .bl_datablock import resolve_datablock_from_uuid +from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies + class BlWorld(ReplicatedDatablock): bl_id = "worlds" @@ -33,22 +36,24 @@ class BlWorld(ReplicatedDatablock): bl_icon = 'WORLD_DATA' bl_reload_parent = False + @staticmethod def construct(data: dict) -> object: return bpy.data.worlds.new(data["name"]) + @staticmethod def load(data: dict, datablock: object): + load_animation_data(datablock.get('animation_data'), datablock) loader = Loader() - loader.load(target, data) + loader.load(datablock, data) if data["use_nodes"]: - if target.node_tree is None: - target.use_nodes = True + if datablock.node_tree is None: + datablock.use_nodes = True - load_node_tree(data['node_tree'], target.node_tree) + load_node_tree(data['node_tree'], datablock.node_tree) + @staticmethod def dump(datablock: object) -> dict: - assert(instance) - world_dumper = Dumper() world_dumper.depth = 1 world_dumper.include_filter = [ @@ -56,17 +61,32 @@ class BlWorld(ReplicatedDatablock): "name", "color" ] - data = world_dumper.dump(instance) - if instance.use_nodes: - data['node_tree'] = dump_node_tree(instance.node_tree) + data = world_dumper.dump(datablock) + if datablock.use_nodes: + data['node_tree'] = dump_node_tree(datablock.node_tree) + data['animation_data'] = dump_animation_data(datablock) return data + + @staticmethod + def resolve(data: dict) -> object: + uuid = data.get('uuid') + name = data.get('name') + datablock = resolve_datablock_from_uuid(uuid, bpy.data.worlds) + if datablock is None: + datablock = bpy.data.worlds.get(name) + return datablock + + @staticmethod def resolve_deps(datablock: object) -> [object]: deps = [] - if self.instance.use_nodes: - deps.extend(get_node_tree_dependencies(self.instance.node_tree)) - if self.is_library: - deps.append(self.instance.library) + if datablock.use_nodes: + deps.extend(get_node_tree_dependencies(datablock.node_tree)) + + deps.extend(resolve_animation_dependencies(datablock)) return deps + +_type = bpy.types.World +_class = BlWorld \ No newline at end of file