[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29202] branches/soc-2010-jwilkins: * symmetric sculpting now feathers the strength of brushes near symmetry planes (unfinished)

Jason Wilkins Jason.A.Wilkins at gmail.com
Fri Jun 4 01:52:57 CEST 2010


Revision: 29202
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29202
Author:   jwilkins
Date:     2010-06-04 01:52:56 +0200 (Fri, 04 Jun 2010)

Log Message:
-----------
* symmetric sculpting now feathers the strength of brushes near symmetry planes (unfinished)
* fixed crash bug in the inflate brush
* redid brush bitflags to use a macro, tired of typing in large integers
* added checkbox to enable/disable adaptive strength reduction based on spacing
* fixed confusion between use of SculptCache::symmetry and SculptCache::symmetry_pass
* changed do_brush_* functions to use math library functions instead of doing the math inline

Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-jwilkins/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2010-jwilkins/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c
    branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_sculpt_paint.c

Modified: branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-06-03 23:37:51 UTC (rev 29201)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-06-03 23:52:56 UTC (rev 29202)
@@ -759,6 +759,13 @@
         row = layout.row(align=True)
         row.active = brush.use_space
         row.prop(brush, "spacing", text="Spacing", slider=True)
+        row = layout.row(align=True)
+        row.active = brush.use_space
+        row.prop(brush, "use_space_atten", text="Adaptive Strength")
+        #row = layout.row(align=True)
+        #row.active = brush.use_space
+        #row.prop(brush, "use_adaptive_space", text="Adaptive Spacing")
+
         if texture_paint:
             row.prop(brush, "use_spacing_pressure", toggle=True, text="")
 
@@ -807,6 +814,7 @@
         col.prop(sculpt, "symmetry_x", text="X")
         col.prop(sculpt, "symmetry_y", text="Y")
         col.prop(sculpt, "symmetry_z", text="Z")
+        col.prop(sculpt, "use_symmetry_feather", text="Feather")
 
         col = split.column()
         col.label(text="Lock:")

Modified: branches/soc-2010-jwilkins/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenlib/BLI_pbvh.h	2010-06-03 23:37:51 UTC (rev 29201)
+++ branches/soc-2010-jwilkins/source/blender/blenlib/BLI_pbvh.h	2010-06-03 23:52:56 UTC (rev 29202)
@@ -161,8 +161,9 @@
 		int *grid_indices, totgrid, gridsize, *vert_indices, uniq_verts, totvert; \
 		\
 		vi.grid= 0; \
-                vi.no= 0; \
-                vi.mvert= 0; \
+		vi.no= 0; \
+		vi.fno= 0; \
+		vi.mvert= 0; \
 		\
 		BLI_pbvh_node_get_grids(bvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids, NULL); \
 		BLI_pbvh_node_num_verts(bvh, node, &uniq_verts, &totvert); \

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-06-03 23:37:51 UTC (rev 29201)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-06-03 23:52:56 UTC (rev 29202)
@@ -537,6 +537,36 @@
 	copy_v3_v3(test->location, ss->cache->location);
 }
 
