[Bf-blender-cvs] [ab49437] master: View Navigation: Walk and Fly modes

Dalai Felinto noreply at git.blender.org
Tue Dec 3 06:23:40 CET 2013


Commit: ab494379586034a6844c858324815e3b1ff3cbb2
Author: Dalai Felinto
Date:   Tue Dec 3 03:14:09 2013 -0200
http://developer.blender.org/rBab494379586034a6844c858324815e3b1ff3cbb2

View Navigation: Walk and Fly modes

This is a addtion to the dynamic fly mode.
It behaves as the first person navigation system available in most 3d world  games nowadays.

You can alternate between the old mode (Fly) and the new mode (Walk) in User Preferences > Inputs

Manual:
-------
http://wiki.blender.org/index.php/Doc:2.6/Manual/3D_interaction/Navigating/3D_View#View_Navigation
http://wiki.blender.org/index.php/Doc:2.6/Manual/3D_interaction/Navigating/3D_View/Navigation_Modes

Shortcuts:
----------
WASD (hold)  - Move forward/backward and straft left/right
QE (hold)    - Move up and down
Tab          - Alternate between Walk and Fly modes
Shift (hold) - Speed up movement
Alt (hold)   - Slow down movement
Space or MMB - Teleport
V            - Jump
+/- or mouse wheel - speed increase/decrease speed for this Blender session

User Preferences Options:
-------------------------
Navigation Mode   - fly/walk navigation systems (fly is the old, walk is the new, next options are for walk mode only)
Gravity           - alternate between free navigation and walk with gravity modes
Mouse Sensitivity - sensitivity factor to mouse influence to look around
Teleport Duration - how long the teleport lasts
Camera Height     - camera height to use in gravity mode
Jump Height       - maximum jump speed in m/s
Move Speed        - base move speed in m/s
Boost Factor      - multiplication factor when running or going slow (1/boost)

Development Notes:
------------------
* The initial code was based on view3d_fly.c.
* The NDoF code was not touched, so it most likely is not working.

Pending Issues:
---------------
* Draw in the UI the shortcut options, and current values (e.g., Mode: Fly/Walk)
  (we need a proper API for that)
* OSX seems to present issues if we re-center the mouse every time. We implemented a workaround for that, but a real fix would be welcome.

Code reviewed and with collaborations from Campbell Barton - @campbellbarton
Differential Revision: http://developer.blender.org/D30

===================================================================

M	release/scripts/startup/bl_ui/space_userpref.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/space_view3d/CMakeLists.txt
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_intern.h
M	source/blender/editors/space_view3d/view3d_ops.c
A	source/blender/editors/space_view3d/view3d_walk.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_userdef.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 17a3e8b..acd4fc8 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1053,6 +1053,28 @@ class USERPREF_PT_input(Panel):
 
         col.separator()
         sub = col.column()
+        sub.label(text="View Navigation:")
+        sub.row().prop(inputs, "navigation_mode", expand=True)
+        if inputs.navigation_mode == 'WALK':
+            walk = inputs.walk_navigation
+
+            sub.prop(walk, "use_mouse_reverse")
+            sub.prop(walk, "mouse_speed")
+            sub.prop(walk, "teleport_time")
+
+            sub = col.column(align=True)
+            sub.prop(walk, "walk_speed")
+            sub.prop(walk, "walk_speed_factor")
+
+            sub.separator()
+            sub.prop(walk, "use_gravity")
+            sub = col.column(align=True)
+            sub.active = walk.use_gravity
+            sub.prop(walk, "view_height")
+            sub.prop(walk, "jump_height")
+
+        col.separator()
+        sub = col.column()
         sub.label(text="NDOF Device:")
         sub.prop(inputs, "ndof_sensitivity", text="NDOF Sensitivity")
         sub.prop(inputs, "ndof_orbit_sensitivity", text="NDOF Orbit Sensitivity")
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 74d274a..dd3710f 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -435,6 +435,7 @@ class VIEW3D_MT_view_navigation(Menu):
         layout.separator()
 
         layout.operator("view3d.fly")
