Fix #111548: Snap only working on some surface curve control points

The loop was ignoring ` nu->pntsv` in this case, resulting in only the
first point of each row being used for snapping.

This commit also simplifies the code by removing the no-snap limitation
when the curve only has 1 point.

This limitation existed because the curve is not visible in this case.

But this is contradictory for when the curve has loose points (which
are also not visible).
This commit is contained in:
Germano Cavalcante
2023-08-30 14:48:09 -03:00
parent 8c193180d3
commit a0b232c80d

View File

@@ -20,6 +20,7 @@
#include "transform_snap_object.hh"
using blender::float4x4;
using blender::IndexRange;
eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float4x4 &obmat)
{
@@ -50,9 +51,9 @@ eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float4x4 &ob
0;
LISTBASE_FOREACH (Nurb *, nu, (use_obedit ? &cu->editnurb->nurbs : &cu->nurb)) {
for (int u = 0; u < nu->pntsu; u++) {
if (use_obedit) {
if (nu->bezt) {
if (nu->bezt) {
for (int u : blender::IndexRange(nu->pntsu)) {
if (use_obedit) {
if (nu->bezt[u].hide) {
/* Skip hidden. */
continue;
@@ -62,7 +63,6 @@ eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float4x4 &ob
if (is_selected && skip_selected) {
continue;
}
has_snap |= nearest2d.snap_point(nu->bezt[u].vec[1]);
/* Don't snap if handle is selected (moving),
* or if it is aligning to a moving handle. */
@@ -78,7 +78,12 @@ eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float4x4 &ob
has_snap |= nearest2d.snap_point(nu->bezt[u].vec[2]);
}
}
else {
has_snap |= nearest2d.snap_point(nu->bezt[u].vec[1]);
}
}
else if (nu->bp) {
for (int u : blender::IndexRange(nu->pntsu * nu->pntsv)) {
if (use_obedit) {
if (nu->bp[u].hide) {
/* Skip hidden. */
continue;
@@ -88,20 +93,8 @@ eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float4x4 &ob
if (is_selected && skip_selected) {
continue;
}
has_snap |= nearest2d.snap_point(nu->bp[u].vec);
}
}
else {
/* Curve is not visible outside editmode if nurb length less than two. */
if (nu->pntsu > 1) {
if (nu->bezt) {
has_snap |= nearest2d.snap_point(nu->bezt[u].vec[1]);
}
else {
has_snap |= nearest2d.snap_point(nu->bp[u].vec);
}
}
has_snap |= nearest2d.snap_point(nu->bp[u].vec);
}
}
}