+//static int sculpt_brush_test_clip(SculptBrushTest* test, float co[3])
+//{
+//	if (test->symmetry) {
+//		int i;
+//
+//		for (i = 0; i < 3; i++) {
+//			if (test->symmetry & (1<<i)) {
+//				if (test->symmetry_pass & (1<<i)) {
+//					if (test->true_location[i] > 0) {
+//						if (co[i] > 0) return 0;
+//					}
+//					else if (test->true_location[i] < 0) {
+//						if (co[i] < 0) return 0;
+//					}
+//				}
+//				else {
+//					if (test->true_location[i] > 0) {
+//						if (co[i] < 0) return 0;
+//					}
+//					else if (test->true_location[i] < 0) {
+//						if (co[i] > 0) return 0;
+//					}
+//				}
+//			}
+//		}
+//	}
+//
+//	return 1;
+//}
+
 static int sculpt_brush_test(SculptBrushTest *test, float co[3])
 {
 	float distsq = len_squared_v3v3(co, test->location);
@@ -670,7 +700,7 @@
 	float pressure = brush->flag & BRUSH_ALPHA_PRESSURE ? cache->pressure : 1;
 	float flip     = cache->flip ? -1 : 1;
 	//float overlap  = (brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100.0f) ? 1 - circle_overlap_percent(brush->spacing/50.0f) : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
-	float overlap  = (brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100) ? (float)brush->spacing/100.0f : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
+	float overlap  = (brush->flag & BRUSH_SPACE_ATTEN && brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100) ? (float)brush->spacing/100.0f : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
 
 	switch(brush->sculpt_tool){
 		case SCULPT_TOOL_DRAW:
@@ -794,7 +824,7 @@
 		   across the symmetry axis in order to project it. This insures
 		   that the brush texture will be oriented correctly. */
 		copy_v3_v3(flip, point);
-		flip_coord(flip, flip, ss->cache->symmetry);
+		flip_coord(flip, flip, ss->cache->symmetry_pass);
 		projectf(ss->cache->mats, flip, point_2d);
 
 		/* For Tile and Drag modes, get the 2D screen coordinates of the
@@ -838,7 +868,7 @@
 		}
 	}
 
-	avg*= brush_curve_strength(br, len, ss->cache->radius); /* Falloff curve */
+	avg *= brush_curve_strength(br, len, ss->cache->radius); /* Falloff curve */
 
 	avg += br->texture_offset;
 
@@ -879,6 +909,28 @@
 	return t[0] * t[0] + t[1] * t[1] + t[2] * t[2] < data->radius_squared;
 }
 
+static void symmetry_feather(Sculpt *sd, SculptSession* ss, float co[3], float val[3])
+{
+	if (ss->cache->symmetry && (sd->flags & SCULPT_SYMMETRY_FEATHER)) {
+		float distsq;
+		float mirror[3];
+		float overlap = 1.0f;
+		int symm = ss->cache->symmetry;
+		int i;
+
+		for (i = 1; i < symm; i++) {
+			if(symm & i && (symm != 5 || i != 3) && (symm != 6 || (i != 3 && i != 5))) {
+				flip_coord(mirror, ss->cache->location, i);
+				distsq = len_squared_v3v3(mirror, co);
+
+				if (distsq < ss->cache->radius*ss->cache->radius) overlap += 1 - sqrt(distsq)/ss->cache->radius;
+			}
+		}
+
+		mul_v3_fl(val, 1.0f / overlap);
+	}
+}
+
 /* Handles clipping against a mirror modifier and SCULPT_LOCK axis flags */
 static void sculpt_clip(Sculpt *sd, SculptSession *ss, float *co, const float val[3])
 {
@@ -892,7 +944,7 @@
 			co[i]= 0.0f;
 		else
 			co[i]= val[i];
-	}		
+	}
 }
 
 static void add_norm_if(float view_vec[3], float out[3], float out_flip[3], float fno[3])
