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/view3d_edit.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c700
1 files changed, 380 insertions, 320 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 83fb87264e3..67dacca85ba 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -23,17 +23,17 @@
* 3D view manipulation/operators.
*/
-#include <string.h>
-#include <stdio.h>
-#include <math.h>
#include <float.h>
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
#include "DNA_armature_types.h"
#include "DNA_camera_types.h"
#include "DNA_curve_types.h"
+#include "DNA_gpencil_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "DNA_gpencil_types.h"
#include "MEM_guardedalloc.h"
@@ -46,9 +46,9 @@
#include "BKE_camera.h"
#include "BKE_context.h"
#include "BKE_font.h"
-#include "BKE_gpencil.h"
+#include "BKE_gpencil_geom.h"
#include "BKE_layer.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_paint.h"
@@ -60,19 +60,19 @@
#include "DEG_depsgraph_query.h"
#include "WM_api.h"
-#include "WM_types.h"
#include "WM_message.h"
+#include "WM_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "ED_armature.h"
+#include "ED_mesh.h"
#include "ED_particle.h"
#include "ED_screen.h"
#include "ED_transform.h"
-#include "ED_mesh.h"
-#include "ED_view3d.h"
#include "ED_transform_snap_object_context.h"
+#include "ED_view3d.h"
#include "UI_resources.h"
@@ -85,6 +85,52 @@ enum {
HAS_ROTATE = (1 << 0),
};
+/* test for unlocked camera view in quad view */
+static bool view3d_camera_user_poll(bContext *C)
+{
+ View3D *v3d;
+ ARegion *region;
+
+ if (ED_view3d_context_user_region(C, &v3d, &region)) {
+ RegionView3D *rv3d = region->regiondata;
+ if ((rv3d->persp == RV3D_CAMOB) && !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static bool view3d_lock_poll(bContext *C)
+{
+ View3D *v3d = CTX_wm_view3d(C);
+ if (v3d) {
+ RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ if (rv3d) {
+ return ED_view3d_offset_lock_check(v3d, rv3d);
+ }
+ }
+ return false;
+}
+
+static bool view3d_pan_poll(bContext *C)
+{
+ if (ED_operator_region_view3d_active(C)) {
+ const RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ return !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_LOCATION);
+ }
+ return false;
+}
+
+static bool view3d_zoom_or_dolly_poll(bContext *C)
+{
+ if (ED_operator_region_view3d_active(C)) {
+ const RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ return !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ZOOM_AND_DOLLY);
+ }
+ return false;
+}
+
/* -------------------------------------------------------------------- */
/** \name Generic View Operator Properties
* \{ */
@@ -130,7 +176,7 @@ typedef struct ViewOpsData {
Main *bmain;
Scene *scene;
ScrArea *sa;
- ARegion *ar;
+ ARegion *region;
View3D *v3d;
RegionView3D *rv3d;
Depsgraph *depsgraph;
@@ -190,7 +236,7 @@ typedef struct ViewOpsData {
} ViewOpsData;
/**
- * Size of the sphere being dragged for trackball rotation withing the view bounds.
+ * Size of the sphere being dragged for trackball rotation within the view bounds.
* also affects speed (smaller is faster).
*/
#define TRACKBALLSIZE (1.1f)
@@ -211,11 +257,11 @@ static void calctrackballvec(const rcti *rect, const int event_xy[2], float r_di
const float d = len_v2(r_dir);
if (d < t) {
/* Inside sphere. */
- r_dir[2] = sqrtf(SQUARE(radius) - SQUARE(d));
+ r_dir[2] = sqrtf(square_f(radius) - square_f(d));
}
else {
/* On hyperbola. */
- r_dir[2] = SQUARE(t) / d;
+ r_dir[2] = square_f(t) / d;
}
}
@@ -232,9 +278,9 @@ static void viewops_data_alloc(bContext *C, wmOperator *op)
vod->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
vod->scene = CTX_data_scene(C);
vod->sa = CTX_wm_area(C);
- vod->ar = CTX_wm_region(C);
+ vod->region = CTX_wm_region(C);
vod->v3d = vod->sa->spacedata.first;
- vod->rv3d = vod->ar->regiondata;
+ vod->rv3d = vod->region->regiondata;
}
void view3d_orbit_apply_dyn_ofs(float r_ofs[3],
@@ -401,17 +447,17 @@ static void viewops_data_create(bContext *C,
negate_v3_v3(fallback_depth_pt, rv3d->ofs);
vod->use_dyn_ofs = ED_view3d_autodist(
- depsgraph, vod->ar, vod->v3d, event->mval, vod->dyn_ofs, true, fallback_depth_pt);
+ depsgraph, vod->region, vod->v3d, event->mval, vod->dyn_ofs, true, fallback_depth_pt);
}
else {
vod->use_dyn_ofs = false;
}
if (viewops_flag & VIEWOPS_FLAG_PERSP_ENSURE) {
- if (ED_view3d_persp_ensure(depsgraph, vod->v3d, vod->ar)) {
+ if (ED_view3d_persp_ensure(depsgraph, vod->v3d, vod->region)) {
/* If we're switching from camera view to the perspective one,
* need to tag viewport update, so camera view and borders are properly updated. */
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
}
}
@@ -432,8 +478,8 @@ static void viewops_data_create(bContext *C,
}
else {
/* Simulate the event starting in the middle of the region. */
- vod->init.event_xy_offset[0] = BLI_rcti_cent_x(&vod->ar->winrct) - event->x;
- vod->init.event_xy_offset[1] = BLI_rcti_cent_y(&vod->ar->winrct) - event->y;
+ vod->init.event_xy_offset[0] = BLI_rcti_cent_x(&vod->region->winrct) - event->x;
+ vod->init.event_xy_offset[1] = BLI_rcti_cent_y(&vod->region->winrct) - event->y;
}
vod->init.event_type = event->type;
@@ -483,9 +529,10 @@ static void viewops_data_create(bContext *C,
negate_v3_v3(rv3d->ofs, dvec);
}
else {
- const float mval_ar_mid[2] = {(float)vod->ar->winx / 2.0f, (float)vod->ar->winy / 2.0f};
+ const float mval_ar_mid[2] = {(float)vod->region->winx / 2.0f,
+ (float)vod->region->winy / 2.0f};
- ED_view3d_win_to_3d(vod->v3d, vod->ar, vod->dyn_ofs, mval_ar_mid, rv3d->ofs);
+ ED_view3d_win_to_3d(vod->v3d, vod->region, vod->dyn_ofs, mval_ar_mid, rv3d->ofs);
negate_v3(rv3d->ofs);
}
negate_v3(vod->dyn_ofs);
@@ -494,7 +541,7 @@ static void viewops_data_create(bContext *C,
}
/* For dolly */
- ED_view3d_win_to_vector(vod->ar, (const float[2]){UNPACK2(event->mval)}, vod->init.mousevec);
+ ED_view3d_win_to_vector(vod->region, (const float[2]){UNPACK2(event->mval)}, vod->init.mousevec);
{
const int event_xy_offset[2] = {
@@ -502,7 +549,7 @@ static void viewops_data_create(bContext *C,
event->y + vod->init.event_xy_offset[1],
};
/* For rotation with trackball rotation. */
- calctrackballvec(&vod->ar->winrct, event_xy_offset, vod->init.trackvec);
+ calctrackballvec(&vod->region->winrct, event_xy_offset, vod->init.trackvec);
}
{
@@ -521,10 +568,10 @@ static void viewops_data_create(bContext *C,
static void viewops_data_free(bContext *C, wmOperator *op)
{
- ARegion *ar;
+ ARegion *region;
if (op->customdata) {
ViewOpsData *vod = op->customdata;
- ar = vod->ar;
+ region = vod->region;
vod->rv3d->rflag &= ~RV3D_NAVIGATING;
if (vod->timer) {
@@ -535,12 +582,12 @@ static void viewops_data_free(bContext *C, wmOperator *op)
op->customdata = NULL;
}
else {
- ar = CTX_wm_region(C);
+ region = CTX_wm_region(C);
}
/* Need to redraw because drawing code uses RV3D_NAVIGATING to draw
* faster while navigation operator runs. */
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(region);
}
/** \} */
@@ -700,9 +747,9 @@ static void viewrotate_apply_snap(ViewOpsData *vod)
if (found) {
/* lock 'quat_best' to an axis view if we can */
- rv3d->view = ED_view3d_quat_to_axis_view(quat_best, 0.01f);
+ ED_view3d_quat_to_axis_view(quat_best, 0.01f, &rv3d->view, &rv3d->view_axis_roll);
if (rv3d->view != RV3D_VIEW_USER) {
- ED_view3d_quat_from_axis_view(rv3d->view, quat_best);
+ ED_view3d_quat_from_axis_view(rv3d->view, rv3d->view_axis_roll, quat_best);
}
}
else {
@@ -741,7 +788,7 @@ static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2])
event_xy[0] + vod->init.event_xy_offset[0],
event_xy[1] + vod->init.event_xy_offset[1],
};
- calctrackballvec(&vod->ar->winrct, event_xy_offset, newvec);
+ calctrackballvec(&vod->region->winrct, event_xy_offset, newvec);
}
sub_v3_v3v3(dvec, newvec, vod->init.trackvec);
@@ -858,7 +905,7 @@ static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2])
ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, rv3d);
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
}
static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event)
@@ -934,12 +981,12 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
vod = op->customdata;
/* poll should check but in some cases fails, see poll func for details */
- if (vod->rv3d->viewlock & RV3D_LOCKED) {
+ if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_ROTATION) {
viewops_data_free(C, op);
return OPERATOR_PASS_THROUGH;
}
- ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar);
+ ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
viewops_data_create(C,
op,
@@ -982,34 +1029,6 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
}
-/* test for unlocked camera view in quad view */
-static bool view3d_camera_user_poll(bContext *C)
-{
- View3D *v3d;
- ARegion *ar;
-
- if (ED_view3d_context_user_region(C, &v3d, &ar)) {
- RegionView3D *rv3d = ar->regiondata;
- if (rv3d->persp == RV3D_CAMOB) {
- return 1;
- }
- }
-
- return 0;
-}
-
-static bool view3d_lock_poll(bContext *C)
-{
- View3D *v3d = CTX_wm_view3d(C);
- if (v3d) {
- RegionView3D *rv3d = CTX_wm_region_view3d(C);
- if (rv3d) {
- return ED_view3d_offset_lock_check(v3d, rv3d);
- }
- }
- return false;
-}
-
static void viewrotate_cancel(bContext *C, wmOperator *op)
{
viewops_data_free(C, op);
@@ -1050,7 +1069,7 @@ static bool ndof_has_translate(const wmNDOFMotionData *ndof,
static bool ndof_has_rotate(const wmNDOFMotionData *ndof, const RegionView3D *rv3d)
{
- return !is_zero_v3(ndof->rvec) && ((rv3d->viewlock & RV3D_LOCKED) == 0);
+ return !is_zero_v3(ndof->rvec) && ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0);
}
/**
@@ -1102,11 +1121,11 @@ static float view3d_ndof_pan_speed_calc(RegionView3D *rv3d)
*/
static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof,
ScrArea *sa,
- ARegion *ar,
+ ARegion *region,
const bool has_translate,
const bool has_zoom)
{
- RegionView3D *rv3d = ar->regiondata;
+ RegionView3D *rv3d = region->regiondata;
float view_inv[4];
float pan_vec[3];
@@ -1158,26 +1177,26 @@ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof,
/* move center of view opposite of hand motion (this is camera mode, not object mode) */
sub_v3_v3(rv3d->ofs, pan_vec);
- if (rv3d->viewlock & RV3D_BOXVIEW) {
- view3d_boxview_sync(sa, ar);
+ if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_sync(sa, region);
}
}
}
static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof,
ScrArea *sa,
- ARegion *ar,
+ ARegion *region,
ViewOpsData *vod,
const bool apply_dyn_ofs)
{
View3D *v3d = sa->spacedata.first;
- RegionView3D *rv3d = ar->regiondata;
+ RegionView3D *rv3d = region->regiondata;
float view_inv[4];
- BLI_assert((rv3d->viewlock & RV3D_LOCKED) == 0);
+ BLI_assert((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0);
- ED_view3d_persp_ensure(vod->depsgraph, v3d, ar);
+ ED_view3d_persp_ensure(vod->depsgraph, v3d, region);
rv3d->view = RV3D_VIEW_USER;
@@ -1385,7 +1404,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
C, op, event, viewops_flag_from_args((U.uiflag & USER_ORBIT_SELECTION) != 0, false));
vod = op->customdata;
- ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar);
+ ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
v3d = vod->v3d;
rv3d = vod->rv3d;
@@ -1399,16 +1418,16 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
const bool has_rotation = ndof_has_rotate(ndof, rv3d);
/* if we can't rotate, fallback to translate (locked axis views) */
const bool has_translate = ndof_has_translate(ndof, v3d, rv3d) &&
- (rv3d->viewlock & RV3D_LOCKED);
+ (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION);
const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp;
if (has_translate || has_zoom) {
- view3d_ndof_pan_zoom(ndof, vod->sa, vod->ar, has_translate, has_zoom);
+ view3d_ndof_pan_zoom(ndof, vod->sa, vod->region, has_translate, has_zoom);
xform_flag |= HAS_TRANSLATE;
}
if (has_rotation) {
- view3d_ndof_orbit(ndof, vod->sa, vod->ar, vod, true);
+ view3d_ndof_orbit(ndof, vod->sa, vod->region, vod, true);
xform_flag |= HAS_ROTATE;
}
}
@@ -1419,7 +1438,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
}
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
viewops_data_free(C, op);
@@ -1467,7 +1486,7 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
vod = op->customdata;
- ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar);
+ ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
v3d = vod->v3d;
rv3d = vod->rv3d;
@@ -1486,7 +1505,7 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
const bool has_zoom = (ndof->tvec[2] != 0.0f) && ED_view3d_offset_lock_check(v3d, rv3d);
if (has_translate || has_zoom) {
- view3d_ndof_pan_zoom(ndof, vod->sa, vod->ar, has_translate, true);
+ view3d_ndof_pan_zoom(ndof, vod->sa, vod->region, has_translate, true);
xform_flag |= HAS_TRANSLATE;
}
}
@@ -1516,7 +1535,7 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
if (!is_orbit_around_pivot) {
ED_view3d_distance_set(rv3d, 0.0f);
}
- view3d_ndof_orbit(ndof, vod->sa, vod->ar, vod, is_orbit_around_pivot);
+ view3d_ndof_orbit(ndof, vod->sa, vod->region, vod, is_orbit_around_pivot);
xform_flag |= HAS_ROTATE;
if (!is_orbit_around_pivot) {
ED_view3d_distance_set(rv3d, dist_backup);
@@ -1524,7 +1543,7 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
}
if (has_translate || has_zoom) {
- view3d_ndof_pan_zoom(ndof, vod->sa, vod->ar, has_translate, has_zoom);
+ view3d_ndof_pan_zoom(ndof, vod->sa, vod->region, has_translate, has_zoom);
xform_flag |= HAS_TRANSLATE;
}
}
@@ -1535,7 +1554,7 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
}
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
viewops_data_free(C, op);
@@ -1589,10 +1608,10 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *e
if (ndof->progress != P_FINISHING) {
ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
if (has_translate || has_zoom) {
- view3d_ndof_pan_zoom(ndof, sa, ar, has_translate, has_zoom);
+ view3d_ndof_pan_zoom(ndof, sa, region, has_translate, has_zoom);
xform_flag |= HAS_TRANSLATE;
}
}
@@ -1694,7 +1713,7 @@ void viewmove_modal_keymap(wmKeyConfig *keyconf)
/* items for modal map */
WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
- WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
+ WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
/* disabled mode switching for now, can re-implement better, later on */
#if 0
@@ -1711,13 +1730,13 @@ void viewmove_modal_keymap(wmKeyConfig *keyconf)
static 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->ar->winx;
- vod->rv3d->ofs_lock[1] -= ((vod->prev.event_xy[1] - y) * 2.0f) / (float)vod->ar->winy;
+ 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;
}
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->ar->winx * zoomfac);
- vod->rv3d->camdy += (vod->prev.event_xy[1] - y) / (vod->ar->winy * zoomfac);
+ 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);
}
@@ -1727,12 +1746,12 @@ static void viewmove_apply(ViewOpsData *vod, int x, int y)
mval_f[0] = x - vod->prev.event_xy[0];
mval_f[1] = y - vod->prev.event_xy[1];
- ED_view3d_win_to_delta(vod->ar, mval_f, dvec, vod->init.zfac);
+ ED_view3d_win_to_delta(vod->region, mval_f, dvec, vod->init.zfac);
add_v3_v3(vod->rv3d->ofs, dvec);
- if (vod->rv3d->viewlock & RV3D_BOXVIEW) {
- view3d_boxview_sync(vod->sa, vod->ar);
+ if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_sync(vod->sa, vod->region);
}
}
@@ -1741,7 +1760,7 @@ static void viewmove_apply(ViewOpsData *vod, int x, int y)
ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
}
static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
@@ -1806,14 +1825,19 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* makes op->customdata */
viewops_data_alloc(C, op);
+ vod = op->customdata;
+ if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_LOCATION) {
+ viewops_data_free(C, op);
+ return OPERATOR_PASS_THROUGH;
+ }
+
viewops_data_create(C,
op,
event,
(viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) |
(use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
- vod = op->customdata;
- ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar);
+ ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
if (event->type == MOUSEPAN) {
/* invert it, trackpad scroll follows same principle as 2d windows this way */
@@ -1901,10 +1925,14 @@ void viewzoom_modal_keymap(wmKeyConfig *keyconf)
* \param zoom_xy: Optionally zoom to window location
* (coords compatible w/ #wmEvent.x, y). Use when not NULL.
*/
-static void view_zoom_to_window_xy_camera(
- Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *ar, float dfac, const int zoom_xy[2])
-{
- RegionView3D *rv3d = ar->regiondata;
+static void view_zoom_to_window_xy_camera(Scene *scene,
+ Depsgraph *depsgraph,
+ View3D *v3d,
+ ARegion *region,
+ float dfac,
+ const int zoom_xy[2])
+{
+ RegionView3D *rv3d = region->regiondata;
const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
const float zoomfac_new = clamp_f(
zoomfac * (1.0f / dfac), RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR);
@@ -1919,14 +1947,14 @@ static void view_zoom_to_window_xy_camera(
float pt_dst[2];
float delta_px[2];
- ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &camera_frame_old, false);
- BLI_rctf_translate(&camera_frame_old, ar->winrct.xmin, ar->winrct.ymin);
+ ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &camera_frame_old, false);
+ BLI_rctf_translate(&camera_frame_old, region->winrct.xmin, region->winrct.ymin);
rv3d->camzoom = camzoom_new;
CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
- ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &camera_frame_new, false);
- BLI_rctf_translate(&camera_frame_new, ar->winrct.xmin, ar->winrct.ymin);
+ ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &camera_frame_new, false);
+ BLI_rctf_translate(&camera_frame_new, region->winrct.xmin, region->winrct.ymin);
BLI_rctf_transform_pt_v(&camera_frame_new, &camera_frame_old, pt_dst, pt_src);
sub_v2_v2v2(delta_px, pt_dst, pt_src);
@@ -1935,8 +1963,8 @@ static void view_zoom_to_window_xy_camera(
* mapped back to the camera (same logic as panning in camera view) */
zoomfac_px = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 2.0f;
- rv3d->camdx += delta_px[0] / (ar->winx * zoomfac_px);
- rv3d->camdy += delta_px[1] / (ar->winy * zoomfac_px);
+ rv3d->camdx += delta_px[0] / (region->winx * zoomfac_px);
+ rv3d->camdy += delta_px[1] / (region->winy * zoomfac_px);
CLAMP(rv3d->camdx, -1.0f, 1.0f);
CLAMP(rv3d->camdy, -1.0f, 1.0f);
}
@@ -1950,9 +1978,9 @@ static void view_zoom_to_window_xy_camera(
* \param zoom_xy: Optionally zoom to window location
* (coords compatible w/ #wmEvent.x, y). Use when not NULL.
*/
-static void view_zoom_to_window_xy_3d(ARegion *ar, float dfac, const int zoom_xy[2])
+static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoom_xy[2])
{
- RegionView3D *rv3d = ar->regiondata;
+ RegionView3D *rv3d = region->regiondata;
const float dist_new = rv3d->dist * dfac;
if (zoom_xy != NULL) {
@@ -1965,12 +1993,12 @@ static void view_zoom_to_window_xy_3d(ARegion *ar, float dfac, const int zoom_xy
negate_v3_v3(tpos, rv3d->ofs);
- mval_f[0] = (float)(((zoom_xy[0] - ar->winrct.xmin) * 2) - ar->winx) / 2.0f;
- mval_f[1] = (float)(((zoom_xy[1] - ar->winrct.ymin) * 2) - ar->winy) / 2.0f;
+ 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;
/* Project cursor position into 3D space */
zfac = ED_view3d_calc_zfac(rv3d, tpos, NULL);
- ED_view3d_win_to_delta(ar, mval_f, dvec, zfac);
+ ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
/* Calculate view target position for dolly */
add_v3_v3v3(tvec, tpos, dvec);
@@ -2102,7 +2130,7 @@ static void viewzoom_apply_camera(ViewOpsData *vod,
float zoomfac_prev = BKE_screen_view3d_zoom_to_fac(vod->init.camzoom) * 2.0f;
float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f;
- zfac = viewzoom_scale_value_offset(&vod->ar->winrct,
+ zfac = viewzoom_scale_value_offset(&vod->region->winrct,
viewzoom,
zoom_invert,
true,
@@ -2119,12 +2147,12 @@ static void viewzoom_apply_camera(ViewOpsData *vod,
view_zoom_to_window_xy_camera(vod->scene,
vod->depsgraph,
vod->v3d,
- vod->ar,
+ vod->region,
zfac,
zoom_to_pos ? vod->prev.event_xy : NULL);
}
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
}
static void viewzoom_apply_3d(ViewOpsData *vod,
@@ -2138,7 +2166,7 @@ static void viewzoom_apply_3d(ViewOpsData *vod,
ED_view3d_dist_range_get(vod->v3d, dist_range);
- zfac = viewzoom_scale_value_offset(&vod->ar->winrct,
+ zfac = viewzoom_scale_value_offset(&vod->region->winrct,
viewzoom,
zoom_invert,
false,
@@ -2154,19 +2182,19 @@ static void viewzoom_apply_3d(ViewOpsData *vod,
const float zfac_max = dist_range[1] / vod->rv3d->dist;
CLAMP(zfac, zfac_min, zfac_max);
- view_zoom_to_window_xy_3d(vod->ar, zfac, zoom_to_pos ? vod->prev.event_xy : NULL);
+ view_zoom_to_window_xy_3d(vod->region, zfac, zoom_to_pos ? vod->prev.event_xy : NULL);
}
/* these limits were in old code too */
CLAMP(vod->rv3d->dist, dist_range[0], dist_range[1]);
- if (vod->rv3d->viewlock & RV3D_BOXVIEW) {
- view3d_boxview_sync(vod->sa, vod->ar);
+ if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_sync(vod->sa, vod->region);
}
ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
}
static void viewzoom_apply(ViewOpsData *vod,
@@ -2253,7 +2281,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
View3D *v3d;
RegionView3D *rv3d;
ScrArea *sa;
- ARegion *ar;
+ ARegion *region;
bool use_cam_zoom;
float dist_range[2];
@@ -2264,15 +2292,15 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
ViewOpsData *vod = op->customdata;
sa = vod->sa;
- ar = vod->ar;
+ region = vod->region;
}
else {
sa = CTX_wm_area(C);
- ar = CTX_wm_region(C);
+ region = CTX_wm_region(C);
}
v3d = sa->spacedata.first;
- rv3d = ar->regiondata;
+ rv3d = region->regiondata;
use_cam_zoom = (rv3d->persp == RV3D_CAMOB) &&
!(rv3d->is_persp && ED_view3d_camera_lock_check(v3d, rv3d));
@@ -2281,9 +2309,9 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
const int *zoom_xy = NULL;
if (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) {
zoom_xy_buf[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") :
- ar->winx / 2;
+ region->winx / 2;
zoom_xy_buf[1] = RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") :
- ar->winy / 2;
+ region->winy / 2;
zoom_xy = zoom_xy_buf;
}
@@ -2293,28 +2321,28 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
const float step = 1.2f;
/* this min and max is also in viewmove() */
if (use_cam_zoom) {
- view_zoom_to_window_xy_camera(scene, depsgraph, v3d, ar, step, zoom_xy);
+ view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy);
}
else {
if (rv3d->dist < dist_range[1]) {
- view_zoom_to_window_xy_3d(ar, step, zoom_xy);
+ view_zoom_to_window_xy_3d(region, step, zoom_xy);
}
}
}
else {
const float step = 1.0f / 1.2f;
if (use_cam_zoom) {
- view_zoom_to_window_xy_camera(scene, depsgraph, v3d, ar, step, zoom_xy);
+ view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy);
}
else {
if (rv3d->dist > dist_range[0]) {
- view_zoom_to_window_xy_3d(ar, step, zoom_xy);
+ view_zoom_to_window_xy_3d(region, step, zoom_xy);
}
}
}
- if (rv3d->viewlock & RV3D_BOXVIEW) {
- view3d_boxview_sync(sa, ar);
+ if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_sync(sa, region);
}
ED_view3d_depth_tag_update(rv3d);
@@ -2322,7 +2350,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, true);
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(region);
viewops_data_free(C, op);
@@ -2345,7 +2373,7 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
(use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
vod = op->customdata;
- ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar);
+ ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
/* if one or the other zoom position aren't set, set from event */
if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) {
@@ -2411,7 +2439,7 @@ void VIEW3D_OT_zoom(wmOperatorType *ot)
ot->invoke = viewzoom_invoke;
ot->exec = viewzoom_exec;
ot->modal = viewzoom_modal;
- ot->poll = ED_operator_region_view3d_active;
+ ot->poll = view3d_zoom_or_dolly_poll;
ot->cancel = viewzoom_cancel;
/* flags */
@@ -2477,9 +2505,9 @@ static bool viewdolly_offset_lock_check(bContext *C, wmOperator *op)
}
}
-static void view_dolly_to_vector_3d(ARegion *ar, float orig_ofs[3], float dvec[3], float dfac)
+static void view_dolly_to_vector_3d(ARegion *region, float orig_ofs[3], float dvec[3], float dfac)
{
- RegionView3D *rv3d = ar->regiondata;
+ RegionView3D *rv3d = region->regiondata;
madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, -(1.0f - dfac));
}
@@ -2491,12 +2519,12 @@ static void viewdolly_apply(ViewOpsData *vod, const int xy[2], const short zoom_
float len1, len2;
if (U.uiflag & USER_ZOOM_HORIZ) {
- len1 = (vod->ar->winrct.xmax - xy[0]) + 5;
- len2 = (vod->ar->winrct.xmax - vod->init.event_xy[0]) + 5;
+ len1 = (vod->region->winrct.xmax - xy[0]) + 5;
+ len2 = (vod->region->winrct.xmax - vod->init.event_xy[0]) + 5;
}
else {
- len1 = (vod->ar->winrct.ymax - xy[1]) + 5;
- len2 = (vod->ar->winrct.ymax - vod->init.event_xy[1]) + 5;
+ len1 = (vod->region->winrct.ymax - xy[1]) + 5;
+ len2 = (vod->region->winrct.ymax - vod->init.event_xy[1]) + 5;
}
if (zoom_invert) {
SWAP(float, len1, len2);
@@ -2506,16 +2534,16 @@ static void viewdolly_apply(ViewOpsData *vod, const int xy[2], const short zoom_
}
if (zfac != 1.0f) {
- view_dolly_to_vector_3d(vod->ar, vod->init.ofs, vod->init.mousevec, zfac);
+ view_dolly_to_vector_3d(vod->region, vod->init.ofs, vod->init.mousevec, zfac);
}
- if (vod->rv3d->viewlock & RV3D_BOXVIEW) {
- view3d_boxview_sync(vod->sa, vod->ar);
+ if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_sync(vod->sa, vod->region);
}
ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
}
static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
@@ -2576,7 +2604,7 @@ static int viewdolly_exec(bContext *C, wmOperator *op)
View3D *v3d;
RegionView3D *rv3d;
ScrArea *sa;
- ARegion *ar;
+ ARegion *region;
float mousevec[3];
const int delta = RNA_int_get(op->ptr, "delta");
@@ -2585,18 +2613,18 @@ static int viewdolly_exec(bContext *C, wmOperator *op)
ViewOpsData *vod = op->customdata;
sa = vod->sa;
- ar = vod->ar;
+ region = vod->region;
copy_v3_v3(mousevec, vod->init.mousevec);
}
else {
sa = CTX_wm_area(C);
- ar = CTX_wm_region(C);
- negate_v3_v3(mousevec, ((RegionView3D *)ar->regiondata)->viewinv[2]);
+ region = CTX_wm_region(C);
+ negate_v3_v3(mousevec, ((RegionView3D *)region->regiondata)->viewinv[2]);
normalize_v3(mousevec);
}
v3d = sa->spacedata.first;
- rv3d = ar->regiondata;
+ rv3d = region->regiondata;
const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
@@ -2605,17 +2633,17 @@ static int viewdolly_exec(bContext *C, wmOperator *op)
normalize_v3_v3(mousevec, rv3d->viewinv[2]);
}
- view_dolly_to_vector_3d(ar, rv3d->ofs, mousevec, delta < 0 ? 0.2f : 1.8f);
+ view_dolly_to_vector_3d(region, rv3d->ofs, mousevec, delta < 0 ? 0.2f : 1.8f);
- if (rv3d->viewlock & RV3D_BOXVIEW) {
- view3d_boxview_sync(sa, ar);
+ if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_sync(sa, region);
}
ED_view3d_depth_tag_update(rv3d);
ED_view3d_camera_lock_sync(CTX_data_ensure_evaluated_depsgraph(C), v3d, rv3d);
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(region);
viewops_data_free(C, op);
@@ -2636,12 +2664,12 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
vod = op->customdata;
/* poll should check but in some cases fails, see poll func for details */
- if (vod->rv3d->viewlock & RV3D_LOCKED) {
+ if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_ROTATION) {
viewops_data_free(C, op);
return OPERATOR_PASS_THROUGH;
}
- ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar);
+ ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
/* needs to run before 'viewops_data_create' so the backup 'rv3d->ofs' is correct */
/* switch from camera view when: */
@@ -2654,7 +2682,7 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
else {
vod->rv3d->persp = RV3D_PERSP;
}
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
}
const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
@@ -2767,17 +2795,17 @@ static bool view3d_object_skip_minmax(const View3D *v3d,
static void view3d_from_minmax(bContext *C,
View3D *v3d,
- ARegion *ar,
+ ARegion *region,
const float min[3],
const float max[3],
bool ok_dist,
const int smooth_viewtx)
{
- RegionView3D *rv3d = ar->regiondata;
+ RegionView3D *rv3d = region->regiondata;
float afm[3];
float size;
- ED_view3d_smooth_view_force_finish(C, v3d, ar);
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
/* SMOOTHVIEW */
float new_ofs[3];
@@ -2811,7 +2839,7 @@ static void view3d_from_minmax(bContext *C,
if (ok_dist) {
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
new_dist = ED_view3d_radius_to_dist(
- v3d, ar, depsgraph, persp, true, (size / 2) * VIEW3D_MARGIN);
+ v3d, region, depsgraph, persp, true, (size / 2) * VIEW3D_MARGIN);
if (rv3d->is_persp) {
/* don't zoom closer than the near clipping plane */
new_dist = max_ff(new_dist, v3d->clip_start * 1.5f);
@@ -2826,7 +2854,7 @@ static void view3d_from_minmax(bContext *C,
rv3d->persp = RV3D_PERSP;
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.camera_old = v3d->camera,
@@ -2837,7 +2865,7 @@ static void view3d_from_minmax(bContext *C,
else {
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.ofs = new_ofs,
@@ -2859,14 +2887,14 @@ static void view3d_from_minmax_multi(bContext *C,
const int smooth_viewtx)
{
ScrArea *sa = CTX_wm_area(C);
- ARegion *ar;
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- RegionView3D *rv3d = ar->regiondata;
+ ARegion *region;
+ for (region = sa->regionbase.first; region; region = region->next) {
+ if (region->regiontype == RGN_TYPE_WINDOW) {
+ RegionView3D *rv3d = region->regiondata;
/* when using all regions, don't jump out of camera view,
* but _do_ allow locked cameras to be moved */
if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
- view3d_from_minmax(C, v3d, ar, min, max, ok_dist, smooth_viewtx);
+ view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx);
}
}
}
@@ -2874,7 +2902,7 @@ static void view3d_from_minmax_multi(bContext *C,
static int view3d_all_exec(bContext *C, wmOperator *op)
{
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
Scene *scene = CTX_data_scene(C);
@@ -2882,7 +2910,7 @@ static int view3d_all_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
Base *base_eval;
const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
- const bool skip_camera = (ED_view3d_camera_lock_check(v3d, ar->regiondata) ||
+ const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) ||
/* any one of the regions may be locked */
(use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA));
const bool center = RNA_boolean_get(op->ptr, "center");
@@ -2928,7 +2956,7 @@ static int view3d_all_exec(bContext *C, wmOperator *op)
}
if (!changed) {
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(region);
/* TODO - should this be cancel?
* I think no, because we always move the cursor, with or without
* object, but in this case there is no change in the scene,
@@ -2943,7 +2971,7 @@ static int view3d_all_exec(bContext *C, wmOperator *op)
view3d_from_minmax_multi(C, v3d, min, max, true, smooth_viewtx);
}
else {
- view3d_from_minmax(C, v3d, ar, min, max, true, smooth_viewtx);
+ view3d_from_minmax(C, v3d, region, min, max, true, smooth_viewtx);
}
return OPERATOR_FINISHED;
@@ -2971,7 +2999,7 @@ void VIEW3D_OT_view_all(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name View Selected Operator
+/** \name Frame Selected Operator
*
* Move & Zoom the view to fit selected contents.
* \{ */
@@ -2979,7 +3007,7 @@ void VIEW3D_OT_view_all(wmOperatorType *ot)
/* like a localview without local!, was centerview() in 2.4x */
static int viewselected_exec(bContext *C, wmOperator *op)
{
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
Scene *scene = CTX_data_scene(C);
@@ -2989,12 +3017,12 @@ static int viewselected_exec(bContext *C, wmOperator *op)
Object *obedit = CTX_data_edit_object(C);
const bGPdata *gpd_eval = ob_eval && (ob_eval->type == OB_GPENCIL) ? ob_eval->data : NULL;
const bool is_gp_edit = gpd_eval ? GPENCIL_ANY_MODE(gpd_eval) : false;
- const bool is_face_map = ((is_gp_edit == false) && ar->gizmo_map &&
- WM_gizmomap_is_any_selected(ar->gizmo_map));
+ const bool is_face_map = ((is_gp_edit == false) && region->gizmo_map &&
+ WM_gizmomap_is_any_selected(region->gizmo_map));
float min[3], max[3];
bool ok = false, ok_dist = true;
const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
- const bool skip_camera = (ED_view3d_camera_lock_check(v3d, ar->regiondata) ||
+ const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) ||
/* any one of the regions may be locked */
(use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA));
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
@@ -3038,7 +3066,7 @@ static int viewselected_exec(bContext *C, wmOperator *op)
}
}
else if (is_face_map) {
- ok = WM_gizmomap_minmax(ar->gizmo_map, true, true, min, max);
+ ok = WM_gizmomap_minmax(region->gizmo_map, true, true, min, max);
}
else if (obedit) {
/* only selected */
@@ -3101,7 +3129,7 @@ static int viewselected_exec(bContext *C, wmOperator *op)
view3d_from_minmax_multi(C, v3d, min, max, ok_dist, smooth_viewtx);
}
else {
- view3d_from_minmax(C, v3d, ar, min, max, ok_dist, smooth_viewtx);
+ view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx);
}
return OPERATOR_FINISHED;
@@ -3110,13 +3138,13 @@ static int viewselected_exec(bContext *C, wmOperator *op)
void VIEW3D_OT_view_selected(wmOperatorType *ot)
{
/* identifiers */
- ot->name = "View Selected";
+ ot->name = "Frame Selected";
ot->description = "Move the view to the selection center";
ot->idname = "VIEW3D_OT_view_selected";
/* api callbacks */
ot->exec = viewselected_exec;
- ot->poll = ED_operator_region_view3d_active;
+ ot->poll = view3d_zoom_or_dolly_poll;
/* flags */
ot->flag = 0;
@@ -3177,7 +3205,7 @@ static int view_lock_to_active_exec(bContext *C, wmOperator *UNUSED(op))
if (v3d) {
ED_view3d_lock_clear(v3d);
- v3d->ob_centre = obact; /* can be NULL */
+ v3d->ob_center = obact; /* can be NULL */
if (obact && obact->type == OB_ARMATURE) {
if (obact->mode & OB_MODE_POSE) {
@@ -3185,13 +3213,13 @@ static int view_lock_to_active_exec(bContext *C, wmOperator *UNUSED(op))
Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact);
bPoseChannel *pcham_act = BKE_pose_channel_active(obact_eval);
if (pcham_act) {
- BLI_strncpy(v3d->ob_centre_bone, pcham_act->name, sizeof(v3d->ob_centre_bone));
+ BLI_strncpy(v3d->ob_center_bone, pcham_act->name, sizeof(v3d->ob_center_bone));
}
}
else {
EditBone *ebone_act = ((bArmature *)obact->data)->act_edbone;
if (ebone_act) {
- BLI_strncpy(v3d->ob_centre_bone, ebone_act->name, sizeof(v3d->ob_centre_bone));
+ BLI_strncpy(v3d->ob_center_bone, ebone_act->name, sizeof(v3d->ob_center_bone));
}
}
}
@@ -3234,15 +3262,16 @@ static int viewcenter_cursor_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
if (rv3d) {
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
- ED_view3d_smooth_view_force_finish(C, v3d, ar);
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
/* non camera center */
float new_ofs[3];
negate_v3_v3(new_ofs, scene->cursor.location);
- ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs});
+ ED_view3d_smooth_view(
+ C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs});
/* smooth view does viewlock RV3D_BOXVIEW copy */
}
@@ -3259,7 +3288,7 @@ void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
/* api callbacks */
ot->exec = viewcenter_cursor_exec;
- ot->poll = ED_operator_view3d_active;
+ ot->poll = view3d_pan_poll;
/* flags */
ot->flag = 0;
@@ -3275,27 +3304,28 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev
{
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
if (rv3d) {
struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
float new_ofs[3];
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
- ED_view3d_smooth_view_force_finish(C, v3d, ar);
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
view3d_operator_needs_opengl(C);
- if (ED_view3d_autodist(depsgraph, ar, v3d, event->mval, new_ofs, false, NULL)) {
+ if (ED_view3d_autodist(depsgraph, region, v3d, event->mval, new_ofs, false, NULL)) {
/* pass */
}
else {
/* fallback to simple pan */
negate_v3_v3(new_ofs, rv3d->ofs);
- ED_view3d_win_to_3d_int(v3d, ar, new_ofs, event->mval, new_ofs);
+ ED_view3d_win_to_3d_int(v3d, region, new_ofs, event->mval, new_ofs);
}
negate_v3(new_ofs);
- ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs});
+ ED_view3d_smooth_view(
+ C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs});
}
return OPERATOR_FINISHED;
@@ -3310,7 +3340,7 @@ void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
/* api callbacks */
ot->invoke = viewcenter_pick_invoke;
- ot->poll = ED_operator_view3d_active;
+ ot->poll = view3d_pan_poll;
/* flags */
ot->flag = 0;
@@ -3330,20 +3360,20 @@ static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op))
float size[2];
View3D *v3d;
- ARegion *ar;
+ ARegion *region;
RegionView3D *rv3d;
/* no NULL check is needed, poll checks */
- ED_view3d_context_user_region(C, &v3d, &ar);
- rv3d = ar->regiondata;
+ ED_view3d_context_user_region(C, &v3d, &region);
+ rv3d = region->regiondata;
rv3d->camdx = rv3d->camdy = 0.0f;
- ED_view3d_calc_camera_border_size(scene, depsgraph, ar, v3d, rv3d, size);
+ ED_view3d_calc_camera_border_size(scene, depsgraph, region, v3d, rv3d, size);
/* 4px is just a little room from the edge of the area */
- xfac = (float)ar->winx / (float)(size[0] + 4);
- yfac = (float)ar->winy / (float)(size[1] + 4);
+ xfac = (float)region->winx / (float)(size[0] + 4);
+ yfac = (float)region->winy / (float)(size[1] + 4);
rv3d->camzoom = BKE_screen_view3d_zoom_from_fac(min_ff(xfac, yfac));
CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
@@ -3409,7 +3439,7 @@ void VIEW3D_OT_view_center_lock(wmOperatorType *ot)
static int render_border_exec(bContext *C, wmOperator *op)
{
View3D *v3d = CTX_wm_view3d(C);
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
RegionView3D *rv3d = ED_view3d_context_rv3d(C);
Scene *scene = CTX_data_scene(C);
@@ -3424,13 +3454,13 @@ static int render_border_exec(bContext *C, wmOperator *op)
if (rv3d->persp == RV3D_CAMOB) {
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &vb, false);
+ ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &vb, false);
}
else {
vb.xmin = 0;
vb.ymin = 0;
- vb.xmax = ar->winx;
- vb.ymax = ar->winy;
+ vb.xmax = region->winx;
+ vb.ymax = region->winy;
}
border.xmin = ((float)rect.xmin - vb.xmin) / BLI_rctf_size_x(&vb);
@@ -3562,7 +3592,7 @@ void VIEW3D_OT_clear_render_border(wmOperatorType *ot)
static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
{
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
@@ -3592,14 +3622,14 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
ED_view3d_dist_range_get(v3d, dist_range);
/* Get Z Depths, needed for perspective, nice for ortho */
- ED_view3d_draw_depth(CTX_data_ensure_evaluated_depsgraph(C), ar, v3d, true);
+ ED_view3d_draw_depth(CTX_data_ensure_evaluated_depsgraph(C), region, v3d, true);
{
/* avoid allocating the whole depth buffer */
ViewDepths depth_temp = {0};
/* avoid view3d_update_depths() for speed. */
- view3d_update_depths_rect(ar, &depth_temp, &rect);
+ view3d_update_depths_rect(region, &depth_temp, &rect);
/* find the closest Z pixel */
depth_close = view3d_depth_near(&depth_temp);
@@ -3619,8 +3649,8 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* convert border to 3d coordinates */
- if ((!ED_view3d_unproject(ar, cent[0], cent[1], depth_close, p)) ||
- (!ED_view3d_unproject(ar, rect.xmin, rect.ymin, depth_close, p_corner))) {
+ if ((!ED_view3d_unproject(region, cent[0], cent[1], depth_close, p)) ||
+ (!ED_view3d_unproject(region, rect.xmin, rect.ymin, depth_close, p_corner))) {
return OPERATOR_CANCELLED;
}
@@ -3632,15 +3662,15 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
/* ignore dist_range min */
dist_range[0] = v3d->clip_start * 1.5f;
}
- else { /* othographic */
+ else { /* orthographic */
/* find the current window width and height */
- vb[0] = ar->winx;
- vb[1] = ar->winy;
+ vb[0] = region->winx;
+ vb[1] = region->winy;
new_dist = rv3d->dist;
/* convert the drawn rectangle into 3d space */
- if (depth_close != FLT_MAX && ED_view3d_unproject(ar, cent[0], cent[1], depth_close, p)) {
+ if (depth_close != FLT_MAX && ED_view3d_unproject(region, cent[0], cent[1], depth_close, p)) {
negate_v3_v3(new_ofs, p);
}
else {
@@ -3658,7 +3688,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
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(ar, mval_f, dvec, zfac);
+ ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
/* center the view to the center of the rectangle */
sub_v3_v3(new_ofs, dvec);
}
@@ -3687,15 +3717,15 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.ofs = new_ofs,
.dist = &new_dist,
});
- if (rv3d->viewlock & RV3D_BOXVIEW) {
- view3d_boxview_sync(CTX_wm_area(C), ar);
+ if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_sync(CTX_wm_area(C), region);
}
return OPERATOR_FINISHED;
@@ -3714,7 +3744,7 @@ void VIEW3D_OT_zoom_border(wmOperatorType *ot)
ot->modal = WM_gesture_box_modal;
ot->cancel = WM_gesture_box_cancel;
- ot->poll = ED_operator_region_view3d_active;
+ ot->poll = view3d_zoom_or_dolly_poll;
/* flags */
ot->flag = 0;
@@ -3733,14 +3763,14 @@ void VIEW3D_OT_zoom_border(wmOperatorType *ot)
static void view3d_set_1_to_1_viewborder(Scene *scene,
Depsgraph *depsgraph,
- ARegion *ar,
+ ARegion *region,
View3D *v3d)
{
- RegionView3D *rv3d = ar->regiondata;
+ RegionView3D *rv3d = region->regiondata;
float size[2];
int im_width = (scene->r.size * scene->r.xsch) / 100;
- ED_view3d_calc_camera_border_size(scene, depsgraph, ar, v3d, rv3d, size);
+ ED_view3d_calc_camera_border_size(scene, depsgraph, region, v3d, rv3d, size);
rv3d->camzoom = BKE_screen_view3d_zoom_from_fac((float)im_width / size[0]);
CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
@@ -3752,12 +3782,12 @@ static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op))
Scene *scene = CTX_data_scene(C);
View3D *v3d;
- ARegion *ar;
+ ARegion *region;
/* no NULL check is needed, poll checks */
- ED_view3d_context_user_region(C, &v3d, &ar);
+ ED_view3d_context_user_region(C, &v3d, &region);
- view3d_set_1_to_1_viewborder(scene, depsgraph, ar, v3d);
+ view3d_set_1_to_1_viewborder(scene, depsgraph, region, v3d);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
@@ -3802,14 +3832,15 @@ static const EnumPropertyItem prop_view_items[] = {
*/
static void axis_set_view(bContext *C,
View3D *v3d,
- ARegion *ar,
+ ARegion *region,
const float quat_[4],
- short view,
+ char view,
+ char view_axis_roll,
int perspo,
const float *align_to_quat,
const int smooth_viewtx)
{
- RegionView3D *rv3d = ar->regiondata; /* no NULL check is needed, poll checks */
+ RegionView3D *rv3d = region->regiondata; /* no NULL check is needed, poll checks */
float quat[4];
const short orig_persp = rv3d->persp;
@@ -3818,14 +3849,16 @@ static void axis_set_view(bContext *C,
if (align_to_quat) {
mul_qt_qtqt(quat, quat, align_to_quat);
rv3d->view = view = RV3D_VIEW_USER;
+ rv3d->view_axis_roll = RV3D_VIEW_AXIS_ROLL_0;
}
if (align_to_quat == NULL) {
rv3d->view = view;
+ rv3d->view_axis_roll = view_axis_roll;
}
- if (rv3d->viewlock & RV3D_LOCKED) {
- ED_region_tag_redraw(ar);
+ if (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) {
+ ED_region_tag_redraw(region);
return;
}
@@ -3840,7 +3873,7 @@ static void axis_set_view(bContext *C,
/* to camera */
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.camera_old = v3d->camera,
@@ -3862,7 +3895,7 @@ static void axis_set_view(bContext *C,
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.ofs = ofs,
@@ -3885,7 +3918,7 @@ static void axis_set_view(bContext *C,
/* no camera involved */
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.quat = quat,
@@ -3897,17 +3930,18 @@ static void axis_set_view(bContext *C,
static int view_axis_exec(bContext *C, wmOperator *op)
{
View3D *v3d;
- ARegion *ar;
+ ARegion *region;
RegionView3D *rv3d;
static int perspo = RV3D_PERSP;
int viewnum;
+ int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0;
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
/* no NULL check is needed, poll checks */
- ED_view3d_context_user_region(C, &v3d, &ar);
- rv3d = ar->regiondata;
+ ED_view3d_context_user_region(C, &v3d, &region);
+ rv3d = region->regiondata;
- ED_view3d_smooth_view_force_finish(C, v3d, ar);
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
viewnum = RNA_enum_get(op->ptr, "type");
@@ -3928,58 +3962,74 @@ static int view_axis_exec(bContext *C, wmOperator *op)
}
if (RNA_boolean_get(op->ptr, "relative")) {
- float z_rel[3];
+ float quat_rotate[4];
+ float quat_test[4];
- if (viewnum == RV3D_VIEW_RIGHT) {
- negate_v3_v3(z_rel, rv3d->viewinv[0]);
+ if (viewnum == RV3D_VIEW_LEFT) {
+ axis_angle_to_quat(quat_rotate, rv3d->viewinv[1], -M_PI / 2.0f);
}
- else if (viewnum == RV3D_VIEW_LEFT) {
- copy_v3_v3(z_rel, rv3d->viewinv[0]);
+ else if (viewnum == RV3D_VIEW_RIGHT) {
+ axis_angle_to_quat(quat_rotate, rv3d->viewinv[1], M_PI / 2.0f);
}
else if (viewnum == RV3D_VIEW_TOP) {
- negate_v3_v3(z_rel, rv3d->viewinv[1]);
+ axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], -M_PI / 2.0f);
}
else if (viewnum == RV3D_VIEW_BOTTOM) {
- copy_v3_v3(z_rel, rv3d->viewinv[1]);
+ axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], M_PI / 2.0f);
}
else if (viewnum == RV3D_VIEW_FRONT) {
- negate_v3_v3(z_rel, rv3d->viewinv[2]);
+ unit_qt(quat_rotate);
}
else if (viewnum == RV3D_VIEW_BACK) {
- copy_v3_v3(z_rel, rv3d->viewinv[2]);
+ axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], M_PI);
}
else {
BLI_assert(0);
}
- float angle_max = FLT_MAX;
- int view_closest = -1;
+ mul_qt_qtqt(quat_test, rv3d->viewquat, quat_rotate);
+
+ float angle_best = FLT_MAX;
+ int view_best = -1;
+ int view_axis_roll_best = -1;
for (int i = RV3D_VIEW_FRONT; i <= RV3D_VIEW_BOTTOM; i++) {
- float quat[4];
- float mat[3][3];
- ED_view3d_quat_from_axis_view(i, quat);
- quat[0] *= -1.0f;
- quat_to_mat3(mat, quat);
- if (align_quat) {
- mul_qt_qtqt(quat, quat, align_quat);
- }
- const float angle_test = angle_normalized_v3v3(z_rel, mat[2]);
- if (angle_max > angle_test) {
- angle_max = angle_test;
- view_closest = i;
+ for (int j = RV3D_VIEW_AXIS_ROLL_0; j <= RV3D_VIEW_AXIS_ROLL_270; j++) {
+ float quat_axis[4];
+ ED_view3d_quat_from_axis_view(i, j, quat_axis);
+ if (align_quat) {
+ mul_qt_qtqt(quat_axis, quat_axis, align_quat);
+ }
+ const float angle_test = fabsf(angle_signed_qtqt(quat_axis, quat_test));
+ if (angle_best > angle_test) {
+ angle_best = angle_test;
+ view_best = i;
+ view_axis_roll_best = j;
+ }
}
}
- if (view_closest == -1) {
- view_closest = RV3D_VIEW_FRONT;
+ if (view_best == -1) {
+ view_best = RV3D_VIEW_FRONT;
+ view_axis_roll_best = RV3D_VIEW_AXIS_ROLL_0;
}
- viewnum = view_closest;
+
+ /* Disallow non-upright views in turn-table modes,
+ * it's too difficult to navigate out of them. */
+ if ((U.flag & USER_TRACKBALL) == 0) {
+ if (!ELEM(view_best, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) {
+ view_axis_roll_best = RV3D_VIEW_AXIS_ROLL_0;
+ }
+ }
+
+ viewnum = view_best;
+ view_axis_roll = view_axis_roll_best;
}
/* Use this to test if we started out with a camera */
const int nextperspo = (rv3d->persp == RV3D_CAMOB) ? rv3d->lpersp : perspo;
float quat[4];
- ED_view3d_quat_from_axis_view(viewnum, quat);
- axis_set_view(C, v3d, ar, quat, viewnum, nextperspo, align_quat, smooth_viewtx);
+ ED_view3d_quat_from_axis_view(viewnum, view_axis_roll, quat);
+ axis_set_view(
+ C, v3d, region, quat, viewnum, view_axis_roll, nextperspo, align_quat, smooth_viewtx);
perspo = rv3d->persp;
@@ -4021,17 +4071,17 @@ void VIEW3D_OT_view_axis(wmOperatorType *ot)
static int view_camera_exec(bContext *C, wmOperator *op)
{
View3D *v3d;
- ARegion *ar;
+ ARegion *region;
RegionView3D *rv3d;
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
/* no NULL check is needed, poll checks */
- ED_view3d_context_user_region(C, &v3d, &ar);
- rv3d = ar->regiondata;
+ ED_view3d_context_user_region(C, &v3d, &region);
+ rv3d = region->regiondata;
- ED_view3d_smooth_view_force_finish(C, v3d, ar);
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
- if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
+ if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) {
/* lastview - */
ViewLayer *view_layer = CTX_data_view_layer(C);
@@ -4092,7 +4142,7 @@ static int view_camera_exec(bContext *C, wmOperator *op)
rv3d->persp = RV3D_CAMOB;
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.camera = v3d->camera,
@@ -4105,7 +4155,15 @@ static int view_camera_exec(bContext *C, wmOperator *op)
else {
/* return to settings of last view */
/* does view3d_smooth_view too */
- axis_set_view(C, v3d, ar, rv3d->lviewquat, rv3d->lview, rv3d->lpersp, NULL, smooth_viewtx);
+ axis_set_view(C,
+ v3d,
+ region,
+ rv3d->lviewquat,
+ rv3d->lview,
+ rv3d->lview_axis_roll,
+ rv3d->lpersp,
+ NULL,
+ smooth_viewtx);
}
}
@@ -4153,7 +4211,7 @@ static const EnumPropertyItem prop_view_orbit_items[] = {
static int vieworbit_exec(bContext *C, wmOperator *op)
{
View3D *v3d;
- ARegion *ar;
+ ARegion *region;
RegionView3D *rv3d;
int orbitdir;
char view_opposite;
@@ -4164,23 +4222,23 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
/* no NULL check is needed, poll checks */
v3d = CTX_wm_view3d(C);
- ar = CTX_wm_region(C);
- rv3d = ar->regiondata;
+ region = CTX_wm_region(C);
+ rv3d = region->regiondata;
/* support for switching to the opposite view (even when in locked views) */
view_opposite = (fabsf(angle) == (float)M_PI) ? ED_view3d_axis_view_opposite(rv3d->view) :
RV3D_VIEW_USER;
orbitdir = RNA_enum_get(op->ptr, "type");
- if ((rv3d->viewlock & RV3D_LOCKED) && (view_opposite == RV3D_VIEW_USER)) {
+ if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) && (view_opposite == RV3D_VIEW_USER)) {
/* no NULL check is needed, poll checks */
- ED_view3d_context_user_region(C, &v3d, &ar);
- rv3d = ar->regiondata;
+ ED_view3d_context_user_region(C, &v3d, &region);
+ rv3d = region->regiondata;
}
- ED_view3d_smooth_view_force_finish(C, v3d, ar);
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
- if ((rv3d->viewlock & RV3D_LOCKED) == 0 || (view_opposite != RV3D_VIEW_USER)) {
+ if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0 || (view_opposite != RV3D_VIEW_USER)) {
if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
float quat_mul[4];
@@ -4188,7 +4246,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
if (view_opposite == RV3D_VIEW_USER) {
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- ED_view3d_persp_ensure(depsgraph, v3d, ar);
+ ED_view3d_persp_ensure(depsgraph, v3d, region);
}
if (ELEM(orbitdir, V3D_VIEW_STEPLEFT, V3D_VIEW_STEPRIGHT)) {
@@ -4217,7 +4275,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
if (view_opposite != RV3D_VIEW_USER) {
rv3d->view = view_opposite;
/* avoid float in-precision, just get a new orientation */
- ED_view3d_quat_from_axis_view(view_opposite, quat_new);
+ ED_view3d_quat_from_axis_view(view_opposite, rv3d->view_axis_roll, quat_new);
}
else {
rv3d->view = RV3D_VIEW_USER;
@@ -4234,7 +4292,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.quat = quat_new,
@@ -4279,9 +4337,9 @@ void VIEW3D_OT_view_orbit(wmOperatorType *ot)
* \{ */
static void view_roll_angle(
- ARegion *ar, float quat[4], const float orig_quat[4], const float dvec[3], float angle)
+ ARegion *region, float quat[4], const float orig_quat[4], const float dvec[3], float angle)
{
- RegionView3D *rv3d = ar->regiondata;
+ RegionView3D *rv3d = region->regiondata;
float quat_mul[4];
/* camera axis */
@@ -4302,14 +4360,14 @@ static void viewroll_apply(ViewOpsData *vod, int x, int UNUSED(y))
{
float len1, len2, tot;
- tot = vod->ar->winrct.xmax - vod->ar->winrct.xmin;
- len1 = (vod->ar->winrct.xmax - x) / tot;
- len2 = (vod->ar->winrct.xmax - vod->init.event_xy[0]) / tot;
+ tot = vod->region->winrct.xmax - vod->region->winrct.xmin;
+ len1 = (vod->region->winrct.xmax - x) / tot;
+ len2 = (vod->region->winrct.xmax - vod->init.event_xy[0]) / tot;
angle = (len1 - len2) * (float)M_PI * 4.0f;
}
if (angle != 0.0f) {
- view_roll_angle(vod->ar, 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);
}
if (vod->use_dyn_ofs) {
@@ -4317,13 +4375,13 @@ static void viewroll_apply(ViewOpsData *vod, int x, int UNUSED(y))
vod->rv3d->ofs, vod->init.ofs, vod->init.quat, vod->rv3d->viewquat, vod->dyn_ofs);
}
- if (vod->rv3d->viewlock & RV3D_BOXVIEW) {
- view3d_boxview_sync(vod->sa, vod->ar);
+ if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_sync(vod->sa, vod->region);
}
ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
- ED_region_tag_redraw(vod->ar);
+ ED_region_tag_redraw(vod->region);
}
static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
@@ -4390,21 +4448,21 @@ static int viewroll_exec(bContext *C, wmOperator *op)
{
View3D *v3d;
RegionView3D *rv3d;
- ARegion *ar;
+ ARegion *region;
if (op->customdata) {
ViewOpsData *vod = op->customdata;
- ar = vod->ar;
+ region = vod->region;
v3d = vod->v3d;
}
else {
- ED_view3d_context_user_region(C, &v3d, &ar);
+ ED_view3d_context_user_region(C, &v3d, &region);
}
- rv3d = ar->regiondata;
+ rv3d = region->regiondata;
if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
- ED_view3d_smooth_view_force_finish(C, v3d, ar);
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
int type = RNA_enum_get(op->ptr, "type");
float angle = (type == 0) ? RNA_float_get(op->ptr, "angle") : DEG2RADF(U.pad_rot_angle);
@@ -4419,7 +4477,7 @@ static int viewroll_exec(bContext *C, wmOperator *op)
normalize_v3_v3(mousevec, rv3d->viewinv[2]);
negate_v3(mousevec);
- view_roll_angle(ar, quat_new, rv3d->viewquat, mousevec, angle);
+ view_roll_angle(region, quat_new, rv3d->viewquat, mousevec, angle);
const float *dyn_ofs_pt = NULL;
float dyn_ofs[3];
@@ -4432,7 +4490,7 @@ static int viewroll_exec(bContext *C, wmOperator *op)
ED_view3d_smooth_view(C,
v3d,
- ar,
+ region,
smooth_viewtx,
&(const V3D_SmoothParams){
.quat = quat_new,
@@ -4463,7 +4521,7 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
viewops_data_create(C, op, event, viewops_flag_from_prefs());
vod = op->customdata;
- ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar);
+ ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
/* overwrite the mouse vector with the view direction */
normalize_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]);
@@ -4586,7 +4644,7 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot)
/* api callbacks */
ot->invoke = viewpan_invoke;
- ot->poll = ED_operator_region_view3d_active;
+ ot->poll = view3d_pan_poll;
/* flags */
ot->flag = 0;
@@ -4605,21 +4663,22 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot)
static int viewpersportho_exec(bContext *C, wmOperator *UNUSED(op))
{
View3D *v3d_dummy;
- ARegion *ar;
+ ARegion *region;
RegionView3D *rv3d;
/* no NULL check is needed, poll checks */
- ED_view3d_context_user_region(C, &v3d_dummy, &ar);
- rv3d = ar->regiondata;
+ ED_view3d_context_user_region(C, &v3d_dummy, &region);
+ rv3d = region->regiondata;
- if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
+ /* Could add a separate lock flag for locking persp. */
+ if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) {
if (rv3d->persp != RV3D_ORTHO) {
rv3d->persp = RV3D_ORTHO;
}
else {
rv3d->persp = RV3D_PERSP;
}
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(region);
}
return OPERATOR_FINISHED;
@@ -4845,7 +4904,7 @@ void ED_view3d_clipping_local(RegionView3D *rv3d, float mat[4][4])
static int view3d_clipping_exec(bContext *C, wmOperator *op)
{
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
rcti rect;
@@ -4855,7 +4914,7 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op)
rv3d->clipbb = MEM_callocN(sizeof(BoundBox), "clipbb");
/* NULL object because we don't want it in object space */
- ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, ar, NULL, &rect);
+ ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, region, NULL, &rect);
return OPERATOR_FINISHED;
}
@@ -4863,11 +4922,11 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op)
static int view3d_clipping_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
RegionView3D *rv3d = CTX_wm_region_view3d(C);
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
if (rv3d->rflag & RV3D_CLIPPING) {
rv3d->rflag &= ~RV3D_CLIPPING;
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(region);
if (rv3d->clipbb) {
MEM_freeN(rv3d->clipbb);
}
@@ -4915,9 +4974,9 @@ void ED_view3d_cursor3d_position(bContext *C,
const bool use_depth,
float cursor_co[3])
{
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
- RegionView3D *rv3d = ar->regiondata;
+ RegionView3D *rv3d = region->regiondata;
bool flip;
bool depth_used = false;
@@ -4940,7 +4999,7 @@ void ED_view3d_cursor3d_position(bContext *C,
struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
view3d_operator_needs_opengl(C);
- if (ED_view3d_autodist(depsgraph, ar, v3d, mval, cursor_co, true, NULL)) {
+ if (ED_view3d_autodist(depsgraph, region, v3d, mval, cursor_co, true, NULL)) {
depth_used = true;
}
}
@@ -4948,7 +5007,7 @@ void ED_view3d_cursor3d_position(bContext *C,
if (depth_used == false) {
float depth_pt[3];
copy_v3_v3(depth_pt, cursor_co);
- ED_view3d_win_to_3d_int(v3d, ar, depth_pt, mval, cursor_co);
+ ED_view3d_win_to_3d_int(v3d, region, depth_pt, mval, cursor_co);
}
}
@@ -4962,8 +5021,8 @@ void ED_view3d_cursor3d_position_rotation(bContext *C,
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
+ ARegion *region = CTX_wm_region(C);
+ RegionView3D *rv3d = region->regiondata;
/* XXX, caller should check. */
if (rv3d == NULL) {
@@ -4993,12 +5052,13 @@ void ED_view3d_cursor3d_position_rotation(bContext *C,
float ray_co[3];
struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
- bmain, scene, CTX_data_ensure_evaluated_depsgraph(C), 0, ar, v3d);
+ bmain, scene, 0, region, v3d);
float obmat[4][4];
Object *ob_dummy = NULL;
float dist_px = 0;
if (ED_transform_snap_object_project_view3d_ex(snap_context,
+ CTX_data_ensure_evaluated_depsgraph(C),
SCE_SNAP_MODE_FACE,
&(const struct SnapObjectParams){
.snap_select = SNAP_ALL,
@@ -5075,8 +5135,8 @@ void ED_view3d_cursor3d_update(bContext *C,
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
+ ARegion *region = CTX_wm_region(C);
+ RegionView3D *rv3d = region->regiondata;
View3DCursor *cursor_curr = &scene->cursor;
View3DCursor cursor_prev = *cursor_curr;
@@ -5104,17 +5164,17 @@ void ED_view3d_cursor3d_update(bContext *C,
}
/* offset the cursor lock to avoid jumping to new offset */
- if (v3d->ob_centre_cursor) {
+ if (v3d->ob_center_cursor) {
if (U.uiflag & USER_LOCK_CURSOR_ADJUST) {
float co_2d_curr[2], co_2d_prev[2];
if ((ED_view3d_project_float_global(
- ar, cursor_prev.location, co_2d_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
+ region, cursor_prev.location, co_2d_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
(ED_view3d_project_float_global(
- ar, cursor_curr->location, co_2d_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK)) {
- rv3d->ofs_lock[0] += (co_2d_curr[0] - co_2d_prev[0]) / (ar->winx * 0.5f);
- rv3d->ofs_lock[1] += (co_2d_curr[1] - co_2d_prev[1]) / (ar->winy * 0.5f);
+ region, cursor_curr->location, co_2d_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK)) {
+ rv3d->ofs_lock[0] += (co_2d_curr[0] - co_2d_prev[0]) / (region->winx * 0.5f);
+ rv3d->ofs_lock[1] += (co_2d_curr[1] - co_2d_prev[1]) / (region->winy * 0.5f);
}
}
else {