Blender V5.3
view3d_navigate_view_camera.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 "BKE_context.hh"
10#include "BKE_layer.hh"
11
12#include "DEG_depsgraph.hh"
13
14#include "WM_api.hh"
15
16#include "view3d_intern.hh"
17
18#include "view3d_navigate.hh" /* own include */
19
20namespace blender {
21
22/* -------------------------------------------------------------------- */
25
27{
28 View3D *v3d;
29 ARegion *region;
30 RegionView3D *rv3d;
31 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
32
33 /* no nullptr check is needed, poll checks */
34 ED_view3d_context_user_region(C, &v3d, &region);
35 rv3d = static_cast<RegionView3D *>(region->regiondata);
36
38
39 if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) {
40 const Main *bmain = CTX_data_main(C);
41 ViewLayer *view_layer = CTX_data_view_layer(C);
42 Scene *scene = CTX_data_scene(C);
43
44 if (rv3d->persp != RV3D_CAMOB) {
45 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
47
48 if (!rv3d->smooth_timer) {
49 /* store settings of current view before allowing overwriting with camera view
50 * only if we're not currently in a view transition */
51
53 }
54
55 /* first get the default camera for the view lock type */
56 if (v3d->scenelock) {
57 /* sets the camera view if available */
58 v3d->camera = scene->camera;
59 }
60 else {
61 /* use scene camera if one is not set (even though we're unlocked) */
62 if (v3d->camera == nullptr) {
63 v3d->camera = scene->camera;
64 }
65 }
66
67 /* if the camera isn't found, check a number of options */
68 if (v3d->camera == nullptr && ob && ob->type == OB_CAMERA) {
69 v3d->camera = ob;
70 }
71
72 if (v3d->camera == nullptr) {
73 v3d->camera = BKE_view_layer_camera_find(*bmain, scene, view_layer);
74 }
75
76 /* couldn't find any useful camera, bail out */
77 if (v3d->camera == nullptr) {
78 return OPERATOR_CANCELLED;
79 }
80
81 /* important these don't get out of sync for locked scenes */
82 if (v3d->scenelock && scene->camera != v3d->camera) {
83 scene->camera = v3d->camera;
85 }
86
87 /* finally do snazzy view zooming */
88 rv3d->persp = RV3D_CAMOB;
89
90 V3D_SmoothParams sview = {nullptr};
91 sview.camera = v3d->camera;
92 sview.ofs = rv3d->ofs;
93 sview.quat = rv3d->viewquat;
94 sview.dist = &rv3d->dist;
95 sview.lens = &v3d->lens;
96 /* No undo because this changes cameras (and wont move the camera). */
97 sview.undo_str = nullptr;
98
99 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview);
100 }
101 else {
102 /* return to settings of last view */
103 /* does view3d_smooth_view too */
105 v3d,
106 region,
107 rv3d->lviewquat,
108 rv3d->lview,
109 rv3d->lview_axis_roll,
110 rv3d->lpersp,
111 nullptr,
112 smooth_viewtx);
113 }
114 }
115
116 return OPERATOR_FINISHED;
117}
118
120{
121 /* identifiers */
122 ot->name = "View Camera";
123 ot->description = "Toggle the camera view";
124 ot->idname = "VIEW3D_OT_view_camera";
125
126 /* API callbacks. */
129
130 /* flags */
131 ot->flag = 0;
132}
133
135
136} // namespace blender
#define RV3D_LOCK_FLAGS(rv3d)
#define C
Definition RandGen.cpp:29
BMesh Iterators.
static wmOperatorStatus view_camera_exec(bContext *C, wmOperator *op)
bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_region)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
bool ED_operator_rv3d_user_region_poll(bContext *C)
int WM_operator_smooth_viewtx_get(const wmOperator *op)
@ RV3D_LOCK_ANY_TRANSFORM
void VIEW3D_OT_view_camera(wmOperatorType *ot)
ViewLayer * CTX_data_view_layer(const bContext *C)
Object * BKE_view_layer_camera_find(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void axis_set_view(bContext *C, View3D *v3d, ARegion *region, const float quat_[4], eRegionView3D_View view, eRegionView3D_ViewAxisRoll view_axis_roll, eRegionView3D_Persp perspo, const float *align_to_quat, const int smooth_viewtx)
void DEG_id_tag_update(ID *id, unsigned int flags)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
Main * CTX_data_main(const bContext *C)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region)
void ED_view3d_lastview_store(RegionView3D *rv3d)
Scene * CTX_data_scene(const bContext *C)
void ED_view3d_smooth_view(bContext *C, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
eRegionView3D_View lview
eRegionView3D_ViewAxisRoll lview_axis_roll
eRegionView3D_Persp lpersp
struct wmTimer * smooth_timer
eRegionView3D_Persp persp
struct Object * camera
struct Object * camera
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165