forked from SE2Dev/io_anim_seanim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
233 lines (184 loc) · 7.2 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import bpy
import bpy_extras.io_utils
from bpy.types import Operator, AddonPreferences
from bpy.props import *
from bpy_extras.io_utils import ExportHelper, ImportHelper
from bpy.utils import register_class
from bpy.utils import unregister_class
import time
bl_info = {
"name": "SEAnim Support",
"author": "SE2Dev",
"version": (0, 4, 1),
"blender": (2, 80, 0),
"location": "File > Import",
"description": "Import SEAnim",
"warning": "ADDITIVE animations are not currently supported",
"wiki_url": "https://github.com/SE2Dev/io_anim_seanim",
"tracker_url": "https://github.com/SE2Dev/io_anim_seanim/issues",
"support": "COMMUNITY",
"category": "Import-Export"
}
# To support reload properly, try to access a package var, if it's there,
# reload everything
if "bpy" in locals():
import imp
if "import_seanim" in locals():
imp.reload(import_seanim)
else:
from . import import_seanim
class ImportSEAnim(bpy.types.Operator, ImportHelper):
bl_idname = "import_scene.seanim"
bl_label = "Import SEAnim"
bl_description = "Import one or more SEAnim files"
bl_options = {'PRESET'}
filename_ext = ".seanim"
filter_glob: StringProperty(default="*.seanim", options={'HIDDEN'})
files: CollectionProperty(type=bpy.types.PropertyGroup)
def execute(self, context):
# print("Selected: " + context.active_object.name)
from . import import_seanim
start_time = time.process_time()
result = import_seanim.load(
self, context, **self.as_keywords(ignore=("filter_glob", "files")))
if not result:
self.report({'INFO'}, "Import finished in %.4f sec." %
(time.process_time() - start_time))
return {'FINISHED'}
else:
self.report({'ERROR'}, result)
return {'CANCELLED'}
@classmethod
def poll(self, context):
if context.active_object is not None:
if context.active_object.type == 'ARMATURE':
return True
# Currently Disabled
"""
elif context.active_object.parent is not None:
return context.active_object.parent.type == 'ARMATURE'
"""
return False
class ExportSEAnim(bpy.types.Operator, ExportHelper):
bl_idname = "export_scene.seanim"
bl_label = "Export SEAnim"
bl_description = "Export an SEAnim"
bl_options = {'PRESET'}
filename_ext = ".seanim"
filter_glob: StringProperty(default="*.seanim", options={'HIDDEN'})
files: CollectionProperty(type=bpy.types.PropertyGroup)
anim_type: EnumProperty(
name="Anim Type",
description="Choose between two items",
items=( ('OPT_ABSOLUTE', "Absolute", "Used for viewmodel animations"),
# ('OPT_ADDITIVE', "Additive", "Used for some idle animations"), # Currently Disabled # nopep8
('OPT_RELATIVE', "Relative", "Used for most animations"),
('OPT_DELTA', "Delta", "Used for walk cycles")),
default='OPT_RELATIVE',
)
key_types: EnumProperty(
name="Keyframe Types",
description="Export specific keyframe types",
options={'ENUM_FLAG'},
items=(('LOC', "Location", ""),
('ROT', "Rotation", ""),
# ('SCALE', "Scale", ""), # Not Currently Supported # nopep8
),
default={'LOC', 'ROT'}, # , 'SCALE'},
)
every_frame: BoolProperty(
name="Every Frame",
description="Automatically generate keyframes for every single frame",
default=False)
high_precision: BoolProperty(
name="High Precision",
description=("Use double precision floating point values for "
"quaternions and vectors (Note: Increases file size)"),
default=False)
is_looped: BoolProperty(
name="Looped",
description="Mark the animation as a looping animation",
default=False)
use_actions: BoolProperty(
name="Export All Actions",
description="Export all actions to the target path",
default=False)
# PREFIX & SUFFIX Require "use_actions" to be true and are enabled /
# disabled from __update_use_actions
prefix: StringProperty(
name="File Prefix",
description=("The prefix string that is applied to the beginning "
"of the filename for each exported action"),
default="")
suffix: StringProperty(
name="File Suffix",
description=("The suffix string that is applied to the end "
"of the filename for each exported action"),
default="")
def draw(self, context):
layout = self.layout
layout.prop(self, "anim_type")
row = layout.row()
row.label(text="Include:")
row.prop(self, "key_types")
layout.prop(self, "high_precision")
layout.prop(self, "is_looped")
layout.prop(self, "every_frame")
box = layout.box()
box.prop(self, "use_actions")
if(self.use_actions):
box.prop(self, "prefix")
box.prop(self, "suffix")
def execute(self, context):
# print("Selected: " + context.active_object.name)
from . import export_seanim
start_time = time.process_time()
result = export_seanim.save(self, context)
if not result:
self.report({'INFO'}, "Export finished in %.4f sec." %
(time.process_time() - start_time))
return {'FINISHED'}
else:
self.report({'ERROR'}, result)
return {'CANCELLED'}
@classmethod
def poll(self, context):
ob = context.active_object
if ob is not None:
if ob.type == 'ARMATURE' and ob.animation_data is not None:
return True
# Currently Disabled
"""
elif context.active_object.parent is not None:
return context.active_object.parent.type == 'ARMATURE'
"""
return False
def get_operator(idname):
op = bpy.ops
for attr in idname.split("."):
op = getattr(op, attr)
return op
def menu_func_seanim_import(self, context):
self.layout.operator(ImportSEAnim.bl_idname, text="SEAnim (.seanim)")
def menu_func_seanim_export(self, context):
self.layout.operator(ExportSEAnim.bl_idname, text="SEAnim (.seanim)")
'''
CLASS REGISTRATION
SEE https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/Addons
'''
classes = (
ImportSEAnim,
ExportSEAnim
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.TOPBAR_MT_file_import.append(menu_func_seanim_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_seanim_export)
def unregister():
bpy.types.TOPBAR_MT_file_import.remove(menu_func_seanim_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_seanim_export)
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()