Blender V5.3
view3d_utils.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
10
11#include <algorithm>
12#include <cfloat>
13#include <cmath>
14#include <cstdio>
15#include <cstring>
16
17#include "DNA_camera_types.h"
18#include "DNA_curve_types.h"
19#include "DNA_object_types.h"
20#include "DNA_scene_types.h"
21#include "DNA_view3d_types.h"
22#include "DNA_world_types.h"
23
24#include "RNA_path.hh"
25
26#include "MEM_guardedalloc.h"
27
28#include "BLI_array_utils_c.hh"
29#include "BLI_bitmap_draw_2d.hh"
30#include "BLI_listbase.hh"
31#include "BLI_math_color_c.hh"
32#include "BLI_math_geom_c.hh"
33#include "BLI_math_matrix.hh"
34#include "BLI_math_matrix_c.hh"
36#include "BLI_math_vector_c.hh"
37#include "BLI_rect.hh"
38#include "BLI_utildefines.hh"
39#include "BLI_vector.hh"
40
41#include "BKE_camera.h"
42#include "BKE_context.hh"
43#include "BKE_library.hh"
44#include "BKE_object.hh"
45#include "BKE_scene.hh"
46#include "BKE_screen.hh"
47
48#include "DEG_depsgraph.hh"
50
51#include "GPU_matrix.hh"
52
53#include "WM_api.hh"
54#include "WM_types.hh"
55
56#include "ED_keyframing.hh"
57#include "ED_screen.hh"
58#include "ED_undo.hh"
59#include "ED_view3d.hh"
60
61#include "ANIM_keyframing.hh"
62#include "ANIM_keyingsets.hh"
63
64#include "UI_resources.hh"
65
66#include "view3d_intern.hh" /* own include */
67
68namespace blender {
69
70/* -------------------------------------------------------------------- */
73
74void ED_view3d_background_color_get(const Scene *scene, const View3D *v3d, float r_color[3])
75{
77 if (scene->world) {
78 copy_v3_v3(r_color, &scene->world->horr);
79 return;
80 }
81 }
83 copy_v3_v3(r_color, v3d->shading.background_color);
84 return;
85 }
86
88}
89
91 const View3D *v3d,
92 float r_text_color[4],
93 float r_shadow_color[4])
94{
95 /* Text fully opaque, shadow slightly transparent. */
96 r_text_color[3] = 1.0f;
97 r_shadow_color[3] = 0.8f;
98
99 /* Default text color from TH_TEXT_HI. If it is too close
100 * to the background color, darken or lighten it. */
102 float text_lightness = srgb_to_grayscale(r_text_color);
103 float bg_color[3];
104 ED_view3d_background_color_get(scene, v3d, bg_color);
105 const float distance = len_v3v3(r_text_color, bg_color);
106 if (distance < 0.5f) {
107 if (text_lightness > 0.5f) {
108 mul_v3_fl(r_text_color, 0.33f);
109 }
110 else {
111 mul_v3_fl(r_text_color, 3.0f);
112 }
113 clamp_v3(r_text_color, 0.0f, 1.0f);
114 }
115
116 /* Shadow color is black or white depending on final text lightness. */
117 text_lightness = srgb_to_grayscale(r_text_color);
118 if (text_lightness > 0.4f) {
119 copy_v3_fl(r_shadow_color, 0.0f);
120 }
121 else {
122 copy_v3_fl(r_shadow_color, 1.0f);
123 }
124}
125
127 const Object *ob,
128 const View3D *v3d)
129{
130 if (v3d->shading.type == OB_SOLID) {
132 return true;
133 }
134 if (ob && ob->mode == OB_MODE_TEXTURE_PAINT) {
135 return true;
136 }
137 }
138 else if (v3d->shading.type == OB_RENDER) {
141 }
142 }
143 return false;
144}
145
147{
148 /* establish the camera object,
149 * so we can default to view mapping if anything is wrong with it */
150 if ((rv3d->persp == RV3D_CAMOB) && v3d->camera && (v3d->camera->type == OB_CAMERA)) {
151 return id_cast<Camera *>(v3d->camera->data);
152 }
153 return nullptr;
154}
155
156float ED_view3d_dist_soft_min_get(const View3D *v3d, const bool use_persp_range)
157{
158 return use_persp_range ? (v3d->clip_start * 1.5f) : v3d->grid * 0.001f;
159}
160
161Bounds<float> ED_view3d_dist_soft_range_get(const View3D *v3d, const bool use_persp_range)
162{
163 return {
164 ED_view3d_dist_soft_min_get(v3d, use_persp_range),
165 v3d->clip_end * 10.0f,
166 };
167}
168
169bool ED_view3d_clip_range_get(const Depsgraph *depsgraph,
170 const View3D *v3d,
171 const RegionView3D *rv3d,
172 const bool use_ortho_factor,
173 float *r_clip_start,
174 float *r_clip_end)
175{
176 CameraParams params;
177
178 BKE_camera_params_init(&params);
179 BKE_camera_params_from_view3d(&params, depsgraph, v3d, rv3d);
180
181 if (use_ortho_factor && params.is_ortho) {
182 const float fac = 2.0f / (params.clip_end - params.clip_start);
183 params.clip_start *= fac;
184 params.clip_end *= fac;
185 }
186
187 if (r_clip_start) {
188 *r_clip_start = params.clip_start;
189 }
190 if (r_clip_end) {
191 *r_clip_end = params.clip_end;
192 }
193
194 return params.is_ortho;
195}
196
197bool ED_view3d_viewplane_get(const Depsgraph *depsgraph,
198 const View3D *v3d,
199 const RegionView3D *rv3d,
200 int winx,
201 int winy,
202 rctf *r_viewplane,
203 float *r_clip_start,
204 float *r_clip_end,
205 float *r_pixsize)
206{
207 CameraParams params;
208
209 BKE_camera_params_init(&params);
210 BKE_camera_params_from_view3d(&params, depsgraph, v3d, rv3d);
211 BKE_camera_params_compute_viewplane(&params, winx, winy, 1.0f, 1.0f);
212
213 if (r_viewplane) {
214 *r_viewplane = params.viewplane;
215 }
216 if (r_clip_start) {
217 *r_clip_start = params.clip_start;
218 }
219 if (r_clip_end) {
220 *r_clip_end = params.clip_end;
221 }
222 if (r_pixsize) {
223 *r_pixsize = params.viewdx;
224 }
225
226 return params.is_ortho;
227}
228
230
231/* -------------------------------------------------------------------- */
234
236{
237 ARegion *region = CTX_wm_region(C);
238
240}
241
243{
244 /* for debugging purpose, context should always be OK */
245 if ((region == nullptr) || (region->regiontype != RGN_TYPE_WINDOW)) {
246 printf("view3d_region_operator_needs_gpu error, wrong region\n");
247 }
248 else {
249 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
250
251 wmViewport(&region->winrct); /* TODO: bad */
253 GPU_matrix_set(rv3d->viewmat);
254 }
255}
256
257void ED_view3d_polygon_offset(const RegionView3D *rv3d, const float dist)
258{
259 if (rv3d->rflag & RV3D_ZOFFSET_DISABLED) {
260 return;
261 }
262
263 float viewdist = rv3d->dist;
264
265 /* Special exception for orthographic camera (`viewdist` isn't used for perspective cameras). */
266 if (dist != 0.0f) {
267 if (rv3d->persp == RV3D_CAMOB) {
268 if (rv3d->is_persp == false) {
269 viewdist = 1.0f / max_ff(fabsf(rv3d->winmat[0][0]), fabsf(rv3d->winmat[1][1]));
270 }
271 }
272 }
273
274 GPU_polygon_offset(viewdist, dist);
275}
276
278{
279 bScreen *screen = CTX_wm_screen(C);
280 ScrArea *area = CTX_wm_area(C);
281
282 /* area can be nullptr when called from python */
283 if (area == nullptr || area->spacetype != SPACE_VIEW3D) {
284 area = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0);
285 }
286
287 if (area == nullptr) {
288 return false;
289 }
290
292 if (region == nullptr) {
293 return false;
294 }
295
296 /* Bad context switch. */
297 CTX_wm_area_set(C, area);
298 CTX_wm_region_set(C, region);
299
300 return true;
301}
302
304
305/* -------------------------------------------------------------------- */
308
310 const BoundBox *bb,
311 const bool is_flip)
312{
313 for (int val = 0; val < 4; val++) {
314 normal_tri_v3(clip[val], bb->vec[val], bb->vec[val == 3 ? 0 : val + 1], bb->vec[val + 4]);
315 if (is_flip) [[unlikely]] {
316 negate_v3(clip[val]);
317 }
318
319 clip[val][3] = -dot_v3v3(clip[val], bb->vec[val]);
320 }
321}
322
324 BoundBox *bb, float planes[4][4], const ARegion *region, const Object *ob, const rcti *rect)
325{
326 /* init in case unproject fails */
327 memset(bb->vec, 0, sizeof(bb->vec));
328
329 /* four clipping planes and bounding volume */
330 /* first do the bounding volume */
331 for (int val = 0; val < 4; val++) {
332 float xs = ELEM(val, 0, 3) ? rect->xmin : rect->xmax;
333 float ys = ELEM(val, 0, 1) ? rect->ymin : rect->ymax;
334
335 ED_view3d_unproject_v3(region, xs, ys, 0.0, bb->vec[val]);
336 ED_view3d_unproject_v3(region, xs, ys, 1.0, bb->vec[4 + val]);
337 }
338
339 /* optionally transform to object space */
340 if (ob) {
341 float imat[4][4];
342 invert_m4_m4(imat, ob->object_to_world().ptr());
343
344 for (int val = 0; val < 8; val++) {
345 mul_m4_v3(imat, bb->vec[val]);
346 }
347 }
348
349 /* verify if we have negative scale. doing the transform before cross
350 * product flips the sign of the vector compared to doing cross product
351 * before transform then, so we correct for that. */
352 int flip_sign = (ob) ? is_negative_m4(ob->object_to_world().ptr()) : false;
353
354 ED_view3d_clipping_calc_from_boundbox(planes, bb, flip_sign);
355}
356
358
359/* -------------------------------------------------------------------- */
362
364 float min[3];
365 float max[3];
366};
367
369 const float co[3], int /*i*/, int /*j*/, int /*k*/, void *user_data_p)
370{
372 user_data_p);
373 minmax_v3v3_v3(user_data->min, user_data->max, co);
374}
375
376bool ED_view3d_clipping_clamp_minmax(const RegionView3D *rv3d, float min[3], float max[3])
377{
378 /* 6 planes for the cube, 4..6 for the current view clipping planes. */
379 float planes[6 + 6][4];
380
381 /* Convert the min/max to 6 planes. */
382 for (int i = 0; i < 3; i++) {
383 float *plane_min = planes[(i * 2) + 0];
384 float *plane_max = planes[(i * 2) + 1];
385 zero_v3(plane_min);
386 zero_v3(plane_max);
387 plane_min[i] = -1.0f;
388 plane_min[3] = +min[i];
389 plane_max[i] = +1.0f;
390 plane_max[3] = -max[i];
391 }
392
393 /* Copy planes from the viewport & flip. */
394 int planes_len = 6;
395 int clip_len = (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXCLIP) ? 4 : 6;
396 for (int i = 0; i < clip_len; i++) {
397 negate_v4_v4(planes[planes_len], rv3d->clip[i]);
398 planes_len += 1;
399 }
400
401 /* Calculate points intersecting all planes (effectively intersecting two bounding boxes). */
403 INIT_MINMAX(user_data.min, user_data.max);
404
405 const float eps_coplanar = 1e-4f;
406 const float eps_isect = 1e-6f;
408 planes, planes_len, eps_coplanar, eps_isect, points_in_planes_minmax_fn, &user_data))
409 {
410 copy_v3_v3(min, user_data.min);
411 copy_v3_v3(max, user_data.max);
412 return true;
413 }
414 return false;
415}
416
418
419/* -------------------------------------------------------------------- */
422
423static bool view3d_boundbox_clip_m4(const BoundBox *bb, const float persmatob[4][4])
424{
425 int a, flag = -1, fl;
426
427 for (a = 0; a < 8; a++) {
428 float vec[4], min, max;
429 copy_v3_v3(vec, bb->vec[a]);
430 vec[3] = 1.0;
431 mul_m4_v4(persmatob, vec);
432 max = vec[3];
433 min = -vec[3];
434
435 fl = 0;
436 if (vec[0] < min) {
437 fl += 1;
438 }
439 if (vec[0] > max) {
440 fl += 2;
441 }
442 if (vec[1] < min) {
443 fl += 4;
444 }
445 if (vec[1] > max) {
446 fl += 8;
447 }
448 if (vec[2] < min) {
449 fl += 16;
450 }
451 if (vec[2] > max) {
452 fl += 32;
453 }
454
455 flag &= fl;
456 if (flag == 0) {
457 return true;
458 }
459 }
460
461 return false;
462}
463
464bool ED_view3d_boundbox_clip_ex(const RegionView3D *rv3d, const BoundBox *bb, float obmat[4][4])
465{
466 /* return 1: draw */
467
468 float persmatob[4][4];
469
470 if (bb == nullptr) {
471 return true;
472 }
473
474 mul_m4_m4m4(persmatob, const_cast<float (*)[4]>(rv3d->persmat), obmat);
475
476 return view3d_boundbox_clip_m4(bb, persmatob);
477}
478
480{
481 if (bb == nullptr) {
482 return true;
483 }
484 return view3d_boundbox_clip_m4(bb, rv3d->persmatob);
485}
486
488
489/* -------------------------------------------------------------------- */
494
496{
497 return (rv3d->persp != RV3D_CAMOB) && (v3d->ob_center_cursor || v3d->ob_center);
498}
499
501{
502 copy_qt_qt(rv3d->lviewquat, rv3d->viewquat);
503 rv3d->lview = rv3d->view;
504 rv3d->lview_axis_roll = rv3d->view_axis_roll;
505 if (rv3d->persp != RV3D_CAMOB) {
506 rv3d->lpersp = rv3d->persp;
507 }
508}
509
511{
512 v3d->ob_center = nullptr;
513 v3d->ob_center_bone[0] = '\0';
514 v3d->ob_center_cursor = false;
515
516 v3d->flag2 &= ~V3D_LOCK_CAMERA;
517}
518
519void ED_view3d_persp_switch_from_camera(const Depsgraph *depsgraph,
520 View3D *v3d,
521 RegionView3D *rv3d,
522 const eRegionView3D_Persp persp)
523{
524 BLI_assert(rv3d->persp == RV3D_CAMOB);
525 BLI_assert(persp != RV3D_CAMOB);
526
527 if (v3d->camera) {
528 Object *ob_camera_eval = DEG_get_evaluated(depsgraph, v3d->camera);
530 ob_camera_eval->object_to_world().ptr(), rv3d->ofs, VIEW3D_DIST_FALLBACK);
532 ob_camera_eval, rv3d->ofs, rv3d->viewquat, &rv3d->dist, rv3d->camroll, nullptr);
534 }
535
536 if (!ED_view3d_camera_lock_check(v3d, rv3d)) {
537 rv3d->persp = persp;
538 }
539}
540bool ED_view3d_persp_ensure(const Depsgraph *depsgraph, View3D *v3d, ARegion *region)
541{
542 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
543 const bool autopersp = (U.uiflag & USER_AUTOPERSP) != 0;
544
546
547 if (ED_view3d_camera_lock_check(v3d, rv3d)) {
548 return false;
549 }
550
551 if (rv3d->persp != RV3D_PERSP) {
552 if (rv3d->persp == RV3D_CAMOB) {
553 /* If autopersp and previous view was an axis one,
554 * switch back to PERSP mode, else reuse previous mode. */
555 eRegionView3D_Persp persp = (autopersp && RV3D_VIEW_IS_AXIS(rv3d->lview)) ? RV3D_PERSP :
556 rv3d->lpersp;
557 ED_view3d_persp_switch_from_camera(depsgraph, v3d, rv3d, persp);
558 }
559 else if (autopersp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
560 rv3d->persp = RV3D_PERSP;
561 }
562 return true;
563 }
564
565 return false;
566}
567
569
570/* -------------------------------------------------------------------- */
575
577{
578 const float camzoom_init = rv3d->camzoom;
579 float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
580 /* Clamp both before and after conversion to prevent NAN on negative values. */
581
582 zoomfac = zoomfac * scale;
586 return (rv3d->camzoom != camzoom_init);
587}
588
589bool ED_view3d_camera_view_pan(ARegion *region, const float event_ofs[2])
590{
591 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
592 const float camdxy_init[2] = {rv3d->camdx, rv3d->camdy};
593 const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 2.0f;
594 float2 xy = {
595 event_ofs[0] / (region->winx * zoomfac),
596 event_ofs[1] / (region->winy * zoomfac),
597 };
598
599 if ((rv3d->rflag & RV3D_FLIP_X) != 0) {
600 xy.x = -xy.x;
601 }
602
603 /* Calculate pan direction after roll. */
604 if (rv3d->camroll != 0.0f) {
605 const float aspect = float(region->winx) / float(region->winy);
606 xy.x *= aspect;
607
609 xy = rot_invert * xy;
610
611 xy.x /= aspect;
612 }
613
614 rv3d->camdx += xy.x;
615 rv3d->camdy += xy.y;
616
617 CLAMP(rv3d->camdx, -1.0f, 1.0f);
618 CLAMP(rv3d->camdy, -1.0f, 1.0f);
619 return (camdxy_init[0] != rv3d->camdx) || (camdxy_init[1] != rv3d->camdy);
620}
621
623
624/* -------------------------------------------------------------------- */
629
631{
632 return ((v3d->camera) && ID_IS_EDITABLE(v3d->camera) && (v3d->flag2 & V3D_LOCK_CAMERA) &&
633 (rv3d->persp == RV3D_CAMOB));
634}
635
636void ED_view3d_camera_lock_init_ex(const Depsgraph *depsgraph,
637 View3D *v3d,
638 RegionView3D *rv3d,
639 const bool calc_dist)
640{
641 if (ED_view3d_camera_lock_check(v3d, rv3d)) {
642 Object *ob_camera_eval = DEG_get_evaluated(depsgraph, v3d->camera);
643 if (calc_dist) {
644 /* using a fallback dist is OK here since ED_view3d_from_object() compensates for it */
646 ob_camera_eval->object_to_world().ptr(), rv3d->ofs, VIEW3D_DIST_FALLBACK);
647 }
648 /* Restore the roll removed when syncing from the camera object. */
650 ob_camera_eval, rv3d->ofs, rv3d->viewquat, &rv3d->dist, rv3d->camroll, nullptr);
651 }
652}
653
654void ED_view3d_camera_lock_init(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
655{
656 ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, true);
657}
658
659bool ED_view3d_camera_lock_sync(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
660{
661 if (ED_view3d_camera_lock_check(v3d, rv3d)) {
663 Object *root_parent;
664
666 (root_parent = v3d->camera->parent))
667 {
668 Object *ob_update;
669 float tmat[4][4];
670 float imat[4][4];
671 float view_mat[4][4];
672 float diff_mat[4][4];
673 float parent_mat[4][4];
674
675 while (root_parent->parent) {
676 root_parent = root_parent->parent;
677 }
678 Object *ob_camera_eval = DEG_get_evaluated(depsgraph, v3d->camera);
679 Object *root_parent_eval = DEG_get_evaluated(depsgraph, root_parent);
680
681 ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist, rv3d->camroll);
682
683 normalize_m4_m4(tmat, ob_camera_eval->object_to_world().ptr());
684
685 invert_m4_m4(imat, tmat);
686 mul_m4_m4m4(diff_mat, view_mat, imat);
687
688 mul_m4_m4m4(parent_mat, diff_mat, root_parent_eval->object_to_world().ptr());
689
690 BKE_object_tfm_protected_backup(root_parent, &obtfm);
691 BKE_object_apply_mat4(root_parent, parent_mat, true, false);
692 BKE_object_tfm_protected_restore(root_parent, &obtfm, root_parent->protectflag);
693
694 ob_update = v3d->camera;
695 while (ob_update) {
698 ob_update = ob_update->parent;
699 }
700 }
701 else {
702 /* always maintain the same scale */
703 const short protect_scale_all = (OB_LOCK_SCALEX | OB_LOCK_SCALEY | OB_LOCK_SCALEZ);
706 depsgraph, v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist, rv3d->camroll);
708 v3d->camera, &obtfm, v3d->camera->protectflag | protect_scale_all);
709
712 }
713
714 return true;
715 }
716 return false;
717}
718
720 const Scene *scene, ID *id_key, bContext *C, const bool do_rotate, const bool do_translate)
721{
722 BLI_assert(GS(id_key->name) == ID_OB);
723 /* While `autokeyframe_object` does already call `autokeyframe_cfra_can_key` we need this here
724 * because at the time of writing this it returns void. Once the keying result is returned, like
725 * implemented for `animrig::insert_keyframes`, this `if` can be removed. */
726 if (!animrig::autokeyframe_cfra_can_key(scene, id_key)) {
727 return false;
728 }
729
730 Object *camera_object = reinterpret_cast<Object *>(id_key);
731
732 Vector<RNAPath> rna_paths;
733
734 if (do_rotate) {
735 switch (camera_object->rotmode) {
736 case ROT_MODE_QUAT:
737 rna_paths.append({"rotation_quaternion"});
738 break;
739
741 rna_paths.append({"rotation_axis_angle"});
742 break;
743
744 default:
745 rna_paths.append({"rotation_euler"});
746 break;
747 }
748 }
749 if (do_translate) {
750 rna_paths.append({"location"});
751 }
752
753 animrig::autokeyframe_object(C, scene, camera_object, rna_paths);
755 return true;
756}
757
759 View3D *v3d, RegionView3D *rv3d, bContext *C, const bool do_rotate, const bool do_translate)
760{
761 /* similar to ED_view3d_cameracontrol_update */
762 if (ED_view3d_camera_lock_check(v3d, rv3d)) {
763 Scene *scene = CTX_data_scene(C);
764 ID *id_key;
765 Object *root_parent;
767 (root_parent = v3d->camera->parent))
768 {
769 while (root_parent->parent) {
770 root_parent = root_parent->parent;
771 }
772 id_key = &root_parent->id;
773 }
774 else {
775 id_key = &v3d->camera->id;
776 }
777
778 return ED_view3d_camera_autokey(scene, id_key, C, do_rotate, do_translate);
779 }
780 return false;
781}
782
784{
785 if (ED_view3d_camera_lock_check(v3d, rv3d)) {
787 return true;
788 }
789 }
790 return false;
791}
792
801static bool view3d_camera_lock_undo_ex(const char *str,
802 const View3D *v3d,
803 const RegionView3D *rv3d,
804 bContext *C,
805 const bool undo_group)
806{
807 if (ED_view3d_camera_lock_undo_test(v3d, rv3d, C)) {
808 if (undo_group) {
810 }
811 else {
813 }
814 return true;
815 }
816 return false;
817}
818
820 const View3D *v3d,
821 const RegionView3D *rv3d,
822 bContext *C)
823{
824 return view3d_camera_lock_undo_ex(str, v3d, rv3d, C, false);
825}
826
828 const View3D *v3d,
829 const RegionView3D *rv3d,
830 bContext *C)
831{
832 return view3d_camera_lock_undo_ex(str, v3d, rv3d, C, true);
833}
834
836
837/* -------------------------------------------------------------------- */
842
843static void view3d_boxview_clip(ScrArea *area)
844{
845 BoundBox *bb = MEM_new<BoundBox>("clipbb");
846 float clip[6][4];
847 float x1 = 0.0f, y1 = 0.0f, z1 = 0.0f, ofs[3] = {0.0f, 0.0f, 0.0f};
848
849 /* create bounding box */
850 for (ARegion &region : area->regionbase) {
851 if (region.regiontype == RGN_TYPE_WINDOW) {
852 RegionView3D *rv3d = static_cast<RegionView3D *>(region.regiondata);
853
854 if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXCLIP) {
856 if (region.winx > region.winy) {
857 x1 = rv3d->dist;
858 }
859 else {
860 x1 = region.winx * rv3d->dist / region.winy;
861 }
862
863 if (region.winx > region.winy) {
864 y1 = region.winy * rv3d->dist / region.winx;
865 }
866 else {
867 y1 = rv3d->dist;
868 }
869 copy_v2_v2(ofs, rv3d->ofs);
870 }
871 else if (ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) {
872 ofs[2] = rv3d->ofs[2];
873
874 if (region.winx > region.winy) {
875 z1 = region.winy * rv3d->dist / region.winx;
876 }
877 else {
878 z1 = rv3d->dist;
879 }
880 }
881 }
882 }
883 }
884
885 for (int val = 0; val < 8; val++) {
886 if (ELEM(val, 0, 3, 4, 7)) {
887 bb->vec[val][0] = -x1 - ofs[0];
888 }
889 else {
890 bb->vec[val][0] = x1 - ofs[0];
891 }
892
893 if (ELEM(val, 0, 1, 4, 5)) {
894 bb->vec[val][1] = -y1 - ofs[1];
895 }
896 else {
897 bb->vec[val][1] = y1 - ofs[1];
898 }
899
900 if (val > 3) {
901 bb->vec[val][2] = -z1 - ofs[2];
902 }
903 else {
904 bb->vec[val][2] = z1 - ofs[2];
905 }
906 }
907
908 /* normals for plane equations */
909 normal_tri_v3(clip[0], bb->vec[0], bb->vec[1], bb->vec[4]);
910 normal_tri_v3(clip[1], bb->vec[1], bb->vec[2], bb->vec[5]);
911 normal_tri_v3(clip[2], bb->vec[2], bb->vec[3], bb->vec[6]);
912 normal_tri_v3(clip[3], bb->vec[3], bb->vec[0], bb->vec[7]);
913 normal_tri_v3(clip[4], bb->vec[4], bb->vec[5], bb->vec[6]);
914 normal_tri_v3(clip[5], bb->vec[0], bb->vec[2], bb->vec[1]);
915
916 /* then plane equations */
917 for (int val = 0; val < 6; val++) {
918 clip[val][3] = -dot_v3v3(clip[val], bb->vec[val % 5]);
919 }
920
921 /* create bounding box */
922 for (ARegion &region : area->regionbase) {
923 if (region.regiontype == RGN_TYPE_WINDOW) {
924 RegionView3D *rv3d = static_cast<RegionView3D *>(region.regiondata);
925
926 if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXCLIP) {
927 rv3d->rflag |= RV3D_CLIPPING;
928 memcpy(rv3d->clip, clip, sizeof(clip));
929 if (rv3d->clipbb) {
930 MEM_delete(rv3d->clipbb);
931 }
932 rv3d->clipbb = MEM_dupalloc(bb);
933 }
934 }
935 }
936 MEM_delete(bb);
937}
938
943static void view3d_boxview_sync_axis(RegionView3D *rv3d_dst, RegionView3D *rv3d_src)
944{
945 /* absolute axis values above this are considered to be set (will be ~1.0f) */
946 const float axis_eps = 0.5f;
947 float viewinv[4];
948
949 /* use the view rotation to identify which axis to sync on */
950 float view_axis_all[4][3] = {
951 {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}};
952
953 float *view_src_x = &view_axis_all[0][0];
954 float *view_src_y = &view_axis_all[1][0];
955
956 float *view_dst_x = &view_axis_all[2][0];
957 float *view_dst_y = &view_axis_all[3][0];
958 int i;
959
960 /* we could use rv3d->viewinv, but better not depend on view matrix being updated */
961 if (ED_view3d_quat_from_axis_view(rv3d_src->view, rv3d_src->view_axis_roll, viewinv) == false)
962 [[unlikely]]
963 {
964 return;
965 }
966 invert_qt_normalized(viewinv);
967 mul_qt_v3(viewinv, view_src_x);
968 mul_qt_v3(viewinv, view_src_y);
969
970 if (ED_view3d_quat_from_axis_view(rv3d_dst->view, rv3d_dst->view_axis_roll, viewinv) == false)
971 [[unlikely]]
972 {
973 return;
974 }
975 invert_qt_normalized(viewinv);
976 mul_qt_v3(viewinv, view_dst_x);
977 mul_qt_v3(viewinv, view_dst_y);
978
979 /* Check source and destination have a matching axis. */
980 for (i = 0; i < 3; i++) {
981 if (((fabsf(view_src_x[i]) > axis_eps) || (fabsf(view_src_y[i]) > axis_eps)) &&
982 ((fabsf(view_dst_x[i]) > axis_eps) || (fabsf(view_dst_y[i]) > axis_eps)))
983 {
984 rv3d_dst->ofs[i] = rv3d_src->ofs[i];
985 }
986 }
987}
988
990{
991 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
992 short clip = 0;
993
994 for (ARegion &region_test : area->regionbase) {
995 if (&region_test != region && region_test.regiontype == RGN_TYPE_WINDOW) {
996 RegionView3D *rv3dtest = static_cast<RegionView3D *>(region_test.regiondata);
997
998 if (RV3D_LOCK_FLAGS(rv3dtest) & RV3D_LOCK_ROTATION) {
999 rv3dtest->dist = rv3d->dist;
1000 view3d_boxview_sync_axis(rv3dtest, rv3d);
1001 clip |= RV3D_LOCK_FLAGS(rv3dtest) & RV3D_BOXCLIP;
1002
1003 ED_region_tag_redraw(&region_test);
1004 }
1005 }
1006 }
1007
1008 if (clip) {
1009 view3d_boxview_clip(area);
1010 }
1011}
1012
1014{
1015 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1016 bool clip = false;
1017
1018 for (ARegion &region_test : area->regionbase) {
1019 if (&region_test != region && region_test.regiontype == RGN_TYPE_WINDOW) {
1020 RegionView3D *rv3dtest = static_cast<RegionView3D *>(region_test.regiondata);
1021
1022 if (RV3D_LOCK_FLAGS(rv3dtest)) {
1023 rv3dtest->dist = rv3d->dist;
1024 copy_v3_v3(rv3dtest->ofs, rv3d->ofs);
1025 ED_region_tag_redraw(&region_test);
1026
1027 clip |= ((RV3D_LOCK_FLAGS(rv3dtest) & RV3D_BOXCLIP) != 0);
1028 }
1029 }
1030 }
1031
1032 if (clip) {
1033 view3d_boxview_clip(area);
1034 }
1035}
1036
1037void ED_view3d_quadview_update(ScrArea *area, ARegion *region, bool do_clip)
1038{
1039 ARegion *region_sync = nullptr;
1040 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1041 /* this function copies flags from the first of the 3 other quadview
1042 * regions to the 2 other, so it assumes this is the region whose
1043 * properties are always being edited, weak */
1044 eRegionView3D_ViewLock viewlock = rv3d->viewlock;
1045
1046 if ((viewlock & RV3D_LOCK_ROTATION) == 0) {
1047 do_clip = (viewlock & RV3D_BOXCLIP) != 0;
1048 viewlock = eRegionView3D_ViewLock{};
1049 }
1050 else if ((viewlock & RV3D_BOXVIEW) == 0 && (viewlock & RV3D_BOXCLIP) != 0) {
1051 do_clip = true;
1052 viewlock &= ~RV3D_BOXCLIP;
1053 }
1054
1055 for (; region; region = region->prev) {
1056 if (region->alignment == RGN_ALIGN_QSPLIT) {
1057 rv3d = static_cast<RegionView3D *>(region->regiondata);
1058 rv3d->viewlock = viewlock;
1059
1060 if (do_clip && (viewlock & RV3D_BOXCLIP) == 0) {
1061 rv3d->rflag &= ~RV3D_CLIPPING;
1062 }
1063
1064 /* use region_sync so we sync with one of the aligned views below
1065 * else the view jumps on changing view settings like 'clip'
1066 * since it copies from the perspective view */
1067 region_sync = region;
1068 }
1069 }
1070
1071 if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
1072 view3d_boxview_sync(area, region_sync ? region_sync : area->regionbase.last());
1073 }
1074
1075 /* ensure locked regions have an axis, locked user views don't make much sense */
1076 if (viewlock & RV3D_LOCK_ROTATION) {
1077 int index_qsplit = 0;
1078 for (ARegion &region_iter : area->regionbase) {
1079 if (region_iter.alignment == RGN_ALIGN_QSPLIT) {
1080 rv3d = static_cast<RegionView3D *>(region_iter.regiondata);
1081 if (rv3d->viewlock) {
1082 if (!RV3D_VIEW_IS_AXIS(rv3d->view) || (rv3d->view_axis_roll != RV3D_VIEW_AXIS_ROLL_0)) {
1083 rv3d->view = ED_view3d_lock_view_from_index(index_qsplit);
1085 rv3d->persp = RV3D_ORTHO;
1086 ED_view3d_lock(rv3d);
1087 }
1088 }
1089 index_qsplit++;
1090 }
1091 }
1092 }
1093
1094 ED_area_tag_redraw(area);
1095}
1096
1098
1099/* -------------------------------------------------------------------- */
1105
1106static const char *view3d_autodepth_last_id = "view3d_autodist_last";
1107
1112 float ofs[3];
1114};
1115
1117{
1118 if (event->flag & WM_EVENT_IS_CONSECUTIVE) {
1119 const View3D_AutoDistLast *autodepth_last = static_cast<const View3D_AutoDistLast *>(
1121 if (autodepth_last) {
1122 return true;
1123 }
1124 }
1125 return false;
1126}
1127
1132
1134 const wmEvent *event,
1135 const float ofs[3],
1136 const bool has_depth)
1137{
1139
1141 View3D_AutoDistLast *autodepth_last = MEM_new_zeroed<View3D_AutoDistLast>(__func__);
1142
1143 autodepth_last->has_depth = has_depth;
1144 copy_v3_v3(autodepth_last->ofs, ofs);
1145
1147 }
1148}
1149
1150bool ED_view3d_autodist_last_get(wmWindow *win, float r_ofs[3])
1151{
1152 const View3D_AutoDistLast *autodepth_last = static_cast<const View3D_AutoDistLast *>(
1154 /* #ED_view3d_autodist_last_check should be called first. */
1155 BLI_assert(autodepth_last);
1156 if (autodepth_last == nullptr) {
1157 return false;
1158 }
1159
1160 if (autodepth_last->has_depth == false) {
1161 zero_v3(r_ofs);
1162 return false;
1163 }
1164 copy_v3_v3(r_ofs, autodepth_last->ofs);
1165 return true;
1166}
1167
1169
1170/* -------------------------------------------------------------------- */
1173
1174static float view_autodist_depth_margin(ARegion *region, const int mval[2], int margin)
1175{
1176 rcti rect;
1177 if (margin == 0) {
1178 /* Get Z Depths, needed for perspective, nice for ortho */
1179 rect.xmin = mval[0];
1180 rect.ymin = mval[1];
1181 rect.xmax = mval[0] + 1;
1182 rect.ymax = mval[1] + 1;
1183 }
1184 else {
1185 BLI_rcti_init_pt_radius(&rect, mval, margin);
1186 }
1187
1188 ViewDepths depth_temp = {0};
1189 view3d_depths_rect_create(region, &rect, &depth_temp);
1190 float depth_close = view3d_depth_near(&depth_temp);
1191 MEM_SAFE_DELETE(depth_temp.depths);
1192 return depth_close;
1193}
1194
1196 View3D *v3d,
1197 const int mval[2],
1198 float mouse_worldloc[3],
1199 const float fallback_depth_pt[3])
1200{
1201 float depth_close;
1202 int margin_arr[] = {0, 2, 4};
1203 bool depth_ok = false;
1204
1205 /* Attempt with low margin's first */
1206 int i = 0;
1207 do {
1208 depth_close = view_autodist_depth_margin(region, mval, margin_arr[i++] * U.pixelsize);
1209 depth_ok = (depth_close != FLT_MAX);
1210 } while ((depth_ok == false) && (i < ARRAY_SIZE(margin_arr)));
1211
1212 if (depth_ok) {
1213 float centx = float(mval[0]) + 0.5f;
1214 float centy = float(mval[1]) + 0.5f;
1215
1216 if (ED_view3d_unproject_v3(region, centx, centy, depth_close, mouse_worldloc)) {
1217 return true;
1218 }
1219 }
1220
1221 if (fallback_depth_pt) {
1222 ED_view3d_win_to_3d_int(v3d, region, fallback_depth_pt, mval, mouse_worldloc);
1223 return true;
1224 }
1225 return false;
1226}
1227
1229 const int mval[2],
1230 float mouse_worldloc[3],
1231 int margin,
1232 const float *force_depth)
1233{
1234 /* Get Z Depths, needed for perspective, nice for ortho */
1235 float depth;
1236 if (force_depth) {
1237 depth = *force_depth;
1238 }
1239 else {
1240 depth = view_autodist_depth_margin(region, mval, margin);
1241 }
1242
1243 if (depth == FLT_MAX) {
1244 return false;
1245 }
1246
1247 float centx = float(mval[0]) + 0.5f;
1248 float centy = float(mval[1]) + 0.5f;
1249 return ED_view3d_unproject_v3(region, centx, centy, depth, mouse_worldloc);
1250}
1251
1252static bool depth_segment_cb(int x, int y, void *user_data)
1253{
1254 struct UserData {
1255 const ViewDepths *vd;
1256 int margin;
1257 float depth;
1258 } *data = static_cast<UserData *>(user_data);
1259 int mval[2];
1260 float depth;
1261
1262 mval[0] = x;
1263 mval[1] = y;
1264
1265 if (ED_view3d_depth_read_cached(data->vd, mval, data->margin, &depth)) {
1266 data->depth = depth;
1267 return false;
1268 }
1269 return true;
1270}
1271
1273 const ViewDepths *vd, const int mval_sta[2], const int mval_end[2], int margin, float *r_depth)
1274{
1275 struct {
1276 const ViewDepths *vd;
1277 int margin;
1278 float depth;
1279 } data = {nullptr};
1280 int p1[2];
1281 int p2[2];
1282
1283 data.vd = vd;
1284 data.margin = margin;
1285 data.depth = 1.0f;
1286
1287 copy_v2_v2_int(p1, mval_sta);
1288 copy_v2_v2_int(p2, mval_end);
1289
1291
1292 *r_depth = data.depth;
1293
1294 return (*r_depth != 1.0f);
1295}
1296
1298
1299/* -------------------------------------------------------------------- */
1304
1305float ED_view3d_radius_to_dist_persp(const float angle, const float radius)
1306{
1307 return radius * (1.0f / tanf(angle / 2.0f));
1308}
1309
1310float ED_view3d_radius_to_dist_ortho(const float lens, const float radius)
1311{
1312 return radius / (DEFAULT_SENSOR_WIDTH / lens);
1313}
1314
1316 const ARegion *region,
1317 const Depsgraph *depsgraph,
1318 const eRegionView3D_Persp persp,
1319 const bool use_aspect,
1320 const float radius)
1321{
1322 float dist;
1323
1325 BLI_assert((persp != RV3D_CAMOB) || v3d->camera);
1326
1327 if (persp == RV3D_ORTHO) {
1328 dist = ED_view3d_radius_to_dist_ortho(v3d->lens, radius);
1329 }
1330 else {
1331 float lens, sensor_size, zoom;
1332
1333 if (persp == RV3D_CAMOB) {
1334 CameraParams params;
1335 BKE_camera_params_init(&params);
1336 params.clip_start = v3d->clip_start;
1337 params.clip_end = v3d->clip_end;
1338 Object *camera_eval = DEG_get_evaluated(depsgraph, v3d->camera);
1339 BKE_camera_params_from_object(&params, camera_eval);
1340
1341 lens = params.lens;
1342 sensor_size = BKE_camera_sensor_size(params.sensor_fit, params.sensor_x, params.sensor_y);
1343
1344 /* ignore 'rv3d->camzoom' because we want to fit to the cameras frame */
1346 }
1347 else {
1348 lens = v3d->lens;
1349 sensor_size = DEFAULT_SENSOR_WIDTH;
1351 }
1352
1353 float angle = focallength_to_fov(lens, sensor_size);
1354
1355 /* zoom influences lens, correct this by scaling the angle as a distance
1356 * (by the zoom-level) */
1357 angle = atanf(tanf(angle / 2.0f) * zoom) * 2.0f;
1358
1359 dist = ED_view3d_radius_to_dist_persp(angle, radius);
1360 }
1361
1362 if (use_aspect) {
1363 const RegionView3D *rv3d = static_cast<const RegionView3D *>(region->regiondata);
1364
1365 float winx, winy;
1366
1367 if (persp == RV3D_CAMOB) {
1368 /* camera frame x/y in pixels */
1369 winx = region->winx / rv3d->viewcamtexcofac[0];
1370 winy = region->winy / rv3d->viewcamtexcofac[1];
1371 }
1372 else {
1373 winx = region->winx;
1374 winy = region->winy;
1375 }
1376
1377 if (winx && winy) {
1378 float aspect = winx / winy;
1379 if (aspect < 1.0f) {
1380 aspect = 1.0f / aspect;
1381 }
1382 dist *= aspect;
1383 }
1384 }
1385
1386 return dist;
1387}
1388
1390
1391/* -------------------------------------------------------------------- */
1394
1395float ED_view3d_offset_distance(const float mat[4][4],
1396 const float ofs[3],
1397 const float fallback_dist)
1398{
1399 float pos[4] = {0.0f, 0.0f, 0.0f, 1.0f};
1400 float dir[4] = {0.0f, 0.0f, 1.0f, 0.0f};
1401
1402 mul_m4_v4(mat, pos);
1403 add_v3_v3(pos, ofs);
1404 mul_m4_v4(mat, dir);
1405 normalize_v3(dir);
1406
1407 float dist = dot_v3v3(pos, dir);
1408
1409 if ((dist < FLT_EPSILON) && (fallback_dist != 0.0f)) {
1410 dist = fallback_dist;
1411 }
1412
1413 return dist;
1414}
1415
1416void ED_view3d_distance_set(RegionView3D *rv3d, const float dist)
1417{
1418 float viewinv[4];
1419 float tvec[3];
1420
1421 BLI_assert(dist >= 0.0f);
1422
1423 copy_v3_fl3(tvec, 0.0f, 0.0f, rv3d->dist - dist);
1424/* rv3d->viewinv isn't always valid */
1425#if 0
1426 mul_mat3_m4_v3(rv3d->viewinv, tvec);
1427#else
1428 invert_qt_qt_normalized(viewinv, rv3d->viewquat);
1429 mul_qt_v3(viewinv, tvec);
1430#endif
1431 sub_v3_v3(rv3d->ofs, tvec);
1432
1433 rv3d->dist = dist;
1434}
1435
1437 const float dist_co[3],
1438 const float dist_min)
1439{
1440 float viewinv[4];
1441 invert_qt_qt_normalized(viewinv, rv3d->viewquat);
1442
1443 float tvec[3] = {0.0f, 0.0f, -1.0f};
1444 mul_qt_v3(viewinv, tvec);
1445
1446 float dist_co_local[3];
1447 negate_v3_v3(dist_co_local, rv3d->ofs);
1448 sub_v3_v3v3(dist_co_local, dist_co, dist_co_local);
1449 const float delta = dot_v3v3(tvec, dist_co_local);
1450 const float dist_new = rv3d->dist + delta;
1451 if (dist_new >= dist_min) {
1452 madd_v3_v3fl(rv3d->ofs, tvec, -delta);
1453 rv3d->dist = dist_new;
1454 return true;
1455 }
1456 return false;
1457}
1458
1460
1461/* -------------------------------------------------------------------- */
1464
1468static float view3d_quat_axis[6][4][4] = {
1469 /* RV3D_VIEW_FRONT */
1470 {
1471 {M_SQRT1_2, -M_SQRT1_2, 0.0f, 0.0f},
1472 {0.5f, -0.5f, -0.5f, 0.5f},
1473 {0, 0, -M_SQRT1_2, M_SQRT1_2},
1474 {-0.5f, 0.5f, -0.5f, 0.5f},
1475 }, /* RV3D_VIEW_BACK */
1476 {
1477 {0.0f, 0.0f, -M_SQRT1_2, -M_SQRT1_2},
1478 {0.5f, 0.5f, -0.5f, -0.5f},
1479 {M_SQRT1_2, M_SQRT1_2, 0, 0},
1480 {0.5f, 0.5f, 0.5f, 0.5f},
1481 }, /* RV3D_VIEW_LEFT */
1482 {
1483 {0.5f, -0.5f, 0.5f, 0.5f},
1484 {0, -M_SQRT1_2, 0.0f, M_SQRT1_2},
1485 {-0.5f, -0.5f, -0.5f, 0.5f},
1486 {-M_SQRT1_2, 0, -M_SQRT1_2, 0},
1487 },
1488
1489 /* RV3D_VIEW_RIGHT */
1490 {
1491 {0.5f, -0.5f, -0.5f, -0.5f},
1492 {M_SQRT1_2, 0, -M_SQRT1_2, 0},
1493 {0.5f, 0.5f, -0.5f, 0.5f},
1494 {0, M_SQRT1_2, 0, M_SQRT1_2},
1495 }, /* RV3D_VIEW_TOP */
1496 {
1497 {1.0f, 0.0f, 0.0f, 0.0f},
1498 {M_SQRT1_2, 0, 0, M_SQRT1_2},
1499 {0, 0, 0, 1},
1500 {-M_SQRT1_2, 0, 0, M_SQRT1_2},
1501 }, /* RV3D_VIEW_BOTTOM */
1502 {
1503 {0.0f, -1.0f, 0.0f, 0.0f},
1504 {0, -M_SQRT1_2, -M_SQRT1_2, 0},
1505 {0, 0, -1, 0},
1506 {0, M_SQRT1_2, -M_SQRT1_2, 0},
1507 },
1508
1509};
1510
1512 const eRegionView3D_ViewAxisRoll view_axis_roll,
1513 float r_quat[4])
1514{
1515 BLI_assert(view_axis_roll <= RV3D_VIEW_AXIS_ROLL_270);
1516 if (RV3D_VIEW_IS_AXIS(view)) {
1517 copy_qt_qt(r_quat, view3d_quat_axis[view - RV3D_VIEW_FRONT][view_axis_roll]);
1518 return true;
1519 }
1520 return false;
1521}
1522
1523bool ED_view3d_quat_to_axis_view(const float quat[4],
1524 const float epsilon,
1525 eRegionView3D_View *r_view,
1526 eRegionView3D_ViewAxisRoll *r_view_axis_roll)
1527{
1528 *r_view = RV3D_VIEW_USER;
1529 *r_view_axis_roll = RV3D_VIEW_AXIS_ROLL_0;
1530
1531 /* Quaternion values are all unit length. */
1532
1533 if (epsilon < M_PI_4) {
1534 /* Under 45 degrees, just pick the closest value. */
1535 for (int view = RV3D_VIEW_FRONT; view <= RV3D_VIEW_BOTTOM; view++) {
1536 for (int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; view_axis_roll <= RV3D_VIEW_AXIS_ROLL_270;
1537 view_axis_roll++)
1538 {
1540 quat, view3d_quat_axis[view - RV3D_VIEW_FRONT][view_axis_roll])) < epsilon)
1541 {
1542 *r_view = eRegionView3D_View(view);
1543 *r_view_axis_roll = eRegionView3D_ViewAxisRoll(view_axis_roll);
1544 return true;
1545 }
1546 }
1547 }
1548 }
1549 else {
1550 /* Epsilon over 45 degrees, check all & find use the closest. */
1551 float delta_best = FLT_MAX;
1552 for (int view = RV3D_VIEW_FRONT; view <= RV3D_VIEW_BOTTOM; view++) {
1553 for (int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; view_axis_roll <= RV3D_VIEW_AXIS_ROLL_270;
1554 view_axis_roll++)
1555 {
1556 const float delta_test = fabsf(
1557 angle_signed_qtqt(quat, view3d_quat_axis[view - RV3D_VIEW_FRONT][view_axis_roll]));
1558 if (delta_best > delta_test) {
1559 delta_best = delta_test;
1560 *r_view = eRegionView3D_View(view);
1561 *r_view_axis_roll = eRegionView3D_ViewAxisRoll(view_axis_roll);
1562 }
1563 }
1564 }
1565 if (*r_view != RV3D_VIEW_USER) {
1566 return true;
1567 }
1568 }
1569
1570 return false;
1571}
1572
1574 const float epsilon,
1575 eRegionView3D_View *r_view,
1576 eRegionView3D_ViewAxisRoll *r_view_axis_roll)
1577{
1578 const bool is_axis_view = ED_view3d_quat_to_axis_view(quat, epsilon, r_view, r_view_axis_roll);
1579 if (is_axis_view) {
1580 /* Reset `quat` to it's view axis, so axis-aligned views are always *exactly* aligned. */
1581 BLI_assert(*r_view != RV3D_VIEW_USER);
1582 ED_view3d_quat_from_axis_view(*r_view, *r_view_axis_roll, quat);
1583 }
1584 return is_axis_view;
1585}
1586
1588{
1589 switch (index) {
1590 case 0:
1591 return RV3D_VIEW_FRONT;
1592 case 1:
1593 return RV3D_VIEW_TOP;
1594 case 2:
1595 return RV3D_VIEW_RIGHT;
1596 default:
1597 return RV3D_VIEW_USER;
1598 }
1599}
1600
1602{
1603 switch (view) {
1604 case RV3D_VIEW_FRONT:
1605 return RV3D_VIEW_BACK;
1606 case RV3D_VIEW_BACK:
1607 return RV3D_VIEW_FRONT;
1608 case RV3D_VIEW_LEFT:
1609 return RV3D_VIEW_RIGHT;
1610 case RV3D_VIEW_RIGHT:
1611 return RV3D_VIEW_LEFT;
1612 case RV3D_VIEW_TOP:
1613 return RV3D_VIEW_BOTTOM;
1614 case RV3D_VIEW_BOTTOM:
1615 return RV3D_VIEW_TOP;
1616 case RV3D_VIEW_USER:
1617 case RV3D_VIEW_CAMERA:
1618 break;
1619 }
1620
1621 return RV3D_VIEW_USER;
1622}
1623
1625{
1626 return ED_view3d_quat_from_axis_view(rv3d->view, rv3d->view_axis_roll, rv3d->viewquat);
1627}
1628
1630{
1631 constexpr float angle_threshold = 0.02f;
1632
1633 if ((rv3d->rflag & RV3D_FLIP_X) != 0) {
1634 if (math::abs(rv3d->camroll) < angle_threshold) {
1636 }
1637
1638 if (math::abs(rv3d->camroll - M_PI) < angle_threshold ||
1639 math::abs(rv3d->camroll + M_PI) < angle_threshold)
1640 {
1642 }
1643
1645 }
1646
1647 if (math::abs(rv3d->camroll) < angle_threshold) {
1649 }
1650
1651 if (math::abs(rv3d->camroll - M_PI / 2.0f) < angle_threshold) {
1653 }
1654
1655 if (math::abs(rv3d->camroll - M_PI) < angle_threshold ||
1656 math::abs(rv3d->camroll + M_PI) < angle_threshold)
1657 {
1659 }
1660
1661 if (math::abs(rv3d->camroll - M_PI * 3.0f / 2.0f) < angle_threshold ||
1662 math::abs(rv3d->camroll + M_PI / 2.0f) < angle_threshold)
1663 {
1665 }
1666
1668}
1669
1671
1672/* -------------------------------------------------------------------- */
1675
1677 const float mat[4][4], float ofs[3], float quat[4], const float *dist, const float roll)
1678{
1679 float nmat[3][3];
1680
1681 /* dist depends on offset */
1682 BLI_assert(dist == nullptr || ofs != nullptr);
1683
1684 copy_m3_m4(nmat, mat);
1685 normalize_m3(nmat);
1686
1687 /* Offset */
1688 if (ofs) {
1689 negate_v3_v3(ofs, mat[3]);
1690 }
1691
1692 /* Quat */
1693 if (quat) {
1694 mat3_normalized_to_quat(quat, nmat);
1696
1697 if (roll != 0.0f) {
1698 float quat_roll[4];
1699 axis_angle_to_quat_single(quat_roll, 'Z', roll);
1700 mul_qt_qtqt(quat, quat_roll, quat);
1701 }
1702 }
1703
1704 if (ofs && dist) {
1705 madd_v3_v3fl(ofs, nmat[2], *dist);
1706 }
1707}
1708
1710 float mat[4][4], const float ofs[3], const float quat[4], const float dist, const float roll)
1711{
1712 float quat_no_roll[4];
1713 const float *quat_p = quat;
1714 if (roll != 0.0f) {
1715 /* Remove roll. */
1716 axis_angle_to_quat_single(quat_no_roll, 'Z', -roll);
1717 mul_qt_qtqt(quat_no_roll, quat_no_roll, quat);
1718 quat_p = quat_no_roll;
1719 }
1720
1721 const float iviewquat[4] = {-quat_p[0], quat_p[1], quat_p[2], quat_p[3]};
1722 float dvec[3] = {0.0f, 0.0f, dist};
1723
1724 quat_to_mat4(mat, iviewquat);
1725 mul_mat3_m4_v3(mat, dvec);
1726 sub_v3_v3v3(mat[3], dvec, ofs);
1727}
1728
1730 float ofs[3],
1731 float quat[4],
1732 const float *dist,
1733 const float roll,
1734 float *r_lens)
1735{
1736 ED_view3d_from_m4(ob->object_to_world().ptr(), ofs, quat, dist, roll);
1737
1738 if (r_lens) {
1739 CameraParams params;
1740
1741 BKE_camera_params_init(&params);
1742 BKE_camera_params_from_object(&params, ob);
1743 *r_lens = params.lens;
1744 }
1745}
1746
1747void ED_view3d_to_object(const Depsgraph *depsgraph,
1748 Object *ob,
1749 const float ofs[3],
1750 const float quat[4],
1751 const float dist,
1752 const float roll)
1753{
1754 float mat[4][4];
1755 ED_view3d_to_m4(mat, ofs, quat, dist, roll);
1756
1757 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
1758 BKE_object_apply_mat4_ex(ob, mat, ob_eval->parent, ob_eval->parentinv, true);
1759}
1760
1762 Depsgraph *depsgraph,
1763 const Scene *scene,
1764 Object *camera_ob,
1765 float *r_clip_start,
1766 float *r_clip_end)
1767{
1768 Object *camera_ob_eval = DEG_get_evaluated(depsgraph, camera_ob);
1769 float co[3]; /* the new location to apply */
1770 float scale; /* only for ortho cameras */
1771
1773 depsgraph, scene, camera_ob_eval, co, &scale, r_clip_start, r_clip_end))
1774 {
1776 float obmat_new[4][4];
1777 bool is_ortho_camera = false;
1778
1779 if ((camera_ob_eval->type == OB_CAMERA) &&
1780 ((id_cast<Camera *>(camera_ob_eval->data))->type == CAM_ORTHO))
1781 {
1782 (id_cast<Camera *>(camera_ob->data))->ortho_scale = scale;
1783 is_ortho_camera = true;
1784 }
1785
1786 copy_m4_m4(obmat_new, camera_ob_eval->object_to_world().ptr());
1787 copy_v3_v3(obmat_new[3], co);
1788
1789 /* only touch location */
1790 BKE_object_tfm_protected_backup(camera_ob, &obtfm);
1791 BKE_object_apply_mat4(camera_ob, obmat_new, true, true);
1793
1794 /* notifiers */
1795 DEG_id_tag_update_ex(bmain, &camera_ob->id, ID_RECALC_TRANSFORM);
1796 if (is_ortho_camera) {
1798 }
1799
1800 return true;
1801 }
1802
1803 return false;
1804}
1805
1807 Depsgraph *depsgraph,
1808 const Scene *scene,
1809 Object *camera_ob)
1810{
1811 return view3d_camera_to_view_selected_impl(bmain, depsgraph, scene, camera_ob, nullptr, nullptr);
1812}
1813
1815 Depsgraph *depsgraph,
1816 const Scene *scene,
1817 Object *camera_ob)
1818{
1819 float clip_start;
1820 float clip_end;
1822 bmain, depsgraph, scene, camera_ob, &clip_start, &clip_end))
1823 {
1824
1825 (id_cast<Camera *>(camera_ob->data))->clip_start = clip_start;
1826 (id_cast<Camera *>(camera_ob->data))->clip_end = clip_end;
1827
1828 /* TODO: Support update via #ID_RECALC_PARAMETERS. */
1829 Object *camera_ob_eval = DEG_get_evaluated(depsgraph, camera_ob);
1830 (id_cast<Camera *>(camera_ob_eval->data))->clip_start = clip_start;
1831 (id_cast<Camera *>(camera_ob_eval->data))->clip_end = clip_end;
1832
1833 return true;
1834 }
1835
1836 return false;
1837}
1838
1840
1841/* -------------------------------------------------------------------- */
1844
1845struct ReadData {
1848 float r_depth;
1849};
1850
1851static bool depth_read_test_fn(const void *value, void *userdata)
1852{
1853 ReadData *data = static_cast<ReadData *>(userdata);
1854 float depth = *static_cast<float *>(const_cast<void *>(value));
1855 data->r_depth = std::min(depth, data->r_depth);
1856
1857 if ((++data->count) >= data->count_max) {
1858 /* Outside the margin. */
1859 return true;
1860 }
1861 return false;
1862}
1863
1865 const int mval[2],
1866 int margin,
1867 float *r_depth)
1868{
1869 *r_depth = 1.0f;
1870
1871 if (!vd || !vd->depths) {
1872 return false;
1873 }
1874
1875 BLI_assert(1.0 <= vd->depth_range[1]);
1876 int x = mval[0];
1877 int y = mval[1];
1878 if (x < 0 || y < 0 || x >= vd->w || y >= vd->h) {
1879 return false;
1880 }
1881
1882 float depth = 1.0f;
1883 if (margin) {
1884 int shape[2] = {vd->w, vd->h};
1885 int pixel_count = (min_ii(x + margin + 1, shape[1]) - max_ii(x - margin, 0)) *
1886 (min_ii(y + margin + 1, shape[0]) - max_ii(y - margin, 0));
1887
1888 ReadData data;
1889 data.count = 0;
1890 data.count_max = pixel_count;
1891 data.r_depth = 1.0f;
1892
1893 /* TODO: No need to go spiral. */
1895 depth = data.r_depth;
1896 }
1897 else {
1898 depth = vd->depths[y * vd->w + x];
1899 }
1900
1901 if (depth != 1.0f) {
1902 *r_depth = depth;
1903 return true;
1904 }
1905
1906 return false;
1907}
1908
1910 const ViewDepths *depths,
1911 const int mval[2],
1912 float r_normal[3])
1913{
1914 /* NOTE: we could support passing in a radius.
1915 * For now just read 9 pixels. */
1916
1917 /* pixels surrounding */
1918 bool depths_valid[9] = {false};
1919 float coords[9][3] = {{0}};
1920
1921 for (int x = 0, i = 0; x < 2; x++) {
1922 for (int y = 0; y < 2; y++) {
1923 const int mval_ofs[2] = {mval[0] + (x - 1), mval[1] + (y - 1)};
1924
1925 float depth_fl = 1.0f;
1926 ED_view3d_depth_read_cached(depths, mval_ofs, 0, &depth_fl);
1927 const double depth = double(depth_fl);
1928 if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
1929 if (ED_view3d_depth_unproject_v3(region, mval_ofs, depth, coords[i])) {
1930 depths_valid[i] = true;
1931 }
1932 }
1933 i++;
1934 }
1935 }
1936
1937 const int edges[2][6][2] = {
1938 /* x edges */
1939 {{0, 1}, {1, 2}, {3, 4}, {4, 5}, {6, 7}, {7, 8}}, /* y edges */
1940 {{0, 3}, {3, 6}, {1, 4}, {4, 7}, {2, 5}, {5, 8}},
1941 };
1942
1943 float cross[2][3] = {{0.0f}};
1944
1945 for (int i = 0; i < 6; i++) {
1946 for (int axis = 0; axis < 2; axis++) {
1947 if (depths_valid[edges[axis][i][0]] && depths_valid[edges[axis][i][1]]) {
1948 float delta[3];
1949 sub_v3_v3v3(delta, coords[edges[axis][i][0]], coords[edges[axis][i][1]]);
1950 add_v3_v3(cross[axis], delta);
1951 }
1952 }
1953 }
1954
1955 cross_v3_v3v3(r_normal, cross[0], cross[1]);
1956
1957 if (normalize_v3(r_normal) != 0.0f) {
1958 return true;
1959 }
1960 return false;
1961}
1962
1964 const int mval[2],
1965 const double depth,
1966 float r_location_world[3])
1967{
1968 float centx = float(mval[0]) + 0.5f;
1969 float centy = float(mval[1]) + 0.5f;
1970 return ED_view3d_unproject_v3(region, centx, centy, depth, r_location_world);
1971}
1972
1974
1975} // namespace blender
Functions to insert, delete or modify keyframes.
Functionality to interact with keying sets.
Camera data-block and utility functions.
#define CAMERA_PARAM_ZOOM_INIT_PERSP
Definition BKE_camera.h:100
#define CAMERA_PARAM_ZOOM_INIT_CAMOB
Definition BKE_camera.h:99
General operations, lookup, etc. for blender objects.
Generic array manipulation API.
#define BLI_array_iter_spiral_square(arr, arr_shape, center, test_fn, user_data)
#define M_SQRT1_2
#define M_PI
#define M_PI_4
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define DEFAULT_SENSOR_WIDTH
Object is a sort of wrapper for general info.
#define RV3D_VIEW_IS_AXIS(view)
#define RV3D_CAMZOOM_MAX
#define RV3D_CAMZOOM_MIN_FACTOR
#define RV3D_LOCK_FLAGS(rv3d)
#define RV3D_CAMZOOM_MAX_FACTOR
#define RV3D_CAMZOOM_MIN
#define VIEW3D_DIST_FALLBACK
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_ANIMATION
Definition WM_types.hh:401
#define NA_ADDED
Definition WM_types.hh:636
#define ND_TRANSFORM
Definition WM_types.hh:475
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define ND_KEYFRAME
Definition WM_types.hh:537
#define NC_OBJECT
Definition WM_types.hh:392
#define NC_SPACE
Definition WM_types.hh:405
#define CLAMP(a, b, c)
#define INIT_MINMAX(min, max)
#define ELEM(...)
btScalar max
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
void append(const T &value)
#define str(s)
#define FLT_MAX
#define FLT_EPSILON
float distance(float, float) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
float3x3 scale(float3x3 mat, float2 scale)
bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
void autokeyframe_object(bContext *C, const Scene *scene, Object *ob, Span< RNAPath > rna_paths)
AngleRadianBase< float > AngleRadian
T abs(const T &a)
MatT from_rotation(const RotationT &rotation)
void get_color_3fv(int colorid, float col[3])
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
bool ED_view3d_camera_lock_autokey(View3D *v3d, RegionView3D *rv3d, bContext *C, bool do_rotate, bool do_translate)
UserDef U
Definition blender.cc:58
bool WM_event_consecutive_gesture_test(const wmEvent *event)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ARegion * BKE_area_find_region_active_win(const ScrArea *area)
Definition screen.cc:1037
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)
bool ED_view3d_depth_read_cached_seg(const ViewDepths *vd, const int mval_sta[2], const int mval_end[2], int margin, float *r_depth)
MINLINE void negate_v3_v3(float r[3], const float a[3])
bool ED_view3d_quat_to_axis_view_and_reset_quat(float quat[4], float epsilon, eRegionView3D_View *r_view, eRegionView3D_ViewAxisRoll *r_view_axis_roll)
bool ED_view3d_camera_to_view_selected(Main *bmain, Depsgraph *depsgraph, const Scene *scene, Object *camera_ob)
ScrArea * CTX_wm_area(const bContext *C)
bool ED_view3d_camera_lock_check(const View3D *v3d, const RegionView3D *rv3d)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
void wmViewport(const rcti *winrct)
bool ED_view3d_clipping_clamp_minmax(const RegionView3D *rv3d, float min[3], float max[3])
void BKE_object_tfm_protected_backup(const Object *ob, ObjectTfmProtectedChannels *obtfm)
Definition object.cc:3025
void ED_undo_grouped_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:357
bool ED_undo_is_memfile_compatible(const bContext *C)
Definition ed_undo.cc:588
void ED_view3d_background_color_get(const Scene *scene, const View3D *v3d, float r_color[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
static bool depth_read_test_fn(const void *value, void *userdata)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
bool ED_view3d_camera_lock_undo_grouped_push(const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C)
static void points_in_planes_minmax_fn(const float co[3], int, int, int, void *user_data_p)
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
bool ED_view3d_autodist_last_get(wmWindow *win, float r_ofs[3])
void ED_view3d_distance_set(RegionView3D *rv3d, float dist)
void mat3_normalized_to_quat(float q[4], const float mat[3][3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
bool ED_view3d_camera_view_zoom_scale(RegionView3D *rv3d, const float scale)
float ED_view3d_radius_to_dist(const View3D *v3d, const ARegion *region, const Depsgraph *depsgraph, eRegionView3D_Persp persp, bool use_aspect, float radius)
void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d)
void normalize_m3(float R[3][3]) ATTR_NONNULL()
bool ED_view3d_persp_ensure(const Depsgraph *depsgraph, View3D *v3d, ARegion *region)
void ED_view3d_polygon_offset(const RegionView3D *rv3d, float dist)
bool ED_view3d_camera_lock_sync(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
MatBase< float, 2, 2 > float2x2
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
bool ED_view3d_camera_lock_undo_push(const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C)
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy)
bool ED_view3d_quat_to_axis_view(const float quat[4], float epsilon, eRegionView3D_View *r_view, eRegionView3D_ViewAxisRoll *r_view_axis_roll)
void WM_event_consecutive_data_set(wmWindow *win, const char *id, void *custom_data)
void ED_view3d_persp_switch_from_camera(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d, eRegionView3D_Persp persp)
bool is_negative_m4(const float mat[4][4])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void view3d_operator_needs_gpu(const bContext *C)
bool ED_view3d_boundbox_clip(RegionView3D *rv3d, const BoundBox *bb)
bool ED_view3d_autodist_last_check(wmWindow *win, const wmEvent *event)
MINLINE int max_ii(int a, int b)
bool ED_view3d_has_workbench_in_texture_color(const Scene *scene, const Object *ob, const View3D *v3d)
bool ED_view3d_distance_set_from_location(RegionView3D *rv3d, const float dist_co[3], float dist_min)
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:45
@ RV3D_LOCK_ANY_TRANSFORM
bool ED_view3d_camera_autokey(const Scene *scene, ID *id_key, bContext *C, bool do_rotate, bool do_translate)
bool isect_planes_v3_fn(const float planes[][4], int planes_len, float eps_coplanar, float eps_isect, void(*callback_fn)(const float co[3], int i, int j, int k, void *user_data), void *user_data)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void ED_view3d_autodist_last_clear(wmWindow *win)
MINLINE float srgb_to_grayscale(const float rgb[3])
static bool view3d_camera_to_view_selected_impl(Main *bmain, Depsgraph *depsgraph, const Scene *scene, Object *camera_ob, float *r_clip_start, float *r_clip_end)
eRegionView3D_View ED_view3d_axis_view_opposite(eRegionView3D_View view)
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
Definition object.cc:3663
MINLINE void mul_v3_fl(float r[3], float f)
void * WM_event_consecutive_data_get(wmWindow *win, const char *id)
bool ED_view3d_unproject_v3(const ARegion *region, float regionx, float regiony, float regionz, float world[3])
float ED_view3d_dist_soft_min_get(const View3D *v3d, bool use_persp_range)
static const char * view3d_autodepth_last_id
@ RV3D_ZOFFSET_DISABLED
MINLINE void sub_v3_v3(float r[3], const float a[3])
void mul_qt_v3(const float q[4], float r[3])
@ RV3D_VIEW_AXIS_ROLL_270
static float view_autodist_depth_margin(ARegion *region, const int mval[2], int margin)
void mul_m4_v3(const float M[4][4], float r[3])
static void view3d_boxview_sync_axis(RegionView3D *rv3d_dst, RegionView3D *rv3d_src)
void ED_view3d_lock_clear(View3D *v3d)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
float focallength_to_fov(float focal_length, float sensor)
bool ED_view3d_boundbox_clip_ex(const RegionView3D *rv3d, const BoundBox *bb, float obmat[4][4])
static void view3d_boxview_clip(ScrArea *area)
@ WM_EVENT_IS_CONSECUTIVE
Definition WM_types.hh:752
bool ED_view3d_autodist(ARegion *region, View3D *v3d, const int mval[2], float mouse_worldloc[3], const float fallback_depth_pt[3])
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
VecBase< float, 2 > float2
void BKE_camera_params_from_view3d(CameraParams *params, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
bool ED_view3d_camera_lock_undo_test(const View3D *v3d, const RegionView3D *rv3d, bContext *C)
static bool depth_segment_cb(int x, int y, void *user_data)
void copy_qt_qt(float q[4], const float a[4])
void DEG_id_tag_update(ID *id, unsigned int flags)
@ OB_MODE_TEXTURE_PAINT
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
float BKE_screen_view3d_zoom_from_fac(float zoomfac)
Definition screen.cc:1288
static float view3d_quat_axis[6][4][4]
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
bool ED_view3d_context_activate(bContext *C)
bool ED_view3d_camera_view_pan(ARegion *region, const float event_ofs[2])
void BKE_camera_params_from_object(CameraParams *params, const struct Object *cam_ob)
void axis_angle_to_quat_single(float q[4], char axis, float angle)
float ED_view3d_radius_to_dist_persp(float angle, float radius)
void ED_view3d_camera_lock_init(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void invert_qt_normalized(float q[4])
MINLINE void negate_v3(float r[3])
eRegionView3D_View ED_view3d_lock_view_from_index(int index)
void GPU_matrix_projection_set(const float m[4][4])
@ V3D_SHADING_TEXTURE_COLOR
MINLINE void zero_v3(float r[3])
void mul_m4_v4(const float mat[4][4], float r[4])
bool ED_view3d_autodist_simple(ARegion *region, const int mval[2], float mouse_worldloc[3], int margin, const float *force_depth)
void view3d_boxview_copy(ScrArea *area, ARegion *region)
void ED_view3d_quadview_update(ScrArea *area, ARegion *region, bool do_clip)
void BLI_bitmap_draw_2d_line_v2v2i(const int p1[2], const int p2[2], bool(*callback)(int, int, void *), void *user_data)
Camera * ED_view3d_camera_data_get(View3D *v3d, RegionView3D *rv3d)
void ED_view3d_to_m4(float mat[4][4], const float ofs[3], const float quat[4], float dist, float roll)
@ OB_TRANSFORM_ADJUST_ROOT_PARENT_FOR_VIEW_LOCK
Bounds< float > ED_view3d_dist_soft_range_get(const View3D *v3d, bool use_persp_range)
bool ED_view3d_clip_range_get(const Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d, bool use_ortho_factor, float *r_clip_start, float *r_clip_end)
bool BKE_camera_view_frame_fit_to_scene(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *camera_ob, float r_co[3], float *r_scale, float *r_clip_start, float *r_clip_end)
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
MINLINE float normalize_v3(float n[3])
@ V3D_SHADING_BACKGROUND_VIEWPORT
@ V3D_SHADING_BACKGROUND_WORLD
bool ED_view3d_offset_lock_check(const View3D *v3d, const RegionView3D *rv3d)
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
bool ED_view3d_lock(RegionView3D *rv3d)
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
bool BKE_scene_uses_blender_workbench(const Scene *scene)
Definition scene.cc:3082
MINLINE void copy_v3_fl(float r[3], float f)
void WM_event_consecutive_data_free(wmWindow *win)
bool ED_view3d_camera_to_view_selected_with_set_clipping(Main *bmain, Depsgraph *depsgraph, const Scene *scene, Object *camera_ob)
void ED_view3d_autodist_last_set(wmWindow *win, const wmEvent *event, const float ofs[3], const bool has_depth)
void ED_view3d_clipping_calc(BoundBox *bb, float planes[4][4], const ARegion *region, const Object *ob, const rcti *rect)
MINLINE float max_ff(float a, float b)
void ED_view3d_camera_lock_init_ex(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d, bool calc_dist)
bool ED_view3d_depth_read_cached(const ViewDepths *vd, const int mval[2], int margin, float *r_depth)
@ ID_RECALC_PARAMETERS
Definition DNA_ID.h:1138
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
ID_Type GS(const char *name)
Definition DNA_ID.h:410
MINLINE void clamp_v3(float vec[3], float min, float max)
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
Definition screen.cc:1189
static bool view3d_boundbox_clip_m4(const BoundBox *bb, const float persmatob[4][4])
bool ED_view3d_depth_read_cached_normal(const ARegion *region, const ViewDepths *depths, const int mval[2], float r_normal[3])
void ED_view3d_win_to_3d_int(const View3D *v3d, const ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
float view3d_depth_near(ViewDepths *d)
void ED_view3d_clipping_calc_from_boundbox(float clip[4][4], const BoundBox *bb, bool is_flip)
void ED_view3d_lastview_store(RegionView3D *rv3d)
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
void invert_qt_qt_normalized(float q1[4], const float q2[4])
float BKE_screen_view3d_zoom_to_fac(float camzoom)
Definition screen.cc:1283
static bool view3d_camera_lock_undo_ex(const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C, const bool undo_group)
bool ED_view3d_depth_unproject_v3(const ARegion *region, const int mval[2], double depth, float r_location_world[3])
bool ED_view3d_quat_from_axis_view(eRegionView3D_View view, eRegionView3D_ViewAxisRoll view_axis_roll, float r_quat[4])
void GPU_polygon_offset(float viewdist, float dist)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
eRegionView3D_ViewFlipRoll
void ED_view3d_to_object(const Depsgraph *depsgraph, Object *ob, const float ofs[3], const float quat[4], float dist, float roll)
float ED_view3d_radius_to_dist_ortho(float lens, float radius)
MINLINE void negate_v4_v4(float r[4], const float a[4])
void BKE_camera_params_init(CameraParams *params)
void normalize_m4_m4(float rmat[4][4], const float mat[4][4]) ATTR_NONNULL()
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void ED_view3d_text_colors_get(const Scene *scene, const View3D *v3d, float r_text_color[4], float r_shadow_color[4])
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
Definition rct.cc:480
void ED_view3d_from_object(const Object *ob, float ofs[3], float quat[4], const float *dist, float roll, float *r_lens)
float angle_signed_qtqt(const float q1[4], const float q2[4])
void view3d_region_operator_needs_gpu(ARegion *region)
MINLINE int min_ii(int a, int b)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
eRegionView3D_ViewFlipRoll ED_view3d_effective_flip_axis(const RegionView3D *rv3d)
ARegion * CTX_wm_region(const bContext *C)
void GPU_matrix_set(const float m[4][4])
void view3d_boxview_sync(ScrArea *area, ARegion *region)
void ED_view3d_from_m4(const float mat[4][4], float ofs[3], float quat[4], const float *dist, float roll)
void BKE_object_tfm_protected_restore(Object *ob, const ObjectTfmProtectedChannels *obtfm, short protectflag)
Definition object.cc:3050
void BKE_object_apply_mat4_ex(Object *ob, const float mat[4][4], Object *parent, const float parentinv[4][4], bool use_compat)
Definition object.cc:3620
void quat_to_mat4(float m[4][4], const float q[4])
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
void CTX_wm_area_set(bContext *C, ScrArea *area)
float ED_view3d_offset_distance(const float mat[4][4], const float ofs[3], float fallback_dist)
#define fabsf
#define atanf
#define tanf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
struct ARegion * prev
eRegion_Alignment alignment
eRegion_Type regiontype
char name[258]
Definition DNA_ID.h:433
struct Object * parent
float parentinv[4][4]
eObject_TransFlag transflag
eObject_ProtectFlag protectflag
eRegionView3D_View lview
eRegionView3D_Flag rflag
eRegionView3D_ViewAxisRoll view_axis_roll
eRegionView3D_ViewAxisRoll lview_axis_roll
struct BoundBox * clipbb
eRegionView3D_Persp lpersp
eRegionView3D_Persp persp
eRegionView3D_ViewLock viewlock
eRegionView3D_View view
struct World * world
struct SceneDisplay display
ListBaseT< ARegion > regionbase
eV3DShadingColorType color_type
eV3DShadingBackgroundType background_type
eView3D_Flag2 flag2
struct Object * ob_center
struct Object * camera
View3DShading shading
unsigned short w
Definition ED_view3d.hh:92
unsigned short h
Definition ED_view3d.hh:92
double depth_range[2]
Definition ED_view3d.hh:96
eWM_EventFlag flag
Definition WM_types.hh:848