[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55864] trunk/blender/source/blender/bmesh /intern/bmesh_interp.c: improve bmesh face interpolation - transforming verts into the faces plane rather then using dominant axis or calculating in 3d with interp_weights_poly_v3 ().

Campbell Barton ideasman42 at gmail.com
Sun Apr 7 04:10:16 CEST 2013


Revision: 55864
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55864
Author:   campbellbarton
Date:     2013-04-07 02:10:15 +0000 (Sun, 07 Apr 2013)
Log Message:
-----------
improve bmesh face interpolation - transforming verts into the faces plane rather then using dominant axis or calculating in 3d with interp_weights_poly_v3().

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_interp.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_interp.c	2013-04-07 01:38:03 UTC (rev 55863)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_interp.c	2013-04-07 02:10:15 UTC (rev 55864)
@@ -173,27 +173,32 @@
 	BMLoop *l_first;
 
 	void **blocks   = BLI_array_alloca(blocks, source->len);
-	float (*cos)[3] = BLI_array_alloca(cos,    source->len);
+	float (*cos_2d)[2] = BLI_array_alloca(cos_2d, source->len);
 	float *w        = BLI_array_alloca(w,      source->len);
+	float axis_mat[3][3];  /* use normal to transform into 2d xy coords */
+	float co[2];
 	int i;
-	
+
+	/* convert the 3d coords into 2d for projection */
+	axis_dominant_v3_to_m3(axis_mat, source->no);
+
 	BM_elem_attrs_copy(bm, bm, source, target);
 
 	i = 0;
 	l_iter = l_first = BM_FACE_FIRST_LOOP(source);
 	do {
-		copy_v3_v3(cos[i], l_iter->v->co);
+		mul_v2_m3v3(cos_2d[i], axis_mat, l_iter->v->co);
 		blocks[i] = l_iter->head.data;
-		i++;
-	} while ((l_iter = l_iter->next) != l_first);
+	} while (i++, (l_iter = l_iter->next) != l_first);
 
+	/* interpolate */
 	i = 0;
 	l_iter = l_first = BM_FACE_FIRST_LOOP(target);
 	do {
-		interp_weights_poly_v3(w, cos, source->len, l_iter->v->co);
+		mul_v2_m3v3(co, axis_mat, l_iter->v->co);
+		interp_weights_poly_v2(w, cos_2d, source->len, co);
 		CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, source->len, l_iter->head.data);
-		i++;
-	} while ((l_iter = l_iter->next) != l_first);
+	} while (i++, (l_iter = l_iter->next) != l_first);
 }
 
 /**
@@ -604,45 +609,32 @@
 	BMLoop *l_iter;
 	BMLoop *l_first;
 	void **vblocks  = do_vertex ? BLI_array_alloca(vblocks, source->len) : NULL;
-	void **blocks   = BLI_array_alloca(blocks,  source->len);
-	float (*cos)[3] = BLI_array_alloca(cos,     source->len);
-	float (*cos_2d)[2] = BLI_array_alloca(cos_2d,     source->len);
-	float *w        = BLI_array_alloca(w,       source->len);
+	void **blocks   = BLI_array_alloca(blocks, source->len);
+	float (*cos_2d)[2] = BLI_array_alloca(cos_2d, source->len);
+	float *w        = BLI_array_alloca(w, source->len);
+	float axis_mat[3][3];  /* use normal to transform into 2d xy coords */
 	float co[2];
-	int i, ax, ay;
+	int i;
 
+	/* convert the 3d coords into 2d for projection */
+	axis_dominant_v3_to_m3(axis_mat, source->no);
+
 	BM_elem_attrs_copy(bm, bm, source, target->f);
 
 	i = 0;
 	l_iter = l_first = BM_FACE_FIRST_LOOP(source);
 	do {
-		copy_v3_v3(cos[i], l_iter->v->co);
-
-		w[i] = 0.0f;
+		mul_v2_m3v3(cos_2d[i], axis_mat, l_iter->v->co);
 		blocks[i] = l_iter->head.data;
 
 		if (do_vertex) {
 			vblocks[i] = l_iter->v->head.data;
 		}
-		i++;
+	} while (i++, (l_iter = l_iter->next) != l_first);
 
-	} while ((l_iter = l_iter->next) != l_first);
+	mul_v2_m3v3(co, axis_mat, target->v->co);
 
-	/* find best projection of face XY, XZ or YZ: barycentric weights of
-	 * the 2d projected coords are the same and faster to compute */
-
-	axis_dominant_v3(&ax, &ay, source->no);
-
-	for (i = 0; i < source->len; i++) {
-		cos_2d[i][0] = cos[i][ax];
-		cos_2d[i][1] = cos[i][ay];
-	}
-
-
 	/* interpolate */
-	co[0] = target->v->co[ax];
-	co[1] = target->v->co[ay];
-
 	interp_weights_poly_v2(w, cos_2d, source->len, co);
 	CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, source->len, target->head.data);
 	if (do_vertex) {
@@ -662,22 +654,26 @@
 	BMLoop *l_iter;
 	BMLoop *l_first;
 	void **blocks   = BLI_array_alloca(blocks, source->len);
-	float (*cos)[3] = BLI_array_alloca(cos,    source->len);
+	float (*cos_2d)[2] = BLI_array_alloca(cos_2d, source->len);
 	float *w        = BLI_array_alloca(w,      source->len);
+	float axis_mat[3][3];  /* use normal to transform into 2d xy coords */
+	float co[2];
 	int i;
 
+	/* convert the 3d coords into 2d for projection */
+	axis_dominant_v3_to_m3(axis_mat, source->no);
+
 	i = 0;
 	l_iter = l_first = BM_FACE_FIRST_LOOP(source);
 	do {
-		copy_v3_v3(cos[i], l_iter->v->co);
-
-		w[i] = 0.0f;
+		mul_v2_m3v3(cos_2d[i], axis_mat, l_iter->v->co);
 		blocks[i] = l_iter->v->head.data;
-		i++;
-	} while ((l_iter = l_iter->next) != l_first);
+	} while (i++, (l_iter = l_iter->next) != l_first);
 
+	mul_v2_m3v3(co, axis_mat, v->co);
+
 	/* interpolate */
-	interp_weights_poly_v3(w, cos, source->len, v->co);
+	interp_weights_poly_v2(w, cos_2d, source->len, co);
 	CustomData_bmesh_interp(&bm->vdata, blocks, w, NULL, source->len, v->head.data);
 }
 




More information about the Bf-blender-cvs mailing list