56#include <fmt/format.h>
68#define USE_TABLET_SUPPORT
196 "Increase Jump Height",
197 "Increase jump height"},
201 "Decrease Jump Height",
202 "Decrease jump height"},
204 {0,
nullptr, 0,
nullptr,
nullptr},
275#ifdef WITH_INPUT_NDOF
277 wmNDOFMotionData *ndof;
313#ifdef USE_TABLET_SUPPORT
351#ifdef WITH_INPUT_NDOF
362 const float outer_length = 24.0f;
363 const float inner_length = 14.0f;
440 const float ray_normal[3] = {0, 0, -1};
442 float location_dummy[3];
443 float normal_dummy[3];
469 *r_distance /= walk->
grid;
482 float *r_ray_distance)
484 float ray_normal[3] = {0, 0, -1};
509 if (
dot_v3v3(ray_normal, r_normal) > 0) {
514 *r_ray_distance /= walk->
grid;
547#ifdef NDOF_WALK_DEBUG
548 puts(
"\n-- walk begin --");
561 "Cannot navigate a camera from an external library or non-editable override");
586 const float userdef_jump_height =
U.walk_navigation.jump_height / walk->
grid;
587 const float userdef_view_height =
U.walk_navigation.view_height / walk->
grid;
589 if (
fabsf(
U.walk_navigation.walk_speed -
g_walk.userdef_speed) > 0.1f ||
592 g_walk.base_speed =
U.walk_navigation.walk_speed / walk->
grid;
593 g_walk.userdef_speed =
U.walk_navigation.walk_speed;
596 if (
fabsf(userdef_jump_height -
g_walk.userdef_jump_height) > 0.1f ||
599 g_walk.jump_height = userdef_jump_height;
600 g_walk.userdef_jump_height = userdef_jump_height;
623 walk->
speed =
U.walk_navigation.walk_speed / walk->
grid;
638#ifdef USE_TABLET_SUPPORT
644#ifdef NDOF_WALK_DRAW_TOOMUCH
651#ifdef WITH_INPUT_NDOF
652 walk->ndof =
nullptr;
689#ifdef WITH_INPUT_NDOF
691 walkApply_ndof(
C, walk,
true);
700#ifdef NDOF_WALK_DEBUG
701 puts(
"\n-- walk end --");
719#ifdef WITH_INPUT_NDOF
721 MEM_delete(walk->ndof);
743#ifdef USE_TABLET_SUPPORT
758#ifdef WITH_INPUT_NDOF
764 const wmNDOFMotionData *incoming_ndof =
static_cast<const wmNDOFMotionData *
>(
766 switch (incoming_ndof->progress) {
769# ifdef NDOF_WALK_DEBUG
770 puts(
"start keeping track of 3D mouse position");
776# ifdef NDOF_WALK_DEBUG
780 if (walk->ndof ==
nullptr) {
782 walk->ndof = MEM_dupalloc(incoming_ndof);
786 memcpy(walk->ndof, incoming_ndof,
sizeof(wmNDOFMotionData));
792# ifdef NDOF_WALK_DEBUG
793 puts(
"stop keeping track of 3D mouse position");
796 MEM_delete(walk->ndof);
798 walk->ndof =
nullptr;
815 switch (event->
val) {
914#define JUMP_SPEED_MIN 1.0f
915#define JUMP_TIME_MAX 0.2f
916#define JUMP_SPEED_MAX sqrtf(2.0f * walk->gravity * walk->jump_height)
961 float loc[3], nor[3];
977 teleport->
duration =
U.walk_navigation.teleport_time;
1014#define JUMP_HEIGHT_FACTOR 1.5f
1015#define JUMP_HEIGHT_MIN 0.1f
1016#define JUMP_HEIGHT_MAX 10.0f
1027#undef JUMP_HEIGHT_FACTOR
1028#undef JUMP_HEIGHT_MIN
1029#undef JUMP_HEIGHT_MAX
1036 const bool do_rotate,
1037 const bool do_translate,
1038 const bool is_confirm)
1042 const bool use_autokey = is_confirm || walk->
anim_playing;
1053 return gravity * (time * time) * 0.5f;
1058 return velocity / gravity;
1063#define WALK_ROTATE_TABLET_FAC 8.8f
1064#define WALK_ROTATE_CONSTANT_FAC DEG2RADF(0.15f)
1065#define WALK_TOP_LIMIT DEG2RADF(85.0f)
1066#define WALK_BOTTOM_LIMIT DEG2RADF(-80.0f)
1067#define WALK_MOVE_SPEED (0 ? 0.0f : g_walk.base_speed)
1068#define WALK_JUMP_HEIGHT (0 ? 0.0f : g_walk.jump_height)
1069#define WALK_BOOST_FACTOR ((void)0, walk->speed_factor)
1070#define WALK_ZUP_CORRECT_FAC 0.1f
1071#define WALK_ZUP_CORRECT_ACCEL 0.05f
1079 float dvec[3] = {0.0f, 0.0f, 0.0f};
1084#ifdef NDOF_WALK_DEBUG
1086 static uint iteration = 1;
1087 printf(
"walk timer %d\n", iteration++);
1100 moffset[1] = -moffset[1];
1104 moffset[0] = -moffset[0];
1105 moffset[1] = -moffset[1];
1118 bool changed_viewquat =
false;
1121 bool dvec_grid_scale =
true;
1126 double time_current;
1128 float time_redraw_clamped;
1129#ifdef NDOF_WALK_DRAW_TOOMUCH
1136 time_redraw_clamped =
min_ff(0.05f, time_redraw);
1163#ifdef USE_TABLET_SUPPORT
1192 changed_viewquat =
true;
1204 if (upvec[2] < 0.0f) {
1205 moffset[0] = -moffset[0];
1212#ifdef USE_TABLET_SUPPORT
1229 changed_viewquat =
true;
1233 const float horizon_plane[3] = {0.0f, 0.0f, 1.0f};
1234 const float factor = 5.0f * time_redraw_clamped * walk->
zlock_momentum *
1240 changed_viewquat =
true;
1295 dvec_tmp[0] = direction * rv3d->
viewinv[0][0];
1296 dvec_tmp[1] = direction * rv3d->
viewinv[0][1];
1348 float difference = -100.0f;
1358 if (
fabsf(difference) < fall_distance) {
1360 dvec[2] -= difference;
1380 float ray_distance, difference = -100.0f;
1401 if (difference > 0.0f) {
1403 dvec[2] -= difference;
1409 dvec[2] = z_cur - z_new;
1414 dvec[2] = z_cur - z_new;
1443 dvec_grid_scale =
false;
1450 if (changed_viewquat) {
1474#undef WALK_ROTATE_TABLET_FAC
1475#undef WALK_TOP_LIMIT
1476#undef WALK_BOTTOM_LIMIT
1477#undef WALK_MOVE_SPEED
1478#undef WALK_JUMP_HEIGHT
1479#undef WALK_BOOST_FACTOR
1482#ifdef WITH_INPUT_NDOF
1483static void walkApply_ndof(bContext *
C, WalkInfo *walk,
bool is_confirm)
1486 bool has_translate, has_rotate;
1488 view3d_ndof_fly(*walk->ndof,
1492 lock_ob ? lock_ob->protectflag : 0,
1496 if (has_translate || has_rotate) {
1497 walk->redraw =
true;
1500 walk->need_rotation_keyframe |= has_rotate;
1501 walk->need_translation_keyframe |= has_translate;
1503 C, walk, walk->need_rotation_keyframe, walk->need_translation_keyframe, is_confirm);
1542 status.
item(
IFACE_(
"Local Up/Down"), ICON_NONE);
1562 status.
item(fmt::format(
"{} ({:.2f})",
IFACE_(
"Acceleration"),
g_walk.base_speed), ICON_NONE);
1566 status.
item(fmt::format(
"{} ({:.2f})",
IFACE_(
"Jump Height"),
g_walk.jump_height), ICON_NONE);
1610 bool do_draw =
false;
1623#ifdef WITH_INPUT_NDOF
1626 walkApply_ndof(
C, walk,
false);
1668 ot->
name =
"Walk Navigation";
1669 ot->
description =
"Interactively walk around the scene";
1670 ot->
idname =
"VIEW3D_OT_walk";
Camera data-block and utility functions.
#define ENUM_OPERATORS(_enum_type)
#define BVH_RAYCAST_DIST_MAX
Platform independent time functions.
Object is a sort of wrapper for general info.
#define RV3D_LOCK_FLAGS(rv3d)
#define REGION_DRAW_POST_PIXEL
Read Blender memory allocation and freeing.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
void item(std::string text, int icon1, int icon2=0)
void opmodal(std::string text, const wmOperatorType *ot, int propvalue, bool inverted=false)
float distance(float, float) RET
MINLINE float min_ff(float a, float b)
void mul_m3_v3(const float M[3][3], float r[3])
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
@ WALK_BIT_LOCAL_BACKWARD
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
bool ED_undo_is_memfile_compatible(const bContext *C)
MINLINE void copy_v3_v3(float r[3], const float a[3])
static void drawWalkPixel(const bContext *, ARegion *region, void *arg)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
Object * ED_view3d_cameracontrol_object_get(View3DCameraControl *vctrl)
@ USER_WALK_MOUSE_REVERSE
static void walk_draw_status(bContext *C, wmOperator *op)
float normalize_qt(float q[4])
@ WALK_MODAL_SLOW_DISABLE
@ WALK_MODAL_DIR_FORWARD_STOP
@ WALK_MODAL_DIR_LOCAL_UP_STOP
@ WALK_MODAL_DECREASE_JUMP
@ WALK_MODAL_DIR_BACKWARD
@ WALK_MODAL_DIR_LOCAL_UP
@ WALK_MODAL_DIR_LEFT_STOP
@ WALK_MODAL_DIR_LOCAL_DOWN
@ WALK_MODAL_INCREASE_JUMP
@ WALK_MODAL_GRAVITY_TOGGLE
@ WALK_MODAL_DIR_DOWN_STOP
@ WALK_MODAL_DIR_BACKWARD_STOP
@ WALK_MODAL_DIR_LOCAL_DOWN_STOP
@ WALK_MODAL_DIR_RIGHT_STOP
@ WALK_MODAL_FAST_DISABLE
bool ED_view3d_camera_lock_undo_push(const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C)
void immBegin(GPUPrimType, uint vertex_len)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
wmWindow * CTX_wm_window(const bContext *C)
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
static struct blender::@320262344277007237041155264327207227220301061033 g_walk
@ RV3D_LOCK_ANY_TRANSFORM
void immUniformThemeColorAlpha(int color_id, float a)
void ED_region_tag_redraw(ARegion *region)
@ WALK_TELEPORT_STATE_OFF
static void walk_cancel(bContext *C, wmOperator *op)
MINLINE void mul_v3_fl(float r[3], float f)
static float walk_calc_free_fall_distance(const float gravity, const float time)
void ED_view3d_cameracontrol_release(View3DCameraControl *vctrl, const bool restore)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
static wmOperatorStatus walk_modal(bContext *C, wmOperator *op, const wmEvent *event)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void immVertex2f(uint attr_id, float x, float y)
static void walkMoveCamera(bContext *C, WalkInfo *walk, const bool do_rotate, const bool do_translate, const bool is_confirm)
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
void WM_cursor_grab_enable(wmWindow *win, const eWM_CursorWrapAxis wrap, const rcti *wrap_region, const bool hide)
bool BKE_constraint_has_influence(const struct bConstraint *con)
static float walk_calc_velocity_zero_time(const float gravity, const float velocity)
void BKE_report(ReportList *reports, eReportType type, const char *message)
View3DCameraControl * ED_view3d_cameracontrol_acquire(Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d)
@ GPU_SHADER_3D_UNIFORM_COLOR
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
rctf BKE_camera_view_border(const struct Scene *scene, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, int winx, int winy, bool no_shift, bool no_zoom, bool no_roll)
void axis_angle_to_quat_single(float q[4], char axis, float angle)
static void walkEvent(WalkInfo *walk, const wmEvent *event)
MINLINE void negate_v3(float r[3])
RegionView3D * CTX_wm_region_view3d(const bContext *C)
void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2])
@ WALK_AXISLOCK_STATE_DONE
@ WALK_AXISLOCK_STATE_OFF
@ WALK_AXISLOCK_STATE_ACTIVE
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
static wmOperatorStatus walkEnd(bContext *C, WalkInfo *walk)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float n[3])
bool ED_view3d_offset_lock_check(const View3D *v3d, const RegionView3D *rv3d)
MINLINE void add_v3_v3(float r[3], const float a[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
@ WALK_GRAVITY_STATE_START
@ WALK_GRAVITY_STATE_JUMP
Main * CTX_data_main(const bContext *C)
static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int mval[2])
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
MINLINE float max_ff(float a, float b)
MINLINE float normalize_v3_length(float n[3], float unit_length)
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
bool ED_operator_region_view3d_active(bContext *C)
static bool walk_ray_cast(RegionView3D *rv3d, WalkInfo *walk, float r_location[3], float r_normal[3], float *r_ray_distance)
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
double BLI_time_now_seconds()
Scene * CTX_data_scene(const bContext *C)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
void VIEW3D_OT_walk(wmOperatorType *ot)
static bool walk_floor_distance_get(RegionView3D *rv3d, WalkInfo *walk, const float dvec[3], float *r_distance)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
void ED_view3d_cameracontrol_update(View3DCameraControl *vctrl, const bool use_autokey, bContext *C, const bool do_rotate, const bool do_translate)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
float view3d_horizon_correct_quat_ease_out(float quat[4], const float horizon_plane[3], const bool horizon_plane_no_flip, const float factor)
View3D * CTX_wm_view3d(const bContext *C)
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
void walk_modal_keymap(wmKeyConfig *keyconf)
static wmOperatorStatus walk_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void walk_navigation_mode_set(WalkInfo *walk, eWalkMethod mode)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
ListBaseT< bConstraint > constraints
eRegionView3D_Persp persp
struct PhysicsSettings physics_settings
ed::transform::SnapObjectContext * snap_context
bool need_translation_keyframe
eWalkMethod navigation_mode
eWalkGravityState gravity_state
bool need_rotation_keyframe
eWalkDirectionFlag active_directions
View3DCameraControl * v3d_camera_control
eWalkMethod navigation_mode
float userdef_jump_height
struct ARegionType * type
void(*) cancel(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
struct wmOperatorType * type
#define WALK_ROTATE_TABLET_FAC
#define WALK_ROTATE_CONSTANT_FAC
#define WALK_ZUP_CORRECT_ACCEL
#define WALK_ZUP_CORRECT_FAC
#define WALK_BOOST_FACTOR
#define JUMP_HEIGHT_FACTOR
#define WALK_BOTTOM_LIMIT
#define ISMOUSE_MOTION(event_type)