+        layout.operator("view3d.walk")
 
 
 class VIEW3D_MT_view_align(Menu):
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index c6cf32c..047dc36 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7385,7 +7385,7 @@ static void convert_tface_mt(FileData *fd, Main *main)
 
 /* initialize userdef with non-UI dependency stuff */
 /* other initializers (such as theme color defaults) go to resources.c */
-static void do_versions_userdef(FileData *UNUSED(fd), BlendFileData *bfd)
+static void do_versions_userdef(FileData *fd, BlendFileData *bfd)
 {
 	Main *bmain = bfd->main;
 	UserDef *user = bfd->user;
@@ -7401,6 +7401,16 @@ static void do_versions_userdef(FileData *UNUSED(fd), BlendFileData *bfd)
 			copy_v4_v4_char(btheme->tseq.grid, btheme->tseq.back);
 		}
 	}
+
+	if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "WalkNavigation", "walk_navigation")) {
+		user->walk_navigation.mouse_speed = 1.0f;
+		user->walk_navigation.walk_speed = 2.5f;       /* m/s */
+		user->walk_navigation.walk_speed_factor = 5.0f;
+		user->walk_navigation.view_height =  1.6f;   /* m */
+		user->walk_navigation.jump_height = 0.4f;      /* m */
+		user->walk_navigation.teleport_time = 0.2f; /* s */
+	}
+
 }
 
 static void do_versions(FileData *fd, Library *lib, Main *main)
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index af89c53..51477ec 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -50,6 +50,7 @@ set(SRC
 	view3d_draw.c
 	view3d_edit.c
 	view3d_fly.c
+	view3d_walk.c
 	view3d_header.c
 	view3d_iterators.c
 	view3d_ops.c
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 372f872..ea335f7 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -3889,6 +3889,35 @@ void VIEW3D_OT_view_persportho(wmOperatorType *ot)
 	ot->flag = 0;
 }
 
+static int view3d_navigate_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
+{
+	eViewNavigation_Method mode = U.navigation_mode;
+
+	switch (mode) {
+		case VIEW_NAVIGATION_FLY:
+			WM_operator_name_call(C, "VIEW3D_OT_fly", WM_OP_INVOKE_DEFAULT, NULL);
+			break;
+		case VIEW_NAVIGATION_WALK:
+		default:
+			WM_operator_name_call(C, "VIEW3D_OT_walk", WM_OP_INVOKE_DEFAULT, NULL);
+			break;
+	}
+
+	return OPERATOR_FINISHED;
+}
+
+void VIEW3D_OT_navigate(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "View Navigation";
+	ot->description = "Interactively navigate around the scene. It uses the mode (walk/fly) preference";
+	ot->idname = "VIEW3D_OT_navigate";
+
+	/* api callbacks */
+	ot->invoke = view3d_navigate_invoke;
+	ot->poll = ED_operator_view3d_active;
+}
+
 
 /* ******************** add background image operator **************** */
 
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 9bca534..fae7804 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -92,6 +92,7 @@ void VIEW3D_OT_view_center_camera(struct wmOperatorType *ot);
 void VIEW3D_OT_view_center_lock(struct wmOperatorType *ot);
 void VIEW3D_OT_view_pan(struct wmOperatorType *ot);
 void VIEW3D_OT_view_persportho(struct wmOperatorType *ot);
+void VIEW3D_OT_navigate(struct wmOperatorType *ot);
 void VIEW3D_OT_background_image_add(struct wmOperatorType *ot);
 void VIEW3D_OT_background_image_remove(struct wmOperatorType *ot);
 void VIEW3D_OT_view_orbit(struct wmOperatorType *ot);
@@ -112,6 +113,9 @@ float ndof_to_axis_angle(const struct wmNDOFMotionData *ndof, float axis[3]);
 void view3d_keymap(struct wmKeyConfig *keyconf);
 void VIEW3D_OT_fly(struct wmOperatorType *ot);
 
