[Bf-blender-cvs] [a4c46575eca] soc-2021-curves: Cleanup and refactoring
dilithjay
noreply at git.blender.org
Thu Sep 30 15:02:16 CEST 2021
Commit: a4c46575eca26ef9d32d690375a1331c10cdaca1
Author: dilithjay
Date: Thu Sep 30 18:16:16 2021 +0530
Branches: soc-2021-curves
https://developer.blender.org/rBa4c46575eca26ef9d32d690375a1331c10cdaca1
Cleanup and refactoring
===================================================================
M release/datafiles/locale
M release/scripts/addons
M release/scripts/addons_contrib
M source/blender/editors/curve/editcurve_pen.c
M source/tools
===================================================================
diff --git a/release/datafiles/locale b/release/datafiles/locale
index 3fc3c6a0f5d..2b0754f815f 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 3fc3c6a0f5df6980c194deca437bd3454c077a96
+Subproject commit 2b0754f815f656eec39bdef72af9c7d885d779b6
diff --git a/release/scripts/addons b/release/scripts/addons
index 53c7859c913..b1226da66a4 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 53c7859c9135eeb5274008d4d6caa8364ea0c308
+Subproject commit b1226da66a49a524ee17053c8f43d356597b18f4
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index 98f6085e9d7..42da56aa737 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit 98f6085e9d71ba35d41e5aafbcb7981bd7c48275
+Subproject commit 42da56aa73726710107031787af5eea186797984
diff --git a/source/blender/editors/curve/editcurve_pen.c b/source/blender/editors/curve/editcurve_pen.c
index 00d9afbf385..388e815cff2 100644
--- a/source/blender/editors/curve/editcurve_pen.c
+++ b/source/blender/editors/curve/editcurve_pen.c
@@ -98,21 +98,21 @@ static void move_bezt_handles_to_mouse(BezTriple *bezt,
float location[3];
mouse_location_to_worldspace(event->mval, bezt->vec[1], vc, location);
- /* If the new point is the last point of the curve, move the second handle. */
+ /* If the new point is the last point of the curve, move the second handle to the mouse. */
if (is_end_point) {
copy_v3_v3(bezt->vec[2], location);
if (bezt->h2 != HD_FREE) {
- mul_v3_fl(location, -1);
- madd_v3_v3v3fl(bezt->vec[0], location, bezt->vec[1], 2);
+ mul_v3_fl(location, -1.0f);
+ madd_v3_v3v3fl(bezt->vec[0], location, bezt->vec[1], 2.0f);
}
}
else {
copy_v3_v3(bezt->vec[0], location);
if (bezt->h1 != HD_FREE) {
- mul_v3_fl(location, -1);
- madd_v3_v3v3fl(bezt->vec[2], location, bezt->vec[1], 2);
+ mul_v3_fl(location, -1.0f);
+ madd_v3_v3v3fl(bezt->vec[2], location, bezt->vec[1], 2.0f);
}
}
}
@@ -127,8 +127,8 @@ static void move_bezt_to_location(BezTriple *bezt, const float location[3])
add_v3_v3(bezt->vec[2], change);
}
-/* Alter handle types to allow free movement. */
-static void free_up_handles_for_movement(BezTriple *bezt, bool f1, bool f3)
+/* Alter handle types to allow free movement (Set handles to FREE or ALIGN). */
+static void free_up_handles_for_movement(BezTriple *bezt, const bool f1, const bool f3)
{
if (f1) {
if (bezt->h1 == HD_VECT) {
@@ -150,7 +150,7 @@ static void free_up_handles_for_movement(BezTriple *bezt, bool f1, bool f3)
}
}
-/* Move BezTriple to mouse. */
+/* Move handles or entire BezTriple to mouse based on selection. */
static void move_selected_bezt_to_mouse(BezTriple *bezt,
const ViewContext *vc,
const wmEvent *event)
@@ -181,7 +181,7 @@ static void move_bp_to_mouse(BPoint *bp, const wmEvent *event, const ViewContext
copy_v3_v3(bp->vec, location);
}
-static int get_nurb_index(ListBase *nurbs, Nurb *nurb)
+static int get_nurb_index(const ListBase *nurbs, const Nurb *nurb)
{
int index = 0;
LISTBASE_FOREACH (Nurb *, nu, nurbs) {
@@ -190,7 +190,7 @@ static int get_nurb_index(ListBase *nurbs, Nurb *nurb)
}
index++;
}
- /* The nurb should've been found by now. */
+ /* The Nurb should've been found by now. */
BLI_assert(false);
return -1;
}
@@ -219,28 +219,32 @@ static void delete_bezt_from_nurb(const BezTriple *bezt, Nurb *nu)
static void delete_bp_from_nurb(const BPoint *bp, Nurb *nu)
{
- BLI_assert(nu->type == CU_NURBS);
+ BLI_assert(nu->type == CU_NURBS || nu->type == CU_POLY);
int index = BKE_curve_nurb_vert_index_get(nu, bp);
nu->pntsu -= 1;
memcpy(nu->bp + index, nu->bp + index + 1, (nu->pntsu - index) * sizeof(BPoint));
}
/* Get the closest point on an edge to a given point based on perpendicular distance. Return true
- * if closest point on curve. */
+ * if the closest point falls on the edge. */
static bool get_closest_point_on_edge(float r_point[3],
const float pos[2],
const float pos1[3],
const float pos2[3],
const ViewContext *vc,
- float *factor)
+ float *r_factor)
{
float pos1_2d[2], pos2_2d[2], vec1[2], vec2[2], vec3[2];
/* Get screen space coordinates of points. */
- ED_view3d_project_float_object(
- vc->region, pos1, pos1_2d, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
- ED_view3d_project_float_object(
- vc->region, pos2, pos2_2d, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
+ 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)) {
+ return false;
+ }
/* Obtain the vectors of each side. */
sub_v2_v2v2(vec1, pos, pos1_2d);
@@ -255,13 +259,14 @@ static bool get_closest_point_on_edge(float r_point[3],
perpendicular line from the mouse to the line.*/
if ((dot1 > 0) == (dot2 > 0)) {
float len_vec3_sq = len_squared_v2(vec3);
- *factor = 1 - dot2 / len_vec3_sq;
+ *r_factor = 1 - dot2 / len_vec3_sq;
float pos_dif[3];
sub_v3_v3v3(pos_dif, pos2, pos1);
- madd_v3_v3v3fl(r_point, pos1, pos_dif, *factor);
+ madd_v3_v3v3fl(r_point, pos1, pos_dif, *r_factor);
return true;
}
+
if (len_manhattan_v2(vec1) < len_manhattan_v2(vec2)) {
copy_v3_v3(r_point, pos1);
return false;
@@ -291,34 +296,39 @@ 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];
- ED_view3d_project_float_object(
- vc->region, bezt->vec[1], bezt_vec, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
- float distance = len_manhattan_v2v2(bezt_vec, point);
- if (distance < min_distance_bezt) {
- min_distance_bezt = distance;
- closest_bezt = bezt;
- closest_bezt_nu = nu;
+ 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) {
+ float distance = len_manhattan_v2v2(bezt_vec, point);
+ if (distance < min_distance_bezt) {
+ min_distance_bezt = distance;
+ closest_bezt = bezt;
+ closest_bezt_nu = nu;
+ }
}
}
}
- if (nu->type == CU_NURBS) {
+ else if (nu->type == CU_NURBS || nu->type == CU_POLY) {
for (int i = 0; i < nu->pntsu; i++) {
BPoint *bp = &nu->bp[i];
float bp_vec[2];
- ED_view3d_project_float_object(
- vc->region, bp->vec, bp_vec, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
- float distance = len_manhattan_v2v2(bp_vec, point);
- if (distance < min_distance_bp) {
- min_distance_bp = distance;
- closest_bp = bp;
- closest_bp_nu = nu;
+ 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) {
+ float distance = len_manhattan_v2v2(bp_vec, point);
+ if (distance < min_distance_bp) {
+ min_distance_bp = distance;
+ closest_bp = bp;
+ closest_bp_nu = nu;
+ }
}
}
}
}
- float threshold_distance = ED_view3d_select_dist_px();
-
+ const float threshold_distance = ED_view3d_select_dist_px();
if (min_distance_bezt < threshold_distance || min_distance_bp < threshold_distance) {
if (min_distance_bp < min_distance_bezt) {
*r_bp = closest_bp;
@@ -331,14 +341,30 @@ static void get_closest_vertex_to_point_in_nurbs(ListBase *nurbs,
}
}
-/* Update CutData with location of closest vertex on curve. */
-static void update_data_if_closest_vertex_in_segment(BezTriple *bezt1,
- BezTriple *bezt2,
- Nurb *nu,
- const int index,
- const ViewContext *vc,
- float screen_co[2],
- void *op_data)
+/* Assign values for several frequently changing attributes of CutData. */
+static void assign_cut_data(CutData *data,
+ const float min_dist,
+ Nurb *nu,
+ const int bext_index,
+ const int bp_index,
+ const float parameter,
+ const float cut_loc[3])
+{
+ data->min_dist = min_dist;
+ data->nurb = nu;
+ data->bezt_index = bext_index;
+ data->bp_index = bp_index;
+ data->parameter = parameter;
+ copy_v3_v3(data->cut_loc, cut_loc);
+}
+
+/* Update CutData with location of closest BezTriple on curve. */
+static void update_data_if_closest_bezt_in_segment(const BezTriple *bezt1,
+ const BezTriple *bezt2,
+ Nurb *nu,
+ const int index,
+ const ViewContext *vc,
+ void *op_data)
{
CutData *data = op_data;
@@ -358,6 +384,8 @@ static void update_data_if_closest_vertex_in_segment(BezTriple *bezt1,
}
for (int k = 0; k <= resolu; k++) {
+ float screen_co[
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list