[Bf-blender-cvs] [ba5a8d5992a] greasepencil-object: GP: Improve collision detection
Antonioya
noreply at git.blender.org
Thu Jan 3 16:41:37 CET 2019
Commit: ba5a8d5992a7a5e894f482b0cbef3566f7a3ef21
Author: Antonioya
Date: Thu Jan 3 16:41:22 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBba5a8d5992a7a5e894f482b0cbef3566f7a3ef21
GP: Improve collision detection
Now the stroke extremes are scaled for improving the collision detection.
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_utils.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index a5ca59a85e2..02495f861ab 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -173,7 +173,7 @@ void BKE_gpencil_stroke_2d_flat(
void BKE_gpencil_stroke_2d_flat_ref(
const struct bGPDspoint *ref_points, int ref_totpoints,
const struct bGPDspoint *points, int totpoints,
- float(*points2d)[2], int *r_direction);
+ float(*points2d)[2], const float scale, int *r_direction);
void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 4f396757253..1099fbfd84a 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1620,7 +1620,7 @@ void BKE_gpencil_stroke_2d_flat(const bGPDspoint *points, int totpoints, float(*
void BKE_gpencil_stroke_2d_flat_ref(
const bGPDspoint *ref_points, int ref_totpoints,
const bGPDspoint *points, int totpoints,
- float(*points2d)[2], int *r_direction)
+ float(*points2d)[2], const float scale, int *r_direction)
{
BLI_assert(totpoints >= 2);
@@ -1661,9 +1661,26 @@ void BKE_gpencil_stroke_2d_flat_ref(
for (int i = 0; i < totpoints; i++) {
const bGPDspoint *pt = &points[i];
float loc[3];
+ float v1[3];
+ /* apply scale to extremes of the stroke to get better collision detection */
+ /* first point */
+ if (i == 0) {
+ const bGPDspoint *pt_next = &points[i + 1];
+ interp_v3_v3v3(v1, &pt->x, &pt_next->x, -scale);
+
+ }
+ /* 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);
+ }
+ else {
+ copy_v3_v3(v1, &pt->x);
+ }
+
/* Get local space using first point as origin (ref stroke) */
- sub_v3_v3v3(loc, &pt->x, &pt0->x);
+ sub_v3_v3v3(loc, v1, &pt0->x);
points2d[i][0] = dot_v3v3(loc, locx);
points2d[i][1] = dot_v3v3(loc, locy);
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index d493ecb28eb..ee288b7e705 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -3818,6 +3818,9 @@ static int gpencil_cutter_lasso_select(
{
for (i = 0; i < gps->totpoints; i++) {
pt = &gps->points[i];
+ if (pt->flag & GP_SPOINT_SELECT) {
+ continue;
+ }
/* convert point coords to screenspace */
const bool is_inside = is_inside_fn(gps, pt, &gsc, gpstroke_iter.diff_mat, user_data);
if (is_inside) {
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 80770eb2961..d0dac7b06d3 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2087,8 +2087,6 @@ static float gp_calc_factor(float p2d_a1[2], float p2d_a2[2], float r_hit2d[2])
float f1 = dist1 > 0.0f ? dist3 / dist1 : 0.0f;
f = f + (f - f1);
- interp_v2_v2v2(v1, p2d_a1, p2d_a2, f);
-
return f;
}
@@ -2142,17 +2140,22 @@ 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(gps->points, gps->totpoints, points2d, &direction);
+ BKE_gpencil_stroke_2d_flat_ref(
+ gps->points, gps->totpoints,
+ gps->points, gps->totpoints, points2d, 0.0f, &direction);
GHash *all_2d = BLI_ghash_ptr_new(__func__);
for (int s = 0; s < totstrokes; s++) {
bGPDstroke *gps_iter = gps_array[s];
float(*points2d_iter)[2] = MEM_mallocN(sizeof(*points2d_iter) * gps_iter->totpoints, __func__);
+
+ /* the extremes of the stroke are scaled to improve collision detection for near lines */
BKE_gpencil_stroke_2d_flat_ref(
gps->points, gps->totpoints,
- gps_iter->points, gps_iter->totpoints, points2d_iter, &direction);
+ gps_iter->points, gps_iter->totpoints, points2d_iter, scale, &direction);
BLI_ghash_insert(all_2d, gps_iter, points2d_iter);
}
More information about the Bf-blender-cvs
mailing list