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

« back to all changes in this revision

Viewing changes to release/scripts/weightpaint_invert.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
#!BPY
 
2
"""
 
3
Name: 'Invert Active Group'
 
4
Blender: 245
 
5
Group: 'WeightPaint'
 
6
Tooltip: 'Invert the active vertex group'
 
7
"""
 
8
 
 
9
# -------------------------------------------------------------------------- 
 
10
# ***** BEGIN GPL LICENSE BLOCK ***** 
 
11
 
12
# This program is free software; you can redistribute it and/or 
 
13
# modify it under the terms of the GNU General Public License 
 
14
# as published by the Free Software Foundation; either version 2 
 
15
# of the License, or (at your option) any later version. 
 
16
 
17
# This program is distributed in the hope that it will be useful, 
 
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 
20
# GNU General Public License for more details. 
 
21
 
22
# You should have received a copy of the GNU General Public License 
 
23
# along with this program; if not, write to the Free Software Foundation, 
 
24
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 
25
 
26
# ***** END GPL LICENCE BLOCK ***** 
 
27
# --------------------------------------------------------------------------
 
28
import Blender
 
29
from Blender import Scene, Mesh, Window, sys
 
30
 
 
31
import BPyMessages
 
32
import bpy
 
33
 
 
34
def vgroup_invert(ob_orig, me):
 
35
        if not me.getVertGroupNames():
 
36
                return
 
37
        group_act = me.activeGroup
 
38
        if group_act == None:
 
39
                return
 
40
        
 
41
        group_data = me.getVertsFromGroup(group_act, 1)
 
42
        
 
43
        weights= [1.0] * len(me.verts) # 1.0 - initialize inverted
 
44
        
 
45
        group_data = me.getVertsFromGroup(group_act, 1) # (i,w)  tuples.
 
46
        
 
47
        me.removeVertGroup(group_act) # messes up the active group.
 
48
        for i,w in group_data:
 
49
                weights[i] = 1.0-w
 
50
        
 
51
        me.addVertGroup(group_act)
 
52
        
 
53
        rep = Blender.Mesh.AssignModes.REPLACE
 
54
        vertList= [None]
 
55
        for i,weight in enumerate(weights):
 
56
                vertList[0] = i
 
57
                me.assignVertsToGroup(group_act, vertList, weight, rep)
 
58
        
 
59
        me.activeGroup = group_act
 
60
        me.update()
 
61
 
 
62
def main():
 
63
        
 
64
        # Gets the current scene, there can be many scenes in 1 blend file.
 
65
        sce = bpy.data.scenes.active
 
66
        
 
67
        # Get the active object, there can only ever be 1
 
68
        # and the active object is always the editmode object.
 
69
        ob_act = sce.objects.active
 
70
        
 
71
        if not ob_act or ob_act.type != 'Mesh':
 
72
                BPyMessages.Error_NoMeshActive()
 
73
                return 
 
74
        
 
75
        # Saves the editmode state and go's out of 
 
76
        # editmode if its enabled, we cant make
 
77
        # changes to the mesh data while in editmode.
 
78
        is_editmode = Window.EditMode()
 
79
        Window.EditMode(0)
 
80
        
 
81
        Window.WaitCursor(1)
 
82
        me = ob_act.getData(mesh=1) # old NMesh api is default
 
83
        t = sys.time()
 
84
        
 
85
        # Run the mesh editing function
 
86
        vgroup_invert(ob_act, me)
 
87
        
 
88
        # Timing the script is a good way to be aware on any speed hits when scripting
 
89
        print 'Invert VGroup in %.2f seconds' % (sys.time()-t)
 
90
        Window.WaitCursor(0)
 
91
        if is_editmode: Window.EditMode(1)
 
92
        
 
93
# This lets you can import the script without running it
 
94
if __name__ == '__main__':
 
95
        main()
 
 
b'\\ No newline at end of file'