[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36954] branches/soc-2011-radish:

Jason Hays jason_hays22 at mymail.eku.edu
Fri May 27 21:13:55 CEST 2011


Revision: 36954
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36954
Author:   jason_hays22
Date:     2011-05-27 19:13:54 +0000 (Fri, 27 May 2011)
Log Message:
-----------


Modified Paths:
--------------
    branches/soc-2011-radish/release/scripts/startup/bl_ui/properties_data_mesh.py
    branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2011-radish/source/blender/makesdna/DNA_object_types.h
    branches/soc-2011-radish/source/blender/makesrna/intern/rna_object.c

Modified: branches/soc-2011-radish/release/scripts/startup/bl_ui/properties_data_mesh.py
===================================================================
--- branches/soc-2011-radish/release/scripts/startup/bl_ui/properties_data_mesh.py	2011-05-27 17:59:48 UTC (rev 36953)
+++ branches/soc-2011-radish/release/scripts/startup/bl_ui/properties_data_mesh.py	2011-05-27 19:13:54 UTC (rev 36954)
@@ -127,7 +127,8 @@
 
         ob = context.object
         group = ob.vertex_groups.active
-
+        
+        
         rows = 2
         if group:
             rows = 5
@@ -136,6 +137,8 @@
         row.template_list(ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
 
         col = row.column(align=True)
+        # Jason was here #
+        col.prop(group, "flag")
         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="")
         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")

Modified: branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c	2011-05-27 17:59:48 UTC (rev 36953)
+++ branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c	2011-05-27 19:13:54 UTC (rev 36954)
@@ -73,6 +73,7 @@
 #include "BKE_object.h"
 #include "BKE_paint.h"
 
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -346,7 +347,6 @@
 	DAG_id_tag_update(&me->id, 0);
 }
 
-
 /* fills in the selected faces with the current weight and vertex group */
 void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
 {
@@ -362,7 +362,7 @@
 	
 	me= ob->data;
 	if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return;
-	
+
 	selected= (me->editflag & ME_EDIT_PAINT_MASK);
 
 	indexar= get_indexarray(me);
@@ -1029,6 +1029,74 @@
 	}
 }
 
+/*Jason was here
+not sure where these prototypes belong at them moment
+static char* gen_lck_flags(Object* ob);
+static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw);
+
+gen_lck_flags gets the status of "flag" for each bDeformGroup in ob->defbase and returns an array containing them 
+*/
+static char* gen_lck_flags(Object* ob)
+{
+	char is_locked = 0;
+	int i, k;
+	int defcnt = BLI_countlist(&ob->defbase);
+	char *flags = MEM_mallocN(defcnt*sizeof(char), "defflags");
+	bDeformGroup *defgroup = ob->defbase.first;
+	for(i = 0; i < defcnt && defgroup; i++) {
+		flags[i] = defgroup->flag;
+		defgroup = defgroup->next;
+		if(flags[i]) {
+			is_locked = 1;
+		}
+	}
+	if(is_locked){
+		return flags;
+	}
+	return NULL;
+}
+/*Jason was here
+this alters the weights in order to maintain the ratios to match with the change in weights of pnt_dw
+*/
+static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw)
+{
+	int i, k, totvert, cnt;
+	float scaledown = 1.0f;
+	float neww = pnt_dw->weight;
+	int defgroup = pnt_dw->def_nr;
+	totvert = me->totvert;
+	pnt_dw->weight = oldw;
+
+	if(oldw == 0 || neww == 0){
+		return;
+	}
+
+	for(i = 0; i < totvert; i++) {
+		cnt = (me->dvert+i)->totweight;
+		for(k = 0; k < cnt; k++) {
+			MDeformWeight *dw = ((me->dvert+i)->dw+k);
+			if(dw->def_nr == defgroup){
+				dw->weight = neww * (dw->weight / oldw);
+				if(dw->weight > scaledown){
+					scaledown = dw->weight;
+				}
+				break;
+			}
+		}
+	}
+	if(scaledown > 1.0f) {
+		for(i = 0; i < totvert; i++) {
+			cnt = (me->dvert+i)->totweight;
+			for(k = 0; k < cnt; k++) {
+				MDeformWeight *dw = ((me->dvert+i)->dw+k);
+				if(dw->def_nr == defgroup){
+					dw->weight /= scaledown;
+					break;
+				}
+			}
+		}
+	}
+}
 static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, 
 				   float alpha, float paintweight, int flip, 
 				   int vgroup_mirror, char *validmap)
