Blender  V2.93
view3d_edit.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
26 #include <float.h>
27 #include <math.h>
28 #include <stdio.h>
29 #include <string.h>
30 
31 #include "DNA_armature_types.h"
32 #include "DNA_camera_types.h"
33 #include "DNA_curve_types.h"
34 #include "DNA_gpencil_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
37 
38 #include "MEM_guardedalloc.h"
39 
40 #include "BLI_blenlib.h"
41 #include "BLI_math.h"
42 #include "BLI_utildefines.h"
43 
44 #include "BKE_action.h"
45 #include "BKE_armature.h"
46 #include "BKE_camera.h"
47 #include "BKE_context.h"
48 #include "BKE_font.h"
49 #include "BKE_gpencil_geom.h"
50 #include "BKE_layer.h"
51 #include "BKE_lib_id.h"
52 #include "BKE_main.h"
53 #include "BKE_object.h"
54 #include "BKE_paint.h"
55 #include "BKE_report.h"
56 #include "BKE_scene.h"
57 #include "BKE_screen.h"
58 
59 #include "DEG_depsgraph.h"
60 #include "DEG_depsgraph_query.h"
61 
62 #include "WM_api.h"
63 #include "WM_message.h"
64 #include "WM_types.h"
65 
66 #include "RNA_access.h"
67 #include "RNA_define.h"
68 
69 #include "ED_armature.h"
70 #include "ED_mesh.h"
71 #include "ED_particle.h"
72 #include "ED_screen.h"
73 #include "ED_transform.h"
75 #include "ED_view3d.h"
76 
77 #include "UI_resources.h"
78 
79 #include "PIL_time.h"
80 
81 #include "view3d_intern.h" /* own include */
82 
83 enum {
84  HAS_TRANSLATE = (1 << 0),
85  HAS_ROTATE = (1 << 0),
86 };
87 
88 /* test for unlocked camera view in quad view */
90 {
91  View3D *v3d;
92  ARegion *region;
93 
94  if (ED_view3d_context_user_region(C, &v3d, &region)) {
95  RegionView3D *rv3d = region->regiondata;
96  if ((rv3d->persp == RV3D_CAMOB) && !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM)) {
97  return 1;
98  }
99  }
100 
101  return 0;
102 }
103 
105 {
106  View3D *v3d = CTX_wm_view3d(C);
107  if (v3d) {
109  if (rv3d) {
110  return ED_view3d_offset_lock_check(v3d, rv3d);
111  }
112  }
113  return false;
114 }
115 
117 {
119  const RegionView3D *rv3d = CTX_wm_region_view3d(C);
120  return !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_LOCATION);
121  }
122  return false;
123 }
124 
126 {
128  const RegionView3D *rv3d = CTX_wm_region_view3d(C);
129  return !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ZOOM_AND_DOLLY);
130  }
131  return false;
132 }
133 
134 /* -------------------------------------------------------------------- */
140  V3D_OP_PROP_DELTA = (1 << 1),
143 };
144 
146 {
147  if (flag & V3D_OP_PROP_MOUSE_CO) {
148  PropertyRNA *prop;
149  prop = RNA_def_int(ot->srna, "mx", 0, 0, INT_MAX, "Region Position X", "", 0, INT_MAX);
151  prop = RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Region Position Y", "", 0, INT_MAX);
153  }
154  if (flag & V3D_OP_PROP_DELTA) {
155  RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
156  }
157  if (flag & V3D_OP_PROP_USE_ALL_REGIONS) {
158  PropertyRNA *prop;
159  prop = RNA_def_boolean(
160  ot->srna, "use_all_regions", 0, "All Regions", "View selected for all regions");
162  }
163  if (flag & V3D_OP_PROP_USE_MOUSE_INIT) {
165  }
166 }
167 
170 /* -------------------------------------------------------------------- */
174 typedef struct ViewOpsData {
183 
186 
188  struct {
189  float dist;
190  float camzoom;
191  float quat[4];
193  int event_xy[2];
199  float ofs[3];
201  float zfac;
202 
204  float trackvec[3];
206  float mousevec[3];
207 
212  char persp;
213  } init;
214 
216  struct {
217  int event_xy[2];
219  double time;
220  } prev;
221 
223  struct {
227  float viewquat[4];
228  } curr;
229 
230  float reverse;
231  bool axis_snap; /* view rotate only */
232 
234  float dyn_ofs[3];
237 
242 #define TRACKBALLSIZE (1.1f)
243 
244 static void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3])
245 {
246  const float radius = TRACKBALLSIZE;
247  const float t = radius / (float)M_SQRT2;
248  const float size[2] = {BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)};
249  /* Aspect correct so dragging in a non-square view doesn't squash the direction.
250  * So diagonal motion rotates the same direction the cursor is moving. */
251  const float size_min = min_ff(size[0], size[1]);
252  const float aspect[2] = {size_min / size[0], size_min / size[1]};
253 
254  /* Normalize x and y. */
255  r_dir[0] = (event_xy[0] - BLI_rcti_cent_x(rect)) / ((size[0] * aspect[0]) / 2.0);
256  r_dir[1] = (event_xy[1] - BLI_rcti_cent_y(rect)) / ((size[1] * aspect[1]) / 2.0);
257  const float d = len_v2(r_dir);
258  if (d < t) {
259  /* Inside sphere. */
260  r_dir[2] = sqrtf(square_f(radius) - square_f(d));
261  }
262  else {
263  /* On hyperbola. */
264  r_dir[2] = square_f(t) / d;
265  }
266 }
267 
272 {
273  ViewOpsData *vod = MEM_callocN(sizeof(ViewOpsData), "viewops data");
274 
275  /* store data */
276  op->customdata = vod;
277  vod->bmain = CTX_data_main(C);
279  vod->scene = CTX_data_scene(C);
280  vod->area = CTX_wm_area(C);
281  vod->region = CTX_wm_region(C);
282  vod->v3d = vod->area->spacedata.first;
283  vod->rv3d = vod->region->regiondata;
284 }
285 
286 void view3d_orbit_apply_dyn_ofs(float r_ofs[3],
287  const float ofs_old[3],
288  const float viewquat_old[4],
289  const float viewquat_new[4],
290  const float dyn_ofs[3])
291 {
292  float q[4];
293  invert_qt_qt_normalized(q, viewquat_old);
294  mul_qt_qtqt(q, q, viewquat_new);
295 
297 
298  sub_v3_v3v3(r_ofs, ofs_old, dyn_ofs);
299  mul_qt_v3(q, r_ofs);
300  add_v3_v3(r_ofs, dyn_ofs);
301 }
302 
303 static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
304 {
305  static float lastofs[3] = {0, 0, 0};
306  bool is_set = false;
307 
311  View3D *v3d = CTX_wm_view3d(C);
312  Object *ob_act_eval = OBACT(view_layer_eval);
313  Object *ob_act = DEG_get_original_object(ob_act_eval);
314 
315  if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT) &&
316  /* with weight-paint + pose-mode, fall through to using calculateTransformCenter */
317  ((ob_act->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(ob_act)) == 0) {
318  /* in case of sculpting use last average stroke position as a rotation
319  * center, in other cases it's not clear what rotation center shall be
320  * so just rotate around object origin
321  */
322  if (ob_act->mode &
324  float stroke[3];
325  BKE_paint_stroke_get_average(scene, ob_act_eval, stroke);
326  copy_v3_v3(lastofs, stroke);
327  }
328  else {
329  copy_v3_v3(lastofs, ob_act_eval->obmat[3]);
330  }
331  is_set = true;
332  }
333  else if (ob_act && (ob_act->mode & OB_MODE_EDIT) && (ob_act->type == OB_FONT)) {
334  Curve *cu = ob_act_eval->data;
335  EditFont *ef = cu->editfont;
336 
337  zero_v3(lastofs);
338  for (int i = 0; i < 4; i++) {
339  add_v2_v2(lastofs, ef->textcurs[i]);
340  }
341  mul_v2_fl(lastofs, 1.0f / 4.0f);
342 
343  mul_m4_v3(ob_act_eval->obmat, lastofs);
344 
345  is_set = true;
346  }
347  else if (ob_act == NULL || ob_act->mode == OB_MODE_OBJECT) {
348  /* object mode use boundbox centers */
349  Base *base_eval;
350  uint tot = 0;
351  float select_center[3];
352 
353  zero_v3(select_center);
354  for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) {
355  if (BASE_SELECTED(v3d, base_eval)) {
356  /* use the boundbox if we can */
357  Object *ob_eval = base_eval->object;
358 
359  if (ob_eval->runtime.bb && !(ob_eval->runtime.bb->flag & BOUNDBOX_DIRTY)) {
360  float cent[3];
361 
362  BKE_boundbox_calc_center_aabb(ob_eval->runtime.bb, cent);
363 
364  mul_m4_v3(ob_eval->obmat, cent);
365  add_v3_v3(select_center, cent);
366  }
367  else {
368  add_v3_v3(select_center, ob_eval->obmat[3]);
369  }
370  tot++;
371  }
372  }
373  if (tot) {
374  mul_v3_fl(select_center, 1.0f / (float)tot);
375  copy_v3_v3(lastofs, select_center);
376  is_set = true;
377  }
378  }
379  else {
380  /* If there's no selection, lastofs is unmodified and last value since static */
382  }
383 
384  copy_v3_v3(r_dyn_ofs, lastofs);
385 
386  return is_set;
387 }
388 
402 };
403 
404 static enum eViewOpsFlag viewops_flag_from_args(bool use_select, bool use_depth)
405 {
406  enum eViewOpsFlag flag = 0;
407  if (use_select) {
409  }
410  if (use_depth) {
412  }
413 
414  return flag;
415 }
416 
417 static enum eViewOpsFlag viewops_flag_from_prefs(void)
418 {
419  return viewops_flag_from_args((U.uiflag & USER_ORBIT_SELECTION) != 0,
420  (U.uiflag & USER_DEPTH_NAVIGATE) != 0);
421 }
422 
427  wmOperator *op,
428  const wmEvent *event,
429  enum eViewOpsFlag viewops_flag)
430 {
432  ViewOpsData *vod = op->customdata;
433  RegionView3D *rv3d = vod->rv3d;
434 
435  /* Could do this more nicely. */
436  if ((viewops_flag & VIEWOPS_FLAG_USE_MOUSE_INIT) == 0) {
437  viewops_flag &= ~VIEWOPS_FLAG_DEPTH_NAVIGATE;
438  }
439 
440  /* we need the depth info before changing any viewport options */
441  if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) {
442  float fallback_depth_pt[3];
443 
444  view3d_operator_needs_opengl(C); /* needed for zbuf drawing */
445 
446  negate_v3_v3(fallback_depth_pt, rv3d->ofs);
447 
449  depsgraph, vod->region, vod->v3d, event->mval, vod->dyn_ofs, true, fallback_depth_pt);
450  }
451  else {
452  vod->use_dyn_ofs = false;
453  }
454 
455  if (viewops_flag & VIEWOPS_FLAG_PERSP_ENSURE) {
456  if (ED_view3d_persp_ensure(depsgraph, vod->v3d, vod->region)) {
457  /* If we're switching from camera view to the perspective one,
458  * need to tag viewport update, so camera view and borders are properly updated. */
460  }
461  }
462 
463  /* set the view from the camera, if view locking is enabled.
464  * we may want to make this optional but for now its needed always */
466 
467  vod->init.persp = rv3d->persp;
468  vod->init.dist = rv3d->dist;
469  vod->init.camzoom = rv3d->camzoom;
470  copy_qt_qt(vod->init.quat, rv3d->viewquat);
471  vod->init.event_xy[0] = vod->prev.event_xy[0] = event->x;
472  vod->init.event_xy[1] = vod->prev.event_xy[1] = event->y;
473 
474  if (viewops_flag & VIEWOPS_FLAG_USE_MOUSE_INIT) {
475  vod->init.event_xy_offset[0] = 0;
476  vod->init.event_xy_offset[1] = 0;
477  }
478  else {
479  /* Simulate the event starting in the middle of the region. */
480  vod->init.event_xy_offset[0] = BLI_rcti_cent_x(&vod->region->winrct) - event->x;
481  vod->init.event_xy_offset[1] = BLI_rcti_cent_y(&vod->region->winrct) - event->y;
482  }
483 
484  vod->init.event_type = event->type;
485  copy_v3_v3(vod->init.ofs, rv3d->ofs);
486 
487  copy_qt_qt(vod->curr.viewquat, rv3d->viewquat);
488 
489  if (viewops_flag & VIEWOPS_FLAG_ORBIT_SELECT) {
490  float ofs[3];
491  if (view3d_orbit_calc_center(C, ofs) || (vod->use_dyn_ofs == false)) {
492  vod->use_dyn_ofs = true;
493  negate_v3_v3(vod->dyn_ofs, ofs);
494  viewops_flag &= ~VIEWOPS_FLAG_DEPTH_NAVIGATE;
495  }
496  }
497 
498  if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) {
499  if (vod->use_dyn_ofs) {
500  if (rv3d->is_persp) {
501  float my_origin[3]; /* original G.vd->ofs */
502  float my_pivot[3]; /* view */
503  float dvec[3];
504 
505  /* locals for dist correction */
506  float mat[3][3];
507  float upvec[3];
508 
509  negate_v3_v3(my_origin, rv3d->ofs); /* ofs is flipped */
510 
511  /* Set the dist value to be the distance from this 3d point this means you'll
512  * always be able to zoom into it and panning wont go bad when dist was zero. */
513 
514  /* remove dist value */
515  upvec[0] = upvec[1] = 0;
516  upvec[2] = rv3d->dist;
517  copy_m3_m4(mat, rv3d->viewinv);
518 
519  mul_m3_v3(mat, upvec);
520  sub_v3_v3v3(my_pivot, rv3d->ofs, upvec);
521  negate_v3(my_pivot); /* ofs is flipped */
522 
523  /* find a new ofs value that is along the view axis
524  * (rather than the mouse location) */
525  closest_to_line_v3(dvec, vod->dyn_ofs, my_pivot, my_origin);
526  vod->init.dist = rv3d->dist = len_v3v3(my_pivot, dvec);
527 
528  negate_v3_v3(rv3d->ofs, dvec);
529  }
530  else {
531  const float mval_region_mid[2] = {(float)vod->region->winx / 2.0f,
532  (float)vod->region->winy / 2.0f};
533 
534  ED_view3d_win_to_3d(vod->v3d, vod->region, vod->dyn_ofs, mval_region_mid, rv3d->ofs);
535  negate_v3(rv3d->ofs);
536  }
537  negate_v3(vod->dyn_ofs);
538  copy_v3_v3(vod->init.ofs, rv3d->ofs);
539  }
540  }
541 
542  /* For dolly */
543  ED_view3d_win_to_vector(vod->region, (const float[2]){UNPACK2(event->mval)}, vod->init.mousevec);
544 
545  {
546  const int event_xy_offset[2] = {
547  event->x + vod->init.event_xy_offset[0],
548  event->y + vod->init.event_xy_offset[1],
549  };
550  /* For rotation with trackball rotation. */
551  calctrackballvec(&vod->region->winrct, event_xy_offset, vod->init.trackvec);
552  }
553 
554  {
555  float tvec[3];
556  negate_v3_v3(tvec, rv3d->ofs);
557  vod->init.zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL);
558  }
559 
560  vod->reverse = 1.0f;
561  if (rv3d->persmat[2][1] < 0.0f) {
562  vod->reverse = -1.0f;
563  }
564 
565  rv3d->rflag |= RV3D_NAVIGATING;
566 }
567 
569 {
570  ARegion *region;
571  if (op->customdata) {
572  ViewOpsData *vod = op->customdata;
573  region = vod->region;
574  vod->rv3d->rflag &= ~RV3D_NAVIGATING;
575 
576  if (vod->timer) {
578  }
579 
580  MEM_freeN(vod);
581  op->customdata = NULL;
582  }
583  else {
584  region = CTX_wm_region(C);
585  }
586 
587  /* Need to redraw because drawing code uses RV3D_NAVIGATING to draw
588  * faster while navigation operator runs. */
589  ED_region_tag_redraw(region);
590 }
591 
594 /* -------------------------------------------------------------------- */
598 enum {
602 };
603 
604 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
605 enum {
606  VIEW_MODAL_CONFIRM = 1, /* used for all view operations */
612 };
613 
614 /* called in transform_ops.c, on each regeneration of keymaps */
616 {
617  static const EnumPropertyItem modal_items[] = {
618  {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
619 
620  {VIEWROT_MODAL_AXIS_SNAP_ENABLE, "AXIS_SNAP_ENABLE", 0, "Axis Snap", ""},
621  {VIEWROT_MODAL_AXIS_SNAP_DISABLE, "AXIS_SNAP_DISABLE", 0, "Axis Snap (Off)", ""},
622 
623  {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"},
624  {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"},
625 
626  {0, NULL, 0, NULL, NULL},
627  };
628 
629  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Rotate Modal");
630 
631  /* this function is called for each spacetype, only needs to add map once */
632  if (keymap && keymap->modal_items) {
633  return;
634  }
635 
636  keymap = WM_modalkeymap_ensure(keyconf, "View3D Rotate Modal", modal_items);
637 
638  /* disabled mode switching for now, can re-implement better, later on */
639 #if 0
643 #endif
644 
645  /* assign map to operators */
646  WM_modalkeymap_assign(keymap, "VIEW3D_OT_rotate");
647 }
648 
649 static void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4])
650 {
651  if (vod->use_dyn_ofs) {
652  RegionView3D *rv3d = vod->rv3d;
654  rv3d->ofs, vod->init.ofs, vod->init.quat, viewquat_new, vod->dyn_ofs);
655  }
656 }
657 
659 {
660  const float axis_limit = DEG2RADF(45 / 3);
661 
662  RegionView3D *rv3d = vod->rv3d;
663 
664  float viewquat_inv[4];
665  float zaxis[3] = {0, 0, 1};
666  float zaxis_best[3];
667  int x, y, z;
668  bool found = false;
669  bool is_axis_aligned = false;
670 
671  invert_qt_qt_normalized(viewquat_inv, vod->curr.viewquat);
672 
673  mul_qt_v3(viewquat_inv, zaxis);
674  normalize_v3(zaxis);
675 
676  for (x = -1; x < 2; x++) {
677  for (y = -1; y < 2; y++) {
678  for (z = -1; z < 2; z++) {
679  if (x || y || z) {
680  float zaxis_test[3] = {x, y, z};
681 
682  normalize_v3(zaxis_test);
683 
684  if (angle_normalized_v3v3(zaxis_test, zaxis) < axis_limit) {
685  copy_v3_v3(zaxis_best, zaxis_test);
686  found = true;
687 
688  if (abs(x) + abs(y) + abs(z) == 1) {
689  is_axis_aligned = true;
690  }
691  }
692  }
693  }
694  }
695  }
696 
697  if (found) {
698 
699  /* find the best roll */
700  float quat_roll[4], quat_final[4], quat_best[4], quat_snap[4];
701  float viewquat_align[4]; /* viewquat aligned to zaxis_best */
702  float viewquat_align_inv[4]; /* viewquat aligned to zaxis_best */
703  float best_angle = axis_limit;
704  int j;
705 
706  /* viewquat_align is the original viewquat aligned to the snapped axis
707  * for testing roll */
708  rotation_between_vecs_to_quat(viewquat_align, zaxis_best, zaxis);
709  normalize_qt(viewquat_align);
710  mul_qt_qtqt(viewquat_align, vod->curr.viewquat, viewquat_align);
711  normalize_qt(viewquat_align);
712  invert_qt_qt_normalized(viewquat_align_inv, viewquat_align);
713 
714  vec_to_quat(quat_snap, zaxis_best, OB_NEGZ, OB_POSY);
715  normalize_qt(quat_snap);
716  invert_qt_normalized(quat_snap);
717 
718  /* check if we can find the roll */
719  found = false;
720 
721  /* find best roll */
722  for (j = 0; j < 8; j++) {
723  float angle;
724  float xaxis1[3] = {1, 0, 0};
725  float xaxis2[3] = {1, 0, 0};
726  float quat_final_inv[4];
727 
728  axis_angle_to_quat(quat_roll, zaxis_best, (float)j * DEG2RADF(45.0f));
729  normalize_qt(quat_roll);
730 
731  mul_qt_qtqt(quat_final, quat_snap, quat_roll);
732  normalize_qt(quat_final);
733 
734  /* compare 2 vector angles to find the least roll */
735  invert_qt_qt_normalized(quat_final_inv, quat_final);
736  mul_qt_v3(viewquat_align_inv, xaxis1);
737  mul_qt_v3(quat_final_inv, xaxis2);
738  angle = angle_v3v3(xaxis1, xaxis2);
739 
740  if (angle <= best_angle) {
741  found = true;
742  best_angle = angle;
743  copy_qt_qt(quat_best, quat_final);
744  }
745  }
746 
747  if (found) {
748  /* lock 'quat_best' to an axis view if we can */
749  ED_view3d_quat_to_axis_view(quat_best, 0.01f, &rv3d->view, &rv3d->view_axis_roll);
750  if (rv3d->view != RV3D_VIEW_USER) {
751  ED_view3d_quat_from_axis_view(rv3d->view, rv3d->view_axis_roll, quat_best);
752  }
753  }
754  else {
755  copy_qt_qt(quat_best, viewquat_align);
756  }
757 
758  copy_qt_qt(rv3d->viewquat, quat_best);
759 
761 
762  if (U.uiflag & USER_AUTOPERSP) {
763  if (is_axis_aligned) {
764  if (rv3d->persp == RV3D_PERSP) {
765  rv3d->persp = RV3D_ORTHO;
766  }
767  }
768  }
769  }
770  else if (U.uiflag & USER_AUTOPERSP) {
771  rv3d->persp = vod->init.persp;
772  }
773 }
774 
775 static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2])
776 {
777  RegionView3D *rv3d = vod->rv3d;
778 
779  rv3d->view = RV3D_VIEW_USER; /* need to reset every time because of view snapping */
780 
781  if (U.flag & USER_TRACKBALL) {
782  float axis[3], q1[4], dvec[3], newvec[3];
783  float angle;
784 
785  {
786  const int event_xy_offset[2] = {
787  event_xy[0] + vod->init.event_xy_offset[0],
788  event_xy[1] + vod->init.event_xy_offset[1],
789  };
790  calctrackballvec(&vod->region->winrct, event_xy_offset, newvec);
791  }
792 
793  sub_v3_v3v3(dvec, newvec, vod->init.trackvec);
794 
795  angle = (len_v3(dvec) / (2.0f * TRACKBALLSIZE)) * (float)M_PI;
796 
797  /* Before applying the sensitivity this is rotating 1:1,
798  * where the cursor would match the surface of a sphere in the view. */
799  angle *= U.view_rotate_sensitivity_trackball;
800 
801  /* Allow for rotation beyond the interval [-pi, pi] */
803 
804  /* This relation is used instead of the actual angle between vectors
805  * so that the angle of rotation is linearly proportional to
806  * the distance that the mouse is dragged. */
807 
808  cross_v3_v3v3(axis, vod->init.trackvec, newvec);
809  axis_angle_to_quat(q1, axis, angle);
810 
811  mul_qt_qtqt(vod->curr.viewquat, q1, vod->init.quat);
812 
814  }
815  else {
816  /* New turntable view code by John Aughey */
817  float quat_local_x[4], quat_global_z[4];
818  float m[3][3];
819  float m_inv[3][3];
820  const float zvec_global[3] = {0.0f, 0.0f, 1.0f};
821  float xaxis[3];
822 
823  /* Radians per-pixel. */
824  const float sensitivity = U.view_rotate_sensitivity_turntable / U.dpi_fac;
825 
826  /* Get the 3x3 matrix and its inverse from the quaternion */
827  quat_to_mat3(m, vod->curr.viewquat);
828  invert_m3_m3(m_inv, m);
829 
830  /* Avoid Gimbal Lock
831  *
832  * Even though turn-table mode is in use, this can occur when the user exits the camera view
833  * or when aligning the view to a rotated object.
834  *
835  * We have gimbal lock when the user's view is rotated +/- 90 degrees along the view axis.
836  * In this case the vertical rotation is the same as the sideways turntable motion.
837  * Making it impossible to get out of the gimbal locked state without resetting the view.
838  *
839  * The logic below lets the user exit out of this state without any abrupt 'fix'
840  * which would be disorienting.
841  *
842  * This works by blending two horizons:
843  * - Rotated-horizon: `cross_v3_v3v3(xaxis, zvec_global, m_inv[2])`
844  * When only this is used, this turntable rotation works - but it's side-ways
845  * (as if the entire turn-table has been placed on its side)
846  * While there is no gimbal lock, it's also awkward to use.
847  * - Un-rotated-horizon: `m_inv[0]`
848  * When only this is used, the turntable rotation can have gimbal lock.
849  *
850  * The solution used here is to blend between these two values,
851  * so the severity of the gimbal lock is used to blend the rotated horizon.
852  * Blending isn't essential, it just makes the transition smoother.
853  *
854  * This allows sideways turn-table rotation on a Z axis that isn't world-space Z,
855  * While up-down turntable rotation eventually corrects gimbal lock. */
856 #if 1
857  if (len_squared_v3v3(zvec_global, m_inv[2]) > 0.001f) {
858  float fac;
859  cross_v3_v3v3(xaxis, zvec_global, m_inv[2]);
860  if (dot_v3v3(xaxis, m_inv[0]) < 0) {
861  negate_v3(xaxis);
862  }
863  fac = angle_normalized_v3v3(zvec_global, m_inv[2]) / (float)M_PI;
864  fac = fabsf(fac - 0.5f) * 2;
865  fac = fac * fac;
866  interp_v3_v3v3(xaxis, xaxis, m_inv[0], fac);
867  }
868  else {
869  copy_v3_v3(xaxis, m_inv[0]);
870  }
871 #else
872  copy_v3_v3(xaxis, m_inv[0]);
873 #endif
874 
875  /* Determine the direction of the x vector (for rotating up and down) */
876  /* This can likely be computed directly from the quaternion. */
877 
878  /* Perform the up/down rotation */
879  axis_angle_to_quat(quat_local_x, xaxis, sensitivity * -(event_xy[1] - vod->prev.event_xy[1]));
880  mul_qt_qtqt(quat_local_x, vod->curr.viewquat, quat_local_x);
881 
882  /* Perform the orbital rotation */
884  quat_global_z, 'Z', sensitivity * vod->reverse * (event_xy[0] - vod->prev.event_xy[0]));
885  mul_qt_qtqt(vod->curr.viewquat, quat_local_x, quat_global_z);
886 
888  }
889 
890  /* avoid precision loss over time */
891  normalize_qt(vod->curr.viewquat);
892 
893  /* use a working copy so view rotation locking doesn't overwrite the locked
894  * rotation back into the view we calculate with */
895  copy_qt_qt(rv3d->viewquat, vod->curr.viewquat);
896 
897  /* check for view snap,
898  * note: don't apply snap to vod->viewquat so the view wont jam up */
899  if (vod->axis_snap) {
901  }
902  vod->prev.event_xy[0] = event_xy[0];
903  vod->prev.event_xy[1] = event_xy[1];
904 
905  ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, rv3d);
906 
908 }
909 
910 static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event)
911 {
912  ViewOpsData *vod = op->customdata;
913  short event_code = VIEW_PASS;
914  bool use_autokey = false;
916 
917  /* execute the events */
918  if (event->type == MOUSEMOVE) {
919  event_code = VIEW_APPLY;
920  }
921  else if (event->type == EVT_MODAL_MAP) {
922  switch (event->val) {
923  case VIEW_MODAL_CONFIRM:
924  event_code = VIEW_CONFIRM;
925  break;
927  vod->axis_snap = true;
928  event_code = VIEW_APPLY;
929  break;
931  vod->rv3d->persp = vod->init.persp;
932  vod->axis_snap = false;
933  event_code = VIEW_APPLY;
934  break;
936  WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL);
937  event_code = VIEW_CONFIRM;
938  break;
940  WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL);
941  event_code = VIEW_CONFIRM;
942  break;
943  }
944  }
945  else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
946  event_code = VIEW_CONFIRM;
947  }
948 
949  if (event_code == VIEW_APPLY) {
950  viewrotate_apply(vod, &event->x);
952  use_autokey = true;
953  }
954  }
955  else if (event_code == VIEW_CONFIRM) {
957  use_autokey = true;
959  }
960 
961  if (use_autokey) {
962  ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, true);
963  }
964 
965  if (ret & OPERATOR_FINISHED) {
966  viewops_data_free(C, op);
967  }
968 
969  return ret;
970 }
971 
972 static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
973 {
974  ViewOpsData *vod;
975 
976  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
977 
978  /* makes op->customdata */
979  viewops_data_alloc(C, op);
980  vod = op->customdata;
981 
982  /* poll should check but in some cases fails, see poll func for details */
984  viewops_data_free(C, op);
985  return OPERATOR_PASS_THROUGH;
986  }
987 
989 
991  op,
992  event,
994  (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
995 
996  if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) {
997  /* Rotate direction we keep always same */
998  int event_xy[2];
999 
1000  if (event->type == MOUSEPAN) {
1001  if (event->is_direction_inverted) {
1002  event_xy[0] = 2 * event->x - event->prevx;
1003  event_xy[1] = 2 * event->y - event->prevy;
1004  }
1005  else {
1006  event_xy[0] = event->prevx;
1007  event_xy[1] = event->prevy;
1008  }
1009  }
1010  else {
1011  /* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */
1012  event_xy[0] = event->prevx;
1013  event_xy[1] = event->y;
1014  }
1015 
1016  viewrotate_apply(vod, event_xy);
1018 
1019  viewops_data_free(C, op);
1020 
1021  return OPERATOR_FINISHED;
1022  }
1023 
1024  /* add temp handler */
1026 
1027  return OPERATOR_RUNNING_MODAL;
1028 }
1029 
1031 {
1032  viewops_data_free(C, op);
1033 }
1034 
1036 {
1037  /* identifiers */
1038  ot->name = "Rotate View";
1039  ot->description = "Rotate the view";
1040  ot->idname = "VIEW3D_OT_rotate";
1041 
1042  /* api callbacks */
1047 
1048  /* flags */
1050 
1052 }
1053 
1056 /* -------------------------------------------------------------------- */
1060 #ifdef WITH_INPUT_NDOF
1061 static bool ndof_has_translate(const wmNDOFMotionData *ndof,
1062  const View3D *v3d,
1063  const RegionView3D *rv3d)
1064 {
1065  return !is_zero_v3(ndof->tvec) && (!ED_view3d_offset_lock_check(v3d, rv3d));
1066 }
1067 
1068 static bool ndof_has_rotate(const wmNDOFMotionData *ndof, const RegionView3D *rv3d)
1069 {
1070  return !is_zero_v3(ndof->rvec) && ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0);
1071 }
1072 
1076 static float view3d_ndof_pan_speed_calc_ex(RegionView3D *rv3d, const float depth_pt[3])
1077 {
1078  float speed = rv3d->pixsize * NDOF_PIXELS_PER_SECOND;
1079 
1080  if (rv3d->is_persp) {
1081  speed *= ED_view3d_calc_zfac(rv3d, depth_pt, NULL);
1082  }
1083 
1084  return speed;
1085 }
1086 
1087 static float view3d_ndof_pan_speed_calc_from_dist(RegionView3D *rv3d, const float dist)
1088 {
1089  float viewinv[4];
1090  float tvec[3];
1091 
1092  BLI_assert(dist >= 0.0f);
1093 
1094  copy_v3_fl3(tvec, 0.0f, 0.0f, dist);
1095  /* rv3d->viewinv isn't always valid */
1096 # if 0
1097  mul_mat3_m4_v3(rv3d->viewinv, tvec);
1098 # else
1099  invert_qt_qt_normalized(viewinv, rv3d->viewquat);
1100  mul_qt_v3(viewinv, tvec);
1101 # endif
1102 
1103  return view3d_ndof_pan_speed_calc_ex(rv3d, tvec);
1104 }
1105 
1106 static float view3d_ndof_pan_speed_calc(RegionView3D *rv3d)
1107 {
1108  float tvec[3];
1109  negate_v3_v3(tvec, rv3d->ofs);
1110 
1111  return view3d_ndof_pan_speed_calc_ex(rv3d, tvec);
1112 }
1113 
1120 static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof,
1121  ScrArea *area,
1122  ARegion *region,
1123  const bool has_translate,
1124  const bool has_zoom)
1125 {
1126  RegionView3D *rv3d = region->regiondata;
1127  float view_inv[4];
1128  float pan_vec[3];
1129 
1130  if (has_translate == false && has_zoom == false) {
1131  return;
1132  }
1133 
1134  WM_event_ndof_pan_get(ndof, pan_vec, false);
1135 
1136  if (has_zoom) {
1137  /* zoom with Z */
1138 
1139  /* Zoom!
1140  * velocity should be proportional to the linear velocity attained by rotational motion
1141  * of same strength [got that?] proportional to `arclength = radius * angle`.
1142  */
1143 
1144  pan_vec[2] = 0.0f;
1145 
1146  /* "zoom in" or "translate"? depends on zoom mode in user settings? */
1147  if (ndof->tvec[2]) {
1148  float zoom_distance = rv3d->dist * ndof->dt * ndof->tvec[2];
1149 
1150  if (U.ndof_flag & NDOF_ZOOM_INVERT) {
1151  zoom_distance = -zoom_distance;
1152  }
1153 
1154  rv3d->dist += zoom_distance;
1155  }
1156  }
1157  else {
1158  /* dolly with Z */
1159 
1160  /* all callers must check */
1161  if (has_translate) {
1162  BLI_assert(ED_view3d_offset_lock_check((View3D *)area->spacedata.first, rv3d) == false);
1163  }
1164  }
1165 
1166  if (has_translate) {
1167  const float speed = view3d_ndof_pan_speed_calc(rv3d);
1168 
1169  mul_v3_fl(pan_vec, speed * ndof->dt);
1170 
1171  /* transform motion from view to world coordinates */
1172  invert_qt_qt_normalized(view_inv, rv3d->viewquat);
1173  mul_qt_v3(view_inv, pan_vec);
1174 
1175  /* move center of view opposite of hand motion (this is camera mode, not object mode) */
1176  sub_v3_v3(rv3d->ofs, pan_vec);
1177 
1178  if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
1179  view3d_boxview_sync(area, region);
1180  }
1181  }
1182 }
1183 
1184 static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof,
1185  ScrArea *area,
1186  ARegion *region,
1187  ViewOpsData *vod,
1188  const bool apply_dyn_ofs)
1189 {
1190  View3D *v3d = area->spacedata.first;
1191  RegionView3D *rv3d = region->regiondata;
1192 
1193  float view_inv[4];
1194 
1196 
1197  ED_view3d_persp_ensure(vod->depsgraph, v3d, region);
1198 
1199  rv3d->view = RV3D_VIEW_USER;
1200 
1201  invert_qt_qt_normalized(view_inv, rv3d->viewquat);
1202 
1203  if (U.ndof_flag & NDOF_TURNTABLE) {
1204  float rot[3];
1205 
1206  /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
1207  float angle, quat[4];
1208  float xvec[3] = {1, 0, 0};
1209 
1210  /* only use XY, ignore Z */
1211  WM_event_ndof_rotate_get(ndof, rot);
1212 
1213  /* Determine the direction of the x vector (for rotating up and down) */
1214  mul_qt_v3(view_inv, xvec);
1215 
1216  /* Perform the up/down rotation */
1217  angle = ndof->dt * rot[0];
1218  axis_angle_to_quat(quat, xvec, angle);
1219  mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat);
1220 
1221  /* Perform the orbital rotation */
1222  angle = ndof->dt * rot[1];
1223 
1224  /* update the onscreen doo-dad */
1225  rv3d->rot_angle = angle;
1226  rv3d->rot_axis[0] = 0;
1227  rv3d->rot_axis[1] = 0;
1228  rv3d->rot_axis[2] = 1;
1229 
1230  axis_angle_to_quat_single(quat, 'Z', angle);
1231  mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat);
1232  }
1233  else {
1234  float quat[4];
1235  float axis[3];
1236  float angle = WM_event_ndof_to_axis_angle(ndof, axis);
1237 
1238  /* transform rotation axis from view to world coordinates */
1239  mul_qt_v3(view_inv, axis);
1240 
1241  /* update the onscreen doo-dad */
1242  rv3d->rot_angle = angle;
1243  copy_v3_v3(rv3d->rot_axis, axis);
1244 
1245  axis_angle_to_quat(quat, axis, angle);
1246 
1247  /* apply rotation */
1248  mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat);
1249  }
1250 
1251  if (apply_dyn_ofs) {
1252  viewrotate_apply_dyn_ofs(vod, rv3d->viewquat);
1253  }
1254 }
1255 
1259 void view3d_ndof_fly(const wmNDOFMotionData *ndof,
1260  View3D *v3d,
1261  RegionView3D *rv3d,
1262  const bool use_precision,
1263  const short protectflag,
1264  bool *r_has_translate,
1265  bool *r_has_rotate)
1266 {
1267  bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
1268  bool has_rotate = ndof_has_rotate(ndof, rv3d);
1269 
1270  float view_inv[4];
1271  invert_qt_qt_normalized(view_inv, rv3d->viewquat);
1272 
1273  rv3d->rot_angle = 0.0f; /* disable onscreen rotation doo-dad */
1274 
1275  if (has_translate) {
1276  /* ignore real 'dist' since fly has its own speed settings,
1277  * also its overwritten at this point. */
1278  float speed = view3d_ndof_pan_speed_calc_from_dist(rv3d, 1.0f);
1279  float trans[3], trans_orig_y;
1280 
1281  if (use_precision) {
1282  speed *= 0.2f;
1283  }
1284 
1285  WM_event_ndof_pan_get(ndof, trans, false);
1286  mul_v3_fl(trans, speed * ndof->dt);
1287  trans_orig_y = trans[1];
1288 
1289  if (U.ndof_flag & NDOF_FLY_HELICOPTER) {
1290  trans[1] = 0.0f;
1291  }
1292 
1293  /* transform motion from view to world coordinates */
1294  mul_qt_v3(view_inv, trans);
1295 
1296  if (U.ndof_flag & NDOF_FLY_HELICOPTER) {
1297  /* replace world z component with device y (yes it makes sense) */
1298  trans[2] = trans_orig_y;
1299  }
1300 
1301  if (rv3d->persp == RV3D_CAMOB) {
1302  /* respect camera position locks */
1303  if (protectflag & OB_LOCK_LOCX) {
1304  trans[0] = 0.0f;
1305  }
1306  if (protectflag & OB_LOCK_LOCY) {
1307  trans[1] = 0.0f;
1308  }
1309  if (protectflag & OB_LOCK_LOCZ) {
1310  trans[2] = 0.0f;
1311  }
1312  }
1313 
1314  if (!is_zero_v3(trans)) {
1315  /* move center of view opposite of hand motion
1316  * (this is camera mode, not object mode) */
1317  sub_v3_v3(rv3d->ofs, trans);
1318  has_translate = true;
1319  }
1320  else {
1321  has_translate = false;
1322  }
1323  }
1324 
1325  if (has_rotate) {
1326  const float turn_sensitivity = 1.0f;
1327 
1328  float rotation[4];
1329  float axis[3];
1330  float angle = turn_sensitivity * WM_event_ndof_to_axis_angle(ndof, axis);
1331 
1332  if (fabsf(angle) > 0.0001f) {
1333  has_rotate = true;
1334 
1335  if (use_precision) {
1336  angle *= 0.2f;
1337  }
1338 
1339  /* transform rotation axis from view to world coordinates */
1340  mul_qt_v3(view_inv, axis);
1341 
1342  /* apply rotation to view */
1343  axis_angle_to_quat(rotation, axis, angle);
1344  mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation);
1345 
1346  if (U.ndof_flag & NDOF_LOCK_HORIZON) {
1347  /* force an upright viewpoint
1348  * TODO: make this less... sudden */
1349  float view_horizon[3] = {1.0f, 0.0f, 0.0f}; /* view +x */
1350  float view_direction[3] = {0.0f, 0.0f, -1.0f}; /* view -z (into screen) */
1351 
1352  /* find new inverse since viewquat has changed */
1353  invert_qt_qt_normalized(view_inv, rv3d->viewquat);
1354  /* could apply reverse rotation to existing view_inv to save a few cycles */
1355 
1356  /* transform view vectors to world coordinates */
1357  mul_qt_v3(view_inv, view_horizon);
1358  mul_qt_v3(view_inv, view_direction);
1359 
1360  /* find difference between view & world horizons
1361  * true horizon lives in world xy plane, so look only at difference in z */
1362  angle = -asinf(view_horizon[2]);
1363 
1364  /* rotate view so view horizon = world horizon */
1365  axis_angle_to_quat(rotation, view_direction, angle);
1366  mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation);
1367  }
1368 
1369  rv3d->view = RV3D_VIEW_USER;
1370  }
1371  else {
1372  has_rotate = false;
1373  }
1374  }
1375 
1376  *r_has_translate = has_translate;
1377  *r_has_rotate = has_rotate;
1378 }
1379 
1382 /* -------------------------------------------------------------------- */
1386 static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1387 {
1388  if (event->type != NDOF_MOTION) {
1389  return OPERATOR_CANCELLED;
1390  }
1391 
1393  ViewOpsData *vod;
1394  View3D *v3d;
1395  RegionView3D *rv3d;
1396  char xform_flag = 0;
1397 
1398  const wmNDOFMotionData *ndof = event->customdata;
1399 
1400  viewops_data_alloc(C, op);
1402  C, op, event, viewops_flag_from_args((U.uiflag & USER_ORBIT_SELECTION) != 0, false));
1403  vod = op->customdata;
1404 
1406 
1407  v3d = vod->v3d;
1408  rv3d = vod->rv3d;
1409 
1410  /* off by default, until changed later this function */
1411  rv3d->rot_angle = 0.0f;
1412 
1413  ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false);
1414 
1415  if (ndof->progress != P_FINISHING) {
1416  const bool has_rotation = ndof_has_rotate(ndof, rv3d);
1417  /* if we can't rotate, fallback to translate (locked axis views) */
1418  const bool has_translate = ndof_has_translate(ndof, v3d, rv3d) &&
1420  const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp;
1421 
1422  if (has_translate || has_zoom) {
1423  view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom);
1424  xform_flag |= HAS_TRANSLATE;
1425  }
1426 
1427  if (has_rotation) {
1428  view3d_ndof_orbit(ndof, vod->area, vod->region, vod, true);
1429  xform_flag |= HAS_ROTATE;
1430  }
1431  }
1432 
1434  if (xform_flag) {
1436  v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
1437  }
1438 
1440 
1441  viewops_data_free(C, op);
1442 
1443  return OPERATOR_FINISHED;
1444 }
1445 
1446 void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot)
1447 {
1448  /* identifiers */
1449  ot->name = "NDOF Orbit View";
1450  ot->description = "Orbit the view using the 3D mouse";
1451  ot->idname = "VIEW3D_OT_ndof_orbit";
1452 
1453  /* api callbacks */
1454  ot->invoke = ndof_orbit_invoke;
1456 
1457  /* flags */
1458  ot->flag = 0;
1459 }
1460 
1463 /* -------------------------------------------------------------------- */
1467 static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1468 {
1469  if (event->type != NDOF_MOTION) {
1470  return OPERATOR_CANCELLED;
1471  }
1472 
1474  ViewOpsData *vod;
1475  View3D *v3d;
1476  RegionView3D *rv3d;
1477  char xform_flag = 0;
1478 
1479  const wmNDOFMotionData *ndof = event->customdata;
1480 
1481  viewops_data_alloc(C, op);
1483  C, op, event, viewops_flag_from_args((U.uiflag & USER_ORBIT_SELECTION) != 0, false));
1484 
1485  vod = op->customdata;
1486 
1488 
1489  v3d = vod->v3d;
1490  rv3d = vod->rv3d;
1491 
1492  /* off by default, until changed later this function */
1493  rv3d->rot_angle = 0.0f;
1494 
1495  ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false);
1496 
1497  if (ndof->progress == P_FINISHING) {
1498  /* pass */
1499  }
1500  else if ((rv3d->persp == RV3D_ORTHO) && RV3D_VIEW_IS_AXIS(rv3d->view)) {
1501  /* if we can't rotate, fallback to translate (locked axis views) */
1502  const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
1503  const bool has_zoom = (ndof->tvec[2] != 0.0f) && ED_view3d_offset_lock_check(v3d, rv3d);
1504 
1505  if (has_translate || has_zoom) {
1506  view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, true);
1507  xform_flag |= HAS_TRANSLATE;
1508  }
1509  }
1510  else {
1511  /* Note: based on feedback from T67579, users want to have pan and orbit enabled at once.
1512  * It's arguable that orbit shouldn't pan (since we have a pan only operator),
1513  * so if there are users who like to separate orbit/pan operations - it can be a preference. */
1514  const bool is_orbit_around_pivot = (U.ndof_flag & NDOF_MODE_ORBIT) ||
1515  ED_view3d_offset_lock_check(v3d, rv3d);
1516  const bool has_rotation = ndof_has_rotate(ndof, rv3d);
1517  bool has_translate, has_zoom;
1518 
1519  if (is_orbit_around_pivot) {
1520  /* Orbit preference or forced lock (Z zooms). */
1521  has_translate = !is_zero_v2(ndof->tvec) && ndof_has_translate(ndof, v3d, rv3d);
1522  has_zoom = (ndof->tvec[2] != 0.0f);
1523  }
1524  else {
1525  /* Free preference (Z translates). */
1526  has_translate = ndof_has_translate(ndof, v3d, rv3d);
1527  has_zoom = false;
1528  }
1529 
1530  /* Rotation first because dynamic offset resets offset otherwise (and disables panning). */
1531  if (has_rotation) {
1532  const float dist_backup = rv3d->dist;
1533  if (!is_orbit_around_pivot) {
1534  ED_view3d_distance_set(rv3d, 0.0f);
1535  }
1536  view3d_ndof_orbit(ndof, vod->area, vod->region, vod, is_orbit_around_pivot);
1537  xform_flag |= HAS_ROTATE;
1538  if (!is_orbit_around_pivot) {
1539  ED_view3d_distance_set(rv3d, dist_backup);
1540  }
1541  }
1542 
1543  if (has_translate || has_zoom) {
1544  view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom);
1545  xform_flag |= HAS_TRANSLATE;
1546  }
1547  }
1548 
1550  if (xform_flag) {
1552  v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
1553  }
1554 
1556 
1557  viewops_data_free(C, op);
1558 
1559  return OPERATOR_FINISHED;
1560 }
1561 
1562 void VIEW3D_OT_ndof_orbit_zoom(struct wmOperatorType *ot)
1563 {
1564  /* identifiers */
1565  ot->name = "NDOF Orbit View with Zoom";
1566  ot->description = "Orbit and zoom the view using the 3D mouse";
1567  ot->idname = "VIEW3D_OT_ndof_orbit_zoom";
1568 
1569  /* api callbacks */
1570  ot->invoke = ndof_orbit_zoom_invoke;
1572 
1573  /* flags */
1574  ot->flag = 0;
1575 }
1576 
1579 /* -------------------------------------------------------------------- */
1583 static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
1584 {
1585  if (event->type != NDOF_MOTION) {
1586  return OPERATOR_CANCELLED;
1587  }
1588 
1590  View3D *v3d = CTX_wm_view3d(C);
1592  const wmNDOFMotionData *ndof = event->customdata;
1593  char xform_flag = 0;
1594 
1595  const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
1596  const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp;
1597 
1598  /* we're panning here! so erase any leftover rotation from other operators */
1599  rv3d->rot_angle = 0.0f;
1600 
1601  if (!(has_translate || has_zoom)) {
1602  return OPERATOR_CANCELLED;
1603  }
1604 
1605  ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false);
1606 
1607  if (ndof->progress != P_FINISHING) {
1608  ScrArea *area = CTX_wm_area(C);
1609  ARegion *region = CTX_wm_region(C);
1610 
1611  if (has_translate || has_zoom) {
1612  view3d_ndof_pan_zoom(ndof, area, region, has_translate, has_zoom);
1613  xform_flag |= HAS_TRANSLATE;
1614  }
1615  }
1616 
1618  if (xform_flag) {
1619  ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, xform_flag & HAS_TRANSLATE);
1620  }
1621 
1623 
1624  return OPERATOR_FINISHED;
1625 }
1626 
1627 void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot)
1628 {
1629  /* identifiers */
1630  ot->name = "NDOF Pan View";
1631  ot->description = "Pan the view with the 3D mouse";
1632  ot->idname = "VIEW3D_OT_ndof_pan";
1633 
1634  /* api callbacks */
1635  ot->invoke = ndof_pan_invoke;
1637 
1638  /* flags */
1639  ot->flag = 0;
1640 }
1641 
1644 /* -------------------------------------------------------------------- */
1651 static int ndof_all_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1652 {
1653  /* weak!, but it works */
1654  const int ndof_flag = U.ndof_flag;
1655  int ret;
1656 
1657  U.ndof_flag &= ~NDOF_MODE_ORBIT;
1658 
1659  ret = ndof_orbit_zoom_invoke(C, op, event);
1660 
1661  U.ndof_flag = ndof_flag;
1662 
1663  return ret;
1664 }
1665 
1666 void VIEW3D_OT_ndof_all(struct wmOperatorType *ot)
1667 {
1668  /* identifiers */
1669  ot->name = "NDOF Transform View";
1670  ot->description = "Pan and rotate the view with the 3D mouse";
1671  ot->idname = "VIEW3D_OT_ndof_all";
1672 
1673  /* api callbacks */
1674  ot->invoke = ndof_all_invoke;
1676 
1677  /* flags */
1678  ot->flag = 0;
1679 }
1680 
1681 #endif /* WITH_INPUT_NDOF */
1682 
1685 /* -------------------------------------------------------------------- */
1689 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
1690 
1691 /* called in transform_ops.c, on each regeneration of keymaps */
1693 {
1694  static const EnumPropertyItem modal_items[] = {
1695  {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
1696 
1697  {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"},
1698  {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"},
1699 
1700  {0, NULL, 0, NULL, NULL},
1701  };
1702 
1703  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Move Modal");
1704 
1705  /* this function is called for each spacetype, only needs to add map once */
1706  if (keymap && keymap->modal_items) {
1707  return;
1708  }
1709 
1710  keymap = WM_modalkeymap_ensure(keyconf, "View3D Move Modal", modal_items);
1711 
1712  /* items for modal map */
1715 
1716  /* disabled mode switching for now, can re-implement better, later on */
1717 #if 0
1721  keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE);
1722 #endif
1723 
1724  /* assign map to operators */
1725  WM_modalkeymap_assign(keymap, "VIEW3D_OT_move");
1726 }
1727 
1728 static void viewmove_apply(ViewOpsData *vod, int x, int y)
1729 {
1730  if (ED_view3d_offset_lock_check(vod->v3d, vod->rv3d)) {
1731  vod->rv3d->ofs_lock[0] -= ((vod->prev.event_xy[0] - x) * 2.0f) / (float)vod->region->winx;
1732  vod->rv3d->ofs_lock[1] -= ((vod->prev.event_xy[1] - y) * 2.0f) / (float)vod->region->winy;
1733  }
1734  else if ((vod->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) {
1735  const float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f;
1736  vod->rv3d->camdx += (vod->prev.event_xy[0] - x) / (vod->region->winx * zoomfac);
1737  vod->rv3d->camdy += (vod->prev.event_xy[1] - y) / (vod->region->winy * zoomfac);
1738  CLAMP(vod->rv3d->camdx, -1.0f, 1.0f);
1739  CLAMP(vod->rv3d->camdy, -1.0f, 1.0f);
1740  }
1741  else {
1742  float dvec[3];
1743  float mval_f[2];
1744 
1745  mval_f[0] = x - vod->prev.event_xy[0];
1746  mval_f[1] = y - vod->prev.event_xy[1];
1747  ED_view3d_win_to_delta(vod->region, mval_f, dvec, vod->init.zfac);
1748 
1749  add_v3_v3(vod->rv3d->ofs, dvec);
1750 
1751  if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
1752  view3d_boxview_sync(vod->area, vod->region);
1753  }
1754  }
1755 
1756  vod->prev.event_xy[0] = x;
1757  vod->prev.event_xy[1] = y;
1758 
1759  ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
1760 
1762 }
1763 
1764 static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
1765 {
1766 
1767  ViewOpsData *vod = op->customdata;
1768  short event_code = VIEW_PASS;
1769  bool use_autokey = false;
1771 
1772  /* execute the events */
1773  if (event->type == MOUSEMOVE) {
1774  event_code = VIEW_APPLY;
1775  }
1776  else if (event->type == EVT_MODAL_MAP) {
1777  switch (event->val) {
1778  case VIEW_MODAL_CONFIRM:
1779  event_code = VIEW_CONFIRM;
1780  break;
1782  WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL);
1783  event_code = VIEW_CONFIRM;
1784  break;
1786  WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL);
1787  event_code = VIEW_CONFIRM;
1788  break;
1789  }
1790  }
1791  else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
1792  event_code = VIEW_CONFIRM;
1793  }
1794 
1795  if (event_code == VIEW_APPLY) {
1796  viewmove_apply(vod, event->x, event->y);
1798  use_autokey = true;
1799  }
1800  }
1801  else if (event_code == VIEW_CONFIRM) {
1803  use_autokey = true;
1805  }
1806 
1807  if (use_autokey) {
1808  ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
1809  }
1810 
1811  if (ret & OPERATOR_FINISHED) {
1812  viewops_data_free(C, op);
1813  }
1814 
1815  return ret;
1816 }
1817 
1818 static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1819 {
1820  ViewOpsData *vod;
1821 
1822  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
1823 
1824  /* makes op->customdata */
1825  viewops_data_alloc(C, op);
1826  vod = op->customdata;
1827  if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_LOCATION) {
1828  viewops_data_free(C, op);
1829  return OPERATOR_PASS_THROUGH;
1830  }
1831 
1833  op,
1834  event,
1836  (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
1837 
1839 
1840  if (event->type == MOUSEPAN) {
1841  /* invert it, trackpad scroll follows same principle as 2d windows this way */
1842  viewmove_apply(vod, 2 * event->x - event->prevx, 2 * event->y - event->prevy);
1844 
1845  viewops_data_free(C, op);
1846 
1847  return OPERATOR_FINISHED;
1848  }
1849 
1850  /* add temp handler */
1852 
1853  return OPERATOR_RUNNING_MODAL;
1854 }
1855 
1857 {
1858  viewops_data_free(C, op);
1859 }
1860 
1862 {
1863 
1864  /* identifiers */
1865  ot->name = "Pan View";
1866  ot->description = "Move the view";
1867  ot->idname = "VIEW3D_OT_move";
1868 
1869  /* api callbacks */
1871  ot->modal = viewmove_modal;
1874 
1875  /* flags */
1877 
1878  /* properties */
1880 }
1881 
1884 /* -------------------------------------------------------------------- */
1888 /* viewdolly_modal_keymap has an exact copy of this, apply fixes to both */
1889 /* called in transform_ops.c, on each regeneration of keymaps */
1891 {
1892  static const EnumPropertyItem modal_items[] = {
1893  {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
1894 
1895  {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"},
1896  {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"},
1897 
1898  {0, NULL, 0, NULL, NULL},
1899  };
1900 
1901  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Zoom Modal");
1902 
1903  /* this function is called for each spacetype, only needs to add map once */
1904  if (keymap && keymap->modal_items) {
1905  return;
1906  }
1907 
1908  keymap = WM_modalkeymap_ensure(keyconf, "View3D Zoom Modal", modal_items);
1909 
1910  /* disabled mode switching for now, can re-implement better, later on */
1911 #if 0
1915 #endif
1916 
1917  /* assign map to operators */
1918  WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom");
1919 }
1920 
1927  View3D *v3d,
1928  ARegion *region,
1929  float dfac,
1930  const int zoom_xy[2])
1931 {
1932  RegionView3D *rv3d = region->regiondata;
1933  const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
1934  const float zoomfac_new = clamp_f(
1935  zoomfac * (1.0f / dfac), RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR);
1936  const float camzoom_new = BKE_screen_view3d_zoom_from_fac(zoomfac_new);
1937 
1938  if (zoom_xy != NULL) {
1939  float zoomfac_px;
1940  rctf camera_frame_old;
1941  rctf camera_frame_new;
1942 
1943  const float pt_src[2] = {zoom_xy[0], zoom_xy[1]};
1944  float pt_dst[2];
1945  float delta_px[2];
1946 
1947  ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &camera_frame_old, false);
1948  BLI_rctf_translate(&camera_frame_old, region->winrct.xmin, region->winrct.ymin);
1949 
1950  rv3d->camzoom = camzoom_new;
1952 
1953  ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &camera_frame_new, false);
1954  BLI_rctf_translate(&camera_frame_new, region->winrct.xmin, region->winrct.ymin);
1955 
1956  BLI_rctf_transform_pt_v(&camera_frame_new, &camera_frame_old, pt_dst, pt_src);
1957  sub_v2_v2v2(delta_px, pt_dst, pt_src);
1958 
1959  /* translate the camera offset using pixel space delta
1960  * mapped back to the camera (same logic as panning in camera view) */
1961  zoomfac_px = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 2.0f;
1962 
1963  rv3d->camdx += delta_px[0] / (region->winx * zoomfac_px);
1964  rv3d->camdy += delta_px[1] / (region->winy * zoomfac_px);
1965  CLAMP(rv3d->camdx, -1.0f, 1.0f);
1966  CLAMP(rv3d->camdy, -1.0f, 1.0f);
1967  }
1968  else {
1969  rv3d->camzoom = camzoom_new;
1971  }
1972 }
1973 
1978 static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoom_xy[2])
1979 {
1980  RegionView3D *rv3d = region->regiondata;
1981  const float dist_new = rv3d->dist * dfac;
1982 
1983  if (zoom_xy != NULL) {
1984  float dvec[3];
1985  float tvec[3];
1986  float tpos[3];
1987  float mval_f[2];
1988 
1989  float zfac;
1990 
1991  negate_v3_v3(tpos, rv3d->ofs);
1992 
1993  mval_f[0] = (float)(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f;
1994  mval_f[1] = (float)(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f;
1995 
1996  /* Project cursor position into 3D space */
1997  zfac = ED_view3d_calc_zfac(rv3d, tpos, NULL);
1998  ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
1999 
2000  /* Calculate view target position for dolly */
2001  add_v3_v3v3(tvec, tpos, dvec);
2002  negate_v3(tvec);
2003 
2004  /* Offset to target position and dolly */
2005  copy_v3_v3(rv3d->ofs, tvec);
2006  rv3d->dist = dist_new;
2007 
2008  /* Calculate final offset */
2009  madd_v3_v3v3fl(rv3d->ofs, tvec, dvec, dfac);
2010  }
2011  else {
2012  rv3d->dist = dist_new;
2013  }
2014 }
2015 
2016 static float viewzoom_scale_value(const rcti *winrct,
2017  const eViewZoom_Style viewzoom,
2018  const bool zoom_invert,
2019  const bool zoom_invert_force,
2020  const int xy_curr[2],
2021  const int xy_init[2],
2022  const float val,
2023  const float val_orig,
2024  double *r_timer_lastdraw)
2025 {
2026  float zfac;
2027 
2028  if (viewzoom == USER_ZOOM_CONTINUE) {
2029  double time = PIL_check_seconds_timer();
2030  float time_step = (float)(time - *r_timer_lastdraw);
2031  float fac;
2032 
2033  if (U.uiflag & USER_ZOOM_HORIZ) {
2034  fac = (float)(xy_init[0] - xy_curr[0]);
2035  }
2036  else {
2037  fac = (float)(xy_init[1] - xy_curr[1]);
2038  }
2039 
2040  fac /= U.dpi_fac;
2041 
2042  if (zoom_invert != zoom_invert_force) {
2043  fac = -fac;
2044  }
2045 
2046  zfac = 1.0f + ((fac / 20.0f) * time_step);
2047  *r_timer_lastdraw = time;
2048  }
2049  else if (viewzoom == USER_ZOOM_SCALE) {
2050  /* method which zooms based on how far you move the mouse */
2051 
2052  const int ctr[2] = {
2053  BLI_rcti_cent_x(winrct),
2054  BLI_rcti_cent_y(winrct),
2055  };
2056  float len_new = (5 * U.dpi_fac) + ((float)len_v2v2_int(ctr, xy_curr) / U.dpi_fac);
2057  float len_old = (5 * U.dpi_fac) + ((float)len_v2v2_int(ctr, xy_init) / U.dpi_fac);
2058 
2059  /* intentionally ignore 'zoom_invert' for scale */
2060  if (zoom_invert_force) {
2061  SWAP(float, len_new, len_old);
2062  }
2063 
2064  zfac = val_orig * (len_old / max_ff(len_new, 1.0f)) / val;
2065  }
2066  else { /* USER_ZOOM_DOLLY */
2067  float len_new = 5 * U.dpi_fac;
2068  float len_old = 5 * U.dpi_fac;
2069 
2070  if (U.uiflag & USER_ZOOM_HORIZ) {
2071  len_new += (winrct->xmax - (xy_curr[0])) / U.dpi_fac;
2072  len_old += (winrct->xmax - (xy_init[0])) / U.dpi_fac;
2073  }
2074  else {
2075  len_new += (winrct->ymax - (xy_curr[1])) / U.dpi_fac;
2076  len_old += (winrct->ymax - (xy_init[1])) / U.dpi_fac;
2077  }
2078 
2079  if (zoom_invert != zoom_invert_force) {
2080  SWAP(float, len_new, len_old);
2081  }
2082 
2083  zfac = val_orig * (2.0f * ((len_new / max_ff(len_old, 1.0f)) - 1.0f) + 1.0f) / val;
2084  }
2085 
2086  return zfac;
2087 }
2088 
2089 static float viewzoom_scale_value_offset(const rcti *winrct,
2090  const eViewZoom_Style viewzoom,
2091  const bool zoom_invert,
2092  const bool zoom_invert_force,
2093  const int xy_curr[2],
2094  const int xy_init[2],
2095  const int xy_offset[2],
2096  const float val,
2097  const float val_orig,
2098  double *r_timer_lastdraw)
2099 {
2100  const int xy_curr_offset[2] = {
2101  xy_curr[0] + xy_offset[0],
2102  xy_curr[1] + xy_offset[1],
2103  };
2104  const int xy_init_offset[2] = {
2105  xy_init[0] + xy_offset[0],
2106  xy_init[1] + xy_offset[1],
2107  };
2108  return viewzoom_scale_value(winrct,
2109  viewzoom,
2110  zoom_invert,
2111  zoom_invert_force,
2112  xy_curr_offset,
2113  xy_init_offset,
2114  val,
2115  val_orig,
2116  r_timer_lastdraw);
2117 }
2118 
2120  const int xy[2],
2121  const eViewZoom_Style viewzoom,
2122  const bool zoom_invert,
2123  const bool zoom_to_pos)
2124 {
2125  float zfac;
2126  float zoomfac_prev = BKE_screen_view3d_zoom_to_fac(vod->init.camzoom) * 2.0f;
2127  float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f;
2128 
2130  viewzoom,
2131  zoom_invert,
2132  true,
2133  xy,
2134  vod->init.event_xy,
2135  vod->init.event_xy_offset,
2136  zoomfac,
2137  zoomfac_prev,
2138  &vod->prev.time);
2139 
2140  if (!ELEM(zfac, 1.0f, 0.0f)) {
2141  /* calculate inverted, then invert again (needed because of camera zoom scaling) */
2142  zfac = 1.0f / zfac;
2144  vod->depsgraph,
2145  vod->v3d,
2146  vod->region,
2147  zfac,
2148  zoom_to_pos ? vod->prev.event_xy : NULL);
2149  }
2150 
2152 }
2153 
2155  const int xy[2],
2156  const eViewZoom_Style viewzoom,
2157  const bool zoom_invert,
2158  const bool zoom_to_pos)
2159 {
2160  float zfac;
2161  float dist_range[2];
2162 
2163  ED_view3d_dist_range_get(vod->v3d, dist_range);
2164 
2166  viewzoom,
2167  zoom_invert,
2168  false,
2169  xy,
2170  vod->init.event_xy,
2171  vod->init.event_xy_offset,
2172  vod->rv3d->dist,
2173  vod->init.dist,
2174  &vod->prev.time);
2175 
2176  if (zfac != 1.0f) {
2177  const float zfac_min = dist_range[0] / vod->rv3d->dist;
2178  const float zfac_max = dist_range[1] / vod->rv3d->dist;
2179  CLAMP(zfac, zfac_min, zfac_max);
2180 
2181  view_zoom_to_window_xy_3d(vod->region, zfac, zoom_to_pos ? vod->prev.event_xy : NULL);
2182  }
2183 
2184  /* these limits were in old code too */
2185  CLAMP(vod->rv3d->dist, dist_range[0], dist_range[1]);
2186 
2187  if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
2188  view3d_boxview_sync(vod->area, vod->region);
2189  }
2190 
2191  ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
2192 
2194 }
2195 
2196 static void viewzoom_apply(ViewOpsData *vod,
2197  const int xy[2],
2198  const eViewZoom_Style viewzoom,
2199  const bool zoom_invert,
2200  const bool zoom_to_pos)
2201 {
2202  if ((vod->rv3d->persp == RV3D_CAMOB) &&
2203  (vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) == 0) {
2204  viewzoom_apply_camera(vod, xy, viewzoom, zoom_invert, zoom_to_pos);
2205  }
2206  else {
2207  viewzoom_apply_3d(vod, xy, viewzoom, zoom_invert, zoom_to_pos);
2208  }
2209 }
2210 
2211 static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
2212 {
2213  ViewOpsData *vod = op->customdata;
2214  short event_code = VIEW_PASS;
2215  bool use_autokey = false;
2217 
2218  /* execute the events */
2219  if (event->type == TIMER && event->customdata == vod->timer) {
2220  /* continuous zoom */
2221  event_code = VIEW_APPLY;
2222  }
2223  else if (event->type == MOUSEMOVE) {
2224  event_code = VIEW_APPLY;
2225  }
2226  else if (event->type == EVT_MODAL_MAP) {
2227  switch (event->val) {
2228  case VIEW_MODAL_CONFIRM:
2229  event_code = VIEW_CONFIRM;
2230  break;
2232  WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL);
2233  event_code = VIEW_CONFIRM;
2234  break;
2236  WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL);
2237  event_code = VIEW_CONFIRM;
2238  break;
2239  }
2240  }
2241  else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
2242  event_code = VIEW_CONFIRM;
2243  }
2244 
2245  if (event_code == VIEW_APPLY) {
2246  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
2247  viewzoom_apply(vod,
2248  &event->x,
2249  (eViewZoom_Style)U.viewzoom,
2250  (U.uiflag & USER_ZOOM_INVERT) != 0,
2251  (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)));
2253  use_autokey = true;
2254  }
2255  }
2256  else if (event_code == VIEW_CONFIRM) {
2258  use_autokey = true;
2260  }
2261 
2262  if (use_autokey) {
2263  ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
2264  }
2265 
2266  if (ret & OPERATOR_FINISHED) {
2267  viewops_data_free(C, op);
2268  }
2269 
2270  return ret;
2271 }
2272 
2274 {
2277  View3D *v3d;
2278  RegionView3D *rv3d;
2279  ScrArea *area;
2280  ARegion *region;
2281  bool use_cam_zoom;
2282  float dist_range[2];
2283 
2284  const int delta = RNA_int_get(op->ptr, "delta");
2285  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
2286 
2287  if (op->customdata) {
2288  ViewOpsData *vod = op->customdata;
2289 
2290  area = vod->area;
2291  region = vod->region;
2292  }
2293  else {
2294  area = CTX_wm_area(C);
2295  region = CTX_wm_region(C);
2296  }
2297 
2298  v3d = area->spacedata.first;
2299  rv3d = region->regiondata;
2300 
2301  use_cam_zoom = (rv3d->persp == RV3D_CAMOB) &&
2302  !(rv3d->is_persp && ED_view3d_camera_lock_check(v3d, rv3d));
2303 
2304  int zoom_xy_buf[2];
2305  const int *zoom_xy = NULL;
2306  if (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) {
2307  zoom_xy_buf[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") :
2308  region->winx / 2;
2309  zoom_xy_buf[1] = RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") :
2310  region->winy / 2;
2311  zoom_xy = zoom_xy_buf;
2312  }
2313 
2314  ED_view3d_dist_range_get(v3d, dist_range);
2315 
2316  if (delta < 0) {
2317  const float step = 1.2f;
2318  /* this min and max is also in viewmove() */
2319  if (use_cam_zoom) {
2320  view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy);
2321  }
2322  else {
2323  if (rv3d->dist < dist_range[1]) {
2324  view_zoom_to_window_xy_3d(region, step, zoom_xy);
2325  }
2326  }
2327  }
2328  else {
2329  const float step = 1.0f / 1.2f;
2330  if (use_cam_zoom) {
2331  view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy);
2332  }
2333  else {
2334  if (rv3d->dist > dist_range[0]) {
2335  view_zoom_to_window_xy_3d(region, step, zoom_xy);
2336  }
2337  }
2338  }
2339 
2340  if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
2341  view3d_boxview_sync(area, region);
2342  }
2343 
2345 
2347  ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, true);
2348 
2349  ED_region_tag_redraw(region);
2350 
2351  viewops_data_free(C, op);
2352 
2353  return OPERATOR_FINISHED;
2354 }
2355 
2356 /* viewdolly_invoke() copied this function, changes here may apply there */
2357 static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2358 {
2359  ViewOpsData *vod;
2360 
2361  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
2362 
2363  /* makes op->customdata */
2364  viewops_data_alloc(C, op);
2366  op,
2367  event,
2369  (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
2370  vod = op->customdata;
2371 
2373 
2374  /* if one or the other zoom position aren't set, set from event */
2375  if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) {
2376  RNA_int_set(op->ptr, "mx", event->x);
2377  RNA_int_set(op->ptr, "my", event->y);
2378  }
2379 
2380  if (RNA_struct_property_is_set(op->ptr, "delta")) {
2381  viewzoom_exec(C, op);
2382  }
2383  else {
2384  if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) {
2385 
2386  if (U.uiflag & USER_ZOOM_HORIZ) {
2387  vod->init.event_xy[0] = vod->prev.event_xy[0] = event->x;
2388  }
2389  else {
2390  /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */
2391  vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->x -
2392  event->prevx;
2393  }
2394  viewzoom_apply(vod,
2395  &event->prevx,
2397  (U.uiflag & USER_ZOOM_INVERT) != 0,
2398  (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)));
2399  ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
2400 
2402 
2403  viewops_data_free(C, op);
2404  return OPERATOR_FINISHED;
2405  }
2406 
2407  if (U.viewzoom == USER_ZOOM_CONTINUE) {
2408  /* needs a timer to continue redrawing */
2411  }
2412 
2413  /* add temp handler */
2415 
2416  return OPERATOR_RUNNING_MODAL;
2417  }
2418  return OPERATOR_FINISHED;
2419 }
2420 
2422 {
2423  viewops_data_free(C, op);
2424 }
2425 
2427 {
2428  /* identifiers */
2429  ot->name = "Zoom View";
2430  ot->description = "Zoom in/out in the view";
2431  ot->idname = "VIEW3D_OT_zoom";
2432 
2433  /* api callbacks */
2435  ot->exec = viewzoom_exec;
2436  ot->modal = viewzoom_modal;
2439 
2440  /* flags */
2442 
2443  /* properties */
2446 }
2447 
2450 /* -------------------------------------------------------------------- */
2457 /* this is an exact copy of viewzoom_modal_keymap */
2458 /* called in transform_ops.c, on each regeneration of keymaps */
2460 {
2461  static const EnumPropertyItem modal_items[] = {
2462  {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
2463 
2464  {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"},
2465  {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"},
2466 
2467  {0, NULL, 0, NULL, NULL},
2468  };
2469 
2470  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Dolly Modal");
2471 
2472  /* this function is called for each spacetype, only needs to add map once */
2473  if (keymap && keymap->modal_items) {
2474  return;
2475  }
2476 
2477  keymap = WM_modalkeymap_ensure(keyconf, "View3D Dolly Modal", modal_items);
2478 
2479  /* disabled mode switching for now, can re-implement better, later on */
2480 #if 0
2484 #endif
2485 
2486  /* assign map to operators */
2487  WM_modalkeymap_assign(keymap, "VIEW3D_OT_dolly");
2488 }
2489 
2491 {
2492  View3D *v3d = CTX_wm_view3d(C);
2494  if (ED_view3d_offset_lock_check(v3d, rv3d)) {
2495  BKE_report(op->reports, RPT_WARNING, "Cannot dolly when the view offset is locked");
2496  return true;
2497  }
2498  return false;
2499 }
2500 
2501 static void view_dolly_to_vector_3d(ARegion *region,
2502  const float orig_ofs[3],
2503  const float dvec[3],
2504  float dfac)
2505 {
2506  RegionView3D *rv3d = region->regiondata;
2507  madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, -(1.0f - dfac));
2508 }
2509 
2510 static void viewdolly_apply(ViewOpsData *vod, const int xy[2], const short zoom_invert)
2511 {
2512  float zfac = 1.0;
2513 
2514  {
2515  float len1, len2;
2516 
2517  if (U.uiflag & USER_ZOOM_HORIZ) {
2518  len1 = (vod->region->winrct.xmax - xy[0]) + 5;
2519  len2 = (vod->region->winrct.xmax - vod->init.event_xy[0]) + 5;
2520  }
2521  else {
2522  len1 = (vod->region->winrct.ymax - xy[1]) + 5;
2523  len2 = (vod->region->winrct.ymax - vod->init.event_xy[1]) + 5;
2524  }
2525  if (zoom_invert) {
2526  SWAP(float, len1, len2);
2527  }
2528 
2529  zfac = 1.0f + ((len1 - len2) * 0.01f * vod->rv3d->dist);
2530  }
2531 
2532  if (zfac != 1.0f) {
2533  view_dolly_to_vector_3d(vod->region, vod->init.ofs, vod->init.mousevec, zfac);
2534  }
2535 
2536  if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
2537  view3d_boxview_sync(vod->area, vod->region);
2538  }
2539 
2540  ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
2541 
2543 }
2544 
2545 static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
2546 {
2547  ViewOpsData *vod = op->customdata;
2548  short event_code = VIEW_PASS;
2549  bool use_autokey = false;
2551 
2552  /* execute the events */
2553  if (event->type == MOUSEMOVE) {
2554  event_code = VIEW_APPLY;
2555  }
2556  else if (event->type == EVT_MODAL_MAP) {
2557  switch (event->val) {
2558  case VIEW_MODAL_CONFIRM:
2559  event_code = VIEW_CONFIRM;
2560  break;
2562  WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL);
2563  event_code = VIEW_CONFIRM;
2564  break;
2566  WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL);
2567  event_code = VIEW_CONFIRM;
2568  break;
2569  }
2570  }
2571  else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
2572  event_code = VIEW_CONFIRM;
2573  }
2574 
2575  if (event_code == VIEW_APPLY) {
2576  viewdolly_apply(vod, &event->x, (U.uiflag & USER_ZOOM_INVERT) != 0);
2578  use_autokey = true;
2579  }
2580  }
2581  else if (event_code == VIEW_CONFIRM) {
2583  use_autokey = true;
2585  }
2586 
2587  if (use_autokey) {
2588  ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
2589  }
2590 
2591  if (ret & OPERATOR_FINISHED) {
2592  viewops_data_free(C, op);
2593  }
2594 
2595  return ret;
2596 }
2597 
2599 {
2600  View3D *v3d;
2601  RegionView3D *rv3d;
2602  ScrArea *area;
2603  ARegion *region;
2604  float mousevec[3];
2605 
2606  const int delta = RNA_int_get(op->ptr, "delta");
2607 
2608  if (op->customdata) {
2609  ViewOpsData *vod = op->customdata;
2610 
2611  area = vod->area;
2612  region = vod->region;
2613  copy_v3_v3(mousevec, vod->init.mousevec);
2614  }
2615  else {
2616  area = CTX_wm_area(C);
2617  region = CTX_wm_region(C);
2618  negate_v3_v3(mousevec, ((RegionView3D *)region->regiondata)->viewinv[2]);
2619  normalize_v3(mousevec);
2620  }
2621 
2622  v3d = area->spacedata.first;
2623  rv3d = region->regiondata;
2624 
2625  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
2626 
2627  /* overwrite the mouse vector with the view direction (zoom into the center) */
2628  if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) {
2629  normalize_v3_v3(mousevec, rv3d->viewinv[2]);
2630  negate_v3(mousevec);
2631  }
2632 
2633  view_dolly_to_vector_3d(region, rv3d->ofs, mousevec, delta < 0 ? 1.8f : 0.2f);
2634 
2635  if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
2636  view3d_boxview_sync(area, region);
2637  }
2638 
2640 
2642 
2643  ED_region_tag_redraw(region);
2644 
2645  viewops_data_free(C, op);
2646 
2647  return OPERATOR_FINISHED;
2648 }
2649 
2650 /* copied from viewzoom_invoke(), changes here may apply there */
2651 static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2652 {
2653  ViewOpsData *vod;
2654 
2655  if (viewdolly_offset_lock_check(C, op)) {
2656  return OPERATOR_CANCELLED;
2657  }
2658 
2659  /* makes op->customdata */
2660  viewops_data_alloc(C, op);
2661  vod = op->customdata;
2662 
2663  /* poll should check but in some cases fails, see poll func for details */
2664  if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_ROTATION) {
2665  viewops_data_free(C, op);
2666  return OPERATOR_PASS_THROUGH;
2667  }
2668 
2670 
2671  /* needs to run before 'viewops_data_create' so the backup 'rv3d->ofs' is correct */
2672  /* switch from camera view when: */
2673  if (vod->rv3d->persp != RV3D_PERSP) {
2674  if (vod->rv3d->persp == RV3D_CAMOB) {
2675  /* ignore rv3d->lpersp because dolly only makes sense in perspective mode */
2678  }
2679  else {
2680  vod->rv3d->persp = RV3D_PERSP;
2681  }
2683  }
2684 
2685  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
2686 
2688  op,
2689  event,
2691  (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
2692 
2693  /* if one or the other zoom position aren't set, set from event */
2694  if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) {
2695  RNA_int_set(op->ptr, "mx", event->x);
2696  RNA_int_set(op->ptr, "my", event->y);
2697  }
2698 
2699  if (RNA_struct_property_is_set(op->ptr, "delta")) {
2700  viewdolly_exec(C, op);
2701  }
2702  else {
2703  /* overwrite the mouse vector with the view direction (zoom into the center) */
2704  if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) {
2705  negate_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]);
2706  normalize_v3(vod->init.mousevec);
2707  }
2708 
2709  if (event->type == MOUSEZOOM) {
2710  /* Bypass Zoom invert flag for track pads (pass false always) */
2711 
2712  if (U.uiflag & USER_ZOOM_HORIZ) {
2713  vod->init.event_xy[0] = vod->prev.event_xy[0] = event->x;
2714  }
2715  else {
2716  /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */
2717  vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->x -
2718  event->prevx;
2719  }
2720  viewdolly_apply(vod, &event->prevx, (U.uiflag & USER_ZOOM_INVERT) == 0);
2722 
2723  viewops_data_free(C, op);
2724  return OPERATOR_FINISHED;
2725  }
2726 
2727  /* add temp handler */
2729  return OPERATOR_RUNNING_MODAL;
2730  }
2731  return OPERATOR_FINISHED;
2732 }
2733 
2735 {
2736  viewops_data_free(C, op);
2737 }
2738 
2740 {
2741  /* identifiers */
2742  ot->name = "Dolly View";
2743  ot->description = "Dolly in/out in the view";
2744  ot->idname = "VIEW3D_OT_dolly";
2745 
2746  /* api callbacks */
2748  ot->exec = viewdolly_exec;
2752 
2753  /* flags */
2755 
2756  /* properties */
2759 }
2760 
2763 /* -------------------------------------------------------------------- */
2769 static bool view3d_object_skip_minmax(const View3D *v3d,
2770  const RegionView3D *rv3d,
2771  const Object *ob,
2772  const bool skip_camera,
2773  bool *r_only_center)
2774 {
2775  BLI_assert(ob->id.orig_id == NULL);
2776  *r_only_center = false;
2777 
2778  if (skip_camera && (ob == v3d->camera)) {
2779  return true;
2780  }
2781 
2782  if ((ob->type == OB_EMPTY) && (ob->empty_drawtype == OB_EMPTY_IMAGE) &&
2784  *r_only_center = true;
2785  return false;
2786  }
2787 
2788  return false;
2789 }
2790 
2792  Scene *scene,
2793  Object *ob_eval,
2794  const bool only_center,
2795  float min[3],
2796  float max[3])
2797 {
2798  /* Account for duplis. */
2799  if (BKE_object_minmax_dupli(depsgraph, scene, ob_eval, min, max, false) == 0) {
2800  /* Use if duplis aren't found. */
2801  if (only_center) {
2802  minmax_v3v3_v3(min, max, ob_eval->obmat[3]);
2803  }
2804  else {
2805  BKE_object_minmax(ob_eval, min, max, false);
2806  }
2807  }
2808 }
2809 
2811  View3D *v3d,
2812  ARegion *region,
2813  const float min[3],
2814  const float max[3],
2815  bool ok_dist,
2816  const int smooth_viewtx)
2817 {
2818  RegionView3D *rv3d = region->regiondata;
2819  float afm[3];
2820  float size;
2821 
2822  ED_view3d_smooth_view_force_finish(C, v3d, region);
2823 
2824  /* SMOOTHVIEW */
2825  float new_ofs[3];
2826  float new_dist;
2827 
2828  sub_v3_v3v3(afm, max, min);
2829  size = max_fff(afm[0], afm[1], afm[2]);
2830 
2831  if (ok_dist) {
2832  char persp;
2833 
2834  if (rv3d->is_persp) {
2835  if (rv3d->persp == RV3D_CAMOB && ED_view3d_camera_lock_check(v3d, rv3d)) {
2836  persp = RV3D_CAMOB;
2837  }
2838  else {
2839  persp = RV3D_PERSP;
2840  }
2841  }
2842  else { /* ortho */
2843  if (size < 0.0001f) {
2844  /* bounding box was a single point so do not zoom */
2845  ok_dist = false;
2846  }
2847  else {
2848  /* adjust zoom so it looks nicer */
2849  persp = RV3D_ORTHO;
2850  }
2851  }
2852 
2853  if (ok_dist) {
2855  new_dist = ED_view3d_radius_to_dist(
2856  v3d, region, depsgraph, persp, true, (size / 2) * VIEW3D_MARGIN);
2857  if (rv3d->is_persp) {
2858  /* don't zoom closer than the near clipping plane */
2859  new_dist = max_ff(new_dist, v3d->clip_start * 1.5f);
2860  }
2861  }
2862  }
2863 
2864  mid_v3_v3v3(new_ofs, min, max);
2865  negate_v3(new_ofs);
2866 
2867  if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) {
2868  rv3d->persp = RV3D_PERSP;
2870  v3d,
2871  region,
2872  smooth_viewtx,
2873  &(const V3D_SmoothParams){
2874  .camera_old = v3d->camera,
2875  .ofs = new_ofs,
2876  .dist = ok_dist ? &new_dist : NULL,
2877  });
2878  }
2879  else {
2881  v3d,
2882  region,
2883  smooth_viewtx,
2884  &(const V3D_SmoothParams){
2885  .ofs = new_ofs,
2886  .dist = ok_dist ? &new_dist : NULL,
2887  });
2888  }
2889 
2890  /* Smooth-view does view-lock #RV3D_BOXVIEW copy. */
2891 }
2892 
2897  View3D *v3d,
2898  const float min[3],
2899  const float max[3],
2900  const bool ok_dist,
2901  const int smooth_viewtx)
2902 {
2903  ScrArea *area = CTX_wm_area(C);
2904  ARegion *region;
2905  for (region = area->regionbase.first; region; region = region->next) {
2906  if (region->regiontype == RGN_TYPE_WINDOW) {
2907  RegionView3D *rv3d = region->regiondata;
2908  /* when using all regions, don't jump out of camera view,
2909  * but _do_ allow locked cameras to be moved */
2910  if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
2911  view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx);
2912  }
2913  }
2914  }
2915 }
2916 
2918 {
2919  ARegion *region = CTX_wm_region(C);
2920  View3D *v3d = CTX_wm_view3d(C);
2924  ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
2925  Base *base_eval;
2926  const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
2927  const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) ||
2928  /* any one of the regions may be locked */
2929  (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA));
2930  const bool center = RNA_boolean_get(op->ptr, "center");
2931  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
2932 
2933  float min[3], max[3];
2934  bool changed = false;
2935 
2936  if (center) {
2937  /* in 2.4x this also move the cursor to (0, 0, 0) (with shift+c). */
2938  View3DCursor *cursor = &scene->cursor;
2939  zero_v3(min);
2940  zero_v3(max);
2941  zero_v3(cursor->location);
2942  float mat3[3][3];
2943  unit_m3(mat3);
2944  BKE_scene_cursor_mat3_to_rot(cursor, mat3, false);
2945  }
2946  else {
2947  INIT_MINMAX(min, max);
2948  }
2949 
2950  for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) {
2951  if (BASE_VISIBLE(v3d, base_eval)) {
2952  bool only_center = false;
2953  Object *ob = DEG_get_original_object(base_eval->object);
2954  if (view3d_object_skip_minmax(v3d, rv3d, ob, skip_camera, &only_center)) {
2955  continue;
2956  }
2957  view3d_object_calc_minmax(depsgraph, scene, base_eval->object, only_center, min, max);
2958  changed = true;
2959  }
2960  }
2961 
2962  if (center) {
2963  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
2964  WM_msg_publish_rna_prop(mbus, &scene->id, &scene->cursor, View3DCursor, location);
2965 
2967  }
2968 
2969  if (!changed) {
2970  ED_region_tag_redraw(region);
2971  /* TODO - should this be cancel?
2972  * I think no, because we always move the cursor, with or without
2973  * object, but in this case there is no change in the scene,
2974  * only the cursor so I choice a ED_region_tag like
2975  * view3d_smooth_view do for the center_cursor.
2976  * See bug T22640.
2977  */
2978  return OPERATOR_FINISHED;
2979  }
2980 
2981  if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
2982  /* This is an approximation, see function documentation for details. */
2984  }
2985 
2986  if (use_all_regions) {
2987  view3d_from_minmax_multi(C, v3d, min, max, true, smooth_viewtx);
2988  }
2989  else {
2990  view3d_from_minmax(C, v3d, region, min, max, true, smooth_viewtx);
2991  }
2992 
2993  return OPERATOR_FINISHED;
2994 }
2995 
2997 {
2998  /* identifiers */
2999  ot->name = "Frame All";
3000  ot->description = "View all objects in scene";
3001  ot->idname = "VIEW3D_OT_view_all";
3002 
3003  /* api callbacks */
3004  ot->exec = view3d_all_exec;
3006 
3007  /* flags */
3008  ot->flag = 0;
3009 
3010  /* properties */
3012  RNA_def_boolean(ot->srna, "center", 0, "Center", "");
3013 }
3014 
3017 /* -------------------------------------------------------------------- */
3024 {
3025  ARegion *region = CTX_wm_region(C);
3026  View3D *v3d = CTX_wm_view3d(C);
3030  ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
3031  Object *ob_eval = OBACT(view_layer_eval);
3032  Object *obedit = CTX_data_edit_object(C);
3033  const bGPdata *gpd_eval = ob_eval && (ob_eval->type == OB_GPENCIL) ? ob_eval->data : NULL;
3034  const bool is_gp_edit = gpd_eval ? GPENCIL_ANY_MODE(gpd_eval) : false;
3035  const bool is_face_map = ((is_gp_edit == false) && region->gizmo_map &&
3037  float min[3], max[3];
3038  bool ok = false, ok_dist = true;
3039  const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
3040  const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) ||
3041  /* any one of the regions may be locked */
3042  (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA));
3043  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
3044 
3045  INIT_MINMAX(min, max);
3046  if (is_face_map) {
3047  ob_eval = NULL;
3048  }
3049 
3050  if (ob_eval && (ob_eval->mode & OB_MODE_WEIGHT_PAINT)) {
3051  /* hard-coded exception, we look for the one selected armature */
3052  /* this is weak code this way, we should make a generic
3053  * active/selection callback interface once... */
3054  Base *base_eval;
3055  for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) {
3056  if (BASE_SELECTED_EDITABLE(v3d, base_eval)) {
3057  if (base_eval->object->type == OB_ARMATURE) {
3058  if (base_eval->object->mode & OB_MODE_POSE) {
3059  break;
3060  }
3061  }
3062  }
3063  }
3064  if (base_eval) {
3065  ob_eval = base_eval->object;
3066  }
3067  }
3068 
3069  if (is_gp_edit) {
3070  CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
3071  /* we're only interested in selected points here... */
3072  if ((gps->flag & GP_STROKE_SELECT) && (gps->flag & GP_STROKE_3DSPACE)) {
3073  ok |= BKE_gpencil_stroke_minmax(gps, true, min, max);
3074  }
3075  if (gps->editcurve != NULL) {
3076  for (int i = 0; i < gps->editcurve->tot_curve_points; i++) {
3077  BezTriple *bezt = &gps->editcurve->curve_points[i].bezt;
3078  if ((bezt->f1 & SELECT)) {
3079  minmax_v3v3_v3(min, max, bezt->vec[0]);
3080  ok = true;
3081  }
3082  if ((bezt->f2 & SELECT)) {
3083  minmax_v3v3_v3(min, max, bezt->vec[1]);
3084  ok = true;
3085  }
3086  if ((bezt->f3 & SELECT)) {
3087  minmax_v3v3_v3(min, max, bezt->vec[2]);
3088  ok = true;
3089  }
3090  }
3091  }
3092  }
3093  CTX_DATA_END;
3094 
3095  if ((ob_eval) && (ok)) {
3096  mul_m4_v3(ob_eval->obmat, min);
3097  mul_m4_v3(ob_eval->obmat, max);
3098  }
3099  }
3100  else if (is_face_map) {
3101  ok = WM_gizmomap_minmax(region->gizmo_map, true, true, min, max);
3102  }
3103  else if (obedit) {
3104  /* only selected */
3105  FOREACH_OBJECT_IN_MODE_BEGIN (view_layer_eval, v3d, obedit->type, obedit->mode, ob_eval_iter) {
3106  ok |= ED_view3d_minmax_verts(ob_eval_iter, min, max);
3107  }
3109  }
3110  else if (ob_eval && (ob_eval->mode & OB_MODE_POSE)) {
3112  view_layer_eval, v3d, ob_eval->type, ob_eval->mode, ob_eval_iter) {
3113  ok |= BKE_pose_minmax(ob_eval_iter, min, max, true, true);
3114  }
3116  }
3117  else if (BKE_paint_select_face_test(ob_eval)) {
3118  ok = paintface_minmax(ob_eval, min, max);
3119  }
3120  else if (ob_eval && (ob_eval->mode & OB_MODE_PARTICLE_EDIT)) {
3122  }
3123  else if (ob_eval && (ob_eval->mode & (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT |
3126  copy_v3_v3(max, min);
3127  ok = true;
3128  ok_dist = 0; /* don't zoom */
3129  }
3130  else {
3131  Base *base_eval;
3132  for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) {
3133  if (BASE_SELECTED(v3d, base_eval)) {
3134  bool only_center = false;
3135  Object *ob = DEG_get_original_object(base_eval->object);
3136  if (view3d_object_skip_minmax(v3d, rv3d, ob, skip_camera, &only_center)) {
3137  continue;
3138  }
3139  view3d_object_calc_minmax(depsgraph, scene, base_eval->object, only_center, min, max);
3140  ok = 1;
3141  }
3142  }
3143  }
3144 
3145  if (ok == 0) {
3146  return OPERATOR_FINISHED;
3147  }
3148 
3149  if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
3150  /* This is an approximation, see function documentation for details. */
3152  }
3153 
3154  if (use_all_regions) {
3155  view3d_from_minmax_multi(C, v3d, min, max, ok_dist, smooth_viewtx);
3156  }
3157  else {
3158  view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx);
3159  }
3160 
3161  return OPERATOR_FINISHED;
3162 }
3163 
3165 {
3166  /* identifiers */
3167  ot->name = "Frame Selected";
3168  ot->description = "Move the view to the selection center";
3169  ot->idname = "VIEW3D_OT_view_selected";
3170 
3171  /* api callbacks */
3174 
3175  /* flags */
3176  ot->flag = 0;
3177 
3178  /* properties */
3180 }
3181 
3184 /* -------------------------------------------------------------------- */
3189 {
3190  View3D *v3d = CTX_wm_view3d(C);
3191 
3192  if (v3d) {
3193  ED_view3d_lock_clear(v3d);
3194 
3196 
3197  return OPERATOR_FINISHED;
3198  }
3199 
3200  return OPERATOR_CANCELLED;
3201 }
3202 
3204 {
3205 
3206  /* identifiers */
3207  ot->name = "View Lock Clear";
3208  ot->description = "Clear all view locking";
3209  ot->idname = "VIEW3D_OT_view_lock_clear";
3210 
3211  /* api callbacks */
3214 
3215  /* flags */
3216  ot->flag = 0;
3217 }
3218 
3221 /* -------------------------------------------------------------------- */
3226 {
3227  View3D *v3d = CTX_wm_view3d(C);
3228  Object *obact = CTX_data_active_object(C);
3229 
3230  if (v3d) {
3231  ED_view3d_lock_clear(v3d);
3232 
3233  v3d->ob_center = obact; /* can be NULL */
3234 
3235  if (obact && obact->type == OB_ARMATURE) {
3236  if (obact->mode & OB_MODE_POSE) {
3238  Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact);
3239  bPoseChannel *pcham_act = BKE_pose_channel_active(obact_eval);
3240  if (pcham_act) {
3241  BLI_strncpy(v3d->ob_center_bone, pcham_act->name, sizeof(v3d->ob_center_bone));
3242  }
3243  }
3244  else {
3245  EditBone *ebone_act = ((bArmature *)obact->data)->act_edbone;
3246  if (ebone_act) {
3247  BLI_strncpy(v3d->ob_center_bone, ebone_act->name, sizeof(v3d->ob_center_bone));
3248  }
3249  }
3250  }
3251 
3253 
3254  return OPERATOR_FINISHED;
3255  }
3256 
3257  return OPERATOR_CANCELLED;
3258 }
3259 
3261 {
3262 
3263  /* identifiers */
3264  ot->name = "View Lock to Active";
3265  ot->description = "Lock the view to the active object/bone";
3266  ot->idname = "VIEW3D_OT_view_lock_to_active";
3267 
3268  /* api callbacks */
3271 
3272  /* flags */
3273  ot->flag = 0;
3274 }
3275 
3278 /* -------------------------------------------------------------------- */
3283 {
3284  View3D *v3d = CTX_wm_view3d(C);
3287 
3288  if (rv3d) {
3289  ARegion *region = CTX_wm_region(C);
3290  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
3291 
3292  ED_view3d_smooth_view_force_finish(C, v3d, region);
3293 
3294  /* non camera center */
3295  float new_ofs[3];
3296  negate_v3_v3(new_ofs, scene->cursor.location);
3298  C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs});
3299 
3300  /* Smooth view does view-lock #RV3D_BOXVIEW copy. */
3301  }
3302 
3303  return OPERATOR_FINISHED;
3304 }
3305 
3307 {
3308  /* identifiers */
3309  ot->name = "Center View to Cursor";
3310  ot->description = "Center the view so that the cursor is in the middle of the view";
3311  ot->idname = "VIEW3D_OT_view_center_cursor";
3312 
3313  /* api callbacks */
3315  ot->poll = view3d_pan_poll;
3316 
3317  /* flags */
3318  ot->flag = 0;
3319 }
3320 
3323 /* -------------------------------------------------------------------- */
3327 static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
3328 {
3329  View3D *v3d = CTX_wm_view3d(C);
3331  ARegion *region = CTX_wm_region(C);
3332 
3333  if (rv3d) {
3335  float new_ofs[3];
3336  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
3337 
3338  ED_view3d_smooth_view_force_finish(C, v3d, region);
3339 
3341 
3342  if (ED_view3d_autodist(depsgraph, region, v3d, event->mval, new_ofs, false, NULL)) {
3343  /* pass */
3344  }
3345  else {
3346  /* fallback to simple pan */
3347  negate_v3_v3(new_ofs, rv3d->ofs);
3348  ED_view3d_win_to_3d_int(v3d, region, new_ofs, event->mval, new_ofs);
3349  }
3350  negate_v3(new_ofs);
3352  C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs});
3353  }
3354 
3355  return OPERATOR_FINISHED;
3356 }
3357 
3359 {
3360  /* identifiers */
3361  ot->name = "Center View to Mouse";
3362  ot->description = "Center the view to the Z-depth position under the mouse cursor";
3363  ot->idname = "VIEW3D_OT_view_center_pick";
3364 
3365  /* api callbacks */
3367  ot->poll = view3d_pan_poll;
3368 
3369  /* flags */
3370  ot->flag = 0;
3371 }
3372 
3375 /* -------------------------------------------------------------------- */
3380 {
3383  float xfac, yfac;
3384  float size[2];
3385 
3386  View3D *v3d;
3387  ARegion *region;
3388  RegionView3D *rv3d;
3389 
3390  /* no NULL check is needed, poll checks */
3391  ED_view3d_context_user_region(C, &v3d, &region);
3392  rv3d = region->regiondata;
3393 
3394  rv3d->camdx = rv3d->camdy = 0.0f;
3395 
3396  ED_view3d_calc_camera_border_size(scene, depsgraph, region, v3d, rv3d, size);
3397 
3398  /* 4px is just a little room from the edge of the area */
3399  xfac = (float)region->winx / (float)(size[0] + 4);
3400  yfac = (float)region->winy / (float)(size[1] + 4);
3401 
3402  rv3d->camzoom = BKE_screen_view3d_zoom_from_fac(min_ff(xfac, yfac));
3404 
3406 
3407  return OPERATOR_FINISHED;
3408 }
3409 
3411 {
3412  /* identifiers */
3413  ot->name = "Frame Camera Bounds";
3414  ot->description = "Center the camera view, resizing the view to fit its bounds";
3415  ot->idname = "VIEW3D_OT_view_center_camera";
3416 
3417  /* api callbacks */
3420 
3421  /* flags */
3422  ot->flag = 0;
3423 }
3424 
3427 /* -------------------------------------------------------------------- */
3432 {
3434 
3435  zero_v2(rv3d->ofs_lock);
3436 
3438 
3439  return OPERATOR_FINISHED;
3440 }
3441 
3443 {
3444  /* identifiers */
3445  ot->name = "View Lock Center";
3446  ot->description = "Center the view lock offset";
3447  ot->idname = "VIEW3D_OT_view_center_lock";
3448 
3449  /* api callbacks */
3452 
3453  /* flags */
3454  ot->flag = 0;
3455 }
3456 
3459 /* -------------------------------------------------------------------- */
3464 {
3465  View3D *v3d = CTX_wm_view3d(C);
3466  ARegion *region = CTX_wm_region(C);
3468 
3470 
3471  rcti rect;
3472  rctf vb, border;
3473 
3474  /* get box select values using rna */
3476 
3477  /* calculate range */
3478 
3479  if (rv3d->persp == RV3D_CAMOB) {
3481  ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &vb, false);
3482  }
3483  else {
3484  vb.xmin = 0;
3485  vb.ymin = 0;
3486  vb.xmax = region->winx;
3487  vb.ymax = region->winy;
3488  }
3489 
3490  border.xmin = ((float)rect.xmin - vb.xmin) / BLI_rctf_size_x(&vb);
3491  border.ymin = ((float)rect.ymin - vb.ymin) / BLI_rctf_size_y(&vb);
3492  border.xmax = ((float)rect.xmax - vb.xmin) / BLI_rctf_size_x(&vb);
3493  border.ymax = ((float)rect.ymax - vb.ymin) / BLI_rctf_size_y(&vb);
3494 
3495  /* actually set border */
3496  CLAMP(border.xmin, 0.0f, 1.0f);
3497  CLAMP(border.ymin, 0.0f, 1.0f);
3498  CLAMP(border.xmax, 0.0f, 1.0f);
3499  CLAMP(border.ymax, 0.0f, 1.0f);
3500 
3501  if (rv3d->persp == RV3D_CAMOB) {
3502  scene->r.border = border;
3503 
3505  }
3506  else {
3507  v3d->render_border = border;
3508 
3510  }
3511 
3512  /* drawing a border outside the camera view switches off border rendering */
3513  if ((border.xmin == border.xmax || border.ymin == border.ymax)) {
3514  if (rv3d->persp == RV3D_CAMOB) {
3515  scene->r.mode &= ~R_BORDER;
3516  }
3517  else {
3518  v3d->flag2 &= ~V3D_RENDER_BORDER;
3519  }
3520  }
3521  else {
3522  if (rv3d->persp == RV3D_CAMOB) {
3523  scene->r.mode |= R_BORDER;
3524  }
3525  else {
3526  v3d->flag2 |= V3D_RENDER_BORDER;
3527  }
3528  }
3529 
3530  if (rv3d->persp == RV3D_CAMOB) {
3532  }
3533  return OPERATOR_FINISHED;
3534 }
3535 
3537 {
3538  /* identifiers */
3539  ot->name = "Set Render Region";
3540  ot->description = "Set the boundaries of the border render and enable border render";
3541  ot->idname = "VIEW3D_OT_render_border";
3542 
3543  /* api callbacks */
3548 
3550 
3551  /* flags */
3553 
3554  /* properties */
3556 }
3557 
3560 /* -------------------------------------------------------------------- */
3565 {
3566  View3D *v3d = CTX_wm_view3d(C);
3568 
3570  rctf *border = NULL;
3571 
3572  if (rv3d->persp == RV3D_CAMOB) {
3573  scene->r.mode &= ~R_BORDER;
3574  border = &scene->r.border;
3575 
3577  }
3578  else {
3579  v3d->flag2 &= ~V3D_RENDER_BORDER;
3580  border = &v3d->render_border;
3581 
3583  }
3584 
3585  border->xmin = 0.0f;
3586  border->ymin = 0.0f;
3587  border->xmax = 1.0f;
3588  border->ymax = 1.0f;
3589 
3590  if (rv3d->persp == RV3D_CAMOB) {
3592  }
3593  return OPERATOR_FINISHED;
3594 }
3595 
3597 {
3598  /* identifiers */
3599  ot->name = "Clear Render Region";
3600  ot->description = "Clear the boundaries of the border render and disable border render";
3601  ot->idname = "VIEW3D_OT_clear_render_border";
3602 
3603  /* api callbacks */
3606 
3607  /* flags */
3609 }
3610 
3613 /* -------------------------------------------------------------------- */
3618 {
3619  ARegion *region = CTX_wm_region(C);
3620  View3D *v3d = CTX_wm_view3d(C);
3622  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
3623 
3624  /* Zooms in on a border drawn by the user */
3625  rcti rect;
3626  float dvec[3], vb[2], xscale, yscale;
3627  float dist_range[2];
3628 
3629  /* SMOOTHVIEW */
3630  float new_dist;
3631  float new_ofs[3];
3632 
3633  /* ZBuffer depth vars */
3634  float depth_close = FLT_MAX;
3635  float cent[2], p[3];
3636 
3637  /* note; otherwise opengl won't work */
3639 
3640  /* get box select values using rna */
3642 
3643  /* check if zooming in/out view */
3644  const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out");
3645 
3646  ED_view3d_dist_range_get(v3d, dist_range);
3647 
3650  {
3651  /* avoid allocating the whole depth buffer */
3652  ViewDepths depth_temp = {0};
3653 
3654  /* avoid view3d_update_depths() for speed. */
3655  view3d_update_depths_rect(region, &depth_temp, &rect);
3656 
3657  /* find the closest Z pixel */
3658  depth_close = view3d_depth_near(&depth_temp);
3659 
3660  MEM_SAFE_FREE(depth_temp.depths);
3661  }
3662 
3663  /* Resize border to the same ratio as the window. */
3664  {
3665  const float region_aspect = (float)region->winx / (float)region->winy;
3666  if (((float)BLI_rcti_size_x(&rect) / (float)BLI_rcti_size_y(&rect)) < region_aspect) {
3667  BLI_rcti_resize_x(&rect, (int)(BLI_rcti_size_y(&rect) * region_aspect));
3668  }
3669  else {
3670  BLI_rcti_resize_y(&rect, (int)(BLI_rcti_size_x(&rect) / region_aspect));
3671  }
3672  }
3673 
3674  cent[0] = (((float)rect.xmin) + ((float)rect.xmax)) / 2;
3675  cent[1] = (((float)rect.ymin) + ((float)rect.ymax)) / 2;
3676 
3677  if (rv3d->is_persp) {
3678  float p_corner[3];
3679 
3680  /* no depths to use, we cant do anything! */
3681  if (depth_close == FLT_MAX) {
3682  BKE_report(op->reports, RPT_ERROR, "Depth too large");
3683  return OPERATOR_CANCELLED;
3684  }
3685  /* convert border to 3d coordinates */
3686  if ((!ED_view3d_unproject(region, cent[0], cent[1], depth_close, p)) ||
3687  (!ED_view3d_unproject(region, rect.xmin, rect.ymin, depth_close, p_corner))) {
3688  return OPERATOR_CANCELLED;
3689  }
3690 
3691  sub_v3_v3v3(dvec, p, p_corner);
3692  negate_v3_v3(new_ofs, p);
3693 
3694  new_dist = len_v3(dvec);
3695 
3696  /* Account for the lens, without this a narrow lens zooms in too close. */
3697  new_dist *= (v3d->lens / DEFAULT_SENSOR_WIDTH);
3698 
3699  /* ignore dist_range min */
3700  dist_range[0] = v3d->clip_start * 1.5f;
3701  }
3702  else { /* orthographic */
3703  /* find the current window width and height */
3704  vb[0] = region->winx;
3705  vb[1] = region->winy;
3706 
3707  new_dist = rv3d->dist;
3708 
3709  /* convert the drawn rectangle into 3d space */
3710  if (depth_close != FLT_MAX && ED_view3d_unproject(region, cent[0], cent[1], depth_close, p)) {
3711  negate_v3_v3(new_ofs, p);
3712  }
3713  else {
3714  float mval_f[2];
3715  float zfac;
3716 
3717  /* We can't use the depth, fallback to the old way that doesn't set the center depth */
3718  copy_v3_v3(new_ofs, rv3d->ofs);
3719 
3720  {
3721  float tvec[3];
3722  negate_v3_v3(tvec, new_ofs);
3723  zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL);
3724  }
3725 
3726  mval_f[0] = (rect.xmin + rect.xmax - vb[0]) / 2.0f;
3727  mval_f[1] = (rect.ymin + rect.ymax - vb[1]) / 2.0f;
3728  ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
3729  /* center the view to the center of the rectangle */
3730  sub_v3_v3(new_ofs, dvec);
3731  }
3732 
3733  /* work out the ratios, so that everything selected fits when we zoom */
3734  xscale = (BLI_rcti_size_x(&rect) / vb[0]);
3735  yscale = (BLI_rcti_size_y(&rect) / vb[1]);
3736  new_dist *= max_ff(xscale, yscale);
3737  }
3738 
3739  if (!zoom_in) {
3740  sub_v3_v3v3(dvec, new_ofs, rv3d->ofs);
3741  new_dist = rv3d->dist * (rv3d->dist / new_dist);
3742  add_v3_v3v3(new_ofs, rv3d->ofs, dvec);
3743  }
3744 
3745  /* clamp after because we may have been zooming out */
3746  CLAMP(new_dist, dist_range[0], dist_range[1]);
3747 
3748  /* TODO(campbell): 'is_camera_lock' not currently working well. */
3749  const bool is_camera_lock = ED_view3d_camera_lock_check(v3d, rv3d);
3750  if ((rv3d->persp == RV3D_CAMOB) && (is_camera_lock == false)) {
3753  }
3754 
3756  v3d,
3757  region,
3758  smooth_viewtx,
3759  &(const V3D_SmoothParams){
3760  .ofs = new_ofs,
3761  .dist = &new_dist,
3762  });
3763 
3764  if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
3765  view3d_boxview_sync(CTX_wm_area(C), region);
3766  }
3767 
3768  return OPERATOR_FINISHED;
3769 }
3770 
3772 {
3773  /* identifiers */
3774  ot->name = "Zoom to Border";
3775  ot->description = "Zoom in the view to the nearest object contained in the border";
3776  ot->idname = "VIEW3D_OT_zoom_border";
3777 
3778  /* api callbacks */
3783 
3785 
3786  /* flags */
3787  ot->flag = 0;
3788 
3789  /* properties */
3791 }
3792 
3795 /* -------------------------------------------------------------------- */
3803  ARegion *region,
3804  View3D *v3d)
3805 {
3806  RegionView3D *rv3d = region->regiondata;
3807  float size[2];
3808  int im_width = (scene->r.size * scene->r.xsch) / 100;
3809 
3810  ED_view3d_calc_camera_border_size(scene, depsgraph, region, v3d, rv3d, size);
3811 
3812  rv3d->camzoom = BKE_screen_view3d_zoom_from_fac((float)im_width / size[0]);
3814 }
3815 
3817 {
3820 
3821  View3D *v3d;
3822  ARegion *region;
3823 
3824  /* no NULL check is needed, poll checks */
3825  ED_view3d_context_user_region(C, &v3d, &region);
3826 
3828 
3830 
3831  return OPERATOR_FINISHED;
3832 }
3833 
3835 {
3836  /* identifiers */
3837  ot->name = "Zoom Camera 1:1";
3838  ot->description = "Match the camera to 1:1 to the render output";
3839  ot->idname = "VIEW3D_OT_zoom_camera_1_to_1";
3840 
3841  /* api callbacks */
3844 
3845  /* flags */
3846  ot->flag = 0;
3847 }
3848 
3851 /* -------------------------------------------------------------------- */
3856  {RV3D_VIEW_LEFT, "LEFT", ICON_TRIA_LEFT, "Left", "View from the left"},
3857  {RV3D_VIEW_RIGHT, "RIGHT", ICON_TRIA_RIGHT, "Right", "View from the right"},
3858  {RV3D_VIEW_BOTTOM, "BOTTOM", ICON_TRIA_DOWN, "Bottom", "View from the bottom"},
3859  {RV3D_VIEW_TOP, "TOP", ICON_TRIA_UP, "Top", "View from the top"},
3860  {RV3D_VIEW_FRONT, "FRONT", 0, "Front", "View from the front"},
3861  {RV3D_VIEW_BACK, "BACK", 0, "Back", "View from the back"},
3862  {0, NULL, 0, NULL, NULL},
3863 };
3864 
3865 /* would like to make this a generic function - outside of transform */
3866 
3870 static void axis_set_view(bContext *C,
3871  View3D *v3d,
3872  ARegion *region,
3873  const float quat_[4],
3874  char view,
3875  char view_axis_roll,
3876  int perspo,
3877  const float *align_to_quat,
3878  const int smooth_viewtx)
3879 {
3880  RegionView3D *rv3d = region->regiondata; /* no NULL check is needed, poll checks */
3881  float quat[4];
3882  const short orig_persp = rv3d->persp;
3883 
3884  normalize_qt_qt(quat, quat_);
3885 
3886  if (align_to_quat) {
3887  mul_qt_qtqt(quat, quat, align_to_quat);
3888  rv3d->view = view = RV3D_VIEW_USER;
3890  }
3891 
3892  if (align_to_quat == NULL) {
3893  rv3d->view = view;
3894  rv3d->view_axis_roll = view_axis_roll;
3895  }
3896 
3897  if (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) {
3898  ED_region_tag_redraw(region);
3899  return;
3900  }
3901 
3902  if (U.uiflag & USER_AUTOPERSP) {
3903  rv3d->persp = RV3D_VIEW_IS_AXIS(view) ? RV3D_ORTHO : perspo;
3904  }
3905  else if (rv3d->persp == RV3D_CAMOB) {
3906  rv3d->persp = perspo;
3907  }
3908 
3909  if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
3910  /* to camera */
3912  v3d,
3913  region,
3914  smooth_viewtx,
3915  &(const V3D_SmoothParams){
3916  .camera_old = v3d->camera,
3917  .ofs = rv3d->ofs,
3918  .quat = quat,
3919  });
3920  }
3921  else if (orig_persp == RV3D_CAMOB && v3d->camera) {
3922  /* from camera */
3923  float ofs[3], dist;
3924 
3925  copy_v3_v3(ofs, rv3d->ofs);
3926  dist = rv3d->dist;
3927 
3928  /* so we animate _from_ the camera location */
3930  v3d->camera);
3931  ED_view3d_from_object(camera_eval, rv3d->ofs, NULL, &rv3d->dist, NULL);
3932 
3934  v3d,
3935  region,
3936  smooth_viewtx,
3937  &(const V3D_SmoothParams){
3938  .camera_old = camera_eval,
3939  .ofs = ofs,
3940  .quat = quat,
3941  .dist = &dist,
3942  });
3943  }
3944  else {
3945  /* rotate around selection */
3946  const float *dyn_ofs_pt = NULL;
3947  float dyn_ofs[3];
3948 
3949  if (U.uiflag & USER_ORBIT_SELECTION) {
3950  if (view3d_orbit_calc_center(C, dyn_ofs)) {
3951  negate_v3(dyn_ofs);
3952  dyn_ofs_pt = dyn_ofs;
3953  }
3954  }
3955 
3956  /* no camera involved */
3958  v3d,
3959  region,
3960  smooth_viewtx,
3961  &(const V3D_SmoothParams){
3962  .quat = quat,
3963  .dyn_ofs = dyn_ofs_pt,
3964  });
3965  }
3966 }
3967 
3969 {
3970  View3D *v3d;
3971  ARegion *region;
3972  RegionView3D *rv3d;
3973  static int perspo = RV3D_PERSP;
3974  int viewnum;
3975  int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0;
3976  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
3977 
3978  /* no NULL check is needed, poll checks */
3979  ED_view3d_context_user_region(C, &v3d, &region);
3980  rv3d = region->regiondata;
3981 
3982  ED_view3d_smooth_view_force_finish(C, v3d, region);
3983 
3984  viewnum = RNA_enum_get(op->ptr, "type");
3985 
3986  float align_quat_buf[4];
3987  float *align_quat = NULL;
3988 
3989  if (RNA_boolean_get(op->ptr, "align_active")) {
3990  /* align to active object */
3991  Object *obact = CTX_data_active_object(C);
3992  if (obact != NULL) {
3993  float twmat[3][3];
3994  Object *obedit = CTX_data_edit_object(C);
3995  /* same as transform gizmo when normal is set */
3996  ED_getTransformOrientationMatrix(C, obact, obedit, V3D_AROUND_ACTIVE, twmat);
3997  align_quat = align_quat_buf;
3998  mat3_to_quat(align_quat, twmat);
3999  invert_qt_normalized(align_quat);
4000  }
4001  }
4002 
4003  if (RNA_boolean_get(op->ptr, "relative")) {
4004  float quat_rotate[4];
4005  float quat_test[4];
4006 
4007  if (viewnum == RV3D_VIEW_LEFT) {
4008  axis_angle_to_quat(quat_rotate, rv3d->viewinv[1], -M_PI / 2.0f);
4009  }
4010  else if (viewnum == RV3D_VIEW_RIGHT) {
4011  axis_angle_to_quat(quat_rotate, rv3d->viewinv[1], M_PI / 2.0f);
4012  }
4013  else if (viewnum == RV3D_VIEW_TOP) {
4014  axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], -M_PI / 2.0f);
4015  }
4016  else if (viewnum == RV3D_VIEW_BOTTOM) {
4017  axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], M_PI / 2.0f);
4018  }
4019  else if (viewnum == RV3D_VIEW_FRONT) {
4020  unit_qt(quat_rotate);
4021  }
4022  else if (viewnum == RV3D_VIEW_BACK) {
4023  axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], M_PI);
4024  }
4025  else {
4026  BLI_assert(0);
4027  }
4028 
4029  mul_qt_qtqt(quat_test, rv3d->viewquat, quat_rotate);
4030 
4031  float angle_best = FLT_MAX;
4032  int view_best = -1;
4033  int view_axis_roll_best = -1;
4034  for (int i = RV3D_VIEW_FRONT; i <= RV3D_VIEW_BOTTOM; i++) {
4035  for (int j = RV3D_VIEW_AXIS_ROLL_0; j <= RV3D_VIEW_AXIS_ROLL_270; j++) {
4036  float quat_axis[4];
4037  ED_view3d_quat_from_axis_view(i, j, quat_axis);
4038  if (align_quat) {
4039  mul_qt_qtqt(quat_axis, quat_axis, align_quat);
4040  }
4041  const float angle_test = fabsf(angle_signed_qtqt(quat_axis, quat_test));
4042  if (angle_best > angle_test) {
4043  angle_best = angle_test;
4044  view_best = i;
4045  view_axis_roll_best = j;
4046  }
4047  }
4048  }
4049  if (view_best == -1) {
4050  view_best = RV3D_VIEW_FRONT;
4051  view_axis_roll_best = RV3D_VIEW_AXIS_ROLL_0;
4052  }
4053 
4054  /* Disallow non-upright views in turn-table modes,
4055  * it's too difficult to navigate out of them. */
4056  if ((U.flag & USER_TRACKBALL) == 0) {
4057  if (!ELEM(view_best, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) {
4058  view_axis_roll_best = RV3D_VIEW_AXIS_ROLL_0;
4059  }
4060  }
4061 
4062  viewnum = view_best;
4063  view_axis_roll = view_axis_roll_best;
4064  }
4065 
4066  /* Use this to test if we started out with a camera */
4067  const int nextperspo = (rv3d->persp == RV3D_CAMOB) ? rv3d->lpersp : perspo;
4068  float quat[4];
4069  ED_view3d_quat_from_axis_view(viewnum, view_axis_roll, quat);
4070  axis_set_view(
4071  C, v3d, region, quat, viewnum, view_axis_roll, nextperspo, align_quat, smooth_viewtx);
4072 
4073  perspo = rv3d->persp;
4074 
4075  return OPERATOR_FINISHED;
4076 }
4077 
4079 {
4080  PropertyRNA *prop;
4081 
4082  /* identifiers */
4083  ot->name = "View Axis";
4084  ot->description = "Use a preset viewpoint";
4085  ot->idname = "VIEW3D_OT_view_axis";
4086 
4087  /* api callbacks */
4088  ot->exec = view_axis_exec;
4090 
4091  /* flags */
4092  ot->flag = 0;
4093 
4094  ot->prop = RNA_def_enum(ot->srna, "type", prop_view_items, 0, "View", "Preset viewpoint to use");
4096  prop = RNA_def_boolean(
4097  ot->srna, "align_active", 0, "Align Active", "Align to the active object's axis");
4099  prop = RNA_def_boolean(
4100  ot->srna, "relative", 0, "Relative", "Rotate relative to the current orientation");
4102 }
4103 
4106 /* -------------------------------------------------------------------- */
4111 {
4112  View3D *v3d;
4113  ARegion *region;
4114  RegionView3D *rv3d;
4115  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
4116 
4117  /* no NULL check is needed, poll checks */
4118  ED_view3d_context_user_region(C, &v3d, &region);
4119  rv3d = region->regiondata;
4120 
4121  ED_view3d_smooth_view_force_finish(C, v3d, region);
4122 
4123  if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) {
4124  ViewLayer *view_layer = CTX_data_view_layer(C);
4126 
4127  if (rv3d->persp != RV3D_CAMOB) {
4128  Object *ob = OBACT(view_layer);
4129 
4130  if (!rv3d->smooth_timer) {
4131  /* store settings of current view before allowing overwriting with camera view
4132  * only if we're not currently in a view transition */
4133 
4135  }
4136 
4137  /* first get the default camera for the view lock type */
4138  if (v3d->scenelock) {
4139  /* sets the camera view if available */
4140  v3d->camera = scene->camera;
4141  }
4142  else {
4143  /* use scene camera if one is not set (even though we're unlocked) */
4144  if (v3d->camera == NULL) {
4145  v3d->camera = scene->camera;
4146  }
4147  }
4148 
4149  /* if the camera isn't found, check a number of options */
4150  if (v3d->camera == NULL && ob && ob->type == OB_CAMERA) {
4151  v3d->camera = ob;
4152  }
4153 
4154  if (v3d->camera == NULL) {
4155  v3d->camera = BKE_view_layer_camera_find(view_layer);
4156  }
4157 
4158  /* couldn't find any useful camera, bail out */
4159  if (v3d->camera == NULL) {
4160  return OPERATOR_CANCELLED;
4161  }
4162 
4163  /* important these don't get out of sync for locked scenes */
4164  if (v3d->scenelock && scene->camera != v3d->camera) {
4165  scene->camera = v3d->camera;
4167  }
4168 
4169  /* finally do snazzy view zooming */
4170  rv3d->persp = RV3D_CAMOB;
4172  v3d,
4173  region,
4174  smooth_viewtx,
4175  &(const V3D_SmoothParams){
4176  .camera = v3d->camera,
4177  .ofs = rv3d->ofs,
4178  .quat = rv3d->viewquat,
4179  .dist = &rv3d->dist,
4180  .lens = &v3d->lens,
4181  });
4182  }
4183  else {
4184  /* return to settings of last view */
4185  /* does view3d_smooth_view too */
4186  axis_set_view(C,
4187  v3d,
4188  region,
4189  rv3d->lviewquat,
4190  rv3d->lview,
4191  rv3d->lview_axis_roll,
4192  rv3d->lpersp,
4193  NULL,
4194  smooth_viewtx);
4195  }
4196  }
4197 
4198  return OPERATOR_FINISHED;
4199 }
4200 
4202 {
4203  /* identifiers */
4204  ot->name = "View Camera";
4205  ot->description = "Toggle the camera view";
4206  ot->idname = "VIEW3D_OT_view_camera";
4207 
4208  /* api callbacks */
4211 
4212  /* flags */
4213  ot->flag = 0;
4214 }
4215 
4218 /* -------------------------------------------------------------------- */
4224 enum {
4229 };
4230 
4232  {V3D_VIEW_STEPLEFT, "ORBITLEFT", 0, "Orbit Left", "Orbit the view around to the left"},
4233  {V3D_VIEW_STEPRIGHT, "ORBITRIGHT", 0, "Orbit Right", "Orbit the view around to the right"},
4234  {V3D_VIEW_STEPUP, "ORBITUP", 0, "Orbit Up", "Orbit the view up"},
4235  {V3D_VIEW_STEPDOWN, "ORBITDOWN", 0, "Orbit Down", "Orbit the view down"},
4236  {0, NULL, 0, NULL, NULL},
4237 };
4238 
4240 {
4241  View3D *v3d;
4242  ARegion *region;
4243  RegionView3D *rv3d;
4244  int orbitdir;
4245  char view_opposite;
4246  PropertyRNA *prop_angle = RNA_struct_find_property(op->ptr, "angle");
4247  float angle = RNA_property_is_set(op->ptr, prop_angle) ?
4248  RNA_property_float_get(op->ptr, prop_angle) :
4249  DEG2RADF(U.pad_rot_angle);
4250 
4251  /* no NULL check is needed, poll checks */
4252  v3d = CTX_wm_view3d(C);
4253  region = CTX_wm_region(C);
4254  rv3d = region->regiondata;
4255 
4256  /* support for switching to the opposite view (even when in locked views) */
4257  view_opposite = (fabsf(angle) == (float)M_PI) ? ED_view3d_axis_view_opposite(rv3d->view) :
4259  orbitdir = RNA_enum_get(op->ptr, "type");
4260 
4261  if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) && (view_opposite == RV3D_VIEW_USER)) {
4262  /* no NULL check is needed, poll checks */
4263  ED_view3d_context_user_region(C, &v3d, &region);
4264  rv3d = region->regiondata;
4265  }
4266 
4267  ED_view3d_smooth_view_force_finish(C, v3d, region);
4268 
4269  if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0 || (view_opposite != RV3D_VIEW_USER)) {
4270  if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
4271  int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
4272  float quat_mul[4];
4273  float quat_new[4];
4274 
4275  if (view_opposite == RV3D_VIEW_USER) {
4277  ED_view3d_persp_ensure(depsgraph, v3d, region);
4278  }
4279 
4280  if (ELEM(orbitdir, V3D_VIEW_STEPLEFT, V3D_VIEW_STEPRIGHT)) {
4281  if (orbitdir == V3D_VIEW_STEPRIGHT) {
4282  angle = -angle;
4283  }
4284 
4285  /* z-axis */
4286  axis_angle_to_quat_single(quat_mul, 'Z', angle);
4287  }
4288  else {
4289 
4290  if (orbitdir == V3D_VIEW_STEPDOWN) {
4291  angle = -angle;
4292  }
4293 
4294  /* horizontal axis */
4295  axis_angle_to_quat(quat_mul, rv3d->viewinv[0], angle);
4296  }
4297 
4298  mul_qt_qtqt(quat_new, rv3d->viewquat, quat_mul);
4299 
4300  /* avoid precision loss over time */
4301  normalize_qt(quat_new);
4302 
4303  if (view_opposite != RV3D_VIEW_USER) {
4304  rv3d->view = view_opposite;
4305  /* avoid float in-precision, just get a new orientation */
4306  ED_view3d_quat_from_axis_view(view_opposite, rv3d->view_axis_roll, quat_new);
4307  }
4308  else {
4309  rv3d->view = RV3D_VIEW_USER;
4310  }
4311 
4312  float dyn_ofs[3], *dyn_ofs_pt = NULL;
4313 
4314  if (U.uiflag & USER_ORBIT_SELECTION) {
4315  if (view3d_orbit_calc_center(C, dyn_ofs)) {
4316  negate_v3(dyn_ofs);
4317  dyn_ofs_pt = dyn_ofs;
4318  }
4319  }
4320 
4322  v3d,
4323  region,
4324  smooth_viewtx,
4325  &(const V3D_SmoothParams){
4326  .quat = quat_new,
4327  .dyn_ofs = dyn_ofs_pt,
4328  });
4329 
4330  return OPERATOR_FINISHED;
4331  }
4332  }
4333 
4334  return OPERATOR_CANCELLED;
4335 }
4336 
4338 {
4339  PropertyRNA *prop;
4340 
4341  /* identifiers */
4342  ot->name = "View Orbit";
4343  ot->description = "Orbit the view";
4344  ot->idname = "VIEW3D_OT_view_orbit";
4345 
4346  /* api callbacks */
4347  ot->exec = vieworbit_exec;
4349 
4350  /* flags */
4351  ot->flag = 0;
4352 
4353  /* properties */
4354  prop = RNA_def_float(ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX);
4356 
4357  ot->prop = RNA_def_enum(
4358  ot->srna, "type", prop_view_orbit_items, 0, "Orbit", "Direction of View Orbit");
4359 }
4360 
4363 /* -------------------------------------------------------------------- */
4367 static void view_roll_angle(
4368  ARegion *region, float quat[4], const float orig_quat[4], const float dvec[3], float angle)
4369 {
4370  RegionView3D *rv3d = region->regiondata;
4371  float quat_mul[4];
4372 
4373  /* camera axis */
4374  axis_angle_normalized_to_quat(quat_mul, dvec, angle);
4375 
4376  mul_qt_qtqt(quat, orig_quat, quat_mul);
4377 
4378  /* avoid precision loss over time */
4379  normalize_qt(quat);
4380 
4381  rv3d->view = RV3D_VIEW_USER;
4382 }
4383 
4384 static void viewroll_apply(ViewOpsData *vod, int x, int UNUSED(y))
4385 {
4386  float angle = 0.0;
4387 
4388  {
4389  float len1, len2, tot;
4390 
4391  tot = vod->region->winrct.xmax - vod->region->winrct.xmin;
4392  len1 = (vod->region->winrct.xmax - x) / tot;
4393  len2 = (vod->region->winrct.xmax - vod->init.event_xy[0]) / tot;
4394  angle = (len1 - len2) * (float)M_PI * 4.0f;
4395  }
4396 
4397  if (angle != 0.0f) {
4398  view_roll_angle(vod->region, vod->rv3d->viewquat, vod->init.quat, vod->init.mousevec, angle);
4399  }
4400 
4401  if (vod->use_dyn_ofs) {
4403  vod->rv3d->ofs, vod->init.ofs, vod->init.quat, vod->rv3d->viewquat, vod->dyn_ofs);
4404  }
4405 
4406  if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) {
4407  view3d_boxview_sync(vod->area, vod->region);
4408  }
4409 
4410  ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
4411 
4413 }
4414 
4415 static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
4416 {
4417  ViewOpsData *vod = op->customdata;
4418  short event_code = VIEW_PASS;
4419  bool use_autokey = false;
4421 
4422  /* execute the events */
4423  if (event->type == MOUSEMOVE) {
4424  event_code = VIEW_APPLY;
4425  }
4426  else if (event->type == EVT_MODAL_MAP) {
4427  switch (event->val) {
4428  case VIEW_MODAL_CONFIRM:
4429  event_code = VIEW_CONFIRM;
4430  break;
4432  WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL);
4433  event_code = VIEW_CONFIRM;
4434  break;
4436  WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL);
4437  event_code = VIEW_CONFIRM;
4438  break;
4439  }
4440  }
4441  else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
4442  event_code = VIEW_CONFIRM;
4443  }
4444 
4445  if (event_code == VIEW_APPLY) {
4446  viewroll_apply(vod, event->x, event->y);
4448  use_autokey = true;
4449  }
4450  }
4451  else if (event_code == VIEW_CONFIRM) {
4453  use_autokey = true;
4455  }
4456 
4457  if (use_autokey) {
4458  ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, false);
4459  }
4460 
4461  if (ret & OPERATOR_FINISHED) {
4462  viewops_data_free(C, op);
4463  }
4464 
4465  return ret;
4466 }
4467 
4469  {0, "ANGLE", 0, "Roll Angle", "Roll the view using an angle value"},
4470  {V3D_VIEW_STEPLEFT, "LEFT", 0, "Roll Left", "Roll the view around to the left"},
4471  {V3D_VIEW_STEPRIGHT, "RIGHT", 0, "Roll Right", "Roll the view around to the right"},
4472  {0, NULL, 0, NULL, NULL},
4473 };
4474 
4476 {
4477  View3D *v3d;
4478  RegionView3D *rv3d;
4479  ARegion *region;
4480 
4481  if (op->customdata) {
4482  ViewOpsData *vod = op->customdata;
4483  region = vod->region;
4484  v3d = vod->v3d;
4485  }
4486  else {
4487  ED_view3d_context_user_region(C, &v3d, &region);
4488  }
4489 
4490  rv3d = region->regiondata;
4491  if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
4492 
4493  ED_view3d_smooth_view_force_finish(C, v3d, region);
4494 
4495  int type = RNA_enum_get(op->ptr, "type");
4496  float angle = (type == 0) ? RNA_float_get(op->ptr, "angle") : DEG2RADF(U.pad_rot_angle);
4497  float mousevec[3];
4498  float quat_new[4];
4499 
4500  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
4501 
4502  if (type == V3D_VIEW_STEPLEFT) {
4503  angle = -angle;
4504  }
4505 
4506  normalize_v3_v3(mousevec, rv3d->viewinv[2]);
4507  negate_v3(mousevec);
4508  view_roll_angle(region, quat_new, rv3d->viewquat, mousevec, angle);
4509 
4510  const float *dyn_ofs_pt = NULL;
4511  float dyn_ofs[3];
4512  if (U.uiflag & USER_ORBIT_SELECTION) {
4513  if (view3d_orbit_calc_center(C, dyn_ofs)) {
4514  negate_v3(dyn_ofs);
4515  dyn_ofs_pt = dyn_ofs;
4516  }
4517  }
4518 
4520  v3d,
4521  region,
4522  smooth_viewtx,
4523  &(const V3D_SmoothParams){
4524  .quat = quat_new,
4525  .dyn_ofs = dyn_ofs_pt,
4526  });
4527 
4528  viewops_data_free(C, op);
4529  return OPERATOR_FINISHED;
4530  }
4531 
4532  viewops_data_free(C, op);
4533  return OPERATOR_CANCELLED;
4534 }
4535 
4536 static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
4537 {
4538  ViewOpsData *vod;
4539 
4540  bool use_angle = RNA_enum_get(op->ptr, "type") != 0;
4541 
4542  if (use_angle || RNA_struct_property_is_set(op->ptr, "angle")) {
4543  viewroll_exec(C, op);
4544  }
4545  else {
4546  /* makes op->customdata */
4547  viewops_data_alloc(C, op);
4549  vod = op->customdata;
4550 
4552 
4553  /* overwrite the mouse vector with the view direction */
4554  normalize_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]);
4555  negate_v3(vod->init.mousevec);
4556 
4557  if (event->type == MOUSEROTATE) {
4558  vod->init.event_xy[0] = vod->prev.event_xy[0] = event->x;
4559  viewroll_apply(vod, event->prevx, event->prevy);
4561 
4562  viewops_data_free(C, op);
4563  return OPERATOR_FINISHED;
4564  }
4565 
4566  /* add temp handler */
4568  return OPERATOR_RUNNING_MODAL;
4569  }
4570  return OPERATOR_FINISHED;
4571 }
4572 
4574 {
4575  viewops_data_free(C, op);
4576 }
4577 
4579 {
4580  PropertyRNA *prop;
4581 
4582  /* identifiers */
4583  ot->name = "View Roll";
4584  ot->description = "Roll the view";
4585  ot->idname = "VIEW3D_OT_view_roll";
4586 
4587  /* api callbacks */
4589  ot->exec = viewroll_exec;
4590  ot->modal = viewroll_modal;
4593 
4594  /* flags */
4595  ot->flag = 0;
4596 
4597  /* properties */
4598  ot->prop = prop = RNA_def_float(
4599  ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX);
4601  prop = RNA_def_enum(ot->srna,
4602  "type",
4604  0,
4605  "Roll Angle Source",
4606  "How roll angle is calculated");
4608 }
4609 
4610 enum {
4615 };
4616 
4618  {V3D_VIEW_PANLEFT, "PANLEFT", 0, "Pan Left", "Pan the view to the left"},
4619  {V3D_VIEW_PANRIGHT, "PANRIGHT", 0, "Pan Right", "Pan the view to the right"},
4620  {V3D_VIEW_PANUP, "PANUP", 0, "Pan Up", "Pan the view up"},
4621  {V3D_VIEW_PANDOWN, "PANDOWN", 0, "Pan Down", "Pan the view down"},
4622  {0, NULL, 0, NULL, NULL},
4623 };
4624 
4627 /* -------------------------------------------------------------------- */
4633 static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
4634 {
4635  int x = 0, y = 0;
4636  int pandir = RNA_enum_get(op->ptr, "type");
4637 
4638  if (pandir == V3D_VIEW_PANRIGHT) {
4639  x = -32;
4640  }
4641  else if (pandir == V3D_VIEW_PANLEFT) {
4642  x = 32;
4643  }
4644  else if (pandir == V3D_VIEW_PANUP) {
4645  y = -25;
4646  }
4647  else if (pandir == V3D_VIEW_PANDOWN) {
4648  y = 25;
4649  }
4650 
4651  viewops_data_alloc(C, op);
4653  ViewOpsData *vod = op->customdata;
4654 
4655  viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y);
4656 
4658  viewops_data_free(C, op);
4659 
4660  return OPERATOR_FINISHED;
4661 }
4662 
4664 {
4665  /* identifiers */
4666  ot->name = "Pan View Direction";
4667  ot->description = "Pan the view in a given direction";
4668  ot->idname = "VIEW3D_OT_view_pan";
4669 
4670  /* api callbacks */
4672  ot->poll = view3d_pan_poll;
4673 
4674  /* flags */
4675  ot->flag = 0;
4676 
4677  /* Properties */
4678  ot->prop = RNA_def_enum(
4679  ot->srna, "type", prop_view_pan_items, 0, "Pan", "Direction of View Pan");
4680 }
4681 
4684 /* -------------------------------------------------------------------- */
4689 {
4690  View3D *v3d_dummy;
4691  ARegion *region;
4692  RegionView3D *rv3d;
4693 
4694  /* no NULL check is needed, poll checks */
4695  ED_view3d_context_user_region(C, &v3d_dummy, &region);
4696  rv3d = region->regiondata;
4697 
4698  /* Could add a separate lock flag for locking persp. */
4699  if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) {
4700  if (rv3d->persp != RV3D_ORTHO) {
4701  rv3d->persp = RV3D_ORTHO;
4702  }
4703  else {
4704  rv3d->persp = RV3D_PERSP;
4705  }
4706  ED_region_tag_redraw(region);
4707  }
4708 
4709  return OPERATOR_FINISHED;
4710 }
4711 
4713 {
4714  /* identifiers */
4715  ot->name = "View Perspective/Orthographic";
4716  ot->description = "Switch the current view from perspective/orthographic projection";
4717  ot->idname = "VIEW3D_OT_view_persportho";
4718 
4719  /* api callbacks */
4722 
4723  /* flags */
4724  ot->flag = 0;
4725 }
4726 
4729 /* -------------------------------------------------------------------- */
4736  wmOperator *UNUSED(op),
4737  const wmEvent *UNUSED(event))
4738 {
4739  eViewNavigation_Method mode = U.navigation_mode;
4740 
4741  switch (mode) {
4742  case VIEW_NAVIGATION_FLY:
4743  WM_operator_name_call(C, "VIEW3D_OT_fly", WM_OP_INVOKE_DEFAULT, NULL);
4744  break;
4745  case VIEW_NAVIGATION_WALK:
4746  default:
4747  WM_operator_name_call(C, "VIEW3D_OT_walk", WM_OP_INVOKE_DEFAULT, NULL);
4748  break;
4749  }
4750 
4751  return OPERATOR_FINISHED;
4752 }
4753 
4755 {
4756  /* identifiers */
4757  ot->name = "View Navigation (Walk/Fly)";
4758  ot->description =
4759  "Interactively navigate around the scene (uses the mode (walk/fly) preference)";
4760  ot->idname = "VIEW3D_OT_navigate";
4761 
4762  /* api callbacks */
4765 }
4766 
4769 /* -------------------------------------------------------------------- */
4774 {
4775  /* Needed to support drag-and-drop & camera buttons context. */
4776  View3D *v3d = CTX_wm_view3d(C);
4777  if (v3d != NULL) {
4778  if (v3d->camera && v3d->camera->data && v3d->camera->type == OB_CAMERA) {
4779  return v3d->camera->data;
4780  }
4781  return NULL;
4782  }
4783 
4784  return CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
4785 }
4786 
4788 {
4791 
4792  return OPERATOR_FINISHED;
4793 }
4794 
4796 {
4798  Image *ima;
4799  CameraBGImage *bgpic;
4800 
4801  ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM);
4802  /* may be NULL, continue anyway */
4803 
4804  bgpic = BKE_camera_background_image_new(cam);
4805  bgpic->ima = ima;
4806 
4807  cam->flag |= CAM_SHOW_BG_IMAGE;
4808 
4811 
4812  return OPERATOR_FINISHED;
4813 }
4814 
4816 {
4818 }
4819 
4821 {
4822  /* identifiers */
4823  /* note: having key shortcut here is bad practice,
4824  * but for now keep because this displays when dragging an image over the 3D viewport */
4825  ot->name = "Add Background Image";
4826  ot->description = "Add a new background image";
4827  ot->idname = "VIEW3D_OT_background_image_add";
4828 
4829  /* api callbacks */
4833 
4834  /* flags */
4835  ot->flag = OPTYPE_UNDO;
4836 
4837  /* properties */
4838  RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Image name to assign");
4841  FILE_SPECIAL,
4842  FILE_OPENFILE,
4846 }
4847 
4850 /* -------------------------------------------------------------------- */
4855 {
4856  Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
4857  const int index = RNA_int_get(op->ptr, "index");
4858  CameraBGImage *bgpic_rem = BLI_findlink(&cam->bg_images, index);
4859 
4860  if (bgpic_rem) {
4861  if (bgpic_rem->source == CAM_BGIMG_SOURCE_IMAGE) {
4862  id_us_min((ID *)bgpic_rem->ima);
4863  }
4864  else if (bgpic_rem->source == CAM_BGIMG_SOURCE_MOVIE) {
4865  id_us_min((ID *)bgpic_rem->clip);
4866  }
4867 
4868  BKE_camera_background_image_remove(cam, bgpic_rem);
4869 
4872 
4873  return OPERATOR_FINISHED;
4874  }
4875  return OPERATOR_CANCELLED;
4876 }
4877 
4879 {
4880  /* identifiers */
4881  ot->name = "Remove Background Image";
4882  ot->description = "Remove a background image from the 3D view";
4883  ot->idname = "VIEW3D_OT_background_image_remove";
4884 
4885  /* api callbacks */
4888 
4889  /* flags */
4890  ot->flag = 0;
4891 
4892  /* properties */
4893  RNA_def_int(
4894  ot->srna, "index", 0, 0, INT_MAX, "Index", "Background image index to remove", 0, INT_MAX);
4895 }
4896 
4899 /* -------------------------------------------------------------------- */
4905 static void calc_local_clipping(float clip_local[6][4],
4906  const BoundBox *clipbb,
4907  const float mat[4][4])
4908 {
4909  BoundBox clipbb_local;
4910  float imat[4][4];
4911 
4912  invert_m4_m4(imat, mat);
4913 
4914  for (int i = 0; i < 8; i++) {
4915  mul_v3_m4v3(clipbb_local.vec[i], imat, clipbb->vec[i]);
4916  }
4917 
4918  ED_view3d_clipping_calc_from_boundbox(clip_local, &clipbb_local, is_negative_m4(mat));
4919 }
4920 
4921 void ED_view3d_clipping_local(RegionView3D *rv3d, const float mat[4][4])
4922 {
4923  if (rv3d->rflag & RV3D_CLIPPING) {
4924  calc_local_clipping(rv3d->clip_local, rv3d->clipbb, mat);
4925  }
4926 }
4927 
4929 {
4930  ARegion *region = CTX_wm_region(C);
4932  rcti rect;
4933 
4935 
4936  rv3d->rflag |= RV3D_CLIPPING;
4937  rv3d->clipbb = MEM_callocN(sizeof(BoundBox), "clipbb");
4938 
4939  /* NULL object because we don't want it in object space */
4940  ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, region, NULL, &rect);
4941 
4942  return OPERATOR_FINISHED;
4943 }
4944 
4945 static int view3d_clipping_invoke(bContext *C, wmOperator *op, const wmEvent *event)
4946 {
4948  ARegion *region = CTX_wm_region(C);
4949 
4950  if (rv3d->rflag & RV3D_CLIPPING) {
4951  rv3d->rflag &= ~RV3D_CLIPPING;
4952  ED_region_tag_redraw(region);
4953  if (rv3d->clipbb) {
4954  MEM_freeN(rv3d->clipbb);
4955  }
4956  rv3d->clipbb = NULL;
4957  return OPERATOR_FINISHED;
4958  }
4959  return WM_gesture_box_invoke(C, op, event);
4960 }
4961 
4963 {
4964 
4965  /* identifiers */
4966  ot->name = "Clipping Region";
4967  ot->description = "Set the view clipping region";
4968  ot->idname = "VIEW3D_OT_clip_border";
4969 
4970  /* api callbacks */
4975 
4977 
4978  /* flags */
4979  ot->flag = 0;
4980 
4981  /* properties */
4983 }
4984 
4987 /* -------------------------------------------------------------------- */
4991 /* cursor position in vec, result in vec, mval in region coords */
4992 /* note: cannot use event->mval here (called by object_add() */
4994  const int mval[2],
4995  const bool use_depth,
4996  float cursor_co[3])
4997 {
4998  ARegion *region = CTX_wm_region(C);
4999  View3D *v3d = CTX_wm_view3d(C);
5000  RegionView3D *rv3d = region->regiondata;
5001  bool flip;
5002  bool depth_used = false;
5003 
5004  /* normally the caller should ensure this,
5005  * but this is called from areas that aren't already dealing with the viewport */
5006  if (rv3d == NULL) {
5007  return;
5008  }
5009 
5010  ED_view3d_calc_zfac(rv3d, cursor_co, &flip);
5011 
5012  /* Reset the depth based on the view offset (we _know_ the offset is in front of us). */
5013  if (flip) {
5014  negate_v3_v3(cursor_co, rv3d->ofs);
5015  /* re initialize, no need to check flip again */
5016  ED_view3d_calc_zfac(rv3d, cursor_co, NULL /* &flip */);
5017  }
5018 
5019  if (use_depth) { /* maybe this should be accessed some other way */
5021 
5023  if (ED_view3d_autodist(depsgraph, region, v3d, mval, cursor_co, true, NULL)) {
5024  depth_used = true;
5025  }
5026  }
5027 
5028  if (depth_used == false) {
5029  float depth_pt[3];
5030  copy_v3_v3(depth_pt, cursor_co);
5031  ED_view3d_win_to_3d_int(v3d, region, depth_pt, mval, cursor_co);
5032  }
5033 }
5034 
5036  const int mval[2],
5037  const bool use_depth,
5038  enum eV3DCursorOrient orientation,
5039  float cursor_co[3],
5040  float cursor_quat[4])
5041 {
5043  View3D *v3d = CTX_wm_view3d(C);
5044  ARegion *region = CTX_wm_region(C);
5045  RegionView3D *rv3d = region->regiondata;
5046 
5047  /* XXX, caller should check. */
5048  if (rv3d == NULL) {
5049  return;
5050  }
5051 
5052  ED_view3d_cursor3d_position(C, mval, use_depth, cursor_co);
5053 
5054  if (orientation == V3D_CURSOR_ORIENT_NONE) {
5055  /* pass */
5056  }
5057  else if (orientation == V3D_CURSOR_ORIENT_VIEW) {
5058  copy_qt_qt(cursor_quat, rv3d->viewquat);
5059  cursor_quat[0] *= -1.0f;
5060  }
5061  else if (orientation == V3D_CURSOR_ORIENT_XFORM) {
5062  float mat[3][3];
5064  mat3_to_quat(cursor_quat, mat);
5065  }
5066  else if (orientation == V3D_CURSOR_ORIENT_GEOM) {
5067  copy_qt_qt(cursor_quat, rv3d->viewquat);
5068  cursor_quat[0] *= -1.0f;
5069 
5070  const float mval_fl[2] = {UNPACK2(mval)};
5071  float ray_no[3];
5072  float ray_co[3];
5073 
5075  scene, 0, region, v3d);
5076 
5077  float obmat[4][4];
5078  Object *ob_dummy = NULL;
5079  float dist_px = 0;
5083  &(const struct SnapObjectParams){
5084  .snap_select = SNAP_ALL,
5085  .use_object_edit_cage = false,
5086  .use_occlusion_test = true,
5087  },
5088  mval_fl,
5089  NULL,
5090  &dist_px,
5091  ray_co,
5092  ray_no,
5093  NULL,
5094  &ob_dummy,
5095  obmat) != 0) {
5096  if (use_depth) {
5097  copy_v3_v3(cursor_co, ray_co);
5098  }
5099 
5100  /* Math normal (Z). */
5101  {
5102  float tquat[4];
5103  float z_src[3] = {0, 0, 1};
5104  mul_qt_v3(cursor_quat, z_src);
5105  rotation_between_vecs_to_quat(tquat, z_src, ray_no);
5106  mul_qt_qtqt(cursor_quat, tquat, cursor_quat);
5107  }
5108 
5109  /* Match object matrix (X). */
5110  {
5111  const float ortho_axis_dot[3] = {
5112  dot_v3v3(ray_no, obmat[0]),
5113  dot_v3v3(ray_no, obmat[1]),
5114  dot_v3v3(ray_no, obmat[2]),
5115  };
5116  const int ortho_axis = axis_dominant_v3_ortho_single(ortho_axis_dot);
5117 
5118  float tquat_best[4];
5119  float angle_best = -1.0f;
5120 
5121  float tan_dst[3];
5122  project_plane_v3_v3v3(tan_dst, obmat[ortho_axis], ray_no);
5123  normalize_v3(tan_dst);
5124 
5125  /* As the tangent is arbitrary from the users point of view,
5126  * make the cursor 'roll' on the shortest angle.
5127  * otherwise this can cause noticeable 'flipping', see T72419. */
5128  for (int axis = 0; axis < 2; axis++) {
5129  float tan_src[3] = {0, 0, 0};
5130  tan_src[axis] = 1.0f;
5131  mul_qt_v3(cursor_quat, tan_src);
5132 
5133  for (int axis_sign = 0; axis_sign < 2; axis_sign++) {
5134  float tquat_test[4];
5135  rotation_between_vecs_to_quat(tquat_test, tan_src, tan_dst);
5136  const float angle_test = angle_normalized_qt(tquat_test);
5137  if (angle_test < angle_best || angle_best == -1.0f) {
5138  angle_best = angle_test;
5139  copy_qt_qt(tquat_best, tquat_test);
5140  }
5141  negate_v3(tan_src);
5142  }
5143  }
5144  mul_qt_qtqt(cursor_quat, tquat_best, cursor_quat);
5145  }
5146  }
5148  }
5149 }
5150 
5152  const int mval[2],
5153  const bool use_depth,
5154  enum eV3DCursorOrient orientation)
5155 {
5157  View3D *v3d = CTX_wm_view3d(C);
5159  RegionView3D *rv3d = region->regiondata;
5160 
5161  View3DCursor *cursor_curr = &scene->cursor;
5162  View3DCursor cursor_prev = *cursor_curr;
5163 
5164  {
5165  float quat[4], quat_prev[4];
5166  BKE_scene_cursor_rot_to_quat(cursor_curr, quat);
5167  copy_qt_qt(quat_prev, quat);
5169  C, mval, use_depth, orientation, cursor_curr->location, quat);
5170 
5171  if (!equals_v4v4(quat_prev, quat)) {
5172  if ((cursor_curr->rotation_mode == ROT_MODE_AXISANGLE) && RV3D_VIEW_IS_AXIS(rv3d->view)) {
5173  float tmat[3][3], cmat[3][3];
5174  quat_to_mat3(tmat, quat);
5175  negate_v3_v3(cursor_curr->rotation_axis, tmat[2]);
5176  axis_angle_to_mat3(cmat, cursor_curr->rotation_axis, 0.0f);
5178  cmat[0], tmat[0], cursor_curr->rotation_axis);
5179  }
5180  else {
5181  BKE_scene_cursor_quat_to_rot(cursor_curr, quat, true);
5182  }
5183  }
5184  }
5185 
5186  /* offset the cursor lock to avoid jumping to new offset */
5187  if (v3d->ob_center_cursor) {
5188  if (U.uiflag & USER_LOCK_CURSOR_ADJUST) {
5189 
5190  float co_2d_curr[2], co_2d_prev[2];
5191 
5193  region, cursor_prev.location, co_2d_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
5195  region, cursor_curr->location, co_2d_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK)) {
5196  rv3d->ofs_lock[0] += (co_2d_curr[0] - co_2d_prev[0]) / (region->winx * 0.5f);
5197  rv3d->ofs_lock[1] += (co_2d_curr[1] - co_2d_prev[1]) / (region->winy * 0.5f);
5198  }
5199  }
5200  else {
5201  /* Cursor may be outside of the view,
5202  * prevent it getting 'lost', see: T40353 & T45301 */
5203  zero_v2(rv3d->ofs_lock);
5204  }
5205  }
5206 
5207  if (v3d->localvd) {
5209  }
5210  else {
5212  }
5213 
5214  {
5215  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
5216  wmMsgParams_RNA msg_key_params = {{0}};
5217  RNA_pointer_create(&scene->id, &RNA_View3DCursor, &scene->cursor, &msg_key_params.ptr);
5218  WM_msg_publish_rna_params(mbus, &msg_key_params);
5219  }
5220 
5222 }
5223 
5224 static int view3d_cursor3d_invoke(bContext *C, wmOperator *op, const wmEvent *event)
5225 {
5226  bool use_depth = (U.uiflag & USER_DEPTH_CURSOR);
5227  {
5228  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_depth");
5229  if (RNA_property_is_set(op->ptr, prop)) {
5230  use_depth = RNA_property_boolean_get(op->ptr, prop);
5231  }
5232  else {
5233  RNA_property_boolean_set(op->ptr, prop, use_depth);
5234  }
5235  }
5236  const enum eV3DCursorOrient orientation = RNA_enum_get(op->ptr, "orientation");
5237  ED_view3d_cursor3d_update(C, event->mval, use_depth, orientation);
5238 
5239  return OPERATOR_FINISHED;
5240 }
5241 
5243 {
5244 
5245  /* identifiers */
5246  ot->name = "Set 3D Cursor";
5247  ot->description = "Set the location of the 3D cursor";
5248  ot->idname = "VIEW3D_OT_cursor3d";
5249 
5250  /* api callbacks */
5252 
5254 
5255  /* flags */
5256  // ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
5257 
5258  PropertyRNA *prop;
5259  static const EnumPropertyItem orientation_items[] = {
5260  {V3D_CURSOR_ORIENT_NONE, "NONE", 0, "None", "Leave orientation unchanged"},
5261  {V3D_CURSOR_ORIENT_VIEW, "VIEW", 0, "View", "Orient to the viewport"},
5263  "XFORM",
5264  0,
5265  "Transform",
5266  "Orient to the current transform setting"},
5267  {V3D_CURSOR_ORIENT_GEOM, "GEOM", 0, "Geometry", "Match the surface normal"},
5268  {0, NULL, 0, NULL, NULL},
5269  };
5270 
5271  prop = RNA_def_boolean(
5272  ot->srna, "use_depth", true, "Surface Project", "Project onto the surface");
5274 
5275  prop = RNA_def_enum(ot->srna,
5276  "orientation",
5277  orientation_items,
5279  "Orientation",
5280  "Preset viewpoint to use");
5282 }
5283 
5286 /* -------------------------------------------------------------------- */
5291  {OB_WIRE, "WIREFRAME", 0, "Wireframe", "Toggle wireframe shading"},
5292  {OB_SOLID, "SOLID", 0, "Solid", "Toggle solid shading"},
5293  {OB_MATERIAL, "MATERIAL", 0, "Material Preview", "Toggle material preview shading"},
5294  {OB_RENDER, "RENDERED", 0, "Rendered", "Toggle rendered shading"},
5295  {0, NULL, 0, NULL, NULL},
5296 };
5297 
5299 {
5300  Main *bmain = CTX_data_main(C);
5301  View3D *v3d = CTX_wm_view3d(C);
5302  ScrArea *area = CTX_wm_area(C);
5303  int type = RNA_enum_get(op->ptr, "type");
5304 
5305  if (type == OB_SOLID) {
5306  if (v3d->shading.type != type) {
5307  v3d->shading.type = type;
5308  }
5309  else if (v3d->shading.type == OB_WIRE) {
5310  v3d->shading.type = OB_SOLID;
5311  }
5312  else {
5313  v3d->shading.type = OB_WIRE;
5314  }
5315  }
5316  else {
5317  char *prev_type = ((type == OB_WIRE) ? &v3d->shading.prev_type_wire : &v3d->shading.prev_type);
5318  if (v3d->shading.type == type) {
5319  if (*prev_type == type || !ELEM(*prev_type, OB_WIRE, OB_SOLID, OB_MATERIAL, OB_RENDER)) {
5320  *prev_type = OB_SOLID;
5321  }
5322  v3d->shading.type = *prev_type;
5323  }
5324  else {
5325  *prev_type = v3d->shading.type;
5326  v3d->shading.type = type;
5327  }
5328  }
5329 
5330  ED_view3d_shade_update(bmain, v3d, area);
5332 
5333  return OPERATOR_FINISHED;
5334 }
5335 
5337 {
5338  PropertyRNA *prop;
5339 
5340  /* identifiers */
5341  ot->name = "Toggle Shading Type";
5342  ot->description = "Toggle shading type in 3D viewport";
5343  ot->idname = "VIEW3D_OT_toggle_shading";
5344 
5345  /* api callbacks */
5348 
5349  prop = RNA_def_enum(
5350  ot->srna, "type", prop_shading_type_items, 0, "Type", "Shading type to toggle");
5352 }
5353 
5356 /* -------------------------------------------------------------------- */
5361 {
5362  View3D *v3d = CTX_wm_view3d(C);
5363  ScrArea *area = CTX_wm_area(C);
5364  Object *obact = CTX_data_active_object(C);
5365 
5366  if (obact && ((obact->mode & OB_MODE_POSE) ||
5367  ((obact->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(obact)))) {
5369  }
5370  else {
5371  const bool xray_active = ((obact && (obact->mode & OB_MODE_EDIT)) ||
5372  ELEM(v3d->shading.type, OB_WIRE, OB_SOLID));
5373 
5374  if (v3d->shading.type == OB_WIRE) {
5376  }
5377  else {
5378  v3d->shading.flag ^= V3D_SHADING_XRAY;
5379  }
5380  if (!xray_active) {
5381  BKE_report(op->reports, RPT_INFO, "X-Ray not available in current mode");
5382  }
5383  }
5384 
5386 
5387  return OPERATOR_FINISHED;
5388 }
5389 
5391 {
5392  /* identifiers */
5393  ot->name = "Toggle X-Ray";
5394  ot->idname = "VIEW3D_OT_toggle_xray";
5395  ot->description = "Transparent scene display. Allow selecting through items";
5396 
5397  /* api callbacks */
5400 }
5401 
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_active(struct Object *ob)
Definition: action.c:708
bool BKE_pose_minmax(struct Object *ob, float r_min[3], float r_max[3], bool use_hidden, bool use_select)
Definition: armature.c:2865
Camera data-block and utility functions.
struct CameraBGImage * BKE_camera_background_image_new(struct Camera *cam)
Definition: camera.c:1131
void BKE_camera_background_image_remove(struct Camera *cam, struct CameraBGImage *bgpic)
Definition: camera.c:1146
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1296
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:252
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
Definition: context.c:456
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1279
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:746
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:769
#define CTX_DATA_END
Definition: BKE_context.h:260
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:699
bool BKE_gpencil_stroke_minmax(const struct bGPDstroke *gps, const bool use_select, float r_min[3], float r_max[3])
struct Object * BKE_view_layer_camera_find(struct ViewLayer *view_layer)
Definition: layer.c:337
#define FOREACH_OBJECT_IN_MODE_END
Definition: BKE_layer.h:284
#define FOREACH_OBJECT_IN_MODE_BEGIN(_view_layer, _v3d, _object_type, _object_mode, _instance)
Definition: BKE_layer.h:280
void id_us_min(struct ID *id)
Definition: lib_id.c:297
General operations, lookup, etc. for blender objects.
bool BKE_object_minmax_dupli(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
Definition: object.c:4138
struct Object * BKE_object_pose_armature_get(struct Object *ob)
Definition: object.c:2487
void BKE_boundbox_calc_center_aabb(const struct BoundBox *bb, float r_cent[3])
void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
Definition: object.c:3964
bool BKE_object_empty_image_frame_is_visible_in_view3d(const struct Object *ob, const struct RegionView3D *rv3d)
bool BKE_paint_select_face_test(struct Object *ob)
Definition: paint.c:968
void BKE_paint_stroke_get_average(struct Scene *scene, struct Object *ob, float stroke[3])
Definition: paint.c:1173
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_scene_cursor_mat3_to_rot(struct View3DCursor *cursor, const float mat[3][3], bool use_compat)
Definition: scene.c:3688
void BKE_scene_cursor_quat_to_rot(struct View3DCursor *cursor, const float quat[4], bool use_compat)
Definition: scene.c:3723
void BKE_scene_cursor_rot_to_quat(const struct View3DCursor *cursor, float quat[4])
float BKE_screen_view3d_zoom_from_fac(float zoomfac)
Definition: screen.c:1085
float BKE_screen_view3d_zoom_to_fac(float camzoom)
Definition: screen.c:1080
#define BLI_assert(a)
Definition: BLI_assert.h:58
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float max_fff(float a, float b, float c)
MINLINE float max_ff(float a, float b)
#define M_SQRT2
Definition: BLI_math_base.h:47
MINLINE float clamp_f(float value, float min, float max)
MINLINE float min_ff(float a, float b)
MINLINE float square_f(float a)
#define M_PI
Definition: BLI_math_base.h:38
MINLINE int axis_dominant_v3_ortho_single(const float vec[3])
float closest_to_line_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3])
Definition: math_geom.c:3364
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
void unit_m3(float m[3][3])
Definition: math_matrix.c:58
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:794
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
bool invert_m3_m3(float R[3][3], const float A[3][3])
Definition: math_matrix.c:1161
bool is_negative_m4(const float mat[4][4])
Definition: math_matrix.c:2590
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
float angle_normalized_qt(const float q[4])
void invert_qt_normalized(float q[4])
void mat3_to_quat(float q[4], const float mat[3][3])
void axis_angle_to_quat(float r[4], const float axis[3], const float angle)
float normalize_qt(float q[4])
#define DEG2RADF(_deg)
void mul_qt_v3(const float q[4], float r[3])
Definition: math_rotation.c:97
void unit_qt(float q[4])
Definition: math_rotation.c:46
void axis_angle_normalized_to_quat(float r[4], const float axis[3], const float angle)
float normalize_qt_qt(float r[4], const float q[4])
void invert_qt_qt_normalized(float q1[4], const float q2[4])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
Definition: math_rotation.c:65
void axis_angle_to_quat_single(float q[4], const char axis, const float angle)
void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle)
void copy_qt_qt(float q[4], const float a[4])
Definition: math_rotation.c:52
float angle_wrap_rad(float angle)
void quat_to_mat3(float mat[3][3], const float q[4])
float angle_signed_qtqt(const float q1[4], const float q2[4])
void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t)
Definition: math_vector.c:49
float angle_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
Definition: math_vector.c:443
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
Definition: math_vector.c:1020
MINLINE bool equals_v4v4(const float a[4], const float b[4]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v3(float r[3])
MINLINE float len_v2v2_int(const int v1[2], const int v2[2])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE bool is_zero_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
void project_plane_v3_v3v3(float out[3], const float p[3], const float v_plane[3])
Definition: math_vector.c:740
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
float angle_signed_on_axis_v3v3_v3(const float v1[3], const float v2[3], const float axis[3]) ATTR_WARN_UNUSED_RESULT
Definition: math_vector.c:551
MINLINE void negate_v3(float r[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void zero_v2(float r[2])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
Definition: math_vector.c:270
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE bool is_zero_v2(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
Definition: math_vector.c:505
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void BLI_rctf_translate(struct rctf *rect, float x, float y)
Definition: rct.c:604
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:157
void BLI_rctf_transform_pt_v(const rctf *dst, const rctf *src, float xy_dst[2], const float xy_src[2])
Definition: rct.c:561
void BLI_rcti_resize_y(struct rcti *rect, int y)
Definition: rct.c:632
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:153
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition: BLI_rect.h:140
void BLI_rcti_resize_x(struct rcti *rect, int x)
Definition: rct.c:626
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:161
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:165
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition: BLI_rect.h:136
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
unsigned int uint
Definition: BLI_sys_types.h:83
#define UNPACK2(a)
#define INIT_MINMAX(min, max)
#define SWAP(type, a, b)
#define UNUSED(x)
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_id_tag_update(struct ID *id, int flag)
struct Object * DEG_get_original_object(struct Object *object)
struct ViewLayer * DEG_get_evaluated_view_layer(const struct Depsgraph *graph)
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
#define MAX_ID_NAME
Definition: DNA_ID.h:269
@ ID_IM
Definition: DNA_ID_enums.h:65
@ ROT_MODE_AXISANGLE
@ CAM_SHOW_BG_IMAGE
@ CAM_BGIMG_SOURCE_IMAGE
@ CAM_BGIMG_SOURCE_MOVIE
#define DEFAULT_SENSOR_WIDTH
@ GP_STROKE_SELECT
@ GP_STROKE_3DSPACE
#define GPENCIL_ANY_MODE(gpd)
@ BASE_SELECTED
#define OB_MODE_ALL_PAINT
@ OB_WIRE
@ OB_SOLID
@ OB_RENDER
@ OB_MATERIAL
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_SCULPT
@ OB_MODE_POSE
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_OBJECT
@ OB_MODE_VERTEX_PAINT
Object is a sort of wrapper for general info.
@ OB_LOCK_LOCY
@ OB_LOCK_LOCZ
@ OB_LOCK_LOCX
@ OB_EMPTY_IMAGE
@ BOUNDBOX_DIRTY
@ OB_NEGZ
@ OB_POSY
@ OB_EMPTY
@ OB_CAMERA
@ OB_FONT
@ OB_ARMATURE
@ OB_GPENCIL
#define BASE_SELECTED_EDITABLE(v3d, base)
#define R_BORDER
#define SCE_SNAP_MODE_FACE
#define FIRSTBASE(_view_layer)
#define OBACT(_view_layer)
#define BASE_VISIBLE(v3d, base)
@ RGN_TYPE_WINDOW
@ FILE_SORT_DEFAULT
@ FILE_SPECIAL
@ FILE_TYPE_MOVIE
@ FILE_TYPE_FOLDER
@ FILE_TYPE_IMAGE
@ FILE_OPENFILE
@ FILE_DEFAULTDISPLAY
eViewNavigation_Method
@ VIEW_NAVIGATION_FLY
@ VIEW_NAVIGATION_WALK
@ USER_DEPTH_CURSOR
@ USER_ORBIT_SELECTION
@ USER_AUTOPERSP
@ USER_LOCK_CURSOR_ADJUST
@ USER_ZOOM_INVERT
@ USER_ZOOM_TO_MOUSEPOS
@ USER_DEPTH_NAVIGATE
@ USER_ZOOM_HORIZ
#define NDOF_PIXELS_PER_SECOND
@ USER_TRACKBALL
eViewZoom_Style
@ USER_ZOOM_SCALE
@ USER_ZOOM_CONTINUE
@ USER_ZOOM_DOLLY
@ NDOF_MODE_ORBIT
@ NDOF_ZOOM_INVERT
@ NDOF_LOCK_HORIZON
@ NDOF_TURNTABLE
@ NDOF_FLY_HELICOPTER
#define RV3D_VIEW_IS_AXIS(view)
#define RV3D_CAMZOOM_MAX
#define V3D_LOCK_CAMERA
#define RV3D_CAMZOOM_MIN_FACTOR
@ V3D_AROUND_ACTIVE
@ V3D_AROUND_CENTER_MEDIAN
#define RV3D_LOCK_FLAGS(rv3d)
#define RV3D_CAMZOOM_MAX_FACTOR
#define RV3D_CAMOB
#define RV3D_VIEW_BACK
#define RV3D_CLIPPING
#define RV3D_CLIPPING_ENABLED(v3d, rv3d)
#define RV3D_VIEW_BOTTOM
#define V3D_RENDER_BORDER
@ RV3D_LOCK_ANY_TRANSFORM
@ RV3D_LOCK_ROTATION
@ RV3D_LOCK_LOCATION
@ RV3D_LOCK_ZOOM_AND_DOLLY
@ RV3D_BOXVIEW
#define RV3D_VIEW_LEFT
#define RV3D_VIEW_RIGHT
#define RV3D_PERSP
#define RV3D_VIEW_TOP
#define RV3D_CAMZOOM_MIN
@ V3D_OVERLAY_BONE_SELECT
@ RV3D_VIEW_AXIS_ROLL_270
@ RV3D_VIEW_AXIS_ROLL_0
#define RV3D_VIEW_USER
@ V3D_SHADING_XRAY_WIREFRAME
@ V3D_SHADING_XRAY
#define RV3D_VIEW_FRONT
#define RV3D_NAVIGATING
#define RV3D_ORTHO
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
@ OPERATOR_PASS_THROUGH
bool paintface_minmax(struct Object *ob, float r_min[3], float r_max[3])
Definition: editface.c:348
int PE_minmax(struct Depsgraph *depsgraph, struct Scene *scene, struct ViewLayer *view_layer, float min[3], float max[3])
void ED_area_tag_redraw(ScrArea *area)
Definition: area.c:745
bScreen * ED_screen_animation_playing(const struct wmWindowManager *wm)
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:667
bool ED_operator_camera(struct bContext *C)
Definition: screen_ops.c:642
bool ED_operator_view3d_active(struct bContext *C)
Definition: screen_ops.c:230
bool ED_operator_region_view3d_active(struct bContext *C)
Definition: screen_ops.c:235
void ED_transform_calc_orientation_from_type(const struct bContext *C, float r_mat[3][3])
bool calculateTransformCenter(struct bContext *C, int centerMode, float cent3d[3], float cent2d[2])
Definition: transform.c:1259
void ED_getTransformOrientationMatrix(const struct bContext *C, struct Object *ob, struct Object *obedit, const short around, float r_orientation_mat[3][3])
SnapObjectContext * ED_transform_snap_object_context_create_view3d(struct Scene *scene, int flag, const struct ARegion *region, const struct View3D *v3d)
short ED_transform_snap_object_project_view3d_ex(struct SnapObjectContext *sctx, struct Depsgraph *depsgraph, const unsigned short snap_to, const struct SnapObjectParams *params, const float mval[2], const float prev_co[3], float *dist_px, float r_loc[3], float r_no[3], int *r_index, struct Object **r_ob, float r_obmat[4][4])
void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx)
void ED_view3d_depth_tag_update(struct RegionView3D *rv3d)
void ED_view3d_persp_switch_from_camera(const struct Depsgraph *depsgraph, struct View3D *v3d, struct RegionView3D *rv3d, const char persp)
bool ED_view3d_camera_lock_sync(const struct Depsgraph *depsgraph, struct View3D *v3d, struct RegionView3D *rv3d)
void ED_view3d_calc_camera_border(const struct Scene *scene, struct Depsgraph *depsgraph, const struct ARegion *region, const struct View3D *v3d, const struct RegionView3D *rv3d, struct rctf *r_viewborder, const bool no_shift)
float ED_view3d_radius_to_dist(const struct View3D *v3d, const struct ARegion *region, const struct Depsgraph *depsgraph, const char persp, const bool use_aspect, const float radius)
void ED_view3d_calc_camera_border_size(const struct Scene *scene, struct Depsgraph *depsgraph, const struct ARegion *region, const struct View3D *v3d, const struct RegionView3D *rv3d, float r_size[2])
bool ED_view3d_clipping_clamp_minmax(const struct RegionView3D *rv3d, float min[3], float max[3])
char ED_view3d_axis_view_opposite(char view)
@ V3D_PROJ_TEST_NOP
Definition: ED_view3d.h:193
void ED_view3d_win_to_3d_int(const struct View3D *v3d, const struct ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
bool ED_view3d_camera_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d)
bool ED_operator_rv3d_user_region_poll(struct bContext *C)
Definition: view3d_view.c:684
bool ED_view3d_quat_to_axis_view(const float viewquat[4], const float epsilon, char *r_view, char *r_view_axis_rotation)
void ED_view3d_dist_range_get(const struct View3D *v3d, float r_dist_range[2])
@ V3D_PROJ_RET_OK
Definition: ED_view3d.h:176
void ED_view3d_win_to_delta(const struct ARegion *region, const float mval[2], float out[3], const float zfac)
bool ED_view3d_quat_from_axis_view(const char view, const char view_axis_roll, float r_quat[4])
bool ED_view3d_offset_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d)
#define VIEW3D_MARGIN
Definition: ED_view3d.h:675
bool ED_view3d_persp_ensure(const struct Depsgraph *depsgraph, struct View3D *v3d, struct ARegion *region)
void ED_view3d_clipping_calc_from_boundbox(float clip[6][4], const struct BoundBox *clipbb, const bool is_flip)
void ED_view3d_from_object(const struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens)
bool ED_view3d_camera_lock_autokey(struct View3D *v3d, struct RegionView3D *rv3d, struct bContext *C, const bool do_rotate, const bool do_translate)
Definition: view3d_utils.c:710
void ED_view3d_win_to_vector(const struct ARegion *region, const float mval[2], float out[3])
void ED_view3d_camera_lock_init_ex(const struct Depsgraph *depsgraph, struct View3D *v3d, struct RegionView3D *rv3d, const bool calc_dist)
void ED_view3d_distance_set(struct RegionView3D *rv3d, const float dist)
bool ED_view3d_autodist(struct Depsgraph *depsgraph, struct ARegion *region, struct View3D *v3d, const int mval[2], float mouse_worldloc[3], const bool alphaoverride, const float fallback_depth_pt[3])
@ V3D_DEPTH_NO_GPENCIL
Definition: ED_view3d.h:148
eV3DCursorOrient
Definition: ED_view3d.h:98
@ V3D_CURSOR_ORIENT_XFORM
Definition: ED_view3d.h:101
@ V3D_CURSOR_ORIENT_GEOM
Definition: ED_view3d.h:102
@ V3D_CURSOR_ORIENT_VIEW
Definition: ED_view3d.h:100
@ V3D_CURSOR_ORIENT_NONE
Definition: ED_view3d.h:99
void ED_view3d_depth_override(struct Depsgraph *depsgraph, struct ARegion *region, struct View3D *v3d, struct Object *obact, eV3DDepthOverrideMode mode, bool update_cache)
Definition: view3d_draw.c:2331
void ED_view3d_clipping_calc(struct BoundBox *bb, float planes[4][4], const struct ARegion *region, const struct Object *ob, const struct rcti *rect)
void ED_view3d_lastview_store(struct RegionView3D *rv3d)
Definition: view3d_utils.c:487
void ED_view3d_win_to_3d(const struct View3D *v3d, const struct ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
void ED_view3d_camera_lock_init(const struct Depsgraph *depsgraph, struct View3D *v3d, struct RegionView3D *rv3d)
void view3d_operator_needs_opengl(const struct bContext *C)
struct RegionView3D * ED_view3d_context_rv3d(struct bContext *C)
Definition: space_view3d.c:89
bool ED_view3d_unproject(const struct ARegion *region, float regionx, float regiony, float regionz, float world[3])
eV3DProjStatus ED_view3d_project_float_global(const struct ARegion *region, const float co[3], float r_co[2], const eV3DProjTest flag)
void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrArea *area)
Definition: space_view3d.c:248
bool ED_view3d_context_user_region(struct bContext *C, struct View3D **r_v3d, struct ARegion **r_region)
Definition: space_view3d.c:107
void ED_view3d_lock_clear(struct View3D *v3d)
Definition: view3d_utils.c:497
float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip)
static AppView * view
NSNotificationCenter * center
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
static void axis_limit(const int axis, const float limits[2], float co[3], float dcut[3])
Group RGB to Bright Vector Camera CLAMP
Platform independent time functions.
StructRNA RNA_Camera
StructRNA RNA_View3DCursor
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_HIDDEN
Definition: RNA_types.h:202
#define C
Definition: RandGen.cpp:39
#define WM_FILESEL_RELPATH
Definition: WM_api.h:533
#define WM_FILESEL_FILEPATH
Definition: WM_api.h:537
@ OPTYPE_BLOCKING
Definition: WM_types.h:157
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_GRAB_CURSOR_XY
Definition: WM_types.h:161
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define ND_RENDER_OPTIONS
Definition: WM_types.h:335
#define KM_ANY
Definition: WM_types.h:240
@ WM_OP_INVOKE_DEFAULT
Definition: WM_types.h:197
#define NC_SCENE
Definition: WM_types.h:279
#define NA_EDITED
Definition: WM_types.h:462
#define KM_PRESS
Definition: WM_types.h:242
#define NC_CAMERA
Definition: WM_types.h:302
#define ND_SPACE_VIEW3D
Definition: WM_types.h:423
@ P_FINISHING
Definition: WM_types.h:655
#define NC_SPACE
Definition: WM_types.h:293
#define ND_DRAW_RENDER_VIEWPORT
Definition: WM_types.h:370
#define KM_RELEASE
Definition: WM_types.h:243
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
#define SELECT
double time
Scene scene
const Depsgraph * depsgraph
#define rot(x, k)
IconTextureDrawCall border
#define asinf(x)
#define fabsf(x)
#define sqrtf(x)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static void area(int d1, int d2, int e1, int e2, float weights[2])
return ret
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2941
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6655
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6319
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2331
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Definition: rna_access.c:2358
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:6685
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3825
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
#define min(a, b)
Definition: sort.c:51
void * regiondata
struct ARegion * next
short regiontype
struct wmGizmoMap * gizmo_map
struct Base * next
struct Object * object
float vec[3][3]
float vec[8][3]
struct MovieClip * clip
struct Image * ima
struct ListBase bg_images
struct EditFont * editfont
char name[64]
Definition: BKE_armature.h:57
float textcurs[4][2]
Definition: BKE_font.h:52
Definition: DNA_ID.h:273
struct ID * orig_id
Definition: DNA_ID.h:324
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct BoundBox * bb
char empty_drawtype
Object_Runtime runtime
float obmat[4][4]
float quat[4]
void * data
void * data
Definition: RNA_types.h:52
float viewquat[4]
float persmat[4][4]
float lviewquat[4]
float clip[6][4]
float clip_local[6][4]
struct wmTimer * smooth_timer
float viewinv[4][4]
struct BoundBox * clipbb
struct RenderData r
View3DCursor cursor
struct Object * camera
ListBase spacedata
const struct ARegion * region
const struct View3D * v3d
float rotation_axis[3]
View3DOverlay overlay
rctf render_border
struct Object * camera
struct View3D * localvd
char ob_center_bone[64]
short scenelock
short ob_center_cursor
struct Object * ob_center
View3DShading shading
float clip_start
float * depths
Definition: ED_view3d.h:91
ListBase object_bases
float reverse
Definition: view3d_edit.c:230
View3D * v3d
Definition: view3d_edit.c:180
int event_xy[2]
Definition: view3d_edit.c:193
float viewquat[4]
Definition: view3d_edit.c:227
struct ViewOpsData::@543 curr
float dyn_ofs[3]
Definition: view3d_edit.c:234
bool use_dyn_ofs
Definition: view3d_edit.c:235
double time
Definition: view3d_edit.c:219
Depsgraph * depsgraph
Definition: view3d_edit.c:182
wmTimer * timer
Definition: view3d_edit.c:185
float camzoom
Definition: view3d_edit.c:190
ARegion * region
Definition: view3d_edit.c:179
struct ViewOpsData::@542 prev
bool axis_snap
Definition: view3d_edit.c:231
float quat[4]
Definition: view3d_edit.c:191
float trackvec[3]
Definition: view3d_edit.c:204
int event_xy_offset[2]
Definition: view3d_edit.c:196
ScrArea * area
Definition: view3d_edit.c:178
RegionView3D * rv3d
Definition: view3d_edit.c:181
float mousevec[3]
Definition: view3d_edit.c:206
Main * bmain
Definition: view3d_edit.c:176
struct ViewOpsData::@541 init
Scene * scene
Definition: view3d_edit.c:177
float ofs[3]
Definition: view3d_edit.c:199
float xmax
Definition: DNA_vec_types.h:85
float xmin
Definition: DNA_vec_types.h:85
float ymax
Definition: DNA_vec_types.h:86
float ymin
Definition: DNA_vec_types.h:86
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int xmax
Definition: DNA_vec_types.h:79
int y
Definition: WM_types.h:581
short val
Definition: WM_types.h:579
char is_direction_inverted
Definition: WM_types.h:638
int mval[2]
Definition: WM_types.h:583
int prevy
Definition: WM_types.h:614
int x
Definition: WM_types.h:581
int prevx
Definition: WM_types.h:614
short type
Definition: WM_types.h:577
void * customdata
Definition: WM_types.h:631
const void * modal_items
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:768
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:760
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
PropertyRNA * prop
Definition: WM_types.h:814
struct ReportList * reports
struct PointerRNA * ptr
struct wmWindow * win
Definition: WM_types.h:693
double PIL_check_seconds_timer(void)
Definition: time.c:80
float max
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
void view3d_update_depths_rect(ARegion *region, ViewDepths *d, rcti *rect)
Definition: view3d_draw.c:2212
float view3d_depth_near(ViewDepths *d)
Definition: view3d_draw.c:2300
static void viewzoom_apply(ViewOpsData *vod, const int xy[2], const eViewZoom_Style viewzoom, const bool zoom_invert, const bool zoom_to_pos)
Definition: view3d_edit.c:2196
void ED_view3d_cursor3d_update(bContext *C, const int mval[2], const bool use_depth, enum eV3DCursorOrient orientation)
Definition: view3d_edit.c:5151
void viewmove_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_edit.c:1692
static void view_zoom_to_window_xy_camera(Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, float dfac, const int zoom_xy[2])
Definition: view3d_edit.c:1925
static int toggle_xray_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:5360
static void viewdolly_cancel(bContext *C, wmOperator *op)
Definition: view3d_edit.c:2734
void VIEW3D_OT_view_roll(wmOperatorType *ot)
Definition: view3d_edit.c:4578
static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
Definition: view3d_edit.c:303
static void view3d_from_minmax_multi(bContext *C, View3D *v3d, const float min[3], const float max[3], const bool ok_dist, const int smooth_viewtx)
Definition: view3d_edit.c:2896
static int view3d_center_lock_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_edit.c:3431
static int view3d_clipping_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:4945
struct ViewOpsData ViewOpsData
void VIEW3D_OT_view_axis(wmOperatorType *ot)
Definition: view3d_edit.c:4078
static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: view3d_edit.c:4795
static int view_camera_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:4110
static int view_axis_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:3968
static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2])
Definition: view3d_edit.c:775
static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:2651
static void viewrotate_cancel(bContext *C, wmOperator *op)
Definition: view3d_edit.c:1030
static int view3d_clipping_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:4928
static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:910
static void viewmove_cancel(bContext *C, wmOperator *op)
Definition: view3d_edit.c:1856
static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *region, const float min[3], const float max[3], bool ok_dist, const int smooth_viewtx)
Definition: view3d_edit.c:2810
void VIEW3D_OT_view_orbit(wmOperatorType *ot)
Definition: view3d_edit.c:4337
static int view3d_cursor3d_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:5224
void ED_view3d_cursor3d_position_rotation(bContext *C, const int mval[2], const bool use_depth, enum eV3DCursorOrient orientation, float cursor_co[3], float cursor_quat[4])
Definition: view3d_edit.c:5035
static void viewroll_cancel(bContext *C, wmOperator *op)
Definition: view3d_edit.c:4573
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])
Definition: view3d_edit.c:286
static int background_image_remove_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:4854
void VIEW3D_OT_view_persportho(wmOperatorType *ot)
Definition: view3d_edit.c:4712
static int viewselected_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:3023
static const EnumPropertyItem prop_shading_type_items[]
Definition: view3d_edit.c:5290
static Camera * background_image_camera_from_context(bContext *C)
Definition: view3d_edit.c:4773
eViewOpsFlag
Definition: view3d_edit.c:389
@ VIEWOPS_FLAG_USE_MOUSE_INIT
Definition: view3d_edit.c:401
@ VIEWOPS_FLAG_ORBIT_SELECT
Definition: view3d_edit.c:391
@ VIEWOPS_FLAG_DEPTH_NAVIGATE
Definition: view3d_edit.c:393
@ VIEWOPS_FLAG_PERSP_ENSURE
Definition: view3d_edit.c:399
static void viewzoom_apply_3d(ViewOpsData *vod, const int xy[2], const eViewZoom_Style viewzoom, const bool zoom_invert, const bool zoom_to_pos)
Definition: view3d_edit.c:2154
static void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4])
Definition: view3d_edit.c:649
static void view_dolly_to_vector_3d(ARegion *region, const float orig_ofs[3], const float dvec[3], float dfac)
Definition: view3d_edit.c:2501
static void viewops_data_create(bContext *C, wmOperator *op, const wmEvent *event, enum eViewOpsFlag viewops_flag)
Definition: view3d_edit.c:426
static void axis_set_view(bContext *C, View3D *v3d, ARegion *region, const float quat_[4], char view, char view_axis_roll, int perspo, const float *align_to_quat, const int smooth_viewtx)
Definition: view3d_edit.c:3870
static bool view3d_camera_user_poll(bContext *C)
Definition: view3d_edit.c:89
static int vieworbit_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:4239
static int viewpersportho_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_edit.c:4688
static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_edit.c:3379
static const EnumPropertyItem prop_view_orbit_items[]
Definition: view3d_edit.c:4231
void VIEW3D_OT_toggle_xray(wmOperatorType *ot)
Definition: view3d_edit.c:5390
static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:972
static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_edit.c:3816
static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:1764
void VIEW3D_OT_zoom_border(wmOperatorType *ot)
Definition: view3d_edit.c:3771
void VIEW3D_OT_rotate(wmOperatorType *ot)
Definition: view3d_edit.c:1035
void VIEW3D_OT_view_center_camera(wmOperatorType *ot)
Definition: view3d_edit.c:3410
static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:2211
@ V3D_VIEW_PANLEFT
Definition: view3d_edit.c:4611
@ V3D_VIEW_PANDOWN
Definition: view3d_edit.c:4613
@ V3D_VIEW_PANUP
Definition: view3d_edit.c:4614
@ V3D_VIEW_PANRIGHT
Definition: view3d_edit.c:4612
void VIEW3D_OT_view_center_lock(wmOperatorType *ot)
Definition: view3d_edit.c:3442
static void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3])
Definition: view3d_edit.c:244
void VIEW3D_OT_zoom_camera_1_to_1(wmOperatorType *ot)
Definition: view3d_edit.c:3834
static void viewmove_apply(ViewOpsData *vod, int x, int y)
Definition: view3d_edit.c:1728
void VIEW3D_OT_clip_border(wmOperatorType *ot)
Definition: view3d_edit.c:4962
static float viewzoom_scale_value(const rcti *winrct, const eViewZoom_Style viewzoom, const bool zoom_invert, const bool zoom_invert_force, const int xy_curr[2], const int xy_init[2], const float val, const float val_orig, double *r_timer_lastdraw)
Definition: view3d_edit.c:2016
static int view_lock_to_active_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_edit.c:3225
static bool view3d_object_skip_minmax(const View3D *v3d, const RegionView3D *rv3d, const Object *ob, const bool skip_camera, bool *r_only_center)
Definition: view3d_edit.c:2769
#define TRACKBALLSIZE
Definition: view3d_edit.c:242
static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_edit.c:4787
static const EnumPropertyItem prop_view_roll_items[]
Definition: view3d_edit.c:4468
static void viewops_data_free(bContext *C, wmOperator *op)
Definition: view3d_edit.c:568
static int toggle_shading_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:5298
void VIEW3D_OT_view_lock_to_active(wmOperatorType *ot)
Definition: view3d_edit.c:3260
static bool viewdolly_offset_lock_check(bContext *C, wmOperator *op)
Definition: view3d_edit.c:2490
static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:4633
static void view3d_set_1_to_1_viewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, View3D *v3d)
Definition: view3d_edit.c:3801
void VIEW3D_OT_view_pan(wmOperatorType *ot)
Definition: view3d_edit.c:4663
void VIEW3D_OT_cursor3d(wmOperatorType *ot)
Definition: view3d_edit.c:5242
static int viewzoom_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:2273
eV3D_OpPropFlag
Definition: view3d_edit.c:138
@ V3D_OP_PROP_USE_MOUSE_INIT
Definition: view3d_edit.c:142
@ V3D_OP_PROP_DELTA
Definition: view3d_edit.c:140
@ V3D_OP_PROP_USE_ALL_REGIONS
Definition: view3d_edit.c:141
@ V3D_OP_PROP_MOUSE_CO
Definition: view3d_edit.c:139
void ED_view3d_clipping_local(RegionView3D *rv3d, const float mat[4][4])
Definition: view3d_edit.c:4921
static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:2545
void VIEW3D_OT_clear_render_border(wmOperatorType *ot)
Definition: view3d_edit.c:3596
void VIEW3D_OT_background_image_add(wmOperatorType *ot)
Definition: view3d_edit.c:4820
static enum eViewOpsFlag viewops_flag_from_prefs(void)
Definition: view3d_edit.c:417
static void view_roll_angle(ARegion *region, float quat[4], const float orig_quat[4], const float dvec[3], float angle)
Definition: view3d_edit.c:4367
void VIEW3D_OT_view_lock_clear(wmOperatorType *ot)
Definition: view3d_edit.c:3203
static bool view3d_zoom_or_dolly_poll(bContext *C)
Definition: view3d_edit.c:125
static int view3d_all_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:2917
static void view3d_object_calc_minmax(Depsgraph *depsgraph, Scene *scene, Object *ob_eval, const bool only_center, float min[3], float max[3])
Definition: view3d_edit.c:2791
static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:1818
static void viewops_data_alloc(bContext *C, wmOperator *op)
Definition: view3d_edit.c:271
void VIEW3D_OT_view_all(wmOperatorType *ot)
Definition: view3d_edit.c:2996
static void viewzoom_cancel(bContext *C, wmOperator *op)
Definition: view3d_edit.c:2421
static void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3D_OpPropFlag flag)
Definition: view3d_edit.c:145
void viewzoom_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_edit.c:1890
static void viewzoom_apply_camera(ViewOpsData *vod, const int xy[2], const eViewZoom_Style viewzoom, const bool zoom_invert, const bool zoom_to_pos)
Definition: view3d_edit.c:2119
void VIEW3D_OT_navigate(wmOperatorType *ot)
Definition: view3d_edit.c:4754
static bool background_image_add_poll(bContext *C)
Definition: view3d_edit.c:4815
@ HAS_ROTATE
Definition: view3d_edit.c:85
@ HAS_TRANSLATE
Definition: view3d_edit.c:84
static void calc_local_clipping(float clip_local[6][4], const BoundBox *clipbb, const float mat[4][4])
Definition: view3d_edit.c:4905
static enum eViewOpsFlag viewops_flag_from_args(bool use_select, bool use_depth)
Definition: view3d_edit.c:404
static int view_lock_clear_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_edit.c:3188
static int render_border_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:3463
static int viewdolly_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:2598
void VIEW3D_OT_view_selected(wmOperatorType *ot)
Definition: view3d_edit.c:3164
static float viewzoom_scale_value_offset(const rcti *winrct, const eViewZoom_Style viewzoom, const bool zoom_invert, const bool zoom_invert_force, const int xy_curr[2], const int xy_init[2], const int xy_offset[2], const float val, const float val_orig, double *r_timer_lastdraw)
Definition: view3d_edit.c:2089
static const EnumPropertyItem prop_view_items[]
Definition: view3d_edit.c:3855
void viewrotate_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_edit.c:615
void VIEW3D_OT_zoom(wmOperatorType *ot)
Definition: view3d_edit.c:2426
@ V3D_VIEW_STEPRIGHT
Definition: view3d_edit.c:4226
@ V3D_VIEW_STEPUP
Definition: view3d_edit.c:4228
@ V3D_VIEW_STEPLEFT
Definition: view3d_edit.c:4225
@ V3D_VIEW_STEPDOWN
Definition: view3d_edit.c:4227
void ED_view3d_cursor3d_position(bContext *C, const int mval[2], const bool use_depth, float cursor_co[3])
Definition: view3d_edit.c:4993
@ VIEWROT_MODAL_SWITCH_ROTATE
Definition: view3d_edit.c:611
@ VIEWROT_MODAL_AXIS_SNAP_ENABLE
Definition: view3d_edit.c:607
@ VIEWROT_MODAL_SWITCH_MOVE
Definition: view3d_edit.c:610
@ VIEW_MODAL_CONFIRM
Definition: view3d_edit.c:606
@ VIEWROT_MODAL_SWITCH_ZOOM
Definition: view3d_edit.c:609
@ VIEWROT_MODAL_AXIS_SNAP_DISABLE
Definition: view3d_edit.c:608
void VIEW3D_OT_view_camera(wmOperatorType *ot)
Definition: view3d_edit.c:4201
void viewdolly_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_edit.c:2459
static int clear_render_border_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_edit.c:3564
void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
Definition: view3d_edit.c:3358
static void viewdolly_apply(ViewOpsData *vod, const int xy[2], const short zoom_invert)
Definition: view3d_edit.c:2510
void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
Definition: view3d_edit.c:3306
static const EnumPropertyItem prop_view_pan_items[]
Definition: view3d_edit.c:4617
static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:3617
static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:4415
static int viewcenter_cursor_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:3282
static void viewroll_apply(ViewOpsData *vod, int x, int UNUSED(y))
Definition: view3d_edit.c:4384
static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:4536
static int viewroll_exec(bContext *C, wmOperator *op)
Definition: view3d_edit.c:4475
@ VIEW_CONFIRM
Definition: view3d_edit.c:601
@ VIEW_PASS
Definition: view3d_edit.c:599
@ VIEW_APPLY
Definition: view3d_edit.c:600
void VIEW3D_OT_render_border(wmOperatorType *ot)
Definition: view3d_edit.c:3536
static void viewrotate_apply_snap(ViewOpsData *vod)
Definition: view3d_edit.c:658
static bool view3d_lock_poll(bContext *C)
Definition: view3d_edit.c:104
void VIEW3D_OT_background_image_remove(wmOperatorType *ot)
Definition: view3d_edit.c:4878
void VIEW3D_OT_toggle_shading(wmOperatorType *ot)
Definition: view3d_edit.c:5336
void VIEW3D_OT_move(wmOperatorType *ot)
Definition: view3d_edit.c:1861
static int view3d_navigate_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
Definition: view3d_edit.c:4735
static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:3327
static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoom_xy[2])
Definition: view3d_edit.c:1978
static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: view3d_edit.c:2357
void VIEW3D_OT_dolly(wmOperatorType *ot)
Definition: view3d_edit.c:2739
static bool view3d_pan_poll(bContext *C)
Definition: view3d_edit.c:116
bool ED_view3d_minmax_verts(struct Object *obedit, float min[3], float max[3])
Definition: view3d_snap.c:985
void ED_view3d_smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *region, const int smooth_viewtx, const V3D_SmoothParams *sview)
void ED_view3d_smooth_view_force_finish(struct bContext *C, struct View3D *v3d, struct ARegion *region)
Definition: view3d_view.c:428
void view3d_boxview_sync(struct ScrArea *area, struct ARegion *region)
Definition: view3d_utils.c:889
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
int WM_operator_name_call(bContext *C, const char *opstring, short context, PointerRNA *properties)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
@ MOUSEPAN
@ TIMER
@ EVT_MODAL_MAP
@ MOUSEZOOM
@ MOUSEROTATE
@ MOUSEMOVE
@ LEFTMOUSE
@ NDOF_MOTION
@ MIDDLEMOUSE
@ EVT_ESCKEY
wmOperatorType * ot
Definition: wm_files.c:3156
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
int WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
bool WM_gizmomap_is_any_selected(const wmGizmoMap *gzmap)
Definition: wm_gizmo_map.c:244
bool WM_gizmomap_minmax(const wmGizmoMap *gzmap, bool UNUSED(use_hidden), bool use_select, float r_min[3], float r_max[3])
Definition: wm_gizmo_map.c:252
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition: wm_keymap.c:914
wmKeyMapItem * WM_modalkeymap_add_item(wmKeyMap *km, int type, int val, int modifier, int keymodifier, int value)
Definition: wm_keymap.c:927
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
Definition: wm_keymap.c:985
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition: wm_keymap.c:888
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)
void WM_msg_publish_rna_params(struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
void WM_operator_properties_border_to_rcti(struct wmOperator *op, rcti *rect)
void WM_operator_properties_border(wmOperatorType *ot)
void WM_operator_properties_use_cursor_init(wmOperatorType *ot)
void WM_operator_properties_gesture_box_zoom(wmOperatorType *ot)
void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type, short action, short flag, short display, short sort)
int WM_operator_smooth_viewtx_get(const wmOperator *op)
Definition: wm_operators.c:944
ID * WM_operator_drop_load_path(struct bContext *C, wmOperator *op, const short idcode)
void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer *timer)
Definition: wm_window.c:1669
wmTimer * WM_event_add_timer(wmWindowManager *wm, wmWindow *win, int event_type, double timestep)
Definition: wm_window.c:1632