18#define FACE_calcIFNo(f, lvl, S, x, y, no) \
19 _face_calcIFNo(f, lvl, S, x, y, no, subdivLevels, vertDataSize)
34 return e->numFaces < 2;
39 for (
int i = 0; i <
v->numEdges; i++) {
71 CCGFace *f,
int lvl,
int S,
int x,
int y,
float no[3],
int levels,
int dataSize)
73 const float *a =
static_cast<float *
>(
75 const float *
b =
static_cast<float *
>(
77 const float *c =
static_cast<float *
>(
79 const float *d =
static_cast<float *
>(
81 const float a_cX = c[0] - a[0], a_cY = c[1] - a[1], a_cZ = c[2] - a[2];
82 const float b_dX = d[0] -
b[0], b_dY = d[1] -
b[1], b_dZ = d[2] -
b[2];
84 no[0] = b_dY * a_cZ - b_dZ * a_cY;
85 no[1] = b_dZ * a_cX - b_dX * a_cZ;
86 no[2] = b_dX * a_cY - b_dY * a_cX;
104 if (
e->crease - lvl < 0.0f) {
107 return e->crease - lvl;
123 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
128 CCGFace *f = data->effectedF[ptrIdx];
140 for (y = 0; y < gridSize - 1; y++) {
141 for (x = 0; x < gridSize - 1; x++) {
147 for (x = 0; x < gridSize - 1; x++) {
152 for (y = 0; y < gridSize - 1; y++) {
164 int yLimitNext = xLimit;
165 int xLimitPrev = yLimit;
167 for (y = 0; y < gridSize - 1; y++) {
168 for (x = 0; x < gridSize - 1; x++) {
169 int xPlusOk = (!xLimit || x < gridSize - 2);
170 int yPlusOk = (!yLimit || y < gridSize - 2);
181 if (xPlusOk && yPlusOk) {
188 if (x == 0 && y == 0) {
191 if (!yLimitNext || 1 < gridSize - 1) {
194 if (!xLimitPrev || 1 < gridSize - 1) {
206 if (!yLimitNext || x < gridSize - 2) {
212 if (!xLimitPrev || y < gridSize - 2) {
222 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
227 CCGFace *f = data->effectedF[ptrIdx];
243 for (y = 0; y < gridSize; y++) {
244 for (x = 0; x < gridSize; x++) {
254 for (x = 1; x < gridSize - 1; x++) {
261 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
266 CCGEdge *
e = data->effectedE[ptrIdx];
275 CCGFace *fLast =
e->faces[
e->numFaces - 1];
278 for (i = 0; i <
e->numFaces - 1; i++) {
283 for (x = 1; x < edgeSize - 1; x++) {
286 fLast,
e, f_ed_idx_last, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset),
288 f,
e, f_ed_idx, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset));
292 for (i = 0; i <
e->numFaces - 1; i++) {
297 for (x = 1; x < edgeSize - 1; x++) {
300 f,
e, f_ed_idx, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset),
302 fLast,
e, f_ed_idx_last, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset));
326 data.effectedV = effectedV;
327 data.effectedE = effectedE;
328 data.effectedF = effectedF;
329 data.numEffectedV = numEffectedV;
330 data.numEffectedE = numEffectedE;
331 data.numEffectedF = numEffectedF;
342 for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
348 for (i = 0; i <
v->numFaces; i++) {
359 for (i = 0; i <
v->numFaces; i++) {
381 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
389 for (x = 0; x < edgeSize; x++) {
392 f,
e, f_ed_idx, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset));
402 for (x = 0; x < edgeSize; x++) {
412 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
417 CCGFace *f = data->effectedF[ptrIdx];
420 const int curLvl = data->curLvl;
421 const int nextLvl = curLvl + 1;
431 for (y = 0; y < gridSize - 1; y++) {
432 for (x = 0; x < gridSize - 1; x++) {
435 const float *co0 =
FACE_getIFCo(f, curLvl, S, x + 0, y + 0);
436 const float *co1 =
FACE_getIFCo(f, curLvl, S, x + 1, y + 0);
437 const float *co2 =
FACE_getIFCo(f, curLvl, S, x + 1, y + 1);
438 const float *co3 =
FACE_getIFCo(f, curLvl, S, x + 0, y + 1);
451 for (x = 0; x < gridSize - 1; x++) {
468 for (x = 1; x < gridSize - 1; x++) {
469 for (y = 0; y < gridSize - 1; y++) {
472 const float *co0 =
FACE_getIFCo(f, curLvl, S, x, y + 0);
473 const float *co1 =
FACE_getIFCo(f, curLvl, S, x, y + 1);
474 const float *co2 =
FACE_getIFCo(f, nextLvl, S, fx - 1, fy);
475 const float *co3 =
FACE_getIFCo(f, nextLvl, S, fx + 1, fy);
483 for (y = 1; y < gridSize - 1; y++) {
484 for (x = 0; x < gridSize - 1; x++) {
487 const float *co0 =
FACE_getIFCo(f, curLvl, S, x + 0, y);
488 const float *co1 =
FACE_getIFCo(f, curLvl, S, x + 1, y);
489 const float *co2 =
FACE_getIFCo(f, nextLvl, S, fx, fy - 1);
490 const float *co3 =
FACE_getIFCo(f, nextLvl, S, fx, fy + 1);
500 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
505 CCGFace *f = data->effectedF[ptrIdx];
508 const int curLvl = data->curLvl;
509 const int nextLvl = curLvl + 1;
513 float *q_thread =
static_cast<float *
>(alloca(vertDataSize));
514 float *r_thread =
static_cast<float *
>(alloca(vertDataSize));
545 for (x = 1; x < gridSize - 1; x++) {
546 for (y = 1; y < gridSize - 1; y++) {
578 for (x = 1; x < gridSize - 1; x++) {
606 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
611 CCGFace *f = data->effectedF[ptrIdx];
614 const int nextLvl = data->curLvl + 1;
616 const int cornerIdx = gridSize - 1;
633 for (x = 1; x < gridSize - 1; x++) {
638 for (x = 0; x < gridSize - 1; x++) {
639 int eI = gridSize - 1 -
x;
641 static_cast<const float *
>(
645 static_cast<const float *
>(
656 const int numEffectedV,
657 const int numEffectedE,
658 const int numEffectedF,
662 const int nextLvl = curLvl + 1;
666 float *q =
static_cast<float *
>(ss->
q), *r =
static_cast<float *
>(ss->
r);
670 data.effectedV = effectedV;
671 data.effectedE = effectedE;
672 data.effectedF = effectedF;
673 data.numEffectedV = numEffectedV;
674 data.numEffectedE = numEffectedE;
675 data.numEffectedF = numEffectedF;
676 data.curLvl = curLvl;
694 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
700 for (x = 0; x < edgeSize - 1; x++) {
712 for (x = 0; x < edgeSize - 1; x++) {
722 for (j = 0; j <
e->numFaces; j++) {
727 f,
e, f_ed_idx, nextLvl, fx, 1, subdivLevels, vertDataSize)),
752 for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
756 int sharpCount = 0, allSharp = 1;
757 float avgSharpness = 0.0;
760 for (j = 0; j <
v->numEdges; j++) {
768 if (sharpness != 0.0f) {
770 avgSharpness += sharpness;
778 avgSharpness /= sharpCount;
779 if (avgSharpness > 1.0f) {
784 if (seamEdges < 2 || seamEdges != v->numEdges) {
795 for (j = 0; j <
v->numEdges; j++) {
799 r,
static_cast<const float *
>(
_edge_getCoVert(
e,
v, curLvl, 1, vertDataSize)), ss);
810 const int cornerIdx = (1 + (1 << (curLvl))) - 2;
811 int numEdges = 0, numFaces = 0;
814 for (j = 0; j <
v->numFaces; j++) {
822 for (j = 0; j <
v->numEdges; j++) {
825 r,
static_cast<const float *
>(
_edge_getCoVert(
e,
v, curLvl, 1, vertDataSize)), ss);
837 if ((sharpCount > 1 &&
v->numFaces) || seam) {
842 sharpCount = seamEdges;
846 for (j = 0; j <
v->numEdges; j++) {
853 q,
static_cast<const float *
>(
_edge_getCoVert(
e,
v, curLvl, 1, vertDataSize)), ss);
856 else if (sharpness != 0.0f) {
858 q,
static_cast<const float *
>(
_edge_getCoVert(
e,
v, curLvl, 1, vertDataSize)), ss);
864 if (sharpCount != 2 || allSharp) {
891 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
895 float avgSharpness = 0.0;
898 if (sharpness != 0.0f) {
900 avgSharpness += sharpness;
902 if (avgSharpness > 1.0f) {
912 for (x = 1; x < edgeSize - 1; x++) {
930 for (x = 1; x < edgeSize - 1; x++) {
940 for (j = 0; j <
e->numFaces; j++) {
945 f,
e, f_ed_idx, nextLvl, fx - 1, 1, subdivLevels, vertDataSize)),
949 f,
e, f_ed_idx, nextLvl, fx + 1, 1, subdivLevels, vertDataSize)),
954 f,
e, f_ed_idx, curLvl, x, 1, subdivLevels, vertDataSize)),
967 if (sharpCount == 2) {
997 for (i = 0; i < numEffectedE; i++) {
1017 int numEffectedV, numEffectedE, numEffectedF;
1020 int i, j, ptrIdx, S;
1021 int curLvl, nextLvl;
1022 void *q = ss->
q, *r = ss->
r;
1024 effectedV =
static_cast<CCGVert **
>(
1026 effectedE =
static_cast<CCGEdge **
>(
1028 effectedF =
static_cast<CCGFace **
>(
1030 numEffectedV = numEffectedE = numEffectedF = 0;
1033 for (;
v;
v =
v->next) {
1035 effectedV[numEffectedV++] =
v;
1037 for (j = 0; j <
v->numEdges; j++) {
1040 effectedE[numEffectedE++] =
e;
1045 for (j = 0; j <
v->numFaces; j++) {
1048 effectedF[numEffectedF++] = f;
1057 nextLvl = curLvl + 1;
1059 for (ptrIdx = 0; ptrIdx < numEffectedF; ptrIdx++) {
1060 CCGFace *f = effectedF[ptrIdx];
1063 for (i = 0; i < f->
numVerts; i++) {
1070 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
1084 for (i = 0; i <
e->numFaces; i++) {
1089 VertDataMulN(
static_cast<float *
>(q), 1.0f / (2.0f + numFaces), ss);
1095 VertDataCopy(
static_cast<float *
>(co),
static_cast<const float *
>(q), ss);
1096 VertDataSub(
static_cast<float *
>(r),
static_cast<const float *
>(q), ss);
1098 VertDataAdd(
static_cast<float *
>(co),
static_cast<const float *
>(r), ss);
1103 for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
1107 int sharpCount = 0, allSharp = 1;
1108 float avgSharpness = 0.0;
1111 for (i = 0; i <
v->numEdges; i++) {
1119 if (sharpness != 0.0f) {
1121 avgSharpness += sharpness;
1129 avgSharpness /= sharpCount;
1130 if (avgSharpness > 1.0f) {
1131 avgSharpness = 1.0f;
1135 if (seamEdges < 2 || seamEdges != v->numEdges) {
1140 VertDataCopy(
static_cast<float *
>(nCo),
static_cast<const float *
>(co), ss);
1143 int numBoundary = 0;
1146 for (i = 0; i <
v->numEdges; i++) {
1153 VertDataCopy(
static_cast<float *
>(nCo),
static_cast<const float *
>(co), ss);
1155 VertDataMulN(
static_cast<float *
>(r), 0.25f / numBoundary, ss);
1156 VertDataAdd(
static_cast<float *
>(nCo),
static_cast<const float *
>(r), ss);
1159 int numEdges = 0, numFaces = 0;
1162 for (i = 0; i <
v->numFaces; i++) {
1167 VertDataMulN(
static_cast<float *
>(q), 1.0f / numFaces, ss);
1169 for (i = 0; i <
v->numEdges; i++) {
1174 VertDataMulN(
static_cast<float *
>(r), 1.0f / numEdges, ss);
1176 VertDataCopy(
static_cast<float *
>(nCo),
static_cast<const float *
>(co), ss);
1177 VertDataMulN(
static_cast<float *
>(nCo), numEdges - 2.0f, ss);
1178 VertDataAdd(
static_cast<float *
>(nCo),
static_cast<const float *
>(q), ss);
1179 VertDataAdd(
static_cast<float *
>(nCo),
static_cast<const float *
>(r), ss);
1180 VertDataMulN(
static_cast<float *
>(nCo), 1.0f / numEdges, ss);
1183 if (sharpCount > 1 || seam) {
1187 avgSharpness = 1.0f;
1188 sharpCount = seamEdges;
1192 for (i = 0; i <
v->numEdges; i++) {
1202 else if (sharpness != 0.0f) {
1208 VertDataMulN(
static_cast<float *
>(q),
float(1) / sharpCount, ss);
1210 if (sharpCount != 2 || allSharp) {
1212 VertDataCopy(
static_cast<float *
>(r),
static_cast<const float *
>(co), ss);
1213 VertDataSub(
static_cast<float *
>(r),
static_cast<const float *
>(q), ss);
1214 VertDataMulN(
static_cast<float *
>(r), avgSharpness, ss);
1215 VertDataAdd(
static_cast<float *
>(q),
static_cast<const float *
>(r), ss);
1219 VertDataCopy(
static_cast<float *
>(r),
static_cast<const float *
>(co), ss);
1222 VertDataAdd(
static_cast<float *
>(r),
static_cast<const float *
>(q), ss);
1225 VertDataSub(
static_cast<float *
>(r),
static_cast<const float *
>(nCo), ss);
1226 VertDataMulN(
static_cast<float *
>(r), avgSharpness, ss);
1227 VertDataAdd(
static_cast<float *
>(nCo),
static_cast<const float *
>(r), ss);
1234 for (i = 0; i < numEffectedV; i++) {
1240 for (i = 0; i < numEffectedE; i++) {
1246 for (i = 0; i < numEffectedF; i++) {
1253 for (i = 0; i < numEffectedE; i++) {
1258 for (i = 0; i < numEffectedF; i++) {
1260 for (S = 0; S < f->
numVerts; S++) {
1272 static_cast<const float *
>(
1276 static_cast<const float *
>(
1282 for (curLvl = 1; curLvl < subdivLevels; curLvl++) {
1284 ss, effectedV, effectedE, effectedF, numEffectedV, numEffectedE, numEffectedF, curLvl);
1289 ss, effectedV, effectedE, effectedF, numEffectedV, numEffectedE, numEffectedF);
1292 for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
1296 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
1305#ifdef DUMP_RESULT_GRIDS
1306 ccgSubSurf__dumpCoords(ss);
1316 int i, numEffectedV, numEffectedE, freeF;
1320 ss, effectedF, numEffectedF, &effectedV, &numEffectedV, &effectedE, &numEffectedE);
1324 ss, effectedV, effectedE, effectedF, numEffectedV, numEffectedE, numEffectedF);
1327 for (i = 0; i < numEffectedV; i++) {
1328 effectedV[i]->
flags = 0;
1330 for (i = 0; i < numEffectedE; i++) {
1331 effectedE[i]->
flags = 0;
1333 for (i = 0; i < numEffectedF; i++) {
1334 effectedF[i]->
flags = 0;
1350 int numEffectedV, numEffectedE, freeF, i;
1355 ss, effectedF, numEffectedF, &effectedV, &numEffectedV, &effectedE, &numEffectedE);
1357 for (curLvl = lvl; curLvl < subdivLevels; curLvl++) {
1359 ss, effectedV, effectedE, effectedF, numEffectedV, numEffectedE, numEffectedF, curLvl);
1362 for (i = 0; i < numEffectedV; i++) {
1363 effectedV[i]->
flags = 0;
1365 for (i = 0; i < numEffectedE; i++) {
1366 effectedE[i]->
flags = 0;
1368 for (i = 0; i < numEffectedF; i++) {
1369 effectedF[i]->
flags = 0;
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
void ccgSubSurf__effectedFaceNeighbors(CCGSubSurf *ss, CCGFace **faces, int numFaces, CCGVert ***verts, int *numVerts, CCGEdge ***edges, int *numEdges)
void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces)
void * ccgSubSurf_getEdgeUserData(CCGSubSurf *ss, CCGEdge *e)
void * ccgSubSurf_getFaceUserData(CCGSubSurf *ss, CCGFace *f)
void * ccgSubSurf_getVertUserData(CCGSubSurf *ss, CCGVert *v)
BLI_INLINE int ccg_edgesize(int level)
BLI_INLINE void Normalize(float no[3])
BLI_INLINE CCGVert ** FACE_getVerts(CCGFace *f)
BLI_INLINE int ccg_gridsize(int level)
BLI_INLINE byte * EDGE_getLevelData(CCGEdge *e)
BLI_INLINE void VertDataZero(float v[], const CCGSubSurf *ss)
BLI_INLINE CCGEdge ** FACE_getEdges(CCGFace *f)
BLI_INLINE int ccg_edgebase(int level)
BLI_INLINE int ccg_face_getEdgeIndex(CCGFace *f, CCGEdge *e)
BLI_INLINE void * ccg_face_getIFCo(CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize)
BLI_INLINE void VertDataSub(float a[], const float b[], const CCGSubSurf *ss)
BLI_INLINE void VertDataCopy(float dst[], const float src[], const CCGSubSurf *ss)
BLI_INLINE int ccg_face_getVertIndex(CCGFace *f, CCGVert *v)
BLI_INLINE void VertDataMulN(float v[], float f, const CCGSubSurf *ss)
BLI_INLINE void VertDataAvg4(float v[], const float a[], const float b[], const float c[], const float d[], const CCGSubSurf *ss)
BLI_INLINE void VertDataAdd(float a[], const float b[], const CCGSubSurf *ss)
BLI_INLINE void * ccg_face_getIFCoEdge(CCGFace *f, CCGEdge *e, int f_ed_idx, int lvl, int eX, int eY, int levels, int dataSize)
BLI_INLINE byte * FACE_getCenterData(CCGFace *f)
#define EDGE_getNo(e, lvl, x)
#define FACE_getIENo(f, lvl, S, x)
#define FACE_getIFNo(f, lvl, S, x, y)
#define EDGE_getCo(e, lvl, x)
#define FACE_getIFCo(f, lvl, S, x, y)
#define VERT_getCo(v, lvl)
#define VERT_getNo(v, lvl)
#define FACE_getIECo(f, lvl, S, x)
static void ccgSubSurf__calcSubdivLevel_interior_faces_edges_midpoints_cb(void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict)
static void ccgSubSurf__calcSubdivLevel_interior_faces_edges_centerpoints_shift_cb(void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict)
static CCGVert * _edge_getOtherVert(CCGEdge *e, CCGVert *vQ)
static int _edge_isBoundary(const CCGEdge *e)
#define FACE_calcIFNo(f, lvl, S, x, y, no)
CCGError ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **effectedF, int numEffectedF)
static void ccgSubSurf__calcVertNormals_edges_accumulate_cb(void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict)
static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss, CCGVert **effectedV, CCGEdge **effectedE, CCGFace **effectedF, int numEffectedV, int numEffectedE, int numEffectedF)
static void ccgSubSurf__calcVertNormals_faces_accumulate_cb(void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict)
CCGError ccgSubSurf_updateLevels(CCGSubSurf *ss, int lvl, CCGFace **effectedF, int numEffectedF)
static void * _edge_getCoVert(CCGEdge *e, CCGVert *v, int lvl, int x, int dataSize)
static float * _face_getIFNoEdge(CCGFace *f, CCGEdge *e, int f_ed_idx, int lvl, int eX, int eY, int levels, int dataSize, int normalDataOffset)
static void _face_calcIFNo(CCGFace *f, int lvl, int S, int x, int y, float no[3], int levels, int dataSize)
static float EDGE_getSharpness(CCGEdge *e, int lvl)
static void ccgSubSurf__calcSubdivLevel_verts_copydata_cb(void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict)
static int VERT_seam(const CCGVert *v)
static bool _vert_isBoundary(const CCGVert *v)
void ccgSubSurf__sync_legacy(CCGSubSurf *ss)
static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, CCGVert **effectedV, CCGEdge **effectedE, CCGFace **effectedF, const int numEffectedV, const int numEffectedE, const int numEffectedF, const int curLvl)
static void ccgSubSurf__calcVertNormals_faces_finalize_cb(void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict)
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
local_group_size(16, 16) .push_constant(Type b
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)