1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 * 16 * The Original Code is Copyright (C) 2008 Blender Foundation. 17 * All rights reserved. 18 */ 19 20 /** \file 21 * \ingroup editors 22 */ 23 24 #pragma once 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* ********* exports for space_view3d/ module ********** */ 31 struct ARegion; 32 struct BMEdge; 33 struct BMElem; 34 struct BMFace; 35 struct BMVert; 36 struct BPoint; 37 struct Base; 38 struct BezTriple; 39 struct BoundBox; 40 struct Camera; 41 struct CustomData_MeshMasks; 42 struct Depsgraph; 43 struct EditBone; 44 struct GPUOffScreen; 45 struct GPUViewport; 46 struct ID; 47 struct MVert; 48 struct Main; 49 struct MetaElem; 50 struct Nurb; 51 struct Object; 52 struct RV3DMatrixStore; 53 struct RegionView3D; 54 struct RenderEngineType; 55 struct Scene; 56 struct ScrArea; 57 struct View3D; 58 struct View3DShading; 59 struct ViewContext; 60 struct ViewLayer; 61 struct bContext; 62 struct bPoseChannel; 63 struct bScreen; 64 struct rctf; 65 struct rcti; 66 struct wmGizmo; 67 struct wmOperator; 68 struct wmOperatorType; 69 struct wmWindow; 70 struct wmWindowManager; 71 72 /* for derivedmesh drawing callbacks, for view3d_select, .... */ 73 typedef struct ViewContext { 74 struct bContext *C; 75 struct Main *bmain; 76 /* Dependency graph is uses for depth drawing, viewport camera matrix access, and also some areas 77 * are re-using this to access evaluated entities. 78 * 79 * Moral of the story: assign to a fully evaluated state. */ 80 struct Depsgraph *depsgraph; 81 struct Scene *scene; 82 struct ViewLayer *view_layer; 83 struct Object *obact; 84 struct Object *obedit; 85 struct ARegion *region; 86 struct View3D *v3d; 87 struct wmWindow *win; 88 struct RegionView3D *rv3d; 89 struct BMEditMesh *em; 90 int mval[2]; 91 } ViewContext; 92 93 typedef struct ViewDepths { 94 unsigned short w, h; 95 short x, y; /* only for temp use for sub-rects, added to region->winx/y */ 96 float *depths; 97 double depth_range[2]; 98 99 bool damaged; 100 } ViewDepths; 101 102 typedef struct ViewDrawOffscreenContext { 103 struct Depsgraph *depsgraph; 104 struct Scene *scene; 105 int drawtype; 106 struct View3D *v3d; 107 struct ARegion *region; 108 int winx; 109 int winy; 110 float viewmat[4][4]; 111 float winmat[4][4]; 112 bool do_sky; 113 bool is_persp; 114 const char *viewname; 115 const bool do_color_management; 116 struct GPUOffScreen *ofs; 117 struct GPUViewport *viewport; 118 } ViewDrawOffscreenContext; 119 120 /* Rotate 3D cursor on placement. */ 121 enum eV3DCursorOrient { 122 V3D_CURSOR_ORIENT_NONE = 0, 123 V3D_CURSOR_ORIENT_VIEW, 124 V3D_CURSOR_ORIENT_XFORM, 125 V3D_CURSOR_ORIENT_GEOM, 126 }; 127 128 void ED_view3d_background_color_get(const struct Scene *scene, 129 const struct View3D *v3d, 130 float r_color[3]); 131 bool ED_view3d_has_workbench_in_texture_color(const struct Scene *scene, 132 const struct Object *ob, 133 const struct View3D *v3d); 134 void ED_view3d_cursor3d_position(struct bContext *C, 135 const int mval[2], 136 const bool use_depth, 137 float r_cursor_co[3]); 138 void ED_view3d_cursor3d_position_rotation(struct bContext *C, 139 const int mval[2], 140 const bool use_depth, 141 enum eV3DCursorOrient orientation, 142 float r_cursor_co[3], 143 float r_cursor_quat[4]); 144 void ED_view3d_cursor3d_update(struct bContext *C, 145 const int mval[2], 146 const bool use_depth, 147 enum eV3DCursorOrient orientation); 148 149 struct Camera *ED_view3d_camera_data_get(struct View3D *v3d, struct RegionView3D *rv3d); 150 151 void ED_view3d_to_m4(float mat[4][4], const float ofs[3], const float quat[4], const float dist); 152 void ED_view3d_from_m4(const float mat[4][4], float ofs[3], float quat[4], const float *dist); 153 154 void ED_view3d_from_object( 155 const struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens); 156 void ED_view3d_to_object(const struct Depsgraph *depsgraph, 157 struct Object *ob, 158 const float ofs[3], 159 const float quat[4], 160 const float dist); 161 162 void ED_view3d_lastview_store(struct RegionView3D *rv3d); 163 164 /* Depth buffer */ 165 void ED_view3d_depth_update(struct ARegion *region); 166 float ED_view3d_depth_read_cached(const struct ViewContext *vc, const int mval[2]); 167 bool ED_view3d_depth_read_cached_normal(const ViewContext *vc, 168 const int mval[2], 169 float r_normal[3]); 170 bool ED_view3d_depth_unproject(const struct ARegion *region, 171 const int mval[2], 172 const double depth, 173 float r_location_world[3]); 174 void ED_view3d_depth_tag_update(struct RegionView3D *rv3d); 175 176 /* Projection */ 177 #define IS_CLIPPED 12000 178 179 /* return values for ED_view3d_project_...() */ 180 typedef enum { 181 V3D_PROJ_RET_OK = 0, 182 /** can't avoid this when in perspective mode, (can't avoid) */ 183 V3D_PROJ_RET_CLIP_NEAR = 1, 184 /** so close to zero we can't apply a perspective matrix usefully */ 185 V3D_PROJ_RET_CLIP_ZERO = 2, 186 /** bounding box clip - RV3D_CLIPPING */ 187 V3D_PROJ_RET_CLIP_BB = 3, 188 /** outside window bounds */ 189 V3D_PROJ_RET_CLIP_WIN = 4, 190 /** outside range (mainly for short), (can't avoid) */ 191 V3D_PROJ_RET_OVERFLOW = 5, 192 } eV3DProjStatus; 193 194 /* some clipping tests are optional */ 195 typedef enum { 196 V3D_PROJ_TEST_NOP = 0, 197 V3D_PROJ_TEST_CLIP_BB = (1 << 0), 198 V3D_PROJ_TEST_CLIP_WIN = (1 << 1), 199 V3D_PROJ_TEST_CLIP_NEAR = (1 << 2), 200 V3D_PROJ_TEST_CLIP_ZERO = (1 << 3), 201 } eV3DProjTest; 202 203 #define V3D_PROJ_TEST_CLIP_DEFAULT \ 204 (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) 205 #define V3D_PROJ_TEST_ALL \ 206 (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR | \ 207 V3D_PROJ_TEST_CLIP_ZERO) 208 209 /* view3d_iterators.c */ 210 211 /* foreach iterators */ 212 void meshobject_foreachScreenVert( 213 struct ViewContext *vc, 214 void (*func)(void *userData, struct MVert *eve, const float screen_co[2], int index), 215 void *userData, 216 const eV3DProjTest clip_flag); 217 void mesh_foreachScreenVert( 218 struct ViewContext *vc, 219 void (*func)(void *userData, struct BMVert *eve, const float screen_co[2], int index), 220 void *userData, 221 const eV3DProjTest clip_flag); 222 void mesh_foreachScreenEdge(struct ViewContext *vc, 223 void (*func)(void *userData, 224 struct BMEdge *eed, 225 const float screen_co_a[2], 226 const float screen_co_b[2], 227 int index), 228 void *userData, 229 const eV3DProjTest clip_flag); 230 231 void mesh_foreachScreenEdge_clip_bb_segment(struct ViewContext *vc, 232 void (*func)(void *userData, 233 struct BMEdge *eed, 234 const float screen_co_a[2], 235 const float screen_co_b[2], 236 int index), 237 void *userData, 238 const eV3DProjTest clip_flag); 239 240 void mesh_foreachScreenFace( 241 struct ViewContext *vc, 242 void (*func)(void *userData, struct BMFace *efa, const float screen_co[2], int index), 243 void *userData, 244 const eV3DProjTest clip_flag); 245 void nurbs_foreachScreenVert(struct ViewContext *vc, 246 void (*func)(void *userData, 247 struct Nurb *nu, 248 struct BPoint *bp, 249 struct BezTriple *bezt, 250 int beztindex, 251 bool handle_visible, 252 const float screen_co[2]), 253 void *userData, 254 const eV3DProjTest clip_flag); 255 void mball_foreachScreenElem(struct ViewContext *vc, 256 void (*func)(void *userData, 257 struct MetaElem *ml, 258 const float screen_co[2]), 259 void *userData, 260 const eV3DProjTest clip_flag); 261 void lattice_foreachScreenVert(struct ViewContext *vc, 262 void (*func)(void *userData, 263 struct BPoint *bp, 264 const float screen_co[2]), 265 void *userData, 266 const eV3DProjTest clip_flag); 267 void armature_foreachScreenBone(struct ViewContext *vc, 268 void (*func)(void *userData, 269 struct EditBone *ebone, 270 const float screen_co_a[2], 271 const float screen_co_b[2]), 272 void *userData, 273 const eV3DProjTest clip_flag); 274 void pose_foreachScreenBone(struct ViewContext *vc, 275 void (*func)(void *userData, 276 struct bPoseChannel *pchan, 277 const float screen_co_a[2], 278 const float screen_co_b[2]), 279 void *userData, 280 const eV3DProjTest clip_flag); 281 /* *** end iterators *** */ 282 283 /* view3d_project.c */ 284 void ED_view3d_project_float_v2_m4(const struct ARegion *region, 285 const float co[3], 286 float r_co[2], 287 float mat[4][4]); 288 void ED_view3d_project_float_v3_m4(const struct ARegion *region, 289 const float co[3], 290 float r_co[3], 291 float mat[4][4]); 292 293 eV3DProjStatus ED_view3d_project_base(const struct ARegion *region, struct Base *base); 294 295 /* *** short *** */ 296 eV3DProjStatus ED_view3d_project_short_ex(const struct ARegion *region, 297 float perspmat[4][4], 298 const bool is_local, 299 const float co[3], 300 short r_co[2], 301 const eV3DProjTest flag); 302 eV3DProjStatus ED_view3d_project_short_global(const struct ARegion *region, 303 const float co[3], 304 short r_co[2], 305 const eV3DProjTest flag); 306 eV3DProjStatus ED_view3d_project_short_object(const struct ARegion *region, 307 const float co[3], 308 short r_co[2], 309 const eV3DProjTest flag); 310 311 /* *** int *** */ 312 eV3DProjStatus ED_view3d_project_int_ex(const struct ARegion *region, 313 float perspmat[4][4], 314 const bool is_local, 315 const float co[3], 316 int r_co[2], 317 const eV3DProjTest flag); 318 eV3DProjStatus ED_view3d_project_int_global(const struct ARegion *region, 319 const float co[3], 320 int r_co[2], 321 const eV3DProjTest flag); 322 eV3DProjStatus ED_view3d_project_int_object(const struct ARegion *region, 323 const float co[3], 324 int r_co[2], 325 const eV3DProjTest flag); 326 327 /* *** float *** */ 328 eV3DProjStatus ED_view3d_project_float_ex(const struct ARegion *region, 329 float perspmat[4][4], 330 const bool is_local, 331 const float co[3], 332 float r_co[2], 333 const eV3DProjTest flag); 334 eV3DProjStatus ED_view3d_project_float_global(const struct ARegion *region, 335 const float co[3], 336 float r_co[2], 337 const eV3DProjTest flag); 338 eV3DProjStatus ED_view3d_project_float_object(const struct ARegion *region, 339 const float co[3], 340 float r_co[2], 341 const eV3DProjTest flag); 342 343 float ED_view3d_pixel_size(const struct RegionView3D *rv3d, const float co[3]); 344 float ED_view3d_pixel_size_no_ui_scale(const struct RegionView3D *rv3d, const float co[3]); 345 346 float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip); 347 bool ED_view3d_clip_segment(const struct RegionView3D *rv3d, float ray_start[3], float ray_end[3]); 348 bool ED_view3d_win_to_ray_clipped(struct Depsgraph *depsgraph, 349 const struct ARegion *region, 350 const struct View3D *v3d, 351 const float mval[2], 352 float ray_start[3], 353 float ray_normal[3], 354 const bool do_clip); 355 bool ED_view3d_win_to_ray_clipped_ex(struct Depsgraph *depsgraph, 356 const struct ARegion *region, 357 const struct View3D *v3d, 358 const float mval[2], 359 float r_ray_co[3], 360 float r_ray_normal[3], 361 float r_ray_start[3], 362 bool do_clip); 363 void ED_view3d_win_to_ray(const struct ARegion *region, 364 const float mval[2], 365 float r_ray_start[3], 366 float r_ray_normal[3]); 367 void ED_view3d_global_to_vector(const struct RegionView3D *rv3d, 368 const float coord[3], 369 float vec[3]); 370 void ED_view3d_win_to_3d(const struct View3D *v3d, 371 const struct ARegion *region, 372 const float depth_pt[3], 373 const float mval[2], 374 float r_out[3]); 375 void ED_view3d_win_to_3d_int(const struct View3D *v3d, 376 const struct ARegion *region, 377 const float depth_pt[3], 378 const int mval[2], 379 float r_out[3]); 380 bool ED_view3d_win_to_3d_on_plane(const struct ARegion *region, 381 const float plane[4], 382 const float mval[2], 383 const bool do_clip, 384 float r_out[3]); 385 bool ED_view3d_win_to_3d_on_plane_int(const struct ARegion *region, 386 const float plane[4], 387 const int mval[2], 388 const bool do_clip, 389 float r_out[3]); 390 void ED_view3d_win_to_delta(const struct ARegion *region, 391 const float mval[2], 392 float out[3], 393 const float zfac); 394 void ED_view3d_win_to_origin(const struct ARegion *region, const float mval[2], float out[3]); 395 void ED_view3d_win_to_vector(const struct ARegion *region, const float mval[2], float out[3]); 396 bool ED_view3d_win_to_segment_clipped(struct Depsgraph *depsgraph, 397 const struct ARegion *region, 398 struct View3D *v3d, 399 const float mval[2], 400 float r_ray_start[3], 401 float r_ray_end[3], 402 const bool do_clip); 403 void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, 404 struct Object *ob, 405 float r_pmat[4][4]); 406 void ED_view3d_ob_project_mat_get_from_obmat(const struct RegionView3D *rv3d, 407 const float obmat[4][4], 408 float r_pmat[4][4]); 409 410 void ED_view3d_project(const struct ARegion *region, const float world[3], float r_region_co[3]); 411 bool ED_view3d_unproject( 412 const struct ARegion *region, float regionx, float regiony, float regionz, float world[3]); 413 414 /* end */ 415 416 void ED_view3d_dist_range_get(const struct View3D *v3d, float r_dist_range[2]); 417 bool ED_view3d_clip_range_get(struct Depsgraph *depsgraph, 418 const struct View3D *v3d, 419 const struct RegionView3D *rv3d, 420 float *r_clipsta, 421 float *r_clipend, 422 const bool use_ortho_factor); 423 bool ED_view3d_viewplane_get(struct Depsgraph *depsgraph, 424 const struct View3D *v3d, 425 const struct RegionView3D *rv3d, 426 int winxi, 427 int winyi, 428 struct rctf *r_viewplane, 429 float *r_clipsta, 430 float *r_clipend, 431 float *r_pixsize); 432 433 void ED_view3d_polygon_offset(const struct RegionView3D *rv3d, const float dist); 434 435 void ED_view3d_calc_camera_border(const struct Scene *scene, 436 struct Depsgraph *depsgraph, 437 const struct ARegion *region, 438 const struct View3D *v3d, 439 const struct RegionView3D *rv3d, 440 struct rctf *r_viewborder, 441 const bool no_shift); 442 void ED_view3d_calc_camera_border_size(const struct Scene *scene, 443 struct Depsgraph *depsgraph, 444 const struct ARegion *region, 445 const struct View3D *v3d, 446 const struct RegionView3D *rv3d, 447 float r_size[2]); 448 bool ED_view3d_calc_render_border(const struct Scene *scene, 449 struct Depsgraph *depsgraph, 450 struct View3D *v3d, 451 struct ARegion *region, 452 struct rcti *rect); 453 454 void ED_view3d_clipping_calc_from_boundbox(float clip[6][4], 455 const struct BoundBox *clipbb, 456 const bool is_flip); 457 void ED_view3d_clipping_calc(struct BoundBox *bb, 458 float planes[4][4], 459 const struct ARegion *region, 460 const struct Object *ob, 461 const struct rcti *rect); 462 void ED_view3d_clipping_local(struct RegionView3D *rv3d, const float mat[4][4]); 463 bool ED_view3d_clipping_test(const struct RegionView3D *rv3d, 464 const float co[3], 465 const bool is_local); 466 467 float ED_view3d_radius_to_dist_persp(const float angle, const float radius); 468 float ED_view3d_radius_to_dist_ortho(const float lens, const float radius); 469 float ED_view3d_radius_to_dist(const struct View3D *v3d, 470 const struct ARegion *region, 471 const struct Depsgraph *depsgraph, 472 const char persp, 473 const bool use_aspect, 474 const float radius); 475 476 void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned int pos); 477 478 /* backbuffer select and draw support */ 479 void ED_view3d_backbuf_depth_validate(struct ViewContext *vc); 480 int ED_view3d_backbuf_sample_size_clamp(struct ARegion *region, const float dist); 481 482 void ED_view3d_select_id_validate(struct ViewContext *vc); 483 484 bool ED_view3d_autodist(struct Depsgraph *depsgraph, 485 struct ARegion *region, 486 struct View3D *v3d, 487 const int mval[2], 488 float mouse_worldloc[3], 489 const bool alphaoverride, 490 const float fallback_depth_pt[3]); 491 492 /* only draw so ED_view3d_autodist_simple can be called many times after */ 493 void ED_view3d_autodist_init(struct Depsgraph *depsgraph, 494 struct ARegion *region, 495 struct View3D *v3d, 496 int mode); 497 bool ED_view3d_autodist_simple(struct ARegion *region, 498 const int mval[2], 499 float mouse_worldloc[3], 500 int margin, 501 const float *force_depth); 502 bool ED_view3d_autodist_depth(struct ARegion *region, const int mval[2], int margin, float *depth); 503 bool ED_view3d_autodist_depth_seg(struct ARegion *region, 504 const int mval_sta[2], 505 const int mval_end[2], 506 int margin, 507 float *depth); 508 509 /* select */ 510 #define MAXPICKELEMS 2500 511 #define MAXPICKBUF (4 * MAXPICKELEMS) 512 513 typedef enum { 514 /* all elements in the region, ignore depth */ 515 VIEW3D_SELECT_ALL = 0, 516 /* pick also depth sorts (only for small regions!) */ 517 VIEW3D_SELECT_PICK_ALL = 1, 518 /* sorts and only returns visible objects (only for small regions!) */ 519 VIEW3D_SELECT_PICK_NEAREST = 2, 520 } eV3DSelectMode; 521 522 typedef enum { 523 /** Don't exclude anything. */ 524 VIEW3D_SELECT_FILTER_NOP = 0, 525 /** Don't select objects outside the current mode. */ 526 VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK = 1, 527 /** A version of #VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK that allows pose-bone selection. */ 528 VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK = 2, 529 } eV3DSelectObjectFilter; 530 531 eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const struct Scene *scene, 532 const struct Object *obact); 533 534 void view3d_opengl_select_cache_begin(void); 535 void view3d_opengl_select_cache_end(void); 536 537 int view3d_opengl_select(struct ViewContext *vc, 538 unsigned int *buffer, 539 unsigned int bufsize, 540 const struct rcti *input, 541 eV3DSelectMode select_mode, 542 eV3DSelectObjectFilter select_filter); 543 int view3d_opengl_select_with_id_filter(struct ViewContext *vc, 544 unsigned int *buffer, 545 unsigned int bufsize, 546 const struct rcti *input, 547 eV3DSelectMode select_mode, 548 eV3DSelectObjectFilter select_filter, 549 uint select_id); 550 551 /* view3d_select.c */ 552 float ED_view3d_select_dist_px(void); 553 void ED_view3d_viewcontext_init(struct bContext *C, 554 struct ViewContext *vc, 555 struct Depsgraph *depsgraph); 556 void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact); 557 void view3d_operator_needs_opengl(const struct bContext *C); 558 void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *region); 559 560 /* XXX should move to BLI_math */ 561 bool edge_inside_circle(const float cent[2], 562 float radius, 563 const float screen_co_a[2], 564 const float screen_co_b[2]); 565 566 /* get 3d region from context, also if mouse is in header or toolbar */ 567 struct RegionView3D *ED_view3d_context_rv3d(struct bContext *C); 568 bool ED_view3d_context_user_region(struct bContext *C, 569 struct View3D **r_v3d, 570 struct ARegion **r_region); 571 bool ED_view3d_area_user_region(const struct ScrArea *area, 572 const struct View3D *v3d, 573 struct ARegion **r_region); 574 bool ED_operator_rv3d_user_region_poll(struct bContext *C); 575 576 void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d); 577 void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d); 578 #ifdef DEBUG 579 void ED_view3d_clear_mats_rv3d(struct RegionView3D *rv3d); 580 void ED_view3d_check_mats_rv3d(struct RegionView3D *rv3d); 581 #else 582 # define ED_view3d_clear_mats_rv3d(rv3d) (void)(rv3d) 583 # define ED_view3d_check_mats_rv3d(rv3d) (void)(rv3d) 584 #endif 585 586 struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d); 587 void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat); 588 589 void ED_draw_object_facemap(struct Depsgraph *depsgraph, 590 struct Object *ob, 591 const float col[4], 592 const int facemap); 593 594 struct RenderEngineType *ED_view3d_engine_type(const struct Scene *scene, int drawtype); 595 596 bool ED_view3d_context_activate(struct bContext *C); 597 void ED_view3d_draw_setup_view(const struct wmWindowManager *wm, 598 struct wmWindow *win, 599 struct Depsgraph *depsgraph, 600 struct Scene *scene, 601 struct ARegion *region, 602 struct View3D *v3d, 603 const float viewmat[4][4], 604 const float winmat[4][4], 605 const struct rcti *rect); 606 607 struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]); 608 struct Object *ED_view3d_give_object_under_cursor(struct bContext *C, const int mval[2]); 609 bool ED_view3d_is_object_under_cursor(struct bContext *C, const int mval[2]); 610 void ED_view3d_quadview_update(struct ScrArea *area, struct ARegion *region, bool do_clip); 611 void ED_view3d_update_viewmat(struct Depsgraph *depsgraph, 612 const struct Scene *scene, 613 struct View3D *v3d, 614 struct ARegion *region, 615 const float viewmat[4][4], 616 const float winmat[4][4], 617 const struct rcti *rect, 618 bool offscreen); 619 bool ED_view3d_quat_from_axis_view(const char view, const char view_axis_roll, float r_quat[4]); 620 bool ED_view3d_quat_to_axis_view(const float viewquat[4], 621 const float epsilon, 622 char *r_view, 623 char *r_view_axis_rotation); 624 625 char ED_view3d_lock_view_from_index(int index); 626 char ED_view3d_axis_view_opposite(char view); 627 bool ED_view3d_lock(struct RegionView3D *rv3d); 628 629 void ED_view3d_datamask(const struct bContext *C, 630 const struct Scene *scene, 631 const struct View3D *v3d, 632 struct CustomData_MeshMasks *r_cddata_masks); 633 void ED_view3d_screen_datamask(const struct bContext *C, 634 const struct Scene *scene, 635 const struct bScreen *screen, 636 struct CustomData_MeshMasks *r_cddata_masks); 637 638 bool ED_view3d_offset_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d); 639 void ED_view3d_persp_switch_from_camera(const struct Depsgraph *depsgraph, 640 struct View3D *v3d, 641 struct RegionView3D *rv3d, 642 const char persp); 643 bool ED_view3d_persp_ensure(const struct Depsgraph *depsgraph, 644 struct View3D *v3d, 645 struct ARegion *region); 646 647 /* camera lock functions */ 648 bool ED_view3d_camera_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d); 649 /* copy the camera to the view before starting a view transformation */ 650 void ED_view3d_camera_lock_init_ex(const struct Depsgraph *depsgraph, 651 struct View3D *v3d, 652 struct RegionView3D *rv3d, 653 const bool calc_dist); 654 void ED_view3d_camera_lock_init(const struct Depsgraph *depsgraph, 655 struct View3D *v3d, 656 struct RegionView3D *rv3d); 657 /* copy the view to the camera, return true if */ 658 bool ED_view3d_camera_lock_sync(const struct Depsgraph *depsgraph, 659 struct View3D *v3d, 660 struct RegionView3D *rv3d); 661 662 bool ED_view3d_camera_autokey(const struct Scene *scene, 663 struct ID *id_key, 664 struct bContext *C, 665 const bool do_rotate, 666 const bool do_translate); 667 bool ED_view3d_camera_lock_autokey(struct View3D *v3d, 668 struct RegionView3D *rv3d, 669 struct bContext *C, 670 const bool do_rotate, 671 const bool do_translate); 672 673 void ED_view3d_lock_clear(struct View3D *v3d); 674 675 #define VIEW3D_MARGIN 1.4f 676 #define VIEW3D_DIST_FALLBACK 1.0f 677 678 float ED_view3d_offset_distance(const float mat[4][4], 679 const float ofs[3], 680 const float fallback_dist); 681 void ED_view3d_distance_set(struct RegionView3D *rv3d, const float dist); 682 bool ED_view3d_distance_set_from_location(struct RegionView3D *rv3d, 683 const float dist_co[3], 684 const float dist_min); 685 686 float ED_scene_grid_scale(const struct Scene *scene, const char **r_grid_unit); 687 float ED_view3d_grid_scale(const struct Scene *scene, 688 struct View3D *v3d, 689 const char **r_grid_unit); 690 void ED_view3d_grid_steps(const struct Scene *scene, 691 struct View3D *v3d, 692 struct RegionView3D *rv3d, 693 float *r_grid_steps); 694 float ED_view3d_grid_view_scale(struct Scene *scene, 695 struct View3D *v3d, 696 struct RegionView3D *rv3d, 697 const char **r_grid_unit); 698 699 void ED_scene_draw_fps(const struct Scene *scene, int xoffset, int *yoffset); 700 701 /* render */ 702 void ED_view3d_stop_render_preview(struct wmWindowManager *wm, struct ARegion *region); 703 void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrArea *area); 704 705 #define XRAY_ALPHA(v3d) \ 706 (((v3d)->shading.type == OB_WIRE) ? (v3d)->shading.xray_alpha_wire : (v3d)->shading.xray_alpha) 707 #define XRAY_FLAG(v3d) \ 708 (((v3d)->shading.type == OB_WIRE) ? V3D_SHADING_XRAY_WIREFRAME : V3D_SHADING_XRAY) 709 #define XRAY_FLAG_ENABLED(v3d) (((v3d)->shading.flag & XRAY_FLAG(v3d)) != 0) 710 #define XRAY_ENABLED(v3d) (XRAY_FLAG_ENABLED(v3d) && (XRAY_ALPHA(v3d) < 1.0f)) 711 #define XRAY_ACTIVE(v3d) (XRAY_ENABLED(v3d) && ((v3d)->shading.type < OB_MATERIAL)) 712 713 /* view3d_draw_legacy.c */ 714 /* Try avoid using these more move out of legacy. */ 715 void ED_view3d_draw_bgpic_test(const struct Scene *scene, 716 struct Depsgraph *depsgraph, 717 struct ARegion *region, 718 struct View3D *v3d, 719 const bool do_foreground, 720 const bool do_camera_frame); 721 722 /* view3d_gizmo_preselect_type.c */ 723 void ED_view3d_gizmo_mesh_preselect_get_active(struct bContext *C, 724 struct wmGizmo *gz, 725 struct Base **r_base, 726 struct BMElem **r_ele); 727 728 /* space_view3d.c */ 729 void ED_view3d_buttons_region_layout_ex(const struct bContext *C, 730 struct ARegion *region, 731 const char *category_override); 732 733 /* view3d_view.c */ 734 bool ED_view3d_local_collections_set(struct Main *bmain, struct View3D *v3d); 735 void ED_view3d_local_collections_reset(struct bContext *C, const bool reset_all); 736 737 #ifdef WITH_XR_OPENXR 738 void ED_view3d_xr_mirror_update(const struct ScrArea *area, 739 const struct View3D *v3d, 740 const bool enable); 741 void ED_view3d_xr_shading_update(struct wmWindowManager *wm, 742 const View3D *v3d, 743 const struct Scene *scene); 744 bool ED_view3d_is_region_xr_mirror_active(const struct wmWindowManager *wm, 745 const struct View3D *v3d, 746 const struct ARegion *region); 747 #endif 748 749 #ifdef __cplusplus 750 } 751 #endif 752