[Bf-blender-cvs] [34f4fc6119b] soc-2021-curves: Added functionality to move all selected points
dilithjay
noreply at git.blender.org
Sun Jan 2 11:03:17 CET 2022
Commit: 34f4fc6119b9ab0b4d973f2ff4e2efde3453f1f7
Author: dilithjay
Date: Sat Jan 1 23:49:29 2022 +0530
Branches: soc-2021-curves
https://developer.blender.org/rB34f4fc6119b9ab0b4d973f2ff4e2efde3453f1f7
Added functionality to move all selected points
===================================================================
M source/blender/editors/curve/editcurve_pen.c
M source/blender/editors/curve/editcurve_query.c
===================================================================
diff --git a/source/blender/editors/curve/editcurve_pen.c b/source/blender/editors/curve/editcurve_pen.c
index 7c9bf9d46e3..f2c87719c7e 100644
--- a/source/blender/editors/curve/editcurve_pen.c
+++ b/source/blender/editors/curve/editcurve_pen.c
@@ -84,8 +84,12 @@ typedef struct CurvePenData {
bool spline_nearby;
/* Whether the extra key was pressed before. */
bool extra_pressed;
+ /* Whether some action was done. Used for select. */
+ bool acted;
/* Whether a point was found underneath the mouse. */
bool found_point;
+ /* Whether multiple selected points should be moved. */
+ bool multi_point;
Nurb *nu;
BezTriple *bezt;
@@ -114,17 +118,36 @@ static const EnumPropertyItem prop_extra_key_types[] = {
{0, NULL, 0, NULL, NULL},
};
-static void mouse_location_to_worldspace(const int mouse_loc[2],
- const float depth[3],
- const ViewContext *vc,
- float r_location[3])
+static void screenspace_to_worldspace(const int pos_2d[2],
+ const float depth[3],
+ const ViewContext *vc,
+ float r_pos_3d[3])
{
- mul_v3_m4v3(r_location, vc->obedit->obmat, depth);
- ED_view3d_win_to_3d_int(vc->v3d, vc->region, r_location, mouse_loc, r_location);
+ mul_v3_m4v3(r_pos_3d, vc->obedit->obmat, depth);
+ ED_view3d_win_to_3d_int(vc->v3d, vc->region, r_pos_3d, pos_2d, r_pos_3d);
float imat[4][4];
invert_m4_m4(imat, vc->obedit->obmat);
- mul_m4_v3(imat, r_location);
+ mul_m4_v3(imat, r_pos_3d);
+}
+
+static bool worldspace_to_screenspace(const float pos_3d[3],
+ const ViewContext *vc,
+ float r_pos_2d[2])
+{
+ return ED_view3d_project_float_object(
+ vc->region, pos_3d, r_pos_2d, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
+ V3D_PROJ_RET_OK;
+}
+
+static bool worldspace_to_screenspace_int(const float pos_3d[3],
+ const ViewContext *vc,
+ int r_pos_2d[2])
+{
+ float pos_2d_fl[2];
+ const bool check = worldspace_to_screenspace(pos_3d, vc, pos_2d_fl);
+ r_pos_2d[0] = (int)pos_2d_fl[0];
+ r_pos_2d[1] = (int)pos_2d_fl[1];
}
/* Move the handle of the newly added #BezTriple to mouse. */
@@ -139,7 +162,7 @@ static void move_bezt_handles_to_mouse(BezTriple *bezt,
}
float location[3];
- mouse_location_to_worldspace(event->mval, bezt->vec[1], vc, location);
+ screenspace_to_worldspace(event->mval, bezt->vec[1], vc, location);
/* If the new point is the last point of the curve, move the second handle to the mouse. */
if (is_end_point) {
@@ -199,7 +222,7 @@ static void move_bezt_handle_or_vertex_to_location(BezTriple *bezt,
const ViewContext *vc)
{
float location[3];
- mouse_location_to_worldspace(mval, bezt->vec[cp_index], vc, location);
+ screenspace_to_worldspace(mval, bezt->vec[cp_index], vc, location);
if (cp_index == 1) {
move_bezt_to_location(bezt, location);
}
@@ -234,14 +257,69 @@ static void move_selected_bezt_to_location(BezTriple *bezt,
}
}
-static void move_bp_to_mouse(BPoint *bp, const wmEvent *event, const ViewContext *vc)
+static void move_bp_to_location(BPoint *bp, const int mval[2], const ViewContext *vc)
{
float location[3];
- mouse_location_to_worldspace(event->mval, bp->vec, vc, location);
+ screenspace_to_worldspace(mval, bp->vec, vc, location);
copy_v3_v3(bp->vec, location);
}
+static void move_all_selected_points(ListBase *editnurb, wmEvent *event, const ViewContext *vc)
+{
+ int change[2];
+ sub_v2_v2v2_int(change, event->xy, event->prev_xy);
+ LISTBASE_FOREACH (Nurb *, nu, editnurb) {
+ if (nu->type == CU_BEZIER) {
+ for (int i = 0; i < nu->pntsu; i++) {
+ BezTriple *bezt = nu->bezt + i;
+ if (BEZT_ISSEL_IDX(bezt, 1)) {
+ int pos[2], dst[2];
+ worldspace_to_screenspace_int(bezt->vec[1], vc, pos);
+ add_v2_v2v2_int(dst, pos, change);
+ move_bezt_handle_or_vertex_to_location(bezt, dst, 1, vc);
+ }
+ else {
+ remove_handle_movement_constraints(bezt, bezt->f1, bezt->f3);
+ if (BEZT_ISSEL_IDX(bezt, 0)) {
+ int pos[2], dst[2];
+ worldspace_to_screenspace_int(bezt->vec[0], vc, pos);
+ add_v2_v2v2_int(dst, pos, change);
+ move_bezt_handle_or_vertex_to_location(bezt, dst, 0, vc);
+ }
+ else if (BEZT_ISSEL_IDX(bezt, 2)) {
+ int pos[2], dst[2];
+ worldspace_to_screenspace_int(bezt->vec[2], vc, pos);
+ add_v2_v2v2_int(dst, pos, change);
+ move_bezt_handle_or_vertex_to_location(bezt, dst, 2, vc);
+ }
+ }
+ }
+ }
+ else {
+ for (int i = 0; i < nu->pntsu; i++) {
+ BPoint *bp = nu->bp + i;
+ if (bp->f1) {
+ int pos[2], dst[2];
+ worldspace_to_screenspace_int(bp->vec, vc, pos);
+ add_v2_v2v2_int(dst, pos, change);
+ move_bp_to_location(bp, dst, vc);
+ }
+ }
+ }
+ }
+}
+
+static bool world_point_near_screen_point(const float world_pos[3],
+ const int screen_pos[2],
+ const float sel_dist_mul,
+ const ViewContext *vc)
+{
+ int pos_2d[2];
+ worldspace_to_screenspace_int(world_pos, vc, pos_2d);
+ return len_v2v2_int(pos_2d, screen_pos) < ED_view3d_select_dist_px() * sel_dist_mul;
+}
+
static int get_nurb_index(const ListBase *nurbs, const Nurb *nurb)
{
int index = 0;
@@ -298,12 +376,8 @@ static bool get_closest_point_on_edge(float r_point[3],
float pos1_2d[2], pos2_2d[2], vec1[2], vec2[2], vec3[2];
/* Get screen space coordinates of points. */
- if (!(ED_view3d_project_float_object(
- vc->region, pos1, pos1_2d, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
- V3D_PROJ_RET_OK &&
- ED_view3d_project_float_object(
- vc->region, pos2, pos2_2d, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
- V3D_PROJ_RET_OK)) {
+ if (!(worldspace_to_screenspace(pos1, vc, pos1_2d) &&
+ worldspace_to_screenspace(pos2, vc, pos2_2d))) {
return false;
}
@@ -339,17 +413,20 @@ static bool get_closest_point_on_edge(float r_point[3],
}
/* Get closest vertex in all nurbs in given #ListBase to a given point. */
-static void get_closest_vertex_to_point_in_nurbs(ListBase *nurbs,
+static bool get_closest_vertex_to_point_in_nurbs(ListBase *nurbs,
Nurb **r_nu,
BezTriple **r_bezt,
BPoint **r_bp,
+ short *r_bezt_idx,
const float point[2],
+ const float sel_dist_mul,
const ViewContext *vc)
{
float min_distance_bezt = FLT_MAX;
float min_distance_bp = FLT_MAX;
BezTriple *closest_bezt = NULL;
+ short closest_handle = 0;
BPoint *closest_bp = NULL;
Nurb *closest_bezt_nu = NULL;
Nurb *closest_bp_nu = NULL;
@@ -359,16 +436,15 @@ static void get_closest_vertex_to_point_in_nurbs(ListBase *nurbs,
for (int i = 0; i < nu->pntsu; i++) {
BezTriple *bezt = &nu->bezt[i];
float bezt_vec[2];
- if (ED_view3d_project_float_object(vc->region,
- bezt->vec[1],
- bezt_vec,
- V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) ==
- V3D_PROJ_RET_OK) {
- const float distance = len_manhattan_v2v2(bezt_vec, point);
- if (distance < min_distance_bezt) {
- min_distance_bezt = distance;
- closest_bezt = bezt;
- closest_bezt_nu = nu;
+ for (short j = 0; j < 3; j++) {
+ if (worldspace_to_screenspace(bezt->vec[j], vc, bezt_vec)) {
+ const float distance = len_manhattan_v2v2(bezt_vec, point);
+ if (distance < min_distance_bezt) {
+ min_distance_bezt = distance;
+ closest_bezt = bezt;
+ closest_bezt_nu = nu;
+ closest_handle = j;
+ }
}
}
}
@@ -377,9 +453,7 @@ static void get_closest_vertex_to_point_in_nurbs(ListBase *nurbs,
for (int i = 0; i < nu->pntsu; i++) {
BPoint *bp = &nu->bp[i];
float bp_vec[2];
- if (ED_view3d_project_float_object(
- vc->region, bp->vec, bp_vec, V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) ==
- V3D_PROJ_RET_OK) {
+ if (worldspace_to_screenspace(bp->vec, vc, bp_vec)) {
const float distance = len_manhattan_v2v2(bp_vec, point);
if (distance < min_distance_bp) {
min_distance_bp = distance;
@@ -391,7 +465,7 @@ static void get_closest_vertex_to_point_in_nurbs(ListBase *nurbs,
}
}
- const float threshold_distance = ED_view3d_select_dist_px();
+ const float threshold_distance = ED_view3d_select_dist_px() * sel_dist_mul;
if (min_distance_bezt < threshold_distance || min_distance_bp < threshold_distance) {
if (min_distance_bp < min_distance_bezt) {
*r_bp = closest_bp;
@@ -399,9 +473,12 @@ static void get_closest_vertex_to_point_in_nurbs(ListBase *nurbs,
}
else {
*r_bezt = closest_bezt;
+ *r_bezt_idx = closest_handle;
*r_nu = closest_bezt_nu;
}
+ return true;
}
+ return false;
}
/* Assign values for several frequently changing attributes of #CutData. */
@@ -447,12 +524,7 @@ static void update_data_if_closest_point_in_segment(const BezTriple *bezt1,
for (int k = 0; k <= resolu; k++) {
float screen_co[2];
-
- bool check = ED_view3d_project_float_object(vc->region,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list