diff options
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 82 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_ruler.c | 62 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_select.c | 33 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_walk.c | 51 |
5 files changed, 85 insertions, 145 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 08f2961d1b3..f636a07b064 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -5167,85 +5167,3 @@ void ED_view3D_lock_clear(View3D *v3d) v3d->ob_centre_cursor = false; v3d->flag2 &= ~V3D_LOCK_CAMERA; } - -/** - * Convenience function for snap ray-casting. - * - * Given a ray, cast it into the scene (snapping to faces). - * - * \return Snap success - */ -bool ED_view3d_snap_from_ray( - Scene *scene, - const float ray_start[3], const float ray_normal[3], - float r_co[3]) -{ - float r_no_dummy[3]; - float ray_dist = BVH_RAYCAST_DIST_MAX; - bool ret; - - struct Object *obedit = scene->obedit; - - /* try snap edge, then face if it fails */ - ret = snapObjectsRayEx( - scene, NULL, NULL, NULL, obedit, - NULL, SNAP_ALL, SCE_SNAP_MODE_FACE, - ray_start, ray_normal, &ray_dist, - r_co, r_no_dummy, NULL, NULL, - NULL, NULL); - - return ret; -} - -/** - * Convenience function for performing snapping. - * - * Given a 2D region value, snap to vert/edge/face. - * - * \param mval: Screenspace coordinate. - * \param dist_px: Maximum distance to snap (in pixels). - * \param use_depth: Snap to the closest element, use when using more than one snap type. - * \param use_obedit: Use editmode cage. - * \param use_vert: Snap to verts. - * \param use_edge: Snap to edges. - * \param use_face: Snap to faces. - * \param r_co: hit location. - * \param r_no: hit normal (optional). - * \return Snap success - */ -bool ED_view3d_snap_from_region( - Scene *scene, View3D *v3d, ARegion *ar, - const float mval[2], float dist_px, - bool use_depth, bool use_obedit, - bool use_vert, bool use_edge, bool use_face, - float r_co[3], float r_no[3]) -{ - float r_no_dummy[3]; - float ray_dist = BVH_RAYCAST_DIST_MAX; - bool is_hit = false; - float *r_no_ptr = r_no ? r_no : r_no_dummy; - - struct Object *obedit = use_obedit ? scene->obedit : NULL; - const int elem_type[3] = {SCE_SNAP_MODE_VERTEX, SCE_SNAP_MODE_EDGE, SCE_SNAP_MODE_FACE}; - const bool elem_test[3] = {use_vert, use_edge, use_face}; - - BLI_assert(use_vert || use_edge || use_face); - - for (int i = 0; i < 3; i++) { - if (elem_test[i] && (is_hit == false || use_depth)) { - if (use_depth == false) { - ray_dist = BVH_RAYCAST_DIST_MAX; - } - if (snapObjectsEx( - scene, v3d, ar, NULL, obedit, - mval, SNAP_ALL, elem_type[i], - &ray_dist, - r_co, r_no_ptr, &dist_px)) - { - is_hit = true; - } - } - } - - return is_hit; -} diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index a5411da131b..c30e688f1e7 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -44,7 +44,7 @@ #include "BLI_utildefines.h" #include "BKE_appdir.h" -#include "BKE_blender.h" +#include "BKE_blender_copybuffer.h" #include "BKE_context.h" #include "BKE_main.h" #include "BKE_report.h" diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c index 198cc3e5703..26eb707624a 100644 --- a/source/blender/editors/space_view3d/view3d_ruler.c +++ b/source/blender/editors/space_view3d/view3d_ruler.c @@ -46,6 +46,7 @@ #include "ED_screen.h" #include "ED_view3d.h" +#include "ED_transform.h" #include "ED_space_api.h" #include "BLF_api.h" @@ -109,6 +110,8 @@ typedef struct RulerInfo { int state; float drag_start_co[3]; + struct SnapObjectContext *snap_context; + /* wm state */ wmWindow *win; ScrArea *sa; @@ -128,6 +131,7 @@ static RulerItem *ruler_item_add(RulerInfo *ruler_info) static void ruler_item_remove(RulerInfo *ruler_info, RulerItem *ruler_item) { BLI_remlink(&ruler_info->items, ruler_item); + MEM_freeN(ruler_item); } @@ -632,6 +636,9 @@ static void view3d_ruler_end(const struct bContext *UNUSED(C), RulerInfo *ruler_ static void view3d_ruler_free(RulerInfo *ruler_info) { BLI_freelistN(&ruler_info->items); + + ED_transform_snap_object_context_destroy(ruler_info->snap_context); + MEM_freeN(ruler_info); } @@ -642,11 +649,12 @@ static void view3d_ruler_item_project(RulerInfo *ruler_info, float r_co[3], } /* use for mousemove events */ -static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, const int mval[2], - const bool do_thickness, const bool do_snap) +static bool view3d_ruler_item_mousemove( + RulerInfo *ruler_info, const int mval[2], + const bool do_thickness, const bool do_snap) { const float eps_bias = 0.0002f; - const float dist_px = MVAL_MAX_PX_DIST * U.pixelsize; /* snap dist */ + float dist_px = MVAL_MAX_PX_DIST * U.pixelsize; /* snap dist */ RulerItem *ruler_item = ruler_item_active_get(ruler_info); ruler_info->snap_flag &= ~RULER_SNAP_OK; @@ -657,8 +665,8 @@ static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, cons copy_v3_v3(co, ruler_info->drag_start_co); view3d_ruler_item_project(ruler_info, co, mval); if (do_thickness && ruler_item->co_index != 1) { - Scene *scene = CTX_data_scene(C); - View3D *v3d = ruler_info->sa->spacedata.first; + // Scene *scene = CTX_data_scene(C); + // View3D *v3d = ruler_info->sa->spacedata.first; const float mval_fl[2] = {UNPACK2(mval)}; float ray_normal[3]; float ray_start[3]; @@ -666,33 +674,37 @@ static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, cons co_other = ruler_item->co[ruler_item->co_index == 0 ? 2 : 0]; - if (ED_view3d_snap_from_region( - scene, v3d, ruler_info->ar, - mval_fl, dist_px, - true, false, - false, false, true, + if (ED_transform_snap_object_project_view3d_mixed( + ruler_info->snap_context, + &(const struct SnapObjectParams){ + .snap_select = SNAP_ALL, + .snap_to_flag = SCE_SELECT_FACE, + }, + mval_fl, &dist_px, true, co, ray_normal)) { negate_v3(ray_normal); /* add some bias */ madd_v3_v3v3fl(ray_start, co, ray_normal, eps_bias); - ED_view3d_snap_from_ray( - scene, - ray_start, ray_normal, - co_other); + ED_transform_snap_object_project_ray( + ruler_info->snap_context, + ray_start, ray_normal, NULL, + co_other, NULL); } } else if (do_snap) { - Scene *scene = CTX_data_scene(C); + // Scene *scene = CTX_data_scene(C); View3D *v3d = ruler_info->sa->spacedata.first; const float mval_fl[2] = {UNPACK2(mval)}; bool use_depth = (v3d->drawtype >= OB_SOLID); - if (ED_view3d_snap_from_region( - scene, v3d, ruler_info->ar, - mval_fl, dist_px, - use_depth, false, - true, true, use_depth, + if (ED_transform_snap_object_project_view3d_mixed( + ruler_info->snap_context, + &(const struct SnapObjectParams){ + .snap_select = SNAP_ALL, + .snap_to_flag = (SCE_SELECT_VERTEX | SCE_SELECT_EDGE) | (use_depth ? SCE_SELECT_FACE : 0), + }, + mval_fl, &dist_px, use_depth, co, NULL)) { ruler_info->snap_flag |= RULER_SNAP_OK; @@ -736,6 +748,10 @@ static int view3d_ruler_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE op->customdata = ruler_info; + ruler_info->snap_context = ED_transform_snap_object_context_create_view3d( + CTX_data_main(C), CTX_data_scene(C), SNAP_OBJECT_USE_CACHE, + ar, CTX_wm_view3d(C)); + ruler_info->win = win; ruler_info->sa = sa; ruler_info->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ruler_info_draw_pixel, @@ -818,7 +834,7 @@ static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event) if (use_depth) { /* snap the first point added, not essential but handy */ ruler_item->co_index = 0; - view3d_ruler_item_mousemove(C, ruler_info, event->mval, false, true); + view3d_ruler_item_mousemove(ruler_info, event->mval, false, true); copy_v3_v3(ruler_info->drag_start_co, ruler_item->co[ruler_item->co_index]); } else { @@ -871,7 +887,7 @@ static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event) } /* update the new location */ - view3d_ruler_item_mousemove(C, ruler_info, event->mval, + view3d_ruler_item_mousemove(ruler_info, event->mval, event->shift != 0, event->ctrl != 0); do_draw = true; } @@ -920,7 +936,7 @@ static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event) case MOUSEMOVE: { if (ruler_info->state == RULER_STATE_DRAG) { - if (view3d_ruler_item_mousemove(C, ruler_info, event->mval, + if (view3d_ruler_item_mousemove(ruler_info, event->mval, event->shift != 0, event->ctrl != 0)) { do_draw = true; diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 11623d06fff..fd7179d06dd 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -417,11 +417,12 @@ static void do_lasso_select_objects(ViewContext *vc, const int mcords[][2], cons for (base = vc->scene->base.first; base; base = base->next) { if (BASE_SELECTABLE(vc->v3d, base)) { /* use this to avoid un-needed lasso lookups */ - ED_view3d_project_base(vc->ar, base); - if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) { - - ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT); - base->object->flag = base->flag; + if (ED_view3d_project_base(vc->ar, base) == V3D_PROJ_RET_OK) { + if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) { + + ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT); + base->object->flag = base->flag; + } } if (vc->obact == base->object && (base->object->mode & OB_MODE_POSE)) { do_lasso_select_pose(vc, base->object, mcords, moves, select); @@ -1093,20 +1094,22 @@ static Base *object_mouse_select_menu(bContext *C, ViewContext *vc, unsigned int /* two selection methods, the CTRL select uses max dist of 15 */ if (buffer) { - int a; - for (a = 0; a < hits; a++) { + for (int a = 0; a < hits; a++) { /* index was converted */ - if (base->selcol == buffer[(4 * a) + 3]) + if (base->selcol == (buffer[(4 * a) + 3] & ~0xFFFF0000)) { ok = true; + break; + } } } else { - int temp, dist = 15; - ED_view3d_project_base(vc->ar, base); - - temp = abs(base->sx - mval[0]) + abs(base->sy - mval[1]); - if (temp < dist) - ok = true; + const int dist = 15 * U.pixelsize; + if (ED_view3d_project_base(vc->ar, base) == V3D_PROJ_RET_OK) { + const int delta_px[2] = {base->sx - mval[0], base->sy - mval[1]}; + if (len_manhattan_v2_int(delta_px) < dist) { + ok = true; + } + } } if (ok) { @@ -1465,7 +1468,7 @@ static bool ed_object_select_pick( const bool has_bones = selectbuffer_has_bones(buffer, hits); /* note; shift+alt goes to group-flush-selecting */ - if (has_bones == 0 && enumerate) { + if (enumerate) { basact = object_mouse_select_menu(C, &vc, buffer, hits, mval, toggle); } else { diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c index 7e1202aef77..73ec0f664da 100644 --- a/source/blender/editors/space_view3d/view3d_walk.c +++ b/source/blender/editors/space_view3d/view3d_walk.c @@ -306,6 +306,8 @@ typedef struct WalkInfo { float jump_height; /* maximum jump height */ float speed_factor; /* to use for fast/slow speeds */ + struct SnapObjectContext *snap_context; + struct View3DCameraControl *v3d_camera_control; } WalkInfo; @@ -402,12 +404,14 @@ static void walk_navigation_mode_set(bContext *C, wmOperator *op, WalkInfo *walk /** * \param r_distance Distance to the hit point */ -static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *walk, const float dvec[3], float *r_distance) +static bool walk_floor_distance_get( + RegionView3D *rv3d, WalkInfo *walk, const float dvec[3], + float *r_distance) { float ray_normal[3] = {0, 0, -1}; /* down */ float ray_start[3]; float r_location[3]; - float r_normal[3]; + float r_normal_dummy[3]; float dvec_tmp[3]; bool ret; @@ -418,12 +422,10 @@ static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *w mul_v3_v3fl(dvec_tmp, dvec, walk->grid); add_v3_v3(ray_start, dvec_tmp); - ret = snapObjectsRayEx( - CTX_data_scene(C), NULL, NULL, NULL, NULL, - NULL, SNAP_ALL, SCE_SNAP_MODE_FACE, + ret = ED_transform_snap_object_project_ray( + walk->snap_context, ray_start, ray_normal, r_distance, - r_location, r_normal, NULL, NULL, - NULL, NULL); + r_location, r_normal_dummy); /* artifically scale the distance to the scene size */ *r_distance /= walk->grid; @@ -435,34 +437,30 @@ static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *w * \param r_location Location of the hit point * \param r_normal Normal of the hit surface, transformed to always face the camera */ -static bool walk_ray_cast(bContext *C, RegionView3D *rv3d, WalkInfo *walk, float r_location[3], float r_normal[3], float *ray_distance) +static bool walk_ray_cast( + RegionView3D *rv3d, WalkInfo *walk, + float r_location[3], float r_normal[3], float *ray_distance) { - float ray_normal[3] = {0, 0, 1}; /* forward */ + float ray_normal[3] = {0, 0, -1}; /* forward */ float ray_start[3]; - float mat[3][3]; /* 3x3 copy of the view matrix so we can move along the view axis */ bool ret; *ray_distance = BVH_RAYCAST_DIST_MAX; copy_v3_v3(ray_start, rv3d->viewinv[3]); - copy_m3_m4(mat, rv3d->viewinv); - mul_m3_v3(mat, ray_normal); + mul_mat3_m4_v3(rv3d->viewinv, ray_normal); - mul_v3_fl(ray_normal, -1); normalize_v3(ray_normal); - ret = snapObjectsRayEx( - CTX_data_scene(C), NULL, NULL, NULL, NULL, - NULL, SNAP_ALL, SCE_SNAP_MODE_FACE, - ray_start, ray_normal, ray_distance, - r_location, r_normal, NULL, NULL, - NULL, NULL); - + ret = ED_transform_snap_object_project_ray( + walk->snap_context, + ray_start, ray_normal, NULL, + r_location, r_normal); /* dot is positive if both rays are facing the same direction */ if (dot_v3v3(ray_normal, r_normal) > 0) { - copy_v3_fl3(r_normal, -r_normal[0], -r_normal[1], -r_normal[2]); + negate_v3(r_normal); } /* artifically scale the distance to the scene size */ @@ -575,6 +573,9 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op) walk->rv3d->rflag |= RV3D_NAVIGATING; + walk->snap_context = ED_transform_snap_object_context_create_view3d( + CTX_data_main(C), walk->scene, SNAP_OBJECT_USE_CACHE, + walk->ar, walk->v3d); walk->v3d_camera_control = ED_view3d_cameracontrol_acquire( walk->scene, walk->v3d, walk->rv3d, @@ -625,6 +626,8 @@ static int walkEnd(bContext *C, WalkInfo *walk) ED_region_draw_cb_exit(walk->ar->type, walk->draw_handle_pixel); + ED_transform_snap_object_context_destroy(walk->snap_context); + ED_view3d_cameracontrol_release(walk->v3d_camera_control, walk->state == WALK_CANCEL); rv3d->rflag &= ~RV3D_NAVIGATING; @@ -897,7 +900,7 @@ static void walkEvent(bContext *C, wmOperator *op, WalkInfo *walk, const wmEvent { float loc[3], nor[3]; float distance; - bool ret = walk_ray_cast(C, walk->rv3d, walk, loc, nor, &distance); + bool ret = walk_ray_cast(walk->rv3d, walk, loc, nor, &distance); /* in case we are teleporting middle way from a jump */ walk->speed_jump = 0.0f; @@ -1178,7 +1181,7 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk) float difference = -100.0f; float fall_distance; - ret = walk_floor_distance_get(C, rv3d, walk, dvec, &ray_distance); + ret = walk_floor_distance_get(rv3d, walk, dvec, &ray_distance); if (ret) { difference = walk->view_height - ray_distance; @@ -1231,7 +1234,7 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk) if (t > walk->teleport.duration) { /* check to see if we are landing */ - ret = walk_floor_distance_get(C, rv3d, walk, dvec, &ray_distance); + ret = walk_floor_distance_get(rv3d, walk, dvec, &ray_distance); if (ret) { difference = walk->view_height - ray_distance; |