-
Notifications
You must be signed in to change notification settings - Fork 5
/
__init__.py
186 lines (154 loc) · 6.19 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
# ##### 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 2
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8-80 compliant>
bl_info = {
"name": "K2 Model/Animation Import-Export",
"author": "Anton Romanov",
"version": (0, 1),
"blender": (2, 6, 3),
"location": "File > Import-Export > K2 model/clip",
"description": "Import-Export meshes and animations used by K2 engine (Savage 2 and Heroes of Newerth games)",
"warning": "",
"wiki_url": "https://github.com/theli-ua/K2-Blender/wiki",
"tracker_url": "https://github.com/theli-ua/K2-Blender/issues",
"category": "Import-Export"}
if "bpy" in locals():
import imp
if "k2_import" in locals():
imp.reload(k2_import)
if "k2_export" in locals():
imp.reload(k2_export)
else:
import bpy
from bpy.props import StringProperty, BoolProperty, IntProperty
class K2ImporterClip(bpy.types.Operator):
'''Load K2/Silverlight clip data'''
bl_idname = "import_clip.k2"
bl_label = "Import K2 Clip"
filepath = StringProperty(
subtype='FILE_PATH',
)
filter_glob = StringProperty(default="*.clip", options={'HIDDEN'})
def execute(self, context):
from . import k2_import
k2_import.readclip(self.filepath)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
class K2Importer(bpy.types.Operator):
'''Load K2/Silverlight mesh data'''
bl_idname = "import_mesh.k2"
bl_label = "Import K2 Mesh"
filepath = StringProperty(
subtype='FILE_PATH',
)
filter_glob = StringProperty(default="*.model", options={'HIDDEN'})
flipuv = BoolProperty(
name="Flip UV",
description="Flip UV",
default=True,
)
def execute(self, context):
from . import k2_import
k2_import.read(self.filepath,self.flipuv)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
class K2ClipExporter(bpy.types.Operator):
'''Save K2 triangle clip data'''
bl_idname = "export_clip.k2"
bl_label = "Export K2 Clip"
filepath = StringProperty(
subtype='FILE_PATH',
)
filter_glob = StringProperty(default="*.clip", options={'HIDDEN'})
check_existing = BoolProperty(
name="Check Existing",
description="Check and warn on overwriting existing files",
default=True,
options={'HIDDEN'},
)
apply_modifiers = BoolProperty(
name="Apply Modifiers",
description="Use transformed mesh data from each object",
default=True,
)
frame_start = IntProperty(name="Start Frame", description="Starting frame for the animation", default=bpy.context.scene.frame_start)
frame_end = IntProperty(name="Ending Frame", description="Ending frame for the animation",default=bpy.context.scene.frame_end)
def execute(self, context):
from . import k2_export
k2_export.export_k2_clip(self.filepath,self.apply_modifiers,
self.frame_start,self.frame_end)
return {'FINISHED'}
def invoke(self, context, event):
if not self.filepath:
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".clip")
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
class K2MeshExporter(bpy.types.Operator):
'''Save K2 triangle mesh data'''
bl_idname = "export_mesh.k2"
bl_label = "Export K2 Mesh"
filepath = StringProperty(
subtype='FILE_PATH',
)
filter_glob = StringProperty(default="*.model", options={'HIDDEN'})
check_existing = BoolProperty(
name="Check Existing",
description="Check and warn on overwriting existing files",
default=True,
options={'HIDDEN'},
)
apply_modifiers = BoolProperty(
name="Apply Modifiers",
description="Use transformed mesh data from each object",
default=True,
)
def execute(self, context):
from . import k2_export
k2_export.export_k2_mesh(self.filepath,
self.apply_modifiers
)
return {'FINISHED'}
def invoke(self, context, event):
if not self.filepath:
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".model")
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
def menu_import(self, context):
self.layout.operator(K2Importer.bl_idname, text="K2 mesh (.model)")
self.layout.operator(K2ImporterClip.bl_idname, text="K2 clip (.clip)")
def menu_export(self, context):
self.layout.operator(K2MeshExporter.bl_idname, text="K2 Mesh (.model)")
self.layout.operator(K2ClipExporter.bl_idname, text="K2 Clip (.clip)")
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_import.append(menu_import)
bpy.types.INFO_MT_file_export.append(menu_export)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_import.remove(menu_import)
bpy.types.INFO_MT_file_export.remove(menu_export)
if __name__ == "__main__":
register()