2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Geoffrey Bantle, Levi Schooley, Joseph Eagar.
20 * ***** END GPL LICENSE BLOCK *****
23 #ifndef __BMESH_CLASS_H__
24 #define __BMESH_CLASS_H__
26 /** \file blender/bmesh/bmesh_class.h
30 /* bmesh data structures */
32 /* dissable holes for now, these are ifdef'd because they use more memory and cant be saved in DNA currently */
33 // #define USE_BMESH_HOLES
44 /* note: it is very important for BMHeader to start with two
45 * pointers. this is a requirement of mempool's method of
48 * hrm. it doesn't but stull works ok, remove the comment above? - campbell.
54 * All mesh elements begin with a BMHeader. This structure
55 * hold several types of data
57 * 1: The type of the element (vert, edge, loop or face)
58 * 2: Persistent "header" flags/markings (smooth, seam, select, hidden, etc)
59 * note that this is different from the "tool" flags.
60 * 3: Unique ID in the bmesh.
61 * 4: some elements for internal record keeping.
63 typedef struct BMHeader {
64 void *data; /* customdata layers */
66 * - Use BM_elem_index_get/set macros for index
67 * - Unitialized to -1 so we can easily tell its not set.
68 * - Used for edge/vert/face, check BMesh.elem_index_dirty for valid index values,
69 * this is abused by various tools which set it dirty.
70 * - For loops this is used for sorting during tessellation. */
72 char htype; /* element geometric type (verts/edges/loops/faces) */
73 char hflag; /* this would be a CD layer, see below */
76 /* note: need some way to specify custom locations for custom data layers. so we can
77 * make them point directly into structs. and some way to make it only happen to the
78 * active layer, and properly update when switching active layers.*/
80 typedef struct BMVert {
82 struct BMFlagLayer *oflags; /* keep after header, an array of flags, mostly used by the operator stack */
89 /* disk link structure, only used by edges */
90 typedef struct BMDiskLink {
91 struct BMEdge *next, *prev;
94 typedef struct BMEdge {
96 struct BMFlagLayer *oflags; /* keep after header, an array of flags, mostly used by the operator stack */
98 struct BMVert *v1, *v2;
101 /* disk cycle pointers */
102 BMDiskLink v1_disk_link, v2_disk_link;
105 typedef struct BMLoop {
107 /* notice no flags layer */
110 struct BMEdge *e; /* edge, using verts (v, next->v) */
113 /* circular linked list of loops which all use the same edge as this one '->e',
114 * but not necessarily the same vertex (can be either v1 or v2 of our own '->e') */
115 struct BMLoop *radial_next, *radial_prev;
117 /* these were originally commented as private but are used all over the code */
118 /* can't use ListBase API, due to head */
119 struct BMLoop *next, *prev; /* next/prev verts around the face */
122 /* can cast BMFace/BMEdge/BMVert, but NOT BMLoop, since these don't have a flag layer */
123 typedef struct BMElemF {
125 struct BMFlagLayer *oflags; /* keep after header, an array of flags, mostly used by the operator stack */
128 /* can cast anything to this, including BMLoop */
129 typedef struct BMElem {
133 #ifdef USE_BMESH_HOLES
134 /* eventually, this structure will be used for supporting holes in faces */
135 typedef struct BMLoopList {
136 struct BMLoopList *next, *prev;
137 struct BMLoop *first, *last;
141 typedef struct BMFace {
143 struct BMFlagLayer *oflags; /* an array of flags, mostly used by the operator stack */
145 int len; /*includes all boundary loops*/
146 #ifdef USE_BMESH_HOLES
147 int totbounds; /*total boundaries, is one plus the number of holes in the face*/
152 float no[3]; /*yes, we do store this here*/
156 typedef struct BMFlagLayer {
157 short f, pflag; /* flags */
160 typedef struct BMesh {
161 int totvert, totedge, totloop, totface;
162 int totvertsel, totedgesel, totfacesel;
164 /* flag index arrays as being dirty so we can check if they are clean and
165 * avoid looping over the entire vert/edge/face array in those cases.
166 * valid flags are - BM_VERT | BM_EDGE | BM_FACE.
167 * BM_LOOP isn't handled so far. */
168 char elem_index_dirty;
171 struct BLI_mempool *vpool, *epool, *lpool, *fpool;
173 /*operator api stuff*/
174 struct BLI_mempool *toolflagpool;
176 struct BMOperator *currentop;
178 CustomData vdata, edata, ldata, pdata;
180 #ifdef USE_BMESH_HOLES
181 struct BLI_mempool *looplistpool;
184 /* should be copy of scene select mode */
185 /* stored in BMEditMesh too, this is a bit confusing,
186 * make sure they're in sync!
187 * Only use when the edit mesh cant be accessed - campbell */
190 /*ID of the shape key this bmesh came from*/
193 int walkers, totflags;
194 ListBase selected, error_stack;
203 /* BMHeader->htype (char) */
211 #define BM_ALL (BM_VERT | BM_EDGE | BM_LOOP | BM_FACE)
213 /* BMHeader->hflag (char) */
215 BM_ELEM_SELECT = (1 << 0),
216 BM_ELEM_HIDDEN = (1 << 1),
217 BM_ELEM_SEAM = (1 << 2),
218 BM_ELEM_SMOOTH = (1 << 3), /* used for faces and edges, note from the user POV,
219 * this is a sharp edge when disabled */
221 BM_ELEM_TAG = (1 << 4), /* internal flag, used for ensuring correct normals
222 * during multires interpolation, and any other time
223 * when temp tagging is handy.
224 * always assume dirty & clear before use. */
226 BM_ELEM_DRAW = (1 << 5), /* edge display */
228 /* spare tag, assumed dirty, use define in each function to name based on use */
229 // _BM_ELEM_TAG_ALT = (1 << 6), // UNUSED
230 BM_ELEM_FREESTYLE = (1 << 6), /* used for Freestyle faces and edges */
232 BM_ELEM_INTERNAL_TAG = (1 << 7) /* for low level internal API tagging,
233 * since tools may want to tag verts and
234 * not have functions clobber them */
239 /*forward declarations*/
241 #ifdef USE_BMESH_HOLES
242 # define BM_FACE_FIRST_LOOP(p) (((BMLoopList *)((p)->loops.first))->first)
244 # define BM_FACE_FIRST_LOOP(p) ((p)->l_first)
248 * size to use for stack arrays when dealing with NGons,
249 * alloc after this limit is reached.
250 * this value is rather arbitrary */
251 #define BM_DEFAULT_NGON_STACK_SIZE 32
253 * size to use for stack arrays dealing with connected mesh data
254 * verts of faces, edges of vert - etc.
255 * often used with #BM_iter_as_arrayN() */
256 #define BM_DEFAULT_ITER_STACK_SIZE 16
258 /* avoid inf loop, this value is arbitrary
259 * but should not error on valid cases */
260 #define BM_LOOP_RADIAL_MAX 10000
261 #define BM_NGON_MAX 100000
263 #endif /* __BMESH_CLASS_H__ */