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