3D View: Add camera view pan/zoom support for NDOF
NDOF navigation in a camera view now behaves like orthographic pan/zoom. Note that NDOF orbiting out of the camera view has been disabled, see code comment for details. Resolves T93666.
This commit is contained in:
parent
f33e6e0d8c
commit
51975b89ed
Notes:
blender-bot
2023-02-14 07:17:43 +01:00
Referenced by commit 391c3848b1
, NDOF: make camera view/pan behavior optional
Referenced by issue #93666, NDOF pan doesn't work in Camera view
|
@ -346,6 +346,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,11 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
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 +619,11 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *e
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue