Blender V4.3
CCGSubSurf_intern.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
19/* Define this to see dump of the grids after the subsurf applied. */
20#undef DUMP_RESULT_GRIDS
21
22/* used for normalize_v3 in BLI_math_vector
23 * float.h's FLT_EPSILON causes trouble with subsurf normals - campbell */
24#define EPSILON (1.0e-35f)
25
26/* With this limit a single triangle becomes over 3 million faces */
27#define CCGSUBSURF_LEVEL_MAX 11
28
33typedef unsigned char byte;
34
39typedef struct _EHEntry {
40 struct _EHEntry *next;
41 void *key;
43
51
52typedef void (*EHEntryFreeFP)(EHEntry *, void *);
53
54#define EHASH_alloc(eh, nb) (EHEntry **)((eh)->allocatorIFC.alloc((eh)->allocator, nb))
55#define EHASH_free(eh, ptr) ((eh)->allocatorIFC.free((eh)->allocator, ptr))
56#define EHASH_hash(eh, item) (((uintptr_t)(item)) % ((unsigned int)(eh)->curSize))
57
58/* Generic hash functions. */
59
60EHash *ccg_ehash_new(int estimatedNumEntries,
61 CCGAllocatorIFC *allocatorIFC,
62 CCGAllocatorHDL allocator);
63void ccg_ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *user_data);
64void ccg_ehash_insert(EHash *eh, EHEntry *entry);
65void *ccg_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r);
66void *ccg_ehash_lookup(EHash *eh, void *key);
67
68/* Hash elements iteration. */
69
74
80
85/* ** Data structures, constants. enums ** */
86
87enum {
88 Vert_eEffected = (1 << 0),
89 Vert_eChanged = (1 << 1),
90 Vert_eSeam = (1 << 2),
91} /*VertFlags*/;
92
93enum {
94 Edge_eEffected = (1 << 0),
95} /*CCGEdgeFlags*/;
96
97enum {
98 Face_eEffected = (1 << 0),
99} /*FaceFlags*/;
100
101struct CCGVert {
102 CCGVert *next; /* EHData.next */
103 CCGVertHDL vHDL; /* EHData.key */
104
106 int osd_index; /* Index of the vertex in the map, used by OSD. */
107
110 // byte *levelData;
111 // byte *user_data;
112};
113
114struct CCGEdge {
115 CCGEdge *next; /* EHData.next */
116 CCGEdgeHDL eHDL; /* EHData.key */
117
119 float crease;
120
123
124 // byte *levelData;
125 // byte *user_data;
126};
127
128struct CCGFace {
129 CCGFace *next; /* EHData.next */
130 CCGFaceHDL fHDL; /* EHData.key */
131
134
135 // CCGVert **verts;
136 // CCGEdge **edges;
137 // byte *centerData;
138 // byte **gridData;
139 // byte *user_data;
140};
141
149
151 EHash *vMap; /* map of CCGVertHDL -> Vert */
152 EHash *eMap; /* map of CCGEdgeHDL -> Edge */
153 EHash *fMap; /* map of CCGFaceHDL -> Face */
154
156
159
165
166 void *q, *r;
167
168 /* Data for calc vert normals. */
171
172 /* Data for paint masks. */
175
176 /* Data for age'ing (to debug sync). */
182
183 /* Data used during syncing. */
185
190};
191
192/* ** Utility macros ** */
193
194#define CCGSUBSURF_alloc(ss, nb) ((ss)->allocatorIFC.alloc((ss)->allocator, nb))
195#define CCGSUBSURF_realloc(ss, ptr, nb, ob) \
196 ((ss)->allocatorIFC.realloc((ss)->allocator, ptr, nb, ob))
197#define CCGSUBSURF_free(ss, ptr) ((ss)->allocatorIFC.free((ss)->allocator, ptr))
198
199#define VERT_getCo(v, lvl) (float *)ccg_vert_getCo(v, lvl, vertDataSize)
200#define VERT_getNo(v, lvl) ccg_vert_getNo(v, lvl, vertDataSize, normalDataOffset)
201#define EDGE_getCo(e, lvl, x) (float *)ccg_edge_getCo(e, lvl, x, vertDataSize)
202#define EDGE_getNo(e, lvl, x) ccg_edge_getNo(e, lvl, x, vertDataSize, normalDataOffset)
203#define FACE_getIFNo(f, lvl, S, x, y) \
204 ccg_face_getIFNo(f, lvl, S, x, y, subdivLevels, vertDataSize, normalDataOffset)
205#if 0
206# define FACE_calcIFNo(f, lvl, S, x, y, no) \
207 _face_calcIFNo(f, lvl, S, x, y, no, subdivLevels, vertDataSize)
208#endif
209#define FACE_getIENo(f, lvl, S, x) \
210 ccg_face_getIENo(f, lvl, S, x, subdivLevels, vertDataSize, normalDataOffset)
211#define FACE_getIECo(f, lvl, S, x) \
212 (float *)ccg_face_getIECo(f, lvl, S, x, subdivLevels, vertDataSize)
213#define FACE_getIFCo(f, lvl, S, x, y) \
214 (float *)ccg_face_getIFCo(f, lvl, S, x, y, subdivLevels, vertDataSize)
215
216#define NormZero(av) \
217 { \
218 float *_a = (float *)av; \
219 _a[0] = _a[1] = _a[2] = 0.0f; \
220 } \
221 (void)0
222#define NormCopy(av, bv) \
223 { \
224 float *_a = (float *)av; \
225 const float *_b = (const float *)bv; \
226 _a[0] = _b[0]; \
227 _a[1] = _b[1]; \
228 _a[2] = _b[2]; \
229 } \
230 (void)0
231#define NormAdd(av, bv) \
232 { \
233 float *_a = (float *)av; \
234 const float *_b = (const float *)bv; \
235 _a[0] += _b[0]; \
236 _a[1] += _b[1]; \
237 _a[2] += _b[2]; \
238 } \
239 (void)0
240
241/* ** General purpose functions ** */
242
243/* `CCGSubSurf.cc` */
244
245void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces);
247 CCGFace **faces,
248 int numFaces,
249 CCGVert ***verts,
250 int *numVerts,
251 CCGEdge ***edges,
252 int *numEdges);
253
254/* `CCGSubSurf_legacy.cc` */
255
257
258/* `CCGSubSurf_util.cc` */
259
260#ifdef DUMP_RESULT_GRIDS
261void ccgSubSurf__dumpCoords(CCGSubSurf *ss);
262#endif
263
264#ifdef __cplusplus
265}
266#endif
267
268#include "CCGSubSurf_inline.h"
void * CCGFaceHDL
Definition CCGSubSurf.h:18
void * CCGEdgeHDL
Definition CCGSubSurf.h:17
void * CCGVertHDL
Definition CCGSubSurf.h:16
void * CCGAllocatorHDL
Definition CCGSubSurf.h:34
unsigned char byte
CCGAllocatorIFC * ccg_getStandardAllocatorIFC(void)
@ Face_eEffected
void ccgSubSurf__effectedFaceNeighbors(CCGSubSurf *ss, CCGFace **faces, int numFaces, CCGVert ***verts, int *numVerts, CCGEdge ***edges, int *numEdges)
struct _EHash EHash
void ccg_ehashIterator_init(EHash *eh, EHashIterator *ehi)
void ccg_ehashIterator_next(EHashIterator *ehi)
void ccg_ehash_insert(EHash *eh, EHEntry *entry)
void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces)
int ccg_ehashIterator_isStopped(EHashIterator *ehi)
void * ccg_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r)
@ Vert_eChanged
@ Vert_eEffected
@ Vert_eSeam
struct _EHEntry EHEntry
@ eSyncState_Edge
@ eSyncState_Vert
@ eSyncState_Face
@ eSyncState_None
@ eSyncState_Partial
void * ccg_ehashIterator_getCurrent(EHashIterator *ehi)
void ccg_ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *user_data)
@ Edge_eEffected
EHash * ccg_ehash_new(int estimatedNumEntries, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator)
void(* EHEntryFreeFP)(EHEntry *, void *)
void * ccg_ehash_lookup(EHash *eh, void *key)
void ccgSubSurf__sync_legacy(CCGSubSurf *ss)
static float verts[][3]
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
CCGVertHDL vHDL
CCGFace ** faces
CCGEdge ** edges
CCGVert * next
struct _EHEntry * next
EHEntry ** buckets
CCGAllocatorIFC allocatorIFC
CCGAllocatorHDL allocator