@@ -993,14 +1045,14 @@
 
 	if (!brush->sculpt_direction == SCULPT_DISP_DIR_AREA) {
 		normalize_v3(an);
-		flip_coord(an, an, ss->cache->symmetry);
+		flip_coord(an, an, ss->cache->symmetry_pass);
 	}
 
 	if ((!ss->cache->first_time)&&(brush->flag & BRUSH_ORIGINAL_NORMAL)) {
 		copy_v3_v3(an, ss->cache->last_area_normal);
-		flip_coord(an, an, ss->cache->symmetry);
+		flip_coord(an, an, ss->cache->symmetry_pass);
 		copy_v3_v3(ss->cache->view_normal_symmetry, ss->cache->last_view_normal_symmetry);
-		flip_coord(ss->cache->view_normal_symmetry, ss->cache->view_normal_symmetry, ss->cache->symmetry);
+		flip_coord(ss->cache->view_normal_symmetry, ss->cache->view_normal_symmetry, ss->cache->symmetry_pass);
 	}
 	else {
 		if (ss->cache->symmetry_pass==0) {
@@ -1037,10 +1089,12 @@
 			if(sculpt_brush_test(&test, vd.co)) {
 				/* offset vertex */
 				float fade = tex_strength(ss, brush, vd.co, test.dist);
-				float val[3]= {vd.co[0] + offset[0]*fade,
-							   vd.co[1] + offset[1]*fade,
-							   vd.co[2] + offset[2]*fade};
+				float val[3];
 
+				mul_v3_v3fl(val, offset, fade);
+				symmetry_feather(sd, ss, vd.co, val);
+				add_v3_v3(val, vd.co);
+
 				sculpt_clip(sd, ss, vd.co, val);
 				if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
@@ -1115,10 +1169,11 @@
 			CLAMP(fade, 0.0f, 1.0f);
 			
 			neighbor_average(ss, avg, vd.vert_indices[vd.i]);
-			val[0] = vd.co[0]+(avg[0]-vd.co[0])*fade;
-			val[1] = vd.co[1]+(avg[1]-vd.co[1])*fade;
-			val[2] = vd.co[2]+(avg[2]-vd.co[2])*fade;
-			
+			sub_v3_v3v3(val, avg, vd.co);
+			mul_v3_fl(val, fade);
+			symmetry_feather(sd, ss, vd.co, val);
+			add_v3_v3(val, vd.co);
+
 			sculpt_clip(sd, ss, vd.co, val);			
 			if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
@@ -1194,10 +1249,11 @@
 
 					CLAMP(fade, 0.0f, 1.0f);
 
-					val[0] = co[0]+(avg[0]-co[0])*fade;
-					val[1] = co[1]+(avg[1]-co[1])*fade;
-					val[2] = co[2]+(avg[2]-co[2])*fade;
-					
+					sub_v3_v3v3(val, avg, co);
+					mul_v3_fl(val, fade);
+					symmetry_feather(sd, ss, co, val);
+					add_v3_v3(val, co);
+
 					sculpt_clip(sd, ss, data[x + y*gridsize].co, val);
 				}
 			}
@@ -1247,10 +1303,13 @@
 		BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
 			if(sculpt_brush_test(&test, vd.co)) {
 				float fade = tex_strength(ss, brush, vd.co, test.dist)*bstrength;
-				float val[3]= {vd.co[0]+(test.location[0]-vd.co[0])*fade,
-							   vd.co[1]+(test.location[1]-vd.co[1])*fade,
-							   vd.co[2]+(test.location[2]-vd.co[2])*fade};
+				float val[3];
 
+				sub_v3_v3v3(val, test.location, vd.co);
+				mul_v3_fl(val, fade);
+				symmetry_feather(sd, ss, vd.co, val);
+				add_v3_v3(val, vd.co);
+
 				sculpt_clip(sd, ss, vd.co, val);			
 				if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
@@ -1285,11 +1344,13 @@
 		BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
 			if(sculpt_brush_test(&test, origco[vd.i])) {
 				float fade = tex_strength(ss, brush, origco[vd.i], test.dist)*bstrength;
-				float add[3]= {vd.co[0]+fade*grab_delta[0],
-							   vd.co[1]+fade*grab_delta[1],
-							   vd.co[2]+fade*grab_delta[2]};
+				float val[3];
 
-				sculpt_clip(sd, ss, vd.co, add);			
+				mul_v3_v3fl(val, grab_delta, fade);
+				symmetry_feather(sd, ss, vd.co, val);
+				add_v3_v3(val, vd.co);
+
+				sculpt_clip(sd, ss, vd.co, val);			
 				if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
 					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
@@ -1346,18 +1407,18 @@
 				if((lim < 0 && *disp < lim) || (lim > 0 && *disp > lim))
 					*disp = lim;
 				
+				mul_v3_v3fl(val, offset, *disp);
+
 				if(ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) {
 					int index= vd.vert_indices[vd.i];
 
 					/* persistent base */
-					val[0] = ss->layer_co[index][0] + (*disp)*offset[0];
-					val[1] = ss->layer_co[index][1] + (*disp)*offset[1];
-					val[2] = ss->layer_co[index][2] + (*disp)*offset[2];
+					symmetry_feather(sd, ss, ss->layer_co[index], val);
+					add_v3_v3(val, ss->layer_co[index]);
 				}
 				else {
-					val[0] = origco[vd.i][0] + (*disp)*offset[0];
-					val[1] = origco[vd.i][1] + (*disp)*offset[1];
-					val[2] = origco[vd.i][2] + (*disp)*offset[2];
+					symmetry_feather(sd, ss, origco[vd.i], val);
+					add_v3_v3(val, origco[vd.i]);
 				}
 
 				sculpt_clip(sd, ss, vd.co, val);
@@ -1390,18 +1451,17 @@
 		BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
 			if(sculpt_brush_test(&test, vd.co)) {
 				float fade = tex_strength(ss, brush, vd.co, test.dist)*bstrength;
-				float add[3];
+				float val[3];
 
-				if(vd.fno) copy_v3_v3(add, vd.fno);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list