[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60121] trunk/blender/source/blender/ editors/sculpt_paint/sculpt.c: Sculpting:

Antony Riakiotakis kalast at gmail.com
Sat Sep 14 01:21:36 CEST 2013


Revision: 60121
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60121
Author:   psy-fi
Date:     2013-09-13 23:21:35 +0000 (Fri, 13 Sep 2013)
Log Message:
-----------
Sculpting:

Modify calculation of sculpt plane to only take into account forward
facing vertices. This will solve cases where sculpting on a volume with
the two sides of the mesh inside the brush radius could move the sculpt
plane inside the mesh volume.

To completely fix the issue where the mesh would "stick" the two sides
of the mesh together on the sculpt plane (for instance for clay strip
brushes), user should enable "front face only". Perhaps some brushes,
like clay strips should enforce this and not present the option in the
first place.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c

Modified: trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-09-13 23:13:49 UTC (rev 60120)
+++ trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-09-13 23:21:35 UTC (rev 60121)
@@ -1078,8 +1078,9 @@
 
 static void calc_area_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **nodes, int totnode)
 {
+	float out_flip[3] = {0.0f, 0.0f, 0.0f};
+
 	SculptSession *ss = ob->sculpt;
-	float out_flip[3] = {0.0f, 0.0f, 0.0f};
 	int n, original;
 
 	/* Grab brush requires to test on original data (see r33888 and
@@ -2279,8 +2280,11 @@
 	SculptSession *ss = ob->sculpt;
 	int n;
 
-	float count = 0;
+	int count = 0;
+	int count_flip = 0;
 
+	float fc_flip[3] = {0.0, 0.0, 0.0};
+
 	(void)sd; /* unused w/o openmp */
 
 	zero_v3(fc);
@@ -2291,7 +2295,9 @@
 		SculptBrushTest test;
 		SculptUndoNode *unode;
 		float private_fc[3] = {0.0f, 0.0f, 0.0f};
+		float private_fc_flip[3] = {0.0f, 0.0f, 0.0f};
 		int private_count = 0;
+		int private_count_flip = 0;
 
 		unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS);
 		sculpt_brush_test_init(ss, &test);
@@ -2300,8 +2306,19 @@
 			BKE_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE)
 			{
 				if (sculpt_brush_test_fast(&test, unode->co[vd.i])) {
-					add_v3_v3(private_fc, unode->co[vd.i]);
-					private_count++;
+					float fno[3];
+					float dot_result;
+
+					normal_short_to_float_v3(fno, unode->no[vd.i]);
+					dot_result = dot_v3v3(ss->cache->view_normal, fno);
+					if (dot_result > 0) {
+						add_v3_v3(private_fc, unode->co[vd.i]);
+						private_count++;
+					}
+					else {
+						add_v3_v3(private_fc_flip, unode->co[vd.i]);
+						private_count_flip++;
+					}
 				}
 			}
 			BKE_pbvh_vertex_iter_end;
@@ -2310,8 +2327,35 @@
 			BKE_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE)
 			{
 				if (sculpt_brush_test_fast(&test, vd.co)) {
-					add_v3_v3(private_fc, vd.co);
-					private_count++;
+					float dot_result;
+
+					/* for area normal */
+					if (vd.no) {
+						float fno[3];
+
+						normal_short_to_float_v3(fno, vd.no);
+						dot_result = dot_v3v3(ss->cache->view_normal, fno);
+
+						if (dot_result > 0) {
+							add_v3_v3(private_fc, vd.co);
+							private_count++;
+						}
+						else {
+							add_v3_v3(private_fc_flip, vd.co);
+							private_count_flip++;
+						}
+					}
+					else {
+						dot_result = dot_v3v3(ss->cache->view_normal, vd.fno);
+						if (dot_result > 0) {
+							add_v3_v3(private_fc, vd.co);
+							private_count++;
+						}
+						else {
+							add_v3_v3(private_fc_flip, vd.co);
+							private_count_flip++;
+						}
+					}
 				}
 			}
 			BKE_pbvh_vertex_iter_end;
@@ -2320,11 +2364,17 @@
 		#pragma omp critical
 		{
 			add_v3_v3(fc, private_fc);
+			add_v3_v3(fc_flip, private_fc_flip);
 			count += private_count;
+			count_flip += private_count_flip;
 		}
 	}
