diff options
author | mano-wii <germano.costa@ig.com.br> | 2018-11-25 22:15:05 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2018-11-26 12:32:03 +0300 |
commit | 9d7b767dd7efe785695fe5ef74e576875c6c9e46 (patch) | |
tree | 8604175d36862b14a4c491187fb420ee0e8a92b7 | |
parent | 36429a5bc99aec3d178fb7c9e0350c82b47bb37a (diff) |
transform_snap_object: fix ray_start_correction in snap to edit_mesh.
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.c | 102 |
1 files changed, 22 insertions, 80 deletions
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 7a17515f5f8..c3a99cc9932 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -230,36 +230,6 @@ static void iter_snap_objects( } } - -static bool walk_parent_bvhroot_cb(const BVHTreeAxisRange *bounds, void *userdata) -{ - BVHTreeRay *ray = userdata; - const float bbmin[3] = {bounds[0].min, bounds[1].min, bounds[2].min}; - const float bbmax[3] = {bounds[0].max, bounds[1].max, bounds[2].max}; - if (!isect_ray_aabb_v3_simple(ray->origin, ray->direction, bbmin, bbmax, &ray->radius, NULL)) { - ray->radius = -1; - } - return false; -} - - -static bool isect_ray_bvhroot_v3(struct BVHTree *tree, const float ray_start[3], const float ray_dir[3], float *depth) -{ - BVHTreeRay ray; - copy_v3_v3(ray.origin, ray_start); - copy_v3_v3(ray.direction, ray_dir); - - BLI_bvhtree_walk_dfs(tree, walk_parent_bvhroot_cb, NULL, NULL, &ray); - - if (ray.radius > 0) { - *depth = ray.radius; - return true; - } - else { - return false; - } -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -395,6 +365,17 @@ static bool raycastMesh( return retval; } } + /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with + * very far away ray_start values (as returned in case of ortho view3d), see T50486, T38358. + */ + if (len_diff > 400.0f) { + len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ + madd_v3_v3fl(ray_start_local, ray_normal_local, len_diff); + local_depth -= len_diff; + } + else { + len_diff = 0.0f; + } SnapObjectData_Mesh *sod = snap_object_data_mesh_get(sctx, ob); @@ -435,32 +416,6 @@ static bool raycastMesh( } } - /* Only use closer ray_start in case of ortho view! In perspective one, ray_start may already - * been *inside* boundbox, leading to snap failures (see T38409). - * Note also ar might be null (see T38435), in this case we assume ray_start is ok! - */ - if (len_diff == 0.0f) { /* do_ray_start_correction */ - /* We *need* a reasonably valid len_diff in this case. - * Get the distance to bvhtree root */ - if (!isect_ray_bvhroot_v3(treedata->tree, ray_start_local, ray_normal_local, &len_diff)) { - return retval; - } - } - /* You need to make sure that ray_start is really far away, - * because even in the Orthografic view, in some cases, - * the ray can start inside the object (see T50486) */ - if (len_diff > 400.0f) { - /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with - * very far away ray_start values (as returned in case of ortho view3d), see T38358. - */ - len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ - madd_v3_v3fl(ray_start_local, ray_normal_local, len_diff); - local_depth -= len_diff; - } - else { - len_diff = 0.0f; - } - float timat[3][3]; /* transpose inverse matrix for normals */ transpose_m3_m4(timat, imat); @@ -564,6 +519,17 @@ static bool raycastEditMesh( return retval; } } + /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with + * very far away ray_start values (as returned in case of ortho view3d), see T50486, T38358. + */ + if (len_diff > 400.0f) { + len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ + madd_v3_v3fl(ray_start_local, ray_normal_local, len_diff); + local_depth -= len_diff; + } + else { + len_diff = 0.0f; + } SnapObjectData_EditMesh *sod = snap_object_data_editmesh_get(sctx, em); @@ -614,30 +580,6 @@ static bool raycastEditMesh( } } - /* Only use closer ray_start in case of ortho view! In perspective one, ray_start - * may already been *inside* boundbox, leading to snap failures (see T38409). - * Note also ar might be null (see T38435), in this case we assume ray_start is ok! - */ - if (sctx->use_v3d && !((RegionView3D *)sctx->v3d_data.ar->regiondata)->is_persp) { /* do_ray_start_correction */ - /* We *need* a reasonably valid len_diff in this case. - * Get the distance to bvhtree root */ - if (!isect_ray_bvhroot_v3(treedata->tree, ray_start_local, ray_normal_local, &len_diff)) { - return retval; - } - /* You need to make sure that ray_start is really far away, - * because even in the Orthografic view, in some cases, - * the ray can start inside the object (see T50486) */ - if (len_diff > 400.0f) { - /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with - * very far away ray_start values (as returned in case of ortho view3d), see T38358. - */ - len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ - madd_v3_v3fl(ray_start_local, ray_normal_local, len_diff); - local_depth -= len_diff; - } - else len_diff = 0.0f; - } - float timat[3][3]; /* transpose inverse matrix for normals */ transpose_m3_m4(timat, imat); |