Blender V5.3
view3d_view.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "BLI_linklist.hh"
12#include "BLI_listbase.hh"
13#include "BLI_math_matrix_c.hh"
15#include "BLI_math_vector_c.hh"
16#include "BLI_rect.hh"
17
18#include "BKE_action.hh"
19#include "BKE_context.hh"
20#ifdef WITH_XR_OPENXR
21# include "BKE_idprop.hh"
22#endif
23#include "BKE_global.hh"
24#include "BKE_layer.hh"
25#include "BKE_lib_id.hh"
26#include "BKE_main.hh"
27#include "BKE_modifier.hh"
28#include "BKE_object.hh"
29#include "BKE_report.hh"
30#include "BKE_scene.hh"
31
33
34#include "UI_resources.hh"
35
36#include "GPU_matrix.hh"
37#include "GPU_select.hh"
38#include "GPU_state.hh"
39
40#include "WM_api.hh"
41
42#include "ED_info.hh"
43#include "ED_object.hh"
44#include "ED_screen.hh"
45
46#include "DRW_engine.hh"
47
48#include "RNA_access.hh"
49#include "RNA_define.hh"
50
51#include "view3d_intern.hh" /* own include */
52#include "view3d_navigate.hh"
53
54#include "DNA_camera_types.h"
55
56namespace blender {
57
58/* -------------------------------------------------------------------- */
61
63{
64 const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
65 View3D *v3d;
66 ARegion *region;
67 RegionView3D *rv3d;
68
70
71 ED_view3d_context_user_region(C, &v3d, &region);
72 rv3d = static_cast<RegionView3D *>(region->regiondata);
73
75
77
79
80 ED_view3d_to_object(depsgraph, v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist, 0.0f);
81 rv3d->camroll = 0.0f;
82 rv3d->rflag &= ~RV3D_FLIP_X;
83
85
87 rv3d->persp = RV3D_CAMOB;
88
90
91 return OPERATOR_FINISHED;
92}
93
95{
96 View3D *v3d;
97 ARegion *region;
98
99 if (ED_view3d_context_user_region(C, &v3d, &region)) {
100 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
101 if (v3d && v3d->camera && BKE_id_is_editable(CTX_data_main(C), &v3d->camera->id)) {
102 if (rv3d && (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) {
103 if (rv3d->persp != RV3D_CAMOB) {
104 return true;
105 }
106 }
107 }
108 }
109
110 return false;
111}
112
114{
115 /* identifiers */
116 ot->name = "Align Camera to View";
117 ot->description = "Set camera view to active view";
118 ot->idname = "VIEW3D_OT_camera_to_view";
119
120 /* API callbacks. */
123
124 /* flags */
126}
127
129
130/* -------------------------------------------------------------------- */
133
139{
140 Main *bmain = CTX_data_main(C);
141 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
142 Scene *scene = CTX_data_scene(C);
143 View3D *v3d = CTX_wm_view3d(C); /* can be nullptr */
144 Object *camera_ob = v3d ? v3d->camera : scene->camera;
145
146 if (camera_ob == nullptr) {
147 BKE_report(op->reports, RPT_ERROR, "No active camera");
148 return OPERATOR_CANCELLED;
149 }
150
151 if (ED_view3d_camera_to_view_selected(bmain, depsgraph, scene, camera_ob)) {
153 return OPERATOR_FINISHED;
154 }
155 return OPERATOR_CANCELLED;
156}
157
159{
160 /* identifiers */
161 ot->name = "Camera Fit Frame to Selected";
162 ot->description = "Move the camera so selected objects are framed";
163 ot->idname = "VIEW3D_OT_camera_to_view_selected";
164
165 /* API callbacks. */
168
169 /* flags */
171}
172
174
175/* -------------------------------------------------------------------- */
178
180 View3D *v3d,
181 Object *ob,
182 const int smooth_viewtx)
183{
184 Main *bmain = CTX_data_main(C);
185 for (bScreen &screen : bmain->screens) {
186 for (ScrArea &area : screen.areabase) {
187 for (SpaceLink &space_link : area.spacedata) {
188 if (space_link.spacetype == SPACE_VIEW3D) {
189 View3D *other_v3d = reinterpret_cast<View3D *>(&space_link);
190 if (other_v3d == v3d) {
191 continue;
192 }
193 if (other_v3d->camera == ob) {
194 continue;
195 }
196 /* Checking the other view is needed to prevent local cameras being modified. */
197 if (v3d->scenelock && other_v3d->scenelock) {
198 ListBaseT<ARegion> *lb = (&space_link == area.spacedata.first_) ?
199 &area.regionbase :
200 &space_link.regionbase;
201 for (ARegion &other_region : *lb) {
202 if (other_region.regiontype == RGN_TYPE_WINDOW) {
203 if (other_region.regiondata) {
204 RegionView3D *other_rv3d = static_cast<RegionView3D *>(other_region.regiondata);
205 if (other_rv3d->persp == RV3D_CAMOB) {
206 Object *other_camera_old = other_v3d->camera;
207 other_v3d->camera = ob;
208
209 V3D_SmoothParams sview_params = {};
210 sview_params.camera_old = other_camera_old;
211 sview_params.camera = other_v3d->camera;
212 sview_params.ofs = other_rv3d->ofs;
213 sview_params.quat = other_rv3d->viewquat;
214 sview_params.dist = &other_rv3d->dist;
215 sview_params.lens = &other_v3d->lens;
216 /* No undo because this switches cameras. */
217 sview_params.undo_str = nullptr;
218
219 ED_view3d_lastview_store(other_rv3d);
221 C, other_v3d, &other_region, smooth_viewtx, &sview_params);
222 }
223 else {
224 other_v3d->camera = ob;
225 }
226 }
227 }
228 }
229 }
230 }
231 }
232 }
233 }
234}
235
237{
238 View3D *v3d;
239 ARegion *region;
240 RegionView3D *rv3d;
241
242 Scene *scene = CTX_data_scene(C);
244
245 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
246
247 /* no nullptr check is needed, poll checks */
248 ED_view3d_context_user_region(C, &v3d, &region);
249 rv3d = static_cast<RegionView3D *>(region->regiondata);
250
252
253 if (ob) {
254 Object *camera_old = (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : nullptr;
255 rv3d->persp = RV3D_CAMOB;
256 v3d->camera = ob;
257 if (v3d->scenelock && scene->camera != ob) {
258 scene->camera = ob;
261 }
262
263 /* unlikely but looks like a glitch when set to the same */
264 if (camera_old != ob) {
265 V3D_SmoothParams sview_params = {};
266 sview_params.camera_old = camera_old;
267 sview_params.camera = v3d->camera;
268 sview_params.ofs = rv3d->ofs;
269 sview_params.quat = rv3d->viewquat;
270 sview_params.dist = &rv3d->dist;
271 sview_params.lens = &v3d->lens;
272 /* No undo because this switches cameras. */
273 sview_params.undo_str = nullptr;
274
276 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview_params);
277 }
278
279 if (v3d->scenelock) {
280 sync_viewport_camera_smoothview(C, v3d, ob, smooth_viewtx);
282 }
284 }
285
286 return OPERATOR_FINISHED;
287}
288
290{
291 View3D *v3d_dummy;
292 ARegion *region_dummy;
293
294 return ED_view3d_context_user_region(C, &v3d_dummy, &region_dummy);
295}
296
298{
299 /* identifiers */
300 ot->name = "Set Active Object as Camera";
301 ot->description = "Set the active object as the active camera for this view or scene";
302 ot->idname = "VIEW3D_OT_object_as_camera";
303
304 /* API callbacks. */
307
308 /* flags */
310}
311
313
314/* -------------------------------------------------------------------- */
317
318void view3d_winmatrix_set(const Depsgraph *depsgraph,
319 ARegion *region,
320 const View3D *v3d,
321 const rcti *rect)
322{
323 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
324 rctf full_viewplane;
325 float clipsta, clipend;
326 bool is_ortho;
327
328 is_ortho = ED_view3d_viewplane_get(depsgraph,
329 v3d,
330 rv3d,
331 region->winx,
332 region->winy,
333 &full_viewplane,
334 &clipsta,
335 &clipend,
336 nullptr);
337 rv3d->is_persp = !is_ortho;
338
339#if 0
340 printf("%s: %d %d %f %f %f %f %f %f\n",
341 __func__,
342 winx,
343 winy,
344 full_viewplane.xmin,
345 full_viewplane.ymin,
346 full_viewplane.xmax,
347 full_viewplane.ymax,
348 clipsta,
349 clipend);
350#endif
351
352 /* Note the code here was tweaked to avoid an apparent compiler bug in clang 13 (see #91680). */
353 rctf viewplane;
354 if (rect) {
355 /* Smaller viewplane subset for selection picking. */
356 viewplane.xmin = full_viewplane.xmin +
357 (BLI_rctf_size_x(&full_viewplane) * (rect->xmin / float(region->winx)));
358 viewplane.ymin = full_viewplane.ymin +
359 (BLI_rctf_size_y(&full_viewplane) * (rect->ymin / float(region->winy)));
360 viewplane.xmax = full_viewplane.xmin +
361 (BLI_rctf_size_x(&full_viewplane) * (rect->xmax / float(region->winx)));
362 viewplane.ymax = full_viewplane.ymin +
363 (BLI_rctf_size_y(&full_viewplane) * (rect->ymax / float(region->winy)));
364 }
365 else {
366 viewplane = full_viewplane;
367 }
368
369 if (is_ortho) {
371 viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
372 }
373 else {
375 viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
376 }
377
378 /* update matrix in 3d view region */
380}
381
382static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
383{
384 float bmat[4][4];
385
386 rv3d->view = RV3D_VIEW_USER; /* don't show the grid */
387
388 normalize_m4_m4(bmat, ob->object_to_world().ptr());
389 /* Apply roll. */
390 if (rv3d->camroll != 0.0f) {
391 rotate_m4(bmat, 'Z', -rv3d->camroll);
392 }
393 invert_m4_m4(rv3d->viewmat, bmat);
394
395 /* view quat calculation, needed for add object */
397
398 if (rv3d->rflag & RV3D_FLIP_X) {
399 transpose_m4(rv3d->viewmat);
400 negate_v4(rv3d->viewmat[0]);
401 transpose_m4(rv3d->viewmat);
402 }
403}
404
405void view3d_viewmatrix_set(const Depsgraph *depsgraph,
406 const Scene *scene,
407 const View3D *v3d,
408 RegionView3D *rv3d,
409 const float rect_scale[2])
410{
411 if (rv3d->persp == RV3D_CAMOB) { /* obs/camera */
412 if (v3d->camera) {
413 Object *ob_camera_eval = DEG_get_evaluated(depsgraph, v3d->camera);
414 obmat_to_viewmat(rv3d, ob_camera_eval);
415 }
416 else {
417 quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
418 rv3d->viewmat[3][2] -= rv3d->dist;
419 }
420 }
421 else {
422 bool use_lock_ofs = false;
423
424 /* should be moved to better initialize later on XXX */
426 ED_view3d_lock(rv3d);
427 }
428
429 quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
430 if (rv3d->persp == RV3D_PERSP) {
431 rv3d->viewmat[3][2] -= rv3d->dist;
432 }
433 if (v3d->ob_center) {
434 Object *ob_eval = DEG_get_evaluated(depsgraph, v3d->ob_center);
435 float vec[3];
436
437 copy_v3_v3(vec, ob_eval->object_to_world().location());
438 if (ob_eval->type == OB_ARMATURE && v3d->ob_center_bone[0]) {
440 if (pchan) {
441 copy_v3_v3(vec, pchan->pose_mat[3]);
442 mul_m4_v3(ob_eval->object_to_world().ptr(), vec);
443 }
444 }
445 translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]);
446 use_lock_ofs = true;
447 }
448 else if (v3d->ob_center_cursor) {
449 float vec[3];
450 copy_v3_v3(vec, scene->cursor.location);
451 translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]);
452 use_lock_ofs = true;
453 }
454 else {
455 translate_m4(rv3d->viewmat, rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2]);
456 }
457
458 /* lock offset */
459 if (use_lock_ofs) {
460 float persmat[4][4], persinv[4][4];
461 float vec[3];
462
463 /* we could calculate the real persmat/persinv here
464 * but it would be unreliable so better to later */
465 mul_m4_m4m4(persmat, rv3d->winmat, rv3d->viewmat);
466 invert_m4_m4(persinv, persmat);
467
468 mul_v2_v2fl(vec, rv3d->ofs_lock, rv3d->is_persp ? rv3d->dist : 1.0f);
469 vec[2] = 0.0f;
470
471 if (rect_scale) {
472 /* Since `RegionView3D.winmat` has been calculated and this function doesn't take the
473 * #ARegion we don't know about the region size.
474 * Use `rect_scale` when drawing a sub-region to apply 2D offset,
475 * scaled by the difference between the sub-region and the region size.
476 */
477 vec[0] /= rect_scale[0];
478 vec[1] /= rect_scale[1];
479 }
480
481 mul_mat3_m4_v3(persinv, vec);
482 translate_m4(rv3d->viewmat, vec[0], vec[1], vec[2]);
483 }
484 /* end lock offset */
485 }
486}
487
489
490/* -------------------------------------------------------------------- */
493
498
503
512
513static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data)
514{
515 bool continue_pass = false;
516 DrawSelectLoopUserData *data = static_cast<DrawSelectLoopUserData *>(user_data);
517 if (stage == DRW_SELECT_PASS_PRE) {
519 data->buffer, data->rect, data->radius, data->gpu_select_mode, data->hits);
520 /* always run POST after PRE. */
521 continue_pass = true;
522 }
523 else if (stage == DRW_SELECT_PASS_POST) {
524 int hits = GPU_select_end();
525 if (data->pass == 0) {
526 /* quirk of GPU_select_end, only take hits value from first call. */
527 data->hits = hits;
528 }
529 data->pass += 1;
530 }
531 else {
532 BLI_assert(0);
533 }
534 return continue_pass;
535}
536
538static std::optional<eV3DSelectObjectFilter> view3d_select_filter_from_mode_lock_override(
539 const View3D *v3d, const Object *obact)
540{
541 /* The caller ensures this only runs when #SCE_OBJECT_MODE_LOCK is set.
542 * Only restrict selection to bones when the user turns on "Lock Object Modes".
543 * If the lock is off, skip this so other objects can still be selected, see #66950 & #125822. */
544
545 if (v3d->flag2 & V3D_HIDE_OVERLAYS) {
546 return std::nullopt;
547 }
548
549 /* NOTE: don't use #BKE_object_pose_armature_get as it doesn't check for weight-paint mode
550 * when using the deforming armature (breaking selection outside weight paint mode). */
551 if (const Object *obpose = OBPOSE_FROM_OBACT(obact)) {
552 if (obpose->mode == OB_MODE_POSE) {
553 /* This check only makes sense in pose-mode,
554 * where this "X-ray" options gives pose-bones a priority over other objects.
555 *
556 * Must not be used in weight-paint mode as it prevents pose
557 * selection *unless* X-ray is enabled. see: #158045. */
558 if ((v3d->overlay.flag & V3D_OVERLAY_BONE_SELECT) == 0) {
559 return std::nullopt;
560 }
562 }
563 }
564 else if (const Object *obweight = OBWEIGHTPAINT_ALL_FROM_OBACT(obact)) {
565 /* Only use Armature pose selection, when connected armature is in pose mode. */
566 if (const Object *ob_armature = BKE_modifiers_is_deformed_by_armature(
567 const_cast<Object *>(obweight)))
568 {
569 if (ob_armature->mode == OB_MODE_POSE) {
571 }
572 }
573 }
574
575 /* No pose override. */
576 return std::nullopt;
577}
578
580 const View3D *v3d,
581 const Object *obact)
582{
583 const ToolSettings *ts = scene->toolsettings;
585 if (std::optional<eV3DSelectObjectFilter> filter_override =
587 {
588 return *filter_override;
589 }
591 }
592
594}
595
597static bool drw_select_filter_object_mode_lock(Object *ob, void *user_data)
598{
599 const Object *obact = static_cast<const Object *>(user_data);
600 return BKE_object_is_mode_compat(ob, obact->mode);
601}
602
605{
606 const Object *obact = static_cast<const Object *>(user_data);
607 return (obact->type == ob->type) && BKE_object_is_mode_compat(ob, obact->mode);
608}
609
615{
616 LinkNode *ob_pose_list = static_cast<LinkNode *>(user_data);
617 return ob_pose_list && (BLI_linklist_index(ob_pose_list, DEG_get_original(ob)) != -1);
618}
619
621 GPUSelectBuffer *buffer,
622 const rcti *input,
623 eV3DSelectMode select_mode,
624 eV3DSelectObjectFilter select_filter,
625 const eV3DSelectShape select_shape,
626 const bool do_material_slot_selection)
627{
628 ui::theme::bThemeState theme_state;
629 const wmWindowManager *wm = CTX_wm_manager(vc->C);
630 Depsgraph *depsgraph = vc->depsgraph;
631 Scene *scene = vc->scene;
632 View3D *v3d = vc->v3d;
633 ARegion *region = vc->region;
634 rcti rect;
635 int hits = 0;
637 const bool use_nearest = select_mode == VIEW3D_SELECT_PICK_NEAREST;
638 bool draw_surface = true;
639
640 GPUSelectMode gpu_select_mode = GPU_SELECT_INVALID;
641
642 /* case not a box select */
643 if (input->xmin == input->xmax) {
644 const int xy[2] = {input->xmin, input->ymin};
645 /* seems to be default value for bones only now */
646 BLI_rcti_init_pt_radius(&rect, xy, 12);
647 }
648 else {
649 rect = *input;
650 }
651
652 if (select_mode == VIEW3D_SELECT_PICK_NEAREST) {
653 gpu_select_mode = GPU_SELECT_PICK_NEAREST;
654 }
655 else if (select_mode == VIEW3D_SELECT_PICK_ALL) {
656 gpu_select_mode = GPU_SELECT_PICK_ALL;
657 }
658 else {
659 gpu_select_mode = GPU_SELECT_ALL;
660 }
661
662 /* Important to use `vc->obact`, not `BKE_view_layer_active_object_get(vc->view_layer)` below,
663 * so it will be nullptr when hidden. */
664 struct {
666 void *user_data;
667 } object_filter = {nullptr, nullptr};
668
669 /* Re-use cache (rect must be smaller than the cached)
670 * other context is assumed to be unchanged */
671 const int select_radius = select_shape == eV3DSelectShape::CIRCLE ? BLI_rcti_size_x(input) / 2 :
672 0;
673 if (GPU_select_is_cached()) {
674 GPU_select_begin_next(buffer, &rect, select_radius, gpu_select_mode, 0);
676 hits = GPU_select_end();
677 return hits;
678 }
679
680 switch (select_filter) {
682 Object *obact = vc->obact;
683 if (obact && obact->mode != OB_MODE_OBJECT) {
684 object_filter.fn = drw_select_filter_object_mode_lock;
685 object_filter.user_data = obact;
686 }
687 break;
688 }
690 Object *obact = vc->obact;
691 if (obact && obact->mode != OB_MODE_OBJECT) {
693 object_filter.user_data = obact;
694 }
695 break;
696 }
698 Object *obact = vc->obact;
699 BLI_assert(obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT));
700 /* While this uses `alloca` in a loop (which we typically avoid),
701 * the number of items is nearly always 1, maybe 2..3 in rare cases. */
702 LinkNode *ob_pose_list = nullptr;
703 VirtualModifierData virtual_modifier_data;
704 ModifierData *md = BKE_modifiers_get_virtual_modifierlist(obact, &virtual_modifier_data);
705 for (; md; md = md->next) {
706 if (md->type == eModifierType_Armature) {
707 ArmatureModifierData *amd = reinterpret_cast<ArmatureModifierData *>(md);
708 if (amd->object && (amd->object->mode & OB_MODE_POSE)) {
709 BLI_linklist_prepend_alloca(&ob_pose_list, amd->object);
710 }
711 }
714 reinterpret_cast<GreasePencilArmatureModifierData *>(md);
715 if (amd->object && (amd->object->mode & OB_MODE_POSE)) {
716 BLI_linklist_prepend_alloca(&ob_pose_list, amd->object);
717 }
718 }
719 }
721 object_filter.user_data = ob_pose_list;
722 break;
723 }
725 break;
726 }
727
728 /* Tools may request depth outside of regular drawing code. */
729 ui::theme::theme_store(&theme_state);
731
732 /* All of the queries need to be perform on the drawing context. */
734
735 G.f |= G_FLAG_PICKSEL;
736
737 /* Important we use the 'viewmat' and don't re-calculate since
738 * the object & bone view locking takes 'rect' into account, see: #51629. */
740 wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, nullptr, &rect);
741
742 if (!XRAY_ACTIVE(v3d)) {
744 }
745
746 /* If in X-ray mode, we select the wires in priority. */
747 if (XRAY_ACTIVE(v3d) && use_nearest) {
748 /* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
749 * because the GPU context created & destroyed inside this function. */
750 DrawSelectLoopUserData drw_select_loop_user_data = {};
751 drw_select_loop_user_data.pass = 0;
752 drw_select_loop_user_data.hits = 0;
753 drw_select_loop_user_data.buffer = buffer;
754 drw_select_loop_user_data.rect = &rect;
755 drw_select_loop_user_data.radius = select_radius;
756 drw_select_loop_user_data.gpu_select_mode = gpu_select_mode;
757
758 draw_surface = false;
759 DRW_draw_select_loop(depsgraph,
760 region,
761 v3d,
762 draw_surface,
763 use_nearest,
764 do_material_slot_selection,
765 &rect,
767 &drw_select_loop_user_data,
768 object_filter.fn,
769 object_filter.user_data);
770 hits = drw_select_loop_user_data.hits;
771 /* FIX: This cleanup the state before doing another selection pass.
772 * (see #56695) */
774 }
775
776 if (hits == 0) {
777 /* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
778 * because the GPU context created & destroyed inside this function. */
779 DrawSelectLoopUserData drw_select_loop_user_data = {};
780 drw_select_loop_user_data.pass = 0;
781 drw_select_loop_user_data.hits = 0;
782 drw_select_loop_user_data.buffer = buffer;
783 drw_select_loop_user_data.rect = &rect;
784 drw_select_loop_user_data.radius = select_radius;
785 drw_select_loop_user_data.gpu_select_mode = gpu_select_mode;
786
787 /* If are not in wireframe mode, we need to use the mesh surfaces to check for hits */
788 draw_surface = (v3d->shading.type > OB_WIRE) || !XRAY_ENABLED(v3d);
789 DRW_draw_select_loop(depsgraph,
790 region,
791 v3d,
792 draw_surface,
793 use_nearest,
794 do_material_slot_selection,
795 &rect,
797 &drw_select_loop_user_data,
798 object_filter.fn,
799 object_filter.user_data);
800 hits = drw_select_loop_user_data.hits;
801 }
802
803 G.f &= ~G_FLAG_PICKSEL;
805 wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, nullptr, nullptr);
806
807 if (!XRAY_ACTIVE(v3d)) {
809 }
810
812
813 ui::theme::theme_restore(&theme_state);
814
815 return hits;
816}
817
819 GPUSelectBuffer *buffer,
820 const rcti *input,
821 eV3DSelectMode select_mode,
822 eV3DSelectObjectFilter select_filter,
823 const eV3DSelectShape select_shape)
824{
825 return view3d_gpu_select_ex(vc, buffer, input, select_mode, select_filter, select_shape, false);
826}
827
829 GPUSelectBuffer *buffer,
830 const rcti *input,
831 eV3DSelectMode select_mode,
832 eV3DSelectObjectFilter select_filter,
833 uint select_id)
834{
835 const int64_t start = buffer->storage.size();
836 int hits = view3d_gpu_select(
837 vc, buffer, input, select_mode, select_filter, eV3DSelectShape::BOX);
838
839 /* Selection sometimes uses -1 for an invalid selection ID, remove these as they
840 * interfere with detection of actual number of hits in the selection. */
841 if (hits > 0) {
842 hits = GPU_select_buffer_remove_by_id(buffer->storage.as_mutable_span().slice(start, hits),
843 select_id);
844
845 /* Trim buffer to the exact size in case selections were removed. */
846 buffer->storage.resize(start + hits);
847 }
848 return hits;
849}
850
852
853/* -------------------------------------------------------------------- */
856
858{
859 ushort local_view_bits = 0;
860
861 /* Sometimes we lose a local-view: when an area is closed.
862 * Check all areas: which local-views are in use? */
863 for (bScreen &screen : bmain->screens) {
864 for (ScrArea &area : screen.areabase) {
865 SpaceLink *sl = area.spacedata.first_as<SpaceLink>();
866 for (; sl; sl = sl->next) {
867 if (sl->spacetype == SPACE_VIEW3D) {
868 View3D *v3d = reinterpret_cast<View3D *>(sl);
869 if (v3d->localvd) {
870 local_view_bits |= v3d->local_view_uid;
871 }
872 }
873 }
874 }
875 }
876
877 for (int i = 0; i < 16; i++) {
878 if ((local_view_bits & (1 << i)) == 0) {
879 return (1 << i);
880 }
881 }
882
883 return 0;
884}
885
886static bool view3d_localview_init(const Depsgraph *depsgraph,
888 wmWindow *win,
889 Main *bmain,
890 const Scene *scene,
891 ViewLayer *view_layer,
892 ScrArea *area,
893 const bool frame_selected,
894 const int smooth_viewtx,
895 ReportList *reports)
896{
897 View3D *v3d = area->spacedata.first_as<View3D>();
898 float3 min, max, box;
899 float size = 0.0f;
900 uint local_view_bit;
901 bool changed = false;
902
903 if (v3d->localvd) {
904 return changed;
905 }
906
908
909 local_view_bit = free_localview_bit(bmain);
910
911 if (local_view_bit == 0) {
912 /* TODO(dfelinto): We can kick one of the other 3D views out of local view
913 * specially if it is not being used. */
914 BKE_report(reports, RPT_ERROR, "No more than 16 local views");
915 changed = false;
916 }
917 else {
918 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
919 Object *obedit = BKE_view_layer_edit_object_get(view_layer);
920 if (obedit) {
921 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
922 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
923 base.local_view_bits &= ~local_view_bit;
924 }
925 FOREACH_BASE_IN_EDIT_MODE_BEGIN (bmain, scene, view_layer, v3d, base_iter) {
926 Object *ob_eval = DEG_get_evaluated(depsgraph, base_iter->object);
927 BKE_object_minmax(ob_eval ? ob_eval : base_iter->object, min, max);
928 base_iter->local_view_bits |= local_view_bit;
929 changed = true;
930 }
932 }
933 else {
934 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
935 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
936 if (BASE_SELECTED(v3d, &base)) {
937 Object *ob_eval = DEG_get_evaluated(depsgraph, base.object);
938 BKE_object_minmax(ob_eval ? ob_eval : base.object, min, max);
939 base.local_view_bits |= local_view_bit;
940 changed = true;
941 }
942 else {
943 base.local_view_bits &= ~local_view_bit;
944 }
945 }
946 }
947
948 sub_v3_v3v3(box, max, min);
949 size = std::max({box[0], box[1], box[2]});
950 }
951
952 if (changed == false) {
953 return false;
954 }
955
956 /* Apply any running smooth-view values before reading from the viewport. */
957 for (ARegion &region : area->regionbase) {
958 if (region.regiontype == RGN_TYPE_WINDOW) {
959 RegionView3D *rv3d = static_cast<RegionView3D *>(region.regiondata);
960 if (rv3d->sms) {
961 ED_view3d_smooth_view_force_finish_no_camera_lock(depsgraph, wm, win, scene, v3d, &region);
962 }
963 }
964 }
965
966 v3d->localvd = MEM_new<View3D>("localview");
967 *v3d->localvd = dna::shallow_copy(*v3d);
968 v3d->local_view_uid = local_view_bit;
969
970 for (ARegion &region : area->regionbase) {
971 if (region.regiontype == RGN_TYPE_WINDOW) {
972 RegionView3D *rv3d = static_cast<RegionView3D *>(region.regiondata);
973 bool ok_dist = true;
974
975 /* New view values. */
976 Object *camera_old = nullptr;
977 float dist_new, ofs_new[3];
978
979 rv3d->localvd = MEM_new<RegionView3D>("localview region", dna::shallow_copy(*rv3d));
980
981 if (frame_selected) {
982 float mid[3];
983 mid_v3_v3v3(mid, min, max);
984 negate_v3_v3(ofs_new, mid);
985
986 if (rv3d->persp == RV3D_CAMOB) {
987 rv3d->persp = RV3D_PERSP;
988 camera_old = v3d->camera;
989 if (camera_old && camera_old->type == OB_CAMERA) {
990 const Camera &camera = *id_cast<Camera *>(camera_old->data);
991 if (camera.type == CAM_ORTHO) {
992 rv3d->persp = RV3D_ORTHO;
993 }
994 }
995 }
996
997 if (rv3d->persp == RV3D_ORTHO) {
998 if (size < 0.0001f) {
999 ok_dist = false;
1000 }
1001 }
1002
1003 if (ok_dist) {
1004 dist_new = ED_view3d_radius_to_dist(
1005 v3d, &region, depsgraph, rv3d->persp, true, (size / 2) * VIEW3D_MARGIN);
1006
1007 if (rv3d->persp == RV3D_PERSP) {
1008 /* Don't zoom closer than the near clipping plane. */
1009 const float dist_min = ED_view3d_dist_soft_min_get(v3d, true);
1010 CLAMP_MIN(dist_new, dist_min);
1011 }
1012 }
1013
1014 V3D_SmoothParams sview_params = {};
1015 sview_params.camera_old = camera_old;
1016 sview_params.ofs = ofs_new;
1017 sview_params.quat = rv3d->viewquat;
1018 sview_params.dist = ok_dist ? &dist_new : nullptr;
1019 sview_params.lens = &v3d->lens;
1020 /* No undo because this doesn't move the camera. */
1021 sview_params.undo_str = nullptr;
1022
1024 depsgraph, wm, win, area, v3d, &region, smooth_viewtx, &sview_params);
1025 }
1026 }
1027 }
1028
1029 return changed;
1030}
1031
1032static bool view3d_localview_exit(const Depsgraph *depsgraph,
1034 wmWindow *win,
1035 const Scene *scene,
1036 ViewLayer *view_layer,
1037 ScrArea *area,
1038 const bool frame_selected,
1039 const int smooth_viewtx)
1040{
1041 View3D *v3d = area->spacedata.first_as<View3D>();
1042 bool changed = false;
1043
1044 if (v3d->localvd == nullptr) {
1045 return changed;
1046 }
1047 BKE_view_layer_synced_ensure(*DEG_get_bmain(depsgraph), scene, view_layer);
1048 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
1049 if (base.local_view_bits & v3d->local_view_uid) {
1050 base.local_view_bits &= ~v3d->local_view_uid;
1051 }
1052 }
1053
1054 /* Apply any running smooth-view values before reading from the viewport. */
1055 for (ARegion &region : area->regionbase) {
1056 if (region.regiontype == RGN_TYPE_WINDOW) {
1057 RegionView3D *rv3d = static_cast<RegionView3D *>(region.regiondata);
1058 if (rv3d->localvd == nullptr) {
1059 continue;
1060 }
1061 if (rv3d->sms) {
1062 ED_view3d_smooth_view_force_finish_no_camera_lock(depsgraph, wm, win, scene, v3d, &region);
1063 }
1064 }
1065 }
1066
1067 Object *camera_old = v3d->camera;
1068 Object *camera_new = v3d->localvd->camera;
1069
1070 v3d->local_view_uid = 0;
1071 v3d->camera = v3d->localvd->camera;
1072
1073 MEM_delete(v3d->localvd);
1074 v3d->localvd = nullptr;
1076
1077 for (ARegion &region : area->regionbase) {
1078 if (region.regiontype == RGN_TYPE_WINDOW) {
1079 RegionView3D *rv3d = static_cast<RegionView3D *>(region.regiondata);
1080
1081 if (rv3d->localvd == nullptr) {
1082 continue;
1083 }
1084
1085 if (frame_selected && depsgraph) {
1086 Object *camera_old_rv3d, *camera_new_rv3d;
1087
1088 camera_old_rv3d = (rv3d->persp == RV3D_CAMOB) ? camera_old : nullptr;
1089 camera_new_rv3d = (rv3d->localvd->persp == RV3D_CAMOB) ? camera_new : nullptr;
1090
1091 rv3d->view = rv3d->localvd->view;
1092 rv3d->view_axis_roll = rv3d->localvd->view_axis_roll;
1093 rv3d->persp = rv3d->localvd->persp;
1094 rv3d->camzoom = rv3d->localvd->camzoom;
1095
1096 V3D_SmoothParams sview_params = {};
1097 sview_params.camera_old = camera_old_rv3d;
1098 sview_params.camera = camera_new_rv3d;
1099 sview_params.ofs = rv3d->localvd->ofs;
1100 sview_params.quat = rv3d->localvd->viewquat;
1101 sview_params.dist = &rv3d->localvd->dist;
1102 /* No undo because this doesn't move the camera. */
1103 sview_params.undo_str = nullptr;
1104
1106 depsgraph, wm, win, area, v3d, &region, smooth_viewtx, &sview_params);
1107 }
1108
1109 MEM_delete(rv3d->localvd);
1110 rv3d->localvd = nullptr;
1111 changed = true;
1112 }
1113 }
1114 return changed;
1115}
1116
1117bool ED_localview_exit_if_empty(const Depsgraph *depsgraph,
1118 Scene *scene,
1119 ViewLayer *view_layer,
1121 wmWindow *win,
1122 View3D *v3d,
1123 ScrArea *area,
1124 const bool frame_selected,
1125 const int smooth_viewtx)
1126{
1127 if (v3d->localvd == nullptr) {
1128 return false;
1129 }
1130
1132
1133 BKE_view_layer_synced_ensure(*DEG_get_bmain(depsgraph), scene, view_layer);
1134 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
1135 if (base.local_view_bits & v3d->local_view_uid) {
1136 return false;
1137 }
1138 }
1139
1140 return view3d_localview_exit(
1141 depsgraph, wm, win, scene, view_layer, area, frame_selected, smooth_viewtx);
1142}
1143
1145{
1146 const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
1147 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
1149 wmWindow *win = CTX_wm_window(C);
1150 Main *bmain = CTX_data_main(C);
1151 Scene *scene = CTX_data_scene(C);
1152 ViewLayer *view_layer = CTX_data_view_layer(C);
1153 ScrArea *area = CTX_wm_area(C);
1154 View3D *v3d = CTX_wm_view3d(C);
1155 bool frame_selected = RNA_boolean_get(op->ptr, "frame_selected");
1156 bool changed;
1157
1158 if (v3d->localvd) {
1159 changed = view3d_localview_exit(
1160 depsgraph, wm, win, scene, view_layer, area, frame_selected, smooth_viewtx);
1161 }
1162 else {
1163 changed = view3d_localview_init(depsgraph,
1164 wm,
1165 win,
1166 bmain,
1167 scene,
1168 view_layer,
1169 area,
1170 frame_selected,
1171 smooth_viewtx,
1172 op->reports);
1173 }
1174
1175 if (changed) {
1176 DEG_id_type_tag(bmain, ID_OB);
1177 ED_area_tag_redraw(area);
1178
1179 /* Unselected objects become selected when exiting. */
1180 if (v3d->localvd == nullptr) {
1183 }
1184 else {
1186 }
1187
1188 return OPERATOR_FINISHED;
1189 }
1190 return OPERATOR_CANCELLED;
1191}
1192
1194{
1195 /* identifiers */
1196 ot->name = "Local View";
1197 ot->description = "Toggle display of selected object(s) separately and centered in view";
1198 ot->idname = "VIEW3D_OT_localview";
1199
1200 /* API callbacks. */
1201 ot->exec = localview_exec;
1202 /* Use undo because local-view changes object layer bit-flags. */
1203 ot->flag = OPTYPE_UNDO;
1204
1206
1208 "frame_selected",
1209 true,
1210 "Frame Selected",
1211 "Move the view to frame the selected objects");
1212}
1213
1215{
1216 View3D *v3d = CTX_wm_view3d(C);
1217 Main *bmain = CTX_data_main(C);
1218 Scene *scene = CTX_data_scene(C);
1219 ViewLayer *view_layer = CTX_data_view_layer(C);
1220 bool changed = false;
1221 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1222 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
1223 if (BASE_SELECTED(v3d, &base)) {
1224 base.local_view_bits &= ~v3d->local_view_uid;
1226
1227 if (&base == view_layer->basact) {
1228 view_layer->basact = nullptr;
1229 }
1230 changed = true;
1231 }
1232 }
1233
1234 /* If some object was removed from the local view, exit the local view if it is now empty. */
1235 if (changed) {
1237 scene,
1238 view_layer,
1241 v3d,
1242 CTX_wm_area(C),
1243 true,
1245 }
1246
1247 if (changed) {
1248 DEG_tag_on_visible_update(bmain, false);
1252 return OPERATOR_FINISHED;
1253 }
1254
1255 BKE_report(op->reports, RPT_ERROR, "No object selected");
1256 return OPERATOR_CANCELLED;
1257}
1258
1260{
1261 if (CTX_data_edit_object(C) != nullptr) {
1262 return false;
1263 }
1264
1265 View3D *v3d = CTX_wm_view3d(C);
1266 return v3d && v3d->localvd;
1267}
1268
1270{
1271 /* identifiers */
1272 ot->name = "Remove from Local View";
1273 ot->description = "Move selected objects out of local view";
1274 ot->idname = "VIEW3D_OT_localview_remove_from";
1275
1276 /* API callbacks. */
1279 ot->flag = OPTYPE_UNDO;
1280}
1281
1283
1284/* -------------------------------------------------------------------- */
1287
1289 ushort local_collections_uid,
1290 bool *r_reset)
1291{
1292 ushort local_view_bits = 0;
1293
1294 /* Check all areas: which local-views are in use? */
1295 for (bScreen &screen : bmain->screens) {
1296 for (ScrArea &area : screen.areabase) {
1297 for (SpaceLink &sl : area.spacedata) {
1298 if (sl.spacetype == SPACE_VIEW3D) {
1299 View3D *v3d = reinterpret_cast<View3D *>(&sl);
1300 if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
1301 local_view_bits |= v3d->local_collections_uid;
1302 }
1303 }
1304 }
1305 }
1306 }
1307
1308 /* First try to keep the old uuid. */
1309 if (local_collections_uid && ((local_collections_uid & local_view_bits) == 0)) {
1310 return local_collections_uid;
1311 }
1312
1313 /* Otherwise get the first free available. */
1314 for (int i = 0; i < 16; i++) {
1315 if ((local_view_bits & (1 << i)) == 0) {
1316 *r_reset = true;
1317 return (1 << i);
1318 }
1319 }
1320
1321 return 0;
1322}
1323
1324static void local_collections_reset_uuid(LayerCollection *layer_collection,
1325 const ushort local_view_bit)
1326{
1327 if (layer_collection->flag & LAYER_COLLECTION_HIDE) {
1328 layer_collection->local_collections_bits &= ~local_view_bit;
1329 }
1330 else {
1331 layer_collection->local_collections_bits |= local_view_bit;
1332 }
1333
1334 for (LayerCollection &child : layer_collection->layer_collections) {
1335 local_collections_reset_uuid(&child, local_view_bit);
1336 }
1337}
1338
1339static void view3d_local_collections_reset(const Main *bmain, const uint local_view_bit)
1340{
1341 for (Scene &scene : bmain->scenes) {
1342 for (ViewLayer &view_layer : scene.view_layers) {
1343 for (LayerCollection &layer_collection : view_layer.layer_collections) {
1344 local_collections_reset_uuid(&layer_collection, local_view_bit);
1345 }
1346 }
1347 }
1348}
1349
1351{
1352 if ((v3d->flag & V3D_LOCAL_COLLECTIONS) == 0) {
1353 return true;
1354 }
1355
1356 bool reset = false;
1358 uint local_view_bit = free_localcollection_bit(bmain, v3d->local_collections_uid, &reset);
1359
1360 if (local_view_bit == 0) {
1361 return false;
1362 }
1363
1364 v3d->local_collections_uid = local_view_bit;
1366
1367 if (reset) {
1368 view3d_local_collections_reset(bmain, local_view_bit);
1369 }
1370
1371 return true;
1372}
1373
1374void ED_view3d_local_collections_reset(const bContext *C, const bool reset_all)
1375{
1376 Main *bmain = CTX_data_main(C);
1377 uint local_view_bit = ~0;
1378 bool do_reset = false;
1379
1380 /* Reset only the ones that are not in use. */
1381 for (bScreen &screen : bmain->screens) {
1382 for (ScrArea &area : screen.areabase) {
1383 for (SpaceLink &sl : area.spacedata) {
1384 if (sl.spacetype == SPACE_VIEW3D) {
1385 View3D *v3d = reinterpret_cast<View3D *>(&sl);
1386 if (v3d->local_collections_uid) {
1387 if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
1388 local_view_bit &= ~v3d->local_collections_uid;
1389 }
1390 else {
1391 do_reset = true;
1392 }
1393 }
1394 }
1395 }
1396 }
1397 }
1398
1399 if (do_reset) {
1400 view3d_local_collections_reset(bmain, local_view_bit);
1401 }
1402 else if (reset_all && (do_reset || (local_view_bit != ~0))) {
1404 View3D v3d = {};
1405 v3d.local_collections_uid = ~0;
1408 }
1409}
1410
1412
1413/* -------------------------------------------------------------------- */
1416
1417#ifdef WITH_XR_OPENXR
1418
1419static void view3d_xr_mirror_begin(RegionView3D *rv3d)
1420{
1421 /* If there is no session yet, changes below should not be applied! */
1422 BLI_assert(WM_xr_session_exists(&((wmWindowManager *)G_MAIN->wm.first_)->xr));
1423
1424 rv3d->runtime_viewlock |= RV3D_LOCK_ANY_TRANSFORM;
1425 /* Force perspective view. This isn't reset but that's not really an issue. */
1426 rv3d->persp = RV3D_PERSP;
1427}
1428
1429static void view3d_xr_mirror_end(RegionView3D *rv3d)
1430{
1431 rv3d->runtime_viewlock &= ~RV3D_LOCK_ANY_TRANSFORM;
1432}
1433
1434void ED_view3d_xr_mirror_update(const ScrArea *area, const View3D *v3d, const bool enable)
1435{
1436 ARegion *region_rv3d;
1437
1438 BLI_assert(v3d->spacetype == SPACE_VIEW3D);
1439
1440 if (ED_view3d_area_user_region(area, v3d, &region_rv3d)) {
1441 if (enable) {
1442 view3d_xr_mirror_begin(static_cast<RegionView3D *>(region_rv3d->regiondata));
1443 }
1444 else {
1445 view3d_xr_mirror_end(static_cast<RegionView3D *>(region_rv3d->regiondata));
1446 }
1447 }
1448}
1449
1450void ED_view3d_xr_shading_update(wmWindowManager *wm, const View3D *v3d, const Scene *scene)
1451{
1452 if (v3d->runtime.flag & V3D_RUNTIME_XR_SESSION_ROOT) {
1453 View3DShading *xr_shading = &wm->xr.session_settings.shading;
1454 /* Flags that shouldn't be overridden by the 3D View shading. */
1456 if (v3d->shading.type != OB_SOLID) {
1457 /* Don't set V3D_SHADING_WORLD_ORIENTATION for solid shading since it results in distorted
1458 * lighting when the view matrix has a scale factor. */
1459 flag_copy |= V3D_SHADING_WORLD_ORIENTATION;
1460 }
1461
1463
1464 if (v3d->shading.type == OB_RENDER) {
1466 /* Keep old shading while using Cycles or another engine, they are typically not usable in
1467 * VR. */
1468 return;
1469 }
1470 }
1471
1472 if (xr_shading->prop) {
1473 IDP_FreeProperty(xr_shading->prop);
1474 xr_shading->prop = nullptr;
1475 }
1476
1477 /* Copy shading from View3D to VR view. */
1478 const eView3DShading_Flag old_xr_shading_flag = xr_shading->flag;
1479 *xr_shading = v3d->shading;
1480 xr_shading->flag = (xr_shading->flag & ~flag_copy) | (old_xr_shading_flag & flag_copy);
1481 if (v3d->shading.prop) {
1482 xr_shading->prop = IDP_CopyProperty(xr_shading->prop);
1483 }
1484 }
1485}
1486
1487bool ED_view3d_is_region_xr_mirror_active(const wmWindowManager *wm,
1488 const View3D *v3d,
1489 const ARegion *region)
1490{
1491 return (v3d->flag & V3D_XR_SESSION_MIRROR) &&
1492 /* The free region (e.g. the camera region in quad-view) is always
1493 * the last in the list base. We don't want any other to be affected. */
1494 !region->next && //
1496}
1497
1498#endif
1499
1501
1502} // namespace blender
Blender kernel action and pose functionality.
#define G_MAIN
#define FOREACH_BASE_IN_EDIT_MODE_BEGIN(_bmain, _scene, _view_layer, _v3d, _instance)
Definition BKE_layer.hh:462
#define FOREACH_BASE_IN_EDIT_MODE_END
Definition BKE_layer.hh:465
General operations, lookup, etc. for blender objects.
#define OB_MODE_ALL_WEIGHT_PAINT
#define OBPOSE_FROM_OBACT(ob)
#define V3D_CAMERA_SCENE(scene, v3d)
#define OBWEIGHTPAINT_ALL_FROM_OBACT(ob)
#define RV3D_LOCK_FLAGS(rv3d)
#define XRAY_ENABLED(v3d)
#define VIEW3D_MARGIN
#define XRAY_ACTIVE(v3d)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ND_DRAW
Definition WM_types.hh:502
#define ND_OB_ACTIVE
Definition WM_types.hh:459
#define ND_OB_SELECT
Definition WM_types.hh:461
#define NC_SCENE
Definition WM_types.hh:391
#define ND_TRANSFORM
Definition WM_types.hh:475
#define NC_OBJECT
Definition WM_types.hh:392
#define INIT_MINMAX(min, max)
#define BLI_assert(a)
#define CLAMP_MIN(a, b)
btScalar max
void reset()
int64_t size() const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
void base_select(Base *base, eObjectSelect_Mode mode)
void theme_store(bThemeState *theme_state)
void theme_set(int spacetype, int regionid)
void theme_restore(const bThemeState *theme_state)
BMesh Iterators.
void DRW_gpu_context_enable()
static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data)
@ V3D_OVERLAY_BONE_SELECT
void GPU_matrix_frustum_set(float left, float right, float bottom, float top, float near, float far)
bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_region)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static uint free_localview_bit(Main *bmain)
void view3d_viewmatrix_set(const Depsgraph *depsgraph, const Scene *scene, const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
bool ED_view3d_viewplane_get(const Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d, int winx, int winy, rctf *r_viewplane, float *r_clip_start, float *r_clip_end, float *r_pixsize)
MINLINE void negate_v3_v3(float r[3], const float a[3])
void DRW_draw_select_loop(Depsgraph *depsgraph, ARegion *region, View3D *v3d, bool draw_surface, bool use_nearest, bool do_material_sub_selection, const rcti *rect, DRW_SelectPassFn select_pass_fn, void *select_pass_user_data, DRW_ObjectFilterFn object_filter_fn, void *object_filter_user_data)
@ V3D_RUNTIME_LOCAL_MAYBE_EMPTY
@ V3D_RUNTIME_XR_SESSION_ROOT
bool ED_operator_scene_editable(bContext *C)
bool ED_view3d_camera_to_view_selected(Main *bmain, Depsgraph *depsgraph, const Scene *scene, Object *camera_ob)
ScrArea * CTX_wm_area(const bContext *C)
__int64 int64_t
Definition BKE_text.h:90
static void sync_viewport_camera_smoothview(bContext *C, View3D *v3d, Object *ob, const int smooth_viewtx)
static wmOperatorStatus view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
void view3d_gpu_select_cache_end()
void BKE_object_tfm_protected_backup(const Object *ob, ObjectTfmProtectedChannels *obtfm)
Definition object.cc:3025
bool ED_view3d_local_collections_set(const Main *bmain, View3D *v3d)
bool ED_operator_rv3d_user_region_poll(bContext *C)
static void local_collections_reset_uuid(LayerCollection *layer_collection, const ushort local_view_bit)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void VIEW3D_OT_localview(wmOperatorType *ot)
void VIEW3D_OT_localview_remove_from(wmOperatorType *ot)
@ GPU_SELECT_INVALID
Definition GPU_select.hh:21
@ GPU_SELECT_PICK_ALL
Definition GPU_select.hh:27
@ GPU_SELECT_PICK_NEAREST
Definition GPU_select.hh:28
@ GPU_SELECT_ALL
Definition GPU_select.hh:22
bool WM_xr_session_exists(const wmXrData *xr)
float ED_view3d_radius_to_dist(const View3D *v3d, const ARegion *region, const Depsgraph *depsgraph, eRegionView3D_Persp persp, bool use_aspect, float radius)
bool(*)(Object *ob, void *user_data) DRW_ObjectFilterFn
Definition DRW_engine.hh:54
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
void mat4_normalized_to_quat(float q[4], const float mat[4][4])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
@ eModifierType_GreasePencilArmature
unsigned short ushort
Definition BKE_text.h:56
Object * BKE_modifiers_is_deformed_by_armature(Object *ob)
int WM_operator_smooth_viewtx_get(const wmOperator *op)
void GPU_select_cache_load_id()
static wmOperatorStatus view3d_setobjectascamera_exec(bContext *C, wmOperator *op)
static bool drw_select_filter_object_mode_lock_same_type(Object *ob, void *user_data)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
wmWindow * CTX_wm_window(const bContext *C)
static bool drw_select_filter_object_mode_lock_for_weight_paint(Object *ob, void *user_data)
@ V3D_LOCAL_COLLECTIONS
@ V3D_XR_SESSION_MIRROR
static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
void GPU_select_begin_next(GPUSelectBuffer *buffer, const rcti *input, int radius, GPUSelectMode mode, int oldhits)
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
static std::optional< eV3DSelectObjectFilter > view3d_select_filter_from_mode_lock_override(const View3D *v3d, const Object *obact)
@ RV3D_LOCK_ANY_TRANSFORM
unsigned int GPU_select_end()
static bool localview_remove_from_poll(bContext *C)
@ V3D_SHADING_WORLD_ORIENTATION
ViewLayer * CTX_data_view_layer(const bContext *C)
void view3d_gpu_select_cache_begin()
uint GPU_select_buffer_remove_by_id(MutableSpan< GPUSelectResult > hit_results, uint select_id)
void DEG_tag_on_visible_update(Main *bmain, bool do_time)
float ED_view3d_dist_soft_min_get(const View3D *v3d, bool use_persp_range)
eV3DSelectObjectFilter
Definition ED_view3d.hh:990
@ VIEW3D_SELECT_FILTER_NOP
Definition ED_view3d.hh:992
@ VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK
@ VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK
Definition ED_view3d.hh:994
@ VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK_SAME_TYPE
Definition ED_view3d.hh:999
void GPU_select_cache_end()
Global G
Definition blender.cc:57
int BLI_linklist_index(const LinkNode *list, const void *ptr) ATTR_WARN_UNUSED_RESULT
void mul_m4_v3(const float M[4][4], float r[3])
static uint free_localcollection_bit(const Main *bmain, ushort local_collections_uid, bool *r_reset)
void DRW_gpu_context_disable()
void BKE_object_minmax(Object *ob, float3 &r_min, float3 &r_max)
Definition object.cc:3842
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
bool BKE_scene_uses_blender_eevee(const Scene *scene)
Definition scene.cc:3077
static bool view3d_localview_exit(const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, const Scene *scene, ViewLayer *view_layer, ScrArea *area, const bool frame_selected, const int smooth_viewtx)
Object * BKE_view_layer_edit_object_get(const ViewLayer *view_layer)
Main * DEG_get_bmain(const Depsgraph *graph)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void ED_view3d_local_stats_free(View3D *v3d)
@ LAYER_COLLECTION_HIDE
eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const Scene *scene, const View3D *v3d, const Object *obact)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
@ VIEW3D_SELECT_PICK_NEAREST
Definition ED_view3d.hh:987
@ VIEW3D_SELECT_PICK_ALL
Definition ED_view3d.hh:985
Object * CTX_data_edit_object(const bContext *C)
void DEG_id_type_tag(Main *bmain, short id_type)
ModifierData * BKE_modifiers_get_virtual_modifierlist(const Object *ob, VirtualModifierData *data)
void ED_view3d_smooth_view_force_finish_no_camera_lock(const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, const Scene *scene, View3D *v3d, ARegion *region)
bool GPU_select_is_cached()
bool BKE_layer_collection_local_sync(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool WM_xr_session_is_ready(const wmXrData *xr)
@ DRW_SELECT_PASS_PRE
Definition DRW_engine.hh:50
@ DRW_SELECT_PASS_POST
Definition DRW_engine.hh:51
bool ED_operator_view3d_active(bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus view3d_camera_to_view_exec(bContext *C, wmOperator *)
void ED_view3d_smooth_view_ex(const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, ScrArea *area, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static bool view3d_camera_to_view_poll(bContext *C)
int view3d_gpu_select_with_id_filter(const ViewContext *vc, GPUSelectBuffer *buffer, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, uint select_id)
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
bool ED_localview_exit_if_empty(const Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, wmWindowManager *wm, wmWindow *win, View3D *v3d, ScrArea *area, bool frame_selected=true, int smooth_viewtx=0)
static bool view3d_localview_init(const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, Main *bmain, const Scene *scene, ViewLayer *view_layer, ScrArea *area, const bool frame_selected, const int smooth_viewtx, ReportList *reports)
static wmOperatorStatus localview_remove_from_exec(bContext *C, wmOperator *op)
void view3d_winmatrix_set(const Depsgraph *depsgraph, ARegion *region, const View3D *v3d, const rcti *rect)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
bool ED_view3d_lock(RegionView3D *rv3d)
T * DEG_get_original(T *id)
static bool drw_select_filter_object_mode_lock(Object *ob, void *user_data)
void rotate_m4(float mat[4][4], char axis, float angle)
bool BKE_scene_uses_blender_workbench(const Scene *scene)
Definition scene.cc:3082
void transpose_m4(float R[4][4])
@ G_FLAG_PICKSEL
Main * CTX_data_main(const bContext *C)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
void VIEW3D_OT_camera_to_view(wmOperatorType *ot)
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far)
void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region)
MINLINE void negate_v4(float r[4])
void ED_view3d_lastview_store(RegionView3D *rv3d)
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
void ED_view3d_draw_setup_view(const wmWindowManager *wm, wmWindow *win, Depsgraph *depsgraph, Scene *scene, ARegion *region, View3D *v3d, const float viewmat[4][4], const float winmat[4][4], const rcti *rect)
int view3d_gpu_select_ex(const ViewContext *vc, GPUSelectBuffer *buffer, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, eV3DSelectShape select_shape, bool do_material_slot_selection)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
VecBase< float, 3 > float3
bool ED_view3d_area_user_region(const ScrArea *area, const View3D *v3d, ARegion **r_region)
void ED_view3d_to_object(const Depsgraph *depsgraph, Object *ob, const float ofs[3], const float quat[4], float dist, float roll)
static void view3d_local_collections_reset(const Main *bmain, const uint local_view_bit)
void GPU_select_cache_begin()
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
const float(* GPU_matrix_projection_get(float m[4][4]))[4]
void normalize_m4_m4(float rmat[4][4], const float mat[4][4]) ATTR_NONNULL()
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
Definition rct.cc:480
bool BKE_object_is_mode_compat(const Object *ob, eObjectMode object_mode)
Definition object.cc:2058
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
int view3d_gpu_select(const ViewContext *vc, GPUSelectBuffer *buffer, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, eV3DSelectShape select_shape)
Object * CTX_data_active_object(const bContext *C)
void ED_view3d_local_collections_reset(const bContext *C, bool reset_all)
void ED_view3d_smooth_view(bContext *C, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
void BKE_object_tfm_protected_restore(Object *ob, const ObjectTfmProtectedChannels *obtfm, short protectflag)
Definition object.cc:3050
View3D * CTX_wm_view3d(const bContext *C)
void quat_to_mat4(float m[4][4], const float q[4])
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
static wmOperatorStatus localview_exec(bContext *C, wmOperator *op)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
eRegion_Type regiontype
GPUSelectStorage storage
Definition GPU_select.hh:49
eLayerCollection_Flag flag
ListBaseT< LayerCollection > layer_collections
unsigned short local_collections_bits
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
struct ModifierData * next
eObject_ProtectFlag protectflag
struct bPose * pose
struct RegionView3D * localvd
eRegionView3D_Flag rflag
eRegionView3D_ViewAxisRoll view_axis_roll
eRegionView3D_Persp persp
struct SmoothView3DStore * sms
eRegionView3D_View view
ListBaseT< ViewLayer > view_layers
struct Object * camera
View3DCursor cursor
struct ToolSettings * toolsettings
ListBaseT< ARegion > regionbase
ListBaseT< SpaceLink > spacedata
eView3DOverlay_Flag flag
View3DOverlay overlay
eView3D_Flag2 flag2
struct Object * ob_center
struct Object * camera
View3DShading shading
unsigned short local_collections_uid
struct View3D * localvd
unsigned short local_view_uid
View3D_Runtime runtime
ViewLayer * view_layer
Definition ED_view3d.hh:80
RegionView3D * rv3d
Definition ED_view3d.hh:86
Depsgraph * depsgraph
Definition ED_view3d.hh:78
ListBaseT< LayerCollection > layer_collections
ListBaseT< struct ScrArea > areabase
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
struct ReportList * reports