Merge branch '24-particle-support' into develop
This commit is contained in:
@@ -42,6 +42,7 @@ __all__ = [
|
||||
# 'bl_sequencer',
|
||||
'bl_node_group',
|
||||
'bl_texture',
|
||||
"bl_particle",
|
||||
] # Order here defines execution order
|
||||
|
||||
if bpy.app.version[1] >= 91:
|
||||
|
||||
@@ -381,6 +381,17 @@ class BlObject(BlDatablock):
|
||||
load_modifier_geometry_node_inputs(
|
||||
data['modifiers'][modifier.name], modifier)
|
||||
|
||||
particles_modifiers = [
|
||||
mod for mod in target.modifiers if mod.type == 'PARTICLE_SYSTEM']
|
||||
|
||||
for mod in particles_modifiers:
|
||||
loader.load(mod.particle_system, data['modifiers'][mod.name]['particle_system'])
|
||||
# default_settings = mod.particle_system.settings
|
||||
# mod.particle_system.settings = get_datablock_from_uuid(data['modifiers'][mod.name]['particle_system']['settings'], None)
|
||||
|
||||
# Hack to remove the default generated particle settings
|
||||
# bpy.data.particles.remove(default_settings)
|
||||
|
||||
transform = data.get('transforms', None)
|
||||
if transform:
|
||||
target.matrix_parent_inverse = mathutils.Matrix(
|
||||
@@ -460,12 +471,18 @@ class BlObject(BlDatablock):
|
||||
dumper.include_filter = None
|
||||
dumper.depth = 1
|
||||
for index, modifier in enumerate(modifiers):
|
||||
data["modifiers"][modifier.name] = dumper.dump(modifier)
|
||||
dumped_modifier = dumper.dump(modifier)
|
||||
# hack to dump geometry nodes inputs
|
||||
if modifier.type == 'NODES':
|
||||
dumped_inputs = dump_modifier_geometry_node_inputs(
|
||||
modifier)
|
||||
data["modifiers"][modifier.name]['inputs'] = dumped_inputs
|
||||
dumped_modifier['inputs'] = dumped_inputs
|
||||
|
||||
if modifier.type == 'PARTICLE_SYSTEM':
|
||||
dumped_modifier['particle_system'] = dumper.dump(modifier.particle_system)
|
||||
|
||||
data["modifiers"][modifier.name] = dumped_modifier
|
||||
|
||||
gp_modifiers = getattr(instance, 'grease_pencil_modifiers', None)
|
||||
|
||||
if gp_modifiers:
|
||||
@@ -487,6 +504,7 @@ class BlObject(BlDatablock):
|
||||
'location']
|
||||
gp_mod_data['curve'] = curve_dumper.dump(modifier.curve)
|
||||
|
||||
|
||||
# CONSTRAINTS
|
||||
if hasattr(instance, 'constraints'):
|
||||
dumper.include_filter = None
|
||||
@@ -592,6 +610,10 @@ class BlObject(BlDatablock):
|
||||
if self.instance.data:
|
||||
deps.append(self.instance.data)
|
||||
|
||||
# Particle systems
|
||||
for particle_slot in self.instance.particle_systems:
|
||||
deps.append(bpy.data.particles[particle_slot.name])
|
||||
|
||||
if self.is_library:
|
||||
deps.append(self.instance.library)
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from . import dump_anything
|
||||
from .bl_datablock import BlDatablock, get_datablock_from_uuid
|
||||
|
||||
def dump_textures_slots(texture_slots):
|
||||
dumped_slots = []
|
||||
for index, slot in enumerate(texture_slots):
|
||||
if slot and slot.texture:
|
||||
dumped_slots.append((index, slot.texture.uuid, slot.texture.name))
|
||||
|
||||
return dumped_slots
|
||||
|
||||
def load_texture_slots(dumped_slots, target_slots):
|
||||
for index, slot in enumerate(target_slots):
|
||||
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)
|
||||
|
||||
class BlParticle(BlDatablock):
|
||||
bl_id = "particles"
|
||||
bl_class = bpy.types.ParticleSettings
|
||||
bl_icon = "PARTICLES"
|
||||
bl_check_common = False
|
||||
bl_reload_parent = False
|
||||
|
||||
def _construct(self, data):
|
||||
return bpy.data.particles.new(data["name"])
|
||||
|
||||
def _load_implementation(self, data, target):
|
||||
dump_anything.load(target, data)
|
||||
|
||||
dump_anything.load(target.effector_weights, data['effector_weights'])
|
||||
|
||||
# Force field
|
||||
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)
|
||||
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)
|
||||
|
||||
def _dump_implementation(self, data, instance=None):
|
||||
assert instance
|
||||
|
||||
dumper = dump_anything.Dumper()
|
||||
dumper.depth = 1
|
||||
data = dumper.dump(instance)
|
||||
|
||||
# Particle effectors
|
||||
data['effector_weights'] = dumper.dump(instance.effector_weights)
|
||||
if 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)
|
||||
|
||||
# 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]
|
||||
@@ -610,6 +610,8 @@ class Loader:
|
||||
instance.write(bpy.data.fonts.get(dump))
|
||||
elif isinstance(rna_property_type, T.Sound):
|
||||
instance.write(bpy.data.sounds.get(dump))
|
||||
elif isinstance(rna_property_type, T.ParticleSettings):
|
||||
instance.write(bpy.data.particles.get(dump))
|
||||
|
||||
def _load_matrix(self, matrix, dump):
|
||||
matrix.write(mathutils.Matrix(dump))
|
||||
|
||||
Reference in New Issue
Block a user