diff options
author | Martin Poirier <theeth@yahoo.com> | 2010-02-04 00:01:41 +0300 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2010-02-04 00:01:41 +0300 |
commit | 9916e0193c36c7c107f9e5763611235185a8b52c (patch) | |
tree | c22d3854af020338f187032032f12392d81d4f5e /source/blender | |
parent | 845136ea133b1b5388b65bcc54aa5add50ec5a90 (diff) |
New Transform 3D view recalculate scheme.
Only recalculate changes when absolutely necessary (mouse move triggers a soft recalc that will only happen before the next redraw other events trigger hard recalcs). The problem was that mouse moves are reported as lots of events (with small dx,dy) between each redraw which would trigger often heavy recalculations every time while only the last one was really important (the one before the redraw).
This makes snap project (retopo) much more manageable but induces a very small lag equal to one refresh cycle. Confirming transform does a hard refresh, so the final result is always consistent with mouse position.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/transform/transform.c | 85 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.h | 9 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_generics.c | 2 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_input.c | 4 |
4 files changed, 62 insertions, 38 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index e8b1e6e0de1..938c0ba7cfa 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -122,6 +122,8 @@ #include "transform.h" +void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg); + /* ************************** SPACE DEPENDANT CODE **************************** */ void setTransformViewMatrices(TransInfo *t) @@ -297,7 +299,7 @@ void removeAspectRatio(TransInfo *t, float *vec) } } -static void viewRedrawForce(bContext *C, TransInfo *t) +static void viewRedrawForce(const bContext *C, TransInfo *t) { if (t->spacetype == SPACE_VIEW3D) { @@ -546,7 +548,7 @@ int transformEvent(TransInfo *t, wmEvent *event) t->mval[0] = event->x - t->ar->winrct.xmin; t->mval[1] = event->y - t->ar->winrct.ymin; - t->redraw = 1; + t->redraw |= TREDRAW_SOFT; if (t->state == TRANS_STARTING) { t->state = TRANS_RUNNING; @@ -571,7 +573,7 @@ int transformEvent(TransInfo *t, wmEvent *event) restoreTransObjects(t); initTranslation(t); initSnapping(t, NULL); // need to reinit after mode change - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_ROTATE: @@ -589,7 +591,7 @@ int transformEvent(TransInfo *t, wmEvent *event) initRotation(t); } initSnapping(t, NULL); // need to reinit after mode change - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_RESIZE: @@ -599,21 +601,21 @@ int transformEvent(TransInfo *t, wmEvent *event) restoreTransObjects(t); initResize(t); initSnapping(t, NULL); // need to reinit after mode change - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_SNAP_INV_ON: t->modifiers |= MOD_SNAP_INVERT; - t->redraw = 1; + t->redraw |= TREDRAW_HARD; break; case TFM_MODAL_SNAP_INV_OFF: t->modifiers &= ~MOD_SNAP_INVERT; - t->redraw = 1; + t->redraw |= TREDRAW_HARD; break; case TFM_MODAL_SNAP_TOGGLE: t->modifiers ^= MOD_SNAP; - t->redraw = 1; + t->redraw |= TREDRAW_HARD; break; case TFM_MODAL_AXIS_X: if ((t->flag & T_NO_CONSTRAINT)==0) { @@ -628,7 +630,7 @@ int transformEvent(TransInfo *t, wmEvent *event) setUserConstraint(t, t->current_orientation, (CON_AXIS0), "along %s X"); } } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_AXIS_Y: @@ -644,7 +646,7 @@ int transformEvent(TransInfo *t, wmEvent *event) setUserConstraint(t, t->current_orientation, (CON_AXIS1), "along %s Y"); } } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_AXIS_Z: @@ -655,7 +657,7 @@ int transformEvent(TransInfo *t, wmEvent *event) else { setUserConstraint(t, t->current_orientation, (CON_AXIS2), "along %s Z"); } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_PLANE_X: @@ -666,7 +668,7 @@ int transformEvent(TransInfo *t, wmEvent *event) else { setUserConstraint(t, t->current_orientation, (CON_AXIS1|CON_AXIS2), "locking %s X"); } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_PLANE_Y: @@ -677,7 +679,7 @@ int transformEvent(TransInfo *t, wmEvent *event) else { setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y"); } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_PLANE_Z: @@ -688,22 +690,22 @@ int transformEvent(TransInfo *t, wmEvent *event) else { setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z"); } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_CONS_OFF: if ((t->flag & T_NO_CONSTRAINT)==0) { stopConstraint(t); - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case TFM_MODAL_ADD_SNAP: addSnapPoint(t); - t->redraw = 1; + t->redraw |= TREDRAW_HARD; break; case TFM_MODAL_REMOVE_SNAP: removeSnapPoint(t); - t->redraw = 1; + t->redraw |= TREDRAW_HARD; break; default: handled = 0; @@ -723,7 +725,7 @@ int transformEvent(TransInfo *t, wmEvent *event) case LEFTSHIFTKEY: case RIGHTSHIFTKEY: t->modifiers |= MOD_CONSTRAINT_PLANE; - t->redraw = 1; + t->redraw |= TREDRAW_HARD; break; case SPACEKEY: @@ -771,7 +773,7 @@ int transformEvent(TransInfo *t, wmEvent *event) postSelectConstraint(t); } } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case ESCKEY: @@ -788,7 +790,7 @@ int transformEvent(TransInfo *t, wmEvent *event) restoreTransObjects(t); initTranslation(t); initSnapping(t, NULL); // need to reinit after mode change - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case SKEY: @@ -798,7 +800,7 @@ int transformEvent(TransInfo *t, wmEvent *event) restoreTransObjects(t); initResize(t); initSnapping(t, NULL); // need to reinit after mode change - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case RKEY: @@ -816,7 +818,7 @@ int transformEvent(TransInfo *t, wmEvent *event) initRotation(t); } initSnapping(t, NULL); // need to reinit after mode change - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case CKEY: @@ -828,7 +830,7 @@ int transformEvent(TransInfo *t, wmEvent *event) } else { stopConstraint(t); - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case XKEY: @@ -857,7 +859,7 @@ int transformEvent(TransInfo *t, wmEvent *event) setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1|CON_AXIS2), "locking %s X"); } } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case YKEY: @@ -886,7 +888,7 @@ int transformEvent(TransInfo *t, wmEvent *event) setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS2), "locking %s Y"); } } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case ZKEY: @@ -907,14 +909,14 @@ int transformEvent(TransInfo *t, wmEvent *event) else if (t->modifiers & MOD_CONSTRAINT_PLANE) setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS1), "locking %s Z"); } - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case OKEY: if (t->flag & T_PROP_EDIT && event->shift) { t->prop_mode = (t->prop_mode + 1) % 6; calculatePropRatio(t); - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case PADPLUSKEY: @@ -985,7 +987,7 @@ int transformEvent(TransInfo *t, wmEvent *event) else { /* Otherwise, just redraw, NDof input was cancelled */ - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; case NDOF_NOMOVE: @@ -996,7 +998,7 @@ int transformEvent(TransInfo *t, wmEvent *event) } break; case NDOF_REFRESH: - t->redraw = 1; + t->redraw |= TREDRAW_HARD; break; default: handled = 0; @@ -1013,14 +1015,14 @@ int transformEvent(TransInfo *t, wmEvent *event) case LEFTSHIFTKEY: case RIGHTSHIFTKEY: t->modifiers &= ~MOD_CONSTRAINT_PLANE; - t->redraw = 1; + t->redraw |= TREDRAW_HARD; break; case MIDDLEMOUSE: if ((t->flag & T_NO_CONSTRAINT)==0) { t->modifiers &= ~MOD_CONSTRAINT_SELECT; postSelectConstraint(t); - t->redraw = 1; + t->redraw |= TREDRAW_HARD; } break; // case LEFTMOUSE: @@ -1456,6 +1458,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int //calc_manipulator_stats(curarea); initTransformOrientation(C, t); + t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW); t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW); //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL); t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), NULL, drawHelpline, t); @@ -1627,16 +1630,18 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int return 1; } -void transformApply(bContext *C, TransInfo *t) +void transformApply(const bContext *C, TransInfo *t) { - if (t->redraw) + if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT))) { selectConstraint(t); if (t->transform) { t->transform(t, t->mval); // calls recalcData() viewRedrawForce(C, t); } - t->redraw = 0; + t->redraw = TREDRAW_NOTHING; + } else if (t->redraw & TREDRAW_SOFT) { + viewRedrawForce(C, t); } /* If auto confirm is on, break after one pass */ @@ -1649,7 +1654,17 @@ void transformApply(bContext *C, TransInfo *t) { // TRANSFORM_FIX_ME //do_screenhandlers(G.curscreen); - t->redraw = 1; + t->redraw |= TREDRAW_HARD; + } +} + +void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg) +{ + TransInfo *t = arg; + + if (t->redraw & TREDRAW_SOFT) { + t->redraw |= TREDRAW_HARD; + transformApply(C, t); } } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 231a01b86d7..6885e87c6a3 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -325,6 +325,7 @@ typedef struct TransInfo { struct wmTimer *animtimer; short mval[2]; /* current mouse position */ struct Object *obedit; + void *draw_handle_apply; void *draw_handle_view; void *draw_handle_pixel; void *draw_handle_cursor; @@ -349,6 +350,12 @@ typedef struct TransInfo { #define TRANS_CONFIRM 2 #define TRANS_CANCEL 3 +/* transinfo->redraw */ +#define TREDRAW_NOTHING 0 +#define TREDRAW_HARD 1 +#define TREDRAW_SOFT 2 + + /* transinfo->flag */ #define T_OBJECT (1 << 0) #define T_EDIT (1 << 1) @@ -440,7 +447,7 @@ void TRANSFORM_OT_transform(struct wmOperatorType *ot); int initTransform(struct bContext *C, struct TransInfo *t, struct wmOperator *op, struct wmEvent *event, int mode); void saveTransform(struct bContext *C, struct TransInfo *t, struct wmOperator *op); int transformEvent(TransInfo *t, struct wmEvent *event); -void transformApply(struct bContext *C, TransInfo *t); +void transformApply(const struct bContext *C, TransInfo *t); int transformEnd(struct bContext *C, TransInfo *t); void setTransformViewMatrices(TransInfo *t); diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 4299529836b..2d32b81de33 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -1072,6 +1072,8 @@ void postTrans (bContext *C, TransInfo *t) if (t->draw_handle_view) ED_region_draw_cb_exit(t->ar->type, t->draw_handle_view); + if (t->draw_handle_apply) + ED_region_draw_cb_exit(t->ar->type, t->draw_handle_apply); if (t->draw_handle_pixel) ED_region_draw_cb_exit(t->ar->type, t->draw_handle_pixel); if (t->draw_handle_cursor) diff --git a/source/blender/editors/transform/transform_input.c b/source/blender/editors/transform/transform_input.c index fbc7f0dd746..879967da837 100644 --- a/source/blender/editors/transform/transform_input.c +++ b/source/blender/editors/transform/transform_input.c @@ -364,7 +364,7 @@ void applyMouseInput(TransInfo *t, MouseInput *mi, short mval[2], float output[3 int handleMouseInput(TransInfo *t, MouseInput *mi, wmEvent *event) { - int redraw = 0; + int redraw = TREDRAW_NOTHING; switch (event->type) { @@ -384,7 +384,7 @@ int handleMouseInput(TransInfo *t, MouseInput *mi, wmEvent *event) t->modifiers &= ~MOD_PRECISION; mi->precision = 0; } - redraw = 1; + redraw = TREDRAW_HARD; break; } |