[Bf-blender-cvs] [0b9a72a] soc-2016-sculpt_tools: first working version of silhouette brush tool

JIANG Kairong noreply at git.blender.org
Sun Jun 26 05:54:02 CEST 2016


Commit: 0b9a72a0dcc8bec6a3cbe3d5b9ea1e98554545b2
Author: JIANG Kairong
Date:   Sun Jun 26 11:53:57 2016 +0800
Branches: soc-2016-sculpt_tools
https://developer.blender.org/rB0b9a72a0dcc8bec6a3cbe3d5b9ea1e98554545b2

first working version of silhouette brush tool

===================================================================

M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/editors/sculpt_paint/paint_curve.c
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

===================================================================

diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index f15aea1..3b01688 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -417,13 +417,14 @@ void BKE_brush_sculpt_reset(Brush *br)
 			br->sub_col[0] = 0.25;
 			br->sub_col[1] = 1;
 			break;
+        case SCULPT_TOOL_SILHOUETTE:
 		case SCULPT_TOOL_INFLATE:
 			br->add_col[0] = 0.750000;
 			br->add_col[1] = 0.750000;
 			br->add_col[2] = 0.750000;
-			br->sub_col[0] = 0.250000;
-			br->sub_col[1] = 0.250000;
-			br->sub_col[2] = 0.250000;
+            br->sub_col[0] = 0.250000;
+            br->sub_col[1] = 0.250000;
+            br->sub_col[2] = 0.250000;
 			break;
 		case SCULPT_TOOL_NUDGE:
 			br->add_col[0] = 0.250000;
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index d307ba1..03d11df 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -797,6 +797,11 @@ void BKE_scene_init(Scene *sce)
 		gp_brush->size = 25;
 		gp_brush->strength = 0.5f;
 		gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
+
+        gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_SILHOUETTE];
+        gp_brush->size = 10;
+        gp_brush->strength = 0.5f;
+        gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
 	}
 	
 	/* GP Stroke Placement */
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 45edaca..b75521b 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -111,6 +111,7 @@ float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const
 float         dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]);
 float dist_squared_to_line_v3(const float p[3], const float l1[3], const float l2[3]);
 float         dist_to_line_v3(const float p[3], const float l1[3], const float l2[3]);
+float dist_squared_to_line_direction_v3v3(const float v1[3], const float v2[3], const float dir[3]);
 float dist_signed_squared_to_corner_v3v3v3(
         const float p[3],
         const float v1[3], const float v2[3], const float v3[3],
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index f80099b..98703c4 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -496,6 +496,16 @@ float dist_to_line_v3(const float p[3], const float l1[3], const float l2[3])
 	return sqrtf(dist_squared_to_line_v3(p, l1, l2));
 }
 
+/* distance v1 to line v2-V_dir in 3D */
+float dist_squared_to_line_direction_v3v3(const float v1[3], const float v2[3], const float dir[3])
+{
+    float v2v1[3];
+    sub_v3_v3v3(v2v1, v1, v2);
+    float e[3];
+    cross_v3_v3v3(e, v2v1, dir);
+    return len_squared_v3(e);
+}
+
 /**
  * Check if \a p is inside the 2x planes defined by ``(v1, v2, v3)``
  * where the 3x points define 2x planes.
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index ad7a3c5..e399cd1 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -109,7 +109,7 @@ void BLO_update_defaults_startup_blend(Main *bmain)
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
 				
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
-				brush->size = 50;
+                brush->size = 50;
 				brush->strength = 0.3f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
 				
@@ -132,6 +132,11 @@ void BLO_update_defaults_startup_blend(Main *bmain)
 				brush->size = 25;
 				brush->strength = 0.5f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
+
+                brush = &gset->brush[GP_EDITBRUSH_TYPE_SILHOUETTE];
+                brush->size = 10;
+                brush->strength = 0.5f;
+                brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
 			}
 			
 			ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
@@ -208,12 +213,19 @@ void BLO_update_defaults_startup_blend(Main *bmain)
 	{
 		Brush *br;
 
-		br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
-		if (!br) {
-			br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
-			br->imagepaint_tool = PAINT_TOOL_FILL;
-			br->ob_mode = OB_MODE_TEXTURE_PAINT;
-		}
+        br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
+        if (!br) {
+            br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
+            br->imagepaint_tool = PAINT_TOOL_FILL;
+            br->ob_mode = OB_MODE_TEXTURE_PAINT;
+        }
+
+        br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Silhouette");
+        if (!br) {
+            br = BKE_brush_add(bmain, "Silhouette", OB_MODE_SCULPT);
+            br->sculpt_tool = SCULPT_TOOL_SILHOUETTE;
+            br->ob_mode = OB_MODE_SCULPT;
+        }
 
 		br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Mask");
 		if (br) {
@@ -222,10 +234,10 @@ void BLO_update_defaults_startup_blend(Main *bmain)
 		}
 
 		/* remove polish brush (flatten/contrast does the same) */
