-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommon_kp.py
359 lines (322 loc) · 11.7 KB
/
common_kp.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
'''
common_kp.py file
File limitations
'''
import bpy
MD2_MAX_TRIANGLES = 4096
MD2_MAX_VERTS = 2048
MD2_MAX_FRAMES = 1024 # 512 - 1024 is an UFO:AI extension.
MD2_MAX_SKINS = 32
MD2_MAX_SKINNAME = 63
MD2_VN = (
(-0.525731, 0.000000, 0.850651),
(-0.442863, 0.238856, 0.864188),
(-0.295242, 0.000000, 0.955423),
(-0.309017, 0.500000, 0.809017),
(-0.162460, 0.262866, 0.951056),
(0.000000, 0.000000, 1.000000),
(0.000000, 0.850651, 0.525731),
(-0.147621, 0.716567, 0.681718),
(0.147621, 0.716567, 0.681718),
(0.000000, 0.525731, 0.850651),
(0.309017, 0.500000, 0.809017),
(0.525731, 0.000000, 0.850651),
(0.295242, 0.000000, 0.955423),
(0.442863, 0.238856, 0.864188),
(0.162460, 0.262866, 0.951056),
(-0.681718, 0.147621, 0.716567),
(-0.809017, 0.309017, 0.500000),
(-0.587785, 0.425325, 0.688191),
(-0.850651, 0.525731, 0.000000),
(-0.864188, 0.442863, 0.238856),
(-0.716567, 0.681718, 0.147621),
(-0.688191, 0.587785, 0.425325),
(-0.500000, 0.809017, 0.309017),
(-0.238856, 0.864188, 0.442863),
(-0.425325, 0.688191, 0.587785),
(-0.716567, 0.681718, -0.147621),
(-0.500000, 0.809017, -0.309017),
(-0.525731, 0.850651, 0.000000),
(0.000000, 0.850651, -0.525731),
(-0.238856, 0.864188, -0.442863),
(0.000000, 0.955423, -0.295242),
(-0.262866, 0.951056, -0.162460),
(0.000000, 1.000000, 0.000000),
(0.000000, 0.955423, 0.295242),
(-0.262866, 0.951056, 0.162460),
(0.238856, 0.864188, 0.442863),
(0.262866, 0.951056, 0.162460),
(0.500000, 0.809017, 0.309017),
(0.238856, 0.864188, -0.442863),
(0.262866, 0.951056, -0.162460),
(0.500000, 0.809017, -0.309017),
(0.850651, 0.525731, 0.000000),
(0.716567, 0.681718, 0.147621),
(0.716567, 0.681718, -0.147621),
(0.525731, 0.850651, 0.000000),
(0.425325, 0.688191, 0.587785),
(0.864188, 0.442863, 0.238856),
(0.688191, 0.587785, 0.425325),
(0.809017, 0.309017, 0.500000),
(0.681718, 0.147621, 0.716567),
(0.587785, 0.425325, 0.688191),
(0.955423, 0.295242, 0.000000),
(1.000000, 0.000000, 0.000000),
(0.951056, 0.162460, 0.262866),
(0.850651, -0.525731, 0.000000),
(0.955423, -0.295242, 0.000000),
(0.864188, -0.442863, 0.238856),
(0.951056, -0.162460, 0.262866),
(0.809017, -0.309017, 0.500000),
(0.681718, -0.147621, 0.716567),
(0.850651, 0.000000, 0.525731),
(0.864188, 0.442863, -0.238856),
(0.809017, 0.309017, -0.500000),
(0.951056, 0.162460, -0.262866),
(0.525731, 0.000000, -0.850651),
(0.681718, 0.147621, -0.716567),
(0.681718, -0.147621, -0.716567),
(0.850651, 0.000000, -0.525731),
(0.809017, -0.309017, -0.500000),
(0.864188, -0.442863, -0.238856),
(0.951056, -0.162460, -0.262866),
(0.147621, 0.716567, -0.681718),
(0.309017, 0.500000, -0.809017),
(0.425325, 0.688191, -0.587785),
(0.442863, 0.238856, -0.864188),
(0.587785, 0.425325, -0.688191),
(0.688191, 0.587785, -0.425325),
(-0.147621, 0.716567, -0.681718),
(-0.309017, 0.500000, -0.809017),
(0.000000, 0.525731, -0.850651),
(-0.525731, 0.000000, -0.850651),
(-0.442863, 0.238856, -0.864188),
(-0.295242, 0.000000, -0.955423),
(-0.162460, 0.262866, -0.951056),
(0.000000, 0.000000, -1.000000),
(0.295242, 0.000000, -0.955423),
(0.162460, 0.262866, -0.951056),
(-0.442863, -0.238856, -0.864188),
(-0.309017, -0.500000, -0.809017),
(-0.162460, -0.262866, -0.951056),
(0.000000, -0.850651, -0.525731),
(-0.147621, -0.716567, -0.681718),
(0.147621, -0.716567, -0.681718),
(0.000000, -0.525731, -0.850651),
(0.309017, -0.500000, -0.809017),
(0.442863, -0.238856, -0.864188),
(0.162460, -0.262866, -0.951056),
(0.238856, -0.864188, -0.442863),
(0.500000, -0.809017, -0.309017),
(0.425325, -0.688191, -0.587785),
(0.716567, -0.681718, -0.147621),
(0.688191, -0.587785, -0.425325),
(0.587785, -0.425325, -0.688191),
(0.000000, -0.955423, -0.295242),
(0.000000, -1.000000, 0.000000),
(0.262866, -0.951056, -0.162460),
(0.000000, -0.850651, 0.525731),
(0.000000, -0.955423, 0.295242),
(0.238856, -0.864188, 0.442863),
(0.262866, -0.951056, 0.162460),
(0.500000, -0.809017, 0.309017),
(0.716567, -0.681718, 0.147621),
(0.525731, -0.850651, 0.000000),
(-0.238856, -0.864188, -0.442863),
(-0.500000, -0.809017, -0.309017),
(-0.262866, -0.951056, -0.162460),
(-0.850651, -0.525731, 0.000000),
(-0.716567, -0.681718, -0.147621),
(-0.716567, -0.681718, 0.147621),
(-0.525731, -0.850651, 0.000000),
(-0.500000, -0.809017, 0.309017),
(-0.238856, -0.864188, 0.442863),
(-0.262866, -0.951056, 0.162460),
(-0.864188, -0.442863, 0.238856),
(-0.809017, -0.309017, 0.500000),
(-0.688191, -0.587785, 0.425325),
(-0.681718, -0.147621, 0.716567),
(-0.442863, -0.238856, 0.864188),
(-0.587785, -0.425325, 0.688191),
(-0.309017, -0.500000, 0.809017),
(-0.147621, -0.716567, 0.681718),
(-0.425325, -0.688191, 0.587785),
(-0.162460, -0.262866, 0.951056),
(0.442863, -0.238856, 0.864188),
(0.162460, -0.262866, 0.951056),
(0.309017, -0.500000, 0.809017),
(0.147621, -0.716567, 0.681718),
(0.000000, -0.525731, 0.850651),
(0.425325, -0.688191, 0.587785),
(0.587785, -0.425325, 0.688191),
(0.688191, -0.587785, 0.425325),
(-0.955423, 0.295242, 0.000000),
(-0.951056, 0.162460, 0.262866),
(-1.000000, 0.000000, 0.000000),
(-0.850651, 0.000000, 0.525731),
(-0.955423, -0.295242, 0.000000),
(-0.951056, -0.162460, 0.262866),
(-0.864188, 0.442863, -0.238856),
(-0.951056, 0.162460, -0.262866),
(-0.809017, 0.309017, -0.500000),
(-0.864188, -0.442863, -0.238856),
(-0.951056, -0.162460, -0.262866),
(-0.809017, -0.309017, -0.500000),
(-0.681718, 0.147621, -0.716567),
(-0.681718, -0.147621, -0.716567),
(-0.850651, 0.000000, -0.525731),
(-0.688191, 0.587785, -0.425325),
(-0.587785, 0.425325, -0.688191),
(-0.425325, 0.688191, -0.587785),
(-0.425325, -0.688191, -0.587785),
(-0.587785, -0.425325, -0.688191),
(-0.688191, -0.587785, -0.425325))
def get_preferences(context=None):
''' Multi version compatibility for getting preferences
https://theduckcow.com/2019/update-addons-both-blender-28-and-27-support/#synved-sections-1-7
'''
if not context:
context = bpy.context
prefs = None
if hasattr(context, "user_preferences"):
prefs = context.user_preferences.addons.get(__package__, None)
elif hasattr(context, "preferences"):
prefs = context.preferences.addons.get(__package__, None)
if prefs:
return prefs.preferences
else:
raise Exception("Could not fetch user preferences")
def get_collection(context):
if hasattr(context, "collection"):
return context.collection.objects # B2.8
else:
return context.scene.objects
def get_objects(context):
if hasattr(context, "view_layer"):
return context.view_layer.objects # B2.8
else:
return context.scene.objects
def get_layers(context):
if hasattr(context, "view_layer"):
return context.view_layer # B2.8
else:
return context.scene
def get_menu_import():
if hasattr(bpy.types, "TOPBAR_MT_file_import"):
return bpy.types.TOPBAR_MT_file_import
elif hasattr(bpy.types, "INFO_MT_file_import"):
return bpy.types.INFO_MT_file_import
else:
raise Exception("Could not fetch menu")
def get_menu_export():
if hasattr(bpy.types, "TOPBAR_MT_file_export"):
return bpy.types.TOPBAR_MT_file_export
elif hasattr(bpy.types, "INFO_MT_file_export"):
return bpy.types.INFO_MT_file_export
else:
raise Exception("Could not fetch menu")
def get_groups():
if hasattr(bpy.data, "collections"):
mygroup = bpy.data.collections.get("MyGroup")
else:
mygroup = bpy.data.groups.get("MyGroup")
def get_uv_data_new(context, uv_name=""):
ret = (0, None)
if hasattr(context, "uv_textures"):
# print("found uv_textures")
ret = (1, context.uv_textures.new(name=uv_name)) # tessface_uv_textures
context.uv_textures.active = ret[1]
else:
# print("found uv_layers") # B2.8
ret = (2, context.uv_layers.new(name=uv_name))
context.uv_layers.active = ret[1]
return ret
def get_uv_data(context):
ret = (0, None)
if hasattr(context, "uv_textures"):
return context.uv_textures
else:
return context.uv_layers # B2.8
def set_select_state(context, opt):
"""Multi version compatibility for setting object selection
https://theduckcow.com/2019/update-addons-both-blender-28-and-27-support/#synved-sections-1-11
"""
if hasattr(context, "select_set"):
context.select_set(state=opt) # B2.8
else:
context.select = opt
def set_mode_state(context, opt):
"""Multi version compatibility for setting object selection
https://theduckcow.com/2019/update-addons-both-blender-28-and-27-support/#synved-sections-1-11
"""
if hasattr(context, "mode_set"):
context.mode_set(state=opt) # B2.8
else:
context.mode = opt
'''
def set_uv_data(context, index, x, y):
if hasattr(context.data[index], "uv"):
# print("uv_1")
context.data[index].uv = (x, y)
else:
# print("uv_2")
context.data[index].uv = (x, y)
# context[index].uv = (x, y)'''
def set_uv_array(context, index, x, y):
return context
def set_uv_data_active(context, obj):
if hasattr(context, "uv_layers"):
context.uv_layers.active = obj
else:
context.tessface_uv_textures.active = obj
def make_annotations1(cls):
''' Converts class fields to annotations if running with Blender 2.8
https://theduckcow.com/2019/update-addons-both-blender-28-and-27-support/#synved-sections-1-1
'''
if bpy.app.version < (2, 80):
print("skip")
return cls
bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, tuple)}
if bl_props:
if '__annotations__' not in cls.__dict__:
setattr(cls, '__annotations__', {})
annotations = cls.__dict__['__annotations__']
for k, v in bl_props.items():
annotations[k] = v
delattr(cls, k)
print("found")
return cls
def make_annotations(cls):
"""Add annotation attribute to fields to avoid Blender 2.8+ warnings
https://github.com/OpenNaja/cobra-tools/blob/master/addon_updater_ops.py"""
if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
return cls
if bpy.app.version < (2, 93, 0):
bl_props = {k: v for k, v in cls.__dict__.items()
if isinstance(v, tuple)}
else:
bl_props = {k: v for k, v in cls.__dict__.items()
if isinstance(v, bpy.props._PropertyDeferred)}
if bl_props:
if '__annotations__' not in cls.__dict__:
setattr(cls, '__annotations__', {})
annotations = cls.__dict__['__annotations__']
for k, v in bl_props.items():
annotations[k] = v
delattr(cls, k)
return cls
def get_user_preferences(context=None):
"""Intermediate method for pre and post blender 2.8 grabbing preferences
https://github.com/OpenNaja/cobra-tools/blob/master/addon_updater_ops.py"""
if not context:
context = bpy.context
prefs = None
if hasattr(context, "user_preferences"):
prefs = context.user_preferences.addons.get(__package__, None)
elif hasattr(context, "preferences"):
prefs = context.preferences.addons.get(__package__, None)
if prefs:
return prefs.preferences
# To make the addon stable and non-exception prone, return None
# raise Exception("Could not fetch user preferences")
return None