Fix #114596: Face Nearest with steps sometimes breaks

When multiple steps are tested, we cannot depend on the distance
calculated for `nearest.dist_sq`, as it reduces with each step.
This commit is contained in:
Germano Cavalcante
2023-11-07 18:30:34 -03:00
parent 13b1d8d5e1
commit 7f89063161
2 changed files with 7 additions and 1 deletions

View File

@@ -723,6 +723,12 @@ bool nearest_world_tree(SnapObjectContext *sctx,
if (sctx->runtime.params.keep_on_same_target) {
r_nearest->dist_sq = original_distance;
}
else if (sctx->runtime.params.face_nearest_steps > 1) {
/* Recalculate the distance.
* When multiple steps are tested, we cannot depend on the distance calculated for
* `nearest.dist_sq`, as it reduces with each step. */
r_nearest->dist_sq = math::distance_squared(sctx->runtime.curr_co, co);
}
return true;
}

View File

@@ -202,7 +202,7 @@ static bool nearest_world_mesh(SnapObjectContext *sctx,
}
BVHTreeNearest nearest{};
nearest.dist_sq = sctx->ret.dist_px_sq;
nearest.dist_sq = sctx->ret.dist_nearest_sq;
if (nearest_world_tree(
sctx, treedata.tree, treedata.nearest_callback, obmat, &treedata, &nearest)) {
SnapData::register_result(sctx, ob_eval, &me_eval->id, obmat, &nearest);