[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57099] trunk/blender/source/blender/ editors/object/object_vgroup.c: tweaks to vertex weight limit

Campbell Barton ideasman42 at gmail.com
Wed May 29 02:00:25 CEST 2013


Revision: 57099
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57099
Author:   campbellbarton
Date:     2013-05-29 00:00:24 +0000 (Wed, 29 May 2013)
Log Message:
-----------
tweaks to vertex weight limit
- double check def_nr is valid (rare cases it is).
- usability, report how many weights are removed.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/object/object_vgroup.c

Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_vgroup.c	2013-05-28 23:13:04 UTC (rev 57098)
+++ trunk/blender/source/blender/editors/object/object_vgroup.c	2013-05-29 00:00:24 UTC (rev 57099)
@@ -1947,16 +1947,16 @@
 /* Used for limiting the number of influencing bones per vertex when exporting
  * skinned meshes.  if all_deform_weights is True, limit all deform modifiers
  * to max_weights regardless of type, otherwise, only limit the number of influencing bones per vertex*/
-static bool vgroup_limit_total_subset(Object *ob,
-                                      const bool *vgroup_validmap,
-                                      const int UNUSED(vgroup_tot),
-                                      const int subset_count,
-                                      const int max_weights)
+static int vgroup_limit_total_subset(Object *ob,
+                                     const bool *vgroup_validmap,
+                                     const int vgroup_tot,
+                                     const int subset_count,
+                                     const int max_weights)
 {
 	MDeformVert *dv, **dvert_array = NULL;
 	int i, dvert_tot = 0;
 	const int use_vert_sel = vertex_group_use_vert_sel(ob);
-	bool is_change = false;
+	int remove_tot = 0;
 
 	ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot, use_vert_sel);
 
@@ -1983,15 +1983,16 @@
 				dw_temp = MEM_mallocN(sizeof(MDeformWeight) * dv->totweight, __func__);
 				bone_count = 0; non_bone_count = 0;
 				for (j = 0; j < dv->totweight; j++) {
-					BLI_assert(dv->dw[j].def_nr < vgroup_tot);
-					if (!vgroup_validmap[dv->dw[j].def_nr]) {
+					if (LIKELY(dv->dw[j].def_nr < vgroup_tot) &&
+					    vgroup_validmap[dv->dw[j].def_nr])
+					{
+						dw_temp[dv->totweight - 1 - bone_count] = dv->dw[j];
+						bone_count += 1;
+					}
+					else {
 						dw_temp[non_bone_count] = dv->dw[j];
 						non_bone_count += 1;
 					}
-					else {
-						dw_temp[dv->totweight - 1 - bone_count] = dv->dw[j];
-						bone_count += 1;
-					}
 				}
 				BLI_assert(bone_count + non_bone_count == dv->totweight);
 				num_to_drop = bone_count - max_weights;
@@ -2001,7 +2002,7 @@
 					/* Do we want to clean/normalize here? */
 					MEM_freeN(dv->dw);
 					dv->dw = MEM_reallocN(dw_temp, sizeof(MDeformWeight) * dv->totweight);
-					is_change = true;
+					remove_tot += num_to_drop;
 				}
 				else {
 					MEM_freeN(dw_temp);
@@ -2013,7 +2014,7 @@
 
 	}
 
-	return is_change;
+	return remove_tot;
 }
 
 
@@ -3297,12 +3298,13 @@
 	int subset_count, vgroup_tot;
 
 	bool *vgroup_validmap = vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
-	bool changed = vgroup_limit_total_subset(ob, vgroup_validmap, vgroup_tot, subset_count, limit);
+	int remove_tot = vgroup_limit_total_subset(ob, vgroup_validmap, vgroup_tot, subset_count, limit);
 
 	MEM_freeN(vgroup_validmap);
 
-	if (changed) {
+	BKE_reportf(op->reports, remove_tot ? RPT_INFO : RPT_WARNING, "%d vertex weights limited", remove_tot);
 
+	if (remove_tot) {
 		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 		WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 		WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3310,8 +3312,6 @@
 		return OPERATOR_FINISHED;
 	}
 	else {
-		BKE_report(op->reports, RPT_WARNING, "No vertex groups limited");
-
 		/* note, would normally return cancelled, except we want the redo
 		 * UI to show up for users to change */
 		return OPERATOR_FINISHED;




More information about the Bf-blender-cvs mailing list