[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44302] trunk/blender/source/blender/bmesh /intern: Improved displacement flipping algorithm to work properly in cases when target grid isn 't orthogonal.

Sergey Sharybin sergey.vfx at gmail.com
Tue Feb 21 18:23:33 CET 2012


Revision: 44302
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44302
Author:   nazgul
Date:     2012-02-21 17:23:32 +0000 (Tue, 21 Feb 2012)
Log Message:
-----------
Improved displacement flipping algorithm to work properly in cases when target grid isn't orthogonal.

Subdivision of face now works pretty smooth, only producing minor unwanted displacement on the along edges.

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

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_interp.c	2012-02-21 17:23:03 UTC (rev 44301)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_interp.c	2012-02-21 17:23:32 UTC (rev 44302)
@@ -551,26 +551,45 @@
 	return 1;
 }
 
+static float bmesh_loop_flip_equotion(float mat[2][2], float b[2], float target_axis_x[3], float target_axis_y[3],
+                                      float coord[3], int i, int j)
+{
+	mat[0][0] = target_axis_x[i];
+	mat[0][1] = target_axis_y[i];
+	mat[1][0] = target_axis_x[j];
+	mat[1][1] = target_axis_y[j];
+	b[0] = coord[i];
+	b[1] = coord[j];
+
+	return mat[0][0]*mat[1][1] - mat[0][1]*mat[1][0];
+}
+
 static void bmesh_loop_flip_disp(float source_axis_x[3], float source_axis_y[3],
                                  float target_axis_x[3], float target_axis_y[3], float disp[3])
 {
 	float vx[3], vy[3], coord[3];
+	float n[3], vec[3];
+	float b[2], mat[2][2], d;
 
 	mul_v3_v3fl(vx, source_axis_x, disp[0]);
 	mul_v3_v3fl(vy, source_axis_y, disp[1]);
 	add_v3_v3v3(coord, vx, vy);
 
-	project_v3_v3v3(vx, coord, target_axis_x);
-	project_v3_v3v3(vy, coord, target_axis_y);
+	/* project displacement from source grid plane onto target grid plane */
+	cross_v3_v3v3(n, target_axis_x, target_axis_y);
+	project_v3_v3v3(vec, coord, n);
+	sub_v3_v3v3(coord, coord, vec);
 
-	disp[0] = len_v3(vx);
-	disp[1] = len_v3(vy);
+	d = bmesh_loop_flip_equotion(mat, b, target_axis_x, target_axis_y, coord, 0, 1);
 
-	if(dot_v3v3(vx, target_axis_x) < 0)
-		disp[0] = -disp[0];
+	if (fabsf(d) < 1e-4) {
+		d = bmesh_loop_flip_equotion(mat, b, target_axis_x, target_axis_y, coord, 0, 2);
+		if (fabsf(d) < 1e-4)
+			d = bmesh_loop_flip_equotion(mat, b, target_axis_x, target_axis_y, coord, 1, 2);
+	}
 
-	if(dot_v3v3(vy, target_axis_y) < 0)
-		disp[1] = -disp[1];
+	disp[0] = (b[0]*mat[1][1] - mat[0][1]*b[1]) / d;
+	disp[1] = (mat[0][0]*b[1] - b[0]*mat[1][0]) / d;
 }
 
 static void bmesh_loop_interp_mdisps(BMesh *bm, BMLoop *target, BMFace *source)

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_mods.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_mods.c	2012-02-21 17:23:03 UTC (rev 44301)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_mods.c	2012-02-21 17:23:32 UTC (rev 44302)
@@ -377,8 +377,11 @@
 
 			BM_face_kill(bm, of);
 
+#if 0
+			/* BM_face_multires_bounds_smooth doesn't flip displacement correct */
 			BM_face_multires_bounds_smooth(bm, f);
 			BM_face_multires_bounds_smooth(bm, nf);
+#endif
 		}
 	}
 




More information about the Bf-blender-cvs mailing list