diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_walk.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_walk.c | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c index c5585857b55..fb445198ccf 100644 --- a/source/blender/editors/space_view3d/view3d_walk.c +++ b/source/blender/editors/space_view3d/view3d_walk.c @@ -65,9 +65,6 @@ /* ensure the target position is one we can reach, see: T45771 */ #define USE_PIXELSIZE_NATIVE_SUPPORT -/* prototypes */ -static float getVelocityZeroTime(const float gravity, const float velocity); - /* NOTE: these defines are saved in keymap files, * do not change values but just add new ones */ enum { @@ -199,6 +196,8 @@ typedef struct WalkInfo { short state; bool redraw; + bool anim_playing; /* needed for autokeyframing */ + int prev_mval[2]; /* previous 2D mouse values */ int center_mval[2]; /* center mouse values */ int moffset[2]; @@ -264,6 +263,10 @@ typedef struct WalkInfo { } WalkInfo; +/* prototypes */ +static int walkApply(bContext *C, struct WalkInfo *walk, bool force_autokey); +static float getVelocityZeroTime(const float gravity, const float velocity); + static void drawWalkPixel(const struct bContext *UNUSED(C), ARegion *ar, void *arg) { /* draws an aim/cross in the center */ @@ -420,6 +423,7 @@ static float userdef_speed = -1.f; static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op) { + wmWindowManager *wm = CTX_wm_manager(C); Main *bmain = CTX_data_main(C); wmWindow *win = CTX_wm_window(C); @@ -512,6 +516,8 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op) walk->ndof = NULL; #endif + walk->anim_playing = ED_screen_animation_playing(wm); + walk->time_lastdraw = PIL_check_seconds_timer(); walk->draw_handle_pixel = ED_region_draw_cb_activate( @@ -563,6 +569,18 @@ static int walkEnd(bContext *C, WalkInfo *walk) if (walk->state == WALK_RUNNING) { return OPERATOR_RUNNING_MODAL; } + else if (walk->state == WALK_CONFIRM) { + /* Needed for auto_keyframe. */ +#ifdef WITH_INPUT_NDOF + if (walk->ndof) { + walkApply_ndof(C, walk, true); + } + else +#endif /* WITH_INPUT_NDOF */ + { + walkApply(C, walk, true); + } + } #ifdef NDOF_WALK_DEBUG puts("\n-- walk end --"); @@ -885,9 +903,15 @@ static void walkEvent(bContext *C, WalkInfo *walk, const wmEvent *event) static void walkMoveCamera(bContext *C, WalkInfo *walk, const bool do_rotate, - const bool do_translate) + const bool do_translate, + const bool is_confirm) { - ED_view3d_cameracontrol_update(walk->v3d_camera_control, true, C, do_rotate, do_translate); + /* we only consider autokeying on playback or if user confirmed walk on the same frame + * otherwise we get a keyframe even if the user cancels. */ + const bool use_autokey = is_confirm || walk->anim_playing; + + ED_view3d_cameracontrol_update( + walk->v3d_camera_control, use_autokey, C, do_rotate, do_translate); } static float getFreeFallDistance(const float gravity, const float time) @@ -900,7 +924,7 @@ static float getVelocityZeroTime(const float gravity, const float velocity) return velocity / gravity; } -static int walkApply(bContext *C, WalkInfo *walk) +static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) { #define WALK_ROTATE_FAC 2.2f /* more is faster */ #define WALK_TOP_LIMIT DEG2RADF(85.0f) @@ -945,7 +969,7 @@ static int walkApply(bContext *C, WalkInfo *walk) /* Should we redraw? */ if ((walk->active_directions) || moffset[0] || moffset[1] || walk->teleport.state == WALK_TELEPORT_STATE_ON || - walk->gravity_state != WALK_GRAVITY_STATE_OFF) { + walk->gravity_state != WALK_GRAVITY_STATE_OFF || is_confirm) { float dvec_tmp[3]; /* time how fast it takes for us to redraw, @@ -1237,7 +1261,7 @@ static int walkApply(bContext *C, WalkInfo *walk) if (rv3d->persp == RV3D_CAMOB) { const bool do_rotate = (moffset[0] || moffset[1]); const bool do_translate = (walk->speed != 0.0f); - walkMoveCamera(C, walk, do_rotate, do_translate); + walkMoveCamera(C, walk, do_rotate, do_translate, is_confirm); } } else { @@ -1277,7 +1301,7 @@ static void walkApply_ndof(bContext *C, WalkInfo *walk) walk->redraw = true; if (walk->rv3d->persp == RV3D_CAMOB) { - walkMoveCamera(C, walk, has_rotate, has_translate); + walkMoveCamera(C, walk, has_rotate, has_translate, true); } } } @@ -1333,13 +1357,13 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event) #ifdef WITH_INPUT_NDOF if (walk->ndof) { /* 3D mouse overrules [2D mouse + timer] */ if (event->type == NDOF_MOTION) { - walkApply_ndof(C, walk); + walkApply_ndof(C, walk, false); } } else #endif /* WITH_INPUT_NDOF */ if (event->type == TIMER && event->customdata == walk->timer) { - walkApply(C, walk); + walkApply(C, walk, false); } do_draw |= walk->redraw; |