refactor: add particle and lattive back
This commit is contained in:
parent
3f6e4f7333
commit
2e261cd66b
@ -22,6 +22,8 @@ import mathutils
|
|||||||
from .dump_anything import Dumper, Loader, np_dump_collection, np_load_collection
|
from .dump_anything import Dumper, Loader, np_dump_collection, np_load_collection
|
||||||
from replication.protocol import ReplicatedDatablock
|
from replication.protocol import ReplicatedDatablock
|
||||||
from replication.exception import ContextError
|
from replication.exception import ContextError
|
||||||
|
from .bl_datablock import resolve_datablock_from_uuid
|
||||||
|
from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies
|
||||||
|
|
||||||
POINT = ['co', 'weight_softbody', 'co_deform']
|
POINT = ['co', 'weight_softbody', 'co_deform']
|
||||||
|
|
||||||
@ -33,20 +35,24 @@ class BlLattice(ReplicatedDatablock):
|
|||||||
bl_icon = 'LATTICE_DATA'
|
bl_icon = 'LATTICE_DATA'
|
||||||
bl_reload_parent = False
|
bl_reload_parent = False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def construct(data: dict) -> object:
|
def construct(data: dict) -> object:
|
||||||
return bpy.data.lattices.new(data["name"])
|
return bpy.data.lattices.new(data["name"])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def load(data: dict, datablock: object):
|
def load(data: dict, datablock: object):
|
||||||
if target.is_editmode:
|
load_animation_data(datablock.get('animation_data'), datablock)
|
||||||
|
if datablock.is_editmode:
|
||||||
raise ContextError("lattice is in edit mode")
|
raise ContextError("lattice is in edit mode")
|
||||||
|
|
||||||
loader = Loader()
|
loader = Loader()
|
||||||
loader.load(target, data)
|
loader.load(datablock, data)
|
||||||
|
|
||||||
np_load_collection(data['points'], target.points, POINT)
|
np_load_collection(data['points'], datablock.points, POINT)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def dump(datablock: object) -> dict:
|
def dump(datablock: object) -> dict:
|
||||||
if instance.is_editmode:
|
if datablock.is_editmode:
|
||||||
raise ContextError("lattice is in edit mode")
|
raise ContextError("lattice is in edit mode")
|
||||||
|
|
||||||
dumper = Dumper()
|
dumper = Dumper()
|
||||||
@ -62,9 +68,25 @@ class BlLattice(ReplicatedDatablock):
|
|||||||
'interpolation_type_w',
|
'interpolation_type_w',
|
||||||
'use_outside'
|
'use_outside'
|
||||||
]
|
]
|
||||||
data = dumper.dump(instance)
|
data = dumper.dump(datablock)
|
||||||
|
|
||||||
data['points'] = np_dump_collection(instance.points, POINT)
|
|
||||||
|
|
||||||
|
data['points'] = np_dump_collection(datablock.points, POINT)
|
||||||
|
data['animation_data'] = dump_animation_data(datablock)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def resolve(data: dict) -> object:
|
||||||
|
uuid = data.get('uuid')
|
||||||
|
name = data.get('name')
|
||||||
|
datablock = resolve_datablock_from_uuid(uuid, bpy.data.lattices)
|
||||||
|
if datablock is None:
|
||||||
|
datablock = bpy.data.lattices.get(name)
|
||||||
|
|
||||||
|
return datablock
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def resolve_deps(datablock: object) -> [object]:
|
||||||
|
return resolve_animation_dependencies(datablock)
|
||||||
|
|
||||||
|
_type = bpy.types.Lattice
|
||||||
|
_class = BlLattice
|
@ -4,6 +4,8 @@ import mathutils
|
|||||||
from . import dump_anything
|
from . import dump_anything
|
||||||
from replication.protocol import ReplicatedDatablock
|
from replication.protocol import ReplicatedDatablock
|
||||||
from .bl_datablock import get_datablock_from_uuid
|
from .bl_datablock import get_datablock_from_uuid
|
||||||
|
from .bl_datablock import resolve_datablock_from_uuid
|
||||||
|
from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies
|
||||||
|
|
||||||
|
|
||||||
def dump_textures_slots(texture_slots: bpy.types.bpy_prop_collection) -> list:
|
def dump_textures_slots(texture_slots: bpy.types.bpy_prop_collection) -> list:
|
||||||
@ -45,47 +47,63 @@ class BlParticle(ReplicatedDatablock):
|
|||||||
bl_check_common = False
|
bl_check_common = False
|
||||||
bl_reload_parent = False
|
bl_reload_parent = False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def construct(data: dict) -> object:
|
def construct(data: dict) -> object:
|
||||||
instance = bpy.data.particles.new(data["name"])
|
return bpy.data.particles.new(data["name"])
|
||||||
instance.uuid = self.uuid
|
|
||||||
return instance
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def load(data: dict, datablock: object):
|
def load(data: dict, datablock: object):
|
||||||
dump_anything.load(target, data)
|
load_animation_data(datablock.get('animation_data'), datablock)
|
||||||
|
dump_anything.load(datablock, data)
|
||||||
|
|
||||||
dump_anything.load(target.effector_weights, data["effector_weights"])
|
dump_anything.load(datablock.effector_weights, data["effector_weights"])
|
||||||
|
|
||||||
# Force field
|
# Force field
|
||||||
force_field_1 = data.get("force_field_1", None)
|
force_field_1 = data.get("force_field_1", None)
|
||||||
if force_field_1:
|
if force_field_1:
|
||||||
dump_anything.load(target.force_field_1, force_field_1)
|
dump_anything.load(datablock.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:
|
if force_field_2:
|
||||||
dump_anything.load(target.force_field_2, force_field_2)
|
dump_anything.load(datablock.force_field_2, force_field_2)
|
||||||
|
|
||||||
# Texture slots
|
# Texture slots
|
||||||
load_texture_slots(data["texture_slots"], target.texture_slots)
|
load_texture_slots(data["texture_slots"], datablock.texture_slots)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def dump(datablock: object) -> dict:
|
def dump(datablock: object) -> dict:
|
||||||
assert instance
|
|
||||||
|
|
||||||
dumper = dump_anything.Dumper()
|
dumper = dump_anything.Dumper()
|
||||||
dumper.depth = 1
|
dumper.depth = 1
|
||||||
dumper.exclude_filter = IGNORED_ATTR
|
dumper.exclude_filter = IGNORED_ATTR
|
||||||
data = dumper.dump(instance)
|
data = dumper.dump(datablock)
|
||||||
|
|
||||||
# Particle effectors
|
# Particle effectors
|
||||||
data["effector_weights"] = dumper.dump(instance.effector_weights)
|
data["effector_weights"] = dumper.dump(datablock.effector_weights)
|
||||||
if instance.force_field_1:
|
if datablock.force_field_1:
|
||||||
data["force_field_1"] = dumper.dump(instance.force_field_1)
|
data["force_field_1"] = dumper.dump(datablock.force_field_1)
|
||||||
if instance.force_field_2:
|
if datablock.force_field_2:
|
||||||
data["force_field_2"] = dumper.dump(instance.force_field_2)
|
data["force_field_2"] = dumper.dump(datablock.force_field_2)
|
||||||
|
|
||||||
# Texture slots
|
# Texture slots
|
||||||
data["texture_slots"] = dump_textures_slots(instance.texture_slots)
|
data["texture_slots"] = dump_textures_slots(datablock.texture_slots)
|
||||||
|
data['animation_data'] = dump_animation_data(datablock)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def resolve(data: dict) -> object:
|
||||||
|
uuid = data.get('uuid')
|
||||||
|
name = data.get('name')
|
||||||
|
datablock = resolve_datablock_from_uuid(uuid, bpy.data.particles)
|
||||||
|
if datablock is None:
|
||||||
|
datablock = bpy.data.particles.get(name)
|
||||||
|
|
||||||
|
return datablock
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def resolve_deps(datablock: object) -> [object]:
|
def resolve_deps(datablock: object) -> [object]:
|
||||||
return [t.texture for t in self.instance.texture_slots if t and t.texture]
|
deps = [t.texture for t in datablock.texture_slots if t and t.texture]
|
||||||
|
deps.extend(resolve_animation_dependencies(datablock))
|
||||||
|
return deps
|
||||||
|
|
||||||
|
_type = bpy.types.ParticleSettings
|
||||||
|
_class = BlParticle
|
Loading…
x
Reference in New Issue
Block a user