@@ -1037,6 +1105,10 @@
 	MDeformWeight *dw, *uw;
 	int vgroup= ob->actdef-1;
 	
+	/* Jason was here */
+	char *flags;
+	float oldw;
+
 	if(wp->flag & VP_ONLYVGROUP) {
 		dw= defvert_find_index(me->dvert+index, vgroup);
 		uw= defvert_find_index(wp->wpaint_prev+index, vgroup);
@@ -1047,8 +1119,20 @@
 	}
 	if(dw==NULL || uw==NULL)
 		return;
-	
+	/* Jason was here */
+	flags = gen_lck_flags(ob);
+	oldw = dw->weight;
+
 	wpaint_blend(wp, dw, uw, alpha, paintweight, flip);
+
+	/* Jason was here */
+	/* you are not allowed to go to or from zero if the group is locked */
+	if(flags && flags[dw->def_nr]) {
+		if(oldw == 0 || dw->weight == 0){
+			dw->weight = oldw;
+		}
+	}
+
 	do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);
 
 	if(me->editflag & ME_EDIT_MIRROR_X) {	/* x mirror painting */
@@ -1065,6 +1149,13 @@
 			do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap);
 		}
 	}
+	/* Jason was here */
+	if(flags){
+		if(flags[dw->def_nr]) {
+			fix_weight_ratios(me, dw, oldw);
+		}
+		MEM_freeN(flags);
+	}
 }
 
 
@@ -1229,7 +1320,7 @@
 	struct WPaintData *wpd;
 	Mesh *me;
 	float mat[4][4], imat[4][4];
-	
+
 	if(scene->obedit) return OPERATOR_CANCELLED;
 	
 	me= get_mesh(ob);
@@ -1240,7 +1331,8 @@
 		ED_vgroup_data_create(&me->id);
 		WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
 	}
-	
+
+
 	/* make mode data storage */
 	wpd= MEM_callocN(sizeof(struct WPaintData), "WPaintData");
 	paint_stroke_set_mode_data(stroke, wpd);
@@ -1320,7 +1412,7 @@
 				wpd->vgroup_mirror= actdef;
 		}
 	}
-	
+
 	return 1;
 }
 

Modified: branches/soc-2011-radish/source/blender/makesdna/DNA_object_types.h
===================================================================
--- branches/soc-2011-radish/source/blender/makesdna/DNA_object_types.h	2011-05-27 17:59:48 UTC (rev 36953)
+++ branches/soc-2011-radish/source/blender/makesdna/DNA_object_types.h	2011-05-27 19:13:54 UTC (rev 36954)
@@ -62,6 +62,8 @@
 typedef struct bDeformGroup {
 	struct bDeformGroup *next, *prev;
 	char name[32];
+	/* Jason was here: need this flag for locking weights */
+	char flag, pad[7];
 } bDeformGroup;
 #define MAX_VGROUP_NAME 32
 

Modified: branches/soc-2011-radish/source/blender/makesrna/intern/rna_object.c
===================================================================
--- branches/soc-2011-radish/source/blender/makesrna/intern/rna_object.c	2011-05-27 17:59:48 UTC (rev 36953)
+++ branches/soc-2011-radish/source/blender/makesrna/intern/rna_object.c	2011-05-27 19:13:54 UTC (rev 36954)
@@ -1237,6 +1237,11 @@
 	RNA_def_property_ui_text(prop, "Name", "Vertex group name");
 	RNA_def_struct_name_property(srna, prop);
 	RNA_def_property_update(prop, NC_GEOM|ND_DATA|NA_RENAME, "rna_Object_internal_update_data"); /* update data because modifiers may use [#24761] */
+	/* Jason was here */
+	prop= RNA_def_property(srna, "flag", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_ui_text(prop, "", "Maintain the relative weights for the group");
+	RNA_def_property_boolean_sdna(prop, "bDeformGroup", "flag", 0);
+	RNA_def_property_update(prop, NC_GEOM|ND_DATA|NA_RENAME, "rna_Object_internal_update_data"); /* update data because modifiers may use [#24761] */
 
 	prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);




More information about the Bf-blender-cvs mailing list