Blender  V3.3
view3d_view.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2008 Blender Foundation. All rights reserved. */
3 
8 #include "MEM_guardedalloc.h"
9 
10 #include "BLI_linklist.h"
11 #include "BLI_listbase.h"
12 #include "BLI_math.h"
13 #include "BLI_rect.h"
14 
15 #include "BKE_action.h"
16 #include "BKE_context.h"
17 #include "BKE_global.h"
18 #include "BKE_gpencil_modifier.h"
19 #include "BKE_idprop.h"
20 #include "BKE_layer.h"
21 #include "BKE_lib_id.h"
22 #include "BKE_main.h"
23 #include "BKE_modifier.h"
24 #include "BKE_object.h"
25 #include "BKE_report.h"
26 #include "BKE_scene.h"
27 
28 #include "DEG_depsgraph_query.h"
29 
30 #include "UI_resources.h"
31 
32 #include "GPU_matrix.h"
33 #include "GPU_select.h"
34 #include "GPU_state.h"
35 
36 #include "WM_api.h"
37 
38 #include "ED_object.h"
39 #include "ED_screen.h"
40 
41 #include "DRW_engine.h"
42 
43 #include "RNA_access.h"
44 #include "RNA_define.h"
45 
46 #include "view3d_intern.h" /* own include */
47 #include "view3d_navigate.h"
48 
49 /* -------------------------------------------------------------------- */
54 {
56  View3D *v3d;
57  ARegion *region;
58  RegionView3D *rv3d;
59 
61 
62  ED_view3d_context_user_region(C, &v3d, &region);
63  rv3d = region->regiondata;
64 
66 
68 
69  ED_view3d_to_object(depsgraph, v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist);
70 
72 
74  rv3d->persp = RV3D_CAMOB;
75 
77 
78  return OPERATOR_FINISHED;
79 }
80 
82 {
83  View3D *v3d;
84  ARegion *region;
85 
86  if (ED_view3d_context_user_region(C, &v3d, &region)) {
87  RegionView3D *rv3d = region->regiondata;
88  if (v3d && v3d->camera && BKE_id_is_editable(CTX_data_main(C), &v3d->camera->id)) {
89  if (rv3d && (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) {
90  if (rv3d->persp != RV3D_CAMOB) {
91  return true;
92  }
93  }
94  }
95  }
96 
97  return false;
98 }
99 
101 {
102  /* identifiers */
103  ot->name = "Align Camera to View";
104  ot->description = "Set camera view to active view";
105  ot->idname = "VIEW3D_OT_camera_to_view";
106 
107  /* api callbacks */
110 
111  /* flags */
113 }
114 
117 /* -------------------------------------------------------------------- */
121 /* unlike VIEW3D_OT_view_selected this is for framing a render and not
122  * meant to take into account vertex/bone selection for eg. */
124 {
125  Main *bmain = CTX_data_main(C);
128  View3D *v3d = CTX_wm_view3d(C); /* can be NULL */
129  Object *camera_ob = v3d ? v3d->camera : scene->camera;
130 
131  if (camera_ob == NULL) {
132  BKE_report(op->reports, RPT_ERROR, "No active camera");
133  return OPERATOR_CANCELLED;
134  }
135 
136  if (ED_view3d_camera_to_view_selected(bmain, depsgraph, scene, camera_ob)) {
138  return OPERATOR_FINISHED;
139  }
140  return OPERATOR_CANCELLED;
141 }
142 
144 {
145  /* identifiers */
146  ot->name = "Camera Fit Frame to Selected";
147  ot->description = "Move the camera so selected objects are framed";
148  ot->idname = "VIEW3D_OT_camera_to_view_selected";
149 
150  /* api callbacks */
153 
154  /* flags */
156 }
157 
160 /* -------------------------------------------------------------------- */
165  View3D *v3d,
166  Object *ob,
167  const int smooth_viewtx)
168 {
169  Main *bmain = CTX_data_main(C);
170  for (bScreen *screen = bmain->screens.first; screen != NULL; screen = screen->id.next) {
171  for (ScrArea *area = screen->areabase.first; area != NULL; area = area->next) {
172  for (SpaceLink *space_link = area->spacedata.first; space_link != NULL;
173  space_link = space_link->next) {
174  if (space_link->spacetype == SPACE_VIEW3D) {
175  View3D *other_v3d = (View3D *)space_link;
176  if (other_v3d == v3d) {
177  continue;
178  }
179  if (other_v3d->camera == ob) {
180  continue;
181  }
182  /* Checking the other view is needed to prevent local cameras being modified. */
183  if (v3d->scenelock && other_v3d->scenelock) {
184  ListBase *lb = (space_link == area->spacedata.first) ? &area->regionbase :
185  &space_link->regionbase;
186  for (ARegion *other_region = lb->first; other_region != NULL;
187  other_region = other_region->next) {
188  if (other_region->regiontype == RGN_TYPE_WINDOW) {
189  if (other_region->regiondata) {
190  RegionView3D *other_rv3d = other_region->regiondata;
191  if (other_rv3d->persp == RV3D_CAMOB) {
192  Object *other_camera_old = other_v3d->camera;
193  other_v3d->camera = ob;
194  ED_view3d_lastview_store(other_rv3d);
196  other_v3d,
197  other_region,
198  smooth_viewtx,
199  &(const V3D_SmoothParams){
200  .camera_old = other_camera_old,
201  .camera = other_v3d->camera,
202  .ofs = other_rv3d->ofs,
203  .quat = other_rv3d->viewquat,
204  .dist = &other_rv3d->dist,
205  .lens = &other_v3d->lens,
206  /* No undo because this switches cameras. */
207  .undo_str = NULL,
208  });
209  }
210  else {
211  other_v3d->camera = ob;
212  }
213  }
214  }
215  }
216  }
217  }
218  }
219  }
220  }
221 }
222 
224 {
225  View3D *v3d;
226  ARegion *region;
227  RegionView3D *rv3d;
228 
231 
232  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
233 
234  /* no NULL check is needed, poll checks */
235  ED_view3d_context_user_region(C, &v3d, &region);
236  rv3d = region->regiondata;
237 
238  if (ob) {
239  Object *camera_old = (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : NULL;
240  rv3d->persp = RV3D_CAMOB;
241  v3d->camera = ob;
242  if (v3d->scenelock && scene->camera != ob) {
243  scene->camera = ob;
245  }
246 
247  /* unlikely but looks like a glitch when set to the same */
248  if (camera_old != ob) {
250 
252  v3d,
253  region,
254  smooth_viewtx,
255  &(const V3D_SmoothParams){
256  .camera_old = camera_old,
257  .camera = v3d->camera,
258  .ofs = rv3d->ofs,
259  .quat = rv3d->viewquat,
260  .dist = &rv3d->dist,
261  .lens = &v3d->lens,
262  /* No undo because this switches cameras. */
263  .undo_str = NULL,
264  });
265  }
266 
267  if (v3d->scenelock) {
268  sync_viewport_camera_smoothview(C, v3d, ob, smooth_viewtx);
270  }
272  }
273 
274  return OPERATOR_FINISHED;
275 }
276 
278 {
279  View3D *v3d_dummy;
280  ARegion *region_dummy;
281 
282  return ED_view3d_context_user_region(C, &v3d_dummy, &region_dummy);
283 }
284 
286 {
287  /* identifiers */
288  ot->name = "Set Active Object as Camera";
289  ot->description = "Set the active object as the active camera for this view or scene";
290  ot->idname = "VIEW3D_OT_object_as_camera";
291 
292  /* api callbacks */
295 
296  /* flags */
298 }
299 
302 /* -------------------------------------------------------------------- */
307  ARegion *region,
308  const View3D *v3d,
309  const rcti *rect)
310 {
311  RegionView3D *rv3d = region->regiondata;
312  rctf full_viewplane;
313  float clipsta, clipend;
314  bool is_ortho;
315 
316  is_ortho = ED_view3d_viewplane_get(
317  depsgraph, v3d, rv3d, region->winx, region->winy, &full_viewplane, &clipsta, &clipend, NULL);
318  rv3d->is_persp = !is_ortho;
319 
320 #if 0
321  printf("%s: %d %d %f %f %f %f %f %f\n",
322  __func__,
323  winx,
324  winy,
325  full_viewplane.xmin,
326  full_viewplane.ymin,
327  full_viewplane.xmax,
328  full_viewplane.ymax,
329  clipsta,
330  clipend);
331 #endif
332 
333  /* Note the code here was tweaked to avoid an apparent compiler bug in clang 13 (see T91680). */
334  rctf viewplane;
335  if (rect) {
336  /* Smaller viewplane subset for selection picking. */
337  viewplane.xmin = full_viewplane.xmin +
338  (BLI_rctf_size_x(&full_viewplane) * (rect->xmin / (float)region->winx));
339  viewplane.ymin = full_viewplane.ymin +
340  (BLI_rctf_size_y(&full_viewplane) * (rect->ymin / (float)region->winy));
341  viewplane.xmax = full_viewplane.xmin +
342  (BLI_rctf_size_x(&full_viewplane) * (rect->xmax / (float)region->winx));
343  viewplane.ymax = full_viewplane.ymin +
344  (BLI_rctf_size_y(&full_viewplane) * (rect->ymax / (float)region->winy));
345  }
346  else {
347  viewplane = full_viewplane;
348  }
349 
350  if (is_ortho) {
352  viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
353  }
354  else {
356  viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
357  }
358 
359  /* update matrix in 3d view region */
361 }
362 
363 static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
364 {
365  float bmat[4][4];
366 
367  rv3d->view = RV3D_VIEW_USER; /* don't show the grid */
368 
369  normalize_m4_m4(bmat, ob->obmat);
370  invert_m4_m4(rv3d->viewmat, bmat);
371 
372  /* view quat calculation, needed for add object */
374 }
375 
377  const Scene *scene,
378  const View3D *v3d,
379  RegionView3D *rv3d,
380  const float rect_scale[2])
381 {
382  if (rv3d->persp == RV3D_CAMOB) { /* obs/camera */
383  if (v3d->camera) {
384  Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
385  obmat_to_viewmat(rv3d, ob_camera_eval);
386  }
387  else {
388  quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
389  rv3d->viewmat[3][2] -= rv3d->dist;
390  }
391  }
392  else {
393  bool use_lock_ofs = false;
394 
395  /* should be moved to better initialize later on XXX */
396  if (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) {
397  ED_view3d_lock(rv3d);
398  }
399 
400  quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
401  if (rv3d->persp == RV3D_PERSP) {
402  rv3d->viewmat[3][2] -= rv3d->dist;
403  }
404  if (v3d->ob_center) {
406  float vec[3];
407 
408  copy_v3_v3(vec, ob_eval->obmat[3]);
409  if (ob_eval->type == OB_ARMATURE && v3d->ob_center_bone[0]) {
411  if (pchan) {
412  copy_v3_v3(vec, pchan->pose_mat[3]);
413  mul_m4_v3(ob_eval->obmat, vec);
414  }
415  }
416  translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]);
417  use_lock_ofs = true;
418  }
419  else if (v3d->ob_center_cursor) {
420  float vec[3];
422  translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]);
423  use_lock_ofs = true;
424  }
425  else {
426  translate_m4(rv3d->viewmat, rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2]);
427  }
428 
429  /* lock offset */
430  if (use_lock_ofs) {
431  float persmat[4][4], persinv[4][4];
432  float vec[3];
433 
434  /* we could calculate the real persmat/persinv here
435  * but it would be unreliable so better to later */
436  mul_m4_m4m4(persmat, rv3d->winmat, rv3d->viewmat);
437  invert_m4_m4(persinv, persmat);
438 
439  mul_v2_v2fl(vec, rv3d->ofs_lock, rv3d->is_persp ? rv3d->dist : 1.0f);
440  vec[2] = 0.0f;
441 
442  if (rect_scale) {
443  /* Since 'RegionView3D.winmat' has been calculated and this function doesn't take the
444  * 'ARegion' we don't know about the region size.
445  * Use 'rect_scale' when drawing a sub-region to apply 2D offset,
446  * scaled by the difference between the sub-region and the region size.
447  */
448  vec[0] /= rect_scale[0];
449  vec[1] /= rect_scale[1];
450  }
451 
452  mul_mat3_m4_v3(persinv, vec);
453  translate_m4(rv3d->viewmat, vec[0], vec[1], vec[2]);
454  }
455  /* end lock offset */
456  }
457 }
458 
461 /* -------------------------------------------------------------------- */
466 {
468 }
469 
471 {
473 }
474 
480  const rcti *rect;
482 };
483 
485 {
486  bool continue_pass = false;
488  if (stage == DRW_SELECT_PASS_PRE) {
490  data->buffer, data->buffer_len, data->rect, data->gpu_select_mode, data->hits);
491  /* always run POST after PRE. */
492  continue_pass = true;
493  }
494  else if (stage == DRW_SELECT_PASS_POST) {
495  int hits = GPU_select_end();
496  if (data->pass == 0) {
497  /* quirk of GPU_select_end, only take hits value from first call. */
498  data->hits = hits;
499  }
500  if (data->gpu_select_mode == GPU_SELECT_NEAREST_FIRST_PASS) {
501  data->gpu_select_mode = GPU_SELECT_NEAREST_SECOND_PASS;
502  continue_pass = (hits > 0);
503  }
504  data->pass += 1;
505  }
506  else {
507  BLI_assert(0);
508  }
509  return continue_pass;
510 }
511 
513 {
515  if (obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT) &&
518  }
520  }
522 }
523 
526 {
527  const Object *obact = user_data;
528  return BKE_object_is_mode_compat(ob, obact->mode);
529 }
530 
536 {
537  LinkNode *ob_pose_list = user_data;
538  return ob_pose_list && (BLI_linklist_index(ob_pose_list, DEG_get_original_object(ob)) != -1);
539 }
540 
544  const rcti *input,
545  eV3DSelectMode select_mode,
546  eV3DSelectObjectFilter select_filter,
547  const bool do_material_slot_selection)
548 {
549  struct bThemeState theme_state;
550  const wmWindowManager *wm = CTX_wm_manager(vc->C);
552  Scene *scene = vc->scene;
553  View3D *v3d = vc->v3d;
554  ARegion *region = vc->region;
555  rcti rect;
556  int hits = 0;
557  const bool use_obedit_skip = (OBEDIT_FROM_VIEW_LAYER(vc->view_layer) != NULL) &&
558  (vc->obedit == NULL);
559  const bool is_pick_select = (U.gpu_flag & USER_GPU_FLAG_NO_DEPT_PICK) == 0;
560  const bool do_passes = ((is_pick_select == false) &&
561  (select_mode == VIEW3D_SELECT_PICK_NEAREST));
562  const bool use_nearest = (is_pick_select && select_mode == VIEW3D_SELECT_PICK_NEAREST);
563  bool draw_surface = true;
564 
565  eGPUSelectMode gpu_select_mode;
566 
567  /* case not a box select */
568  if (input->xmin == input->xmax) {
569  /* seems to be default value for bones only now */
570  BLI_rcti_init_pt_radius(&rect, (const int[2]){input->xmin, input->ymin}, 12);
571  }
572  else {
573  rect = *input;
574  }
575 
576  if (is_pick_select) {
577  if (select_mode == VIEW3D_SELECT_PICK_NEAREST) {
578  gpu_select_mode = GPU_SELECT_PICK_NEAREST;
579  }
580  else if (select_mode == VIEW3D_SELECT_PICK_ALL) {
581  gpu_select_mode = GPU_SELECT_PICK_ALL;
582  }
583  else {
584  gpu_select_mode = GPU_SELECT_ALL;
585  }
586  }
587  else {
588  if (do_passes) {
589  gpu_select_mode = GPU_SELECT_NEAREST_FIRST_PASS;
590  }
591  else {
592  gpu_select_mode = GPU_SELECT_ALL;
593  }
594  }
595 
596  /* Re-use cache (rect must be smaller than the cached)
597  * other context is assumed to be unchanged */
598  if (GPU_select_is_cached()) {
599  GPU_select_begin(buffer, buffer_len, &rect, gpu_select_mode, 0);
601  hits = GPU_select_end();
602  goto finally;
603  }
604 
605  /* Important to use 'vc->obact', not 'OBACT(vc->view_layer)' below,
606  * so it will be NULL when hidden. */
607  struct {
609  void *user_data;
610  } object_filter = {NULL, NULL};
611  switch (select_filter) {
613  Object *obact = vc->obact;
614  if (obact && obact->mode != OB_MODE_OBJECT) {
615  object_filter.fn = drw_select_filter_object_mode_lock;
616  object_filter.user_data = obact;
617  }
618  break;
619  }
621  Object *obact = vc->obact;
622  BLI_assert(obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT));
623  /* While this uses 'alloca' in a loop (which we typically avoid),
624  * the number of items is nearly always 1, maybe 2..3 in rare cases. */
625  LinkNode *ob_pose_list = NULL;
626  if (obact->type == OB_GPENCIL) {
627  GpencilVirtualModifierData virtualModifierData;
629  obact, &virtualModifierData);
630  for (; md; md = md->next) {
631  if (md->type == eGpencilModifierType_Armature) {
633  if (agmd->object && (agmd->object->mode & OB_MODE_POSE)) {
634  BLI_linklist_prepend_alloca(&ob_pose_list, agmd->object);
635  }
636  }
637  }
638  }
639  else {
640  VirtualModifierData virtualModifierData;
642  &virtualModifierData);
643  for (; md; md = md->next) {
644  if (md->type == eModifierType_Armature) {
646  if (amd->object && (amd->object->mode & OB_MODE_POSE)) {
647  BLI_linklist_prepend_alloca(&ob_pose_list, amd->object);
648  }
649  }
650  }
651  }
653  object_filter.user_data = ob_pose_list;
654  break;
655  }
657  break;
658  }
659 
660  /* Tools may request depth outside of regular drawing code. */
661  UI_Theme_Store(&theme_state);
663 
664  /* All of the queries need to be perform on the drawing context. */
666 
667  G.f |= G_FLAG_PICKSEL;
668 
669  /* Important we use the 'viewmat' and don't re-calculate since
670  * the object & bone view locking takes 'rect' into account, see: T51629. */
672  wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, NULL, &rect);
673 
674  if (!XRAY_ACTIVE(v3d)) {
676  }
677 
678  /* If in xray mode, we select the wires in priority. */
679  if (XRAY_ACTIVE(v3d) && use_nearest) {
680  /* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
681  * because the OpenGL context created & destroyed inside this function. */
682  struct DrawSelectLoopUserData drw_select_loop_user_data = {
683  .pass = 0,
684  .hits = 0,
685  .buffer = buffer,
686  .buffer_len = buffer_len,
687  .rect = &rect,
688  .gpu_select_mode = gpu_select_mode,
689  };
690  draw_surface = false;
692  region,
693  v3d,
694  use_obedit_skip,
695  draw_surface,
696  use_nearest,
697  do_material_slot_selection,
698  &rect,
700  &drw_select_loop_user_data,
701  object_filter.fn,
702  object_filter.user_data);
703  hits = drw_select_loop_user_data.hits;
704  /* FIX: This cleanup the state before doing another selection pass.
705  * (see T56695) */
707  }
708 
709  if (hits == 0) {
710  /* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
711  * because the OpenGL context created & destroyed inside this function. */
712  struct DrawSelectLoopUserData drw_select_loop_user_data = {
713  .pass = 0,
714  .hits = 0,
715  .buffer = buffer,
716  .buffer_len = buffer_len,
717  .rect = &rect,
718  .gpu_select_mode = gpu_select_mode,
719  };
720  /* If are not in wireframe mode, we need to use the mesh surfaces to check for hits */
721  draw_surface = (v3d->shading.type > OB_WIRE) || !XRAY_ENABLED(v3d);
723  region,
724  v3d,
725  use_obedit_skip,
726  draw_surface,
727  use_nearest,
728  do_material_slot_selection,
729  &rect,
731  &drw_select_loop_user_data,
732  object_filter.fn,
733  object_filter.user_data);
734  hits = drw_select_loop_user_data.hits;
735  }
736 
737  G.f &= ~G_FLAG_PICKSEL;
739  wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, NULL, NULL);
740 
741  if (!XRAY_ACTIVE(v3d)) {
743  }
744 
746 
747  UI_Theme_Restore(&theme_state);
748 
749 finally:
750 
751  if (hits < 0) {
752  printf("Too many objects in select buffer\n"); /* XXX make error message */
753  }
754 
755  return hits;
756 }
757 
761  const rcti *input,
762  eV3DSelectMode select_mode,
763  eV3DSelectObjectFilter select_filter)
764 {
765  return view3d_opengl_select_ex(vc, buffer, buffer_len, input, select_mode, select_filter, false);
766 }
767 
770  const uint buffer_len,
771  const rcti *input,
772  eV3DSelectMode select_mode,
773  eV3DSelectObjectFilter select_filter,
774  uint select_id)
775 {
776  int hits = view3d_opengl_select(vc, buffer, buffer_len, input, select_mode, select_filter);
777 
778  /* Selection sometimes uses -1 for an invalid selection ID, remove these as they
779  * interfere with detection of actual number of hits in the selection. */
780  if (hits > 0) {
782  }
783  return hits;
784 }
785 
788 /* -------------------------------------------------------------------- */
793 {
794  ScrArea *area;
795  bScreen *screen;
796 
797  ushort local_view_bits = 0;
798 
799  /* Sometimes we lose a local-view: when an area is closed.
800  * Check all areas: which local-views are in use? */
801  for (screen = bmain->screens.first; screen; screen = screen->id.next) {
802  for (area = screen->areabase.first; area; area = area->next) {
803  SpaceLink *sl = area->spacedata.first;
804  for (; sl; sl = sl->next) {
805  if (sl->spacetype == SPACE_VIEW3D) {
806  View3D *v3d = (View3D *)sl;
807  if (v3d->localvd) {
808  local_view_bits |= v3d->local_view_uuid;
809  }
810  }
811  }
812  }
813  }
814 
815  for (int i = 0; i < 16; i++) {
816  if ((local_view_bits & (1 << i)) == 0) {
817  return (1 << i);
818  }
819  }
820 
821  return 0;
822 }
823 
825  wmWindowManager *wm,
826  wmWindow *win,
827  Main *bmain,
828  ViewLayer *view_layer,
829  ScrArea *area,
830  const bool frame_selected,
831  const int smooth_viewtx,
832  ReportList *reports)
833 {
834  View3D *v3d = area->spacedata.first;
835  Base *base;
836  float min[3], max[3], box[3];
837  float size = 0.0f;
838  uint local_view_bit;
839  bool ok = false;
840 
841  if (v3d->localvd) {
842  return ok;
843  }
844 
845  INIT_MINMAX(min, max);
846 
847  local_view_bit = free_localview_bit(bmain);
848 
849  if (local_view_bit == 0) {
850  /* TODO(dfelinto): We can kick one of the other 3D views out of local view
851  * specially if it is not being used. */
852  BKE_report(reports, RPT_ERROR, "No more than 16 local views");
853  ok = false;
854  }
855  else {
856  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
857  if (obedit) {
858  for (base = FIRSTBASE(view_layer); base; base = base->next) {
859  base->local_view_bits &= ~local_view_bit;
860  }
861  FOREACH_BASE_IN_EDIT_MODE_BEGIN (view_layer, v3d, base_iter) {
862  BKE_object_minmax(base_iter->object, min, max, false);
863  base_iter->local_view_bits |= local_view_bit;
864  ok = true;
865  }
867  }
868  else {
869  for (base = FIRSTBASE(view_layer); base; base = base->next) {
870  if (BASE_SELECTED(v3d, base)) {
871  BKE_object_minmax(base->object, min, max, false);
872  base->local_view_bits |= local_view_bit;
873  ok = true;
874  }
875  else {
876  base->local_view_bits &= ~local_view_bit;
877  }
878  }
879  }
880 
881  sub_v3_v3v3(box, max, min);
882  size = max_fff(box[0], box[1], box[2]);
883  }
884 
885  if (ok == false) {
886  return false;
887  }
888 
889  ARegion *region;
890 
891  v3d->localvd = MEM_mallocN(sizeof(View3D), "localview");
892 
893  memcpy(v3d->localvd, v3d, sizeof(View3D));
894  v3d->local_view_uuid = local_view_bit;
895 
896  for (region = area->regionbase.first; region; region = region->next) {
897  if (region->regiontype == RGN_TYPE_WINDOW) {
898  RegionView3D *rv3d = region->regiondata;
899  bool ok_dist = true;
900 
901  /* New view values. */
902  Object *camera_old = NULL;
903  float dist_new, ofs_new[3];
904 
905  rv3d->localvd = MEM_mallocN(sizeof(RegionView3D), "localview region");
906  memcpy(rv3d->localvd, rv3d, sizeof(RegionView3D));
907 
908  if (frame_selected) {
909  float mid[3];
910  mid_v3_v3v3(mid, min, max);
911  negate_v3_v3(ofs_new, mid);
912 
913  if (rv3d->persp == RV3D_CAMOB) {
914  rv3d->persp = RV3D_PERSP;
915  camera_old = v3d->camera;
916  }
917 
918  if (rv3d->persp == RV3D_ORTHO) {
919  if (size < 0.0001f) {
920  ok_dist = false;
921  }
922  }
923 
924  if (ok_dist) {
925  dist_new = ED_view3d_radius_to_dist(
926  v3d, region, depsgraph, rv3d->persp, true, (size / 2) * VIEW3D_MARGIN);
927 
928  if (rv3d->persp == RV3D_PERSP) {
929  /* Don't zoom closer than the near clipping plane. */
930  dist_new = max_ff(dist_new, v3d->clip_start * 1.5f);
931  }
932  }
933 
935  wm,
936  win,
937  area,
938  v3d,
939  region,
940  smooth_viewtx,
941  &(const V3D_SmoothParams){
942  .camera_old = camera_old,
943  .ofs = ofs_new,
944  .quat = rv3d->viewquat,
945  .dist = ok_dist ? &dist_new : NULL,
946  .lens = &v3d->lens,
947  /* No undo because this doesn't move the camera. */
948  .undo_str = NULL,
949  });
950  }
951  }
952  }
953 
954  return ok;
955 }
956 
958  wmWindowManager *wm,
959  wmWindow *win,
960  ViewLayer *view_layer,
961  ScrArea *area,
962  const bool frame_selected,
963  const int smooth_viewtx)
964 {
965  View3D *v3d = area->spacedata.first;
966 
967  if (v3d->localvd == NULL) {
968  return;
969  }
970 
971  for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
972  if (base->local_view_bits & v3d->local_view_uuid) {
973  base->local_view_bits &= ~v3d->local_view_uuid;
974  }
975  }
976 
977  Object *camera_old = v3d->camera;
978  Object *camera_new = v3d->localvd->camera;
979 
980  v3d->local_view_uuid = 0;
981  v3d->camera = v3d->localvd->camera;
982 
983  MEM_freeN(v3d->localvd);
984  v3d->localvd = NULL;
986 
987  LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
988  if (region->regiontype == RGN_TYPE_WINDOW) {
989  RegionView3D *rv3d = region->regiondata;
990 
991  if (rv3d->localvd == NULL) {
992  continue;
993  }
994 
995  if (frame_selected) {
996  Object *camera_old_rv3d, *camera_new_rv3d;
997 
998  camera_old_rv3d = (rv3d->persp == RV3D_CAMOB) ? camera_old : NULL;
999  camera_new_rv3d = (rv3d->localvd->persp == RV3D_CAMOB) ? camera_new : NULL;
1000 
1001  rv3d->view = rv3d->localvd->view;
1002  rv3d->persp = rv3d->localvd->persp;
1003  rv3d->camzoom = rv3d->localvd->camzoom;
1004 
1006  wm,
1007  win,
1008  area,
1009  v3d,
1010  region,
1011  smooth_viewtx,
1012  &(const V3D_SmoothParams){
1013  .camera_old = camera_old_rv3d,
1014  .camera = camera_new_rv3d,
1015  .ofs = rv3d->localvd->ofs,
1016  .quat = rv3d->localvd->viewquat,
1017  .dist = &rv3d->localvd->dist,
1018  /* No undo because this doesn't move the camera. */
1019  .undo_str = NULL,
1020  });
1021  }
1022 
1023  MEM_freeN(rv3d->localvd);
1024  rv3d->localvd = NULL;
1025  }
1026  }
1027 }
1028 
1030 {
1032  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
1034  wmWindow *win = CTX_wm_window(C);
1035  Main *bmain = CTX_data_main(C);
1037  ViewLayer *view_layer = CTX_data_view_layer(C);
1038  ScrArea *area = CTX_wm_area(C);
1039  View3D *v3d = CTX_wm_view3d(C);
1040  bool frame_selected = RNA_boolean_get(op->ptr, "frame_selected");
1041  bool changed;
1042 
1043  if (v3d->localvd) {
1044  view3d_localview_exit(depsgraph, wm, win, view_layer, area, frame_selected, smooth_viewtx);
1045  changed = true;
1046  }
1047  else {
1048  changed = view3d_localview_init(
1049  depsgraph, wm, win, bmain, view_layer, area, frame_selected, smooth_viewtx, op->reports);
1050  }
1051 
1052  if (changed) {
1053  DEG_id_type_tag(bmain, ID_OB);
1055 
1056  /* Unselected objects become selected when exiting. */
1057  if (v3d->localvd == NULL) {
1060  }
1061  else {
1063  }
1064 
1065  return OPERATOR_FINISHED;
1066  }
1067  return OPERATOR_CANCELLED;
1068 }
1069 
1071 {
1072  /* identifiers */
1073  ot->name = "Local View";
1074  ot->description = "Toggle display of selected object(s) separately and centered in view";
1075  ot->idname = "VIEW3D_OT_localview";
1076 
1077  /* api callbacks */
1078  ot->exec = localview_exec;
1079  ot->flag = OPTYPE_UNDO; /* localview changes object layer bitflags */
1080 
1082 
1084  "frame_selected",
1085  true,
1086  "Frame Selected",
1087  "Move the view to frame the selected objects");
1088 }
1089 
1091 {
1092  View3D *v3d = CTX_wm_view3d(C);
1093  Main *bmain = CTX_data_main(C);
1095  ViewLayer *view_layer = CTX_data_view_layer(C);
1096  bool changed = false;
1097 
1098  for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
1099  if (BASE_SELECTED(v3d, base)) {
1100  base->local_view_bits &= ~v3d->local_view_uuid;
1102 
1103  if (base == BASACT(view_layer)) {
1104  view_layer->basact = NULL;
1105  }
1106  changed = true;
1107  }
1108  }
1109 
1110  if (changed) {
1111  DEG_tag_on_visible_update(bmain, false);
1115  return OPERATOR_FINISHED;
1116  }
1117 
1118  BKE_report(op->reports, RPT_ERROR, "No object selected");
1119  return OPERATOR_CANCELLED;
1120 }
1121 
1123 {
1124  if (CTX_data_edit_object(C) != NULL) {
1125  return false;
1126  }
1127 
1128  View3D *v3d = CTX_wm_view3d(C);
1129  return v3d && v3d->localvd;
1130 }
1131 
1133 {
1134  /* identifiers */
1135  ot->name = "Remove from Local View";
1136  ot->description = "Move selected objects out of local view";
1137  ot->idname = "VIEW3D_OT_localview_remove_from";
1138 
1139  /* api callbacks */
1142  ot->flag = OPTYPE_UNDO;
1143 }
1144 
1147 /* -------------------------------------------------------------------- */
1151 static uint free_localcollection_bit(Main *bmain, ushort local_collections_uuid, bool *r_reset)
1152 {
1153  ScrArea *area;
1154  bScreen *screen;
1155 
1156  ushort local_view_bits = 0;
1157 
1158  /* Check all areas: which local-views are in use? */
1159  for (screen = bmain->screens.first; screen; screen = screen->id.next) {
1160  for (area = screen->areabase.first; area; area = area->next) {
1161  SpaceLink *sl = area->spacedata.first;
1162  for (; sl; sl = sl->next) {
1163  if (sl->spacetype == SPACE_VIEW3D) {
1164  View3D *v3d = (View3D *)sl;
1165  if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
1166  local_view_bits |= v3d->local_collections_uuid;
1167  }
1168  }
1169  }
1170  }
1171  }
1172 
1173  /* First try to keep the old uuid. */
1174  if (local_collections_uuid && ((local_collections_uuid & local_view_bits) == 0)) {
1175  return local_collections_uuid;
1176  }
1177 
1178  /* Otherwise get the first free available. */
1179  for (int i = 0; i < 16; i++) {
1180  if ((local_view_bits & (1 << i)) == 0) {
1181  *r_reset = true;
1182  return (1 << i);
1183  }
1184  }
1185 
1186  return 0;
1187 }
1188 
1189 static void local_collections_reset_uuid(LayerCollection *layer_collection,
1190  const ushort local_view_bit)
1191 {
1192  if (layer_collection->flag & LAYER_COLLECTION_HIDE) {
1193  layer_collection->local_collections_bits &= ~local_view_bit;
1194  }
1195  else {
1196  layer_collection->local_collections_bits |= local_view_bit;
1197  }
1198 
1199  LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) {
1200  local_collections_reset_uuid(child, local_view_bit);
1201  }
1202 }
1203 
1204 static void view3d_local_collections_reset(Main *bmain, const uint local_view_bit)
1205 {
1206  LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
1207  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
1208  LISTBASE_FOREACH (LayerCollection *, layer_collection, &view_layer->layer_collections) {
1209  local_collections_reset_uuid(layer_collection, local_view_bit);
1210  }
1211  }
1212  }
1213 }
1214 
1216 {
1217  if ((v3d->flag & V3D_LOCAL_COLLECTIONS) == 0) {
1218  return true;
1219  }
1220 
1221  bool reset = false;
1222  v3d->flag &= ~V3D_LOCAL_COLLECTIONS;
1223  uint local_view_bit = free_localcollection_bit(bmain, v3d->local_collections_uuid, &reset);
1224 
1225  if (local_view_bit == 0) {
1226  return false;
1227  }
1228 
1229  v3d->local_collections_uuid = local_view_bit;
1230  v3d->flag |= V3D_LOCAL_COLLECTIONS;
1231 
1232  if (reset) {
1233  view3d_local_collections_reset(bmain, local_view_bit);
1234  }
1235 
1236  return true;
1237 }
1238 
1239 void ED_view3d_local_collections_reset(struct bContext *C, const bool reset_all)
1240 {
1241  Main *bmain = CTX_data_main(C);
1242  uint local_view_bit = ~(0);
1243  bool do_reset = false;
1244 
1245  /* Reset only the ones that are not in use. */
1246  LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
1247  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
1248  LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
1249  if (sl->spacetype == SPACE_VIEW3D) {
1250  View3D *v3d = (View3D *)sl;
1251  if (v3d->local_collections_uuid) {
1252  if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
1253  local_view_bit &= ~v3d->local_collections_uuid;
1254  }
1255  else {
1256  do_reset = true;
1257  }
1258  }
1259  }
1260  }
1261  }
1262  }
1263 
1264  if (do_reset) {
1265  view3d_local_collections_reset(bmain, local_view_bit);
1266  }
1267  else if (reset_all && (do_reset || (local_view_bit != ~(0)))) {
1268  view3d_local_collections_reset(bmain, ~(0));
1269  View3D v3d = {.local_collections_uuid = ~(0)};
1272  }
1273 }
1274 
1277 /* -------------------------------------------------------------------- */
1281 #ifdef WITH_XR_OPENXR
1282 
1283 static void view3d_xr_mirror_begin(RegionView3D *rv3d)
1284 {
1285  /* If there is no session yet, changes below should not be applied! */
1286  BLI_assert(WM_xr_session_exists(&((wmWindowManager *)G_MAIN->wm.first)->xr));
1287 
1289  /* Force perspective view. This isn't reset but that's not really an issue. */
1290  rv3d->persp = RV3D_PERSP;
1291 }
1292 
1293 static void view3d_xr_mirror_end(RegionView3D *rv3d)
1294 {
1296 }
1297 
1298 void ED_view3d_xr_mirror_update(const ScrArea *area, const View3D *v3d, const bool enable)
1299 {
1300  ARegion *region_rv3d;
1301 
1303 
1304  if (ED_view3d_area_user_region(area, v3d, &region_rv3d)) {
1305  if (enable) {
1306  view3d_xr_mirror_begin(region_rv3d->regiondata);
1307  }
1308  else {
1309  view3d_xr_mirror_end(region_rv3d->regiondata);
1310  }
1311  }
1312 }
1313 
1314 void ED_view3d_xr_shading_update(wmWindowManager *wm, const View3D *v3d, const Scene *scene)
1315 {
1317  View3DShading *xr_shading = &wm->xr.session_settings.shading;
1318  /* Flags that shouldn't be overridden by the 3D View shading. */
1319  int flag_copy = 0;
1320  if (v3d->shading.type != OB_SOLID) {
1321  /* Don't set V3D_SHADING_WORLD_ORIENTATION for solid shading since it results in distorted
1322  * lighting when the view matrix has a scale factor. */
1323  flag_copy |= V3D_SHADING_WORLD_ORIENTATION;
1324  }
1325 
1327 
1328  if (v3d->shading.type == OB_RENDER) {
1330  /* Keep old shading while using Cycles or another engine, they are typically not usable in
1331  * VR. */
1332  return;
1333  }
1334  }
1335 
1336  if (xr_shading->prop) {
1337  IDP_FreeProperty(xr_shading->prop);
1338  xr_shading->prop = NULL;
1339  }
1340 
1341  /* Copy shading from View3D to VR view. */
1342  const int old_xr_shading_flag = xr_shading->flag;
1343  *xr_shading = v3d->shading;
1344  xr_shading->flag = (xr_shading->flag & ~flag_copy) | (old_xr_shading_flag & flag_copy);
1345  if (v3d->shading.prop) {
1346  xr_shading->prop = IDP_CopyProperty(xr_shading->prop);
1347  }
1348  }
1349 }
1350 
1351 bool ED_view3d_is_region_xr_mirror_active(const wmWindowManager *wm,
1352  const View3D *v3d,
1353  const ARegion *region)
1354 {
1355  return (v3d->flag & V3D_XR_SESSION_MIRROR) &&
1356  /* The free region (e.g. the camera region in quad-view) is always
1357  * the last in the list base. We don't want any other to be affected. */
1358  !region->next && //
1359  WM_xr_session_is_ready(&wm->xr);
1360 }
1361 
1362 #endif
1363 
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1370
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1528
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1353
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:784
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:723
#define G_MAIN
Definition: BKE_global.h:267
@ G_FLAG_PICKSEL
Definition: BKE_global.h:149
struct GpencilModifierData * BKE_gpencil_modifiers_get_virtual_modifierlist(const struct Object *ob, struct GpencilVirtualModifierData *data)
void IDP_FreeProperty(struct IDProperty *prop)
Definition: idprop.c:1093
struct IDProperty * IDP_CopyProperty(const struct IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define FOREACH_BASE_IN_EDIT_MODE_BEGIN(_view_layer, _v3d, _instance)
Definition: BKE_layer.h:375
void BKE_layer_collection_local_sync(struct ViewLayer *view_layer, const struct View3D *v3d)
#define FOREACH_BASE_IN_EDIT_MODE_END
Definition: BKE_layer.h:378
bool BKE_id_is_editable(const struct Main *bmain, const struct ID *id)
struct ModifierData * BKE_modifiers_get_virtual_modifierlist(const struct Object *ob, struct VirtualModifierData *data)
General operations, lookup, etc. for blender objects.
void BKE_object_tfm_protected_restore(struct Object *ob, const ObjectTfmProtectedChannels *obtfm, short protectflag)
Definition: object.cc:3007
struct Object * BKE_object_pose_armature_get(struct Object *ob)
Definition: object.cc:2511
bool BKE_object_is_mode_compat(const struct Object *ob, eObjectMode object_mode)
Definition: object.cc:2034
void BKE_object_tfm_protected_backup(const struct Object *ob, ObjectTfmProtectedChannels *obtfm)
void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], bool use_hidden)
Definition: object.cc:3839
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
bool BKE_scene_uses_blender_eevee(const struct Scene *scene)
bool BKE_scene_uses_blender_workbench(const struct Scene *scene)
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
MINLINE float max_fff(float a, float b, float c)
MINLINE float max_ff(float a, float b)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:790
void translate_m4(float mat[4][4], float tx, float ty, float tz)
Definition: math_matrix.c:2318
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:729
void normalize_m4_m4(float R[4][4], const float M[4][4]) ATTR_NONNULL()
Definition: math_matrix.c:1965
void mat4_normalized_to_quat(float q[4], const float mat[4][4])
void quat_to_mat4(float mat[4][4], const float q[4])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
Definition: math_vector.c:237
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
Definition: rct.c:469
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:194
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:198
unsigned int uint
Definition: BLI_sys_types.h:67
unsigned short ushort
Definition: BLI_sys_types.h:68
#define INIT_MINMAX(min, max)
#define UNUSED(x)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
void DEG_tag_on_visible_update(struct Main *bmain, bool do_time)
void DEG_id_type_tag(struct Main *bmain, short id_type)
void DEG_id_tag_update(struct ID *id, int flag)
struct Object * DEG_get_original_object(struct Object *object)
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
@ ID_RECALC_SELECT
Definition: DNA_ID.h:818
@ ID_RECALC_BASE_FLAGS
Definition: DNA_ID.h:821
@ ID_OB
Definition: DNA_ID_enums.h:47
@ eGpencilModifierType_Armature
@ LAYER_COLLECTION_HIDE
@ BASE_SELECTED
@ eModifierType_Armature
@ OB_WIRE
@ OB_SOLID
@ OB_RENDER
#define OB_MODE_ALL_WEIGHT_PAINT
@ OB_MODE_POSE
@ OB_MODE_OBJECT
@ OB_ARMATURE
@ OB_GPENCIL
#define OBEDIT_FROM_VIEW_LAYER(view_layer)
#define FIRSTBASE(_view_layer)
#define V3D_CAMERA_SCENE(scene, v3d)
@ SCE_OBJECT_MODE_LOCK
#define BASACT(_view_layer)
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
@ USER_GPU_FLAG_NO_DEPT_PICK
#define RV3D_LOCK_FLAGS(rv3d)
@ V3D_RUNTIME_XR_SESSION_ROOT
#define RV3D_CAMOB
@ RV3D_LOCK_ANY_TRANSFORM
@ RV3D_LOCK_ROTATION
@ V3D_SHADING_WORLD_ORIENTATION
#define V3D_XR_SESSION_MIRROR
#define RV3D_PERSP
#define V3D_LOCAL_COLLECTIONS
#define RV3D_VIEW_USER
#define RV3D_ORTHO
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void DRW_opengl_context_enable(void)
eDRWSelectStage
Definition: DRW_engine.h:60
@ DRW_SELECT_PASS_POST
Definition: DRW_engine.h:62
@ DRW_SELECT_PASS_PRE
Definition: DRW_engine.h:61
bool(* DRW_ObjectFilterFn)(struct Object *ob, void *user_data)
Definition: DRW_engine.h:65
void DRW_draw_select_loop(struct Depsgraph *depsgraph, struct ARegion *region, struct View3D *v3d, bool use_obedit_skip, bool draw_surface, bool use_nearest, bool do_material_sub_selection, const struct rcti *rect, DRW_SelectPassFn select_pass_fn, void *select_pass_user_data, DRW_ObjectFilterFn object_filter_fn, void *object_filter_user_data)
void DRW_opengl_context_disable(void)
void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode)
Definition: object_select.c:76
@ BA_DESELECT
Definition: ED_object.h:154
void ED_area_tag_redraw(ScrArea *area)
Definition: area.c:729
bool ED_operator_view3d_active(struct bContext *C)
Definition: screen_ops.c:225
bool ED_operator_scene_editable(struct bContext *C)
Definition: screen_ops.c:177
bool ED_view3d_area_user_region(const struct ScrArea *area, const struct View3D *v3d, struct ARegion **r_region)
#define XRAY_ENABLED(v3d)
Definition: ED_view3d.h:1299
bool ED_view3d_viewplane_get(struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *r_viewplane, float *r_clipsta, float *r_clipend, float *r_pixsize)
bool ED_view3d_camera_to_view_selected(struct Main *bmain, struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *camera_ob)
void ED_view3d_draw_setup_view(const struct wmWindowManager *wm, struct wmWindow *win, struct Depsgraph *depsgraph, struct Scene *scene, struct ARegion *region, struct View3D *v3d, const float viewmat[4][4], const float winmat[4][4], const struct rcti *rect)
#define VIEW3D_MARGIN
Definition: ED_view3d.h:1229
#define XRAY_ACTIVE(v3d)
Definition: ED_view3d.h:1300
void ED_view3d_to_object(const struct Depsgraph *depsgraph, struct Object *ob, const float ofs[3], const float quat[4], float dist)
float ED_view3d_radius_to_dist(const struct View3D *v3d, const struct ARegion *region, const struct Depsgraph *depsgraph, char persp, bool use_aspect, float radius)
eV3DSelectMode
Definition: ED_view3d.h:896
@ VIEW3D_SELECT_PICK_ALL
Definition: ED_view3d.h:900
@ VIEW3D_SELECT_PICK_NEAREST
Definition: ED_view3d.h:902
void ED_view3d_lastview_store(struct RegionView3D *rv3d)
Definition: view3d_utils.c:440
bool ED_view3d_lock(struct RegionView3D *rv3d)
bool ED_view3d_context_user_region(struct bContext *C, struct View3D **r_v3d, struct ARegion **r_region)
Definition: space_view3d.c:98
eV3DSelectObjectFilter
Definition: ED_view3d.h:905
@ VIEW3D_SELECT_FILTER_NOP
Definition: ED_view3d.h:907
@ VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK
Definition: ED_view3d.h:909
@ VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK
Definition: ED_view3d.h:911
void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far)
Definition: gpu_matrix.cc:399
void GPU_matrix_frustum_set(float left, float right, float bottom, float top, float near, float far)
Definition: gpu_matrix.cc:422
#define GPU_matrix_projection_get(x)
Definition: GPU_matrix.h:228
uint GPU_select_buffer_remove_by_id(GPUSelectResult *buffer, int hits, uint select_id)
Definition: gpu_select.c:221
void GPU_select_begin(GPUSelectResult *buffer, unsigned int buffer_len, const struct rcti *input, eGPUSelectMode mode, int oldhits)
eGPUSelectMode
Definition: GPU_select.h:19
@ GPU_SELECT_NEAREST_SECOND_PASS
Definition: GPU_select.h:23
@ GPU_SELECT_NEAREST_FIRST_PASS
Definition: GPU_select.h:22
@ GPU_SELECT_PICK_ALL
Definition: GPU_select.h:25
@ GPU_SELECT_ALL
Definition: GPU_select.h:20
@ GPU_SELECT_PICK_NEAREST
Definition: GPU_select.h:26
void GPU_select_cache_begin(void)
Definition: gpu_select.c:165
bool GPU_select_is_cached(void)
Definition: gpu_select.c:195
void GPU_select_cache_load_id(void)
Definition: gpu_select.c:176
void GPU_select_cache_end(void)
Definition: gpu_select.c:184
unsigned int GPU_select_end(void)
Definition: gpu_select.c:135
@ GPU_DEPTH_LESS_EQUAL
Definition: GPU_state.h:86
@ GPU_DEPTH_NONE
Definition: GPU_state.h:83
void GPU_depth_test(eGPUDepthTest test)
Definition: gpu_state.cc:65
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
#define C
Definition: RandGen.cpp:25
void UI_Theme_Restore(struct bThemeState *theme_state)
Definition: resources.c:1076
void UI_SetTheme(int spacetype, int regionid)
Definition: resources.c:1045
void UI_Theme_Store(struct bThemeState *theme_state)
Definition: resources.c:1072
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define ND_DRAW
Definition: WM_types.h:410
#define ND_OB_ACTIVE
Definition: WM_types.h:388
#define ND_OB_SELECT
Definition: WM_types.h:390
#define NC_SCENE
Definition: WM_types.h:328
#define ND_TRANSFORM
Definition: WM_types.h:405
#define NC_OBJECT
Definition: WM_types.h:329
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
unsigned int U
Definition: btGjkEpa3.h:78
EvaluationStage stage
Definition: deg_eval.cc:89
Scene scene
const Depsgraph * depsgraph
void * user_data
ccl_global float * buffer
ccl_global KernelShaderEvalInput * input
ccl_gpu_kernel_postfix ccl_global float int int int int float bool reset
clear internal cached data and reset random seed
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
#define G(x, y, z)
static void area(int d1, int d2, int e1, int e2, float weights[2])
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
#define min(a, b)
Definition: sort.c:35
void * regiondata
struct ARegion * next
short regiontype
struct Base * next
struct Object * object
unsigned short local_view_bits
GPUSelectResult * buffer
Definition: view3d_view.c:478
eGPUSelectMode gpu_select_mode
Definition: view3d_view.c:481
struct GpencilModifierData * next
void * next
Definition: DNA_ID.h:369
ListBase layer_collections
unsigned short local_collections_bits
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
ListBase scenes
Definition: BKE_main.h:168
ListBase screens
Definition: BKE_main.h:183
struct ModifierData * next
struct bPose * pose
float obmat[4][4]
float quat[4]
short protectflag
float viewquat[4]
struct RegionView3D * localvd
float viewmat[4][4]
float winmat[4][4]
struct ToolSettings * toolsettings
View3DCursor cursor
ListBase view_layers
struct Object * camera
struct IDProperty * prop
struct SceneStats * local_stats
unsigned short local_view_uuid
View3D_Runtime runtime
struct Object * camera
struct View3D * localvd
char ob_center_bone[64]
short scenelock
char spacetype
unsigned short local_collections_uuid
short ob_center_cursor
struct Object * ob_center
View3DShading shading
float clip_start
struct Depsgraph * depsgraph
Definition: ED_view3d.h:64
struct Scene * scene
Definition: ED_view3d.h:65
struct ARegion * region
Definition: ED_view3d.h:69
struct ViewLayer * view_layer
Definition: ED_view3d.h:66
struct bContext * C
Definition: ED_view3d.h:58
struct Object * obact
Definition: ED_view3d.h:67
struct Object * obedit
Definition: ED_view3d.h:68
struct wmWindow * win
Definition: ED_view3d.h:71
struct View3D * v3d
Definition: ED_view3d.h:70
struct RegionView3D * rv3d
Definition: ED_view3d.h:72
struct Base * basact
struct View3DShading shading
Definition: DNA_xr_types.h:19
float pose_mat[4][4]
ListBase areabase
float xmax
Definition: DNA_vec_types.h:69
float xmin
Definition: DNA_vec_types.h:69
float ymax
Definition: DNA_vec_types.h:70
float ymin
Definition: DNA_vec_types.h:70
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct PointerRNA * ptr
XrSessionSettings session_settings
float max
void ED_view3d_smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
void ED_view3d_smooth_view_ex(const struct Depsgraph *depsgraph, struct wmWindowManager *wm, struct wmWindow *win, struct ScrArea *area, struct View3D *v3d, struct ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
static void local_collections_reset_uuid(LayerCollection *layer_collection, const ushort local_view_bit)
Definition: view3d_view.c:1189
static bool view3d_localview_init(const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, Main *bmain, ViewLayer *view_layer, ScrArea *area, const bool frame_selected, const int smooth_viewtx, ReportList *reports)
Definition: view3d_view.c:824
void view3d_opengl_select_cache_end(void)
Definition: view3d_view.c:470
static int localview_remove_from_exec(bContext *C, wmOperator *op)
Definition: view3d_view.c:1090
void ED_view3d_local_collections_reset(struct bContext *C, const bool reset_all)
Definition: view3d_view.c:1239
void VIEW3D_OT_localview(wmOperatorType *ot)
Definition: view3d_view.c:1070
static void view3d_local_collections_reset(Main *bmain, const uint local_view_bit)
Definition: view3d_view.c:1204
static uint free_localview_bit(Main *bmain)
Definition: view3d_view.c:792
static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
Definition: view3d_view.c:363
static int localview_exec(bContext *C, wmOperator *op)
Definition: view3d_view.c:1029
void VIEW3D_OT_localview_remove_from(wmOperatorType *ot)
Definition: view3d_view.c:1132
static void view3d_localview_exit(const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, ViewLayer *view_layer, ScrArea *area, const bool frame_selected, const int smooth_viewtx)
Definition: view3d_view.c:957
void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
Definition: view3d_view.c:143
static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
Definition: view3d_view.c:123
static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data)
Definition: view3d_view.c:484
static bool drw_select_filter_object_mode_lock(Object *ob, void *user_data)
Definition: view3d_view.c:525
static int view3d_camera_to_view_exec(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_view.c:53
void view3d_winmatrix_set(Depsgraph *depsgraph, ARegion *region, const View3D *v3d, const rcti *rect)
Definition: view3d_view.c:306
static bool drw_select_filter_object_mode_lock_for_weight_paint(Object *ob, void *user_data)
Definition: view3d_view.c:535
static void sync_viewport_camera_smoothview(bContext *C, View3D *v3d, Object *ob, const int smooth_viewtx)
Definition: view3d_view.c:164
static uint free_localcollection_bit(Main *bmain, ushort local_collections_uuid, bool *r_reset)
Definition: view3d_view.c:1151
int view3d_opengl_select_with_id_filter(ViewContext *vc, GPUSelectResult *buffer, const uint buffer_len, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, uint select_id)
Definition: view3d_view.c:768
void view3d_viewmatrix_set(Depsgraph *depsgraph, const Scene *scene, const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
Definition: view3d_view.c:376
eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const Scene *scene, const Object *obact)
Definition: view3d_view.c:512
static bool localview_remove_from_poll(bContext *C)
Definition: view3d_view.c:1122
bool ED_view3d_local_collections_set(Main *bmain, struct View3D *v3d)
Definition: view3d_view.c:1215
void view3d_opengl_select_cache_begin(void)
Definition: view3d_view.c:465
int view3d_opengl_select_ex(ViewContext *vc, GPUSelectResult *buffer, uint buffer_len, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, const bool do_material_slot_selection)
Definition: view3d_view.c:541
int view3d_opengl_select(ViewContext *vc, GPUSelectResult *buffer, uint buffer_len, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter)
Definition: view3d_view.c:758
void VIEW3D_OT_camera_to_view(wmOperatorType *ot)
Definition: view3d_view.c:100
static bool view3d_camera_to_view_poll(bContext *C)
Definition: view3d_view.c:81
bool ED_operator_rv3d_user_region_poll(bContext *C)
Definition: view3d_view.c:277
static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op)
Definition: view3d_view.c:223
void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
Definition: view3d_view.c:285
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3479
int WM_operator_smooth_viewtx_get(const wmOperator *op)
bool WM_xr_session_is_ready(const wmXrData *xr)
bool WM_xr_session_exists(const wmXrData *xr)