multi-user/multi_user/io_bpy/bl_metaball.py

105 lines
2.6 KiB
Python
Raw Normal View History

2020-03-20 14:56:50 +01:00
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
2019-09-24 00:42:30 +02:00
import bpy
import mathutils
from .dump_anything import (
Dumper, Loader, np_dump_collection_primitive, np_load_collection_primitives,
np_dump_collection, np_load_collection)
2020-03-30 18:50:54 +02:00
2019-09-24 00:42:30 +02:00
from .bl_datablock import BlDatablock
2020-03-30 18:50:54 +02:00
ELEMENT = [
2020-03-31 10:13:49 +02:00
'co',
'hide',
'radius',
'rotation',
'size_x',
'size_y',
'size_z',
'stiffness',
'type'
2020-03-31 10:13:49 +02:00
]
2020-03-30 18:50:54 +02:00
def dump_metaball_elements(elements):
""" Dump a metaball element
:arg element: metaball element
:type bpy.types.MetaElement
:return: dict
"""
2020-03-31 10:13:49 +02:00
dumped_elements = np_dump_collection(elements, ELEMENT)
2020-03-30 18:50:54 +02:00
return dumped_elements
def load_metaball_elements(elements_data, elements):
""" Dump a metaball element
:arg element: metaball element
:type bpy.types.MetaElement
:return: dict
"""
np_load_collection(elements_data, elements, ELEMENT)
2020-03-30 18:50:54 +02:00
2019-09-24 00:42:30 +02:00
class BlMetaball(BlDatablock):
bl_id = "metaballs"
bl_class = bpy.types.MetaBall
2020-09-17 22:47:11 +02:00
bl_check_common = False
bl_icon = 'META_BALL'
bl_reload_parent = False
def construct(data: dict) -> object:
2019-09-24 00:42:30 +02:00
return bpy.data.metaballs.new(data["name"])
def load(data: dict, datablock: object):
2020-04-01 11:34:24 +02:00
loader = Loader()
loader.load(target, data)
2020-03-30 18:50:54 +02:00
2019-09-24 00:42:30 +02:00
target.elements.clear()
2020-03-30 18:50:54 +02:00
for mtype in data["elements"]['type']:
new_element = target.elements.new()
2020-03-31 10:13:49 +02:00
2020-03-30 18:50:54 +02:00
load_metaball_elements(data['elements'], target.elements)
2019-09-26 22:30:22 +02:00
def dump(datablock: object) -> dict:
assert(instance)
2020-04-01 11:34:24 +02:00
dumper = Dumper()
2020-03-30 18:50:54 +02:00
dumper.depth = 1
dumper.include_filter = [
'name',
'resolution',
'render_resolution',
'threshold',
'update_method',
'use_auto_texspace',
'texspace_location',
'texspace_size'
2020-03-30 18:50:54 +02:00
]
2019-09-24 00:42:30 +02:00
data = dumper.dump(instance)
data['elements'] = dump_metaball_elements(instance.elements)
2020-03-11 15:17:13 +01:00
2020-03-30 18:50:54 +02:00
return data