[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34009] trunk/blender/source/blender/ blenkernel: Splitting quad into triangles and merging triangles into quad should

Sergey Sharybin g.ulairi at gmail.com
Sun Jan 2 18:38:22 CET 2011


Revision: 34009
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34009
Author:   nazgul
Date:     2011-01-02 18:38:22 +0100 (Sun, 02 Jan 2011)

Log Message:
-----------
Splitting quad into triangles and merging triangles into quad should
work correct with sculpting data now.

Joining two triangles could give incorrect sculpting result for
special topologies, but it's that case that can't be nicely handled
with our layers architecture.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_multires.h
    trunk/blender/source/blender/blenkernel/intern/customdata.c
    trunk/blender/source/blender/blenkernel/intern/multires.c

Modified: trunk/blender/source/blender/blenkernel/BKE_multires.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_multires.h	2011-01-02 17:09:39 UTC (rev 34008)
+++ trunk/blender/source/blender/blenkernel/BKE_multires.h	2011-01-02 17:38:22 UTC (rev 34009)
@@ -87,6 +87,7 @@
 int mdisp_rot_face_to_crn(int corners, int face_side, float u, float v, float *x, float *y);
 void mdisp_apply_weight(int S, int corners, int x, int y, int face_side, float crn_weight[4][2], float *u_r, float *v_r);
 void mdisp_flip_disp(int S, int corners, float axis_x[2], float axis_y[2], float disp[3]);
+void mdisp_join_tris(struct MDisps *dst, struct MDisps *tri1, struct MDisps *tri2);
 
 #endif
 

Modified: trunk/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata.c	2011-01-02 17:09:39 UTC (rev 34008)
+++ trunk/blender/source/blender/blenkernel/intern/customdata.c	2011-01-02 17:38:22 UTC (rev 34009)
@@ -441,16 +441,55 @@
 	int i, x, y;
 	int side, S, dst_corners, src_corners;
 	float crn_weight[4][2];
-	float (*sw)[4] = NULL;
+	float (*sw)[4] = (void*)sub_weights;
 	float (*disps)[3], (*out)[3];
 
 	s = sources[0];
 	dst_corners = multires_mdisp_corners(d);
 	src_corners = multires_mdisp_corners(s);
 
-	/* XXX: For now, some restrictions on the input
-	        should be implemented to allow quad<->tris face conversion */
-	if(count != 1 || !sub_weights || dst_corners != src_corners) {
+	if(sub_weights && count == 2 && src_corners == 3) {
+		src_corners = multires_mdisp_corners(sources[1]);
+
+		/* special case -- converting two triangles to quad */
+		if(src_corners == 3 && dst_corners == 4) {
+			MDisps tris[2];
+			int vindex[4] = {0};
+
+			S = 0;
+			for(i = 0; i < 2; i++)
+				for(y = 0; y < 4; y++)
+					for(x = 0; x < 4; x++)
+						if(sw[x+i*4][y])
+							vindex[x] = y;
+
+			for(i = 0; i < 2; i++) {
+				float sw[4][4] = {{0}};
+				int a = 7 & ~(1 << vindex[i*2] | 1 << vindex[i*2+1]);
+
+				sw[0][vindex[i*2+1]] = 1;
+				sw[1][vindex[i*2]] = 1;
+
+				for(x = 0; x < 3; x++)
+					if(a & (1 << x))
+						sw[2][x] = 1;
+
+				tris[i] = *((MDisps*)sources[i]);
+				tris[i].disps = MEM_dupallocN(tris[i].disps);
+				layerInterp_mdisps(&sources[i], NULL, (float*)sw, 1, &tris[i]);
+			}
+
+			mdisp_join_tris(d, &tris[0], &tris[1]);
+
+			for(i = 0; i < 2; i++)
+				MEM_freeN(tris[i].disps);
+
+			return;
+		}
+	}
+
+	/* For now, some restrictions on the input */
+	if(count != 1 || !sub_weights) {
 		for(i = 0; i < d->totdisp; ++i)
 			zero_v3(d->disps[i]);
 

Modified: trunk/blender/source/blender/blenkernel/intern/multires.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/multires.c	2011-01-02 17:09:39 UTC (rev 34008)
+++ trunk/blender/source/blender/blenkernel/intern/multires.c	2011-01-02 17:38:22 UTC (rev 34009)
@@ -1981,3 +1981,47 @@
 		disp[1] = 0;
 	}
 }
+
+/* Join two triangular displacements into one quad
+	 Corners mapping:
+	 2 -------- 3
+	 | \   tri2 |
+	 |    \     |
+	 | tri1  \  |
+	 0 -------- 1 */
+void mdisp_join_tris(MDisps *dst, MDisps *tri1, MDisps *tri2)
+{
+	int side, st;
+	int S, x, y, crn;
+	float face_u, face_v, crn_u, crn_v;
+	float (*out)[3];
+	MDisps *src;
+
+	if(dst->disps)
+		MEM_freeN(dst->disps);
+
+	side = sqrt(tri1->totdisp / 3);
+	st = (side<<1)-1;
+
+	dst->totdisp = 4 * side * side;
+	out = dst->disps = MEM_callocN(3*dst->totdisp*sizeof(float), "join disps");
+
+	for(S = 0; S < 4; S++)
+		for(y = 0; y < side; ++y)
+			for(x = 0; x < side; ++x, ++out) {
+				mdisp_rot_crn_to_face(S, 4, st, x, y, &face_u, &face_v);
+				face_u = st - 1 - face_u;
+
+				if(face_v > face_u) {
+					src = tri2;
+					face_u = st - 1 - face_u;
+					face_v = st - 1 - face_v;
+				} else src = tri1;
+
+				crn = mdisp_rot_face_to_crn(3, st, face_u, face_v, &crn_u, &crn_v);
+
+				old_mdisps_bilinear((*out), &src->disps[crn*side*side], side, crn_u, crn_v);
+				(*out)[0] = 0;
+				(*out)[1] = 0;
+			}
+}





More information about the Bf-blender-cvs mailing list