forked from Sollumz/Sollumz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sollumz_ui.py
525 lines (408 loc) · 16.1 KB
/
sollumz_ui.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
import bpy
from .tools.blenderhelper import get_armature_obj
from .sollumz_helper import *
from .sollumz_properties import *
class OrderListHelper:
orderkey = "name"
def filter_items(self, context, data, propname):
helper = bpy.types.UI_UL_list
items = getattr(data, propname)
ordered = helper.sort_items_by_name(items, self.orderkey)
filtered = helper.filter_items_by_name(
self.filter_name, self.bitflag_filter_item, items, propname=self.orderkey, flags=None, reverse=False)
return filtered, ordered
class SOLLUMZ_PT_import_main(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = ""
bl_parent_id = "FILE_PT_operator"
bl_options = {'HIDE_HEADER'}
bl_order = 0
@ classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_import"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator.import_settings, "batch_mode")
class SOLLUMZ_PT_import_geometry(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Geometry"
bl_parent_id = "FILE_PT_operator"
bl_order = 1
@ classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_import"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator.import_settings, "join_geometries")
class SOLLUMZ_PT_import_fragment(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Fragment"
bl_parent_id = "FILE_PT_operator"
bl_order = 2
@ classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_import"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator.import_settings, "split_by_bone")
class SOLLUMZ_PT_import_skeleton(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Skeleton"
bl_parent_id = "FILE_PT_operator"
bl_order = 3
@ classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_import"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator.import_settings, "import_ext_skeleton")
class SOLLUMZ_UL_armature_list(bpy.types.UIList):
bl_idname = "SOLLUMZ_UL_armature_list"
def draw_item(
self, context, layout, data, item, icon, active_data, active_propname, index
):
if self.layout_type in {"DEFAULT", "COMPACT"}:
row = layout.row()
# Armature is contained in 'skel' object, so we need its parent (which is pack:/... or ped root..)
armature_parent = get_armature_obj(item).parent
row.label(text=F'{armature_parent.name} - {item.name}',
icon="OUTLINER_DATA_ARMATURE")
elif self.layout_type in {"GRID"}:
layout.alignment = "CENTER"
layout.prop(item, "name",
text=item.name, emboss=False, icon="OUTLINER_DATA_ARMATURE")
class SOLLUMZ_PT_import_animation(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Animation"
bl_parent_id = "FILE_PT_operator"
bl_order = 4
@ classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_import"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
armature_list_box = layout.box()
armature_list_box.label(text="Target skeleton")
armature_list_box.template_list(SOLLUMZ_UL_armature_list.bl_idname, "",
bpy.data, "armatures", operator.import_settings, "selected_armature")
class SOLLUMZ_PT_export_main(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = ""
bl_parent_id = "FILE_PT_operator"
bl_options = {'HIDE_HEADER'}
bl_order = 0
@ classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_export"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
row = layout.row(align=True)
row.prop(operator.export_settings, "batch_mode")
sub = row.row(align=True)
sub.prop(operator.export_settings, "use_batch_own_dir",
text="", icon='NEWFOLDER')
class SOLLUMZ_PT_export_include(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Include"
bl_parent_id = "FILE_PT_operator"
bl_order = 1
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_export"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
sublayout = layout.column(heading="Limit to")
sublayout.enabled = (operator.export_settings.batch_mode == "OFF")
sublayout.prop(operator.export_settings, "use_selection")
sublayout.prop(operator.export_settings, "use_active_collection")
col = layout.column()
col.prop(operator.export_settings, "sollum_types")
layout.prop(operator.export_settings, "export_with_ytyp")
class SOLLUMZ_PT_export_exclude(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Exclude"
bl_parent_id = "FILE_PT_operator"
bl_order = 2
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_export"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator.export_settings, "exclude_skeleton")
class SOLLUMZ_PT_export_geometry(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Geometry"
bl_parent_id = "FILE_PT_operator"
bl_order = 3
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_export"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator.export_settings, "use_transforms")
class SOLLUMZ_PT_export_fragment(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Fragment"
bl_parent_id = "FILE_PT_operator"
bl_order = 4
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "SOLLUMZ_OT_export"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator.export_settings, "export_with_hi")
class SOLLUMZ_PT_TOOL_PANEL(bpy.types.Panel):
bl_label = "General Tools"
bl_idname = "SOLLUMZ_PT_TOOL_PANEL"
bl_category = "Sollumz Tools"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_options = {'DEFAULT_CLOSED'}
bl_order = 0
def draw_header(self, context):
# Example property to display a checkbox, can be anything
self.layout.label(text="", icon="MODIFIER_DATA")
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("sollumz.import")
row.operator("sollumz.export")
layout.label(text="View")
row = layout.row()
row.prop(context.scene, "hide_high_lods")
row.prop(context.scene, "hide_medium_lods")
row2 = layout.row()
row2.prop(context.scene, "hide_low_lods")
row2.prop(context.scene, "hide_collision")
row3 = layout.row()
row3.prop(context.scene, "hide_very_low_lods")
row3.prop(context.space_data.overlay, "show_bones", text="Show Skeleton")
class SOLLUMZ_PT_DEBUG_PANEL(bpy.types.Panel):
bl_label = "Debug"
bl_idname = "SOLLUMZ_PT_DEBUG_PANEL"
bl_category = "Sollumz Tools"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_options = {'DEFAULT_CLOSED'}
bl_parent_id = SOLLUMZ_PT_TOOL_PANEL.bl_idname
def draw_header(self, context):
# Example property to display a checkbox, can be anything
self.layout.label(text="", icon="PREFERENCES")
def draw(self, context):
layout = self.layout
layout.label(text="Sollumz Version: 1.3.1")
row = layout.row()
row.operator("sollumz.debug_hierarchy")
row.prop(context.scene, "debug_sollum_type")
class SOLLUMZ_PT_VERTEX_TOOL_PANEL(bpy.types.Panel):
bl_label = "Vertex Painter"
bl_idname = "SOLLUMZ_PT_VERTEX_TOOL_PANELL"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_options = {'DEFAULT_CLOSED'}
bl_parent_id = SOLLUMZ_PT_TOOL_PANEL.bl_idname
def draw_header(self, context):
# Example property to display a checkbox, can be anything
self.layout.label(text="", icon="BRUSH_DATA")
def draw(self, context):
layout = self.layout
row = layout.row()
row.prop(context.scene, "vert_paint_color")
row.operator("sollumz.paint_vertices")
class SOLLUMZ_PT_TERRAIN_PAINTER_PANEL(bpy.types.Panel):
bl_label = "Terrain Painter"
bl_idname = "SOLLUMZ_PT_TERRAIN_PAINTER_PANEL"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_options = {'DEFAULT_CLOSED'}
bl_parent_id = SOLLUMZ_PT_VERTEX_TOOL_PANEL.bl_idname
def draw_header(self, context):
# Example property to display a checkbox, can be anything
self.layout.label(text="", icon="IMAGE")
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("sollumz.paint_tex1")
row.operator("sollumz.paint_tex2")
row = layout.row()
row.operator("sollumz.paint_tex3")
row.operator("sollumz.paint_tex4")
row = layout.row()
row.operator("sollumz.paint_a")
row.prop(context.scene, "vert_paint_alpha")
class SOLLUMZ_PT_YMAP_TOOL_PANEL(bpy.types.Panel):
bl_label = "Ymap Tools"
bl_idname = "SOLLUMZ_PT_YMAP_TOOL_PANEL"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_options = {'DEFAULT_CLOSED'}
bl_parent_id = SOLLUMZ_PT_TOOL_PANEL.bl_idname
def draw_header(self, context):
# Example property to display a checkbox, can be anything
self.layout.label(text="", icon="FILE")
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("sollumz.importymap")
row.operator("sollumz.exportymap")
class SOLLUMZ_PT_OBJECT_PANEL(bpy.types.Panel):
bl_label = "Sollumz"
bl_idname = "SOLLUMZ_PT_MAIN_PANEL"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'object'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
layout.use_property_split = True
obj = context.active_object
row = layout.row()
row.enabled = False
row.prop(obj, "sollum_type")
if not obj or obj.sollum_type == SollumType.NONE:
layout.label(
text="No sollumz objects in scene selected.", icon="ERROR")
class SOLLUMZ_PT_ENTITY_PANEL(bpy.types.Panel):
bl_label = "Entity Definition"
bl_idname = 'SOLLUMZ_PT_ENTITY_PANEL'
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
bl_options = {'DEFAULT_CLOSED'}
bl_parent_id = SOLLUMZ_PT_OBJECT_PANEL.bl_idname
@ classmethod
def poll(cls, context):
aobj = context.active_object
return aobj != None and aobj.sollum_type == SollumType.DRAWABLE
def draw(self, context):
layout = self.layout
grid = layout.grid_flow(columns=2, even_columns=True, even_rows=True)
grid.use_property_split = True
aobj = context.active_object
grid.prop(aobj.entity_properties, "flags")
grid.prop(aobj.entity_properties, "guid")
grid.prop(aobj.entity_properties, "parent_index")
grid.prop(aobj.entity_properties, "lod_dist")
grid.prop(aobj.entity_properties, "child_lod_dist")
grid.prop(aobj.entity_properties, "num_children")
grid.prop(aobj.entity_properties, "ambient_occlusion_multiplier")
grid.prop(aobj.entity_properties, "artificial_ambient_occlusion")
grid.prop(aobj.entity_properties, "tint_value")
grid.prop(aobj.entity_properties, "lod_level")
grid.prop(aobj.entity_properties, "priority_level")
class SOLLUMZ_PT_MAT_PANEL(bpy.types.Panel):
bl_label = "Sollumz"
bl_idname = "SOLLUMZ_PT_MAT_PANEL"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'material'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
aobj = context.active_object
if context.active_object == None:
return
mat = aobj.active_material
if not mat or mat.sollum_type == MaterialType.NONE:
layout.label(text="No sollumz material active.", icon="ERROR")
class FlagsPanel:
bl_label = "Flags"
bl_options = {'DEFAULT_CLOSED'}
def get_flags(self, context):
raise NotImplementedError(
f"Failed to display flags. '{self.__class__.__name__}.get_flags()' method not defined.")
def draw(self, context):
data_block = self.get_flags(context)
self.layout.prop(data_block, "total")
self.layout.separator()
grid = self.layout.grid_flow(columns=2)
for index, prop_name in enumerate(data_block.__annotations__):
if index > data_block.size - 1:
break
grid.prop(data_block, prop_name)
class TimeFlagsPanel(FlagsPanel):
bl_label = "Time Flags"
select_operator = None
clear_operator = None
def draw(self, context):
super().draw(context)
if self.select_operator is None or self.clear_operator is None:
raise NotImplementedError(
f"'select_operator' and 'clear_operator' bl_idnames must be defined for {self.__class__.__name__}!")
flags = self.get_flags(context)
row = self.layout.row()
row.operator(self.select_operator)
row.prop(flags, "time_flags_start", text="from")
row.prop(flags, "time_flags_end", text="to")
row = self.layout.row()
row.operator(self.clear_operator)