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) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup DNA
22  */
23 
24 #pragma once
25 
26 #include "DNA_ID.h"
27 #include "DNA_customdata_types.h"
28 #include "DNA_defs.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct AnimData;
35 struct BVHCache;
36 struct Ipo;
37 struct Key;
38 struct LinkNode;
39 struct MCol;
40 struct MEdge;
41 struct MFace;
42 struct MLoop;
43 struct MLoopCol;
44 struct MLoopTri;
45 struct MLoopUV;
46 struct MPoly;
47 struct MPropCol;
48 struct MVert;
49 struct Material;
50 struct Mesh;
51 struct Multires;
52 struct SubdivCCG;
53 
54 #
55 #
56 typedef struct EditMeshData {
57   /** when set, \a vertexNos, polyNos are lazy initialized */
58   const float (*vertexCos)[3];
59 
60   /** lazy initialize (when \a vertexCos is set) */
61   float const (*vertexNos)[3];
62   float const (*polyNos)[3];
63   /** also lazy init but dont depend on \a vertexCos */
64   const float (*polyCos)[3];
65 } EditMeshData;
66 
67 /**
68  * \warning Typical access is done via
69  * #BKE_mesh_runtime_looptri_ensure, #BKE_mesh_runtime_looptri_len.
70  */
71 struct MLoopTri_Store {
72   /* WARNING! swapping between array (ready-to-be-used data) and array_wip
73    * (where data is actually computed)
74    * shall always be protected by same lock as one used for looptris computing. */
75   struct MLoopTri *array, *array_wip;
76   int len;
77   int len_alloc;
78 };
79 
80 /* not saved in file! */
81 typedef struct Mesh_Runtime {
82   /* Evaluated mesh for objects which do not have effective modifiers.
83    * This mesh is used as a result of modifier stack evaluation.
84    * Since modifier stack evaluation is threaded on object level we need some synchronization. */
85   struct Mesh *mesh_eval;
86   void *eval_mutex;
87 
88   struct EditMeshData *edit_data;
89   void *batch_cache;
90 
91   struct SubdivCCG *subdiv_ccg;
92   void *_pad1;
93   int subdiv_ccg_tot_level;
94   char _pad2[4];
95 
96   int64_t cd_dirty_vert;
97   int64_t cd_dirty_edge;
98   int64_t cd_dirty_loop;
99   int64_t cd_dirty_poly;
100 
101   struct MLoopTri_Store looptris;
102 
103   /** `BVHCache` defined in 'BKE_bvhutil.c' */
104   struct BVHCache *bvh_cache;
105 
106   /** Non-manifold boundary data for Shrinkwrap Target Project. */
107   struct ShrinkwrapBoundaryData *shrinkwrap_data;
108 
109   /** Set by modifier stack if only deformed from original. */
110   char deformed_only;
111   /**
112    * Copied from edit-mesh (hint, draw with edit-mesh data when true).
113    *
114    * Modifiers that edit the mesh data in-place must set this to false
115    * (most #eModifierTypeType_NonGeometrical modifiers). Otherwise the edit-mesh
116    * data will be used for drawing, missing changes from modifiers. See T79517.
117    */
118   char is_original;
119 
120   /** #eMeshWrapperType and others. */
121   char wrapper_type;
122   /**
123    * A type mask from wrapper_type,
124    * in case there are differences in finalizing logic between types.
125    */
126   char wrapper_type_finalize;
127 
128   char _pad[4];
129 
130   /** Needed in case we need to lazily initialize the mesh. */
131   CustomData_MeshMasks cd_mask_extra;
132 
133 } Mesh_Runtime;
134 
135 typedef struct Mesh {
136   ID id;
137   /** Animation data (must be immediately after id for utilities to use it). */
138   struct AnimData *adt;
139 
140   /** Old animation system, deprecated for 2.5. */
141   struct Ipo *ipo DNA_DEPRECATED;
142   struct Key *key;
143   struct Material **mat;
144   struct MSelect *mselect;
145 
146   /* BMESH ONLY */
147   /*new face structures*/
148   struct MPoly *mpoly;
149   struct MLoop *mloop;
150   struct MLoopUV *mloopuv;
151   struct MLoopCol *mloopcol;
152   /* END BMESH ONLY */
153 
154   /**
155    * Legacy face storage (quads & tries only),
156    * faces are now stored in #Mesh.mpoly & #Mesh.mloop arrays.
157    *
158    * \note This would be marked deprecated however the particles still use this at run-time
159    * for placing particles on the mesh (something which should be eventually upgraded).
160    */
161   struct MFace *mface;
162   /** Store tessellation face UV's and texture here. */
163   struct MTFace *mtface;
164   /** Deprecated, use mtface. */
165   struct TFace *tface DNA_DEPRECATED;
166   /** Array of verts. */
167   struct MVert *mvert;
168   /** Array of edges. */
169   struct MEdge *medge;
170   /** Deformgroup vertices. */
171   struct MDeformVert *dvert;
172 
173   /* array of colors for the tessellated faces, must be number of tessellated
174    * faces * 4 in length */
175   struct MCol *mcol;
176   struct Mesh *texcomesh;
177 
178   /* When the object is available, the preferred access method is: BKE_editmesh_from_object(ob) */
179   /** Not saved in file!. */
180   struct BMEditMesh *edit_mesh;
181 
182   struct CustomData vdata, edata, fdata;
183 
184   /* BMESH ONLY */
185   struct CustomData pdata, ldata;
186   /* END BMESH ONLY */
187 
188   int totvert, totedge, totface, totselect;
189 
190   /* BMESH ONLY */
191   int totpoly, totloop;
192   /* END BMESH ONLY */
193 
194   int attributes_active_index;
195   int _pad3;
196 
197   /* the last selected vertex/edge/face are used for the active face however
198    * this means the active face must always be selected, this is to keep track
199    * of the last selected face and is similar to the old active face flag where
200    * the face does not need to be selected, -1 is inactive */
201   int act_face;
202 
203   /* texture space, copied as one block in editobject.c */
204   float loc[3];
205   float size[3];
206 
207   short texflag, flag;
208   float smoothresh;
209 
210   /* customdata flag, for bevel-weight and crease, which are now optional */
211   char cd_flag, _pad;
212 
213   char subdiv DNA_DEPRECATED, subdivr DNA_DEPRECATED;
214   /** Only kept for backwards compat, not used anymore. */
215   char subsurftype DNA_DEPRECATED;
216   char editflag;
217 
218   short totcol;
219 
220   float remesh_voxel_size;
221   float remesh_voxel_adaptivity;
222   char remesh_mode;
223 
224   char symmetry;
225 
226   char _pad1[2];
227 
228   int face_sets_color_seed;
229   /* Stores the initial Face Set to be rendered white. This way the overlay can be enabled by
230    * default and Face Sets can be used without affecting the color of the mesh. */
231   int face_sets_color_default;
232 
233   /** Deprecated multiresolution modeling data, only keep for loading old files. */
234   struct Multires *mr DNA_DEPRECATED;
235 
236   Mesh_Runtime runtime;
237 } Mesh;
238 
239 /* deprecated by MTFace, only here for file reading */
240 #ifdef DNA_DEPRECATED_ALLOW
241 typedef struct TFace {
242   /** The faces image for the active UVLayer. */
243   void *tpage;
244   float uv[4][2];
245   unsigned int col[4];
246   char flag, transp;
247   short mode, tile, unwrap;
248 } TFace;
249 #endif
250 
251 /* **************** MESH ********************* */
252 
253 /** #Mesh_Runtime.wrapper_type */
254 typedef enum eMeshWrapperType {
255   /** Use mesh data (#Mesh.mvert, #Mesh.medge, #Mesh.mloop, #Mesh.mpoly). */
256   ME_WRAPPER_TYPE_MDATA = 0,
257   /** Use edit-mesh data (#Mesh.edit_mesh, #Mesh_Runtime.edit_data). */
258   ME_WRAPPER_TYPE_BMESH = 1,
259   /* ME_WRAPPER_TYPE_SUBD = 2, */ /* TODO */
260 } eMeshWrapperType;
261 
262 /* texflag */
263 enum {
264   ME_AUTOSPACE = 1,
265   ME_AUTOSPACE_EVALUATED = 2,
266 };
267 
268 /* me->editflag */
269 enum {
270   ME_EDIT_VERTEX_GROUPS_X_SYMMETRY = 1 << 0,
271   ME_EDIT_MIRROR_Y = 1 << 1, /* unused so far */
272   ME_EDIT_MIRROR_Z = 1 << 2, /* unused so far */
273 
274   ME_EDIT_PAINT_FACE_SEL = 1 << 3,
275   ME_EDIT_MIRROR_TOPO = 1 << 4,
276   ME_EDIT_PAINT_VERT_SEL = 1 << 5,
277 };
278 
279 /* we cant have both flags enabled at once,
280  * flags defined in DNA_scene_types.h */
281 #define ME_EDIT_PAINT_SEL_MODE(_me) \
282   (((_me)->editflag & ME_EDIT_PAINT_FACE_SEL) ? \
283        SCE_SELECT_FACE : \
284        ((_me)->editflag & ME_EDIT_PAINT_VERT_SEL) ? SCE_SELECT_VERTEX : 0)
285 
286 /* me->flag */
287 enum {
288   ME_FLAG_UNUSED_0 = 1 << 0,     /* cleared */
289   ME_FLAG_UNUSED_1 = 1 << 1,     /* cleared */
290   ME_FLAG_DEPRECATED_2 = 1 << 2, /* deprecated */
291   ME_FLAG_UNUSED_3 = 1 << 3,     /* cleared */
292   ME_FLAG_UNUSED_4 = 1 << 4,     /* cleared */
293   ME_AUTOSMOOTH = 1 << 5,
294   ME_FLAG_UNUSED_6 = 1 << 6, /* cleared */
295   ME_FLAG_UNUSED_7 = 1 << 7, /* cleared */
296   ME_REMESH_REPROJECT_VERTEX_COLORS = 1 << 8,
297   ME_DS_EXPAND = 1 << 9,
298   ME_SCULPT_DYNAMIC_TOPOLOGY = 1 << 10,
299   ME_REMESH_SMOOTH_NORMALS = 1 << 11,
300   ME_REMESH_REPROJECT_PAINT_MASK = 1 << 12,
301   ME_REMESH_FIX_POLES = 1 << 13,
302   ME_REMESH_REPROJECT_VOLUME = 1 << 14,
303   ME_REMESH_REPROJECT_SCULPT_FACE_SETS = 1 << 15,
304 };
305 
306 /* me->cd_flag */
307 enum {
308   ME_CDFLAG_VERT_BWEIGHT = 1 << 0,
309   ME_CDFLAG_EDGE_BWEIGHT = 1 << 1,
310   ME_CDFLAG_EDGE_CREASE = 1 << 2,
311 };
312 
313 /* me->remesh_mode */
314 enum {
315   REMESH_VOXEL = 0,
316   REMESH_QUAD = 1,
317 };
318 
319 /* Subsurf Type */
320 enum {
321   ME_CC_SUBSURF = 0,
322   ME_SIMPLE_SUBSURF = 1,
323 };
324 
325 /* me->symmetry */
326 typedef enum eMeshSymmetryType {
327   ME_SYMMETRY_X = 1 << 0,
328   ME_SYMMETRY_Y = 1 << 1,
329   ME_SYMMETRY_Z = 1 << 2,
330 } eMeshSymmetryType;
331 
332 #define MESH_MAX_VERTS 2000000000L
333 
334 #ifdef __cplusplus
335 }
336 #endif
337