From 8cc418b6fc00372bbbc3bca3ad3e7c3e44cd40dd Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Fri, 30 Jun 2023 12:44:35 -0300 Subject: [PATCH] Fix Snap to Face Nearest not working properly if transformed Local `init_co` and `curr_co` were being calculated incorrectly. --- .../editors/transform/transform_snap_object_editmesh.cc | 5 +++-- .../blender/editors/transform/transform_snap_object_mesh.cc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/transform/transform_snap_object_editmesh.cc b/source/blender/editors/transform/transform_snap_object_editmesh.cc index d40d5e9463e..f0088035e69 100644 --- a/source/blender/editors/transform/transform_snap_object_editmesh.cc +++ b/source/blender/editors/transform/transform_snap_object_editmesh.cc @@ -416,8 +416,9 @@ static bool nearest_world_editmesh(SnapCache_EditMesh *em_cache, return false; } - float3 init_co = math::transform_point(obmat, float3(sctx->runtime.init_co)); - float3 curr_co = math::transform_point(obmat, float3(sctx->runtime.curr_co)); + float4x4 imat = math::invert(obmat); + float3 init_co = math::transform_point(imat, float3(sctx->runtime.init_co)); + float3 curr_co = math::transform_point(imat, float3(sctx->runtime.curr_co)); BVHTreeNearest nearest{}; nearest.dist_sq = sctx->ret.dist_px_sq; diff --git a/source/blender/editors/transform/transform_snap_object_mesh.cc b/source/blender/editors/transform/transform_snap_object_mesh.cc index e53f97e6bc3..af77ad631ce 100644 --- a/source/blender/editors/transform/transform_snap_object_mesh.cc +++ b/source/blender/editors/transform/transform_snap_object_mesh.cc @@ -231,8 +231,9 @@ static bool nearest_world_mesh(SnapObjectContext *sctx, return false; } - float3 init_co = math::transform_point(obmat, float3(sctx->runtime.init_co)); - float3 curr_co = math::transform_point(obmat, float3(sctx->runtime.curr_co)); + float4x4 imat = math::invert(obmat); + float3 init_co = math::transform_point(imat, float3(sctx->runtime.init_co)); + float3 curr_co = math::transform_point(imat, float3(sctx->runtime.curr_co)); BVHTreeNearest nearest{}; nearest.dist_sq = sctx->ret.dist_px_sq;