-
Notifications
You must be signed in to change notification settings - Fork 0
/
skinning_suite.py
799 lines (612 loc) · 26.4 KB
/
skinning_suite.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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
import os
import json
import bpy
# sorry mac/linux users
CLIPBOARD_WEIGHTS_JSON_PATH = r"C:/tmp/blender_skinning_clipboard.json"
SELECTION_SAVE_JSON = "c:/tmp/saved_selection_blender.json"
if not os.path.exists(os.path.dirname(SELECTION_SAVE_JSON)):
os.makedirs(os.path.dirname(SELECTION_SAVE_JSON))
class RemoveUnusedVertexGroups(bpy.types.Operator):
bl_idname = "paint.skinsuite_remove_unused_vertex_groups"
bl_label = "Remove Unused Influences"
bl_description = "Remove vertex groups from object that don't have any skinning"
bl_options = {'REGISTER', 'UNDO'}
margin: bpy.props.FloatProperty(
name="Margin",
default=0.0001,
precision=4,
min=0.0,
max=1.0,
)
def draw(self, context):
layout = self.layout
layout.prop(self, "margin")
def invoke(self, context: 'Context', event: 'Event'):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
used_groups = []
for vg in ob.vertex_groups:
for vertex in ob.data.vertices:
try:
weight = vg.weight(vertex.index)
except Exception as e:
weight = 0
if weight > self.margin:
# a weight value was found for this vertex group, skip to next group
used_groups.append(vg)
break
unused_groups = [vg.name for vg in ob.vertex_groups if vg not in used_groups]
# remove groups
for unused_group in unused_groups:
ob.vertex_groups.remove(ob.vertex_groups.get(unused_group))
bpy.ops.object.vertex_group_normalize_all()
return {"FINISHED"}
class TransferVertexGroups(bpy.types.Operator):
bl_idname = "paint.skinsuite_transfer_vertex_groups"
bl_label = "Transfer Weights"
bl_description = "Transfer weights from the active object to all selected"
bl_options = {'REGISTER', 'UNDO'}
def draw(self, context):
layout = self.layout
layout.prop(self, "margin")
def execute(self, context):
bpy.ops.object.data_transfer(
data_type='VGROUP_WEIGHTS',
use_create=True,
vert_mapping='POLYINTERP_NEAREST',
layers_select_src='ALL',
layers_select_dst='NAME',
mix_mode='REPLACE',
)
return {"FINISHED"}
"""
class SelectInfluencedVertices(bpy.types.Operator):
bl_idname = "paint.skinsuite_select_influenced_vertices"
bl_label = "Select Influenced Verts"
bl_description = ""
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
vertex_groups = ob.vertex_groups # type: bpy.types.VertexGroups
ob.data.use_paint_mask_vertex = True
bpy.ops.paint.vert_select_all(action='DESELECT')
for vtx in ob.data.vertices: # type: bpy.types.MeshVertex
try:
weight = vertex_groups.active.weight(vtx.index)
except Exception as e:
weight = 0
if weight > 0:
vtx.select = True
return {"FINISHED"}
"""
class SelectVerticesInWeightRange(bpy.types.Operator):
bl_idname = "paint.skinsuite_select_vertices_in_weight_range"
bl_label = "Select Vertices in Weight Range"
bl_description = "Find vertices that have weighting within the defined limits"
bl_options = {'REGISTER', 'UNDO'}
def _update_func(self, context):
SelectVerticesInWeightRange.select_vertices_in_weight_range(
SelectVerticesInWeightRange,
context,
lower_limit=self.lower_limit,
upper_limit=self.upper_limit,
)
lower_limit: bpy.props.FloatProperty(
name="Lower Limit",
default=0.0,
soft_min=0.0,
soft_max=1.0,
precision=6,
update=_update_func,
)
upper_limit: bpy.props.FloatProperty(
name="Upper Limit",
default=1.0,
soft_min=0.0,
soft_max=1.0,
precision=6,
update=_update_func,
)
def draw(self, context):
layout = self.layout
layout.prop(self, "upper_limit")
layout.prop(self, "lower_limit")
def invoke(self, context, event):
self.lower_limit = 0.0
self.upper_limit = 1.0
self.select_vertices_in_weight_range(
context,
lower_limit=self.lower_limit,
upper_limit=self.upper_limit,
)
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
self.select_vertices_in_weight_range(
context,
lower_limit=self.lower_limit,
upper_limit=self.upper_limit,
)
return {"FINISHED"}
def select_vertices_in_weight_range(self, context, lower_limit=0, upper_limit=1):
ob = context.active_object # type: bpy.types.Object
vertex_groups = ob.vertex_groups # type: bpy.types.VertexGroups
ob.data.use_paint_mask_vertex = True
for vtx in ob.data.vertices: # type: bpy.types.MeshVertex
try:
weight = vertex_groups.active.weight(vtx.index)
except Exception as e:
weight = 0
if weight > lower_limit and weight <= upper_limit:
vtx.select = True
else:
vtx.select = False
class SelectWeightIslandsInRange(bpy.types.Operator):
bl_idname = "paint.skinsuite_select_weight_islands_in_range"
bl_label = "Select Weight Islands in Range"
bl_description = "Find weight islands, and select those where the average weighting is between the limit values"
bl_options = {'REGISTER', 'UNDO'}
def _update_func(self, context):
SelectWeightIslandsInRange.select_islands_in_range(
SelectWeightIslandsInRange,
context,
lower_limit=self.lower_limit,
upper_limit=self.upper_limit,
)
lower_limit: bpy.props.FloatProperty(
name="Lower Limit",
default=0.0,
soft_min=0.0,
soft_max=1.0,
precision=6,
update=_update_func,
)
upper_limit: bpy.props.FloatProperty(
name="Upper Limit",
default=0.1,
soft_min=0.0,
soft_max=1.0,
precision=6,
update=_update_func,
)
def draw(self, context):
layout = self.layout
layout.prop(self, "upper_limit")
layout.prop(self, "lower_limit")
def invoke(self, context, event):
self.lower_limit = 0.0
self.upper_limit = 0.1
self._get_island_data(context)
self.select_islands_in_range(
context,
lower_limit=self.lower_limit,
upper_limit=self.upper_limit,
)
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
self.select_islands_in_range(
context,
lower_limit=self.lower_limit,
upper_limit=self.upper_limit,
)
return {"FINISHED"}
def _get_island_data(self, context):
ob = context.active_object # type: bpy.types.Object
active_vert_group = ob.vertex_groups.active # type: bpy.types.VertexGroup
# find all vertices with weighting
weighting = {}
for vtx in ob.data.vertices: # type: bpy.types.MeshVertex
try:
weight = active_vert_group.weight(vtx.index)
except Exception as e:
weight = 0
if weight > 0:
weighting[vtx.index] = weight
# make_edge_connection map
vert_edge_map = {}
for edge in ob.data.edges:
edge = edge # type: bpy.types.MeshEdge
for vert_id in edge.vertices:
connected_edges = vert_edge_map.get(vert_id, [])
connected_edges.extend(edge.vertices)
vert_edge_map[vert_id] = connected_edges
# sort by highest weighted vert
highest_inf = sorted(weighting, key=weighting.get, reverse=True)
islands = []
visited_verts = []
for vert_id in highest_inf:
# we've searched all the verts, exit search
if len(visited_verts) == len(highest_inf):
break
if vert_id in visited_verts:
continue
search_list = [vert_id]
while True:
# find connected vertices that have weighting on them
good_roots = []
for search_id in search_list:
for connected_vert_id in vert_edge_map.get(search_id):
# skip verts that have already been found
if connected_vert_id in search_list:
continue
if connected_vert_id in good_roots:
continue
if connected_vert_id in highest_inf:
good_roots.append(connected_vert_id)
# no weighted verts connected to these verts, exit while-loop
if len(good_roots) == 0:
break
search_list.extend(good_roots)
visited_verts.extend(search_list)
islands.append(search_list)
bpy.types.WindowManager.SKINSUITE_VERT_WEIGHT_ISLAND_DATA = {
"islands": islands,
"weighting": weighting,
}
def select_islands_in_range(self, context, lower_limit=0.0, upper_limit=0.1):
ob = context.active_object # type: bpy.types.Object
islands = bpy.types.WindowManager.SKINSUITE_VERT_WEIGHT_ISLAND_DATA.get("islands")
weighting = bpy.types.WindowManager.SKINSUITE_VERT_WEIGHT_ISLAND_DATA.get("weighting")
suspect_islands = []
for island in islands:
weight_values = []
for vert_id in island:
weight_values.append(weighting.get(vert_id))
average_weight = sum(weight_values) / len(weight_values)
if average_weight > lower_limit and average_weight <= upper_limit:
suspect_islands.append(island)
# select the verts
bpy.ops.paint.vert_select_all(action='DESELECT')
ob.data.use_paint_mask_vertex = True
for island in suspect_islands:
for vert_id in island:
vtx = ob.data.vertices[vert_id]
vtx.select = True
class SelectMoreComponents(bpy.types.Operator):
bl_idname = "paint.skinsuite_select_more_verts"
bl_label = "Select More"
bl_description = "Grow vertex selection via edge connections"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
# make_edge_connection
vert_edge_map = {}
for edge in ob.data.edges:
edge = edge # type: bpy.types.MeshEdge
for vert_id in edge.vertices:
connected_edges = vert_edge_map.get(vert_id, [])
connected_edges.append(edge)
vert_edge_map[vert_id] = connected_edges
indices_to_select = []
for vtx in ob.data.vertices:
vtx = vtx # type: bpy.types.MeshVertex
if vtx.select:
for edge in vert_edge_map.get(vtx.index, []):
indices_to_select.extend(edge.vertices)
indices_to_select = list(set(indices_to_select))
for index_to_select in indices_to_select:
ob.data.vertices[index_to_select].select = True
return {"FINISHED"}
class SelectLessComponents(bpy.types.Operator):
bl_idname = "paint.skinsuite_select_less_verts"
bl_label = "Select Less"
bl_description = "Shrink vertex selection via edge connections"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
# make_edge_connection map
vert_edge_map = {}
for edge in ob.data.edges:
edge = edge # type: bpy.types.MeshEdge
for vert_id in edge.vertices:
connected_edges = vert_edge_map.get(vert_id, [])
connected_edges.append(edge)
vert_edge_map[vert_id] = connected_edges
selected_verts = []
for vtx in ob.data.vertices:
if vtx.select:
selected_verts.append(vtx.index)
# find edges where we only have one vert selected
verts_to_deselect = []
for vert_id in selected_verts:
for edge in vert_edge_map.get(vert_id):
edge_verts_in_sel = len([v for v in edge.vertices if v in selected_verts])
if edge_verts_in_sel == 1:
verts_to_deselect.extend(edge.vertices)
verts_to_deselect = list(set(verts_to_deselect))
for index_to_select in verts_to_deselect:
ob.data.vertices[index_to_select].select = False
return {"FINISHED"}
class RemoveWeightingOnSelected(bpy.types.Operator):
bl_idname = "paint.skinsuite_remove_weighting_on_selected"
bl_label = "Apply 0 Weights"
bl_description = "Sets 0 influence on the selected group on the selected verts"
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
ob.data.use_paint_mask_vertex = True
active_vert_group = ob.vertex_groups.active # type: bpy.types.VertexGroup
for vtx in ob.data.vertices: # type: bpy.types.MeshVertex
vtx = vtx # type: bpy.types.MeshVertex
if not vtx.select:
continue
weighting = {}
for vtx_grp in vtx.groups:
vtx_grp = vtx_grp # type: bpy.types.VertexGroupElement
if vtx_grp.group == active_vert_group.index:
weight_val = 0.0
else:
weight_val = vtx_grp.weight
if weight_val:
weighting[vtx_grp] = weight_val
# set all the weighting to zero (since we'll apply normalized weights)
vtx_grp.weight = 0.0
un_normalized_max = sum(weighting.values())
normalized_weights = {k: v / un_normalized_max for k, v in weighting.items()}
# sum(normalized_weights.values()) # should be 1.0
# apply normalized weights on selected verts
for vtx_grp, target_weight in normalized_weights.items():
vtx_grp.weight = target_weight
return {"FINISHED"}
class LinkArmatureToCurrentScene(bpy.types.Operator):
bl_idname = "paint.skinsuite_link_armature_to_scene"
bl_label = "Link Armature To Scene"
bl_description = "Find the armature attached to the active object, and link it to the current scene"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
armature_modifiers = [mod for mod in ob.modifiers if mod.type == "ARMATURE"]
for armature_modifier in armature_modifiers:
armature_obj = armature_modifier.object
if armature_obj and not bpy.context.scene.objects.get(armature_obj.name):
bpy.context.scene.collection.objects.link(armature_obj)
return {"FINISHED"}
class SaveSelection(bpy.types.Operator):
bl_idname = "paint.skinsuite_save_selection"
bl_label = "Save Selection"
bl_description = "Save the selected vertex ids to a file"
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
selected_verts = []
for vtx in ob.data.vertices:
vtx = vtx # type: bpy.types.MeshVertex
if vtx.select:
selected_verts.append(vtx.index)
with open(SELECTION_SAVE_JSON, "w") as fp:
json.dump(selected_verts, fp, indent=2)
return {"FINISHED"}
class SelectSavedSelection(bpy.types.Operator):
bl_idname = "paint.skinsuite_select_saved_selection"
bl_label = "Select Saved"
bl_description = "Select the saved vertex ids"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
with open(SELECTION_SAVE_JSON, "r") as fp:
verts_to_sel = json.load(fp)
for vtx in ob.data.vertices:
vtx = vtx # type: bpy.types.MeshVertex
if vtx.index in verts_to_sel:
vtx.select = True
return {"FINISHED"}
class DeSelectSavedSelection(bpy.types.Operator):
bl_idname = "paint.skinsuite_deselect_saved_selection"
bl_label = "DeSelect Saved"
bl_description = "Deselect the saved vertex ids"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
with open(SELECTION_SAVE_JSON, "r") as fp:
verts_to_sel = json.load(fp)
for vtx in ob.data.vertices:
vtx = vtx # type: bpy.types.MeshVertex
if vtx.index in verts_to_sel:
vtx.select = False
return {"FINISHED"}
class SelectUnNormalizedVertices(bpy.types.Operator):
bl_idname = "paint.skinsuite_select_unnormalized_vertices"
bl_label = "Select UnNormalized Verts"
bl_description = "Find vertices where the total weight exceeds 1"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
ob.data.use_paint_mask_vertex = True
bpy.ops.paint.vert_select_all(action='DESELECT')
for vtx in ob.data.vertices: # type: bpy.types.MeshVertex
total_weight = 0
for grp in vtx.groups:
if 0:
grp = grp # type: bpy.types.VertexGroupElement
total_weight += grp.weight
if round(total_weight, 8) > 1:
print(f"weight exceeds 1: {total_weight} - {vtx.index}")
vtx.select = True
return {"FINISHED"}
class CopySelectedVertexWeights(bpy.types.Operator):
bl_idname = "paint.skinsuite_copy_selected_vertex_weights"
bl_label = "Copy Selected Weights"
bl_description = "Copy the average weighting of all selected vertices"
def execute(self, context):
ob = context.active_object # type: bpy.types.Object
max_influence = 8
# get weighting data of all selected vertices
weight_data = {}
for vtx in ob.data.vertices:
if 0:
vtx = vtx # type: bpy.types.MeshVertex
if not vtx.select:
continue
weight_data[vtx.index] = {}
for grp in vtx.groups:
if 0:
grp = grp # type: bpy.types.VertexGroupElement
if grp.weight == 0:
continue
vg_name = ob.vertex_groups[grp.group].name
weight_data[vtx.index][vg_name] = grp.weight
if not weight_data:
self.report({'ERROR'}, "No weight data found in selection.")
return {"FINISHED"}
###########################################
# Calculate average weighting of all verts
# sum up all weight data
total_vals = {}
for vtx_data in weight_data.values():
for vg_name, weight_val in vtx_data.items():
v = total_vals.get(vg_name, 0.0)
v += weight_val
total_vals[vg_name] = v
# get most affecting bones
most_vals = {k: v for k, v in sorted(total_vals.items(), key=lambda item: item[1])[-max_influence:]}
total_weight = sum(most_vals.values())
# average out the results from 0.0 to 1.0
averaged = {}
for k, v in most_vals.items():
ratio = v / total_weight
averaged[k] = ratio
# make sure the weights make sense
print(f"average weight sum: {sum(averaged.values())}")
assert(round(sum(averaged.values()), 8) == 1)
with open(CLIPBOARD_WEIGHTS_JSON_PATH, "w+") as fp:
json.dump(averaged, fp)
self.report({'INFO'}, f"Saved weights to: {CLIPBOARD_WEIGHTS_JSON_PATH}")
return {"FINISHED"}
class PasteSelectedVertexWeights(bpy.types.Operator):
bl_idname = "paint.skinsuite_paste_selected_vertex_weights"
bl_label = "Paste Weights on Selected"
bl_description = "Paste the copied weighting onto the selected verts, with a weighting slider"
bl_options = {'REGISTER', 'UNDO'}
def _update_func(self, context):
PasteSelectedVertexWeights.set_weights_on_selected(
PasteSelectedVertexWeights,
context,
paste_weight=self.paste_weight,
)
paste_weight: bpy.props.FloatProperty(
name="Weight",
default=1.0,
min=0.0,
max=1.0,
update=_update_func,
)
def draw(self, context):
layout = self.layout
layout.prop(self, "paste_weight")
def invoke(self, context, event):
self.store_selected_vert_data(context)
self.set_weights_on_selected(context, paste_weight=self.paste_weight)
return context.window_manager.invoke_props_dialog(self)
def store_selected_vert_data(self, context):
with open(CLIPBOARD_WEIGHTS_JSON_PATH, "r") as fp:
json_data = json.load(fp)
json_bones = json_data.keys()
ob = context.active_object # type: bpy.types.Object
# get weight data
sel_weight_data = {}
for vtx_index, vtx in enumerate(ob.data.vertices):
if 0:
vtx = vtx # type: bpy.types.MeshVertex
if not vtx.select:
continue
sel_weight_data[vtx_index] = {}
for grp in vtx.groups:
vg_name = ob.vertex_groups[grp.group].name
sel_weight_data[vtx_index][vg_name] = grp.weight
# assign missing vertex groups
missing_bones = [b for b in json_bones if b not in sel_weight_data[vtx_index].keys()]
for missing_bone in missing_bones:
v_group = ob.vertex_groups.get(missing_bone)
if v_group is None:
v_group = ob.vertex_groups.new(name=missing_bone)
# this can be optimized
v_group.add([vtx.index], 0, 'REPLACE')
bpy.types.WindowManager.SKINSUITE_COPY_PASTE_WEIGHT_DATA = {
"sel": sel_weight_data,
"json": json_data
}
def set_weights_on_selected(self, context, paste_weight=1.0):
sel_weight_data = bpy.types.WindowManager.SKINSUITE_COPY_PASTE_WEIGHT_DATA.get("sel")
json_weight_data = bpy.types.WindowManager.SKINSUITE_COPY_PASTE_WEIGHT_DATA.get("json")
ob = context.active_object # type: bpy.types.Object
# blend in weights
for vtx_index, weight_data in sel_weight_data.items():
vtx = ob.data.vertices[vtx_index]
if 0:
vtx = vtx # type: bpy.types.MeshVertex
for grp in vtx.groups:
vg_name = ob.vertex_groups[grp.group].name
json_weight = json_weight_data.get(vg_name)
if json_weight is None:
continue
pre_weight = weight_data.get(vg_name, 0)
# blend in json
new_val = lerp(pre_weight, json_weight, paste_weight)
grp.weight = new_val
def execute(self, context):
self.set_weights_on_selected(context, paste_weight=self.paste_weight)
bpy.ops.object.vertex_group_normalize_all()
self.report({'INFO'}, f"Pasted weights from: {CLIPBOARD_WEIGHTS_JSON_PATH}")
return {"FINISHED"}
def lerp(a, b, t):
return a + (b - a) * t
class RENDER_PT_SkinSuiteVertexGroupTools(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_idname = "DATA_PT_SkinSuiteVertexGroupTools"
bl_category = 'SKM'
bl_parent_id = 'DATA_PT_vertex_groups'
bl_label = "Skinning Suite Tools"
bl_options = {"HEADER_LAYOUT_EXPAND"}
def draw(self, context):
layout = self.layout
copy_paste_row = layout.row()
copy_paste_row.operator(CopySelectedVertexWeights.bl_idname)
copy_paste_row.operator(PasteSelectedVertexWeights.bl_idname)
layout.operator(TransferVertexGroups.bl_idname)
layout.separator()
remove_row = layout.row()
remove_row.operator(RemoveUnusedVertexGroups.bl_idname)
remove_row.operator(RemoveWeightingOnSelected.bl_idname)
layout.operator(LinkArmatureToCurrentScene.bl_idname)
layout.separator()
layout.operator(SelectUnNormalizedVertices.bl_idname)
layout.operator(SelectVerticesInWeightRange.bl_idname)
layout.operator(SelectWeightIslandsInRange.bl_idname)
layout.separator()
select_row = layout.row()
select_row.operator(SelectMoreComponents.bl_idname)
select_row.operator(SelectLessComponents.bl_idname)
saved_select_row = layout.row()
saved_select_row.operator(SaveSelection.bl_idname)
saved_select_row.operator(SelectSavedSelection.bl_idname)
saved_select_row.operator(DeSelectSavedSelection.bl_idname)
CLASS_LIST = [
LinkArmatureToCurrentScene,
SelectMoreComponents,
SelectLessComponents,
SaveSelection,
SelectSavedSelection,
DeSelectSavedSelection,
SelectVerticesInWeightRange,
SelectWeightIslandsInRange,
SelectUnNormalizedVertices,
RemoveWeightingOnSelected,
RemoveUnusedVertexGroups,
CopySelectedVertexWeights,
PasteSelectedVertexWeights,
TransferVertexGroups,
]
def menu_func(self, context):
for cls in CLASS_LIST:
self.layout.operator(cls.bl_idname)
def register():
for cls in CLASS_LIST:
bpy.utils.register_class(cls)
bpy.utils.register_class(RENDER_PT_SkinSuiteVertexGroupTools)
# add to menu so we can register shortcuts
bpy.types.VIEW3D_MT_select_paint_mask_vertex.append(menu_func)
def unregister():
for cls in CLASS_LIST:
bpy.utils.unregister_class(cls)
bpy.utils.unregister_class(RENDER_PT_SkinSuiteVertexGroupTools)
# add to menu so we can register shortcuts
bpy.types.VIEW3D_MT_select_paint_mask_vertex.remove(menu_func)