Commit: 2d6bfb5b63cdb92422e6b6d8e2ff58f844b7ed94 Author: Germano Date: Fri May 18 11:40:32 2018 -0300 Branches: blender2.8 https://developer.blender.org/rB2d6bfb5b63cdb92422e6b6d8e2ff58f844b7ed94
Transform: Improve the hierarchy in the choice of snapped elements in the mixed snap. To snap to small edges in 3d_view is no longer obfuscated by vertices if then is also enabled. =================================================================== M source/blender/editors/transform/transform_snap_object.c =================================================================== diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index c24f3bf01f8..26288b162f7 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -80,7 +80,7 @@ enum eViewProj { }; typedef struct SnapData { - short snap_to; + short snap_to_flag; float mval[2]; float pmat[4][4]; /* perspective matrix */ float win_size[2];/* win x and y */ @@ -933,128 +933,6 @@ static bool test_projected_edge_dist( is_persp, near_co, dist_px_sq, r_co); } -static bool snapMeshPolygon( - SnapObjectContext *sctx, SnapData *snapdata, - Object *ob, float obmat[4][4], - /* read/write args */ - float *dist_px, - /* return args */ - float r_loc[3], float r_no[3], int *r_index) -{ - bool retval = false; - - float lpmat[4][4], dist_px_sq = SQUARE(*dist_px); - mul_m4_m4m4(lpmat, snapdata->pmat, obmat); - - struct DistProjectedAABBPrecalc neasrest_precalc; - dist_squared_to_projected_aabb_precalc( - &neasrest_precalc, lpmat, snapdata->win_size, snapdata->mval); - - float tobmat[4][4], clip_planes_local[MAX_CLIPPLANE_LEN][4]; - transpose_m4_m4(tobmat, obmat); - for (int i = snapdata->clip_plane_len; i--;) { - mul_v4_m4v4(clip_planes_local[i], tobmat, snapdata->clip_plane[i]); - } - - bool is_persp = snapdata->view_proj == VIEW_PROJ_PERSP; - - SnapObjectData *sod = BLI_ghash_lookup(sctx->cache.object_map, ob); - BLI_assert(sod != NULL); - - if (sod->type == SNAP_MESH) { - Mesh *me = ob->data; - MPoly *mp = &me->mpoly[*r_index]; - - const MLoop *ml = &me->mloop[mp->loopstart]; - for (int i = mp->totloop; i--; ml++) { - if (snapdata->snap_to == SCE_SNAP_MODE_VERTEX) { - const MVert *vert = &me->mvert[ml->v]; - if (test_projected_vert_dist( - &neasrest_precalc, - clip_planes_local, snapdata->clip_plane_len, - is_persp, vert->co, - &dist_px_sq, r_loc)) - { - normal_short_to_float_v3(r_no, vert->no); - *r_index = ml->v; - retval = true; - } - } - else { - float co_pair[2][3]; - const MEdge *edge = &me->medge[ml->e]; - copy_v3_v3(co_pair[0], me->mvert[edge->v1].co); - copy_v3_v3(co_pair[1], me->mvert[edge->v2].co); - if (test_projected_edge_dist( - &neasrest_precalc, - clip_planes_local, snapdata->clip_plane_len, - is_persp, co_pair[0], co_pair[1], - &dist_px_sq, r_loc)) - { - sub_v3_v3v3(r_no, co_pair[0], co_pair[1]); - *r_index = ml->e; - retval = true; - } - } - } - } - else { - BLI_assert(sod->type == SNAP_EDIT_MESH); - - BMEditMesh *em = BKE_editmesh_from_object(ob); - BM_mesh_elem_table_ensure(em->bm, BM_FACE); - BMFace *f = BM_face_at_index(em->bm, *r_index); - - BMLoop *l_iter, *l_first; - l_iter = l_first = BM_FACE_FIRST_LOOP(f); - - do { - if (snapdata->snap_to == SCE_SNAP_MODE_VERTEX) { - const float *co = l_iter->v->co; - if (test_projected_vert_dist( - &neasrest_precalc, - clip_planes_local, snapdata->clip_plane_len, - is_persp, co, - &dist_px_sq, r_loc)) - { - copy_v3_v3(r_no, l_iter->v->no); - *r_index = BM_elem_index_get(l_iter->v); - retval = true; - } - } - else { - float co_pair[2][3]; - copy_v3_v3(co_pair[0], l_iter->e->v1->co); - copy_v3_v3(co_pair[1], l_iter->e->v2->co); - if (test_projected_edge_dist( - &neasrest_precalc, - clip_planes_local, snapdata->clip_plane_len, - is_persp, co_pair[0], co_pair[1], - &dist_px_sq, r_loc)) - { - sub_v3_v3v3(r_no, co_pair[0], co_pair[1]); - *r_index = BM_elem_index_get(l_iter->e); - retval = true; - } - } - } while ((l_iter = l_iter->next) != l_first); - } - - if (retval) { - float imat[4][4]; - invert_m4_m4(imat, obmat); - - mul_m4_v3(obmat, r_loc); - mul_transposed_mat3_m4_v3(obmat, r_no); - normalize_v3(r_no); - - *dist_px = sqrtf(dist_px_sq); - - return true; - } - return false; -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -1069,7 +947,6 @@ typedef void (*Nearest2DCopyVertNoCallback)(const int index, float r_no[3], void typedef struct Nearest2dUserData { bool is_persp; - short snap_to; void *userdata; Nearest2DGetVertCoCallback get_vert_co; @@ -1081,7 +958,7 @@ typedef struct Nearest2dUserData { } Nearest2dUserData; -static void cb_walk_leaf_snap_vert( +static void cb_snap_vert( void *userdata, int index, const struct DistProjectedAABBPrecalc *precalc, const float (*clip_plane)[4], const int clip_plane_len, @@ -1105,7 +982,7 @@ static void cb_walk_leaf_snap_vert( } } -static void cb_walk_leaf_snap_edge( +static void cb_snap_edge( void *userdata, int index, const struct DistProjectedAABBPrecalc *precalc, const float (*clip_plane)[4], const int clip_plane_len, @@ -1116,37 +993,68 @@ static void cb_walk_leaf_snap_edge( int vindex[2]; data->get_edge_verts_index(index, vindex, data->userdata); - if (data->snap_to == SCE_SNAP_MODE_EDGE) { - const float *v_pair[2]; - data->get_vert_co(vindex[0], &v_pair[0], data->userdata); - data->get_vert_co(vindex[1], &v_pair[1], data->userdata); - - if (test_projected_edge_dist( - precalc, - clip_plane, - clip_plane_len, - data->is_persp, - v_pair[0], v_pair[1], - &nearest->dist_sq, - nearest->co)) - { - sub_v3_v3v3(nearest->no, v_pair[0], v_pair[1]); - nearest->index = index; + const float *v_pair[2]; + data->get_vert_co(vindex[0], &v_pair[0], data->userdata); + data->get_vert_co(vindex[1], &v_pair[1], data->userdata); + + if (test_projected_edge_dist( + precalc, + clip_plane, + clip_plane_len, + data->is_persp, + v_pair[0], v_pair[1], + &nearest->dist_sq, + nearest->co)) + { + sub_v3_v3v3(nearest->no, v_pair[0], v_pair[1]); + nearest->index = index; + } +} + +static void cb_snap_edge_verts( + void *userdata, int index, + const struct DistProjectedAABBPrecalc *precalc, + const float (*clip_plane)[4], const int clip_plane_len, + BVHTreeNearest *nearest) +{ + struct Nearest2dUserData *data = userdata; + + int vindex[2]; + data->get_edge_verts_index(index, vindex, data->userdata); + + for (int i = 2; i--;) { + if (vindex[i] == nearest->index) { + continue; } + cb_snap_vert( + userdata, vindex[i], precalc, + clip_plane, clip_plane_len, nearest); } - else { - for (int i = 0; i < 2; i++) { - if (vindex[i] == nearest->index) { +} + +static void cb_snap_tri_edges( + void *userdata, int index, + const struct DistProjectedAABBPrecalc *precalc, + const float (*clip_plane)[4], const int clip_plane_len, + BVHTreeNearest *nearest) +{ + struct Nearest2dUserData *data = userdata; + + int eindex[3]; + data->get_tri_edges_index(index, eindex, data->userdata); + for (int i = 3; i--;) { + if (eindex[i] != -1) { + if (eindex[i] == nearest->index) { continue; } - cb_walk_leaf_snap_vert( - userdata, vindex[i], precalc, + cb_snap_edge( + userdata, eindex[i], precalc, clip_plane, clip_plane_len, nearest); } } } -static void cb_walk_leaf_snap_tri( +static void cb_snap_tri_verts( void *userdata, int index, const struct DistProjectedAABBPrecalc *precalc, const float (*clip_plane)[4], const int clip_plane_len, @@ -1154,31 +1062,15 @@ static void cb_walk_leaf_snap_tri( { struct Nearest2dUserData *data = userdata; - if (data->snap_to == SCE_SNAP_MODE_EDGE) { - int eindex[3]; - data->get_tri_edges_index(index, eindex, data->userdata); - for (int i = 0; i < 3; i++) { - if (eindex[i] != -1) { - if (eindex[i] == nearest->index) { - continue; - } - cb_walk_leaf_snap_edge( - userdata, eindex[i], precalc, - clip_plane, clip_plane_len, nearest); - } - } - } - else { - int vindex[3]; - data->get_tri_verts_index(index, vindex, data->userdata); - for (int i = 0; i < 3; i++) { - if (vindex[i] == nearest->index) { - continue; - } - cb_walk_leaf_snap_vert( - userdata, vindex[i], precalc, - clip_plane, clip_plane_len, nearest); + int vindex[3]; + data->get_tri_verts_index(index, vindex, data->userdata); + for (int i = 3; i--;) { + if (vindex[i] == nearest->index) { + continue; } + cb_snap_vert( + userdata, vindex[i], precalc, + clip_plane, clip_plane_len, nearest); } } @@ -1188,7 +1080,236 @@ static void cb_walk_leaf_snap_tri( /** \name Internal Object Snapping API * \{ */ -static bool snapArmature( +static short snap_mesh_polygon( + SnapObjectContext *sctx, SnapData *snapdata, + Object *ob, float obmat[4][4], + /* read/write args */ + float *dist_px, + /* return args */ + float r_loc[3], float r_no[3], int *r_index) +{ + short elem = 0; + + float lpmat[4][4]; + mul_m4_m4m4(lpmat, snapdata->pmat, obmat); + + struct DistProjectedAABBPrecalc neasrest_precalc; + dist_squared_to_projected_aabb_precalc( + &neasrest_precalc, lpmat, snapdata->win_size, snapdata->mval); + + float tobmat[4][4], clip_planes_local[MAX_CLIPPLANE_LEN][4]; + transpose_m4_m4(tobmat, obmat); + for (int i = snapdata->clip_plane_len; i--;) { + mul_v4_m4v4(clip_planes_local[i], tobmat, snapdata->clip_plane[i]); + } + + Nearest2dUserData nearest2d = { + .is_persp = snapdata->view_proj == VIEW_PROJ_PERSP, + }; + + BVHTreeNearest nearest = { + .index = -1, + .dist_sq = SQUARE(*dist_px), + }; + + SnapObjectData *sod = BLI_ghash_lookup(sctx->cache.object_map, ob); + BLI_assert(sod != NULL); + + if (sod->type == SNAP_MESH) { + BVHTreeFromMesh *treedata = &((SnapObjectData_Mesh *)sod)->treedata; + + nearest2d.userdata = treedata; + nearest2d.get_vert_co = (Nearest2DGetVertCoCallback)cb_mvert_co_get; + nearest2d.get_edge_verts_index = (Nearest2DGetEdgeVertsCallback)cb_medge_verts_get; + nearest2d.copy_vert_no = (Neares @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs