Files
multi-user/multi_user/io_bpy/bl_lattice.py

71 lines
2.1 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 #####
import bpy
import mathutils
from .dump_anything import Dumper, Loader, np_dump_collection, np_load_collection
from .bl_datablock import BlDatablock
2020-07-10 16:50:09 +02:00
from replication.exception import ContextError
2020-04-01 10:23:28 +02:00
POINT = ['co', 'weight_softbody', 'co_deform']
class BlLattice(BlDatablock):
bl_id = "lattices"
bl_class = bpy.types.Lattice
2020-09-17 22:47:11 +02:00
bl_check_common = False
bl_icon = 'LATTICE_DATA'
bl_reload_parent = False
def construct(data: dict) -> object:
2020-04-07 09:59:04 +02:00
return bpy.data.lattices.new(data["name"])
def load(data: dict, datablock: object):
2020-04-22 17:04:14 +02:00
if target.is_editmode:
raise ContextError("lattice is in edit mode")
2020-04-01 10:23:28 +02:00
loader = Loader()
loader.load(target, data)
np_load_collection(data['points'], target.points, POINT)
def dump(datablock: object) -> dict:
2020-04-22 17:04:14 +02:00
if instance.is_editmode:
raise ContextError("lattice is in edit mode")
2020-04-01 10:23:28 +02:00
dumper = Dumper()
dumper.depth = 1
dumper.include_filter = [
"name",
'type',
'points_u',
'points_v',
'points_w',
'interpolation_type_u',
'interpolation_type_v',
'interpolation_type_w',
2020-04-01 10:23:28 +02:00
'use_outside'
]
data = dumper.dump(instance)
data['points'] = np_dump_collection(instance.points, POINT)
2020-04-22 17:04:14 +02:00
return data