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-11-04 17:55:41 +01:00
|
|
|
import bpy
|
|
|
|
import mathutils
|
|
|
|
|
2020-04-01 11:37:05 +02:00
|
|
|
from .dump_anything import Dumper, Loader, np_dump_collection, np_load_collection
|
2019-11-04 17:55:41 +01:00
|
|
|
from .bl_datablock import BlDatablock
|
2020-07-10 16:50:09 +02:00
|
|
|
from replication.exception import ContextError
|
2019-11-04 17:55:41 +01:00
|
|
|
|
2020-04-01 10:23:28 +02:00
|
|
|
POINT = ['co', 'weight_softbody', 'co_deform']
|
|
|
|
|
2019-11-04 17:55:41 +01:00
|
|
|
|
|
|
|
class BlLattice(BlDatablock):
|
2020-01-13 18:51:31 +01:00
|
|
|
bl_id = "lattices"
|
|
|
|
bl_class = bpy.types.Lattice
|
2020-09-17 22:47:11 +02:00
|
|
|
bl_check_common = False
|
2020-01-13 18:51:31 +01:00
|
|
|
bl_icon = 'LATTICE_DATA'
|
2020-12-09 14:49:26 +01:00
|
|
|
bl_reload_parent = False
|
2020-01-13 18:51:31 +01:00
|
|
|
|
2021-03-26 12:30:15 +01:00
|
|
|
def construct(data: dict) -> object:
|
2020-04-07 09:59:04 +02:00
|
|
|
return bpy.data.lattices.new(data["name"])
|
|
|
|
|
2021-03-26 12:30:15 +01:00
|
|
|
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)
|
2019-11-04 17:55:41 +01:00
|
|
|
|
2021-03-26 12:30:15 +01:00
|
|
|
def dump(datablock: object) -> dict:
|
2020-04-22 17:04:14 +02:00
|
|
|
if instance.is_editmode:
|
|
|
|
raise ContextError("lattice is in edit mode")
|
2019-11-04 17:55:41 +01:00
|
|
|
|
2020-04-01 10:23:28 +02:00
|
|
|
dumper = Dumper()
|
|
|
|
dumper.depth = 1
|
2019-11-04 17:55:41 +01:00
|
|
|
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'
|
2019-11-04 17:55:41 +01:00
|
|
|
]
|
2020-04-07 14:49:43 +02:00
|
|
|
data = dumper.dump(instance)
|
2019-11-04 17:55:41 +01:00
|
|
|
|
2020-04-07 14:49:43 +02:00
|
|
|
data['points'] = np_dump_collection(instance.points, POINT)
|
2020-04-22 17:04:14 +02:00
|
|
|
|
2019-11-04 17:55:41 +01:00
|
|
|
return data
|
|
|
|
|