38
38
# ***** END GPL LICENCE BLOCK *****
39
39
# --------------------------------------------------------------------------
41
from Blender import Scene, Draw
41
from Blender import Scene, Draw, Object
44
def actWeightNormalize(me, PREF_THRESH, PREF_KEEP_SINGLE):
43
def weightClean(me, PREF_THRESH, PREF_KEEP_SINGLE, PREF_OTHER_GROUPS):
46
45
groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
47
46
act_group= me.activeGroup
49
for wd in vWeightDict:
50
if not PREF_KEEP_SINGLE or len(wd) > 1:
54
# small weight, remove.
51
for wd in vWeightDict:
53
if not PREF_KEEP_SINGLE or l > 1:
54
for group in wd.keys():
57
# small weight, remove.
62
if PREF_KEEP_SINGLE and l == 1:
66
for wd in vWeightDict:
67
if not PREF_KEEP_SINGLE or len(wd) > 1:
71
# small weight, remove.
59
77
# Copy weights back to the mesh.
60
78
BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
64
83
scn= Scene.GetCurrent()
65
ob= scn.getActiveObject()
84
ob= scn.objects.active
67
if not ob or ob.getType() != 'Mesh':
86
if not ob or ob.type != 'Mesh':
68
87
Draw.PupMenu('Error, no active mesh object, aborting.')
71
90
me= ob.getData(mesh=1)
73
PREF_PEAKWEIGHT= Draw.Create(0.005)
92
PREF_PEAKWEIGHT= Draw.Create(0.001)
74
93
PREF_KEEP_SINGLE= Draw.Create(1)
94
PREF_OTHER_GROUPS= Draw.Create(0)
77
('Peak Weight:', PREF_PEAKWEIGHT, 0.01, 1.0, 'Upper weight for normalizing.'),\
78
('Keep Single User', PREF_KEEP_SINGLE, 'Dont remove verts that are in this group only.'),\
97
('Peak Weight:', PREF_PEAKWEIGHT, 0.005, 1.0, 'Remove verts from groups below this weight.'),\
98
('All Other Groups', PREF_OTHER_GROUPS, 'Clean all groups, not just the current one.'),\
99
('Keep Single User', PREF_KEEP_SINGLE, 'Keep verts in at least 1 group.'),\
81
102
if not Draw.PupBlock('Clean Selected Meshes...', pup_block):
84
PREF_PEAKWEIGHT= PREF_PEAKWEIGHT.val
85
PREF_KEEP_SINGLE= PREF_KEEP_SINGLE.val
105
rem_count = weightClean(me, PREF_PEAKWEIGHT.val, PREF_KEEP_SINGLE.val, PREF_OTHER_GROUPS.val)
87
actWeightNormalize(me, PREF_PEAKWEIGHT, PREF_KEEP_SINGLE)
107
# Run on entire blend file. usefull sometimes but dont let users do it.
110
for ob in Object.Get():
111
if ob.type != 'Mesh':
113
me= ob.getData(mesh=1)
115
rem_count += weightClean(me, PREF_PEAKWEIGHT.val, PREF_KEEP_SINGLE.val, PREF_OTHER_GROUPS.val)
117
Draw.PupMenu('Removed %i verts from groups' % rem_count)
89
119
if __name__=='__main__':
b'\\ No newline at end of file'