Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-04-21 04:29:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-04-22 09:36:53 +0300
commit19e5540ff7712a45ab4ced4a4a02b12ce02637a9 (patch)
treeb43be4638a05372d802dc71580099e53f54545bc /source/blender/editors/space_view3d/view3d_ruler.c
parent8dcdde52b17228601c95fed04f5bca03484d27ac (diff)
Transform Snap: initial snap context refactor
This introduces a snap-context that can be re-used for casting rays into the scene (by operators such as walk-mode, ruler and transform code). This can be used to cache data between calls too.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_ruler.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_ruler.c62
1 files changed, 39 insertions, 23 deletions
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;