20#define FACE_calcIFNo(f, lvl, S, x, y, no) \
21 _face_calcIFNo(f, lvl, S, x, y, no, subdivLevels, vertDataSize)
36 return e->numFaces < 2;
41 for (
int i = 0;
i <
v->numEdges;
i++) {
73 CCGFace *f,
int lvl,
int S,
int x,
int y,
float no[3],
int levels,
int dataSize)
75 const float *a =
static_cast<float *
>(
77 const float *
b =
static_cast<float *
>(
79 const float *c =
static_cast<float *
>(
81 const float *d =
static_cast<float *
>(
83 const float a_cX = c[0] - a[0], a_cY = c[1] - a[1], a_cZ = c[2] - a[2];
84 const float b_dX = d[0] -
b[0], b_dY = d[1] -
b[1], b_dZ = d[2] -
b[2];
86 no[0] = b_dY * a_cZ - b_dZ * a_cY;
87 no[1] = b_dZ * a_cX - b_dX * a_cZ;
88 no[2] = b_dX * a_cY - b_dY * a_cX;
106 if (
e->crease - lvl < 0.0f) {
109 return e->crease - lvl;
125 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
142 for (
y = 0;
y < gridSize - 1;
y++) {
143 for (
x = 0;
x < gridSize - 1;
x++) {
149 for (
x = 0;
x < gridSize - 1;
x++) {
154 for (
y = 0;
y < gridSize - 1;
y++) {
166 int yLimitNext = xLimit;
167 int xLimitPrev = yLimit;
169 for (
y = 0;
y < gridSize - 1;
y++) {
170 for (
x = 0;
x < gridSize - 1;
x++) {
171 int xPlusOk = (!xLimit ||
x < gridSize - 2);
172 int yPlusOk = (!yLimit ||
y < gridSize - 2);
183 if (xPlusOk && yPlusOk) {
190 if (
x == 0 &&
y == 0) {
193 if (!yLimitNext || 1 < gridSize - 1) {
196 if (!xLimitPrev || 1 < gridSize - 1) {
208 if (!yLimitNext ||
x < gridSize - 2) {
214 if (!xLimitPrev ||
y < gridSize - 2) {
224 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
245 for (
y = 0;
y < gridSize;
y++) {
246 for (
x = 0;
x < gridSize;
x++) {
255 for (
x = 1;
x < gridSize - 1;
x++) {
262 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
276 CCGFace *fLast =
e->faces[
e->numFaces - 1];
279 for (
i = 0;
i <
e->numFaces - 1;
i++) {
284 for (
x = 1;
x < edgeSize - 1;
x++) {
287 fLast,
e, f_ed_idx_last, lvl,
x, 0, subdivLevels, vertDataSize, normalDataOffset),
289 f,
e, f_ed_idx, lvl,
x, 0, subdivLevels, vertDataSize, normalDataOffset));
293 for (
i = 0;
i <
e->numFaces - 1;
i++) {
298 for (
x = 1;
x < edgeSize - 1;
x++) {
301 f,
e, f_ed_idx, lvl,
x, 0, subdivLevels, vertDataSize, normalDataOffset),
303 fLast,
e, f_ed_idx_last, lvl,
x, 0, subdivLevels, vertDataSize, normalDataOffset));
327 data.effectedV = effectedV;
328 data.effectedE = effectedE;
329 data.effectedF = effectedF;
330 data.numEffectedV = numEffectedV;
331 data.numEffectedE = numEffectedE;
332 data.numEffectedF = numEffectedF;
343 for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
349 for (
i = 0;
i <
v->numFaces;
i++) {
360 for (
i = 0;
i <
v->numFaces;
i++) {
382 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
390 for (
x = 0;
x < edgeSize;
x++) {
393 f,
e, f_ed_idx, lvl,
x, 0, subdivLevels, vertDataSize, normalDataOffset));
403 for (
x = 0;
x < edgeSize;
x++) {
413 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
421 const int curLvl =
data->curLvl;
422 const int nextLvl = curLvl + 1;
432 for (
y = 0;
y < gridSize - 1;
y++) {
433 for (
x = 0;
x < gridSize - 1;
x++) {
452 for (
x = 0;
x < gridSize - 1;
x++) {
469 for (
x = 1;
x < gridSize - 1;
x++) {
470 for (
y = 0;
y < gridSize - 1;
y++) {
475 const float *co2 =
FACE_getIFCo(f, nextLvl, S, fx - 1, fy);
476 const float *co3 =
FACE_getIFCo(f, nextLvl, S, fx + 1, fy);
484 for (
y = 1;
y < gridSize - 1;
y++) {
485 for (
x = 0;
x < gridSize - 1;
x++) {
490 const float *co2 =
FACE_getIFCo(f, nextLvl, S, fx, fy - 1);
491 const float *co3 =
FACE_getIFCo(f, nextLvl, S, fx, fy + 1);
501 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
509 const int curLvl =
data->curLvl;
510 const int nextLvl = curLvl + 1;
514 float *q_thread =
static_cast<float *
>(alloca(vertDataSize));
515 float *r_thread =
static_cast<float *
>(alloca(vertDataSize));
546 for (
x = 1;
x < gridSize - 1;
x++) {
547 for (
y = 1;
y < gridSize - 1;
y++) {
579 for (
x = 1;
x < gridSize - 1;
x++) {
607 void *__restrict userdata,
const int ptrIdx,
const TaskParallelTLS *__restrict )
615 const int nextLvl =
data->curLvl + 1;
617 const int cornerIdx = gridSize - 1;
634 for (
x = 1;
x < gridSize - 1;
x++) {
639 for (
x = 0;
x < gridSize - 1;
x++) {
640 int eI = gridSize - 1 -
x;
642 static_cast<const float *
>(
646 static_cast<const float *
>(
657 const int numEffectedV,
658 const int numEffectedE,
659 const int numEffectedF,
663 const int nextLvl = curLvl + 1;
667 float *q =
static_cast<float *
>(ss->
q), *r =
static_cast<float *
>(ss->
r);
671 data.effectedV = effectedV;
672 data.effectedE = effectedE;
673 data.effectedF = effectedF;
674 data.numEffectedV = numEffectedV;
675 data.numEffectedE = numEffectedE;
676 data.numEffectedF = numEffectedF;
677 data.curLvl = curLvl;
695 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
701 for (
x = 0;
x < edgeSize - 1;
x++) {
713 for (
x = 0;
x < edgeSize - 1;
x++) {
723 for (j = 0; j <
e->numFaces; j++) {
728 f,
e, f_ed_idx, nextLvl, fx, 1, subdivLevels, vertDataSize)),
753 for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
757 int sharpCount = 0, allSharp = 1;
758 float avgSharpness = 0.0;
761 for (j = 0; j <
v->numEdges; j++) {
769 if (sharpness != 0.0f) {
771 avgSharpness += sharpness;
779 avgSharpness /= sharpCount;
780 avgSharpness = std::min(avgSharpness, 1.0f);
783 if (seamEdges < 2 || seamEdges != v->numEdges) {
794 for (j = 0; j <
v->numEdges; j++) {
798 r,
static_cast<const float *
>(
_edge_getCoVert(
e,
v, curLvl, 1, vertDataSize)), ss);
809 const int cornerIdx = (1 + (1 << (curLvl))) - 2;
810 int numEdges = 0, numFaces = 0;
813 for (j = 0; j <
v->numFaces; j++) {
821 for (j = 0; j <
v->numEdges; j++) {
824 r,
static_cast<const float *
>(
_edge_getCoVert(
e,
v, curLvl, 1, vertDataSize)), ss);
836 if ((sharpCount > 1 &&
v->numFaces) || seam) {
841 sharpCount = seamEdges;
845 for (j = 0; j <
v->numEdges; j++) {
852 q,
static_cast<const float *
>(
_edge_getCoVert(
e,
v, curLvl, 1, vertDataSize)), ss);
855 else if (sharpness != 0.0f) {
857 q,
static_cast<const float *
>(
_edge_getCoVert(
e,
v, curLvl, 1, vertDataSize)), ss);
863 if (sharpCount != 2 || allSharp) {
890 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
894 float avgSharpness = 0.0;
897 if (sharpness != 0.0f) {
899 avgSharpness += sharpness;
901 avgSharpness = std::min(avgSharpness, 1.0f);
909 for (
x = 1;
x < edgeSize - 1;
x++) {
927 for (
x = 1;
x < edgeSize - 1;
x++) {
937 for (j = 0; j <
e->numFaces; j++) {
942 f,
e, f_ed_idx, nextLvl, fx - 1, 1, subdivLevels, vertDataSize)),
946 f,
e, f_ed_idx, nextLvl, fx + 1, 1, subdivLevels, vertDataSize)),
951 f,
e, f_ed_idx, curLvl,
x, 1, subdivLevels, vertDataSize)),
964 if (sharpCount == 2) {
994 for (
i = 0;
i < numEffectedE;
i++) {
1014 int numEffectedV, numEffectedE, numEffectedF;
1017 int i, j, ptrIdx, S;
1018 int curLvl, nextLvl;
1019 void *q = ss->
q, *r = ss->
r;
1024 numEffectedV = numEffectedE = numEffectedF = 0;
1027 for (;
v;
v =
v->next) {
1029 effectedV[numEffectedV++] =
v;
1031 for (j = 0; j <
v->numEdges; j++) {
1034 effectedE[numEffectedE++] =
e;
1039 for (j = 0; j <
v->numFaces; j++) {
1042 effectedF[numEffectedF++] = f;
1051 nextLvl = curLvl + 1;
1053 for (ptrIdx = 0; ptrIdx < numEffectedF; ptrIdx++) {
1054 CCGFace *f = effectedF[ptrIdx];
1064 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
1078 for (
i = 0;
i <
e->numFaces;
i++) {
1083 VertDataMulN(
static_cast<float *
>(q), 1.0f / (2.0f + numFaces), ss);
1089 VertDataCopy(
static_cast<float *
>(co),
static_cast<const float *
>(q), ss);
1090 VertDataSub(
static_cast<float *
>(r),
static_cast<const float *
>(q), ss);
1092 VertDataAdd(
static_cast<float *
>(co),
static_cast<const float *
>(r), ss);
1097 for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
1101 int sharpCount = 0, allSharp = 1;
1102 float avgSharpness = 0.0;
1105 for (
i = 0;
i <
v->numEdges;
i++) {
1113 if (sharpness != 0.0f) {
1115 avgSharpness += sharpness;
1123 avgSharpness /= sharpCount;
1124 avgSharpness = std::min(avgSharpness, 1.0f);
1127 if (seamEdges < 2 || seamEdges != v->numEdges) {
1132 VertDataCopy(
static_cast<float *
>(nCo),
static_cast<const float *
>(co), ss);
1135 int numBoundary = 0;
1138 for (
i = 0;
i <
v->numEdges;
i++) {
1145 VertDataCopy(
static_cast<float *
>(nCo),
static_cast<const float *
>(co), ss);
1147 VertDataMulN(
static_cast<float *
>(r), 0.25f / numBoundary, ss);
1148 VertDataAdd(
static_cast<float *
>(nCo),
static_cast<const float *
>(r), ss);
1151 int numEdges = 0, numFaces = 0;
1154 for (
i = 0;
i <
v->numFaces;
i++) {
1159 VertDataMulN(
static_cast<float *
>(q), 1.0f / numFaces, ss);
1161 for (
i = 0;
i <
v->numEdges;
i++) {
1166 VertDataMulN(
static_cast<float *
>(r), 1.0f / numEdges, ss);
1168 VertDataCopy(
static_cast<float *
>(nCo),
static_cast<const float *
>(co), ss);
1169 VertDataMulN(
static_cast<float *
>(nCo), numEdges - 2.0f, ss);
1170 VertDataAdd(
static_cast<float *
>(nCo),
static_cast<const float *
>(q), ss);
1171 VertDataAdd(
static_cast<float *
>(nCo),
static_cast<const float *
>(r), ss);
1172 VertDataMulN(
static_cast<float *
>(nCo), 1.0f / numEdges, ss);
1175 if (sharpCount > 1 || seam) {
1179 avgSharpness = 1.0f;
1180 sharpCount = seamEdges;
1184 for (
i = 0;
i <
v->numEdges;
i++) {
1194 else if (sharpness != 0.0f) {
1200 VertDataMulN(
static_cast<float *
>(q),
float(1) / sharpCount, ss);
1202 if (sharpCount != 2 || allSharp) {
1204 VertDataCopy(
static_cast<float *
>(r),
static_cast<const float *
>(co), ss);
1205 VertDataSub(
static_cast<float *
>(r),
static_cast<const float *
>(q), ss);
1206 VertDataMulN(
static_cast<float *
>(r), avgSharpness, ss);
1207 VertDataAdd(
static_cast<float *
>(q),
static_cast<const float *
>(r), ss);
1211 VertDataCopy(
static_cast<float *
>(r),
static_cast<const float *
>(co), ss);
1214 VertDataAdd(
static_cast<float *
>(r),
static_cast<const float *
>(q), ss);
1217 VertDataSub(
static_cast<float *
>(r),
static_cast<const float *
>(nCo), ss);
1218 VertDataMulN(
static_cast<float *
>(r), avgSharpness, ss);
1219 VertDataAdd(
static_cast<float *
>(nCo),
static_cast<const float *
>(r), ss);
1226 for (
i = 0;
i < numEffectedV;
i++) {
1232 for (
i = 0;
i < numEffectedE;
i++) {
1238 for (
i = 0;
i < numEffectedF;
i++) {
1245 for (
i = 0;
i < numEffectedE;
i++) {
1250 for (
i = 0;
i < numEffectedF;
i++) {
1252 for (S = 0; S < f->
numVerts; S++) {
1264 static_cast<const float *
>(
1268 static_cast<const float *
>(
1274 for (curLvl = 1; curLvl < subdivLevels; curLvl++) {
1276 ss, effectedV, effectedE, effectedF, numEffectedV, numEffectedE, numEffectedF, curLvl);
1281 ss, effectedV, effectedE, effectedF, numEffectedV, numEffectedE, numEffectedF);
1284 for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
1288 for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
1297#ifdef DUMP_RESULT_GRIDS
1298 ccgSubSurf__dumpCoords(ss);
1308 int i, numEffectedV, numEffectedE, freeF;
1312 ss, effectedF, numEffectedF, &effectedV, &numEffectedV, &effectedE, &numEffectedE);
1316 ss, effectedV, effectedE, effectedF, numEffectedV, numEffectedE, numEffectedF);
1319 for (
i = 0;
i < numEffectedV;
i++) {
1322 for (
i = 0;
i < numEffectedE;
i++) {
1325 for (
i = 0;
i < numEffectedF;
i++) {
1342 int numEffectedV, numEffectedE, freeF,
i;
1347 ss, effectedF, numEffectedF, &effectedV, &numEffectedV, &effectedE, &numEffectedE);
1349 for (curLvl = lvl; curLvl < subdivLevels; curLvl++) {
1351 ss, effectedV, effectedE, effectedF, numEffectedV, numEffectedE, numEffectedF, curLvl);
1354 for (
i = 0;
i < numEffectedV;
i++) {
1357 for (
i = 0;
i < numEffectedE;
i++) {
1360 for (
i = 0;
i < numEffectedF;
i++) {
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 uint8_t * EDGE_getLevelData(CCGEdge *e)
BLI_INLINE void Normalize(float no[3])
BLI_INLINE CCGVert ** FACE_getVerts(CCGFace *f)
BLI_INLINE int ccg_gridsize(int level)
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 uint8_t * FACE_getCenterData(CCGFace *f)
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)
#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.
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)