-
-	mul_v3_fl(fc, 1.0f / count);
+	if (count != 0)
+		mul_v3_fl(fc, 1.0f / count);
+	else if (count_flip != 0)
+		mul_v3_v3fl(fc, fc_flip, 1.0f / count_flip);
+	else
+		zero_v3(fc);
 }
 
 /* this calculates flatten center and area normal together, 
@@ -2338,9 +2388,11 @@
 
 	/* for area normal */
 	float out_flip[3] = {0.0f, 0.0f, 0.0f};
+	float fc_flip[3] = {0.0f, 0.0f, 0.0f};
 
 	/* for flatten center */
-	float count = 0;
+	int count = 0;
+	int count_flipped = 0;
 
 	(void)sd; /* unused w/o openmp */
 	
@@ -2358,7 +2410,9 @@
 		float private_an[3] = {0.0f, 0.0f, 0.0f};
 		float private_out_flip[3] = {0.0f, 0.0f, 0.0f};
 		float private_fc[3] = {0.0f, 0.0f, 0.0f};
+		float private_fc_flip[3] = {0.0f, 0.0f, 0.0f};
 		int private_count = 0;
+		int private_count_flip = 0;
 
 		unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS);
 		sculpt_brush_test_init(ss, &test);
@@ -2369,13 +2423,20 @@
 				if (sculpt_brush_test_fast(&test, unode->co[vd.i])) {
 					/* for area normal */
 					float fno[3];
+					float dot_result;
 
 					normal_short_to_float_v3(fno, unode->no[vd.i]);
-					add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno);
-
-					/* for flatten center */
-					add_v3_v3(private_fc, unode->co[vd.i]);
-					private_count++;
+					dot_result = dot_v3v3(ss->cache->view_normal, fno);
+					if (dot_result > 0) {
+						add_v3_v3(private_an, fno);
+						add_v3_v3(private_fc, unode->co[vd.i]);
+						private_count++;
+					}
+					else {
+						add_v3_v3(private_out_flip, fno);
+						add_v3_v3(private_fc_flip, unode->co[vd.i]);
+						private_count_flip++;
+					}
 				}
 			}
 			BKE_pbvh_vertex_iter_end;
@@ -2384,20 +2445,39 @@
 			BKE_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE)
 			{
 				if (sculpt_brush_test_fast(&test, vd.co)) {
+					float dot_result;
+
 					/* for area normal */
 					if (vd.no) {
 						float fno[3];
 
 						normal_short_to_float_v3(fno, vd.no);
-						add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno);
+						dot_result = dot_v3v3(ss->cache->view_normal, fno);
+
+						if (dot_result > 0) {
+							add_v3_v3(private_an, fno);
+							add_v3_v3(private_fc, vd.co);
+							private_count++;
+						}
+						else {
+							add_v3_v3(private_out_flip, fno);
+							add_v3_v3(private_fc_flip, vd.co);
+							private_count_flip++;
+						}
 					}
 					else {
-						add_norm_if(ss->cache->view_normal, private_an, private_out_flip, vd.fno);
+						dot_result = dot_v3v3(ss->cache->view_normal, vd.fno);
+						if (dot_result > 0) {
+							add_v3_v3(private_an, vd.fno);
+							add_v3_v3(private_fc, vd.co);
+							private_count++;
+						}
+						else {
+							add_v3_v3(private_out_flip, vd.fno);
+							add_v3_v3(private_fc_flip, vd.co);
+							private_count_flip++;
+						}
 					}
-
-					/* for flatten center */
-					add_v3_v3(private_fc, vd.co);
-					private_count++;
 				}
 			}
 			BKE_pbvh_vertex_iter_end;
@@ -2411,7 +2491,9 @@
 
 			/* for flatten center */
 			add_v3_v3(fc, private_fc);
+			add_v3_v3(fc_flip, private_fc);
 			count += private_count;
+			count_flipped += private_count_flip;
 		}
 	}
 
@@ -2422,12 +2504,12 @@
 	normalize_v3(an);
 
 	/* for flatten center */
-	if (count != 0) {
+	if (count != 0)
 		mul_v3_fl(fc, 1.0f / count);
-	}
-	else {
+	else if (count_flipped !=0 )
+		mul_v3_v3fl(fc, fc_flip, 1.0f / count_flipped);
+	else
 		zero_v3(fc);
-	}
 }
 
 static void calc_sculpt_plane(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float an[3], float fc[3])




More information about the Bf-blender-cvs mailing list