[Bf-blender-cvs] [a47d4bf244e] temp-gpencil-bezier-stroke-type: GPencil: Deduplicate gpencil_3d_point_to_screen_space
Antonio Vazquez
noreply at git.blender.org
Tue Apr 27 16:28:15 CEST 2021
Commit: a47d4bf244e1ba976080e0cc6f931221228a8b25
Author: Antonio Vazquez
Date: Tue Apr 27 16:28:11 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rBa47d4bf244e1ba976080e0cc6f931221228a8b25
GPencil: Deduplicate gpencil_3d_point_to_screen_space
===================================================================
M source/blender/editors/gpencil/gpencil_select.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/gpencil/gpencil_vertex_paint.c
M source/blender/editors/gpencil/gpencil_weight_paint.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 8cbd12b64e2..dea11c31630 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -132,27 +132,6 @@ static bool gpencil_select_poll(bContext *C)
return false;
}
-static bool gpencil_3d_point_to_screen_space(ARegion *region,
- const float diff_mat[4][4],
- const float co[3],
- int r_co[2])
-{
- float parent_co[3];
- mul_v3_m4v3(parent_co, diff_mat, co);
- int screen_co[2];
- if (ED_view3d_project_int_global(
- region, parent_co, screen_co, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
- V3D_PROJ_RET_OK) {
- if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1])) {
- copy_v2_v2_int(r_co, screen_co);
- return true;
- }
- }
- r_co[0] = V2D_IS_CLIPPED;
- r_co[1] = V2D_IS_CLIPPED;
- return false;
-}
-
/* helper to deselect all selected strokes/points */
static void deselect_all_selected(bContext *C)
{
@@ -1571,7 +1550,7 @@ static bool gpencil_stroke_fill_isect_rect(ARegion *region,
int *pt2d = points2d[i];
int screen_co[2];
- gpencil_3d_point_to_screen_space(region, diff_mat, &pt->x, screen_co);
+ ED_gpencil_3d_point_to_screen_space(region, NULL, diff_mat, &pt->x, screen_co);
DO_MINMAX2(screen_co, min, max);
copy_v2_v2_int(pt2d, screen_co);
@@ -1990,7 +1969,7 @@ static bool gpencil_test_box(ARegion *region,
GP_SelectUserData *user_data)
{
int co[2] = {0};
- if (gpencil_3d_point_to_screen_space(region, diff_mat, pt, co)) {
+ if (ED_gpencil_3d_point_to_screen_space(region, NULL, diff_mat, pt, co)) {
return BLI_rcti_isect_pt(&user_data->rect, co[0], co[1]);
}
return false;
@@ -2039,7 +2018,7 @@ static bool gpencil_test_lasso(ARegion *region,
GP_SelectUserData *user_data)
{
int co[2] = {0};
- if (gpencil_3d_point_to_screen_space(region, diff_mat, pt, co)) {
+ if (ED_gpencil_3d_point_to_screen_space(region, NULL, diff_mat, pt, co)) {
/* test if in lasso boundbox + within the lasso noose */
return (BLI_rcti_isect_pt(&user_data->rect, co[0], co[1]) &&
BLI_lasso_is_point_inside(
@@ -2130,7 +2109,8 @@ static bool gpencil_select_curve_point_closest(bContext *C,
for (int j = from; j < to; j++) {
int screen_co[2];
- if (gpencil_3d_point_to_screen_space(region, gps_iter->diff_mat, bezt->vec[j], screen_co)) {
+ if (ED_gpencil_3d_point_to_screen_space(
+ region, NULL, gps_iter->diff_mat, bezt->vec[j], screen_co)) {
const int pt_distance = len_manhattan_v2v2_int(mval, screen_co);
if (pt_distance <= radius_squared && pt_distance < *hit_distance) {
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index ff3f6ff713f..ababb85f068 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -3487,3 +3487,34 @@ void ED_gpencil_stroke_close_by_distance(bGPDstroke *gps, const float threshold)
BKE_gpencil_stroke_close(gps);
}
}
+
+/* Convert 3D point to 2D point in screen space. */
+bool ED_gpencil_3d_point_to_screen_space(struct ARegion *region,
+ const struct rcti *rect,
+ const float diff_mat[4][4],
+ const float co[3],
+ int r_co[2])
+{
+ float parent_co[3];
+ mul_v3_m4v3(parent_co, diff_mat, co);
+ int screen_co[2];
+ if (ED_view3d_project_int_global(
+ region, parent_co, screen_co, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
+ V3D_PROJ_RET_OK) {
+ if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1])) {
+ if (rect == NULL) {
+ copy_v2_v2_int(r_co, screen_co);
+ return true;
+ }
+ else {
+ if (BLI_rcti_isect_pt(rect, screen_co[0], screen_co[1])) {
+ copy_v2_v2_int(r_co, screen_co);
+ return true;
+ }
+ }
+ }
+ }
+ r_co[0] = V2D_IS_CLIPPED;
+ r_co[1] = V2D_IS_CLIPPED;
+ return false;
+}
diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c
index 4792e8a01f0..a154fdce41d 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_paint.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c
@@ -161,27 +161,6 @@ typedef struct tGP_BrushVertexpaintData {
} tGP_BrushVertexpaintData;
-/* TODO: This function is duplicated in other places and should not be here. */
-static bool gpencil_3d_point_to_screen_space(
- ARegion *region, const rcti *rect, const float diff_mat[4][4], const float co[3], int r_co[2])
-{
- float parent_co[3];
- mul_v3_m4v3(parent_co, diff_mat, co);
- int screen_co[2];
- if (ED_view3d_project_int_global(
- region, parent_co, screen_co, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
- V3D_PROJ_RET_OK) {
- if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1]) &&
- BLI_rcti_isect_pt(rect, screen_co[0], screen_co[1])) {
- copy_v2_v2_int(r_co, screen_co);
- return true;
- }
- }
- r_co[0] = V2D_IS_CLIPPED;
- r_co[1] = V2D_IS_CLIPPED;
- return false;
-}
-
/* Ensure the buffer to hold temp selected point size is enough to save all points selected. */
static tGP_Selected *gpencil_select_buffer_ensure(tGP_Selected *buffer_array,
int *buffer_size,
@@ -900,7 +879,7 @@ static void gpencil_vertexpaint_select_curve(tGP_BrushVertexpaintData *gso,
int screen_co[2];
/* Test if points can be projected. */
- if (!gpencil_3d_point_to_screen_space(region, rect, diff_mat, bezt->vec[1], screen_co)) {
+ if (!ED_gpencil_3d_point_to_screen_space(region, rect, diff_mat, bezt->vec[1], screen_co)) {
continue;
}
diff --git a/source/blender/editors/gpencil/gpencil_weight_paint.c b/source/blender/editors/gpencil/gpencil_weight_paint.c
index 339e9695efe..b3e40addb3d 100644
--- a/source/blender/editors/gpencil/gpencil_weight_paint.c
+++ b/source/blender/editors/gpencil/gpencil_weight_paint.c
@@ -143,27 +143,6 @@ typedef struct tGP_BrushWeightpaintData {
int pbuffer_size;
} tGP_BrushWeightpaintData;
-/* TODO: This function is duplicated in other places and should not be here. */
-static bool gpencil_3d_point_to_screen_space(
- ARegion *region, const rcti *rect, const float diff_mat[4][4], const float co[3], int r_co[2])
-{
- float parent_co[3];
- mul_v3_m4v3(parent_co, diff_mat, co);
- int screen_co[2];
- if (ED_view3d_project_int_global(
- region, parent_co, screen_co, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
- V3D_PROJ_RET_OK) {
- if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1]) &&
- BLI_rcti_isect_pt(rect, screen_co[0], screen_co[1])) {
- copy_v2_v2_int(r_co, screen_co);
- return true;
- }
- }
- r_co[0] = V2D_IS_CLIPPED;
- r_co[1] = V2D_IS_CLIPPED;
- return false;
-}
-
/* Ensure the buffer to hold temp selected point size is enough to save all points selected. */
static tGP_Selected *gpencil_select_buffer_ensure(tGP_Selected *buffer_array,
int *buffer_size,
@@ -446,7 +425,7 @@ static void gpencil_weightpaint_select_curve(tGP_BrushWeightpaintData *gso,
int screen_co[2];
/* Test if points can be projected. */
- if (!gpencil_3d_point_to_screen_space(region, rect, diff_mat, bezt->vec[1], screen_co)) {
+ if (!ED_gpencil_3d_point_to_screen_space(region, rect, diff_mat, bezt->vec[1], screen_co)) {
continue;
}
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index e9ac21f60cf..3ad723582d3 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -52,6 +52,7 @@ struct SnapObjectContext;
struct ToolSettings;
struct View3D;
struct bContext;
+struct rcti;
struct Material;
struct Object;
@@ -292,6 +293,11 @@ void ED_gpencil_stroke_reproject(struct Depsgraph *depsgraph,
struct bGPDstroke *gps,
const eGP_ReprojectModes mode,
const bool keep_original);
+bool ED_gpencil_3d_point_to_screen_space(struct ARegion *region,
+ const struct rcti *rect,
+ const float diff_mat[4][4],
+ const float co[3],
+ int r_co[2]);
/* set sculpt cursor */
void ED_gpencil_toggle_brush_cursor(struct bContext *C, bool enable, void *customdata);
More information about the Bf-blender-cvs
mailing list