Blender V5.3
bmesh_class.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
13
14#include "BLI_assert.hh"
15#include "BLI_sys_types.hh"
16
18#include "DNA_listBase.h"
19
20namespace blender {
21
22/* disable holes for now,
23 * these are ifdef'd because they use more memory and can't be saved in DNA currently */
24// #define USE_BMESH_HOLES
25
26struct BMEditSelection;
27struct BMEdge;
28struct BMFace;
29struct BMLoop;
30struct BMOpError;
31struct BMVert;
32struct BMesh;
33
35
36struct BLI_mempool;
37
38// #pragma GCC diagnostic push
39// #pragma GCC diagnostic error "-Wpadded"
40
53struct BMHeader {
54
55 /* NOTE: it its essential the #BMHeader is at least the size of two pointers.
56 * This is a requirement of mempool's method of iteration.
57 *
58 * Even though there is only a single pointer, the struct will be padded to two. */
59
61 void *data;
62
71 int index;
72
74 char htype;
76 char hflag;
77
85 // char _pad;
86};
87
88BLI_STATIC_ASSERT((sizeof(BMHeader) <= 16), "BMHeader size has grown!");
89
90/* NOTE: need some way to specify custom locations for custom data layers. so we can
91 * make them point directly into structs. and some way to make it only happen to the
92 * active layer, and properly update when switching active layers. */
93
94struct BMVert {
97 float co[3];
99 float no[3];
100
108 struct BMEdge *e;
109};
110
115
121 struct BMEdge *next, *prev;
122};
123
152
157
158struct BMLoop {
160 /* Notice no #BMFlagLayer, making this different from other elements. */
161
167 struct BMVert *v;
168
178 struct BMEdge *e;
185 struct BMFace *f;
186
219
247 struct BMLoop *next, *prev;
248};
249
254struct BMElemF {
256};
257
262struct BMElem {
264};
265
266#ifdef USE_BMESH_HOLES
271struct BMLoopList {
272 struct BMLoopList *next, *prev;
273 struct BMLoop *first, *last;
274};
275#endif
276
277struct BMFace {
279
280#ifdef USE_BMESH_HOLES
282 int totbounds;
283 ListBaseT<BMLoop> loops;
284#else
286#endif
291 int len;
295 float no[3];
305 short mat_nr;
306 // short _pad[3];
307};
308
313
315 short f; /* flags */
316};
317
318// #pragma GCC diagnostic pop
319
320struct BMesh {
321 int totvert = 0;
322 int totedge = 0;
323 int totloop = 0;
324 int totface = 0;
325 int totvertsel = 0;
326 int totedgesel = 0;
327 int totfacesel = 0;
328
335
341
343 BLI_mempool *vpool = nullptr;
344 BLI_mempool *epool = nullptr;
345 BLI_mempool *lpool = nullptr;
346 BLI_mempool *fpool = nullptr;
347
348 /* #BLI_mempool lookup tables (optional).
349 * Map indices to elements via #BM_mesh_elem_table_ensure and associated functions.
350 * Don't touch this or read it directly.
351 * Use #BM_mesh_elem_table_ensure(), `BM_vert/edge/face_at_index()`. */
352
354 BMVert **vtable = nullptr;
356 BMEdge **etable = nullptr;
358 BMFace **ftable = nullptr;
359
360 /* Size of allocated tables. */
361
362 int vtable_tot = 0;
363 int etable_tot = 0;
364 int ftable_tot = 0;
365
370
371 bool use_toolflags = false;
372
390
392
397
398#ifdef USE_BMESH_HOLES
399 BLI_mempool *looplistpool = nullptr;
400#endif
401
404
411 short selectmode = 0;
412
414 int shapenr = 0;
415
416 int totflags = 0;
417 ListBaseT<BMEditSelection> selected = {};
418
427 BMFace *act_face = nullptr;
428
430 ListBaseT<BMOpError> errorstack = {};
431
441 void *py_handle = nullptr;
442};
443
445enum {
450};
451
455 float niloc[3];
456 float nloc[3];
457 float *loc;
459};
460
472
473#define BM_ALL (BM_VERT | BM_EDGE | BM_LOOP | BM_FACE)
474#define BM_ALL_NOLOOP (BM_VERT | BM_EDGE | BM_FACE)
475
477enum {
481};
482
483/* args for _Generic */
484#define _BM_GENERIC_TYPE_ELEM_NONCONST \
485 void *, BMVert *, BMEdge *, BMLoop *, BMFace *, BMVert_OFlag *, BMEdge_OFlag *, BMFace_OFlag *, \
486 BMElem *, BMElemF *, BMHeader *
487
488#define _BM_GENERIC_TYPE_ELEM_CONST \
489 const void *, const BMVert *, const BMEdge *, const BMLoop *, const BMFace *, \
490 const BMVert_OFlag *, const BMEdge_OFlag *, const BMFace_OFlag *, const BMElem *, \
491 const BMElemF *, const BMHeader *
492
493#define BM_CHECK_TYPE_ELEM_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPES_CONST)
494
495#define BM_CHECK_TYPE_ELEM_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST)
496
497#define BM_CHECK_TYPE_ELEM(ele) \
498 CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST, _BM_GENERIC_TYPE_ELEM_CONST)
499
500/* vert */
501#define _BM_GENERIC_TYPE_VERT_NONCONST BMVert *, BMVert_OFlag *
502#define _BM_GENERIC_TYPE_VERT_CONST const BMVert *, const BMVert_OFlag *
503#define BM_CHECK_TYPE_VERT_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_VERT_CONST)
504#define BM_CHECK_TYPE_VERT_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST)
505#define BM_CHECK_TYPE_VERT(ele) \
506 CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_VERT_NONCONST, _BM_GENERIC_TYPE_VERT_CONST)
507/* edge */
508#define _BM_GENERIC_TYPE_EDGE_NONCONST BMEdge *, BMEdge_OFlag *
509#define _BM_GENERIC_TYPE_EDGE_CONST const BMEdge *, const BMEdge_OFlag *
510#define BM_CHECK_TYPE_EDGE_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_EDGE_CONST)
511#define BM_CHECK_TYPE_EDGE_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST)
512#define BM_CHECK_TYPE_EDGE(ele) \
513 CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_EDGE_NONCONST, _BM_GENERIC_TYPE_EDGE_CONST)
514/* face */
515#define _BM_GENERIC_TYPE_FACE_NONCONST BMFace *, BMFace_OFlag *
516#define _BM_GENERIC_TYPE_FACE_CONST const BMFace *, const BMFace_OFlag *
517#define BM_CHECK_TYPE_FACE_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_FACE_CONST)
518#define BM_CHECK_TYPE_FACE_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST)
519#define BM_CHECK_TYPE_FACE(ele) \
520 CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_FACE_NONCONST, _BM_GENERIC_TYPE_FACE_CONST)
521
526#define BM_CHECK_TYPE_ELEM_ASSIGN(ele) (BM_CHECK_TYPE_ELEM(ele)), *((void **)&ele)
527
529enum {
530 BM_ELEM_SELECT = (1 << 0),
531 BM_ELEM_HIDDEN = (1 << 1),
532 BM_ELEM_SEAM = (1 << 2),
534 BM_ELEM_SMOOTH = (1 << 3),
541 BM_ELEM_TAG = (1 << 4),
542
548
550 BM_ELEM_TAG_ALT = (1 << 6),
551
558};
559
560/* Only for #BMLoop to select an edge. */
561#define BM_ELEM_SELECT_UV_EDGE BM_ELEM_SEAM
562
563struct BPy_BMGeneric;
564extern void bpy_bm_generic_invalidate(struct BPy_BMGeneric *self);
565
566using BMElemFilterFunc = bool (*)(const BMElem *, void *user_data);
567using BMVertFilterFunc = bool (*)(const BMVert *, void *user_data);
568using BMEdgeFilterFunc = bool (*)(const BMEdge *, void *user_data);
569using BMFaceFilterFunc = bool (*)(const BMFace *, void *user_data);
570using BMLoopFilterFunc = bool (*)(const BMLoop *, void *user_data);
571using BMLoopPairFilterFunc = bool (*)(const BMLoop *, const BMLoop *, void *user_data);
572
573/* defines */
574#define BM_ELEM_CD_SET_INT(ele, offset, f) \
575 { \
576 CHECK_TYPE_NONCONST(ele); \
577 BLI_assert(offset != -1); \
578 *((int *)((char *)(ele)->head.data + (offset))) = (f); \
579 } \
580 (void)0
581
582#define BM_ELEM_CD_GET_INT(ele, offset) \
583 (BLI_assert(offset != -1), *((int *)((char *)(ele)->head.data + (offset))))
584
585#define BM_ELEM_CD_SET_BOOL(ele, offset, f) \
586 { \
587 CHECK_TYPE_NONCONST(ele); \
588 BLI_assert(offset != -1); \
589 *((bool *)((char *)(ele)->head.data + (offset))) = (f); \
590 } \
591 (void)0
592
593#define BM_ELEM_CD_GET_BOOL(ele, offset) \
594 (BLI_assert(offset != -1), *((bool *)((char *)(ele)->head.data + (offset))))
595
596#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
597# define BM_ELEM_CD_GET_BOOL_P(ele, offset) \
598 (BLI_assert(offset != -1), \
599 _Generic(ele, \
600 GENERIC_TYPE_ANY((bool *)POINTER_OFFSET((ele)->head.data, offset), \
601 _BM_GENERIC_TYPE_ELEM_NONCONST), \
602 GENERIC_TYPE_ANY((const bool *)POINTER_OFFSET((ele)->head.data, offset), \
603 _BM_GENERIC_TYPE_ELEM_CONST)))
604#else
605# define BM_ELEM_CD_GET_BOOL_P(ele, offset) \
606 (BLI_assert(offset != -1), (bool *)((char *)(ele)->head.data + (offset)))
607#endif
608
609#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
610# define BM_ELEM_CD_GET_VOID_P(ele, offset) \
611 (BLI_assert(offset != -1), \
612 _Generic(ele, \
613 GENERIC_TYPE_ANY(POINTER_OFFSET((ele)->head.data, offset), \
614 _BM_GENERIC_TYPE_ELEM_NONCONST), \
615 GENERIC_TYPE_ANY((const void *)POINTER_OFFSET((ele)->head.data, offset), \
616 _BM_GENERIC_TYPE_ELEM_CONST)))
617#else
618# define BM_ELEM_CD_GET_VOID_P(ele, offset) \
619 (BLI_assert(offset != -1), (void *)((char *)(ele)->head.data + (offset)))
620#endif
621
622#define BM_ELEM_CD_SET_FLOAT(ele, offset, f) \
623 { \
624 CHECK_TYPE_NONCONST(ele); \
625 BLI_assert(offset != -1); \
626 *((float *)((char *)(ele)->head.data + (offset))) = (f); \
627 } \
628 (void)0
629
630#define BM_ELEM_CD_GET_FLOAT(ele, offset) \
631 (BLI_assert(offset != -1), *((float *)((char *)(ele)->head.data + (offset))))
632
633#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
634
635# define BM_ELEM_CD_GET_FLOAT_P(ele, offset) \
636 (BLI_assert(offset != -1), \
637 _Generic(ele, \
638 GENERIC_TYPE_ANY((float *)POINTER_OFFSET((ele)->head.data, offset), \
639 _BM_GENERIC_TYPE_ELEM_NONCONST), \
640 GENERIC_TYPE_ANY((const float *)POINTER_OFFSET((ele)->head.data, offset), \
641 _BM_GENERIC_TYPE_ELEM_CONST)))
642
643# define BM_ELEM_CD_GET_FLOAT2_P(ele, offset) \
644 (BLI_assert(offset != -1), \
645 _Generic(ele, \
646 GENERIC_TYPE_ANY((float (*)[2])POINTER_OFFSET((ele)->head.data, offset), \
647 _BM_GENERIC_TYPE_ELEM_NONCONST), \
648 GENERIC_TYPE_ANY((const float (*)[2])POINTER_OFFSET((ele)->head.data, offset), \
649 _BM_GENERIC_TYPE_ELEM_CONST)))
650
651# define BM_ELEM_CD_GET_FLOAT3_P(ele, offset) \
652 (BLI_assert(offset != -1), \
653 _Generic(ele, \
654 GENERIC_TYPE_ANY((float (*)[3])POINTER_OFFSET((ele)->head.data, offset), \
655 _BM_GENERIC_TYPE_ELEM_NONCONST), \
656 GENERIC_TYPE_ANY((const float (*)[3])POINTER_OFFSET((ele)->head.data, offset), \
657 _BM_GENERIC_TYPE_ELEM_CONST)))
658
659#else
660
661# define BM_ELEM_CD_GET_FLOAT_P(ele, offset) \
662 (BLI_assert(offset != -1), (float *)((char *)(ele)->head.data + (offset)))
663
664# define BM_ELEM_CD_GET_FLOAT2_P(ele, offset) \
665 (BLI_assert(offset != -1), (float (*)[2])((char *)(ele)->head.data + (offset)))
666
667# define BM_ELEM_CD_GET_FLOAT3_P(ele, offset) \
668 (BLI_assert(offset != -1), (float (*)[3])((char *)(ele)->head.data + (offset)))
669
670#endif
671
672#define BM_ELEM_CD_SET_FLOAT2(ele, offset, f) \
673 { \
674 CHECK_TYPE_NONCONST(ele); \
675 BLI_assert(offset != -1); \
676 ((float *)((char *)(ele)->head.data + (offset)))[0] = (f)[0]; \
677 ((float *)((char *)(ele)->head.data + (offset)))[1] = (f)[1]; \
678 } \
679 (void)0
680
681#define BM_ELEM_CD_SET_FLOAT3(ele, offset, f) \
682 { \
683 CHECK_TYPE_NONCONST(ele); \
684 BLI_assert(offset != -1); \
685 ((float *)((char *)(ele)->head.data + (offset)))[0] = (f)[0]; \
686 ((float *)((char *)(ele)->head.data + (offset)))[1] = (f)[1]; \
687 ((float *)((char *)(ele)->head.data + (offset)))[2] = (f)[2]; \
688 } \
689 (void)0
690
691#define BM_ELEM_CD_GET_FLOAT_AS_UCHAR(ele, offset) \
692 (BLI_assert(offset != -1), (uchar)(BM_ELEM_CD_GET_FLOAT(ele, offset) * 255.0f))
693
694/* Forward declarations. */
695
696#ifdef USE_BMESH_HOLES
697# define BM_FACE_FIRST_LOOP(p) (((BMLoopList *)((p)->loops.first))->first)
698#else
699# define BM_FACE_FIRST_LOOP(p) ((p)->l_first)
700#endif
701
702#define BM_DISK_EDGE_NEXT(e, v) \
703 (CHECK_TYPE_INLINE(e, BMEdge *), \
704 CHECK_TYPE_INLINE(v, BMVert *), \
705 BLI_assert(BM_vert_in_edge(e, v)), \
706 (((&e->v1_disk_link)[v == e->v2]).next))
707#define BM_DISK_EDGE_PREV(e, v) \
708 (CHECK_TYPE_INLINE(e, BMEdge *), \
709 CHECK_TYPE_INLINE(v, BMVert *), \
710 BLI_assert(BM_vert_in_edge(e, v)), \
711 (((&e->v1_disk_link)[v == e->v2]).prev))
712
717#define BM_DEFAULT_NGON_STACK_SIZE 32
723#define BM_DEFAULT_ITER_STACK_SIZE 16
729#define BM_DEFAULT_TOPOLOGY_STACK_SIZE 64
730
732#define BM_LOOP_RADIAL_MAX 10000
733#define BM_NGON_MAX 100000
734
736#define BM_THREAD_LIMIT 10000
737
738} // namespace blender
These structs are the foundation for all linked lists in the library system.
BMesh Iterators.
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
@ BM_SPACEARR_DIRTY_ALL
@ BM_SPACEARR_DIRTY
@ BM_SPACEARR_BMO_SET
bool(*)(const BMEdge *, void *user_data) BMEdgeFilterFunc
bool(*)(const BMElem *, void *user_data) BMElemFilterFunc
bool(*)(const BMVert *, void *user_data) BMVertFilterFunc
bool(*)(const BMLoop *, void *user_data) BMLoopFilterFunc
bool(*)(const BMFace *, void *user_data) BMFaceFilterFunc
@ BM_ELEM_SELECT_UV
@ BM_ELEM_INTERNAL_TAG
@ BM_ELEM_TAG_ALT
void bpy_bm_generic_invalidate(struct BPy_BMGeneric *)
bool(*)(const BMLoop *, const BMLoop *, void *user_data) BMLoopPairFilterFunc
struct BMFlagLayer * oflags
struct BMLoop * l
BMDiskLink v1_disk_link
BMDiskLink v2_disk_link
struct BMFlagLayer * oflags
BMLoopNorEditData * lnor_editdata
BMLoopNorEditData ** lidx_to_lnor_editdata
struct BMLoop * next
struct BMLoop * prev
struct BMLoop * radial_prev
struct BMEdge * e
struct BMVert * v
struct BMLoop * radial_next
struct BMFace * f
struct BMFlagLayer * oflags
struct BMEdge * e
BMVert ** vtable
ListBaseT< BMOpError > errorstack
BLI_mempool * epool
BLI_mempool * fpool
BLI_mempool * lpool
BMEdge ** etable
BLI_mempool * ftoolflagpool
CustomData pdata
ListBaseT< BMEditSelection > selected
BLI_mempool * vpool
CustomData vdata
struct MLoopNorSpaceArray * lnor_spacearr
CustomData edata
CustomData ldata
BLI_mempool * etoolflagpool
BMFace ** ftable
bool uv_select_sync_valid
BMFace * act_face
BLI_mempool * vtoolflagpool