fead: added materials support for volumes

This commit is contained in:
Swann 2020-12-09 19:06:30 +01:00
parent 682c983a64
commit 54f416e8c3
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB

View File

@ -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