CMake: add WITH_LINKER_LLD option for unix platforms
[blender-staging.git] / source / blender / editors / include / ED_mesh.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_MESH_H__
25 #define __ED_MESH_H__
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 struct ARegion;
32 struct BMBVHTree;
33 struct BMEdge;
34 struct BMEditMesh;
35 struct BMElem;
36 struct BMFace;
37 struct BMLoop;
38 struct BMVert;
39 struct BMesh;
40 struct Base;
41 struct Depsgraph;
42 struct ID;
43 struct MDeformVert;
44 struct Mesh;
45 struct Object;
46 struct ReportList;
47 struct Scene;
48 struct UndoType;
49 struct UvMapVert;
50 struct UvMapVert;
51 struct UvVertMap;
52 struct UvVertMap;
53 struct View3D;
54 struct ViewContext;
55 struct bContext;
56 struct bDeformGroup;
57 struct wmKeyConfig;
58 struct wmOperator;
59
60 /* editmesh_utils.c */
61 void EDBM_verts_mirror_cache_begin_ex(struct BMEditMesh *em,
62                                       const int axis,
63                                       const bool use_self,
64                                       const bool use_select,
65                                       const bool use_topology,
66                                       float maxdist,
67                                       int *r_index);
68 void EDBM_verts_mirror_cache_begin(struct BMEditMesh *em,
69                                    const int axis,
70                                    const bool use_self,
71                                    const bool use_select,
72                                    const bool use_toplogy);
73 void EDBM_verts_mirror_apply(struct BMEditMesh *em, const int sel_from, const int sel_to);
74 struct BMVert *EDBM_verts_mirror_get(struct BMEditMesh *em, struct BMVert *v);
75 struct BMEdge *EDBM_verts_mirror_get_edge(struct BMEditMesh *em, struct BMEdge *e);
76 struct BMFace *EDBM_verts_mirror_get_face(struct BMEditMesh *em, struct BMFace *f);
77 void EDBM_verts_mirror_cache_clear(struct BMEditMesh *em, struct BMVert *v);
78 void EDBM_verts_mirror_cache_end(struct BMEditMesh *em);
79
80 void EDBM_mesh_normals_update(struct BMEditMesh *em);
81 void EDBM_mesh_clear(struct BMEditMesh *em);
82
83 void EDBM_selectmode_to_scene(struct bContext *C);
84 void EDBM_mesh_make(struct Object *ob, const int select_mode, const bool add_key_index);
85 void EDBM_mesh_free(struct BMEditMesh *em);
86 void EDBM_mesh_load_ex(struct Main *bmain, struct Object *ob, bool free_data);
87 void EDBM_mesh_load(struct Main *bmain, struct Object *ob);
88
89 /* flushes based on the current select mode.  if in vertex select mode,
90  * verts select/deselect edges and faces, if in edge select mode,
91  * edges select/deselect faces and vertices, and in face select mode faces select/deselect
92  * edges and vertices.*/
93 void EDBM_select_more(struct BMEditMesh *em, const bool use_face_step);
94 void EDBM_select_less(struct BMEditMesh *em, const bool use_face_step);
95
96 void EDBM_selectmode_flush_ex(struct BMEditMesh *em, const short selectmode);
97 void EDBM_selectmode_flush(struct BMEditMesh *em);
98
99 void EDBM_deselect_flush(struct BMEditMesh *em);
100 void EDBM_select_flush(struct BMEditMesh *em);
101
102 bool EDBM_vert_color_check(struct BMEditMesh *em);
103
104 bool EDBM_mesh_hide(struct BMEditMesh *em, bool swap);
105 bool EDBM_mesh_reveal(struct BMEditMesh *em, bool select);
106
107 void EDBM_update_generic(struct Mesh *me, const bool do_tessellation, const bool is_destructive);
108
109 struct UvElementMap *BM_uv_element_map_create(struct BMesh *bm,
110                                               const struct Scene *scene,
111                                               const bool face_selected,
112                                               const bool uv_selected,
113                                               const bool use_winding,
114                                               const bool do_islands);
115 void BM_uv_element_map_free(struct UvElementMap *vmap);
116 struct UvElement *BM_uv_element_get(struct UvElementMap *map,
117                                     struct BMFace *efa,
118                                     struct BMLoop *l);
119
120 bool EDBM_uv_check(struct BMEditMesh *em);
121 struct BMFace *EDBM_uv_active_face_get(struct BMEditMesh *em,
122                                        const bool sloppy,
123                                        const bool selected);
124
125 void BM_uv_vert_map_free(struct UvVertMap *vmap);
126 struct UvMapVert *BM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v);
127 struct UvVertMap *BM_uv_vert_map_create(struct BMesh *bm,
128                                         const float limit[2],
129                                         const bool use_select,
130                                         const bool use_winding);
131
132 void EDBM_flag_enable_all(struct BMEditMesh *em, const char hflag);
133 void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag);
134
135 bool BMBVH_EdgeVisible(struct BMBVHTree *tree,
136                        struct BMEdge *e,
137                        struct Depsgraph *depsgraph,
138                        struct ARegion *region,
139                        struct View3D *v3d,
140                        struct Object *obedit);
141
142 void EDBM_project_snap_verts(struct bContext *C,
143                              struct Depsgraph *depsgraph,
144                              struct ARegion *region,
145                              struct Object *obedit,
146                              struct BMEditMesh *em);
147
148 /* editmesh_automerge.c */
149 void EDBM_automerge(struct Object *ob, bool update, const char hflag, const float dist);
150 void EDBM_automerge_and_split(struct Object *ob,
151                               const bool split_edges,
152                               const bool split_faces,
153                               const bool update,
154                               const char hflag,
155                               const float dist);
156
157 /* editmesh_undo.c */
158 void ED_mesh_undosys_type(struct UndoType *ut);
159
160 /* editmesh_select.c */
161 void EDBM_select_mirrored(struct BMEditMesh *em,
162                           const struct Mesh *me,
163                           const int axis,
164                           const bool extend,
165                           int *r_totmirr,
166                           int *r_totfail);
167
168 struct BMVert *EDBM_vert_find_nearest_ex(struct ViewContext *vc,
169                                          float *r_dist,
170                                          const bool use_select_bias,
171                                          bool use_cycle,
172                                          struct Base **bases,
173                                          uint bases_len,
174                                          uint *r_base_index);
175 struct BMVert *EDBM_vert_find_nearest(struct ViewContext *vc, float *r_dist);
176
177 struct BMEdge *EDBM_edge_find_nearest_ex(struct ViewContext *vc,
178                                          float *r_dist,
179                                          float *r_dist_center,
180                                          const bool use_select_bias,
181                                          bool use_cycle,
182                                          struct BMEdge **r_eed_zbuf,
183                                          struct Base **bases,
184                                          uint bases_len,
185                                          uint *r_base_index);
186 struct BMEdge *EDBM_edge_find_nearest(struct ViewContext *vc, float *r_dist);
187
188 struct BMFace *EDBM_face_find_nearest_ex(struct ViewContext *vc,
189                                          float *r_dist,
190                                          float *r_dist_center,
191                                          const bool use_select_bias,
192                                          bool use_cycle,
193                                          struct BMFace **r_efa_zbuf,
194                                          struct Base **bases,
195                                          uint bases_len,
196                                          uint *r_base_index);
197 struct BMFace *EDBM_face_find_nearest(struct ViewContext *vc, float *r_dist);
198
199 bool EDBM_unified_findnearest(struct ViewContext *vc,
200                               struct Base **bases,
201                               const uint bases_len,
202                               int *r_base_index,
203                               struct BMVert **r_eve,
204                               struct BMEdge **r_eed,
205                               struct BMFace **r_efa);
206
207 bool EDBM_unified_findnearest_from_raycast(struct ViewContext *vc,
208                                            struct Base **bases,
209                                            const uint bases_len,
210                                            bool use_boundary_vertices,
211                                            bool use_boundary_edges,
212                                            int *r_base_index_vert,
213                                            int *r_base_index_edge,
214                                            int *r_base_index_face,
215                                            struct BMVert **r_eve,
216                                            struct BMEdge **r_eed,
217                                            struct BMFace **r_efa);
218
219 bool EDBM_select_pick(
220     struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle);
221
222 void EDBM_selectmode_set(struct BMEditMesh *em);
223 void EDBM_selectmode_convert(struct BMEditMesh *em,
224                              const short selectmode_old,
225                              const short selectmode_new);
226
227 /* user access this */
228 bool EDBM_selectmode_set_multi(struct bContext *C, const short selectmode);
229 bool EDBM_selectmode_toggle_multi(struct bContext *C,
230                                   const short selectmode_new,
231                                   const int action,
232                                   const bool use_extend,
233                                   const bool use_expand);
234
235 bool EDBM_selectmode_disable(struct Scene *scene,
236                              struct BMEditMesh *em,
237                              const short selectmode_disable,
238                              const short selectmode_fallback);
239
240 bool EDBM_deselect_by_material(struct BMEditMesh *em, const short index, const bool select);
241
242 void EDBM_select_toggle_all(struct BMEditMesh *em);
243
244 void EDBM_select_swap(struct BMEditMesh *em); /* exported for UV */
245 bool EDBM_select_interior_faces(struct BMEditMesh *em);
246 void em_setup_viewcontext(struct bContext *C, struct ViewContext *vc); /* rename? */
247
248 bool EDBM_mesh_deselect_all_multi_ex(struct Base **bases, const uint bases_len);
249 bool EDBM_mesh_deselect_all_multi(struct bContext *C);
250 bool EDBM_selectmode_disable_multi_ex(struct Scene *scene,
251                                       struct Base **bases,
252                                       const uint bases_len,
253                                       const short selectmode_disable,
254                                       const short selectmode_fallback);
255 bool EDBM_selectmode_disable_multi(struct bContext *C,
256                                    const short selectmode_disable,
257                                    const short selectmode_fallback);
258
259 /* editmesh_preselect_edgering.c */
260 struct EditMesh_PreSelEdgeRing;
261 struct EditMesh_PreSelEdgeRing *EDBM_preselect_edgering_create(void);
262 void EDBM_preselect_edgering_destroy(struct EditMesh_PreSelEdgeRing *psel);
263 void EDBM_preselect_edgering_clear(struct EditMesh_PreSelEdgeRing *psel);
264 void EDBM_preselect_edgering_draw(struct EditMesh_PreSelEdgeRing *psel, const float matrix[4][4]);
265 void EDBM_preselect_edgering_update_from_edge(struct EditMesh_PreSelEdgeRing *psel,
266                                               struct BMesh *bm,
267                                               struct BMEdge *eed_start,
268                                               int previewlines,
269                                               const float (*coords)[3]);
270
271 /* editmesh_preselect_elem.c */
272 struct EditMesh_PreSelElem;
273 typedef enum eEditMesh_PreSelPreviewAction {
274   PRESELECT_ACTION_TRANSFORM = 1,
275   PRESELECT_ACTION_CREATE = 2,
276   PRESELECT_ACTION_DELETE = 3,
277 } eEditMesh_PreSelPreviewAction;
278
279 struct EditMesh_PreSelElem *EDBM_preselect_elem_create(void);
280 void EDBM_preselect_elem_destroy(struct EditMesh_PreSelElem *psel);
281 void EDBM_preselect_elem_clear(struct EditMesh_PreSelElem *psel);
282 void EDBM_preselect_preview_clear(struct EditMesh_PreSelElem *psel);
283 void EDBM_preselect_elem_draw(struct EditMesh_PreSelElem *psel, const float matrix[4][4]);
284 void EDBM_preselect_elem_update_from_single(struct EditMesh_PreSelElem *psel,
285                                             struct BMesh *bm,
286                                             struct BMElem *ele,
287                                             const float (*coords)[3]);
288
289 void EDBM_preselect_elem_update_preview(struct EditMesh_PreSelElem *psel,
290                                         struct ViewContext *vc,
291                                         struct BMesh *bm,
292                                         struct BMElem *ele,
293                                         const int mval[2]);
294 void EDBM_preselect_action_set(struct EditMesh_PreSelElem *psel,
295                                eEditMesh_PreSelPreviewAction action);
296 eEditMesh_PreSelPreviewAction EDBM_preselect_action_get(struct EditMesh_PreSelElem *psel);
297 /* mesh_ops.c */
298 void ED_operatortypes_mesh(void);
299 void ED_operatormacros_mesh(void);
300 void ED_keymap_mesh(struct wmKeyConfig *keyconf);
301
302 /* editface.c */
303 void paintface_flush_flags(struct bContext *C, struct Object *ob, short flag);
304 bool paintface_mouse_select(struct bContext *C,
305                             struct Object *ob,
306                             const int mval[2],
307                             bool extend,
308                             bool deselect,
309                             bool toggle);
310 bool paintface_deselect_all_visible(struct bContext *C,
311                                     struct Object *ob,
312                                     int action,
313                                     bool flush_flags);
314 void paintface_select_linked(struct bContext *C,
315                              struct Object *ob,
316                              const int mval[2],
317                              const bool select);
318 bool paintface_minmax(struct Object *ob, float r_min[3], float r_max[3]);
319
320 void paintface_hide(struct bContext *C, struct Object *ob, const bool unselected);
321 void paintface_reveal(struct bContext *C, struct Object *ob, const bool select);
322
323 bool paintvert_deselect_all_visible(struct Object *ob, int action, bool flush_flags);
324 void paintvert_select_ungrouped(struct Object *ob, bool extend, bool flush_flags);
325 void paintvert_flush_flags(struct Object *ob);
326 void paintvert_tag_select_update(struct bContext *C, struct Object *ob);
327
328 /* mirrtopo */
329 typedef struct MirrTopoStore_t {
330   intptr_t *index_lookup;
331   int prev_vert_tot;
332   int prev_edge_tot;
333   bool prev_is_editmode;
334 } MirrTopoStore_t;
335
336 bool ED_mesh_mirrtopo_recalc_check(struct BMEditMesh *em,
337                                    struct Mesh *me,
338                                    MirrTopoStore_t *mesh_topo_store);
339 void ED_mesh_mirrtopo_init(struct BMEditMesh *em,
340                            struct Mesh *me,
341                            MirrTopoStore_t *mesh_topo_store,
342                            const bool skip_em_vert_array_init);
343 void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store);
344
345 /* object_vgroup.c */
346 #define WEIGHT_REPLACE 1
347 #define WEIGHT_ADD 2
348 #define WEIGHT_SUBTRACT 3
349
350 bool ED_vgroup_sync_from_pose(struct Object *ob);
351 void ED_vgroup_select_by_name(struct Object *ob, const char *name);
352 void ED_vgroup_data_clamp_range(struct ID *id, const int total);
353 bool ED_vgroup_array_copy(struct Object *ob, struct Object *ob_from);
354 bool ED_vgroup_parray_alloc(struct ID *id,
355                             struct MDeformVert ***dvert_arr,
356                             int *dvert_tot,
357                             const bool use_vert_sel);
358 void ED_vgroup_parray_mirror_sync(struct Object *ob,
359                                   struct MDeformVert **dvert_array,
360                                   const int dvert_tot,
361                                   const bool *vgroup_validmap,
362                                   const int vgroup_tot);
363 void ED_vgroup_parray_mirror_assign(struct Object *ob,
364                                     struct MDeformVert **dvert_array,
365                                     const int dvert_tot);
366 void ED_vgroup_parray_remove_zero(struct MDeformVert **dvert_array,
367                                   const int dvert_tot,
368                                   const bool *vgroup_validmap,
369                                   const int vgroup_tot,
370                                   const float epsilon,
371                                   const bool keep_single);
372 void ED_vgroup_parray_to_weight_array(const struct MDeformVert **dvert_array,
373                                       const int dvert_tot,
374                                       float *dvert_weights,
375                                       const int def_nr);
376 void ED_vgroup_parray_from_weight_array(struct MDeformVert **dvert_array,
377                                         const int dvert_tot,
378                                         const float *dvert_weights,
379                                         const int def_nr,
380                                         const bool remove_zero);
381 void ED_vgroup_mirror(struct Object *ob,
382                       const bool mirror_weights,
383                       const bool flip_vgroups,
384                       const bool all_vgroups,
385                       const bool use_topology,
386                       int *r_totmirr,
387                       int *r_totfail);
388
389 void ED_vgroup_vert_add(
390     struct Object *ob, struct bDeformGroup *dg, int vertnum, float weight, int assignmode);
391 void ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum);
392 float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum);
393 void ED_vgroup_vert_active_mirror(struct Object *ob, int def_nr);
394
395 /* mesh_data.c */
396 void ED_mesh_verts_add(struct Mesh *mesh, struct ReportList *reports, int count);
397 void ED_mesh_edges_add(struct Mesh *mesh, struct ReportList *reports, int count);
398 void ED_mesh_loops_add(struct Mesh *mesh, struct ReportList *reports, int count);
399 void ED_mesh_polys_add(struct Mesh *mesh, struct ReportList *reports, int count);
400
401 void ED_mesh_verts_remove(struct Mesh *mesh, struct ReportList *reports, int count);
402 void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count);
403 void ED_mesh_loops_remove(struct Mesh *mesh, struct ReportList *reports, int count);
404 void ED_mesh_polys_remove(struct Mesh *mesh, struct ReportList *reports, int count);
405
406 void ED_mesh_geometry_clear(struct Mesh *mesh);
407
408 void ED_mesh_update(struct Mesh *mesh, struct bContext *C, bool calc_edges, bool calc_edges_loose);
409
410 void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name);
411 int ED_mesh_uv_texture_add(struct Mesh *me,
412                            const char *name,
413                            const bool active_set,
414                            const bool do_init);
415 bool ED_mesh_uv_texture_remove_index(struct Mesh *me, const int n);
416 bool ED_mesh_uv_texture_remove_active(struct Mesh *me);
417 bool ED_mesh_uv_texture_remove_named(struct Mesh *me, const char *name);
418 void ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me);
419 void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum);
420 bool ED_mesh_color_ensure(struct Mesh *me, const char *name);
421 int ED_mesh_color_add(struct Mesh *me,
422                       const char *name,
423                       const bool active_set,
424                       const bool do_init);
425 bool ED_mesh_color_remove_index(struct Mesh *me, const int n);
426 bool ED_mesh_color_remove_active(struct Mesh *me);
427 bool ED_mesh_color_remove_named(struct Mesh *me, const char *name);
428
429 void ED_mesh_report_mirror(struct wmOperator *op, int totmirr, int totfail);
430 void ED_mesh_report_mirror_ex(struct wmOperator *op, int totmirr, int totfail, char selectmode);
431
432 /* Returns the pinned mesh, the mesh from the pinned object, or the mesh from the active object. */
433 struct Mesh *ED_mesh_context(struct bContext *C);
434
435 /* mesh backup */
436 typedef struct BMBackup {
437   struct BMesh *bmcopy;
438 } BMBackup;
439
440 /* save a copy of the bmesh for restoring later */
441 struct BMBackup EDBM_redo_state_store(struct BMEditMesh *em);
442 /* restore a bmesh from backup */
443 void EDBM_redo_state_restore(struct BMBackup, struct BMEditMesh *em, int recalctess);
444 /* delete the backup, optionally flushing it to an editmesh */
445 void EDBM_redo_state_free(struct BMBackup *, struct BMEditMesh *em, int recalctess);
446
447 /* *** meshtools.c *** */
448 int join_mesh_exec(struct bContext *C, struct wmOperator *op);
449 int join_mesh_shapes_exec(struct bContext *C, struct wmOperator *op);
450
451 /* mirror lookup api */
452 /* Spatial Mirror */
453 void ED_mesh_mirror_spatial_table_begin(struct Object *ob,
454                                         struct BMEditMesh *em,
455                                         struct Mesh *me_eval);
456 void ED_mesh_mirror_spatial_table_end(struct Object *ob);
457 int ED_mesh_mirror_spatial_table_lookup(struct Object *ob,
458                                         struct BMEditMesh *em,
459                                         struct Mesh *me_eval,
460                                         const float co[3]);
461
462 /* Topology Mirror */
463 void ED_mesh_mirror_topo_table_begin(struct Object *ob, struct Mesh *me_eval);
464 void ED_mesh_mirror_topo_table_end(struct Object *ob);
465
466 /* retrieves mirrored cache vert, or NULL if there isn't one.
467  * note: calling this without ensuring the mirror cache state
468  * is bad.*/
469 int mesh_get_x_mirror_vert(struct Object *ob,
470                            struct Mesh *me_eval,
471                            int index,
472                            const bool use_topology);
473 struct BMVert *editbmesh_get_x_mirror_vert(struct Object *ob,
474                                            struct BMEditMesh *em,
475                                            struct BMVert *eve,
476                                            const float co[3],
477                                            int index,
478                                            const bool use_topology);
479 int *mesh_get_x_mirror_faces(struct Object *ob, struct BMEditMesh *em, struct Mesh *me_eval);
480
481 int ED_mesh_mirror_get_vert(struct Object *ob, int index);
482
483 bool ED_mesh_pick_vert(struct bContext *C,
484                        struct Object *ob,
485                        const int mval[2],
486                        uint dist_px,
487                        bool use_zbuf,
488                        uint *r_index);
489 bool ED_mesh_pick_face(
490     struct bContext *C, struct Object *ob, const int mval[2], uint dist_px, uint *r_index);
491 bool ED_mesh_pick_face_vert(
492     struct bContext *C, struct Object *ob, const int mval[2], uint dist_px, uint *r_index);
493
494 struct MDeformVert *ED_mesh_active_dvert_get_em(struct Object *ob, struct BMVert **r_eve);
495 struct MDeformVert *ED_mesh_active_dvert_get_ob(struct Object *ob, int *r_index);
496 struct MDeformVert *ED_mesh_active_dvert_get_only(struct Object *ob);
497
498 void EDBM_mesh_stats_multi(struct Object **objects,
499                            const uint objects_len,
500                            int totelem[3],
501                            int totelem_sel[3]);
502 void EDBM_mesh_elem_index_ensure_multi(struct Object **objects,
503                                        const uint objects_len,
504                                        const char htype);
505
506 #define ED_MESH_PICK_DEFAULT_VERT_DIST 25
507 #define ED_MESH_PICK_DEFAULT_FACE_DIST 1
508
509 #define USE_LOOPSLIDE_HACK
510
511 #ifdef __cplusplus
512 }
513 #endif
514
515 #endif /* __ED_MESH_H__ */