diff options
author | Germano <germano.costa@ig.com.br> | 2018-05-13 01:10:23 +0300 |
---|---|---|
committer | Germano <germano.costa@ig.com.br> | 2018-05-13 01:10:23 +0300 |
commit | 375c6a7967b18dbc560b9e47bbdf017eac5f57f1 (patch) | |
tree | ef2d32c249ceda732325f6658edaff6a49c258a4 /source/blender/editors/transform | |
parent | 5be0dfe086c7b3f2b705b90059a0d3c377effbf4 (diff) |
Cleanup: transform_snap_object: Remove unused variables and reuse the precalc used to test the distance to the projected bound_box.
Diffstat (limited to 'source/blender/editors/transform')
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.c | 101 |
1 files changed, 38 insertions, 63 deletions
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index ed7ada26bd7..33722f61a2f 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -1199,16 +1199,15 @@ static bool snapCurve( return retval; } - float lpmat[4][4], dist_px_sq; + bool is_persp = snapdata->view_proj == VIEW_PROJ_PERSP; + float dist_px_sq = SQUARE(*dist_px); + 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); - bool is_persp = snapdata->view_proj == VIEW_PROJ_PERSP; - dist_px_sq = SQUARE(*dist_px); - for (Nurb *nu = (use_obedit ? cu->editnurb->nurbs.first : cu->nurb.first); nu; nu = nu->next) { for (int u = 0; u < nu->pntsu; u++) { switch (snapdata->snap_to) { @@ -1432,8 +1431,6 @@ static bool snapMesh( /* return args */ float r_loc[3], float r_no[3]) { -// #define USE_RAY_MIN - bool retval = false; if (snapdata->snap_to == SCE_SNAP_MODE_EDGE) { @@ -1447,39 +1444,20 @@ static bool snapMesh( } } - float imat[4][4]; - float timat[3][3]; /* transpose inverse matrix for normals */ - float ray_normal_local[3]; - - - invert_m4_m4(imat, obmat); - transpose_m3_m4(timat, imat); - - copy_v3_v3(ray_normal_local, snapdata->ray_dir); - - mul_mat3_m4_v3(imat, ray_normal_local); - -#ifdef USE_RAY_MIN - /* local scale in normal direction */ - const float local_scale = normalize_v3(ray_normal_local); -#endif - float lpmat[4][4]; - float ray_org_local[3]; - mul_m4_m4m4(lpmat, snapdata->pmat, obmat); -#ifdef USE_RAY_MIN - const float ray_min_dist = snapdata->depth_range[0] * local_scale; -#endif - copy_v3_v3(ray_org_local, snapdata->ray_origin); - mul_m4_v3(imat, ray_org_local); + + Nearest2dUserData neasrest2d; + dist_squared_to_projected_aabb_precalc( + &neasrest2d.data_precalc, lpmat, snapdata->win_size, snapdata->mval); /* Test BoundBox */ BoundBox *bb = BKE_mesh_boundbox_get(ob); if (bb) { + bool dummy[3] = {true, true, true}; /* In vertex and edges you need to get the pixel distance from ray to BoundBox, see: T46099, T46816 */ - float dist_px_sq = dist_squared_to_projected_aabb_simple( - lpmat, snapdata->win_size, snapdata->mval, bb->vec[0], bb->vec[6]); + float dist_px_sq = dist_squared_to_projected_aabb( + &neasrest2d.data_precalc, bb->vec[0], bb->vec[6], dummy); if (dist_px_sq > SQUARE(*dist_px)) { return retval; @@ -1582,22 +1560,24 @@ static bool snapMesh( * And more... ray_depth is being confused with Z-depth here... (varies only the precision) */ const float ray_depth_max_global = *ray_depth + snapdata->depth_range[0]; - Nearest2dUserData neasrest2d = { - .r_axis_closest = {1.0f, 1.0f, 1.0f}, - .is_persp = snapdata->view_proj == VIEW_PROJ_PERSP, - .depth_range = {snapdata->depth_range[0], ray_depth_max_global}, - .snap_to = snapdata->snap_to, - .userdata = treedata, - .get_vert_co = (Nearest2DGetVertCoCallback)cb_mvert_co_get, - .get_edge_verts_index = (Nearest2DGetEdgeVertsCallback)cb_medge_verts_get, - .get_tri_verts_index = (Nearest2DGetTriVertsCallback)cb_mlooptri_verts_get, - .get_tri_edges_index = (Nearest2DGetTriEdgesCallback)cb_mlooptri_edges_get, - .copy_vert_no = (Nearest2DCopyVertNoCallback)cb_mvert_no_copy, - .dist_px_sq = SQUARE(*dist_px), - .index = -1}; + neasrest2d.r_axis_closest[0] = true; + neasrest2d.r_axis_closest[1] = true; + neasrest2d.r_axis_closest[2] = true; - dist_squared_to_projected_aabb_precalc( - &neasrest2d.data_precalc, lpmat, snapdata->win_size, snapdata->mval); + neasrest2d.is_persp = snapdata->view_proj == VIEW_PROJ_PERSP; + + neasrest2d.depth_range[0] = snapdata->depth_range[0]; + neasrest2d.depth_range[1] = ray_depth_max_global; + + neasrest2d.snap_to = snapdata->snap_to; + neasrest2d.userdata = treedata; + neasrest2d.get_vert_co = (Nearest2DGetVertCoCallback)cb_mvert_co_get; + neasrest2d.get_edge_verts_index = (Nearest2DGetEdgeVertsCallback)cb_medge_verts_get; + neasrest2d.get_tri_verts_index = (Nearest2DGetTriVertsCallback)cb_mlooptri_verts_get; + neasrest2d.get_tri_edges_index = (Nearest2DGetTriEdgesCallback)cb_mlooptri_edges_get; + neasrest2d.copy_vert_no = (Nearest2DCopyVertNoCallback)cb_mvert_no_copy; + neasrest2d.dist_px_sq = SQUARE(*dist_px); + neasrest2d.index = -1; if (bvhtree[1]) { @@ -1622,6 +1602,11 @@ static bool snapMesh( } if (neasrest2d.index != -1) { + float imat[4][4]; + float timat[3][3]; /* transpose inverse matrix for normals */ + invert_m4_m4(imat, obmat); + transpose_m3_m4(timat, imat); + copy_v3_v3(r_loc, neasrest2d.co); mul_m4_v3(obmat, r_loc); if (r_no) { @@ -1659,17 +1644,6 @@ static bool snapEditMesh( } } - float imat[4][4]; - float timat[3][3]; /* transpose inverse matrix for normals */ - float ray_normal_local[3]; - - invert_m4_m4(imat, obmat); - transpose_m3_m4(timat, imat); - - copy_v3_v3(ray_normal_local, snapdata->ray_dir); - - mul_mat3_m4_v3(imat, ray_normal_local); - SnapObjectData_EditMesh *sod = NULL; BVHTreeFromEditMesh *treedata = NULL; @@ -1741,12 +1715,8 @@ static bool snapEditMesh( return retval; } - float ray_org_local[3]; - copy_v3_v3(ray_org_local, snapdata->ray_origin); - mul_m4_v3(imat, ray_org_local); - Nearest2dUserData neasrest2d = { - .r_axis_closest = {1.0f, 1.0f, 1.0f}, + .r_axis_closest = {true, true, true}, .is_persp = snapdata->view_proj == VIEW_PROJ_PERSP, .depth_range = {snapdata->depth_range[0], *ray_depth + snapdata->depth_range[0]}, .snap_to = snapdata->snap_to, @@ -1771,6 +1741,11 @@ static bool snapEditMesh( cb_walk_parent_snap_project, cb_walk_leaf, cb_nearest_walk_order, &neasrest2d); if (neasrest2d.index != -1) { + float imat[4][4]; + float timat[3][3]; /* transpose inverse matrix for normals */ + invert_m4_m4(imat, obmat); + transpose_m3_m4(timat, imat); + copy_v3_v3(r_loc, neasrest2d.co); mul_m4_v3(obmat, r_loc); if (r_no) { |