[Bf-blender-cvs] [eba3cb75b02] greasepencil-object: GP: Improve intersections and add Threshold parameter
Antonioya
noreply at git.blender.org
Fri Jan 4 18:16:42 CET 2019
Commit: eba3cb75b02f047a98db506a7dad65c438d130ec
Author: Antonioya
Date: Fri Jan 4 17:52:29 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBeba3cb75b02f047a98db506a7dad65c438d130ec
GP: Improve intersections and add Threshold parameter
Now the threshold can be defined using a UI parameter.
The parameter is available in Edit selecction and in Cutter tool.
Also improved the use of this threshold.
===================================================================
M release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M release/scripts/startup/bl_ui/space_topbar.py
M source/blender/blenkernel/intern/gpencil.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_select.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
M source/blender/makesdna/DNA_scene_types.h
M source/blender/makesrna/intern/rna_sculpt_paint.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 18c4d8710ec..84413f6c40a 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1134,7 +1134,7 @@ class _defs_gpencil_edit:
@ToolDef.from_fn
def select():
def draw_settings(context, layout, tool):
- pass
+ layout.prop(context.tool_settings.gpencil_sculpt, "isect_threshold")
return dict(
text="Select",
icon="ops.generic.select",
@@ -1148,6 +1148,7 @@ class _defs_gpencil_edit:
def draw_settings(context, layout, tool):
props = tool.operator_properties("gpencil.select_box")
layout.prop(props, "mode", expand=True)
+ layout.prop(context.tool_settings.gpencil_sculpt, "isect_threshold")
return dict(
text="Select Box",
icon="ops.generic.select_box",
@@ -1161,6 +1162,7 @@ class _defs_gpencil_edit:
def draw_settings(context, layout, tool):
props = tool.operator_properties("gpencil.select_lasso")
layout.prop(props, "mode", expand=True)
+ layout.prop(context.tool_settings.gpencil_sculpt, "isect_threshold")
return dict(
text="Select Lasso",
icon="ops.generic.select_lasso",
@@ -1171,11 +1173,14 @@ class _defs_gpencil_edit:
@ToolDef.from_fn
def circle_select():
+ def draw_settings(context, layout, tool):
+ layout.prop(context.tool_settings.gpencil_sculpt, "isect_threshold")
return dict(
text="Select Circle",
icon="ops.generic.select_circle",
widget=None,
keymap=(),
+ draw_settings=draw_settings,
)
@ToolDef.from_fn
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 077003bc6ae..0757481f882 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -301,9 +301,11 @@ class _draw_left_context_mode:
is_paint = True
if tool.name in {"Line", "Box", "Circle", "Arc", "Curve"}:
is_paint = False
- elif not tool.has_datablock:
- return
elif tool.name == "Cutter":
+ row = layout.row(align=True)
+ row.prop(context.tool_settings.gpencil_sculpt, "isect_threshold")
+ return
+ elif not tool.has_datablock:
return
paint = context.tool_settings.gpencil_paint
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 1099fbfd84a..54025a3cd20 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1662,18 +1662,26 @@ void BKE_gpencil_stroke_2d_flat_ref(
const bGPDspoint *pt = &points[i];
float loc[3];
float v1[3];
+ float vn[3] = { 0.0f, 0.0f, 0.0f };
- /* apply scale to extremes of the stroke to get better collision detection */
+ /* apply scale to extremes of the stroke to get better collision detection
+ * the scale is divided to get more control in the UI parameter
+ */
/* first point */
if (i == 0) {
const bGPDspoint *pt_next = &points[i + 1];
- interp_v3_v3v3(v1, &pt->x, &pt_next->x, -scale);
-
+ sub_v3_v3v3(vn, &pt->x, &pt_next->x);
+ normalize_v3(vn);
+ mul_v3_fl(vn, scale / 10.0f);
+ add_v3_v3v3(v1, &pt->x, vn);
}
/* last point */
else if (i == totpoints - 1) {
const bGPDspoint *pt_prev = &points[i - 1];
- interp_v3_v3v3(v1, &pt_prev->x, &pt->x, 1.0f + scale);
+ sub_v3_v3v3(vn, &pt->x, &pt_prev->x);
+ normalize_v3(vn);
+ mul_v3_fl(vn, scale / 10.0f);
+ add_v3_v3v3(v1, &pt->x, vn);
}
else {
copy_v3_v3(v1, &pt->x);
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 1fe4a33f0e8..65e013ca7f9 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -3793,6 +3793,8 @@ static int gpencil_cutter_lasso_select(
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
ScrArea *sa = CTX_wm_area(C);
+ ToolSettings *ts = CTX_data_tool_settings(C);
+ const float scale = ts->gp_sculpt.isect_threshold;
bGPDspoint *pt;
int i;
@@ -3839,7 +3841,7 @@ static int gpencil_cutter_lasso_select(
float r_hita[3], r_hitb[3];
if (gps->totpoints > 1) {
ED_gpencil_select_stroke_segment(
- gpl, gps, pt, true, true, r_hita, r_hitb);
+ gpl, gps, pt, true, true, scale, r_hita, r_hitb);
}
}
}
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 1e099b844ee..1deeab641f4 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -864,7 +864,8 @@ static bool gp_stroke_do_circle_sel(
bGPDlayer *gpl,
bGPDstroke *gps, GP_SpaceConversion *gsc,
const int mx, const int my, const int radius,
- const bool select, rcti *rect, float diff_mat[4][4], const int selectmode)
+ const bool select, rcti *rect, float diff_mat[4][4], const int selectmode,
+ const float scale)
{
bGPDspoint *pt1 = NULL;
bGPDspoint *pt2 = NULL;
@@ -965,7 +966,7 @@ static bool gp_stroke_do_circle_sel(
float r_hita[3], r_hitb[3];
bool hit_select = (bool)(pt1->flag & GP_SPOINT_SELECT);
ED_gpencil_select_stroke_segment(
- gpl, gps, pt1, hit_select, false, r_hita, r_hitb);
+ gpl, gps, pt1, hit_select, false, scale, r_hita, r_hitb);
}
/* Ensure that stroke selection is in sync with its points */
@@ -981,6 +982,7 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
bGPdata *gpd = ED_gpencil_data_get_active(C);
ToolSettings *ts = CTX_data_tool_settings(C);
const int selectmode = ts->gpencil_selectmode;
+ const float scale = ts->gp_sculpt.isect_threshold;
/* if not edit/sculpt mode, the event is catched but not processed */
if (GPENCIL_NONE_EDIT_MODE(gpd)) {
@@ -1023,7 +1025,7 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
{
changed |= gp_stroke_do_circle_sel(
gpl, gps, &gsc, mx, my, radius, select, &rect,
- gpstroke_iter.diff_mat, selectmode);
+ gpstroke_iter.diff_mat, selectmode, scale);
}
GP_EDITABLE_STROKES_END(gpstroke_iter);
@@ -1089,6 +1091,7 @@ static int gpencil_generic_select_exec(
(ts->gpencil_selectmode == GP_SELECTMODE_SEGMENT) &&
((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0));
const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
+ const float scale = ts->gp_sculpt.isect_threshold;
GP_SpaceConversion gsc = {NULL};
@@ -1146,7 +1149,7 @@ static int gpencil_generic_select_exec(
bool hit_select = (bool)(pt->flag & GP_SPOINT_SELECT);
float r_hita[3], r_hitb[3];
ED_gpencil_select_stroke_segment(
- gpl, gps, pt, hit_select, false, r_hita, r_hitb);
+ gpl, gps, pt, hit_select, false, scale, r_hita, r_hitb);
}
}
@@ -1361,6 +1364,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
ScrArea *sa = CTX_wm_area(C);
bGPdata *gpd = ED_gpencil_data_get_active(C);
ToolSettings *ts = CTX_data_tool_settings(C);
+ const float scale = ts->gp_sculpt.isect_threshold;
/* "radius" is simply a threshold (screen space) to make it easier to test with a tolerance */
const float radius = 0.50f * U.widget_unit;
@@ -1488,7 +1492,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
bool hit_select = (bool)(hit_point->flag & GP_SPOINT_SELECT);
ED_gpencil_select_stroke_segment(
hit_layer, hit_stroke, hit_point, hit_select,
- false, r_hita, r_hitb);
+ false, scale, r_hita, r_hitb);
}
}
else {
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 0a4781346b5..068f9f54e30 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2094,7 +2094,7 @@ static float gp_calc_factor(float p2d_a1[2], float p2d_a2[2], float r_hit2d[2])
/* extend selection to stroke intersections */
int ED_gpencil_select_stroke_segment(
bGPDlayer *gpl, bGPDstroke *gps, bGPDspoint *pt,
- bool select, bool insert,
+ bool select, bool insert, const float scale,
float r_hita[3], float r_hitb[3])
{
const float min_factor = 0.0015f;
@@ -2141,7 +2141,6 @@ int ED_gpencil_select_stroke_segment(
/* convert all gps points to 2d and save in a hash to avoid recalculation */
int direction = 0;
- const float scale = 0.5f;
float(*points2d)[2] = MEM_mallocN(sizeof(*points2d) * gps->totpoints, "GP Stroke temp 2d points");
BKE_gpencil_stroke_2d_flat_ref(
gps->points, gps->totpoints,
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 6daafae8e6f..808e8461471 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -269,7 +269,7 @@ void ED_gpencil_update_color_uv(struct Main *bmain, struct Material *mat);
int ED_gpencil_select_stroke_segment(
struct bGPDlayer *gpl,
struct bGPDstroke *gps, struct bGPDspoint *pt,
- bool select, bool insert,
+ bool select, bool insert, const float scale,
float r_hita[3], float r_hitb[3]);
#endif /* __ED_GPENCIL_H__ */
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 599e1f68645..eb0810a3d08 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1023,13 +1023,13 @@ typedef struct GP_Sculpt_Settings {
int brushtype; /* eGP_Sculpt_Types (sculpt) */
int flag; /* eGP_Sculpt_SettingsFlag */
int lock_axis; /* eGP_Lockaxis_Types lock drawing to one axis */
- char pad1[4];
+ float isect_threshold; /* threshold for intersections */
/* weight paint is a submode of sculpt but use its own index. All weight paint
* brushes
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list