[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42633] trunk/blender/source/blender: vertex group changes,

Campbell Barton ideasman42 at gmail.com
Wed Dec 14 22:08:22 CET 2011


Revision: 42633
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42633
Author:   campbellbarton
Date:     2011-12-14 21:08:08 +0000 (Wed, 14 Dec 2011)
Log Message:
-----------
vertex group changes,

use more api functions more (some vertex group editing functions were copied about), also make some functions int oapi calls.

- remove defgroup_find_index(), use BLI_findlink instead since they both work the same way.
- move static function getNearestPointOnPlane() to BLI_math api function closest_to_plane_v3()
- ED_vgroup_give_parray() added option to return an array where unselected verts are NULL (simplifies code & works for lattice when it didn't before).
- more consistant error checking of ob->actdef.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_deform.h
    trunk/blender/source/blender/blenkernel/intern/deform.c
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/object/object_vgroup.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
    trunk/blender/source/blender/makesrna/intern/rna_object_api.c

Modified: trunk/blender/source/blender/blenkernel/BKE_deform.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_deform.h	2011-12-14 19:12:06 UTC (rev 42632)
+++ trunk/blender/source/blender/blenkernel/BKE_deform.h	2011-12-14 21:08:08 UTC (rev 42633)
@@ -43,7 +43,6 @@
 void				 defgroup_copy_list(struct ListBase *lb1, struct ListBase *lb2);
 struct bDeformGroup *defgroup_duplicate(struct bDeformGroup *ingroup);
 struct bDeformGroup *defgroup_find_name(struct Object *ob, const char *name);
-int					 defgroup_find_index(struct Object *ob, struct bDeformGroup *dg);
 int					*defgroup_flip_map(struct Object *ob, int *flip_map_len, int use_default);
 int					*defgroup_flip_map_single(struct Object *ob, int *flip_map_len, int use_default, int defgroup);
 int					 defgroup_flip_index(struct Object *ob, int index, int use_default);
@@ -66,6 +65,7 @@
 void defvert_remap (struct MDeformVert *dvert, int *map, const int map_len);
 void defvert_flip(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len);
 void defvert_normalize(struct MDeformVert *dvert);
+void defvert_normalize_lock(struct MDeformVert *dvert, const int def_nr_lock);
 
 /* utility function, note that 32 chars is the maximum string length since its only
  * used with defgroups currently */

Modified: trunk/blender/source/blender/blenkernel/intern/deform.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/deform.c	2011-12-14 19:12:06 UTC (rev 42632)
+++ trunk/blender/source/blender/blenkernel/intern/deform.c	2011-12-14 21:08:08 UTC (rev 42633)
@@ -163,37 +163,89 @@
 /* be sure all flip_map values are valid */
 void defvert_remap(MDeformVert *dvert, int *map, const int map_len)
 {
-	MDeformWeight *dw;
-	int i;
-	for (i=0, dw=dvert->dw; i<dvert->totweight; i++, dw++) {
+	MDeformWeight *dw= dvert->dw;
+	unsigned int i;
+	for (i= dvert->totweight; i != 0; i--, dw++) {
 		if (dw->def_nr < map_len) {
 			dw->def_nr= map[dw->def_nr];
+
+			/* just incase */
+			BLI_assert(dw->def_nr >= 0);
 		}
 	}
 }
 
 void defvert_normalize(MDeformVert *dvert)
 {
-	if (dvert->totweight<=0) {
+	if (dvert->totweight <= 0) {
 		/* nothing */
 	}
 	else if (dvert->totweight==1) {
 		dvert->dw[0].weight= 1.0f;
 	}
 	else {
-		int i;
-		float tot= 0.0f;
 		MDeformWeight *dw;
-		for (i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++)
-			tot += dw->weight;
+		unsigned int i;
+		float tot_weight= 0.0f;
 
-		if (tot > 0.0f) {
-			for (i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++)
-				dw->weight /= tot;
+		for (i= dvert->totweight, dw= dvert->dw; i != 0; i--, dw++) {
+			tot_weight += dw->weight;
 		}
+
+		if (tot_weight > 0.0f) {
+			float scalar= 1.0f / tot_weight;
+			for (i= dvert->totweight, dw= dvert->dw; i != 0; i--, dw++) {
+				dw->weight *= scalar;
+
+				/* incase of division errors with very low weights */
+				CLAMP(dw->weight, 0.0f, 1.0f);
+			}
+		}
 	}
 }
 
+void defvert_normalize_lock(MDeformVert *dvert, const int def_nr_lock)
+{
+	if (dvert->totweight <= 0) {
+		/* nothing */
+	}
+	else if (dvert->totweight==1) {
+		dvert->dw[0].weight= 1.0f;
+	}
+	else {
+		MDeformWeight *dw_lock;
+		MDeformWeight *dw;
+		unsigned int i;
+		float tot_weight= 0.0f;
+		float lock_iweight= 1.0f;
+
+		for (i= dvert->totweight, dw= dvert->dw; i != 0; i--, dw++) {
+			if(dw->def_nr != def_nr_lock) {
+				tot_weight += dw->weight;
+			}
+			else {
+				dw_lock= dw;
+				lock_iweight = (1.0f - dw_lock->weight);
+				CLAMP(lock_iweight, 0.0f, 1.0f);
+			}
+		}
+
+		if (tot_weight > 0.0f) {
+			/* paranoid, should be 1.0 but incase of float error clamp anyway */
+
+			float scalar= (1.0f / tot_weight) * lock_iweight;
+			for (i= dvert->totweight, dw= dvert->dw; i != 0; i--, dw++) {
+				if(dw != dw_lock) {
+					dw->weight *= scalar;
+
+					/* incase of division errors with very low weights */
+					CLAMP(dw->weight, 0.0f, 1.0f);
+				}
+			}
+		}
+	}
+}
+
 void defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_len)
 {
 	MDeformWeight *dw;
@@ -227,7 +279,7 @@
 int defgroup_name_index(Object *ob, const char *name)
 {
 	/* Return the location of the named deform group within the list of
-	 * deform groups. This function is a combination of defgroup_find_index and
+	 * deform groups. This function is a combination of BLI_findlink and
 	 * defgroup_find_name. The other two could be called instead, but that
 	 * require looping over the vertexgroups twice.
 	 */
@@ -244,46 +296,6 @@
 	return -1;
 }
 
-int defgroup_find_index(Object *ob, bDeformGroup *dg)
-{
-	/* Fetch the location of this deform group
-	 * within the linked list of deform groups.
-	 * (this number is stored in the deform
-	 * weights of the deform verts to link them
-	 * to this deform group).
-	 *
-	 * note: this is zero based, ob->actdef starts at 1.
-	 */
-
-	bDeformGroup *eg;
-	int def_nr;
-
-	eg = ob->defbase.first;
-	def_nr = 0;
-
-	/* loop through all deform groups */
-	while (eg != NULL) {
-
-		/* if the current deform group is
-		 * the one we are after, return
-		 * def_nr
-		 */
-		if (eg == dg) {
-			break;
-		}
-		++def_nr;
-		eg = eg->next;
-	}
-
-	/* if there was no deform group found then
-	 * return -1 (should set up a nice symbolic
-	 * constant for this)
-	 */
-	if (eg == NULL) return -1;
-
-	return def_nr;
-}
-
 /* note, must be freed */
 int *defgroup_flip_map(Object *ob, int *flip_map_len, int use_default)
 {
@@ -540,9 +552,9 @@
 {
 	if (dvert && defgroup >= 0) {
 		MDeformWeight *dw = dvert->dw;
-		int i;
+		unsigned int i;
 
-		for (i=dvert->totweight; i>0; i--, dw++) {
+		for (i= dvert->totweight; i != 0; i--, dw++) {
 			if (dw->def_nr == defgroup) {
 				return dw;
 			}
@@ -626,7 +638,7 @@
 		 */
 		if (dvert->totweight) {
 			dw_new = MEM_mallocN(sizeof(MDeformWeight)*(dvert->totweight), __func__);
-			if (dvert->dw){
+			if (dvert->dw) {
 				memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*i);
 				memcpy(dw_new+i, dvert->dw+i+1, sizeof(MDeformWeight)*(dvert->totweight-i));
 				MEM_freeN(dvert->dw);

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2011-12-14 19:12:06 UTC (rev 42632)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2011-12-14 21:08:08 UTC (rev 42633)
@@ -65,8 +65,10 @@
 float dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]);
 float closest_to_line_v3(float r[3], const float p[3], const float l1[3], const float l2[3]);
 float closest_to_line_v2(float r[2], const float p[2], const float l1[2], const float l2[2]);
-void closest_to_line_segment_v3(float r[3], const float p[3], const float l1[3], const float l2[3]);
+void  closest_to_line_segment_v3(float r[3], const float p[3], const float l1[3], const float l2[3]);
+void  closest_to_plane_v3(float r[3], const float plane_co[3], const float plane_no_unit[3], const float pt[3]);
 
+
 float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3]);
 float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2]);
 

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2011-12-14 19:12:06 UTC (rev 42632)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2011-12-14 21:08:08 UTC (rev 42633)
@@ -209,35 +209,56 @@
 }
 
 /* point closest to v1 on line v2-v3 in 2D */
-void closest_to_line_segment_v2(float closest[2], const float p[2], const float l1[2], const float l2[2])
+void closest_to_line_segment_v2(float close_r[2], const float p[2], const float l1[2], const float l2[2])
 {
 	float lambda, cp[2];
 
 	lambda= closest_to_line_v2(cp,p, l1, l2);
 
 	if(lambda <= 0.0f)
-		copy_v2_v2(closest, l1);
+		copy_v2_v2(close_r, l1);
 	else if(lambda >= 1.0f)
-		copy_v2_v2(closest, l2);
+		copy_v2_v2(close_r, l2);
 	else
-		copy_v2_v2(closest, cp);
+		copy_v2_v2(close_r, cp);
 }
 
 /* point closest to v1 on line v2-v3 in 3D */
-void closest_to_line_segment_v3(float closest[3], const float v1[3], const float v2[3], const float v3[3])
+void closest_to_line_segment_v3(float close_r[3], const float v1[3], const float v2[3], const float v3[3])
 {
 	float lambda, cp[3];
 
 	lambda= closest_to_line_v3(cp,v1, v2, v3);
 
 	if(lambda <= 0.0f)
-		copy_v3_v3(closest, v2);
+		copy_v3_v3(close_r, v2);
 	else if(lambda >= 1.0f)
-		copy_v3_v3(closest, v3);
+		copy_v3_v3(close_r, v3);
 	else
-		copy_v3_v3(closest, cp);
+		copy_v3_v3(close_r, cp);
 }
 
+/* find the closest point on a plane to another point and store it in close_r
+ * close_r:       return coordinate
+ * plane_co:      a point on the plane
+ * plane_no_unit: the plane's normal, and d is the last number in the plane equation 0 = ax + by + cz + d
+ * pt:            the point that you want the nearest of
+ */
+
+// const float norm[3], const float coord[3], const float point[3], float dst_r[3]
+void closest_to_plane_v3(float close_r[3], const float plane_co[3], const float plane_no_unit[3], const float pt[3])
+{
+	float temp[3];
+	float dotprod;
+
+	sub_v3_v3v3(temp, pt, plane_co);
+	dotprod= dot_v3v3(temp, plane_no_unit);
+
+	close_r[0] = pt[0] - (plane_no_unit[0] * dotprod);
+	close_r[1] = pt[1] - (plane_no_unit[1] * dotprod);
+	close_r[2] = pt[2] - (plane_no_unit[2] * dotprod);
+}
+
 /* signed distance from the point to the plane in 3D */
 float dist_to_plane_normalized_v3(const float p[3], const float plane_co[3], const float plane_no_unit[3])
 {

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2011-12-14 19:12:06 UTC (rev 42632)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2011-12-14 21:08:08 UTC (rev 42633)
@@ -8725,9 +8725,9 @@
 			}
 			if(ob->soft && ob->soft->vertgroup==0) {
 				bDeformGroup *locGroup = defgroup_find_name(ob, "SOFTGOAL");
-				if(locGroup){
+				if (locGroup) {
 					/* retrieve index for that group */
-					ob->soft->vertgroup =  1 + defgroup_find_index(ob, locGroup); 
+					ob->soft->vertgroup =  1 + BLI_findindex(&ob->defbase, locGroup);
 				}
 			}
 		}

Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list