Blender V4.5
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.h"
15#include "BLI_sys_types.h"
16
18#include "DNA_listBase.h"
19
20/* disable holes for now,
21 * these are ifdef'd because they use more memory and can't be saved in DNA currently */
22// #define USE_BMESH_HOLES
23
24struct BMEdge;
25struct BMFace;
26struct BMLoop;
27struct BMVert;
28struct BMesh;
29
31
32struct BLI_mempool;
33
34// #pragma GCC diagnostic push
35// #pragma GCC diagnostic error "-Wpadded"
36
49struct BMHeader {
50
51 /* NOTE: it its essential the #BMHeader is at least the size of two pointers.
52 * This is a requirement of mempool's method of iteration.
53 *
54 * Even though there is only a single pointer, the struct will be padded to two. */
55
57 void *data;
58
67 int index;
68
70 char htype;
72 char hflag;
73
81 // char _pad;
82};
83
84BLI_STATIC_ASSERT((sizeof(BMHeader) <= 16), "BMHeader size has grown!");
85
86/* NOTE: need some way to specify custom locations for custom data layers. so we can
87 * make them point directly into structs. and some way to make it only happen to the
88 * active layer, and properly update when switching active layers. */
89
90struct BMVert {
93 float co[3];
95 float no[3];
96
104 struct BMEdge *e;
105};
106
111
117 struct BMEdge *next, *prev;
118};
119
148
153
154struct BMLoop {
156 /* Notice no #BMFlagLayer, making this different from other elements. */
157
163 struct BMVert *v;
164
174 struct BMEdge *e;
181 struct BMFace *f;
182
215
243 struct BMLoop *next, *prev;
244};
245
250struct BMElemF {
252};
253
258struct BMElem {
260};
261
262#ifdef USE_BMESH_HOLES
267struct BMLoopList {
268 struct BMLoopList *next, *prev;
269 struct BMLoop *first, *last;
270};
271#endif
272
273struct BMFace {
275
276#ifdef USE_BMESH_HOLES
278 int totbounds;
279 ListBase loops;
280#else
282#endif
287 int len;
291 float no[3];
301 short mat_nr;
302 // short _pad[3];
303};
304
309
311 short f; /* flags */
312};
313
314// #pragma GCC diagnostic pop
315
316struct BMesh {
319
326
332
335
336 /* #BLI_mempool lookup tables (optional).
337 * Map indices to elements via #BM_mesh_elem_table_ensure and associated functions.
338 * Don't touch this or read it directly.
339 * Use #BM_mesh_elem_table_ensure(), `BM_vert/edge/face_at_index()`. */
340
347
348 /* Size of allocated tables. */
349
353
356
358
360
362
363#ifdef USE_BMESH_HOLES
364 struct BLI_mempool *looplistpool;
365#endif
366
369
377
380
383
393
396
407};
408
410enum {
415};
416
420 float niloc[3];
421 float nloc[3];
422 float *loc;
424};
425
437
438#define BM_ALL (BM_VERT | BM_EDGE | BM_LOOP | BM_FACE)
439#define BM_ALL_NOLOOP (BM_VERT | BM_EDGE | BM_FACE)
440
442enum {
446};
447
448/* args for _Generic */
449#define _BM_GENERIC_TYPE_ELEM_NONCONST \
450 void *, BMVert *, BMEdge *, BMLoop *, BMFace *, BMVert_OFlag *, BMEdge_OFlag *, BMFace_OFlag *, \
451 BMElem *, BMElemF *, BMHeader *
452
453#define _BM_GENERIC_TYPE_ELEM_CONST \
454 const void *, const BMVert *, const BMEdge *, const BMLoop *, const BMFace *, \
455 const BMVert_OFlag *, const BMEdge_OFlag *, const BMFace_OFlag *, const BMElem *, \
456 const BMElemF *, const BMHeader *
457
458#define BM_CHECK_TYPE_ELEM_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPES_CONST)
459
460#define BM_CHECK_TYPE_ELEM_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST)
461
462#define BM_CHECK_TYPE_ELEM(ele) \
463 CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST, _BM_GENERIC_TYPE_ELEM_CONST)
464
465/* vert */
466#define _BM_GENERIC_TYPE_VERT_NONCONST BMVert *, BMVert_OFlag *
467#define _BM_GENERIC_TYPE_VERT_CONST const BMVert *, const BMVert_OFlag *
468#define BM_CHECK_TYPE_VERT_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_VERT_CONST)
469#define BM_CHECK_TYPE_VERT_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST)
470#define BM_CHECK_TYPE_VERT(ele) \
471 CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_VERT_NONCONST, _BM_GENERIC_TYPE_VERT_CONST)
472/* edge */
473#define _BM_GENERIC_TYPE_EDGE_NONCONST BMEdge *, BMEdge_OFlag *
474#define _BM_GENERIC_TYPE_EDGE_CONST const BMEdge *, const BMEdge_OFlag *
475#define BM_CHECK_TYPE_EDGE_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_EDGE_CONST)
476#define BM_CHECK_TYPE_EDGE_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST)
477#define BM_CHECK_TYPE_EDGE(ele) \
478 CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_EDGE_NONCONST, _BM_GENERIC_TYPE_EDGE_CONST)
479/* face */
480#define _BM_GENERIC_TYPE_FACE_NONCONST BMFace *, BMFace_OFlag *
481#define _BM_GENERIC_TYPE_FACE_CONST const BMFace *, const BMFace_OFlag *
482#define BM_CHECK_TYPE_FACE_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_FACE_CONST)
483#define BM_CHECK_TYPE_FACE_NONCONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_ELEM_NONCONST)
484#define BM_CHECK_TYPE_FACE(ele) \
485 CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPE_FACE_NONCONST, _BM_GENERIC_TYPE_FACE_CONST)
486
491#define BM_CHECK_TYPE_ELEM_ASSIGN(ele) (BM_CHECK_TYPE_ELEM(ele)), *((void **)&ele)
492
494enum {
495 BM_ELEM_SELECT = (1 << 0),
496 BM_ELEM_HIDDEN = (1 << 1),
497 BM_ELEM_SEAM = (1 << 2),
499 BM_ELEM_SMOOTH = (1 << 3),
506 BM_ELEM_TAG = (1 << 4),
507
508 BM_ELEM_DRAW = (1 << 5), /* edge display */
509
511 BM_ELEM_TAG_ALT = (1 << 6),
512
519};
520
521struct BPy_BMGeneric;
522extern void bpy_bm_generic_invalidate(struct BPy_BMGeneric *self);
523
524using BMElemFilterFunc = bool (*)(const BMElem *, void *user_data);
525using BMVertFilterFunc = bool (*)(const BMVert *, void *user_data);
526using BMEdgeFilterFunc = bool (*)(const BMEdge *, void *user_data);
527using BMFaceFilterFunc = bool (*)(const BMFace *, void *user_data);
528using BMLoopFilterFunc = bool (*)(const BMLoop *, void *user_data);
529using BMLoopPairFilterFunc = bool (*)(const BMLoop *, const BMLoop *, void *user_data);
530
531/* defines */
532#define BM_ELEM_CD_SET_INT(ele, offset, f) \
533 { \
534 CHECK_TYPE_NONCONST(ele); \
535 BLI_assert(offset != -1); \
536 *((int *)((char *)(ele)->head.data + (offset))) = (f); \
537 } \
538 (void)0
539
540#define BM_ELEM_CD_GET_INT(ele, offset) \
541 (BLI_assert(offset != -1), *((int *)((char *)(ele)->head.data + (offset))))
542
543#define BM_ELEM_CD_SET_BOOL(ele, offset, f) \
544 { \
545 CHECK_TYPE_NONCONST(ele); \
546 BLI_assert(offset != -1); \
547 *((bool *)((char *)(ele)->head.data + (offset))) = (f); \
548 } \
549 (void)0
550
551#define BM_ELEM_CD_GET_BOOL(ele, offset) \
552 (BLI_assert(offset != -1), *((bool *)((char *)(ele)->head.data + (offset))))
553
554#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
555# define BM_ELEM_CD_GET_BOOL_P(ele, offset) \
556 (BLI_assert(offset != -1), \
557 _Generic(ele, \
558 GENERIC_TYPE_ANY((bool *)POINTER_OFFSET((ele)->head.data, offset), \
559 _BM_GENERIC_TYPE_ELEM_NONCONST), \
560 GENERIC_TYPE_ANY((const bool *)POINTER_OFFSET((ele)->head.data, offset), \
561 _BM_GENERIC_TYPE_ELEM_CONST)))
562#else
563# define BM_ELEM_CD_GET_BOOL_P(ele, offset) \
564 (BLI_assert(offset != -1), (bool *)((char *)(ele)->head.data + (offset)))
565#endif
566
567#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
568# define BM_ELEM_CD_GET_VOID_P(ele, offset) \
569 (BLI_assert(offset != -1), \
570 _Generic(ele, \
571 GENERIC_TYPE_ANY(POINTER_OFFSET((ele)->head.data, offset), _BM_GENERIC_TYPE_ELEM_NONCONST), \
572 GENERIC_TYPE_ANY((const void *)POINTER_OFFSET((ele)->head.data, offset), \
573 _BM_GENERIC_TYPE_ELEM_CONST)))
574#else
575# define BM_ELEM_CD_GET_VOID_P(ele, offset) \
576 (BLI_assert(offset != -1), (void *)((char *)(ele)->head.data + (offset)))
577#endif
578
579#define BM_ELEM_CD_SET_FLOAT(ele, offset, f) \
580 { \
581 CHECK_TYPE_NONCONST(ele); \
582 BLI_assert(offset != -1); \
583 *((float *)((char *)(ele)->head.data + (offset))) = (f); \
584 } \
585 (void)0
586
587#define BM_ELEM_CD_GET_FLOAT(ele, offset) \
588 (BLI_assert(offset != -1), *((float *)((char *)(ele)->head.data + (offset))))
589
590#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
591
592# define BM_ELEM_CD_GET_FLOAT_P(ele, offset) \
593 (BLI_assert(offset != -1), \
594 _Generic(ele, \
595 GENERIC_TYPE_ANY((float *)POINTER_OFFSET((ele)->head.data, offset), \
596 _BM_GENERIC_TYPE_ELEM_NONCONST), \
597 GENERIC_TYPE_ANY((const float *)POINTER_OFFSET((ele)->head.data, offset), \
598 _BM_GENERIC_TYPE_ELEM_CONST)))
599
600# define BM_ELEM_CD_GET_FLOAT2_P(ele, offset) \
601 (BLI_assert(offset != -1), \
602 _Generic(ele, \
603 GENERIC_TYPE_ANY((float(*)[2])POINTER_OFFSET((ele)->head.data, offset), \
604 _BM_GENERIC_TYPE_ELEM_NONCONST), \
605 GENERIC_TYPE_ANY((const float(*)[2])POINTER_OFFSET((ele)->head.data, offset), \
606 _BM_GENERIC_TYPE_ELEM_CONST)))
607
608# define BM_ELEM_CD_GET_FLOAT3_P(ele, offset) \
609 (BLI_assert(offset != -1), \
610 _Generic(ele, \
611 GENERIC_TYPE_ANY((float(*)[3])POINTER_OFFSET((ele)->head.data, offset), \
612 _BM_GENERIC_TYPE_ELEM_NONCONST), \
613 GENERIC_TYPE_ANY((const float(*)[3])POINTER_OFFSET((ele)->head.data, offset), \
614 _BM_GENERIC_TYPE_ELEM_CONST)))
615
616#else
617
618# define BM_ELEM_CD_GET_FLOAT_P(ele, offset) \
619 (BLI_assert(offset != -1), (float *)((char *)(ele)->head.data + (offset)))
620
621# define BM_ELEM_CD_GET_FLOAT2_P(ele, offset) \
622 (BLI_assert(offset != -1), (float(*)[2])((char *)(ele)->head.data + (offset)))
623
624# define BM_ELEM_CD_GET_FLOAT3_P(ele, offset) \
625 (BLI_assert(offset != -1), (float(*)[3])((char *)(ele)->head.data + (offset)))
626
627#endif
628
629#define BM_ELEM_CD_SET_FLOAT2(ele, offset, f) \
630 { \
631 CHECK_TYPE_NONCONST(ele); \
632 BLI_assert(offset != -1); \
633 ((float *)((char *)(ele)->head.data + (offset)))[0] = (f)[0]; \
634 ((float *)((char *)(ele)->head.data + (offset)))[1] = (f)[1]; \
635 } \
636 (void)0
637
638#define BM_ELEM_CD_SET_FLOAT3(ele, offset, f) \
639 { \
640 CHECK_TYPE_NONCONST(ele); \
641 BLI_assert(offset != -1); \
642 ((float *)((char *)(ele)->head.data + (offset)))[0] = (f)[0]; \
643 ((float *)((char *)(ele)->head.data + (offset)))[1] = (f)[1]; \
644 ((float *)((char *)(ele)->head.data + (offset)))[2] = (f)[2]; \
645 } \
646 (void)0
647
648#define BM_ELEM_CD_GET_FLOAT_AS_UCHAR(ele, offset) \
649 (BLI_assert(offset != -1), (uchar)(BM_ELEM_CD_GET_FLOAT(ele, offset) * 255.0f))
650
651/* Forward declarations. */
652
653#ifdef USE_BMESH_HOLES
654# define BM_FACE_FIRST_LOOP(p) (((BMLoopList *)((p)->loops.first))->first)
655#else
656# define BM_FACE_FIRST_LOOP(p) ((p)->l_first)
657#endif
658
659#define BM_DISK_EDGE_NEXT(e, v) \
660 (CHECK_TYPE_INLINE(e, BMEdge *), \
661 CHECK_TYPE_INLINE(v, BMVert *), \
662 BLI_assert(BM_vert_in_edge(e, v)), \
663 (((&e->v1_disk_link)[v == e->v2]).next))
664#define BM_DISK_EDGE_PREV(e, v) \
665 (CHECK_TYPE_INLINE(e, BMEdge *), \
666 CHECK_TYPE_INLINE(v, BMVert *), \
667 BLI_assert(BM_vert_in_edge(e, v)), \
668 (((&e->v1_disk_link)[v == e->v2]).prev))
669
674#define BM_DEFAULT_NGON_STACK_SIZE 32
680#define BM_DEFAULT_ITER_STACK_SIZE 16
681
683#define BM_LOOP_RADIAL_MAX 10000
684#define BM_NGON_MAX 100000
685
687#define BM_THREAD_LIMIT 10000
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:83
unsigned int uint
These structs are the foundation for all linked lists in the library system.
bool(*)(const BMEdge *, void *user_data) BMEdgeFilterFunc
bool(*)(const BMFace *, void *user_data) BMFaceFilterFunc
@ BM_ELEM_HIDDEN
@ BM_ELEM_SEAM
@ BM_ELEM_SELECT
@ BM_ELEM_SMOOTH
@ BM_ELEM_INTERNAL_TAG
@ BM_ELEM_TAG
@ BM_ELEM_DRAW
@ BM_ELEM_TAG_ALT
bool(*)(const BMLoop *, void *user_data) BMLoopFilterFunc
@ BM_SPACEARR_BMO_SET
@ BM_SPACEARR_DIRTY_ALL
@ BM_SPACEARR_DIRTY
@ BM_LOOP
bool(*)(const BMElem *, void *user_data) BMElemFilterFunc
void bpy_bm_generic_invalidate(struct BPy_BMGeneric *self)
bool(*)(const BMVert *, void *user_data) BMVertFilterFunc
bool(*)(const BMLoop *, const BMLoop *, void *user_data) BMLoopPairFilterFunc
#define BM_FACE
#define BM_EDGE
#define BM_VERT
PyObject * self
static ulong * next
struct BMFlagLayer * oflags
BMHeader head
BMVert * v1
BMDiskLink v2_disk_link
BMDiskLink v1_disk_link
BMVert * v2
struct BMLoop * l
BMHeader head
BMHeader head
struct BMFlagLayer * oflags
short mat_nr
BMHeader head
float no[3]
BMLoop * l_first
void * data
char api_flag
BMLoopNorEditData ** lidx_to_lnor_editdata
BMLoopNorEditData * lnor_editdata
BMHeader head
struct BMVert * v
struct BMEdge * e
struct BMLoop * radial_prev
struct BMLoop * radial_next
struct BMLoop * prev
struct BMFace * f
struct BMLoop * next
struct BMFlagLayer * oflags
float co[3]
struct BMEdge * e
float no[3]
BMHeader head
int totvert
BMEdge ** etable
struct BLI_mempool * epool
int totflags
int totfacesel
struct MLoopNorSpaceArray * lnor_spacearr
int shapenr
char elem_index_dirty
CustomData vdata
int totedge
char elem_table_dirty
struct BLI_mempool * vtoolflagpool
ListBase selected
CustomData edata
uint use_toolflags
int totvertsel
int totloop
int ftable_tot
void * py_handle
struct BLI_mempool * etoolflagpool
BMFace * act_face
short selectmode
BMVert ** vtable
struct BLI_mempool * ftoolflagpool
int totedgesel
char spacearr_dirty
CustomData pdata
CustomData ldata
int vtable_tot
BMFace ** ftable
int totface
int toolflag_index
int etable_tot
struct BLI_mempool * fpool
struct BLI_mempool * vpool
struct BLI_mempool * lpool
ListBase errorstack