-		br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Polish");
-		if (br) {
-			BKE_libblock_free(bmain, br);
-		}
+        br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Polish");
+        if (br) {
+            BKE_libblock_free(bmain, br);
+        }
 
 		/* remove brush brush (huh?) from some modes (draw brushes do the same) */
 		br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Brush");
diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c
index 9704db9..5e0fc64 100644
--- a/source/blender/editors/sculpt_paint/paint_curve.c
+++ b/source/blender/editors/sculpt_paint/paint_curve.c
@@ -762,7 +762,7 @@ void PAINTCURVE_OT_draw(wmOperatorType *ot)
 	/* identifiers */
 	ot->name = "Draw Curve";
 	ot->description = "Draw curve";
-	ot->idname = "PAINTCURVE_OT_draw";
+    ot->idname = "PAINTCURVE_OT_draw";
 
 	/* api callbacks */
 	ot->exec = paintcurve_draw_exec;
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 65857cc..3f4d95a 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -469,9 +469,14 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float
 
 	ups->last_hit = paint_brush_update(C, brush, mode, stroke, mouse_in, mouse_out, pressure, location);
 	copy_v3_v3(ups->last_location, location);
-	if (!ups->last_hit) {
-		return;
-	}
+    if (brush->sculpt_tool == SCULPT_TOOL_SILHOUETTE) {
+        if (ups->last_hit) {
+            return;
+        }
+    }
+    else if (!ups->last_hit) {
+        return;
+    }
 
 	/* Add to stroke */
 	RNA_collection_add(op->ptr, "stroke", &itemptr);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index f02b061..200157f 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -268,6 +268,9 @@ typedef struct StrokeCache {
 
 	rcti previous_r; /* previous redraw rectangle */
 	rcti current_r; /* current redraw rectangle */
+
+    /* not so good, could be another way */
+    int brush_size;
 } StrokeCache;
 
 /************** Access to original unmodified vertex data *************/
@@ -653,9 +656,16 @@ void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar,
 typedef struct SculptBrushTest {
 	float radius_squared;
 	float location[3];
+    float normal[3];
 	float dist;
 	int mirror_symmetry_pass;
 
+    ViewContext* vc;
+    int brush_size;
+    float true_location[3];
+    float prep_foot[3];
+    float radius;
+
 	/* View3d clipping - only set rv3d for clipping */
 	RegionView3D *clip_rv3d;
 } SculptBrushTest;
@@ -663,9 +673,13 @@ typedef struct SculptBrushTest {
 static void sculpt_brush_test_init(SculptSession *ss, SculptBrushTest *test)
 {
 	RegionView3D *rv3d = ss->cache->vc->rv3d;
+    test->vc = ss->cache->vc;
+    test->brush_size = ss->cache->brush_size;
+    copy_v3_v3(test->true_location, ss->cache->true_location);
 
 	test->radius_squared = ss->cache->radius_squared;
 	copy_v3_v3(test->location, ss->cache->location);
+    copy_v3_v3(test->normal, ss->cache->view_normal);
 	test->dist = 0.0f;   /* just for initialize */
 
 	test->mirror_symmetry_pass = ss->cache->mirror_symmetry_pass;
@@ -1157,7 +1171,7 @@ static float brush_strength(const Sculpt *sd, const StrokeCache *cache, const fl
 	float pressure     = BKE_brush_use_alpha_pressure(scene, brush) ? cache->pressure : 1;
 	float pen_flip     = cache->pen_flip ? -1 : 1;
 	float invert       = cache->invert ? -1 : 1;
-	float overlap       = ups->overlap_factor;
+    float overlap      = ups->overlap_factor;
 	/* spacing is integer percentage of radius, divide by 50 to get
 	 * normalized diameter */
 
@@ -1182,7 +1196,7 @@ static float brush_strength(const Sculpt *sd, const StrokeCache *cache, const fl
 		case SCULPT_TOOL_CREASE:
 		case SCULPT_TOOL_BLOB:
 			return alpha * flip * pressure * overlap * feather;
-
+        case SCULPT_TOOL_SILHOUETTE:
 		case SCULPT_TOOL_INFLATE:
 			if (flip > 0) {
 				return 0.250f * alpha * flip * pressure * overlap * feather;
@@ -1346,6 +1360,12 @@ static bool sculpt_search_sphere_cb(PBVHNode *node, void *data_v)
 	return len_squared_v3(t) < data->radius_squared;
 }
 
+/* temporary function to make silhouette brush loop through all the nodes */
+static bool sculpt_search_silhouette_cb (PBVHNode *UNUSED(node), void *UNUSED(data_v))
+{
+    return true;
+}
+
 /* Handles clipping against a mirror modifier and SCULPT_LOCK axis flags */
 static void sculpt_clip(Sculpt *sd, SculptSession *ss, float co[3], const float val[3])
 {
@@ -2232,7 +2252,8 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
 	copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry);
 
 	if (ss->cache->normal_weight > 0.0f) {
-		sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta);
+        sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta);
+
 	}
 
 	SculptThreadedTa

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list