-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
291 lines (236 loc) · 8.67 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
bl_info = {
"name": "Export SMF",
"description": "Export to SMF 11 (SnidrsModelFormat)",
"author": "Bart Teunis",
"version": (0, 9, 4),
"blender": (2, 80, 0),
"location": "File > Export",
"warning": "", # used for warning icon and text in addons panel
"doc_url": "https://github.com/blender-to-gmstudio/blender-to-smf/wiki",
"tracker_url": "https://github.com/blender-to-gmstudio/blender-to-smf/issues",
"support": 'COMMUNITY',
"category": "Import-Export"}
# Make sure to reload changes to code that we maintain ourselves
# when reloading scripts in Blender
if "bpy" in locals():
import importlib
if "export_smf" in locals():
importlib.reload(export_smf)
if "import_smf" in locals():
importlib.reload(import_smf)
import bpy
from bpy.types import Operator
from bpy.props import (
StringProperty,
BoolProperty,
EnumProperty,
FloatProperty,
IntProperty,
)
from bpy_extras.io_utils import (
ExportHelper,
ImportHelper,
)
from . import export_smf
from . import import_smf
from .export_smf import export_smf_file
from .import_smf import import_smf_file
class ImportSMF(Operator, ImportHelper):
"""Import an SMF 3D model"""
bl_idname = "import_scene.smf"
bl_label = "SMF (*.smf)"
bl_options = {'REGISTER'}
filename_ext = ".smf"
filter_glob: StringProperty(
default="*.smf",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
create_new_materials_images: BoolProperty(
name="Create New Materials/Images",
description= ("Force the creation of new materials and images, "
"even if materials/images with the same name already exist"),
default=True,
)
def execute(self, context):
keywords = self.as_keywords(ignore=("check_existing", "filter_glob", "ui_tab"))
return import_smf_file(self, context, **keywords)
class ExportSMF(Operator, ExportHelper):
"""Export a selection of the current scene to SMF (SnidrsModelFormat)"""
bl_idname = "export_scene.smf"
bl_label = "SMF (*.smf)"
bl_options = {'REGISTER', 'PRESET'}
# ExportHelper mixin class uses this
filename_ext = ".smf"
filter_glob: StringProperty(
default="*.smf",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
export_textures: BoolProperty(
name="Export Textures",
description="Whether textures should be exported with the model",
default=True,
)
# "Advanced" export settings
anim_export_mode: EnumProperty(
name="What to export",
description="How to export animations",
items=[
("CUR", "Current Action", "Export the Armature's current action as a single animation", 0),
("LNK", "Linked NLA Actions", "Export all (unique) actions that are linked indirectly through NLA tracks", 1),
#("TRA", "NLA Tracks", "Export every NLA track as a separate animation", 2),
#("SCN", "Scene", "Export a single animation directly from the scene. This allows for the most advanced animations", 3),
],
default="CUR",
)
anim_length_mode: EnumProperty(
name="Animation Length",
description="What value to use for the exported animation lengths",
items=[
("SCN", "Scene", "Animation length equals scene length", 0),
("ACT", "Action", "Animation length equals action length", 1),
],
default="SCN",
)
export_type: EnumProperty(
name="Export Type",
description="What to export",
items=[
("KFR", "Keyframes", "Export the actual keyframes as defined in the animation", 0),
("SPL", "Samples", "Sample the animation at a given rate", 1),
],
default="KFR",
)
multiplier: IntProperty(
name="Sample Frame Multiplier",
description=("Sample Frame Multiplier - Determines number of precomputed samples "
"using (number of keyframes) * (sample frame multiplier)"),
default=4,
soft_min=4,
soft_max=20,
)
"""
normal_source: EnumProperty(
name="Normal",
description="The type of normal to export (vertex, loop, face)",
items=[
("VERT", "Vertex", "Vertex normal", 0),
("LOOP", "Loop", "Loop normal", 1),
("FACE", "Face", "Face normal", 2),
],
default="VERT",
)
"""
subdivisions: IntProperty(
name="Subdivisions",
description=("Number of times to subdivide an animation when exporting samples. "
"This subdivision is made for each animation individually."),
default=10,
soft_min=2,
)
scale: FloatProperty(
name="Scale",
description="Scale factor to be applied to geometry and rig",
default=1,
soft_min=.1,
)
interpolation: EnumProperty(
name="Interpolation",
description="The interpolation to use when playing the animations in SMF",
items=[
("KFR", "Keyframe", "Use keyframe interpolation", 0),
("LIN", "Linear", "Sample the animation at a given rate", 1),
("QAD", "Quadratic", "Use quadratic interpolation", 2),
],
default="LIN",
)
bone_influences: IntProperty(
name="Bone Influences",
description=("The number of bone influences to use"),
default=4,
min=1,
max=4,
)
invert_uv_v: BoolProperty(
name="Invert UV",
description="Invert the v coordinate of uvs, i.e. export (u, 1 - v)",
default=False,
)
def execute(self, context):
keywords = self.as_keywords(ignore=("check_existing", "filter_glob", "ui_tab"))
return export_smf_file(self, context, **keywords)
def draw(self, context):
# Everything gets displayed through the panels that are defined below
pass
class SMF_PT_export_general(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "General"
bl_parent_id = "FILE_PT_operator"
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "EXPORT_SCENE_OT_smf"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator, 'export_textures')
layout.prop(operator, "invert_uv_v")
class SMF_PT_export_advanced(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Advanced"
bl_parent_id = "FILE_PT_operator"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "EXPORT_SCENE_OT_smf"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
sfile = context.space_data
operator = sfile.active_operator
layout.label(text="General")
layout.prop(operator, 'anim_export_mode')
#layout.prop(operator, 'anim_length_mode')
layout.label(text="Sampling")
layout.prop(operator, 'export_type')
if operator.export_type == 'SPL':
layout.prop(operator, 'subdivisions')
layout.label(text="Skinning")
layout.prop(operator, 'bone_influences')
layout.label(text="Other")
#layout.prop(operator, "normal_source")
layout.prop(operator, 'interpolation')
layout.prop(operator, 'multiplier')
#layout.prop(operator, "scale")
def menu_func_export(self, context):
self.layout.operator(ExportSMF.bl_idname, text="SMF (*.smf)")
def menu_func_import(self, context):
self.layout.operator(ImportSMF.bl_idname, text="SMF (*.smf)")
classes = (
SMF_PT_export_general,
SMF_PT_export_advanced,
ExportSMF,
ImportSMF, # Uncomment this to enable the WIP importer
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
if __name__ == "__main__":
register()