move mesh_vgroup_average to the weightpaint menu and rename. also added an option...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 12 Aug 2007 06:14:33 +0000 (06:14 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 12 Aug 2007 06:14:33 +0000 (06:14 +0000)
 - fix from 2.44 so makeDisplayList updates 3d text

release/scripts/weightpaint_average.py [moved from release/scripts/mesh_vgroup_average.py with 71% similarity]
source/blender/python/api2_2x/Object.c

similarity index 71%
rename from release/scripts/mesh_vgroup_average.py
rename to release/scripts/weightpaint_average.py
index 3832bf37a965b1852d8b46a7d9139c1ca856f7b7..57c27605da54cc4396e01d1e6bc0c22c98e02ebc 100644 (file)
@@ -2,7 +2,7 @@
 """
 Name: 'Vertex Groups Island Average'
 Blender: 243
-Group: 'Mesh'
+Group: 'WeightPaint'
 Tooltip: 'Average the vertex weights for each connected set of verts'
 """
 
@@ -26,7 +26,7 @@ Tooltip: 'Average the vertex weights for each connected set of verts'
 # ***** END GPL LICENCE BLOCK ***** 
 # --------------------------------------------------------------------------
 import Blender
-from Blender import Scene, Mesh, Window, sys
+from Blender import Scene, Mesh, Window, sys, Draw
 from BPyMesh import meshWeight2List, list2MeshWeight, mesh2linkedFaces
 
 import BPyMessages
@@ -37,7 +37,7 @@ def faceGroups2VertSets(face_groups):
        return [set([v.index for f in fg for v in f]) for fg in face_groups]
 
 
-def vgroup_average(ob_orig, me, sce):
+def vgroup_average(ob_orig, me, sce, PREF_ALL_VGROUPS=True):
        if not me.getVertGroupNames():
                return
        
@@ -47,22 +47,36 @@ def vgroup_average(ob_orig, me, sce):
        vgroup_dummy = [0.0] * weight_names_len
        vgroup_range = range(weight_names_len)
        
+       if not PREF_ALL_VGROUPS:
+               weight_active_index = weight_names.index(me.activeGroup)
+       
        for vert_set in faceGroups2VertSets( mesh2linkedFaces(me) ):
                if not vert_set:
                        continue
                
-               collected_group = vgroup_dummy[:]
                
-               # We need to average the vgroups
-               for i in vert_set:
-                       vert_group = weight_list[i]                     # get the original weight
-                       weight_list[i] = collected_group        # replace with the collected group
+               if PREF_ALL_VGROUPS:
+                       # We need to average the vgroups
+                       collected_group = vgroup_dummy[:]
+                       for i in vert_set:
+                               vert_group = weight_list[i]                     # get the original weight
+                               weight_list[i] = collected_group        # replace with the collected group
+                               
+                               for j in vgroup_range: # iter through the vgroups
+                                       collected_group[j] += vert_group[j]
                        
-                       for j in vgroup_range: # iter through the vgroups
-                               collected_group[j] += vert_group[j]
-               
-               for j in vgroup_range:
-                       collected_group[j] /= len(vert_set)
+                       for j in vgroup_range:
+                               collected_group[j] /= len(vert_set)
+               else:
+                       # Active group only
+                       vert_weight = 0.0
+                       for i in vert_set:
+                               vert_weight += weight_list[i][weight_active_index]
+                       
+                       vert_weight /= len(vert_set)
+                       
+                       for i in vert_set:
+                               weight_list[i][weight_active_index] = vert_weight
        
        list2MeshWeight(me, weight_names, weight_list)
 
@@ -85,12 +99,17 @@ def main():
        is_editmode = Window.EditMode()
        Window.EditMode(0)
        
+       PREF_ALL_VGROUPS = Draw.PupMenu("All Groups?%t|All Groups%x1|Active Group Only%x0")
+       if PREF_ALL_VGROUPS==-1:
+               return
+       
+       print "sd", PREF_ALL_VGROUPS
        Window.WaitCursor(1)
        me = ob_act.getData(mesh=1) # old NMesh api is default
        t = sys.time()
        
        # Run the mesh editing function
-       vgroup_average(ob_act, me, sce)
+       vgroup_average(ob_act, me, sce, PREF_ALL_VGROUPS)
        
        # Timing the script is a good way to be aware on any speed hits when scripting
        print 'Average VGroups in %.2f seconds' % (sys.time()-t)
index 0620b156a0fa0f0045158e66dd031fd124056890..73d30aa6ed3c9ed78248024f40a4a98a3b04a00e 100644 (file)
@@ -70,6 +70,7 @@ struct rctf;
 #include "BKE_idprop.h"
 #include "BKE_object.h"
 #include "BKE_key.h" /* for setting the activeShape */
+#include "BKE_displist.h"
 
 #include "BSE_editipo.h"
 #include "BSE_edit.h"
@@ -1556,8 +1557,11 @@ static PyObject *Object_makeDisplayList( BPy_Object * self )
 {
        Object *ob = self->object;
 
-       if( ob->type == OB_FONT )
+       if( ob->type == OB_FONT ) {
+               Curve *cu = ob->data;
+               freedisplist( &cu->disp );
                text_to_curve( ob, 0 );
+       }
 
        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);