[Bf-blender-cvs] [3a20d82] temp-curve-draw: Add curve/pressure option
Campbell Barton
noreply at git.blender.org
Wed Apr 13 18:05:12 CEST 2016
Commit: 3a20d82428e269ec8be932222d55797c8eaeee4b
Author: Campbell Barton
Date: Thu Apr 14 02:04:56 2016 +1000
Branches: temp-curve-draw
https://developer.blender.org/rB3a20d82428e269ec8be932222d55797c8eaeee4b
Add curve/pressure 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 c4800ef..127c945 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -566,13 +566,25 @@ class VIEW3D_PT_tools_curveedit_options(View3DPanel, Panel):
cps = tool_settings.curve_paint_settings
col.prop(cps, "error_threshold")
col.prop(cps, "use_corners_detect")
+
col = layout.column()
col.active = cps.use_corners_detect
col.prop(cps, "corner_angle")
+ col.label("Radius/Pressure:")
+ 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")
+
+ row.prop(cps, "use_pressure_radius", text="", icon_only=True)
-# ********** default tools for editmode_surface ****************
+# ********** default tools for editmode_surface ****************
class VIEW3D_PT_tools_transform_surface(View3DPanel, Panel):
bl_category = "Tools"
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 5580a62..9847a46 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -332,6 +332,7 @@ static void curve_draw_exit(wmOperator *op)
static int curve_draw_exec(bContext *C, wmOperator *op)
{
struct CurveDrawData *cdd = op->customdata;
+ const CurvePaintSettings *cps = &cdd->scene->toolsettings->curve_paint_settings;
Object *obedit = cdd->scene->obedit;
Curve *cu = obedit->data;
ListBase *nurblist = object_editcurve_get(obedit);
@@ -339,6 +340,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
int stroke_len = BLI_mempool_count(cdd->stroke_elem_pool);
const bool is_3d = (cu->flag & CU_3D) != 0;
+ const bool use_pressure_radius = (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) != 0;
invert_m4_m4(obedit->imat, obedit->obmat);
if (BLI_mempool_count(cdd->stroke_elem_pool) == 0) {
@@ -348,6 +350,10 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
ED_curve_deselect_all(cu->editnurb);
+ const double radius_min = cps->radius_min;
+ const double radius_max = cps->radius_max;
+ const double radius_range = cps->radius_max - cps->radius_min;
+
Nurb *nu = MEM_callocN(sizeof(Nurb), __func__);
nu->pntsv = 1;
nu->resolu = cu->resolu;
@@ -359,7 +365,6 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
nu->type = CU_BEZIER;
#ifdef USE_SPLINE_FIT
- const CurvePaintSettings *curve_paint_settings = &cdd->scene->toolsettings->curve_paint_settings;
#define DIMS 4
@@ -392,7 +397,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
selem_prev = selem;
}
scale_px = len_3d / len_2d;
- error_threshold = (float)curve_paint_settings->error_threshold * scale_px;
+ error_threshold = (float)cps->error_threshold * scale_px;
RNA_property_float_set(op->ptr, prop_error, error_threshold);
printf("%.6f ~ %.6f ~ %.6f\n", scale_px, len_3d, len_2d);
}
@@ -412,7 +417,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
unsigned int *corners = NULL;
unsigned int corners_len = 0;
- if (curve_paint_settings->flag & CURVE_PAINT_FLAG_CORNERS_DETECT) {
+ if (cps->flag & CURVE_PAINT_FLAG_CORNERS_DETECT) {
/* this could be configurable... */
const float corner_radius_min = error_threshold;
const float corner_radius_max = error_threshold * 3;
@@ -420,7 +425,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
spline_fit_corners_detect_fl(
(const float *)coords, stroke_len, DIMS,
corner_radius_min, corner_radius_max,
- samples_max, curve_paint_settings->corner_angle,
+ samples_max, cps->corner_angle,
&corners, &corners_len);
}
@@ -437,8 +442,6 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
nu->pntsu = cubic_spline_len + 1;
nu->bezt = MEM_callocN(sizeof(BezTriple) * nu->pntsu, __func__);
-float rad_fac = 1.0f;
-
float *fl = cubic_spline;
for (int j = 0; j < cubic_spline_len; j++, fl += (DIMS * 4)) {
const float *pt_l = fl + (DIMS * 0);
@@ -456,8 +459,14 @@ float rad_fac = 1.0f;
copy_v3_v3(nu->bezt[j + 1].vec[0], handle_r);
copy_v3_v3(nu->bezt[j + 1].vec[1], pt_r);
- nu->bezt[j + 0].radius = pt_l[3] * rad_fac;
- nu->bezt[j + 1].radius = pt_r[3] * rad_fac;
+ if (use_pressure_radius) {
+ nu->bezt[j + 0].radius = (pt_l[3] * radius_range) + radius_min;
+ nu->bezt[j + 1].radius = (pt_r[3] * radius_range) + radius_min;
+ }
+ else {
+ nu->bezt[j + 0].radius = radius_max;
+ nu->bezt[j + 1].radius = radius_max;
+ }
}
{
@@ -511,7 +520,14 @@ float rad_fac = 1.0f;
if (!is_3d) {
bezt->vec[1][2] = 0.0f;
}
- bezt->radius = selem->pressure;
+
+ if (use_pressure_radius) {
+ bezt->radius = selem->pressure;
+ }
+ else {
+ bezt->radius = cps->radius_max;
+ }
+
bezt->h1 = bezt->h2 = HD_AUTO;
@@ -542,7 +558,13 @@ float rad_fac = 1.0f;
if (!is_3d) {
bp->vec[2] = 0.0f;
}
- bp->radius = selem->pressure;
+
+ if (use_pressure_radius) {
+ bp->radius = (selem->pressure * radius_range) + radius_min;
+ }
+ else {
+ bp->radius = cps->radius_max;
+ }
bp->f1 = SELECT;
bp->vec[3] = 1.0f;
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 3470ab1..4b98617 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1277,7 +1277,8 @@ typedef struct CurvePaintSettings {
} CurvePaintSettings;
enum {
- CURVE_PAINT_FLAG_CORNERS_DETECT = (1 << 0),
+ CURVE_PAINT_FLAG_CORNERS_DETECT = (1 << 0),
+ CURVE_PAINT_FLAG_PRESSURE_RADIUS = (1 << 1),
};
enum {
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 13042a4..a6fd6de 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2616,11 +2616,15 @@ static void rna_def_curve_paint_settings(BlenderRNA *brna)
RNA_def_struct_path_func(srna, "rna_CurvePaintSettings_path");
RNA_def_struct_ui_text(srna, "Curve Paint Settings", "");
- /* high-level flags to enable or disable unified paint settings */
prop = RNA_def_property(srna, "use_corners_detect", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", CURVE_PAINT_FLAG_CORNERS_DETECT);
RNA_def_property_ui_text(prop, "Detect Corners", "");
+ prop = RNA_def_property(srna, "use_pressure_radius", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CURVE_PAINT_FLAG_PRESSURE_RADIUS);
+ RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0);
+ RNA_def_property_ui_text(prop, "Use Pressure", "Map tablet pressure to curve radius");
+
prop = RNA_def_property(srna, "error_threshold", PROP_INT, PROP_PIXEL);
RNA_def_property_range(prop, 1, 100);
RNA_def_property_ui_text(prop, "Tolerance", "Allow deviation for a smoother, less preceise line");
@@ -2628,6 +2632,16 @@ static void rna_def_curve_paint_settings(BlenderRNA *brna)
prop = RNA_def_property(srna, "corner_angle", PROP_FLOAT, PROP_ANGLE);
RNA_def_property_range(prop, 0, M_PI);
RNA_def_property_ui_text(prop, "Corner Angle", "Angles above this are considered corners");
+
+ prop = RNA_def_property(srna, "radius_min", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_range(prop, 0.0, 1000.0);
+ RNA_def_property_ui_range(prop, 0.0f, 10.0, 0.001, 2);
+ 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_ui_range(prop, 0.0f, 10.0, 0.001, 1);
+ RNA_def_property_ui_text(prop, "Radius Max", "");
}
static void rna_def_statvis(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list