[Bf-blender-cvs] [bcee57e] master: Roto: Improve spline sliding vs. curvature detection
Sergey Sharybin
noreply at git.blender.org
Mon Oct 13 18:00:09 CEST 2014
Commit: bcee57e74e587260f2a7050b3b8a1894fe592466
Author: Sergey Sharybin
Date: Mon Oct 13 17:59:03 2014 +0200
Branches: master
https://developer.blender.org/rBbcee57e74e587260f2a7050b3b8a1894fe592466
Roto: Improve spline sliding vs. curvature detection
If the mouse is closer to the spline than to it's center do a
spline curvature correction operator instead.
===================================================================
M source/blender/editors/mask/mask_add.c
M source/blender/editors/mask/mask_intern.h
M source/blender/editors/mask/mask_ops.c
===================================================================
diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c
index b816103..cd6e937 100644
--- a/source/blender/editors/mask/mask_add.c
+++ b/source/blender/editors/mask/mask_add.c
@@ -62,7 +62,8 @@ bool ED_mask_find_nearest_diff_point(const bContext *C,
MaskSplinePoint **point_r,
float *u_r, float tangent[2],
const bool use_deform,
- const bool use_project)
+ const bool use_project,
+ float *score_r)
{
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C);
@@ -171,6 +172,10 @@ bool ED_mask_find_nearest_diff_point(const bContext *C,
*u_r = u;
}
+ if (score_r) {
+ *score_r = dist;
+ }
+
return true;
}
@@ -339,7 +344,7 @@ static bool add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2
float tangent[2];
float u;
- if (ED_mask_find_nearest_diff_point(C, mask, co, threshold, false, &masklay, &spline, &point, &u, tangent, true, true)) {
+ if (ED_mask_find_nearest_diff_point(C, mask, co, threshold, false, &masklay, &spline, &point, &u, tangent, true, true, NULL)) {
MaskSplinePoint *new_point;
int point_index = point - spline->points;
@@ -624,7 +629,7 @@ static int add_feather_vertex_exec(bContext *C, wmOperator *op)
if (point)
return OPERATOR_FINISHED;
- if (ED_mask_find_nearest_diff_point(C, mask, co, threshold, true, &masklay, &spline, &point, &u, NULL, true, true)) {
+ if (ED_mask_find_nearest_diff_point(C, mask, co, threshold, true, &masklay, &spline, &point, &u, NULL, true, true, NULL)) {
Scene *scene = CTX_data_scene(C);
float w = BKE_mask_point_weight(spline, point, u);
float weight_scalar = BKE_mask_point_weight_scalar(spline, point, u);
diff --git a/source/blender/editors/mask/mask_intern.h b/source/blender/editors/mask/mask_intern.h
index 6899cf7..af91afe 100644
--- a/source/blender/editors/mask/mask_intern.h
+++ b/source/blender/editors/mask/mask_intern.h
@@ -49,7 +49,8 @@ bool ED_mask_find_nearest_diff_point(const struct bContext *C,
struct MaskSplinePoint **point_r,
float *u_r, float tangent[2],
const bool use_deform,
- const bool use_project);
+ const bool use_project,
+ float *score_r);
void MASK_OT_add_vertex(struct wmOperatorType *ot);
void MASK_OT_add_feather_vertex(struct wmOperatorType *ot);
diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c
index d322ca9..486704c 100644
--- a/source/blender/editors/mask/mask_ops.c
+++ b/source/blender/editors/mask/mask_ops.c
@@ -510,6 +510,7 @@ static bool spline_under_mouse_get(const bContext *C,
MaskLayer **mask_layer_r,
MaskSpline **mask_spline_r)
{
+ const float threshold = 19.0f;
ScrArea *sa = CTX_wm_area(C);
SpaceClip *sc = CTX_wm_space_clip(C);
MaskLayer *mask_layer;
@@ -580,10 +581,17 @@ static bool spline_under_mouse_get(const bContext *C,
}
}
}
- /* TODO(sergey): Chech whether tessellated spline point is closer
- * to the mouse than the spline center.
- */
- if (closest_dist_squared < SQUARE(32.0f) && closest_spline != NULL) {
+ if (closest_dist_squared < SQUARE(threshold) && closest_spline != NULL) {
+ float diff_score;
+ if (ED_mask_find_nearest_diff_point(C, mask, co, threshold, false,
+ NULL, NULL, NULL, NULL,
+ NULL, true, false, &diff_score))
+ {
+ if (SQUARE(diff_score) < closest_dist_squared) {
+ return false;
+ }
+ }
+
*mask_layer_r = closest_layer;
*mask_spline_r = closest_spline;
return true;
@@ -1185,7 +1193,7 @@ static bool slide_spline_curvature_check(bContext *C, const wmEvent *event)
static SlideSplineCurvatureData *slide_spline_curvature_customdata(
bContext *C, const wmEvent *event)
{
- const float threshold = 19;
+ const float threshold = 19.0f;
Mask *mask = CTX_data_edit_mask(C);
SlideSplineCurvatureData *slide_data;
@@ -1199,7 +1207,7 @@ static SlideSplineCurvatureData *slide_spline_curvature_customdata(
if (!ED_mask_find_nearest_diff_point(C, mask, co, threshold, false,
&mask_layer, &spline, &point, &u,
- NULL, true, false))
+ NULL, true, false, NULL))
{
return NULL;
}
More information about the Bf-blender-cvs
mailing list