[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56549] trunk/blender/source/blender: add matrix multiply for projection that outputs 2d values.

Campbell Barton ideasman42 at gmail.com
Wed May 8 14:55:36 CEST 2013


Revision: 56549
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56549
Author:   campbellbarton
Date:     2013-05-08 12:55:36 +0000 (Wed, 08 May 2013)
Log Message:
-----------
add matrix multiply for projection that outputs 2d values.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/mesh.c
    trunk/blender/source/blender/blenlib/BLI_math_matrix.h
    trunk/blender/source/blender/blenlib/intern/math_matrix.c
    trunk/blender/source/blender/modifiers/intern/MOD_uvproject.c

Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c	2013-05-08 12:55:23 UTC (rev 56548)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c	2013-05-08 12:55:36 UTC (rev 56549)
@@ -118,8 +118,9 @@
 
 /* thresh is threshold for comparing vertices, uvs, vertex colors,
  * weights, etc.*/
-static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, float thresh)
+static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, const float thresh)
 {
+	const float thresh_sq = thresh * thresh;
 	CustomDataLayer *l1, *l2;
 	int i, i1 = 0, i2 = 0, tot, j;
 	
@@ -225,7 +226,7 @@
 			int ltot = m1->totloop;
 		
 			for (j = 0; j < ltot; j++, lp1++, lp2++) {
-				if (len_v2v2(lp1->uv, lp2->uv) > thresh)
+				if (len_squared_v2v2(lp1->uv, lp2->uv) > thresh_sq)
 					return MESHCMP_LOOPUVMISMATCH;
 			}
 		}

Modified: trunk/blender/source/blender/blenlib/BLI_math_matrix.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_matrix.h	2013-05-08 12:55:23 UTC (rev 56548)
+++ trunk/blender/source/blender/blenlib/BLI_math_matrix.h	2013-05-08 12:55:36 UTC (rev 56549)
@@ -88,11 +88,13 @@
 
 void mul_m4_v3(float M[4][4], float r[3]);
 void mul_v3_m4v3(float r[3], float M[4][4], const float v[3]);
+void mul_v2_m4v3(float r[2], float M[4][4], const float v[3]);
 void mul_v2_m2v2(float r[2], float M[2][2], const float v[2]);
 void mul_mat3_m4_v3(float M[4][4], float r[3]);
 void mul_m4_v4(float M[4][4], float r[4]);
 void mul_v4_m4v4(float r[4], float M[4][4], const float v[4]);
 void mul_project_m4_v3(float M[4][4], float vec[3]);
+void mul_v2_project_m4_v3(float r[2], float M[4][4], const float vec[3]);
 
 void mul_m3_v3(float M[3][3], float r[3]);
 void mul_v3_m3v3(float r[3], float M[3][3], const float a[3]);

Modified: trunk/blender/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_matrix.c	2013-05-08 12:55:23 UTC (rev 56548)
+++ trunk/blender/source/blender/blenlib/intern/math_matrix.c	2013-05-08 12:55:36 UTC (rev 56549)
@@ -344,6 +344,15 @@
 	r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2];
 }
 
+void mul_v2_m4v3(float r[2], float mat[4][4], const float vec[3])
+{
+	float x;
+
+	x = vec[0];
+	r[0] = x * mat[0][0] + vec[1] * mat[1][0] + mat[2][0] * vec[2] + mat[3][0];
+	r[1] = x * mat[0][1] + vec[1] * mat[1][1] + mat[2][1] * vec[2] + mat[3][1];
+}
+
 void mul_v2_m2v2(float r[2], float mat[2][2], const float vec[2])
 {
 	float x;
@@ -375,6 +384,15 @@
 	vec[2] /= w;
 }
 
+void mul_v2_project_m4_v3(float r[2], float mat[4][4], const float vec[3])
+{
+	const float w = mul_project_m4_v3_zfac(mat, vec);
+	mul_v2_m4v3(r, mat, vec);
+
+	r[0] /= w;
+	r[1] /= w;
+}
+
 void mul_v4_m4v4(float r[4], float mat[4][4], const float v[4])
 {
 	float x, y, z;

Modified: trunk/blender/source/blender/modifiers/intern/MOD_uvproject.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_uvproject.c	2013-05-08 12:55:23 UTC (rev 56548)
+++ trunk/blender/source/blender/modifiers/intern/MOD_uvproject.c	2013-05-08 12:55:36 UTC (rev 56549)
@@ -321,12 +321,7 @@
 					do {
 						unsigned int lidx = mp->loopstart + fidx;
 						unsigned int vidx = mloop[lidx].v;
-						float tco[3];
-
-						copy_v3_v3(tco, coords[vidx]);
-						mul_project_m4_v3(best_projector->projmat, tco);
-						copy_v2_v2(mloop_uv[lidx].uv, tco);
-
+						mul_v2_project_m4_v3(mloop_uv[lidx].uv, best_projector->projmat, coords[vidx]);
 					} while (fidx--);
 				}
 			}




More information about the Bf-blender-cvs mailing list