diff options
-rw-r--r-- | source/blender/editors/mesh/editmesh_knife.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 165af62c715..30d8918d85c 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -182,6 +182,7 @@ typedef struct KnifeTool_OpData { BLI_mempool *refs; float projmat[4][4]; + float projmat_inv[4][4]; KnifeColors colors; @@ -251,6 +252,27 @@ static void knife_project_v2(const KnifeTool_OpData *kcd, const float co[3], flo ED_view3d_project_float_v2_m4(kcd->ar, co, sco, (float (*)[4])kcd->projmat); } +/* use when lambda is in screen-space */ +static void knife_interp_v3_v3v3( + const KnifeTool_OpData *kcd, + float r_co[3], const float v1[3], const float v2[3], float lambda_ss) +{ + if (kcd->is_ortho) { + interp_v3_v3v3(r_co, v1, v2, lambda_ss); + } + else { + /* transform into screen-space, interp, then transform back */ + float v1_ss[3], v2_ss[3]; + + mul_v3_project_m4_v3(v1_ss, (float (*)[4])kcd->projmat, v1); + mul_v3_project_m4_v3(v2_ss, (float (*)[4])kcd->projmat, v2); + + interp_v3_v3v3(r_co, v1_ss, v2_ss, lambda_ss); + + mul_project_m4_v3((float (*)[4])kcd->projmat_inv, r_co); + } +} + static void knife_pos_data_clear(KnifePosData *kpd) { zero_v3(kpd->co); @@ -1682,8 +1704,8 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo } } - /* now we have 'lambda' calculated */ - interp_v3_v3v3(test_cagep, kfe->v1->cageco, kfe->v2->cageco, lambda); + /* now we have 'lambda' calculated (in screen-space) */ + knife_interp_v3_v3v3(kcd, test_cagep, kfe->v1->cageco, kfe->v2->cageco, lambda); if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) { /* check we're in the view */ @@ -2597,7 +2619,7 @@ static void knife_recalc_projmat(KnifeTool_OpData *kcd) { invert_m4_m4(kcd->ob->imat, kcd->ob->obmat); ED_view3d_ob_project_mat_get(kcd->ar->regiondata, kcd->ob, kcd->projmat); - //mul_m4_m4m4(kcd->projmat, kcd->vc.rv3d->winmat, kcd->vc.rv3d->viewmat); + invert_m4_m4(kcd->projmat_inv, kcd->projmat); kcd->is_ortho = ED_view3d_clip_range_get(kcd->vc.v3d, kcd->vc.rv3d, &kcd->clipsta, &kcd->clipend, true); |