+/* view3d_walk.c */
+void VIEW3D_OT_walk(struct wmOperatorType *ot);
+
 /* view3d_ruler.c */
 void VIEW3D_OT_ruler(struct wmOperatorType *ot);
 
@@ -195,6 +199,7 @@ void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect);
 void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d);
 
 void fly_modal_keymap(struct wmKeyConfig *keyconf);
+void walk_modal_keymap(struct wmKeyConfig *keyconf);
 void viewrotate_modal_keymap(struct wmKeyConfig *keyconf);
 void viewmove_modal_keymap(struct wmKeyConfig *keyconf);
 void viewzoom_modal_keymap(struct wmKeyConfig *keyconf);
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c
index 111b2ea..1240515 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -172,6 +172,8 @@ void view3d_operatortypes(void)
 	WM_operatortype_append(VIEW3D_OT_localview);
 	WM_operatortype_append(VIEW3D_OT_game_start);
 	WM_operatortype_append(VIEW3D_OT_fly);
+	WM_operatortype_append(VIEW3D_OT_walk);
+	WM_operatortype_append(VIEW3D_OT_navigate);
 	WM_operatortype_append(VIEW3D_OT_ruler);
 	WM_operatortype_append(VIEW3D_OT_layers);
 	WM_operatortype_append(VIEW3D_OT_copybuffer);
@@ -224,7 +226,7 @@ void view3d_keymap(wmKeyConfig *keyconf)
 	WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_to_active", PADPERIOD, KM_PRESS, KM_SHIFT, 0);
 	WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_clear", PADPERIOD, KM_PRESS, KM_ALT, 0);
 
-	WM_keymap_verify_item(keymap, "VIEW3D_OT_fly", FKEY, KM_PRESS, KM_SHIFT, 0);
+	WM_keymap_verify_item(keymap, "VIEW3D_OT_navigate", FKEY, KM_PRESS, KM_SHIFT, 0);
 
 	WM_keymap_verify_item(keymap, "VIEW3D_OT_smoothview", TIMER1, KM_ANY, KM_ANY, 0);
 	
@@ -504,6 +506,7 @@ void view3d_keymap(wmKeyConfig *keyconf)
 	transform_keymap_for_space(keyconf, keymap, SPACE_VIEW3D);
 
 	fly_modal_keymap(keyconf);
+	walk_modal_keymap(keyconf);
 	viewrotate_modal_keymap(keyconf);
 	viewmove_modal_keymap(keyconf);
 	viewzoom_modal_keymap(keyconf);
diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c
new file mode 100644
index 0000000..26f942b
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_walk.c
@@ -0,0 +1,1419 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Dalai Felinto, Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_walk.c
+ *  \ingroup spview3d
+ */
+
+/* defines VIEW3D_OT_navigate - walk modal operator */
+
+//#define NDOF_WALK_DEBUG
+//#define NDOF_WALK_DRAW_TOOMUCH  /* is this needed for ndof? - commented so redraw doesnt thrash - campbell */
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+#include "DNA_camera_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+#include "BKE_report.h"
+
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "BIF_gl.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_space_api.h"
+#include "ED_transform.h"
+
+#include "PIL_time.h" /* smoothview */
+
+#include "view3d_intern.h"  /* own include */
+
+#define EARTH_GRAVITY 9.80668f /* m/s2 */
+
+/* prototypes */
+static float getVelocityZeroTime(float velocity);
+
+/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
+enum {
+	WALK_MODAL_CANCEL = 1,
+	WALK_MODAL_CONFIRM,
+	WALK_MODAL_DIR_FORWARD,
+	WALK_MODAL_DIR_FORWARD_STOP,
+	WALK_MODAL_DIR_BACKWARD,
+	WALK_MODAL_DIR_BACKWARD_STOP,
+	WALK_MODAL_DIR_LEFT,
+	WALK_MODAL_DIR_LEFT_STOP,
+	WALK_MODAL_DIR_RIGHT,
+	WALK_MODAL_DIR_RIGHT_STOP,
+	WALK_MODAL_DIR_UP,
+	WALK_MODAL_DIR_UP_STOP,
+	WALK_MODA

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list