Blender  V2.93
CCGSubSurf_intern.h
Go to the documentation of this file.
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 
21 #pragma once
22 
27 /* Define this to see dump of the grids after the subsurf applied. */
28 #undef DUMP_RESULT_GRIDS
29 
30 /* used for normalize_v3 in BLI_math_vector
31  * float.h's FLT_EPSILON causes trouble with subsurf normals - campbell */
32 #define EPSILON (1.0e-35f)
33 
34 /* With this limit a single triangle becomes over 3 million faces */
35 #define CCGSUBSURF_LEVEL_MAX 11
36 
41 typedef unsigned char byte;
42 
47 typedef struct _EHEntry {
48  struct _EHEntry *next;
49  void *key;
51 
52 typedef struct _EHash {
55 
59 
60 typedef void (*EHEntryFreeFP)(EHEntry *, void *);
61 
62 #define EHASH_alloc(eh, nb) ((eh)->allocatorIFC.alloc((eh)->allocator, nb))
63 #define EHASH_free(eh, ptr) ((eh)->allocatorIFC.free((eh)->allocator, ptr))
64 #define EHASH_hash(eh, item) (((uintptr_t)(item)) % ((unsigned int)(eh)->curSize))
65 
66 /* Generic hash functions. */
67 
68 EHash *ccg_ehash_new(int estimatedNumEntries,
69  CCGAllocatorIFC *allocatorIFC,
70  CCGAllocatorHDL allocator);
71 void ccg_ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *userData);
72 void ccg_ehash_insert(EHash *eh, EHEntry *entry);
73 void *ccg_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r);
74 void *ccg_ehash_lookup(EHash *eh, void *key);
75 
76 /* Hash elements iteration. */
77 
82 
88 
93 /* TODO(sergey): Get rid of this, it's more or less a bad level call. */
94 struct DerivedMesh;
95 
96 /* ** Data structures, constants. enums ** */
97 
98 enum {
99  Vert_eEffected = (1 << 0),
100  Vert_eChanged = (1 << 1),
101  Vert_eSeam = (1 << 2),
102 } /*VertFlags*/;
103 
104 enum {
105  Edge_eEffected = (1 << 0),
106 } /*CCGEdgeFlags*/;
107 
108 enum {
109  Face_eEffected = (1 << 0),
110 } /*FaceFlags*/;
111 
112 struct CCGVert {
113  CCGVert *next; /* EHData.next */
114  CCGVertHDL vHDL; /* EHData.key */
115 
117  int osd_index; /* Index of the vertex in the map, used by OSD. */
118 
121  /* byte *levelData; */
122  /* byte *userData; */
123 };
124 
125 struct CCGEdge {
126  CCGEdge *next; /* EHData.next */
127  CCGEdgeHDL eHDL; /* EHData.key */
128 
129  short numFaces, flags;
130  float crease;
131 
134 
135  /* byte *levelData; */
136  /* byte *userData; */
137 };
138 
139 struct CCGFace {
140  CCGFace *next; /* EHData.next */
141  CCGFaceHDL fHDL; /* EHData.key */
142 
143  short numVerts, flags;
145 
146  /* CCGVert **verts; */
147  /* CCGEdge **edges; */
148  /* byte *centerData; */
149  /* byte **gridData; */
150  /* byte *userData; */
151 };
152 
153 typedef enum {
159 } SyncState;
160 
161 struct CCGSubSurf {
162  EHash *vMap; /* map of CCGVertHDL -> Vert */
163  EHash *eMap; /* map of CCGEdgeHDL -> Edge */
164  EHash *fMap; /* map of CCGFaceHDL -> Face */
165 
167 
170 
172  int numGrids;
176 
177  void *q, *r;
178 
179  /* Data for calc vert normals. */
182 
183  /* Data for paint masks. */
186 
187  /* Data for age'ing (to debug sync). */
193 
194  /* Data used during syncing. */
196 
201 };
202 
203 /* ** Utility macros ** */
204 
205 #define CCGSUBSURF_alloc(ss, nb) ((ss)->allocatorIFC.alloc((ss)->allocator, nb))
206 #define CCGSUBSURF_realloc(ss, ptr, nb, ob) \
207  ((ss)->allocatorIFC.realloc((ss)->allocator, ptr, nb, ob))
208 #define CCGSUBSURF_free(ss, ptr) ((ss)->allocatorIFC.free((ss)->allocator, ptr))
209 
210 #define VERT_getCo(v, lvl) ccg_vert_getCo(v, lvl, vertDataSize)
211 #define VERT_getNo(v, lvl) ccg_vert_getNo(v, lvl, vertDataSize, normalDataOffset)
212 #define EDGE_getCo(e, lvl, x) ccg_edge_getCo(e, lvl, x, vertDataSize)
213 #define EDGE_getNo(e, lvl, x) ccg_edge_getNo(e, lvl, x, vertDataSize, normalDataOffset)
214 #define FACE_getIFNo(f, lvl, S, x, y) \
215  ccg_face_getIFNo(f, lvl, S, x, y, subdivLevels, vertDataSize, normalDataOffset)
216 #if 0
217 # define FACE_calcIFNo(f, lvl, S, x, y, no) \
218  _face_calcIFNo(f, lvl, S, x, y, no, subdivLevels, vertDataSize)
219 #endif
220 #define FACE_getIENo(f, lvl, S, x) \
221  ccg_face_getIENo(f, lvl, S, x, subdivLevels, vertDataSize, normalDataOffset)
222 #define FACE_getIECo(f, lvl, S, x) ccg_face_getIECo(f, lvl, S, x, subdivLevels, vertDataSize)
223 #define FACE_getIFCo(f, lvl, S, x, y) ccg_face_getIFCo(f, lvl, S, x, y, subdivLevels, vertDataSize)
224 
225 #define NormZero(av) \
226  { \
227  float *_a = (float *)av; \
228  _a[0] = _a[1] = _a[2] = 0.0f; \
229  } \
230  (void)0
231 #define NormCopy(av, bv) \
232  { \
233  float *_a = (float *)av, *_b = (float *)bv; \
234  _a[0] = _b[0]; \
235  _a[1] = _b[1]; \
236  _a[2] = _b[2]; \
237  } \
238  (void)0
239 #define NormAdd(av, bv) \
240  { \
241  float *_a = (float *)av, *_b = (float *)bv; \
242  _a[0] += _b[0]; \
243  _a[1] += _b[1]; \
244  _a[2] += _b[2]; \
245  } \
246  (void)0
247 
248 /* ** General purpose functions ** */
249 
250 /* * CCGSubSurf.c * */
251 
252 void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces);
254  CCGFace **faces,
255  int numFaces,
256  CCGVert ***verts,
257  int *numVerts,
258  CCGEdge ***edges,
259  int *numEdges);
260 
261 /* * CCGSubSurf_legacy.c * */
262 
264 
265 /* * CCGSubSurf_opensubdiv.c * */
266 
268 
269 /* * CCGSubSurf_opensubdiv_converter.c * */
270 
271 struct OpenSubdiv_Converter;
272 
274  struct DerivedMesh *dm,
275  struct OpenSubdiv_Converter *converter);
276 
278 
280 
281 /* * CCGSubSurf_util.c * */
282 
283 #ifdef DUMP_RESULT_GRIDS
284 void ccgSubSurf__dumpCoords(CCGSubSurf *ss);
285 #endif
286 
287 #include "CCGSubSurf_inline.h"
void * CCGFaceHDL
Definition: CCGSubSurf.h:26
void * CCGEdgeHDL
Definition: CCGSubSurf.h:25
void * CCGVertHDL
Definition: CCGSubSurf.h:24
void * CCGAllocatorHDL
Definition: CCGSubSurf.h:42
void * ccg_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r)
unsigned char byte
void ccgSubSurf_converter_setup_from_ccg(CCGSubSurf *ss, struct OpenSubdiv_Converter *converter)
void ccgSubSurf__effectedFaceNeighbors(CCGSubSurf *ss, CCGFace **faces, int numFaces, CCGVert ***verts, int *numVerts, CCGEdge ***edges, int *numEdges)
Definition: CCGSubSurf.c:881
void ccgSubSurf__sync_opensubdiv(CCGSubSurf *ss)
struct _EHash EHash
void ccg_ehashIterator_init(EHash *eh, EHashIterator *ehi)
void ccg_ehashIterator_next(EHashIterator *ehi)
void * ccg_ehash_lookup(EHash *eh, void *key)
void ccg_ehash_insert(EHash *eh, EHEntry *entry)
void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces)
Definition: CCGSubSurf.c:856
EHash * ccg_ehash_new(int estimatedNumEntries, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator)
@ Face_eEffected
void ccg_ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *userData)
@ Vert_eChanged
@ Vert_eEffected
@ Vert_eSeam
void * ccg_ehashIterator_getCurrent(EHashIterator *ehi)
int ccg_ehashIterator_isStopped(EHashIterator *ehi)
CCGAllocatorIFC * ccg_getStandardAllocatorIFC(void)
struct _EHEntry EHEntry
@ Edge_eEffected
@ eSyncState_Edge
@ eSyncState_Vert
@ eSyncState_Face
@ eSyncState_None
@ eSyncState_Partial
void ccgSubSurf_converter_setup_from_derivedmesh(CCGSubSurf *ss, struct DerivedMesh *dm, struct OpenSubdiv_Converter *converter)
void(* EHEntryFreeFP)(EHEntry *, void *)
void ccgSubSurf_converter_free(struct OpenSubdiv_Converter *converter)
void ccgSubSurf__sync_legacy(CCGSubSurf *ss)
static float verts[][3]
static char faces[256]
CCGVert * v1
CCGFace ** faces
CCGVert * v0
CCGEdge * next
CCGEdgeHDL eHDL
CCGFace * next
CCGFaceHDL fHDL
CCGAllocatorIFC allocatorIFC
void * defaultEdgeUserData
SyncState syncState
CCGMeshIFC meshIFC
CCGEdge ** tempEdges
CCGAllocatorHDL allocator
CCGVert ** tempVerts
float defaultCreaseValue
CCGVertHDL vHDL
CCGFace ** faces
CCGEdge ** edges
CCGVert * next
struct _EHEntry * next
EHEntry ** buckets
CCGAllocatorIFC allocatorIFC
CCGAllocatorHDL allocator