diff --git a/multi_user/bl_types/bl_volume.py b/multi_user/bl_types/bl_volume.py index 377bdb9..fc67012 100644 --- a/multi_user/bl_types/bl_volume.py +++ b/multi_user/bl_types/bl_volume.py @@ -21,7 +21,7 @@ import mathutils from pathlib import Path from .dump_anything import Loader, Dumper -from .bl_datablock import BlDatablock +from .bl_datablock import BlDatablock, get_datablock_from_uuid class BlVolume(BlDatablock): @@ -39,6 +39,21 @@ class BlVolume(BlDatablock): loader.load(target, data) loader.load(target.display, data['display']) + # MATERIAL SLOTS + target.materials.clear() + + for mat_uuid, mat_name in data["material_list"]: + mat_ref = None + if mat_uuid is not None: + mat_ref = get_datablock_from_uuid(mat_uuid, None) + else: + mat_ref = bpy.data.materials.get(mat_name, None) + + if mat_ref is None: + raise Exception("Material doesn't exist") + + target.materials.append(mat_ref) + def _construct(self, data): return bpy.data.volumes.new(data["name"]) @@ -62,6 +77,9 @@ class BlVolume(BlDatablock): data['display'] = dumper.dump(instance.display) + # Fix material index + data['material_list'] = [(m.uuid, m.name) for m in instance.materials if m] + return data def _resolve_deps_implementation(self): @@ -72,6 +90,10 @@ class BlVolume(BlDatablock): if external_vdb.exists() and not external_vdb.is_dir(): deps.append(external_vdb) + for material in self.instance.materials: + if material: + deps.append(material) + return deps