[Bf-blender-cvs] [fe19194] temp-curve-draw: Offset factor to allow drawing above/below the surface

Campbell Barton noreply at git.blender.org
Thu Apr 14 21:57:12 CEST 2016


Commit: fe191947e066ddc806f954bcf409f891c45533f6
Author: Campbell Barton
Date:   Fri Apr 15 05:57:09 2016 +1000
Branches: temp-curve-draw
https://developer.blender.org/rBfe191947e066ddc806f954bcf409f891c45533f6

Offset factor to allow drawing above/below the surface

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/curve/editcurve_paint.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 4af4cbe..b155a6a 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -592,6 +592,8 @@ class VIEW3D_PT_tools_curveedit_options_stroke(View3DPanel, Panel):
             if cps.use_stroke_endpoints:
                 colsub = layout.column(align=True)
                 colsub.prop(cps, "surface_plane", expand=True)
+            else:
+                col.prop(cps, "radius_offset")
 
 
 # ********** default tools for editmode_surface ****************
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 24093f4..4e7d66f 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -120,6 +120,7 @@ struct CurveDrawData {
 
 	struct {
 		float min, max, range;
+		float offset;
 	} radius;
 
 	struct {
@@ -141,6 +142,12 @@ struct CurveDrawData {
 	void *draw_handle_view;
 };
 
+static float stroke_elem_radius(const struct CurveDrawData *cdd, const struct StrokeElem *selem)
+{
+	const Curve *cu = cdd->vc.obedit->data;
+	return ((selem->pressure * cdd->radius.range) + cdd->radius.min) * cu->ext2;
+}
+
 static void stroke_elem_interp(
         struct StrokeElem *selem_out,
         const struct StrokeElem *selem_a,  const struct StrokeElem *selem_b, float t)
@@ -244,8 +251,7 @@ static void curve_draw_stroke_3d(const struct bContext *UNUSED(C), ARegion *UNUS
 			        selem->location_local[1] - location_prev[1],
 			        selem->location_local[2] - location_prev[2]);
 			location_prev = selem->location_local;
-			const float radius = ((selem->pressure * cdd->radius.range) + cdd->radius.min) * cu->ext2;
-			gluSphere(qobj, radius, 16, 12);
+			gluSphere(qobj, stroke_elem_radius(cdd, selem), 16, 12);
 
 			location_prev = selem->location_local;
 		}
@@ -391,6 +397,7 @@ static bool depth_read_normal(
 static bool stroke_elem_project(
         const struct CurveDrawData *cdd,
         const int mval_i[2], const float mval_fl[2],
+        const float radius_offset, const float radius,
         float r_location_world[3])
 {
 	View3D *v3d = cdd->vc.v3d;
@@ -421,6 +428,13 @@ static bool stroke_elem_project(
 			if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
 				if (depth_unproject(ar, &cdd->mats, mval_i, depth, r_location_world)) {
 					is_location_world_set = true;
+
+					if (radius_offset != 0.0f) {
+						float normal[3];
+						if (depth_read_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
+							madd_v3_v3fl(r_location_world, normal, radius_offset * radius);
+						}
+					}
 				}
 			}
 		}
@@ -432,10 +446,14 @@ static bool stroke_elem_project(
 static bool stroke_elem_project_fallback(
         const struct CurveDrawData *cdd,
         const int mval_i[2], const float mval_fl[2],
+        const float radius_offset, const float radius,
         const float location_fallback_depth[3],
         float r_location_world[3], float r_location_local[3])
 {
-	bool is_depth_found = stroke_elem_project(cdd, mval_i, mval_fl, r_location_world);
+	bool is_depth_found = stroke_elem_project(
+	        cdd, mval_i, mval_fl,
+	        radius_offset, radius,
+	        r_location_world);
 	if (is_depth_found == false) {
 		ED_view3d_win_to_3d(cdd->vc.ar, location_fallback_depth, mval_fl, r_location_world);
 	}
@@ -444,14 +462,20 @@ static bool stroke_elem_project_fallback(
 	return is_depth_found;
 }
 
+/**
+ * \note #StrokeElem.mval & #StrokeElem.pressure must be set first.
+ */
 static bool stroke_elem_project_fallback_elem(
         const struct CurveDrawData *cdd,
         const float location_fallback_depth[3],
         struct StrokeElem *selem)
 {
 	const int mval_i[2] = {UNPACK2(selem->mval)};
+	const float radius = stroke_elem_radius(cdd, selem);
 	return stroke_elem_project_fallback(
-	        cdd, mval_i, selem->mval, location_fallback_depth,
+	        cdd, mval_i, selem->mval,
+	        cdd->radius.offset, radius,
+	        location_fallback_depth,
 	        selem->location_world, selem->location_local);
 }
 
@@ -467,16 +491,6 @@ static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
 
 	ARRAY_SET_ITEMS(selem->mval, event->mval[0], event->mval[1]);
 
-	bool is_depth_found = stroke_elem_project_fallback_elem(
-	        cdd, cdd->prev.location_world_valid, selem);
-
-	if (is_depth_found) {
-		/* use the depth if a fallback wasn't used */
-		copy_v3_v3(cdd->prev.location_world_valid, selem->location_world);
-	}
-	copy_v3_v3(cdd->prev.location_world, selem->location_world);
-
-
 	/* handle pressure sensitivity (which is supplied by tablets) */
 	if (event->tablet_data) {
 		const wmTabletData *wmtab = event->tablet_data;
@@ -486,6 +500,15 @@ static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
 		selem->pressure = 1.0f;
 	}
 
+	bool is_depth_found = stroke_elem_project_fallback_elem(
+	        cdd, cdd->prev.location_world_valid, selem);
+
+	if (is_depth_found) {
+		/* use the depth if a fallback wasn't used */
+		copy_v3_v3(cdd->prev.location_world_valid, selem->location_world);
+	}
+	copy_v3_v3(cdd->prev.location_world, selem->location_world);
+
 	float len_sq = len_squared_v2v2(cdd->prev.mouse, selem->mval);
 	copy_v2_v2(cdd->prev.mouse, selem->mval);
 
@@ -801,6 +824,7 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 	cdd->radius.min = cps->radius_min;
 	cdd->radius.max = cps->radius_max;
 	cdd->radius.range = cps->radius_max - cps->radius_min;
+	cdd->radius.offset = cps->radius_offset;
 
 	/* fallback (incase we can't find the depth on first test) */
 	{
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 06ccaa9..2b879a5 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1271,9 +1271,10 @@ typedef struct CurvePaintSettings {
 	char flag;
 	char depth_mode;
 	char surface_plane;
-	char _pad[5];
+	char _pad[1];
 	int error_threshold;
 	float radius_min, radius_max;
+	float radius_offset;
 	float corner_angle;
 } CurvePaintSettings;
 
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index c233356..25424e8 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2648,6 +2648,11 @@ static void rna_def_curve_paint_settings(BlenderRNA  *brna)
 	RNA_def_property_ui_range(prop, 0.0f, 10.0, 0.1, 2);
 	RNA_def_property_ui_text(prop, "Radius Max", "");
 
+	prop = RNA_def_property(srna, "radius_offset", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, -10.0, 10.0);
+	RNA_def_property_ui_range(prop, -1.0f, 1.0, 0.1, 2);
+	RNA_def_property_ui_text(prop, "Offset", "Offset the stroke from the surface");
+
 	static EnumPropertyItem depth_mode_items[] = {
 		{CURVE_PAINT_PROJECT_CURSOR,  "CURSOR",  0, "Cursor",  ""},
 		{CURVE_PAINT_PROJECT_SURFACE, "SURFACE", 0, "Surface", ""},




More information about the Bf-blender-cvs mailing list