[Bf-blender-cvs] [41ee544] temp-curve-draw: Add radius taper option

Campbell Barton noreply at git.blender.org
Fri Apr 15 04:08:15 CEST 2016


Commit: 41ee544d52ad5d0fa8e92751d21a82f24807666e
Author: Campbell Barton
Date:   Fri Apr 15 11:15:48 2016 +1000
Branches: temp-curve-draw
https://developer.blender.org/rB41ee544d52ad5d0fa8e92751d21a82f24807666e

Add radius taper option

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

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 4131254..08661a7 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -571,19 +571,21 @@ class VIEW3D_PT_tools_curveedit_options_stroke(View3DPanel, Panel):
             col.active = cps.use_corners_detect
             col.prop(cps, "corner_angle")
 
-        col.label("Radius/Pressure:")
+        col.label("Pressure Radius:")
         row = layout.row(align=True)
         rowsub = row.row(align=True)
-        if cps.use_pressure_radius:
-            rowsub.active = cps.use_pressure_radius
-            rowsub.prop(cps, "radius_min", text="Min")
-            rowsub.prop(cps, "radius_max", text="Max")
-        else:
-            rowsub.prop(cps, "radius_max", text="Radius")
+        rowsub.prop(cps, "radius_min", text="Min")
+        rowsub.prop(cps, "radius_max", text="Max")
 
         row.prop(cps, "use_pressure_radius", text="", icon_only=True)
 
         col = layout.column()
+        col.label("Taper Radius:")
+        row = layout.row(align=True)
+        row.prop(cps, "radius_taper_start", text="Stard")
+        row.prop(cps, "radius_taper_end", text="End")
+
+        col = layout.column()
         col.label("Projection/Depth:")
         row = layout.row(align=True)
         row.prop(cps, "depth_mode", expand=True)
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index be4d7a0..5966564 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -593,10 +593,11 @@ static void curve_draw_exit(wmOperator *op)
  */
 static void curve_draw_exec_precalc(wmOperator *op)
 {
+	struct CurveDrawData *cdd = op->customdata;
+	const CurvePaintSettings *cps = &cdd->vc.scene->toolsettings->curve_paint_settings;
+
 	PropertyRNA *prop_error = RNA_struct_find_property(op->ptr, "error_threshold");
 	if (!RNA_property_is_set(op->ptr, prop_error)) {
-		struct CurveDrawData *cdd = op->customdata;
-		const CurvePaintSettings *cps = &cdd->vc.scene->toolsettings->curve_paint_settings;
 
 		/* error isnt set so we'll have to calculate it from the pixel values */
 		BLI_mempool_iter iter;
@@ -617,6 +618,54 @@ static void curve_draw_exec_precalc(wmOperator *op)
 		float error_threshold = (cps->error_threshold * U.pixelsize) * scale_px;
 		RNA_property_float_set(op->ptr, prop_error, error_threshold);
 	}
+
+	if ((cps->radius_taper_start != 0.0f) ||
+	    (cps->radius_taper_end   != 0.0f))
+	{
+		/* note, we could try to de-duplicate the length calculations above */
+		const int stroke_len = BLI_mempool_count(cdd->stroke_elem_pool);
+
+		BLI_mempool_iter iter;
+		struct StrokeElem *selem, *selem_prev;
+
+		float *lengths = MEM_mallocN(sizeof(float) * stroke_len, __func__);
+		struct StrokeElem **selem_array = MEM_mallocN(sizeof(*selem_array) * stroke_len, __func__);
+		lengths[0] = 0.0f;
+
+		float len_3d = 0.0f;
+
+		int i = 1;
+		BLI_mempool_iternew(cdd->stroke_elem_pool, &iter);
+		selem_prev = BLI_mempool_iterstep(&iter);
+		selem_array[0] = selem_prev;
+		for (selem = BLI_mempool_iterstep(&iter); selem; selem = BLI_mempool_iterstep(&iter), i++) {
+			const float len_3d_segment = len_v3v3(selem->location_local, selem_prev->location_local);
+			len_3d += len_3d_segment;
+			lengths[i] = len_3d;
+			selem_array[i] = selem;
+			selem_prev = selem;
+		}
+
+		if (cps->radius_taper_start != 0.0) {
+			selem_array[0]->pressure = 0.0f;
+			const float len_taper_max = cps->radius_taper_start * len_3d;
+			for (i = 1; i < stroke_len && lengths[i] < len_taper_max; i++) {
+				selem_array[i]->pressure *=   lengths[i] / len_taper_max;
+			}
+		}
+
+		if (cps->radius_taper_end != 0.0) {
+			selem_array[stroke_len - 1]->pressure = 0.0f;
+			const float len_taper_max = cps->radius_taper_end * len_3d;
+			const float len_taper_min = len_3d - len_taper_max;
+			for (i = stroke_len - 2; i > 0 && lengths[i] > len_taper_min; i--) {
+				selem_array[i]->pressure *= (len_3d - lengths[i]) / len_taper_max;
+			}
+		}
+
+		MEM_freeN(lengths);
+		MEM_freeN(selem_array);
+	}
 }
 
 static int curve_draw_exec(bContext *C, wmOperator *op)
@@ -654,6 +703,10 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
 	nu->resolv = cu->resolv;
 	nu->flag |= CU_SMOOTH;
 
+	const bool use_pressure_radius =
+	        (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) ||
+	        ((cps->radius_taper_start != 0.0f) ||
+	         (cps->radius_taper_end   != 0.0f));
 
 	if (cdd->curve_type == CU_BEZIER) {
 		nu->type = CU_BEZIER;
@@ -665,7 +718,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
 		struct {
 			int radius;
 		} coords_indices;
-		coords_indices.radius = (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) ? dims++ : -1;
+		coords_indices.radius = use_pressure_radius ? dims++ : -1;
 
 		float *coords = MEM_mallocN(sizeof(*coords) * stroke_len * dims, __func__);
 
@@ -786,7 +839,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
 					bezt->vec[1][2] = 0.0f;
 				}
 
-				if (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) {
+				if (use_pressure_radius) {
 					bezt->radius = selem->pressure;
 				}
 				else {
@@ -823,7 +876,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
 				bp->vec[2] = 0.0f;
 			}
 
-			if (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) {
+			if (use_pressure_radius) {
 				bp->radius = (selem->pressure * radius_range) + radius_min;
 			}
 			else {
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 4340c24..ba5a3a4 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1274,6 +1274,7 @@ typedef struct CurvePaintSettings {
 	char surface_plane;
 	int error_threshold;
 	float radius_min, radius_max;
+	float radius_taper_start, radius_taper_end;
 	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 2fdffd1..aff65da 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2653,10 +2653,20 @@ static void rna_def_curve_paint_settings(BlenderRNA  *brna)
 	RNA_def_property_ui_text(prop, "Radius Min", "");
 
 	prop = RNA_def_property(srna, "radius_max", PROP_FLOAT, PROP_NONE);
-	RNA_def_property_range(prop, 0.0, 10.0);
+	RNA_def_property_range(prop, 0.0, 100.0);
 	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_taper_start", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0, 1.0);
+	RNA_def_property_ui_range(prop, 0.0f, 1.0, 0.1, 2);
+	RNA_def_property_ui_text(prop, "Radius Min", "");
+
+	prop = RNA_def_property(srna, "radius_taper_end", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0, 10.0);
+	RNA_def_property_ui_range(prop, 0.0f, 1.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);




More information about the Bf-blender-cvs mailing list