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/space_view3d.c9
-rw-r--r--source/blender/editors/space_view3d/view3d_buttons.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_cursor_snap.c25
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_iterators.c5
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate.c28
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_dolly.c9
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_move.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_ndof.c80
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_roll.c29
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_rotate.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_zoom.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_zoom_border.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_placement.c11
-rw-r--r--source/blender/editors/space_view3d/view3d_project.c59
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c8
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c33
19 files changed, 244 insertions, 92 deletions
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 7addda0f8c3..4656540c19b 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -413,6 +413,9 @@ static void view3d_main_region_init(wmWindowManager *wm, ARegion *region)
keymap = WM_keymap_ensure(wm->defaultconf, "Particle", 0, 0);
WM_event_add_keymap_handler(&region->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Sculpt Curves", 0, 0);
+ WM_event_add_keymap_handler(&region->handlers, keymap);
+
/* editfont keymap swallows all... */
keymap = WM_keymap_ensure(wm->defaultconf, "Font", 0, 0);
WM_event_add_keymap_handler(&region->handlers, keymap);
@@ -1475,6 +1478,9 @@ void ED_view3d_buttons_region_layout_ex(const bContext *C,
case CTX_MODE_EDIT_CURVE:
ARRAY_SET_ITEMS(contexts, ".curve_edit");
break;
+ case CTX_MODE_EDIT_CURVES:
+ ARRAY_SET_ITEMS(contexts, ".curves_edit");
+ break;
case CTX_MODE_EDIT_SURFACE:
ARRAY_SET_ITEMS(contexts, ".curve_edit");
break;
@@ -1523,6 +1529,9 @@ void ED_view3d_buttons_region_layout_ex(const bContext *C,
case CTX_MODE_VERTEX_GPENCIL:
ARRAY_SET_ITEMS(contexts, ".greasepencil_vertex");
break;
+ case CTX_MODE_SCULPT_CURVES:
+ ARRAY_SET_ITEMS(contexts, ".curves_sculpt");
+ break;
default:
break;
}
diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c
index b77994e28cb..cf52134f5ab 100644
--- a/source/blender/editors/space_view3d/view3d_buttons.c
+++ b/source/blender/editors/space_view3d/view3d_buttons.c
@@ -355,7 +355,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
has_meshdata = (tot || totedgedata);
}
- else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
+ else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
TransformMedian_Curve *median = &median_basis.curve;
Curve *cu = ob->data;
BPoint *bp;
@@ -1089,7 +1089,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
}
}
}
- else if (ELEM(ob->type, OB_CURVE, OB_SURF) &&
+ else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF) &&
(apply_vcos || median_basis.curve.b_weight || median_basis.curve.weight ||
median_basis.curve.radius || median_basis.curve.tilt)) {
const TransformMedian_Curve *median = &median_basis.curve,
diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c
index 785c5ab28c8..53f7b3d5871 100644
--- a/source/blender/editors/space_view3d/view3d_cursor_snap.c
+++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c
@@ -63,7 +63,7 @@ typedef struct SnapCursorDataIntern {
int x;
int y;
#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
- short shift, ctrl, alt, oskey;
+ uint8_t modifier;
#endif
} last_eventstate;
@@ -478,10 +478,7 @@ static bool v3d_cursor_eventstate_has_changed(SnapCursorDataIntern *data_intern,
}
#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
if (!(state && (state->flag & V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE))) {
- if ((event->ctrl != data_intern->last_eventstate.ctrl) ||
- (event->shift != data_intern->last_eventstate.shift) ||
- (event->alt != data_intern->last_eventstate.alt) ||
- (event->oskey != data_intern->last_eventstate.oskey)) {
+ if (event->modifier != data_intern->last_eventstate.modifier) {
return true;
}
}
@@ -507,19 +504,13 @@ static bool v3d_cursor_is_snap_invert(SnapCursorDataIntern *data_intern, const w
}
const wmEvent *event = wm->winactive->eventstate;
- if ((event->ctrl == data_intern->last_eventstate.ctrl) &&
- (event->shift == data_intern->last_eventstate.shift) &&
- (event->alt == data_intern->last_eventstate.alt) &&
- (event->oskey == data_intern->last_eventstate.oskey)) {
+ if (event->modifier == data_intern->last_eventstate.modifier) {
/* Nothing has changed. */
return data_intern->snap_data.is_snap_invert;
}
/* Save new eventstate. */
- data_intern->last_eventstate.ctrl = event->ctrl;
- data_intern->last_eventstate.shift = event->shift;
- data_intern->last_eventstate.alt = event->alt;
- data_intern->last_eventstate.oskey = event->oskey;
+ data_intern->last_eventstate.modifier = event->modifier;
const int snap_on = data_intern->snap_on;
@@ -530,10 +521,10 @@ static bool v3d_cursor_is_snap_invert(SnapCursorDataIntern *data_intern, const w
}
if (kmi->propvalue == snap_on) {
- if ((ELEM(kmi->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY) && event->ctrl) ||
- (ELEM(kmi->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY) && event->shift) ||
- (ELEM(kmi->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY) && event->alt) ||
- ((kmi->type == EVT_OSKEY) && event->oskey)) {
+ if ((ELEM(kmi->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY) && (event->modifier & KM_CTRL)) ||
+ (ELEM(kmi->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY) && (event->modifier & KM_SHIFT)) ||
+ (ELEM(kmi->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY) && (event->modifier & KM_ALT)) ||
+ ((kmi->type == EVT_OSKEY) && (event->modifier & KM_OSKEY))) {
return true;
}
}
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index c4078c4a690..593c4f6e755 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1351,7 +1351,7 @@ static void draw_selected_name(
}
}
}
- else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
+ else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVES_LEGACY)) {
/* try to display active bone and active shapekey too (if they exist) */
if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) {
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index d6bc7ded92e..5adce170e06 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -832,13 +832,13 @@ void ED_view3d_cursor3d_position(bContext *C,
return;
}
- ED_view3d_calc_zfac(rv3d, cursor_co, &flip);
+ ED_view3d_calc_zfac_ex(rv3d, cursor_co, &flip);
/* Reset the depth based on the view offset (we _know_ the offset is in front of us). */
if (flip) {
negate_v3_v3(cursor_co, rv3d->ofs);
/* re initialize, no need to check flip again */
- ED_view3d_calc_zfac(rv3d, cursor_co, NULL /* &flip */);
+ ED_view3d_calc_zfac(rv3d, cursor_co);
}
if (use_depth) { /* maybe this should be accessed some other way */
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c
index 6cc197c8a43..a0c010a6813 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c
@@ -105,8 +105,8 @@ static int gizmo_preselect_elem_test_select(bContext *C, wmGizmo *gz, const int
MeshElemGizmo3D *gz_ele = (MeshElemGizmo3D *)gz;
/* Hack: Switch action mode based on key input */
- const bool is_ctrl_pressed = WM_event_modifier_flag(event) & KM_CTRL;
- const bool is_shift_pressed = WM_event_modifier_flag(event) & KM_SHIFT;
+ const bool is_ctrl_pressed = (event->modifier & KM_CTRL) != 0;
+ const bool is_shift_pressed = (event->modifier & KM_SHIFT) != 0;
EDBM_preselect_action_set(gz_ele->psel, PRESELECT_ACTION_TRANSFORM);
if (is_ctrl_pressed && !is_shift_pressed) {
EDBM_preselect_action_set(gz_ele->psel, PRESELECT_ACTION_CREATE);
diff --git a/source/blender/editors/space_view3d/view3d_iterators.c b/source/blender/editors/space_view3d/view3d_iterators.c
index e1fd96ca1d4..055aac041f1 100644
--- a/source/blender/editors/space_view3d/view3d_iterators.c
+++ b/source/blender/editors/space_view3d/view3d_iterators.c
@@ -25,6 +25,7 @@
#include "BKE_editmesh.h"
#include "BKE_mesh_iterators.h"
#include "BKE_mesh_runtime.h"
+#include "BKE_mesh_wrapper.h"
#include "BKE_modifier.h"
#include "DEG_depsgraph.h"
@@ -334,6 +335,7 @@ void mesh_foreachScreenVert(
Mesh *me = editbmesh_get_eval_cage_from_orig(
vc->depsgraph, vc->scene, vc->obedit, &CD_MASK_BAREMESH);
+ me = BKE_mesh_wrapper_ensure_subdivision(vc->obedit, me);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -396,6 +398,7 @@ void mesh_foreachScreenEdge(ViewContext *vc,
Mesh *me = editbmesh_get_eval_cage_from_orig(
vc->depsgraph, vc->scene, vc->obedit, &CD_MASK_BAREMESH);
+ me = BKE_mesh_wrapper_ensure_subdivision(vc->obedit, me);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -483,6 +486,7 @@ void mesh_foreachScreenEdge_clip_bb_segment(ViewContext *vc,
Mesh *me = editbmesh_get_eval_cage_from_orig(
vc->depsgraph, vc->scene, vc->obedit, &CD_MASK_BAREMESH);
+ me = BKE_mesh_wrapper_ensure_subdivision(vc->obedit, me);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -554,6 +558,7 @@ void mesh_foreachScreenFace(
Mesh *me = editbmesh_get_eval_cage_from_orig(
vc->depsgraph, vc->scene, vc->obedit, &CD_MASK_BAREMESH);
+ me = BKE_mesh_wrapper_ensure_subdivision(vc->obedit, me);
ED_view3d_check_mats_rv3d(vc->rv3d);
data.vc = *vc;
diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c
index 0305989d142..d1e7f6ffb12 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate.c
@@ -396,7 +396,7 @@ ViewOpsData *viewops_data_create(bContext *C, const wmEvent *event, enum eViewOp
{
float tvec[3];
negate_v3_v3(tvec, rv3d->ofs);
- vod->init.zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL);
+ vod->init.zfac = ED_view3d_calc_zfac(rv3d, tvec);
}
vod->reverse = 1.0f;
@@ -544,26 +544,24 @@ static void axis_set_view(bContext *C,
void viewmove_apply(ViewOpsData *vod, int x, int y)
{
- if (ED_view3d_offset_lock_check(vod->v3d, vod->rv3d)) {
- vod->rv3d->ofs_lock[0] -= ((vod->prev.event_xy[0] - x) * 2.0f) / (float)vod->region->winx;
- vod->rv3d->ofs_lock[1] -= ((vod->prev.event_xy[1] - y) * 2.0f) / (float)vod->region->winy;
+ const float event_ofs[2] = {
+ vod->prev.event_xy[0] - x,
+ vod->prev.event_xy[1] - y,
+ };
+
+ if ((vod->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) {
+ ED_view3d_camera_view_pan(vod->region, event_ofs);
}
- else if ((vod->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) {
- const float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f;
- vod->rv3d->camdx += (vod->prev.event_xy[0] - x) / (vod->region->winx * zoomfac);
- vod->rv3d->camdy += (vod->prev.event_xy[1] - y) / (vod->region->winy * zoomfac);
- CLAMP(vod->rv3d->camdx, -1.0f, 1.0f);
- CLAMP(vod->rv3d->camdy, -1.0f, 1.0f);
+ else if (ED_view3d_offset_lock_check(vod->v3d, vod->rv3d)) {
+ vod->rv3d->ofs_lock[0] -= (event_ofs[0] * 2.0f) / (float)vod->region->winx;
+ vod->rv3d->ofs_lock[1] -= (event_ofs[1] * 2.0f) / (float)vod->region->winy;
}
else {
float dvec[3];
- float mval_f[2];
- mval_f[0] = x - vod->prev.event_xy[0];
- mval_f[1] = y - vod->prev.event_xy[1];
- ED_view3d_win_to_delta(vod->region, mval_f, dvec, vod->init.zfac);
+ ED_view3d_win_to_delta(vod->region, event_ofs, vod->init.zfac, dvec);
- add_v3_v3(vod->rv3d->ofs, dvec);
+ sub_v3_v3(vod->rv3d->ofs, dvec);
if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
view3d_boxview_sync(vod->area, vod->region);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
index 06b616e71da..7b6b119294d 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_dolly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
@@ -50,9 +50,12 @@ void viewdolly_modal_keymap(wmKeyConfig *keyconf)
/* disabled mode switching for now, can re-implement better, later on */
#if 0
- WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE);
- WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE);
- WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE);
+ WM_modalkeymap_add_item(
+ keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, KM_ANY, VIEWROT_MODAL_SWITCH_ROTATE);
+ WM_modalkeymap_add_item(
+ keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, KM_ANY, VIEWROT_MODAL_SWITCH_ROTATE);
+ WM_modalkeymap_add_item(
+ keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, KM_ANY, VIEWROT_MODAL_SWITCH_MOVE);
#endif
/* assign map to operators */
diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.c
index d2fd505a703..071643e9314 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_move.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_move.c
@@ -43,8 +43,8 @@ void viewmove_modal_keymap(wmKeyConfig *keyconf)
keymap = WM_modalkeymap_ensure(keyconf, "View3D Move Modal", modal_items);
/* items for modal map */
- WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
- WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
+ WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, KM_ANY, VIEW_MODAL_CONFIRM);
+ WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, KM_ANY, VIEW_MODAL_CONFIRM);
/* disabled mode switching for now, can re-implement better, later on */
#if 0
diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
index ced8eca710b..1ce9bdcb211 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
@@ -48,7 +48,7 @@ static float view3d_ndof_pan_speed_calc_ex(RegionView3D *rv3d, const float depth
float speed = rv3d->pixsize * NDOF_PIXELS_PER_SECOND;
if (rv3d->is_persp) {
- speed *= ED_view3d_calc_zfac(rv3d, depth_pt, NULL);
+ speed *= ED_view3d_calc_zfac(rv3d, depth_pt);
}
return speed;
@@ -347,6 +347,70 @@ void view3d_ndof_fly(const wmNDOFMotionData *ndof,
/** \} */
/* -------------------------------------------------------------------- */
+/** \name NDOF Camera View Support
+ * \{ */
+
+/**
+ * 2D orthographic style NDOF navigation within the camera view.
+ * Support navigating the camera view instead of leaving the camera-view and navigating in 3D.
+ */
+static int view3d_ndof_cameraview_pan_zoom(bContext *C, const wmEvent *event)
+{
+ const wmNDOFMotionData *ndof = event->customdata;
+ View3D *v3d = CTX_wm_view3d(C);
+ ARegion *region = CTX_wm_region(C);
+ RegionView3D *rv3d = region->regiondata;
+
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
+
+ if ((v3d->camera && (rv3d->persp == RV3D_CAMOB) && (v3d->flag2 & V3D_LOCK_CAMERA) == 0)) {
+ /* pass */
+ }
+ else {
+ return OPERATOR_PASS_THROUGH;
+ }
+
+ const bool has_translate = !is_zero_v2(ndof->tvec);
+ const bool has_zoom = ndof->tvec[2] != 0.0f;
+
+ /* NOTE(@campbellbarton): In principle rotating could pass through to regular
+ * non-camera NDOF behavior (exiting the camera-view and rotating).
+ * Disabled this block since in practice it's difficult to control NDOF devices
+ * to perform some rotation with absolutely no translation. Causing rotation to
+ * randomly exit from the user perspective. Adjusting the dead-zone could avoid
+ * the motion feeling *glitchy* although in my own tests even then it didn't work reliably.
+ * Leave rotating out of camera-view disabled unless it can be made to work reliably. */
+ if (!(has_translate || has_zoom)) {
+ // return OPERATOR_PASS_THROUGH;
+ }
+
+ bool changed = false;
+
+ if (has_translate) {
+ const float speed = ndof->dt * NDOF_PIXELS_PER_SECOND;
+ float event_ofs[2] = {ndof->tvec[0] * speed, ndof->tvec[1] * speed};
+ if (ED_view3d_camera_view_pan(region, event_ofs)) {
+ changed = true;
+ }
+ }
+
+ if (has_zoom) {
+ const float scale = 1.0f + (ndof->dt * ndof->tvec[2]);
+ if (ED_view3d_camera_view_zoom_scale(rv3d, scale)) {
+ changed = true;
+ }
+ }
+
+ if (changed) {
+ ED_region_tag_redraw(region);
+ return OPERATOR_FINISHED;
+ }
+ return OPERATOR_CANCELLED;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name NDOF Orbit/Translate Operator
* \{ */
@@ -436,6 +500,13 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
return OPERATOR_CANCELLED;
}
+ if (U.ndof_flag & NDOF_CAMERA_PAN_ZOOM) {
+ const int camera_retval = view3d_ndof_cameraview_pan_zoom(C, event);
+ if (camera_retval != OPERATOR_PASS_THROUGH) {
+ return camera_retval;
+ }
+ }
+
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewOpsData *vod;
View3D *v3d;
@@ -550,6 +621,13 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *e
return OPERATOR_CANCELLED;
}
+ if (U.ndof_flag & NDOF_CAMERA_PAN_ZOOM) {
+ const int camera_retval = view3d_ndof_cameraview_pan_zoom(C, event);
+ if (camera_retval != OPERATOR_PASS_THROUGH) {
+ return camera_retval;
+ }
+ }
+
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.c
index 56bd9c93216..9c070fb0341 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_roll.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_roll.c
@@ -24,8 +24,17 @@
/** \name View Roll Operator
* \{ */
-static void view_roll_angle(
- ARegion *region, float quat[4], const float orig_quat[4], const float dvec[3], float angle)
+/**
+ * \param use_axis_view: When true, keep axis-aligned orthographic views
+ * (when rotating in 90 degree increments). While this may seem obscure some NDOF
+ * devices have key shortcuts to do this (see #NDOF_BUTTON_ROLL_CW & #NDOF_BUTTON_ROLL_CCW).
+ */
+static void view_roll_angle(ARegion *region,
+ float quat[4],
+ const float orig_quat[4],
+ const float dvec[3],
+ float angle,
+ bool use_axis_view)
{
RegionView3D *rv3d = region->regiondata;
float quat_mul[4];
@@ -38,7 +47,16 @@ static void view_roll_angle(
/* avoid precision loss over time */
normalize_qt(quat);
- rv3d->view = RV3D_VIEW_USER;
+ if (use_axis_view && RV3D_VIEW_IS_AXIS(rv3d->view) && (fabsf(angle) == (float)M_PI_2)) {
+ if (ED_view3d_quat_to_axis_view(quat, 0.01f, &rv3d->view, &rv3d->view_axis_roll)) {
+ if (rv3d->view != RV3D_VIEW_USER) {
+ ED_view3d_quat_from_axis_view(rv3d->view, rv3d->view_axis_roll, quat_mul);
+ }
+ }
+ }
+ else {
+ rv3d->view = RV3D_VIEW_USER;
+ }
}
static void viewroll_apply(ViewOpsData *vod, int x, int y)
@@ -46,7 +64,8 @@ static void viewroll_apply(ViewOpsData *vod, int x, int y)
float angle = BLI_dial_angle(vod->init.dial, (const float[2]){x, y});
if (angle != 0.0f) {
- view_roll_angle(vod->region, vod->rv3d->viewquat, vod->init.quat, vod->init.mousevec, angle);
+ view_roll_angle(
+ vod->region, vod->rv3d->viewquat, vod->init.quat, vod->init.mousevec, angle, false);
}
if (vod->use_dyn_ofs) {
@@ -169,7 +188,7 @@ static int viewroll_exec(bContext *C, wmOperator *op)
normalize_v3_v3(mousevec, rv3d->viewinv[2]);
negate_v3(mousevec);
- view_roll_angle(region, quat_new, rv3d->viewquat, mousevec, angle);
+ view_roll_angle(region, quat_new, rv3d->viewquat, mousevec, angle, true);
const float *dyn_ofs_pt = NULL;
float dyn_ofs[3];
diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.c b/source/blender/editors/space_view3d/view3d_navigate_rotate.c
index 774a8983c67..11de5463cdb 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_rotate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.c
@@ -383,7 +383,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int event_xy[2];
if (event->type == MOUSEPAN) {
- if (event->is_direction_inverted) {
+ if (event->flag & WM_EVENT_SCROLL_INVERT) {
event_xy[0] = 2 * event->xy[0] - event->prev_xy[0];
event_xy[1] = 2 * event->xy[1] - event->prev_xy[1];
}
diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.c b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
index 8eb8fffaa31..5f6f9fde324 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_zoom.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
@@ -125,18 +125,18 @@ static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoo
float dvec[3];
float tvec[3];
float tpos[3];
- float mval_f[2];
+ float xy_delta[2];
float zfac;
negate_v3_v3(tpos, rv3d->ofs);
- mval_f[0] = (float)(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f;
- mval_f[1] = (float)(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f;
+ xy_delta[0] = (float)(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f;
+ xy_delta[1] = (float)(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f;
/* Project cursor position into 3D space */
- zfac = ED_view3d_calc_zfac(rv3d, tpos, NULL);
- ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
+ zfac = ED_view3d_calc_zfac(rv3d, tpos);
+ ED_view3d_win_to_delta(region, xy_delta, zfac, dvec);
/* Calculate view target position for dolly */
add_v3_v3v3(tvec, tpos, dvec);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
index 4e909151ce4..f834efe4a7b 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
@@ -125,7 +125,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
negate_v3_v3(new_ofs, p);
}
else {
- float mval_f[2];
+ float xy_delta[2];
float zfac;
/* We can't use the depth, fallback to the old way that doesn't set the center depth */
@@ -134,12 +134,12 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
{
float tvec[3];
negate_v3_v3(tvec, new_ofs);
- zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL);
+ zfac = ED_view3d_calc_zfac(rv3d, tvec);
}
- mval_f[0] = (rect.xmin + rect.xmax - vb[0]) / 2.0f;
- mval_f[1] = (rect.ymin + rect.ymax - vb[1]) / 2.0f;
- ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
+ xy_delta[0] = (rect.xmin + rect.xmax - vb[0]) / 2.0f;
+ xy_delta[1] = (rect.ymin + rect.ymax - vb[1]) / 2.0f;
+ ED_view3d_win_to_delta(region, xy_delta, zfac, dvec);
/* center the view to the center of the rectangle */
sub_v3_v3(new_ofs, dvec);
}
diff --git a/source/blender/editors/space_view3d/view3d_placement.c b/source/blender/editors/space_view3d/view3d_placement.c
index 06b848571d8..98fb914cda9 100644
--- a/source/blender/editors/space_view3d/view3d_placement.c
+++ b/source/blender/editors/space_view3d/view3d_placement.c
@@ -727,6 +727,17 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
V3DSnapCursorState *snap_state_new = ED_view3d_cursor_snap_active();
if (snap_state_new) {
ipd->snap_state = snap_state = snap_state_new;
+
+ /* For drag events, update the location since it will be set from the drag-start.
+ * This is needed as cursor-drawing doesn't deal with drag events and will use
+ * the current cursor location instead of the drag-start. */
+ if (event->val == KM_CLICK_DRAG) {
+ /* Set this flag so snapping always updated. */
+ int flag_orig = snap_state_new->flag;
+ snap_state_new->flag |= V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE;
+ ED_view3d_cursor_snap_data_get(snap_state_new, C, event->mval[0], event->mval[1]);
+ snap_state_new->flag = flag_orig;
+ }
}
snap_state->draw_point = true;
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c
index 2cf9ac0a52e..85d239507ce 100644
--- a/source/blender/editors/space_view3d/view3d_project.c
+++ b/source/blender/editors/space_view3d/view3d_project.c
@@ -276,7 +276,7 @@ float ED_view3d_pixel_size_no_ui_scale(const RegionView3D *rv3d, const float co[
return mul_project_m4_v3_zfac(rv3d->persmat, co) * rv3d->pixsize;
}
-float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_flip)
+float ED_view3d_calc_zfac_ex(const RegionView3D *rv3d, const float co[3], bool *r_flip)
{
float zfac = mul_project_m4_v3_zfac(rv3d->persmat, co);
@@ -299,10 +299,15 @@ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_f
return zfac;
}
+float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3])
+{
+ return ED_view3d_calc_zfac_ex(rv3d, co, NULL);
+}
+
float ED_view3d_calc_depth_for_comparison(const RegionView3D *rv3d, const float co[3])
{
if (rv3d->is_persp) {
- return ED_view3d_calc_zfac(rv3d, co, NULL);
+ return ED_view3d_calc_zfac(rv3d, co);
}
return -dot_v3v3(rv3d->viewinv[2], co);
}
@@ -436,8 +441,8 @@ bool view3d_get_view_aligned_coordinate(ARegion *region,
if (ret == V3D_PROJ_RET_OK) {
const float mval_f[2] = {(float)(mval_cpy[0] - mval[0]), (float)(mval_cpy[1] - mval[1])};
- const float zfac = ED_view3d_calc_zfac(rv3d, fp, NULL);
- ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
+ const float zfac = ED_view3d_calc_zfac(rv3d, fp);
+ ED_view3d_win_to_delta(region, mval_f, zfac, dvec);
sub_v3_v3(fp, dvec);
return true;
@@ -584,57 +589,57 @@ bool ED_view3d_win_to_3d_on_plane_with_fallback(const ARegion *region,
}
void ED_view3d_win_to_delta(const ARegion *region,
- const float mval[2],
- float out[3],
- const float zfac)
+ const float xy_delta[2],
+ const float zfac,
+ float r_out[3])
{
RegionView3D *rv3d = region->regiondata;
float dx, dy;
- dx = 2.0f * mval[0] * zfac / region->winx;
- dy = 2.0f * mval[1] * zfac / region->winy;
+ dx = 2.0f * xy_delta[0] * zfac / region->winx;
+ dy = 2.0f * xy_delta[1] * zfac / region->winy;
- out[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy);
- out[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy);
- out[2] = (rv3d->persinv[0][2] * dx + rv3d->persinv[1][2] * dy);
+ r_out[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy);
+ r_out[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy);
+ r_out[2] = (rv3d->persinv[0][2] * dx + rv3d->persinv[1][2] * dy);
}
-void ED_view3d_win_to_origin(const ARegion *region, const float mval[2], float out[3])
+void ED_view3d_win_to_origin(const ARegion *region, const float mval[2], float r_out[3])
{
RegionView3D *rv3d = region->regiondata;
if (rv3d->is_persp) {
- copy_v3_v3(out, rv3d->viewinv[3]);
+ copy_v3_v3(r_out, rv3d->viewinv[3]);
}
else {
- out[0] = 2.0f * mval[0] / region->winx - 1.0f;
- out[1] = 2.0f * mval[1] / region->winy - 1.0f;
+ r_out[0] = 2.0f * mval[0] / region->winx - 1.0f;
+ r_out[1] = 2.0f * mval[1] / region->winy - 1.0f;
if (rv3d->persp == RV3D_CAMOB) {
- out[2] = -1.0f;
+ r_out[2] = -1.0f;
}
else {
- out[2] = 0.0f;
+ r_out[2] = 0.0f;
}
- mul_project_m4_v3(rv3d->persinv, out);
+ mul_project_m4_v3(rv3d->persinv, r_out);
}
}
-void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float out[3])
+void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float r_out[3])
{
RegionView3D *rv3d = region->regiondata;
if (rv3d->is_persp) {
- out[0] = 2.0f * (mval[0] / region->winx) - 1.0f;
- out[1] = 2.0f * (mval[1] / region->winy) - 1.0f;
- out[2] = -0.5f;
- mul_project_m4_v3(rv3d->persinv, out);
- sub_v3_v3(out, rv3d->viewinv[3]);
+ r_out[0] = 2.0f * (mval[0] / region->winx) - 1.0f;
+ r_out[1] = 2.0f * (mval[1] / region->winy) - 1.0f;
+ r_out[2] = -0.5f;
+ mul_project_m4_v3(rv3d->persinv, r_out);
+ sub_v3_v3(r_out, rv3d->viewinv[3]);
}
else {
- negate_v3_v3(out, rv3d->viewinv[2]);
+ negate_v3_v3(r_out, rv3d->viewinv[2]);
}
- normalize_v3(out);
+ normalize_v3(r_out);
}
bool ED_view3d_win_to_segment_clipped(struct Depsgraph *depsgraph,
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index f08c53fff47..e380a08dcc7 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1313,7 +1313,7 @@ static bool view3d_lasso_select(bContext *C,
case OB_MESH:
changed = do_lasso_select_mesh(vc, wm_userdata, mcoords, mcoords_len, sel_op);
break;
- case OB_CURVE:
+ case OB_CURVES_LEGACY:
case OB_SURF:
changed = do_lasso_select_curve(vc, mcoords, mcoords_len, sel_op);
break;
@@ -2695,7 +2695,7 @@ static int view3d_select_exec(bContext *C, wmOperator *op)
retval = ED_lattice_deselect_all_multi(C);
}
}
- else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
+ else if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) {
retval = ED_curve_editnurb_select_pick(C, location, extend, deselect, toggle);
if (!retval && deselect_all) {
retval = ED_curve_deselect_all_multi(C);
@@ -3586,7 +3586,7 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
}
break;
- case OB_CURVE:
+ case OB_CURVES_LEGACY:
case OB_SURF:
changed = do_nurbs_box_select(&vc, &rect, sel_op);
if (changed) {
@@ -4342,7 +4342,7 @@ static bool obedit_circle_select(bContext *C,
case OB_MESH:
changed = mesh_circle_select(vc, wm_userdata, sel_op, mval, rad);
break;
- case OB_CURVE:
+ case OB_CURVES_LEGACY:
case OB_SURF:
changed = nurbscurve_circle_select(vc, sel_op, mval, rad);
break;
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index 8a219cd96d1..3e788f2d643 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -510,6 +510,39 @@ bool ED_view3d_persp_ensure(const Depsgraph *depsgraph, View3D *v3d, ARegion *re
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Camera View Utilities
+ *
+ * Utilities for manipulating the camera-view.
+ * \{ */
+
+bool ED_view3d_camera_view_zoom_scale(RegionView3D *rv3d, const float scale)
+{
+ const float camzoom_init = rv3d->camzoom;
+ float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
+ /* Clamp both before and after conversion to prevent NAN on negative values. */
+
+ zoomfac = zoomfac * scale;
+ CLAMP(zoomfac, RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR);
+ rv3d->camzoom = BKE_screen_view3d_zoom_from_fac(zoomfac);
+ CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
+ return (rv3d->camzoom != camzoom_init);
+}
+
+bool ED_view3d_camera_view_pan(ARegion *region, const float event_ofs[2])
+{
+ RegionView3D *rv3d = region->regiondata;
+ const float camdxy_init[2] = {rv3d->camdx, rv3d->camdy};
+ const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 2.0f;
+ rv3d->camdx += event_ofs[0] / (region->winx * zoomfac);
+ rv3d->camdy += event_ofs[1] / (region->winy * zoomfac);
+ CLAMP(rv3d->camdx, -1.0f, 1.0f);
+ CLAMP(rv3d->camdy, -1.0f, 1.0f);
+ return (camdxy_init[0] != rv3d->camdx) || (camdxy_init[1] != rv3d->camdy);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Camera Lock API
*
* Lock the camera to the 3D Viewport, allowing view manipulation to transform the camera.