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:
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r--source/blender/editors/space_view3d/view3d_draw_legacy.c41
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c20
-rw-r--r--source/blender/editors/space_view3d/view3d_fly.c45
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_navigate.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c42
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c44
-rw-r--r--source/blender/editors/space_view3d/view3d_walk.c51
7 files changed, 147 insertions, 100 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c
index 39cbc67f996..040b257bb90 100644
--- a/source/blender/editors/space_view3d/view3d_draw_legacy.c
+++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c
@@ -102,6 +102,7 @@
#include "RE_engine.h"
#include "DRW_engine.h"
+#include "DRW_select_buffer.h"
#include "view3d_intern.h" /* own include */
@@ -238,22 +239,6 @@ void ED_view3d_backbuf_depth_validate(ViewContext *vc)
}
}
-uint *ED_view3d_select_id_read_rect(const rcti *clip, uint *r_buf_len)
-{
- uint width = BLI_rcti_size_x(clip);
- uint height = BLI_rcti_size_y(clip);
- uint buf_len = width * height;
- uint *buf = MEM_mallocN(buf_len * sizeof(*buf), __func__);
-
- DRW_framebuffer_select_id_read(clip, buf);
-
- if (r_buf_len) {
- *r_buf_len = buf_len;
- }
-
- return buf;
-}
-
/**
* allow for small values [0.5 - 2.5],
* and large values, FLT_MAX by clamping by the area size
@@ -263,30 +248,6 @@ int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist)
return (int)min_ff(ceilf(dist), (float)max_ii(ar->winx, ar->winx));
}
-/* reads full rect, converts indices */
-uint *ED_view3d_select_id_read(int xmin, int ymin, int xmax, int ymax, uint *r_buf_len)
-{
- if (UNLIKELY((xmin > xmax) || (ymin > ymax))) {
- return NULL;
- }
-
- const rcti rect = {
- .xmin = xmin,
- .xmax = xmax + 1,
- .ymin = ymin,
- .ymax = ymax + 1,
- };
-
- uint buf_len;
- uint *buf = ED_view3d_select_id_read_rect(&rect, &buf_len);
-
- if (r_buf_len) {
- *r_buf_len = buf_len;
- }
-
- return buf;
-}
-
/* *********************** */
void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect)
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index ff0052c1fd1..ec7c1c0b3b9 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -201,7 +201,7 @@ static void calctrackballvec(const rcti *rect, const int event_xy[2], float r_di
/* Normalize x and y. */
r_dir[0] = (event_xy[0] - BLI_rcti_cent_x(rect)) / ((size[0] * aspect[0]) / 2.0);
- r_dir[1] = (event_xy[1] - BLI_rcti_cent_x(rect)) / ((size[1] * aspect[1]) / 2.0);
+ r_dir[1] = (event_xy[1] - BLI_rcti_cent_y(rect)) / ((size[1] * aspect[1]) / 2.0);
const float d = len_v2(r_dir);
if (d < t) {
/* Inside sphere. */
@@ -1959,6 +1959,8 @@ static float viewzoom_scale_value(const rcti *winrct,
fac = (float)(xy_init[1] - xy_curr[1]);
}
+ fac /= U.pixelsize;
+
if (zoom_invert != zoom_invert_force) {
fac = -fac;
}
@@ -1974,8 +1976,8 @@ static float viewzoom_scale_value(const rcti *winrct,
BLI_rcti_cent_x(winrct),
BLI_rcti_cent_y(winrct),
};
- float len_new = 5 + len_v2v2_int(ctr, xy_curr);
- float len_old = 5 + len_v2v2_int(ctr, xy_init);
+ float len_new = (5 * U.pixelsize) + ((float)len_v2v2_int(ctr, xy_curr) / U.pixelsize);
+ float len_old = (5 * U.pixelsize) + ((float)len_v2v2_int(ctr, xy_init) / U.pixelsize);
/* intentionally ignore 'zoom_invert' for scale */
if (zoom_invert_force) {
@@ -1985,16 +1987,16 @@ static float viewzoom_scale_value(const rcti *winrct,
zfac = val_orig * (len_old / max_ff(len_new, 1.0f)) / val;
}
else { /* USER_ZOOM_DOLLY */
- float len_new = 5;
- float len_old = 5;
+ float len_new = 5 * U.pixelsize;
+ float len_old = 5 * U.pixelsize;
if (U.uiflag & USER_ZOOM_HORIZ) {
- len_new += (winrct->xmax - (xy_curr[0]));
- len_old += (winrct->xmax - (xy_init[0]));
+ len_new += (winrct->xmax - (xy_curr[0])) / U.pixelsize;
+ len_old += (winrct->xmax - (xy_init[0])) / U.pixelsize;
}
else {
- len_new += (winrct->ymax - (xy_curr[1]));
- len_old += (winrct->ymax - (xy_init[1]));
+ len_new += (winrct->ymax - (xy_curr[1])) / U.pixelsize;
+ len_old += (winrct->ymax - (xy_init[1])) / U.pixelsize;
}
if (zoom_invert != zoom_invert_force) {
diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c
index 961ac4c26fb..3e2e113be3e 100644
--- a/source/blender/editors/space_view3d/view3d_fly.c
+++ b/source/blender/editors/space_view3d/view3d_fly.c
@@ -155,6 +155,8 @@ typedef struct FlyInfo {
* without moving the direction there looking */
bool use_freelook;
+ bool anim_playing; /* needed for autokeyframing */
+
int mval[2]; /* latest 2D mouse values */
int center_mval[2]; /* center mouse values */
float width, height; /* camera viewport dimensions */
@@ -185,6 +187,12 @@ typedef struct FlyInfo {
} FlyInfo;
+/* prototypes */
+#ifdef WITH_INPUT_NDOF
+static void flyApply_ndof(bContext *C, FlyInfo *fly, bool is_confirm);
+#endif /* WITH_INPUT_NDOF */
+static int flyApply(bContext *C, struct FlyInfo *fly, bool force_autokey);
+
static void drawFlyPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg)
{
FlyInfo *fly = arg;
@@ -261,6 +269,7 @@ enum {
static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent *event)
{
+ wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = CTX_wm_window(C);
rctf viewborder;
@@ -308,6 +317,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent
fly->grid = 1.0f;
fly->use_precision = false;
fly->use_freelook = false;
+ fly->anim_playing = ED_screen_animation_playing(wm);
#ifdef NDOF_FLY_DRAW_TOOMUCH
fly->redraw = 1;
@@ -374,6 +384,18 @@ static int flyEnd(bContext *C, FlyInfo *fly)
if (fly->state == FLY_RUNNING) {
return OPERATOR_RUNNING_MODAL;
}
+ else if (fly->state == FLY_CONFIRM) {
+ /* Needed for auto_keyframe. */
+#ifdef WITH_INPUT_NDOF
+ if (fly->ndof) {
+ flyApply_ndof(C, fly, true);
+ }
+ else
+#endif /* WITH_INPUT_NDOF */
+ {
+ flyApply(C, fly, true);
+ }
+ }
#ifdef NDOF_FLY_DEBUG
puts("\n-- fly end --");
@@ -672,12 +694,19 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event)
}
}
-static void flyMoveCamera(bContext *C, FlyInfo *fly, const bool do_rotate, const bool do_translate)
+static void flyMoveCamera(bContext *C,
+ FlyInfo *fly,
+ const bool do_rotate,
+ const bool do_translate,
+ const bool is_confirm)
{
- ED_view3d_cameracontrol_update(fly->v3d_camera_control, true, C, do_rotate, do_translate);
+ /* we only consider autokeying on playback or if user confirmed fly on the same frame
+ * otherwise we get a keyframe even if the user cancels. */
+ const bool use_autokey = is_confirm || fly->anim_playing;
+ ED_view3d_cameracontrol_update(fly->v3d_camera_control, use_autokey, C, do_rotate, do_translate);
}
-static int flyApply(bContext *C, FlyInfo *fly)
+static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
{
#define FLY_ROTATE_FAC 10.0f /* more is faster */
#define FLY_ZUP_CORRECT_FAC 0.1f /* amount to correct per step */
@@ -948,7 +977,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
(fly->zlock != FLY_AXISLOCK_STATE_OFF) ||
((moffset[0] || moffset[1]) && !fly->pan_view));
const bool do_translate = (fly->speed != 0.0f || fly->pan_view);
- flyMoveCamera(C, fly, do_rotate, do_translate);
+ flyMoveCamera(C, fly, do_rotate, do_translate, is_confirm);
}
}
else {
@@ -963,7 +992,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
}
#ifdef WITH_INPUT_NDOF
-static void flyApply_ndof(bContext *C, FlyInfo *fly)
+static void flyApply_ndof(bContext *C, FlyInfo *fly, bool is_confirm)
{
Object *lock_ob = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control);
bool has_translate, has_rotate;
@@ -980,7 +1009,7 @@ static void flyApply_ndof(bContext *C, FlyInfo *fly)
fly->redraw = true;
if (fly->rv3d->persp == RV3D_CAMOB) {
- flyMoveCamera(C, fly, has_rotate, has_translate);
+ flyMoveCamera(C, fly, has_rotate, has_translate, is_confirm);
}
}
}
@@ -1035,13 +1064,13 @@ static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
#ifdef WITH_INPUT_NDOF
if (fly->ndof) { /* 3D mouse overrules [2D mouse + timer] */
if (event->type == NDOF_MOTION) {
- flyApply_ndof(C, fly);
+ flyApply_ndof(C, fly, false);
}
}
else
#endif /* WITH_INPUT_NDOF */
if (event->type == TIMER && event->customdata == fly->timer) {
- flyApply(C, fly);
+ flyApply(C, fly, false);
}
do_draw |= fly->redraw;
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
index 1724a8bd86d..ad1a57eb71f 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
@@ -184,10 +184,6 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
wmOperatorType *ot = WM_operatortype_find(info->opname, true);
WM_gizmo_operator_set(gz, 0, ot, NULL);
-
- /* We only need this for rotation so click/drag events aren't stolen
- * by paint mode press events, however it's strange if only rotation has this behavior. */
- WM_gizmo_set_flag(gz, WM_GIZMO_EVENT_HANDLE_ALL, true);
}
{
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index b4bc2748de5..d20a854c022 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -89,7 +89,6 @@
#include "ED_mesh.h"
#include "ED_object.h"
#include "ED_screen.h"
-#include "ED_select_buffer_utils.h"
#include "ED_select_utils.h"
#include "ED_sculpt.h"
#include "ED_mball.h"
@@ -105,6 +104,7 @@
#include "DEG_depsgraph_query.h"
#include "DRW_engine.h"
+#include "DRW_select_buffer.h"
#include "view3d_intern.h" /* own include */
@@ -269,7 +269,8 @@ static bool edbm_backbuf_check_and_select_verts(struct EditSelectBuf_Cache *esel
bool changed = false;
const BLI_bitmap *select_bitmap = esel->select_bitmap;
- uint index = DRW_select_context_offset_for_object_elem(ob->runtime.select_id, SCE_SELECT_VERTEX);
+ uint index = DRW_select_buffer_context_offset_for_object_elem(ob->runtime.select_id,
+ SCE_SELECT_VERTEX);
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
@@ -296,7 +297,8 @@ static bool edbm_backbuf_check_and_select_edges(struct EditSelectBuf_Cache *esel
bool changed = false;
const BLI_bitmap *select_bitmap = esel->select_bitmap;
- uint index = DRW_select_context_offset_for_object_elem(ob->runtime.select_id, SCE_SELECT_EDGE);
+ uint index = DRW_select_buffer_context_offset_for_object_elem(ob->runtime.select_id,
+ SCE_SELECT_EDGE);
BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
@@ -323,7 +325,8 @@ static bool edbm_backbuf_check_and_select_faces(struct EditSelectBuf_Cache *esel
bool changed = false;
const BLI_bitmap *select_bitmap = esel->select_bitmap;
- uint index = DRW_select_context_offset_for_object_elem(ob->runtime.select_id, SCE_SELECT_FACE);
+ uint index = DRW_select_buffer_context_offset_for_object_elem(ob->runtime.select_id,
+ SCE_SELECT_FACE);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
@@ -828,8 +831,7 @@ static bool do_lasso_select_mesh(ViewContext *vc,
if (wm_userdata->data == NULL) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, ts->selectmode);
esel = wm_userdata->data;
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_poly(mcords, moves, &rect);
}
}
@@ -847,7 +849,7 @@ static bool do_lasso_select_mesh(ViewContext *vc,
struct LassoSelectUserData_ForMeshEdge data_for_edge = {
.data = &data,
.esel = use_zbuf ? esel : NULL,
- .backbuf_offset = use_zbuf ? DRW_select_context_offset_for_object_elem(
+ .backbuf_offset = use_zbuf ? DRW_select_buffer_context_offset_for_object_elem(
vc->obedit->runtime.select_id, SCE_SELECT_EDGE) :
0,
};
@@ -1139,8 +1141,7 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
if (wm_userdata->data == NULL) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_VERTEX);
esel = wm_userdata->data;
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_poly(mcords, moves, &rect);
}
}
@@ -1198,8 +1199,7 @@ static bool do_lasso_select_paintface(ViewContext *vc,
if (esel == NULL) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_FACE);
esel = wm_userdata->data;
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_poly(mcords, moves, &rect);
}
if (esel->select_bitmap) {
@@ -2554,8 +2554,7 @@ static bool do_paintvert_box_select(ViewContext *vc,
if (wm_userdata->data == NULL) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_VERTEX);
esel = wm_userdata->data;
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_rect(rect, NULL);
}
if (esel->select_bitmap != NULL) {
changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
@@ -2609,8 +2608,7 @@ static bool do_paintface_box_select(ViewContext *vc,
if (wm_userdata->data == NULL) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_FACE);
esel = wm_userdata->data;
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_rect(rect, NULL);
}
if (esel->select_bitmap != NULL) {
changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op);
@@ -2807,8 +2805,7 @@ static bool do_mesh_box_select(ViewContext *vc,
if (wm_userdata->data == NULL) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, ts->selectmode);
esel = wm_userdata->data;
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_rect(rect, NULL);
}
}
@@ -2826,7 +2823,7 @@ static bool do_mesh_box_select(ViewContext *vc,
struct BoxSelectUserData_ForMeshEdge cb_data = {
.data = &data,
.esel = use_zbuf ? esel : NULL,
- .backbuf_offset = use_zbuf ? DRW_select_context_offset_for_object_elem(
+ .backbuf_offset = use_zbuf ? DRW_select_buffer_context_offset_for_object_elem(
vc->obedit->runtime.select_id, SCE_SELECT_EDGE) :
0,
};
@@ -3395,8 +3392,7 @@ static bool mesh_circle_select(ViewContext *vc,
struct EditSelectBuf_Cache *esel = wm_userdata->data;
if (use_zbuf) {
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f));
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_circle(mval, (int)(rad + 1.0f), NULL);
}
if (ts->selectmode & SCE_SELECT_VERTEX) {
@@ -3473,8 +3469,7 @@ static bool paint_facesel_circle_select(ViewContext *vc,
{
struct EditSelectBuf_Cache *esel = wm_userdata->data;
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f));
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_circle(mval, (int)(rad + 1.0f), NULL);
if (esel->select_bitmap != NULL) {
changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op);
MEM_freeN(esel->select_bitmap);
@@ -3528,8 +3523,7 @@ static bool paint_vertsel_circle_select(ViewContext *vc,
if (use_zbuf) {
struct EditSelectBuf_Cache *esel = wm_userdata->data;
- const uint buffer_len = DRW_select_context_elem_len();
- esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f));
+ esel->select_bitmap = DRW_select_buffer_bitmap_from_circle(mval, (int)(rad + 1.0f), NULL);
if (esel->select_bitmap != NULL) {
changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
MEM_freeN(esel->select_bitmap);
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index bb8c1a40a05..7f930f1d876 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -1212,9 +1212,17 @@ float ED_view3d_radius_to_dist(const View3D *v3d,
/** \name View Distance Utilities
* \{ */
-/* problem - ofs[3] can be on same location as camera itself.
- * Blender needs proper dist value for zoom.
- * use fallback_dist to override small values
+/**
+ * This function solves the problem of having to switch between camera and non-camera views.
+ *
+ * When viewing from the perspective of \a mat, and having the view center \a ofs,
+ * this calculates a distance from \a ofs to the matrix \a mat.
+ * Using \a fallback_dist when the distance would be too small.
+ *
+ * \param mat: A matrix use for the view-point (typically the camera objects matrix).
+ * \param ofs: Orbit center (negated), matching #RegionView3D.ofs, which is typically passed in.
+ * \param fallback_dist: The distance to use if the object is too near or in front of \a ofs.
+ * \returns A newly calculated distance or the fallback.
*/
float ED_view3d_offset_distance(float mat[4][4], const float ofs[3], const float fallback_dist)
{
@@ -1261,6 +1269,36 @@ void ED_view3d_distance_set(RegionView3D *rv3d, const float dist)
rv3d->dist = dist;
}
+/**
+ * Change the distance & offset to match the depth of \a dist_co along the view axis.
+ *
+ * \param dist_co: A world-space location to use for the new depth.
+ * \param dist_min: Resulting distances below this will be ignored.
+ * \return Success if the distance was set.
+ */
+bool ED_view3d_distance_set_from_location(RegionView3D *rv3d,
+ const float dist_co[3],
+ const float dist_min)
+{
+ float viewinv[4];
+ invert_qt_qt_normalized(viewinv, rv3d->viewquat);
+
+ float tvec[3] = {0.0f, 0.0f, -1.0f};
+ mul_qt_v3(viewinv, tvec);
+
+ float dist_co_local[3];
+ negate_v3_v3(dist_co_local, rv3d->ofs);
+ sub_v3_v3v3(dist_co_local, dist_co, dist_co_local);
+ const float delta = dot_v3v3(tvec, dist_co_local);
+ const float dist_new = rv3d->dist + delta;
+ if (dist_new >= dist_min) {
+ madd_v3_v3fl(rv3d->ofs, tvec, -delta);
+ rv3d->dist = dist_new;
+ return true;
+ }
+ return false;
+}
+
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c
index c5585857b55..22c1aafd7c4 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,13 @@ typedef struct WalkInfo {
} WalkInfo;
+/* prototypes */
+#ifdef WITH_INPUT_NDOF
+static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm);
+#endif /* WITH_INPUT_NDOF */
+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 +426,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 +519,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 +572,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 +906,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 +927,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 +972,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 +1264,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 {
@@ -1260,7 +1287,7 @@ static int walkApply(bContext *C, WalkInfo *walk)
}
#ifdef WITH_INPUT_NDOF
-static void walkApply_ndof(bContext *C, WalkInfo *walk)
+static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm)
{
Object *lock_ob = ED_view3d_cameracontrol_object_get(walk->v3d_camera_control);
bool has_translate, has_rotate;
@@ -1277,7 +1304,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, is_confirm);
}
}
}
@@ -1333,13 +1360,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;