feat: cleanup metaballs
This commit is contained in:
parent
d46ea3a117
commit
9c9d7a31bf
@ -20,8 +20,57 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.dump_anything import (
|
||||
Dumper, Loader, dump_collection_attr, load_collection_attr, dump_collection_attr_to_dict, load_collection_attr_from_dict)
|
||||
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
ENUM_METABALL_TYPE = [
|
||||
'BALL',
|
||||
'CAPSULE',
|
||||
'PLANE',
|
||||
'ELLIPSOID',
|
||||
'CUBE'
|
||||
]
|
||||
|
||||
|
||||
ELEMENTS_FAST_ATTR = [
|
||||
'co',
|
||||
'hide',
|
||||
'radius',
|
||||
'rotation',
|
||||
'size_x',
|
||||
'size_y',
|
||||
'size_z',
|
||||
'stiffness']
|
||||
|
||||
|
||||
def dump_metaball_elements(elements):
|
||||
""" Dump a metaball element
|
||||
|
||||
:arg element: metaball element
|
||||
:type bpy.types.MetaElement
|
||||
:return: dict
|
||||
"""
|
||||
|
||||
dumped_elements = {}
|
||||
|
||||
dump_collection_attr_to_dict(dumped_elements, elements, ELEMENTS_FAST_ATTR)
|
||||
|
||||
dumped_elements['type'] = [ENUM_METABALL_TYPE.index(e.type) for e in elements]
|
||||
|
||||
return dumped_elements
|
||||
|
||||
|
||||
def load_metaball_elements(elements_data, elements):
|
||||
""" Dump a metaball element
|
||||
|
||||
:arg element: metaball element
|
||||
:type bpy.types.MetaElement
|
||||
:return: dict
|
||||
"""
|
||||
load_collection_attr_from_dict(elements_data, elements, ELEMENTS_FAST_ATTR)
|
||||
|
||||
|
||||
class BlMetaball(BlDatablock):
|
||||
bl_id = "metaballs"
|
||||
@ -34,22 +83,31 @@ class BlMetaball(BlDatablock):
|
||||
def _construct(self, data):
|
||||
return bpy.data.metaballs.new(data["name"])
|
||||
|
||||
def load(self, data, target):
|
||||
def _load_implementation(self, data, target):
|
||||
utils.dump_anything.load(target, data)
|
||||
|
||||
target.elements.clear()
|
||||
for element in data["elements"]:
|
||||
new_element = target.elements.new(type=data["elements"][element]['type'])
|
||||
utils.dump_anything.load(new_element, data["elements"][element])
|
||||
|
||||
for element_type in data["elements"]['type']:
|
||||
new_element = target.elements.new(
|
||||
type=ENUM_METABALL_TYPE[element_type])
|
||||
|
||||
load_metaball_elements(data['elements'], target.elements)
|
||||
|
||||
def _dump_implementation(self, data, pointer=None):
|
||||
assert(pointer)
|
||||
dumper = utils.dump_anything.Dumper()
|
||||
dumper.depth = 3
|
||||
dumper.exclude_filter = ["is_editmode"]
|
||||
dumper.depth = 1
|
||||
dumper.exclude_filter = [
|
||||
"is_editmode",
|
||||
"is_evaluated",
|
||||
"is_embedded_data",
|
||||
"is_library_indirect",
|
||||
"name_full"
|
||||
]
|
||||
|
||||
data = dumper.dump(pointer)
|
||||
data['elements'] = dump_metaball_elements(pointer.elements)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
|
||||
|
@ -30,6 +30,33 @@ BPY_TO_NUMPY_TYPES = {
|
||||
'BOOL': np.bool
|
||||
}
|
||||
|
||||
def load_collection_attr_from_dict(dikt, collection, attributes):
|
||||
""" Dump a list of attributes from the sane collection
|
||||
to the target dikt
|
||||
|
||||
:arg dikt: target dict
|
||||
:type dikt: dict
|
||||
:arg collection: source collection
|
||||
:type collection: bpy.types.CollectionProperty
|
||||
:arg attributes: list of attributes name
|
||||
:type attributes: list
|
||||
"""
|
||||
for attr in attributes:
|
||||
load_collection_attr(collection, attr, dikt[attr])
|
||||
|
||||
def dump_collection_attr_to_dict(dikt, collection, attributes):
|
||||
""" Dump a list of attributes from the sane collection
|
||||
to the target dikt
|
||||
|
||||
:arg dikt: target dict
|
||||
:type dikt: dict
|
||||
:arg collection: source collection
|
||||
:type collection: bpy.types.CollectionProperty
|
||||
:arg attributes: list of attributes name
|
||||
:type attributes: list
|
||||
"""
|
||||
for attr in attributes:
|
||||
dikt[attr] = dump_collection_attr(collection, attr)
|
||||
|
||||
def dump_collection_attr(collection, attribute):
|
||||
""" Dump a collection attribute as a sequence
|
||||
|
Loading…
x
Reference in New Issue
Block a user