~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to release/scripts/weightpaint_clean.py

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!BPY
2
2
"""
3
3
Name: 'Clean Weight...'
4
 
Blender: 241
 
4
Blender: 245
5
5
Group: 'WeightPaint'
6
6
Tooltip: 'Removed verts from groups below a weight limit.'
7
7
"""
8
8
 
9
 
__author__ = ["Campbell Barton"]
10
 
__url__ = ("blender", "elysiun", "http://members.iinet.net.au/~cpbarton/ideasman/")
 
9
__author__ = "Campbell Barton aka ideasman42"
 
10
__url__ = ["www.blender.org", "blenderartists.org", "www.python.org"]
11
11
__version__ = "0.1"
12
12
__bpydoc__ = """\
13
13
 
38
38
# ***** END GPL LICENCE BLOCK *****
39
39
# --------------------------------------------------------------------------
40
40
 
41
 
from Blender import Scene, Draw
 
41
from Blender import Scene, Draw, Object
42
42
import BPyMesh
43
 
SMALL_NUM= 0.000001
44
 
def actWeightNormalize(me, PREF_THRESH, PREF_KEEP_SINGLE):
 
43
def weightClean(me, PREF_THRESH, PREF_KEEP_SINGLE, PREF_OTHER_GROUPS):
45
44
        
46
45
        groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
47
46
        act_group= me.activeGroup
48
47
        
49
 
        for wd in vWeightDict:
50
 
                if not PREF_KEEP_SINGLE or len(wd) > 1:
51
 
                        try:
52
 
                                w= wd[act_group]
53
 
                                if w <= PREF_THRESH:
54
 
                                        # small weight, remove.
55
 
                                        del wd[act_group]
56
 
                        except:
57
 
                                pass
 
48
        rem_count = 0
 
49
        
 
50
        if PREF_OTHER_GROUPS:
 
51
                for wd in vWeightDict:
 
52
                        l = len(wd)
 
53
                        if not PREF_KEEP_SINGLE or l > 1:
 
54
                                for group in wd.keys():
 
55
                                        w= wd[group]
 
56
                                        if w <= PREF_THRESH:
 
57
                                                # small weight, remove.
 
58
                                                del wd[group]
 
59
                                                rem_count +=1
 
60
                                        l-=1
 
61
                                        
 
62
                                        if PREF_KEEP_SINGLE and l == 1:
 
63
                                                break
 
64
        
 
65
        else:
 
66
                for wd in vWeightDict:
 
67
                        if not PREF_KEEP_SINGLE or len(wd) > 1:
 
68
                                try:
 
69
                                        w= wd[act_group]
 
70
                                        if w <= PREF_THRESH:
 
71
                                                # small weight, remove.
 
72
                                                del wd[act_group]
 
73
                                                rem_count +=1
 
74
                                except:
 
75
                                        pass
58
76
        
59
77
        # Copy weights back to the mesh.
60
78
        BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
 
79
        return rem_count
61
80
 
62
81
 
63
82
def main():
64
83
        scn= Scene.GetCurrent()
65
 
        ob= scn.getActiveObject()
 
84
        ob= scn.objects.active
66
85
        
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.')
69
88
                return
70
89
        
71
90
        me= ob.getData(mesh=1)
72
91
        
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)
75
95
        
76
96
        pup_block= [\
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.'),\
79
100
        ]
80
101
        
81
102
        if not Draw.PupBlock('Clean Selected Meshes...', pup_block):
82
103
                return
83
104
        
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)
86
106
        
87
 
        actWeightNormalize(me, PREF_PEAKWEIGHT, PREF_KEEP_SINGLE)
 
107
        # Run on entire blend file. usefull sometimes but dont let users do it.
 
108
        '''
 
109
        rem_count = 0
 
110
        for ob in Object.Get():
 
111
                if ob.type != 'Mesh':
 
112
                        continue
 
113
                me= ob.getData(mesh=1)
 
114
                
 
115
                rem_count += weightClean(me, PREF_PEAKWEIGHT.val, PREF_KEEP_SINGLE.val, PREF_OTHER_GROUPS.val)
 
116
        '''
 
117
        Draw.PupMenu('Removed %i verts from groups' % rem_count)
88
118
        
89
119
if __name__=='__main__':
90
120
        main()
 
 
b'\\ No newline at end of file'