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 #pragma once
20 
21 /** \file
22  * \ingroup bke
23  */
24 
25 /* struct DerivedMesh is used directly */
26 #include "BKE_DerivedMesh.h"
27 
28 /* Thread sync primitives used directly.  */
29 #include "BLI_threads.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 struct CCGEdge;
36 struct CCGElem;
37 struct CCGFace;
38 struct CCGVert;
39 struct DMFlagMat;
40 struct DerivedMesh;
41 struct EdgeHash;
42 struct MPoly;
43 struct Mesh;
44 struct MeshElemMap;
45 struct Object;
46 struct PBVH;
47 struct SubsurfModifierData;
48 
49 /**************************** External *****************************/
50 
51 typedef enum {
52   SUBSURF_USE_RENDER_PARAMS = 1,
53   SUBSURF_IS_FINAL_CALC = 2,
54   SUBSURF_FOR_EDIT_MODE = 4,
55   SUBSURF_IN_EDIT_MODE = 8,
56   SUBSURF_ALLOC_PAINT_MASK = 16,
57   SUBSURF_USE_GPU_BACKEND = 32,
58   SUBSURF_IGNORE_SIMPLIFY = 64,
59 } SubsurfFlags;
60 
61 struct DerivedMesh *subsurf_make_derived_from_derived(struct DerivedMesh *dm,
62                                                       struct SubsurfModifierData *smd,
63                                                       const struct Scene *scene,
64                                                       float (*vertCos)[3],
65                                                       SubsurfFlags flags);
66 
67 void subsurf_calculate_limit_positions(struct Mesh *me, float (*r_positions)[3]);
68 
69 /* get gridsize from 'level', level must be greater than zero */
70 int BKE_ccg_gridsize(int level);
71 
72 /* x/y grid coordinates at 'low_level' can be multiplied by the result
73  * of this function to convert to grid coordinates at 'high_level' */
74 int BKE_ccg_factor(int low_level, int high_level);
75 
76 void subsurf_copy_grid_hidden(struct DerivedMesh *dm,
77                               const struct MPoly *mpoly,
78                               struct MVert *mvert,
79                               const struct MDisps *mdisps);
80 
81 void subsurf_copy_grid_paint_mask(struct DerivedMesh *dm,
82                                   const struct MPoly *mpoly,
83                                   float *paint_mask,
84                                   const struct GridPaintMask *grid_paint_mask);
85 
86 bool subsurf_has_edges(struct DerivedMesh *dm);
87 bool subsurf_has_faces(struct DerivedMesh *dm);
88 
89 typedef enum MultiresModifiedFlags {
90   /* indicates the grids have been sculpted on, so MDisps
91    * have to be updated */
92   MULTIRES_COORDS_MODIFIED = 1,
93   /* indicates elements have been hidden or unhidden */
94   MULTIRES_HIDDEN_MODIFIED = 2,
95 } MultiresModifiedFlags;
96 
97 /**************************** Internal *****************************/
98 
99 typedef struct CCGDerivedMesh {
100   DerivedMesh dm;
101 
102   struct CCGSubSurf *ss;
103   int freeSS;
104   int drawInteriorEdges, useSubsurfUv;
105 
106   struct {
107     int startVert;
108     struct CCGVert *vert;
109   } * vertMap;
110   struct {
111     int startVert;
112     int startEdge;
113     struct CCGEdge *edge;
114   } * edgeMap;
115   struct {
116     int startVert;
117     int startEdge;
118     int startFace;
119     struct CCGFace *face;
120   } * faceMap;
121 
122   short *edgeFlags;
123   struct DMFlagMat *faceFlags;
124 
125   int *reverseFaceMap;
126 
127   struct PBVH *pbvh;
128 
129   struct MeshElemMap *pmap;
130   int *pmap_mem;
131 
132   struct CCGElem **gridData;
133   int *gridOffset;
134   struct CCGFace **gridFaces;
135   struct DMFlagMat *gridFlagMats;
136   unsigned int **gridHidden;
137   /* Elements in arrays above. */
138   unsigned int numGrid;
139 
140   struct {
141     struct MultiresModifierData *mmd;
142     int local_mmd;
143 
144     int lvl, totlvl;
145     float (*orco)[3];
146 
147     struct Object *ob;
148     MultiresModifiedFlags modified_flags;
149   } multires;
150 
151   struct EdgeHash *ehash;
152 
153   ThreadMutex loops_cache_lock;
154   ThreadRWMutex origindex_cache_rwlock;
155 } CCGDerivedMesh;
156 
157 #ifdef __cplusplus
158 }
159 #endif
160