Blender V5.0
view3d_navigate_view_center_pick.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_vector.h"
10
11#include "BKE_context.hh"
12
13#include "WM_api.hh"
14
15#include "view3d_intern.hh"
16
17#include "view3d_navigate.hh" /* own include */
18
19/* -------------------------------------------------------------------- */
22
24{
25 View3D *v3d = CTX_wm_view3d(C);
27 ARegion *region = CTX_wm_region(C);
28
29 if (rv3d) {
31 float ofs_new[3];
32 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
33
35
37
38 /* Ensure the depth buffer is updated for #ED_view3d_autodist. */
39 ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, true, nullptr);
40
41 if (ED_view3d_autodist(region, v3d, event->mval, ofs_new, nullptr)) {
42 /* pass */
43 }
44 else {
45 /* fall back to simple pan */
46 negate_v3_v3(ofs_new, rv3d->ofs);
47 ED_view3d_win_to_3d_int(v3d, region, ofs_new, event->mval, ofs_new);
48 }
49 negate_v3(ofs_new);
50
51 V3D_SmoothParams sview = {nullptr};
52 sview.ofs = ofs_new;
53 sview.undo_str = op->type->name;
54
55 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview);
56 }
57
58 return OPERATOR_FINISHED;
59}
60
62{
63 /* identifiers */
64 ot->name = "Center View to Mouse";
65 ot->description = "Center the view to the Z-depth position under the mouse cursor";
66 ot->idname = "VIEW3D_OT_view_center_pick";
67
68 /* API callbacks. */
69 ot->invoke = viewcenter_pick_invoke;
71
72 /* flags */
73 ot->flag = 0;
74}
75
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3(float r[3])
@ OPERATOR_FINISHED
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
void ED_view3d_win_to_3d_int(const View3D *v3d, const ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
bool ED_view3d_autodist(ARegion *region, View3D *v3d, const int mval[2], float mouse_worldloc[3], const float fallback_depth_pt[3])
@ V3D_DEPTH_NO_GPENCIL
Definition ED_view3d.hh:192
void view3d_operator_needs_gpu(const bContext *C)
#define C
Definition RandGen.cpp:29
BPy_StructRNA * depsgraph
const char * undo_str
int mval[2]
Definition WM_types.hh:763
const char * name
Definition WM_types.hh:1033
struct wmOperatorType * type
bool view3d_location_poll(bContext *C)
void ED_view3d_smooth_view(bContext *C, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region)
void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
static wmOperatorStatus viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorType * ot
Definition wm_files.cc:4237
int WM_operator_smooth_viewtx_get(const wmOperator *op)