Blender V5.3
view3d_navigate.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 "DNA_curve_types.h"
10
11#include "BLI_dial_2d.hh"
12#include "BLI_listbase.hh"
13#include "BLI_math_geom_c.hh"
14#include "BLI_math_matrix.hh"
15#include "BLI_math_matrix_c.hh"
17#include "BLI_math_vector.hh"
18#include "BLI_rect.hh"
19
20#include "BKE_context.hh"
21#include "BKE_layer.hh"
22#include "BKE_object.hh"
23#include "BKE_paint.hh"
24#include "BKE_vfont.hh"
25
27
28#include "ED_screen.hh"
29#include "ED_transform.hh"
30
31#include "WM_api.hh"
32
33#include "RNA_access.hh"
34#include "RNA_define.hh"
35
36#include "view3d_intern.hh"
37
38#include "view3d_navigate.hh" /* own include */
39
40namespace blender {
41
42/* Prototypes. */
43static const ViewOpsType *view3d_navigation_type_from_idname(const char *idname);
44
46{
47 const bool use_select = (U.uiflag & USER_ORBIT_SELECTION) != 0;
48 const bool use_depth = (U.uiflag & USER_DEPTH_NAVIGATE) != 0;
49 const bool use_zoom_to_mouse = (U.uiflag & USER_ZOOM_TO_MOUSEPOS) != 0;
50
65
66 if (use_select) {
68 }
69 if (use_depth) {
71 }
72 if (use_zoom_to_mouse) {
74 }
75
76 return flag;
77}
78
79/* -------------------------------------------------------------------- */
82
84{
85 /* Store data. */
87 this->scene = CTX_data_scene(C);
88 this->area = CTX_wm_area(C);
89 this->region = CTX_wm_region(C);
90 this->v3d = this->area->spacedata.first_as<View3D>();
91 this->rv3d = static_cast<RegionView3D *>(this->region->regiondata);
92}
93
95{
96 copy_v3_v3(this->init.ofs, rv3d->ofs);
97 copy_v2_v2(this->init.ofs_lock, rv3d->ofs_lock);
98 this->init.camdx = rv3d->camdx;
99 this->init.camdy = rv3d->camdy;
100 this->init.camzoom = rv3d->camzoom;
101 this->init.camroll = rv3d->camroll;
102 this->init.cam_flip_x = (rv3d->rflag & RV3D_FLIP_X) != 0;
103 this->init.dist = rv3d->dist;
104 copy_qt_qt(this->init.quat, rv3d->viewquat);
105
106 this->init.persp = rv3d->persp;
107 this->init.view = rv3d->view;
108 this->init.view_axis_roll = rv3d->view_axis_roll;
109}
110
112{
113 /* DOLLY, MOVE, ROTATE and ZOOM. */
114 {
115 /* For Move this only changes when offset is not locked. */
116 /* For Rotate this only changes when rotating around objects or last-brush. */
117 /* For Zoom this only changes when zooming to mouse position. */
118 /* Note this does not remove auto-keys on locked cameras. */
119 copy_v3_v3(this->rv3d->ofs, this->init.ofs);
120 }
121
122 /* MOVE and ZOOM. */
123 {
124 /* For Move this only changes when offset is not locked. */
125 /* For Zoom this only changes when zooming to mouse position in camera view. */
126 this->rv3d->camdx = this->init.camdx;
127 this->rv3d->camdy = this->init.camdy;
128 }
129
130 /* MOVE. */
131 {
132 if ((this->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(this->v3d, this->rv3d)) {
133 // this->rv3d->camdx = this->init.camdx;
134 // this->rv3d->camdy = this->init.camdy;
135 }
136 else if (ED_view3d_offset_lock_check(this->v3d, this->rv3d)) {
137 copy_v2_v2(this->rv3d->ofs_lock, this->init.ofs_lock);
138 }
139 else {
140 // copy_v3_v3(vod->rv3d->ofs, vod->init.ofs);
141 if (RV3D_LOCK_FLAGS(this->rv3d) & RV3D_BOXVIEW) {
142 view3d_boxview_sync(this->area, this->region);
143 }
144 }
145 }
146
147 /* ZOOM. */
148 {
149 this->rv3d->camzoom = this->init.camzoom;
150 }
151
152 /* ROTATE and ZOOM. */
153 {
154 /* For Rotate this only changes when orbiting from a camera view.
155 * In this case the `dist` is calculated based on the camera relative to the `ofs`. */
156
157 /* Note this does not remove auto-keys on locked cameras. */
158 this->rv3d->dist = this->init.dist;
159 }
160
161 /* ROLL and ROTATE. */
162 {
163 /* Note this does not remove auto-keys on locked cameras. */
164 copy_qt_qt(this->rv3d->viewquat, this->init.quat);
165 this->rv3d->camroll = this->init.camroll;
166 }
167
168 /* FLIP. */
169 {
170 this->rv3d->rflag &= ~RV3D_FLIP_X;
171 if (this->init.cam_flip_x) {
172 this->rv3d->rflag |= RV3D_FLIP_X;
173 }
174 }
175
176 /* ROTATE. */
177 {
178 this->rv3d->persp = this->init.persp;
179 this->rv3d->view = this->init.view;
180 this->rv3d->view_axis_roll = this->init.view_axis_roll;
181 }
182
183 /* NOTE: there is no need to restore "last" values (as set by #ED_view3d_lastview_store). */
184
185 ED_view3d_camera_lock_sync(this->depsgraph, this->v3d, this->rv3d);
186}
187
189 Depsgraph *depsgraph,
190 ARegion *region,
191 View3D *v3d,
192 const wmEvent *event,
193 eViewOpsFlag viewops_flag,
194 const float dyn_ofs_override[3],
195 float r_pivot[3])
196{
197 if ((viewops_flag & VIEWOPS_FLAG_ORBIT_SELECT) && view3d_orbit_calc_center(C, r_pivot)) {
199 }
200
201 wmWindow *win = CTX_wm_window(C);
202
203 if (!(viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE)) {
205
206 /* Uses the `lastofs` in #view3d_orbit_calc_center. */
210 }
211 /* No valid pivot, don't use any dynamic offset. */
212 return VIEWOPS_FLAG_NONE;
213 }
214
215 if (dyn_ofs_override) {
216 ED_view3d_win_to_3d_int(v3d, region, dyn_ofs_override, event->mval, r_pivot);
218 }
219
220 const bool use_depth_last = ED_view3d_autodist_last_check(win, event);
221
222 if (use_depth_last) {
223 ED_view3d_autodist_last_get(win, r_pivot);
224 }
225 else {
226 float fallback_depth_pt[3];
227 negate_v3_v3(fallback_depth_pt, static_cast<RegionView3D *>(region->regiondata)->ofs);
228
229 if (!ED_view3d_has_depth_buffer_updated(depsgraph, v3d)) {
231 depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, true, nullptr);
232 }
233
234 const bool is_set = ED_view3d_autodist(region, v3d, event->mval, r_pivot, fallback_depth_pt);
235
236 ED_view3d_autodist_last_set(win, event, r_pivot, is_set);
237 }
238
240}
241
243 const wmEvent *event,
244 const ViewOpsType *nav_type,
245 const float dyn_ofs_override[3],
246 const bool use_cursor_init)
247{
248 this->nav_type = nav_type;
250 constexpr eViewOpsFlag viewops_flag_dynamic_ofs = VIEWOPS_FLAG_DEPTH_NAVIGATE |
252
253 if (!use_cursor_init) {
255 }
256
257 bool calc_rv3d_dist = true;
258#ifdef WITH_INPUT_NDOF
259 if (ELEM(nav_type,
260 &ViewOpsType_ndof_orbit,
261 &ViewOpsType_ndof_orbit_zoom,
262 &ViewOpsType_ndof_pan,
263 &ViewOpsType_ndof_all))
264 {
265 calc_rv3d_dist = false;
266
267 /* When using "Free" NDOF navigation, ignore "Orbit Around Selected" preference.
268 * Logically it doesn't make sense to use the selection as a pivot when the first-person
269 * navigation pivots from the view-point. This also interferes with zoom-speed,
270 * causing zoom-speed scale based on the distance to the selection center, see: #115253. */
271 if (U.ndof_navigation_mode == NDOF_NAVIGATION_MODE_FLY) {
273 }
274 }
275#endif
276
277 /* Set the view from the camera, if view locking is enabled.
278 * we may want to make this optional but for now its needed always. */
280
281 this->state_backup();
282
284 if (ED_view3d_persp_ensure(depsgraph, this->v3d, this->region)) {
285 /* If we're switching from camera view to the perspective one,
286 * need to tag viewport update, so camera view and borders are properly updated. */
288 }
289 }
290
291 if (viewops_flag & viewops_flag_dynamic_ofs) {
292 float pivot_new[3];
293 eViewOpsFlag pivot_type = navigate_pivot_get(
294 C, depsgraph, region, v3d, event, viewops_flag, dyn_ofs_override, pivot_new);
295
296 viewops_flag &= ~viewops_flag_dynamic_ofs;
297 viewops_flag |= pivot_type;
298
299 /* It's possible no offset can be found, see: #111098. */
300 if (viewops_flag & viewops_flag_dynamic_ofs) {
301 negate_v3_v3(this->dyn_ofs, pivot_new);
302 this->use_dyn_ofs = true;
303
304 if (pivot_type == VIEWOPS_FLAG_DEPTH_NAVIGATE) {
305 /* Ensure we'll always be able to zoom into the new pivot point and panning won't go bad
306 * when dist is zero. Therefore, set a new #RegionView3D::ofs and #RegionView3D::dist so
307 * that the dist value becomes the distance from the new pivot point. */
308
309 if (rv3d->is_persp) {
310 float my_origin[3]; /* Original #RegionView3D.ofs. */
311 float my_pivot[3]; /* View pivot. */
312 float dvec[3];
313
314 negate_v3_v3(my_origin, rv3d->ofs); /* ofs is flipped */
315
316 /* remove dist value */
317 float3 upvec;
318 upvec[0] = upvec[1] = 0;
319 upvec[2] = rv3d->dist;
321
322 upvec = math::transform_point(mat, upvec);
323 add_v3_v3v3(my_pivot, my_origin, upvec);
324
325 /* find a new ofs value that is along the view axis
326 * (rather than the mouse location) */
327 float lambda = closest_to_line_v3(dvec, pivot_new, my_pivot, my_origin);
328
329 negate_v3_v3(rv3d->ofs, dvec);
330 rv3d->dist = len_v3v3(my_pivot, dvec);
331
332 if (lambda < 0.0f) {
333 /* The distance is actually negative. */
334 rv3d->dist *= -1;
335 }
336 }
337 else {
338 const float mval_region_mid[2] = {float(region->winx) / 2.0f,
339 float(region->winy) / 2.0f};
340 ED_view3d_win_to_3d(v3d, region, pivot_new, mval_region_mid, rv3d->ofs);
342 }
343 }
344
345 /* Reinitialize `this->init.dist` and `this->init.ofs` as these values may have changed
346 * when #ED_view3d_persp_ensure was called or when the operator uses `Auto Depth`.
347 *
348 * XXX: The initial state captured by #ViewOpsData::state_backup is being modified here.
349 * This causes the state not to be fully restored when canceling a navigation operation. */
350 this->init.dist = rv3d->dist;
351 copy_v3_v3(this->init.ofs, rv3d->ofs);
352 }
353 }
354
356 float tvec[3];
357 negate_v3_v3(tvec, rv3d->ofs);
358 this->init.zfac = ED_view3d_calc_zfac(rv3d, tvec);
359 }
360
361 this->init.persp_with_auto_persp_applied = rv3d->persp;
362
363 if (event) {
364 this->init.event_type = event->type;
365 copy_v2_v2_int(this->init.event_xy, event->xy);
366 copy_v2_v2_int(this->prev.event_xy, event->xy);
367
368 if (use_cursor_init) {
369 zero_v2_int(this->init.event_xy_offset);
370 }
371 else {
372 /* Simulate the event starting in the middle of the region. */
373 this->init.event_xy_offset[0] = BLI_rcti_cent_x(&this->region->winrct) - event->xy[0];
374 this->init.event_xy_offset[1] = BLI_rcti_cent_y(&this->region->winrct) - event->xy[1];
375 }
376
377 /* For dolly */
378 const float mval[2] = {float(event->mval[0]), float(event->mval[1])};
379 ED_view3d_win_to_vector(region, mval, this->init.mousevec);
380
381 {
382 int2 event_xy_offset = int2(event->xy) + this->init.event_xy_offset;
383
384 /* For rotation with trackball rotation. */
385 calctrackballvec(&region->winrct, event_xy_offset, this->init.trackvec);
386 }
387 }
388
389 copy_qt_qt(this->curr.viewquat, rv3d->viewquat);
390
391 this->reverse = 1.0f;
392 if (rv3d->persmat[2][1] < 0.0f) {
393 this->reverse = -1.0f;
394 }
395
396 if (rv3d->persp == RV3D_CAMOB && (rv3d->rflag & RV3D_FLIP_X) != 0) {
397 this->reverse *= -1.0f;
398 }
399
400 this->viewops_flag = viewops_flag;
401
402 /* Default. */
403 this->use_dyn_ofs_ortho_correction = false;
404
406}
407
409{
410 this->rv3d->rflag &= ~RV3D_NAVIGATING;
411
412 if (this->timer) {
413 WM_event_timer_remove(CTX_wm_manager(C), this->timer->win, this->timer);
414 }
415
416 if (this->init.dial) {
417 BLI_dial_free(this->init.dial);
418 this->init.dial = nullptr;
419 }
420
421 /* Need to redraw because drawing code uses RV3D_NAVIGATING to draw
422 * faster while navigation operator runs. */
424}
425
427
428/* -------------------------------------------------------------------- */
431
432/* Used for navigation utility in operators. */
434 /* To track only the navigation #wmKeyMapItem items and allow changes to them, an internal
435 * #wmKeyMap is created with their copy. */
436 ListBaseT<wmKeyMapItem> keymap_items;
437
438 /* Used by #ED_view3d_navigation_do. */
439 bool is_modal_event = false;
440
441 ViewOpsData_Utility(bContext *C, const wmKeyMapItem *kmi_merge = nullptr)
443 {
444 this->init_context(C);
445
448
450
451 wmKeyMap keymap_tmp = {};
452
453 for (wmKeyMapItem &kmi : keymap->items) {
454 if (!STRPREFIX(kmi.idname, "VIEW3D")) {
455 continue;
456 }
457 if (kmi.flag & KMI_INACTIVE) {
458 continue;
459 }
460 if (view3d_navigation_type_from_idname(kmi.idname) == nullptr) {
461 continue;
462 }
463
464 wmKeyMapItem *kmi_cpy = WM_keymap_add_item_copy(&keymap_tmp, &kmi);
465 if (kmi_merge) {
466 if (kmi_merge->shift == KM_MOD_HELD ||
467 ELEM(kmi_merge->type, EVT_RIGHTSHIFTKEY, EVT_LEFTSHIFTKEY))
468 {
469 kmi_cpy->shift = KM_MOD_HELD;
470 }
471 if (kmi_merge->ctrl == KM_MOD_HELD ||
472 ELEM(kmi_merge->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY))
473 {
474 kmi_cpy->ctrl = KM_MOD_HELD;
475 }
476 if (kmi_merge->alt == KM_MOD_HELD ||
477 ELEM(kmi_merge->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY))
478 {
479 kmi_cpy->alt = KM_MOD_HELD;
480 }
481 if (kmi_merge->oskey == KM_MOD_HELD || ELEM(kmi_merge->type, EVT_OSKEY)) {
482 kmi_cpy->oskey = KM_MOD_HELD;
483 }
484 if (kmi_merge->hyper == KM_MOD_HELD || ELEM(kmi_merge->type, EVT_HYPER)) {
485 kmi_cpy->hyper = KM_MOD_HELD;
486 }
487 if (!ISKEYMODIFIER(kmi_merge->type)) {
488 kmi_cpy->keymodifier = kmi_merge->type;
489 }
490 }
491 }
492
493 /* Weak, but only the keymap items from the #wmKeyMap struct are needed here. */
494 this->keymap_items = keymap_tmp.items;
495
497 }
498
500 {
501 /* Weak, but rebuild the struct #wmKeyMap to clear the keymap items. */
503
504 wmKeyMap keymap_tmp = {};
505 keymap_tmp.items = this->keymap_items;
506 WM_keymap_clear(&keymap_tmp);
507
509 }
510
511 MEM_CXX_CLASS_ALLOC_FUNCS("ViewOpsData_Utility")
512};
513
515{
517 return false;
518 }
519
520 const RegionView3D *rv3d = CTX_wm_region_view3d(C);
521 return !(RV3D_LOCK_FLAGS(rv3d) & viewlock);
522}
523
525{
526 if (event->type == EVT_MODAL_MAP) {
527 switch (event->val) {
529 return VIEW_CANCEL;
531 return VIEW_CONFIRM;
533 vod->axis_snap = true;
534 return VIEW_APPLY;
536 vod->rv3d->persp = vod->init.persp_with_auto_persp_applied;
537 vod->axis_snap = false;
538 return VIEW_APPLY;
542 const ViewOpsType *nav_type_new = (event->val == VIEWROT_MODAL_SWITCH_ZOOM) ?
544 (event->val == VIEWROT_MODAL_SWITCH_MOVE) ?
547 if (nav_type_new == vod->nav_type) {
548 break;
549 }
550 vod->nav_type = nav_type_new;
551 return VIEW_APPLY;
552 }
553 }
554 }
555 else {
556 if (event->type == TIMER && event->customdata == vod->timer) {
557 /* Zoom uses timer for continuous zoom. */
558 return VIEW_APPLY;
559 }
560 if (event->type == MOUSEMOVE) {
561 return VIEW_APPLY;
562 }
563 if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
564 return VIEW_CONFIRM;
565 }
566 if (event->type == EVT_ESCKEY && event->val == KM_PRESS) {
567 return VIEW_CANCEL;
568 }
569 }
570
571 return VIEW_PASS;
572}
573
575 ViewOpsData *vod,
576 const wmEvent *event,
577 PointerRNA *ptr,
578 const ViewOpsType *nav_type,
579 const float dyn_ofs_override[3])
580{
581 if (!nav_type->init_fn) {
582 return OPERATOR_CANCELLED;
583 }
584
585 bool use_cursor_init = false;
586 if (PropertyRNA *prop = RNA_struct_find_property(ptr, "use_cursor_init")) {
587 use_cursor_init = RNA_property_boolean_get(ptr, prop);
588 }
589
590 vod->init_navigation(C, event, nav_type, dyn_ofs_override, use_cursor_init);
592
593 return nav_type->init_fn(C, vod, event, ptr);
594}
595
597 wmOperator *op,
598 const wmEvent *event,
599 const ViewOpsType *nav_type)
600{
601 ViewOpsData *vod = new ViewOpsData();
602 vod->init_context(C);
604 C, vod, event, op->ptr, nav_type, nullptr);
605 op->customdata = static_cast<void *>(vod);
606
610 }
611
612 viewops_data_free(C, vod);
613 op->customdata = nullptr;
614 return ret;
615}
616
618
619/* -------------------------------------------------------------------- */
622
627
632
637
639{
640 /* This combination of flags is needed for the dolly operator,
641 * see code-comments there for details. */
643}
644
646{
647 ViewOpsData *vod = static_cast<ViewOpsData *>(op->customdata);
648
649 const ViewOpsType *nav_type_prev = vod->nav_type;
650 const eV3D_OpEvent event_code = view3d_navigate_event(vod, event);
651 if (nav_type_prev != vod->nav_type) {
652 wmOperatorType *ot_new = WM_operatortype_find(vod->nav_type->idname, false);
653 WM_operator_type_set(op, ot_new);
654 vod->end_navigation(C);
655 return view3d_navigation_invoke_generic(C, vod, event, op->ptr, vod->nav_type, nullptr);
656 }
657
658 wmOperatorStatus ret = vod->nav_type->apply_fn(C, vod, event_code, event->xy);
659
660 if ((ret & OPERATOR_RUNNING_MODAL) == 0) {
661 if (ret & OPERATOR_FINISHED) {
663 }
664 viewops_data_free(C, vod);
665 op->customdata = nullptr;
666 }
667
668 return ret;
669}
670
672{
673 viewops_data_free(C, static_cast<ViewOpsData *>(op->customdata));
674 op->customdata = nullptr;
675}
676
678
679/* -------------------------------------------------------------------- */
682
684{
685 if (flag & V3D_OP_PROP_MOUSE_CO) {
686 PropertyRNA *prop;
687 prop = RNA_def_int(ot->srna, "mx", 0, 0, INT_MAX, "Region Position X", "", 0, INT_MAX);
689 prop = RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Region Position Y", "", 0, INT_MAX);
691 }
692 if (flag & V3D_OP_PROP_DELTA) {
693 RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
694 }
695 if (flag & V3D_OP_PROP_USE_ALL_REGIONS) {
696 PropertyRNA *prop;
697 prop = RNA_def_boolean(
698 ot->srna, "use_all_regions", false, "All Regions", "View selected for all regions");
700 }
701 if (flag & V3D_OP_PROP_USE_MOUSE_INIT) {
703 }
704}
705
707
708/* -------------------------------------------------------------------- */
711
712void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3])
713{
714 const float radius = V3D_OP_TRACKBALLSIZE;
715 const float t = radius / float(M_SQRT2);
716 const float size[2] = {float(BLI_rcti_size_x(rect)), float(BLI_rcti_size_y(rect))};
717 /* Aspect correct so dragging in a non-square view doesn't squash the direction.
718 * So diagonal motion rotates the same direction the cursor is moving. */
719 const float size_min = min_ff(size[0], size[1]);
720 const float aspect[2] = {size_min / size[0], size_min / size[1]};
721
722 /* Normalize x and y. */
723 r_dir[0] = (event_xy[0] - BLI_rcti_cent_x(rect)) / ((size[0] * aspect[0]) / 2.0);
724 r_dir[1] = (event_xy[1] - BLI_rcti_cent_y(rect)) / ((size[1] * aspect[1]) / 2.0);
725 const float d = len_v2(r_dir);
726 if (d < t) {
727 /* Inside sphere. */
728 r_dir[2] = sqrtf(square_f(radius) - square_f(d));
729 }
730 else {
731 /* On hyperbola. */
732 r_dir[2] = square_f(t) / d;
733 }
734}
735
736void view3d_orbit_apply_dyn_ofs(float r_ofs[3],
737 const float ofs_old[3],
738 const float viewquat_old[4],
739 const float viewquat_new[4],
740 const float dyn_ofs[3])
741{
742 float q[4];
743 invert_qt_qt_normalized(q, viewquat_old);
744 mul_qt_qtqt(q, q, viewquat_new);
745
747
748 sub_v3_v3v3(r_ofs, ofs_old, dyn_ofs);
749 mul_qt_v3(q, r_ofs);
750 add_v3_v3(r_ofs, dyn_ofs);
751}
752
754 const float viewquat_old[4],
755 const float viewquat_new[4],
756 const float dyn_ofs[3])
757{
758 /* NOTE(@ideasman42): While orbiting in orthographic mode the "depth" of the offset
759 * (position along the views Z-axis) is only noticeable when the view contents is clipped.
760 * The likelihood of clipping depends on the clipping range & size of the scene.
761 * In practice some users might not run into this, however using dynamic-offset in
762 * orthographic views can cause the depth of the offset to drift while navigating the view,
763 * causing unexpected clipping that seems like a bug from the user perspective, see: #104385.
764 *
765 * Imagine a camera is focused on a distant object. Now imagine a closer object in front of
766 * the camera is used as a pivot, the camera is rotated to view it from the side (~90d rotation).
767 * The outcome is the camera is now focused on a distant region to the left/right.
768 * The new focal point is unlikely to point to anything useful (unless by accident).
769 * Instead of a focal point - the `rv3d->ofs` is being manipulated in this case.
770 *
771 * Resolve by moving #RegionView3D::ofs so it is depth-aligned to `dyn_ofs`,
772 * this is interpolated by the amount of rotation so minor rotations don't cause
773 * the view-clipping to suddenly jump.
774 *
775 * Perspective Views
776 * =================
777 *
778 * This logic could also be applied to perspective views because the issue of the `ofs`
779 * being a location which isn't useful exists there too, however the problem where this location
780 * impacts the clipping does *not* exist, as the clipping range starts from the view-point
781 * (`ofs` + `dist` along the view Z-axis) unlike orthographic views which center around `ofs`.
782 * Nevertheless there will be cases when having `ofs` and a large `dist` pointing nowhere doesn't
783 * give ideal behavior (zooming may jump in larger than expected steps and panning the view may
784 * move too much in relation to nearby objects - for example). So it's worth investigating but
785 * should be done with extra care as changing `ofs` in perspective view also requires changing
786 * the `dist` which could cause unexpected results if the calculated `dist` happens to be small.
787 * So disable this workaround in perspective view unless there are clear benefits to enabling. */
788
789 float q_inv[4];
790
791 float view_z_init[3] = {0.0f, 0.0f, 1.0f};
792 invert_qt_qt_normalized(q_inv, viewquat_old);
793 mul_qt_v3(q_inv, view_z_init);
794
795 float view_z_curr[3] = {0.0f, 0.0f, 1.0f};
796 invert_qt_qt_normalized(q_inv, viewquat_new);
797 mul_qt_v3(q_inv, view_z_curr);
798
799 const float angle_cos = max_ff(0.0f, dot_v3v3(view_z_init, view_z_curr));
800 /* 1.0 or more means no rotation, there is nothing to do in that case. */
801 if (angle_cos < 1.0f) [[likely]] {
802 const float dot_ofs_curr = dot_v3v3(view_z_curr, ofs);
803 const float dot_ofs_next = dot_v3v3(view_z_curr, dyn_ofs);
804 const float ofs_delta = dot_ofs_next - dot_ofs_curr;
805 if (ofs_delta != 0.0f) [[likely]] {
806 /* Calculate a factor where 0.0 represents no rotation and 1.0 represents 90d or more.
807 * NOTE: Without applying the factor, the distances immediately changes
808 * (useful for testing), but not good for the users experience as minor rotations
809 * should not immediately adjust the depth. */
810 const float factor = acosf(angle_cos) / M_PI_2;
811 madd_v3_v3fl(ofs, view_z_curr, ofs_delta * factor);
812 }
813 }
814}
815
816void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4])
817{
818 if (vod->use_dyn_ofs) {
819 RegionView3D *rv3d = vod->rv3d;
821 rv3d->ofs, vod->init.ofs, vod->init.quat, viewquat_new, vod->dyn_ofs);
822
825 rv3d->ofs, vod->init.quat, viewquat_new, vod->dyn_ofs);
826 }
827 }
828}
829
830bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
831{
832 float3 ofs = float3(0);
833 bool is_set = false;
834
835 const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
837 ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
838 View3D *v3d = CTX_wm_view3d(C);
839 /* Evaluated view layers should always be in sync with the evaluated scene and its collections.
840 */
841 BLI_assert(BKE_view_layer_is_synced(*view_layer_eval));
842 Object *ob_act_eval = BKE_view_layer_active_object_get(view_layer_eval);
843 Object *ob_act = DEG_get_original(ob_act_eval);
844
846 ofs = -float3(v3d->runtime.ofs_last_center);
847 }
848
849 if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT_MESH) &&
850 /* with weight-paint + pose-mode, fall through to using calculateTransformCenter */
851 ((ob_act->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(ob_act)) == 0)
852 {
853 ofs = bke::paint::stroke_get_average(paint, ob_act_eval);
854 is_set = true;
855 }
856 else if (ob_act && ELEM(ob_act->mode,
862 {
863 ofs = bke::paint::stroke_get_average(paint, ob_act_eval);
864 is_set = true;
865 }
866 else if (ob_act && (ob_act->mode & OB_MODE_EDIT) && (ob_act->type == OB_FONT)) {
867 Curve *cu = id_cast<Curve *>(ob_act_eval->data);
868 EditFont *ef = cu->editfont;
869
870 ofs = float3(0);
871 for (int i = 0; i < 4; i++) {
872 add_v2_v2(ofs, ef->textcurs[i]);
873 }
874 ofs *= 0.25f;
875
876 ofs = math::transform_point(ob_act_eval->object_to_world(), ofs);
877
878 is_set = true;
879 }
880 else if (ob_act == nullptr || ob_act->mode == OB_MODE_OBJECT) {
881 /* Object mode uses bounding-box centers. */
882 int total = 0;
883 float3 select_center(0);
884
885 zero_v3(select_center);
886 for (const Base &base_eval : *BKE_view_layer_object_bases_get(view_layer_eval)) {
887 if (BASE_SELECTED(v3d, &base_eval)) {
888 /* Use the bounding-box if we can. */
889 const Object *ob_eval = base_eval.object;
890
891 if (const std::optional<Bounds<float3>> bounds = BKE_object_boundbox_get(ob_eval)) {
892 const float3 center = math::midpoint(bounds->min, bounds->max);
893 select_center += math::transform_point(ob_eval->object_to_world(), center);
894 }
895 else {
896 add_v3_v3(select_center, ob_eval->object_to_world().location());
897 }
898 total++;
899 }
900 }
901 if (total) {
902 mul_v3_fl(select_center, 1.0f / float(total));
903 copy_v3_v3(ofs, select_center);
904 is_set = true;
905 }
906 }
907 else {
908 /* If there's no selection, `ofs` is unmodified, the last offset will be used if set.
909 * Otherwise the value of `ofs` is zero and should not be used. */
911 }
912
913 if (is_set) {
916 }
917
918 copy_v3_v3(r_dyn_ofs, ofs);
919
920 return is_set;
921}
922
924 const wmEvent *event,
925 const ViewOpsType *nav_type,
926 const bool use_cursor_init)
927{
928 ViewOpsData *vod = new ViewOpsData();
929 vod->init_context(C);
930 vod->init_navigation(C, event, nav_type, nullptr, use_cursor_init);
931 return vod;
932}
933
935{
936 if (!vod) {
937 return;
938 }
939 vod->end_navigation(C);
940 delete vod;
941}
942
944
945/* -------------------------------------------------------------------- */
948
950 View3D *v3d,
951 ARegion *region,
952 const float quat_[4],
954 eRegionView3D_ViewAxisRoll view_axis_roll,
955 eRegionView3D_Persp perspo,
956 const float *align_to_quat,
957 const int smooth_viewtx)
958{
959 /* no nullptr check is needed, poll checks */
960 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
961
962 float quat[4];
963 const eRegionView3D_Persp orig_persp = rv3d->persp;
964 const eRegionView3D_View orig_view = rv3d->view;
965 const eRegionView3D_ViewAxisRoll orig_view_axis_roll = rv3d->view_axis_roll;
966
967 normalize_qt_qt(quat, quat_);
968
969 if (align_to_quat) {
970 mul_qt_qtqt(quat, quat, align_to_quat);
971 rv3d->view = view = RV3D_VIEW_USER;
973 }
974 else {
975 rv3d->view = view;
976 rv3d->view_axis_roll = view_axis_roll;
977 }
978
979 /* Redrawing when changes are detected is needed because the current view
980 * orientation may be a "User" view that matches the axis exactly.
981 * In this case smooth-view exits early as no view transition is needed.
982 * However, changing the view must redraw the region as it changes the
983 * viewport name & grid drawing. */
984 if ((rv3d->view != orig_view) || (rv3d->view_axis_roll != orig_view_axis_roll)) {
985 ED_region_tag_redraw(region);
986 }
987
989 return;
990 }
991
992 if (U.uiflag & USER_AUTOPERSP) {
993 rv3d->persp = RV3D_VIEW_IS_AXIS(view) ? RV3D_ORTHO : perspo;
994 }
995 else if (rv3d->persp == RV3D_CAMOB) {
996 rv3d->persp = perspo;
997 }
998 if (rv3d->persp != orig_persp) {
999 ED_region_tag_redraw(region);
1000 }
1001
1002 if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
1003 /* to camera */
1004 V3D_SmoothParams sview = {nullptr};
1005 sview.camera_old = v3d->camera;
1006 sview.ofs = rv3d->ofs;
1007 sview.quat = quat;
1008 /* No undo because this switches to/from camera. */
1009 sview.undo_str = nullptr;
1010
1011 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview);
1012 }
1013 else if (orig_persp == RV3D_CAMOB && v3d->camera) {
1014 /* from camera */
1015 float ofs[3], dist;
1016
1017 copy_v3_v3(ofs, rv3d->ofs);
1018 dist = rv3d->dist;
1019
1020 /* so we animate _from_ the camera location */
1022 ED_view3d_from_object(camera_eval, rv3d->ofs, nullptr, &rv3d->dist, 0.0f, nullptr);
1023
1024 V3D_SmoothParams sview = {nullptr};
1025 sview.camera_old = camera_eval;
1026 sview.ofs = ofs;
1027 sview.quat = quat;
1028 sview.dist = &dist;
1029 /* No undo because this switches to/from camera. */
1030 sview.undo_str = nullptr;
1031
1032 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview);
1033 }
1034 else {
1035 /* rotate around selection */
1036 const float *dyn_ofs_pt = nullptr;
1037 float dyn_ofs[3];
1038
1039 if (U.uiflag & USER_ORBIT_SELECTION) {
1040 if (view3d_orbit_calc_center(C, dyn_ofs)) {
1041 negate_v3(dyn_ofs);
1042 dyn_ofs_pt = dyn_ofs;
1043 }
1044 }
1045
1046 /* no camera involved */
1047 V3D_SmoothParams sview = {nullptr};
1048 sview.quat = quat;
1049 sview.dyn_ofs = dyn_ofs_pt;
1050 /* No undo because this switches to/from camera. */
1051 sview.undo_str = nullptr;
1052
1053 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview);
1054 }
1055}
1056
1057void viewmove_apply(ViewOpsData *vod, int x, int y)
1058{
1059 const float event_ofs[2] = {
1060 float(vod->prev.event_xy[0] - x),
1061 float(vod->prev.event_xy[1] - y),
1062 };
1063
1064 if ((vod->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) {
1065 ED_view3d_camera_view_pan(vod->region, event_ofs);
1066 }
1067 else if (ED_view3d_offset_lock_check(vod->v3d, vod->rv3d)) {
1068 vod->rv3d->ofs_lock[0] -= (event_ofs[0] * 2.0f) / float(vod->region->winx);
1069 vod->rv3d->ofs_lock[1] -= (event_ofs[1] * 2.0f) / float(vod->region->winy);
1070 }
1071 else {
1072 float dvec[3];
1073
1074 ED_view3d_win_to_delta(vod->region, event_ofs, vod->init.zfac, dvec, true);
1075
1076 sub_v3_v3(vod->rv3d->ofs, dvec);
1077
1078 if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
1079 view3d_boxview_sync(vod->area, vod->region);
1080 }
1081 }
1082
1083 vod->prev.event_xy[0] = x;
1084 vod->prev.event_xy[1] = y;
1085
1086 ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
1087
1089}
1090
1092
1093/* -------------------------------------------------------------------- */
1096
1098static const float view3d_horizon_eps = 1e-5f;
1099
1107static float view3d_horizon_angle_calc(const float quat[4],
1108 const float horizon_plane[3],
1109 const bool horizon_plane_no_flip,
1110 const float axis_fallback[3],
1111 const float angle_target,
1112 const bool use_ease_out)
1113{
1114 BLI_ASSERT_UNIT_V3(horizon_plane);
1115
1116 float imat[3][3];
1117 quat_to_mat3(imat, quat);
1118 transpose_m3(imat);
1119
1120 float axis_horizon[3];
1121 cross_v3_v3v3(axis_horizon, horizon_plane, imat[2]);
1122 const float axis_length = normalize_v3(axis_horizon);
1123 if (axis_length < view3d_horizon_eps) {
1124 /* Undefined when looking along `horizon_plane`. */
1125 if (axis_fallback == nullptr) {
1126 return 0.0f;
1127 }
1128 BLI_ASSERT_UNIT_V3(axis_fallback);
1129 /* A fallback parallel to the plane leaves nothing to use. */
1130 project_plane_normalized_v3_v3v3(axis_horizon, axis_fallback, horizon_plane);
1131 if (normalize_v3(axis_horizon) < view3d_horizon_eps) {
1132 return 0.0f;
1133 }
1134 }
1135
1136 float angle = angle_wrap_rad(angle_signed_on_axis_v3v3_v3(axis_horizon, imat[0], imat[2]));
1137
1138 if (horizon_plane_no_flip) {
1139 /* Align to the closer end of the horizon axis. */
1140 if (angle > float(M_PI_2)) {
1141 angle -= float(M_PI);
1142 }
1143 else if (angle < -float(M_PI_2)) {
1144 angle += float(M_PI);
1145 }
1146 }
1147
1148 if (use_ease_out) {
1149 /* Distance of the view X axis from the horizon plane,
1150 * signed from `angle` which may have been flipped above.
1151 * The same as: `angle = sinf(angle) * axis_length;`. */
1152 angle = copysignf(dot_v3v3(imat[0], horizon_plane), angle);
1153 }
1154
1155 angle -= angle_target;
1156
1157 return (fabsf(angle) < view3d_horizon_eps) ? 0.0f : angle;
1158}
1159
1161static void view3d_horizon_angle_apply(float quat[4], const float angle)
1162{
1163 float quat_roll[4];
1164 axis_angle_to_quat_single(quat_roll, 'Z', -angle);
1165 mul_qt_qtqt(quat, quat_roll, quat);
1166}
1167
1169 const float horizon_plane[3],
1170 const bool horizon_plane_no_flip,
1171 const float axis_fallback[3],
1172 const float angle_target,
1173 const float factor)
1174{
1175 const float angle = view3d_horizon_angle_calc(
1176 quat, horizon_plane, horizon_plane_no_flip, axis_fallback, angle_target, false);
1177 if (angle != 0.0f) {
1178 view3d_horizon_angle_apply(quat, angle * factor);
1179 }
1180
1181 return angle;
1182}
1183
1185 const float horizon_plane[3],
1186 const bool horizon_plane_no_flip,
1187 const float factor)
1188{
1189 const float angle = view3d_horizon_angle_calc(
1190 quat, horizon_plane, horizon_plane_no_flip, nullptr, 0.0f, true);
1191 if (angle != 0.0f) {
1192 view3d_horizon_angle_apply(quat, angle * factor);
1193 }
1194
1195 return angle;
1196}
1197
1199
1200/* -------------------------------------------------------------------- */
1203
1204/* Detect the navigation operation, by the name of the navigation operator (obtained by
1205 * `wmKeyMapItem::idname`) */
1206static const ViewOpsType *view3d_navigation_type_from_idname(const char *idname)
1207{
1208 const Array<const ViewOpsType *> nav_types = {
1213// &ViewOpsType_orbit,
1214// &ViewOpsType_roll,
1215// &ViewOpsType_dolly,
1216#ifdef WITH_INPUT_NDOF
1217 &ViewOpsType_ndof_orbit,
1218 &ViewOpsType_ndof_orbit_zoom,
1219 &ViewOpsType_ndof_pan,
1220 &ViewOpsType_ndof_all,
1221#endif
1222 };
1223
1224 const char *op_name = idname + sizeof("VIEW3D_OT_");
1225 for (const ViewOpsType *nav_type : nav_types) {
1226 if (STREQ(op_name, nav_type->idname + sizeof("VIEW3D_OT_"))) {
1227 return nav_type;
1228 }
1229 }
1230 return nullptr;
1231}
1232
1234{
1235 /* Unlike #viewops_data_create, #ED_view3d_navigation_init creates a navigation context along
1236 * with an array of `wmKeyMapItem`s used for navigation. */
1237 if (!CTX_wm_region_view3d(C)) {
1238 return nullptr;
1239 }
1240
1241 return new ViewOpsData_Utility(C, kmi_merge);
1242}
1243
1245 ViewOpsData *vod,
1246 const wmEvent *event,
1247 const float depth_loc_override[3])
1248{
1249 if (!vod) {
1250 return false;
1251 }
1252
1253 wmEvent event_tmp;
1254 if (event->type == EVT_MODAL_MAP) {
1255 /* Workaround to use the original event values. */
1256 event_tmp = *event;
1257 event_tmp.type = event->prev_type;
1258 event_tmp.val = event->prev_val;
1259 event = &event_tmp;
1260 }
1261
1263
1264 ViewOpsData_Utility *vod_intern = static_cast<ViewOpsData_Utility *>(vod);
1265 if (vod_intern->is_modal_event) {
1266 const eV3D_OpEvent event_code = view3d_navigate_event(vod, event);
1267 op_return = vod->nav_type->apply_fn(C, vod, event_code, event->xy);
1268 if (op_return != OPERATOR_RUNNING_MODAL) {
1269 vod->end_navigation(C);
1270 vod_intern->is_modal_event = false;
1271 }
1272 }
1273 else {
1274 for (wmKeyMapItem &kmi : vod_intern->keymap_items) {
1275 if (!WM_event_match(event, &kmi)) {
1276 continue;
1277 }
1278
1280 if (nav_type->poll_fn && !nav_type->poll_fn(C)) {
1281 break;
1282 }
1283
1285 C, vod, event, kmi.ptr, nav_type, depth_loc_override);
1286
1287 if (op_return == OPERATOR_RUNNING_MODAL) {
1288 vod_intern->is_modal_event = true;
1289 }
1290 else {
1291 vod->end_navigation(C);
1292 /* Postpone the navigation confirmation to the next call.
1293 * This avoids constant updating of the transform operation for example. */
1294 vod->rv3d->rflag |= RV3D_NAVIGATING;
1295 }
1296 break;
1297 }
1298 }
1299
1300 if (op_return != OPERATOR_CANCELLED) {
1301 /* Although #ED_view3d_update_viewmat is already called when redrawing the 3D View, do it here
1302 * as well, so the updated matrix values can be accessed by the operator. */
1304 vod->depsgraph, vod->scene, vod->v3d, vod->region, nullptr, nullptr, nullptr, false);
1305
1306 return true;
1307 }
1308 if (vod->rv3d->rflag & RV3D_NAVIGATING) {
1309 /* Add a fake confirmation. */
1310 vod->rv3d->rflag &= ~RV3D_NAVIGATING;
1311 return true;
1312 }
1313
1314 return false;
1315}
1316
1318{
1319 ViewOpsData_Utility *vod_intern = static_cast<ViewOpsData_Utility *>(vod);
1320 vod_intern->end_navigation(C);
1321 delete vod_intern;
1322}
1323
1325
1326} // namespace blender
General operations, lookup, etc. for blender objects.
#define BLI_ASSERT_UNIT_V3(v)
#define M_SQRT2
#define M_PI_2
#define M_PI
#define OB_MODE_ALL_PAINT_MESH
#define RV3D_VIEW_IS_AXIS(view)
#define RV3D_LOCK_FLAGS(rv3d)
#define C
Definition RandGen.cpp:29
#define KM_MOD_HELD
Definition WM_types.hh:339
#define STRPREFIX(a, b)
#define ELEM(...)
#define STREQ(a, b)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
#define acosf(x)
#define copysignf(x, y)
#define INT_MAX
float3 stroke_get_average(const Paint *paint, const Object *ob)
bool calc_pivot_pos(const bContext *C, const short pivot_type, float r_pivot_pos[3])
T midpoint(const T &a, const T &b)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
bool WM_event_match(const wmEvent *winevent, const wmKeyMapItem *kmi)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void negate_v3_v3(float r[3], const float a[3])
static eViewOpsFlag viewops_flag_from_prefs()
@ V3D_RUNTIME_OFS_LAST_CENTER_IS_VALID
static eViewOpsFlag navigate_pivot_get(bContext *C, Depsgraph *depsgraph, ARegion *region, View3D *v3d, const wmEvent *event, eViewOpsFlag viewops_flag, const float dyn_ofs_override[3], float r_pivot[3])
ViewOpsData * ED_view3d_navigation_init(bContext *C, const wmKeyMapItem *kmi_merge)
ScrArea * CTX_wm_area(const bContext *C)
wmKeyMap * WM_keymap_find_all(wmWindowManager *wm, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:949
bool ED_view3d_camera_lock_check(const View3D *v3d, const RegionView3D *rv3d)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
MINLINE void copy_v3_v3(float r[3], const float a[3])
static float view3d_horizon_angle_calc(const float quat[4], const float horizon_plane[3], const bool horizon_plane_no_flip, const float axis_fallback[3], const float angle_target, const bool use_ease_out)
void viewops_data_free(bContext *C, ViewOpsData *vod)
void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
bool ED_view3d_autodist_last_get(wmWindow *win, float r_ofs[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
void WM_operator_type_set(wmOperator *op, wmOperatorType *ot)
Definition wm.cc:323
void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3D_OpPropFlag flag)
ViewOpsData * viewops_data_create(bContext *C, const wmEvent *event, const ViewOpsType *nav_type, const bool use_cursor_init)
bool ED_view3d_persp_ensure(const Depsgraph *depsgraph, View3D *v3d, ARegion *region)
bool ED_view3d_camera_lock_sync(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
void ED_view3d_update_viewmat(const Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, const float viewmat[4][4], const float winmat[4][4], const rcti *rect, bool offscreen)
bool ED_view3d_camera_lock_undo_push(const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C)
@ V3D_AROUND_CENTER_MEDIAN
static const float view3d_horizon_eps
wmWindow * CTX_wm_window(const bContext *C)
static const ViewOpsType * view3d_navigation_type_from_idname(const char *idname)
bool ED_view3d_autodist_last_check(wmWindow *win, const wmEvent *event)
void project_plane_normalized_v3_v3v3(float out[3], const float p[3], const float v_plane[3])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
MatBase< float, 4, 4 > float4x4
@ RV3D_LOCK_ZOOM_AND_DOLLY
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void WM_keymap_clear(wmKeyMap *keymap)
Definition wm_keymap.cc:461
void ED_view3d_autodist_last_clear(wmWindow *win)
bool ED_view3d_navigation_do(bContext *C, ViewOpsData *vod, const wmEvent *event, const float depth_loc_override[3])
static void view3d_orbit_apply_dyn_ofs_ortho_correction(float ofs[3], const float viewquat_old[4], const float viewquat_new[4], const float dyn_ofs[3])
float angle_signed_on_axis_v3v3_v3(const float v1[3], const float v2[3], const float axis[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v3_fl(float r[3], float f)
static wmOperatorStatus view3d_navigation_invoke_generic(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *ptr, const ViewOpsType *nav_type, const float dyn_ofs_override[3])
bool view3d_zoom_or_dolly_or_rotation_poll(bContext *C)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
void WM_operator_properties_use_cursor_init(wmOperatorType *ot)
MINLINE void sub_v3_v3(float r[3], const float a[3])
void mul_qt_v3(const float q[4], float r[3])
const ViewOpsType ViewOpsType_pan
void quat_to_mat3(float m[3][3], const float q[4])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
static eV3D_OpEvent view3d_navigate_event(ViewOpsData *vod, const wmEvent *event)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
bool ED_view3d_autodist(ARegion *region, View3D *v3d, const int mval[2], float mouse_worldloc[3], const float fallback_depth_pt[3])
const ViewOpsType ViewOpsType_move
VecBase< int32_t, 2 > int2
wmOperatorStatus view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, const ViewOpsType *nav_type)
MINLINE void add_v2_v2(float r[2], const float a[2])
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 transpose_m3(float R[3][3])
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition BLI_rect.hh:190
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void copy_qt_qt(float q[4], const float a[4])
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_SCULPT_CURVES
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
bool BKE_view_layer_is_synced(const ViewLayer &view_layer)
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
bool view3d_location_poll(bContext *C)
bool ED_view3d_camera_view_pan(ARegion *region, const float event_ofs[2])
wmKeyMapItem * WM_keymap_add_item_copy(wmKeyMap *keymap, const wmKeyMapItem *kmi_src)
Definition wm_keymap.cc:582
const ViewOpsType ViewOpsType_rotate
void axis_angle_to_quat_single(float q[4], char axis, float angle)
void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float r_out[3])
void invert_qt_normalized(float q[4])
MINLINE void negate_v3(float r[3])
@ VIEW_CONFIRM
Definition image_ops.cc:652
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3])
RegionView3D * CTX_wm_region_view3d(const bContext *C)
void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3])
void WM_keyconfig_update_suppress_begin()
MINLINE void zero_v3(float r[3])
MatBase< float, 3, 3 > float3x3
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
bool view3d_rotation_poll(bContext *C)
bool ED_view3d_has_depth_buffer_updated(const Depsgraph *depsgraph, const View3D *v3d)
@ VIEWOPS_FLAG_ZOOM_TO_MOUSE
@ VIEWOPS_FLAG_DEPTH_NAVIGATE
@ VIEWOPS_FLAG_INIT_ZFAC
@ VIEWOPS_FLAG_ORBIT_SELECT
@ VIEWOPS_FLAG_PERSP_ENSURE
bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
@ VIEWROT_MODAL_AXIS_SNAP_ENABLE
@ VIEWROT_MODAL_AXIS_SNAP_DISABLE
@ VIEWROT_MODAL_SWITCH_MOVE
@ VIEWROT_MODAL_SWITCH_ZOOM
@ VIEWROT_MODAL_SWITCH_ROTATE
MINLINE float normalize_v3(float n[3])
bool ED_view3d_offset_lock_check(const View3D *v3d, const RegionView3D *rv3d)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
MINLINE void add_v3_v3(float r[3], const float a[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void viewmove_apply(ViewOpsData *vod, int x, int y)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void view3d_navigate_cancel_fn(bContext *C, wmOperator *op)
T * DEG_get_original(T *id)
MINLINE void zero_v2_int(int r[2])
void BLI_dial_free(Dial *dial)
bool view3d_zoom_or_dolly_poll(bContext *C)
const ViewOpsType ViewOpsType_zoom
void ED_view3d_autodist_last_set(wmWindow *win, const wmEvent *event, const float ofs[3], const bool has_depth)
Paint * BKE_paint_get_active_from_context(const bContext *C)
MINLINE float max_ff(float a, float b)
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
void ED_view3d_camera_lock_init_ex(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d, bool calc_dist)
void WM_keyconfig_update_suppress_end()
float closest_to_line_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3])
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
bool ED_operator_region_view3d_active(bContext *C)
void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region)
MINLINE float square_f(float a)
@ V3D_DEPTH_NO_GPENCIL
Definition ED_view3d.hh:209
void view3d_orbit_apply_dyn_ofs(float r_ofs[3], const float ofs_old[3], const float viewquat_old[4], const float viewquat_new[4], const float dyn_ofs[3])
@ KM_RELEASE
Definition WM_types.hh:325
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])
static void view3d_horizon_angle_apply(float quat[4], const float angle)
Scene * CTX_data_scene(const bContext *C)
@ V3D_OP_PROP_USE_ALL_REGIONS
@ V3D_OP_PROP_USE_MOUSE_INIT
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
void invert_qt_qt_normalized(float q1[4], const float q2[4])
std::optional< Bounds< float3 > > BKE_object_boundbox_get(const Object *ob)
Definition object.cc:3726
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
void ED_view3d_navigation_free(bContext *C, ViewOpsData *vod)
VecBase< float, 3 > float3
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.hh:186
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void ED_view3d_win_to_3d(const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
void ED_view3d_from_object(const Object *ob, float ofs[3], float quat[4], const float *dist, float roll, float *r_lens)
static bool view3d_navigation_poll_impl(bContext *C, const eRegionView3D_ViewLock viewlock)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ARegion * CTX_wm_region(const bContext *C)
void ED_view3d_smooth_view(bContext *C, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
void view3d_boxview_sync(ScrArea *area, ARegion *region)
float view3d_horizon_correct_quat(float quat[4], const float horizon_plane[3], const bool horizon_plane_no_flip, const float axis_fallback[3], const float angle_target, const float factor)
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
void ED_view3d_win_to_delta(const ARegion *region, const float xy_delta[2], float zfac, float r_out[3], bool precise=false)
float view3d_horizon_correct_quat_ease_out(float quat[4], const float horizon_plane[3], const bool horizon_plane_no_flip, const float factor)
View3D * CTX_wm_view3d(const bContext *C)
float normalize_qt_qt(float r[4], const float q[4])
float angle_wrap_rad(float angle)
wmOperatorStatus view3d_navigate_modal_fn(bContext *C, wmOperator *op, const wmEvent *event)
#define fabsf
#define sqrtf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct EditFont * editfont
float2 textcurs[4]
Definition BKE_vfont.hh:54
eRegionView3D_Flag rflag
eRegionView3D_ViewAxisRoll view_axis_roll
eRegionView3D_Persp persp
eRegionView3D_View view
ListBaseT< SpaceLink > spacedata
struct Object * camera
View3D_Runtime runtime
ViewOpsData_Utility(bContext *C, const wmKeyMapItem *kmi_merge=nullptr)
ListBaseT< wmKeyMapItem > keymap_items
const ViewOpsType * nav_type
struct blender::ViewOpsData::@013213354235237006300365026145043140112021271057 prev
void end_navigation(bContext *C)
void init_navigation(bContext *C, const wmEvent *event, const ViewOpsType *nav_type, const float dyn_ofs_override[3]=nullptr, const bool use_cursor_init=false)
void init_context(bContext *C)
struct blender::ViewOpsData::@337054214024237015354033064215073157327063021373 curr
struct blender::ViewOpsData::@130157306301264131203124134151333300254160116071 init
bool(*) poll_fn(bContext *C)
wmOperatorStatus(*) init_fn(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *ptr)
wmOperatorStatus(*) apply_fn(bContext *C, ViewOpsData *vod, const eV3D_OpEvent event_code, const int xy[2])
wmEventType type
Definition WM_types.hh:817
ListBaseT< wmKeyMapItem > items
struct wmOperatorType * type
wmWindow * win
Definition WM_types.hh:1026
bool is_set(uint i)
#define V3D_OP_TRACKBALLSIZE
#define ISKEYMODIFIER(event_type)