Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDilith Jayakody <dilithjay@gmail.com>2022-04-03 20:07:22 +0300
committerDilith Jayakody <dilithjay@gmail.com>2022-04-03 20:07:22 +0300
commit336082acba51b3a237338e2cc316b04320c05ad4 (patch)
tree1efef10ea6854931bbb2c0f2916eba1e2fbfe8b7 /source/blender/editors/curve/editcurve.c
parent1cdf8b19e5885c26f7341a0c21d243401a89d50e (diff)
Curves: Curve Pen
This tool can be used to rapidly edit curves. The current set of functionalities for Bezier splines are as follows: The functionalities are divided into three versions of the operator: * Left-Click * Ctrl + Left-Click * Double Click All current functionalities and their defaults are as follows: * Extrude Point: Add a point connected to an existing point. Enabled for Left-Click. * Extrude Handle Type: Type of the handles of the extruded points. Can be either Vector or Auto. Defaults to Vector. * Delete Point: Delete existing point. Enabled for Ctrl + Left-Click. * Insert Point: Insert a point into a curve segment. Enabled for Ctrl + Left-Click. * Move Segment: Move curve segment. Enabled for Left-Click. * Select Point: Select a single point or handle at a time. Enabled for Left-Click. * Move point: Move existing points or handles. Enabled for Left-Click. * Close Spline: Close spline by clicking the endpoints consecutively. Defaults to True. * Close Spline Method: The condition for Close Spline to activate. Can be one of None, On Press or On Click. Defaults to On Click for Left-Click and None for the others. * None: Functionality is turned off. * On Press: Activate on mouse down. This makes it possible to move the handles by dragging immediately after closing the spline. * On Click: Activate on mouse release. This makes it possible to avoid triggering the Close Spline functionality by dragging afterward. * Toggle Vector: Toggle handle between Vector and Auto handle types. Enabled for Double Click on a handle. * Cycle Handle Type: Cycle between all four handle types. Enabled for Double Click on the middle point of a Bezier point. The keybindings for the following functionalities can be adjusted from the modal keymap * Free-Align Toggle: Toggle between Free and Align handle types. Defaults to Left Shift. Activated on hold. * Move Adjacent Handle: Move the closer handle of the adjacent vertex. Defaults to Left Ctrl. Activated on hold. * Move Entire: Move the entire point by moving by grabbing on the handle Defaults to Spacebar. Activated on hold. * Link Handles: Mirror the movement of one handle onto the other. Defaults to Right Ctrl. Activated on press. * Lock Handle Angle: Move the handle along its current angle. Defaults to Left Alt. Activated on hold. All the above functionalities, except for Move Segment and those that work with handles, work similarly in the case of Poly and NURBS splines. Reviewed By: HooglyBoogly, weasel, campbellbarton Differential Revision: http://developer.blender.org/D12155
Diffstat (limited to 'source/blender/editors/curve/editcurve.c')
-rw-r--r--source/blender/editors/curve/editcurve.c142
1 files changed, 79 insertions, 63 deletions
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 38c14391273..c7c2468a6e4 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -4727,6 +4727,14 @@ bool ED_curve_editnurb_select_pick(bContext *C,
const int mval[2],
const struct SelectPick_Params *params)
{
+ return ED_curve_editnurb_select_pick_ex(C, mval, 1.0f, params);
+}
+
+bool ED_curve_editnurb_select_pick_ex(bContext *C,
+ const int mval[2],
+ const float sel_dist_mul,
+ const struct SelectPick_Params *params)
+{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc;
Nurb *nu;
@@ -4740,7 +4748,8 @@ bool ED_curve_editnurb_select_pick(bContext *C,
ED_view3d_viewcontext_init(C, &vc, depsgraph);
copy_v2_v2_int(vc.mval, mval);
- bool found = ED_curve_pick_vert(&vc, 1, &nu, &bezt, &bp, &hand, &basact);
+ bool found = ED_curve_pick_vert_ex(
+ &vc, 1, sel_dist_mul * ED_view3d_select_dist_px(), &nu, &bezt, &bp, &hand, &basact);
if (params->sel_op == SEL_OP_SET) {
if ((found && params->select_passthrough) &&
@@ -5344,10 +5353,7 @@ static bool ed_editcurve_extrude(Curve *cu, EditNurb *editnurb, View3D *v3d)
/** \name Add Vertex Operator
* \{ */
-static int ed_editcurve_addvert(Curve *cu,
- EditNurb *editnurb,
- View3D *v3d,
- const float location_init[3])
+int ed_editcurve_addvert(Curve *cu, EditNurb *editnurb, View3D *v3d, const float location_init[3])
{
float center[3];
float temp[3];
@@ -5719,7 +5725,7 @@ void CURVE_OT_extrude(wmOperatorType *ot)
/** \name Make Cyclic Operator
* \{ */
-static bool curve_toggle_cyclic(View3D *v3d, ListBase *editnurb, int direction)
+bool curve_toggle_cyclic(View3D *v3d, ListBase *editnurb, int direction)
{
BezTriple *bezt;
BPoint *bp;
@@ -6502,6 +6508,70 @@ static bool test_bezt_is_sel_any(const void *bezt_v, void *user_data)
return BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt);
}
+void ed_dissolve_bez_segment(BezTriple *bezt_prev,
+ BezTriple *bezt_next,
+ const Nurb *nu,
+ const Curve *cu,
+ const int span_len,
+ const int span_step[2])
+{
+ int i_span_edge_len = span_len + 1;
+ const int dims = 3;
+
+ const int points_len = ((cu->resolu - 1) * i_span_edge_len) + 1;
+ float *points = MEM_mallocN(points_len * dims * sizeof(float), __func__);
+ float *points_stride = points;
+ const int points_stride_len = (cu->resolu - 1);
+
+ for (int segment = 0; segment < i_span_edge_len; segment++) {
+ BezTriple *bezt_a = &nu->bezt[mod_i((span_step[0] + segment) - 1, nu->pntsu)];
+ BezTriple *bezt_b = &nu->bezt[mod_i((span_step[0] + segment), nu->pntsu)];
+
+ for (int axis = 0; axis < dims; axis++) {
+ BKE_curve_forward_diff_bezier(bezt_a->vec[1][axis],
+ bezt_a->vec[2][axis],
+ bezt_b->vec[0][axis],
+ bezt_b->vec[1][axis],
+ points_stride + axis,
+ points_stride_len,
+ dims * sizeof(float));
+ }
+
+ points_stride += dims * points_stride_len;
+ }
+
+ BLI_assert(points_stride + dims == points + (points_len * dims));
+
+ float tan_l[3], tan_r[3], error_sq_dummy;
+ uint error_index_dummy;
+
+ sub_v3_v3v3(tan_l, bezt_prev->vec[1], bezt_prev->vec[2]);
+ normalize_v3(tan_l);
+ sub_v3_v3v3(tan_r, bezt_next->vec[0], bezt_next->vec[1]);
+ normalize_v3(tan_r);
+
+ curve_fit_cubic_to_points_single_fl(points,
+ points_len,
+ NULL,
+ dims,
+ FLT_EPSILON,
+ tan_l,
+ tan_r,
+ bezt_prev->vec[2],
+ bezt_next->vec[0],
+ &error_sq_dummy,
+ &error_index_dummy);
+
+ if (!ELEM(bezt_prev->h2, HD_FREE, HD_ALIGN)) {
+ bezt_prev->h2 = (bezt_prev->h2 == HD_VECT) ? HD_FREE : HD_ALIGN;
+ }
+ if (!ELEM(bezt_next->h1, HD_FREE, HD_ALIGN)) {
+ bezt_next->h1 = (bezt_next->h1 == HD_VECT) ? HD_FREE : HD_ALIGN;
+ }
+
+ MEM_freeN(points);
+}
+
static int curve_dissolve_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain = CTX_data_main(C);
@@ -6523,8 +6593,8 @@ static int curve_dissolve_exec(bContext *C, wmOperator *UNUSED(op))
LISTBASE_FOREACH (Nurb *, nu, editnurb) {
if ((nu->type == CU_BEZIER) && (nu->pntsu > 2)) {
- uint span_step[2] = {nu->pntsu, nu->pntsu};
- uint span_len;
+ int span_step[2] = {nu->pntsu, nu->pntsu};
+ int span_len;
while (BLI_array_iter_span(nu->bezt,
nu->pntsu,
@@ -6537,61 +6607,7 @@ static int curve_dissolve_exec(bContext *C, wmOperator *UNUSED(op))
BezTriple *bezt_prev = &nu->bezt[mod_i(span_step[0] - 1, nu->pntsu)];
BezTriple *bezt_next = &nu->bezt[mod_i(span_step[1] + 1, nu->pntsu)];
- int i_span_edge_len = span_len + 1;
- const uint dims = 3;
-
- const uint points_len = ((cu->resolu - 1) * i_span_edge_len) + 1;
- float *points = MEM_mallocN(points_len * dims * sizeof(float), __func__);
- float *points_stride = points;
- const int points_stride_len = (cu->resolu - 1);
-
- for (int segment = 0; segment < i_span_edge_len; segment++) {
- BezTriple *bezt_a = &nu->bezt[mod_i((span_step[0] + segment) - 1, nu->pntsu)];
- BezTriple *bezt_b = &nu->bezt[mod_i((span_step[0] + segment), nu->pntsu)];
-
- for (int axis = 0; axis < dims; axis++) {
- BKE_curve_forward_diff_bezier(bezt_a->vec[1][axis],
- bezt_a->vec[2][axis],
- bezt_b->vec[0][axis],
- bezt_b->vec[1][axis],
- points_stride + axis,
- points_stride_len,
- dims * sizeof(float));
- }
-
- points_stride += dims * points_stride_len;
- }
-
- BLI_assert(points_stride + dims == points + (points_len * dims));
-
- float tan_l[3], tan_r[3], error_sq_dummy;
- uint error_index_dummy;
-
- sub_v3_v3v3(tan_l, bezt_prev->vec[1], bezt_prev->vec[2]);
- normalize_v3(tan_l);
- sub_v3_v3v3(tan_r, bezt_next->vec[0], bezt_next->vec[1]);
- normalize_v3(tan_r);
-
- curve_fit_cubic_to_points_single_fl(points,
- points_len,
- NULL,
- dims,
- FLT_EPSILON,
- tan_l,
- tan_r,
- bezt_prev->vec[2],
- bezt_next->vec[0],
- &error_sq_dummy,
- &error_index_dummy);
-
- if (!ELEM(bezt_prev->h2, HD_FREE, HD_ALIGN)) {
- bezt_prev->h2 = (bezt_prev->h2 == HD_VECT) ? HD_FREE : HD_ALIGN;
- }
- if (!ELEM(bezt_next->h1, HD_FREE, HD_ALIGN)) {
- bezt_next->h1 = (bezt_next->h1 == HD_VECT) ? HD_FREE : HD_ALIGN;
- }
-
- MEM_freeN(points);
+ ed_dissolve_bez_segment(bezt_prev, bezt_next, nu, cu, span_len, span_step);
}
}
}