Blender V4.5
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
8
9#pragma once
10
11#include "CCGSubSurf.h"
12
16
17/* Define this to see dump of the grids after the subsurf applied. */
18#undef DUMP_RESULT_GRIDS
19
20/* used for normalize_v3 in BLI_math_vector
21 * float.h's FLT_EPSILON causes trouble with subsurf normals - campbell */
22#define EPSILON (1.0e-35f)
23
24/* With this limit a single triangle becomes over 3 million faces */
25#define CCGSUBSURF_LEVEL_MAX 11
26
30
34
35struct EHEntry {
36 struct EHEntry *next;
37 void *key;
38};
39
47
48using EHEntryFreeFP = void (*)(EHEntry *, void *);
49
50#define EHASH_alloc(eh, nb) (EHEntry **)((eh)->allocatorIFC.alloc((eh)->allocator, nb))
51#define EHASH_free(eh, ptr) ((eh)->allocatorIFC.free((eh)->allocator, ptr))
52#define EHASH_hash(eh, item) (((uintptr_t)(item)) % ((unsigned int)(eh)->curSize))
53
54/* Generic hash functions. */
55
56EHash *ccg_ehash_new(int estimatedNumEntries,
57 CCGAllocatorIFC *allocatorIFC,
58 CCGAllocatorHDL allocator);
59void ccg_ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *user_data);
60void ccg_ehash_insert(EHash *eh, EHEntry *entry);
61void *ccg_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r);
62void *ccg_ehash_lookup(EHash *eh, void *key);
63
64/* Hash elements iteration. */
65
70
74
76
80
81/* ** Data structures, constants. enums ** */
82
83enum {
84 Vert_eEffected = (1 << 0),
85 Vert_eChanged = (1 << 1),
86 Vert_eSeam = (1 << 2),
87} /*VertFlags*/;
88
89enum {
90 Edge_eEffected = (1 << 0),
91} /*CCGEdgeFlags*/;
92
93enum {
94 Face_eEffected = (1 << 0),
95} /*FaceFlags*/;
96
97struct CCGVert {
98 CCGVert *next; /* EHData.next */
99 CCGVertHDL vHDL; /* EHData.key */
100
102 int osd_index; /* Index of the vertex in the map, used by OSD. */
103
106 // uint8_t *levelData;
107 // uint8_t *user_data;
108};
109
110struct CCGEdge {
111 CCGEdge *next; /* EHData.next */
112 CCGEdgeHDL eHDL; /* EHData.key */
113
115 float crease;
116
119
120 // uint8_t *levelData;
121 // uint8_t *user_data;
122};
123
124struct CCGFace {
125 CCGFace *next; /* EHData.next */
126 CCGFaceHDL fHDL; /* EHData.key */
127
130
131 // CCGVert **verts;
132 // CCGEdge **edges;
133 // uint8_t *centerData;
134 // uint8_t **gridData;
135 // uint8_t *user_data;
136};
137
145
147 EHash *vMap; /* map of CCGVertHDL -> Vert */
148 EHash *eMap; /* map of CCGEdgeHDL -> Edge */
149 EHash *fMap; /* map of CCGFaceHDL -> Face */
150
152
155
161
162 void *q, *r;
163
164 /* Data for calc vert normals. */
167
168 /* Data for paint masks. */
171
172 /* Data for age'ing (to debug sync). */
178
179 /* Data used during syncing. */
181
186};
187
188/* ** Utility macros ** */
189
190#define CCGSUBSURF_alloc(ss, nb) ((ss)->allocatorIFC.alloc((ss)->allocator, nb))
191#define CCGSUBSURF_realloc(ss, ptr, nb, ob) \
192 ((ss)->allocatorIFC.realloc((ss)->allocator, ptr, nb, ob))
193#define CCGSUBSURF_free(ss, ptr) ((ss)->allocatorIFC.free((ss)->allocator, ptr))
194
195#define VERT_getCo(v, lvl) (float *)ccg_vert_getCo(v, lvl, vertDataSize)
196#define VERT_getNo(v, lvl) ccg_vert_getNo(v, lvl, vertDataSize, normalDataOffset)
197#define EDGE_getCo(e, lvl, x) (float *)ccg_edge_getCo(e, lvl, x, vertDataSize)
198#define EDGE_getNo(e, lvl, x) ccg_edge_getNo(e, lvl, x, vertDataSize, normalDataOffset)
199#define FACE_getIFNo(f, lvl, S, x, y) \
200 ccg_face_getIFNo(f, lvl, S, x, y, subdivLevels, vertDataSize, normalDataOffset)
201#if 0
202# define FACE_calcIFNo(f, lvl, S, x, y, no) \
203 _face_calcIFNo(f, lvl, S, x, y, no, subdivLevels, vertDataSize)
204#endif
205#define FACE_getIENo(f, lvl, S, x) \
206 ccg_face_getIENo(f, lvl, S, x, subdivLevels, vertDataSize, normalDataOffset)
207#define FACE_getIECo(f, lvl, S, x) \
208 (float *)ccg_face_getIECo(f, lvl, S, x, subdivLevels, vertDataSize)
209#define FACE_getIFCo(f, lvl, S, x, y) \
210 (float *)ccg_face_getIFCo(f, lvl, S, x, y, subdivLevels, vertDataSize)
211
212#define NormZero(av) \
213 { \
214 float *_a = (float *)av; \
215 _a[0] = _a[1] = _a[2] = 0.0f; \
216 } \
217 (void)0
218#define NormCopy(av, bv) \
219 { \
220 float *_a = (float *)av; \
221 const float *_b = (const float *)bv; \
222 _a[0] = _b[0]; \
223 _a[1] = _b[1]; \
224 _a[2] = _b[2]; \
225 } \
226 (void)0
227#define NormAdd(av, bv) \
228 { \
229 float *_a = (float *)av; \
230 const float *_b = (const float *)bv; \
231 _a[0] += _b[0]; \
232 _a[1] += _b[1]; \
233 _a[2] += _b[2]; \
234 } \
235 (void)0
236
237/* ** General purpose functions ** */
238
239/* `CCGSubSurf.cc` */
240
241void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces);
243 CCGFace **faces,
244 int numFaces,
245 CCGVert ***verts,
246 int *numVerts,
247 CCGEdge ***edges,
248 int *numEdges);
249
250/* `CCGSubSurf_legacy.cc` */
251
253
254/* `CCGSubSurf_util.cc` */
255
256#ifdef DUMP_RESULT_GRIDS
257void ccgSubSurf__dumpCoords(CCGSubSurf *ss);
258#endif
void * CCGEdgeHDL
Definition CCGSubSurf.h:13
void * CCGVertHDL
Definition CCGSubSurf.h:12
void * CCGAllocatorHDL
Definition CCGSubSurf.h:30
void * CCGFaceHDL
Definition CCGSubSurf.h:14
CCGAllocatorIFC * ccg_getStandardAllocatorIFC(void)
void ccgSubSurf__effectedFaceNeighbors(CCGSubSurf *ss, CCGFace **faces, int numFaces, CCGVert ***verts, int *numVerts, CCGEdge ***edges, int *numEdges)
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)
@ Face_eEffected
@ 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)
void(*)(EHEntry *, void *) EHEntryFreeFP
EHash * ccg_ehash_new(int estimatedNumEntries, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator)
@ Vert_eChanged
@ Vert_eEffected
@ Vert_eSeam
@ Edge_eEffected
void * ccg_ehash_lookup(EHash *eh, void *key)
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
CCGVertHDL vHDL
CCGFace ** faces
CCGEdge ** edges
CCGVert * next
struct EHEntry * next
CCGAllocatorHDL allocator
EHEntry ** buckets
CCGAllocatorIFC allocatorIFC