move mesh_vgroup_average to the weightpaint menu and rename. also added an option to add the active weight group or all groups.

- fix from 2.44 so makeDisplayList updates 3d text
This commit is contained in:
2007-08-12 06:14:33 +00:00
parent 0d5f195ba7
commit fb985daf01
2 changed files with 38 additions and 15 deletions

View File

@@ -2,7 +2,7 @@
""" """
Name: 'Vertex Groups Island Average' Name: 'Vertex Groups Island Average'
Blender: 243 Blender: 243
Group: 'Mesh' Group: 'WeightPaint'
Tooltip: 'Average the vertex weights for each connected set of verts' 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 ***** # ***** END GPL LICENCE BLOCK *****
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
import Blender import Blender
from Blender import Scene, Mesh, Window, sys from Blender import Scene, Mesh, Window, sys, Draw
from BPyMesh import meshWeight2List, list2MeshWeight, mesh2linkedFaces from BPyMesh import meshWeight2List, list2MeshWeight, mesh2linkedFaces
import BPyMessages 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] 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(): if not me.getVertGroupNames():
return return
@@ -47,22 +47,36 @@ def vgroup_average(ob_orig, me, sce):
vgroup_dummy = [0.0] * weight_names_len vgroup_dummy = [0.0] * weight_names_len
vgroup_range = range(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) ): for vert_set in faceGroups2VertSets( mesh2linkedFaces(me) ):
if not vert_set: if not vert_set:
continue continue
collected_group = vgroup_dummy[:]
# We need to average the vgroups if PREF_ALL_VGROUPS:
for i in vert_set: # We need to average the vgroups
vert_group = weight_list[i] # get the original weight collected_group = vgroup_dummy[:]
weight_list[i] = collected_group # replace with the collected group 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 for j in vgroup_range:
collected_group[j] += vert_group[j] collected_group[j] /= len(vert_set)
else:
for j in vgroup_range: # Active group only
collected_group[j] /= len(vert_set) 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) list2MeshWeight(me, weight_names, weight_list)
@@ -85,12 +99,17 @@ def main():
is_editmode = Window.EditMode() is_editmode = Window.EditMode()
Window.EditMode(0) 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) Window.WaitCursor(1)
me = ob_act.getData(mesh=1) # old NMesh api is default me = ob_act.getData(mesh=1) # old NMesh api is default
t = sys.time() t = sys.time()
# Run the mesh editing function # 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 # 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) print 'Average VGroups in %.2f seconds' % (sys.time()-t)

View File

@@ -70,6 +70,7 @@ struct rctf;
#include "BKE_idprop.h" #include "BKE_idprop.h"
#include "BKE_object.h" #include "BKE_object.h"
#include "BKE_key.h" /* for setting the activeShape */ #include "BKE_key.h" /* for setting the activeShape */
#include "BKE_displist.h"
#include "BSE_editipo.h" #include "BSE_editipo.h"
#include "BSE_edit.h" #include "BSE_edit.h"
@@ -1556,8 +1557,11 @@ static PyObject *Object_makeDisplayList( BPy_Object * self )
{ {
Object *ob = self->object; 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 ); text_to_curve( ob, 0 );
}
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);