feat: particle texture slot support

This commit is contained in:
Swann 2021-04-14 09:45:18 +02:00
parent 5ee4988aca
commit 826a59085e
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB

View File

@ -4,7 +4,11 @@ import mathutils
from . import dump_anything
from .bl_datablock import BlDatablock, get_datablock_from_uuid
def dump_textures_slots(texture_slots):
def dump_textures_slots(texture_slots: bpy.types.bpy_prop_collection) -> list:
""" Dump every texture slot collection as the form:
[(index, slot_texture_uuid, slot_texture_name), (), ...]
"""
dumped_slots = []
for index, slot in enumerate(texture_slots):
if slot and slot.texture:
@ -12,12 +16,19 @@ def dump_textures_slots(texture_slots):
return dumped_slots
def load_texture_slots(dumped_slots, target_slots):
def load_texture_slots(dumped_slots: list, target_slots: bpy.types.bpy_prop_collection):
"""
"""
for index, slot in enumerate(target_slots):
if slot:
target_slots.clear(index)
for index, slot_uuid, slot_name in dumped_slots:
target_slots.create(index).texture = get_datablock_from_uuid(slot_uuid, slot_name)
target_slots.create(index).texture = get_datablock_from_uuid(
slot_uuid, slot_name
)
class BlParticle(BlDatablock):
bl_id = "particles"
@ -32,19 +43,19 @@ class BlParticle(BlDatablock):
def _load_implementation(self, data, target):
dump_anything.load(target, data)
dump_anything.load(target.effector_weights, data['effector_weights'])
dump_anything.load(target.effector_weights, data["effector_weights"])
# Force field
force_field_1 = data.get('force_field_1', None)
force_field_1 = data.get("force_field_1", None)
if force_field_1:
dump_anything.load(target.force_field_1, force_field_1)
force_field_2 = data.get('force_field_2', None)
force_field_2 = data.get("force_field_2", None)
if force_field_2:
dump_anything.load(target.force_field_2, force_field_2)
# Texture slots
# load_texture_slots(data['texture_slots'], target.texture_slots)
load_texture_slots(data["texture_slots"], target.texture_slots)
def _dump_implementation(self, data, instance=None):
assert instance
@ -54,16 +65,16 @@ class BlParticle(BlDatablock):
data = dumper.dump(instance)
# Particle effectors
data['effector_weights'] = dumper.dump(instance.effector_weights)
data["effector_weights"] = dumper.dump(instance.effector_weights)
if instance.force_field_1:
data['force_field_1'] = dumper.dump(instance.force_field_1)
data["force_field_1"] = dumper.dump(instance.force_field_1)
if instance.force_field_2:
data['force_field_2'] = dumper.dump(instance.force_field_2)
data["force_field_2"] = dumper.dump(instance.force_field_2)
# Texture slots
# data['texture_slots'] = dump_textures_slots(instance.texture_slots)
data["texture_slots"] = dump_textures_slots(instance.texture_slots)
return data
def _resolve_deps_implementation(self):
return [ t.texture for t in self.instance.texture_slots if t]
return [t.texture for t in self.instance.texture_slots if t and t.texture]