diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-05-19 12:40:56 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-05-19 12:40:56 +0400 |
commit | a5152b7ca0d6d7f340b1955c0e8a15ba23fda336 (patch) | |
tree | 1b8289047b989964a442deb8f084a04d07f97b00 /source/blender/blenkernel/intern | |
parent | 8925ed1420ea2557abc7867cf12f89730ef77718 (diff) | |
parent | 65228807725d57aa4d33bcb8c3e3966d1acf0b8a (diff) |
Merged changes in the trunk up to revision 46787.
Conflicts resolved:
source/blender/blenkernel/intern/idcode.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/include/ED_anim_api.h
source/blender/editors/include/UI_resources.h
source/blender/makesrna/intern/rna_main.c
Diffstat (limited to 'source/blender/blenkernel/intern')
43 files changed, 3865 insertions, 5328 deletions
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c index 42c9fa84a91..6f768a147f7 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf.c +++ b/source/blender/blenkernel/intern/CCGSubSurf.c @@ -416,10 +416,10 @@ struct CCGSubSurf { static int VertDataEqual(const float a[], const float b[], const CCGSubSurf *ss) { int i; - for(i = 0; i < ss->meshIFC.numLayers; i++) { - if(a[i] != b[i]) + for (i = 0; i < ss->meshIFC.numLayers; i++) { + if (a[i] != b[i]) return 0; - } + } return 1; } @@ -431,38 +431,38 @@ static void VertDataZero(float v[], const CCGSubSurf *ss) static void VertDataCopy(float dst[], const float src[], const CCGSubSurf *ss) { int i; - for(i = 0; i < ss->meshIFC.numLayers; i++) + for (i = 0; i < ss->meshIFC.numLayers; i++) dst[i] = src[i]; } static void VertDataAdd(float a[], const float b[], const CCGSubSurf *ss) { int i; - for(i = 0; i < ss->meshIFC.numLayers; i++) + for (i = 0; i < ss->meshIFC.numLayers; i++) a[i] += b[i]; } static void VertDataSub(float a[], const float b[], const CCGSubSurf *ss) { int i; - for(i = 0; i < ss->meshIFC.numLayers; i++) + for (i = 0; i < ss->meshIFC.numLayers; i++) a[i] -= b[i]; } static void VertDataMulN(float v[], float f, const CCGSubSurf *ss) { int i; - for(i = 0; i < ss->meshIFC.numLayers; i++) + for (i = 0; i < ss->meshIFC.numLayers; i++) v[i] *= f; } static void VertDataAvg4(float v[], - const float a[], const float b[], - const float c[], const float d[], - const CCGSubSurf *ss) + const float a[], const float b[], + const float c[], const float d[], + const CCGSubSurf *ss) { int i; - for(i = 0; i < ss->meshIFC.numLayers; i++) + for (i = 0; i < ss->meshIFC.numLayers; i++) v[i] = (a[i] + b[i] + c[i] + d[i]) * 0.25f; } @@ -777,7 +777,7 @@ static float *_face_getIFNoEdge(CCGFace *f, CCGEdge *e, int f_ed_idx, int lvl, i { return (float *) ((byte *) _face_getIFCoEdge(f, e, f_ed_idx, lvl, eX, eY, levels, dataSize) + normalDataOffset); } -static void _face_calcIFNo(CCGFace *f, int lvl, int S, int x, int y, float *no, int levels, int dataSize) +static void _face_calcIFNo(CCGFace *f, int lvl, int S, int x, int y, float no[3], int levels, int dataSize) { float *a = _face_getIFCo(f, lvl, S, x + 0, y + 0, levels, dataSize); float *b = _face_getIFCo(f, lvl, S, x + 1, y + 0, levels, dataSize); @@ -1133,7 +1133,8 @@ CCGError ccgSubSurf_syncVert(CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertDa v->flags = Vert_eEffected | seamflag; } else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize), ss) || - ((v->flags & Vert_eSeam) != seamflag)) { + ((v->flags & Vert_eSeam) != seamflag)) + { int i, j; VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData, ss); @@ -1165,7 +1166,7 @@ CCGError ccgSubSurf_syncVert(CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertDa v->flags = Vert_eEffected | seamflag; } else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize), ss) || - ((v->flags & Vert_eSeam) != seamflag)) { + ((v->flags & Vert_eSeam) != seamflag)) { *prevp = v->next; _ehash_insert(ss->vMap, (EHEntry *) v); VertDataCopy(_vert_getCo(v, 0, ss->meshIFC.vertDataSize), vertData, ss); @@ -2001,10 +2002,10 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, } VertDataMulN(r, 1.0f / f->numVerts, ss); - VertDataMulN((float*)FACE_getCenterData(f), f->numVerts - 2.0f, ss); - VertDataAdd((float*)FACE_getCenterData(f), q, ss); - VertDataAdd((float*)FACE_getCenterData(f), r, ss); - VertDataMulN((float*)FACE_getCenterData(f), 1.0f / f->numVerts, ss); + VertDataMulN((float *)FACE_getCenterData(f), f->numVerts - 2.0f, ss); + VertDataAdd((float *)FACE_getCenterData(f), q, ss); + VertDataAdd((float *)FACE_getCenterData(f), r, ss); + VertDataMulN((float *)FACE_getCenterData(f), 1.0f / f->numVerts, ss); for (S = 0; S < f->numVerts; S++) { /* interior face shift @@ -2024,14 +2025,14 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, FACE_getIFCo(f, nextLvl, S, fx + 1, fy - 1), FACE_getIFCo(f, nextLvl, S, fx + 1, fy + 1), FACE_getIFCo(f, nextLvl, S, fx - 1, fy + 1), - ss); + ss); VertDataAvg4(r, FACE_getIFCo(f, nextLvl, S, fx - 1, fy + 0), FACE_getIFCo(f, nextLvl, S, fx + 1, fy + 0), FACE_getIFCo(f, nextLvl, S, fx + 0, fy - 1), FACE_getIFCo(f, nextLvl, S, fx + 0, fy + 1), - ss); + ss); VertDataCopy(nCo, co, ss); VertDataSub(nCo, q, ss); @@ -2061,7 +2062,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, FACE_getIECo(f, nextLvl, S, fx + 1), FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 1, fx), FACE_getIFCo(f, nextLvl, S, fx, 1), - ss); + ss); VertDataCopy(nCo, co, ss); VertDataSub(nCo, q, ss); @@ -2099,8 +2100,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts]; - VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), (float*)FACE_getCenterData(f), ss); - VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), (float *)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), (float *)FACE_getCenterData(f), ss); VertDataCopy(FACE_getIFCo(f, nextLvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], nextLvl), ss); VertDataCopy(FACE_getIECo(f, nextLvl, S, cornerIdx), EDGE_getCo(FACE_getEdges(f)[S], nextLvl, cornerIdx), ss); for (x = 1; x < gridSize - 1; x++) { @@ -2189,7 +2190,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) VertDataAdd(q, VERT_getCo(e->v1, curLvl), ss); for (i = 0; i < e->numFaces; i++) { CCGFace *f = e->faces[i]; - VertDataAdd(q, (float*)FACE_getCenterData(f), ss); + VertDataAdd(q, (float *)FACE_getCenterData(f), ss); numFaces++; } VertDataMulN(q, 1.0f / (2.0f + numFaces), ss); @@ -2265,7 +2266,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) VertDataZero(q, ss); for (i = 0; i < v->numFaces; i++) { CCGFace *f = v->faces[i]; - VertDataAdd(q, (float*)FACE_getCenterData(f), ss); + VertDataAdd(q, (float *)FACE_getCenterData(f), ss); numFaces++; } VertDataMulN(q, 1.0f / numFaces, ss); @@ -2365,8 +2366,8 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts]; - VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), (float*)FACE_getCenterData(f), ss); - VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), (float *)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), (float *)FACE_getCenterData(f), ss); VertDataCopy(FACE_getIFCo(f, nextLvl, S, 1, 1), VERT_getCo(FACE_getVerts(f)[S], nextLvl), ss); VertDataCopy(FACE_getIECo(f, nextLvl, S, 1), EDGE_getCo(FACE_getEdges(f)[S], nextLvl, 1), ss); @@ -2405,7 +2406,7 @@ static void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces CCGFace **array; int i, num; - if (!*faces) { + if (*faces == NULL) { array = MEM_mallocN(sizeof(*array) * ss->fMap->numEntries, "CCGSubsurf allFaces"); num = 0; for (i = 0; i < ss->fMap->curSize; i++) { @@ -2495,7 +2496,7 @@ CCGError ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts]; - VertDataCopy((float*)FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0), ss); + VertDataCopy((float *)FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0), ss); VertDataCopy(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), ss); for (x = 0; x < gridSize; x++) @@ -2546,7 +2547,7 @@ CCGError ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, VertDataCopy(FACE_getIFCo(f, lvl, S, x, 0), FACE_getIECo(f, lvl, S, x), ss); } - VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), (float *)FACE_getCenterData(f), ss); VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], lvl), ss); } } @@ -2595,7 +2596,7 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in for (i = 0; i < numEffectedF; i++) { CCGFace *f = effectedF[i]; - VertDataZero((float*)FACE_getCenterData(f), ss); + VertDataZero((float *)FACE_getCenterData(f), ss); for (S = 0; S < f->numVerts; S++) for (x = 0; x < gridSize; x++) @@ -2606,7 +2607,7 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[prevS]; - VertDataAdd((float*)FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0), ss); + VertDataAdd((float *)FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0), ss); if (FACE_getVerts(f)[S]->flags & Vert_eEffected) VertDataAdd(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), ss); @@ -2648,7 +2649,7 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in for (i = 0; i < numEffectedF; i++) { CCGFace *f = effectedF[i]; - VertDataMulN((float*)FACE_getCenterData(f), 1.0f / f->numVerts, ss); + VertDataMulN((float *)FACE_getCenterData(f), 1.0f / f->numVerts, ss); for (S = 0; S < f->numVerts; S++) for (x = 1; x < gridSize - 1; x++) @@ -2659,7 +2660,7 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in CCGEdge *e = FACE_getEdges(f)[S]; CCGEdge *prevE = FACE_getEdges(f)[prevS]; - VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), (float *)FACE_getCenterData(f), ss); VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], lvl), ss); for (x = 1; x < gridSize - 1; x++) { @@ -2674,7 +2675,7 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in VertDataCopy(FACE_getIFCo(f, lvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI, vertDataSize), ss); } - VertDataCopy(FACE_getIECo(f, lvl, S, 0), (float*)FACE_getCenterData(f), ss); + VertDataCopy(FACE_getIECo(f, lvl, S, 0), (float *)FACE_getCenterData(f), ss); VertDataCopy(FACE_getIECo(f, lvl, S, gridSize - 1), FACE_getIFCo(f, lvl, S, gridSize - 1, 0), ss); } } @@ -3126,7 +3127,7 @@ void CCG_key(CCGKey *key, const CCGSubSurf *ss, int level) key->num_layers = ss->meshIFC.numLayers; /* if normals are present, always the last three floats of an - element */ + * element */ if (key->has_normals) key->normal_offset = key->elem_size - sizeof(float) * 3; else diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 50c10ea3c3d..18560d3dbc0 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -95,7 +95,7 @@ static MVert *dm_getVertArray(DerivedMesh *dm) if (!mvert) { mvert = CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, - dm->getNumVerts(dm)); + dm->getNumVerts(dm)); CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY); dm->copyVertArray(dm, mvert); } @@ -109,7 +109,7 @@ static MEdge *dm_getEdgeArray(DerivedMesh *dm) if (!medge) { medge = CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, - dm->getNumEdges(dm)); + dm->getNumEdges(dm)); CustomData_set_layer_flag(&dm->edgeData, CD_MEDGE, CD_FLAG_TEMPORARY); dm->copyEdgeArray(dm, medge); } @@ -146,7 +146,7 @@ static MLoop *dm_getLoopArray(DerivedMesh *dm) if (!mloop) { mloop = CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL, - dm->getNumLoops(dm)); + dm->getNumLoops(dm)); CustomData_set_layer_flag(&dm->loopData, CD_MLOOP, CD_FLAG_TEMPORARY); dm->copyLoopArray(dm, mloop); } @@ -160,7 +160,7 @@ static MPoly *dm_getPolyArray(DerivedMesh *dm) if (!mpoly) { mpoly = CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL, - dm->getNumPolys(dm)); + dm->getNumPolys(dm)); CustomData_set_layer_flag(&dm->polyData, CD_MPOLY, CD_FLAG_TEMPORARY); dm->copyPolyArray(dm, mpoly); } @@ -171,7 +171,7 @@ static MPoly *dm_getPolyArray(DerivedMesh *dm) static MVert *dm_dupVertArray(DerivedMesh *dm) { MVert *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumVerts(dm), - "dm_dupVertArray tmp"); + "dm_dupVertArray tmp"); if (tmp) dm->copyVertArray(dm, tmp); @@ -181,7 +181,7 @@ static MVert *dm_dupVertArray(DerivedMesh *dm) static MEdge *dm_dupEdgeArray(DerivedMesh *dm) { MEdge *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumEdges(dm), - "dm_dupEdgeArray tmp"); + "dm_dupEdgeArray tmp"); if (tmp) dm->copyEdgeArray(dm, tmp); @@ -191,7 +191,7 @@ static MEdge *dm_dupEdgeArray(DerivedMesh *dm) static MFace *dm_dupFaceArray(DerivedMesh *dm) { MFace *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumTessFaces(dm), - "dm_dupFaceArray tmp"); + "dm_dupFaceArray tmp"); if (tmp) dm->copyTessFaceArray(dm, tmp); @@ -201,7 +201,7 @@ static MFace *dm_dupFaceArray(DerivedMesh *dm) static MLoop *dm_dupLoopArray(DerivedMesh *dm) { MLoop *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumLoops(dm), - "dm_dupLoopArray tmp"); + "dm_dupLoopArray tmp"); if (tmp) dm->copyLoopArray(dm, tmp); @@ -211,7 +211,7 @@ static MLoop *dm_dupLoopArray(DerivedMesh *dm) static MPoly *dm_dupPolyArray(DerivedMesh *dm) { MPoly *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumPolys(dm), - "dm_dupPolyArray tmp"); + "dm_dupPolyArray tmp"); if (tmp) dm->copyPolyArray(dm, tmp); @@ -295,11 +295,11 @@ void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type int numLoops, int numPolys) { CustomData_copy(&source->vertData, &dm->vertData, CD_MASK_DERIVEDMESH, - CD_CALLOC, numVerts); + CD_CALLOC, numVerts); CustomData_copy(&source->edgeData, &dm->edgeData, CD_MASK_DERIVEDMESH, - CD_CALLOC, numEdges); + CD_CALLOC, numEdges); CustomData_copy(&source->faceData, &dm->faceData, CD_MASK_DERIVEDMESH, - CD_CALLOC, numTessFaces); + CD_CALLOC, numTessFaces); CustomData_copy(&source->loopData, &dm->loopData, CD_MASK_DERIVEDMESH, CD_CALLOC, numLoops); CustomData_copy(&source->polyData, &dm->polyData, CD_MASK_DERIVEDMESH, @@ -463,7 +463,7 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob) /* dm might depend on me, so we need to do everything with a local copy */ Mesh tmp = *me; int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly; - int did_shapekeys=0; + int did_shapekeys = 0; memset(&tmp.vdata, 0, sizeof(tmp.vdata)); memset(&tmp.edata, 0, sizeof(tmp.edata)); @@ -486,13 +486,13 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob) int uid; if (ob) { - kb = BLI_findlink(&me->key->block, ob->shapenr-1); + kb = BLI_findlink(&me->key->block, ob->shapenr - 1); if (kb) { uid = kb->uid; } else { printf("%s: error - could not find active shapekey %d!\n", - __func__, ob->shapenr-1); + __func__, ob->shapenr - 1); uid = INT_MAX; } @@ -558,16 +558,16 @@ void DM_to_meshkey(DerivedMesh *dm, Mesh *me, KeyBlock *kb) float *fp; MVert *mvert; - if (totvert==0 || me->totvert==0 || me->totvert!=totvert) return; + if (totvert == 0 || me->totvert == 0 || me->totvert != totvert) return; if (kb->data) MEM_freeN(kb->data); - kb->data= MEM_callocN(me->key->elemsize*me->totvert, "kb->data"); - kb->totelem= totvert; + kb->data = MEM_callocN(me->key->elemsize * me->totvert, "kb->data"); + kb->totelem = totvert; - fp= kb->data; - mvert=dm->getVertDataArray(dm, CD_MVERT); + fp = kb->data; + mvert = dm->getVertDataArray(dm, CD_MVERT); - for (a=0; a<kb->totelem; a++, fp+=3, mvert++) { + for (a = 0; a < kb->totelem; a++, fp += 3, mvert++) { copy_v3_v3(fp, mvert->co); } } @@ -669,24 +669,24 @@ void DM_set_tessface_data(DerivedMesh *dm, int index, int type, void *data) } void DM_copy_vert_data(DerivedMesh *source, DerivedMesh *dest, - int source_index, int dest_index, int count) + int source_index, int dest_index, int count) { CustomData_copy_data(&source->vertData, &dest->vertData, - source_index, dest_index, count); + source_index, dest_index, count); } void DM_copy_edge_data(DerivedMesh *source, DerivedMesh *dest, - int source_index, int dest_index, int count) + int source_index, int dest_index, int count) { CustomData_copy_data(&source->edgeData, &dest->edgeData, - source_index, dest_index, count); + source_index, dest_index, count); } void DM_copy_tessface_data(DerivedMesh *source, DerivedMesh *dest, - int source_index, int dest_index, int count) + int source_index, int dest_index, int count) { CustomData_copy_data(&source->faceData, &dest->faceData, - source_index, dest_index, count); + source_index, dest_index, count); } void DM_copy_loop_data(DerivedMesh *source, DerivedMesh *dest, @@ -729,29 +729,29 @@ void DM_free_poly_data(struct DerivedMesh *dm, int index, int count) } void DM_interp_vert_data(DerivedMesh *source, DerivedMesh *dest, - int *src_indices, float *weights, - int count, int dest_index) + int *src_indices, float *weights, + int count, int dest_index) { CustomData_interp(&source->vertData, &dest->vertData, src_indices, - weights, NULL, count, dest_index); + weights, NULL, count, dest_index); } void DM_interp_edge_data(DerivedMesh *source, DerivedMesh *dest, - int *src_indices, - float *weights, EdgeVertWeight *vert_weights, - int count, int dest_index) + int *src_indices, + float *weights, EdgeVertWeight *vert_weights, + int count, int dest_index) { CustomData_interp(&source->edgeData, &dest->edgeData, src_indices, - weights, (float*)vert_weights, count, dest_index); + weights, (float *)vert_weights, count, dest_index); } void DM_interp_tessface_data(DerivedMesh *source, DerivedMesh *dest, - int *src_indices, - float *weights, FaceVertWeight *vert_weights, - int count, int dest_index) + int *src_indices, + float *weights, FaceVertWeight *vert_weights, + int count, int dest_index) { CustomData_interp(&source->faceData, &dest->faceData, src_indices, - weights, (float*)vert_weights, count, dest_index); + weights, (float *)vert_weights, count, dest_index); } void DM_swap_tessface_data(DerivedMesh *dm, int index, const int *corner_indices) @@ -801,16 +801,16 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, DerivedMesh *dm; KeyBlock *kb; - md->scene= scene; + md->scene = scene; - if (!(md->mode&eModifierMode_Realtime)) return NULL; + if (!(md->mode & eModifierMode_Realtime)) return NULL; if (mti->isDisabled && mti->isDisabled(md, 0)) return NULL; - if (build_shapekey_layers && me->key && (kb = BLI_findlink(&me->key->block, ob->shapenr-1))) { + if (build_shapekey_layers && me->key && (kb = BLI_findlink(&me->key->block, ob->shapenr - 1))) { key_to_mesh(kb, me); } - if (mti->type==eModifierTypeType_OnlyDeform) { + if (mti->type == eModifierTypeType_OnlyDeform) { int numVerts; float (*deformedVerts)[3] = mesh_getVertexCos(me, &numVerts); @@ -846,13 +846,13 @@ static float *get_editbmesh_orco_verts(BMEditMesh *em) /* these may not really be the orco's, but it's only for preview. * could be solver better once, but isn't simple */ - totvert= em->bm->totvert; + totvert = em->bm->totvert; - orco = MEM_mallocN(sizeof(float)*3*totvert, "BMEditMesh Orco"); + orco = MEM_mallocN(sizeof(float) * 3 * totvert, "BMEditMesh Orco"); eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for (a=0; eve; eve=BM_iter_step(&iter), a+=3) { - copy_v3_v3(orco+a, eve->co); + for (a = 0; eve; eve = BM_iter_step(&iter), a += 3) { + copy_v3_v3(orco + a, eve->co); } return orco; @@ -861,11 +861,11 @@ static float *get_editbmesh_orco_verts(BMEditMesh *em) /* orco custom data layer */ static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free) { - *free= 0; + *free = 0; if (layer == CD_ORCO) { /* get original coordinates */ - *free= 1; + *free = 1; if (em) return (float(*)[3])get_editbmesh_orco_verts(em); @@ -877,7 +877,7 @@ static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free * by a more flexible customdata system, but not simple */ if (!em) { ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); - KeyBlock *kb= key_get_keyblock(ob_get_key(ob), clmd->sim_parms->shapekey_rest); + KeyBlock *kb = key_get_keyblock(ob_get_key(ob), clmd->sim_parms->shapekey_rest); if (kb->data) return kb->data; @@ -895,10 +895,10 @@ static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int lay float (*orco)[3]; int free; - if (em) dm= CDDM_from_BMEditMesh(em, me, FALSE, FALSE); - else dm= CDDM_from_mesh(me, ob); + if (em) dm = CDDM_from_BMEditMesh(em, me, FALSE, FALSE); + else dm = CDDM_from_mesh(me, ob); - orco= get_orco_coords_dm(ob, em, layer, &free); + orco = get_orco_coords_dm(ob, em, layer, &free); if (orco) { CDDM_apply_vert_coords(dm, orco); @@ -911,16 +911,16 @@ static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int lay } static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, - DerivedMesh *orcodm, int layer) + DerivedMesh *orcodm, int layer) { float (*orco)[3], (*layerorco)[3]; int totvert, free; - totvert= dm->getNumVerts(dm); + totvert = dm->getNumVerts(dm); if (orcodm) { - orco= MEM_callocN(sizeof(float)*3*totvert, "dm orco"); - free= 1; + orco = MEM_callocN(sizeof(float) * 3 * totvert, "dm orco"); + free = 1; if (orcodm->getNumVerts(orcodm) == totvert) orcodm->getVertCos(orcodm, orco); @@ -928,7 +928,7 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, dm->getVertCos(dm, orco); } else - orco= get_orco_coords_dm(ob, em, layer, &free); + orco = get_orco_coords_dm(ob, em, layer, &free); if (orco) { if (layer == CD_ORCO) @@ -939,7 +939,7 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, layerorco = DM_get_vert_data_layer(dm, layer); } - memcpy(layerorco, orco, sizeof(float)*3*totvert); + memcpy(layerorco, orco, sizeof(float) * 3 * totvert); if (free) MEM_freeN(orco); } } @@ -954,41 +954,41 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, void weight_to_rgb(float r_rgb[3], const float weight) { - const float blend= ((weight/2.0f)+0.5f); + const float blend = ((weight / 2.0f) + 0.5f); - if (weight<=0.25f) { // blue->cyan - r_rgb[0]= 0.0f; - r_rgb[1]= blend*weight*4.0f; - r_rgb[2]= blend; + if (weight <= 0.25f) { // blue->cyan + r_rgb[0] = 0.0f; + r_rgb[1] = blend * weight * 4.0f; + r_rgb[2] = blend; } - else if (weight<=0.50f) { // cyan->green - r_rgb[0]= 0.0f; - r_rgb[1]= blend; - r_rgb[2]= blend*(1.0f-((weight-0.25f)*4.0f)); + else if (weight <= 0.50f) { // cyan->green + r_rgb[0] = 0.0f; + r_rgb[1] = blend; + r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f)); } - else if (weight <= 0.75f) { // green->yellow - r_rgb[0]= blend * ((weight-0.50f)*4.0f); - r_rgb[1]= blend; - r_rgb[2]= 0.0f; + else if (weight <= 0.75f) { // green->yellow + r_rgb[0] = blend * ((weight - 0.50f) * 4.0f); + r_rgb[1] = blend; + r_rgb[2] = 0.0f; } else if (weight <= 1.0f) { // yellow->red - r_rgb[0]= blend; - r_rgb[1]= blend * (1.0f-((weight-0.75f)*4.0f)); - r_rgb[2]= 0.0f; + r_rgb[0] = blend; + r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f)); + r_rgb[2] = 0.0f; } else { /* exceptional value, unclamped or nan, * avoid uninitialized memory use */ - r_rgb[0]= 1.0f; - r_rgb[1]= 0.0f; - r_rgb[2]= 1.0f; + r_rgb[0] = 1.0f; + r_rgb[1] = 0.0f; + r_rgb[2] = 1.0f; } } /* draw_flag's for calc_weightpaint_vert_color */ enum { - CALC_WP_MULTIPAINT= (1<<0), - CALC_WP_AUTO_NORMALIZE= (1<<1) + CALC_WP_MULTIPAINT = (1 << 0), + CALC_WP_AUTO_NORMALIZE = (1 << 1) }; static void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input) @@ -1020,13 +1020,13 @@ static void calc_weightpaint_vert_color( { float input = 0.0f; - int make_black= FALSE; + int make_black = FALSE; if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { - int was_a_nonzero= FALSE; + int was_a_nonzero = FALSE; unsigned int i; - MDeformWeight *dw= dv->dw; + MDeformWeight *dw = dv->dw; for (i = dv->totweight; i != 0; i--, dw++) { /* in multipaint, get the average if auto normalize is inactive * get the sum if it is active */ @@ -1034,7 +1034,7 @@ static void calc_weightpaint_vert_color( if (dg_flags[dw->def_nr]) { if (dw->weight) { input += dw->weight; - was_a_nonzero= TRUE; + was_a_nonzero = TRUE; } } } @@ -1050,7 +1050,7 @@ static void calc_weightpaint_vert_color( } else { /* default, non tricky behavior */ - input= defvert_find_weight(dv, defbase_act); + input = defvert_find_weight(dv, defbase_act); } if (make_black) { /* TODO, theme color */ @@ -1065,11 +1065,11 @@ static void calc_weightpaint_vert_color( } } -static ColorBand *stored_cb= NULL; +static ColorBand *stored_cb = NULL; void vDM_ColorBand_store(ColorBand *coba) { - stored_cb= coba; + stored_cb = coba; } /* return an array of vertex weight colors, caller must free. @@ -1081,7 +1081,7 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i { MDeformVert *dv = DM_get_vert_data_layer(dm, CD_MDEFORMVERT); int numVerts = dm->getNumVerts(dm); - unsigned char *wtcol_v = MEM_mallocN (sizeof(unsigned char) * numVerts * 4, "weightmap_v"); + unsigned char *wtcol_v = MEM_mallocN(sizeof(unsigned char) * numVerts * 4, "weightmap_v"); if (dv) { unsigned char *wc = wtcol_v; @@ -1089,7 +1089,7 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i /* variables for multipaint */ const int defbase_tot = BLI_countlist(&ob->defbase); - const int defbase_act = ob->actdef-1; + const int defbase_act = ob->actdef - 1; char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__); const int selected = get_selected_defgroups(ob, dg_flags, defbase_tot); @@ -1128,7 +1128,7 @@ static unsigned char *calc_colors_from_weights_array(const int num, float *weigh void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, float *weights, int num, const int *indices) { - ColorBand *coba= stored_cb; /* warning, not a local var */ + ColorBand *coba = stored_cb; /* warning, not a local var */ unsigned char *wtcol_v; #if 0 /* See coment below. */ @@ -1148,7 +1148,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, int i, j; #if 0 /* See comment below */ - /* If no CD_PREVIEW_MCOL existed yet, add a new one! */ + /* If no CD_PREVIEW_MCOL existed yet, add a new one! */ if (!wtcol_f) wtcol_f = CustomData_add_layer(&dm->faceData, CD_PREVIEW_MCOL, CD_CALLOC, NULL, numFaces); @@ -1170,7 +1170,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, /* If indices is not NULL, it means we do not have weights for all vertices, * so we must create them (and set them to zero)... */ if (indices) { - w = MEM_callocN(sizeof(float)*numVerts, "Temp weight array DM_update_weight_mcol"); + w = MEM_callocN(sizeof(float) * numVerts, "Temp weight array DM_update_weight_mcol"); i = num; while (i--) w[indices[i]] = weights[i]; @@ -1196,9 +1196,9 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, for (i = 0; i < numFaces; i++, mf++, wtcol_f_step += (4 * 4)) { /*origindex being NULL means we're operating on original mesh data*/ #if 0 - unsigned int fidx= mf->v4 ? 3:2; + unsigned int fidx = mf->v4 ? 3 : 2; -#else /* better zero out triangles 4th component. else valgrind complains when the buffer's copied */ +#else /* better zero out triangles 4th component. else valgrind complains when the buffer's copied */ unsigned int fidx; if (mf->v4) { fidx = 3; @@ -1220,7 +1220,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, if (!wtcol_l) { BLI_array_declare(wtcol_l); totloop = 0; - for (i=0; i<dm->numPolyData; i++, mp++) { + for (i = 0; i < dm->numPolyData; i++, mp++) { ml = mloop + mp->loopstart; BLI_array_grow_items(wtcol_l, mp->totloop); @@ -1233,10 +1233,10 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, } else { totloop = 0; - for (i=0; i < dm->numPolyData; i++, mp++) { + for (i = 0; i < dm->numPolyData; i++, mp++) { ml = mloop + mp->loopstart; - for (j=0; j < mp->totloop; j++, ml++, totloop++) { + for (j = 0; j < mp->totloop; j++, ml++, totloop++) { copy_v4_v4_char((char *)&wtcol_l[totloop], (char *)&wtcol_v[4 * ml->v]); } @@ -1258,11 +1258,11 @@ static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape return; tot = CustomData_number_of_layers(&dm->vertData, CD_SHAPEKEY); - for (i=0; i<tot; i++) { + for (i = 0; i < tot; i++) { CustomDataLayer *layer = &dm->vertData.layers[CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i)]; float (*cos)[3], (*kbcos)[3]; - for (kb=me->key->block.first; kb; kb=kb->next) { + for (kb = me->key->block.first; kb; kb = kb->next) { if (kb->uid == layer->uid) break; } @@ -1278,28 +1278,28 @@ static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape cos = CustomData_get_layer_n(&dm->vertData, CD_SHAPEKEY, i); kb->totelem = dm->numVertData; - kb->data = kbcos = MEM_mallocN(sizeof(float)*3*kb->totelem, "kbcos DerivedMesh.c"); + kb->data = kbcos = MEM_mallocN(sizeof(float) * 3 * kb->totelem, "kbcos DerivedMesh.c"); if (kb->uid == actshape_uid) { MVert *mvert = dm->getVertArray(dm); - for (j=0; j<dm->numVertData; j++, kbcos++, mvert++) { + for (j = 0; j < dm->numVertData; j++, kbcos++, mvert++) { copy_v3_v3(*kbcos, mvert->co); } } else { - for (j=0; j<kb->totelem; j++, cos++, kbcos++) { + for (j = 0; j < kb->totelem; j++, cos++, kbcos++) { copy_v3_v3(*kbcos, *cos); } } } - for (kb=me->key->block.first; kb; kb=kb->next) { + for (kb = me->key->block.first; kb; kb = kb->next) { if (kb->totelem != dm->numVertData) { if (kb->data) MEM_freeN(kb->data); kb->totelem = dm->numVertData; - kb->data = MEM_callocN(sizeof(float)*3*kb->totelem, "kb->data derivedmesh.c"); + kb->data = MEM_callocN(sizeof(float) * 3 * kb->totelem, "kb->data derivedmesh.c"); fprintf(stderr, "%s: lost a shapekey layer: '%s'! (bmesh internal error)\n", __func__, kb->name); } } @@ -1319,11 +1319,11 @@ static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob)) if (me->totvert != dm->getNumVerts(dm)) { fprintf(stderr, "%s: vertex size mismatch (mesh/dm) '%s' (%d != %d)\n", - __func__, me->id.name+2, me->totvert, dm->getNumVerts(dm)); + __func__, me->id.name + 2, me->totvert, dm->getNumVerts(dm)); return; } - for (i=0, kb=key->block.first; kb; kb=kb->next, i++) { + for (i = 0, kb = key->block.first; kb; kb = kb->next, i++) { int ci; float *array; @@ -1351,10 +1351,10 @@ static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob)) * - apply deform modifiers and input vertexco */ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos)[3], - DerivedMesh **deform_r, DerivedMesh **final_r, - int useRenderParams, int useDeform, - int needMapping, CustomDataMask dataMask, - int index, int useCache, int build_shapekey_layers) + DerivedMesh **deform_r, DerivedMesh **final_r, + int useRenderParams, int useDeform, + int needMapping, CustomDataMask dataMask, + int index, int useCache, int build_shapekey_layers) { Mesh *me = ob->data; ModifierData *firstmd, *md, *previewmd = NULL; @@ -1362,17 +1362,17 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* XXX Always copying POLYINDEX, else tessellated data are no more valid! */ CustomDataMask mask, nextmask, append_mask = CD_MASK_POLYINDEX; float (*deformedVerts)[3] = NULL; - DerivedMesh *dm=NULL, *orcodm, *clothorcodm, *finaldm; + DerivedMesh *dm = NULL, *orcodm, *clothorcodm, *finaldm; int numVerts = me->totvert; int required_mode; - int isPrevDeform= FALSE; + int isPrevDeform = FALSE; int skipVirtualArmature = (useDeform < 0); - MultiresModifierData *mmd= get_multires_modifier(scene, ob, 0); + MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0); int has_multires = mmd != NULL, multires_applied = 0; int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt; - const int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | - (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); + const int draw_flag = ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | + (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); /* Generic preview only in object mode! */ const int do_mod_mcol = (ob->mode == OB_MODE_OBJECT); #if 0 /* XXX Will re-enable this when we have global mod stack options. */ @@ -1385,9 +1385,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos ModifierApplyFlag app_flags = useRenderParams ? MOD_APPLY_RENDER : 0; ModifierApplyFlag deform_app_flags = app_flags; - if (useCache) + if (useCache) app_flags |= MOD_APPLY_USECACHE; - if (useDeform) + if (useDeform) deform_app_flags |= MOD_APPLY_USECACHE; if (mmd && !mmd->sculptlvl) @@ -1429,10 +1429,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos deformedVerts = inputVertexCos; /* Apply all leading deforming modifiers */ - for (;md; md = md->next, curr = curr->next) { + for (; md; md = md->next, curr = curr->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; if (!modifier_isEnabled(scene, md, required_mode)) continue; if (useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) continue; @@ -1484,10 +1484,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos orcodm = NULL; clothorcodm = NULL; - for (;md; md = md->next, curr = curr->next) { + for (; md; md = md->next, curr = curr->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; if (!modifier_isEnabled(scene, md, required_mode)) continue; if (mti->type == eModifierTypeType_OnlyDeform && !useDeform) continue; @@ -1496,13 +1496,13 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos continue; } if (sculpt_mode && (!has_multires || multires_applied)) { - int unsupported= 0; + int unsupported = 0; if (scene->toolsettings->sculpt->flags & SCULPT_ONLY_DEFORM) - unsupported|= mti->type != eModifierTypeType_OnlyDeform; + unsupported |= mti->type != eModifierTypeType_OnlyDeform; - unsupported|= md->type == eModifierType_Multires && ((MultiresModifierData*)md)->sculptlvl==0; - unsupported|= multires_applied; + unsupported |= md->type == eModifierType_Multires && ((MultiresModifierData *)md)->sculptlvl == 0; + unsupported |= multires_applied; if (unsupported) { modifier_setError(md, "%s", TIP_("Not supported in sculpt mode.")); @@ -1536,7 +1536,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos */ numVerts = dm->getNumVerts(dm); deformedVerts = - MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv"); + MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv"); dm->getVertCos(dm, deformedVerts); } else { @@ -1561,9 +1561,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* determine which data layers are needed by following modifiers */ if (curr->next) - nextmask= curr->next->mask; + nextmask = curr->next->mask; else - nextmask= dataMask; + nextmask = dataMask; /* apply vertex coordinates or build a DerivedMesh as necessary */ if (dm) { @@ -1611,7 +1611,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* set the DerivedMesh to only copy needed data */ - mask= curr->mask; + mask = curr->mask; /* needMapping check here fixes bug [#28112], otherwise its * possible that it wont be copied */ mask |= append_mask; @@ -1648,7 +1648,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* create an orco derivedmesh in parallel */ if (nextmask & CD_MASK_ORCO) { if (!orcodm) - orcodm= create_orco_dm(ob, me, NULL, CD_ORCO); + orcodm = create_orco_dm(ob, me, NULL, CD_ORCO); nextmask &= ~CD_MASK_ORCO; DM_set_only_copy(orcodm, nextmask | CD_MASK_ORIGINDEX); @@ -1664,7 +1664,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* create cloth orco derivedmesh in parallel */ if (nextmask & CD_MASK_CLOTH_ORCO) { if (!clothorcodm) - clothorcodm= create_orco_dm(ob, me, NULL, CD_CLOTH_ORCO); + clothorcodm = create_orco_dm(ob, me, NULL, CD_CLOTH_ORCO); nextmask &= ~CD_MASK_CLOTH_ORCO; DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX); @@ -1688,7 +1688,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } } - isPrevDeform= (mti->type == eModifierTypeType_OnlyDeform); + isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform); /* grab modifiers until index i */ if ((index >= 0) && (modifiers_indexInObject(ob, md) >= index)) @@ -1698,7 +1698,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos multires_applied = 1; } - for (md=firstmd; md; md=md->next) + for (md = firstmd; md; md = md->next) modifier_freeTemporaryData(md); /* Yay, we are done. If we have a DerivedMesh and deformed vertices @@ -1729,18 +1729,18 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos #endif } else { - int recalc_normals= 0; + int recalc_normals = 0; finaldm = CDDM_from_mesh(me, ob); if (build_shapekey_layers) { add_shapekey_layers(finaldm, me, ob); - recalc_normals= 1; + recalc_normals = 1; } if (deformedVerts) { CDDM_apply_vert_coords(finaldm, deformedVerts); - recalc_normals= 1; + recalc_normals = 1; } if (recalc_normals) { @@ -1819,10 +1819,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* NavMesh - this is a hack but saves having a NavMesh modifier */ if ((ob->gameflag & OB_NAVMESH) && (finaldm->type == DM_TYPE_CDDM)) { DerivedMesh *tdm; - tdm= navmesh_dm_createNavMeshForVisualization(finaldm); + tdm = navmesh_dm_createNavMeshForVisualization(finaldm); if (finaldm != tdm) { finaldm->release(finaldm); - finaldm= tdm; + finaldm = tdm; } } #endif /* WITH_GAMEENGINE */ @@ -1837,20 +1837,20 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos if (deformedVerts && deformedVerts != inputVertexCos) MEM_freeN(deformedVerts); - BLI_linklist_free((LinkNode*)datamasks, NULL); + BLI_linklist_free((LinkNode *)datamasks, NULL); } -float (*editbmesh_get_vertex_cos(BMEditMesh *em, int *numVerts_r))[3] +float (*editbmesh_get_vertex_cos(BMEditMesh * em, int *numVerts_r))[3] { int i, numVerts = *numVerts_r = em->bm->totvert; float (*cos)[3]; BMIter iter; BMVert *eve; - cos = MEM_mallocN(sizeof(float)*3*numVerts, "vertexcos"); + cos = MEM_mallocN(sizeof(float) * 3 * numVerts, "vertexcos"); eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for (i=0; eve; eve=BM_iter_step(&iter), i++) { + for (i = 0; eve; eve = BM_iter_step(&iter), i++) { copy_v3_v3(cos[i], eve->co); } @@ -1872,8 +1872,8 @@ int editbmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh *d } static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, DerivedMesh **cage_r, - DerivedMesh **final_r, - CustomDataMask dataMask) + DerivedMesh **final_r, + CustomDataMask dataMask) { ModifierData *md; float (*deformedVerts)[3] = NULL; @@ -1898,7 +1898,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D for (i = 0; md; i++, md = md->next, curr = curr->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; if (!editbmesh_modifier_is_enabled(scene, md, dm)) continue; @@ -1925,7 +1925,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D */ numVerts = dm->getNumVerts(dm); deformedVerts = - MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv"); + MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv"); dm->getVertCos(dm, deformedVerts); } else { @@ -1968,10 +1968,10 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D } /* create an orco derivedmesh in parallel */ - mask= curr->mask; + mask = curr->mask; if (mask & CD_MASK_ORCO) { if (!orcodm) - orcodm= create_orco_dm(ob, ob->data, em, CD_ORCO); + orcodm = create_orco_dm(ob, ob->data, em, CD_ORCO); mask &= ~CD_MASK_ORCO; DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX); @@ -1989,7 +1989,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D } /* set the DerivedMesh to only copy needed data */ - mask= curr->mask; /* CD_MASK_ORCO may have been cleared above */ + mask = curr->mask; /* CD_MASK_ORCO may have been cleared above */ DM_set_only_copy(dm, mask | CD_MASK_ORIGINDEX); @@ -2028,13 +2028,13 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D } else { *cage_r = - getEditDerivedBMesh(em, ob, - deformedVerts ? MEM_dupallocN(deformedVerts) : NULL); + getEditDerivedBMesh(em, ob, + deformedVerts ? MEM_dupallocN(deformedVerts) : NULL); } } } - BLI_linklist_free((LinkNode*)datamasks, NULL); + BLI_linklist_free((LinkNode *)datamasks, NULL); /* Yay, we are done. If we have a DerivedMesh and deformed vertices need * to apply these back onto the DerivedMesh. If we have no DerivedMesh @@ -2093,9 +2093,9 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D static void clear_mesh_caches(Object *ob) { - Mesh *me= ob->data; + Mesh *me = ob->data; - /* also serves as signal to remake texspace */ + /* also serves as signal to remake texspace */ if (ob->bb) { MEM_freeN(ob->bb); ob->bb = NULL; @@ -2110,12 +2110,12 @@ static void clear_mesh_caches(Object *ob) if (ob->derivedFinal) { ob->derivedFinal->needsFree = 1; ob->derivedFinal->release(ob->derivedFinal); - ob->derivedFinal= NULL; + ob->derivedFinal = NULL; } if (ob->derivedDeform) { ob->derivedDeform->needsFree = 1; ob->derivedDeform->release(ob->derivedDeform); - ob->derivedDeform= NULL; + ob->derivedDeform = NULL; } if (ob->sculpt) { @@ -2126,18 +2126,18 @@ static void clear_mesh_caches(Object *ob) static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask, int build_shapekey_layers) { - Object *obact = scene->basact?scene->basact->object:NULL; + Object *obact = scene->basact ? scene->basact->object : NULL; int editing = paint_facesel_test(ob); /* weight paint and face select need original indices because of selection buffer drawing */ - int needMapping = (ob==obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT|OB_MODE_VERTEX_PAINT|OB_MODE_TEXTURE_PAINT))); + int needMapping = (ob == obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT | OB_MODE_TEXTURE_PAINT))); clear_mesh_caches(ob); mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform, - &ob->derivedFinal, 0, 1, - needMapping, dataMask, -1, 1, build_shapekey_layers); + &ob->derivedFinal, 0, 1, + needMapping, dataMask, -1, 1, build_shapekey_layers); - DM_set_object_boundbox (ob, ob->derivedFinal); + DM_set_object_boundbox(ob, ob->derivedFinal); ob->derivedFinal->needsFree = 0; ob->derivedDeform->needsFree = 0; @@ -2146,7 +2146,7 @@ static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask, if ((ob->mode & OB_MODE_SCULPT) && ob->sculpt) { /* create PBVH immediately (would be created on the fly too, * but this avoids waiting on first stroke) */ - ob->sculpt->pbvh= ob->derivedFinal->getPBVH(ob, ob->derivedFinal); + ob->sculpt->pbvh = ob->derivedFinal->getPBVH(ob, ob->derivedFinal); } } @@ -2155,7 +2155,7 @@ static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, C clear_mesh_caches(obedit); if (em->derivedFinal) { - if (em->derivedFinal!=em->derivedCage) { + if (em->derivedFinal != em->derivedCage) { em->derivedFinal->needsFree = 1; em->derivedFinal->release(em->derivedFinal); } @@ -2168,7 +2168,7 @@ static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, C } editbmesh_calc_modifiers(scene, obedit, em, &em->derivedCage, &em->derivedFinal, dataMask); - DM_set_object_boundbox (obedit, em->derivedFinal); + DM_set_object_boundbox(obedit, em->derivedFinal); em->lastDataMask = dataMask; em->derivedFinal->needsFree = 0; @@ -2238,7 +2238,7 @@ DerivedMesh *mesh_create_derived_view(Scene *scene, Object *ob, CustomDataMask d } DerivedMesh *mesh_create_derived_no_deform(Scene *scene, Object *ob, float (*vertCos)[3], - CustomDataMask dataMask) + CustomDataMask dataMask) { DerivedMesh *final; @@ -2248,7 +2248,7 @@ DerivedMesh *mesh_create_derived_no_deform(Scene *scene, Object *ob, float (*ver } DerivedMesh *mesh_create_derived_no_virtual(Scene *scene, Object *ob, float (*vertCos)[3], - CustomDataMask dataMask) + CustomDataMask dataMask) { DerivedMesh *final; @@ -2258,7 +2258,7 @@ DerivedMesh *mesh_create_derived_no_virtual(Scene *scene, Object *ob, float (*ve } DerivedMesh *mesh_create_derived_physics(Scene *scene, Object *ob, float (*vertCos)[3], - CustomDataMask dataMask) + CustomDataMask dataMask) { DerivedMesh *final; @@ -2268,8 +2268,8 @@ DerivedMesh *mesh_create_derived_physics(Scene *scene, Object *ob, float (*vertC } DerivedMesh *mesh_create_derived_no_deform_render(Scene *scene, Object *ob, - float (*vertCos)[3], - CustomDataMask dataMask) + float (*vertCos)[3], + CustomDataMask dataMask) { DerivedMesh *final; @@ -2281,7 +2281,7 @@ DerivedMesh *mesh_create_derived_no_deform_render(Scene *scene, Object *ob, /***/ DerivedMesh *editbmesh_get_derived_cage_and_final(Scene *scene, Object *obedit, BMEditMesh *em, DerivedMesh **final_r, - CustomDataMask dataMask) + CustomDataMask dataMask) { /* if there's no derived mesh or the last data mask used doesn't include * the data we need, rebuild the derived mesh @@ -2323,13 +2323,13 @@ static void make_vertexcosnos__mapFunc(void *userData, int index, const float co { float *vec = userData; - vec+= 6*index; + vec += 6 * index; /* check if we've been here before (normal should not be 0) */ if (vec[3] || vec[4] || vec[5]) return; copy_v3_v3(vec, co); - vec+= 3; + vec += 3; if (no_f) { copy_v3_v3(vec, no_f); } @@ -2345,27 +2345,27 @@ static void make_vertexcosnos__mapFunc(void *userData, int index, const float co float *mesh_get_mapped_verts_nors(Scene *scene, Object *ob) { - Mesh *me= ob->data; + Mesh *me = ob->data; DerivedMesh *dm; float *vertexcosnos; /* lets prevent crashing... */ - if (ob->type!=OB_MESH || me->totvert==0) + if (ob->type != OB_MESH || me->totvert == 0) return NULL; - dm= mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH|CD_MASK_ORIGINDEX); - vertexcosnos= MEM_callocN(6*sizeof(float)*me->totvert, "vertexcosnos map"); + dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + vertexcosnos = MEM_callocN(6 * sizeof(float) * me->totvert, "vertexcosnos map"); if (dm->foreachMappedVert) { dm->foreachMappedVert(dm, make_vertexcosnos__mapFunc, vertexcosnos); } else { - float *fp= vertexcosnos; + float *fp = vertexcosnos; int a; - for (a=0; a< me->totvert; a++, fp+=6) { + for (a = 0; a < me->totvert; a++, fp += 6) { dm->getVertCo(dm, a, fp); - dm->getVertNo(dm, a, fp+3); + dm->getVertNo(dm, a, fp + 3); } } @@ -2375,14 +2375,13 @@ float *mesh_get_mapped_verts_nors(Scene *scene, Object *ob) /* ******************* GLSL ******************** */ -typedef struct -{ - float * precomputedFaceNormals; - MTFace * mtface; // texture coordinates - MFace * mface; // indices - MVert * mvert; // vertices & normals +typedef struct { + float *precomputedFaceNormals; + MTFace *mtface; // texture coordinates + MFace *mface; // indices + MVert *mvert; // vertices & normals float (*orco)[3]; - float (*tangent)[4]; // destination + float (*tangent)[4]; // destination int numTessFaces; } SGLSLMeshToTangent; @@ -2390,56 +2389,56 @@ typedef struct // interface #include "mikktspace.h" -static int GetNumFaces(const SMikkTSpaceContext * pContext) +static int GetNumFaces(const SMikkTSpaceContext *pContext) { - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; return pMesh->numTessFaces; } -static int GetNumVertsOfFace(const SMikkTSpaceContext * pContext, const int face_num) +static int GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num) { - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; - return pMesh->mface[face_num].v4!=0 ? 4 : 3; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + return pMesh->mface[face_num].v4 != 0 ? 4 : 3; } -static void GetPosition(const SMikkTSpaceContext * pContext, float fPos[], const int face_num, const int vert_index) +static void GetPosition(const SMikkTSpaceContext *pContext, float fPos[], const int face_num, const int vert_index) { //assert(vert_index>=0 && vert_index<4); - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; - const float *co= pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].co; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + const float *co = pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].co; copy_v3_v3(fPos, co); } -static void GetTextureCoordinate(const SMikkTSpaceContext * pContext, float fUV[], const int face_num, const int vert_index) +static void GetTextureCoordinate(const SMikkTSpaceContext *pContext, float fUV[], const int face_num, const int vert_index) { //assert(vert_index>=0 && vert_index<4); - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; - if (pMesh->mtface!=NULL) { - float * uv = pMesh->mtface[face_num].uv[vert_index]; - fUV[0]=uv[0]; fUV[1]=uv[1]; + if (pMesh->mtface != NULL) { + float *uv = pMesh->mtface[face_num].uv[vert_index]; + fUV[0] = uv[0]; fUV[1] = uv[1]; } else { - const float *orco= pMesh->orco[(&pMesh->mface[face_num].v1)[vert_index]]; + const float *orco = pMesh->orco[(&pMesh->mface[face_num].v1)[vert_index]]; map_to_sphere(&fUV[0], &fUV[1], orco[0], orco[1], orco[2]); } } -static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const int face_num, const int vert_index) +static void GetNormal(const SMikkTSpaceContext *pContext, float fNorm[], const int face_num, const int vert_index) { //assert(vert_index>=0 && vert_index<4); - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; const int smoothnormal = (pMesh->mface[face_num].flag & ME_SMOOTH); - if (!smoothnormal) { // flat + if (!smoothnormal) { // flat if (pMesh->precomputedFaceNormals) { - copy_v3_v3(fNorm, &pMesh->precomputedFaceNormals[3*face_num]); + copy_v3_v3(fNorm, &pMesh->precomputedFaceNormals[3 * face_num]); } else { - MFace *mf= &pMesh->mface[face_num]; - float *p0= pMesh->mvert[mf->v1].co; - float *p1= pMesh->mvert[mf->v2].co; - float *p2= pMesh->mvert[mf->v3].co; + MFace *mf = &pMesh->mface[face_num]; + float *p0 = pMesh->mvert[mf->v1].co; + float *p1 = pMesh->mvert[mf->v2].co; + float *p2 = pMesh->mvert[mf->v3].co; if (mf->v4) { float *p3 = pMesh->mvert[mf->v4].co; @@ -2451,17 +2450,17 @@ static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const } } else { - const short *no= pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].no; + const short *no = pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].no; normal_short_to_float_v3(fNorm, no); } } -static void SetTSpace(const SMikkTSpaceContext * pContext, const float fvTangent[], const float fSign, const int face_num, const int iVert) +static void SetTSpace(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fSign, const int face_num, const int iVert) { //assert(vert_index>=0 && vert_index<4); - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; - float * pRes = pMesh->tangent[4*face_num+iVert]; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + float *pRes = pMesh->tangent[4 * face_num + iVert]; copy_v3_v3(pRes, fvTangent); - pRes[3]=fSign; + pRes[3] = fSign; } @@ -2471,9 +2470,9 @@ void DM_add_tangent_layer(DerivedMesh *dm) MTFace *mtface, *tf; MFace *mface, *mf; MVert *mvert, *v1, *v2, *v3, *v4; - MemArena *arena= NULL; - VertexTangent **vtangents= NULL; - float (*orco)[3]= NULL, (*tangent)[4]; + MemArena *arena = NULL; + VertexTangent **vtangents = NULL; + float (*orco)[3] = NULL, (*tangent)[4]; float *uv1, *uv2, *uv3, *uv4, *vtang; float fno[3], tang[3], uv[4][2]; int i, j, len, mf_vi[4], totvert, totface, iCalcNewMethod; @@ -2485,34 +2484,34 @@ void DM_add_tangent_layer(DerivedMesh *dm) nors = dm->getTessFaceDataArray(dm, CD_NORMAL); /* check we have all the needed layers */ - totvert= dm->getNumVerts(dm); - totface= dm->getNumTessFaces(dm); + totvert = dm->getNumVerts(dm); + totface = dm->getNumTessFaces(dm); - mvert= dm->getVertArray(dm); - mface= dm->getTessFaceArray(dm); - mtface= dm->getTessFaceDataArray(dm, CD_MTFACE); + mvert = dm->getVertArray(dm); + mface = dm->getTessFaceArray(dm); + mtface = dm->getTessFaceDataArray(dm, CD_MTFACE); if (!mtface) { - orco= dm->getVertDataArray(dm, CD_ORCO); + orco = dm->getVertDataArray(dm, CD_ORCO); if (!orco) return; } /* create tangent layer */ DM_add_tessface_layer(dm, CD_TANGENT, CD_CALLOC, NULL); - tangent= DM_get_tessface_data_layer(dm, CD_TANGENT); + tangent = DM_get_tessface_data_layer(dm, CD_TANGENT); /* allocate some space */ - arena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "tangent layer arena"); + arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "tangent layer arena"); BLI_memarena_use_calloc(arena); - vtangents= MEM_callocN(sizeof(VertexTangent*)*totvert, "VertexTangent"); + vtangents = MEM_callocN(sizeof(VertexTangent *) * totvert, "VertexTangent"); // new computation method iCalcNewMethod = 1; if (iCalcNewMethod != 0) { - SGLSLMeshToTangent mesh2tangent= {0}; - SMikkTSpaceContext sContext= {0}; - SMikkTSpaceInterface sInterface= {0}; + SGLSLMeshToTangent mesh2tangent = {0}; + SMikkTSpaceContext sContext = {0}; + SMikkTSpaceInterface sInterface = {0}; mesh2tangent.precomputedFaceNormals = nors; mesh2tangent.mtface = mtface; @@ -2537,28 +2536,28 @@ void DM_add_tangent_layer(DerivedMesh *dm) if (!iCalcNewMethod) { /* sum tangents at connected vertices */ - for (i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++) { - v1= &mvert[mf->v1]; - v2= &mvert[mf->v2]; - v3= &mvert[mf->v3]; + for (i = 0, tf = mtface, mf = mface; i < totface; mf++, tf++, i++) { + v1 = &mvert[mf->v1]; + v2 = &mvert[mf->v2]; + v3 = &mvert[mf->v3]; if (mf->v4) { - v4= &mvert[mf->v4]; + v4 = &mvert[mf->v4]; normal_quad_v3(fno, v4->co, v3->co, v2->co, v1->co); } else { - v4= NULL; + v4 = NULL; normal_tri_v3(fno, v3->co, v2->co, v1->co); } if (mtface) { - uv1= tf->uv[0]; - uv2= tf->uv[1]; - uv3= tf->uv[2]; - uv4= tf->uv[3]; + uv1 = tf->uv[0]; + uv2 = tf->uv[1]; + uv3 = tf->uv[2]; + uv4 = tf->uv[3]; } else { - uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3]; + uv1 = uv[0]; uv2 = uv[1]; uv3 = uv[2]; uv4 = uv[3]; map_to_sphere(&uv[0][0], &uv[0][1], orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]); map_to_sphere(&uv[1][0], &uv[1][1], orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]); map_to_sphere(&uv[2][0], &uv[2][1], orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]); @@ -2572,7 +2571,7 @@ void DM_add_tangent_layer(DerivedMesh *dm) sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3); if (mf->v4) { - v4= &mvert[mf->v4]; + v4 = &mvert[mf->v4]; tangent_from_uv(uv1, uv3, uv4, v1->co, v3->co, v4->co, fno, tang); sum_or_add_vertex_tangent(arena, &vtangents[mf->v1], tang, uv1); @@ -2582,26 +2581,26 @@ void DM_add_tangent_layer(DerivedMesh *dm) } /* write tangent to layer */ - for (i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++, tangent+=4) { - len= (mf->v4)? 4 : 3; + for (i = 0, tf = mtface, mf = mface; i < totface; mf++, tf++, i++, tangent += 4) { + len = (mf->v4) ? 4 : 3; if (mtface == NULL) { map_to_sphere(&uv[0][0], &uv[0][1], orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]); map_to_sphere(&uv[1][0], &uv[1][1], orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]); map_to_sphere(&uv[2][0], &uv[2][1], orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]); - if (len==4) + if (len == 4) map_to_sphere(&uv[3][0], &uv[3][1], orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2]); } - mf_vi[0]= mf->v1; - mf_vi[1]= mf->v2; - mf_vi[2]= mf->v3; - mf_vi[3]= mf->v4; + mf_vi[0] = mf->v1; + mf_vi[1] = mf->v2; + mf_vi[2] = mf->v3; + mf_vi[3] = mf->v4; - for (j=0; j<len; j++) { - vtang= find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]); + for (j = 0; j < len; j++) { + vtang = find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]); normalize_v3_v3(tangent[j], vtang); - ((float *) tangent[j])[3]=1.0f; + ((float *) tangent[j])[3] = 1.0f; } } } @@ -2613,34 +2612,34 @@ void DM_add_tangent_layer(DerivedMesh *dm) void DM_calc_auto_bump_scale(DerivedMesh *dm) { /* int totvert= dm->getNumVerts(dm); */ /* UNUSED */ - int totface= dm->getNumTessFaces(dm); + int totface = dm->getNumTessFaces(dm); - MVert * mvert = dm->getVertArray(dm); - MFace * mface = dm->getTessFaceArray(dm); - MTFace * mtface = dm->getTessFaceDataArray(dm, CD_MTFACE); + MVert *mvert = dm->getVertArray(dm); + MFace *mface = dm->getTessFaceArray(dm); + MTFace *mtface = dm->getTessFaceDataArray(dm, CD_MTFACE); if (mtface) { double dsum = 0.0; int nr_accumulated = 0; int f; - for (f=0; f < totface; f++ ) { + for (f = 0; f < totface; f++) { { - float * verts[4], * tex_coords[4]; - const int nr_verts = mface[f].v4!=0 ? 4 : 3; + float *verts[4], *tex_coords[4]; + const int nr_verts = mface[f].v4 != 0 ? 4 : 3; int i, is_degenerate; - verts[0]=mvert[mface[f].v1].co; verts[1]=mvert[mface[f].v2].co; verts[2]=mvert[mface[f].v3].co; - tex_coords[0]=mtface[f].uv[0]; tex_coords[1]=mtface[f].uv[1]; tex_coords[2]=mtface[f].uv[2]; - if (nr_verts==4) { - verts[3]=mvert[mface[f].v4].co; - tex_coords[3]=mtface[f].uv[3]; + verts[0] = mvert[mface[f].v1].co; verts[1] = mvert[mface[f].v2].co; verts[2] = mvert[mface[f].v3].co; + tex_coords[0] = mtface[f].uv[0]; tex_coords[1] = mtface[f].uv[1]; tex_coords[2] = mtface[f].uv[2]; + if (nr_verts == 4) { + verts[3] = mvert[mface[f].v4].co; + tex_coords[3] = mtface[f].uv[3]; } // discard degenerate faces is_degenerate = 0; - if ( equals_v3v3(verts[0], verts[1]) || equals_v3v3(verts[0], verts[2]) || equals_v3v3(verts[1], verts[2]) || - equals_v2v2(tex_coords[0], tex_coords[1]) || equals_v2v2(tex_coords[0], tex_coords[2]) || equals_v2v2(tex_coords[1], tex_coords[2])) + if (equals_v3v3(verts[0], verts[1]) || equals_v3v3(verts[0], verts[2]) || equals_v3v3(verts[1], verts[2]) || + equals_v2v2(tex_coords[0], tex_coords[1]) || equals_v2v2(tex_coords[0], tex_coords[2]) || equals_v2v2(tex_coords[1], tex_coords[2])) { is_degenerate = 1; } @@ -2662,10 +2661,10 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) i = 0; while (is_degenerate == 0 && i < 4) { float cur_edge[2], signed_area; - sub_v2_v2v2(cur_edge, tex_coords[(i+1)&0x3], tex_coords[i]); - signed_area = prev_edge[0]*cur_edge[1] - prev_edge[1]*cur_edge[0]; + sub_v2_v2v2(cur_edge, tex_coords[(i + 1) & 0x3], tex_coords[i]); + signed_area = prev_edge[0] * cur_edge[1] - prev_edge[1] * cur_edge[0]; - if (i == 0 ) { + if (i == 0) { is_signed = (signed_area < 0.0f) ? 1 : 0; } else if ((is_signed != 0) != (signed_area < 0.0f)) { @@ -2682,9 +2681,9 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) // proceed if not a degenerate face if (is_degenerate == 0) { - int nr_tris_to_pile=0; + int nr_tris_to_pile = 0; // quads split at shortest diagonal - int offs = 0; // initial triangulation is 0,1,2 and 0, 2, 3 + int offs = 0; // initial triangulation is 0,1,2 and 0, 2, 3 if (nr_verts == 4) { float pos_len_diag0, pos_len_diag1; float vtmp[3]; @@ -2693,10 +2692,10 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) sub_v3_v3v3(vtmp, verts[3], verts[1]); pos_len_diag1 = dot_v3v3(vtmp, vtmp); - if (pos_len_diag1<pos_len_diag0) { - offs=1; // alter split + if (pos_len_diag1 < pos_len_diag0) { + offs = 1; // alter split } - else if (pos_len_diag0==pos_len_diag1) { /* do UV check instead */ + else if (pos_len_diag0 == pos_len_diag1) { /* do UV check instead */ float tex_len_diag0, tex_len_diag1; sub_v2_v2v2(vtmp, tex_coords[2], tex_coords[0]); @@ -2704,34 +2703,34 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) sub_v2_v2v2(vtmp, tex_coords[3], tex_coords[1]); tex_len_diag1 = dot_v2v2(vtmp, vtmp); - if (tex_len_diag1<tex_len_diag0) { - offs=1; /* alter split */ + if (tex_len_diag1 < tex_len_diag0) { + offs = 1; /* alter split */ } } } nr_tris_to_pile = nr_verts - 2; - if (nr_tris_to_pile==1 || nr_tris_to_pile==2) { - const int indices[] = {offs+0, offs+1, offs+2, offs+0, offs+2, (offs+3)&0x3 }; + if (nr_tris_to_pile == 1 || nr_tris_to_pile == 2) { + const int indices[] = {offs + 0, offs + 1, offs + 2, offs + 0, offs + 2, (offs + 3) & 0x3 }; int t; - for (t=0; t<nr_tris_to_pile; t++ ) { + for (t = 0; t < nr_tris_to_pile; t++) { float f2x_area_uv; - float * p0 = verts[indices[t*3+0]]; - float * p1 = verts[indices[t*3+1]]; - float * p2 = verts[indices[t*3+2]]; + float *p0 = verts[indices[t * 3 + 0]]; + float *p1 = verts[indices[t * 3 + 1]]; + float *p2 = verts[indices[t * 3 + 2]]; float edge_t0[2], edge_t1[2]; - sub_v2_v2v2(edge_t0, tex_coords[indices[t*3+1]], tex_coords[indices[t*3+0]]); - sub_v2_v2v2(edge_t1, tex_coords[indices[t*3+2]], tex_coords[indices[t*3+0]]); + sub_v2_v2v2(edge_t0, tex_coords[indices[t * 3 + 1]], tex_coords[indices[t * 3 + 0]]); + sub_v2_v2v2(edge_t1, tex_coords[indices[t * 3 + 2]], tex_coords[indices[t * 3 + 0]]); - f2x_area_uv = fabsf(edge_t0[0]*edge_t1[1] - edge_t0[1]*edge_t1[0]); - if (f2x_area_uv>FLT_EPSILON) { + f2x_area_uv = fabsf(edge_t0[0] * edge_t1[1] - edge_t0[1] * edge_t1[0]); + if (f2x_area_uv > FLT_EPSILON) { float norm[3], v0[3], v1[3], f2x_surf_area, fsurf_ratio; sub_v3_v3v3(v0, p1, p0); sub_v3_v3v3(v1, p2, p0); cross_v3_v3v3(norm, v0, v1); f2x_surf_area = len_v3(norm); - fsurf_ratio = f2x_surf_area/f2x_area_uv; // tri area divided by texture area + fsurf_ratio = f2x_surf_area / f2x_area_uv; // tri area divided by texture area nr_accumulated++; dsum += (double)(fsurf_ratio); @@ -2744,8 +2743,8 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) // finalize { - const float avg_area_ratio = (nr_accumulated>0) ? ((float)(dsum / nr_accumulated)) : 1.0f; - const float use_as_render_bump_scale = sqrtf(avg_area_ratio); // use width of average surface ratio as your bump scale + const float avg_area_ratio = (nr_accumulated > 0) ? ((float)(dsum / nr_accumulated)) : 1.0f; + const float use_as_render_bump_scale = sqrtf(avg_area_ratio); // use width of average surface ratio as your bump scale dm->auto_bump_scale = use_as_render_bump_scale; } } @@ -2786,7 +2785,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, if (gattribs->layer[b].name[0]) layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV, - gattribs->layer[b].name); + gattribs->layer[b].name); else layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV); @@ -2802,7 +2801,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, else { if (gattribs->layer[b].name[0]) layer = CustomData_get_named_layer_index(tfdata, CD_MTFACE, - gattribs->layer[b].name); + gattribs->layer[b].name); else layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE); @@ -2823,7 +2822,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, if (gattribs->layer[b].name[0]) layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, - gattribs->layer[b].name); + gattribs->layer[b].name); else layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL); @@ -2839,7 +2838,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, /* vertex colors */ if (gattribs->layer[b].name[0]) layer = CustomData_get_named_layer_index(tfdata, CD_MCOL, - gattribs->layer[b].name); + gattribs->layer[b].name); else layer = CustomData_get_active_layer_index(tfdata, CD_MCOL); @@ -2890,7 +2889,7 @@ void DM_set_object_boundbox(Object *ob, DerivedMesh *dm) dm->getMinMax(dm, min, max); if (!ob->bb) - ob->bb= MEM_callocN(sizeof(BoundBox), "DM-BoundBox"); + ob->bb = MEM_callocN(sizeof(BoundBox), "DM-BoundBox"); BKE_boundbox_init_from_minmax(ob->bb, min, max); } @@ -2914,12 +2913,12 @@ BLI_INLINE int navmesh_bit(int a, int b) BLI_INLINE void navmesh_intToCol(int i, float col[3]) { - int r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1; - int g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1; - int b = navmesh_bit(i, 2) + navmesh_bit(i, 5) * 2 + 1; - col[0] = 1 - r*63.0f/255.0f; - col[1] = 1 - g*63.0f/255.0f; - col[2] = 1 - b*63.0f/255.0f; + int r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1; + int g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1; + int b = navmesh_bit(i, 2) + navmesh_bit(i, 5) * 2 + 1; + col[0] = 1 - r * 63.0f / 255.0f; + col[1] = 1 - g * 63.0f / 255.0f; + col[2] = 1 - b * 63.0f / 255.0f; } static void navmesh_drawColored(DerivedMesh *dm) @@ -2948,7 +2947,7 @@ static void navmesh_drawColored(DerivedMesh *dm) //glShadeModel(GL_SMOOTH); glBegin(glmode = GL_QUADS); for (a = 0; a < dm->numTessFaceData; a++, mface++) { - int new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES; + int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES; int pi = polygonIdx[a]; if (pi <= 0) { zero_v3(col); @@ -2975,9 +2974,9 @@ static void navmesh_drawColored(DerivedMesh *dm) } static void navmesh_DM_drawFacesTex(DerivedMesh *dm, - DMSetDrawOptionsTex setDrawOptions, - DMCompareDrawOptions compareDrawOptions, - void *userData) + DMSetDrawOptionsTex setDrawOptions, + DMCompareDrawOptions compareDrawOptions, + void *userData) { (void) setDrawOptions; (void) compareDrawOptions; @@ -3002,21 +3001,21 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm) DerivedMesh *result; int maxFaces = dm->getNumPolys(dm); int *recastData; - int vertsPerPoly=0, nverts=0, ndtris=0, npolys=0; - float* verts=NULL; - unsigned short *dtris=NULL, *dmeshes=NULL, *polys=NULL; - int *dtrisToPolysMap=NULL, *dtrisToTrisMap=NULL, *trisToFacesMap=NULL; + int vertsPerPoly = 0, nverts = 0, ndtris = 0, npolys = 0; + float *verts = NULL; + unsigned short *dtris = NULL, *dmeshes = NULL, *polys = NULL; + int *dtrisToPolysMap = NULL, *dtrisToTrisMap = NULL, *trisToFacesMap = NULL; int res; result = CDDM_copy(dm); if (!CustomData_has_layer(&result->polyData, CD_RECAST)) { - int *sourceRecastData = (int*)CustomData_get_layer(&dm->polyData, CD_RECAST); + int *sourceRecastData = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST); if (sourceRecastData) { CustomData_add_layer_named(&result->polyData, CD_RECAST, CD_DUPLICATE, sourceRecastData, maxFaces, "recastData"); } } - recastData = (int*)CustomData_get_layer(&result->polyData, CD_RECAST); + recastData = (int *)CustomData_get_layer(&result->polyData, CD_RECAST); /* note: This is not good design! - really should not be doing this */ result->drawFacesTex = navmesh_DM_drawFacesTex; @@ -3031,17 +3030,17 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm) size_t polyIdx; /* invalidate concave polygon */ - for (polyIdx=0; polyIdx<(size_t)npolys; polyIdx++) { - unsigned short* poly = &polys[polyIdx*2*vertsPerPoly]; + for (polyIdx = 0; polyIdx < (size_t)npolys; polyIdx++) { + unsigned short *poly = &polys[polyIdx * 2 * vertsPerPoly]; if (!polyIsConvex(poly, vertsPerPoly, verts)) { /* set negative polygon idx to all faces */ - unsigned short *dmesh = &dmeshes[4*polyIdx]; + unsigned short *dmesh = &dmeshes[4 * polyIdx]; unsigned short tbase = dmesh[2]; unsigned short tnum = dmesh[3]; unsigned short ti; - for (ti=0; ti<tnum; ti++) { - unsigned short triidx = dtrisToTrisMap[tbase+ti]; + for (ti = 0; ti < tnum; ti++) { + unsigned short triidx = dtrisToTrisMap[tbase + ti]; unsigned short faceidx = trisToFacesMap[triidx]; if (recastData[faceidx] > 0) { recastData[faceidx] = -recastData[faceidx]; @@ -3055,19 +3054,19 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm) } /* clean up */ - if (verts!=NULL) + if (verts != NULL) MEM_freeN(verts); - if (dtris!=NULL) + if (dtris != NULL) MEM_freeN(dtris); - if (dmeshes!=NULL) + if (dmeshes != NULL) MEM_freeN(dmeshes); - if (polys!=NULL) + if (polys != NULL) MEM_freeN(polys); - if (dtrisToPolysMap!=NULL) + if (dtrisToPolysMap != NULL) MEM_freeN(dtrisToPolysMap); - if (dtrisToTrisMap!=NULL) + if (dtrisToTrisMap != NULL) MEM_freeN(dtrisToTrisMap); - if (trisToFacesMap!=NULL) + if (trisToFacesMap != NULL) MEM_freeN(trisToFacesMap); return result; @@ -3132,7 +3131,7 @@ static void dm_debug_info_layers(DynStr *dynstr, DerivedMesh *dm, void *(*getEle char *DM_debug_info(DerivedMesh *dm) { - DynStr *dynstr= BLI_dynstr_new(); + DynStr *dynstr = BLI_dynstr_new(); char *ret; const char *tstr; diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 9e46d03a3ab..0f8716e2b04 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -574,7 +574,7 @@ void BKE_pose_channels_hash_make(bPose *pose) if (!pose->chanhash) { bPoseChannel *pchan; - pose->chanhash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "make_pose_chan gh"); + pose->chanhash = BLI_ghash_str_new("make_pose_chan gh"); for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) BLI_ghash_insert(pose->chanhash, pchan->name, pchan); } diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 8982017403d..e8e8a100f34 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -80,7 +80,7 @@ short id_type_can_have_animdata(ID *id) /* Only some ID-blocks have this info for now */ // TODO: finish adding this for the other blocktypes switch (GS(id->name)) { - /* has AnimData */ + /* has AnimData */ case ID_OB: case ID_ME: case ID_MB: case ID_CU: case ID_AR: case ID_LT: case ID_KE: @@ -95,7 +95,7 @@ short id_type_can_have_animdata(ID *id) return 1; } - /* no AnimData */ + /* no AnimData */ default: return 0; } @@ -106,14 +106,14 @@ short id_type_can_have_animdata(ID *id) * the AnimData pointer is stored immediately after the given ID-block in the struct, * as per IdAdtTemplate. */ -AnimData *BKE_animdata_from_id (ID *id) +AnimData *BKE_animdata_from_id(ID *id) { /* only some ID-blocks have this info for now, so we cast the * types that do to be of type IdAdtTemplate, and extract the * AnimData that way */ if (id_type_can_have_animdata(id)) { - IdAdtTemplate *iat= (IdAdtTemplate *)id; + IdAdtTemplate *iat = (IdAdtTemplate *)id; return iat->adt; } else @@ -124,24 +124,24 @@ AnimData *BKE_animdata_from_id (ID *id) * the AnimData pointer is stored immediately after the given ID-block in the struct, * as per IdAdtTemplate. Also note that */ -AnimData *BKE_id_add_animdata (ID *id) +AnimData *BKE_id_add_animdata(ID *id) { /* Only some ID-blocks have this info for now, so we cast the * types that do to be of type IdAdtTemplate, and add the AnimData * to it using the template */ if (id_type_can_have_animdata(id)) { - IdAdtTemplate *iat= (IdAdtTemplate *)id; + IdAdtTemplate *iat = (IdAdtTemplate *)id; /* check if there's already AnimData, in which case, don't add */ if (iat->adt == NULL) { AnimData *adt; /* add animdata */ - adt= iat->adt= MEM_callocN(sizeof(AnimData), "AnimData"); + adt = iat->adt = MEM_callocN(sizeof(AnimData), "AnimData"); /* set default settings */ - adt->act_influence= 1.0f; + adt->act_influence = 1.0f; } return iat->adt; @@ -175,7 +175,7 @@ short BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act) /* manage usercount for current action */ if (adt->action) - id_us_min((ID*)adt->action); + id_us_min((ID *)adt->action); /* assume that AnimData's action can in fact be edited... */ if (act) { @@ -183,14 +183,14 @@ short BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act) if (ELEM(act->idroot, 0, GS(id->name))) { /* can set */ adt->action = act; - id_us_plus((ID*)adt->action); + id_us_plus((ID *)adt->action); ok = 1; } else { /* cannot set */ BKE_reportf(reports, RPT_ERROR, - "Couldn't set Action '%s' onto ID '%s', as it doesn't have suitably rooted paths for this purpose", - act->id.name+2, id->name); + "Couldn't set Action '%s' onto ID '%s', as it doesn't have suitably rooted paths for this purpose", + act->id.name + 2, id->name); //ok = 0; } } @@ -212,8 +212,8 @@ void BKE_free_animdata(ID *id) * types that do to be of type IdAdtTemplate */ if (id_type_can_have_animdata(id)) { - IdAdtTemplate *iat= (IdAdtTemplate *)id; - AnimData *adt= iat->adt; + IdAdtTemplate *iat = (IdAdtTemplate *)id; + AnimData *adt = iat->adt; /* check if there's any AnimData to start with */ if (adt) { @@ -235,7 +235,7 @@ void BKE_free_animdata(ID *id) /* free animdata now */ MEM_freeN(adt); - iat->adt= NULL; + iat->adt = NULL; } } } @@ -243,19 +243,19 @@ void BKE_free_animdata(ID *id) /* Freeing -------------------------------------------- */ /* Make a copy of the given AnimData - to be used when copying datablocks */ -AnimData *BKE_copy_animdata (AnimData *adt, const short do_action) +AnimData *BKE_copy_animdata(AnimData *adt, const short do_action) { AnimData *dadt; /* sanity check before duplicating struct */ if (adt == NULL) return NULL; - dadt= MEM_dupallocN(adt); + dadt = MEM_dupallocN(adt); /* make a copy of action - at worst, user has to delete copies... */ if (do_action) { - dadt->action= BKE_action_copy(adt->action); - dadt->tmpact= BKE_action_copy(adt->tmpact); + dadt->action = BKE_action_copy(adt->action); + dadt->tmpact = BKE_action_copy(adt->tmpact); } else { id_us_plus((ID *)dadt->action); @@ -269,7 +269,7 @@ AnimData *BKE_copy_animdata (AnimData *adt, const short do_action) copy_fcurves(&dadt->drivers, &adt->drivers); /* don't copy overrides */ - dadt->overrides.first= dadt->overrides.last= NULL; + dadt->overrides.first = dadt->overrides.last = NULL; /* return */ return dadt; @@ -287,7 +287,7 @@ int BKE_copy_animdata_id(ID *id_to, ID *id_from, const short do_action) adt = BKE_animdata_from_id(id_from); if (adt) { IdAdtTemplate *iat = (IdAdtTemplate *)id_to; - iat->adt= BKE_copy_animdata(adt, do_action); + iat->adt = BKE_copy_animdata(adt, do_action); } return 1; @@ -295,15 +295,15 @@ int BKE_copy_animdata_id(ID *id_to, ID *id_from, const short do_action) void BKE_copy_animdata_id_action(ID *id) { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); if (adt) { if (adt->action) { id_us_min((ID *)adt->action); - adt->action= BKE_action_copy(adt->action); + adt->action = BKE_action_copy(adt->action); } if (adt->tmpact) { id_us_min((ID *)adt->tmpact); - adt->tmpact= BKE_action_copy(adt->tmpact); + adt->tmpact = BKE_action_copy(adt->tmpact); } } } @@ -314,7 +314,7 @@ static void make_local_strips(ListBase *strips) { NlaStrip *strip; - for (strip=strips->first; strip; strip=strip->next) { + for (strip = strips->first; strip; strip = strip->next) { if (strip->act) BKE_action_make_local(strip->act); if (strip->remap && strip->remap->target) BKE_action_make_local(strip->remap->target); @@ -337,7 +337,7 @@ void BKE_animdata_make_local(AnimData *adt) // TODO: need to remap the ID-targets too? /* NLA Data */ - for (nlt=adt->nla_tracks.first; nlt; nlt=nlt->next) + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) make_local_strips(&nlt->strips); } @@ -356,17 +356,17 @@ void BKE_relink_animdata(AnimData *adt) FCurve *fcu; /* check each driver against all the base paths to see if any should go */ - for (fcu= adt->drivers.first; fcu; fcu=fcu->next) { - ChannelDriver *driver= fcu->driver; + for (fcu = adt->drivers.first; fcu; fcu = fcu->next) { + ChannelDriver *driver = fcu->driver; DriverVar *dvar; /* driver variables */ - for (dvar= driver->variables.first; dvar; dvar=dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { /* only change the used targets, since the others will need fixing manually anyway */ DRIVER_TARGETS_USED_LOOPER(dvar) { if (dtar->id && dtar->id->newid) { - dtar->id= dtar->id->newid; + dtar->id = dtar->id->newid; } } DRIVER_TARGETS_LOOPER_END @@ -382,7 +382,7 @@ void BKE_relink_animdata(AnimData *adt) * < basepath: (str) shorter path fragment to look for * > returns (bool) whether there is a match */ -static short animpath_matches_basepath (const char path[], const char basepath[]) +static short animpath_matches_basepath(const char path[], const char basepath[]) { /* we need start of path to be basepath */ return (path && basepath) && (strstr(path, basepath) == path); @@ -396,13 +396,13 @@ static short animpath_matches_basepath (const char path[], const char basepath[] */ void action_move_fcurves_by_basepath(bAction *srcAct, bAction *dstAct, const char basepath[]) { - FCurve *fcu, *fcn=NULL; + FCurve *fcu, *fcn = NULL; /* sanity checks */ if (ELEM3(NULL, srcAct, dstAct, basepath)) { if (G.debug & G_DEBUG) { printf("ERROR: action_partition_fcurves_by_basepath(%p, %p, %p) has insufficient info to work with\n", - (void *)srcAct, (void *)dstAct, (void *)basepath); + (void *)srcAct, (void *)dstAct, (void *)basepath); } return; } @@ -451,7 +451,7 @@ void action_move_fcurves_by_basepath(bAction *srcAct, bAction *dstAct, const cha /* cleanup groups (if present) */ if (srcAct->groups.first) { - bActionGroup *agrp, *grp=NULL; + bActionGroup *agrp, *grp = NULL; for (agrp = srcAct->groups.first; agrp; agrp = grp) { grp = agrp->next; @@ -476,7 +476,7 @@ void action_move_fcurves_by_basepath(bAction *srcAct, bAction *dstAct, const cha */ void BKE_animdata_separate_by_basepath(ID *srcID, ID *dstID, ListBase *basepaths) { - AnimData *srcAdt=NULL, *dstAdt=NULL; + AnimData *srcAdt = NULL, *dstAdt = NULL; LinkData *ld; /* sanity checks */ @@ -500,15 +500,15 @@ void BKE_animdata_separate_by_basepath(ID *srcID, ID *dstID, ListBase *basepaths if (srcAdt->action) { /* set up an action if necessary, and name it in a similar way so that it can be easily found again */ if (dstAdt->action == NULL) { - dstAdt->action = add_empty_action(srcAdt->action->id.name+2); + dstAdt->action = add_empty_action(srcAdt->action->id.name + 2); } else if (dstAdt->action == srcAdt->action) { printf("Argh! Source and Destination share animation! ('%s' and '%s' both use '%s') Making new empty action\n", - srcID->name, dstID->name, srcAdt->action->id.name); + srcID->name, dstID->name, srcAdt->action->id.name); // TODO: review this... id_us_min(&dstAdt->action->id); - dstAdt->action = add_empty_action(dstAdt->action->id.name+2); + dstAdt->action = add_empty_action(dstAdt->action->id.name + 2); } /* loop over base paths, trying to fix for each one... */ @@ -520,7 +520,7 @@ void BKE_animdata_separate_by_basepath(ID *srcID, ID *dstID, ListBase *basepaths /* drivers */ if (srcAdt->drivers.first) { - FCurve *fcu, *fcn=NULL; + FCurve *fcu, *fcn = NULL; /* check each driver against all the base paths to see if any should go */ for (fcu = srcAdt->drivers.first; fcu; fcu = fcn) { @@ -548,10 +548,10 @@ void BKE_animdata_separate_by_basepath(ID *srcID, ID *dstID, ListBase *basepaths /* Path Validation -------------------------------------------- */ /* Check if a given RNA Path is valid, by tracing it from the given ID, and seeing if we can resolve it */ -static short check_rna_path_is_valid (ID *owner_id, const char *path) +static short check_rna_path_is_valid(ID *owner_id, const char *path) { PointerRNA id_ptr, ptr; - PropertyRNA *prop=NULL; + PropertyRNA *prop = NULL; /* make initial RNA pointer to start resolving from */ RNA_id_pointer_create(owner_id, &id_ptr); @@ -563,30 +563,30 @@ static short check_rna_path_is_valid (ID *owner_id, const char *path) /* Check if some given RNA Path needs fixing - free the given path and set a new one as appropriate * NOTE: we assume that oldName and newName have [" "] padding around them */ -static char *rna_path_rename_fix (ID *owner_id, const char *prefix, const char *oldName, const char *newName, char *oldpath, int verify_paths) +static char *rna_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, char *oldpath, int verify_paths) { - char *prefixPtr= strstr(oldpath, prefix); - char *oldNamePtr= strstr(oldpath, oldName); - int prefixLen= strlen(prefix); - int oldNameLen= strlen(oldName); + char *prefixPtr = strstr(oldpath, prefix); + char *oldNamePtr = strstr(oldpath, oldName); + int prefixLen = strlen(prefix); + int oldNameLen = strlen(oldName); /* only start fixing the path if the prefix and oldName feature in the path, * and prefix occurs immediately before oldName */ - if ( (prefixPtr && oldNamePtr) && (prefixPtr+prefixLen == oldNamePtr) ) { + if ( (prefixPtr && oldNamePtr) && (prefixPtr + prefixLen == oldNamePtr) ) { /* if we haven't aren't able to resolve the path now, try again after fixing it */ if (!verify_paths || check_rna_path_is_valid(owner_id, oldpath) == 0) { - DynStr *ds= BLI_dynstr_new(); - char *postfixPtr= oldNamePtr+oldNameLen; + DynStr *ds = BLI_dynstr_new(); + char *postfixPtr = oldNamePtr + oldNameLen; char *newPath = NULL; char oldChar; /* add the part of the string that goes up to the start of the prefix */ if (prefixPtr > oldpath) { - oldChar= prefixPtr[0]; - prefixPtr[0]= 0; + oldChar = prefixPtr[0]; + prefixPtr[0] = 0; BLI_dynstr_append(ds, oldpath); - prefixPtr[0]= oldChar; + prefixPtr[0] = oldChar; } /* add the prefix */ @@ -599,7 +599,7 @@ static char *rna_path_rename_fix (ID *owner_id, const char *prefix, const char * BLI_dynstr_append(ds, postfixPtr); /* create new path, and cleanup old data */ - newPath= BLI_dynstr_get_cstring(ds); + newPath = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); /* check if the new path will solve our problems */ @@ -621,15 +621,15 @@ static char *rna_path_rename_fix (ID *owner_id, const char *prefix, const char * } /* Check RNA-Paths for a list of F-Curves */ -static void fcurves_path_rename_fix (ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *curves, int verify_paths) +static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *curves, int verify_paths) { FCurve *fcu; /* we need to check every curve... */ - for (fcu= curves->first; fcu; fcu= fcu->next) { + for (fcu = curves->first; fcu; fcu = fcu->next) { /* firstly, handle the F-Curve's own path */ if (fcu->rna_path) - fcu->rna_path= rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path, verify_paths); + fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path, verify_paths); } } @@ -640,29 +640,29 @@ static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix FCurve *fcu; /* we need to check every curve - drivers are F-Curves too! */ - for (fcu= curves->first; fcu; fcu= fcu->next) { + for (fcu = curves->first; fcu; fcu = fcu->next) { /* firstly, handle the F-Curve's own path */ if (fcu->rna_path) - fcu->rna_path= rna_path_rename_fix(owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); + fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); /* driver? */ if (fcu->driver) { - ChannelDriver *driver= fcu->driver; + ChannelDriver *driver = fcu->driver; DriverVar *dvar; /* driver variables */ - for (dvar= driver->variables.first; dvar; dvar=dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { /* only change the used targets, since the others will need fixing manually anyway */ DRIVER_TARGETS_USED_LOOPER(dvar) { /* rename RNA path */ if (dtar->rna_path && dtar->id) - dtar->rna_path= rna_path_rename_fix(dtar->id, prefix, oldKey, newKey, dtar->rna_path, verify_paths); + dtar->rna_path = rna_path_rename_fix(dtar->id, prefix, oldKey, newKey, dtar->rna_path, verify_paths); /* also fix the bone-name (if applicable) */ if (strstr(prefix, "bones")) { - if ( ((dtar->id) && (GS(dtar->id->name) == ID_OB) && (!ref_id || ((Object*)(dtar->id))->data == ref_id)) && - (dtar->pchan_name[0]) && (strcmp(oldName, dtar->pchan_name)==0) ) + if ( ((dtar->id) && (GS(dtar->id->name) == ID_OB) && (!ref_id || ((Object *)(dtar->id))->data == ref_id)) && + (dtar->pchan_name[0]) && (strcmp(oldName, dtar->pchan_name) == 0) ) { BLI_strncpy(dtar->pchan_name, newName, sizeof(dtar->pchan_name)); } @@ -675,12 +675,12 @@ static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix } /* Fix all RNA-Paths for Actions linked to NLA Strips */ -static void nlastrips_path_rename_fix (ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *strips, int verify_paths) +static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *strips, int verify_paths) { NlaStrip *strip; /* recursively check strips, fixing only actions... */ - for (strip= strips->first; strip; strip= strip->next) { + for (strip = strips->first; strip; strip = strip->next) { /* fix strip's action */ if (strip->act) fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &strip->act->curves, verify_paths); @@ -693,7 +693,7 @@ static void nlastrips_path_rename_fix (ID *owner_id, const char *prefix, char *o /* Fix all RNA-Paths in the AnimData block used by the given ID block * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> - * i.e. pose.bones["Bone"] + * i.e. pose.bones["Bone"] */ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, const char *prefix, const char *oldName, const char *newName, int oldSubscript, int newSubscript, int verify_paths) @@ -707,12 +707,12 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, cons if ((oldName != NULL) && (newName != NULL)) { /* pad the names with [" "] so that only exact matches are made */ - oldN= BLI_sprintfN("[\"%s\"]", oldName); - newN= BLI_sprintfN("[\"%s\"]", newName); + oldN = BLI_sprintfN("[\"%s\"]", oldName); + newN = BLI_sprintfN("[\"%s\"]", newName); } else { - oldN= BLI_sprintfN("[%d]", oldSubscript); - newN= BLI_sprintfN("[%d]", newSubscript); + oldN = BLI_sprintfN("[%d]", oldSubscript); + newN = BLI_sprintfN("[%d]", newSubscript); } /* Active action and temp action */ @@ -725,7 +725,7 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, cons drivers_path_rename_fix(owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths); /* NLA Data - Animation Data for Strips */ - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips, verify_paths); /* free the temp names */ @@ -742,18 +742,18 @@ void BKE_animdata_main_cb(Main *mainptr, ID_AnimData_Edit_Callback func, void *u /* standard data version */ #define ANIMDATA_IDS_CB(first) \ - for (id= first; id; id= id->next) { \ - AnimData *adt= BKE_animdata_from_id(id); \ + for (id = first; id; id = id->next) { \ + AnimData *adt = BKE_animdata_from_id(id); \ if (adt) func(id, adt, user_data); \ } /* "embedded" nodetree cases (i.e. scene/material/texture->nodetree) */ #define ANIMDATA_NODETREE_IDS_CB(first, NtId_Type) \ - for (id= first; id; id= id->next) { \ - AnimData *adt= BKE_animdata_from_id(id); \ - NtId_Type *ntp= (NtId_Type *)id; \ + for (id = first; id; id = id->next) { \ + AnimData *adt = BKE_animdata_from_id(id); \ + NtId_Type *ntp = (NtId_Type *)id; \ if (ntp->nodetree) { \ - AnimData *adt2= BKE_animdata_from_id((ID *)ntp); \ + AnimData *adt2 = BKE_animdata_from_id((ID *)ntp); \ if (adt2) func(id, adt2, user_data); \ } \ if (adt) func(id, adt, user_data); \ @@ -816,12 +816,12 @@ void BKE_animdata_main_cb(Main *mainptr, ID_AnimData_Edit_Callback func, void *u /* Fix all RNA-Paths throughout the database (directly access the Global.main version) * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> - * i.e. pose.bones["Bone"] + * i.e. pose.bones["Bone"] */ /* TODO: use BKE_animdata_main_cb for looping over all data */ void BKE_all_animdata_fix_paths_rename(ID *ref_id, const char *prefix, const char *oldName, const char *newName) { - Main *mainptr= G.main; + Main *mainptr = G.main; ID *id; /* macro for less typing @@ -829,21 +829,21 @@ void BKE_all_animdata_fix_paths_rename(ID *ref_id, const char *prefix, const cha * this outside of the function may make things slightly faster? */ #define RENAMEFIX_ANIM_IDS(first) \ - for (id= first; id; id= id->next) { \ - AnimData *adt= BKE_animdata_from_id(id); \ - BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1);\ + for (id = first; id; id = id->next) { \ + AnimData *adt = BKE_animdata_from_id(id); \ + BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1); \ } /* another version of this macro for nodetrees */ #define RENAMEFIX_ANIM_NODETREE_IDS(first, NtId_Type) \ - for (id= first; id; id= id->next) { \ - AnimData *adt= BKE_animdata_from_id(id); \ - NtId_Type *ntp= (NtId_Type *)id; \ + for (id = first; id; id = id->next) { \ + AnimData *adt = BKE_animdata_from_id(id); \ + NtId_Type *ntp = (NtId_Type *)id; \ if (ntp->nodetree) { \ - AnimData *adt2= BKE_animdata_from_id((ID *)ntp); \ - BKE_animdata_fix_paths_rename((ID *)ntp, adt2, ref_id, prefix, oldName, newName, 0, 0, 1);\ + AnimData *adt2 = BKE_animdata_from_id((ID *)ntp); \ + BKE_animdata_fix_paths_rename((ID *)ntp, adt2, ref_id, prefix, oldName, newName, 0, 0, 1); \ } \ - BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1);\ + BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1); \ } /* nodes */ @@ -908,7 +908,7 @@ void BKE_all_animdata_fix_paths_rename(ID *ref_id, const char *prefix, const cha /* Find the first path that matches the given criteria */ // TODO: do we want some method to perform partial matches too? -KS_Path *BKE_keyingset_find_path (KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, int UNUSED(group_mode)) +KS_Path *BKE_keyingset_find_path(KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, int UNUSED(group_mode)) { KS_Path *ksp; @@ -919,20 +919,20 @@ KS_Path *BKE_keyingset_find_path (KeyingSet *ks, ID *id, const char group_name[] /* loop over paths in the current KeyingSet, finding the first one where all settings match * (i.e. the first one where none of the checks fail and equal 0) */ - for (ksp= ks->paths.first; ksp; ksp= ksp->next) { - short eq_id=1, eq_path=1, eq_index=1, eq_group=1; + for (ksp = ks->paths.first; ksp; ksp = ksp->next) { + short eq_id = 1, eq_path = 1, eq_index = 1, eq_group = 1; /* id */ if (id != ksp->id) - eq_id= 0; + eq_id = 0; /* path */ - if ((ksp->rna_path==NULL) || strcmp(rna_path, ksp->rna_path)) - eq_path= 0; + if ((ksp->rna_path == NULL) || strcmp(rna_path, ksp->rna_path)) + eq_path = 0; /* index - need to compare whole-array setting too... */ if (ksp->array_index != array_index) - eq_index= 0; + eq_index = 0; /* group */ if (group_name) { @@ -951,19 +951,19 @@ KS_Path *BKE_keyingset_find_path (KeyingSet *ks, ID *id, const char group_name[] /* Defining Tools --------------------------- */ /* Used to create a new 'custom' KeyingSet for the user, that will be automatically added to the stack */ -KeyingSet *BKE_keyingset_add (ListBase *list, const char idname[], const char name[], short flag, short keyingflag) +KeyingSet *BKE_keyingset_add(ListBase *list, const char idname[], const char name[], short flag, short keyingflag) { KeyingSet *ks; /* allocate new KeyingSet */ - ks= MEM_callocN(sizeof(KeyingSet), "KeyingSet"); + ks = MEM_callocN(sizeof(KeyingSet), "KeyingSet"); BLI_strncpy(ks->idname, idname ? idname : name ? name : "KeyingSet", sizeof(ks->idname)); BLI_strncpy(ks->name, name ? name : idname ? idname : "Keying Set", sizeof(ks->name)); - ks->flag= flag; - ks->keyingflag= keyingflag; + ks->flag = flag; + ks->keyingflag = keyingflag; /* add KeyingSet to list */ BLI_addtail(list, ks); @@ -981,7 +981,7 @@ KeyingSet *BKE_keyingset_add (ListBase *list, const char idname[], const char na /* Add a path to a KeyingSet. Nothing is returned for now... * Checks are performed to ensure that destination is appropriate for the KeyingSet in question */ -KS_Path *BKE_keyingset_add_path (KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, short flag, short groupmode) +KS_Path *BKE_keyingset_add_path(KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, short flag, short groupmode) { KS_Path *ksp; @@ -1005,27 +1005,27 @@ KS_Path *BKE_keyingset_add_path (KeyingSet *ks, ID *id, const char group_name[], } /* allocate a new KeyingSet Path */ - ksp= MEM_callocN(sizeof(KS_Path), "KeyingSet Path"); + ksp = MEM_callocN(sizeof(KS_Path), "KeyingSet Path"); /* just store absolute info */ - ksp->id= id; + ksp->id = id; if (group_name) BLI_strncpy(ksp->group, group_name, sizeof(ksp->group)); else - ksp->group[0]= '\0'; + ksp->group[0] = '\0'; /* store additional info for relative paths (just in case user makes the set relative) */ if (id) - ksp->idtype= GS(id->name); + ksp->idtype = GS(id->name); /* just copy path info */ // TODO: should array index be checked too? - ksp->rna_path= BLI_strdupn(rna_path, strlen(rna_path)); - ksp->array_index= array_index; + ksp->rna_path = BLI_strdupn(rna_path, strlen(rna_path)); + ksp->array_index = array_index; /* store flags */ - ksp->flag= flag; - ksp->groupmode= groupmode; + ksp->flag = flag; + ksp->groupmode = groupmode; /* add KeyingSet path to KeyingSet */ BLI_addtail(&ks->paths, ksp); @@ -1057,11 +1057,11 @@ void BKE_keyingsets_copy(ListBase *newlist, ListBase *list) BLI_duplicatelist(newlist, list); - for (ksn=newlist->first; ksn; ksn=ksn->next) { + for (ksn = newlist->first; ksn; ksn = ksn->next) { BLI_duplicatelist(&ksn->paths, &ksn->paths); - for (kspn=ksn->paths.first; kspn; kspn=kspn->next) - kspn->rna_path= MEM_dupallocN(kspn->rna_path); + for (kspn = ksn->paths.first; kspn; kspn = kspn->next) + kspn->rna_path = MEM_dupallocN(kspn->rna_path); } } @@ -1077,8 +1077,8 @@ void BKE_keyingset_free(KeyingSet *ks) return; /* free each path as we go to avoid looping twice */ - for (ksp= ks->paths.first; ksp; ksp= kspn) { - kspn= ksp->next; + for (ksp = ks->paths.first; ksp; ksp = kspn) { + kspn = ksp->next; BKE_keyingset_free_path(ks, ksp); } } @@ -1093,10 +1093,10 @@ void BKE_keyingsets_free(ListBase *list) return; /* loop over KeyingSets freeing them - * - BKE_keyingset_free() doesn't free the set itself, but it frees its sub-data + * - BKE_keyingset_free() doesn't free the set itself, but it frees its sub-data */ - for (ks= list->first; ks; ks= ksn) { - ksn= ks->next; + for (ks = list->first; ks; ks = ksn) { + ksn = ks->next; BKE_keyingset_free(ks); BLI_freelinkN(list, ks); } @@ -1113,25 +1113,25 @@ void BKE_keyingsets_free(ListBase *list) * - path: original path string (as stored in F-Curve data) * - dst: destination string to write data to */ -static short animsys_remap_path (AnimMapper *UNUSED(remap), char *path, char **dst) +static short animsys_remap_path(AnimMapper *UNUSED(remap), char *path, char **dst) { /* is there a valid remapping table to use? */ //if (remap) { - /* find a matching entry... to use to remap */ - // ...TODO... + /* find a matching entry... to use to remap */ + // ...TODO... //} /* nothing suitable found, so just set dst to look at path (i.e. no alloc/free needed) */ - *dst= path; + *dst = path; return 0; } /* less then 1.0 evaluates to false, use epsilon to avoid float error */ -#define ANIMSYS_FLOAT_AS_BOOL(value) ((value) > ((1.0f-FLT_EPSILON))) +#define ANIMSYS_FLOAT_AS_BOOL(value) ((value) > ((1.0f - FLT_EPSILON))) /* Write the given value to a setting using RNA, and return success */ -static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_index, float value) +static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_index, float value) { PropertyRNA *prop; PointerRNA new_ptr; @@ -1142,13 +1142,13 @@ static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_i if (RNA_path_resolve(ptr, path, &new_ptr, &prop)) { /* set value - only for animatable numerical values */ if (RNA_property_animateable(&new_ptr, prop)) { - int array_len= RNA_property_array_length(&new_ptr, prop); + int array_len = RNA_property_array_length(&new_ptr, prop); if (array_len && array_index >= array_len) { if (G.debug & G_DEBUG) { printf("Animato: Invalid array index. ID = '%s', '%s[%d]', array length is %d\n", - (ptr && ptr->id.data) ? (((ID *)ptr->id.data)->name+2) : "<No ID>", - path, array_index, array_len-1); + (ptr && ptr->id.data) ? (((ID *)ptr->id.data)->name + 2) : "<No ID>", + path, array_index, array_len - 1); } return 0; @@ -1205,7 +1205,7 @@ static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_i * as having been updated. this flag does not cause any updates to * be run, it's for e.g. render engines to synchronize data */ if (new_ptr.id.data) { - ID *id= new_ptr.id.data; + ID *id = new_ptr.id.data; id->flag |= LIB_ID_RECALC; DAG_id_type_tag(G.main, GS(id->name)); } @@ -1220,26 +1220,26 @@ static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_i // where some channels will not exist, but shouldn't lock up Action if (G.debug & G_DEBUG) { printf("Animato: Invalid path. ID = '%s', '%s[%d]'\n", - (ptr && ptr->id.data) ? (((ID *)ptr->id.data)->name+2) : "<No ID>", - path, array_index); + (ptr && ptr->id.data) ? (((ID *)ptr->id.data)->name + 2) : "<No ID>", + path, array_index); } return 0; } } /* Simple replacement based data-setting of the FCurve using RNA */ -static short animsys_execute_fcurve (PointerRNA *ptr, AnimMapper *remap, FCurve *fcu) +static short animsys_execute_fcurve(PointerRNA *ptr, AnimMapper *remap, FCurve *fcu) { char *path = NULL; - short free_path=0; - short ok= 0; + short free_path = 0; + short ok = 0; /* get path, remapped as appropriate to work in its new environment */ - free_path= animsys_remap_path(remap, fcu->rna_path, &path); + free_path = animsys_remap_path(remap, fcu->rna_path, &path); /* write value to setting */ if (path) - ok= animsys_write_rna_setting(ptr, path, fcu->array_index, fcu->curval); + ok = animsys_write_rna_setting(ptr, path, fcu->array_index, fcu->curval); /* free temp path-info */ if (free_path) @@ -1252,16 +1252,16 @@ static short animsys_execute_fcurve (PointerRNA *ptr, AnimMapper *remap, FCurve /* Evaluate all the F-Curves in the given list * This performs a set of standard checks. If extra checks are required, separate code should be used */ -static void animsys_evaluate_fcurves (PointerRNA *ptr, ListBase *list, AnimMapper *remap, float ctime) +static void animsys_evaluate_fcurves(PointerRNA *ptr, ListBase *list, AnimMapper *remap, float ctime) { FCurve *fcu; /* calculate then execute each curve */ - for (fcu= list->first; fcu; fcu= fcu->next) { + for (fcu = list->first; fcu; fcu = fcu->next) { /* check if this F-Curve doesn't belong to a muted group */ - if ((fcu->grp == NULL) || (fcu->grp->flag & AGRP_MUTED)==0) { + if ((fcu->grp == NULL) || (fcu->grp->flag & AGRP_MUTED) == 0) { /* check if this curve should be skipped */ - if ((fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) == 0) { + if ((fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0) { calculate_fcurve(fcu, ctime); animsys_execute_fcurve(ptr, remap, fcu); } @@ -1273,25 +1273,25 @@ static void animsys_evaluate_fcurves (PointerRNA *ptr, ListBase *list, AnimMappe /* Driver Evaluation */ /* Evaluate Drivers */ -static void animsys_evaluate_drivers (PointerRNA *ptr, AnimData *adt, float ctime) +static void animsys_evaluate_drivers(PointerRNA *ptr, AnimData *adt, float ctime) { FCurve *fcu; /* drivers are stored as F-Curves, but we cannot use the standard code, as we need to check if * the depsgraph requested that this driver be evaluated... */ - for (fcu= adt->drivers.first; fcu; fcu= fcu->next) { - ChannelDriver *driver= fcu->driver; - short ok= 0; + for (fcu = adt->drivers.first; fcu; fcu = fcu->next) { + ChannelDriver *driver = fcu->driver; + short ok = 0; /* check if this driver's curve should be skipped */ - if ((fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) == 0) { + if ((fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0) { /* check if driver itself is tagged for recalculation */ - if ((driver) && !(driver->flag & DRIVER_FLAG_INVALID)/*&& (driver->flag & DRIVER_FLAG_RECALC)*/) { // XXX driver recalc flag is not set yet by depsgraph! + if ((driver) && !(driver->flag & DRIVER_FLAG_INVALID) /*&& (driver->flag & DRIVER_FLAG_RECALC)*/) { // XXX driver recalc flag is not set yet by depsgraph! /* evaluate this using values set already in other places */ // NOTE: for 'layering' option later on, we should check if we should remove old value before adding new to only be done when drivers only changed calculate_fcurve(fcu, ctime); - ok= animsys_execute_fcurve(ptr, NULL, fcu); + ok = animsys_execute_fcurve(ptr, NULL, fcu); /* clear recalc flag */ driver->flag &= ~DRIVER_FLAG_RECALC; @@ -1311,7 +1311,7 @@ static void animsys_evaluate_drivers (PointerRNA *ptr, AnimData *adt, float ctim * to reduce the amount of times that users end up having to "revive" wrongly-assigned * actions */ -static void action_idcode_patch_check (ID *id, bAction *act) +static void action_idcode_patch_check(ID *id, bAction *act) { int idcode = 0; @@ -1324,7 +1324,7 @@ static void action_idcode_patch_check (ID *id, bAction *act) /* the actual checks... hopefully not too much of a performance hit in the long run... */ if (act->idroot == 0) { /* use the current root if not set already (i.e. newly created actions and actions from 2.50-2.57 builds) - * - this has problems if there are 2 users, and the first one encountered is the invalid one + * - this has problems if there are 2 users, and the first one encountered is the invalid one * in which case, the user will need to manually fix this (?) */ act->idroot = idcode; @@ -1333,7 +1333,7 @@ static void action_idcode_patch_check (ID *id, bAction *act) /* only report this error if debug mode is enabled (to save performance everywhere else) */ if (G.debug & G_DEBUG) { printf("AnimSys Safety Check Failed: Action '%s' is not meant to be used from ID-Blocks of type %d such as '%s'\n", - act->id.name+2, idcode, id->name); + act->id.name + 2, idcode, id->name); } } } @@ -1347,7 +1347,7 @@ void animsys_evaluate_action_group(PointerRNA *ptr, bAction *act, bActionGroup * /* check if mapper is appropriate for use here (we set to NULL if it's inappropriate) */ if (ELEM(NULL, act, agrp)) return; - if ((remap) && (remap->target != act)) remap= NULL; + if ((remap) && (remap->target != act)) remap = NULL; action_idcode_patch_check(ptr->id.data, act); @@ -1356,9 +1356,9 @@ void animsys_evaluate_action_group(PointerRNA *ptr, bAction *act, bActionGroup * return; /* calculate then execute each curve */ - for (fcu= agrp->channels.first; (fcu) && (fcu->grp == agrp); fcu= fcu->next) { + for (fcu = agrp->channels.first; (fcu) && (fcu->grp == agrp); fcu = fcu->next) { /* check if this curve should be skipped */ - if ((fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) == 0) { + if ((fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0) { calculate_fcurve(fcu, ctime); animsys_execute_fcurve(ptr, remap, fcu); } @@ -1370,7 +1370,7 @@ void animsys_evaluate_action(PointerRNA *ptr, bAction *act, AnimMapper *remap, f { /* check if mapper is appropriate for use here (we set to NULL if it's inappropriate) */ if (act == NULL) return; - if ((remap) && (remap->target != act)) remap= NULL; + if ((remap) && (remap->target != act)) remap = NULL; action_idcode_patch_check(ptr->id.data, act); @@ -1382,18 +1382,18 @@ void animsys_evaluate_action(PointerRNA *ptr, bAction *act, AnimMapper *remap, f /* NLA System - Evaluation */ /* calculate influence of strip based for given frame based on blendin/out values */ -static float nlastrip_get_influence (NlaStrip *strip, float cframe) +static float nlastrip_get_influence(NlaStrip *strip, float cframe) { /* sanity checks - normalize the blendin/out values? */ - strip->blendin= fabsf(strip->blendin); - strip->blendout= fabsf(strip->blendout); + strip->blendin = fabsf(strip->blendin); + strip->blendout = fabsf(strip->blendout); /* result depends on where frame is in respect to blendin/out values */ - if (IS_EQ(strip->blendin, 0)==0 && (cframe <= (strip->start + strip->blendin))) { + if (IS_EQ(strip->blendin, 0) == 0 && (cframe <= (strip->start + strip->blendin))) { /* there is some blend-in */ return fabsf(cframe - strip->start) / (strip->blendin); } - else if (IS_EQ(strip->blendout, 0)==0 && (cframe >= (strip->end - strip->blendout))) { + else if (IS_EQ(strip->blendout, 0) == 0 && (cframe >= (strip->end - strip->blendout))) { /* there is some blend-out */ return fabsf(strip->end - cframe) / (strip->blendout); } @@ -1404,13 +1404,13 @@ static float nlastrip_get_influence (NlaStrip *strip, float cframe) } /* evaluate the evaluation time and influence for the strip, storing the results in the strip */ -static void nlastrip_evaluate_controls (NlaStrip *strip, float ctime) +static void nlastrip_evaluate_controls(NlaStrip *strip, float ctime) { /* firstly, analytically generate values for influence and time (if applicable) */ if ((strip->flag & NLASTRIP_FLAG_USR_TIME) == 0) - strip->strip_time= nlastrip_get_frame(strip, ctime, NLATIME_CONVERT_EVAL); + strip->strip_time = nlastrip_get_frame(strip, ctime, NLATIME_CONVERT_EVAL); if ((strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) == 0) - strip->influence= nlastrip_get_influence(strip, ctime); + strip->influence = nlastrip_get_influence(strip, ctime); /* now strip's evaluate F-Curves for these settings (if applicable) */ if (strip->fcurves.first) { @@ -1429,23 +1429,23 @@ static void nlastrip_evaluate_controls (NlaStrip *strip, float ctime) */ // NOTE: if we add any more of these special cases, we better group them up nicely... if ((strip->flag & NLASTRIP_FLAG_USR_TIME) && (strip->flag & NLASTRIP_FLAG_USR_TIME_CYCLIC)) - strip->strip_time= fmod(strip->strip_time - strip->actstart, strip->actend - strip->actstart); + strip->strip_time = fmod(strip->strip_time - strip->actstart, strip->actend - strip->actstart); } /* gets the strip active at the current time for a list of strips for evaluation purposes */ -NlaEvalStrip *nlastrips_ctime_get_strip (ListBase *list, ListBase *strips, short index, float ctime) +NlaEvalStrip *nlastrips_ctime_get_strip(ListBase *list, ListBase *strips, short index, float ctime) { - NlaStrip *strip, *estrip=NULL; + NlaStrip *strip, *estrip = NULL; NlaEvalStrip *nes; - short side= 0; + short side = 0; /* loop over strips, checking if they fall within the range */ - for (strip= strips->first; strip; strip= strip->next) { + for (strip = strips->first; strip; strip = strip->next) { /* check if current time occurs within this strip */ if (IN_RANGE_INCL(ctime, strip->start, strip->end)) { /* this strip is active, so try to use it */ - estrip= strip; - side= NES_TIME_WITHIN; + estrip = strip; + side = NES_TIME_WITHIN; break; } @@ -1454,22 +1454,22 @@ NlaEvalStrip *nlastrips_ctime_get_strip (ListBase *list, ListBase *strips, short if (strip == strips->first) { /* before first strip - only try to use it if it extends backwards in time too */ if (strip->extendmode == NLASTRIP_EXTEND_HOLD) - estrip= strip; + estrip = strip; /* side is 'before' regardless of whether there's a useful strip */ - side= NES_TIME_BEFORE; + side = NES_TIME_BEFORE; } else { /* before next strip - previous strip has ended, but next hasn't begun, * so blending mode depends on whether strip is being held or not... - * - only occurs when no transition strip added, otherwise the transition would have - * been picked up above... + * - only occurs when no transition strip added, otherwise the transition would have + * been picked up above... */ - strip= strip->prev; + strip = strip->prev; if (strip->extendmode != NLASTRIP_EXTEND_NOTHING) - estrip= strip; - side= NES_TIME_AFTER; + estrip = strip; + side = NES_TIME_AFTER; } break; } @@ -1479,9 +1479,9 @@ NlaEvalStrip *nlastrips_ctime_get_strip (ListBase *list, ListBase *strips, short /* only if this is the last strip should we do anything, and only if that is being held */ if (strip == strips->last) { if (strip->extendmode != NLASTRIP_EXTEND_NOTHING) - estrip= strip; + estrip = strip; - side= NES_TIME_AFTER; + side = NES_TIME_AFTER; break; } @@ -1498,15 +1498,15 @@ NlaEvalStrip *nlastrips_ctime_get_strip (ListBase *list, ListBase *strips, short /* if ctime was not within the boundaries of the strip, clamp! */ switch (side) { case NES_TIME_BEFORE: /* extend first frame only */ - ctime= estrip->start; + ctime = estrip->start; break; case NES_TIME_AFTER: /* extend last frame only */ - ctime= estrip->end; + ctime = estrip->end; break; } /* evaluate strip's evaluation controls - * - skip if no influence (i.e. same effect as muting the strip) + * - skip if no influence (i.e. same effect as muting the strip) * - negative influence is not supported yet... how would that be defined? */ // TODO: this sounds a bit hacky having a few isolated F-Curves stuck on some data it operates on... @@ -1535,12 +1535,12 @@ NlaEvalStrip *nlastrips_ctime_get_strip (ListBase *list, ListBase *strips, short } /* add to list of strips we need to evaluate */ - nes= MEM_callocN(sizeof(NlaEvalStrip), "NlaEvalStrip"); + nes = MEM_callocN(sizeof(NlaEvalStrip), "NlaEvalStrip"); - nes->strip= estrip; - nes->strip_mode= side; - nes->track_index= index; - nes->strip_time= estrip->strip_time; + nes->strip = estrip; + nes->strip_mode = side; + nes->track_index = index; + nes->strip_time = estrip->strip_time; if (list) BLI_addtail(list, nes); @@ -1553,7 +1553,7 @@ NlaEvalStrip *nlastrips_ctime_get_strip (ListBase *list, ListBase *strips, short /* find an NlaEvalChannel that matches the given criteria * - ptr and prop are the RNA data to find a match for */ -static NlaEvalChannel *nlaevalchan_find_match (ListBase *channels, PointerRNA *ptr, PropertyRNA *prop, int array_index) +static NlaEvalChannel *nlaevalchan_find_match(ListBase *channels, PointerRNA *ptr, PropertyRNA *prop, int array_index) { NlaEvalChannel *nec; @@ -1562,7 +1562,7 @@ static NlaEvalChannel *nlaevalchan_find_match (ListBase *channels, PointerRNA *p return NULL; /* loop through existing channels, checking for a channel which affects the same property */ - for (nec= channels->first; nec; nec= nec->next) { + for (nec = channels->first; nec; nec = nec->next) { /* - comparing the PointerRNA's is done by comparing the pointers * to the actual struct the property resides in, since that all the * other data stored in PointerRNA cannot allow us to definitively @@ -1577,10 +1577,10 @@ static NlaEvalChannel *nlaevalchan_find_match (ListBase *channels, PointerRNA *p } /* verify that an appropriate NlaEvalChannel for this F-Curve exists */ -static NlaEvalChannel *nlaevalchan_verify (PointerRNA *ptr, ListBase *channels, NlaEvalStrip *nes, FCurve *fcu, short *newChan) +static NlaEvalChannel *nlaevalchan_verify(PointerRNA *ptr, ListBase *channels, NlaEvalStrip *nes, FCurve *fcu, short *newChan) { NlaEvalChannel *nec; - NlaStrip *strip= nes->strip; + NlaStrip *strip = nes->strip; PropertyRNA *prop; PointerRNA new_ptr; char *path = NULL; @@ -1591,50 +1591,50 @@ static NlaEvalChannel *nlaevalchan_verify (PointerRNA *ptr, ListBase *channels, return NULL; /* get RNA pointer+property info from F-Curve for more convenient handling */ - /* get path, remapped as appropriate to work in its new environment */ + /* get path, remapped as appropriate to work in its new environment */ /* free_path= */ /* UNUSED */ animsys_remap_path(strip->remap, fcu->rna_path, &path); - /* a valid property must be available, and it must be animatable */ + /* a valid property must be available, and it must be animatable */ if (RNA_path_resolve(ptr, path, &new_ptr, &prop) == 0) { if (G.debug & G_DEBUG) printf("NLA Strip Eval: Cannot resolve path\n"); return NULL; } - /* only ok if animatable */ + /* only ok if animatable */ else if (RNA_property_animateable(&new_ptr, prop) == 0) { if (G.debug & G_DEBUG) printf("NLA Strip Eval: Property not animatable\n"); return NULL; } /* try to find a match */ - nec= nlaevalchan_find_match(channels, &new_ptr, prop, fcu->array_index); + nec = nlaevalchan_find_match(channels, &new_ptr, prop, fcu->array_index); /* allocate a new struct for this if none found */ if (nec == NULL) { - nec= MEM_callocN(sizeof(NlaEvalChannel), "NlaEvalChannel"); - *newChan= 1; + nec = MEM_callocN(sizeof(NlaEvalChannel), "NlaEvalChannel"); + *newChan = 1; BLI_addtail(channels, nec); - nec->ptr= new_ptr; - nec->prop= prop; - nec->index= fcu->array_index; + nec->ptr = new_ptr; + nec->prop = prop; + nec->index = fcu->array_index; } else - *newChan= 0; + *newChan = 0; /* we can now return */ return nec; } /* accumulate (i.e. blend) the given value on to the channel it affects */ -static void nlaevalchan_accumulate (NlaEvalChannel *nec, NlaEvalStrip *nes, short newChan, float value) +static void nlaevalchan_accumulate(NlaEvalChannel *nec, NlaEvalStrip *nes, short newChan, float value) { - NlaStrip *strip= nes->strip; - short blendmode= strip->blendmode; - float inf= strip->influence; + NlaStrip *strip = nes->strip; + short blendmode = strip->blendmode; + float inf = strip->influence; /* if channel is new, just store value regardless of blending factors, etc. */ if (newChan) { - nec->value= value; + nec->value = value; return; } @@ -1671,13 +1671,13 @@ static void nlaevalchan_accumulate (NlaEvalChannel *nec, NlaEvalStrip *nes, shor * - the influence of the accumulated data (elsewhere, that is called dstweight) * is 1 - influence, since the strip's influence is srcweight */ - nec->value= nec->value * (1.0f - inf) + value; + nec->value = nec->value * (1.0f - inf) + value; break; } } /* accumulate the results of a temporary buffer with the results of the full-buffer */ -static void nlaevalchan_buffers_accumulate (ListBase *channels, ListBase *tmp_buffer, NlaEvalStrip *nes) +static void nlaevalchan_buffers_accumulate(ListBase *channels, ListBase *tmp_buffer, NlaEvalStrip *nes) { NlaEvalChannel *nec, *necn, *necd; @@ -1686,12 +1686,12 @@ static void nlaevalchan_buffers_accumulate (ListBase *channels, ListBase *tmp_bu return; /* accumulate results in tmp_channels buffer to the accumulation buffer */ - for (nec= tmp_buffer->first; nec; nec= necn) { + for (nec = tmp_buffer->first; nec; nec = necn) { /* get pointer to next channel in case we remove the current channel from the temp-buffer */ - necn= nec->next; + necn = nec->next; /* try to find an existing matching channel for this setting in the accumulation buffer */ - necd= nlaevalchan_find_match(channels, &nec->ptr, nec->prop, nec->index); + necd = nlaevalchan_find_match(channels, &nec->ptr, nec->prop, nec->index); /* if there was a matching channel already in the buffer, accumulate to it, * otherwise, add the current channel to the buffer for efficiency @@ -1712,39 +1712,39 @@ static void nlaevalchan_buffers_accumulate (ListBase *channels, ListBase *tmp_bu /* F-Modifier stack joining/separation utilities - should we generalise these for BLI_listbase.h interface? */ /* Temporarily join two lists of modifiers together, storing the result in a third list */ -static void nlaeval_fmodifiers_join_stacks (ListBase *result, ListBase *list1, ListBase *list2) +static void nlaeval_fmodifiers_join_stacks(ListBase *result, ListBase *list1, ListBase *list2) { FModifier *fcm1, *fcm2; /* if list1 is invalid... */ if (ELEM(NULL, list1, list1->first)) { if (list2 && list2->first) { - result->first= list2->first; - result->last= list2->last; + result->first = list2->first; + result->last = list2->last; } } /* if list 2 is invalid... */ else if (ELEM(NULL, list2, list2->first)) { - result->first= list1->first; - result->last= list1->last; + result->first = list1->first; + result->last = list1->last; } else { /* list1 should be added first, and list2 second, with the endpoints of these being the endpoints for result - * - the original lists must be left unchanged though, as we need that fact for restoring + * - the original lists must be left unchanged though, as we need that fact for restoring */ - result->first= list1->first; - result->last= list2->last; + result->first = list1->first; + result->last = list2->last; - fcm1= list1->last; - fcm2= list2->first; + fcm1 = list1->last; + fcm2 = list2->first; - fcm1->next= fcm2; - fcm2->prev= fcm1; + fcm1->next = fcm2; + fcm2->prev = fcm1; } } /* Split two temporary lists of modifiers */ -static void nlaeval_fmodifiers_split_stacks (ListBase *list1, ListBase *list2) +static void nlaeval_fmodifiers_split_stacks(ListBase *list1, ListBase *list2) { FModifier *fcm1, *fcm2; @@ -1755,21 +1755,21 @@ static void nlaeval_fmodifiers_split_stacks (ListBase *list1, ListBase *list2) return; /* get endpoints */ - fcm1= list1->last; - fcm2= list2->first; + fcm1 = list1->last; + fcm2 = list2->first; /* clear their links */ - fcm1->next= NULL; - fcm2->prev= NULL; + fcm1->next = NULL; + fcm2->prev = NULL; } /* ---------------------- */ /* evaluate action-clip strip */ -static void nlastrip_evaluate_actionclip (PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes) +static void nlastrip_evaluate_actionclip(PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes) { ListBase tmp_modifiers = {NULL, NULL}; - NlaStrip *strip= nes->strip; + NlaStrip *strip = nes->strip; FCurve *fcu; float evaltime; @@ -1788,16 +1788,16 @@ static void nlastrip_evaluate_actionclip (PointerRNA *ptr, ListBase *channels, L nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &strip->modifiers, modifiers); /* evaluate strip's modifiers which modify time to evaluate the base curves at */ - evaltime= evaluate_time_fmodifiers(&tmp_modifiers, NULL, 0.0f, strip->strip_time); + evaltime = evaluate_time_fmodifiers(&tmp_modifiers, NULL, 0.0f, strip->strip_time); /* evaluate all the F-Curves in the action, saving the relevant pointers to data that will need to be used */ - for (fcu= strip->act->curves.first; fcu; fcu= fcu->next) { + for (fcu = strip->act->curves.first; fcu; fcu = fcu->next) { NlaEvalChannel *nec; float value = 0.0f; short newChan = -1; /* check if this curve should be skipped */ - if (fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) + if (fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) continue; if ((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) continue; @@ -1805,7 +1805,7 @@ static void nlastrip_evaluate_actionclip (PointerRNA *ptr, ListBase *channels, L /* evaluate the F-Curve's value for the time given in the strip * NOTE: we use the modified time here, since strip's F-Curve Modifiers are applied on top of this */ - value= evaluate_fcurve(fcu, evaltime); + value = evaluate_fcurve(fcu, evaltime); /* apply strip's F-Curve Modifiers on this value * NOTE: we apply the strip's original evaluation time not the modified one (as per standard F-Curve eval) @@ -1816,7 +1816,7 @@ static void nlastrip_evaluate_actionclip (PointerRNA *ptr, ListBase *channels, L /* get an NLA evaluation channel to work with, and accumulate the evaluated value with the value(s) * stored in this channel if it has been used already */ - nec= nlaevalchan_verify(ptr, channels, nes, fcu, &newChan); + nec = nlaevalchan_verify(ptr, channels, nes, fcu, &newChan); if (nec) nlaevalchan_accumulate(nec, nes, newChan, value); } @@ -1826,7 +1826,7 @@ static void nlastrip_evaluate_actionclip (PointerRNA *ptr, ListBase *channels, L } /* evaluate transition strip */ -static void nlastrip_evaluate_transition (PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes) +static void nlastrip_evaluate_transition(PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes) { ListBase tmp_channels = {NULL, NULL}; ListBase tmp_modifiers = {NULL, NULL}; @@ -1844,12 +1844,12 @@ static void nlastrip_evaluate_transition (PointerRNA *ptr, ListBase *channels, L * otherwise they will be interpolated wrong */ if (nes->strip->flag & NLASTRIP_FLAG_REVERSE) { - s1= nes->strip->next; - s2= nes->strip->prev; + s1 = nes->strip->next; + s2 = nes->strip->prev; } else { - s1= nes->strip->prev; - s2= nes->strip->next; + s1 = nes->strip->prev; + s2 = nes->strip->next; } /* prepare template for 'evaluation strip' @@ -1859,18 +1859,18 @@ static void nlastrip_evaluate_transition (PointerRNA *ptr, ListBase *channels, L * which doubles up as an additional weighting factor for the strip influences * which allows us to appear to be 'interpolating' between the two extremes */ - tmp_nes= *nes; + tmp_nes = *nes; /* evaluate these strips into a temp-buffer (tmp_channels) */ // FIXME: modifier evalation here needs some work... - /* first strip */ - tmp_nes.strip_mode= NES_TIME_TRANSITION_START; - tmp_nes.strip= s1; + /* first strip */ + tmp_nes.strip_mode = NES_TIME_TRANSITION_START; + tmp_nes.strip = s1; nlastrip_evaluate(ptr, &tmp_channels, &tmp_modifiers, &tmp_nes); - /* second strip */ - tmp_nes.strip_mode= NES_TIME_TRANSITION_END; - tmp_nes.strip= s2; + /* second strip */ + tmp_nes.strip_mode = NES_TIME_TRANSITION_END; + tmp_nes.strip = s2; nlastrip_evaluate(ptr, &tmp_channels, &tmp_modifiers, &tmp_nes); @@ -1882,11 +1882,11 @@ static void nlastrip_evaluate_transition (PointerRNA *ptr, ListBase *channels, L } /* evaluate meta-strip */ -static void nlastrip_evaluate_meta (PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes) +static void nlastrip_evaluate_meta(PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes) { ListBase tmp_channels = {NULL, NULL}; ListBase tmp_modifiers = {NULL, NULL}; - NlaStrip *strip= nes->strip; + NlaStrip *strip = nes->strip; NlaEvalStrip *tmp_nes; float evaltime; @@ -1902,8 +1902,8 @@ static void nlastrip_evaluate_meta (PointerRNA *ptr, ListBase *channels, ListBas nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &strip->modifiers, modifiers); /* find the child-strip to evaluate */ - evaltime= (nes->strip_time * (strip->end - strip->start)) + strip->start; - tmp_nes= nlastrips_ctime_get_strip(NULL, &strip->strips, -1, evaltime); + evaltime = (nes->strip_time * (strip->end - strip->start)) + strip->start; + tmp_nes = nlastrips_ctime_get_strip(NULL, &strip->strips, -1, evaltime); if (tmp_nes == NULL) return; @@ -1925,7 +1925,7 @@ static void nlastrip_evaluate_meta (PointerRNA *ptr, ListBase *channels, ListBas /* evaluates the given evaluation strip */ void nlastrip_evaluate(PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes) { - NlaStrip *strip= nes->strip; + NlaStrip *strip = nes->strip; /* to prevent potential infinite recursion problems (i.e. transition strip, beside meta strip containing a transition * several levels deep inside it), we tag the current strip as being evaluated, and clear this when we leave @@ -1965,11 +1965,11 @@ void nladata_flush_channels(ListBase *channels) return; /* for each channel with accumulated values, write its value on the property it affects */ - for (nec= channels->first; nec; nec= nec->next) { - PointerRNA *ptr= &nec->ptr; - PropertyRNA *prop= nec->prop; - int array_index= nec->index; - float value= nec->value; + for (nec = channels->first; nec; nec = nec->next) { + PointerRNA *ptr = &nec->ptr; + PropertyRNA *prop = nec->prop; + int array_index = nec->index; + float value = nec->value; /* write values - see animsys_write_rna_setting() to sync the code */ switch (RNA_property_type(prop)) { @@ -2007,23 +2007,23 @@ void nladata_flush_channels(ListBase *channels) * ! This is exported so that keyframing code can use this for make use of it for anim layers support * > echannels: (list<NlaEvalChannels>) evaluation channels with calculated values */ -static void animsys_evaluate_nla (ListBase *echannels, PointerRNA *ptr, AnimData *adt, float ctime) +static void animsys_evaluate_nla(ListBase *echannels, PointerRNA *ptr, AnimData *adt, float ctime) { NlaTrack *nlt; - short track_index=0; + short track_index = 0; short has_strips = 0; - ListBase estrips= {NULL, NULL}; + ListBase estrips = {NULL, NULL}; NlaEvalStrip *nes; /* 1. get the stack of strips to evaluate at current time (influence calculated here) */ - for (nlt=adt->nla_tracks.first; nlt; nlt=nlt->next, track_index++) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next, track_index++) { /* stop here if tweaking is on and this strip is the tweaking track (it will be the first one that's 'disabled')... */ if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED)) break; /* skip if we're only considering a track tagged 'solo' */ - if ((adt->flag & ADT_NLA_SOLO_TRACK) && (nlt->flag & NLATRACK_SOLO)==0) + if ((adt->flag & ADT_NLA_SOLO_TRACK) && (nlt->flag & NLATRACK_SOLO) == 0) continue; /* skip if track is muted */ if (nlt->flag & NLATRACK_MUTED) @@ -2033,11 +2033,11 @@ static void animsys_evaluate_nla (ListBase *echannels, PointerRNA *ptr, AnimData * - used for mainly for still allowing normal action evaluation... */ if (nlt->strips.first) - has_strips= 1; + has_strips = 1; /* otherwise, get strip to evaluate for this channel */ - nes= nlastrips_ctime_get_strip(&estrips, &nlt->strips, track_index, ctime); - if (nes) nes->track= nlt; + nes = nlastrips_ctime_get_strip(&estrips, &nlt->strips, track_index, ctime); + if (nes) nes->track = nlt; } /* add 'active' Action (may be tweaking track) as last strip to evaluate in NLA stack @@ -2045,14 +2045,14 @@ static void animsys_evaluate_nla (ListBase *echannels, PointerRNA *ptr, AnimData * - however, if the 'solo' track houses the current 'tweaking' strip, * then we should allow this to play, otherwise nothing happens */ - if ((adt->action) && ((adt->flag & ADT_NLA_SOLO_TRACK)==0 || (adt->flag & ADT_NLA_EDIT_ON))) { + if ((adt->action) && ((adt->flag & ADT_NLA_SOLO_TRACK) == 0 || (adt->flag & ADT_NLA_EDIT_ON))) { /* if there are strips, evaluate action as per NLA rules */ if ((has_strips) || (adt->actstrip)) { /* make dummy NLA strip, and add that to the stack */ - NlaStrip dummy_strip= {NULL}; + NlaStrip dummy_strip = {NULL}; ListBase dummy_trackslist; - dummy_trackslist.first= dummy_trackslist.last= &dummy_strip; + dummy_trackslist.first = dummy_trackslist.last = &dummy_strip; if ((nlt) && !(adt->flag & ADT_NLA_EDIT_NOMAP)) { /* edit active action in-place according to its active strip, so copy the data */ @@ -2061,17 +2061,17 @@ static void animsys_evaluate_nla (ListBase *echannels, PointerRNA *ptr, AnimData } else { /* set settings of dummy NLA strip from AnimData settings */ - dummy_strip.act= adt->action; - dummy_strip.remap= adt->remap; + dummy_strip.act = adt->action; + dummy_strip.remap = adt->remap; /* action range is calculated taking F-Modifiers into account (which making new strips doesn't do due to the troublesome nature of that) */ calc_action_range(dummy_strip.act, &dummy_strip.actstart, &dummy_strip.actend, 1); dummy_strip.start = dummy_strip.actstart; - dummy_strip.end = (IS_EQF(dummy_strip.actstart, dummy_strip.actend)) ? (dummy_strip.actstart + 1.0f): (dummy_strip.actend); + dummy_strip.end = (IS_EQF(dummy_strip.actstart, dummy_strip.actend)) ? (dummy_strip.actstart + 1.0f) : (dummy_strip.actend); - dummy_strip.blendmode= adt->act_blendmode; - dummy_strip.extendmode= adt->act_extendmode; - dummy_strip.influence= adt->act_influence; + dummy_strip.blendmode = adt->act_blendmode; + dummy_strip.extendmode = adt->act_extendmode; + dummy_strip.influence = adt->act_influence; } /* add this to our list of evaluation strips */ @@ -2091,7 +2091,7 @@ static void animsys_evaluate_nla (ListBase *echannels, PointerRNA *ptr, AnimData /* 2. for each strip, evaluate then accumulate on top of existing channels, but don't set values yet */ - for (nes= estrips.first; nes; nes= nes->next) + for (nes = estrips.first; nes; nes = nes->next) nlastrip_evaluate(ptr, echannels, NULL, nes); /* 3. free temporary evaluation data that's not used elsewhere */ @@ -2102,9 +2102,9 @@ static void animsys_evaluate_nla (ListBase *echannels, PointerRNA *ptr, AnimData * - All channels that will be affected are not cleared anymore. Instead, we just evaluate into * some temp channels, where values can be accumulated in one go. */ -static void animsys_calculate_nla (PointerRNA *ptr, AnimData *adt, float ctime) +static void animsys_calculate_nla(PointerRNA *ptr, AnimData *adt, float ctime) { - ListBase echannels= {NULL, NULL}; + ListBase echannels = {NULL, NULL}; // TODO: need to zero out all channels used, otherwise we have problems with threadsafety // and also when the user jumps between different times instead of moving sequentially... @@ -2126,7 +2126,7 @@ static void animsys_calculate_nla (PointerRNA *ptr, AnimData *adt, float ctime) /* Add or get existing Override for given setting */ #if 0 -AnimOverride *BKE_animsys_validate_override (PointerRNA *UNUSED(ptr), char *UNUSED(path), int UNUSED(array_index)) +AnimOverride *BKE_animsys_validate_override(PointerRNA *UNUSED(ptr), char *UNUSED(path), int UNUSED(array_index)) { // FIXME: need to define how to get overrides return NULL; @@ -2136,12 +2136,12 @@ AnimOverride *BKE_animsys_validate_override (PointerRNA *UNUSED(ptr), char *UNUS /* -------------------- */ /* Evaluate Overrides */ -static void animsys_evaluate_overrides (PointerRNA *ptr, AnimData *adt) +static void animsys_evaluate_overrides(PointerRNA *ptr, AnimData *adt) { AnimOverride *aor; /* for each override, simply execute... */ - for (aor= adt->overrides.first; aor; aor= aor->next) + for (aor = adt->overrides.first; aor; aor = aor->next) animsys_write_rna_setting(ptr, aor->rna_path, aor->array_index, aor->value); } @@ -2176,7 +2176,7 @@ static void animsys_evaluate_overrides (PointerRNA *ptr, AnimData *adt) * * Current Status: * - Currently (as of September 2009), overrides we haven't needed to (fully) implement overrides. - * However, the code for this is relatively harmless, so is left in the code for now. + * However, the code for this is relatively harmless, so is left in the code for now. */ /* Evaluation loop for evaluation animation data @@ -2245,7 +2245,7 @@ void BKE_animsys_evaluate_animdata(Scene *scene, ID *id, AnimData *adt, float ct } /* clear recalc flag now */ - adt->recalc= 0; + adt->recalc = 0; } /* Evaluation of all ID-blocks with Animation Data blocks - Animation Data Only @@ -2268,25 +2268,25 @@ void BKE_animsys_evaluate_all_animation(Main *main, Scene *scene, float ctime) * this outside of the function may make things slightly faster? */ #define EVAL_ANIM_IDS(first, aflag) \ - for (id= first; id; id= id->next) { \ + for (id = first; id; id = id->next) { \ if (ID_REAL_USERS(id) > 0) { \ - AnimData *adt= BKE_animdata_from_id(id); \ + AnimData *adt = BKE_animdata_from_id(id); \ BKE_animsys_evaluate_animdata(scene, id, adt, ctime, aflag); \ } \ } /* another macro for the "embedded" nodetree cases * - this is like EVAL_ANIM_IDS, but this handles the case "embedded nodetrees" * (i.e. scene/material/texture->nodetree) which we need a special exception - * for, otherwise they'd get skipped + * for, otherwise they'd get skipped * - ntp = "node tree parent" = datablock where node tree stuff resides */ #define EVAL_ANIM_NODETREE_IDS(first, NtId_Type, aflag) \ - for (id= first; id; id= id->next) { \ + for (id = first; id; id = id->next) { \ if (ID_REAL_USERS(id) > 0) { \ - AnimData *adt= BKE_animdata_from_id(id); \ - NtId_Type *ntp= (NtId_Type *)id; \ + AnimData *adt = BKE_animdata_from_id(id); \ + NtId_Type *ntp = (NtId_Type *)id; \ if (ntp->nodetree) { \ - AnimData *adt2= BKE_animdata_from_id((ID *)ntp->nodetree); \ + AnimData *adt2 = BKE_animdata_from_id((ID *)ntp->nodetree); \ BKE_animsys_evaluate_animdata(scene, (ID *)ntp->nodetree, adt2, ctime, ADT_RECALC_ANIM); \ } \ BKE_animsys_evaluate_animdata(scene, id, adt, ctime, aflag); \ @@ -2354,10 +2354,10 @@ void BKE_animsys_evaluate_all_animation(Main *main, Scene *scene, float ctime) EVAL_ANIM_IDS(main->linestyle.first, ADT_RECALC_ANIM); /* objects */ - /* ADT_RECALC_ANIM doesn't need to be supplied here, since object AnimData gets - * this tagged by Depsgraph on framechange. This optimization means that objects - * linked from other (not-visible) scenes will not need their data calculated. - */ + /* ADT_RECALC_ANIM doesn't need to be supplied here, since object AnimData gets + * this tagged by Depsgraph on framechange. This optimization means that objects + * linked from other (not-visible) scenes will not need their data calculated. + */ EVAL_ANIM_IDS(main->object.first, 0); /* worlds */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 09b295aabf1..fe95d15f82e 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -459,7 +459,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) } } - hlength1 = bone->ease1 * length * 0.390464f; /* 0.5*sqrt(2)*kappa, the handle length for near-perfect circles */ + hlength1 = bone->ease1 * length * 0.390464f; /* 0.5f * sqrt(2) * kappa, the handle length for near-perfect circles */ hlength2 = bone->ease2 * length * 0.390464f; /* evaluate next and prev bones */ @@ -566,14 +566,10 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) if (bone->segments > MAX_BBONE_SUBDIV) bone->segments = MAX_BBONE_SUBDIV; - BKE_curve_forward_diff_bezier(0.0, h1[0], h2[0], 0.0, data[0], - MAX_BBONE_SUBDIV, 4*sizeof(float)); - BKE_curve_forward_diff_bezier(0.0, h1[1], length + h2[1], length, data[0]+1, - MAX_BBONE_SUBDIV, 4*sizeof(float)); - BKE_curve_forward_diff_bezier(0.0, h1[2], h2[2], 0.0, data[0]+2, - MAX_BBONE_SUBDIV, 4*sizeof(float)); - BKE_curve_forward_diff_bezier(roll1, roll1 + 0.390464f*(roll2-roll1), roll2 - 0.390464f*(roll2-roll1), roll2, data[0]+3, - MAX_BBONE_SUBDIV, 4*sizeof(float)); + BKE_curve_forward_diff_bezier(0.0f, h1[0], h2[0], 0.0f, data[0], MAX_BBONE_SUBDIV, 4 * sizeof(float)); + BKE_curve_forward_diff_bezier(0.0f, h1[1], length + h2[1], length, data[0] + 1, MAX_BBONE_SUBDIV, 4 * sizeof(float)); + BKE_curve_forward_diff_bezier(0.0f, h1[2], h2[2], 0.0f, data[0] + 2, MAX_BBONE_SUBDIV, 4 * sizeof(float)); + BKE_curve_forward_diff_bezier(roll1, roll1 + 0.390464f * (roll2 - roll1), roll2 - 0.390464f * (roll2 - roll1), roll2, data[0] + 3, MAX_BBONE_SUBDIV, 4 * sizeof(float)); equalize_bezier(data[0], bone->segments); /* note: does stride 4! */ @@ -2545,20 +2541,20 @@ int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_tot) } /************** Bounding box ********************/ -int minmax_armature(Object *ob, float min[3], float max[3]) +static int minmax_armature(Object *ob, float r_min[3], float r_max[3]) { bPoseChannel *pchan; /* For now, we assume BKE_pose_where_is has already been called (hence we have valid data in pachan). */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - DO_MINMAX(pchan->pose_head, min, max); - DO_MINMAX(pchan->pose_tail, min, max); + minmax_v3v3_v3(r_min, r_max, pchan->pose_head); + minmax_v3v3_v3(r_min, r_max, pchan->pose_tail); } return (ob->pose->chanbase.first != NULL); } -void boundbox_armature(Object *ob, float *loc, float *size) +static void boundbox_armature(Object *ob, float loc[3], float size[3]) { BoundBox *bb; float min[3], max[3]; diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 3ef2ce56cd6..3450408a0a0 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -177,7 +177,7 @@ static void cdDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) if (dm->numVertData) { for (i = 0; i < dm->numVertData; i++) { - DO_MINMAX(cddm->mvert[i].co, min_r, max_r); + minmax_v3v3_v3(min_r, max_r, cddm->mvert[i].co); } } else { @@ -522,7 +522,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, glNormal3sv(no); \ } \ glVertex3fv(mvert[index].co); \ -} +} (void)0 if (cddm->pbvh && cddm->pbvh_draw) { if (dm->numTessFaceData) { diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index b521285c626..b38f0f78cdb 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -92,7 +92,7 @@ static CM_SOLVER_DEF solvers [] = /* ********** cloth engine ******* */ /* Prototypes for internal functions. -*/ + */ static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertexCos)[3]); static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm ); static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float framenr, int first); @@ -101,10 +101,10 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ); /****************************************************************************** -* -* External interface called by modifier.c clothModifier functions. -* -******************************************************************************/ + * + * External interface called by modifier.c clothModifier functions. + * + ******************************************************************************/ /** * cloth_init - creates a new cloth simulation. * @@ -145,8 +145,8 @@ void cloth_init(ClothModifierData *clmd ) clmd->coll_parms->selfepsilon = 0.75; /* These defaults are copied from softbody.c's - * softbody_calc_forces() function. - */ + * softbody_calc_forces() function. + */ clmd->sim_parms->eff_force_scale = 1000.0; clmd->sim_parms->eff_wind_scale = 250.0; @@ -419,9 +419,64 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul return ret; } +#if 0 +static DerivedMesh *cloth_to_triangles(DerivedMesh *dm) +{ + DerivedMesh *result = NULL; + unsigned int i = 0, j = 0; + unsigned int quads = 0, numfaces = dm->getNumTessFaces(dm); + MFace *mface = dm->getTessFaceArray(dm); + MFace *mface2 = NULL; + + /* calc faces */ + for(i = 0; i < numfaces; i++) + { + if(mface[i].v4) + quads++; + } + + result = CDDM_from_template(dm, dm->getNumVerts(dm), 0, numfaces + quads, 0, 0); + + DM_copy_vert_data(dm, result, 0, 0, dm->getNumVerts(dm)); + DM_copy_tessface_data(dm, result, 0, 0, numfaces); + + DM_ensure_tessface(result); + mface2 = result->getTessFaceArray(result); + + for(i = 0, j = numfaces; i < numfaces; i++) + { + // DG TODO: is this necessary? + mface2[i].v1 = mface[i].v1; + mface2[i].v2 = mface[i].v2; + mface2[i].v3 = mface[i].v3; + + mface2[i].v4 = 0; + //test_index_face(&mface2[i], &result->faceData, i, 3); + + if(mface[i].v4) + { + DM_copy_tessface_data(dm, result, i, j, 1); + + mface2[j].v1 = mface[i].v1; + mface2[j].v2 = mface[i].v3; + mface2[j].v3 = mface[i].v4; + mface2[j].v4 = 0; + //test_index_face(&mface2[j], &result->faceData, j, 3); + + j++; + } + } + + CDDM_calc_edges_tessface(result); + CDDM_tessfaces_to_faces(result); /* builds ngon faces from tess (mface) faces */ + + return result; +} +#endif + /************************************************ * clothModifier_do - main simulation function -************************************************/ + ************************************************/ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3]) { PointCache *cache; @@ -674,10 +729,10 @@ void cloth_free_modifier_extern(ClothModifierData *clmd ) } /****************************************************************************** -* -* Internal functions. -* -******************************************************************************/ + * + * Internal functions. + * + ******************************************************************************/ /** * cloth_to_object - copies the deformed vertices to the object. @@ -923,16 +978,16 @@ static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm ) memcpy ( &clmd->clothObject->mfaces[i], &mface[i], sizeof ( MFace ) ); /* Free the springs since they can't be correct if the vertices - * changed. - */ + * changed. + */ if ( clmd->clothObject->springs != NULL ) MEM_freeN ( clmd->clothObject->springs ); } /*************************************************************************************** -* SPRING NETWORK BUILDING IMPLEMENTATION BEGIN -***************************************************************************************/ + * SPRING NETWORK BUILDING IMPLEMENTATION BEGIN + ***************************************************************************************/ // be careful: implicit solver has to be resettet when using this one! // --> only for implicit handling of this spring! @@ -1221,6 +1276,6 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) } /* cloth_build_springs */ /*************************************************************************************** -* SPRING NETWORK BUILDING IMPLEMENTATION END -***************************************************************************************/ + * SPRING NETWORK BUILDING IMPLEMENTATION END + ***************************************************************************************/ diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 609b2d3496c..a93653537c7 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -161,284 +161,7 @@ void bvhtree_update_from_mvert(BVHTree * bvhtree, MFace *faces, int numfaces, MV /*********************************** Collision modifier code end ***********************************/ - -/** -* gsl_poly_solve_cubic - -* -* copied from SOLVE_CUBIC.C --> GSL -*/ - #define mySWAP(a, b) do { double tmp = b ; b = a ; a = tmp ; } while (0) -#if 0 /* UNUSED */ -static int -gsl_poly_solve_cubic (double a, double b, double c, - double *x0, double *x1, double *x2) -{ - double q = (a * a - 3 * b); - double r = (2 * a * a * a - 9 * a * b + 27 * c); - - double Q = q / 9; - double R = r / 54; - - double Q3 = Q * Q * Q; - double R2 = R * R; - - double CR2 = 729 * r * r; - double CQ3 = 2916 * q * q * q; - - if (R == 0 && Q == 0) - { - *x0 = - a / 3; - *x1 = - a / 3; - *x2 = - a / 3; - return 3; - } - else if (CR2 == CQ3) - { - /* this test is actually R2 == Q3, written in a form suitable - for exact computation with integers */ - - /* Due to finite precision some double roots may be missed, and - considered to be a pair of complex roots z = x +/- epsilon i - close to the real axis. */ - - double sqrtQ = sqrt (Q); - - if (R > 0) - { - *x0 = -2 * sqrtQ - a / 3; - *x1 = sqrtQ - a / 3; - *x2 = sqrtQ - a / 3; - } - else - { - *x0 = - sqrtQ - a / 3; - *x1 = - sqrtQ - a / 3; - *x2 = 2 * sqrtQ - a / 3; - } - return 3; - } - else if (CR2 < CQ3) /* equivalent to R2 < Q3 */ - { - double sqrtQ = sqrt (Q); - double sqrtQ3 = sqrtQ * sqrtQ * sqrtQ; - double theta = acos (R / sqrtQ3); - double norm = -2 * sqrtQ; - *x0 = norm * cos (theta / 3) - a / 3; - *x1 = norm * cos ((theta + 2.0 * M_PI) / 3) - a / 3; - *x2 = norm * cos ((theta - 2.0 * M_PI) / 3) - a / 3; - - /* Sort *x0, *x1, *x2 into increasing order */ - - if (*x0 > *x1) - mySWAP(*x0, *x1); - - if (*x1 > *x2) - { - mySWAP(*x1, *x2); - - if (*x0 > *x1) - mySWAP(*x0, *x1); - } - - return 3; - } - else - { - double sgnR = (R >= 0 ? 1 : -1); - double A = -sgnR * pow (fabs (R) + sqrt (R2 - Q3), 1.0/3.0); - double B = Q / A; - *x0 = A + B - a / 3; - return 1; - } -} - - - -/** -* gsl_poly_solve_quadratic -* -* copied from GSL -*/ -static int -gsl_poly_solve_quadratic (double a, double b, double c, - double *x0, double *x1) -{ - double disc = b * b - 4 * a * c; - - if (a == 0) /* Handle linear case */ - { - if (b == 0) - { - return 0; - } - else - { - *x0 = -c / b; - return 1; - }; - } - - if (disc > 0) - { - if (b == 0) - { - double r = fabs (0.5 * sqrt (disc) / a); - *x0 = -r; - *x1 = r; - } - else - { - double sgnb = (b > 0 ? 1 : -1); - double temp = -0.5 * (b + sgnb * sqrt (disc)); - double r1 = temp / a; - double r2 = c / temp; - - if (r1 < r2) - { - *x0 = r1; - *x1 = r2; - } - else - { - *x0 = r2; - *x1 = r1; - } - } - return 2; - } - else if (disc == 0) - { - *x0 = -0.5 * b / a; - *x1 = -0.5 * b / a; - return 2; - } - else - { - return 0; - } -} -#endif /* UNUSED */ - - - -/* -* See Bridson et al. "Robust Treatment of Collision, Contact and Friction for Cloth Animation" -* page 4, left column -*/ -#if 0 -static int cloth_get_collision_time ( double a[3], double b[3], double c[3], double d[3], double e[3], double f[3], double solution[3] ) -{ - int num_sols = 0; - - // x^0 - checked - double g = a[0] * c[1] * e[2] - a[0] * c[2] * e[1] + - a[1] * c[2] * e[0] - a[1] * c[0] * e[2] + - a[2] * c[0] * e[1] - a[2] * c[1] * e[0]; - - // x^1 - double h = -b[2] * c[1] * e[0] + b[1] * c[2] * e[0] - a[2] * d[1] * e[0] + - a[1] * d[2] * e[0] + b[2] * c[0] * e[1] - b[0] * c[2] * e[1] + - a[2] * d[0] * e[1] - a[0] * d[2] * e[1] - b[1] * c[0] * e[2] + - b[0] * c[1] * e[2] - a[1] * d[0] * e[2] + a[0] * d[1] * e[2] - - a[2] * c[1] * f[0] + a[1] * c[2] * f[0] + a[2] * c[0] * f[1] - - a[0] * c[2] * f[1] - a[1] * c[0] * f[2] + a[0] * c[1] * f[2]; - - // x^2 - double i = -b[2] * d[1] * e[0] + b[1] * d[2] * e[0] + - b[2] * d[0] * e[1] - b[0] * d[2] * e[1] - - b[1] * d[0] * e[2] + b[0] * d[1] * e[2] - - b[2] * c[1] * f[0] + b[1] * c[2] * f[0] - - a[2] * d[1] * f[0] + a[1] * d[2] * f[0] + - b[2] * c[0] * f[1] - b[0] * c[2] * f[1] + - a[2] * d[0] * f[1] - a[0] * d[2] * f[1] - - b[1] * c[0] * f[2] + b[0] * c[1] * f[2] - - a[1] * d[0] * f[2] + a[0] * d[1] * f[2]; - - // x^3 - checked - double j = -b[2] * d[1] * f[0] + b[1] * d[2] * f[0] + - b[2] * d[0] * f[1] - b[0] * d[2] * f[1] - - b[1] * d[0] * f[2] + b[0] * d[1] * f[2]; - - /* - printf("r1: %lf\n", a[0] * c[1] * e[2] - a[0] * c[2] * e[1]); - printf("r2: %lf\n", a[1] * c[2] * e[0] - a[1] * c[0] * e[2]); - printf("r3: %lf\n", a[2] * c[0] * e[1] - a[2] * c[1] * e[0]); - - printf("x1 x: %f, y: %f, z: %f\n", a[0], a[1], a[2]); - printf("x2 x: %f, y: %f, z: %f\n", c[0], c[1], c[2]); - printf("x3 x: %f, y: %f, z: %f\n", e[0], e[1], e[2]); - - printf("v1 x: %f, y: %f, z: %f\n", b[0], b[1], b[2]); - printf("v2 x: %f, y: %f, z: %f\n", d[0], d[1], d[2]); - printf("v3 x: %f, y: %f, z: %f\n", f[0], f[1], f[2]); - - printf("t^3: %lf, t^2: %lf, t^1: %lf, t^0: %lf\n", j, i, h, g); - -*/ - // Solve cubic equation to determine times t1, t2, t3, when the collision will occur. - if ( ABS ( j ) > DBL_EPSILON ) - { - i /= j; - h /= j; - g /= j; - num_sols = gsl_poly_solve_cubic ( i, h, g, &solution[0], &solution[1], &solution[2] ); - } - else - { - num_sols = gsl_poly_solve_quadratic ( i, h, g, &solution[0], &solution[1] ); - solution[2] = -1.0; - } - - // printf("num_sols: %d, sol1: %lf, sol2: %lf, sol3: %lf\n", num_sols, solution[0], solution[1], solution[2]); - - // Discard negative solutions - if ( ( num_sols >= 1 ) && ( solution[0] < DBL_EPSILON ) ) - { - --num_sols; - solution[0] = solution[num_sols]; - } - if ( ( num_sols >= 2 ) && ( solution[1] < DBL_EPSILON ) ) - { - --num_sols; - solution[1] = solution[num_sols]; - } - if ( ( num_sols == 3 ) && ( solution[2] < DBL_EPSILON ) ) - { - --num_sols; - } - - // Sort - if ( num_sols == 2 ) - { - if ( solution[0] > solution[1] ) - { - double tmp = solution[0]; - solution[0] = solution[1]; - solution[1] = tmp; - } - } - else if ( num_sols == 3 ) - { - - // Bubblesort - if ( solution[0] > solution[1] ) - { - double tmp = solution[0]; solution[0] = solution[1]; solution[1] = tmp; - } - if ( solution[1] > solution[2] ) - { - double tmp = solution[1]; solution[1] = solution[2]; solution[2] = tmp; - } - if ( solution[0] > solution[1] ) - { - double tmp = solution[0]; solution[0] = solution[1]; solution[1] = tmp; - } - } - - return num_sols; -} -#endif // w3 is not perfect @@ -485,7 +208,6 @@ DO_INLINE void collision_interpolateOnTriangle ( float to[3], float v1[3], float VECADDMUL(to, v3, w3); } -#ifndef WITH_ELTOPO static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) { int result = 0; @@ -498,6 +220,12 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM cloth1 = clmd->clothObject; for ( ; collpair != collision_end; collpair++ ) { + float i1[3], i2[3], i3[3]; + + zero_v3(i1); + zero_v3(i2); + zero_v3(i3); + // only handle static collisions here if ( collpair->flag & COLLISION_IN_FUTURE ) continue; @@ -553,9 +281,9 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM normalize_v3(vrel_t_pre); impulse = magtangent / ( 1.0f + w1*w1 + w2*w2 + w3*w3 ); // 2.0 * - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, vrel_t_pre, w1 * impulse ); - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, vrel_t_pre, w2 * impulse ); - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, vrel_t_pre, w3 * impulse ); + VECADDMUL ( i1, vrel_t_pre, w1 * impulse ); + VECADDMUL ( i2, vrel_t_pre, w2 * impulse ); + VECADDMUL ( i3, vrel_t_pre, w3 * impulse ); } // Apply velocity stopping impulse @@ -563,13 +291,13 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM // no 2.0 * magrelVel normally, but looks nicer DG impulse = magrelVel / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, collpair->normal, w1 * impulse ); + VECADDMUL ( i1, collpair->normal, w1 * impulse ); cloth1->verts[collpair->ap1].impulse_count++; - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, collpair->normal, w2 * impulse ); + VECADDMUL ( i2, collpair->normal, w2 * impulse ); cloth1->verts[collpair->ap2].impulse_count++; - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, collpair->normal, w3 * impulse ); + VECADDMUL ( i3, collpair->normal, w3 * impulse ); cloth1->verts[collpair->ap3].impulse_count++; // Apply repulse impulse if distance too short @@ -586,785 +314,64 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM repulse = MAX2 ( impulse, repulse ); impulse = repulse / ( 1.0f + w1*w1 + w2*w2 + w3*w3 ); // original 2.0 / 0.25 - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, collpair->normal, impulse ); - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, collpair->normal, impulse ); - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, collpair->normal, impulse ); + VECADDMUL ( i1, collpair->normal, impulse ); + VECADDMUL ( i2, collpair->normal, impulse ); + VECADDMUL ( i3, collpair->normal, impulse ); } result = 1; } - } - return result; -} -#endif /* !WITH_ELTOPO */ - -#ifdef WITH_ELTOPO -typedef struct edgepairkey { - int a1, a2, b1, b2; -} edgepairkey; - -unsigned int edgepair_hash(void *vkey) -{ - edgepairkey *key = vkey; - int keys[4] = {key->a1, key->a2, key->b1, key->b2}; - int i, j; - - for (i=0; i<4; i++) { - for (j=0; j<3; j++) { - if (keys[j] >= keys[j+1]) { - SWAP(int, keys[j], keys[j+1]); - } - } - } - - return keys[0]*101 + keys[1]*72 + keys[2]*53 + keys[3]*34; -} - -int edgepair_cmp(const void *va, const void *vb) -{ - edgepairkey *a = va, *b = vb; - int keysa[4] = {a->a1, a->a2, a->b1, a->b2}; - int keysb[4] = {b->a1, b->a2, b->b1, b->b2}; - int i; - - for (i=0; i<4; i++) { - int j, ok=0; - for (j=0; j<4; j++) { - if (keysa[i] == keysa[j]) { - ok = 1; - break; - } - } - if (!ok) - return -1; - } - - return 0; -} - -static void get_edgepairkey(edgepairkey *key, int a1, int a2, int b1, int b2) -{ - key->a1 = a1; - key->a2 = a2; - key->b1 = b1; - key->b2 = b2; -} - -/*an immense amount of duplication goes on here. . .a major performance hit, I'm sure*/ -static CollPair* cloth_edge_collision ( ModifierData *md1, ModifierData *md2, - BVHTreeOverlap *overlap, CollPair *collpair, - GHash *visithash, MemArena *arena) -{ - ClothModifierData *clmd = (ClothModifierData *)md1; - CollisionModifierData *collmd = (CollisionModifierData *) md2; - MFace *face1=NULL, *face2 = NULL; - ClothVertex *verts1 = clmd->clothObject->verts; - double distance = 0; - edgepairkey *key, tstkey; - float epsilon1 = clmd->coll_parms->epsilon; - float epsilon2 = BLI_bvhtree_getepsilon ( collmd->bvhtree ); - float no[3], uv[3], t, relnor; - int i, i1, i2, i3, i4, i5, i6; - Cloth *cloth = clmd->clothObject; - float n1[3], n2[3], off[3], v1[2][3], v2[2][3], v3[2][3], v4[2][3], v5[2][3], v6[2][3]; - void **verts[] = {v1, v2, v3, v4, v5, v6}; - int j, ret, bp1, bp2, bp3, ap1, ap2, ap3, table[6]; - - face1 = & ( clmd->clothObject->mfaces[overlap->indexA] ); - face2 = & ( collmd->mfaces[overlap->indexB] ); - - // check all 4 possible collisions - for ( i = 0; i < 4; i++ ) { - if ( i == 0 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v2; - ap3 = face1->v3; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v2; - bp3 = face2->v3; - } - else if ( i == 1 ) { - if ( face1->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v3; - ap3 = face1->v4; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v2; - bp3 = face2->v3; - } - else { - continue; - } - } - if ( i == 2 ) { - if ( face2->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v2; - ap3 = face1->v3; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v3; - bp3 = face2->v4; - } - else { - continue; - } - } - else if ( i == 3 ) { - if ( face1->v4 && face2->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v3; - ap3 = face1->v4; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v3; - bp3 = face2->v4; - } - else { - continue; - } - } - - copy_v3_v3(v1[0], cloth->verts[ap1].txold); - copy_v3_v3(v1[1], cloth->verts[ap1].tx); - copy_v3_v3(v2[0], cloth->verts[ap2].txold); - copy_v3_v3(v2[1], cloth->verts[ap2].tx); - copy_v3_v3(v3[0], cloth->verts[ap3].txold); - copy_v3_v3(v3[1], cloth->verts[ap3].tx); - - copy_v3_v3(v4[0], collmd->current_x[bp1].co); - copy_v3_v3(v4[1], collmd->current_xnew[bp1].co); - copy_v3_v3(v5[0], collmd->current_x[bp2].co); - copy_v3_v3(v5[1], collmd->current_xnew[bp2].co); - copy_v3_v3(v6[0], collmd->current_x[bp3].co); - copy_v3_v3(v6[1], collmd->current_xnew[bp3].co); - - normal_tri_v3(n2, v4[1], v5[1], v6[1]); - - /*offset new positions a bit, to account for margins*/ - i1 = ap1; i2 = ap2; i3 = ap3; - i4 = bp1; i5 = bp2; i6 = bp3; - - for (j=0; j<3; j++) { - int collp1, collp2, k, j2 = (j+1)%3; - - table[0] = ap1; table[1] = ap2; table[2] = ap3; - table[3] = bp1; table[4] = bp2; table[5] = bp3; - for (k=0; k<3; k++) { - float p1[3], p2[3]; - int k2 = (k+1)%3; - - get_edgepairkey(&tstkey, table[j], table[j2], table[k+3], table[k2+3]); - //if (BLI_ghash_haskey(visithash, &tstkey)) - // continue; - - key = BLI_memarena_alloc(arena, sizeof(edgepairkey)); - *key = tstkey; - BLI_ghash_insert(visithash, key, NULL); - - sub_v3_v3v3(p1, verts[j], verts[j2]); - sub_v3_v3v3(p2, verts[k+3], verts[k2+3]); - - cross_v3_v3v3(off, p1, p2); - normalize_v3(off); - - if (dot_v3v3(n2, off) < 0.0) - negate_v3(off); - - mul_v3_fl(off, epsilon1 + epsilon2 + ALMOST_ZERO); - copy_v3_v3(p1, verts[k+3]); - copy_v3_v3(p2, verts[k2+3]); - add_v3_v3(p1, off); - add_v3_v3(p2, off); - - ret = eltopo_line_line_moving_isect_v3v3_f(verts[j], table[j], verts[j2], table[j2], - p1, table[k+3], p2, table[k2+3], - no, uv, &t, &relnor); - /*cloth vert versus coll face*/ - if (ret) { - collpair->ap1 = table[j]; collpair->ap2 = table[j2]; - collpair->bp1 = table[k+3]; collpair->bp2 = table[k2+3]; - - /*I'm not sure if this is correct, but hopefully it's - better then simply ignoring back edges*/ - if (dot_v3v3(n2, no) < 0.0) { - negate_v3(no); - } - - copy_v3_v3(collpair->normal, no); - mul_v3_v3fl(collpair->vector, collpair->normal, relnor); - collpair->distance = relnor; - collpair->time = t; - - copy_v2_v2(collpair->bary, uv); - - collpair->flag = COLLISION_IS_EDGES; - collpair++; - } - } - } - } - - return collpair; -} - -static int cloth_edge_collision_response_moving ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) -{ - int result = 0; - Cloth *cloth1; - float w1, w2; - float v1[3], v2[3], relativeVelocity[3]; - float magrelVel, pimpulse[3]; - - cloth1 = clmd->clothObject; - - for ( ; collpair != collision_end; collpair++ ) { - if (!(collpair->flag & COLLISION_IS_EDGES)) - continue; - - // was: txold - w1 = collpair->bary[0]; w2 = collpair->bary[1]; - - // Calculate relative "velocity". - VECADDFAC(v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, w1); - VECADDFAC(v2, collmd->current_v[collpair->bp1].co, collmd->current_v[collpair->bp2].co, w2); - - sub_v3_v3v3(relativeVelocity, v2, v1); - - // Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). - magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); - - // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) { - // Calculate Impulse magnitude to stop all motion in normal direction. - float magtangent = 0, repulse = 0, d = 0; - double impulse = 0.0; - float vrel_t_pre[3]; - float temp[3], spf; - - zero_v3(pimpulse); - - // calculate tangential velocity - copy_v3_v3 ( temp, collpair->normal ); - mul_v3_fl(temp, magrelVel); - sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); - - // Decrease in magnitude of relative tangential velocity due to coulomb friction - // in original formula "magrelVel" should be the "change of relative velocity in normal direction" - magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel, sqrt ( dot_v3v3 ( vrel_t_pre, vrel_t_pre ) ) ); - - // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) { - normalize_v3(vrel_t_pre); - - impulse = magtangent; - VECADDMUL ( pimpulse, vrel_t_pre, impulse); - } - - // Apply velocity stopping impulse - // I_c = m * v_N / 2.0 - // no 2.0 * magrelVel normally, but looks nicer DG - impulse = magrelVel; - - mul_v3_fl(collpair->normal, 0.5); - VECADDMUL ( pimpulse, collpair->normal, impulse); - + else + { // Apply repulse impulse if distance too short // I_r = -min(dt*kd, m(0, 1d/dt - v_n)) - spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; - - d = collpair->distance; - if ( ( magrelVel < 0.1*d*spf && ( d > ALMOST_ZERO ) ) ) { - repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); + float spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; + float d = clmd->coll_parms->epsilon*8.0f/9.0f + epsilon2*8.0f/9.0f - collpair->distance; + if ( d > ALMOST_ZERO) { // stay on the safe side and clamp repulse - if ( impulse > ALMOST_ZERO ) - repulse = MIN2 ( repulse, 5.0*impulse ); - repulse = MAX2 ( impulse, repulse ); + float repulse = d*1.0f/spf; - impulse = repulse / ( 5.0 ); // original 2.0 / 0.25 - VECADDMUL ( pimpulse, collpair->normal, impulse); - } - - w2 = 1.0f-w1; - if (w1 < 0.5) - w1 *= 2.0; - else - w2 *= 2.0; - - VECADDFAC(cloth1->verts[collpair->ap1].impulse, cloth1->verts[collpair->ap1].impulse, pimpulse, w1*2.0); - VECADDFAC(cloth1->verts[collpair->ap2].impulse, cloth1->verts[collpair->ap2].impulse, pimpulse, w2*2.0); - - cloth1->verts[collpair->ap1].impulse_count++; - cloth1->verts[collpair->ap2].impulse_count++; - - result = 1; - } - } - - return result; -} + float impulse = repulse / ( 1.0f + w1*w1 + w2*w2 + w3*w3 ); // original 2.0 / 0.25 + VECADDMUL ( i1, collpair->normal, impulse ); + VECADDMUL ( i2, collpair->normal, impulse ); + VECADDMUL ( i3, collpair->normal, impulse ); -static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) -{ - int result = 0; - Cloth *cloth1; - float w1, w2, w3, u1, u2, u3; - float v1[3], v2[3], relativeVelocity[3]; - float magrelVel; - float epsilon2 = BLI_bvhtree_getepsilon ( collmd->bvhtree ); - - cloth1 = clmd->clothObject; - - for ( ; collpair != collision_end; collpair++ ) { - if (collpair->flag & COLLISION_IS_EDGES) - continue; - - if ( collpair->flag & COLLISION_USE_COLLFACE ) { - // was: txold - w1 = collpair->bary[0]; w2 = collpair->bary[1]; w3 = collpair->bary[2]; - - // Calculate relative "velocity". - collision_interpolateOnTriangle ( v1, collmd->current_v[collpair->bp1].co, collmd->current_v[collpair->bp2].co, collmd->current_v[collpair->bp3].co, w1, w2, w3); - - sub_v3_v3v3(relativeVelocity, v1, cloth1->verts[collpair->collp].tv); - - // Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). - magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); - - // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) { - // Calculate Impulse magnitude to stop all motion in normal direction. - float magtangent = 0, repulse = 0, d = 0; - double impulse = 0.0; - float vrel_t_pre[3]; - float temp[3], spf; - - // calculate tangential velocity - copy_v3_v3 ( temp, collpair->normal ); - mul_v3_fl(temp, magrelVel); - sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); - - // Decrease in magnitude of relative tangential velocity due to coulomb friction - // in original formula "magrelVel" should be the "change of relative velocity in normal direction" - magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel, sqrt ( dot_v3v3 ( vrel_t_pre, vrel_t_pre ) ) ); - - // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) { - normalize_v3(vrel_t_pre); - - impulse = magtangent; // 2.0 * - VECADDMUL ( cloth1->verts[collpair->collp].impulse, vrel_t_pre, impulse); - } - - // Apply velocity stopping impulse - // I_c = m * v_N / 2.0 - // no 2.0 * magrelVel normally, but looks nicer DG - impulse = magrelVel/2.0; - - VECADDMUL ( cloth1->verts[collpair->collp].impulse, collpair->normal, impulse); - cloth1->verts[collpair->collp].impulse_count++; - - // Apply repulse impulse if distance too short - // I_r = -min(dt*kd, m(0, 1d/dt - v_n)) - spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; - - d = -collpair->distance; - if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) ) { - repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); - - // stay on the safe side and clamp repulse - if ( impulse > ALMOST_ZERO ) - repulse = MIN2 ( repulse, 5.0*impulse ); - repulse = MAX2 ( impulse, repulse ); - - impulse = repulse / ( 5.0 ); // original 2.0 / 0.25 - VECADDMUL ( cloth1->verts[collpair->collp].impulse, collpair->normal, impulse); - } - - result = 1; - } - } - else { - w1 = collpair->bary[0]; w2 = collpair->bary[1]; w3 = collpair->bary[2]; - - // Calculate relative "velocity". - collision_interpolateOnTriangle ( v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3 ); - - sub_v3_v3v3(relativeVelocity, collmd->current_v[collpair->collp].co, v1); - - // Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). - magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); - - // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) { - // Calculate Impulse magnitude to stop all motion in normal direction. - float magtangent = 0, repulse = 0, d = 0; - double impulse = 0.0; - float vrel_t_pre[3], pimpulse[3] = {0.0f, 0.0f, 0.0f}; - float temp[3], spf; - - // calculate tangential velocity - copy_v3_v3 ( temp, collpair->normal ); - mul_v3_fl(temp, magrelVel); - sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); - - // Decrease in magnitude of relative tangential velocity due to coulomb friction - // in original formula "magrelVel" should be the "change of relative velocity in normal direction" - magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel, sqrt ( dot_v3v3 ( vrel_t_pre, vrel_t_pre ) ) ); - - // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) { - normalize_v3(vrel_t_pre); - - impulse = magtangent; // 2.0 * - VECADDMUL ( pimpulse, vrel_t_pre, impulse); - } - - // Apply velocity stopping impulse - // I_c = m * v_N / 2.0 - // no 2.0 * magrelVel normally, but looks nicer DG - impulse = magrelVel/2.0; - - VECADDMUL ( pimpulse, collpair->normal, impulse); - - // Apply repulse impulse if distance too short - // I_r = -min(dt*kd, m(0, 1d/dt - v_n)) - spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; - - d = -collpair->distance; - if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) ) { - repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); - - // stay on the safe side and clamp repulse - if ( impulse > ALMOST_ZERO ) - repulse = MIN2 ( repulse, 5.0*impulse ); - repulse = MAX2 ( impulse, repulse ); - - impulse = repulse / ( 2.0 ); // original 2.0 / 0.25 - VECADDMUL ( pimpulse, collpair->normal, impulse); - } - - if (w1 < 0.5) w1 *= 2.0; - if (w2 < 0.5) w2 *= 2.0; - if (w3 < 0.5) w3 *= 2.0; - - VECADDMUL(cloth1->verts[collpair->ap1].impulse, pimpulse, w1*2.0); - VECADDMUL(cloth1->verts[collpair->ap2].impulse, pimpulse, w2*2.0); - VECADDMUL(cloth1->verts[collpair->ap3].impulse, pimpulse, w3*2.0); cloth1->verts[collpair->ap1].impulse_count++; cloth1->verts[collpair->ap2].impulse_count++; cloth1->verts[collpair->ap3].impulse_count++; - - result = 1; - } - } - } - - return result; -} - - -typedef struct tripairkey { - int p, a1, a2, a3; -} tripairkey; - -unsigned int tripair_hash(void *vkey) -{ - tripairkey *key = vkey; - int keys[4] = {key->p, key->a1, key->a2, key->a3}; - int i, j; - - for (i=0; i<4; i++) { - for (j=0; j<3; j++) { - if (keys[j] >= keys[j+1]) { - SWAP(int, keys[j], keys[j+1]); - } - } - } - - return keys[0]*101 + keys[1]*72 + keys[2]*53 + keys[3]*34; -} - -int tripair_cmp(const void *va, const void *vb) -{ - tripairkey *a = va, *b = vb; - int keysa[4] = {a->p, a->a1, a->a2, a->a3}; - int keysb[4] = {b->p, b->a1, b->a2, b->a3}; - int i; - - for (i=0; i<4; i++) { - int j, ok=0; - for (j=0; j<4; j++) { - if (keysa[i] == keysa[j]) { - ok = 1; - break; - } - } - if (!ok) - return -1; - } - - return 0; -} - -static void get_tripairkey(tripairkey *key, int p, int a1, int a2, int a3) -{ - key->a1 = a1; - key->a2 = a2; - key->a3 = a3; - key->p = p; -} - -static int checkvisit(MemArena *arena, GHash *gh, int p, int a1, int a2, int a3) -{ - tripairkey key, *key2; - - get_tripairkey(&key, p, a1, a2, a3); - if (BLI_ghash_haskey(gh, &key)) - return 1; - - key2 = BLI_memarena_alloc(arena, sizeof(*key2)); - *key2 = key; - BLI_ghash_insert(gh, key2, NULL); - - return 0; -} - -int cloth_point_tri_moving_v3v3_f(float v1[2][3], int i1, float v2[2][3], int i2, - float v3[2][3], int i3, float v4[2][3], int i4, - float normal[3], float bary[3], float *t, - float *relnor, GHash *gh, MemArena *arena) -{ - if (checkvisit(arena, gh, i1, i2, i3, i4)) - return 0; - - return eltopo_point_tri_moving_v3v3_f(v1, i1, v2, i2, v3, i3, v4, i4, normal, bary, t, relnor); -} -static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap *overlap, - CollPair *collpair, double dt, GHash *gh, MemArena *arena) -{ - ClothModifierData *clmd = (ClothModifierData *)md1; - CollisionModifierData *collmd = (CollisionModifierData *) md2; - MFace *face1=NULL, *face2 = NULL; - ClothVertex *verts1 = clmd->clothObject->verts; - double distance = 0; - float epsilon1 = clmd->coll_parms->epsilon; - float epsilon2 = BLI_bvhtree_getepsilon ( collmd->bvhtree ); - float no[3], uv[3], t, relnor; - int i, i1, i2, i3, i4, i5, i6; - Cloth *cloth = clmd->clothObject; - float n1[3], sdis, p[3], l, n2[3], off[3], v1[2][3], v2[2][3], v3[2][3], v4[2][3], v5[2][3], v6[2][3]; - int j, ret, bp1, bp2, bp3, ap1, ap2, ap3; - - face1 = & ( clmd->clothObject->mfaces[overlap->indexA] ); - face2 = & ( collmd->mfaces[overlap->indexB] ); - - // check all 4 possible collisions - for ( i = 0; i < 4; i++ ) { - if ( i == 0 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v2; - ap3 = face1->v3; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v2; - bp3 = face2->v3; - } - else if ( i == 1 ) { - if ( face1->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v3; - ap3 = face1->v4; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v2; - bp3 = face2->v3; - } - else { - continue; - } - } - if ( i == 2 ) { - if ( face2->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v2; - ap3 = face1->v3; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v3; - bp3 = face2->v4; - } - else { - continue; + result = 1; } } - else if ( i == 3 ) { - if ( face1->v4 && face2->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v3; - ap3 = face1->v4; - // fill faceB - bp1 = face2->v1; - bp2 = face2->v3; - bp3 = face2->v4; - } - else { - continue; - } - } - - copy_v3_v3(v1[0], cloth->verts[ap1].txold); - copy_v3_v3(v1[1], cloth->verts[ap1].tx); - copy_v3_v3(v2[0], cloth->verts[ap2].txold); - copy_v3_v3(v2[1], cloth->verts[ap2].tx); - copy_v3_v3(v3[0], cloth->verts[ap3].txold); - copy_v3_v3(v3[1], cloth->verts[ap3].tx); - - copy_v3_v3(v4[0], collmd->current_x[bp1].co); - copy_v3_v3(v4[1], collmd->current_xnew[bp1].co); - copy_v3_v3(v5[0], collmd->current_x[bp2].co); - copy_v3_v3(v5[1], collmd->current_xnew[bp2].co); - copy_v3_v3(v6[0], collmd->current_x[bp3].co); - copy_v3_v3(v6[1], collmd->current_xnew[bp3].co); - - normal_tri_v3(n2, v4[1], v5[1], v6[1]); - - sdis = clmd->coll_parms->distance_repel + epsilon2 + FLT_EPSILON; - - /*apply a repulsion force, to help the solver along*/ - copy_v3_v3(off, n2); - negate_v3(off); - if (isect_ray_plane_v3(v1[1], off, v4[1], v5[1], v6[1], &l, 0)) { - if (l >= 0.0 && l < sdis) { - mul_v3_fl(off, (l-sdis)*cloth->verts[ap1].mass*dt*clmd->coll_parms->repel_force*0.1); - - add_v3_v3(cloth->verts[ap1].tv, off); - add_v3_v3(cloth->verts[ap2].tv, off); - add_v3_v3(cloth->verts[ap3].tv, off); - } - } + if(result) + { + int i = 0; - /*offset new positions a bit, to account for margins*/ - copy_v3_v3(off, n2); - mul_v3_fl(off, epsilon1 + epsilon2 + ALMOST_ZERO); - add_v3_v3(v4[1], off); add_v3_v3(v5[1], off); add_v3_v3(v6[1], off); - - i1 = ap1; i2 = ap2; i3 = ap3; - i4 = bp1+cloth->numverts; i5 = bp2+cloth->numverts; i6 = bp3+cloth->numverts; - - for (j=0; j<6; j++) { - int collp; + for(i = 0; i < 3; i++) + { + if(cloth1->verts[collpair->ap1].impulse_count > 0 && ABS(cloth1->verts[collpair->ap1].impulse[i]) < ABS(i1[i])) + cloth1->verts[collpair->ap1].impulse[i] = i1[i]; - switch (j) { - case 0: - ret = cloth_point_tri_moving_v3v3_f(v1, i1, v4, i4, v5, i5, v6, i6, no, uv, &t, &relnor, gh, arena); - collp = ap1; - break; - case 1: - collp = ap2; - ret = cloth_point_tri_moving_v3v3_f(v2, i2, v4, i4, v5, i5, v6, i6, no, uv, &t, &relnor, gh, arena); - break; - case 2: - collp = ap3; - ret = cloth_point_tri_moving_v3v3_f(v3, i3, v4, i4, v5, i5, v6, i6, no, uv, &t, &relnor, gh, arena); - break; - case 3: - collp = bp1; - ret = cloth_point_tri_moving_v3v3_f(v4, i4, v1, i1, v2, i2, v3, i3, no, uv, &t, &relnor, gh, arena); - break; - case 4: - collp = bp2; - ret = cloth_point_tri_moving_v3v3_f(v5, i5, v1, i1, v2, i2, v3, i3, no, uv, &t, &relnor, gh, arena); - break; - case 5: - collp = bp3; - ret = cloth_point_tri_moving_v3v3_f(v6, i6, v1, i1, v2, i2, v3, i3, no, uv, &t, &relnor, gh, arena); - break; - } - - /*cloth vert versus coll face*/ - if (ret && j < 3) { - collpair->bp1 = bp1; collpair->bp2 = bp2; collpair->bp3 = bp3; - collpair->collp = collp; - - copy_v3_v3(collpair->normal, no); - mul_v3_v3fl(collpair->vector, collpair->normal, relnor); - collpair->distance = relnor; - collpair->time = t; - - copy_v3_v3(collpair->bary, uv); - - collpair->flag = COLLISION_USE_COLLFACE; - collpair++; - } - else if (ret && j >= 3) { /*coll vert versus cloth face*/ - collpair->ap1 = ap1; collpair->ap2 = ap2; collpair->ap3 = ap3; - collpair->collp = collp; - - copy_v3_v3(collpair->normal, no); - mul_v3_v3fl(collpair->vector, collpair->normal, relnor); - collpair->distance = relnor; - collpair->time = t; - - copy_v3_v3(collpair->bary, uv); + if(cloth1->verts[collpair->ap2].impulse_count > 0 && ABS(cloth1->verts[collpair->ap2].impulse[i]) < ABS(i2[i])) + cloth1->verts[collpair->ap2].impulse[i] = i2[i]; - collpair->flag = 0; - collpair++; + if(cloth1->verts[collpair->ap3].impulse_count > 0 && ABS(cloth1->verts[collpair->ap3].impulse[i]) < ABS(i3[i])) + cloth1->verts[collpair->ap3].impulse[i] = i3[i]; } } } - - return collpair; -} - -static void machine_epsilon_offset(Cloth *cloth) -{ - ClothVertex *cv; - int i, j; - - cv = cloth->verts; - for (i=0; i<cloth->numverts; i++, cv++) { - /*aggrevatingly enough, it's necessary to offset the coordinates - by a multiple of the 32-bit floating point epsilon when switching - into doubles*/ - #define RNDSIGN (float)(-1*(BLI_rand()%2==0)|1) - for (j=0; j<3; j++) { - cv->tx[j] += FLT_EPSILON*30.0f*RNDSIGN; - cv->txold[j] += FLT_EPSILON*30.0f*RNDSIGN; - cv->tv[j] += FLT_EPSILON*30.0f*RNDSIGN; - } - } + return result; } -#else /* !WITH_ELTOPO */ - //Determines collisions on overlap, collisions are written to collpair[i] and collision+number_collision_found is returned -static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, - BVHTreeOverlap *overlap, CollPair *collpair, float dt ) +static CollPair* cloth_collision(ModifierData *md1, ModifierData *md2, + BVHTreeOverlap *overlap, CollPair *collpair, float UNUSED(dt)) { ClothModifierData *clmd = (ClothModifierData *)md1; CollisionModifierData *collmd = (CollisionModifierData *) md2; - Cloth *cloth = clmd->clothObject; + /* Cloth *cloth = clmd->clothObject; */ /* UNUSED */ MFace *face1=NULL, *face2 = NULL; #ifdef USE_BULLET ClothVertex *verts1 = clmd->clothObject->verts; @@ -1372,7 +379,6 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, double distance = 0; float epsilon1 = clmd->coll_parms->epsilon; float epsilon2 = BLI_bvhtree_getepsilon ( collmd->bvhtree ); - float n2[3], sdis, l; int i; face1 = & ( clmd->clothObject->mfaces[overlap->indexA] ); @@ -1395,8 +401,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, if ( face1->v4 ) { // fill faceA collpair->ap1 = face1->v1; - collpair->ap2 = face1->v4; - collpair->ap3 = face1->v3; + collpair->ap2 = face1->v3; + collpair->ap3 = face1->v4; // fill faceB collpair->bp1 = face2->v1; @@ -1425,39 +431,18 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, if ( face1->v4 && face2->v4 ) { // fill faceA collpair->ap1 = face1->v1; - collpair->ap2 = face1->v4; - collpair->ap3 = face1->v3; + collpair->ap2 = face1->v3; + collpair->ap3 = face1->v4; // fill faceB collpair->bp1 = face2->v1; - collpair->bp2 = face2->v4; - collpair->bp3 = face2->v3; + collpair->bp2 = face2->v3; + collpair->bp3 = face2->v4; } else break; } - normal_tri_v3(n2, collmd->current_xnew[collpair->bp1].co, - collmd->current_xnew[collpair->bp2].co, - collmd->current_xnew[collpair->bp3].co); - - sdis = clmd->coll_parms->distance_repel + epsilon2 + FLT_EPSILON; - - /* apply a repulsion force, to help the solver along. - * this is kindof crude, it only tests one vert of the triangle */ - if (isect_ray_plane_v3(cloth->verts[collpair->ap1].tx, n2, collmd->current_xnew[collpair->bp1].co, - collmd->current_xnew[collpair->bp2].co, - collmd->current_xnew[collpair->bp3].co, &l, 0)) - { - if (l >= 0.0f && l < sdis) { - mul_v3_fl(n2, (l-sdis)*cloth->verts[collpair->ap1].mass*dt*clmd->coll_parms->repel_force*0.1f); - - add_v3_v3(cloth->verts[collpair->ap1].tv, n2); - add_v3_v3(cloth->verts[collpair->ap2].tv, n2); - add_v3_v3(cloth->verts[collpair->ap3].tv, n2); - } - } - #ifdef USE_BULLET // calc distance + normal distance = plNearestPoints ( @@ -1512,579 +497,6 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, } return collpair; } -#endif /* WITH_ELTOPO */ - - -#if 0 -static int cloth_collision_response_moving( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) -{ - int result = 0; - Cloth *cloth1; - float w1, w2, w3, u1, u2, u3; - float v1[3], v2[3], relativeVelocity[3]; - float magrelVel; - - cloth1 = clmd->clothObject; - - for ( ; collpair != collision_end; collpair++ ) - { - // compute barycentric coordinates for both collision points - collision_compute_barycentric ( collpair->pa, - cloth1->verts[collpair->ap1].txold, - cloth1->verts[collpair->ap2].txold, - cloth1->verts[collpair->ap3].txold, - &w1, &w2, &w3 ); - - // was: txold - collision_compute_barycentric ( collpair->pb, - collmd->current_x[collpair->bp1].co, - collmd->current_x[collpair->bp2].co, - collmd->current_x[collpair->bp3].co, - &u1, &u2, &u3 ); - - // Calculate relative "velocity". - collision_interpolateOnTriangle ( v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3 ); - - collision_interpolateOnTriangle ( v2, collmd->current_v[collpair->bp1].co, collmd->current_v[collpair->bp2].co, collmd->current_v[collpair->bp3].co, u1, u2, u3 ); - - sub_v3_v3v3(relativeVelocity, v2, v1); - - // Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). - magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); - - // printf("magrelVel: %f\n", magrelVel); - - // Calculate masses of points. - // TODO - - // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) - { - // Calculate Impulse magnitude to stop all motion in normal direction. - float magtangent = 0; - double impulse = 0.0; - float vrel_t_pre[3]; - float temp[3]; - - // calculate tangential velocity - copy_v3_v3 ( temp, collpair->normal ); - mul_v3_fl(temp, magrelVel); - sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); - - // Decrease in magnitude of relative tangential velocity due to coulomb friction - // in original formula "magrelVel" should be the "change of relative velocity in normal direction" - magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel, sqrt ( dot_v3v3 ( vrel_t_pre, vrel_t_pre ) ) ); - - // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) - { - normalize_v3(vrel_t_pre); - - impulse = 2.0 * magtangent / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, vrel_t_pre, w1 * impulse ); - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, vrel_t_pre, w2 * impulse ); - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, vrel_t_pre, w3 * impulse ); - } - - // Apply velocity stopping impulse - // I_c = m * v_N / 2.0 - // no 2.0 * magrelVel normally, but looks nicer DG - impulse = magrelVel / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); - - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, collpair->normal, w1 * impulse ); - cloth1->verts[collpair->ap1].impulse_count++; - - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, collpair->normal, w2 * impulse ); - cloth1->verts[collpair->ap2].impulse_count++; - - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, collpair->normal, w3 * impulse ); - cloth1->verts[collpair->ap3].impulse_count++; - - // Apply repulse impulse if distance too short - // I_r = -min(dt*kd, m(0, 1d/dt - v_n)) - /* - d = clmd->coll_parms->epsilon*8.0/9.0 + epsilon2*8.0/9.0 - collpair->distance; - if ( ( magrelVel < 0.1*d*clmd->sim_parms->stepsPerFrame ) && ( d > ALMOST_ZERO ) ) - { - repulse = MIN2 ( d*1.0/clmd->sim_parms->stepsPerFrame, 0.1*d*clmd->sim_parms->stepsPerFrame - magrelVel ); - - // stay on the safe side and clamp repulse - if ( impulse > ALMOST_ZERO ) - repulse = MIN2 ( repulse, 5.0*impulse ); - repulse = MAX2 ( impulse, repulse ); - - impulse = repulse / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); // original 2.0 / 0.25 - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, collpair->normal, impulse ); - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, collpair->normal, impulse ); - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, collpair->normal, impulse ); - } - */ - result = 1; - } - } - return result; -} -#endif - -#if 0 -static float projectPointOntoLine(float *p, float *a, float *b) -{ - float ba[3], pa[3]; - sub_v3_v3v3(ba, b, a); - sub_v3_v3v3(pa, p, a); - return dot_v3v3(pa, ba) / dot_v3v3(ba, ba); -} - -static void calculateEENormal(float *np1, float *np2, float *np3, float *np4, float *out_normal) -{ - float line1[3], line2[3]; - float length; - - sub_v3_v3v3(line1, np2, np1); - sub_v3_v3v3(line2, np3, np1); - - // printf("l1: %f, l1: %f, l2: %f, l2: %f\n", line1[0], line1[1], line2[0], line2[1]); - - cross_v3_v3v3(out_normal, line1, line2); - - - - length = normalize_v3(out_normal); - if (length <= FLT_EPSILON) - { // lines are collinear - sub_v3_v3v3(out_normal, np2, np1); - normalize_v3(out_normal); - } -} - -static void findClosestPointsEE(float *x1, float *x2, float *x3, float *x4, float *w1, float *w2) -{ - float temp[3], temp2[3]; - - double a, b, c, e, f; - - sub_v3_v3v3(temp, x2, x1); - a = dot_v3v3(temp, temp); - - sub_v3_v3v3(temp2, x4, x3); - b = -dot_v3v3(temp, temp2); - - c = dot_v3v3(temp2, temp2); - - sub_v3_v3v3(temp2, x3, x1); - e = dot_v3v3(temp, temp2); - - sub_v3_v3v3(temp, x4, x3); - f = -dot_v3v3(temp, temp2); - - *w1 = (e * c - b * f) / (a * c - b * b); - *w2 = (f - b * *w1) / c; - -} - -// calculates the distance of 2 edges -static float edgedge_distance(float np11[3], float np12[3], float np21[3], float np22[3], float *out_a1, float *out_a2, float *out_normal) -{ - float line1[3], line2[3], cross[3]; - float length; - float temp[3], temp2[3]; - float dist_a1, dist_a2; - - sub_v3_v3v3(line1, np12, np11); - sub_v3_v3v3(line2, np22, np21); - - cross_v3_v3v3(cross, line1, line2); - length = dot_v3v3(cross, cross); - - if (length < FLT_EPSILON) - { - *out_a2 = projectPointOntoLine(np11, np21, np22); - if ((*out_a2 >= -FLT_EPSILON) && (*out_a2 <= 1.0 + FLT_EPSILON)) - { - *out_a1 = 0; - calculateEENormal(np11, np12, np21, np22, out_normal); - sub_v3_v3v3(temp, np22, np21); - mul_v3_fl(temp, *out_a2); - VECADD(temp2, temp, np21); - VECADD(temp2, temp2, np11); - return dot_v3v3(temp2, temp2); - } - - CLAMP(*out_a2, 0.0, 1.0); - if (*out_a2 > .5) - { // == 1.0 - *out_a1 = projectPointOntoLine(np22, np11, np12); - if ((*out_a1 >= -FLT_EPSILON) && (*out_a1 <= 1.0 + FLT_EPSILON)) - { - calculateEENormal(np11, np12, np21, np22, out_normal); - - // return (np22 - (np11 + (np12 - np11) * out_a1)).lengthSquared(); - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(temp2, temp, np11); - sub_v3_v3v3(temp2, np22, temp2); - return dot_v3v3(temp2, temp2); - } - } - else - { // == 0.0 - *out_a1 = projectPointOntoLine(np21, np11, np12); - if ((*out_a1 >= -FLT_EPSILON) && (*out_a1 <= 1.0 + FLT_EPSILON)) - { - calculateEENormal(np11, np11, np21, np22, out_normal); - - // return (np21 - (np11 + (np12 - np11) * out_a1)).lengthSquared(); - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(temp2, temp, np11); - sub_v3_v3v3(temp2, np21, temp2); - return dot_v3v3(temp2, temp2); - } - } - - CLAMP(*out_a1, 0.0, 1.0); - calculateEENormal(np11, np12, np21, np22, out_normal); - if (*out_a1 > .5) - { - if (*out_a2 > .5) - { - sub_v3_v3v3(temp, np12, np22); - } - else - { - sub_v3_v3v3(temp, np12, np21); - } - } - else - { - if (*out_a2 > .5) - { - sub_v3_v3v3(temp, np11, np22); - } - else - { - sub_v3_v3v3(temp, np11, np21); - } - } - - return dot_v3v3(temp, temp); - } - else - { - - // If the lines aren't parallel (but coplanar) they have to intersect - - findClosestPointsEE(np11, np12, np21, np22, out_a1, out_a2); - - // If both points are on the finite edges, we're done. - if (*out_a1 >= 0.0 && *out_a1 <= 1.0 && *out_a2 >= 0.0 && *out_a2 <= 1.0) - { - float p1[3], p2[3]; - - // p1= np11 + (np12 - np11) * out_a1; - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(p1, np11, temp); - - // p2 = np21 + (np22 - np21) * out_a2; - sub_v3_v3v3(temp, np22, np21); - mul_v3_fl(temp, *out_a2); - VECADD(p2, np21, temp); - - calculateEENormal(np11, np12, np21, np22, out_normal); - sub_v3_v3v3(temp, p1, p2); - return dot_v3v3(temp, temp); - } - - - /* - * Clamp both points to the finite edges. - * The one that moves most during clamping is one part of the solution. - */ - dist_a1 = *out_a1; - CLAMP(dist_a1, 0.0, 1.0); - dist_a2 = *out_a2; - CLAMP(dist_a2, 0.0, 1.0); - - // Now project the "most clamped" point on the other line. - if (dist_a1 > dist_a2) - { - /* keep out_a1 */ - float p1[3]; - - // p1 = np11 + (np12 - np11) * out_a1; - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(p1, np11, temp); - - *out_a2 = projectPointOntoLine(p1, np21, np22); - CLAMP(*out_a2, 0.0, 1.0); - - calculateEENormal(np11, np12, np21, np22, out_normal); - - // return (p1 - (np21 + (np22 - np21) * out_a2)).lengthSquared(); - sub_v3_v3v3(temp, np22, np21); - mul_v3_fl(temp, *out_a2); - VECADD(temp, temp, np21); - sub_v3_v3v3(temp, p1, temp); - return dot_v3v3(temp, temp); - } - else - { - /* keep out_a2 */ - float p2[3]; - - // p2 = np21 + (np22 - np21) * out_a2; - sub_v3_v3v3(temp, np22, np21); - mul_v3_fl(temp, *out_a2); - VECADD(p2, np21, temp); - - *out_a1 = projectPointOntoLine(p2, np11, np12); - CLAMP(*out_a1, 0.0, 1.0); - - calculateEENormal(np11, np12, np21, np22, out_normal); - - // return ((np11 + (np12 - np11) * out_a1) - p2).lengthSquared(); - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(temp, temp, np11); - sub_v3_v3v3(temp, temp, p2); - return dot_v3v3(temp, temp); - } - } - - printf("Error in edgedge_distance: end of function\n"); - return 0; -} - -static int cloth_collision_moving_edges ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair ) -{ - EdgeCollPair edgecollpair; - Cloth *cloth1=NULL; - ClothVertex *verts1=NULL; - unsigned int i = 0, k = 0; - int numsolutions = 0; - double x1[3], v1[3], x2[3], v2[3], x3[3], v3[3]; - double solution[3], solution2[3]; - MVert *verts2 = collmd->current_x; // old x - MVert *velocity2 = collmd->current_v; // velocity - float distance = 0; - float triA[3][3], triB[3][3]; - int result = 0; - - cloth1 = clmd->clothObject; - verts1 = cloth1->verts; - - for (i = 0; i < 9; i++) - { - // 9 edge - edge possibilities - - if (i == 0) // cloth edge: 1-2; coll edge: 1-2 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap2; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp2; - } - else if (i == 1) // cloth edge: 1-2; coll edge: 2-3 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap2; - - edgecollpair.p21 = collpair->bp2; - edgecollpair.p22 = collpair->bp3; - } - else if (i == 2) // cloth edge: 1-2; coll edge: 1-3 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap2; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp3; - } - else if (i == 3) // cloth edge: 2-3; coll edge: 1-2 - { - edgecollpair.p11 = collpair->ap2; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp2; - } - else if (i == 4) // cloth edge: 2-3; coll edge: 2-3 - { - edgecollpair.p11 = collpair->ap2; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp2; - edgecollpair.p22 = collpair->bp3; - } - else if (i == 5) // cloth edge: 2-3; coll edge: 1-3 - { - edgecollpair.p11 = collpair->ap2; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp3; - } - else if (i ==6) // cloth edge: 1-3; coll edge: 1-2 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp2; - } - else if (i ==7) // cloth edge: 1-3; coll edge: 2-3 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp2; - edgecollpair.p22 = collpair->bp3; - } - else if (i == 8) // cloth edge: 1-3; coll edge: 1-3 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp3; - } - /* - if ((edgecollpair.p11 == 3) && (edgecollpair.p12 == 16)) - printf("Ahier!\n"); - if ((edgecollpair.p11 == 16) && (edgecollpair.p12 == 3)) - printf("Ahier!\n"); - */ - - // if ( !cloth_are_edges_adjacent ( clmd, collmd, &edgecollpair ) ) - { - // always put coll points in p21/p22 - sub_v3_v3v3(x1, verts1[edgecollpair.p12].txold, verts1[edgecollpair.p11].txold); - sub_v3_v3v3(v1, verts1[edgecollpair.p12].tv, verts1[edgecollpair.p11].tv); - - sub_v3_v3v3(x2, verts2[edgecollpair.p21].co, verts1[edgecollpair.p11].txold); - sub_v3_v3v3(v2, velocity2[edgecollpair.p21].co, verts1[edgecollpair.p11].tv); - - sub_v3_v3v3(x3, verts2[edgecollpair.p22].co, verts1[edgecollpair.p11].txold); - sub_v3_v3v3(v3, velocity2[edgecollpair.p22].co, verts1[edgecollpair.p11].tv); - - numsolutions = cloth_get_collision_time ( x1, v1, x2, v2, x3, v3, solution ); - - if ((edgecollpair.p11 == 3 && edgecollpair.p12==16)|| (edgecollpair.p11==16 && edgecollpair.p12==3)) - { - if (edgecollpair.p21==6 || edgecollpair.p22 == 6) - { - printf("dist: %f, sol[k]: %f, sol2[k]: %f\n", distance, solution[k], solution2[k]); - printf("a1: %f, a2: %f, b1: %f, b2: %f\n", x1[0], x2[0], x3[0], v1[0]); - printf("b21: %d, b22: %d\n", edgecollpair.p21, edgecollpair.p22); - } - } - - for ( k = 0; k < numsolutions; k++ ) - { - // printf("sol %d: %lf\n", k, solution[k]); - if ( ( solution[k] >= ALMOST_ZERO ) && ( solution[k] <= 1.0 ) && ( solution[k] > ALMOST_ZERO)) - { - float a, b; - float out_normal[3]; - float distance; - float impulse = 0; - float I_mag; - - // move verts - VECADDS(triA[0], verts1[edgecollpair.p11].txold, verts1[edgecollpair.p11].tv, solution[k]); - VECADDS(triA[1], verts1[edgecollpair.p12].txold, verts1[edgecollpair.p12].tv, solution[k]); - - VECADDS(triB[0], collmd->current_x[edgecollpair.p21].co, collmd->current_v[edgecollpair.p21].co, solution[k]); - VECADDS(triB[1], collmd->current_x[edgecollpair.p22].co, collmd->current_v[edgecollpair.p22].co, solution[k]); - - // TODO: check for collisions - distance = edgedge_distance(triA[0], triA[1], triB[0], triB[1], &a, &b, out_normal); - - if ((distance <= clmd->coll_parms->epsilon + BLI_bvhtree_getepsilon ( collmd->bvhtree ) + ALMOST_ZERO) && (dot_v3v3(out_normal, out_normal) > 0)) - { - float vrel_1_to_2[3], temp[3], temp2[3], out_normalVelocity; - float desiredVn; - - copy_v3_v3(vrel_1_to_2, verts1[edgecollpair.p11].tv); - mul_v3_fl(vrel_1_to_2, 1.0 - a); - copy_v3_v3(temp, verts1[edgecollpair.p12].tv); - mul_v3_fl(temp, a); - - VECADD(vrel_1_to_2, vrel_1_to_2, temp); - - copy_v3_v3(temp, verts1[edgecollpair.p21].tv); - mul_v3_fl(temp, 1.0 - b); - copy_v3_v3(temp2, verts1[edgecollpair.p22].tv); - mul_v3_fl(temp2, b); - VECADD(temp, temp, temp2); - - sub_v3_v3v3(vrel_1_to_2, vrel_1_to_2, temp); - - out_normalVelocity = dot_v3v3(vrel_1_to_2, out_normal); -/* - // this correction results in wrong normals sometimes? - if (out_normalVelocity < 0.0) - { - out_normalVelocity*= -1.0; - negate_v3(out_normal); - } -*/ - /* Inelastic repulsion impulse. */ - - // Calculate which normal velocity we need. - desiredVn = (out_normalVelocity * (float)solution[k] - (.1 * (clmd->coll_parms->epsilon + BLI_bvhtree_getepsilon ( collmd->bvhtree )) - sqrt(distance)) - ALMOST_ZERO); - - // Now calculate what impulse we need to reach that velocity. - I_mag = (out_normalVelocity - desiredVn) / 2.0; // / (1/m1 + 1/m2); - - // Finally apply that impulse. - impulse = (2.0 * -I_mag) / (a*a + (1.0-a)*(1.0-a) + b*b + (1.0-b)*(1.0-b)); - - VECADDMUL ( verts1[edgecollpair.p11].impulse, out_normal, (1.0-a) * impulse ); - verts1[edgecollpair.p11].impulse_count++; - - VECADDMUL ( verts1[edgecollpair.p12].impulse, out_normal, a * impulse ); - verts1[edgecollpair.p12].impulse_count++; - - // return true; - result = 1; - break; - } - else - { - // missing from collision.hpp - } - // mintime = MIN2(mintime, (float)solution[k]); - - break; - } - } - } - } - return result; -} - -static int cloth_collision_moving ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) -{ - Cloth *cloth1; - cloth1 = clmd->clothObject; - - for ( ; collpair != collision_end; collpair++ ) - { - // only handle moving collisions here - if (!( collpair->flag & COLLISION_IN_FUTURE )) - continue; - - cloth_collision_moving_edges ( clmd, collmd, collpair); - // cloth_collision_moving_tris ( clmd, collmd, collpair); - } - - return 1; -} -#endif static void add_collision_object(Object ***objs, unsigned int *numobj, unsigned int *maxobj, Object *ob, Object *self, int level, unsigned int modifier_type) { @@ -2224,37 +636,14 @@ static void cloth_bvh_objcollisions_nearcheck ( ClothModifierData * clmd, Collis CollPair **collisions, CollPair **collisions_index, int numresult, BVHTreeOverlap *overlap, double dt) { int i; -#ifdef WITH_ELTOPO - GHash *visithash = BLI_ghash_new(edgepair_hash, edgepair_cmp, "visthash, collision.c"); - GHash *tri_visithash = BLI_ghash_new(tripair_hash, tripair_cmp, "tri_visthash, collision.c"); - MemArena *arena = BLI_memarena_new(1<<16, "edge hash arena, collision.c"); -#endif *collisions = ( CollPair* ) MEM_mallocN ( sizeof ( CollPair ) * numresult * 64, "collision array" ); //*4 since cloth_collision_static can return more than 1 collision *collisions_index = *collisions; - -#ifdef WITH_ELTOPO - machine_epsilon_offset(clmd->clothObject); - - for ( i = 0; i < numresult; i++ ) { - *collisions_index = cloth_collision ( (ModifierData *)clmd, (ModifierData *)collmd, - overlap+i, *collisions_index, dt, tri_visithash, arena ); - } for ( i = 0; i < numresult; i++ ) { - *collisions_index = cloth_edge_collision ( (ModifierData *)clmd, (ModifierData *)collmd, - overlap+i, *collisions_index, visithash, arena ); - } - BLI_ghash_free(visithash, NULL, NULL); - BLI_ghash_free(tri_visithash, NULL, NULL); - BLI_memarena_free(arena); -#else /* WITH_ELTOPO */ - for ( i = 0; i < numresult; i++ ) { *collisions_index = cloth_collision ( (ModifierData *)clmd, (ModifierData *)collmd, overlap+i, *collisions_index, dt ); } -#endif /* WITH_ELTOPO */ - } static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, CollisionModifierData *collmd, CollPair *collisions, CollPair *collisions_index) @@ -2264,36 +653,26 @@ static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, Collision ClothVertex *verts = NULL; int ret = 0; int result = 0; - float tnull[3] = {0, 0, 0}; - /*numfaces = clmd->clothObject->numfaces;*/ /*UNUSED*/ numverts = clmd->clothObject->numverts; - verts = cloth->verts; // process all collisions (calculate impulses, TODO: also repulses if distance too short) result = 1; - for ( j = 0; j < 5; j++ ) { /* 5 is just a value that ensures convergence */ + for ( j = 0; j < 2; j++ ) { /* 5 is just a value that ensures convergence */ result = 0; if ( collmd->bvhtree ) { -#ifdef WITH_ELTOPO - result += cloth_collision_response_moving(clmd, collmd, collisions, collisions_index); - result += cloth_edge_collision_response_moving(clmd, collmd, collisions, collisions_index); -#else result += cloth_collision_response_static ( clmd, collmd, collisions, collisions_index ); -#endif -#ifdef WITH_ELTOPO - { -#else + // apply impulses in parallel if (result) { -#endif for (i = 0; i < numverts; i++) { // calculate "velocities" (just xnew = xold + v; no dt in v) if (verts[i].impulse_count) { - VECADDMUL ( verts[i].tv, verts[i].impulse, 1.0f / verts[i].impulse_count ); - copy_v3_v3 ( verts[i].impulse, tnull ); + // VECADDMUL ( verts[i].tv, verts[i].impulse, 1.0f / verts[i].impulse_count ); + VECADD ( verts[i].tv, verts[i].tv, verts[i].impulse); + zero_v3(verts[i].impulse); verts[i].impulse_count = 0; ret++; @@ -2301,6 +680,9 @@ static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, Collision } } } + + if(!result) + break; } return ret; } @@ -2337,6 +719,18 @@ int cloth_bvh_objcollision(Object *ob, ClothModifierData * clmd, float step, flo if (!collobjs) return 0; + /* move object to position (step) in time */ + for (i = 0; i < numcollobj; i++) { + Object *collob= collobjs[i]; + CollisionModifierData *collmd = (CollisionModifierData*)modifiers_findByType(collob, eModifierType_Collision); + + if (!collmd->bvhtree) + continue; + + /* move object to position (step) in time */ + collision_move_object ( collmd, step + dt, step ); + } + do { CollPair **collisions, **collisions_index; @@ -2356,10 +750,6 @@ int cloth_bvh_objcollision(Object *ob, ClothModifierData * clmd, float step, flo if (!collmd->bvhtree) continue; - /* move object to position (step) in time */ - - collision_move_object ( collmd, step + dt, step ); - /* search for overlapping collision pairs */ overlap = BLI_bvhtree_overlap ( cloth_bvh, collmd->bvhtree, &result ); diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 7ba117861bb..d15f678f1c5 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -146,6 +146,32 @@ void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], con /* ***************** operations on single curve ************* */ /* ********** NOTE: requires curvemapping_changed() call after ******** */ +/* remove specified point */ +void curvemap_remove_point(CurveMap *cuma, CurveMapPoint *point) +{ + CurveMapPoint *cmp; + int a, b, removed = 0; + + /* must have 2 points minimum */ + if (cuma->totpoint <= 2) + return; + + cmp = MEM_mallocN((cuma->totpoint) * sizeof(CurveMapPoint), "curve points"); + + /* well, lets keep the two outer points! */ + for (a = 0, b = 0; a < cuma->totpoint; a++) { + if (&cuma->curve[a] != point) { + cmp[b] = cuma->curve[a]; + b++; + } + else removed++; + } + + MEM_freeN(cuma->curve); + cuma->curve = cmp; + cuma->totpoint -= removed; +} + /* removes with flag set */ void curvemap_remove(CurveMap *cuma, int flag) { @@ -168,9 +194,10 @@ void curvemap_remove(CurveMap *cuma, int flag) cuma->totpoint -= removed; } -void curvemap_insert(CurveMap *cuma, float x, float y) +CurveMapPoint *curvemap_insert(CurveMap *cuma, float x, float y) { CurveMapPoint *cmp = MEM_callocN((cuma->totpoint + 1) * sizeof(CurveMapPoint), "curve points"); + CurveMapPoint *newcmp = NULL; int a, b, foundloc = 0; /* insert fragments of the old one and the new point to the new curve */ @@ -181,6 +208,7 @@ void curvemap_insert(CurveMap *cuma, float x, float y) cmp[a].y = y; cmp[a].flag = CUMA_SELECT; foundloc = 1; + newcmp = &cmp[a]; } else { cmp[a].x = cuma->curve[b].x; @@ -195,6 +223,8 @@ void curvemap_insert(CurveMap *cuma, float x, float y) /* free old curve and replace it with new one */ MEM_freeN(cuma->curve); cuma->curve = cmp; + + return newcmp; } void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) @@ -670,6 +700,20 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles) curvemap_make_table(cuma, clipr); } +void curvemapping_changed_all(CurveMapping *cumap) +{ + int a, cur = cumap->cur; + + for (a = 0; a < CM_TOT; a++) { + if (cumap->cm[a].curve) { + cumap->cur = a; + curvemapping_changed(cumap, 0); + } + } + + cumap->cur = cur; +} + /* table should be verified */ float curvemap_evaluateF(CurveMap *cuma, float value) { diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 868da0fda94..a1f87762db7 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -961,7 +961,7 @@ static int basis_cross(int n, int m) } } -static void vectomat(float *vec, float *target_up, short axis, short upflag, short flags, float m[][3]) +static void vectomat(const float vec[3], const float target_up[3], short axis, short upflag, short flags, float m[][3]) { float n[3]; float u[3]; /* vector specifying the up axis */ diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 43cc63aefa6..6a0991cf4e5 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -393,7 +393,7 @@ void BKE_curve_texspace_calc(Curve *cu) if (tot) doit = 1; fp = dl->verts; while (tot--) { - DO_MINMAX(fp, min, max); + minmax_v3v3_v3(min, max, fp); fp += 3; } dl = dl->next; @@ -588,7 +588,7 @@ void BKE_nurb_test2D(Nurb *nu) } } -void BKE_nurb_minmax(Nurb *nu, float *min, float *max) +void BKE_nurb_minmax(Nurb *nu, float min[3], float max[3]) { BezTriple *bezt; BPoint *bp; @@ -598,9 +598,9 @@ void BKE_nurb_minmax(Nurb *nu, float *min, float *max) a = nu->pntsu; bezt = nu->bezt; while (a--) { - DO_MINMAX(bezt->vec[0], min, max); - DO_MINMAX(bezt->vec[1], min, max); - DO_MINMAX(bezt->vec[2], min, max); + minmax_v3v3_v3(min, max, bezt->vec[0]); + minmax_v3v3_v3(min, max, bezt->vec[1]); + minmax_v3v3_v3(min, max, bezt->vec[2]); bezt++; } } @@ -608,7 +608,7 @@ void BKE_nurb_minmax(Nurb *nu, float *min, float *max) a = nu->pntsu * nu->pntsv; bp = nu->bp; while (a--) { - DO_MINMAX(bp->vec, min, max); + minmax_v3v3_v3(min, max, bp->vec); bp++; } } @@ -1166,19 +1166,23 @@ void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float } } -static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float *p3, float *p, int it, int stride) +static void forward_diff_bezier_cotangent(const float p0[3], const float p1[3], const float p2[3], const float p3[3], + float p[3], int it, int stride) { /* note that these are not purpendicular to the curve * they need to be rotated for this, * - * This could also be optimized like forward_diff_bezier */ + * This could also be optimized like BKE_curve_forward_diff_bezier */ int a; for (a = 0; a <= it; a++) { float t = (float)a / (float)it; int i; for (i = 0; i < 3; i++) { - p[i] = (-6 * t + 6) * p0[i] + (18 * t - 12) * p1[i] + (-18 * t + 6) * p2[i] + (6 * t) * p3[i]; + p[i] = (-6.0f * t + 6.0f) * p0[i] + + ( 18.0f * t - 12.0f) * p1[i] + + (-18.0f * t + 6.0f) * p2[i] + + ( 6.0f * t) * p3[i]; } normalize_v3(p); p = (float *)(((char *)p) + stride); @@ -2043,7 +2047,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) normalize_v3(vec_2); /* align the vector, can avoid this and it looks 98% OK but - * better to align the angle quat roll's before comparing */ + * better to align the angle quat roll's before comparing */ { cross_v3_v3v3(cross_tmp, bevp_last->dir, bevp_first->dir); angle = angle_normalized_v3v3(bevp_first->dir, bevp_last->dir); diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 5eab6aeccef..90a3e617477 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -128,7 +128,7 @@ typedef struct LayerTypeInfo { } LayerTypeInfo; static void layerCopy_mdeformvert(const void *source, void *dest, - int count) + int count) { int i, size = sizeof(MDeformVert); @@ -139,7 +139,7 @@ static void layerCopy_mdeformvert(const void *source, void *dest, if (dvert->totweight) { MDeformWeight *dw = MEM_callocN(dvert->totweight * sizeof(*dw), - "layerCopy_mdeformvert dw"); + "layerCopy_mdeformvert dw"); memcpy(dw, dvert->dw, dvert->totweight * sizeof(*dw)); dvert->dw = dw; @@ -204,7 +204,7 @@ static void linklist_free_simple(void *link) } static void layerInterp_mdeformvert(void **sources, float *weights, - float *UNUSED(sub_weights), int count, void *dest) + float *UNUSED(sub_weights), int count, void *dest) { MDeformVert *dvert = dest; LinkNode *dest_dw = NULL; /* a list of lists of MDeformWeight pointers */ @@ -234,7 +234,7 @@ static void layerInterp_mdeformvert(void **sources, float *weights, /* if this def_nr is not in the list, add it */ if (!node) { MDeformWeight *tmp_dw = MEM_callocN(sizeof(*tmp_dw), - "layerInterp_mdeformvert tmp_dw"); + "layerInterp_mdeformvert tmp_dw"); tmp_dw->def_nr = dw->def_nr; tmp_dw->weight = dw->weight * interp_weight; BLI_linklist_prepend(&dest_dw, tmp_dw); @@ -248,7 +248,7 @@ static void layerInterp_mdeformvert(void **sources, float *weights, if (totweight) { dvert->dw = MEM_callocN(sizeof(*dvert->dw) * totweight, - "layerInterp_mdeformvert dvert->dw"); + "layerInterp_mdeformvert dvert->dw"); dvert->totweight = totweight; for (i = 0, node = dest_dw; node; node = node->next, ++i) @@ -262,7 +262,7 @@ static void layerInterp_mdeformvert(void **sources, float *weights, static void layerInterp_msticky(void **sources, float *weights, - float *UNUSED(sub_weights), int count, void *dest) + float *UNUSED(sub_weights), int count, void *dest) { float co[2], w; MSticky *mst; @@ -271,20 +271,20 @@ static void layerInterp_msticky(void **sources, float *weights, co[0] = co[1] = 0.0f; for (i = 0; i < count; i++) { w = weights ? weights[i] : 1.0f; - mst = (MSticky*)sources[i]; + mst = (MSticky *)sources[i]; madd_v2_v2fl(co, mst->co, w); } - mst = (MSticky*)dest; + mst = (MSticky *)dest; copy_v2_v2(mst->co, co); } static void layerCopy_tface(const void *source, void *dest, int count) { - const MTFace *source_tf = (const MTFace*)source; - MTFace *dest_tf = (MTFace*)dest; + const MTFace *source_tf = (const MTFace *)source; + MTFace *dest_tf = (MTFace *)dest; int i; for (i = 0; i < count; ++i) @@ -292,7 +292,7 @@ static void layerCopy_tface(const void *source, void *dest, int count) } static void layerInterp_tface(void **sources, float *weights, - float *sub_weights, int count, void *dest) + float *sub_weights, int count, void *dest) { MTFace *tf = dest; int i, j, k; @@ -326,10 +326,8 @@ static void layerSwap_tface(void *data, const int *corner_indices) { MTFace *tf = data; float uv[4][2]; - static const short pin_flags[4] = - { TF_PIN1, TF_PIN2, TF_PIN3, TF_PIN4 }; - static const char sel_flags[4] = - { TF_SEL1, TF_SEL2, TF_SEL3, TF_SEL4 }; + static const short pin_flags[4] = { TF_PIN1, TF_PIN2, TF_PIN3, TF_PIN4 }; + static const char sel_flags[4] = { TF_SEL1, TF_SEL2, TF_SEL3, TF_SEL4 }; short unwrap = tf->unwrap & ~(TF_PIN1 | TF_PIN2 | TF_PIN3 | TF_PIN4); char flag = tf->flag & ~(TF_SEL1 | TF_SEL2 | TF_SEL3 | TF_SEL4); int j; @@ -358,8 +356,8 @@ static void layerSwap_tface(void *data, const int *corner_indices) static void layerDefault_tface(void *data, int count) { static MTFace default_tf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, NULL, - 0, 0, TF_DYNAMIC|TF_CONVERTED, 0, 0}; - MTFace *tf = (MTFace*)data; + 0, 0, TF_DYNAMIC | TF_CONVERTED, 0, 0}; + MTFace *tf = (MTFace *)data; int i; for (i = 0; i < count; i++) @@ -367,27 +365,27 @@ static void layerDefault_tface(void *data, int count) } static void layerCopy_propFloat(const void *source, void *dest, - int count) + int count) { - memcpy(dest, source, sizeof(MFloatProperty)*count); + memcpy(dest, source, sizeof(MFloatProperty) * count); } static void layerCopy_propInt(const void *source, void *dest, - int count) + int count) { - memcpy(dest, source, sizeof(MIntProperty)*count); + memcpy(dest, source, sizeof(MIntProperty) * count); } static void layerCopy_propString(const void *source, void *dest, - int count) + int count) { - memcpy(dest, source, sizeof(MStringProperty)*count); + memcpy(dest, source, sizeof(MStringProperty) * count); } static void layerCopy_origspace_face(const void *source, void *dest, int count) { - const OrigSpaceFace *source_tf = (const OrigSpaceFace*)source; - OrigSpaceFace *dest_tf = (OrigSpaceFace*)dest; + const OrigSpaceFace *source_tf = (const OrigSpaceFace *)source; + OrigSpaceFace *dest_tf = (OrigSpaceFace *)dest; int i; for (i = 0; i < count; ++i) @@ -395,7 +393,7 @@ static void layerCopy_origspace_face(const void *source, void *dest, int count) } static void layerInterp_origspace_face(void **sources, float *weights, - float *sub_weights, int count, void *dest) + float *sub_weights, int count, void *dest) { OrigSpaceFace *osf = dest; int i, j, k; @@ -442,7 +440,7 @@ static void layerSwap_origspace_face(void *data, const int *corner_indices) static void layerDefault_origspace_face(void *data, int count) { static OrigSpaceFace default_osf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}; - OrigSpaceFace *osf = (OrigSpaceFace*)data; + OrigSpaceFace *osf = (OrigSpaceFace *)data; int i; for (i = 0; i < count; i++) @@ -456,27 +454,27 @@ static void layerSwap_mdisps(void *data, const int *ci) int corners, cornersize, S; if (s->disps) { - int nverts= (ci[1] == 3) ? 4 : 3; /* silly way to know vertex count of face */ - corners= multires_mdisp_corners(s); - cornersize= s->totdisp/corners; + int nverts = (ci[1] == 3) ? 4 : 3; /* silly way to know vertex count of face */ + corners = multires_mdisp_corners(s); + cornersize = s->totdisp / corners; - if (corners!=nverts) { + if (corners != nverts) { /* happens when face changed vertex count in edit mode * if it happened, just forgot displacement */ MEM_freeN(s->disps); - s->totdisp= (s->totdisp/corners)*nverts; - s->disps= MEM_callocN(s->totdisp*sizeof(float)*3, "mdisp swap"); + s->totdisp = (s->totdisp / corners) * nverts; + s->disps = MEM_callocN(s->totdisp * sizeof(float) * 3, "mdisp swap"); return; } - d= MEM_callocN(sizeof(float) * 3 * s->totdisp, "mdisps swap"); + d = MEM_callocN(sizeof(float) * 3 * s->totdisp, "mdisps swap"); for (S = 0; S < corners; S++) - memcpy(d + cornersize*S, s->disps + cornersize*ci[S], cornersize*3*sizeof(float)); + memcpy(d + cornersize * S, s->disps + cornersize * ci[S], cornersize * 3 * sizeof(float)); MEM_freeN(s->disps); - s->disps= d; + s->disps = d; } } @@ -527,9 +525,9 @@ static int layerRead_mdisps(CDataFile *cdf, void *data, int count) for (i = 0; i < count; ++i) { if (!d[i].disps) - d[i].disps = MEM_callocN(sizeof(float)*3*d[i].totdisp, "mdisps read"); + d[i].disps = MEM_callocN(sizeof(float) * 3 * d[i].totdisp, "mdisps read"); - if (!cdf_read_data(cdf, d[i].totdisp*3*sizeof(float), d[i].disps)) { + if (!cdf_read_data(cdf, d[i].totdisp * 3 * sizeof(float), d[i].disps)) { printf("failed to read multires displacement %d/%d %d\n", i, count, d[i].totdisp); return 0; } @@ -544,7 +542,7 @@ static int layerWrite_mdisps(CDataFile *cdf, void *data, int count) int i; for (i = 0; i < count; ++i) { - if (!cdf_write_data(cdf, d[i].totdisp*3*sizeof(float), d[i].disps)) { + if (!cdf_write_data(cdf, d[i].totdisp * 3 * sizeof(float), d[i].disps)) { printf("failed to write multires displacement %d/%d %d\n", i, count, d[i].totdisp); return 0; } @@ -560,7 +558,7 @@ static size_t layerFilesize_mdisps(CDataFile *UNUSED(cdf), void *data, int count int i; for (i = 0; i < count; ++i) - size += d[i].totdisp*3*sizeof(float); + size += d[i].totdisp * 3 * sizeof(float); return size; } @@ -571,8 +569,8 @@ static void layerCopy_grid_paint_mask(const void *source, void *dest, int count) const GridPaintMask *s = source; GridPaintMask *d = dest; - for(i = 0; i < count; ++i) { - if(s[i].data) { + for (i = 0; i < count; ++i) { + if (s[i].data) { d[i].data = MEM_dupallocN(s[i].data); d[i].level = s[i].level; } @@ -589,8 +587,8 @@ static void layerFree_grid_paint_mask(void *data, int count, int UNUSED(size)) int i; GridPaintMask *gpm = data; - for(i = 0; i < count; ++i) { - if(gpm[i].data) + for (i = 0; i < count; ++i) { + if (gpm[i].data) MEM_freeN(gpm[i].data); gpm[i].data = NULL; gpm[i].level = 0; @@ -675,7 +673,7 @@ static void layerInitMinMax_mloopcol(void *vmin, void *vmax) static void layerDefault_mloopcol(void *data, int count) { MLoopCol default_mloopcol = {255, 255, 255, 255}; - MLoopCol *mlcol = (MLoopCol*)data; + MLoopCol *mlcol = (MLoopCol *)data; int i; for (i = 0; i < count; i++) mlcol[i] = default_mloopcol; @@ -683,7 +681,7 @@ static void layerDefault_mloopcol(void *data, int count) } static void layerInterp_mloopcol(void **sources, float *weights, - float *sub_weights, int count, void *dest) + float *sub_weights, int count, void *dest) { MLoopCol *mc = dest; int i; @@ -774,7 +772,7 @@ static void layerInterp_mloopuv(void **sources, float *weights, float *sub_weights, int count, void *dest) { MLoopUV *mluv = dest; - float *uv= mluv->uv; + float *uv = mluv->uv; int i; zero_v2(uv); @@ -841,10 +839,10 @@ static void layerAdd_mloop_origspace(void *data1, void *data2) } static void layerInterp_mloop_origspace(void **sources, float *weights, - float *sub_weights, int count, void *dest) + float *sub_weights, int count, void *dest) { OrigSpaceLoop *mluv = dest; - float *uv= mluv->uv; + float *uv = mluv->uv; int i; zero_v2(uv); @@ -869,7 +867,7 @@ static void layerInterp_mloop_origspace(void **sources, float *weights, /* --- end copy */ static void layerInterp_mcol(void **sources, float *weights, - float *sub_weights, int count, void *dest) + float *sub_weights, int count, void *dest) { MCol *mc = dest; int i, j, k; @@ -892,7 +890,7 @@ static void layerInterp_mcol(void **sources, float *weights, if (sub_weights) { MCol *src = sources[i]; for (k = 0; k < 4; ++k, ++sub_weight, ++src) { - const float w= (*sub_weight) * weight; + const float w = (*sub_weight) * weight; col[j].a += src->a * w; col[j].r += src->r * w; col[j].g += src->g * w; @@ -940,10 +938,10 @@ static void layerSwap_mcol(void *data, const int *corner_indices) static void layerDefault_mcol(void *data, int count) { static MCol default_mcol = {255, 255, 255, 255}; - MCol *mcol = (MCol*)data; + MCol *mcol = (MCol *)data; int i; - for (i = 0; i < 4*count; i++) { + for (i = 0; i < 4 * count; i++) { mcol[i] = default_mcol; } } @@ -1012,13 +1010,13 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { layerInterp_tface, layerSwap_tface, layerDefault_tface}, /* 6: CD_MCOL */ /* 4 MCol structs per face */ - {sizeof(MCol)*4, "MCol", 4, "Col", NULL, NULL, layerInterp_mcol, + {sizeof(MCol) * 4, "MCol", 4, "Col", NULL, NULL, layerInterp_mcol, layerSwap_mcol, layerDefault_mcol}, /* 7: CD_ORIGINDEX */ {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, /* 8: CD_NORMAL */ /* 3 floats per normal vector */ - {sizeof(float)*3, "vec3f", 1, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(float) * 3, "vec3f", 1, NULL, NULL, NULL, NULL, NULL, NULL}, /* 9: CD_POLYINDEX */ {sizeof(int), "MIntProperty", 1, NULL, NULL, NULL, NULL, NULL, NULL}, /* 10: CD_PROP_FLT */ @@ -1031,10 +1029,10 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { {sizeof(OrigSpaceFace), "OrigSpaceFace", 1, "UVMap", layerCopy_origspace_face, NULL, layerInterp_origspace_face, layerSwap_origspace_face, layerDefault_origspace_face}, /* 14: CD_ORCO */ - {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(float) * 3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, /* 15: CD_MTEXPOLY */ /* note, when we expose the UV Map / TexFace split to the user, change this back to face Texture */ - {sizeof(MTexPoly), "MTexPoly", 1, "UVMap"/* "Face Texture" */, NULL, NULL, NULL, NULL, NULL}, + {sizeof(MTexPoly), "MTexPoly", 1, "UVMap" /* "Face Texture" */, NULL, NULL, NULL, NULL, NULL}, /* 16: CD_MLOOPUV */ {sizeof(MLoopUV), "MLoopUV", 1, "UV coord", NULL, NULL, layerInterp_mloopuv, NULL, NULL, layerEqual_mloopuv, layerMultiply_mloopuv, layerInitMinMax_mloopuv, @@ -1044,23 +1042,23 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { layerDefault_mloopcol, layerEqual_mloopcol, layerMultiply_mloopcol, layerInitMinMax_mloopcol, layerAdd_mloopcol, layerDoMinMax_mloopcol, layerCopyValue_mloopcol}, /* 18: CD_TANGENT */ - {sizeof(float)*4*4, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(float) * 4 * 4, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, /* 19: CD_MDISPS */ {sizeof(MDisps), "MDisps", 1, NULL, layerCopy_mdisps, layerFree_mdisps, NULL, layerSwap_mdisps, NULL, NULL, NULL, NULL, NULL, NULL, NULL, layerRead_mdisps, layerWrite_mdisps, layerFilesize_mdisps}, /* 20: CD_PREVIEW_MCOL */ - {sizeof(MCol)*4, "MCol", 4, "PreviewCol", NULL, NULL, layerInterp_mcol, + {sizeof(MCol) * 4, "MCol", 4, "PreviewCol", NULL, NULL, layerInterp_mcol, layerSwap_mcol, layerDefault_mcol}, /* 21: CD_ID_MCOL */ - {sizeof(MCol)*4, "MCol", 4, "IDCol", NULL, NULL, layerInterp_mcol, + {sizeof(MCol) * 4, "MCol", 4, "IDCol", NULL, NULL, layerInterp_mcol, layerSwap_mcol, layerDefault_mcol}, /* 22: CD_TEXTURE_MCOL */ - {sizeof(MCol)*4, "MCol", 4, "TexturedCol", NULL, NULL, layerInterp_mcol, + {sizeof(MCol) * 4, "MCol", 4, "TexturedCol", NULL, NULL, layerInterp_mcol, layerSwap_mcol, layerDefault_mcol}, /* 23: CD_CLOTH_ORCO */ - {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(float) * 3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, /* 24: CD_RECAST */ {sizeof(MRecast), "MRecast", 1, "Recast", NULL, NULL, NULL, NULL}, @@ -1072,7 +1070,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { /* 27: CD_SHAPE_KEYINDEX */ {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, /* 28: CD_SHAPEKEY */ - {sizeof(float)*3, "", 0, "ShapeKey", NULL, NULL, layerInterp_shapekey}, + {sizeof(float) * 3, "", 0, "ShapeKey", NULL, NULL, layerInterp_shapekey}, /* 29: CD_BWEIGHT */ {sizeof(float), "", 0, "BevelWeight", NULL, NULL, layerInterp_bweight}, /* 30: CD_CREASE */ @@ -1105,7 +1103,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = { /* 5-9 */ "CDMTFace", "CDMCol", "CDOrigIndex", "CDNormal", "CDFlags", /* 10-14 */ "CDMFloatProperty", "CDMIntProperty", "CDMStringProperty", "CDOrigSpace", "CDOrco", /* 15-19 */ "CDMTexPoly", "CDMLoopUV", "CDMloopCol", "CDTangent", "CDMDisps", - /* 20-24 */"CDPreviewMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco", "CDMRecast", + /* 20-24 */ "CDPreviewMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco", "CDMRecast", /* BMESH ONLY */ /* 25-29 */ "CDMPoly", "CDMLoop", "CDShapeKeyIndex", "CDShapeKey", "CDBevelWeight", @@ -1118,35 +1116,36 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = { const CustomDataMask CD_MASK_BAREMESH = - CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_MLOOP | CD_MASK_MPOLY | CD_MASK_BWEIGHT; + CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_MLOOP | CD_MASK_MPOLY | CD_MASK_BWEIGHT; const CustomDataMask CD_MASK_MESH = - CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | - CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | - CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | - CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP | - CD_MASK_MTEXPOLY | CD_MASK_NORMAL | CD_MASK_RECAST | CD_MASK_PAINT_MASK | - CD_MASK_GRID_PAINT_MASK; + CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | + CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | + CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | + CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP | + CD_MASK_MTEXPOLY | CD_MASK_NORMAL | CD_MASK_RECAST | CD_MASK_PAINT_MASK | + CD_MASK_GRID_PAINT_MASK; const CustomDataMask CD_MASK_EDITMESH = - CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV | - CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX | - CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | - CD_MASK_MDISPS | CD_MASK_SHAPEKEY | CD_MASK_RECAST | CD_MASK_PAINT_MASK | - CD_MASK_GRID_PAINT_MASK; + CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV | + CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX | + CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | + CD_MASK_MDISPS | CD_MASK_SHAPEKEY | CD_MASK_RECAST | CD_MASK_PAINT_MASK | + CD_MASK_GRID_PAINT_MASK; const CustomDataMask CD_MASK_DERIVEDMESH = - CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | - CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO | - CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_PREVIEW_MLOOPCOL | - CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_ORCO | CD_MASK_TANGENT | - CD_MASK_PREVIEW_MCOL | CD_MASK_NORMAL | CD_MASK_SHAPEKEY | CD_MASK_RECAST | - CD_MASK_ORIGINDEX | CD_MASK_POLYINDEX; -const CustomDataMask CD_MASK_BMESH = CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | - CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | - CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS | - CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK | - CD_MASK_GRID_PAINT_MASK; + CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | + CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO | + CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_PREVIEW_MLOOPCOL | + CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_ORCO | CD_MASK_TANGENT | + CD_MASK_PREVIEW_MCOL | CD_MASK_NORMAL | CD_MASK_SHAPEKEY | CD_MASK_RECAST | + CD_MASK_ORIGINDEX | CD_MASK_POLYINDEX; +const CustomDataMask CD_MASK_BMESH = + CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | + CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | + CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS | + CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK | + CD_MASK_GRID_PAINT_MASK; const CustomDataMask CD_MASK_FACECORNERS = - CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV | - CD_MASK_MLOOPCOL; + CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV | + CD_MASK_MLOOPCOL; static const LayerTypeInfo *layerType_getInfo(int type) { @@ -1166,7 +1165,7 @@ static const char *layerType_getName(int type) static void customData_update_offsets(CustomData *data); static CustomDataLayer *customData_add_layer__internal(CustomData *data, - int type, int alloctype, void *layerdata, int totelem, const char *name); + int type, int alloctype, void *layerdata, int totelem, const char *name); void CustomData_update_typemap(CustomData *data) { @@ -1175,11 +1174,11 @@ void CustomData_update_typemap(CustomData *data) /* since we cant do in a pre-processor do here as an assert */ BLI_assert(sizeof(data->typemap) / sizeof(int) >= CD_NUMTYPES); - for (i=0; i<CD_NUMTYPES; i++) { + for (i = 0; i < CD_NUMTYPES; i++) { data->typemap[i] = -1; } - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { if (data->layers[i].type != lasttype) { data->typemap[data->layers[i].type] = i; } @@ -1188,7 +1187,7 @@ void CustomData_update_typemap(CustomData *data) } void CustomData_merge(const struct CustomData *source, struct CustomData *dest, - CustomDataMask mask, int alloctype, int totelem) + CustomDataMask mask, int alloctype, int totelem) { /*const LayerTypeInfo *typeInfo;*/ CustomDataLayer *layer, *newlayer; @@ -1230,10 +1229,10 @@ void CustomData_merge(const struct CustomData *source, struct CustomData *dest, if ((alloctype == CD_ASSIGN) && (lastflag & CD_FLAG_NOFREE)) newlayer = customData_add_layer__internal(dest, type, CD_REFERENCE, - data, totelem, layer->name); + data, totelem, layer->name); else newlayer = customData_add_layer__internal(dest, type, alloctype, - data, totelem, layer->name); + data, totelem, layer->name); if (newlayer) { newlayer->uid = layer->uid; @@ -1242,7 +1241,7 @@ void CustomData_merge(const struct CustomData *source, struct CustomData *dest, newlayer->active_rnd = lastrender; newlayer->active_clone = lastclone; newlayer->active_mask = lastmask; - newlayer->flag |= lastflag & (CD_FLAG_EXTERNAL|CD_FLAG_IN_MEMORY); + newlayer->flag |= lastflag & (CD_FLAG_EXTERNAL | CD_FLAG_IN_MEMORY); } } @@ -1250,12 +1249,12 @@ void CustomData_merge(const struct CustomData *source, struct CustomData *dest, } void CustomData_copy(const struct CustomData *source, struct CustomData *dest, - CustomDataMask mask, int alloctype, int totelem) + CustomDataMask mask, int alloctype, int totelem) { memset(dest, 0, sizeof(*dest)); if (source->external) - dest->external= MEM_dupallocN(source->external); + dest->external = MEM_dupallocN(source->external); CustomData_merge(source, dest, mask, alloctype, totelem); } @@ -1279,7 +1278,7 @@ static void CustomData_external_free(CustomData *data) { if (data->external) { MEM_freeN(data->external); - data->external= NULL; + data->external = NULL; } } @@ -1318,7 +1317,7 @@ int CustomData_get_layer_index(const CustomData *data, int type) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) return i; @@ -1340,8 +1339,8 @@ int CustomData_get_named_layer_index(const CustomData *data, int type, const cha { int i; - for (i=0; i < data->totlayer; ++i) - if (data->layers[i].type == type && strcmp(data->layers[i].name, name)==0) + for (i = 0; i < data->totlayer; ++i) + if (data->layers[i].type == type && strcmp(data->layers[i].name, name) == 0) return i; return -1; @@ -1363,7 +1362,7 @@ int CustomData_get_render_layer_index(const CustomData *data, int type) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) return i + data->layers[i].active_rnd; @@ -1374,7 +1373,7 @@ int CustomData_get_clone_layer_index(const CustomData *data, int type) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) return i + data->layers[i].active_clone; @@ -1385,7 +1384,7 @@ int CustomData_get_stencil_layer_index(const CustomData *data, int type) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) return i + data->layers[i].active_mask; @@ -1396,7 +1395,7 @@ int CustomData_get_active_layer(const CustomData *data, int type) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) return data->layers[i].active; @@ -1407,7 +1406,7 @@ int CustomData_get_render_layer(const CustomData *data, int type) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) return data->layers[i].active_rnd; @@ -1418,7 +1417,7 @@ int CustomData_get_clone_layer(const CustomData *data, int type) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) return data->layers[i].active_clone; @@ -1429,7 +1428,7 @@ int CustomData_get_stencil_layer(const CustomData *data, int type) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) return data->layers[i].active_mask; @@ -1440,7 +1439,7 @@ void CustomData_set_layer_active(CustomData *data, int type, int n) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) data->layers[i].active = n; } @@ -1449,7 +1448,7 @@ void CustomData_set_layer_render(CustomData *data, int type, int n) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) data->layers[i].active_rnd = n; } @@ -1458,7 +1457,7 @@ void CustomData_set_layer_clone(CustomData *data, int type, int n) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) data->layers[i].active_clone = n; } @@ -1467,7 +1466,7 @@ void CustomData_set_layer_stencil(CustomData *data, int type, int n) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) data->layers[i].active_mask = n; } @@ -1477,51 +1476,51 @@ void CustomData_set_layer_active_index(CustomData *data, int type, int n) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) - data->layers[i].active = n-i; + data->layers[i].active = n - i; } void CustomData_set_layer_render_index(CustomData *data, int type, int n) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) - data->layers[i].active_rnd = n-i; + data->layers[i].active_rnd = n - i; } void CustomData_set_layer_clone_index(CustomData *data, int type, int n) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) - data->layers[i].active_clone = n-i; + data->layers[i].active_clone = n - i; } void CustomData_set_layer_stencil_index(CustomData *data, int type, int n) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) - data->layers[i].active_mask = n-i; + data->layers[i].active_mask = n - i; } void CustomData_set_layer_flag(struct CustomData *data, int type, int flag) { int i; - for (i=0; i < data->totlayer; ++i) + for (i = 0; i < data->totlayer; ++i) if (data->layers[i].type == type) data->layers[i].flag |= flag; } static int customData_resize(CustomData *data, int amount) { - CustomDataLayer *tmp = MEM_callocN(sizeof(*tmp)*(data->maxlayer + amount), - "CustomData->layers"); + CustomDataLayer *tmp = MEM_callocN(sizeof(*tmp) * (data->maxlayer + amount), + "CustomData->layers"); if (!tmp) return 0; data->maxlayer += amount; @@ -1535,9 +1534,9 @@ static int customData_resize(CustomData *data, int amount) } static CustomDataLayer *customData_add_layer__internal(CustomData *data, - int type, int alloctype, void *layerdata, int totelem, const char *name) + int type, int alloctype, void *layerdata, int totelem, const char *name) { - const LayerTypeInfo *typeInfo= layerType_getInfo(type); + const LayerTypeInfo *typeInfo = layerType_getInfo(type); int size = typeInfo->size * totelem, flag = 0, index = data->totlayer; void *newlayerdata = NULL; @@ -1568,7 +1567,7 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, } else if (alloctype == CD_DEFAULT) { if (typeInfo->set_default) - typeInfo->set_default((char*)newlayerdata, totelem); + typeInfo->set_default((char *)newlayerdata, totelem); } else if (alloctype == CD_REFERENCE) flag |= CD_FLAG_NOFREE; @@ -1584,25 +1583,25 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, data->totlayer++; /* keep layers ordered by type */ - for ( ; index > 0 && data->layers[index - 1].type > type; --index) + for (; index > 0 && data->layers[index - 1].type > type; --index) data->layers[index] = data->layers[index - 1]; data->layers[index].type = type; data->layers[index].flag = flag; data->layers[index].data = newlayerdata; - if (name || (name=typeInfo->defaultname)) { + if (name || (name = typeInfo->defaultname)) { BLI_strncpy(data->layers[index].name, name, sizeof(data->layers[index].name)); CustomData_set_layer_unique_name(data, index); } else data->layers[index].name[0] = '\0'; - if (index > 0 && data->layers[index-1].type == type) { - data->layers[index].active = data->layers[index-1].active; - data->layers[index].active_rnd = data->layers[index-1].active_rnd; - data->layers[index].active_clone = data->layers[index-1].active_clone; - data->layers[index].active_mask = data->layers[index-1].active_mask; + if (index > 0 && data->layers[index - 1].type == type) { + data->layers[index].active = data->layers[index - 1].active; + data->layers[index].active_rnd = data->layers[index - 1].active_rnd; + data->layers[index].active_clone = data->layers[index - 1].active_clone; + data->layers[index].active_mask = data->layers[index - 1].active_mask; } else { data->layers[index].active = 0; @@ -1617,13 +1616,13 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, } void *CustomData_add_layer(CustomData *data, int type, int alloctype, - void *layerdata, int totelem) + void *layerdata, int totelem) { CustomDataLayer *layer; - const LayerTypeInfo *typeInfo= layerType_getInfo(type); + const LayerTypeInfo *typeInfo = layerType_getInfo(type); layer = customData_add_layer__internal(data, type, alloctype, layerdata, - totelem, typeInfo->defaultname); + totelem, typeInfo->defaultname); CustomData_update_typemap(data); if (layer) @@ -1634,12 +1633,12 @@ void *CustomData_add_layer(CustomData *data, int type, int alloctype, /*same as above but accepts a name*/ void *CustomData_add_layer_named(CustomData *data, int type, int alloctype, - void *layerdata, int totelem, const char *name) + void *layerdata, int totelem, const char *name) { CustomDataLayer *layer; layer = customData_add_layer__internal(data, type, alloctype, layerdata, - totelem, name); + totelem, name); CustomData_update_typemap(data); if (layer) @@ -1657,8 +1656,8 @@ int CustomData_free_layer(CustomData *data, int type, int totelem, int index) customData_free_layer__internal(&data->layers[index], totelem); - for (i=index+1; i < data->totlayer; ++i) - data->layers[i-1] = data->layers[i]; + for (i = index + 1; i < data->totlayer; ++i) + data->layers[i - 1] = data->layers[i]; data->totlayer--; @@ -1675,7 +1674,7 @@ int CustomData_free_layer(CustomData *data, int type, int totelem, int index) } } - if (data->totlayer <= data->maxlayer-CUSTOMDATA_GROW) + if (data->totlayer <= data->maxlayer - CUSTOMDATA_GROW) customData_resize(data, -CUSTOMDATA_GROW); customData_update_offsets(data); @@ -1748,7 +1747,7 @@ void *CustomData_duplicate_referenced_layer(struct CustomData *data, const int t } void *CustomData_duplicate_referenced_layer_named(struct CustomData *data, - const int type, const char *name, const int totelem) + const int type, const char *name, const int totelem) { CustomDataLayer *layer; int layer_index; @@ -1813,7 +1812,7 @@ void CustomData_free_temporary(CustomData *data, int totelem) data->totlayer = j; - if (data->totlayer <= data->maxlayer-CUSTOMDATA_GROW) + if (data->totlayer <= data->maxlayer - CUSTOMDATA_GROW) customData_resize(data, -CUSTOMDATA_GROW); customData_update_offsets(data); @@ -1836,11 +1835,11 @@ void CustomData_copy_elements(int type, void *source, void *dest, int count) if (typeInfo->copy) typeInfo->copy(source, dest, count); else - memcpy(dest, source, typeInfo->size*count); + memcpy(dest, source, typeInfo->size * count); } void CustomData_copy_data(const CustomData *source, CustomData *dest, - int source_index, int dest_index, int count) + int source_index, int dest_index, int count) { const LayerTypeInfo *typeInfo; int src_i, dest_i; @@ -1882,12 +1881,12 @@ void CustomData_copy_data(const CustomData *source, CustomData *dest, if (typeInfo->copy) typeInfo->copy(src_data + src_offset, - dest_data + dest_offset, - count); + dest_data + dest_offset, + count); else memcpy(dest_data + dest_offset, - src_data + src_offset, - count * typeInfo->size); + src_data + src_offset, + count * typeInfo->size); /* if there are multiple source & dest layers of the same type, * we don't want to copy all source layers to the same dest, so @@ -1911,7 +1910,7 @@ void CustomData_free_elem(CustomData *data, int index, int count) int offset = typeInfo->size * index; typeInfo->free((char *)data->layers[i].data + offset, - count, typeInfo->size); + count, typeInfo->size); } } } @@ -1920,8 +1919,8 @@ void CustomData_free_elem(CustomData *data, int index, int count) #define SOURCE_BUF_SIZE 100 void CustomData_interp(const CustomData *source, CustomData *dest, - int *src_indices, float *weights, float *sub_weights, - int count, int dest_index) + int *src_indices, float *weights, float *sub_weights, + int count, int dest_index) { int src_i, dest_i; int dest_offset; @@ -1934,12 +1933,12 @@ void CustomData_interp(const CustomData *source, CustomData *dest, */ if (count > SOURCE_BUF_SIZE) sources = MEM_callocN(sizeof(*sources) * count, - "CustomData_interp sources"); + "CustomData_interp sources"); /* interpolates a layer at a time */ dest_i = 0; for (src_i = 0; src_i < source->totlayer; ++src_i) { - const LayerTypeInfo *typeInfo= layerType_getInfo(source->layers[src_i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(source->layers[src_i].type); if (!typeInfo->interp) continue; /* find the first dest layer with type >= the source type @@ -1962,7 +1961,7 @@ void CustomData_interp(const CustomData *source, CustomData *dest, dest_offset = dest_index * typeInfo->size; typeInfo->interp(sources, weights, sub_weights, count, - (char *)dest->layers[dest_i].data + dest_offset); + (char *)dest->layers[dest_i].data + dest_offset); /* if there are multiple source & dest layers of the same type, * we don't want to copy all source layers to the same dest, so @@ -2016,7 +2015,7 @@ void *CustomData_get_n(const CustomData *data, int type, int index, int n) if (layer_index < 0) return NULL; offset = layerType_getInfo(type)->size * index; - return (char *)data->layers[layer_index+n].data + offset; + return (char *)data->layers[layer_index + n].data + offset; } void *CustomData_get_layer(const CustomData *data, int type) @@ -2038,7 +2037,7 @@ void *CustomData_get_layer_n(const CustomData *data, int type, int n) } void *CustomData_get_layer_named(const struct CustomData *data, int type, - const char *name) + const char *name) { int layer_index = CustomData_get_named_layer_index(data, type, name); if (layer_index < 0) return NULL; @@ -2102,7 +2101,7 @@ void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *l int totloop, int totpoly) { int i; - for (i=0; i < fdata->totlayer; i++) { + for (i = 0; i < fdata->totlayer; i++) { if (fdata->layers[i].type == CD_MTFACE) { CustomData_add_layer_named(pdata, CD_MTEXPOLY, CD_CALLOC, NULL, totpoly, fdata->layers[i].name); CustomData_add_layer_named(ldata, CD_MLOOPUV, CD_CALLOC, NULL, totloop, fdata->layers[i].name); @@ -2119,12 +2118,12 @@ void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *l void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *ldata, int total) { int i; - for (i=0; i < pdata->totlayer; i++) { + for (i = 0; i < pdata->totlayer; i++) { if (pdata->layers[i].type == CD_MTEXPOLY) { CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, pdata->layers[i].name); } } - for (i=0; i < ldata->totlayer; i++) { + for (i = 0; i < ldata->totlayer; i++) { if (ldata->layers[i].type == CD_MLOOPCOL) { CustomData_add_layer_named(fdata, CD_MCOL, CD_CALLOC, NULL, total, ldata->layers[i].name); } @@ -2273,7 +2272,7 @@ void CustomData_bmesh_free_block(CustomData *data, void **block) if (typeInfo->free) { int offset = data->layers[i].offset; - typeInfo->free((char*)*block + offset, 1, typeInfo->size); + typeInfo->free((char *)*block + offset, 1, typeInfo->size); } } } @@ -2297,7 +2296,7 @@ static void CustomData_bmesh_alloc_block(CustomData *data, void **block) } void CustomData_bmesh_copy_data(const CustomData *source, CustomData *dest, - void *src_block, void **dest_block) + void *src_block, void **dest_block) { const LayerTypeInfo *typeInfo; int dest_i, src_i; @@ -2324,9 +2323,9 @@ void CustomData_bmesh_copy_data(const CustomData *source, CustomData *dest, /* if we found a matching layer, copy the data */ if (dest->layers[dest_i].type == source->layers[src_i].type && - strcmp(dest->layers[dest_i].name, source->layers[src_i].name) == 0) { - char *src_data = (char*)src_block + source->layers[src_i].offset; - char *dest_data = (char*)*dest_block + dest->layers[dest_i].offset; + strcmp(dest->layers[dest_i].name, source->layers[src_i].name) == 0) { + char *src_data = (char *)src_block + source->layers[src_i].offset; + char *dest_data = (char *)*dest_block + dest->layers[dest_i].offset; typeInfo = layerType_getInfo(source->layers[src_i].type); @@ -2364,7 +2363,7 @@ void *CustomData_bmesh_get_n(const CustomData *data, void *block, int type, int layer_index = CustomData_get_layer_index(data, type); if (layer_index < 0) return NULL; - return (char *)block + data->layers[layer_index+n].offset; + return (char *)block + data->layers[layer_index + n].offset; } /*gets from the layer at physical index n, note: doesn't check type.*/ @@ -2486,7 +2485,7 @@ void CustomData_bmesh_set_layer_n(CustomData *data, void *block, int n, void *so } void CustomData_bmesh_interp(CustomData *data, void **src_blocks, float *weights, - float *sub_weights, int count, void *dest_block) + float *sub_weights, int count, void *dest_block) { int i, j; void *source_buf[SOURCE_BUF_SIZE]; @@ -2497,7 +2496,7 @@ void CustomData_bmesh_interp(CustomData *data, void **src_blocks, float *weights */ if (count > SOURCE_BUF_SIZE) sources = MEM_callocN(sizeof(*sources) * count, - "CustomData_interp sources"); + "CustomData_interp sources"); /* interpolates a layer at a time */ for (i = 0; i < data->totlayer; ++i) { @@ -2508,7 +2507,7 @@ void CustomData_bmesh_interp(CustomData *data, void **src_blocks, float *weights sources[j] = (char *)src_blocks[j] + layer->offset; typeInfo->interp(sources, weights, sub_weights, count, - (char *)dest_block + layer->offset); + (char *)dest_block + layer->offset); } } @@ -2529,13 +2528,13 @@ void CustomData_bmesh_set_default(CustomData *data, void **block) typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->set_default) - typeInfo->set_default((char*)*block + offset, 1); - else memset((char*)*block + offset, 0, typeInfo->size); + typeInfo->set_default((char *)*block + offset, 1); + else memset((char *)*block + offset, 0, typeInfo->size); } } void CustomData_to_bmesh_block(const CustomData *source, CustomData *dest, - int src_index, void **dest_block) + int src_index, void **dest_block) { const LayerTypeInfo *typeInfo; int dest_i, src_i, src_offset; @@ -2561,7 +2560,7 @@ void CustomData_to_bmesh_block(const CustomData *source, CustomData *dest, if (dest->layers[dest_i].type == source->layers[src_i].type) { int offset = dest->layers[dest_i].offset; char *src_data = source->layers[src_i].data; - char *dest_data = (char*)*dest_block + offset; + char *dest_data = (char *)*dest_block + offset; typeInfo = layerType_getInfo(dest->layers[dest_i].type); src_offset = src_index * typeInfo->size; @@ -2581,7 +2580,7 @@ void CustomData_to_bmesh_block(const CustomData *source, CustomData *dest, } void CustomData_from_bmesh_block(const CustomData *source, CustomData *dest, - void *src_block, int dest_index) + void *src_block, int dest_index) { const LayerTypeInfo *typeInfo; int dest_i, src_i, dest_offset; @@ -2603,7 +2602,7 @@ void CustomData_from_bmesh_block(const CustomData *source, CustomData *dest, /* if we found a matching layer, copy the data */ if (dest->layers[dest_i].type == source->layers[src_i].type) { int offset = source->layers[src_i].offset; - char *src_data = (char*)src_block + offset; + char *src_data = (char *)src_block + offset; char *dest_data = dest->layers[dest_i].data; typeInfo = layerType_getInfo(dest->layers[dest_i].type); @@ -2665,17 +2664,17 @@ static int cd_layer_find_dupe(CustomData *data, const char *name, int type, int { int i; /* see if there is a duplicate */ - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { if (i != index) { - CustomDataLayer *layer= &data->layers[i]; + CustomDataLayer *layer = &data->layers[i]; if (CustomData_is_property_layer(type)) { - if (CustomData_is_property_layer(layer->type) && strcmp(layer->name, name)==0) { + if (CustomData_is_property_layer(layer->type) && strcmp(layer->name, name) == 0) { return 1; } } else { - if (i!=index && layer->type==type && strcmp(layer->name, name)==0) { + if (i != index && layer->type == type && strcmp(layer->name, name) == 0) { return 1; } } @@ -2687,19 +2686,19 @@ static int cd_layer_find_dupe(CustomData *data, const char *name, int type, int static int customdata_unique_check(void *arg, const char *name) { - struct {CustomData *data; int type; int index;} *data_arg= arg; + struct {CustomData *data; int type; int index; } *data_arg = arg; return cd_layer_find_dupe(data_arg->data, name, data_arg->type, data_arg->index); } void CustomData_set_layer_unique_name(CustomData *data, int index) { - CustomDataLayer *nlayer= &data->layers[index]; - const LayerTypeInfo *typeInfo= layerType_getInfo(nlayer->type); + CustomDataLayer *nlayer = &data->layers[index]; + const LayerTypeInfo *typeInfo = layerType_getInfo(nlayer->type); - struct {CustomData *data; int type; int index;} data_arg; - data_arg.data= data; - data_arg.type= nlayer->type; - data_arg.index= index; + struct {CustomData *data; int type; int index; } data_arg; + data_arg.data = data; + data_arg.type = nlayer->type; + data_arg.index = index; if (!typeInfo->defaultname) return; @@ -2739,15 +2738,15 @@ int CustomData_verify_versions(struct CustomData *data, int index) typeInfo = layerType_getInfo(layer->type); if (!typeInfo->defaultname && (index > 0) && - data->layers[index-1].type == layer->type) + data->layers[index - 1].type == layer->type) { keeplayer = 0; /* multiple layers of which we only support one */ } } if (!keeplayer) { - for (i=index+1; i < data->totlayer; ++i) - data->layers[i-1] = data->layers[i]; + for (i = index + 1; i < data->totlayer; ++i) + data->layers[i - 1] = data->layers[i]; data->totlayer--; } @@ -2768,11 +2767,11 @@ void CustomData_external_reload(CustomData *data, ID *UNUSED(id), CustomDataMask const LayerTypeInfo *typeInfo; int i; - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); - if (!(mask & CD_TYPE_AS_MASK(layer->type))); + if (!(mask & CD_TYPE_AS_MASK(layer->type))) ; else if ((layer->flag & CD_FLAG_EXTERNAL) && (layer->flag & CD_FLAG_IN_MEMORY)) { if (typeInfo->free) typeInfo->free(layer->data, totelem, typeInfo->size); @@ -2783,7 +2782,7 @@ void CustomData_external_reload(CustomData *data, ID *UNUSED(id), CustomDataMask void CustomData_external_read(CustomData *data, ID *id, CustomDataMask mask, int totelem) { - CustomDataExternal *external= data->external; + CustomDataExternal *external = data->external; CustomDataLayer *layer; CDataFile *cdf; CDataFileLayer *blay; @@ -2794,14 +2793,14 @@ void CustomData_external_read(CustomData *data, ID *id, CustomDataMask mask, int if (!external) return; - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); - if (!(mask & CD_TYPE_AS_MASK(layer->type))); - else if (layer->flag & CD_FLAG_IN_MEMORY); + if (!(mask & CD_TYPE_AS_MASK(layer->type))) ; + else if (layer->flag & CD_FLAG_IN_MEMORY) ; else if ((layer->flag & CD_FLAG_EXTERNAL) && typeInfo->read) - update= 1; + update = 1; } if (!update) @@ -2809,24 +2808,24 @@ void CustomData_external_read(CustomData *data, ID *id, CustomDataMask mask, int customdata_external_filename(filename, id, external); - cdf= cdf_create(CDF_TYPE_MESH); + cdf = cdf_create(CDF_TYPE_MESH); if (!cdf_read_open(cdf, filename)) { fprintf(stderr, "Failed to read %s layer from %s.\n", layerType_getName(layer->type), filename); return; } - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); - if (!(mask & CD_TYPE_AS_MASK(layer->type))); - else if (layer->flag & CD_FLAG_IN_MEMORY); + if (!(mask & CD_TYPE_AS_MASK(layer->type))) ; + else if (layer->flag & CD_FLAG_IN_MEMORY) ; else if ((layer->flag & CD_FLAG_EXTERNAL) && typeInfo->read) { - blay= cdf_layer_find(cdf, layer->type, layer->name); + blay = cdf_layer_find(cdf, layer->type, layer->name); if (blay) { if (cdf_read_layer(cdf, blay)) { - if (typeInfo->read(cdf, layer->data, totelem)); + if (typeInfo->read(cdf, layer->data, totelem)) ; else break; layer->flag |= CD_FLAG_IN_MEMORY; } @@ -2842,7 +2841,7 @@ void CustomData_external_read(CustomData *data, ID *id, CustomDataMask mask, int void CustomData_external_write(CustomData *data, ID *id, CustomDataMask mask, int totelem, int free) { - CustomDataExternal *external= data->external; + CustomDataExternal *external = data->external; CustomDataLayer *layer; CDataFile *cdf; CDataFileLayer *blay; @@ -2854,13 +2853,13 @@ void CustomData_external_write(CustomData *data, ID *id, CustomDataMask mask, in return; /* test if there is anything to write */ - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); - if (!(mask & CD_TYPE_AS_MASK(layer->type))); + if (!(mask & CD_TYPE_AS_MASK(layer->type))) ; else if ((layer->flag & CD_FLAG_EXTERNAL) && typeInfo->write) - update= 1; + update = 1; } if (!update) @@ -2870,16 +2869,16 @@ void CustomData_external_write(CustomData *data, ID *id, CustomDataMask mask, in CustomData_external_read(data, id, mask, totelem); customdata_external_filename(filename, id, external); - cdf= cdf_create(CDF_TYPE_MESH); + cdf = cdf_create(CDF_TYPE_MESH); - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); if ((layer->flag & CD_FLAG_EXTERNAL) && typeInfo->filesize) { if (layer->flag & CD_FLAG_IN_MEMORY) { cdf_layer_add(cdf, layer->type, layer->name, - typeInfo->filesize(cdf, layer->data, totelem)); + typeInfo->filesize(cdf, layer->data, totelem)); } else { cdf_free(cdf); @@ -2893,15 +2892,15 @@ void CustomData_external_write(CustomData *data, ID *id, CustomDataMask mask, in return; } - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); if ((layer->flag & CD_FLAG_EXTERNAL) && typeInfo->write) { - blay= cdf_layer_find(cdf, layer->type, layer->name); + blay = cdf_layer_find(cdf, layer->type, layer->name); if (cdf_write_layer(cdf, blay)) { - if (typeInfo->write(cdf, layer->data, totelem)); + if (typeInfo->write(cdf, layer->data, totelem)) ; else break; } else @@ -2915,7 +2914,7 @@ void CustomData_external_write(CustomData *data, ID *id, CustomDataMask mask, in return; } - for (i=0; i<data->totlayer; i++) { + for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -2934,7 +2933,7 @@ void CustomData_external_write(CustomData *data, ID *id, CustomDataMask mask, in void CustomData_external_add(CustomData *data, ID *UNUSED(id), int type, int UNUSED(totelem), const char *filename) { - CustomDataExternal *external= data->external; + CustomDataExternal *external = data->external; CustomDataLayer *layer; int layer_index; @@ -2947,17 +2946,17 @@ void CustomData_external_add(CustomData *data, ID *UNUSED(id), int type, int UNU return; if (!external) { - external= MEM_callocN(sizeof(CustomDataExternal), "CustomDataExternal"); - data->external= external; + external = MEM_callocN(sizeof(CustomDataExternal), "CustomDataExternal"); + data->external = external; } BLI_strncpy(external->filename, filename, sizeof(external->filename)); - layer->flag |= CD_FLAG_EXTERNAL|CD_FLAG_IN_MEMORY; + layer->flag |= CD_FLAG_EXTERNAL | CD_FLAG_IN_MEMORY; } void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem) { - CustomDataExternal *external= data->external; + CustomDataExternal *external = data->external; CustomDataLayer *layer; //char filename[FILE_MAX]; int layer_index; // i, remove_file; @@ -2977,10 +2976,10 @@ void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem) layer->flag &= ~CD_FLAG_EXTERNAL; #if 0 - remove_file= 1; - for (i=0; i<data->totlayer; i++) + remove_file = 1; + for (i = 0; i < data->totlayer; i++) if (data->layers[i].flag & CD_FLAG_EXTERNAL) - remove_file= 0; + remove_file = 0; if (remove_file) { customdata_external_filename(filename, id, external); @@ -3006,7 +3005,7 @@ int CustomData_external_test(CustomData *data, int type) #if 0 void CustomData_external_remove_object(CustomData *data, ID *id) { - CustomDataExternal *external= data->external; + CustomDataExternal *external = data->external; char filename[FILE_MAX]; if (!external) diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c index 6d0dabede47..71801c4729f 100644 --- a/source/blender/blenkernel/intern/customdata_file.c +++ b/source/blender/blenkernel/intern/customdata_file.c @@ -39,47 +39,47 @@ /************************* File Format Definitions ***************************/ -#define CDF_ENDIAN_LITTLE 0 -#define CDF_ENDIAN_BIG 1 +#define CDF_ENDIAN_LITTLE 0 +#define CDF_ENDIAN_BIG 1 -#define CDF_DATA_FLOAT 0 +#define CDF_DATA_FLOAT 0 typedef struct CDataFileHeader { - char ID[4]; /* "BCDF" */ - char endian; /* little, big */ - char version; /* non-compatible versions */ - char subversion; /* compatible sub versions */ - char pad; /* padding */ - - int structbytes; /* size of this struct in bytes */ - int type; /* image, mesh */ - int totlayer; /* number of layers in the file */ + char ID[4]; /* "BCDF" */ + char endian; /* little, big */ + char version; /* non-compatible versions */ + char subversion; /* compatible sub versions */ + char pad; /* padding */ + + int structbytes; /* size of this struct in bytes */ + int type; /* image, mesh */ + int totlayer; /* number of layers in the file */ } CDataFileHeader; typedef struct CDataFileImageHeader { - int structbytes; /* size of this struct in bytes */ - int width; /* image width */ - int height; /* image height */ - int tile_size; /* tile size (required power of 2) */ + int structbytes; /* size of this struct in bytes */ + int width; /* image width */ + int height; /* image height */ + int tile_size; /* tile size (required power of 2) */ } CDataFileImageHeader; typedef struct CDataFileMeshHeader { - int structbytes; /* size of this struct in bytes */ + int structbytes; /* size of this struct in bytes */ } CDataFileMeshHeader; struct CDataFileLayer { - int structbytes; /* size of this struct in bytes */ - int datatype; /* only float for now */ - uint64_t datasize; /* size of data in layer */ - int type; /* layer type */ - char name[CDF_LAYER_NAME_MAX]; /* layer name */ + int structbytes; /* size of this struct in bytes */ + int datatype; /* only float for now */ + uint64_t datasize; /* size of data in layer */ + int type; /* layer type */ + char name[CDF_LAYER_NAME_MAX]; /* layer name */ }; /**************************** Other Definitions ******************************/ -#define CDF_VERSION 0 -#define CDF_SUBVERSION 0 -#define CDF_TILE_SIZE 64 +#define CDF_VERSION 0 +#define CDF_SUBVERSION 0 +#define CDF_TILE_SIZE 64 struct CDataFile { int type; @@ -121,9 +121,9 @@ static int cdf_data_type_size(int datatype) CDataFile *cdf_create(int type) { - CDataFile *cdf= MEM_callocN(sizeof(CDataFile), "CDataFile"); + CDataFile *cdf = MEM_callocN(sizeof(CDataFile), "CDataFile"); - cdf->type= type; + cdf->type = type; return cdf; } @@ -147,11 +147,11 @@ static int cdf_read_header(CDataFile *cdf) CDataFileImageHeader *image; CDataFileMeshHeader *mesh; CDataFileLayer *layer; - FILE *f= cdf->readf; + FILE *f = cdf->readf; size_t offset = 0; int a; - header= &cdf->header; + header = &cdf->header; if (!fread(header, sizeof(CDataFileHeader), 1, cdf->readf)) return 0; @@ -161,8 +161,8 @@ static int cdf_read_header(CDataFile *cdf) if (header->version > CDF_VERSION) return 0; - cdf->switchendian= header->endian != cdf_endian(); - header->endian= cdf_endian(); + cdf->switchendian = header->endian != cdf_endian(); + header->endian = cdf_endian(); if (cdf->switchendian) { SWITCH_INT(header->type); @@ -174,13 +174,13 @@ static int cdf_read_header(CDataFile *cdf) return 0; offset += header->structbytes; - header->structbytes= sizeof(CDataFileHeader); + header->structbytes = sizeof(CDataFileHeader); if (fseek(f, offset, SEEK_SET) != 0) return 0; if (header->type == CDF_TYPE_IMAGE) { - image= &cdf->btype.image; + image = &cdf->btype.image; if (!fread(image, sizeof(CDataFileImageHeader), 1, f)) return 0; @@ -192,10 +192,10 @@ static int cdf_read_header(CDataFile *cdf) } offset += image->structbytes; - image->structbytes= sizeof(CDataFileImageHeader); + image->structbytes = sizeof(CDataFileImageHeader); } else if (header->type == CDF_TYPE_MESH) { - mesh= &cdf->btype.mesh; + mesh = &cdf->btype.mesh; if (!fread(mesh, sizeof(CDataFileMeshHeader), 1, f)) return 0; @@ -203,17 +203,17 @@ static int cdf_read_header(CDataFile *cdf) SWITCH_INT(mesh->structbytes); offset += mesh->structbytes; - mesh->structbytes= sizeof(CDataFileMeshHeader); + mesh->structbytes = sizeof(CDataFileMeshHeader); } if (fseek(f, offset, SEEK_SET) != 0) return 0; - cdf->layer= MEM_callocN(sizeof(CDataFileLayer)*header->totlayer, "CDataFileLayer"); - cdf->totlayer= header->totlayer; + cdf->layer = MEM_callocN(sizeof(CDataFileLayer) * header->totlayer, "CDataFileLayer"); + cdf->totlayer = header->totlayer; - for (a=0; a<header->totlayer; a++) { - layer= &cdf->layer[a]; + for (a = 0; a < header->totlayer; a++) { + layer = &cdf->layer[a]; if (!fread(layer, sizeof(CDataFileLayer), 1, f)) return 0; @@ -229,13 +229,13 @@ static int cdf_read_header(CDataFile *cdf) return 0; offset += layer->structbytes; - layer->structbytes= sizeof(CDataFileLayer); + layer->structbytes = sizeof(CDataFileLayer); if (fseek(f, offset, SEEK_SET) != 0) return 0; } - cdf->dataoffset= offset; + cdf->dataoffset = offset; return 1; } @@ -246,27 +246,27 @@ static int cdf_write_header(CDataFile *cdf) CDataFileImageHeader *image; CDataFileMeshHeader *mesh; CDataFileLayer *layer; - FILE *f= cdf->writef; + FILE *f = cdf->writef; int a; - header= &cdf->header; + header = &cdf->header; if (!fwrite(header, sizeof(CDataFileHeader), 1, f)) return 0; if (header->type == CDF_TYPE_IMAGE) { - image= &cdf->btype.image; + image = &cdf->btype.image; if (!fwrite(image, sizeof(CDataFileImageHeader), 1, f)) return 0; } else if (header->type == CDF_TYPE_MESH) { - mesh= &cdf->btype.mesh; + mesh = &cdf->btype.mesh; if (!fwrite(mesh, sizeof(CDataFileMeshHeader), 1, f)) return 0; } - for (a=0; a<header->totlayer; a++) { - layer= &cdf->layer[a]; + for (a = 0; a < header->totlayer; a++) { + layer = &cdf->layer[a]; if (!fwrite(layer, sizeof(CDataFileLayer), 1, f)) return 0; @@ -279,11 +279,11 @@ int cdf_read_open(CDataFile *cdf, const char *filename) { FILE *f; - f= BLI_fopen(filename, "rb"); + f = BLI_fopen(filename, "rb"); if (!f) return 0; - cdf->readf= f; + cdf->readf = f; if (!cdf_read_header(cdf)) { cdf_read_close(cdf); @@ -304,8 +304,8 @@ int cdf_read_layer(CDataFile *cdf, CDataFileLayer *blay) int a; /* seek to right location in file */ - offset= cdf->dataoffset; - for (a=0; a<cdf->totlayer; a++) { + offset = cdf->dataoffset; + for (a = 0; a < cdf->totlayer; a++) { if (&cdf->layer[a] == blay) break; else @@ -326,9 +326,9 @@ int cdf_read_data(CDataFile *cdf, unsigned int size, void *data) /* switch endian if necessary */ if (cdf->switchendian) { - fdata= data; + fdata = data; - for (a=0; a<size/sizeof(float); a++) { + for (a = 0; a < size / sizeof(float); a++) { SWITCH_INT(fdata[a]); } } @@ -340,7 +340,7 @@ void cdf_read_close(CDataFile *cdf) { if (cdf->readf) { fclose(cdf->readf); - cdf->readf= NULL; + cdf->readf = NULL; } } @@ -351,34 +351,34 @@ int cdf_write_open(CDataFile *cdf, const char *filename) CDataFileMeshHeader *mesh; FILE *f; - f= BLI_fopen(filename, "wb"); + f = BLI_fopen(filename, "wb"); if (!f) return 0; - cdf->writef= f; + cdf->writef = f; /* fill header */ - header= &cdf->header; + header = &cdf->header; /* strcpy(, "BCDF"); // terminator out of range */ - header->ID[0]= 'B'; header->ID[1]= 'C'; header->ID[2]= 'D'; header->ID[3]= 'F'; - header->endian= cdf_endian(); - header->version= CDF_VERSION; - header->subversion= CDF_SUBVERSION; + header->ID[0] = 'B'; header->ID[1] = 'C'; header->ID[2] = 'D'; header->ID[3] = 'F'; + header->endian = cdf_endian(); + header->version = CDF_VERSION; + header->subversion = CDF_SUBVERSION; - header->structbytes= sizeof(CDataFileHeader); - header->type= cdf->type; - header->totlayer= cdf->totlayer; + header->structbytes = sizeof(CDataFileHeader); + header->type = cdf->type; + header->totlayer = cdf->totlayer; if (cdf->type == CDF_TYPE_IMAGE) { /* fill image header */ - image= &cdf->btype.image; - image->structbytes= sizeof(CDataFileImageHeader); - image->tile_size= CDF_TILE_SIZE; + image = &cdf->btype.image; + image->structbytes = sizeof(CDataFileImageHeader); + image->tile_size = CDF_TILE_SIZE; } else if (cdf->type == CDF_TYPE_MESH) { /* fill mesh header */ - mesh= &cdf->btype.mesh; - mesh->structbytes= sizeof(CDataFileMeshHeader); + mesh = &cdf->btype.mesh; + mesh->structbytes = sizeof(CDataFileMeshHeader); } cdf_write_header(cdf); @@ -404,7 +404,7 @@ void cdf_write_close(CDataFile *cdf) { if (cdf->writef) { fclose(cdf->writef); - cdf->writef= NULL; + cdf->writef = NULL; } } @@ -420,8 +420,8 @@ CDataFileLayer *cdf_layer_find(CDataFile *cdf, int type, const char *name) CDataFileLayer *layer; int a; - for (a=0; a<cdf->totlayer; a++) { - layer= &cdf->layer[a]; + for (a = 0; a < cdf->totlayer; a++) { + layer = &cdf->layer[a]; if (layer->type == type && strcmp(layer->name, name) == 0) return layer; @@ -435,18 +435,18 @@ CDataFileLayer *cdf_layer_add(CDataFile *cdf, int type, const char *name, size_t CDataFileLayer *newlayer, *layer; /* expand array */ - newlayer= MEM_callocN(sizeof(CDataFileLayer)*(cdf->totlayer+1), "CDataFileLayer"); - memcpy(newlayer, cdf->layer, sizeof(CDataFileLayer)*cdf->totlayer); - cdf->layer= newlayer; + newlayer = MEM_callocN(sizeof(CDataFileLayer) * (cdf->totlayer + 1), "CDataFileLayer"); + memcpy(newlayer, cdf->layer, sizeof(CDataFileLayer) * cdf->totlayer); + cdf->layer = newlayer; cdf->totlayer++; /* fill in new layer */ - layer= &cdf->layer[cdf->totlayer-1]; - layer->structbytes= sizeof(CDataFileLayer); - layer->datatype= CDF_DATA_FLOAT; - layer->datasize= datasize; - layer->type= type; + layer = &cdf->layer[cdf->totlayer - 1]; + layer->structbytes = sizeof(CDataFileLayer); + layer->datatype = CDF_DATA_FLOAT; + layer->datasize = datasize; + layer->type = type; BLI_strncpy(layer->name, name, CDF_LAYER_NAME_MAX); return layer; diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index ebf5735c1cd..0396733760f 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -251,7 +251,7 @@ void defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_le MDeformWeight *dw; int i; - for (dw = dvert->dw, i = 0; i<dvert->totweight; dw++, i++) { + for (dw = dvert->dw, i = 0; i < dvert->totweight; dw++, i++) { if (dw->def_nr < flip_map_len) { if (flip_map[dw->def_nr] >= 0) { dw->def_nr = flip_map[dw->def_nr]; @@ -424,13 +424,13 @@ static int defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *o static int defgroup_unique_check(void *arg, const char *name) { - struct {Object *ob; void *dg;} *data = arg; + struct {Object *ob; void *dg; } *data = arg; return defgroup_find_name_dupe(name, data->dg, data->ob); } void defgroup_unique_name(bDeformGroup *dg, Object *ob) { - struct {Object *ob; void *dg;} data; + struct {Object *ob; void *dg; } data; data.ob = ob; data.dg = dg; @@ -595,7 +595,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ } } - BLI_snprintf (name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number); + BLI_snprintf(name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number); } float defvert_find_weight(const struct MDeformVert *dvert, const int defgroup) @@ -710,7 +710,7 @@ void defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw) if (dvert->totweight) { dw_new = MEM_mallocN(sizeof(MDeformWeight) * (dvert->totweight), __func__); if (dvert->dw) { -#if 1 /* since we don't care about order, swap this with the last, save a memcpy */ +#if 1 /* since we don't care about order, swap this with the last, save a memcpy */ if (i != dvert->totweight) { dvert->dw[i] = dvert->dw[dvert->totweight]; } diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index fc54ea6eed5..e44264c8d4b 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -718,7 +718,8 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation"); } -struct DagForest *build_dag(Main *bmain, Scene *sce, short mask){ +DagForest *build_dag(Main *bmain, Scene *sce, short mask) +{ Base *base; Object *ob; Group *group; @@ -867,7 +868,7 @@ DagNode *dag_add_node(DagForest *forest, void *fob) } if (!forest->nodeHash) - forest->nodeHash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "dag_add_node gh"); + forest->nodeHash = BLI_ghash_ptr_new("dag_add_node gh"); BLI_ghash_insert(forest->nodeHash, fob, node); } @@ -1253,7 +1254,7 @@ DagNodeQueue *graph_dfs(void) int maxpos = 0; /* int is_cycle = 0; */ /* UNUSED */ /* - *fprintf(stderr, "starting DFS\n ------------\n"); + *fprintf(stderr, "starting DFS\n ------------\n"); */ nqueue = queue_create(DAGQUEUEALLOC); retqueue = queue_create(MainDag->numNodes); @@ -1458,7 +1459,8 @@ int pre_and_post_source_DFS(DagForest *dag, short mask, DagNode *source, graph_a // used to get the obs owning a datablock -struct DagNodeQueue *get_obparents(struct DagForest *dag, void *ob){ +DagNodeQueue *get_obparents(struct DagForest *dag, void *ob) +{ DagNode *node, *node1; DagNodeQueue *nqueue; DagAdjList *itA; @@ -1491,7 +1493,8 @@ struct DagNodeQueue *get_obparents(struct DagForest *dag, void *ob){ return nqueue; } -struct DagNodeQueue *get_first_ancestors(struct DagForest *dag, void *ob){ +DagNodeQueue *get_first_ancestors(struct DagForest *dag, void *ob) +{ DagNode *node, *node1; DagNodeQueue *nqueue; DagAdjList *itA; @@ -1519,7 +1522,8 @@ struct DagNodeQueue *get_first_ancestors(struct DagForest *dag, void *ob){ } // standard DFS list -struct DagNodeQueue *get_all_childs(struct DagForest *dag, void *ob){ +DagNodeQueue *get_all_childs(struct DagForest *dag, void *ob) +{ DagNode *node; DagNodeQueue *nqueue; DagNodeQueue *retqueue; @@ -2385,7 +2389,7 @@ static void dag_current_scene_layers(Main *bmain, Scene **sce, unsigned int *lay /* if we have a windowmanager, look into windows */ for (win = wm->windows.first; win; win = win->next) { if (win->screen) { - if (!*sce) *sce = win->screen->scene; + if (*sce == NULL) *sce = win->screen->scene; *lay |= BKE_screen_visible_layers(win->screen, win->screen->scene); } } diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 0154a2fa1e5..9274d7aefcb 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -425,8 +425,8 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, i void BKE_displist_fill(ListBase *dispbase, ListBase *to, int flipnormal) { ScanFillContext sf_ctx; - ScanFillVert *eve, *v1, *vlast; - ScanFillFace *efa; + ScanFillVert *sf_vert, *sf_vert_new, *sf_vert_last; + ScanFillFace *sf_tri; DispList *dlnew = NULL, *dl; float *f1; int colnr = 0, charidx = 0, cont = 1, tot, a, *index, nextcol = 0; @@ -454,24 +454,24 @@ void BKE_displist_fill(ListBase *dispbase, ListBase *to, int flipnormal) /* make editverts and edges */ f1 = dl->verts; a = dl->nr; - eve = v1 = NULL; + sf_vert = sf_vert_new = NULL; while (a--) { - vlast = eve; + sf_vert_last = sf_vert; - eve = BLI_scanfill_vert_add(&sf_ctx, f1); + sf_vert = BLI_scanfill_vert_add(&sf_ctx, f1); totvert++; - if (vlast == NULL) - v1 = eve; + if (sf_vert_last == NULL) + sf_vert_new = sf_vert; else { - BLI_scanfill_edge_add(&sf_ctx, vlast, eve); + BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert); } f1 += 3; } - if (eve != NULL && v1 != NULL) { - BLI_scanfill_edge_add(&sf_ctx, eve, v1); + if (sf_vert != NULL && sf_vert_new != NULL) { + BLI_scanfill_edge_add(&sf_ctx, sf_vert, sf_vert_new); } } else if (colnr < dl->col) { @@ -499,31 +499,31 @@ void BKE_displist_fill(ListBase *dispbase, ListBase *to, int flipnormal) /* vert data */ f1 = dlnew->verts; totvert = 0; - eve = sf_ctx.fillvertbase.first; - while (eve) { - copy_v3_v3(f1, eve->co); + sf_vert = sf_ctx.fillvertbase.first; + while (sf_vert) { + copy_v3_v3(f1, sf_vert->co); f1 += 3; /* index number */ - eve->tmp.l = totvert; + sf_vert->tmp.l = totvert; totvert++; - eve = eve->next; + sf_vert = sf_vert->next; } /* index data */ - efa = sf_ctx.fillfacebase.first; + sf_tri = sf_ctx.fillfacebase.first; index = dlnew->index; - while (efa) { - index[0] = (intptr_t)efa->v1->tmp.l; - index[1] = (intptr_t)efa->v2->tmp.l; - index[2] = (intptr_t)efa->v3->tmp.l; + while (sf_tri) { + index[0] = (intptr_t)sf_tri->v1->tmp.l; + index[1] = (intptr_t)sf_tri->v2->tmp.l; + index[2] = (intptr_t)sf_tri->v3->tmp.l; if (flipnormal) SWAP(int, index[0], index[2]); index += 3; - efa = efa->next; + sf_tri = sf_tri->next; } } @@ -752,7 +752,7 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, fl Curve *cu = ob->data; ListBase *nurb = BKE_curve_nurbs_get(cu); int numVerts = 0; - const int editmode = (!forRender && cu->editnurb); + const int editmode = (!forRender && (cu->editnurb || cu->editfont)); ModifierApplyFlag app_flag = 0; float (*originalVerts)[3] = NULL; float (*deformedVerts)[3] = NULL; @@ -793,9 +793,7 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, fl md->scene = scene; - if ((md->mode & required_mode) != required_mode) - continue; - if (mti->isDisabled && mti->isDisabled(md, forRender)) + if (!modifier_isEnabled(scene, md, required_mode)) continue; if (mti->type != eModifierTypeType_OnlyDeform) continue; @@ -867,7 +865,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba Curve *cu = ob->data; ListBase *nurb = BKE_curve_nurbs_get(cu); int required_mode = 0, totvert = 0; - int editmode = (!forRender && cu->editnurb); + int editmode = (!forRender && (cu->editnurb || cu->editfont)); DerivedMesh *dm = NULL, *ndm; float (*vertCos)[3] = NULL; int useCache = !forRender; @@ -899,9 +897,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba md->scene = scene; - if ((md->mode & required_mode) != required_mode) - continue; - if (mti->isDisabled && mti->isDisabled(md, forRender)) + if (!modifier_isEnabled(scene, md, required_mode)) continue; if (mti->type == eModifierTypeType_OnlyDeform || @@ -1095,7 +1091,7 @@ static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *derivedFina ModifierData *pretessellatePoint; Curve *cu = ob->data; int required_mode; - int editmode = (!forRender && cu->editnurb); + int editmode = (!forRender && (cu->editnurb || cu->editfont)); DerivedMesh *ndm, *orcodm = NULL; const ModifierApplyFlag app_flag = forRender ? MOD_APPLY_RENDER : 0; @@ -1118,9 +1114,7 @@ static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *derivedFina md->scene = scene; - if ((md->mode & required_mode) != required_mode) - continue; - if (mti->isDisabled && mti->isDisabled(md, forRender)) + if (!modifier_isEnabled(scene, md, required_mode)) continue; if (mti->type != eModifierTypeType_Constructive) continue; @@ -1606,19 +1600,13 @@ static void boundbox_displist(Object *ob) if (cu->bb == NULL) cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); bb = cu->bb; - dl = ob->disp.first; - - while (dl) { - if (dl->type == DL_INDEX3) tot = dl->nr; - else tot = dl->nr * dl->parts; - + for (dl = ob->disp.first; dl; dl = dl->next) { + tot = (dl->type == DL_INDEX3) ? dl->nr : dl->nr * dl->parts; vert = dl->verts; for (a = 0; a < tot; a++, vert += 3) { - doit = 1; - DO_MINMAX(vert, min, max); + minmax_v3v3_v3(min, max, vert); } - - dl = dl->next; + doit = (tot != 0); } if (!doit) { diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 2bde31cfd63..b3ed3dcaf1d 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -46,7 +46,7 @@ #include "DNA_texture_types.h" #include "BKE_animsys.h" -#include "BKE_bvhutils.h" /* bvh tree */ +#include "BKE_bvhutils.h" /* bvh tree */ #include "BKE_blender.h" #include "BKE_cdderivedmesh.h" #include "BKE_constraint.h" @@ -86,11 +86,11 @@ #endif /* precalculated gaussian factors for 5x super sampling */ -static float gaussianFactors[5] = { 0.996849f, - 0.596145f, - 0.596145f, - 0.596145f, - 0.524141f}; +static float gaussianFactors[5] = {0.996849f, + 0.596145f, + 0.596145f, + 0.596145f, + 0.524141f}; static float gaussianTotal = 3.309425f; /* UV Image neighboring pixel table x and y list */ @@ -98,11 +98,11 @@ static int neighX[8] = {1, 1, 0, -1, -1, -1, 0, 1}; static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1}; /* subframe_updateObject() flags */ -#define UPDATE_PARENTS (1<<0) -#define UPDATE_MESH (1<<1) -#define UPDATE_EVERYTHING (UPDATE_PARENTS|UPDATE_MESH) +#define UPDATE_PARENTS (1 << 0) +#define UPDATE_MESH (1 << 1) +#define UPDATE_EVERYTHING (UPDATE_PARENTS | UPDATE_MESH) /* surface_getBrushFlags() return vals */ -#define BRUSH_USES_VELOCITY (1<<0) +#define BRUSH_USES_VELOCITY (1 << 0) /* brush mesh raycast status */ #define HIT_VOLUME 1 #define HIT_PROXIMITY 2 @@ -113,13 +113,13 @@ static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1}; /* paint effect default movement per frame in global units */ #define EFF_MOVEMENT_PER_FRAME 0.05f /* initial wave time factor */ -#define WAVE_TIME_FAC (1.0f/24.f) +#define WAVE_TIME_FAC (1.0f / 24.f) #define CANVAS_REL_SIZE 5.0f /* drying limits */ #define MIN_WETNESS 0.001f #define MAX_WETNESS 5.0f /* dissolve macro */ -#define VALUE_DISSOLVE(VALUE, TIME, SCALE, LOG) (VALUE) = (LOG) ? (VALUE) * (pow(MIN_WETNESS, 1.0f/(1.2f*((float)(TIME))/(SCALE)))) : (VALUE) - 1.0f/(TIME)*(SCALE) +#define VALUE_DISSOLVE(VALUE, TIME, SCALE, LOG) (VALUE) = (LOG) ? (VALUE) *(pow(MIN_WETNESS, 1.0f / (1.2f * ((float)(TIME)) / (SCALE)))) : (VALUE) -1.0f / (TIME)*(SCALE) /***************************** Internal Structs ***************************/ @@ -136,11 +136,11 @@ typedef struct VolumeGrid { int dim[3]; Bounds3D grid_bounds; /* whole grid bounds */ - Bounds3D *bounds; /* (x*y*z) precalculated grid cell bounds */ + Bounds3D *bounds; /* (x*y*z) precalculated grid cell bounds */ int *s_pos; /* (x*y*z) t_index begin id */ int *s_num; /* (x*y*z) number of t_index points */ int *t_index; /* actual surface point index, - access: (s_pos+s_num) */ + * access: (s_pos+s_num) */ } VolumeGrid; typedef struct Vec3f { @@ -148,8 +148,8 @@ typedef struct Vec3f { } Vec3f; typedef struct BakeAdjPoint { - float dir[3]; /* vector pointing towards this neighbor */ - float dist; /* distance to */ + float dir[3]; /* vector pointing towards this neighbor */ + float dist; /* distance to */ } BakeAdjPoint; /* Surface data used while processing a frame */ @@ -162,8 +162,8 @@ typedef struct PaintBakeNormal { typedef struct PaintBakeData { /* point space data */ PaintBakeNormal *bNormal; - int *s_pos; /* index to start reading point sample realCoord */ - int *s_num; /* num of realCoord samples */ + int *s_pos; /* index to start reading point sample realCoord */ + int *s_num; /* num of realCoord samples */ Vec3f *realCoord; /* current pixel center world-space coordinates for each sample * ordered as (s_pos+s_num)*/ Bounds3D mesh_bounds; @@ -172,44 +172,44 @@ typedef struct PaintBakeData { BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */ double average_dist; /* space partitioning */ - VolumeGrid *grid; /* space partitioning grid to optimize brush checks */ + VolumeGrid *grid; /* space partitioning grid to optimize brush checks */ /* velocity and movement */ - Vec3f *velocity; /* speed vector in global space movement per frame, if required */ + Vec3f *velocity; /* speed vector in global space movement per frame, if required */ Vec3f *prev_velocity; - float *brush_velocity; /* special temp data for post-p velocity based brushes like smudge - * 3 float dir vec + 1 float str */ - MVert *prev_verts; /* copy of previous frame vertices. used to observe surface movement */ + float *brush_velocity; /* special temp data for post-p velocity based brushes like smudge + * 3 float dir vec + 1 float str */ + MVert *prev_verts; /* copy of previous frame vertices. used to observe surface movement */ float prev_obmat[4][4]; /* previous frame object matrix */ - int clear; /* flag to check if surface was cleared/reset -> have to redo velocity etc. */ + int clear; /* flag to check if surface was cleared/reset -> have to redo velocity etc. */ } PaintBakeData; /* UV Image sequence format point */ typedef struct PaintUVPoint { /* Pixel / mesh data */ - unsigned int face_index, pixel_index; /* face index on domain derived mesh */ - unsigned int v1, v2, v3; /* vertex indexes */ + unsigned int face_index, pixel_index; /* face index on domain derived mesh */ + unsigned int v1, v2, v3; /* vertex indexes */ - unsigned int neighbour_pixel; /* If this pixel isn't uv mapped to any face, - but it's neighboring pixel is */ + unsigned int neighbour_pixel; /* If this pixel isn't uv mapped to any face, + * but it's neighboring pixel is */ short quad; } PaintUVPoint; typedef struct ImgSeqFormatData { PaintUVPoint *uv_p; - Vec3f *barycentricWeights; /* b-weights for all pixel samples */ + Vec3f *barycentricWeights; /* b-weights for all pixel samples */ } ImgSeqFormatData; /* adjacency data flags */ -#define ADJ_ON_MESH_EDGE (1<<0) +#define ADJ_ON_MESH_EDGE (1 << 0) typedef struct PaintAdjData { - int *n_target; /* array of neighboring point indexes, - for single sample use (n_index+neigh_num) */ - int *n_index; /* index to start reading n_target for each point */ - int *n_num; /* num of neighs for each point */ - int *flags; /* vertex adjacency flags */ + int *n_target; /* array of neighboring point indexes, + * for single sample use (n_index + neigh_num) */ + int *n_index; /* index to start reading n_target for each point */ + int *n_num; /* num of neighs for each point */ + int *flags; /* vertex adjacency flags */ int total_targets; /* size of n_target */ } PaintAdjData; @@ -230,7 +230,7 @@ static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface) return 0; /* not supported atm */ } else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { - if (!surface->canvas->dm) return 0; /* invalid derived mesh */ + if (!surface->canvas->dm) return 0; /* invalid derived mesh */ return surface->canvas->dm->getNumVerts(surface->canvas->dm); } else @@ -259,12 +259,12 @@ int dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface) } /* get currently active surface (in user interface) */ -struct DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas) +DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas) { DynamicPaintSurface *surface = canvas->surfaces.first; int i; - for (i=0; surface; surface=surface->next) { + for (i = 0; surface; surface = surface->next) { if (i == canvas->active_sur) return surface; i++; @@ -276,12 +276,12 @@ struct DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas void dynamicPaint_resetPreview(DynamicPaintCanvasSettings *canvas) { DynamicPaintSurface *surface = canvas->surfaces.first; - int done=0; + int done = 0; - for (; surface; surface=surface->next) { + for (; surface; surface = surface->next) { if (!done && dynamicPaint_surfaceHasColorPreview(surface)) { surface->flags |= MOD_DPAINT_PREVIEW; - done=1; + done = 1; } else surface->flags &= ~MOD_DPAINT_PREVIEW; @@ -292,7 +292,7 @@ void dynamicPaint_resetPreview(DynamicPaintCanvasSettings *canvas) static void dynamicPaint_setPreview(DynamicPaintSurface *t_surface) { DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; - for (; surface; surface=surface->next) { + for (; surface; surface = surface->next) { if (surface == t_surface) surface->flags |= MOD_DPAINT_PREVIEW; else @@ -325,14 +325,15 @@ int dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object * static int surface_duplicateOutputExists(void *arg, const char *name) { - DynamicPaintSurface *t_surface = (DynamicPaintSurface*)arg; + DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg; DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; - for (; surface; surface=surface->next) { - if (surface!=t_surface && surface->type==t_surface->type && - surface->format==t_surface->format) { - if (surface->output_name[0]!='\0' && !BLI_path_cmp(name, surface->output_name)) return 1; - if (surface->output_name2[0]!='\0' && !BLI_path_cmp(name, surface->output_name2)) return 1; + for (; surface; surface = surface->next) { + if (surface != t_surface && surface->type == t_surface->type && + surface->format == t_surface->format) + { + if (surface->output_name[0] != '\0' && !BLI_path_cmp(name, surface->output_name)) return 1; + if (surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2)) return 1; } } return 0; @@ -351,11 +352,11 @@ static void surface_setUniqueOutputName(DynamicPaintSurface *surface, char *base static int surface_duplicateNameExists(void *arg, const char *name) { - DynamicPaintSurface *t_surface = (DynamicPaintSurface*)arg; + DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg; DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; - for (; surface; surface=surface->next) { - if (surface!=t_surface && !strcmp(name, surface->name)) return 1; + for (; surface; surface = surface->next) { + if (surface != t_surface && !strcmp(name, surface->name)) return 1; } return 0; } @@ -372,8 +373,8 @@ void dynamicPaintSurface_setUniqueName(DynamicPaintSurface *surface, const char void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface) { if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - surface->output_name[0]='\0'; - surface->output_name2[0]='\0'; + surface->output_name[0] = '\0'; + surface->output_name2[0] = '\0'; surface->flags |= MOD_DPAINT_ANTIALIAS; surface->depth_clamp = 1.0f; } @@ -418,22 +419,22 @@ static int surface_totalSamples(DynamicPaintSurface *surface) if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && surface->flags & MOD_DPAINT_ANTIALIAS && surface->data->adj_data) { - return (surface->data->total_points+surface->data->adj_data->total_targets); + return (surface->data->total_points + surface->data->adj_data->total_targets); } return surface->data->total_points; } -static void blendColors(float t_color[3], float t_alpha, float s_color[3], float s_alpha, float result[4]) +static void blendColors(const float t_color[3], float t_alpha, const float s_color[3], float s_alpha, float result[4]) { int i; float i_alpha = 1.0f - s_alpha; - float f_alpha = t_alpha*i_alpha + s_alpha; + float f_alpha = t_alpha * i_alpha + s_alpha; /* blend colors */ if (f_alpha) { - for (i=0; i<3; i++) { - result[i] = (t_color[i]*t_alpha*i_alpha + s_color[i]*s_alpha)/f_alpha; + for (i = 0; i < 3; i++) { + result[i] = (t_color[i] * t_alpha * i_alpha + s_color[i] * s_alpha) / f_alpha; } } else { @@ -451,23 +452,23 @@ static float mixColors(float a_color[3], float a_weight, float b_color[3], float /* if first value has no weight just use b_color */ if (!a_weight) { copy_v3_v3(a_color, b_color); - return b_weight*ratio; + return b_weight * ratio; } - weight_ratio = b_weight/(a_weight+b_weight); + weight_ratio = b_weight / (a_weight + b_weight); } - else return a_weight*(1.0f-ratio); + else return a_weight * (1.0f - ratio); /* calculate final interpolation factor */ - if (ratio<=0.5f) { - factor = weight_ratio*(ratio*2.0f); + if (ratio <= 0.5f) { + factor = weight_ratio * (ratio * 2.0f); } else { - ratio = (ratio*2.0f - 1.0f); - factor = weight_ratio*(1.0f-ratio) + ratio; + ratio = (ratio * 2.0f - 1.0f); + factor = weight_ratio * (1.0f - ratio) + ratio; } /* mix final color */ interp_v3_v3v3(a_color, a_color, b_color, factor); - return (1.0f-factor)*a_weight + factor*b_weight; + return (1.0f - factor) * a_weight + factor * b_weight; } /* set "ignore cache" flag for all caches on this object */ @@ -477,7 +478,7 @@ static void object_cacheIgnoreClear(Object *ob, int state) PTCacheID *pid; BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); - for (pid=pidlist.first; pid; pid=pid->next) { + for (pid = pidlist.first; pid; pid = pid->next) { if (pid->cache) { if (state) pid->cache->flag |= PTCACHE_IGNORE_CLEAR; @@ -505,19 +506,19 @@ static int subframe_updateObject(Scene *scene, Object *ob, int flags, float fram if (ob->track) is_canvas += subframe_updateObject(scene, ob->track, 0, frame); /* skip subframe if object is parented - * to vertex of a dynamic paint canvas */ + * to vertex of a dynamic paint canvas */ if (is_canvas && (ob->partype == PARVERT1 || ob->partype == PARVERT3)) return 0; /* also update constraint targets */ - for (con = ob->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = ob->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; if (cti && cti->get_constraint_targets) { bConstraintTarget *ct; cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar) subframe_updateObject(scene, ct->tar, 0, frame); } @@ -528,8 +529,8 @@ static int subframe_updateObject(Scene *scene, Object *ob, int flags, float fram } } /* for curve following objects, parented curve has to be updated too */ - if (ob->type==OB_CURVE) { - Curve *cu= ob->data; + if (ob->type == OB_CURVE) { + Curve *cu = ob->data; BKE_animsys_evaluate_animdata(scene, &cu->id, cu->adt, frame, ADT_RECALC_ANIM); } @@ -538,7 +539,7 @@ static int subframe_updateObject(Scene *scene, Object *ob, int flags, float fram BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, frame, ADT_RECALC_ANIM); if (flags & UPDATE_MESH) { /* ignore cache clear during subframe updates - * to not mess up cache validity */ + * to not mess up cache validity */ object_cacheIgnoreClear(ob, 1); BKE_object_handle_update(scene, ob); object_cacheIgnoreClear(ob, 0); @@ -575,21 +576,21 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, Scene *scene) /* select object */ if (surface->brush_group) { - if (go->ob) brushObj = go->ob; + if (go->ob) brushObj = go->ob; } else brushObj = base->object; if (!brushObj) { if (surface->brush_group) go = go->next; - else base= base->next; + else base = base->next; continue; } if (surface->brush_group) go = go->next; else - base= base->next; + base = base->next; md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { @@ -615,9 +616,9 @@ static int brush_usesMaterial(DynamicPaintBrushSettings *brush, Scene *scene) /* check whether two bounds intersect */ static int boundsIntersect(Bounds3D *b1, Bounds3D *b2) { - int i=2; + int i = 2; if (!b1->valid || !b2->valid) return 0; - for (; i>=0; i-=1) + for (; i >= 0; i -= 1) if (!(b1->min[i] <= b2->max[i] && b1->max[i] >= b2->min[i])) return 0; return 1; } @@ -625,36 +626,36 @@ static int boundsIntersect(Bounds3D *b1, Bounds3D *b2) /* check whether two bounds intersect inside defined proximity */ static int boundsIntersectDist(Bounds3D *b1, Bounds3D *b2, float dist) { - int i=2; + int i = 2; if (!b1->valid || !b2->valid) return 0; - for (; i>=0; i-=1) - if (!(b1->min[i] <= (b2->max[i]+dist) && b1->max[i] >= (b2->min[i]-dist))) return 0; + for (; i >= 0; i -= 1) + if (!(b1->min[i] <= (b2->max[i] + dist) && b1->max[i] >= (b2->min[i] - dist))) return 0; return 1; } /* check whether bounds intersects a point with given radius */ static int boundIntersectPoint(Bounds3D *b, float point[3], float radius) { - int i=2; + int i = 2; if (!b->valid) return 0; - for (; i>=0; i-=1) - if (!(b->min[i] <= (point[i]+radius) && b->max[i] >= (point[i]-radius))) return 0; + for (; i >= 0; i -= 1) + if (!(b->min[i] <= (point[i] + radius) && b->max[i] >= (point[i] - radius))) return 0; return 1; } /* expand bounds by a new point */ static void boundInsert(Bounds3D *b, float point[3]) { - int i=2; + int i = 2; if (!b->valid) { copy_v3_v3(b->min, point); copy_v3_v3(b->max, point); b->valid = 1; } else { - for (; i>=0; i-=1) { - if (point[i] < b->min[i]) b->min[i]=point[i]; - if (point[i] > b->max[i]) b->max[i]=point[i]; + for (; i >= 0; i -= 1) { + if (point[i] < b->min[i]) b->min[i] = point[i]; + if (point[i] > b->max[i]) b->max[i] = point[i]; } } } @@ -662,7 +663,7 @@ static void boundInsert(Bounds3D *b, float point[3]) float getSurfaceDimension(PaintSurfaceData *sData) { Bounds3D *mb = &sData->bData->mesh_bounds; - return MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2])); + return MAX3((mb->max[0] - mb->min[0]), (mb->max[1] - mb->min[1]), (mb->max[2] - mb->min[2])); } static void freeGrid(PaintSurfaceData *data) @@ -699,7 +700,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) freeGrid(sData); /* allocate separate bounds for each thread */ - grid_bounds = MEM_callocN(sizeof(Bounds3D)*num_of_threads, "Grid Bounds"); + grid_bounds = MEM_callocN(sizeof(Bounds3D) * num_of_threads, "Grid Bounds"); bData->grid = MEM_callocN(sizeof(VolumeGrid), "Surface Grid"); grid = bData->grid; @@ -711,7 +712,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) /* calculate canvas dimensions */ #pragma omp parallel for schedule(static) - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { #ifdef _OPENMP int id = omp_get_thread_num(); boundInsert(&grid_bounds[id], (bData->realCoord[bData->s_pos[i]].v)); @@ -721,7 +722,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) } /* get final dimensions */ - for (i=0; i<num_of_threads; i++) { + for (i = 0; i < num_of_threads; i++) { boundInsert(&grid->grid_bounds, grid_bounds[i].min); boundInsert(&grid->grid_bounds, grid_bounds[i].max); } @@ -732,8 +733,8 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) min_dim = MAX3(td[0], td[1], td[2]) / 1000.f; /* deactivate zero axises */ - for (i=0; i<3; i++) { - if (td[i]<min_dim) {td[i]=1.0f; axis-=1;} + for (i = 0; i < 3; i++) { + if (td[i] < min_dim) {td[i] = 1.0f; axis -= 1; } } if (axis == 0 || MAX3(td[0], td[1], td[2]) < 0.0001f) { @@ -744,22 +745,22 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) } /* now calculate grid volume/area/width depending on num of active axis */ - volume = td[0]*td[1]*td[2]; + volume = td[0] * td[1] * td[2]; /* determine final grid size by trying to fit average 10.000 points per grid cell */ - dim_factor = (float)pow(volume / ((double)sData->total_points / 10000.0), 1.0/(double)axis); + dim_factor = (float)pow(volume / ((double)sData->total_points / 10000.0), 1.0 / (double)axis); /* define final grid size using dim_factor, use min 3 for active axises */ - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { grid->dim[i] = (int)floor(td[i] / dim_factor); - CLAMP(grid->dim[i], (dim[i]>=min_dim) ? 3 : 1, 100); + CLAMP(grid->dim[i], (dim[i] >= min_dim) ? 3 : 1, 100); } - grid_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; + grid_cells = grid->dim[0] * grid->dim[1] * grid->dim[2]; /* allocate memory for grids */ grid->bounds = MEM_callocN(sizeof(Bounds3D) * grid_cells, "Surface Grid Bounds"); grid->s_pos = MEM_callocN(sizeof(int) * grid_cells, "Surface Grid Position"); - grid->s_num = MEM_callocN(sizeof(int) * grid_cells*num_of_threads, "Surface Grid Points"); + grid->s_num = MEM_callocN(sizeof(int) * grid_cells * num_of_threads, "Surface Grid Points"); temp_s_num = MEM_callocN(sizeof(int) * grid_cells, "Temp Surface Grid Points"); grid->t_index = MEM_callocN(sizeof(int) * sData->total_points, "Surface Grid Target Ids"); temp_t_index = MEM_callocN(sizeof(int) * sData->total_points, "Temp Surface Grid Target Ids"); @@ -771,37 +772,37 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) if (!error) { /* calculate number of points withing each cell */ #pragma omp parallel for schedule(static) - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { int co[3], j; - for (j=0; j<3; j++) { - co[j] = (int)floor((bData->realCoord[bData->s_pos[i]].v[j] - grid->grid_bounds.min[j])/dim[j]*grid->dim[j]); - CLAMP(co[j], 0, grid->dim[j]-1); + for (j = 0; j < 3; j++) { + co[j] = (int)floor((bData->realCoord[bData->s_pos[i]].v[j] - grid->grid_bounds.min[j]) / dim[j] * grid->dim[j]); + CLAMP(co[j], 0, grid->dim[j] - 1); } - temp_t_index[i] = co[0] + co[1] * grid->dim[0] + co[2] * grid->dim[0]*grid->dim[1]; + temp_t_index[i] = co[0] + co[1] * grid->dim[0] + co[2] * grid->dim[0] * grid->dim[1]; #ifdef _OPENMP - grid->s_num[temp_t_index[i]+omp_get_thread_num()*grid_cells]++; + grid->s_num[temp_t_index[i] + omp_get_thread_num() * grid_cells]++; #else grid->s_num[temp_t_index[i]]++; #endif } /* for first cell only calc s_num */ - for (i=1; i<num_of_threads; i++) { - grid->s_num[0] += grid->s_num[i*grid_cells]; + for (i = 1; i < num_of_threads; i++) { + grid->s_num[0] += grid->s_num[i * grid_cells]; } /* calculate grid indexes */ - for (i=1; i<grid_cells; i++) { + for (i = 1; i < grid_cells; i++) { int id; - for (id=1; id<num_of_threads; id++) { - grid->s_num[i] += grid->s_num[i+id*grid_cells]; + for (id = 1; id < num_of_threads; id++) { + grid->s_num[i] += grid->s_num[i + id * grid_cells]; } - grid->s_pos[i] = grid->s_pos[i-1] + grid->s_num[i-1]; + grid->s_pos[i] = grid->s_pos[i - 1] + grid->s_num[i - 1]; } /* save point indexes to final array */ - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { int pos = grid->s_pos[temp_t_index[i]] + temp_s_num[temp_t_index[i]]; grid->t_index[pos] = i; @@ -812,17 +813,17 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) { int x; #pragma omp parallel for schedule(static) - for (x=0; x<grid->dim[0]; x++) { + for (x = 0; x < grid->dim[0]; x++) { int y; - for (y=0; y<grid->dim[1]; y++) { + for (y = 0; y < grid->dim[1]; y++) { int z; - for (z=0; z<grid->dim[2]; z++) { - int j, b_index = x + y * grid->dim[0] + z * grid->dim[0]*grid->dim[1]; + for (z = 0; z < grid->dim[2]; z++) { + int j, b_index = x + y * grid->dim[0] + z * grid->dim[0] * grid->dim[1]; /* set bounds */ - for (j=0; j<3; j++) { - int s = (j==0) ? x : ((j==1) ? y : z); - grid->bounds[b_index].min[j] = grid->grid_bounds.min[j] + dim[j]/grid->dim[j]*s; - grid->bounds[b_index].max[j] = grid->grid_bounds.min[j] + dim[j]/grid->dim[j]*(s+1); + for (j = 0; j < 3; j++) { + int s = (j == 0) ? x : ((j == 1) ? y : z); + grid->bounds[b_index].min[j] = grid->grid_bounds.min[j] + dim[j] / grid->dim[j] * s; + grid->bounds[b_index].max[j] = grid->grid_bounds.min[j] + dim[j] / grid->dim[j] * (s + 1); } grid->bounds[b_index].valid = 1; } @@ -857,10 +858,10 @@ void dynamicPaint_freeBrush(struct DynamicPaintModifierData *pmd) pmd->brush->dm = NULL; if (pmd->brush->paint_ramp) - MEM_freeN(pmd->brush->paint_ramp); + MEM_freeN(pmd->brush->paint_ramp); pmd->brush->paint_ramp = NULL; if (pmd->brush->vel_ramp) - MEM_freeN(pmd->brush->vel_ramp); + MEM_freeN(pmd->brush->vel_ramp); pmd->brush->vel_ramp = NULL; MEM_freeN(pmd->brush); @@ -919,7 +920,7 @@ void dynamicPaint_freeSurfaceData(DynamicPaintSurface *surface) if (data->format_data) { /* format specific free */ if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - ImgSeqFormatData *format_data = (ImgSeqFormatData*)data->format_data; + ImgSeqFormatData *format_data = (ImgSeqFormatData *)data->format_data; if (format_data->uv_p) MEM_freeN(format_data->uv_p); if (format_data->barycentricWeights) @@ -989,13 +990,13 @@ void dynamicPaint_Modifier_free(struct DynamicPaintModifierData *pmd) /***************************** Initialize and reset ******************************/ /* -* Creates a new surface and adds it to the list -* If scene is null, frame range of 1-250 is used -* A pointer to this surface is returned -*/ -struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSettings *canvas, Scene *scene) + * Creates a new surface and adds it to the list + * If scene is null, frame range of 1-250 is used + * A pointer to this surface is returned + */ +DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSettings *canvas, Scene *scene) { - DynamicPaintSurface *surface= MEM_callocN(sizeof(DynamicPaintSurface), "DynamicPaintSurface"); + DynamicPaintSurface *surface = MEM_callocN(sizeof(DynamicPaintSurface), "DynamicPaintSurface"); if (!surface) return NULL; surface->canvas = canvas; @@ -1009,7 +1010,7 @@ struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSett /* Set initial values */ surface->flags = MOD_DPAINT_ANTIALIAS | MOD_DPAINT_MULALPHA | MOD_DPAINT_DRY_LOG | MOD_DPAINT_DISSOLVE_LOG | - MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING; + MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING; surface->effect = 0; surface->effect_ui = 1; @@ -1064,8 +1065,8 @@ struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSett } /* -* Initialize modifier data -*/ + * Initialize modifier data + */ int dynamicPaint_createType(struct DynamicPaintModifierData *pmd, int type, struct Scene *scene) { if (pmd) { @@ -1212,16 +1213,16 @@ static void dynamicPaint_allocateSurfaceType(DynamicPaintSurface *surface) switch (surface->type) { case MOD_DPAINT_SURFACE_T_PAINT: - sData->type_data = MEM_callocN(sizeof(PaintPoint)*sData->total_points, "DynamicPaintSurface Data"); + sData->type_data = MEM_callocN(sizeof(PaintPoint) * sData->total_points, "DynamicPaintSurface Data"); break; case MOD_DPAINT_SURFACE_T_DISPLACE: - sData->type_data = MEM_callocN(sizeof(float)*sData->total_points, "DynamicPaintSurface DepthData"); + sData->type_data = MEM_callocN(sizeof(float) * sData->total_points, "DynamicPaintSurface DepthData"); break; case MOD_DPAINT_SURFACE_T_WEIGHT: - sData->type_data = MEM_callocN(sizeof(float)*sData->total_points, "DynamicPaintSurface WeightData"); + sData->type_data = MEM_callocN(sizeof(float) * sData->total_points, "DynamicPaintSurface WeightData"); break; case MOD_DPAINT_SURFACE_T_WAVE: - sData->type_data = MEM_callocN(sizeof(PaintWavePoint)*sData->total_points, "DynamicPaintSurface WaveData"); + sData->type_data = MEM_callocN(sizeof(PaintWavePoint) * sData->total_points, "DynamicPaintSurface WaveData"); break; } @@ -1261,21 +1262,21 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { /* For vertex format, neighbors are connected by edges */ - neigh_points = 2*dm->getNumEdges(dm); + neigh_points = 2 * dm->getNumEdges(dm); } else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) - neigh_points = sData->total_points*8; + neigh_points = sData->total_points * 8; if (!neigh_points) return; /* allocate memory */ ad = sData->adj_data = MEM_callocN(sizeof(PaintAdjData), "Surface Adj Data"); if (!ad) return; - ad->n_index = MEM_callocN(sizeof(int)*sData->total_points, "Surface Adj Index"); - ad->n_num = MEM_callocN(sizeof(int)*sData->total_points, "Surface Adj Counts"); - temp_data = MEM_callocN(sizeof(int)*sData->total_points, "Temp Adj Data"); - ad->n_target = MEM_callocN(sizeof(int)*neigh_points, "Surface Adj Targets"); - ad->flags = MEM_callocN(sizeof(int)*sData->total_points, "Surface Adj Flags"); + ad->n_index = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Index"); + ad->n_num = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Counts"); + temp_data = MEM_callocN(sizeof(int) * sData->total_points, "Temp Adj Data"); + ad->n_target = MEM_callocN(sizeof(int) * neigh_points, "Surface Adj Targets"); + ad->flags = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Flags"); ad->total_targets = neigh_points; /* in case of allocation error, free memory */ @@ -1298,7 +1299,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for struct MLoop *mloop = dm->getLoopArray(dm); /* count number of edges per vertex */ - for (i=0; i<numOfEdges; i++) { + for (i = 0; i < numOfEdges; i++) { ad->n_num[edge[i].v1]++; ad->n_num[edge[i].v2]++; @@ -1307,17 +1308,17 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for } /* also add number of vertices to temp_data - * to locate points on "mesh edge" */ - for (i=0; i<numOfPolys; i++) { - int j=0; - for (; j<mpoly[i].totloop; j++) { + * to locate points on "mesh edge" */ + for (i = 0; i < numOfPolys; i++) { + int j = 0; + for (; j < mpoly[i].totloop; j++) { temp_data[mloop[mpoly[i].loopstart + j].v]++; } } /* now check if total number of edges+faces for - * each vertex is even, if not -> vertex is on mesh edge */ - for (i=0; i<sData->total_points; i++) { + * each vertex is even, if not -> vertex is on mesh edge */ + for (i = 0; i < sData->total_points; i++) { if ((temp_data[i] % 2) || (temp_data[i] < 4)) { @@ -1330,29 +1331,29 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for /* order n_index array */ n_pos = 0; - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { ad->n_index[i] = n_pos; n_pos += ad->n_num[i]; } /* and now add neighbor data using that info */ - for (i=0; i<numOfEdges; i++) { + for (i = 0; i < numOfEdges; i++) { /* first vertex */ int index = edge[i].v1; - n_pos = ad->n_index[index]+temp_data[index]; + n_pos = ad->n_index[index] + temp_data[index]; ad->n_target[n_pos] = edge[i].v2; temp_data[index]++; /* second vertex */ index = edge[i].v2; - n_pos = ad->n_index[index]+temp_data[index]; + n_pos = ad->n_index[index] + temp_data[index]; ad->n_target[n_pos] = edge[i].v1; temp_data[index]++; } } else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { /* for image sequences, only allocate memory. - * bake initialization takes care of rest */ + * bake initialization takes care of rest */ } MEM_freeN(temp_data); @@ -1361,7 +1362,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) { PaintSurfaceData *sData = surface->data; - PaintPoint* pPoint = (PaintPoint*)sData->type_data; + PaintPoint *pPoint = (PaintPoint *)sData->type_data; DerivedMesh *dm = surface->canvas->dm; int i; @@ -1374,7 +1375,7 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) else if (surface->init_color_type == MOD_DPAINT_INITIAL_COLOR) { /* apply color to every surface point */ #pragma omp parallel for schedule(static) - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { copy_v3_v3(pPoint[i].color, surface->init_color); pPoint[i].alpha = surface->init_color[3]; } @@ -1395,20 +1396,20 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) if (!tface) return; /* for vertex surface loop through tfaces and find uv color - * that provides highest alpha */ + * that provides highest alpha */ if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { #pragma omp parallel for schedule(static) - for (i=0; i<numOfFaces; i++) { + for (i = 0; i < numOfFaces; i++) { int numOfVert = (mface[i].v4) ? 4 : 3; float uv[3] = {0.0f}; int j; - for (j=0; j<numOfVert; j++) { + for (j = 0; j < numOfVert; j++) { TexResult texres = {0}; - unsigned int *vert = (&mface[i].v1)+j; + unsigned int *vert = (&mface[i].v1) + j; /* remap to -1.0 to 1.0 */ - uv[0] = tface[i].uv[j][0]*2.0f - 1.0f; - uv[1] = tface[i].uv[j][1]*2.0f - 1.0f; + uv[0] = tface[i].uv[j][0] * 2.0f - 1.0f; + uv[1] = tface[i].uv[j][1] * 2.0f - 1.0f; multitex_ext_safe(tex, uv, &texres); @@ -1420,28 +1421,28 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) } } else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; int samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; #pragma omp parallel for schedule(static) - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { float uv[9] = {0.0f}; float uv_final[3] = {0.0f}; int j; TexResult texres = {0}; /* collect all uvs */ - for (j=0; j<3; j++) { - int v=(f_data->uv_p[i].quad && j>0) ? j+1 : j; - copy_v2_v2(&uv[j*3], tface[f_data->uv_p[i].face_index].uv[v]); + for (j = 0; j < 3; j++) { + int v = (f_data->uv_p[i].quad && j > 0) ? j + 1 : j; + copy_v2_v2(&uv[j * 3], tface[f_data->uv_p[i].face_index].uv[v]); } /* interpolate final uv pos */ interp_v3_v3v3v3(uv_final, &uv[0], &uv[3], &uv[6], - f_data->barycentricWeights[i*samples].v); + f_data->barycentricWeights[i * samples].v); /* remap to -1.0 to 1.0 */ - uv_final[0] = uv_final[0]*2.0f - 1.0f; - uv_final[1] = uv_final[1]*2.0f - 1.0f; + uv_final[0] = uv_final[0] * 2.0f - 1.0f; + uv_final[1] = uv_final[1] * 2.0f - 1.0f; multitex_ext_safe(tex, uv_final, &texres); @@ -1462,37 +1463,37 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) if (!col) return; #pragma omp parallel for schedule(static) - for (i=0; i<numOfLoops; i++) { - pPoint[mloop[i].v].color[0] = 1.0f/255.f*(float)col[i].b; - pPoint[mloop[i].v].color[1] = 1.0f/255.f*(float)col[i].g; - pPoint[mloop[i].v].color[2] = 1.0f/255.f*(float)col[i].r; - pPoint[mloop[i].v].alpha = 1.0f/255.f*(float)col[i].a; + for (i = 0; i < numOfLoops; i++) { + pPoint[mloop[i].v].color[0] = 1.0f / 255.f * (float)col[i].b; + pPoint[mloop[i].v].color[1] = 1.0f / 255.f * (float)col[i].g; + pPoint[mloop[i].v].color[2] = 1.0f / 255.f * (float)col[i].r; + pPoint[mloop[i].v].alpha = 1.0f / 255.f * (float)col[i].a; } } else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; int samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; MCol *col = CustomData_get_layer_named(&dm->faceData, CD_MCOL, surface->init_layername); if (!col) return; #pragma omp parallel for schedule(static) - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { int face_ind = f_data->uv_p[i].face_index; float colors[3][4] = {{0.0f, 0.0f, 0.0f, 0.0f}}; float final_color[4]; int j; /* collect color values */ - for (j=0; j<3; j++) { - int v=(f_data->uv_p[i].quad && j>0) ? j+1 : j; - colors[j][0] = 1.0f/255.f*(float)col[face_ind*4+v].b; - colors[j][1] = 1.0f/255.f*(float)col[face_ind*4+v].g; - colors[j][2] = 1.0f/255.f*(float)col[face_ind*4+v].r; - colors[j][3] = 1.0f/255.f*(float)col[face_ind*4+v].a; + for (j = 0; j < 3; j++) { + int v = (f_data->uv_p[i].quad && j > 0) ? j + 1 : j; + colors[j][0] = 1.0f / 255.f * (float)col[face_ind * 4 + v].b; + colors[j][1] = 1.0f / 255.f * (float)col[face_ind * 4 + v].g; + colors[j][2] = 1.0f / 255.f * (float)col[face_ind * 4 + v].r; + colors[j][3] = 1.0f / 255.f * (float)col[face_ind * 4 + v].a; } /* interpolate final color */ interp_v4_v4v4v4(final_color, colors[0], colors[1], colors[2], - f_data->barycentricWeights[i*samples].v); + f_data->barycentricWeights[i * samples].v); copy_v3_v3(pPoint[i].color, final_color); pPoint[i].alpha = final_color[3]; @@ -1577,28 +1578,28 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Deri if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { MVert *mvert = result->getVertArray(result); int i; - float* value = (float*)sData->type_data; + float *value = (float *)sData->type_data; #pragma omp parallel for schedule(static) - for (i=0; i<sData->total_points; i++) { - float normal[3], val=value[i]*surface->disp_factor; + for (i = 0; i < sData->total_points; i++) { + float normal[3], val = value[i] * surface->disp_factor; normal_short_to_float_v3(normal, mvert[i].no); normalize_v3(normal); - mvert[i].co[0] -= normal[0]*val; - mvert[i].co[1] -= normal[1]*val; - mvert[i].co[2] -= normal[2]*val; + mvert[i].co[0] -= normal[0] * val; + mvert[i].co[1] -= normal[1] * val; + mvert[i].co[2] -= normal[2] * val; } } } /* -* Apply canvas data to the object derived mesh -*/ -static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, - Object *ob, - DerivedMesh *dm) -{ + * Apply canvas data to the object derived mesh + */ +struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, + Object *ob, + DerivedMesh *dm) +{ DerivedMesh *result = CDDM_copy(dm); if (pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) { @@ -1607,7 +1608,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData int update_normals = 0; /* loop through surfaces */ - for (surface = pmd->canvas->surfaces.first; surface; surface=surface->next) { + for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { PaintSurfaceData *sData = surface->data; if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ && sData) { @@ -1620,18 +1621,18 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { int i; - PaintPoint* pPoint = (PaintPoint*)sData->type_data; + PaintPoint *pPoint = (PaintPoint *)sData->type_data; MLoopCol *col = NULL; MLoop *mloop = CDDM_get_loops(result); int totloop = result->numLoopData; /* paint is stored on dry and wet layers, so mix final color first */ - float *fcolor = MEM_callocN(sizeof(float)*sData->total_points*4, "Temp paint color"); + float *fcolor = MEM_callocN(sizeof(float) * sData->total_points * 4, "Temp paint color"); #pragma omp parallel for schedule(static) - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { /* blend dry and wet layer */ - blendColors(pPoint[i].color, pPoint[i].alpha, pPoint[i].e_color, pPoint[i].e_alpha, &fcolor[i*4]); + blendColors(pPoint[i].color, pPoint[i].alpha, pPoint[i].e_color, pPoint[i].e_alpha, &fcolor[i * 4]); } /* viewport preview */ @@ -1649,7 +1650,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData #endif /* Save preview results to weight layer to be - * able to share same drawing methods */ + * able to share same drawing methods */ col = CustomData_get_layer(&result->loopData, CD_PREVIEW_MLOOPCOL); if (!col) col = CustomData_add_layer(&result->loopData, CD_PREVIEW_MLOOPCOL, CD_CALLOC, @@ -1657,11 +1658,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData if (col) { #pragma omp parallel for schedule(static) - for (i=0; i<totpoly; i++) { - int j=0; + for (i = 0; i < totpoly; i++) { + int j = 0; Material *material = give_current_material(ob, mp[i].mat_nr + 1); - for (; j<mp[i].totloop; j++) { + for (; j < mp[i].totloop; j++) { int l_index = mp[i].loopstart + j; int v_index = mloop[l_index].v; @@ -1682,14 +1683,14 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData c[2] = 0.65f; } /* mix surface color */ - interp_v3_v3v3(c, c, &fcolor[v_index], fcolor[v_index+3]); + interp_v3_v3v3(c, c, &fcolor[v_index], fcolor[v_index + 3]); rgb_float_to_uchar((unsigned char *)&col[l_index].r, c); } else { col[l_index].r = - col[l_index].g = - col[l_index].b = FTOCHAR(pPoint[v_index].wetness); + col[l_index].g = + col[l_index].b = FTOCHAR(pPoint[v_index].wetness); col[l_index].a = 255; } } @@ -1708,10 +1709,10 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData /* apply color */ if (col) { #pragma omp parallel for schedule(static) - for (i=0; i<totloop; i++) { - int index = mloop[i].v*4; + for (i = 0; i < totloop; i++) { + int index = mloop[i].v * 4; rgb_float_to_uchar((unsigned char *)&col[i].r, &fcolor[index]); - col[i].a = FTOCHAR(fcolor[index+3]); /* IS THIS NEEDED? */ + col[i].a = FTOCHAR(fcolor[index + 3]); /* IS THIS NEEDED? */ } } @@ -1725,11 +1726,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData /* apply color */ if (col) { #pragma omp parallel for schedule(static) - for (i=0; i<totloop; i++) { + for (i = 0; i < totloop; i++) { int index = mloop[i].v; col[i].r = - col[i].g = - col[i].b = FTOCHAR(pPoint[index].wetness); + col[i].g = + col[i].b = FTOCHAR(pPoint[index].wetness); col[i].a = 255; } } @@ -1741,7 +1742,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { int defgrp_index = defgroup_name_index(ob, surface->output_name); MDeformVert *dvert = result->getVertDataArray(result, CD_MDEFORMVERT); - float *weight = (float*)sData->type_data; + float *weight = (float *)sData->type_data; /* viewport preview */ if (surface->flags & MOD_DPAINT_PREVIEW) { @@ -1754,11 +1755,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData /* apply weights into a vertex group, if doesnt exists add a new layer */ if (defgrp_index >= 0 && !dvert && (surface->output_name[0] != '\0')) dvert = CustomData_add_layer_named(&result->vertData, CD_MDEFORMVERT, CD_CALLOC, - NULL, sData->total_points, surface->output_name); + NULL, sData->total_points, surface->output_name); if (defgrp_index >= 0 && dvert) { int i; - for (i=0; i<sData->total_points; i++) { - MDeformVert *dv= &dvert[i]; + for (i = 0; i < sData->total_points; i++) { + MDeformVert *dv = &dvert[i]; MDeformWeight *def_weight = defvert_find_index(dv, defgrp_index); /* skip if weight value is 0 and no existing weight is found */ @@ -1766,7 +1767,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData /* if not found, add a weight for it */ if (def_weight == NULL) { - def_weight= defvert_verify_index(dv, defgrp_index); + def_weight = defvert_verify_index(dv, defgrp_index); } /* set weight value */ @@ -1779,10 +1780,10 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { MVert *mvert = result->getVertArray(result); int i; - PaintWavePoint* wPoint = (PaintWavePoint*)sData->type_data; + PaintWavePoint *wPoint = (PaintWavePoint *)sData->type_data; #pragma omp parallel for schedule(static) - for (i=0; i<sData->total_points; i++) { + for (i = 0; i < sData->total_points; i++) { float normal[3]; normal_short_to_float_v3(normal, mvert[i].no); madd_v3_v3fl(mvert[i].co, normal, wPoint[i].height); @@ -1827,8 +1828,8 @@ void canvas_copyDerivedMesh(DynamicPaintCanvasSettings *canvas, DerivedMesh *dm) } /* -* Updates derived mesh copy and processes dynamic paint step / caches. -*/ + * Updates derived mesh copy and processes dynamic paint step / caches. + */ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene, Object *ob, DerivedMesh *dm) { if (pmd->canvas) { @@ -1842,7 +1843,7 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene if (canvas->flags & MOD_DPAINT_BAKING) return; /* loop through surfaces */ - for (; surface; surface=surface->next) { + for (; surface; surface = surface->next) { int current_frame = (int)scene->r.cfra; /* free bake data if not required anymore */ @@ -1903,10 +1904,10 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene } /* Modifier call. Processes dynamic paint modifier step. */ -struct DerivedMesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, Scene *scene, Object *ob, DerivedMesh *dm) -{ +DerivedMesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, Scene *scene, Object *ob, DerivedMesh *dm) +{ /* For now generate tessfaces in every case - * XXX - move/remove when most of dpaint functions are converted to use bmesh types */ + * XXX - move/remove when most of dpaint functions are converted to use bmesh types */ DM_ensure_tessface(dm); /* Update canvas data for a new frame */ @@ -1920,19 +1921,19 @@ struct DerivedMesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, Scen /***************************** Image Sequence / UV Image Surface Calls ******************************/ /* -* Tries to find the neighboring pixel in given (uv space) direction. -* Result is used by effect system to move paint on the surface. -* -* px, py : origin pixel x and y -* n_index : lookup direction index (use neighX, neighY to get final index) -*/ + * Tries to find the neighboring pixel in given (uv space) direction. + * Result is used by effect system to move paint on the surface. + * + * px, py : origin pixel x and y + * n_index : lookup direction index (use neighX, neighY to get final index) + */ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh *dm, const char *uvname, int w, int h, int px, int py, int n_index) { /* Note: Current method only uses polygon edges to detect neighboring pixels. - * -> It doesn't always lead to the optimum pixel but is accurate enough - * and faster/simplier than including possible face tip point links) - */ + * -> It doesn't always lead to the optimum pixel but is accurate enough + * and faster/simplier than including possible face tip point links) + */ int x, y; PaintUVPoint *tPoint = NULL; @@ -1942,44 +1943,44 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh x = px + neighX[n_index]; y = py + neighY[n_index]; - if (x<0 || x>=w) return OUT_OF_TEXTURE; - if (y<0 || y>=h) return OUT_OF_TEXTURE; + if (x < 0 || x >= w) return OUT_OF_TEXTURE; + if (y < 0 || y >= h) return OUT_OF_TEXTURE; - tPoint = &tempPoints[x+w*y]; /* UV neighbor */ - cPoint = &tempPoints[px+w*py]; /* Origin point */ + tPoint = &tempPoints[x + w * y]; /* UV neighbor */ + cPoint = &tempPoints[px + w * py]; /* Origin point */ /* - * Check if shifted point is on same face -> it's a correct neighbor - * (and if it isn't marked as an "edge pixel") - */ + * Check if shifted point is on same face -> it's a correct neighbor + * (and if it isn't marked as an "edge pixel") + */ if ((tPoint->face_index == cPoint->face_index) && (tPoint->neighbour_pixel == -1)) - return (x+w*y); + return (x + w * y); /* - * Even if shifted point is on another face - * -> use this point. - * - * !! Replace with "is uv faces linked" check !! - * This should work fine as long as uv island - * margin is > 1 pixel. - */ + * Even if shifted point is on another face + * -> use this point. + * + * !! Replace with "is uv faces linked" check !! + * This should work fine as long as uv island + * margin is > 1 pixel. + */ if ((tPoint->face_index != -1) && (tPoint->neighbour_pixel == -1)) { - return (x+w*y); + return (x + w * y); } /* - * If we get here, the actual neighboring pixel - * is located on a non-linked uv face, and we have to find - * it's "real" position. - * - * Simple neighboring face finding algorithm: - * - find closest uv edge to shifted pixel and get - * the another face that shares that edge - * - find corresponding position of that new face edge - * in uv space - * - * TODO: Implement something more accurate / optimized? - */ + * If we get here, the actual neighboring pixel + * is located on a non-linked uv face, and we have to find + * it's "real" position. + * + * Simple neighboring face finding algorithm: + * - find closest uv edge to shifted pixel and get + * the another face that shares that edge + * - find corresponding position of that new face edge + * in uv space + * + * TODO: Implement something more accurate / optimized? + */ { int numOfFaces = dm->getNumTessFaces(dm); MFace *mface = dm->getTessFaceArray(dm); @@ -1989,7 +1990,7 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh { float pixel[2], dist, t_dist; int i, uindex[3], edge1_index, edge2_index, - e1_index, e2_index, target_face; + e1_index, e2_index, target_face; float closest_point[2], lambda, dir_vec[2]; int target_uv1, target_uv2, final_pixel[2], final_index; @@ -2007,41 +2008,41 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh } /* - * Find closest edge to that pixel - */ + * Find closest edge to that pixel + */ /* Dist to first edge */ e1_index = cPoint->v1; e2_index = cPoint->v2; edge1_index = uindex[0]; edge2_index = uindex[1]; dist = dist_to_line_segment_v2(pixel, tface[cPoint->face_index].uv[edge1_index], tface[cPoint->face_index].uv[edge2_index]); /* Dist to second edge */ t_dist = dist_to_line_segment_v2(pixel, tface[cPoint->face_index].uv[uindex[1]], tface[cPoint->face_index].uv[uindex[2]]); - if (t_dist < dist) {e1_index = cPoint->v2; e2_index = cPoint->v3; edge1_index = uindex[1]; edge2_index = uindex[2]; dist = t_dist;} + if (t_dist < dist) {e1_index = cPoint->v2; e2_index = cPoint->v3; edge1_index = uindex[1]; edge2_index = uindex[2]; dist = t_dist; } /* Dist to third edge */ t_dist = dist_to_line_segment_v2(pixel, tface[cPoint->face_index].uv[uindex[2]], tface[cPoint->face_index].uv[uindex[0]]); - if (t_dist < dist) {e1_index = cPoint->v3; e2_index = cPoint->v1; edge1_index = uindex[2]; edge2_index = uindex[0]; dist = t_dist;} + if (t_dist < dist) {e1_index = cPoint->v3; e2_index = cPoint->v1; edge1_index = uindex[2]; edge2_index = uindex[0]; dist = t_dist; } /* - * Now find another face that is linked to that edge - */ + * Now find another face that is linked to that edge + */ target_face = -1; - for (i=0; i<numOfFaces; i++) { + for (i = 0; i < numOfFaces; i++) { /* - * Check if both edge vertices share this face - */ + * Check if both edge vertices share this face + */ int v4 = (mface[i].v4) ? mface[i].v4 : -1; if ((e1_index == mface[i].v1 || e1_index == mface[i].v2 || e1_index == mface[i].v3 || e1_index == v4) && - (e2_index == mface[i].v1 || e2_index == mface[i].v2 || e2_index == mface[i].v3 || e2_index == v4)) { + (e2_index == mface[i].v1 || e2_index == mface[i].v2 || e2_index == mface[i].v3 || e2_index == v4)) { if (i == cPoint->face_index) continue; target_face = i; /* - * Get edge UV index - */ + * Get edge UV index + */ if (e1_index == mface[i].v1) target_uv1 = 0; else if (e1_index == mface[i].v2) target_uv1 = 1; else if (e1_index == mface[i].v3) target_uv1 = 2; @@ -2060,8 +2061,8 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh if (target_face == -1) return ON_MESH_EDGE; /* - * If target face is connected in UV space as well, just use original index - */ + * If target face is connected in UV space as well, just use original index + */ s_uv1 = (float *)tface[cPoint->face_index].uv[edge1_index]; s_uv2 = (float *)tface[cPoint->face_index].uv[edge2_index]; t_uv1 = (float *)tface[target_face].uv[target_uv1]; @@ -2074,13 +2075,13 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh ((s_uv2[0] == t_uv1[0] && s_uv2[1] == t_uv1[1]) && (s_uv1[0] == t_uv2[0] && s_uv1[1] == t_uv2[1]) )) { - return ((px+neighX[n_index]) + w*(py+neighY[n_index])); + return ((px + neighX[n_index]) + w * (py + neighY[n_index])); } /* - * Find a point that is relatively at same edge position - * on this other face UV - */ + * Find a point that is relatively at same edge position + * on this other face UV + */ lambda = closest_to_line_v2(closest_point, pixel, tface[cPoint->face_index].uv[edge1_index], tface[cPoint->face_index].uv[edge2_index]); if (lambda < 0.0f) lambda = 0.0f; if (lambda > 1.0f) lambda = 1.0f; @@ -2104,13 +2105,13 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh final_index = final_pixel[0] + w * final_pixel[1]; /* If we ended up to our origin point ( mesh has smaller than pixel sized faces) */ - if (final_index == (px+w*py)) return NOT_FOUND; + if (final_index == (px + w * py)) return NOT_FOUND; /* If found pixel still lies on wrong face ( mesh has smaller than pixel sized faces) */ if (tempPoints[final_index].face_index != target_face) return NOT_FOUND; /* - * If final point is an "edge pixel", use it's "real" neighbor instead - */ + * If final point is an "edge pixel", use it's "real" neighbor instead + */ if (tempPoints[final_index].neighbour_pixel != -1) final_index = cPoint->neighbour_pixel; return final_index; @@ -2119,16 +2120,16 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh } /* -* Create a surface for uv image sequence format -*/ + * Create a surface for uv image sequence format + */ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) { /* Antialias jitter point relative coords */ float jitter5sample[10] = {0.0f, 0.0f, - -0.2f, -0.4f, - 0.2f, 0.4f, - 0.4f, -0.2f, - -0.4f, 0.3f}; + -0.2f, -0.4f, + 0.2f, 0.4f, + 0.4f, -0.2f, + -0.4f, 0.3f}; int ty; int w, h; int numOfFaces; @@ -2165,8 +2166,8 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) w = h = surface->image_resolution; /* - * Start generating the surface - */ + * Start generating the surface + */ printf("DynamicPaint: Preparing UV surface of %ix%i pixels and %i faces.\n", w, h, numOfFaces); /* Init data struct */ @@ -2175,55 +2176,55 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) if (!surface->data) return setError(canvas, "Not enough free memory."); aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; - tempPoints = (struct PaintUVPoint *) MEM_callocN(w*h*sizeof(struct PaintUVPoint), "Temp PaintUVPoint"); - if (!tempPoints) error=1; + tempPoints = (struct PaintUVPoint *) MEM_callocN(w * h * sizeof(struct PaintUVPoint), "Temp PaintUVPoint"); + if (!tempPoints) error = 1; - final_index = (int *) MEM_callocN(w*h*sizeof(int), "Temp UV Final Indexes"); - if (!final_index) error=1; + final_index = (int *) MEM_callocN(w * h * sizeof(int), "Temp UV Final Indexes"); + if (!final_index) error = 1; - tempWeights = (struct Vec3f *) MEM_mallocN(w*h*aa_samples*sizeof(struct Vec3f), "Temp bWeights"); - if (!tempWeights) error=1; + tempWeights = (struct Vec3f *) MEM_mallocN(w * h * aa_samples * sizeof(struct Vec3f), "Temp bWeights"); + if (!tempWeights) error = 1; /* - * Generate a temporary bounding box array for UV faces to optimize - * the pixel-inside-a-face search. - */ + * Generate a temporary bounding box array for UV faces to optimize + * the pixel-inside-a-face search. + */ if (!error) { - faceBB = (struct Bounds2D *) MEM_mallocN(numOfFaces*sizeof(struct Bounds2D), "MPCanvasFaceBB"); - if (!faceBB) error=1; + faceBB = (struct Bounds2D *) MEM_mallocN(numOfFaces * sizeof(struct Bounds2D), "MPCanvasFaceBB"); + if (!faceBB) error = 1; } if (!error) - for (ty=0; ty<numOfFaces; ty++) { - int numOfVert = (mface[ty].v4) ? 4 : 3; - int i; + for (ty = 0; ty < numOfFaces; ty++) { + int numOfVert = (mface[ty].v4) ? 4 : 3; + int i; - copy_v2_v2(faceBB[ty].min, tface[ty].uv[0]); - copy_v2_v2(faceBB[ty].max, tface[ty].uv[0]); + copy_v2_v2(faceBB[ty].min, tface[ty].uv[0]); + copy_v2_v2(faceBB[ty].max, tface[ty].uv[0]); - for (i = 1; i<numOfVert; i++) { - if (tface[ty].uv[i][0] < faceBB[ty].min[0]) faceBB[ty].min[0] = tface[ty].uv[i][0]; - if (tface[ty].uv[i][1] < faceBB[ty].min[1]) faceBB[ty].min[1] = tface[ty].uv[i][1]; - if (tface[ty].uv[i][0] > faceBB[ty].max[0]) faceBB[ty].max[0] = tface[ty].uv[i][0]; - if (tface[ty].uv[i][1] > faceBB[ty].max[1]) faceBB[ty].max[1] = tface[ty].uv[i][1]; + for (i = 1; i < numOfVert; i++) { + if (tface[ty].uv[i][0] < faceBB[ty].min[0]) faceBB[ty].min[0] = tface[ty].uv[i][0]; + if (tface[ty].uv[i][1] < faceBB[ty].min[1]) faceBB[ty].min[1] = tface[ty].uv[i][1]; + if (tface[ty].uv[i][0] > faceBB[ty].max[0]) faceBB[ty].max[0] = tface[ty].uv[i][0]; + if (tface[ty].uv[i][1] > faceBB[ty].max[1]) faceBB[ty].max[1] = tface[ty].uv[i][1]; + } } - } /* - * Loop through every pixel and check - * if pixel is uv-mapped on a canvas face. - */ + * Loop through every pixel and check + * if pixel is uv-mapped on a canvas face. + */ if (!error) { #pragma omp parallel for schedule(static) for (ty = 0; ty < h; ty++) { int tx; for (tx = 0; tx < w; tx++) { int i, sample; - int index = tx+w*ty; + int index = tx + w * ty; PaintUVPoint *tPoint = (&tempPoints[index]); - short isInside = 0; /* if point is inside a uv face */ + short isInside = 0; /* if point is inside a uv face */ float d1[2], d2[2], d3[2], point[5][2]; float dot00, dot01, dot02, dot11, dot12, invDenom, u, v; @@ -2238,27 +2239,27 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) point[0][1] = ((float)ty + 0.5f) / h; /* - * A pixel middle sample isn't enough to find very narrow polygons - * So using 4 samples of each corner too - */ + * A pixel middle sample isn't enough to find very narrow polygons + * So using 4 samples of each corner too + */ point[1][0] = ((float)tx) / w; point[1][1] = ((float)ty) / h; - point[2][0] = ((float)tx+1) / w; + point[2][0] = ((float)tx + 1) / w; point[2][1] = ((float)ty) / h; point[3][0] = ((float)tx) / w; - point[3][1] = ((float)ty+1) / h; + point[3][1] = ((float)ty + 1) / h; - point[4][0] = ((float)tx+1) / w; - point[4][1] = ((float)ty+1) / h; + point[4][0] = ((float)tx + 1) / w; + point[4][1] = ((float)ty + 1) / h; /* Loop through samples, starting from middle point */ - for (sample=0; sample<5; sample++) { + for (sample = 0; sample < 5; sample++) { /* Loop through every face in the mesh */ - for (i=0; i<numOfFaces; i++) { + for (i = 0; i < numOfFaces; i++) { /* Check uv bb */ if (faceBB[i].min[0] > (point[sample][0])) continue; @@ -2267,55 +2268,55 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) if (faceBB[i].max[1] < (point[sample][1])) continue; /* Calculate point inside a triangle check - * for uv0, 1, 2 */ - sub_v2_v2v2(d1, tface[i].uv[2], tface[i].uv[0]); // uv2 - uv0 - sub_v2_v2v2(d2, tface[i].uv[1], tface[i].uv[0]); // uv1 - uv0 - sub_v2_v2v2(d3, point[sample], tface[i].uv[0]); // point - uv0 + * for uv0, 1, 2 */ + sub_v2_v2v2(d1, tface[i].uv[2], tface[i].uv[0]); // uv2 - uv0 + sub_v2_v2v2(d2, tface[i].uv[1], tface[i].uv[0]); // uv1 - uv0 + sub_v2_v2v2(d3, point[sample], tface[i].uv[0]); // point - uv0 - dot00 = d1[0]*d1[0] + d1[1]*d1[1]; - dot01 = d1[0]*d2[0] + d1[1]*d2[1]; - dot02 = d1[0]*d3[0] + d1[1]*d3[1]; - dot11 = d2[0]*d2[0] + d2[1]*d2[1]; - dot12 = d2[0]*d3[0] + d2[1]*d3[1]; + dot00 = d1[0] * d1[0] + d1[1] * d1[1]; + dot01 = d1[0] * d2[0] + d1[1] * d2[1]; + dot02 = d1[0] * d3[0] + d1[1] * d3[1]; + dot11 = d2[0] * d2[0] + d2[1] * d2[1]; + dot12 = d2[0] * d3[0] + d2[1] * d3[1]; invDenom = 1 / (dot00 * dot11 - dot01 * dot01); u = (dot11 * dot02 - dot01 * dot12) * invDenom; v = (dot00 * dot12 - dot01 * dot02) * invDenom; - if ((u > 0) && (v > 0) && (u + v < 1)) {isInside=1;} /* is inside a triangle */ + if ((u > 0) && (v > 0) && (u + v < 1)) {isInside = 1; } /* is inside a triangle */ /* If collision wasn't found but the face is a quad - * do another check for the second half */ + * do another check for the second half */ if ((!isInside) && mface[i].v4) { /* change d2 to test the other half */ - sub_v2_v2v2(d2, tface[i].uv[3], tface[i].uv[0]); // uv3 - uv0 + sub_v2_v2v2(d2, tface[i].uv[3], tface[i].uv[0]); // uv3 - uv0 /* test again */ - dot00 = d1[0]*d1[0] + d1[1]*d1[1]; - dot01 = d1[0]*d2[0] + d1[1]*d2[1]; - dot02 = d1[0]*d3[0] + d1[1]*d3[1]; - dot11 = d2[0]*d2[0] + d2[1]*d2[1]; - dot12 = d2[0]*d3[0] + d2[1]*d3[1]; + dot00 = d1[0] * d1[0] + d1[1] * d1[1]; + dot01 = d1[0] * d2[0] + d1[1] * d2[1]; + dot02 = d1[0] * d3[0] + d1[1] * d3[1]; + dot11 = d2[0] * d2[0] + d2[1] * d2[1]; + dot12 = d2[0] * d3[0] + d2[1] * d3[1]; invDenom = 1 / (dot00 * dot11 - dot01 * dot01); u = (dot11 * dot02 - dot01 * dot12) * invDenom; v = (dot00 * dot12 - dot01 * dot02) * invDenom; - if ((u > 0) && (v > 0) && (u + v < 1)) {isInside=2;} /* is inside the second half of the quad */ + if ((u > 0) && (v > 0) && (u + v < 1)) {isInside = 2; } /* is inside the second half of the quad */ } /* - * If point was inside the face - */ + * If point was inside the face + */ if (isInside != 0) { float uv1co[2], uv2co[2], uv3co[2], uv[2]; int j; /* Get triagnle uvs */ - if (isInside==1) { + if (isInside == 1) { copy_v2_v2(uv1co, tface[i].uv[0]); copy_v2_v2(uv2co, tface[i].uv[1]); copy_v2_v2(uv3co, tface[i].uv[2]); @@ -2327,23 +2328,23 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* Add b-weights per anti-aliasing sample */ - for (j=0; j<aa_samples; j++) { - uv[0] = point[0][0] + jitter5sample[j*2] / w; - uv[1] = point[0][1] + jitter5sample[j*2+1] / h; + for (j = 0; j < aa_samples; j++) { + uv[0] = point[0][0] + jitter5sample[j * 2] / w; + uv[1] = point[0][1] + jitter5sample[j * 2 + 1] / h; - barycentric_weights_v2(uv1co, uv2co, uv3co, uv, tempWeights[index*aa_samples+j].v); + barycentric_weights_v2(uv1co, uv2co, uv3co, uv, tempWeights[index * aa_samples + j].v); } /* Set surface point face values */ - tPoint->face_index = i; /* face index */ - tPoint->quad = (isInside == 2) ? 1 : 0; /* quad or tri part*/ + tPoint->face_index = i; /* face index */ + tPoint->quad = (isInside == 2) ? 1 : 0; /* quad or tri part*/ /* save vertex indexes */ tPoint->v1 = mface[i].v1; tPoint->v2 = (isInside == 2) ? mface[i].v3 : mface[i].v2; tPoint->v3 = (isInside == 2) ? mface[i].v4 : mface[i].v3; - sample = 5; /* make sure we exit sample loop as well */ + sample = 5; /* make sure we exit sample loop as well */ break; } } @@ -2352,16 +2353,16 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* - * Now loop through every pixel that was left without index - * and find if they have neighboring pixels that have an index. - * If so use that polygon as pixel surface. - * (To avoid seams on uv island edges) - */ + * Now loop through every pixel that was left without index + * and find if they have neighboring pixels that have an index. + * If so use that polygon as pixel surface. + * (To avoid seams on uv island edges) + */ #pragma omp parallel for schedule(static) for (ty = 0; ty < h; ty++) { int tx; for (tx = 0; tx < w; tx++) { - int index = tx+w*ty; + int index = tx + w * ty; PaintUVPoint *tPoint = (&tempPoints[index]); /* If point isn't't on canvas mesh */ @@ -2372,19 +2373,19 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) /* get loop area */ u_min = (tx > 0) ? -1 : 0; - u_max = (tx < (w-1)) ? 1 : 0; + u_max = (tx < (w - 1)) ? 1 : 0; v_min = (ty > 0) ? -1 : 0; - v_max = (ty < (h-1)) ? 1 : 0; + v_max = (ty < (h - 1)) ? 1 : 0; point[0] = ((float)tx + 0.5f) / w; point[1] = ((float)ty + 0.5f) / h; /* search through defined area for neighbor */ - for (u=u_min; u<=u_max; u++) - for (v=v_min; v<=v_max; v++) { + for (u = u_min; u <= u_max; u++) + for (v = v_min; v <= v_max; v++) { /* if not this pixel itself */ - if (u!=0 || v!=0) { - ind = (tx+u)+w*(ty+v); + if (u != 0 || v != 0) { + ind = (tx + u) + w * (ty + v); /* if neighbor has index */ if (tempPoints[ind].face_index != -1) { @@ -2405,39 +2406,39 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* Add b-weights per anti-aliasing sample */ - for (j=0; j<aa_samples; j++) { + for (j = 0; j < aa_samples; j++) { - uv[0] = point[0] + jitter5sample[j*2] / w; - uv[1] = point[1] + jitter5sample[j*2+1] / h; - barycentric_weights_v2(uv1co, uv2co, uv3co, uv, tempWeights[index*aa_samples+j].v); + uv[0] = point[0] + jitter5sample[j * 2] / w; + uv[1] = point[1] + jitter5sample[j * 2 + 1] / h; + barycentric_weights_v2(uv1co, uv2co, uv3co, uv, tempWeights[index * aa_samples + j].v); } /* Set values */ - tPoint->neighbour_pixel = ind; // face index - tPoint->quad = tempPoints[ind].quad; // quad or tri + tPoint->neighbour_pixel = ind; // face index + tPoint->quad = tempPoints[ind].quad; // quad or tri /* save vertex indexes */ tPoint->v1 = mface[i].v1; tPoint->v2 = (tPoint->quad) ? mface[i].v3 : mface[i].v2; tPoint->v3 = (tPoint->quad) ? mface[i].v4 : mface[i].v3; - u = u_max + 1; /* make sure we exit outer loop as well */ + u = u_max + 1; /* make sure we exit outer loop as well */ break; } + } } - } } } } /* - * When base loop is over convert found neighbor indexes to real ones - * Also count the final number of active surface points - */ + * When base loop is over convert found neighbor indexes to real ones + * Also count the final number of active surface points + */ for (ty = 0; ty < h; ty++) { int tx; for (tx = 0; tx < w; tx++) { - int index = tx+w*ty; + int index = tx + w * ty; PaintUVPoint *tPoint = (&tempPoints[index]); if (tPoint->face_index == -1 && tPoint->neighbour_pixel != -1) tPoint->face_index = tempPoints[tPoint->neighbour_pixel].face_index; @@ -2447,18 +2448,18 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) /* Generate surface adjacency data. */ { - int i, cursor=0; + int i, cursor = 0; /* Create a temporary array of final indexes (before unassigned - * pixels have been dropped) */ - for (i=0; i<w*h; i++) { + * pixels have been dropped) */ + for (i = 0; i < w * h; i++) { if (tempPoints[i].face_index != -1) { final_index[i] = cursor; cursor++; } } /* allocate memory */ - sData->total_points = w*h; + sData->total_points = w * h; dynamicPaint_initAdjacencyData(surface, 1); if (sData->adj_data) { @@ -2467,16 +2468,16 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) for (ty = 0; ty < h; ty++) { int tx; for (tx = 0; tx < w; tx++) { - int i, index = tx+w*ty; + int i, index = tx + w * ty; if (tempPoints[index].face_index != -1) { ed->n_index[final_index[index]] = n_pos; ed->n_num[final_index[index]] = 0; - for (i=0; i<8; i++) { + for (i = 0; i < 8; i++) { /* Try to find a neighboring pixel in defined direction - * If not found, -1 is returned */ + * If not found, -1 is returned */ int n_target = dynamicPaint_findNeighbourPixel(tempPoints, dm, uvname, w, h, tx, ty, i); if (n_target >= 0) { @@ -2498,12 +2499,12 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) { ImgSeqFormatData *f_data = MEM_callocN(sizeof(struct ImgSeqFormatData), "ImgSeqFormatData"); if (f_data) { - f_data->uv_p = MEM_callocN(active_points*sizeof(struct PaintUVPoint), "PaintUVPoint"); - f_data->barycentricWeights = MEM_callocN(active_points*aa_samples*sizeof(struct Vec3f), "PaintUVPoint"); + f_data->uv_p = MEM_callocN(active_points * sizeof(struct PaintUVPoint), "PaintUVPoint"); + f_data->barycentricWeights = MEM_callocN(active_points * aa_samples * sizeof(struct Vec3f), "PaintUVPoint"); - if (!f_data->uv_p || !f_data->barycentricWeights) error=1; + if (!f_data->uv_p || !f_data->barycentricWeights) error = 1; } - else error=1; + else error = 1; sData->total_points = active_points; @@ -2520,17 +2521,17 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) sData->total_points = active_points; sData->format_data = f_data; - for (index = 0; index < (w*h); index++) { + for (index = 0; index < (w * h); index++) { if (tempPoints[index].face_index != -1) { memcpy(&f_data->uv_p[cursor], &tempPoints[index], sizeof(PaintUVPoint)); - memcpy(&f_data->barycentricWeights[cursor*aa_samples], &tempWeights[index*aa_samples], sizeof(Vec3f)*aa_samples); + memcpy(&f_data->barycentricWeights[cursor * aa_samples], &tempWeights[index * aa_samples], sizeof(Vec3f) * aa_samples); cursor++; } } } } } - if (error==1) setError(canvas, "Not enough free memory."); + if (error == 1) setError(canvas, "Not enough free memory."); if (faceBB) MEM_freeN(faceBB); if (tempPoints) MEM_freeN(tempPoints); @@ -2543,22 +2544,22 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) #if 0 /* ----------------------------------------------------------------- - * For debug, output pixel statuses to the color map - * -----------------------------------------------------------------*/ + * For debug, output pixel statuses to the color map + * -----------------------------------------------------------------*/ #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; - PaintUVPoint *uvPoint = &((PaintUVPoint*)f_data->uv_p)[index]; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; - pPoint->alpha=1.0f; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; + PaintUVPoint *uvPoint = &((PaintUVPoint *)f_data->uv_p)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; + pPoint->alpha = 1.0f; /* Every pixel that is assigned as "edge pixel" gets blue color */ if (uvPoint->neighbour_pixel != -1) pPoint->color[2] = 1.0f; /* and every pixel that finally got an polygon gets red color */ if (uvPoint->face_index != -1) pPoint->color[0] = 1.0f; /* green color shows pixel face index hash */ - if (uvPoint->face_index != -1) pPoint->color[1] = (float)(uvPoint->face_index % 255)/256.0f; + if (uvPoint->face_index != -1) pPoint->color[1] = (float)(uvPoint->face_index % 255) / 256.0f; } #endif @@ -2569,19 +2570,19 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* -* Outputs an image file from uv surface data. -*/ -void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filename, short output_layer) + * Outputs an image file from uv surface data. + */ +void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filename, short output_layer) { int index; - ImBuf* ibuf = NULL; + ImBuf *ibuf = NULL; PaintSurfaceData *sData = surface->data; - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; /* OpenEXR or PNG */ int format = (surface->image_fileformat & MOD_DPAINT_IMGFORMAT_OPENEXR) ? R_IMF_IMTYPE_OPENEXR : R_IMF_IMTYPE_PNG; char output_file[FILE_MAX]; - if (!sData || !sData->type_data) {setError(surface->canvas, "Image save failed: Invalid surface.");return;} + if (!sData || !sData->type_data) {setError(surface->canvas, "Image save failed: Invalid surface."); return; } /* if selected format is openexr, but current build doesnt support one */ #ifndef WITH_OPENEXR if (format == R_IMF_IMTYPE_OPENEXR) format = R_IMF_IMTYPE_PNG; @@ -2595,78 +2596,78 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filenam /* Init image buffer */ ibuf = IMB_allocImBuf(surface->image_resolution, surface->image_resolution, 32, IB_rectfloat); - if (ibuf == NULL) {setError(surface->canvas, "Image save failed: Not enough free memory.");return;} + if (ibuf == NULL) {setError(surface->canvas, "Image save failed: Not enough free memory."); return; } #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { - int pos=f_data->uv_p[index].pixel_index*4; /* image buffer position */ + int pos = f_data->uv_p[index].pixel_index * 4; /* image buffer position */ /* Set values of preferred type */ if (output_layer == 1) { /* wetmap */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - PaintPoint *point = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *point = &((PaintPoint *)sData->type_data)[index]; float value = (point->wetness > 1.0f) ? 1.0f : point->wetness; - ibuf->rect_float[pos]=value; - ibuf->rect_float[pos+1]=value; - ibuf->rect_float[pos+2]=value; - ibuf->rect_float[pos+3]=1.0f; + ibuf->rect_float[pos] = value; + ibuf->rect_float[pos + 1] = value; + ibuf->rect_float[pos + 2] = value; + ibuf->rect_float[pos + 3] = 1.0f; } } else if (output_layer == 0) { /* Paintmap */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - PaintPoint *point = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *point = &((PaintPoint *)sData->type_data)[index]; /* blend wet and dry layers */ blendColors(point->color, point->alpha, point->e_color, point->e_alpha, &ibuf->rect_float[pos]); /* Multiply color by alpha if enabled */ if (surface->flags & MOD_DPAINT_MULALPHA) { - ibuf->rect_float[pos] *= ibuf->rect_float[pos+3]; - ibuf->rect_float[pos+1] *= ibuf->rect_float[pos+3]; - ibuf->rect_float[pos+2] *= ibuf->rect_float[pos+3]; + ibuf->rect_float[pos] *= ibuf->rect_float[pos + 3]; + ibuf->rect_float[pos + 1] *= ibuf->rect_float[pos + 3]; + ibuf->rect_float[pos + 2] *= ibuf->rect_float[pos + 3]; } } /* displace */ else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { - float depth = ((float*)sData->type_data)[index]; + float depth = ((float *)sData->type_data)[index]; if (surface->depth_clamp) depth /= surface->depth_clamp; if (surface->disp_type == MOD_DPAINT_DISP_DISPLACE) { - depth = (0.5f - depth/2.0f); + depth = (0.5f - depth / 2.0f); } CLAMP(depth, 0.0f, 1.0f); - ibuf->rect_float[pos]=depth; - ibuf->rect_float[pos+1]=depth; - ibuf->rect_float[pos+2]=depth; - ibuf->rect_float[pos+3]=1.0f; + ibuf->rect_float[pos] = depth; + ibuf->rect_float[pos + 1] = depth; + ibuf->rect_float[pos + 2] = depth; + ibuf->rect_float[pos + 3] = 1.0f; } /* waves */ else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { - PaintWavePoint *wPoint = &((PaintWavePoint*)sData->type_data)[index]; + PaintWavePoint *wPoint = &((PaintWavePoint *)sData->type_data)[index]; float depth = wPoint->height; if (surface->depth_clamp) - depth /= surface->depth_clamp; - depth = (0.5f + depth/2.0f); + depth /= surface->depth_clamp; + depth = (0.5f + depth / 2.0f); CLAMP(depth, 0.0f, 1.0f); - ibuf->rect_float[pos]=depth; - ibuf->rect_float[pos+1]=depth; - ibuf->rect_float[pos+2]=depth; - ibuf->rect_float[pos+3]=1.0f; + ibuf->rect_float[pos] = depth; + ibuf->rect_float[pos + 1] = depth; + ibuf->rect_float[pos + 2] = depth; + ibuf->rect_float[pos + 3] = 1.0f; } } } /* Set output format, png in case exr isn't supported */ - ibuf->ftype= PNG|95; + ibuf->ftype = PNG | 95; #ifdef WITH_OPENEXR - if (format == R_IMF_IMTYPE_OPENEXR) { /* OpenEXR 32-bit float */ + if (format == R_IMF_IMTYPE_OPENEXR) { /* OpenEXR 32-bit float */ ibuf->ftype = OPENEXR | OPENEXR_COMPRESS; } #endif @@ -2680,7 +2681,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filenam /***************************** Material / Texture Sampling ******************************/ /* stores a copy of required materials to allow doing adjustments -* without interfering the render/preview */ + * without interfering the render/preview */ typedef struct BrushMaterials { Material *mat; Material **ob_mats; @@ -2688,24 +2689,24 @@ typedef struct BrushMaterials { } BrushMaterials; /* Initialize materials for brush object: -* Calculates inverse matrices for linked objects, updates -* volume caches etc. */ + * Calculates inverse matrices for linked objects, updates + * volume caches etc. */ static void dynamicPaint_updateBrushMaterials(Object *brushOb, Material *ui_mat, Scene *scene, BrushMaterials *bMats) { /* Calculate inverse transformation matrix - * for this object */ + * for this object */ invert_m4_m4(brushOb->imat, brushOb->obmat); copy_m4_m4(brushOb->imat_ren, brushOb->imat); /* Now process every material linked to this brush object */ if ((ui_mat == NULL) && brushOb->mat && brushOb->totcol) { - int i, tot=(*give_totcolp(brushOb)); + int i, tot = (*give_totcolp(brushOb)); /* allocate material pointer array */ if (tot) { - bMats->ob_mats = MEM_callocN(sizeof(Material*)*(tot), "BrushMaterials"); - for (i=0; i<tot; i++) { - bMats->ob_mats[i] = RE_init_sample_material(give_current_material(brushOb, (i+1)), scene); + bMats->ob_mats = MEM_callocN(sizeof(Material *) * (tot), "BrushMaterials"); + for (i = 0; i < tot; i++) { + bMats->ob_mats[i] = RE_init_sample_material(give_current_material(brushOb, (i + 1)), scene); } } bMats->tot = tot; @@ -2721,7 +2722,7 @@ static void dynamicPaint_freeBrushMaterials(BrushMaterials *bMats) /* Now process every material linked to this brush object */ if (bMats->ob_mats) { int i; - for (i=0; i<bMats->tot; i++) { + for (i = 0; i < bMats->tot; i++) { RE_free_sample_material(bMats->ob_mats[i]); } MEM_freeN(bMats->ob_mats); @@ -2732,8 +2733,8 @@ static void dynamicPaint_freeBrushMaterials(BrushMaterials *bMats) } /* -* Get material diffuse color and alpha (including linked textures) in given coordinates -*/ + * Get material diffuse color and alpha (including linked textures) in given coordinates + */ void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], float *alpha, Object *brushOb, const float volume_co[3], const float surface_co[3], int faceIndex, short isQuad, DerivedMesh *orcoDm) { Material *mat = bMats->mat; @@ -2745,7 +2746,7 @@ void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], float *al int mat_nr = mface[faceIndex].mat_nr; if (mat_nr >= (*give_totcolp(brushOb))) return; mat = bMats->ob_mats[mat_nr]; - if (mat == NULL) return; /* No material assigned */ + if (mat == NULL) return; /* No material assigned */ } else return; } @@ -2758,26 +2759,25 @@ void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], float *al /* A modified callback to bvh tree raycast. The tree must bust have been built using bvhtree_from_mesh_faces. -* userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. -* -* To optimize brush detection speed this doesn't calculate hit coordinates or normal. -* If ray hit the second half of a quad, no[0] is set to 1.0f. -*/ + * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. + * + * To optimize brush detection speed this doesn't calculate hit coordinates or normal. + * If ray hit the second half of a quad, no[0] is set to 1.0f. + */ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) { - const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; - MVert *vert = data->vert; + const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata; + MVert *vert = data->vert; MFace *face = data->face + index; short quad = 0; float *t0, *t1, *t2, *t3; - t0 = vert[ face->v1 ].co; - t1 = vert[ face->v2 ].co; - t2 = vert[ face->v3 ].co; - t3 = face->v4 ? vert[ face->v4].co : NULL; + t0 = vert[face->v1].co; + t1 = vert[face->v2].co; + t2 = vert[face->v3].co; + t3 = face->v4 ? vert[face->v4].co : NULL; - do - { + do { float dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2); if (dist >= 0 && dist < hit->dist) { @@ -2795,26 +2795,25 @@ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay } /* A modified callback to bvh tree nearest point. The tree must bust have been built using bvhtree_from_mesh_faces. -* userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. -* -* To optimize brush detection speed this doesn't calculate hit normal. -* If ray hit the second half of a quad, no[0] is set to 1.0f, else 0.0f -*/ + * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. + * + * To optimize brush detection speed this doesn't calculate hit normal. + * If ray hit the second half of a quad, no[0] is set to 1.0f, else 0.0f + */ static void mesh_faces_nearest_point_dp(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) { - const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; - MVert *vert = data->vert; + const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata; + MVert *vert = data->vert; MFace *face = data->face + index; short quad = 0; float *t0, *t1, *t2, *t3; - t0 = vert[ face->v1 ].co; - t1 = vert[ face->v2 ].co; - t2 = vert[ face->v3 ].co; - t3 = face->v4 ? vert[ face->v4].co : NULL; + t0 = vert[face->v1].co; + t1 = vert[face->v2].co; + t2 = vert[face->v3].co; + t3 = face->v4 ? vert[face->v4].co : NULL; - do - { + do { float nearest_tmp[3], dist; int vertex, edge; @@ -2838,18 +2837,19 @@ static void mesh_faces_nearest_point_dp(void *userdata, int index, const float c /***************************** Brush Painting Calls ******************************/ /* -* Mix color values to canvas point. -* -* surface : canvas surface -* index : surface point index -* paintFlags : paint object flags -* paintColor,Alpha,Wetness : to be mixed paint values -* timescale : value used to adjust time dependand -* operations when using substeps -*/ -static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, int paintFlags, float *paintColor, float *paintAlpha, float *paintWetness, float *timescale) + * Mix color values to canvas point. + * + * surface : canvas surface + * index : surface point index + * paintFlags : paint object flags + * paintColor,Alpha,Wetness : to be mixed paint values + * timescale : value used to adjust time dependand + * operations when using substeps + */ +static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, int paintFlags, + const float paintColor[3], float *paintAlpha, float *paintWetness, float *timescale) { - PaintPoint *pPoint = &((PaintPoint*)surface->data->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)surface->data->type_data)[index]; /* Add paint */ if (!(paintFlags & MOD_DPAINT_ERASE)) { @@ -2870,10 +2870,10 @@ static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, float wetness = (*paintWetness); CLAMP(wetness, 0.0f, 1.0f); pPoint->e_alpha = mix[3]; - pPoint->wetness = pPoint->wetness*(1.0f-wetness) + wetness; + pPoint->wetness = pPoint->wetness * (1.0f - wetness) + wetness; } - if (pPoint->wetness<MIN_WETNESS) pPoint->wetness = MIN_WETNESS; + if (pPoint->wetness < MIN_WETNESS) pPoint->wetness = MIN_WETNESS; pPoint->state = DPAINT_PAINT_NEW; } @@ -2884,9 +2884,9 @@ static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, float invFact = 1.0f - (*paintAlpha); /* - * Make highest alpha to match erased value - * but maintain alpha ratio - */ + * Make highest alpha to match erased value + * but maintain alpha ratio + */ if (paintFlags & MOD_DPAINT_ABS_ALPHA) { a_highest = (pPoint->e_alpha > pPoint->alpha) ? pPoint->e_alpha : pPoint->alpha; if (a_highest > invFact) { @@ -2937,100 +2937,100 @@ static void dynamicPaint_mixWaveHeight(PaintWavePoint *wPoint, DynamicPaintBrush wPoint->state = DPAINT_WAVE_REFLECT_ONLY; else if (brush->wave_type == MOD_DPAINT_WAVEB_CHANGE) { if (isect_change < 0.0f) - wPoint->height += isect_change*brush->wave_factor; + wPoint->height += isect_change * brush->wave_factor; } } } /* -* add brush results to the surface data depending on surface type -*/ + * add brush results to the surface data depending on surface type + */ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned int index, DynamicPaintBrushSettings *brush, - float paint[3], float influence, float depth, float vel_factor, float timescale) + float paint[3], float influence, float depth, float vel_factor, float timescale) { - PaintSurfaceData *sData = surface->data; - float strength; - - /* apply influence scale */ - influence *= surface->influence_scale; - depth *= surface->influence_scale; - - strength = influence * brush->alpha; - CLAMP(strength, 0.0f, 1.0f); - - /* Sample velocity colorband if required */ - if (brush->flags & (MOD_DPAINT_VELOCITY_ALPHA|MOD_DPAINT_VELOCITY_COLOR|MOD_DPAINT_VELOCITY_DEPTH)) { - float coba_res[4]; - vel_factor /= brush->max_velocity; - CLAMP(vel_factor, 0.0f, 1.0f); - - if (do_colorband(brush->vel_ramp, vel_factor, coba_res)) { - if (brush->flags & MOD_DPAINT_VELOCITY_COLOR) { - paint[0] = coba_res[0]; - paint[1] = coba_res[1]; - paint[2] = coba_res[2]; - } - if (brush->flags & MOD_DPAINT_VELOCITY_ALPHA) - strength *= coba_res[3]; - if (brush->flags & MOD_DPAINT_VELOCITY_DEPTH) - depth *= coba_res[3]; + PaintSurfaceData *sData = surface->data; + float strength; + + /* apply influence scale */ + influence *= surface->influence_scale; + depth *= surface->influence_scale; + + strength = influence * brush->alpha; + CLAMP(strength, 0.0f, 1.0f); + + /* Sample velocity colorband if required */ + if (brush->flags & (MOD_DPAINT_VELOCITY_ALPHA | MOD_DPAINT_VELOCITY_COLOR | MOD_DPAINT_VELOCITY_DEPTH)) { + float coba_res[4]; + vel_factor /= brush->max_velocity; + CLAMP(vel_factor, 0.0f, 1.0f); + + if (do_colorband(brush->vel_ramp, vel_factor, coba_res)) { + if (brush->flags & MOD_DPAINT_VELOCITY_COLOR) { + paint[0] = coba_res[0]; + paint[1] = coba_res[1]; + paint[2] = coba_res[2]; } + if (brush->flags & MOD_DPAINT_VELOCITY_ALPHA) + strength *= coba_res[3]; + if (brush->flags & MOD_DPAINT_VELOCITY_DEPTH) + depth *= coba_res[3]; } + } - /* mix paint surface */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - - float paintWetness = brush->wetness * strength; - float paintAlpha = strength; + /* mix paint surface */ + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - dynamicPaint_mixPaintColors(surface, index, brush->flags, paint, &paintAlpha, &paintWetness, ×cale); + float paintWetness = brush->wetness * strength; + float paintAlpha = strength; - } - /* displace surface */ - else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { - float *value = (float*)sData->type_data; + dynamicPaint_mixPaintColors(surface, index, brush->flags, paint, &paintAlpha, &paintWetness, ×cale); - if (surface->flags & MOD_DPAINT_DISP_INCREMENTAL) - depth = value[index] + depth; + } + /* displace surface */ + else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { + float *value = (float *)sData->type_data; - if (surface->depth_clamp) { - CLAMP(depth, 0.0f-surface->depth_clamp, surface->depth_clamp); - } + if (surface->flags & MOD_DPAINT_DISP_INCREMENTAL) + depth = value[index] + depth; - if (brush->flags & MOD_DPAINT_ERASE) { - value[index] *= (1.0f - strength); - if (value[index] < 0.0f) value[index] = 0.0f; - } - else { - if (value[index] < depth) value[index] = depth; - } + if (surface->depth_clamp) { + CLAMP(depth, 0.0f - surface->depth_clamp, surface->depth_clamp); } - /* vertex weight group surface */ - else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { - float *value = (float*)sData->type_data; - if (brush->flags & MOD_DPAINT_ERASE) { - value[index] *= (1.0f - strength); - if (value[index] < 0.0f) value[index] = 0.0f; - } - else { - if (value[index] < strength) value[index] = strength; - } + if (brush->flags & MOD_DPAINT_ERASE) { + value[index] *= (1.0f - strength); + if (value[index] < 0.0f) value[index] = 0.0f; } - /* wave surface */ - else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { - if (brush->wave_clamp) { - CLAMP(depth, 0.0f-brush->wave_clamp, brush->wave_clamp); - } - - dynamicPaint_mixWaveHeight(&((PaintWavePoint*)sData->type_data)[index], - brush, 0.0f-depth); + else { + if (value[index] < depth) value[index] = depth; } + } + /* vertex weight group surface */ + else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { + float *value = (float *)sData->type_data; - /* doing velocity based painting */ - if (sData->bData->brush_velocity) { - sData->bData->brush_velocity[index*4+3] *= influence; + if (brush->flags & MOD_DPAINT_ERASE) { + value[index] *= (1.0f - strength); + if (value[index] < 0.0f) value[index] = 0.0f; + } + else { + if (value[index] < strength) value[index] = strength; + } + } + /* wave surface */ + else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { + if (brush->wave_clamp) { + CLAMP(depth, 0.0f - brush->wave_clamp, brush->wave_clamp); } + + dynamicPaint_mixWaveHeight(&((PaintWavePoint *)sData->type_data)[index], + brush, 0.0f - depth); + } + + /* doing velocity based painting */ + if (sData->bData->brush_velocity) { + sData->bData->brush_velocity[index * 4 + 3] *= influence; + } } /* checks whether surface and brush bounds intersect depending on brush type */ @@ -3081,17 +3081,17 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy numOfVerts_c = dm_c->getNumVerts(dm_c); mvert_c = dm_p->getVertArray(dm_c); - (*brushVel) = (struct Vec3f *) MEM_mallocN(numOfVerts_c*sizeof(Vec3f), "Dynamic Paint brush velocity"); + (*brushVel) = (struct Vec3f *) MEM_mallocN(numOfVerts_c * sizeof(Vec3f), "Dynamic Paint brush velocity"); if (!(*brushVel)) return; /* if mesh is constructive -> num of verts has changed, - * only use current frame derived mesh */ + * only use current frame derived mesh */ if (numOfVerts_p != numOfVerts_c) mvert_p = mvert_c; /* calculate speed */ #pragma omp parallel for schedule(static) - for (i=0; i<numOfVerts_c; i++) { + for (i = 0; i < numOfVerts_c; i++) { float p1[3], p2[3]; copy_v3_v3(p1, mvert_p[i].co); @@ -3101,7 +3101,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy mul_m4_v3(ob->obmat, p2); sub_v3_v3v3((*brushVel)[i].v, p2, p1); - mul_v3_fl((*brushVel)[i].v, 1.0f/timescale); + mul_v3_fl((*brushVel)[i].v, 1.0f / timescale); } dm_p->release(dm_p); @@ -3139,12 +3139,12 @@ static void dynamicPaint_brushObjectCalculateVelocity(Scene *scene, Object *ob, mul_m4_v3(ob->obmat, cur_loc); sub_v3_v3v3(brushVel->v, cur_loc, prev_loc); - mul_v3_fl(brushVel->v, 1.0f/timescale); + mul_v3_fl(brushVel->v, 1.0f / timescale); } /* -* Paint a brush object mesh to the surface -*/ + * Paint a brush object mesh to the surface + */ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, DynamicPaintBrushSettings *brush, Object *brushOb, @@ -3178,9 +3178,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, numOfVerts = dm->getNumVerts(dm); /* Transform collider vertices to global space - * (Faster than transforming per surface point - * coordinates and normals to object space) */ - for (ii=0; ii<numOfVerts; ii++) { + * (Faster than transforming per surface point + * coordinates and normals to object space) */ + for (ii = 0; ii < numOfVerts; ii++) { mul_m4_v3(brushOb->obmat, mvert[ii].co); boundInsert(&mesh_bb, mvert[ii].co); @@ -3196,7 +3196,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } if (brush->flags & MOD_DPAINT_PROX_PROJECT && brush->collision != MOD_DPAINT_COL_VOLUME) { - mul_v3_fl(avg_brushNor, 1.0f/(float)numOfVerts); + mul_v3_fl(avg_brushNor, 1.0f / (float)numOfVerts); /* instead of null vector use positive z */ if (!(MIN3(avg_brushNor[0], avg_brushNor[1], avg_brushNor[2]))) avg_brushNor[2] = 1.0f; @@ -3205,316 +3205,318 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } /* check bounding box collision */ - if (grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush, brush_radius)) - /* Build a bvh tree from transformed vertices */ - if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8)) { - int c_index; - int total_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; - - /* loop through space partitioning grid */ - for (c_index=0; c_index<total_cells; c_index++) { - int id; + if (grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush, brush_radius)) { + /* Build a bvh tree from transformed vertices */ + if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8)) { + int c_index; + int total_cells = grid->dim[0] * grid->dim[1] * grid->dim[2]; + + /* loop through space partitioning grid */ + for (c_index = 0; c_index < total_cells; c_index++) { + int id; - /* check grid cell bounding box */ - if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius)) - continue; + /* check grid cell bounding box */ + if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius)) + continue; - /* loop through cell points and process brush */ + /* loop through cell points and process brush */ #pragma omp parallel for schedule(static) - for (id = 0; id < grid->s_num[c_index]; id++) { - int index = grid->t_index[grid->s_pos[c_index] + id]; - int ss, samples = bData->s_num[index]; - float total_sample = (float)samples; - float brushStrength = 0.0f; /* brush influence factor */ - float depth = 0.0f; /* brush intersection depth */ - float velocity_val = 0.0f; - - float paintColor[3] = {0.0f}; - int numOfHits = 0; - - /* for image sequence anti-aliasing, use gaussian factors */ - if (samples > 1 && surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) - total_sample = gaussianTotal; - - /* Supersampling */ - for (ss=0; ss<samples; ss++) { - - float ray_start[3], ray_dir[3]; - float sample_factor = 0.0f; - float sampleStrength = 0.0f; - BVHTreeRayHit hit; - BVHTreeNearest nearest; - short hit_found = 0; - - /* volume sample */ - float volume_factor = 0.0f; - /* proximity sample */ - float proximity_factor = 0.0f; - float prox_colorband[4] = {0.0f}; - int inner_proximity = (brush->flags & MOD_DPAINT_INVERSE_PROX && - brush->collision == MOD_DPAINT_COL_VOLDIST); - - /* hit data */ - float hitCoord[3]; - int hitFace = -1; - short hitQuad = 0; - - /* Supersampling factor */ + for (id = 0; id < grid->s_num[c_index]; id++) { + int index = grid->t_index[grid->s_pos[c_index] + id]; + int ss, samples = bData->s_num[index]; + float total_sample = (float)samples; + float brushStrength = 0.0f; /* brush influence factor */ + float depth = 0.0f; /* brush intersection depth */ + float velocity_val = 0.0f; + + float paintColor[3] = {0.0f}; + int numOfHits = 0; + + /* for image sequence anti-aliasing, use gaussian factors */ if (samples > 1 && surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) - sample_factor = gaussianFactors[ss]; - else - sample_factor = 1.0f; - - /* Get current sample position in world coordinates */ - copy_v3_v3(ray_start, bData->realCoord[bData->s_pos[index]+ss].v); - copy_v3_v3(ray_dir, bData->bNormal[index].invNorm); - - /* a simple hack to minimize chance of ray leaks at identical ray <-> edge locations */ - add_v3_fl(ray_start, 0.001f); - - hit.index = -1; - hit.dist = 9999; - nearest.index = -1; - nearest.dist = brush_radius * brush_radius; /* find_nearest uses squared distance */ - - /* Check volume collision */ - if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST) - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { - /* We hit a triangle, now check if collision point normal is facing the point */ - - /* For optimization sake, hit point normal isn't calculated in ray cast loop */ - int v1=mface[hit.index].v1, v2=mface[hit.index].v2, v3=mface[hit.index].v3, quad=(hit.no[0] == 1.0f); - float dot; - - if (quad) {v2=mface[hit.index].v3; v3=mface[hit.index].v4;} - normal_tri_v3(hit.no, mvert[v1].co, mvert[v2].co, mvert[v3].co); - dot = ray_dir[0]*hit.no[0] + ray_dir[1]*hit.no[1] + ray_dir[2]*hit.no[2]; - - /* If ray and hit face normal are facing same direction - * hit point is inside a closed mesh. */ - if (dot>=0) { - float dist = hit.dist; - int f_index = hit.index; - - /* Also cast a ray in opposite direction to make sure - * point is at least surrounded by two brush faces */ - negate_v3(ray_dir); - hit.index = -1; - hit.dist = 9999; - - BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData); - - if (hit.index != -1) { - /* Add factor on supersample filter */ - volume_factor = 1.0f; - hit_found = HIT_VOLUME; - - /* Mark hit info */ - madd_v3_v3v3fl(hitCoord, ray_start, ray_dir, hit.dist); /* Calculate final hit coordinates */ - depth += dist*sample_factor; - hitFace = f_index; - hitQuad = quad; - } - } - } + total_sample = gaussianTotal; - /* Check proximity collision */ - if ((brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST) && - (!hit_found || (brush->flags & MOD_DPAINT_INVERSE_PROX))) - { - float proxDist = -1.0f; - float hitCo[3]; - short hQuad; - int face; - - /* if inverse prox and no hit found, skip this sample */ - if (inner_proximity && !hit_found) continue; - - /* If pure distance proximity, find the nearest point on the mesh */ - if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) { - if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_faces_nearest_point_dp, &treeData) != -1) { - proxDist = sqrtf(nearest.dist); - copy_v3_v3(hitCo, nearest.co); - hQuad = (nearest.no[0] == 1.0f); - face = nearest.index; + /* Supersampling */ + for (ss = 0; ss < samples; ss++) { + + float ray_start[3], ray_dir[3]; + float sample_factor = 0.0f; + float sampleStrength = 0.0f; + BVHTreeRayHit hit; + BVHTreeNearest nearest; + short hit_found = 0; + + /* volume sample */ + float volume_factor = 0.0f; + /* proximity sample */ + float proximity_factor = 0.0f; + float prox_colorband[4] = {0.0f}; + int inner_proximity = (brush->flags & MOD_DPAINT_INVERSE_PROX && + brush->collision == MOD_DPAINT_COL_VOLDIST); + + /* hit data */ + float hitCoord[3]; + int hitFace = -1; + short hitQuad = 0; + + /* Supersampling factor */ + if (samples > 1 && surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) + sample_factor = gaussianFactors[ss]; + else + sample_factor = 1.0f; + + /* Get current sample position in world coordinates */ + copy_v3_v3(ray_start, bData->realCoord[bData->s_pos[index] + ss].v); + copy_v3_v3(ray_dir, bData->bNormal[index].invNorm); + + /* a simple hack to minimize chance of ray leaks at identical ray <-> edge locations */ + add_v3_fl(ray_start, 0.001f); + + hit.index = -1; + hit.dist = 9999; + nearest.index = -1; + nearest.dist = brush_radius * brush_radius; /* find_nearest uses squared distance */ + + /* Check volume collision */ + if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST) + if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { + /* We hit a triangle, now check if collision point normal is facing the point */ + + /* For optimization sake, hit point normal isn't calculated in ray cast loop */ + int v1 = mface[hit.index].v1, v2 = mface[hit.index].v2, v3 = mface[hit.index].v3, quad = (hit.no[0] == 1.0f); + float dot; + + if (quad) {v2 = mface[hit.index].v3; v3 = mface[hit.index].v4; } + normal_tri_v3(hit.no, mvert[v1].co, mvert[v2].co, mvert[v3].co); + dot = ray_dir[0] * hit.no[0] + ray_dir[1] * hit.no[1] + ray_dir[2] * hit.no[2]; + + /* If ray and hit face normal are facing same direction + * hit point is inside a closed mesh. */ + if (dot >= 0) { + float dist = hit.dist; + int f_index = hit.index; + + /* Also cast a ray in opposite direction to make sure + * point is at least surrounded by two brush faces */ + negate_v3(ray_dir); + hit.index = -1; + hit.dist = 9999; + + BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData); + + if (hit.index != -1) { + /* Add factor on supersample filter */ + volume_factor = 1.0f; + hit_found = HIT_VOLUME; + + /* Mark hit info */ + madd_v3_v3v3fl(hitCoord, ray_start, ray_dir, hit.dist); /* Calculate final hit coordinates */ + depth += dist * sample_factor; + hitFace = f_index; + hitQuad = quad; + } + } } - } - else { /* else cast a ray in defined projection direction */ - float proj_ray[3] = {0.0f}; - if (brush->ray_dir == MOD_DPAINT_RAY_CANVAS) { - copy_v3_v3(proj_ray, bData->bNormal[index].invNorm); - negate_v3(proj_ray); - } - else if (brush->ray_dir == MOD_DPAINT_RAY_BRUSH_AVG) { - copy_v3_v3(proj_ray, avg_brushNor); - } - else { /* MOD_DPAINT_RAY_ZPLUS */ - proj_ray[2] = 1.0f; + /* Check proximity collision */ + if ((brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST) && + (!hit_found || (brush->flags & MOD_DPAINT_INVERSE_PROX))) + { + float proxDist = -1.0f; + float hitCo[3]; + short hQuad; + int face; + + /* if inverse prox and no hit found, skip this sample */ + if (inner_proximity && !hit_found) continue; + + /* If pure distance proximity, find the nearest point on the mesh */ + if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) { + if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_faces_nearest_point_dp, &treeData) != -1) { + proxDist = sqrtf(nearest.dist); + copy_v3_v3(hitCo, nearest.co); + hQuad = (nearest.no[0] == 1.0f); + face = nearest.index; + } } - hit.index = -1; - hit.dist = brush_radius; - - /* Do a face normal directional raycast, and use that distance */ - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { - proxDist = hit.dist; - madd_v3_v3v3fl(hitCo, ray_start, proj_ray, hit.dist); /* Calculate final hit coordinates */ - hQuad = (hit.no[0] == 1.0f); - face = hit.index; + else { /* else cast a ray in defined projection direction */ + float proj_ray[3] = {0.0f}; + + if (brush->ray_dir == MOD_DPAINT_RAY_CANVAS) { + copy_v3_v3(proj_ray, bData->bNormal[index].invNorm); + negate_v3(proj_ray); + } + else if (brush->ray_dir == MOD_DPAINT_RAY_BRUSH_AVG) { + copy_v3_v3(proj_ray, avg_brushNor); + } + else { /* MOD_DPAINT_RAY_ZPLUS */ + proj_ray[2] = 1.0f; + } + hit.index = -1; + hit.dist = brush_radius; + + /* Do a face normal directional raycast, and use that distance */ + if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { + proxDist = hit.dist; + madd_v3_v3v3fl(hitCo, ray_start, proj_ray, hit.dist); /* Calculate final hit coordinates */ + hQuad = (hit.no[0] == 1.0f); + face = hit.index; + } } - } - /* If a hit was found, calculate required values */ - if (proxDist >= 0.0f && proxDist <= brush_radius) { - proximity_factor = proxDist / brush_radius; - CLAMP(proximity_factor, 0.0f, 1.0f); - if (!inner_proximity) - proximity_factor = 1.0f - proximity_factor; + /* If a hit was found, calculate required values */ + if (proxDist >= 0.0f && proxDist <= brush_radius) { + proximity_factor = proxDist / brush_radius; + CLAMP(proximity_factor, 0.0f, 1.0f); + if (!inner_proximity) + proximity_factor = 1.0f - proximity_factor; - hit_found = HIT_PROXIMITY; + hit_found = HIT_PROXIMITY; - /* if no volume hit, use prox point face info */ - if (hitFace == -1) { - copy_v3_v3(hitCoord, hitCo); - hitQuad = hQuad; - hitFace = face; + /* if no volume hit, use prox point face info */ + if (hitFace == -1) { + copy_v3_v3(hitCoord, hitCo); + hitQuad = hQuad; + hitFace = face; + } } } - } - /* mix final sample strength depending on brush settings */ - if (hit_found) { - /* if "negate volume" enabled, negate all factors within volume*/ - if (brush->collision == MOD_DPAINT_COL_VOLDIST && brush->flags & MOD_DPAINT_NEGATE_VOLUME) { - volume_factor = 1.0f - volume_factor; - if (inner_proximity) - proximity_factor = 1.0f - proximity_factor; - } + /* mix final sample strength depending on brush settings */ + if (hit_found) { + /* if "negate volume" enabled, negate all factors within volume*/ + if (brush->collision == MOD_DPAINT_COL_VOLDIST && brush->flags & MOD_DPAINT_NEGATE_VOLUME) { + volume_factor = 1.0f - volume_factor; + if (inner_proximity) + proximity_factor = 1.0f - proximity_factor; + } - /* apply final sample depending on final hit type */ - if (hit_found == HIT_VOLUME) { - sampleStrength = volume_factor; - } - else if (hit_found == HIT_PROXIMITY) { - /* apply falloff curve to the proximity_factor */ - if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f-proximity_factor), prox_colorband)) - proximity_factor = prox_colorband[3]; - else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_CONSTANT) - proximity_factor = (!inner_proximity || brush->flags & MOD_DPAINT_NEGATE_VOLUME) ? 1.0f : 0.0f; - /* apply sample */ - sampleStrength = proximity_factor; - } + /* apply final sample depending on final hit type */ + if (hit_found == HIT_VOLUME) { + sampleStrength = volume_factor; + } + else if (hit_found == HIT_PROXIMITY) { + /* apply falloff curve to the proximity_factor */ + if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f - proximity_factor), prox_colorband)) + proximity_factor = prox_colorband[3]; + else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_CONSTANT) + proximity_factor = (!inner_proximity || brush->flags & MOD_DPAINT_NEGATE_VOLUME) ? 1.0f : 0.0f; + /* apply sample */ + sampleStrength = proximity_factor; + } - sampleStrength *= sample_factor; - } - else continue; - - /* velocity brush, only do on main sample */ - if (brush->flags & MOD_DPAINT_USES_VELOCITY && ss==0 && brushVelocity) { - int v1, v2, v3; - float weights[4]; - float brushPointVelocity[3]; - float velocity[3]; - - if (!hitQuad) { - v1 = mface[hitFace].v1; - v2 = mface[hitFace].v2; - v3 = mface[hitFace].v3; - } - else { - v1 = mface[hitFace].v2; - v2 = mface[hitFace].v3; - v3 = mface[hitFace].v4; + sampleStrength *= sample_factor; } - /* calculate barycentric weights for hit point */ - interp_weights_face_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, NULL, hitCoord); + else continue; + + /* velocity brush, only do on main sample */ + if (brush->flags & MOD_DPAINT_USES_VELOCITY && ss == 0 && brushVelocity) { + int v1, v2, v3; + float weights[4]; + float brushPointVelocity[3]; + float velocity[3]; + + if (!hitQuad) { + v1 = mface[hitFace].v1; + v2 = mface[hitFace].v2; + v3 = mface[hitFace].v3; + } + else { + v1 = mface[hitFace].v2; + v2 = mface[hitFace].v3; + v3 = mface[hitFace].v4; + } + /* calculate barycentric weights for hit point */ + interp_weights_face_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, NULL, hitCoord); - /* simple check based on brush surface velocity, - * todo: perhaps implement something that handles volume movement as well */ + /* simple check based on brush surface velocity, + * todo: perhaps implement something that handles volume movement as well */ - /* interpolate vertex speed vectors to get hit point velocity */ - interp_v3_v3v3v3(brushPointVelocity, - brushVelocity[v1].v, - brushVelocity[v2].v, - brushVelocity[v3].v, weights); - - /* substract canvas point velocity */ - if (bData->velocity) { - sub_v3_v3v3(velocity, brushPointVelocity, bData->velocity[index].v); - } - else { - copy_v3_v3(velocity, brushPointVelocity); - } - velocity_val = len_v3(velocity); - - /* if brush has smudge enabled store brush velocity */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && - brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { - copy_v3_v3(&bData->brush_velocity[index*4], velocity); - mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); - bData->brush_velocity[index*4+3] = velocity_val; + /* interpolate vertex speed vectors to get hit point velocity */ + interp_v3_v3v3v3(brushPointVelocity, + brushVelocity[v1].v, + brushVelocity[v2].v, + brushVelocity[v3].v, weights); + + /* substract canvas point velocity */ + if (bData->velocity) { + sub_v3_v3v3(velocity, brushPointVelocity, bData->velocity[index].v); + } + else { + copy_v3_v3(velocity, brushPointVelocity); + } + velocity_val = len_v3(velocity); + + /* if brush has smudge enabled store brush velocity */ + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && + brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) + { + copy_v3_v3(&bData->brush_velocity[index * 4], velocity); + mul_v3_fl(&bData->brush_velocity[index * 4], 1.0f / velocity_val); + bData->brush_velocity[index * 4 + 3] = velocity_val; + } } - } - /* - * Process hit color and alpha - */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - float sampleColor[3]; - float alpha_factor = 1.0f; - - sampleColor[0] = brush->r; - sampleColor[1] = brush->g; - sampleColor[2] = brush->b; - - /* Get material+textures color on hit point if required */ - if (brush_usesMaterial(brush, scene)) - dynamicPaint_doMaterialTex(bMats, sampleColor, &alpha_factor, brushOb, bData->realCoord[bData->s_pos[index]+ss].v, hitCoord, hitFace, hitQuad, brush->dm); - - /* Sample proximity colorband if required */ - if ((hit_found == HIT_PROXIMITY) && (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP)) { - if (!(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { - sampleColor[0] = prox_colorband[0]; - sampleColor[1] = prox_colorband[1]; - sampleColor[2] = prox_colorband[2]; + /* + * Process hit color and alpha + */ + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { + float sampleColor[3]; + float alpha_factor = 1.0f; + + sampleColor[0] = brush->r; + sampleColor[1] = brush->g; + sampleColor[2] = brush->b; + + /* Get material+textures color on hit point if required */ + if (brush_usesMaterial(brush, scene)) + dynamicPaint_doMaterialTex(bMats, sampleColor, &alpha_factor, brushOb, bData->realCoord[bData->s_pos[index] + ss].v, hitCoord, hitFace, hitQuad, brush->dm); + + /* Sample proximity colorband if required */ + if ((hit_found == HIT_PROXIMITY) && (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP)) { + if (!(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { + sampleColor[0] = prox_colorband[0]; + sampleColor[1] = prox_colorband[1]; + sampleColor[2] = prox_colorband[2]; + } } + + /* Add AA sample */ + paintColor[0] += sampleColor[0]; + paintColor[1] += sampleColor[1]; + paintColor[2] += sampleColor[2]; + sampleStrength *= alpha_factor; + numOfHits++; } - /* Add AA sample */ - paintColor[0] += sampleColor[0]; - paintColor[1] += sampleColor[1]; - paintColor[2] += sampleColor[2]; - sampleStrength *= alpha_factor; - numOfHits++; - } + /* apply sample strength */ + brushStrength += sampleStrength; + } // end supersampling - /* apply sample strength */ - brushStrength += sampleStrength; - } // end supersampling + /* if any sample was inside paint range */ + if (brushStrength > 0.0f || depth > 0.0f) { - /* if any sample was inside paint range */ - if (brushStrength > 0.0f || depth > 0.0f) { + /* apply supersampling results */ + if (samples > 1) { + brushStrength /= total_sample; + } + CLAMP(brushStrength, 0.0f, 1.0f); - /* apply supersampling results */ - if (samples > 1) { - brushStrength /= total_sample; - } - CLAMP(brushStrength, 0.0f, 1.0f); + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { + /* Get final pixel color and alpha */ + paintColor[0] /= numOfHits; + paintColor[1] /= numOfHits; + paintColor[2] /= numOfHits; + } + /* get final object space depth */ + else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || + surface->type == MOD_DPAINT_SURFACE_T_WAVE) { + depth /= bData->bNormal[index].normal_scale * total_sample; + } - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - /* Get final pixel color and alpha */ - paintColor[0] /= numOfHits; - paintColor[1] /= numOfHits; - paintColor[2] /= numOfHits; + dynamicPaint_updatePointData(surface, index, brush, paintColor, brushStrength, depth, velocity_val, timescale); } - /* get final object space depth */ - else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) { - depth /= bData->bNormal[index].normal_scale * total_sample; - } - - dynamicPaint_updatePointData(surface, index, brush, paintColor, brushStrength, depth, velocity_val, timescale); } } } @@ -3533,14 +3535,14 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } /* -* Paint a particle system to the surface -*/ + * Paint a particle system to the surface + */ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, ParticleSystem *psys, DynamicPaintBrushSettings *brush, float timescale) { - ParticleSettings *part=psys->part; + ParticleSettings *part = psys->part; ParticleData *pa = NULL; PaintSurfaceData *sData = surface->data; PaintBakeData *bData = sData->bData; @@ -3551,8 +3553,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, int invalidParticles = 0; int p = 0; - float solidradius = surface->radius_scale*((brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius); - float smooth = brush->particle_smooth*surface->radius_scale; + float solidradius = surface->radius_scale * ((brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius); + float smooth = brush->particle_smooth * surface->radius_scale; float range = solidradius + smooth; float particle_timestep = 0.04f * part->timetweak; @@ -3562,21 +3564,21 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, if (psys->totpart < 1) return 1; /* - * Build a kd-tree to optimize distance search - */ - tree= BLI_kdtree_new(psys->totpart); + * Build a kd-tree to optimize distance search + */ + tree = BLI_kdtree_new(psys->totpart); /* loop through particles and insert valid ones to the tree */ - for (p=0, pa=psys->particles; p<psys->totpart; p++, pa++) { + for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++) { /* Proceed only if particle is active */ - if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0) continue; - else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0) continue; + if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) continue; + else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) continue; else if (pa->flag & PARS_UNEXIST) continue; /* for debug purposes check if any NAN particle proceeds - * For some reason they get past activity check, this should rule most of them out */ - if (isnan(pa->state.co[0]) || isnan(pa->state.co[1]) || isnan(pa->state.co[2])) {invalidParticles++;continue;} + * For some reason they get past activity check, this should rule most of them out */ + if (isnan(pa->state.co[0]) || isnan(pa->state.co[1]) || isnan(pa->state.co[2])) {invalidParticles++; continue; } /* make sure particle is close enough to canvas */ if (!boundIntersectPoint(&grid->grid_bounds, pa->state.co, range)) continue; @@ -3603,13 +3605,13 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* only continue if particle bb is close enough to canvas bb */ if (boundsIntersectDist(&grid->grid_bounds, &part_bb, range)) { int c_index; - int total_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; + int total_cells = grid->dim[0] * grid->dim[1] * grid->dim[2]; /* balance tree */ BLI_kdtree_balance(tree); /* loop through space partitioning grid */ - for (c_index=0; c_index<total_cells; c_index++) { + for (c_index = 0; c_index < total_cells; c_index++) { int id; /* check cell bounding box */ @@ -3627,12 +3629,12 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, float radius = 0.0f; float strength = 0.0f; float velocity_val = 0.0f; - int part_index= -1; + int part_index = -1; /* - * With predefined radius, there is no variation between particles. - * It's enough to just find the nearest one. - */ + * With predefined radius, there is no variation between particles. + * It's enough to just find the nearest one. + */ { KDTreeNearest nearest; float smooth_range, part_solidradius; @@ -3654,9 +3656,9 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, if (nearest.dist < radius) { /* distances inside solid radius has maximum influence -> dist = 0 */ smooth_range = (nearest.dist - part_solidradius); - if (smooth_range<0.0f) smooth_range=0.0f; + if (smooth_range < 0.0f) smooth_range = 0.0f; /* do smoothness if enabled */ - if (smooth) smooth_range/=smooth; + if (smooth) smooth_range /= smooth; strength = 1.0f - smooth_range; disp_intersect = radius - nearest.dist; @@ -3666,20 +3668,20 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* If using random per particle radius and closest particle didn't give max influence */ if (brush->flags & MOD_DPAINT_PART_RAD && strength < 1.0f && psys->part->randsize > 0.0f) { /* - * If we use per particle radius, we have to sample all particles - * within max radius range - */ + * If we use per particle radius, we have to sample all particles + * within max radius range + */ KDTreeNearest *nearest; int n, particles = 0; - float smooth_range = smooth * (1.0f-strength), dist; + float smooth_range = smooth * (1.0f - strength), dist; /* calculate max range that can have particles with higher influence than the nearest one */ - float max_range = smooth - strength*smooth + solidradius; + float max_range = smooth - strength * smooth + solidradius; particles = BLI_kdtree_range_search(tree, max_range, bData->realCoord[bData->s_pos[index]].v, NULL, &nearest); /* Find particle that produces highest influence */ - for (n=0; n<particles; n++) { + for (n = 0; n < particles; n++) { ParticleData *pa = psys->particles + nearest[n].index; float s_range; @@ -3712,14 +3714,14 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* now calculate influence for this particle */ { float rad = radius + smooth, str; - if ((rad-dist) > disp_intersect) { + if ((rad - dist) > disp_intersect) { disp_intersect = radius - dist; radius = rad; } /* do smoothness if enabled */ - if (smooth_range<0.0f) smooth_range=0.0f; - if (smooth) smooth_range/=smooth; + if (smooth_range < 0.0f) smooth_range = 0.0f; + if (smooth) smooth_range /= smooth; str = 1.0f - smooth_range; /* if influence is greater, use this one */ if (str > strength) strength = str; @@ -3746,9 +3748,9 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, if ( (surface->type == MOD_DPAINT_SURFACE_T_PAINT) && (brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity)) { - copy_v3_v3(&bData->brush_velocity[index*4], velocity); - mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); - bData->brush_velocity[index*4+3] = velocity_val; + copy_v3_v3(&bData->brush_velocity[index * 4], velocity); + mul_v3_fl(&bData->brush_velocity[index * 4], 1.0f / velocity_val); + bData->brush_velocity[index * 4 + 3] = velocity_val; } } @@ -3758,10 +3760,10 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, else if ( (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) || (surface->type == MOD_DPAINT_SURFACE_T_WAVE)) { - /* get displace depth */ + /* get displace depth */ disp_intersect = (1.0f - sqrtf(disp_intersect / radius)) * radius; depth = (radius - disp_intersect) / bData->bNormal[index].normal_scale; - if (depth<0.0f) depth = 0.0f; + if (depth < 0.0f) depth = 0.0f; } dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale); @@ -3789,8 +3791,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po dynamicPaint_brushObjectCalculateVelocity(scene, brushOb, &brushVel, timescale); /* - * Loop through every surface point - */ + * Loop through every surface point + */ #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { float distance = len_v3v3(pointCoord, bData->realCoord[bData->s_pos[index]].v); @@ -3801,7 +3803,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po /* Smooth range or color ramp */ if (brush->proximity_falloff == MOD_DPAINT_PRFALL_SMOOTH || - brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP) { + brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP) { strength = 1.0f - distance / brush_radius; CLAMP(strength, 0.0f, 1.0f); @@ -3826,7 +3828,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po } /* color ramp */ - if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f-strength), colorband)) + if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f - strength), colorband)) strength = colorband[3]; if (brush->flags & MOD_DPAINT_USES_VELOCITY) { @@ -3843,16 +3845,17 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po /* store brush velocity for smudge */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && - brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { - copy_v3_v3(&bData->brush_velocity[index*4], velocity); - mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); - bData->brush_velocity[index*4+3] = velocity_val; + brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) + { + copy_v3_v3(&bData->brush_velocity[index * 4], velocity); + mul_v3_fl(&bData->brush_velocity[index * 4], 1.0f / velocity_val); + bData->brush_velocity[index * 4 + 3] = velocity_val; } } if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && - !(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { + !(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { paintColor[0] = colorband[0]; paintColor[1] = colorband[1]; paintColor[2] = colorband[2]; @@ -3866,11 +3869,12 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po } } else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) { - /* get displace depth */ - float disp_intersect = (1.0f - sqrtf((brush_radius-distance) / brush_radius)) * brush_radius; + surface->type == MOD_DPAINT_SURFACE_T_WAVE) + { + /* get displace depth */ + float disp_intersect = (1.0f - sqrtf((brush_radius - distance) / brush_radius)) * brush_radius; depth = (brush_radius - disp_intersect) / bData->bNormal[index].normal_scale; - if (depth<0.0f) depth = 0.0f; + if (depth < 0.0f) depth = 0.0f; } dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale); } @@ -3883,8 +3887,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po /***************************** Dynamic Paint Step / Baking ******************************/ /* -* Calculate current frame distances and directions for adjacency data -*/ + * Calculate current frame distances and directions for adjacency data + */ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int force_init) { PaintSurfaceData *sData = surface->data; @@ -3897,7 +3901,7 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int if ((!surface_usesAdjDistance(surface) && !force_init) || !sData->adj_data) return; if (bData->bNeighs) MEM_freeN(bData->bNeighs); - bNeighs = bData->bNeighs = MEM_mallocN(sData->adj_data->total_targets*sizeof(struct BakeAdjPoint), "PaintEffectBake"); + bNeighs = bData->bNeighs = MEM_mallocN(sData->adj_data->total_targets * sizeof(struct BakeAdjPoint), "PaintEffectBake"); if (!bNeighs) return; #pragma omp parallel for schedule(static) @@ -3905,8 +3909,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int int i; int numOfNeighs = adj_data->n_num[index]; - for (i=0; i<numOfNeighs; i++) { - int n_index = adj_data->n_index[index]+i; + for (i = 0; i < numOfNeighs; i++) { + int n_index = adj_data->n_index[index] + i; int t_index = adj_data->n_target[n_index]; /* dir vec */ @@ -3914,7 +3918,7 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int /* dist */ bNeighs[n_index].dist = len_v3(bNeighs[n_index].dir); /* normalize dir */ - if (bNeighs[n_index].dist) mul_v3_fl(bNeighs[n_index].dir, 1.0f/bNeighs[n_index].dist); + if (bNeighs[n_index].dist) mul_v3_fl(bNeighs[n_index].dir, 1.0f / bNeighs[n_index].dist); } } @@ -3924,8 +3928,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int int i; int numOfNeighs = adj_data->n_num[index]; - for (i=0; i<numOfNeighs; i++) { - bData->average_dist += (double)bNeighs[adj_data->n_index[index]+i].dist; + for (i = 0; i < numOfNeighs; i++) { + bData->average_dist += (double)bNeighs[adj_data->n_index[index] + i].dist; } } bData->average_dist /= adj_data->total_targets; @@ -3938,34 +3942,36 @@ void surface_determineForceTargetPoints(PaintSurfaceData *sData, int index, floa int numOfNeighs = sData->adj_data->n_num[index]; int i; - closest_id[0]=closest_id[1]= -1; - closest_d[0]=closest_d[1]= -1.0f; + closest_id[0] = closest_id[1] = -1; + closest_d[0] = closest_d[1] = -1.0f; /* find closest neigh */ - for (i=0; i<numOfNeighs; i++) { - int n_index = sData->adj_data->n_index[index]+i; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; float dir_dot = dot_v3v3(bNeighs[n_index].dir, force); - if (dir_dot>closest_d[0] && dir_dot>0.0f) {closest_d[0]=dir_dot; closest_id[0]=n_index;} + if (dir_dot > closest_d[0] && dir_dot > 0.0f) {closest_d[0] = dir_dot; closest_id[0] = n_index; } } if (closest_d[0] < 0.0f) return; /* find second closest neigh */ - for (i=0; i<numOfNeighs; i++) { - int n_index = sData->adj_data->n_index[index]+i; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; float dir_dot = dot_v3v3(bNeighs[n_index].dir, force); float closest_dot = dot_v3v3(bNeighs[n_index].dir, bNeighs[closest_id[0]].dir); if (n_index == closest_id[0]) continue; /* only accept neighbor at "other side" of the first one in relation to force dir - * so make sure angle between this and closest neigh is greater than first angle */ - if (dir_dot>closest_d[1] && closest_dot<closest_d[0] && dir_dot>0.0f) {closest_d[1]=dir_dot; closest_id[1]=n_index;} + * so make sure angle between this and closest neigh is greater than first angle */ + if (dir_dot > closest_d[1] && closest_dot < closest_d[0] && dir_dot > 0.0f) { + closest_d[1] = dir_dot; closest_id[1] = n_index; + } } /* if two valid neighs found, calculate how force effect is divided - * evenly between them (so that d[0]+d[1] = 1.0)*/ + * evenly between them (so that d[0]+d[1] = 1.0)*/ if (closest_id[1] != -1) { float force_proj[3]; float tangent[3]; @@ -3974,28 +3980,27 @@ void surface_determineForceTargetPoints(PaintSurfaceData *sData, int index, floa float temp; /* project force vector on the plane determined by these two neightbour points - * and calculate relative force angle from it*/ + * and calculate relative force angle from it*/ cross_v3_v3v3(tangent, bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir); normalize_v3(tangent); force_intersect = dot_v3v3(force, tangent); - madd_v3_v3v3fl(force_proj, force, tangent, (-1.0f)*force_intersect); + madd_v3_v3v3fl(force_proj, force, tangent, (-1.0f) * force_intersect); normalize_v3(force_proj); /* get drip factor based on force dir in relation to angle between those neighbors */ temp = dot_v3v3(bNeighs[closest_id[0]].dir, force_proj); CLAMP(temp, -1.0f, 1.0f); /* float precision might cause values > 1.0f that return infinite */ - closest_d[1] = acosf(temp)/neigh_diff; + closest_d[1] = acosf(temp) / neigh_diff; closest_d[0] = 1.0f - closest_d[1]; /* and multiply depending on how deeply force intersects surface */ temp = fabs(force_intersect); CLAMP(temp, 0.0f, 1.0f); - closest_d[0] *= acosf(temp)/1.57079633f; - closest_d[1] *= acosf(temp)/1.57079633f; + mul_v2_fl(closest_d, acosf(temp) / (float)M_PI_2); } else { /* if only single neighbor, still linearize force intersection effect */ - closest_d[0] = 1.0f - acosf(closest_d[0])/1.57079633f; + closest_d[0] = 1.0f - acosf(closest_d[0]) / (float)M_PI_2; } } @@ -4011,20 +4016,20 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus /* find max velocity */ for (index = 0; index < sData->total_points; index++) { - float vel = bData->brush_velocity[index*4+3]; + float vel = bData->brush_velocity[index * 4 + 3]; if (vel > max_velocity) max_velocity = vel; } steps = (int)ceil(max_velocity / bData->average_dist * timescale); CLAMP(steps, 0, 12); - eff_scale = brush->smudge_strength/(float)steps*timescale; + eff_scale = brush->smudge_strength / (float)steps * timescale; - for (step=0; step<steps; step++) { + for (step = 0; step < steps; step++) { for (index = 0; index < sData->total_points; index++) { int i; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; - float smudge_str = bData->brush_velocity[index*4+3]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; + float smudge_str = bData->brush_velocity[index * 4 + 3]; /* force targets */ int closest_id[2]; @@ -4033,15 +4038,15 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus if (!smudge_str) continue; /* get force affect points */ - surface_determineForceTargetPoints(sData, index, &bData->brush_velocity[index*4], closest_d, closest_id); + surface_determineForceTargetPoints(sData, index, &bData->brush_velocity[index * 4], closest_d, closest_id); /* Apply movement towards those two points */ - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) { int n_index = closest_id[i]; - if (n_index != -1 && closest_d[i]>0.0f) { + if (n_index != -1 && closest_d[i] > 0.0f) { float dir_dot = closest_d[i], dir_factor; - float speed_scale = eff_scale*smudge_str/bNeighs[n_index].dist; - PaintPoint *ePoint = &((PaintPoint*)sData->type_data)[sData->adj_data->n_target[n_index]]; + float speed_scale = eff_scale * smudge_str / bNeighs[n_index].dist; + PaintPoint *ePoint = &((PaintPoint *)sData->type_data)[sData->adj_data->n_target[n_index]]; /* just skip if angle is too extreme */ if (dir_dot <= 0.0f) continue; @@ -4051,12 +4056,12 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus /* mix new color and alpha */ mixColors(ePoint->color, ePoint->alpha, pPoint->color, pPoint->alpha, dir_factor); - ePoint->alpha = ePoint->alpha*(1.0f-dir_factor) + pPoint->alpha*dir_factor; + ePoint->alpha = ePoint->alpha * (1.0f - dir_factor) + pPoint->alpha * dir_factor; /* smudge "wet layer" */ mixColors(ePoint->e_color, ePoint->e_alpha, pPoint->e_color, pPoint->e_alpha, dir_factor); - ePoint->e_alpha = ePoint->e_alpha*(1.0f-dir_factor) + pPoint->e_alpha*dir_factor; - pPoint->wetness *= (1.0f-dir_factor); + ePoint->e_alpha = ePoint->e_alpha * (1.0f - dir_factor) + pPoint->e_alpha * dir_factor; + pPoint->wetness *= (1.0f - dir_factor); } } } @@ -4064,13 +4069,13 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus } /* -* Prepare data required by effects for current frame. -* Returns number of steps required -*/ + * Prepare data required by effects for current frame. + * Returns number of steps required + */ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale) { double average_force = 0.0f; - float shrink_speed=0.0f, spread_speed=0.0f; + float shrink_speed = 0.0f, spread_speed = 0.0f; float fastest_effect, avg_dist; int steps; PaintSurfaceData *sData = surface->data; @@ -4084,7 +4089,7 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s ListBase *effectors = pdInitEffectors(scene, ob, NULL, surface->effector_weights); /* allocate memory for force data (dir vector + strength) */ - *force = MEM_mallocN(sData->total_points*4*sizeof(float), "PaintEffectForces"); + *force = MEM_mallocN(sData->total_points * 4 * sizeof(float), "PaintEffectForces"); if (*force) { #pragma omp parallel for schedule(static) @@ -4102,34 +4107,34 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s /* if global gravity is enabled, add it too */ if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) /* also divide by 10 to about match default grav - * with default force strength (1.0) */ + * with default force strength (1.0) */ madd_v3_v3fl(forc, scene->physics_settings.gravity, - surface->effector_weights->global_gravity*surface->effector_weights->weight[0] / 10.f); + surface->effector_weights->global_gravity * surface->effector_weights->weight[0] / 10.f); /* add surface point velocity and acceleration if enabled */ if (bData->velocity) { if (surface->drip_vel) - madd_v3_v3fl(forc, bData->velocity[index].v, surface->drip_vel*(-1.0f)); + madd_v3_v3fl(forc, bData->velocity[index].v, surface->drip_vel * (-1.0f)); /* acceleration */ if (bData->prev_velocity && surface->drip_acc) { float acc[3]; copy_v3_v3(acc, bData->velocity[index].v); sub_v3_v3(acc, bData->prev_velocity[index].v); - madd_v3_v3fl(forc, acc, surface->drip_acc*(-1.0f)); + madd_v3_v3fl(forc, acc, surface->drip_acc * (-1.0f)); } } /* force strength */ - (*force)[index*4+3] = len_v3(forc); + (*force)[index * 4 + 3] = len_v3(forc); /* normalize and copy */ - if ((*force)[index*4+3]) mul_v3_fl(forc, 1.0f/(*force)[index*4+3]); - copy_v3_v3(&((*force)[index*4]), forc); + if ((*force)[index * 4 + 3]) mul_v3_fl(forc, 1.0f / (*force)[index * 4 + 3]); + copy_v3_v3(&((*force)[index * 4]), forc); } /* calculate average values (single thread) */ for (index = 0; index < sData->total_points; index++) { - average_force += (*force)[index*4+3]; + average_force += (*force)[index * 4 + 3]; } average_force /= sData->total_points; } @@ -4137,7 +4142,7 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s } /* Get number of required steps using averate point distance - * so that just a few ultra close pixels wont up substeps to max */ + * so that just a few ultra close pixels wont up substeps to max */ /* adjust number of required substep by fastest active effect */ if (surface->effect & MOD_DPAINT_EFFECT_DO_SPREAD) @@ -4146,9 +4151,9 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s shrink_speed = surface->shrink_speed; fastest_effect = MAX3(spread_speed, shrink_speed, average_force); - avg_dist = bData->average_dist*CANVAS_REL_SIZE/getSurfaceDimension(sData); + avg_dist = bData->average_dist * CANVAS_REL_SIZE / getSurfaceDimension(sData); - steps = (int)ceil(1.5f*EFF_MOVEMENT_PER_FRAME*fastest_effect/avg_dist*timescale); + steps = (int)ceil(1.5f * EFF_MOVEMENT_PER_FRAME * fastest_effect / avg_dist * timescale); CLAMP(steps, 1, 20); return steps; @@ -4161,7 +4166,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force { PaintSurfaceData *sData = surface->data; BakeAdjPoint *bNeighs = sData->bData->bNeighs; - float distance_scale = getSurfaceDimension(sData)/CANVAS_REL_SIZE; + float distance_scale = getSurfaceDimension(sData) / CANVAS_REL_SIZE; int index; timescale /= steps; @@ -4171,39 +4176,39 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force * Spread Effect */ if (surface->effect & MOD_DPAINT_EFFECT_DO_SPREAD) { - float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*surface->spread_speed*timescale; + float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * surface->spread_speed * timescale; /* Copy current surface to the previous points array to read unmodified values */ - memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); + memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint)); #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = sData->adj_data->n_num[index]; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; /* Only reads values from the surface copy (prevPoint[]), * so this one is thread safe */ /* Loop through neighboring points */ - for (i=0; i<numOfNeighs; i++) { - int n_index = sData->adj_data->n_index[index]+i; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; float w_factor; PaintPoint *ePoint = &prevPoint[sData->adj_data->n_target[n_index]]; - float speed_scale = (bNeighs[n_index].dist<eff_scale) ? 1.0f : eff_scale/bNeighs[n_index].dist; - float color_mix = (MIN3(ePoint->wetness, pPoint->wetness, 1.0f))*0.25f*surface->color_spread_speed; + float speed_scale = (bNeighs[n_index].dist < eff_scale) ? 1.0f : eff_scale / bNeighs[n_index].dist; + float color_mix = (MIN3(ePoint->wetness, pPoint->wetness, 1.0f)) * 0.25f * surface->color_spread_speed; /* do color mixing */ if (color_mix) mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, ePoint->e_alpha, color_mix); /* Only continue if surrounding point has higher wetness */ - if (ePoint->wetness<pPoint->wetness || ePoint->wetness<MIN_WETNESS) continue; + if (ePoint->wetness < pPoint->wetness || ePoint->wetness < MIN_WETNESS) continue; - w_factor = 1.0f/numOfNeighs * MIN2(ePoint->wetness, 1.0f) * speed_scale; + w_factor = 1.0f / numOfNeighs *MIN2(ePoint->wetness, 1.0f) * speed_scale; CLAMP(w_factor, 0.0f, 1.0f); /* mix new wetness and color */ - pPoint->wetness = (1.0f-w_factor)*pPoint->wetness + w_factor*ePoint->wetness; + pPoint->wetness = (1.0f - w_factor) * pPoint->wetness + w_factor * ePoint->wetness; pPoint->e_alpha = mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, ePoint->e_alpha, w_factor); } } @@ -4213,21 +4218,21 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force * Shrink Effect */ if (surface->effect & MOD_DPAINT_EFFECT_DO_SHRINK) { - float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*surface->shrink_speed*timescale; + float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * surface->shrink_speed * timescale; /* Copy current surface to the previous points array to read unmodified values */ - memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); + memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint)); #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = sData->adj_data->n_num[index]; float totalAlpha = 0.0f; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; - for (i=0; i<numOfNeighs; i++) { - int n_index = sData->adj_data->n_index[index]+i; - float speed_scale = (bNeighs[n_index].dist<eff_scale) ? 1.0f : eff_scale/bNeighs[n_index].dist; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; + float speed_scale = (bNeighs[n_index].dist < eff_scale) ? 1.0f : eff_scale / bNeighs[n_index].dist; PaintPoint *ePoint = &prevPoint[sData->adj_data->n_target[n_index]]; float a_factor, ea_factor, w_factor; @@ -4238,13 +4243,13 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force if (pPoint->alpha <= 0.0f && pPoint->e_alpha <= 0.0f && pPoint->wetness <= 0.0f) continue; /* decrease factor for dry paint alpha */ - a_factor = (1.0f - ePoint->alpha)/numOfNeighs * (pPoint->alpha - ePoint->alpha) * speed_scale; + a_factor = (1.0f - ePoint->alpha) / numOfNeighs * (pPoint->alpha - ePoint->alpha) * speed_scale; if (a_factor < 0.0f) a_factor = 0.0f; /* decrease factor for wet paint alpha */ - ea_factor = (1.0f - ePoint->e_alpha)/8 * (pPoint->e_alpha - ePoint->e_alpha) * speed_scale; + ea_factor = (1.0f - ePoint->e_alpha) / 8 * (pPoint->e_alpha - ePoint->e_alpha) * speed_scale; if (ea_factor < 0.0f) ea_factor = 0.0f; /* decrease factor for paint wetness */ - w_factor = (1.0f - ePoint->wetness)/8 * (pPoint->wetness - ePoint->wetness) * speed_scale; + w_factor = (1.0f - ePoint->wetness) / 8 * (pPoint->wetness - ePoint->wetness) * speed_scale; if (w_factor < 0.0f) w_factor = 0.0f; pPoint->alpha -= a_factor; @@ -4261,13 +4266,13 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force * Drip Effect */ if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force) { - float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*timescale/2.0f; + float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * timescale / 2.0f; /* Copy current surface to the previous points array to read unmodified values */ - memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); + memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint)); for (index = 0; index < sData->total_points; index++) { int i; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; PaintPoint *pPoint_prev = &prevPoint[index]; int closest_id[2]; @@ -4279,15 +4284,15 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force CLAMP(w_factor, 0.0f, 1.0f); /* get force affect points */ - surface_determineForceTargetPoints(sData, index, &force[index*4], closest_d, closest_id); + surface_determineForceTargetPoints(sData, index, &force[index * 4], closest_d, closest_id); /* Apply movement towards those two points */ - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) { int n_index = closest_id[i]; - if (n_index != -1 && closest_d[i]>0.0f) { + if (n_index != -1 && closest_d[i] > 0.0f) { float dir_dot = closest_d[i], dir_factor, a_factor; - float speed_scale = eff_scale*force[index*4+3]/bNeighs[n_index].dist; - PaintPoint *ePoint = &((PaintPoint*)sData->type_data)[sData->adj_data->n_target[n_index]]; + float speed_scale = eff_scale * force[index * 4 + 3] / bNeighs[n_index].dist; + PaintPoint *ePoint = &((PaintPoint *)sData->type_data)[sData->adj_data->n_target[n_index]]; float e_wet = ePoint->wetness; /* just skip if angle is too extreme */ @@ -4330,11 +4335,11 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) float wave_speed = surface->wave_speed; double average_dist = 0.0f; Bounds3D *mb = &sData->bData->mesh_bounds; - float canvas_size = MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2])); - float wave_scale = CANVAS_REL_SIZE/canvas_size; + float canvas_size = MAX3((mb->max[0] - mb->min[0]), (mb->max[1] - mb->min[1]), (mb->max[2] - mb->min[2])); + float wave_scale = CANVAS_REL_SIZE / canvas_size; /* allocate memory */ - PaintWavePoint *prevPoint = MEM_mallocN(sData->total_points*sizeof(PaintWavePoint), "Temp previous points for wave simulation"); + PaintWavePoint *prevPoint = MEM_mallocN(sData->total_points * sizeof(PaintWavePoint), "Temp previous points for wave simulation"); if (!prevPoint) return; /* calculate average neigh distance (single thread) */ @@ -4342,30 +4347,30 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) int i; int numOfNeighs = sData->adj_data->n_num[index]; - for (i=0; i<numOfNeighs; i++) { - average_dist += bNeighs[sData->adj_data->n_index[index]+i].dist; + for (i = 0; i < numOfNeighs; i++) { + average_dist += bNeighs[sData->adj_data->n_index[index] + i].dist; } } - average_dist *= wave_scale/sData->adj_data->total_targets; + average_dist *= wave_scale / sData->adj_data->total_targets; /* determine number of required steps */ - steps = (int)ceil((WAVE_TIME_FAC*timescale*surface->wave_timescale) / (average_dist/wave_speed/3)); + steps = (int)ceil((WAVE_TIME_FAC * timescale * surface->wave_timescale) / (average_dist / wave_speed / 3)); CLAMP(steps, 1, 20); timescale /= steps; /* apply simulation values for final timescale */ - dt = WAVE_TIME_FAC*timescale*surface->wave_timescale; - min_dist = wave_speed*dt*1.5f; - damp_factor = pow((1.0f-surface->wave_damping), timescale*surface->wave_timescale); + dt = WAVE_TIME_FAC * timescale * surface->wave_timescale; + min_dist = wave_speed * dt * 1.5f; + damp_factor = pow((1.0f - surface->wave_damping), timescale * surface->wave_timescale); - for (ss=0; ss<steps; ss++) { + for (ss = 0; ss < steps; ss++) { /* copy previous frame data */ - memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(PaintWavePoint)); + memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(PaintWavePoint)); #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { - PaintWavePoint *wPoint = &((PaintWavePoint*)sData->type_data)[index]; + PaintWavePoint *wPoint = &((PaintWavePoint *)sData->type_data)[index]; int numOfNeighs = sData->adj_data->n_num[index]; float force = 0.0f, avg_dist = 0.0f, avg_height = 0.0f; int numOfN = 0, numOfRN = 0; @@ -4374,13 +4379,13 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) if (wPoint->state > 0) continue; /* calculate force from surrounding points */ - for (i=0; i<numOfNeighs; i++) { - int n_index = sData->adj_data->n_index[index]+i; - float dist = bNeighs[n_index].dist*wave_scale; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; + float dist = bNeighs[n_index].dist * wave_scale; PaintWavePoint *tPoint = &prevPoint[sData->adj_data->n_target[n_index]]; - if (!dist || tPoint->state>0) continue; - if (dist<min_dist) dist=min_dist; + if (!dist || tPoint->state > 0) continue; + if (dist < min_dist) dist = min_dist; avg_dist += dist; numOfN++; @@ -4390,28 +4395,28 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) numOfRN++; } - force += (tPoint->height - wPoint->height) / (dist*dist); + force += (tPoint->height - wPoint->height) / (dist * dist); } - avg_dist = (numOfN) ? avg_dist/numOfN : 0.0f; + avg_dist = (numOfN) ? avg_dist / numOfN : 0.0f; if (surface->flags & MOD_DPAINT_WAVE_OPEN_BORDERS && - sData->adj_data->flags[index] & ADJ_ON_MESH_EDGE) { + sData->adj_data->flags[index] & ADJ_ON_MESH_EDGE) { /* if open borders, apply a fake height to keep waves going on */ - avg_height = (numOfRN) ? avg_height/numOfRN : 0.0f; - wPoint->height = (dt*wave_speed*avg_height + wPoint->height*avg_dist) / (avg_dist + dt*wave_speed); + avg_height = (numOfRN) ? avg_height / numOfRN : 0.0f; + wPoint->height = (dt * wave_speed * avg_height + wPoint->height * avg_dist) / (avg_dist + dt * wave_speed); } /* else do wave eq */ else { /* add force towards zero height based on average dist */ if (avg_dist) - force += (0.0f - wPoint->height) * surface->wave_spring / (avg_dist*avg_dist) / 2.0f; + force += (0.0f - wPoint->height) * surface->wave_spring / (avg_dist * avg_dist) / 2.0f; /* change point velocity */ - wPoint->velocity += force*dt * wave_speed*wave_speed; + wPoint->velocity += force * dt * wave_speed * wave_speed; /* damping */ wPoint->velocity *= damp_factor; /* and new height */ - wPoint->height += wPoint->velocity*dt; + wPoint->height += wPoint->velocity * dt; } } } @@ -4419,7 +4424,7 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) /* reset state */ #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { - PaintWavePoint *wPoint = &((PaintWavePoint*)sData->type_data)[index]; + PaintWavePoint *wPoint = &((PaintWavePoint *)sData->type_data)[index]; /* if there wasnt any brush intersection, clear isect height */ if (wPoint->state == DPAINT_WAVE_NONE) { wPoint->brush_isect = 0.0f; @@ -4437,10 +4442,10 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time int index; #pragma omp parallel for schedule(static) - for (index=0; index<sData->total_points; index++) { + for (index = 0; index < sData->total_points; index++) { /* Do drying dissolve effects */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; /* drying */ if (surface->flags & MOD_DPAINT_USE_DRYING) { if (pPoint->wetness >= MIN_WETNESS) { @@ -4448,10 +4453,10 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time float dry_ratio, f_color[4]; float p_wetness = pPoint->wetness; VALUE_DISSOLVE(pPoint->wetness, surface->dry_speed, timescale, (surface->flags & MOD_DPAINT_DRY_LOG)); - if (pPoint->wetness<0.0f) pPoint->wetness=0.0f; + if (pPoint->wetness < 0.0f) pPoint->wetness = 0.0f; if (pPoint->wetness < surface->color_dry_threshold) { - dry_ratio = pPoint->wetness/p_wetness; + dry_ratio = pPoint->wetness / p_wetness; /* * Slowly "shift" paint from wet layer to dry layer as it drys: @@ -4466,12 +4471,12 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time pPoint->e_alpha *= dry_ratio; /* now calculate new alpha for dry layer that keeps final blended color unchanged */ - pPoint->alpha = (f_color[3] - pPoint->e_alpha)/(1.0f-pPoint->e_alpha); + pPoint->alpha = (f_color[3] - pPoint->e_alpha) / (1.0f - pPoint->e_alpha); /* for each rgb component, calculate a new dry layer color that keeps the final blend color * with these new alpha values. (wet layer color doesnt change)*/ if (pPoint->alpha) { - for (i=0; i<3; i++) { - pPoint->color[i] = (f_color[i]*f_color[3] - pPoint->e_color[i]*pPoint->e_alpha)/(pPoint->alpha*(1.0f-pPoint->e_alpha)); + for (i = 0; i < 3; i++) { + pPoint->color[i] = (f_color[i] * f_color[3] - pPoint->e_color[i] * pPoint->e_alpha) / (pPoint->alpha * (1.0f - pPoint->e_alpha)); } } } @@ -4501,10 +4506,10 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time } /* dissolve for float types */ else if (surface->flags & MOD_DPAINT_DISSOLVE && - (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WEIGHT)) { + (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || + surface->type == MOD_DPAINT_SURFACE_T_WEIGHT)) { - float *point = &((float*)sData->type_data)[index]; + float *point = &((float *)sData->type_data)[index]; /* log or linear */ VALUE_DISSOLVE(*point, surface->diss_speed, timescale, (surface->flags & MOD_DPAINT_DISSOLVE_LOG)); if (*point < 0.0f) *point = 0.0f; @@ -4526,17 +4531,17 @@ static int dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *ob if (!bData->prev_verts) return 1; /* matrix comparison */ - for (i=0; i<4; i++) { + for (i = 0; i < 4; i++) { int j; - for (j=0; j<4; j++) - if (bData->prev_obmat[i][j] != ob->obmat[i][j]) return 1; + for (j = 0; j < 4; j++) + if (bData->prev_obmat[i][j] != ob->obmat[i][j]) return 1; } /* vertices */ #pragma omp parallel for schedule(static) - for (i=0; i<numOfVerts; i++) { + for (i = 0; i < numOfVerts; i++) { int j; - for (j=0; j<3; j++) + for (j = 0; j < 3; j++) if (bData->prev_verts[i].co[j] != mvert[i].co[j]) { ret = 1; break; @@ -4585,18 +4590,18 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc /* get previous speed for accelertaion */ if (do_accel_data && bData->prev_velocity && bData->velocity) - memcpy(bData->prev_velocity, bData->velocity, sData->total_points*sizeof(Vec3f)); + memcpy(bData->prev_velocity, bData->velocity, sData->total_points * sizeof(Vec3f)); /* reset speed vectors */ if (do_velocity_data && bData->velocity && (bData->clear || !surface_moved)) - memset(bData->velocity, 0, sData->total_points*sizeof(Vec3f)); + memset(bData->velocity, 0, sData->total_points * sizeof(Vec3f)); /* if previous data exists and mesh hasn't moved, no need to recalc */ if (!surface_moved) return 1; } - canvas_verts = (struct Vec3f *) MEM_mallocN(canvasNumOfVerts*sizeof(struct Vec3f), "Dynamic Paint transformed canvas verts"); + canvas_verts = (struct Vec3f *) MEM_mallocN(canvasNumOfVerts * sizeof(struct Vec3f), "Dynamic Paint transformed canvas verts"); if (!canvas_verts) return 0; /* allocate memory if required */ @@ -4608,11 +4613,11 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } /* Init bdata */ - bData->bNormal = (struct PaintBakeNormal *) MEM_mallocN(sData->total_points*sizeof(struct PaintBakeNormal), "Dynamic Paint step data"); - bData->s_pos = MEM_mallocN(sData->total_points*sizeof(unsigned int), "Dynamic Paint bData s_pos"); - bData->s_num = MEM_mallocN(sData->total_points*sizeof(unsigned int), "Dynamic Paint bData s_num"); - bData->realCoord = (struct Vec3f *) MEM_mallocN(surface_totalSamples(surface)*sizeof(Vec3f), "Dynamic Paint point coords"); - bData->prev_verts = MEM_mallocN(canvasNumOfVerts*sizeof(MVert), "Dynamic Paint bData prev_verts"); + bData->bNormal = (struct PaintBakeNormal *) MEM_mallocN(sData->total_points * sizeof(struct PaintBakeNormal), "Dynamic Paint step data"); + bData->s_pos = MEM_mallocN(sData->total_points * sizeof(unsigned int), "Dynamic Paint bData s_pos"); + bData->s_num = MEM_mallocN(sData->total_points * sizeof(unsigned int), "Dynamic Paint bData s_num"); + bData->realCoord = (struct Vec3f *) MEM_mallocN(surface_totalSamples(surface) * sizeof(Vec3f), "Dynamic Paint point coords"); + bData->prev_verts = MEM_mallocN(canvasNumOfVerts * sizeof(MVert), "Dynamic Paint bData prev_verts"); /* if any allocation failed, free everything */ if (!bData->bNormal || !bData->s_pos || !bData->s_num || !bData->realCoord || !canvas_verts) { @@ -4629,20 +4634,20 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } if (do_velocity_data && !bData->velocity) { - bData->velocity = (struct Vec3f *) MEM_callocN(sData->total_points*sizeof(Vec3f), "Dynamic Paint velocity"); + bData->velocity = (struct Vec3f *) MEM_callocN(sData->total_points * sizeof(Vec3f), "Dynamic Paint velocity"); } if (do_accel_data && !bData->prev_velocity) { - bData->prev_velocity = (struct Vec3f *) MEM_mallocN(sData->total_points*sizeof(Vec3f), "Dynamic Paint prev velocity"); + bData->prev_velocity = (struct Vec3f *) MEM_mallocN(sData->total_points * sizeof(Vec3f), "Dynamic Paint prev velocity"); /* copy previous vel */ if (bData->prev_velocity && bData->velocity) - memcpy(bData->prev_velocity, bData->velocity, sData->total_points*sizeof(Vec3f)); + memcpy(bData->prev_velocity, bData->velocity, sData->total_points * sizeof(Vec3f)); } /* * Make a transformed copy of canvas derived mesh vertices to avoid recalculation. */ bData->mesh_bounds.valid = 0; - for (index=0; index<canvasNumOfVerts; index++) { + for (index = 0; index < canvasNumOfVerts; index++) { copy_v3_v3(canvas_verts[index].v, mvert[index].co); mul_m4_v3(ob->obmat, canvas_verts[index].v); boundInsert(&bData->mesh_bounds, canvas_verts[index].v); @@ -4652,7 +4657,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc * Prepare each surface point for a new step */ #pragma omp parallel for schedule(static) - for (index=0; index<sData->total_points; index++) { + for (index = 0; index < sData->total_points; index++) { float prev_point[3] = {0.0f, 0.0f, 0.0f}; if (do_velocity_data && !new_bdata) { copy_v3_v3(prev_point, bData->realCoord[bData->s_pos[index]].v); @@ -4662,16 +4667,16 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc */ if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { float n1[3], n2[3], n3[3]; - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; - PaintUVPoint *tPoint = &((PaintUVPoint*)f_data->uv_p)[index]; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; + PaintUVPoint *tPoint = &((PaintUVPoint *)f_data->uv_p)[index]; int ss; bData->s_num[index] = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; bData->s_pos[index] = index * bData->s_num[index]; /* per sample coordinates */ - for (ss=0; ss<bData->s_num[index]; ss++) { - interp_v3_v3v3v3(bData->realCoord[bData->s_pos[index]+ss].v, + for (ss = 0; ss < bData->s_num[index]; ss++) { + interp_v3_v3v3v3(bData->realCoord[bData->s_pos[index] + ss].v, canvas_verts[tPoint->v1].v, canvas_verts[tPoint->v2].v, canvas_verts[tPoint->v3].v, @@ -4684,7 +4689,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc normal_short_to_float_v3(n3, mvert[tPoint->v3].no); interp_v3_v3v3v3(bData->bNormal[index].invNorm, - n1, n2, n3, f_data->barycentricWeights[index*bData->s_num[index]].v); + n1, n2, n3, f_data->barycentricWeights[index * bData->s_num[index]].v); mul_mat3_m4_v3(ob->obmat, bData->bNormal[index].invNorm); normalize_v3(bData->bNormal[index].invNorm); negate_v3(bData->bNormal[index].invNorm); @@ -4692,8 +4697,8 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { int ss; if (surface->flags & MOD_DPAINT_ANTIALIAS && adj_data) { - bData->s_num[index] = adj_data->n_num[index]+1; - bData->s_pos[index] = adj_data->n_index[index]+index; + bData->s_num[index] = adj_data->n_num[index] + 1; + bData->s_pos[index] = adj_data->n_index[index] + index; } else { bData->s_num[index] = 1; @@ -4701,14 +4706,14 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } /* calculate position for each sample */ - for (ss=0; ss<bData->s_num[index]; ss++) { + for (ss = 0; ss < bData->s_num[index]; ss++) { /* first sample is always point center */ - copy_v3_v3(bData->realCoord[bData->s_pos[index]+ss].v, canvas_verts[index].v); + copy_v3_v3(bData->realCoord[bData->s_pos[index] + ss].v, canvas_verts[index].v); if (ss > 0) { - int t_index = adj_data->n_index[index]+(ss-1); + int t_index = adj_data->n_index[index] + (ss - 1); /* get vertex position at 1/3 of each neigh edge */ - mul_v3_fl(bData->realCoord[bData->s_pos[index]+ss].v, 2.0f/3.0f); - madd_v3_v3fl(bData->realCoord[bData->s_pos[index]+ss].v, canvas_verts[adj_data->n_target[t_index]].v, 1.0f/3.0f); + mul_v3_fl(bData->realCoord[bData->s_pos[index] + ss].v, 2.0f / 3.0f); + madd_v3_v3fl(bData->realCoord[bData->s_pos[index] + ss].v, canvas_verts[adj_data->n_target[t_index]].v, 1.0f / 3.0f); } } @@ -4722,7 +4727,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc /* Prepare surface normal directional scale to easily convert * brush intersection amount between global and local space */ if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) { + surface->type == MOD_DPAINT_SURFACE_T_WAVE) { float temp_nor[3]; if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { normal_short_to_float_v3(temp_nor, mvert[index].no); @@ -4730,14 +4735,14 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } else { float n1[3], n2[3], n3[3]; - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; - PaintUVPoint *tPoint = &((PaintUVPoint*)f_data->uv_p)[index]; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; + PaintUVPoint *tPoint = &((PaintUVPoint *)f_data->uv_p)[index]; normal_short_to_float_v3(n1, mvert[tPoint->v1].no); normal_short_to_float_v3(n2, mvert[tPoint->v2].no); normal_short_to_float_v3(n3, mvert[tPoint->v3].no); interp_v3_v3v3v3(temp_nor, - n1, n2, n3, f_data->barycentricWeights[index*bData->s_num[index]].v); + n1, n2, n3, f_data->barycentricWeights[index * bData->s_num[index]].v); } mul_v3_v3(temp_nor, ob->size); @@ -4759,7 +4764,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc /* Copy current frame vertices to check against in next frame */ copy_m4_m4(bData->prev_obmat, ob->obmat); - memcpy(bData->prev_verts, mvert, canvasNumOfVerts*sizeof(MVert)); + memcpy(bData->prev_verts, mvert, canvasNumOfVerts * sizeof(MVert)); bData->clear = 0; @@ -4801,7 +4806,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su brushObj = NULL; /* select object */ if (surface->brush_group) { - if (go->ob) brushObj = go->ob; + if (go->ob) brushObj = go->ob; } else brushObj = base->object; @@ -4809,7 +4814,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su if (!brushObj) { /* skip item */ if (surface->brush_group) go = go->next; - else base= base->next; + else base = base->next; continue; } @@ -4817,7 +4822,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su if (surface->brush_group) go = go->next; else - base= base->next; + base = base->next; /* check if target has an active dp modifier */ md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); @@ -4830,7 +4835,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* calculate brush speed vectors if required */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && brush->flags & MOD_DPAINT_DO_SMUDGE) { - bData->brush_velocity = MEM_callocN(sData->total_points*sizeof(float)*4, "Dynamic Paint brush velocity"); + bData->brush_velocity = MEM_callocN(sData->total_points * sizeof(float) * 4, "Dynamic Paint brush velocity"); /* init adjacency data if not already */ if (!sData->adj_data) dynamicPaint_initAdjacencyData(surface, 1); @@ -4850,8 +4855,8 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* Apply brush on the surface depending on it's collision type */ /* Particle brush: */ if (brush->collision == MOD_DPAINT_COL_PSYS) { - if (brush && brush->psys && brush->psys->part && brush->psys->part->type==PART_EMITTER && - psys_check_enabled(brushObj, brush->psys)) { + if (brush && brush->psys && brush->psys->part && brush->psys->part->type == PART_EMITTER && + psys_check_enabled(brushObj, brush->psys)) { /* Paint a particle system */ BKE_animsys_evaluate_animdata(scene, &brush->psys->part->id, brush->psys->part->adt, BKE_scene_frame_get(scene), ADT_RECALC_ANIM); @@ -4903,7 +4908,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su float *force = NULL; /* Allocate memory for surface previous points to read unchanged values from */ - prevPoint = MEM_mallocN(sData->total_points*sizeof(struct PaintPoint), "PaintSurfaceDataCopy"); + prevPoint = MEM_mallocN(sData->total_points * sizeof(struct PaintPoint), "PaintSurfaceDataCopy"); if (!prevPoint) return setError(canvas, "Not enough free memory."); @@ -4939,10 +4944,10 @@ int dynamicPaint_calculateFrame(DynamicPaintSurface *surface, Scene *scene, Obje /* don't do substeps for first frame */ if (surface->substeps && (frame != surface->start_frame)) { int st; - timescale = 1.0f / (surface->substeps+1); + timescale = 1.0f / (surface->substeps + 1); for (st = 1; st <= surface->substeps; st++) { - float subframe = ((float) st) / (surface->substeps+1); + float subframe = ((float) st) / (surface->substeps + 1); if (!dynamicPaint_doStep(scene, cObject, surface, timescale, subframe)) return 0; } } diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 428dc176e1d..3e25281dd08 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -113,10 +113,10 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) #define USE_TESSFACE_SPEEDUP BMesh *bm = tm->bm; - BMLoop *(*looptris)[3]= NULL; + BMLoop *(*looptris)[3] = NULL; BLI_array_declare(looptris); BMIter iter, liter; - BMFace *f; + BMFace *efa; BMLoop *l; int i = 0, j; @@ -150,9 +150,9 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) #endif - BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { + BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { /*don't consider two-edged faces*/ - if (f->len < 3) { + if (efa->len < 3) { /* do nothing */ } @@ -160,20 +160,18 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) /* no need to ensure the loop order, we know its ok */ - else if (f->len == 3) { + else if (efa->len == 3) { BLI_array_grow_one(looptris); - l = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, f); - for (j=0; l; l=BM_iter_step(&liter), j++) { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) { looptris[i][j] = l; } i += 1; } - else if (f->len == 4) { + else if (efa->len == 4) { BMLoop *ltmp[4]; BLI_array_grow_items(looptris, 2); - l = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, f); - for (j=0; l; l=BM_iter_step(&liter), j++) { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) { ltmp[j] = l; } @@ -191,43 +189,43 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) #endif /* USE_TESSFACE_SPEEDUP */ else { - ScanFillVert *v, *lastv=NULL, *firstv=NULL; + ScanFillVert *sf_vert, *sf_vert_last = NULL, *sf_vert_first = NULL; /* ScanFillEdge *e; */ /* UNUSED */ - ScanFillFace *efa; + ScanFillFace *sf_tri; int totfilltri; BLI_scanfill_begin(&sf_ctx); - /*scanfill time*/ - l = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, f); - for (j=0; l; l=BM_iter_step(&liter), j++) { + + /* scanfill time */ + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) { /*mark order*/ BM_elem_index_set(l, j); /* set_loop */ - v = BLI_scanfill_vert_add(&sf_ctx, l->v->co); - v->tmp.p = l; + sf_vert = BLI_scanfill_vert_add(&sf_ctx, l->v->co); + sf_vert->tmp.p = l; - if (lastv) { - /* e = */ BLI_scanfill_edge_add(&sf_ctx, lastv, v); + if (sf_vert_last) { + /* e = */ BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert); } - lastv = v; - if (firstv==NULL) firstv = v; + sf_vert_last = sf_vert; + if (sf_vert_first == NULL) sf_vert_first = sf_vert; } - /*complete the loop*/ - BLI_scanfill_edge_add(&sf_ctx, firstv, v); + /* complete the loop */ + BLI_scanfill_edge_add(&sf_ctx, sf_vert_first, sf_vert); - totfilltri = BLI_scanfill_calc_ex(&sf_ctx, FALSE, f->no); + totfilltri = BLI_scanfill_calc_ex(&sf_ctx, FALSE, efa->no); BLI_array_grow_items(looptris, totfilltri); - for (efa = sf_ctx.fillfacebase.first; efa; efa=efa->next) { - BMLoop *l1= efa->v1->tmp.p; - BMLoop *l2= efa->v2->tmp.p; - BMLoop *l3= efa->v3->tmp.p; + for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next) { + BMLoop *l1 = sf_tri->v1->tmp.p; + BMLoop *l2 = sf_tri->v2->tmp.p; + BMLoop *l3 = sf_tri->v3->tmp.p; - if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop*, l1, l2); } - if (BM_elem_index_get(l2) > BM_elem_index_get(l3)) { SWAP(BMLoop*, l2, l3); } - if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop*, l1, l2); } + if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); } + if (BM_elem_index_get(l2) > BM_elem_index_get(l3)) { SWAP(BMLoop *, l2, l3); } + if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); } looptris[i][0] = l1; looptris[i][1] = l2; @@ -289,16 +287,16 @@ void BMEdit_UpdateLinkedCustomData(BMEditMesh *em) void BMEdit_Free(BMEditMesh *em) { if (em->derivedFinal) { - if (em->derivedFinal!=em->derivedCage) { - em->derivedFinal->needsFree= 1; + if (em->derivedFinal != em->derivedCage) { + em->derivedFinal->needsFree = 1; em->derivedFinal->release(em->derivedFinal); } - em->derivedFinal= NULL; + em->derivedFinal = NULL; } if (em->derivedCage) { - em->derivedCage->needsFree= 1; + em->derivedCage->needsFree = 1; em->derivedCage->release(em->derivedCage); - em->derivedCage= NULL; + em->derivedCage = NULL; } if (em->looptris) MEM_freeN(em->looptris); @@ -351,12 +349,11 @@ static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm)) /* do nothing */ } -static void emDM_foreachMappedVert( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]), - void *userData) +static void emDM_foreachMappedVert(DerivedMesh *dm, + void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]), + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMVert *eve; BMIter iter; int i; @@ -372,12 +369,11 @@ static void emDM_foreachMappedVert( } } } -static void emDM_foreachMappedEdge( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]), - void *userData) +static void emDM_foreachMappedEdge(DerivedMesh *dm, + void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]), + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEdge *eed; BMIter iter; int i; @@ -386,25 +382,24 @@ static void emDM_foreachMappedEdge( BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT); - eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) + BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) { func(userData, i, - bmdm->vertexCos[BM_elem_index_get(eed->v1)], - bmdm->vertexCos[BM_elem_index_get(eed->v2)]); + bmdm->vertexCos[BM_elem_index_get(eed->v1)], + bmdm->vertexCos[BM_elem_index_get(eed->v2)]); + } } else { - eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) + BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) { func(userData, i, eed->v1->co, eed->v2->co); + } } } -static void emDM_drawMappedEdges( - DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - void *userData) +static void emDM_drawMappedEdges(DerivedMesh *dm, + DMSetDrawOptions setDrawOptions, + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEdge *eed; BMIter iter; int i; @@ -414,8 +409,7 @@ static void emDM_drawMappedEdges( BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT); glBegin(GL_LINES); - eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) { + BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) { if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]); glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]); @@ -425,8 +419,7 @@ static void emDM_drawMappedEdges( } else { glBegin(GL_LINES); - eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) { + BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) { if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { glVertex3fv(eed->v1->co); glVertex3fv(eed->v2->co); @@ -435,21 +428,19 @@ static void emDM_drawMappedEdges( glEnd(); } } -static void emDM_drawEdges( - DerivedMesh *dm, - int UNUSED(drawLooseEdges), - int UNUSED(drawAllEdges)) +static void emDM_drawEdges(DerivedMesh *dm, + int UNUSED(drawLooseEdges), + int UNUSED(drawAllEdges)) { emDM_drawMappedEdges(dm, NULL, NULL); } -static void emDM_drawMappedEdgesInterp( - DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - DMSetDrawInterpOptions setDrawInterpOptions, - void *userData) +static void emDM_drawMappedEdgesInterp(DerivedMesh *dm, + DMSetDrawOptions setDrawOptions, + DMSetDrawInterpOptions setDrawInterpOptions, + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEdge *eed; BMIter iter; int i; @@ -459,8 +450,7 @@ static void emDM_drawMappedEdgesInterp( BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT); glBegin(GL_LINES); - eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) { + BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) { if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { setDrawInterpOptions(userData, i, 0.0); glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]); @@ -472,8 +462,7 @@ static void emDM_drawMappedEdgesInterp( } else { glBegin(GL_LINES); - eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) { + BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) { if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { setDrawInterpOptions(userData, i, 0.0); glVertex3fv(eed->v1->co); @@ -487,7 +476,7 @@ static void emDM_drawMappedEdgesInterp( static void emDM_drawUVEdges(DerivedMesh *dm) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEditMesh *em = bmdm->tc; BMFace *efa; BMIter iter; @@ -523,9 +512,9 @@ static void emDM_drawUVEdges(DerivedMesh *dm) glEnd(); } -static void emDM__calcFaceCent(BMesh *bm, BMFace *efa, float cent[3], float (*vertexCos)[3]) +static void emDM__calcFaceCent(BMFace *efa, float cent[3], float (*vertexCos)[3]) { - BMIter iter; + BMIter liter; BMLoop *l; int tot = 0; @@ -534,30 +523,27 @@ static void emDM__calcFaceCent(BMesh *bm, BMFace *efa, float cent[3], float (*ve /*simple (and stupid) median (average) based method :/ */ if (vertexCos) { - l = BM_iter_new(&iter, bm, BM_LOOPS_OF_FACE, efa); - for (; l; l=BM_iter_step(&iter)) { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { add_v3_v3(cent, vertexCos[BM_elem_index_get(l->v)]); tot++; } } else { - l = BM_iter_new(&iter, bm, BM_LOOPS_OF_FACE, efa); - for (; l; l=BM_iter_step(&iter)) { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { add_v3_v3(cent, l->v->co); tot++; } } - if (tot==0) return; - mul_v3_fl(cent, 1.0f/(float)tot); + if (tot == 0) return; + mul_v3_fl(cent, 1.0f / (float)tot); } -static void emDM_foreachMappedFaceCenter( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float co[3], const float no[3]), - void *userData) +static void emDM_foreachMappedFaceCenter(DerivedMesh *dm, + void (*func)(void *userData, int index, const float co[3], const float no[3]), + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; float (*polyNos)[3] = NULL; BMFace *efa; BMIter iter; @@ -573,18 +559,17 @@ static void emDM_foreachMappedFaceCenter( } BM_ITER_MESH_INDEX (efa, &iter, bmdm->tc->bm, BM_FACES_OF_MESH, i) { - emDM__calcFaceCent(bmdm->tc->bm, efa, cent, bmdm->vertexCos); + emDM__calcFaceCent(efa, cent, bmdm->vertexCos); func(userData, i, cent, polyNos ? polyNos[i] : efa->no); } } -static void emDM_drawMappedFaces( - DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - DMSetMaterial setMaterial, - DMCompareDrawOptions compareDrawOptions, - void *userData, - DMDrawFlag flag) +static void emDM_drawMappedFaces(DerivedMesh *dm, + DMSetDrawOptions setDrawOptions, + DMSetMaterial setMaterial, + DMCompareDrawOptions compareDrawOptions, + void *userData, + DMDrawFlag flag) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMFace *efa; @@ -621,8 +606,8 @@ static void emDM_drawMappedFaces( drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH); draw_option = (!setDrawOptions ? - DM_DRAW_OPTION_NORMAL : - setDrawOptions(userData, BM_elem_index_get(efa))); + DM_DRAW_OPTION_NORMAL : + setDrawOptions(userData, BM_elem_index_get(efa))); if (draw_option != DM_DRAW_OPTION_SKIP) { const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */ if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */ @@ -673,7 +658,7 @@ static void emDM_drawMappedFaces( flush = (draw_option == DM_DRAW_OPTION_STIPPLE); if (!skip_normals && !flush && (i != lasttri)) - flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */ + flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */ if (flush) { glEnd(); @@ -687,16 +672,16 @@ static void emDM_drawMappedFaces( else { BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_FACE); - for (i=0; i < tottri; i++) { + for (i = 0; i < tottri; i++) { BMLoop **l = looptris[i]; int drawSmooth; efa = l[0]->f; - drawSmooth= (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH); + drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH); draw_option = (!setDrawOptions ? - DM_DRAW_OPTION_NORMAL : - setDrawOptions(userData, BM_elem_index_get(efa))); + DM_DRAW_OPTION_NORMAL : + setDrawOptions(userData, BM_elem_index_get(efa))); if (draw_option != DM_DRAW_OPTION_SKIP) { const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */ if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */ @@ -752,7 +737,7 @@ static void emDM_drawMappedFaces( if (flush) { glEnd(); - poly_prev= GL_ZERO; /* force glBegin */ + poly_prev = GL_ZERO; /* force glBegin */ glDisable(GL_POLYGON_STIPPLE); } @@ -782,12 +767,11 @@ static void bmdm_get_tri_tex(BMesh *bm, BMLoop **ls, MLoopUV *luv[3], MLoopCol * } -static void emDM_drawFacesTex_common( - DerivedMesh *dm, - DMSetDrawOptionsTex drawParams, - DMSetDrawOptions drawParamsMapped, - DMCompareDrawOptions compareDrawOptions, - void *userData) +static void emDM_drawFacesTex_common(DerivedMesh *dm, + DMSetDrawOptionsTex drawParams, + DMSetDrawOptions drawParamsMapped, + DMCompareDrawOptions compareDrawOptions, + void *userData) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEditMesh *em = bmdm->tc; @@ -965,29 +949,26 @@ static void emDM_drawFacesTex_common( glShadeModel(GL_FLAT); } -static void emDM_drawFacesTex( - DerivedMesh *dm, - DMSetDrawOptionsTex setDrawOptions, - DMCompareDrawOptions compareDrawOptions, - void *userData) +static void emDM_drawFacesTex(DerivedMesh *dm, + DMSetDrawOptionsTex setDrawOptions, + DMCompareDrawOptions compareDrawOptions, + void *userData) { emDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData); } -static void emDM_drawMappedFacesTex( - DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - DMCompareDrawOptions compareDrawOptions, - void *userData) +static void emDM_drawMappedFacesTex(DerivedMesh *dm, + DMSetDrawOptions setDrawOptions, + DMCompareDrawOptions compareDrawOptions, + void *userData) { emDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData); } -static void emDM_drawMappedFacesGLSL( - DerivedMesh *dm, - DMSetMaterial setMaterial, - DMSetDrawOptions setDrawOptions, - void *userData) +static void emDM_drawMappedFacesGLSL(DerivedMesh *dm, + DMSetMaterial setMaterial, + DMSetDrawOptions setDrawOptions, + void *userData) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMesh *bm = bmdm->tc->bm; @@ -1010,26 +991,28 @@ static void emDM_drawMappedFacesGLSL( glShadeModel(GL_SMOOTH); BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE); -#define PASSATTRIB(loop, eve, vert) { \ - if (attribs.totorco) { \ - float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \ - glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \ - } \ - for (b = 0; b < attribs.tottface; b++) { \ - MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, b);\ - glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \ - } \ - for (b = 0; b < attribs.totmcol; b++) { \ - MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPCOL, b);\ - GLubyte _col[4]; \ - _col[0]= _cp->b; _col[1]= _cp->g; _col[2]= _cp->r; _col[3]= _cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \ - } \ - if (attribs.tottang) { \ - float *tang = attribs.tang.array[i*4 + vert]; \ - glVertexAttrib3fvARB(attribs.tang.gl_index, tang); \ - } \ - } +#define PASSATTRIB(loop, eve, vert) { \ + if (attribs.totorco) { \ + float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \ + glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \ + } \ + for (b = 0; b < attribs.tottface; b++) { \ + MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \ + CD_MLOOPUV, b); \ + glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \ + } \ + for (b = 0; b < attribs.totmcol; b++) { \ + MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \ + CD_MLOOPCOL, b); \ + GLubyte _col[4]; \ + _col[0] = _cp->b; _col[1] = _cp->g; _col[2] = _cp->r; _col[3] = _cp->a; \ + glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \ + } \ + if (attribs.tottang) { \ + float *tang = attribs.tang.array[i * 4 + vert]; \ + glVertexAttrib3fvARB(attribs.tang.gl_index, tang); \ + } \ + } (void)0 for (i = 0, ltri = em->looptris[0]; i < em->tottri; i++, ltri += 3) { @@ -1103,17 +1086,15 @@ static void emDM_drawMappedFacesGLSL( #undef PASSATTRIB } -static void emDM_drawFacesGLSL( - DerivedMesh *dm, - int (*setMaterial)(int, void *attribs)) +static void emDM_drawFacesGLSL(DerivedMesh *dm, + int (*setMaterial)(int, void *attribs)) { dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL); } -static void emDM_drawMappedFacesMat( - DerivedMesh *dm, - void (*setMaterial)(void *userData, int, void *attribs), - int (*setFace)(void *userData, int index), void *userData) +static void emDM_drawMappedFacesMat(DerivedMesh *dm, + void (*setMaterial)(void *userData, int, void *attribs), + int (*setFace)(void *userData, int index), void *userData) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMesh *bm = bmdm->tc->bm; @@ -1133,32 +1114,34 @@ static void emDM_drawMappedFacesMat( BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE); -#define PASSATTRIB(loop, eve, vert) { \ - if (attribs.totorco) { \ - float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \ - if (attribs.orco.gl_texco) \ - glTexCoord3fv(orco); \ - else \ - glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \ - } \ - for (b = 0; b < attribs.tottface; b++) { \ - MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, b);\ - if (attribs.tface[b].gl_texco) \ - glTexCoord2fv(_luv->uv); \ - else \ - glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \ - } \ - for (b = 0; b < attribs.totmcol; b++) { \ - MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPCOL, b);\ - GLubyte _col[4]; \ - _col[0]= _cp->b; _col[1]= _cp->g; _col[2]= _cp->r; _col[3]= _cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \ - } \ - if (attribs.tottang) { \ - float *tang = attribs.tang.array[i*4 + vert]; \ - glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ - } \ -} +#define PASSATTRIB(loop, eve, vert) { \ + if (attribs.totorco) { \ + float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \ + if (attribs.orco.gl_texco) \ + glTexCoord3fv(orco); \ + else \ + glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \ + } \ + for (b = 0; b < attribs.tottface; b++) { \ + MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \ + CD_MLOOPUV, b); \ + if (attribs.tface[b].gl_texco) \ + glTexCoord2fv(_luv->uv); \ + else \ + glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \ + } \ + for (b = 0; b < attribs.totmcol; b++) { \ + MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \ + CD_MLOOPCOL, b); \ + GLubyte _col[4]; \ + _col[0] = _cp->b; _col[1] = _cp->g; _col[2] = _cp->r; _col[3] = _cp->a; \ + glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \ + } \ + if (attribs.tottang) { \ + float *tang = attribs.tang.array[i * 4 + vert]; \ + glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ + } \ + } (void)0 for (i = 0, ltri = em->looptris[0]; i < em->tottri; i++, ltri += 3) { int drawSmooth; @@ -1242,12 +1225,12 @@ static void emDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) if (bmdm->tc->bm->totvert) { if (bmdm->vertexCos) { BM_ITER_MESH_INDEX (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH, i) { - DO_MINMAX(bmdm->vertexCos[i], min_r, max_r); + minmax_v3v3_v3(min_r, max_r, bmdm->vertexCos[i]); } } else { BM_ITER_MESH (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH) { - DO_MINMAX(eve->co, min_r, max_r); + minmax_v3v3_v3(min_r, max_r, eve->co); } } } @@ -1300,7 +1283,7 @@ static int bmvert_to_mvert(BMesh *bm, BMVert *ev, MVert *vert_r) vert_r->flag = BM_vert_flag_to_mflag(ev); if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { - vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, ev, CD_BWEIGHT)*255.0f); + vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, ev, CD_BWEIGHT) * 255.0f); } return 1; @@ -1339,11 +1322,11 @@ static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r) e = BM_edge_at_index(bmdm->tc->bm, index); /* warning, does list loop, _not_ ideal */ if (CustomData_has_layer(&bm->edata, CD_BWEIGHT)) { - edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_BWEIGHT)*255.0f); + edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_BWEIGHT) * 255.0f); } if (CustomData_has_layer(&bm->edata, CD_CREASE)) { - edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_CREASE)*255.0f); + edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_CREASE) * 255.0f); } edge_r->flag = BM_edge_flag_to_mflag(e); @@ -1382,23 +1365,34 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMesh *bm = bmdm->tc->bm; - BMVert *ev; + BMVert *eve; BMIter iter; - int i; + const int has_bweight = CustomData_has_layer(&bm->vdata, CD_BWEIGHT); - ev = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); - for (i = 0 ; ev; ev = BM_iter_step(&iter), ++vert_r, ++i) { - if (bmdm->vertexCos) - copy_v3_v3(vert_r->co, bmdm->vertexCos[i]); - else - copy_v3_v3(vert_r->co, ev->co); + if (bmdm->vertexCos) { + int i; - normal_float_to_short_v3(vert_r->no, ev->no); + BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { + copy_v3_v3(vert_r->co, bmdm->vertexCos[i]); + normal_float_to_short_v3(vert_r->no, eve->no); + vert_r->flag = BM_vert_flag_to_mflag(eve); - vert_r->flag = BM_vert_flag_to_mflag(ev); + if (has_bweight) { + vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f); + } + vert_r++; + } + } + else { + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + copy_v3_v3(vert_r->co, eve->co); + normal_float_to_short_v3(vert_r->no, eve->no); + vert_r->flag = BM_vert_flag_to_mflag(eve); - if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { - vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, ev, CD_BWEIGHT)*255.0f); + if (has_bweight) { + vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f); + } + vert_r++; } } } @@ -1406,26 +1400,28 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r) static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r) { BMesh *bm = ((EditDerivedBMesh *)dm)->tc->bm; - BMEdge *ee; + BMEdge *eed; BMIter iter; - int has_bweight = CustomData_has_layer(&bm->edata, CD_BWEIGHT); - int has_crease = CustomData_has_layer(&bm->edata, CD_CREASE); + const int has_bweight = CustomData_has_layer(&bm->edata, CD_BWEIGHT); + const int has_crease = CustomData_has_layer(&bm->edata, CD_CREASE); BM_mesh_elem_index_ensure(bm, BM_VERT); - for (ee = BM_iter_new(&iter, bm, BM_EDGES_OF_MESH, NULL); ee; ee = BM_iter_step(&iter), edge_r++) { + BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) { if (has_bweight) { - edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, ee, CD_BWEIGHT)*255.0f); + edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, eed, CD_BWEIGHT) * 255.0f); } if (has_crease) { - edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, ee, CD_CREASE)*255.0f); + edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, eed, CD_CREASE) * 255.0f); } - edge_r->flag = BM_edge_flag_to_mflag(ee); + edge_r->flag = BM_edge_flag_to_mflag(eed); - edge_r->v1 = BM_elem_index_get(ee->v1); - edge_r->v2 = BM_elem_index_get(ee->v2); + edge_r->v1 = BM_elem_index_get(eed->v1); + edge_r->v2 = BM_elem_index_get(eed->v2); + + edge_r++; } } @@ -1456,19 +1452,18 @@ static void emDM_copyTessFaceArray(DerivedMesh *dm, MFace *face_r) } } - static void emDM_copyLoopArray(DerivedMesh *dm, MLoop *loop_r) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMesh *bm = bmdm->tc->bm; BMIter iter, liter; - BMFace *f; + BMFace *efa; BMLoop *l; BM_mesh_elem_index_ensure(bm, BM_VERT | BM_EDGE); - BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { + BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { loop_r->v = BM_elem_index_get(l->v); loop_r->e = BM_elem_index_get(l->e); loop_r++; @@ -1481,18 +1476,18 @@ static void emDM_copyPolyArray(DerivedMesh *dm, MPoly *poly_r) EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMesh *bm = bmdm->tc->bm; BMIter iter; - BMFace *f; + BMFace *efa; int i; i = 0; - BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - poly_r->flag = BM_face_flag_to_mflag(f); + BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { + poly_r->flag = BM_face_flag_to_mflag(efa); poly_r->loopstart = i; - poly_r->totloop = f->len; - poly_r->mat_nr = f->mat_nr; + poly_r->totloop = efa->len; + poly_r->mat_nr = efa->mat_nr; poly_r++; - i += f->len; + i += efa->len; } } @@ -1586,52 +1581,51 @@ static void emDM_release(DerivedMesh *dm) static CustomData *bmDm_getVertDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->tc->bm->vdata; } static CustomData *bmDm_getEdgeDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->tc->bm->edata; } static CustomData *bmDm_getTessFaceDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->dm.faceData; } static CustomData *bmDm_getLoopDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->tc->bm->ldata; } static CustomData *bmDm_getPolyDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->tc->bm->pdata; } -DerivedMesh *getEditDerivedBMesh( - BMEditMesh *em, - Object *UNUSED(ob), - float (*vertexCos)[3]) +DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, + Object *UNUSED(ob), + float (*vertexCos)[3]) { EditDerivedBMesh *bmdm = MEM_callocN(sizeof(*bmdm), __func__); BMesh *bm = em->bm; bmdm->tc = em; - DM_init((DerivedMesh*)bmdm, DM_TYPE_EDITBMESH, em->bm->totvert, - em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface); + DM_init((DerivedMesh *)bmdm, DM_TYPE_EDITBMESH, em->bm->totvert, + em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface); bmdm->dm.getVertCos = emDM_getVertCos; bmdm->dm.getMinMax = emDM_getMinMax; @@ -1690,7 +1684,7 @@ DerivedMesh *getEditDerivedBMesh( BM_ITER_MESH_INDEX (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH, i) { DM_set_vert_data(&bmdm->dm, i, CD_MDEFORMVERT, - CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT)); + CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT)); } } @@ -1704,7 +1698,7 @@ DerivedMesh *getEditDerivedBMesh( BM_mesh_elem_index_ensure(bm, BM_VERT); bmdm->vertexNos = MEM_callocN(sizeof(*bmdm->vertexNos) * bm->totvert, "bmdm_vno"); - bmdm->polyNos = MEM_mallocN(sizeof(*bmdm->polyNos)*bm->totface, "bmdm_pno"); + bmdm->polyNos = MEM_mallocN(sizeof(*bmdm->polyNos) * bm->totface, "bmdm_pno"); BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) { BM_elem_index_set(efa, i); /* set_inline */ diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index fda078f5c42..07c5d6d0329 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -520,7 +520,8 @@ static float char_width(Curve *cu, VChar *che, CharInfo *info) } } -struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode){ +struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode) +{ VFont *vfont, *oldvfont; VFontData *vfd = NULL; Curve *cu; diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c index edde21ed7c8..8a49cba7649 100644 --- a/source/blender/blenkernel/intern/icons.c +++ b/source/blender/blenkernel/intern/icons.c @@ -51,11 +51,9 @@ #include "BLO_sys_types.h" // for intptr_t support -#define GS(a) (*((short *)(a))) - /* GLOBALS */ -static GHash* gIcons = NULL; +static GHash *gIcons = NULL; static int gNextIconId = 1; @@ -64,7 +62,7 @@ static int gFirstIconId = 1; static void icon_free(void *val) { - Icon* icon = val; + Icon *icon = val; if (icon) { if (icon->drawinfo_free) { @@ -84,15 +82,15 @@ static int get_next_free_id(void) int startId = gFirstIconId; /* if we haven't used up the int number range, we just return the next int */ - if (gNextIconId>=gFirstIconId) + if (gNextIconId >= gFirstIconId) return gNextIconId++; /* now we try to find the smallest icon id not stored in the gIcons hash */ - while (BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(startId)) && startId>=gFirstIconId) + while (BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(startId)) && startId >= gFirstIconId) startId++; /* if we found a suitable one that isn't used yet, return it */ - if (startId>=gFirstIconId) + if (startId >= gFirstIconId) return startId; /* fail */ @@ -105,7 +103,7 @@ void BKE_icons_init(int first_dyn_id) gFirstIconId = first_dyn_id; if (!gIcons) - gIcons = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "icons_init gh"); + gIcons = BLI_ghash_int_new("icons_init gh"); } void BKE_icons_free(void) @@ -115,14 +113,14 @@ void BKE_icons_free(void) gIcons = NULL; } -struct PreviewImage* BKE_previewimg_create(void) +PreviewImage *BKE_previewimg_create(void) { - PreviewImage* prv_img = NULL; + PreviewImage *prv_img = NULL; int i; prv_img = MEM_callocN(sizeof(PreviewImage), "img_prv"); - for (i=0; i<NUM_ICON_SIZES; ++i) { + for (i = 0; i < NUM_ICON_SIZES; ++i) { prv_img->changed[i] = 1; prv_img->changed_timestamp[i] = 0; } @@ -135,7 +133,7 @@ void BKE_previewimg_freefunc(void *link) if (prv) { int i; - for (i=0; i<NUM_ICON_SIZES;++i) { + for (i = 0; i < NUM_ICON_SIZES; ++i) { if (prv->rect[i]) { MEM_freeN(prv->rect[i]); prv->rect[i] = NULL; @@ -153,14 +151,14 @@ void BKE_previewimg_free(PreviewImage **prv) } } -struct PreviewImage* BKE_previewimg_copy(PreviewImage *prv) +PreviewImage *BKE_previewimg_copy(PreviewImage *prv) { - PreviewImage* prv_img = NULL; + PreviewImage *prv_img = NULL; int i; if (prv) { prv_img = MEM_dupallocN(prv); - for (i=0; i < NUM_ICON_SIZES; ++i) { + for (i = 0; i < NUM_ICON_SIZES; ++i) { if (prv->rect[i]) { prv_img->rect[i] = MEM_dupallocN(prv->rect[i]); } @@ -175,62 +173,62 @@ struct PreviewImage* BKE_previewimg_copy(PreviewImage *prv) void BKE_previewimg_free_id(ID *id) { if (GS(id->name) == ID_MA) { - Material *mat = (Material*)id; + Material *mat = (Material *)id; BKE_previewimg_free(&mat->preview); } else if (GS(id->name) == ID_TE) { - Tex *tex = (Tex*)id; + Tex *tex = (Tex *)id; BKE_previewimg_free(&tex->preview); } else if (GS(id->name) == ID_WO) { - World *wo = (World*)id; + World *wo = (World *)id; BKE_previewimg_free(&wo->preview); } else if (GS(id->name) == ID_LA) { - Lamp *la = (Lamp*)id; + Lamp *la = (Lamp *)id; BKE_previewimg_free(&la->preview); } else if (GS(id->name) == ID_IM) { - Image *img = (Image*)id; + Image *img = (Image *)id; BKE_previewimg_free(&img->preview); } else if (GS(id->name) == ID_BR) { - Brush *br = (Brush*)id; + Brush *br = (Brush *)id; BKE_previewimg_free(&br->preview); } } -PreviewImage* BKE_previewimg_get(ID *id) +PreviewImage *BKE_previewimg_get(ID *id) { - PreviewImage* prv_img = NULL; + PreviewImage *prv_img = NULL; if (GS(id->name) == ID_MA) { - Material *mat = (Material*)id; + Material *mat = (Material *)id; if (!mat->preview) mat->preview = BKE_previewimg_create(); prv_img = mat->preview; } else if (GS(id->name) == ID_TE) { - Tex *tex = (Tex*)id; + Tex *tex = (Tex *)id; if (!tex->preview) tex->preview = BKE_previewimg_create(); prv_img = tex->preview; } else if (GS(id->name) == ID_WO) { - World *wo = (World*)id; + World *wo = (World *)id; if (!wo->preview) wo->preview = BKE_previewimg_create(); prv_img = wo->preview; } else if (GS(id->name) == ID_LA) { - Lamp *la = (Lamp*)id; + Lamp *la = (Lamp *)id; if (!la->preview) la->preview = BKE_previewimg_create(); prv_img = la->preview; } else if (GS(id->name) == ID_IM) { - Image *img = (Image*)id; + Image *img = (Image *)id; if (!img->preview) img->preview = BKE_previewimg_create(); prv_img = img->preview; } else if (GS(id->name) == ID_BR) { - Brush *br = (Brush*)id; + Brush *br = (Brush *)id; if (!br->preview) br->preview = BKE_previewimg_create(); prv_img = br->preview; } @@ -240,19 +238,19 @@ PreviewImage* BKE_previewimg_get(ID *id) void BKE_icon_changed(int id) { - Icon* icon = NULL; + Icon *icon = NULL; if (!id || G.background) return; icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(id)); if (icon) { - PreviewImage *prv = BKE_previewimg_get((ID*)icon->obj); + PreviewImage *prv = BKE_previewimg_get((ID *)icon->obj); /* all previews changed */ if (prv) { int i; - for (i=0; i<NUM_ICON_SIZES; ++i) { + for (i = 0; i < NUM_ICON_SIZES; ++i) { prv->changed[i] = 1; prv->changed_timestamp[i]++; } @@ -260,9 +258,9 @@ void BKE_icon_changed(int id) } } -int BKE_icon_getid(struct ID* id) +int BKE_icon_getid(struct ID *id) { - Icon* new_icon = NULL; + Icon *new_icon = NULL; if (!id || G.background) return 0; @@ -291,9 +289,9 @@ int BKE_icon_getid(struct ID* id) return id->icon_id; } -Icon* BKE_icon_get(int icon_id) +Icon *BKE_icon_get(int icon_id) { - Icon* icon = NULL; + Icon *icon = NULL; icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(icon_id)); @@ -305,9 +303,9 @@ Icon* BKE_icon_get(int icon_id) return icon; } -void BKE_icon_set(int icon_id, struct Icon* icon) +void BKE_icon_set(int icon_id, struct Icon *icon) { - Icon* old_icon = NULL; + Icon *old_icon = NULL; old_icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(icon_id)); @@ -319,10 +317,10 @@ void BKE_icon_set(int icon_id, struct Icon* icon) BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(icon_id), icon); } -void BKE_icon_delete(struct ID* id) +void BKE_icon_delete(struct ID *id) { - if (!id->icon_id) return; /* no icon defined for library object */ + if (!id->icon_id) return; /* no icon defined for library object */ BLI_ghash_remove(gIcons, SET_INT_IN_POINTER(id->icon_id), NULL, icon_free); id->icon_id = 0; diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c index c3bd36348c6..c5d25276085 100644 --- a/source/blender/blenkernel/intern/idcode.c +++ b/source/blender/blenkernel/intern/idcode.c @@ -43,62 +43,62 @@ typedef struct { const char *name, *plural; int flags; -#define IDTYPE_FLAGS_ISLINKABLE (1<<0) +#define IDTYPE_FLAGS_ISLINKABLE (1 << 0) } IDType; /* plural need to match rna_main.c's MainCollectionDef */ -static IDType idtypes[]= { - { ID_AC, "Action", "actions", IDTYPE_FLAGS_ISLINKABLE}, - { ID_AR, "Armature", "armatures", IDTYPE_FLAGS_ISLINKABLE}, - { ID_BR, "Brush", "brushes", IDTYPE_FLAGS_ISLINKABLE}, - { ID_CA, "Camera", "cameras", IDTYPE_FLAGS_ISLINKABLE}, - { ID_CU, "Curve", "curves", IDTYPE_FLAGS_ISLINKABLE}, - { ID_GD, "GPencil", "grease_pencil", IDTYPE_FLAGS_ISLINKABLE}, /* rename gpencil */ - { ID_GR, "Group", "groups", IDTYPE_FLAGS_ISLINKABLE}, - { ID_ID, "ID", "ids", 0}, /* plural is fake */ - { ID_IM, "Image", "images", IDTYPE_FLAGS_ISLINKABLE}, - { ID_IP, "Ipo", "ipos", IDTYPE_FLAGS_ISLINKABLE}, /* deprecated */ - { ID_KE, "Key", "shape_keys", 0}, - { ID_LA, "Lamp", "lamps", IDTYPE_FLAGS_ISLINKABLE}, - { ID_LI, "Library", "libraries", 0}, - { ID_LS, "FreestyleLineStyle", "linestyles", IDTYPE_FLAGS_ISLINKABLE}, - { ID_LT, "Lattice", "lattices", IDTYPE_FLAGS_ISLINKABLE}, - { ID_MA, "Material", "materials", IDTYPE_FLAGS_ISLINKABLE}, - { ID_MB, "Metaball", "metaballs", IDTYPE_FLAGS_ISLINKABLE}, - { ID_ME, "Mesh", "meshes", IDTYPE_FLAGS_ISLINKABLE}, - { ID_NT, "NodeTree", "node_groups", IDTYPE_FLAGS_ISLINKABLE}, - { ID_OB, "Object", "objects", IDTYPE_FLAGS_ISLINKABLE}, - { ID_PA, "ParticleSettings", "particles", 0}, - { ID_SCE, "Scene", "scenes", IDTYPE_FLAGS_ISLINKABLE}, - { ID_SCR, "Screen", "screens", 0}, - { ID_SEQ, "Sequence", "sequences", 0}, /* not actually ID data */ - { ID_SPK, "Speaker", "speakers", IDTYPE_FLAGS_ISLINKABLE}, - { ID_SO, "Sound", "sounds", IDTYPE_FLAGS_ISLINKABLE}, - { ID_TE, "Texture", "textures", IDTYPE_FLAGS_ISLINKABLE}, - { ID_TXT, "Text", "texts", IDTYPE_FLAGS_ISLINKABLE}, - { ID_VF, "VFont", "fonts", IDTYPE_FLAGS_ISLINKABLE}, - { ID_WO, "World", "worlds", IDTYPE_FLAGS_ISLINKABLE}, - { ID_WM, "WindowManager", "window_managers", 0}, - { ID_MC, "MovieClip", "movieclips", IDTYPE_FLAGS_ISLINKABLE}, +static IDType idtypes[] = { + { ID_AC, "Action", "actions", IDTYPE_FLAGS_ISLINKABLE}, + { ID_AR, "Armature", "armatures", IDTYPE_FLAGS_ISLINKABLE}, + { ID_BR, "Brush", "brushes", IDTYPE_FLAGS_ISLINKABLE}, + { ID_CA, "Camera", "cameras", IDTYPE_FLAGS_ISLINKABLE}, + { ID_CU, "Curve", "curves", IDTYPE_FLAGS_ISLINKABLE}, + { ID_GD, "GPencil", "grease_pencil", IDTYPE_FLAGS_ISLINKABLE}, /* rename gpencil */ + { ID_GR, "Group", "groups", IDTYPE_FLAGS_ISLINKABLE}, + { ID_ID, "ID", "ids", 0}, /* plural is fake */ + { ID_IM, "Image", "images", IDTYPE_FLAGS_ISLINKABLE}, + { ID_IP, "Ipo", "ipos", IDTYPE_FLAGS_ISLINKABLE}, /* deprecated */ + { ID_KE, "Key", "shape_keys", 0}, + { ID_LA, "Lamp", "lamps", IDTYPE_FLAGS_ISLINKABLE}, + { ID_LI, "Library", "libraries", 0}, + { ID_LS, "FreestyleLineStyle", "linestyles", IDTYPE_FLAGS_ISLINKABLE}, + { ID_LT, "Lattice", "lattices", IDTYPE_FLAGS_ISLINKABLE}, + { ID_MA, "Material", "materials", IDTYPE_FLAGS_ISLINKABLE}, + { ID_MB, "Metaball", "metaballs", IDTYPE_FLAGS_ISLINKABLE}, + { ID_ME, "Mesh", "meshes", IDTYPE_FLAGS_ISLINKABLE}, + { ID_NT, "NodeTree", "node_groups", IDTYPE_FLAGS_ISLINKABLE}, + { ID_OB, "Object", "objects", IDTYPE_FLAGS_ISLINKABLE}, + { ID_PA, "ParticleSettings", "particles", 0}, + { ID_SCE, "Scene", "scenes", IDTYPE_FLAGS_ISLINKABLE}, + { ID_SCR, "Screen", "screens", 0}, + { ID_SEQ, "Sequence", "sequences", 0}, /* not actually ID data */ + { ID_SPK, "Speaker", "speakers", IDTYPE_FLAGS_ISLINKABLE}, + { ID_SO, "Sound", "sounds", IDTYPE_FLAGS_ISLINKABLE}, + { ID_TE, "Texture", "textures", IDTYPE_FLAGS_ISLINKABLE}, + { ID_TXT, "Text", "texts", IDTYPE_FLAGS_ISLINKABLE}, + { ID_VF, "VFont", "fonts", IDTYPE_FLAGS_ISLINKABLE}, + { ID_WO, "World", "worlds", IDTYPE_FLAGS_ISLINKABLE}, + { ID_WM, "WindowManager", "window_managers", 0}, + { ID_MC, "MovieClip", "movieclips", IDTYPE_FLAGS_ISLINKABLE}, }; -static int nidtypes= sizeof(idtypes)/sizeof(idtypes[0]); +static int nidtypes = sizeof(idtypes) / sizeof(idtypes[0]); static IDType *idtype_from_name(const char *str) { - int i= nidtypes; + int i = nidtypes; while (i--) - if (strcmp(str, idtypes[i].name)==0) + if (strcmp(str, idtypes[i].name) == 0) return &idtypes[i]; return NULL; } static IDType *idtype_from_code(int code) { - int i= nidtypes; + int i = nidtypes; while (i--) - if (code==idtypes[i].code) + if (code == idtypes[i].code) return &idtypes[i]; return NULL; @@ -106,34 +106,34 @@ static IDType *idtype_from_code(int code) int BKE_idcode_is_valid(int code) { - return idtype_from_code(code)?1:0; + return idtype_from_code(code) ? 1 : 0; } int BKE_idcode_is_linkable(int code) { - IDType *idt= idtype_from_code(code); - return idt?(idt->flags&IDTYPE_FLAGS_ISLINKABLE):0; + IDType *idt = idtype_from_code(code); + return idt ? (idt->flags & IDTYPE_FLAGS_ISLINKABLE) : 0; } const char *BKE_idcode_to_name(int code) { - IDType *idt= idtype_from_code(code); + IDType *idt = idtype_from_code(code); - return idt?idt->name:NULL; + return idt ? idt->name : NULL; } int BKE_idcode_from_name(const char *name) { - IDType *idt= idtype_from_name(name); + IDType *idt = idtype_from_name(name); - return idt?idt->code:0; + return idt ? idt->code : 0; } const char *BKE_idcode_to_name_plural(int code) { - IDType *idt= idtype_from_code(code); + IDType *idt = idtype_from_code(code); - return idt?idt->plural:NULL; + return idt ? idt->plural : NULL; } int BKE_idcode_iter_step(int *index) diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index e3735cfd374..42c7869a365 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -299,7 +299,8 @@ static IDProperty *IDP_CopyArray(IDProperty *prop) s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; \ s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; \ s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; \ - s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; } + s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; \ + } (void)0 diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index aff1e65224b..797a2093729 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -505,6 +505,20 @@ void BKE_image_merge(Image *dest, Image *source) } } +/* note, we could be clever and scale all imbuf's but since some are mipmaps its not so simple */ +void BKE_image_scale(Image *image, int width, int height) +{ + ImBuf *ibuf; + void *lock; + + ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); + + IMB_scaleImBuf(ibuf, width, height); + ibuf->userflags |= IB_BITMAPDIRTY; + + BKE_image_release_ibuf(image, lock); +} + Image *BKE_image_load(const char *filepath) { Image *ima; @@ -1729,7 +1743,8 @@ void BKE_makepicstring(char *string, const char *base, const char *relbase, int } /* used by sequencer too */ -struct anim *openanim(const char *name, int flags, int streamindex){ +struct anim *openanim(const char *name, int flags, int streamindex) +{ struct anim *anim; struct ImBuf *ibuf; @@ -2177,7 +2192,8 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) flag = IB_rect | IB_multilayer; if (ima->flag & IMA_DO_PREMUL) flag |= IB_premul; - ibuf = IMB_ibImageFromMemory((unsigned char *)ima->packedfile->data, ima->packedfile->size, flag, "<packed data>"); + ibuf = IMB_ibImageFromMemory((unsigned char *)ima->packedfile->data, + ima->packedfile->size, flag, "<packed data>"); } else { flag = IB_rect | IB_multilayer | IB_metadata; diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index e36e7bf6cf3..f4ec223a2fe 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1055,8 +1055,7 @@ static float *get_weights_array(Object *ob, char *vgroup) weights = MEM_callocN(totvert * sizeof(float), "weights"); if (em) { - eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for (i = 0; eve; eve = BM_iter_step(&iter), i++) { + BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); if (dvert) { diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index c6f2bb75858..6a69ffb474a 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -701,7 +701,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, if (defvert_find_weight(dvert, index) > 0.0f) { mul_m4_v3(cd.curvespace, vertexCos[a]); - DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); + minmax_v3v3_v3(cd.dmin, cd.dmax, vertexCos[a]); } } @@ -736,7 +736,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, for (a = 0; a < numVerts; a++) { mul_m4_v3(cd.curvespace, vertexCos[a]); - DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); + minmax_v3v3_v3(cd.dmin, cd.dmax, vertexCos[a]); } for (a = 0; a < numVerts; a++) { diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 8075aaa21d3..7da0661fef6 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -368,7 +368,7 @@ void BKE_mball_texspace_calc(Object *ob) data = dl->verts; while (tot--) { /* Also weird... but longer. From utildefines. */ - DO_MINMAX(data, min, max); + minmax_v3v3_v3(min, max, data); data += 3; } dl = dl->next; @@ -2397,7 +2397,7 @@ int BKE_mball_minmax(MetaBall *mb, float min[3], float max[3]) INIT_MINMAX(min, max); for (ml = mb->elems.first; ml; ml = ml->next) { - DO_MINMAX(&ml->x, min, max); + minmax_v3v3_v3(min, max, &ml->x); } return (mb->elems.first != NULL); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 944f06cf740..7a5c43b28f8 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -2092,8 +2092,9 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) mp->mat_nr = mf->mat_nr; mp->flag = mf->flag; -# define ML(v1, v2) {ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++; \ -} +# define ML(v1, v2) { \ + ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++; \ + } (void)0 ML(v1, v2); ML(v2, v3); @@ -2287,21 +2288,39 @@ void create_vert_poly_map(MeshElemMap **map, int **mem, /* Generates a map where the key is the vertex and the value is a list * of edges that use that vertex as an endpoint. The lists are allocated * from one memory pool. */ -void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, const int totvert, const int totedge) +void create_vert_edge_map(MeshElemMap **map, int **mem, + const MEdge *medge, int totvert, int totedge) { - int i, j; - IndexNode *node = NULL; - - (*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert edge map"); - (*mem) = MEM_callocN(sizeof(IndexNode) * totedge * 2, "vert edge map mem"); - node = *mem; + int i, *indices; + + (*map) = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert-edge map"); + (*mem) = MEM_mallocN(sizeof(int) * totedge * 2, "vert-edge map mem"); + + /* Count number of edges for each vertex */ + for (i = 0; i < totedge; i++) { + (*map)[medge[i].v1].count++; + (*map)[medge[i].v2].count++; + } + + /* Assign indices mem */ + indices = (*mem); + for (i = 0; i < totvert; i++) { + (*map)[i].indices = indices; + indices += (*map)[i].count; + /* Reset 'count' for use as index in last loop */ + (*map)[i].count = 0; + } + /* Find the users */ - for (i = 0; i < totedge; ++i) { - for (j = 0; j < 2; ++j, ++node) { - node->index = i; - BLI_addtail(&(*map)[((unsigned int *)(&medge[i].v1))[j]], node); - } + for (i = 0; i < totedge; i++) { + const int v[2] = {medge[i].v1, medge[i].v2}; + + (*map)[v[0]].indices[(*map)[v[0]].count] = i; + (*map)[v[1]].indices[(*map)[v[1]].count] = i; + + (*map)[v[0]].count++; + (*map)[v[1]].count++; } } @@ -2391,8 +2410,8 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, MFace *mface = NULL, *mf; BLI_array_declare(mface); ScanFillContext sf_ctx; - ScanFillVert *v, *lastv, *firstv; - ScanFillFace *f; + ScanFillVert *sf_vert, *sf_vert_last, *sf_vert_first; + ScanFillFace *sf_tri; int *mface_orig_index = NULL; BLI_array_declare(mface_orig_index); int *mface_to_poly_map = NULL; @@ -2485,21 +2504,21 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, ml = mloop + mp->loopstart; BLI_scanfill_begin(&sf_ctx); - firstv = NULL; - lastv = NULL; + sf_vert_first = NULL; + sf_vert_last = NULL; for (j = 0; j < mp->totloop; j++, ml++) { - v = BLI_scanfill_vert_add(&sf_ctx, mvert[ml->v].co); + sf_vert = BLI_scanfill_vert_add(&sf_ctx, mvert[ml->v].co); - v->keyindex = mp->loopstart + j; + sf_vert->keyindex = mp->loopstart + j; - if (lastv) - BLI_scanfill_edge_add(&sf_ctx, lastv, v); + if (sf_vert_last) + BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert); - if (!firstv) - firstv = v; - lastv = v; + if (!sf_vert_first) + sf_vert_first = sf_vert; + sf_vert_last = sf_vert; } - BLI_scanfill_edge_add(&sf_ctx, lastv, firstv); + BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert_first); totfilltri = BLI_scanfill_calc(&sf_ctx, FALSE); if (totfilltri) { @@ -2509,14 +2528,14 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, BLI_array_grow_items(mface_orig_index, totfilltri); } - for (f = sf_ctx.fillfacebase.first; f; f = f->next, mf++) { + for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next, mf++) { mface_to_poly_map[mface_index] = poly_index; mf = &mface[mface_index]; /* set loop indices, transformed to vert indices later */ - mf->v1 = f->v1->keyindex; - mf->v2 = f->v2->keyindex; - mf->v3 = f->v3->keyindex; + mf->v1 = sf_tri->v1->keyindex; + mf->v2 = sf_tri->v2->keyindex; + mf->v3 = sf_tri->v3->keyindex; mf->v4 = 0; mf->mat_nr = mp->mat_nr; @@ -2771,16 +2790,19 @@ static void mesh_calc_ngon_normal(MPoly *mpoly, MLoop *loopstart, { const int nverts = mpoly->totloop; float const *v_prev = mvert[loopstart[nverts - 1].v].co; - float const *v_curr = mvert[loopstart->v].co; - float n[3] = {0.0f}; + float const *v_curr; int i; + zero_v3(normal); + /* Newell's Method */ - for (i = 0; i < nverts; v_prev = v_curr, v_curr = mvert[loopstart[++i].v].co) { - add_newell_cross_v3_v3v3(n, v_prev, v_curr); + for (i = 0; i < nverts; i++) { + v_curr = mvert[loopstart[i].v].co; + add_newell_cross_v3_v3v3(normal, v_prev, v_curr); + v_prev = v_curr; } - if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) { + if (UNLIKELY(normalize_v3(normal) == 0.0f)) { normal[2] = 1.0f; /* other axis set to 0.0 */ } } @@ -2818,16 +2840,19 @@ static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart, { const int nverts = mpoly->totloop; float const *v_prev = vertex_coords[loopstart[nverts - 1].v]; - float const *v_curr = vertex_coords[loopstart->v]; - float n[3] = {0.0f}; + float const *v_curr; int i; + zero_v3(normal); + /* Newell's Method */ - for (i = 0; i < nverts; v_prev = v_curr, v_curr = vertex_coords[loopstart[++i].v]) { - add_newell_cross_v3_v3v3(n, v_prev, v_curr); + for (i = 0; i < nverts; i++) { + v_curr = vertex_coords[loopstart[i].v]; + add_newell_cross_v3_v3v3(normal, v_prev, v_curr); + v_prev = v_curr; } - if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) { + if (UNLIKELY(normalize_v3(normal) == 0.0f)) { normal[2] = 1.0f; /* other axis set to 0.0 */ } } @@ -3011,7 +3036,7 @@ int BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3]) int i = me->totvert; MVert *mvert; for (mvert = me->mvert; i--; mvert++) { - DO_MINMAX(mvert->co, r_min, r_max); + minmax_v3v3_v3(r_min, r_max, mvert->co); } return (me->totvert != 0); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 724d80afdd9..4e8b67bd55b 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -600,7 +600,7 @@ static void multires_copy_dm_grid(CCGElem *gridA, CCGElem *gridB, CCGKey *keyA, } /* Reallocate gpm->data at a lower resolution and copy values over - from the original high-resolution data */ + * from the original high-resolution data */ static void multires_grid_paint_mask_downsample(GridPaintMask *gpm, int level) { if (level < gpm->level) { @@ -1056,12 +1056,10 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm dispgrid = mdisp->disps; /* if needed, reallocate multires paint mask */ - if (gpm && op == CALC_DISPLACEMENTS) { - if (gpm->level < key.level) { - gpm->level = key.level; - MEM_freeN(gpm->data); - gpm->data = MEM_callocN(sizeof(float) * key.grid_area, "gpm.data"); - } + if (gpm && gpm->level < key.level) { + gpm->level = key.level; + MEM_freeN(gpm->data); + gpm->data = MEM_callocN(sizeof(float) * key.grid_area, "gpm.data"); } for (y = 0; y < gridSize; y++) { @@ -1094,7 +1092,7 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm break; case CALC_DISPLACEMENTS: /* Calculate displacement between new and old - * grid points and convert to tangent space */ + * grid points and convert to tangent space */ sub_v3_v3v3(disp, co, sco); invert_m3(mat); mul_v3_m3v3(data, mat, disp); @@ -1483,7 +1481,7 @@ DerivedMesh *multires_make_derived_from_derived(DerivedMesh *dm, } /**** Old Multires code **** -***************************/ + ***************************/ /* Adapted from sculptmode.c */ void old_mdisps_bilinear(float out[3], float (*disps)[3], const int st, float u, float v) diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 96c62a32139..2b4fe72e8bb 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -82,8 +82,8 @@ void free_nlastrip(ListBase *strips, NlaStrip *strip) return; /* free child-strips */ - for (cs= strip->strips.first; cs; cs= csn) { - csn= cs->next; + for (cs = strip->strips.first; cs; cs = csn) { + csn = cs->next; free_nlastrip(&strip->strips, cs); } @@ -120,8 +120,8 @@ void free_nlatrack(ListBase *tracks, NlaTrack *nlt) return; /* free strips */ - for (strip= nlt->strips.first; strip; strip= stripn) { - stripn= strip->next; + for (strip = nlt->strips.first; strip; strip = stripn) { + stripn = strip->next; free_nlastrip(&nlt->strips, strip); } @@ -144,19 +144,19 @@ void free_nladata(ListBase *tracks) return; /* free tracks one by one */ - for (nlt= tracks->first; nlt; nlt= nltn) { - nltn= nlt->next; + for (nlt = tracks->first; nlt; nlt = nltn) { + nltn = nlt->next; free_nlatrack(tracks, nlt); } /* clear the list's pointers to be safe */ - tracks->first= tracks->last= NULL; + tracks->first = tracks->last = NULL; } /* Copying ------------------------------------------- */ /* Copy NLA strip */ -NlaStrip *copy_nlastrip (NlaStrip *strip) +NlaStrip *copy_nlastrip(NlaStrip *strip) { NlaStrip *strip_d; NlaStrip *cs, *cs_d; @@ -166,8 +166,8 @@ NlaStrip *copy_nlastrip (NlaStrip *strip) return NULL; /* make a copy */ - strip_d= MEM_dupallocN(strip); - strip_d->next= strip_d->prev= NULL; + strip_d = MEM_dupallocN(strip); + strip_d->next = strip_d->prev = NULL; /* increase user-count of action */ if (strip_d->act) @@ -178,10 +178,10 @@ NlaStrip *copy_nlastrip (NlaStrip *strip) copy_fmodifiers(&strip_d->modifiers, &strip->modifiers); /* make a copy of all the child-strips, one at a time */ - strip_d->strips.first= strip_d->strips.last= NULL; + strip_d->strips.first = strip_d->strips.last = NULL; - for (cs= strip->strips.first; cs; cs= cs->next) { - cs_d= copy_nlastrip(cs); + for (cs = strip->strips.first; cs; cs = cs->next) { + cs_d = copy_nlastrip(cs); BLI_addtail(&strip_d->strips, cs_d); } @@ -190,7 +190,7 @@ NlaStrip *copy_nlastrip (NlaStrip *strip) } /* Copy NLA Track */ -NlaTrack *copy_nlatrack (NlaTrack *nlt) +NlaTrack *copy_nlatrack(NlaTrack *nlt) { NlaStrip *strip, *strip_d; NlaTrack *nlt_d; @@ -200,14 +200,14 @@ NlaTrack *copy_nlatrack (NlaTrack *nlt) return NULL; /* make a copy */ - nlt_d= MEM_dupallocN(nlt); - nlt_d->next= nlt_d->prev= NULL; + nlt_d = MEM_dupallocN(nlt); + nlt_d->next = nlt_d->prev = NULL; /* make a copy of all the strips, one at a time */ - nlt_d->strips.first= nlt_d->strips.last= NULL; + nlt_d->strips.first = nlt_d->strips.last = NULL; - for (strip= nlt->strips.first; strip; strip= strip->next) { - strip_d= copy_nlastrip(strip); + for (strip = nlt->strips.first; strip; strip = strip->next) { + strip_d = copy_nlastrip(strip); BLI_addtail(&nlt_d->strips, strip_d); } @@ -225,12 +225,12 @@ void copy_nladata(ListBase *dst, ListBase *src) return; /* clear out the destination list first for precautions... */ - dst->first= dst->last= NULL; + dst->first = dst->last = NULL; /* copy each NLA-track, one at a time */ - for (nlt= src->first; nlt; nlt= nlt->next) { + for (nlt = src->first; nlt; nlt = nlt->next) { /* make a copy, and add the copy to the destination list */ - nlt_d= copy_nlatrack(nlt); + nlt_d = copy_nlatrack(nlt); BLI_addtail(dst, nlt_d); } } @@ -240,7 +240,7 @@ void copy_nladata(ListBase *dst, ListBase *src) /* Add a NLA Track to the given AnimData * - prev: NLA-Track to add the new one after */ -NlaTrack *add_nlatrack (AnimData *adt, NlaTrack *prev) +NlaTrack *add_nlatrack(AnimData *adt, NlaTrack *prev) { NlaTrack *nlt; @@ -249,11 +249,11 @@ NlaTrack *add_nlatrack (AnimData *adt, NlaTrack *prev) return NULL; /* allocate new track */ - nlt= MEM_callocN(sizeof(NlaTrack), "NlaTrack"); + nlt = MEM_callocN(sizeof(NlaTrack), "NlaTrack"); /* set settings requiring the track to not be part of the stack yet */ nlt->flag = NLATRACK_SELECTED; - nlt->index= BLI_countlist(&adt->nla_tracks); + nlt->index = BLI_countlist(&adt->nla_tracks); /* add track to stack, and make it the active one */ if (prev) @@ -271,7 +271,7 @@ NlaTrack *add_nlatrack (AnimData *adt, NlaTrack *prev) } /* Add a NLA Strip referencing the given Action */ -NlaStrip *add_nlastrip (bAction *act) +NlaStrip *add_nlastrip(bAction *act) { NlaStrip *strip; @@ -280,7 +280,7 @@ NlaStrip *add_nlastrip (bAction *act) return NULL; /* allocate new strip */ - strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip"); + strip = MEM_callocN(sizeof(NlaStrip), "NlaStrip"); /* generic settings * - selected flag to highlight this to the user @@ -290,10 +290,10 @@ NlaStrip *add_nlastrip (bAction *act) * is not done though, since this should only really happens in editmode for strips now * though this decision is still subject to further review... */ - strip->flag = NLASTRIP_FLAG_SELECT|NLASTRIP_FLAG_AUTO_BLENDS; + strip->flag = NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_AUTO_BLENDS; /* assign the action reference */ - strip->act= act; + strip->act = act; id_us_plus(&act->id); /* determine initial range @@ -302,10 +302,10 @@ NlaStrip *add_nlastrip (bAction *act) calc_action_range(strip->act, &strip->actstart, &strip->actend, 0); strip->start = strip->actstart; - strip->end = (IS_EQF(strip->actstart, strip->actend)) ? (strip->actstart + 1.0f): (strip->actend); + strip->end = (IS_EQF(strip->actstart, strip->actend)) ? (strip->actstart + 1.0f) : (strip->actend); /* strip should be referenced as-is */ - strip->scale= 1.0f; + strip->scale = 1.0f; strip->repeat = 1.0f; /* return the new strip */ @@ -313,7 +313,7 @@ NlaStrip *add_nlastrip (bAction *act) } /* Add new NLA-strip to the top of the NLA stack - i.e. into the last track if space, or a new one otherwise */ -NlaStrip *add_nlastrip_to_stack (AnimData *adt, bAction *act) +NlaStrip *add_nlastrip_to_stack(AnimData *adt, bAction *act) { NlaStrip *strip; NlaTrack *nlt; @@ -323,7 +323,7 @@ NlaStrip *add_nlastrip_to_stack (AnimData *adt, bAction *act) return NULL; /* create a new NLA strip */ - strip= add_nlastrip(act); + strip = add_nlastrip(act); if (strip == NULL) return NULL; @@ -332,7 +332,7 @@ NlaStrip *add_nlastrip_to_stack (AnimData *adt, bAction *act) /* trying to add to the last track failed (no track or no space), * so add a new track to the stack, and add to that... */ - nlt= add_nlatrack(adt, NULL); + nlt = add_nlatrack(adt, NULL); BKE_nlatrack_add_strip(nlt, strip); } @@ -344,7 +344,7 @@ NlaStrip *add_nlastrip_to_stack (AnimData *adt, bAction *act) } /* Add a NLA Strip referencing the given speaker's sound */ -NlaStrip *add_nla_soundstrip (Scene *scene, Speaker *speaker) +NlaStrip *add_nla_soundstrip(Scene *scene, Speaker *speaker) { NlaStrip *strip = MEM_callocN(sizeof(NlaStrip), "NlaSoundStrip"); @@ -388,7 +388,7 @@ NlaStrip *add_nla_soundstrip (Scene *scene, Speaker *speaker) /* non clipped mapping for strip-time <-> global time (for Action-Clips) * invert = convert action-strip time to global time */ -static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short mode) +static float nlastrip_get_frame_actionclip(NlaStrip *strip, float cframe, short mode) { float actlength, scale; // float repeat; // UNUSED @@ -398,7 +398,7 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short // repeat = strip->repeat; // UNUSED /* scaling */ - if (IS_EQF(strip->scale, 0.0f)) strip->scale= 1.0f; + if (IS_EQF(strip->scale, 0.0f)) strip->scale = 1.0f; scale = fabsf(strip->scale); /* scale must be positive - we've got a special flag for reversing */ /* length of referenced action */ @@ -409,12 +409,12 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short if (strip->flag & NLASTRIP_FLAG_REVERSE) { // FIXME: this won't work right with Graph Editor? if (mode == NLATIME_CONVERT_MAP) { - return strip->end - scale*(cframe - strip->actstart); + return strip->end - scale * (cframe - strip->actstart); } else if (mode == NLATIME_CONVERT_UNMAP) { return (strip->end + (strip->actstart * scale - cframe)) / scale; } - else /* if (mode == NLATIME_CONVERT_EVAL) */{ + else { /* if (mode == NLATIME_CONVERT_EVAL) */ if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, ((int)strip->repeat))) { /* this case prevents the motion snapping back to the first frame at the end of the strip * by catching the case where repeats is a whole number, which means that the end of the strip @@ -426,18 +426,18 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short /* - the 'fmod(..., actlength*scale)' is needed to get the repeats working * - the '/ scale' is needed to ensure that scaling influences the timing within the repeat */ - return strip->actend - fmodf(cframe - strip->start, actlength*scale) / scale; + return strip->actend - fmodf(cframe - strip->start, actlength * scale) / scale; } } } else { if (mode == NLATIME_CONVERT_MAP) { - return strip->start + scale*(cframe - strip->actstart); + return strip->start + scale * (cframe - strip->actstart); } else if (mode == NLATIME_CONVERT_UNMAP) { return strip->actstart + (cframe - strip->start) / scale; } - else /* if (mode == NLATIME_CONVERT_EVAL) */{ + else { /* if (mode == NLATIME_CONVERT_EVAL) */ if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, ((int)strip->repeat))) { /* this case prevents the motion snapping back to the first frame at the end of the strip * by catching the case where repeats is a whole number, which means that the end of the strip @@ -449,7 +449,7 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short /* - the 'fmod(..., actlength*scale)' is needed to get the repeats working * - the '/ scale' is needed to ensure that scaling influences the timing within the repeat */ - return strip->actstart + fmodf(cframe - strip->start, actlength*scale) / scale; + return strip->actstart + fmodf(cframe - strip->start, actlength * scale) / scale; } } } @@ -458,12 +458,12 @@ static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short /* non clipped mapping for strip-time <-> global time (for Transitions) * invert = convert action-strip time to global time */ -static float nlastrip_get_frame_transition (NlaStrip *strip, float cframe, short mode) +static float nlastrip_get_frame_transition(NlaStrip *strip, float cframe, short mode) { float length; /* length of strip */ - length= strip->end - strip->start; + length = strip->end - strip->start; /* reversed = play strip backwards */ if (strip->flag & NLASTRIP_FLAG_REVERSE) { @@ -481,7 +481,7 @@ static float nlastrip_get_frame_transition (NlaStrip *strip, float cframe, short } /* non clipped mapping for strip-time <-> global time - * mode = eNlaTime_ConvertModes[] -> NLATIME_CONVERT_* + * mode = eNlaTime_ConvertModes[] -> NLATIME_CONVERT_* * * only secure for 'internal' (i.e. within AnimSys evaluation) operations, * but should not be directly relied on for stuff which interacts with editors @@ -515,17 +515,17 @@ float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, short mode) * - when not in tweakmode, the active Action does not have any scaling applied :) * - when in tweakmode, if the no-mapping flag is set, do not map */ - if ((adt == NULL) || (adt->flag & ADT_NLA_EDIT_ON)==0 || (adt->flag & ADT_NLA_EDIT_NOMAP)) + if ((adt == NULL) || (adt->flag & ADT_NLA_EDIT_ON) == 0 || (adt->flag & ADT_NLA_EDIT_NOMAP)) return cframe; /* if the active-strip info has been stored already, access this, otherwise look this up * and store for (very probable) future usage */ if (adt->actstrip == NULL) { - NlaTrack *nlt= BKE_nlatrack_find_active(&adt->nla_tracks); - adt->actstrip= BKE_nlastrip_find_active(nlt); + NlaTrack *nlt = BKE_nlatrack_find_active(&adt->nla_tracks); + adt->actstrip = BKE_nlastrip_find_active(nlt); } - strip= adt->actstrip; + strip = adt->actstrip; /* sanity checks * - in rare cases, we may not be able to find this strip for some reason (internal error) @@ -559,7 +559,7 @@ short BKE_nlastrips_has_space(ListBase *strips, float start, float end) } /* loop over NLA strips checking for any overlaps with this area... */ - for (strip= strips->first; strip; strip= strip->next) { + for (strip = strips->first; strip; strip = strip->next) { /* if start frame of strip is past the target end-frame, that means that * we've gone past the window we need to check for, so things are fine */ @@ -592,21 +592,21 @@ void BKE_nlastrips_sort_strips(ListBase *strips) /* we simply perform insertion sort on this list, since it is assumed that per track, * there are only likely to be at most 5-10 strips */ - for (strip= strips->first; strip; strip= stripn) { + for (strip = strips->first; strip; strip = stripn) { short not_added = 1; - stripn= strip->next; + stripn = strip->next; /* remove this strip from the list, and add it to the new list, searching from the end of * the list, assuming that the lists are in order */ BLI_remlink(strips, strip); - for (sstrip= tmp.last; sstrip; sstrip= sstrip->prev) { + for (sstrip = tmp.last; sstrip; sstrip = sstrip->prev) { /* check if add after */ if (sstrip->end <= strip->start) { BLI_insertlinkafter(&tmp, sstrip, strip); - not_added= 0; + not_added = 0; break; } } @@ -617,8 +617,8 @@ void BKE_nlastrips_sort_strips(ListBase *strips) } /* reassign the start and end points of the strips */ - strips->first= tmp.first; - strips->last= tmp.last; + strips->first = tmp.first; + strips->last = tmp.last; } /* Add the given NLA-Strip to the given list of strips, assuming that it @@ -634,15 +634,15 @@ short BKE_nlastrips_add_strip(ListBase *strips, NlaStrip *strip) return 0; /* check if any space to add */ - if (BKE_nlastrips_has_space(strips, strip->start, strip->end)==0) + if (BKE_nlastrips_has_space(strips, strip->start, strip->end) == 0) return 0; /* find the right place to add the strip to the nominated track */ - for (ns= strips->first; ns; ns= ns->next) { + for (ns = strips->first; ns; ns = ns->next) { /* if current strip occurs after the new strip, add it before */ if (ns->start >= strip->end) { BLI_insertlinkbefore(strips, ns, strip); - not_added= 0; + not_added = 0; break; } } @@ -672,14 +672,14 @@ void BKE_nlastrips_make_metas(ListBase *strips, short temp) return; /* group all continuous chains of selected strips into meta-strips */ - for (strip= strips->first; strip; strip= stripn) { - stripn= strip->next; + for (strip = strips->first; strip; strip = stripn) { + stripn = strip->next; if (strip->flag & NLASTRIP_FLAG_SELECT) { /* if there is an existing meta-strip, add this strip to it, otherwise, create a new one */ if (mstrip == NULL) { /* add a new meta-strip, and add it before the current strip that it will replace... */ - mstrip= MEM_callocN(sizeof(NlaStrip), "Meta-NlaStrip"); + mstrip = MEM_callocN(sizeof(NlaStrip), "Meta-NlaStrip"); mstrip->type = NLASTRIP_TYPE_META; BLI_insertlinkbefore(strips, strip, mstrip); @@ -691,10 +691,10 @@ void BKE_nlastrips_make_metas(ListBase *strips, short temp) mstrip->flag |= NLASTRIP_FLAG_TEMP_META; /* set default repeat/scale values to prevent warnings */ - mstrip->repeat= mstrip->scale= 1.0f; + mstrip->repeat = mstrip->scale = 1.0f; /* make its start frame be set to the start frame of the current strip */ - mstrip->start= strip->start; + mstrip->start = strip->start; } /* remove the selected strips from the track, and add to the meta */ @@ -702,13 +702,13 @@ void BKE_nlastrips_make_metas(ListBase *strips, short temp) BLI_addtail(&mstrip->strips, strip); /* expand the meta's dimensions to include the newly added strip- i.e. its last frame */ - mstrip->end= strip->end; + mstrip->end = strip->end; } else { /* current strip wasn't selected, so the end of 'island' of selected strips has been reached, * so stop adding strips to the current meta */ - mstrip= NULL; + mstrip = NULL; } } } @@ -725,8 +725,8 @@ void BKE_nlastrips_clear_metastrip(ListBase *strips, NlaStrip *strip) /* move each one of the meta-strip's children before the meta-strip * in the list of strips after unlinking them from the meta-strip */ - for (cs= strip->strips.first; cs; cs= csn) { - csn= cs->next; + for (cs = strip->strips.first; cs; cs = csn) { + csn = cs->next; BLI_remlink(&strip->strips, cs); BLI_insertlinkbefore(strips, strip, cs); } @@ -748,13 +748,13 @@ void BKE_nlastrips_clear_metas(ListBase *strips, short onlySel, short onlyTemp) return; /* remove meta-strips fitting the criteria of the arguments */ - for (strip= strips->first; strip; strip= stripn) { - stripn= strip->next; + for (strip = strips->first; strip; strip = stripn) { + stripn = strip->next; /* check if strip is a meta-strip */ if (strip->type == NLASTRIP_TYPE_META) { /* if check if selection and 'temporary-only' considerations are met */ - if ((onlySel==0) || (strip->flag & NLASTRIP_FLAG_SELECT)) { + if ((onlySel == 0) || (strip->flag & NLASTRIP_FLAG_SELECT)) { if ((!onlyTemp) || (strip->flag & NLASTRIP_FLAG_TEMP_META)) { BKE_nlastrips_clear_metastrip(strips, strip); } @@ -786,7 +786,7 @@ short BKE_nlameta_add_strip(NlaStrip *mstrip, NlaStrip *strip) if ((mstrip->prev == NULL) || (mstrip->prev->end <= strip->start)) { /* add strip to start of meta's list, and expand dimensions */ BLI_addhead(&mstrip->strips, strip); - mstrip->start= strip->start; + mstrip->start = strip->start; return 1; } @@ -800,7 +800,7 @@ short BKE_nlameta_add_strip(NlaStrip *mstrip, NlaStrip *strip) if ((mstrip->next == NULL) || (mstrip->next->start >= strip->end)) { /* add strip to end of meta's list, and expand dimensions */ BLI_addtail(&mstrip->strips, strip); - mstrip->end= strip->end; + mstrip->end = strip->end; return 1; } @@ -821,7 +821,7 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) NlaStrip *strip; float oStart, oEnd, offset; float oLen, nLen; - short scaleChanged= 0; + short scaleChanged = 0; /* sanity checks * - strip must exist @@ -836,9 +836,9 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) * - these are simply the start/end frames of the child strips, * since we assume they weren't transformed yet */ - oStart= ((NlaStrip *)mstrip->strips.first)->start; - oEnd= ((NlaStrip *)mstrip->strips.last)->end; - offset= mstrip->start - oStart; + oStart = ((NlaStrip *)mstrip->strips.first)->start; + oEnd = ((NlaStrip *)mstrip->strips.last)->end; + offset = mstrip->start - oStart; /* optimization: * don't flush if nothing changed yet @@ -851,20 +851,20 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) oLen = oEnd - oStart; nLen = mstrip->end - mstrip->start; if (IS_EQF(nLen, oLen) == 0) - scaleChanged= 1; + scaleChanged = 1; /* for each child-strip, calculate new start/end points based on this new info */ - for (strip= mstrip->strips.first; strip; strip= strip->next) { + for (strip = mstrip->strips.first; strip; strip = strip->next) { if (scaleChanged) { float p1, p2; /* compute positions of endpoints relative to old extents of strip */ - p1= (strip->start - oStart) / oLen; - p2= (strip->end - oStart) / oLen; + p1 = (strip->start - oStart) / oLen; + p2 = (strip->end - oStart) / oLen; /* apply new strip endpoints using the proportions, then wait for second pass to flush scale properly */ - strip->start= (p1 * nLen) + mstrip->start; - strip->end= (p2 * nLen) + mstrip->start; + strip->start = (p1 * nLen) + mstrip->start; + strip->end = (p2 * nLen) + mstrip->start; } else { /* just apply the changes in offset to both ends of the strip */ @@ -874,7 +874,7 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) } /* apply a second pass over child strips, to finish up unfinished business */ - for (strip= mstrip->strips.first; strip; strip= strip->next) { + for (strip = mstrip->strips.first; strip; strip = strip->next) { /* only if scale changed, need to perform RNA updates */ if (scaleChanged) { PointerRNA ptr; @@ -894,7 +894,7 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) /* NLA-Tracks ---------------------------------------- */ /* Find the active NLA-track for the given stack */ -NlaTrack *BKE_nlatrack_find_active (ListBase *tracks) +NlaTrack *BKE_nlatrack_find_active(ListBase *tracks) { NlaTrack *nlt; @@ -903,7 +903,7 @@ NlaTrack *BKE_nlatrack_find_active (ListBase *tracks) return NULL; /* try to find the first active track */ - for (nlt= tracks->first; nlt; nlt= nlt->next) { + for (nlt = tracks->first; nlt; nlt = nlt->next) { if (nlt->flag & NLATRACK_ACTIVE) return nlt; } @@ -924,7 +924,7 @@ void BKE_nlatrack_solo_toggle(AnimData *adt, NlaTrack *nlt) return; /* firstly, make sure 'solo' flag for all tracks is disabled */ - for (nt= adt->nla_tracks.first; nt; nt= nt->next) { + for (nt = adt->nla_tracks.first; nt; nt = nt->next) { if (nt != nlt) nt->flag &= ~NLATRACK_SOLO; } @@ -956,7 +956,7 @@ void BKE_nlatrack_set_active(ListBase *tracks, NlaTrack *nlt_a) return; /* deactive all the rest */ - for (nlt= tracks->first; nlt; nlt= nlt->next) + for (nlt = tracks->first; nlt; nlt = nlt->next) nlt->flag &= ~NLATRACK_ACTIVE; /* set the given one as the active one */ @@ -968,9 +968,9 @@ void BKE_nlatrack_set_active(ListBase *tracks, NlaTrack *nlt_a) short BKE_nlatrack_has_space(NlaTrack *nlt, float start, float end) { /* sanity checks - * - track must exist - * - track must be editable - * - bounds cannot be equal (0-length is nasty) + * - track must exist + * - track must be editable + * - bounds cannot be equal (0-length is nasty) */ if ((nlt == NULL) || (nlt->flag & NLATRACK_PROTECTED) || IS_EQF(start, end)) return 0; @@ -1042,7 +1042,7 @@ short BKE_nlatrack_get_bounds(NlaTrack *nlt, float bounds[2]) /* NLA Strips -------------------------------------- */ /* Find the active NLA-strip within the given track */ -NlaStrip *BKE_nlastrip_find_active (NlaTrack *nlt) +NlaStrip *BKE_nlastrip_find_active(NlaTrack *nlt) { NlaStrip *strip; @@ -1051,7 +1051,7 @@ NlaStrip *BKE_nlastrip_find_active (NlaTrack *nlt) return NULL; /* try to find the first active strip */ - for (strip= nlt->strips.first; strip; strip= strip->next) { + for (strip = nlt->strips.first; strip; strip = strip->next) { if (strip->flag & NLASTRIP_FLAG_ACTIVE) return strip; } @@ -1071,8 +1071,8 @@ void BKE_nlastrip_set_active(AnimData *adt, NlaStrip *strip) return; /* loop over tracks, deactivating*/ - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) { - for (nls= nlt->strips.first; nls; nls= nls->next) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + for (nls = nlt->strips.first; nls; nls = nls->next) { if (nls != strip) nls->flag &= ~NLASTRIP_FLAG_ACTIVE; else @@ -1085,8 +1085,8 @@ void BKE_nlastrip_set_active(AnimData *adt, NlaStrip *strip) /* Does the given NLA-strip fall within the given bounds (times)? */ short BKE_nlastrip_within_bounds(NlaStrip *strip, float min, float max) { - const float stripLen= (strip) ? strip->end - strip->start : 0.0f; - const float boundsLen= fabsf(max - min); + const float stripLen = (strip) ? strip->end - strip->start : 0.0f; + const float boundsLen = fabsf(max - min); /* sanity checks */ if ((strip == NULL) || IS_EQF(stripLen, 0.0f) || IS_EQF(boundsLen, 0.0f)) @@ -1128,10 +1128,10 @@ void BKE_nlastrip_recalculate_bounds(NlaStrip *strip) return; /* calculate new length factors */ - actlen= strip->actend - strip->actstart; - if (IS_EQF(actlen, 0.0f)) actlen= 1.0f; + actlen = strip->actend - strip->actstart; + if (IS_EQF(actlen, 0.0f)) actlen = 1.0f; - mapping= strip->scale * strip->repeat; + mapping = strip->scale * strip->repeat; /* adjust endpoint of strip in response to this */ if (IS_EQF(mapping, 0.0f) == 0) @@ -1140,7 +1140,7 @@ void BKE_nlastrip_recalculate_bounds(NlaStrip *strip) /* Is the given NLA-strip the first one to occur for the given AnimData block */ // TODO: make this an api method if necesary, but need to add prefix first -static short nlastrip_is_first (AnimData *adt, NlaStrip *strip) +static short nlastrip_is_first(AnimData *adt, NlaStrip *strip) { NlaTrack *nlt; NlaStrip *ns; @@ -1155,9 +1155,9 @@ static short nlastrip_is_first (AnimData *adt, NlaStrip *strip) /* check other tracks to see if they have a strip that's earlier */ // TODO: or should we check that the strip's track is also the first? - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { /* only check the first strip, assuming that they're all in order */ - ns= nlt->strips.first; + ns = nlt->strips.first; if (ns) { if (ns->start < strip->start) return 0; @@ -1180,7 +1180,7 @@ short BKE_nlatrack_has_animated_strips(NlaTrack *nlt) return 0; /* check each strip for F-Curves only (don't care about whether the flags are set) */ - for (strip= nlt->strips.first; strip; strip= strip->next) { + for (strip = nlt->strips.first; strip; strip = strip->next) { if (strip->fcurves.first) return 1; } @@ -1199,7 +1199,7 @@ short BKE_nlatracks_have_animated_strips(ListBase *tracks) return 0; /* check each track, stopping on the first hit */ - for (nlt= tracks->first; nlt; nlt= nlt->next) { + for (nlt = tracks->first; nlt; nlt = nlt->next) { if (BKE_nlatrack_has_animated_strips(nlt)) return 1; } @@ -1220,19 +1220,19 @@ void BKE_nlastrip_validate_fcurves(NlaStrip *strip) /* if controlling influence... */ if (strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) { /* try to get F-Curve */ - fcu= list_find_fcurve(&strip->fcurves, "influence", 0); + fcu = list_find_fcurve(&strip->fcurves, "influence", 0); /* add one if not found */ if (fcu == NULL) { /* make new F-Curve */ - fcu= MEM_callocN(sizeof(FCurve), "NlaStrip FCurve"); + fcu = MEM_callocN(sizeof(FCurve), "NlaStrip FCurve"); BLI_addtail(&strip->fcurves, fcu); /* set default flags */ - fcu->flag = (FCURVE_VISIBLE|FCURVE_SELECTED); + fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED); /* store path - make copy, and store that */ - fcu->rna_path= BLI_strdupn("influence", 9); + fcu->rna_path = BLI_strdupn("influence", 9); // TODO: insert a few keyframes to ensure default behavior? } @@ -1241,19 +1241,19 @@ void BKE_nlastrip_validate_fcurves(NlaStrip *strip) /* if controlling time... */ if (strip->flag & NLASTRIP_FLAG_USR_TIME) { /* try to get F-Curve */ - fcu= list_find_fcurve(&strip->fcurves, "strip_time", 0); + fcu = list_find_fcurve(&strip->fcurves, "strip_time", 0); /* add one if not found */ if (fcu == NULL) { /* make new F-Curve */ - fcu= MEM_callocN(sizeof(FCurve), "NlaStrip FCurve"); + fcu = MEM_callocN(sizeof(FCurve), "NlaStrip FCurve"); BLI_addtail(&strip->fcurves, fcu); /* set default flags */ - fcu->flag = (FCURVE_VISIBLE|FCURVE_SELECTED); + fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED); /* store path - make copy, and store that */ - fcu->rna_path= BLI_strdupn("strip_time", 10); + fcu->rna_path = BLI_strdupn("strip_time", 10); // TODO: insert a few keyframes to ensure default behavior? } @@ -1283,10 +1283,10 @@ void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip) return; /* give strip a default name if none already */ - if (strip->name[0]==0) { + if (strip->name[0] == 0) { switch (strip->type) { case NLASTRIP_TYPE_CLIP: /* act-clip */ - BLI_strncpy(strip->name, (strip->act)?(strip->act->id.name+2):("<No Action>"), sizeof(strip->name)); + BLI_strncpy(strip->name, (strip->act) ? (strip->act->id.name + 2) : ("<No Action>"), sizeof(strip->name)); break; case NLASTRIP_TYPE_TRANSITION: /* transition */ BLI_strncpy(strip->name, "Transition", sizeof(strip->name)); @@ -1304,10 +1304,10 @@ void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip) * - this is easier than iterating over all the tracks+strips hierarchy everytime * (and probably faster) */ - gh= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "nlastrip_validate_name gh"); + gh = BLI_ghash_str_new("nlastrip_validate_name gh"); - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) { - for (tstrip= nlt->strips.first; tstrip; tstrip= tstrip->next) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + for (tstrip = nlt->strips.first; tstrip; tstrip = tstrip->next) { /* don't add the strip of interest */ if (tstrip == strip) continue; @@ -1333,7 +1333,7 @@ void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip) * - track: nla-track that the overlapping strips should be found from * - start, end: frames for the offending endpoints */ -static void nlastrip_get_endpoint_overlaps (NlaStrip *strip, NlaTrack *track, float **start, float **end) +static void nlastrip_get_endpoint_overlaps(NlaStrip *strip, NlaTrack *track, float **start, float **end) { NlaStrip *nls; @@ -1341,46 +1341,46 @@ static void nlastrip_get_endpoint_overlaps (NlaStrip *strip, NlaTrack *track, fl * but which don't cover the entire length */ // TODO: this scheme could get quite slow for doing this on many strips... - for (nls= track->strips.first; nls; nls= nls->next) { + for (nls = track->strips.first; nls; nls = nls->next) { /* check if strip overlaps (extends over or exactly on) the entire range of the strip we're validating */ if ((nls->start <= strip->start) && (nls->end >= strip->end)) { - *start= NULL; - *end= NULL; + *start = NULL; + *end = NULL; return; } /* check if strip doesn't even occur anywhere near... */ if (nls->end < strip->start) - continue; /* skip checking this strip... not worthy of mention */ + continue; /* skip checking this strip... not worthy of mention */ if (nls->start > strip->end) - return; /* the range we're after has already passed */ + return; /* the range we're after has already passed */ /* if this strip is not part of an island of continuous strips, it can be used * - this check needs to be done for each end of the strip we try and use... */ - if ((nls->next == NULL) || IS_EQF(nls->next->start, nls->end)==0) { + if ((nls->next == NULL) || IS_EQF(nls->next->start, nls->end) == 0) { if ((nls->end > strip->start) && (nls->end < strip->end)) - *start= &nls->end; + *start = &nls->end; } - if ((nls->prev == NULL) || IS_EQF(nls->prev->end, nls->start)==0) { + if ((nls->prev == NULL) || IS_EQF(nls->prev->end, nls->start) == 0) { if ((nls->start < strip->end) && (nls->start > strip->start)) - *end= &nls->start; + *end = &nls->start; } } } /* Determine auto-blending for the given strip */ -static void BKE_nlastrip_validate_autoblends (NlaTrack *nlt, NlaStrip *nls) +static void BKE_nlastrip_validate_autoblends(NlaTrack *nlt, NlaStrip *nls) { - float *ps=NULL, *pe=NULL; - float *ns=NULL, *ne=NULL; + float *ps = NULL, *pe = NULL; + float *ns = NULL, *ne = NULL; /* sanity checks */ if (ELEM(NULL, nls, nlt)) return; if ((nlt->prev == NULL) && (nlt->next == NULL)) return; - if ((nls->flag & NLASTRIP_FLAG_AUTO_BLENDS)==0) + if ((nls->flag & NLASTRIP_FLAG_AUTO_BLENDS) == 0) return; /* get test ranges */ @@ -1394,31 +1394,31 @@ static void BKE_nlastrip_validate_autoblends (NlaTrack *nlt, NlaStrip *nls) * is directly followed/preceeded by another strip, forming an * 'island' of continuous strips */ - if ((ps || ns) && ((nls->prev == NULL) || IS_EQF(nls->prev->end, nls->start)==0)) { + if ((ps || ns) && ((nls->prev == NULL) || IS_EQF(nls->prev->end, nls->start) == 0)) { /* start overlaps - pick the largest overlap */ if ( ((ps && ns) && (*ps > *ns)) || (ps) ) - nls->blendin= *ps - nls->start; + nls->blendin = *ps - nls->start; else - nls->blendin= *ns - nls->start; + nls->blendin = *ns - nls->start; } else /* no overlap allowed/needed */ - nls->blendin= 0.0f; + nls->blendin = 0.0f; - if ((pe || ne) && ((nls->next == NULL) || IS_EQF(nls->next->start, nls->end)==0)) { + if ((pe || ne) && ((nls->next == NULL) || IS_EQF(nls->next->start, nls->end) == 0)) { /* end overlaps - pick the largest overlap */ if ( ((pe && ne) && (*pe > *ne)) || (pe) ) - nls->blendout= nls->end - *pe; + nls->blendout = nls->end - *pe; else - nls->blendout= nls->end - *ne; + nls->blendout = nls->end - *ne; } else /* no overlap allowed/needed */ - nls->blendout= 0.0f; + nls->blendout = 0.0f; } /* Ensure that auto-blending and other settings are set correctly */ void BKE_nla_validate_state(AnimData *adt) { - NlaStrip *strip, *fstrip=NULL; + NlaStrip *strip, *fstrip = NULL; NlaTrack *nlt; /* sanity checks */ @@ -1426,20 +1426,20 @@ void BKE_nla_validate_state(AnimData *adt) return; /* adjust blending values for auto-blending, and also do an initial pass to find the earliest strip */ - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) { - for (strip= nlt->strips.first; strip; strip= strip->next) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + for (strip = nlt->strips.first; strip; strip = strip->next) { /* auto-blending first */ BKE_nlastrip_validate_autoblends(nlt, strip); /* extend mode - find first strip */ if ((fstrip == NULL) || (strip->start < fstrip->start)) - fstrip= strip; + fstrip = strip; } } /* second pass over the strips to adjust the extend-mode to fix any problems */ - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) { - for (strip= nlt->strips.first; strip; strip= strip->next) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + for (strip = nlt->strips.first; strip; strip = strip->next) { /* apart from 'nothing' option which user has to explicitly choose, we don't really know if * we should be overwriting the extend setting (but assume that's what the user wanted) */ @@ -1454,9 +1454,9 @@ void BKE_nla_validate_state(AnimData *adt) * Should fix problems such as [#29869] */ if (strip == fstrip) - strip->extendmode= NLASTRIP_EXTEND_HOLD; + strip->extendmode = NLASTRIP_EXTEND_HOLD; else if (strip->blendmode == NLASTRIP_MODE_REPLACE) - strip->extendmode= NLASTRIP_EXTEND_HOLD_FORWARD; + strip->extendmode = NLASTRIP_EXTEND_HOLD_FORWARD; } } } @@ -1489,13 +1489,13 @@ void BKE_nla_action_pushdown(AnimData *adt) } /* add a new NLA strip to the track, which references the active action */ - strip= add_nlastrip_to_stack(adt, adt->action); + strip = add_nlastrip_to_stack(adt, adt->action); /* do other necessary work on strip */ if (strip) { /* clear reference to action now that we've pushed it onto the stack */ id_us_min(&adt->action->id); - adt->action= NULL; + adt->action = NULL; /* if the strip is the first one in the track it lives in, check if there * are strips in any other tracks that may be before this, and set the extend @@ -1506,7 +1506,7 @@ void BKE_nla_action_pushdown(AnimData *adt) * so that it doesn't override strips in previous tracks */ // FIXME: this needs to be more automated, since user can rearrange strips - strip->extendmode= NLASTRIP_EXTEND_HOLD_FORWARD; + strip->extendmode = NLASTRIP_EXTEND_HOLD_FORWARD; } /* make strip the active one... */ @@ -1520,8 +1520,8 @@ void BKE_nla_action_pushdown(AnimData *adt) */ short BKE_nla_tweakmode_enter(AnimData *adt) { - NlaTrack *nlt, *activeTrack=NULL; - NlaStrip *strip, *activeStrip=NULL; + NlaTrack *nlt, *activeTrack = NULL; + NlaStrip *strip, *activeStrip = NULL; /* verify that data is valid */ if (ELEM(NULL, adt, adt->nla_tracks.first)) @@ -1534,16 +1534,16 @@ short BKE_nla_tweakmode_enter(AnimData *adt) return 1; /* go over the tracks, finding the active one, and its active strip - * - if we cannot find both, then there's nothing to do + * - if we cannot find both, then there's nothing to do */ - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { /* check if active */ if (nlt->flag & NLATRACK_ACTIVE) { /* store reference to this active track */ - activeTrack= nlt; + activeTrack = nlt; /* now try to find active strip */ - activeStrip= BKE_nlastrip_find_active(nlt); + activeStrip = BKE_nlastrip_find_active(nlt); break; } } @@ -1557,18 +1557,18 @@ short BKE_nla_tweakmode_enter(AnimData *adt) for (nlt = adt->nla_tracks.last; nlt; nlt = nlt->prev) { if (nlt->flag & NLATRACK_SELECTED) { /* assume this is the active track */ - activeTrack= nlt; + activeTrack = nlt; /* try to find active strip */ - activeStrip= BKE_nlastrip_find_active(nlt); + activeStrip = BKE_nlastrip_find_active(nlt); break; } } } if ((activeTrack) && (activeStrip == NULL)) { /* no active strip in active or last selected track; compromise for first selected (assuming only single)... */ - for (strip = activeTrack->strips.first; strip; strip= strip->next) { - if (strip->flag & (NLASTRIP_FLAG_SELECT|NLASTRIP_FLAG_ACTIVE)) { + for (strip = activeTrack->strips.first; strip; strip = strip->next) { + if (strip->flag & (NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_ACTIVE)) { activeStrip = strip; break; } @@ -1586,8 +1586,8 @@ short BKE_nla_tweakmode_enter(AnimData *adt) /* go over all the tracks up to the active one, tagging each strip that uses the same * action as the active strip, but leaving everything else alone */ - for (nlt= activeTrack->prev; nlt; nlt= nlt->prev) { - for (strip= nlt->strips.first; strip; strip= strip->next) { + for (nlt = activeTrack->prev; nlt; nlt = nlt->prev) { + for (strip = nlt->strips.first; strip; strip = strip->next) { if (strip->act == activeStrip->act) strip->flag |= NLASTRIP_FLAG_TWEAKUSER; else @@ -1599,7 +1599,7 @@ short BKE_nla_tweakmode_enter(AnimData *adt) /* go over all the tracks after AND INCLUDING the active one, tagging them as being disabled * - the active track needs to also be tagged, otherwise, it'll overlap with the tweaks going on */ - for (nlt= activeTrack; nlt; nlt= nlt->next) + for (nlt = activeTrack; nlt; nlt = nlt->next) nlt->flag |= NLATRACK_DISABLED; /* handle AnimData level changes: @@ -1608,9 +1608,9 @@ short BKE_nla_tweakmode_enter(AnimData *adt) * - editing-flag for this AnimData block should also get turned on (for more efficient restoring) * - take note of the active strip for mapping-correction of keyframes in the action being edited */ - adt->tmpact= adt->action; - adt->action= activeStrip->act; - adt->actstrip= activeStrip; + adt->tmpact = adt->action; + adt->action = activeStrip->act; + adt->actstrip = activeStrip; id_us_plus(&activeStrip->act->id); adt->flag |= ADT_NLA_EDIT_ON; @@ -1637,10 +1637,10 @@ void BKE_nla_tweakmode_exit(AnimData *adt) /* for all Tracks, clear the 'disabled' flag * for all Strips, clear the 'tweak-user' flag */ - for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) { + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { nlt->flag &= ~NLATRACK_DISABLED; - for (strip= nlt->strips.first; strip; strip= strip->next) + for (strip = nlt->strips.first; strip; strip = strip->next) strip->flag &= ~NLASTRIP_FLAG_TWEAKUSER; } @@ -1652,15 +1652,15 @@ void BKE_nla_tweakmode_exit(AnimData *adt) * - clear pointer to active strip */ if (adt->action) adt->action->id.us--; - adt->action= adt->tmpact; - adt->tmpact= NULL; - adt->actstrip= NULL; + adt->action = adt->tmpact; + adt->tmpact = NULL; + adt->actstrip = NULL; adt->flag &= ~ADT_NLA_EDIT_ON; } /* Baking Tools ------------------------------------------- */ -static void UNUSED_FUNCTION(BKE_nla_bake) (Scene *scene, ID *UNUSED(id), AnimData *adt, int UNUSED(flag)) +static void UNUSED_FUNCTION(BKE_nla_bake) (Scene * scene, ID *UNUSED(id), AnimData * adt, int UNUSED(flag)) { /* verify that data is valid diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index a25cd0d3b38..c6424580a31 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1930,6 +1930,13 @@ static void registerCompositNodes(bNodeTreeType *ttype) register_node_type_cmp_transform(ttype); register_node_type_cmp_stabilize2d(ttype); register_node_type_cmp_moviedistortion(ttype); + + register_node_type_cmp_colorcorrection(ttype); + register_node_type_cmp_boxmask(ttype); + register_node_type_cmp_ellipsemask(ttype); + register_node_type_cmp_bokehimage(ttype); + register_node_type_cmp_bokehblur(ttype); + register_node_type_cmp_switch(ttype); } static void registerShaderNodes(bNodeTreeType *ttype) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 7bf0eadf088..6fec35add8b 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2269,7 +2269,7 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3]) for (a = 0; a < 8; a++) { mul_m4_v3(ob->obmat, bb.vec[a]); - DO_MINMAX(bb.vec[a], min_r, max_r); + minmax_v3v3_v3(min_r, max_r, bb.vec[a]); } change = TRUE; } @@ -2284,7 +2284,7 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3]) for (v = 0; v < lt->pntsv; v++) { for (u = 0; u < lt->pntsu; u++, bp++) { mul_v3_m4v3(vec, ob->obmat, bp->vec); - DO_MINMAX(vec, min_r, max_r); + minmax_v3v3_v3(min_r, max_r, vec); } } } @@ -2296,9 +2296,9 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3]) bPoseChannel *pchan; for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { mul_v3_m4v3(vec, ob->obmat, pchan->pose_head); - DO_MINMAX(vec, min_r, max_r); + minmax_v3v3_v3(min_r, max_r, vec); mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail); - DO_MINMAX(vec, min_r, max_r); + minmax_v3v3_v3(min_r, max_r, vec); } change = TRUE; } @@ -2312,7 +2312,7 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3]) for (a = 0; a < 8; a++) { mul_m4_v3(ob->obmat, bb.vec[a]); - DO_MINMAX(bb.vec[a], min_r, max_r); + minmax_v3v3_v3(min_r, max_r, bb.vec[a]); } change = TRUE; } @@ -2321,15 +2321,15 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3]) } if (change == FALSE) { - DO_MINMAX(ob->obmat[3], min_r, max_r); + minmax_v3v3_v3(min_r, max_r, ob->obmat[3]); copy_v3_v3(vec, ob->obmat[3]); add_v3_v3(vec, ob->size); - DO_MINMAX(vec, min_r, max_r); + minmax_v3v3_v3(min_r, max_r, vec); copy_v3_v3(vec, ob->obmat[3]); sub_v3_v3(vec, ob->size); - DO_MINMAX(vec, min_r, max_r); + minmax_v3v3_v3(min_r, max_r, vec); } } @@ -2353,7 +2353,7 @@ int BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_ma for (i = 0; i < 8; i++) { float vec[3]; mul_v3_m4v3(vec, dob->mat, bb->vec[i]); - DO_MINMAX(vec, r_min, r_max); + minmax_v3v3_v3(r_min, r_max, vec); } ok = 1; @@ -3030,6 +3030,19 @@ int BKE_object_is_deform_modified(Scene *scene, Object *ob) return flag; } +/* See if an object is using an animated modifier */ +int BKE_object_is_animated(Scene *scene, Object *ob) +{ + ModifierData *md; + + for (md = modifiers_getVirtualModifierList(ob); md; md = md->next) + if(modifier_dependsOnTime(md) && + (modifier_isEnabled(scene, md, eModifierMode_Realtime) || + modifier_isEnabled(scene, md, eModifierMode_Render))) + return 1; + return 0; +} + static void copy_object__forwardModifierLinks(void *UNUSED(userData), Object *UNUSED(ob), ID **idpoin) { /* this is copied from ID_NEW; it might be better to have a macro */ diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 6242976d323..e76cde652c8 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -39,7 +39,7 @@ #include "BKE_ocean.h" #include "BKE_utildefines.h" -#include "BKE_global.h" // XXX TESTING +#include "BKE_global.h" // XXX TESTING #include "BLI_math_base.h" #include "BLI_math_inline.h" @@ -84,7 +84,7 @@ typedef struct Ocean { float _Lx; float _Lz; - float normalize_factor; // init w + float normalize_factor; // init w float time; short _do_disp_y; @@ -98,73 +98,71 @@ typedef struct Ocean { /* ********* sim data arrays ********* */ /* two dimensional arrays of complex */ - fftw_complex *_fft_in; // init w sim w - fftw_complex *_fft_in_x; // init w sim w - fftw_complex *_fft_in_z; // init w sim w - fftw_complex *_fft_in_jxx; // init w sim w - fftw_complex *_fft_in_jzz; // init w sim w - fftw_complex *_fft_in_jxz; // init w sim w - fftw_complex *_fft_in_nx; // init w sim w - fftw_complex *_fft_in_nz; // init w sim w - fftw_complex *_htilda; // init w sim w (only once) + fftw_complex *_fft_in; // init w sim w + fftw_complex *_fft_in_x; // init w sim w + fftw_complex *_fft_in_z; // init w sim w + fftw_complex *_fft_in_jxx; // init w sim w + fftw_complex *_fft_in_jzz; // init w sim w + fftw_complex *_fft_in_jxz; // init w sim w + fftw_complex *_fft_in_nx; // init w sim w + fftw_complex *_fft_in_nz; // init w sim w + fftw_complex *_htilda; // init w sim w (only once) /* fftw "plans" */ - fftw_plan _disp_y_plan; // init w sim r - fftw_plan _disp_x_plan; // init w sim r - fftw_plan _disp_z_plan; // init w sim r - fftw_plan _N_x_plan; // init w sim r - fftw_plan _N_z_plan; // init w sim r - fftw_plan _Jxx_plan; // init w sim r - fftw_plan _Jxz_plan; // init w sim r - fftw_plan _Jzz_plan; // init w sim r + fftw_plan _disp_y_plan; // init w sim r + fftw_plan _disp_x_plan; // init w sim r + fftw_plan _disp_z_plan; // init w sim r + fftw_plan _N_x_plan; // init w sim r + fftw_plan _N_z_plan; // init w sim r + fftw_plan _Jxx_plan; // init w sim r + fftw_plan _Jxz_plan; // init w sim r + fftw_plan _Jzz_plan; // init w sim r /* two dimensional arrays of float */ - double * _disp_y; // init w sim w via plan? - double * _N_x; // init w sim w via plan? + double *_disp_y; // init w sim w via plan? + double *_N_x; // init w sim w via plan? /*float * _N_y; all member of this array has same values, so convert this array to a float to reduce memory usage (MEM01)*/ - double _N_y; // sim w ********* can be rearranged? - double * _N_z; // init w sim w via plan? - double * _disp_x; // init w sim w via plan? - double * _disp_z; // init w sim w via plan? + double _N_y; // sim w ********* can be rearranged? + double *_N_z; // init w sim w via plan? + double *_disp_x; // init w sim w via plan? + double *_disp_z; // init w sim w via plan? /* two dimensional arrays of float */ /* Jacobian and minimum eigenvalue */ - double * _Jxx; // init w sim w - double * _Jzz; // init w sim w - double * _Jxz; // init w sim w + double *_Jxx; // init w sim w + double *_Jzz; // init w sim w + double *_Jxz; // init w sim w /* one dimensional float array */ - float * _kx; // init w sim r - float * _kz; // init w sim r + float *_kx; // init w sim r + float *_kz; // init w sim r /* two dimensional complex array */ - fftw_complex * _h0; // init w sim r - fftw_complex * _h0_minus; // init w sim r + fftw_complex *_h0; // init w sim r + fftw_complex *_h0_minus; // init w sim r /* two dimensional float array */ - float * _k; // init w sim r + float *_k; // init w sim r } Ocean; static float nextfr(float min, float max) { - return BLI_frand()*(min-max)+max; + return BLI_frand() * (min - max) + max; } -static float gaussRand (void) +static float gaussRand(void) { - float x; // Note: to avoid numerical problems with very small - float y; // numbers, we make these variables singe-precision - float length2; // floats, but later we call the double-precision log() + float x; // Note: to avoid numerical problems with very small + float y; // numbers, we make these variables singe-precision + float length2; // floats, but later we call the double-precision log() // and sqrt() functions instead of logf() and sqrtf(). - do - { - x = (float) (nextfr (-1, 1)); - y = (float)(nextfr (-1, 1)); + do { + x = (float) (nextfr(-1, 1)); + y = (float)(nextfr(-1, 1)); length2 = x * x + y * y; - } - while (length2 >= 1 || length2 == 0); + } while (length2 >= 1 || length2 == 0); return x * sqrtf(-2.0f * logf(length2) / length2); } @@ -174,63 +172,63 @@ static float gaussRand (void) * */ MINLINE float lerp(float a, float b, float f) { - return a + (b-a)*f; + return a + (b - a) * f; } MINLINE float catrom(float p0, float p1, float p2, float p3, float f) { - return 0.5f *((2.0f * p1) + - (-p0 + p2) * f + - (2.0f*p0 - 5.0f*p1 + 4.0f*p2 - p3) * f*f + - (-p0 + 3.0f*p1- 3.0f*p2 + p3) * f*f*f); + return 0.5f * ((2.0f * p1) + + (-p0 + p2) * f + + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * f * f + + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * f * f * f); } MINLINE float omega(float k, float depth) { - return sqrt(GRAVITY*k * tanh(k*depth)); + return sqrt(GRAVITY * k * tanh(k * depth)); } // modified Phillips spectrum -static float Ph(struct Ocean* o, float kx, float kz ) +static float Ph(struct Ocean *o, float kx, float kz) { float tmp; - float k2 = kx*kx + kz*kz; + float k2 = kx * kx + kz * kz; if (k2 == 0.0f) { return 0.0f; // no DC component } // damp out the waves going in the direction opposite the wind - tmp = (o->_wx * kx + o->_wz * kz)/sqrtf(k2); + tmp = (o->_wx * kx + o->_wz * kz) / sqrtf(k2); if (tmp < 0) { tmp *= o->_damp_reflections; } - return o->_A * expf( -1.0f / (k2*(o->_L*o->_L))) * expf(-k2 * (o->_l*o->_l)) * powf(fabsf(tmp), o->_wind_alignment) / (k2*k2); + return o->_A * expf(-1.0f / (k2 * (o->_L * o->_L))) * expf(-k2 * (o->_l * o->_l)) * powf(fabsf(tmp), o->_wind_alignment) / (k2 * k2); } static void compute_eigenstuff(struct OceanResult *ocr, float jxx, float jzz, float jxz) { float a, b, qplus, qminus; a = jxx + jzz; - b = sqrt((jxx - jzz)*(jxx - jzz) + 4 * jxz * jxz); + b = sqrt((jxx - jzz) * (jxx - jzz) + 4 * jxz * jxz); - ocr->Jminus = 0.5f*(a-b); - ocr->Jplus = 0.5f*(a+b); + ocr->Jminus = 0.5f * (a - b); + ocr->Jplus = 0.5f * (a + b); - qplus = (ocr->Jplus - jxx)/jxz; - qminus = (ocr->Jminus - jxx)/jxz; + qplus = (ocr->Jplus - jxx) / jxz; + qminus = (ocr->Jminus - jxx) / jxz; - a = sqrt(1 + qplus*qplus); - b = sqrt(1 + qminus*qminus); + a = sqrt(1 + qplus * qplus); + b = sqrt(1 + qminus * qminus); - ocr->Eplus[0] = 1.0f/ a; + ocr->Eplus[0] = 1.0f / a; ocr->Eplus[1] = 0.0f; - ocr->Eplus[2] = qplus/a; + ocr->Eplus[2] = qplus / a; - ocr->Eminus[0] = 1.0f/b; + ocr->Eminus[0] = 1.0f / b; ocr->Eminus[1] = 0.0f; - ocr->Eminus[2] = qminus/b; + ocr->Eminus[2] = qminus / b; } /* @@ -244,7 +242,7 @@ static void init_complex(fftw_complex cmpl, float real, float image) cmpl[1] = image; } -#if 0 // unused +#if 0 // unused static void add_complex_f(fftw_complex res, fftw_complex cmpl, float f) { res[0] = cmpl[0] + f; @@ -260,15 +258,15 @@ static void add_comlex_c(fftw_complex res, fftw_complex cmpl1, fftw_complex cmpl static void mul_complex_f(fftw_complex res, fftw_complex cmpl, float f) { - res[0] = cmpl[0]*f; - res[1] = cmpl[1]*f; + res[0] = cmpl[0] * f; + res[1] = cmpl[1] * f; } static void mul_complex_c(fftw_complex res, fftw_complex cmpl1, fftw_complex cmpl2) { fftwf_complex temp; - temp[0] = cmpl1[0]*cmpl2[0]-cmpl1[1]*cmpl2[1]; - temp[1] = cmpl1[0]*cmpl2[1]+cmpl1[1]*cmpl2[0]; + temp[0] = cmpl1[0] * cmpl2[0] - cmpl1[1] * cmpl2[1]; + temp[1] = cmpl1[0] * cmpl2[1] + cmpl1[1] * cmpl2[0]; res[0] = temp[0]; res[1] = temp[1]; } @@ -293,15 +291,15 @@ static void exp_complex(fftw_complex res, fftw_complex cmpl) { float r = expf(cmpl[0]); - res[0] = cos(cmpl[1])*r; - res[1] = sin(cmpl[1])*r; + res[0] = cos(cmpl[1]) * r; + res[1] = sin(cmpl[1]) * r; } float BKE_ocean_jminus_to_foam(float jminus, float coverage) { float foam = jminus * -0.005f + coverage; CLAMP(foam, 0.0f, 1.0f); - return foam*foam; + return foam * foam; } void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float v) @@ -338,7 +336,7 @@ void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float j1 = j1 % oc->_N; -#define BILERP(m) (lerp(lerp(m[i0*oc->_N+j0], m[i1*oc->_N+j0], frac_x), lerp(m[i0*oc->_N+j1], m[i1*oc->_N+j1], frac_x), frac_z)) +#define BILERP(m) (lerp(lerp(m[i0 * oc->_N + j0], m[i1 * oc->_N + j0], frac_x), lerp(m[i0 * oc->_N + j1], m[i1 * oc->_N + j1], frac_x), frac_z)) { if (oc->_do_disp_y) { ocr->disp[1] = BILERP(oc->_disp_y); @@ -346,7 +344,7 @@ void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float if (oc->_do_normals) { ocr->normal[0] = BILERP(oc->_N_x); - ocr->normal[1] = oc->_N_y/*BILERP(oc->_N_y) (MEM01)*/; + ocr->normal[1] = oc->_N_y /*BILERP(oc->_N_y) (MEM01)*/; ocr->normal[2] = BILERP(oc->_N_z); } @@ -402,21 +400,21 @@ void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u i2 = i2 % oc->_M; j2 = j2 % oc->_N; - i0 = (i1-1); - i3 = (i2+1); + i0 = (i1 - 1); + i3 = (i2 + 1); i0 = i0 < 0 ? i0 + oc->_M : i0; i3 = i3 >= oc->_M ? i3 - oc->_M : i3; - j0 = (j1-1); - j3 = (j2+1); + j0 = (j1 - 1); + j3 = (j2 + 1); j0 = j0 < 0 ? j0 + oc->_N : j0; j3 = j3 >= oc->_N ? j3 - oc->_N : j3; -#define INTERP(m) catrom(catrom(m[i0*oc->_N+j0], m[i1*oc->_N+j0], m[i2*oc->_N+j0], m[i3*oc->_N+j0], frac_x), \ - catrom(m[i0*oc->_N+j1], m[i1*oc->_N+j1], m[i2*oc->_N+j1], m[i3*oc->_N+j1], frac_x), \ - catrom(m[i0*oc->_N+j2], m[i1*oc->_N+j2], m[i2*oc->_N+j2], m[i3*oc->_N+j2], frac_x), \ - catrom(m[i0*oc->_N+j3], m[i1*oc->_N+j3], m[i2*oc->_N+j3], m[i3*oc->_N+j3], frac_x), \ - frac_z) +#define INTERP(m) catrom(catrom(m[i0 * oc->_N + j0], m[i1 * oc->_N + j0], m[i2 * oc->_N + j0], m[i3 * oc->_N + j0], frac_x), \ + catrom(m[i0 * oc->_N + j1], m[i1 * oc->_N + j1], m[i2 * oc->_N + j1], m[i3 * oc->_N + j1], frac_x), \ + catrom(m[i0 * oc->_N + j2], m[i1 * oc->_N + j2], m[i2 * oc->_N + j2], m[i3 * oc->_N + j2], frac_x), \ + catrom(m[i0 * oc->_N + j3], m[i1 * oc->_N + j3], m[i2 * oc->_N + j3], m[i3 * oc->_N + j3], frac_x), \ + frac_z) { if (oc->_do_disp_y) { @@ -424,7 +422,7 @@ void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u } if (oc->_do_normals) { ocr->normal[0] = INTERP(oc->_N_x); - ocr->normal[1] = oc->_N_y/*INTERP(oc->_N_y) (MEM01)*/; + ocr->normal[1] = oc->_N_y /*INTERP(oc->_N_y) (MEM01)*/; ocr->normal[2] = INTERP(oc->_N_z); } if (oc->_do_chop) { @@ -448,12 +446,12 @@ void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u void BKE_ocean_eval_xz(struct Ocean *oc, struct OceanResult *ocr, float x, float z) { - BKE_ocean_eval_uv(oc, ocr, x/oc->_Lx, z/oc->_Lz); + BKE_ocean_eval_uv(oc, ocr, x / oc->_Lx, z / oc->_Lz); } void BKE_ocean_eval_xz_catrom(struct Ocean *oc, struct OceanResult *ocr, float x, float z) { - BKE_ocean_eval_uv_catrom(oc, ocr, x/oc->_Lx, z/oc->_Lz); + BKE_ocean_eval_uv_catrom(oc, ocr, x / oc->_Lx, z / oc->_Lz); } // note that this doesn't wrap properly for i, j < 0, but its @@ -466,11 +464,11 @@ void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i, int j) i = abs(i) % oc->_M; j = abs(j) % oc->_N; - ocr->disp[1] = oc->_do_disp_y ? oc->_disp_y[i*oc->_N+j] : 0.0f; + ocr->disp[1] = oc->_do_disp_y ? oc->_disp_y[i * oc->_N + j] : 0.0f; if (oc->_do_chop) { - ocr->disp[0] = oc->_disp_x[i*oc->_N+j]; - ocr->disp[2] = oc->_disp_z[i*oc->_N+j]; + ocr->disp[0] = oc->_disp_x[i * oc->_N + j]; + ocr->disp[2] = oc->_disp_z[i * oc->_N + j]; } else { ocr->disp[0] = 0.0f; @@ -478,15 +476,15 @@ void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i, int j) } if (oc->_do_normals) { - ocr->normal[0] = oc->_N_x[i*oc->_N+j]; - ocr->normal[1] = oc->_N_y/*oc->_N_y[i*oc->_N+j] (MEM01)*/; - ocr->normal[2] = oc->_N_z[i*oc->_N+j]; + ocr->normal[0] = oc->_N_x[i * oc->_N + j]; + ocr->normal[1] = oc->_N_y /*oc->_N_y[i*oc->_N+j] (MEM01)*/; + ocr->normal[2] = oc->_N_z[i * oc->_N + j]; normalize_v3(ocr->normal); } if (oc->_do_jacobian) { - compute_eigenstuff(ocr, oc->_Jxx[i*oc->_N+j], oc->_Jzz[i*oc->_N+j], oc->_Jxz[i*oc->_N+j]); + compute_eigenstuff(ocr, oc->_Jxx[i * oc->_N + j], oc->_Jzz[i * oc->_N + j], oc->_Jxz[i * oc->_N + j]); } BLI_rw_mutex_unlock(&oc->oceanmutex); @@ -502,26 +500,26 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount // compute a new htilda #pragma omp parallel for private(i, j) - for (i = 0 ; i < o->_M ; ++i) { + for (i = 0; i < o->_M; ++i) { // note the <= _N/2 here, see the fftw doco about // the mechanics of the complex->real fft storage - for ( j = 0 ; j <= o->_N / 2 ; ++j) { + for (j = 0; j <= o->_N / 2; ++j) { fftw_complex exp_param1; fftw_complex exp_param2; fftw_complex conj_param; - init_complex(exp_param1, 0.0, omega(o->_k[i*(1+o->_N/2)+j], o->_depth)*t); - init_complex(exp_param2, 0.0, -omega(o->_k[i*(1+o->_N/2)+j], o->_depth)*t); + init_complex(exp_param1, 0.0, omega(o->_k[i * (1 + o->_N / 2) + j], o->_depth) * t); + init_complex(exp_param2, 0.0, -omega(o->_k[i * (1 + o->_N / 2) + j], o->_depth) * t); exp_complex(exp_param1, exp_param1); exp_complex(exp_param2, exp_param2); - conj_complex(conj_param, o->_h0_minus[i*o->_N+j]); + conj_complex(conj_param, o->_h0_minus[i * o->_N + j]); - mul_complex_c(exp_param1, o->_h0[i*o->_N+j], exp_param1); + mul_complex_c(exp_param1, o->_h0[i * o->_N + j], exp_param1); mul_complex_c(exp_param2, conj_param, exp_param2); - add_comlex_c(o->_htilda[i*(1+o->_N/2)+j], exp_param1, exp_param2); - mul_complex_f(o->_fft_in[i*(1+o->_N/2)+j], o->_htilda[i*(1+o->_N/2)+j], scale); + add_comlex_c(o->_htilda[i * (1 + o->_N / 2) + j], exp_param1, exp_param2); + mul_complex_f(o->_fft_in[i * (1 + o->_N / 2) + j], o->_htilda[i * (1 + o->_N / 2) + j], scale); } } @@ -540,8 +538,8 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { if (o->_do_chop) { // x displacement - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j <= o->_N / 2 ; ++j) { + for (i = 0; i < o->_M; ++i) { + for (j = 0; j <= o->_N / 2; ++j) { fftw_complex mul_param; fftw_complex minus_i; @@ -549,9 +547,9 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount init_complex(mul_param, -scale, 0); mul_complex_f(mul_param, mul_param, chop_amount); mul_complex_c(mul_param, mul_param, minus_i); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kx[i] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_x[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0 ? 0.0 : o->_kx[i] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_x[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_disp_x_plan); @@ -562,8 +560,8 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { if (o->_do_chop) { // z displacement - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j <= o->_N / 2 ; ++j) { + for (i = 0; i < o->_M; ++i) { + for (j = 0; j <= o->_N / 2; ++j) { fftw_complex mul_param; fftw_complex minus_i; @@ -571,9 +569,9 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount init_complex(mul_param, -scale, 0); mul_complex_f(mul_param, mul_param, chop_amount); mul_complex_c(mul_param, mul_param, minus_i); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kz[j] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_z[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0 ? 0.0 : o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_z[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_disp_z_plan); @@ -584,24 +582,24 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { if (o->_do_jacobian) { // Jxx - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j <= o->_N / 2 ; ++j) { + for (i = 0; i < o->_M; ++i) { + for (j = 0; j <= o->_N / 2; ++j) { fftw_complex mul_param; //init_complex(mul_param, -scale, 0); init_complex(mul_param, -1, 0); mul_complex_f(mul_param, mul_param, chop_amount); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kx[i]*o->_kx[i] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_jxx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0 ? 0.0 : o->_kx[i] * o->_kx[i] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_jxx[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_Jxx_plan); - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j < o->_N ; ++j) { - o->_Jxx[i*o->_N+j] += 1.0; + for (i = 0; i < o->_M; ++i) { + for (j = 0; j < o->_N; ++j) { + o->_Jxx[i * o->_N + j] += 1.0; } } } @@ -611,23 +609,23 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { if (o->_do_jacobian) { // Jzz - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j <= o->_N / 2 ; ++j) { + for (i = 0; i < o->_M; ++i) { + for (j = 0; j <= o->_N / 2; ++j) { fftw_complex mul_param; //init_complex(mul_param, -scale, 0); init_complex(mul_param, -1, 0); mul_complex_f(mul_param, mul_param, chop_amount); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kz[j]*o->_kz[j] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_jzz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0 ? 0.0 : o->_kz[j] * o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_jzz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_Jzz_plan); - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j < o->_N ; ++j) { - o->_Jzz[i*o->_N+j] += 1.0; + for (i = 0; i < o->_M; ++i) { + for (j = 0; j < o->_N; ++j) { + o->_Jzz[i * o->_N + j] += 1.0; } } } @@ -637,17 +635,17 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { if (o->_do_jacobian) { // Jxz - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j <= o->_N / 2 ; ++j) { + for (i = 0; i < o->_M; ++i) { + for (j = 0; j <= o->_N / 2; ++j) { fftw_complex mul_param; //init_complex(mul_param, -scale, 0); init_complex(mul_param, -1, 0); mul_complex_f(mul_param, mul_param, chop_amount); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0f ? 0.0f : o->_kx[i]*o->_kz[j] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_jxz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0f ? 0.0f : o->_kx[i] * o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_jxz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_Jxz_plan); @@ -658,14 +656,14 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { // fft normals if (o->_do_normals) { - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j <= o->_N / 2 ; ++j) { + for (i = 0; i < o->_M; ++i) { + for (j = 0; j <= o->_N / 2; ++j) { fftw_complex mul_param; init_complex(mul_param, 0.0, -1.0); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); mul_complex_f(mul_param, mul_param, o->_kx[i]); - init_complex(o->_fft_in_nx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + init_complex(o->_fft_in_nx[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_N_x_plan); @@ -676,27 +674,27 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { if (o->_do_normals) { - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j <= o->_N / 2 ; ++j) { + for (i = 0; i < o->_M; ++i) { + for (j = 0; j <= o->_N / 2; ++j) { fftw_complex mul_param; init_complex(mul_param, 0.0, -1.0); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); mul_complex_f(mul_param, mul_param, o->_kz[i]); - init_complex(o->_fft_in_nz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + init_complex(o->_fft_in_nz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_N_z_plan); #if 0 - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j < o->_N ; ++j) { - o->_N_y[i*o->_N+j] = 1.0f/scale; + for (i = 0; i < o->_M; ++i) { + for (j = 0; j < o->_N; ++j) { + o->_N_y[i * o->_N + j] = 1.0f / scale; } } (MEM01) #endif - o->_N_y = 1.0f/scale; + o->_N_y = 1.0f / scale; } } // section 8 @@ -722,15 +720,15 @@ static void set_height_normalize_factor(struct Ocean *oc) for (i = 0; i < oc->_M; ++i) { for (j = 0; j < oc->_N; ++j) { - if ( max_h < fabsf(oc->_disp_y[i*oc->_N+j])) { - max_h = fabsf(oc->_disp_y[i*oc->_N+j]); + if (max_h < fabsf(oc->_disp_y[i * oc->_N + j])) { + max_h = fabsf(oc->_disp_y[i * oc->_N + j]); } } } BLI_rw_mutex_unlock(&oc->oceanmutex); - if (max_h == 0.0f) max_h = 0.00001f; // just in case ... + if (max_h == 0.0f) max_h = 0.00001f; // just in case ... res = 1.0f / (max_h); @@ -746,8 +744,8 @@ struct Ocean *BKE_add_ocean(void) return oc; } -void BKE_init_ocean(struct Ocean* o, int M, int N, float Lx, float Lz, float V, float l, float A, float w, float damp, - float alignment, float depth, float time, short do_height_field, short do_chop, short do_normals, short do_jacobian, int seed) +void BKE_init_ocean(struct Ocean *o, int M, int N, float Lx, float Lz, float V, float l, float A, float w, float damp, + float alignment, float depth, float time, short do_height_field, short do_chop, short do_normals, short do_jacobian, int seed) { int i, j, ii; @@ -766,7 +764,7 @@ void BKE_init_ocean(struct Ocean* o, int M, int N, float Lx, float Lz, float V, o->_Lz = Lz; o->_wx = cos(w); o->_wz = -sin(w); // wave direction - o->_L = V*V / GRAVITY; // largest wave for a given velocity V + o->_L = V * V / GRAVITY; // largest wave for a given velocity V o->time = time; o->_do_disp_y = do_height_field; @@ -774,11 +772,11 @@ void BKE_init_ocean(struct Ocean* o, int M, int N, float Lx, float Lz, float V, o->_do_chop = do_chop; o->_do_jacobian = do_jacobian; - o->_k = (float*) MEM_mallocN(M * (1+N/2) * sizeof(float), "ocean_k"); - o->_h0 = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0"); - o->_h0_minus = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0_minus"); - o->_kx = (float*) MEM_mallocN(o->_M * sizeof(float), "ocean_kx"); - o->_kz = (float*) MEM_mallocN(o->_N * sizeof(float), "ocean_kz"); + o->_k = (float *) MEM_mallocN(M * (1 + N / 2) * sizeof(float), "ocean_k"); + o->_h0 = (fftw_complex *) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0"); + o->_h0_minus = (fftw_complex *) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0_minus"); + o->_kx = (float *) MEM_mallocN(o->_M * sizeof(float), "ocean_kx"); + o->_kz = (float *) MEM_mallocN(o->_N * sizeof(float), "ocean_kz"); // make this robust in the face of erroneous usage if (o->_Lx == 0.0f) @@ -788,79 +786,79 @@ void BKE_init_ocean(struct Ocean* o, int M, int N, float Lx, float Lz, float V, o->_Lz = 0.001f; // the +ve components and DC - for (i = 0 ; i <= o->_M/2 ; ++i) + for (i = 0; i <= o->_M / 2; ++i) o->_kx[i] = 2.0f * (float)M_PI * i / o->_Lx; // the -ve components - for (i = o->_M-1, ii=0 ; i > o->_M/2 ; --i, ++ii) + for (i = o->_M - 1, ii = 0; i > o->_M / 2; --i, ++ii) o->_kx[i] = -2.0f * (float)M_PI * ii / o->_Lx; // the +ve components and DC - for (i = 0 ; i <= o->_N/2 ; ++i) + for (i = 0; i <= o->_N / 2; ++i) o->_kz[i] = 2.0f * (float)M_PI * i / o->_Lz; // the -ve components - for (i = o->_N-1, ii=0 ; i > o->_N/2 ; --i, ++ii) + for (i = o->_N - 1, ii = 0; i > o->_N / 2; --i, ++ii) o->_kz[i] = -2.0f * (float)M_PI * ii / o->_Lz; // pre-calculate the k matrix - for (i = 0 ; i < o->_M ; ++i) - for (j = 0 ; j <= o->_N / 2 ; ++j) - o->_k[i*(1+o->_N/2)+j] = sqrt(o->_kx[i]*o->_kx[i] + o->_kz[j]*o->_kz[j] ); + for (i = 0; i < o->_M; ++i) + for (j = 0; j <= o->_N / 2; ++j) + o->_k[i * (1 + o->_N / 2) + j] = sqrt(o->_kx[i] * o->_kx[i] + o->_kz[j] * o->_kz[j]); /*srand(seed);*/ BLI_srand(seed); - for (i = 0 ; i < o->_M ; ++i) { - for (j = 0 ; j < o->_N ; ++j) { + for (i = 0; i < o->_M; ++i) { + for (j = 0; j < o->_N; ++j) { float r1 = gaussRand(); float r2 = gaussRand(); fftw_complex r1r2; init_complex(r1r2, r1, r2); - mul_complex_f(o->_h0[i*o->_N+j], r1r2, (float)(sqrt(Ph(o, o->_kx[i], o->_kz[j]) / 2.0f))); - mul_complex_f(o->_h0_minus[i*o->_N+j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i], -o->_kz[j]) / 2.0f))); + mul_complex_f(o->_h0[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, o->_kx[i], o->_kz[j]) / 2.0f))); + mul_complex_f(o->_h0_minus[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i], -o->_kz[j]) / 2.0f))); } } - o->_fft_in = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in"); - o->_htilda = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_htilda"); + o->_fft_in = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in"); + o->_htilda = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_htilda"); if (o->_do_disp_y) { - o->_disp_y = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_y"); + o->_disp_y = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_y"); o->_disp_y_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in, o->_disp_y, FFTW_ESTIMATE); } if (o->_do_normals) { - o->_fft_in_nx = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_nx"); - o->_fft_in_nz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_nz"); + o->_fft_in_nx = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_nx"); + o->_fft_in_nz = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_nz"); - o->_N_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x"); + o->_N_x = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x"); /*o->_N_y = (float*) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01)*/ - o->_N_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z"); + o->_N_z = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z"); o->_N_x_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_nx, o->_N_x, FFTW_ESTIMATE); o->_N_z_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_nz, o->_N_z, FFTW_ESTIMATE); } if (o->_do_chop) { - o->_fft_in_x = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_x"); - o->_fft_in_z = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_z"); + o->_fft_in_x = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_x"); + o->_fft_in_z = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_z"); - o->_disp_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_x"); - o->_disp_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_z"); + o->_disp_x = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_x"); + o->_disp_z = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_z"); o->_disp_x_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_x, o->_disp_x, FFTW_ESTIMATE); o->_disp_z_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_z, o->_disp_z, FFTW_ESTIMATE); } if (o->_do_jacobian) { - o->_fft_in_jxx = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jxx"); - o->_fft_in_jzz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jzz"); - o->_fft_in_jxz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jxz"); + o->_fft_in_jxx = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_jxx"); + o->_fft_in_jzz = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_jzz"); + o->_fft_in_jxz = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_jxz"); - o->_Jxx = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxx"); - o->_Jzz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jzz"); - o->_Jxz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxz"); + o->_Jxx = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxx"); + o->_Jzz = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jzz"); + o->_Jxz = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxz"); o->_Jxx_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_jxx, o->_Jxx, FFTW_ESTIMATE); o->_Jzz_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_jzz, o->_Jzz, FFTW_ESTIMATE); @@ -947,9 +945,9 @@ void BKE_free_ocean(struct Ocean *oc) /* ********* Baking/Caching ********* */ -#define CACHE_TYPE_DISPLACE 1 -#define CACHE_TYPE_FOAM 2 -#define CACHE_TYPE_NORMAL 3 +#define CACHE_TYPE_DISPLACE 1 +#define CACHE_TYPE_FOAM 2 +#define CACHE_TYPE_NORMAL 3 static void cache_filename(char *string, const char *path, const char *relbase, int frame, int type) { @@ -957,16 +955,16 @@ static void cache_filename(char *string, const char *path, const char *relbase, const char *fname; switch (type) { - case CACHE_TYPE_FOAM: - fname= "foam_"; - break; - case CACHE_TYPE_NORMAL: - fname= "normal_"; - break; - case CACHE_TYPE_DISPLACE: - default: - fname= "disp_"; - break; + case CACHE_TYPE_FOAM: + fname = "foam_"; + break; + case CACHE_TYPE_NORMAL: + fname = "normal_"; + break; + case CACHE_TYPE_DISPLACE: + default: + fname = "disp_"; + break; } BLI_join_dirfile(cachepath, sizeof(cachepath), path, fname); @@ -977,27 +975,27 @@ static void cache_filename(char *string, const char *path, const char *relbase, /* silly functions but useful to inline when the args do a lot of indirections */ MINLINE void rgb_to_rgba_unit_alpha(float r_rgba[4], const float rgb[3]) { - r_rgba[0]= rgb[0]; - r_rgba[1]= rgb[1]; - r_rgba[2]= rgb[2]; - r_rgba[3]= 1.0f; + r_rgba[0] = rgb[0]; + r_rgba[1] = rgb[1]; + r_rgba[2] = rgb[2]; + r_rgba[3] = 1.0f; } MINLINE void value_to_rgba_unit_alpha(float r_rgba[4], const float value) { - r_rgba[0]= value; - r_rgba[1]= value; - r_rgba[2]= value; - r_rgba[3]= 1.0f; + r_rgba[0] = value; + r_rgba[1] = value; + r_rgba[2] = value; + r_rgba[3] = 1.0f; } void BKE_free_ocean_cache(struct OceanCache *och) { - int i, f=0; + int i, f = 0; if (!och) return; if (och->ibufs_disp) { - for (i=och->start, f=0; i<=och->end; i++, f++) { + for (i = och->start, f = 0; i <= och->end; i++, f++) { if (och->ibufs_disp[f]) { IMB_freeImBuf(och->ibufs_disp[f]); } @@ -1006,7 +1004,7 @@ void BKE_free_ocean_cache(struct OceanCache *och) } if (och->ibufs_foam) { - for (i=och->start, f=0; i<=och->end; i++, f++) { + for (i = och->start, f = 0; i <= och->end; i++, f++) { if (och->ibufs_foam[f]) { IMB_freeImBuf(och->ibufs_foam[f]); } @@ -1015,7 +1013,7 @@ void BKE_free_ocean_cache(struct OceanCache *och) } if (och->ibufs_norm) { - for (i=och->start, f=0; i<=och->end; i++, f++) { + for (i = och->start, f = 0; i <= och->end; i++, f++) { if (och->ibufs_norm[f]) { IMB_freeImBuf(och->ibufs_norm[f]); } @@ -1041,17 +1039,17 @@ void BKE_ocean_cache_eval_uv(struct OceanCache *och, struct OceanResult *ocr, in if (v < 0) v += 1.0f; if (och->ibufs_disp[f]) { - ibuf_sample(och->ibufs_disp[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result); + ibuf_sample(och->ibufs_disp[f], u, v, (1.0f / (float)res_x), (1.0f / (float)res_y), result); copy_v3_v3(ocr->disp, result); } if (och->ibufs_foam[f]) { - ibuf_sample(och->ibufs_foam[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result); + ibuf_sample(och->ibufs_foam[f], u, v, (1.0f / (float)res_x), (1.0f / (float)res_y), result); ocr->foam = result[0]; } if (och->ibufs_norm[f]) { - ibuf_sample(och->ibufs_norm[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result); + ibuf_sample(och->ibufs_norm[f], u, v, (1.0f / (float)res_x), (1.0f / (float)res_y), result); copy_v3_v3(ocr->normal, result); } } @@ -1061,22 +1059,22 @@ void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, in const int res_x = och->resolution_x; const int res_y = och->resolution_y; - if (i < 0) i= -i; - if (j < 0) j= -j; + if (i < 0) i = -i; + if (j < 0) j = -j; i = i % res_x; j = j % res_y; if (och->ibufs_disp[f]) { - copy_v3_v3(ocr->disp, &och->ibufs_disp[f]->rect_float[4*(res_x*j + i)]); + copy_v3_v3(ocr->disp, &och->ibufs_disp[f]->rect_float[4 * (res_x * j + i)]); } if (och->ibufs_foam[f]) { - ocr->foam = och->ibufs_foam[f]->rect_float[4*(res_x*j + i)]; + ocr->foam = och->ibufs_foam[f]->rect_float[4 * (res_x * j + i)]; } if (och->ibufs_norm[f]) { - copy_v3_v3(ocr->normal, &och->ibufs_norm[f]->rect_float[4*(res_x*j + i)]); + copy_v3_v3(ocr->normal, &och->ibufs_norm[f]->rect_float[4 * (res_x * j + i)]); } } @@ -1096,12 +1094,12 @@ struct OceanCache *BKE_init_ocean_cache(const char *bakepath, const char *relbas och->chop_amount = chop_amount; och->foam_coverage = foam_coverage; och->foam_fade = foam_fade; - och->resolution_x = resolution*resolution; - och->resolution_y = resolution*resolution; + och->resolution_x = resolution * resolution; + och->resolution_y = resolution * resolution; - och->ibufs_disp = MEM_callocN(sizeof(ImBuf *)*och->duration, "displacement imbuf pointer array"); - och->ibufs_foam = MEM_callocN(sizeof(ImBuf *)*och->duration, "foam imbuf pointer array"); - och->ibufs_norm = MEM_callocN(sizeof(ImBuf *)*och->duration, "normal imbuf pointer array"); + och->ibufs_disp = MEM_callocN(sizeof(ImBuf *) * och->duration, "displacement imbuf pointer array"); + och->ibufs_foam = MEM_callocN(sizeof(ImBuf *) * och->duration, "foam imbuf pointer array"); + och->ibufs_norm = MEM_callocN(sizeof(ImBuf *) * och->duration, "normal imbuf pointer array"); och->time = NULL; @@ -1116,10 +1114,10 @@ void BKE_simulate_ocean_cache(struct OceanCache *och, int frame) /* ibufs array is zero based, but filenames are based on frame numbers */ /* still need to clamp frame numbers to valid range of images on disk though */ CLAMP(frame, och->start, och->end); - f = frame - och->start; // shift to 0 based + f = frame - och->start; // shift to 0 based /* if image is already loaded in mem, return */ - if (och->ibufs_disp[f] != NULL ) return; + if (och->ibufs_disp[f] != NULL) return; cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE); @@ -1146,9 +1144,9 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v * before use - campbell */ OceanResult ocr; - ImageFormatData imf= {0}; + ImageFormatData imf = {0}; - int f, i=0, x, y, cancel=0; + int f, i = 0, x, y, cancel = 0; float progress; ImBuf *ibuf_foam, *ibuf_disp, *ibuf_normal; @@ -1159,17 +1157,17 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v if (!o) return; - if (o->_do_jacobian) prev_foam = MEM_callocN(res_x*res_y*sizeof(float), "previous frame foam bake data"); - else prev_foam = NULL; + if (o->_do_jacobian) prev_foam = MEM_callocN(res_x * res_y * sizeof(float), "previous frame foam bake data"); + else prev_foam = NULL; BLI_srand(0); /* setup image format */ - imf.imtype= R_IMF_IMTYPE_OPENEXR; - imf.depth= R_IMF_CHAN_DEPTH_16; - imf.exr_codec= R_IMF_EXR_CODEC_ZIP; + imf.imtype = R_IMF_IMTYPE_OPENEXR; + imf.depth = R_IMF_CHAN_DEPTH_16; + imf.exr_codec = R_IMF_EXR_CODEC_ZIP; - for (f=och->start, i=0; f<=och->end; f++, i++) { + for (f = och->start, i = 0; f <= och->end; f++, i++) { /* create a new imbuf to store image for this frame */ ibuf_foam = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat); @@ -1181,25 +1179,25 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v BKE_simulate_ocean(o, och->time[i], och->wave_scale, och->chop_amount); /* add new foam */ - for (y=0; y < res_y; y++) { - for (x=0; x < res_x; x++) { + for (y = 0; y < res_y; y++) { + for (x = 0; x < res_x; x++) { BKE_ocean_eval_ij(o, &ocr, x, y); /* add to the image */ - rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4*(res_x*y + x)], ocr.disp); + rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4 * (res_x * y + x)], ocr.disp); if (o->_do_jacobian) { /* TODO, cleanup unused code - campbell */ - float /*r, */ /* UNUSED */ pr=0.0f, foam_result; + float /*r, */ /* UNUSED */ pr = 0.0f, foam_result; float neg_disp, neg_eplus; ocr.foam = BKE_ocean_jminus_to_foam(ocr.Jminus, och->foam_coverage); /* accumulate previous value for this cell */ if (i > 0) { - pr = prev_foam[res_x*y + x]; + pr = prev_foam[res_x * y + x]; } /* r = BLI_frand(); */ /* UNUSED */ // randomly reduce foam @@ -1217,12 +1215,12 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v CLAMP(hor_stretch, 0.0, 1.0); #endif - neg_disp = ocr.disp[1] < 0.0f ? 1.0f+ocr.disp[1] : 1.0f; + neg_disp = ocr.disp[1] < 0.0f ? 1.0f + ocr.disp[1] : 1.0f; neg_disp = neg_disp < 0.0f ? 0.0f : neg_disp; /* foam, 'ocr.Eplus' only initialized with do_jacobian */ - neg_eplus = ocr.Eplus[2] < 0.0f ? 1.0f + ocr.Eplus[2]:1.0f; - neg_eplus = neg_eplus<0.0f ? 0.0f : neg_eplus; + neg_eplus = ocr.Eplus[2] < 0.0f ? 1.0f + ocr.Eplus[2] : 1.0f; + neg_eplus = neg_eplus < 0.0f ? 0.0f : neg_eplus; //if (ocr.disp[1] < 0.0 || r > och->foam_fade) // pr *= och->foam_fade; @@ -1231,20 +1229,20 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v //pr = pr * (1.0 - hor_stretch) * ocr.disp[1]; //pr = pr * neg_disp * neg_eplus; - if (pr < 1.0f) pr *=pr; + if (pr < 1.0f) pr *= pr; pr *= och->foam_fade * (0.75f + neg_eplus * 0.25f); foam_result = pr + ocr.foam; - prev_foam[res_x*y + x] = foam_result; + prev_foam[res_x * y + x] = foam_result; - value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4*(res_x*y + x)], foam_result); + value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4 * (res_x * y + x)], foam_result); } if (o->_do_normals) { - rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4*(res_x*y + x)], ocr.normal); + rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4 * (res_x * y + x)], ocr.normal); } } } @@ -1330,8 +1328,8 @@ struct Ocean *BKE_add_ocean(void) return oc; } -void BKE_init_ocean(struct Ocean* UNUSED(o), int UNUSED(M), int UNUSED(N), float UNUSED(Lx), float UNUSED(Lz), float UNUSED(V), float UNUSED(l), float UNUSED(A), float UNUSED(w), float UNUSED(damp), - float UNUSED(alignment), float UNUSED(depth), float UNUSED(time), short UNUSED(do_height_field), short UNUSED(do_chop), short UNUSED(do_normals), short UNUSED(do_jacobian), int UNUSED(seed)) +void BKE_init_ocean(struct Ocean *UNUSED(o), int UNUSED(M), int UNUSED(N), float UNUSED(Lx), float UNUSED(Lz), float UNUSED(V), float UNUSED(l), float UNUSED(A), float UNUSED(w), float UNUSED(damp), + float UNUSED(alignment), float UNUSED(depth), float UNUSED(time), short UNUSED(do_height_field), short UNUSED(do_chop), short UNUSED(do_normals), short UNUSED(do_jacobian), int UNUSED(seed)) { } @@ -1364,7 +1362,7 @@ void BKE_ocean_cache_eval_ij(struct OceanCache *UNUSED(och), struct OceanResult { } -struct OceanCache *BKE_init_ocean_cache(const char *UNUSED(bakepath), const char *UNUSED(relbase), +OceanCache *BKE_init_ocean_cache(const char *UNUSED(bakepath), const char *UNUSED(relbase), int UNUSED(start), int UNUSED(end), float UNUSED(wave_scale), float UNUSED(chop_amount), float UNUSED(foam_coverage), float UNUSED(foam_fade), int UNUSED(resolution)) { diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index cd1561734cc..5397b1729f9 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -241,10 +241,10 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart) } if (psys->particles) { - totsaved=MIN2(psys->totpart, totpart); + totsaved=MIN2(psys->totpart,totpart); /*save old pars*/ if (totsaved) { - memcpy(newpars, psys->particles, totsaved*sizeof(ParticleData)); + memcpy(newpars,psys->particles,totsaved*sizeof(ParticleData)); if (psys->particles->boid) memcpy(newboids, psys->particles->boid, totsaved*sizeof(BoidParticle)); @@ -418,7 +418,7 @@ static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *fi cpa = psys->child; for (i=0; i<child_nbr; i++) { - for (p=0; p<psys->totpart; p++, cpa++) { + for (p=0; p<psys->totpart; p++,cpa++) { float length=2.0; cpa->parent=p; @@ -440,7 +440,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) { ParticleData *pa=NULL; float min[3], max[3], delta[3], d; - MVert *mv, *mvert = dm->getVertDataArray(dm, 0); + MVert *mv, *mvert = dm->getVertDataArray(dm,0); int totvert=dm->getNumVerts(dm), from=psys->part->from; int i, j, k, p, res=psys->part->grid_res, size[3], axis; @@ -452,13 +452,13 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) mv++; for (i=1; i<totvert; i++, mv++) { - min[0]=MIN2(min[0], mv->co[0]); - min[1]=MIN2(min[1], mv->co[1]); - min[2]=MIN2(min[2], mv->co[2]); + min[0]=MIN2(min[0],mv->co[0]); + min[1]=MIN2(min[1],mv->co[1]); + min[2]=MIN2(min[2],mv->co[2]); - max[0]=MAX2(max[0], mv->co[0]); - max[1]=MAX2(max[1], mv->co[1]); - max[2]=MAX2(max[2], mv->co[2]); + max[0]=MAX2(max[0],mv->co[0]); + max[1]=MAX2(max[1],mv->co[1]); + max[2]=MAX2(max[2],mv->co[2]); } sub_v3_v3v3(delta, max, min); @@ -473,8 +473,8 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) size[(axis+2)%3] = (int)ceil(delta[(axis+2)%3]/d); /* float errors grrr.. */ - size[(axis+1)%3] = MIN2(size[(axis+1)%3], res); - size[(axis+2)%3] = MIN2(size[(axis+2)%3], res); + size[(axis+1)%3] = MIN2(size[(axis+1)%3],res); + size[(axis+2)%3] = MIN2(size[(axis+2)%3],res); size[0] = MAX2(size[0], 1); size[1] = MAX2(size[1], 1); @@ -485,9 +485,9 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) min[1]+= d < delta[1] ? d/2.f : delta[1]/2.f; min[2]+= d < delta[2] ? d/2.f : delta[2]/2.f; - for (i=0, p=0, pa=psys->particles; i<res; i++) { + for (i=0,p=0,pa=psys->particles; i<res; i++) { for (j=0; j<res; j++) { - for (k=0; k<res; k++, p++, pa++) { + for (k=0; k<res; k++,p++,pa++) { pa->fuv[0] = min[0] + (float)i*d; pa->fuv[1] = min[1] + (float)j*d; pa->fuv[2] = min[2] + (float)k*d; @@ -507,8 +507,8 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) min[1] -= d/2.0f; min[2] -= d/2.0f; - for (i=0, mv=mvert; i<totvert; i++, mv++) { - sub_v3_v3v3(vec, mv->co, min); + for (i=0,mv=mvert; i<totvert; i++,mv++) { + sub_v3_v3v3(vec,mv->co,min); vec[0]/=delta[0]; vec[1]/=delta[1]; vec[2]/=delta[2]; @@ -517,7 +517,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) (int)(vec[2] * (size[2] - 1)))->flag &= ~PARS_UNEXIST; } } - else if (ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) { + else if (ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) { float co1[3], co2[3]; MFace *mface= NULL, *mface_array; @@ -526,7 +526,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) int amax= from==PART_FROM_FACE ? 3 : 1; totface=dm->getNumTessFaces(dm); - mface=mface_array=dm->getTessFaceDataArray(dm, CD_MFACE); + mface=mface_array=dm->getTessFaceDataArray(dm,CD_MFACE); for (a=0; a<amax; a++) { if (a==0) { a0mul=res*res; a1mul=res; a2mul=1; } @@ -545,7 +545,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) co1[a] -= 0.001f*d; /* lets intersect the faces */ - for (i=0; i<totface; i++, mface++) { + for (i=0; i<totface; i++,mface++) { copy_v3_v3(v1, mvert[mface->v1].co); copy_v3_v3(v2, mvert[mface->v2].co); copy_v3_v3(v3, mvert[mface->v3].co); @@ -586,9 +586,9 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) } if (psys->part->flag & PART_GRID_HEXAGONAL) { - for (i=0, p=0, pa=psys->particles; i<res; i++) { + for (i=0,p=0,pa=psys->particles; i<res; i++) { for (j=0; j<res; j++) { - for (k=0; k<res; k++, p++, pa++) { + for (k=0; k<res; k++,p++,pa++) { if (j%2) pa->fuv[0] += d/2.f; @@ -614,7 +614,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) if (psys->part->grid_rand > 0.f) { float rfac = d * psys->part->grid_rand; - for (p=0, pa=psys->particles; p<psys->totpart; p++, pa++) { + for (p=0,pa=psys->particles; p<psys->totpart; p++,pa++) { if (pa->flag & PARS_UNEXIST) continue; @@ -708,10 +708,10 @@ static void psys_uv_to_w(float u, float v, int quad, float *w) if (quad) { vert[3][0]= 0.0f; vert[3][1]= 1.0f; vert[3][2]= 0.0f; - interp_weights_poly_v3(w, vert, 4, co); + interp_weights_poly_v3( w,vert, 4, co); } else { - interp_weights_poly_v3(w, vert, 3, co); + interp_weights_poly_v3( w,vert, 3, co); w[3]= 0.0f; } } @@ -771,9 +771,9 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch KDTreeNearest ptn[3]; int w, maxw; - psys_particle_on_dm(ctx->dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co1, 0, 0, 0, orco1, 0); + psys_particle_on_dm(ctx->dm,from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co1,0,0,0,orco1,0); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); - maxw = BLI_kdtree_find_n_nearest(ctx->tree, 3, orco1, NULL, ptn); + maxw = BLI_kdtree_find_n_nearest(ctx->tree,3,orco1,NULL,ptn); for (w=0; w<maxw; w++) { pa->verts[w]=ptn->num; @@ -785,7 +785,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch MFace *mface; pa->num = i = ctx->index[p]; - mface = dm->getTessFaceData(dm, i, CD_MFACE); + mface = dm->getTessFaceData(dm,i,CD_MFACE); switch (distr) { case PART_DISTR_JIT: @@ -796,7 +796,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch psys_uv_to_w(0.33333f, 0.33333f, mface->v4, pa->fuv); } else { - ctx->jitoff[i] = fmod(ctx->jitoff[i], (float)ctx->jitlevel); + ctx->jitoff[i] = fmod(ctx->jitoff[i],(float)ctx->jitlevel); psys_uv_to_w(ctx->jit[2*(int)ctx->jitoff[i]], ctx->jit[2*(int)ctx->jitoff[i]+1], mface->v4, pa->fuv); ctx->jitoff[i]++; } @@ -813,21 +813,21 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch /* experimental */ if (from==PART_FROM_VOLUME) { - MVert *mvert=dm->getVertDataArray(dm, CD_MVERT); + MVert *mvert=dm->getVertDataArray(dm,CD_MVERT); tot=dm->getNumTessFaces(dm); - psys_interpolate_face(mvert, mface, 0, 0, pa->fuv, co1, nor, 0, 0, 0, 0); + psys_interpolate_face(mvert,mface,0,0,pa->fuv,co1,nor,0,0,0,0); normalize_v3(nor); - mul_v3_fl(nor, -100.0); + mul_v3_fl(nor,-100.0); - add_v3_v3v3(co2, co1, nor); + add_v3_v3v3(co2,co1,nor); min_d=2.0; intersect=0; - for (i=0, mface=dm->getTessFaceDataArray(dm, CD_MFACE); i<tot; i++, mface++) { + for (i=0,mface=dm->getTessFaceDataArray(dm,CD_MFACE); i<tot; i++,mface++) { if (i==pa->num) continue; v1=mvert[mface->v1].co; @@ -889,14 +889,14 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch if (ctx->tree) { KDTreeNearest ptn[10]; - int w, maxw;//, do_seams; - float maxd /*, mind, dd */, totw= 0.0f; + int w,maxw;//, do_seams; + float maxd /*, mind,dd */, totw= 0.0f; int parent[10]; float pweight[10]; - psys_particle_on_dm(dm, cfrom, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co1, nor1, NULL, NULL, orco1, NULL); + psys_particle_on_dm(dm,cfrom,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,co1,nor1,NULL,NULL,orco1,NULL); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); - maxw = BLI_kdtree_find_n_nearest(ctx->tree, 4, orco1, NULL, ptn); + maxw = BLI_kdtree_find_n_nearest(ctx->tree,4,orco1,NULL,ptn); maxd=ptn[maxw-1].dist; /* mind=ptn[0].dist; */ /* UNUSED */ @@ -904,14 +904,14 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch /* the weights here could be done better */ for (w=0; w<maxw; w++) { parent[w]=ptn[w].index; - pweight[w]=(float)pow(2.0, (double)(-6.0f*ptn[w].dist/maxd)); + pweight[w]=(float)pow(2.0,(double)(-6.0f*ptn[w].dist/maxd)); } for (;w<10; w++) { parent[w]=-1; pweight[w]=0.0f; } - for (w=0, i=0; w<maxw && i<4; w++) { + for (w=0,i=0; w<maxw && i<4; w++) { if (parent[w]>=0) { cpa->pa[i]=parent[w]; cpa->w[i]=pweight[w]; @@ -997,7 +997,7 @@ static void distribute_invalid(Scene *scene, ParticleSystem *psys, int from) int p, totchild = get_psys_tot_child(scene, psys); if (psys->child && totchild) { - for (p=0, cpa=psys->child; p<totchild; p++, cpa++) { + for (p=0,cpa=psys->child; p<totchild; p++,cpa++) { cpa->fuv[0]=cpa->fuv[1]=cpa->fuv[2]=cpa->fuv[3]= 0.0; cpa->foffset= 0.0f; cpa->parent=0; @@ -1033,7 +1033,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D int cfrom=0; int totelem=0, totpart, *particle_element=0, children=0, totseam=0; int jitlevel= 1, distr; - float *element_weight=NULL, *element_sum=NULL, *jitter_offset=NULL, *vweight=NULL; + float *element_weight=NULL,*element_sum=NULL,*jitter_offset=NULL, *vweight=NULL; float cur, maxweight=0.0, tweight, totweight, inv_totweight, co[3], nor[3], orco[3], ornor[3]; if (ELEM3(NULL, ob, psys, psys->part)) @@ -1065,7 +1065,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D BLI_srandom(31415926 + psys->seed); dm= CDDM_from_mesh((Mesh*)ob->data, ob); DM_ensure_tessface(dm); - distribute_grid(dm, psys); + distribute_grid(dm,psys); dm->release(dm); return 0; } @@ -1084,8 +1084,8 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D tree=BLI_kdtree_new(totpart); - for (p=0, pa=psys->particles; p<totpart; p++, pa++) { - psys_particle_on_dm(dm, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, nor, 0, 0, orco, ornor); + for (p=0,pa=psys->particles; p<totpart; p++,pa++) { + psys_particle_on_dm(dm,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,ornor); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco, 1, 1); BLI_kdtree_insert(tree, p, orco, ornor); } @@ -1118,12 +1118,12 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D for (p=0; p<totvert; p++) { if (orcodata) { - copy_v3_v3(co, orcodata[p]); + copy_v3_v3(co,orcodata[p]); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co, 1, 1); } else - copy_v3_v3(co, mv[p].co); - BLI_kdtree_insert(tree, p, co, NULL); + copy_v3_v3(co,mv[p].co); + BLI_kdtree_insert(tree,p,co,NULL); } BLI_kdtree_balance(tree); @@ -1137,7 +1137,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D distribute_invalid(scene, psys, children ? PART_FROM_CHILD : 0); if (G.debug & G_DEBUG) - fprintf(stderr, "Particle distribution error: Nothing to emit from!\n"); + fprintf(stderr,"Particle distribution error: Nothing to emit from!\n"); if (dm != finaldm) dm->release(dm); @@ -1160,7 +1160,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D orcodata= dm->getVertDataArray(dm, CD_ORCO); for (i=0; i<totelem; i++) { - MFace *mf=dm->getTessFaceData(dm, i, CD_MFACE); + MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE); if (orcodata) { copy_v3_v3(co1, orcodata[mf->v1]); @@ -1175,14 +1175,14 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D } } else { - v1= (MVert*)dm->getVertData(dm, mf->v1, CD_MVERT); - v2= (MVert*)dm->getVertData(dm, mf->v2, CD_MVERT); - v3= (MVert*)dm->getVertData(dm, mf->v3, CD_MVERT); + v1= (MVert*)dm->getVertData(dm,mf->v1,CD_MVERT); + v2= (MVert*)dm->getVertData(dm,mf->v2,CD_MVERT); + v3= (MVert*)dm->getVertData(dm,mf->v3,CD_MVERT); copy_v3_v3(co1, v1->co); copy_v3_v3(co2, v2->co); copy_v3_v3(co3, v3->co); if (mf->v4) { - v4= (MVert*)dm->getVertData(dm, mf->v4, CD_MVERT); + v4= (MVert*)dm->getVertData(dm,mf->v4,CD_MVERT); copy_v3_v3(co4, v4->co); } } @@ -1202,14 +1202,14 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D maxweight /= totarea; } else { - float min=1.0f/(float)(MIN2(totelem, totpart)); + float min=1.0f/(float)(MIN2(totelem,totpart)); for (i=0; i<totelem; i++) element_weight[i]=min; maxweight=min; } /* Calculate weights from vgroup */ - vweight = psys_cache_vgroup(dm, psys, PSYS_VG_DENSITY); + vweight = psys_cache_vgroup(dm,psys,PSYS_VG_DENSITY); if (vweight) { if (from==PART_FROM_VERT) { @@ -1218,7 +1218,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D } else { /* PART_FROM_FACE / PART_FROM_VOLUME */ for (i=0;i<totelem; i++) { - MFace *mf=dm->getTessFaceData(dm, i, CD_MFACE); + MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE); tweight = vweight[mf->v1] + vweight[mf->v2] + vweight[mf->v3]; if (mf->v4) { @@ -1303,7 +1303,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D } /* Create jittering if needed */ - if (distr==PART_DISTR_JIT && ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) { + if (distr==PART_DISTR_JIT && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) { jitlevel= part->userjit; if (jitlevel == 0) { @@ -1399,7 +1399,7 @@ static void distribute_particles_on_shape(ParticleSimulationData *sim, int UNUSE { distribute_invalid(sim->scene, sim->psys, 0); - fprintf(stderr, "Shape emission not yet possible!\n"); + fprintf(stderr,"Shape emission not yet possible!\n"); } static void distribute_particles(ParticleSimulationData *sim, int from) @@ -1419,7 +1419,7 @@ static void distribute_particles(ParticleSimulationData *sim, int from) if (distr_error) { distribute_invalid(sim->scene, sim->psys, from); - fprintf(stderr, "Particle distribution error!\n"); + fprintf(stderr,"Particle distribution error!\n"); } } @@ -1620,18 +1620,18 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P ParticleSystem *psys = sim->psys; ParticleSettings *part; ParticleTexture ptex; - float fac, phasefac, nor[3]={0, 0, 0}, loc[3], vel[3]={0.0, 0.0, 0.0}, rot[4], q2[4]; - float r_vel[3], r_ave[3], r_rot[4], vec[3], p_vel[3]={0.0, 0.0, 0.0}; - float x_vec[3]={1.0, 0.0, 0.0}, utan[3]={0.0, 1.0, 0.0}, vtan[3]={0.0, 0.0, 1.0}, rot_vec[3]={0.0, 0.0, 0.0}; + float fac, phasefac, nor[3]={0,0,0},loc[3],vel[3]={0.0,0.0,0.0},rot[4],q2[4]; + float r_vel[3],r_ave[3],r_rot[4],vec[3],p_vel[3]={0.0,0.0,0.0}; + float x_vec[3]={1.0,0.0,0.0}, utan[3]={0.0,1.0,0.0}, vtan[3]={0.0,0.0,1.0}, rot_vec[3]={0.0,0.0,0.0}; float q_phase[4]; int p = pa - psys->particles; part=psys->part; /* get birth location from object */ if (part->tanfac != 0.f) - psys_particle_on_emitter(sim->psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, nor, utan, vtan, 0, 0); + psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,utan,vtan,0,0); else - psys_particle_on_emitter(sim->psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, nor, 0, 0, 0, 0); + psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,0,0,0,0); /* get possible textural influence */ psys_get_texture(sim, pa, &ptex, PAMAP_IVEL, cfra); @@ -1647,16 +1647,16 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P /* -tangent */ if (part->tanfac!=0.0f) { - //float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm, part->from, pa, vg_rot)-0.5f):0.0f; + //float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm,part->from,pa,vg_rot)-0.5f):0.0f; float phase=0.0f; - mul_v3_fl(vtan, -cosf((float)M_PI*(part->tanphase+phase))); + mul_v3_fl(vtan,-cosf((float)M_PI*(part->tanphase+phase))); fac= -sinf((float)M_PI*(part->tanphase+phase)); madd_v3_v3fl(vtan, utan, fac); - mul_mat3_m4_v3(ob->obmat, vtan); + mul_mat3_m4_v3(ob->obmat,vtan); copy_v3_v3(utan, nor); - mul_v3_fl(utan, dot_v3v3(vtan, nor)); + mul_v3_fl(utan,dot_v3v3(vtan,nor)); sub_v3_v3(vtan, utan); normalize_v3(vtan); @@ -1679,7 +1679,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P r_ave[1] = 2.0f * (PSYS_FRAND(p + 14) - 0.5f); r_ave[2] = 2.0f * (PSYS_FRAND(p + 15) - 0.5f); - mul_mat3_m4_v3(ob->obmat, r_ave); + mul_mat3_m4_v3(ob->obmat,r_ave); normalize_v3(r_ave); } @@ -1691,14 +1691,14 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P r_rot[3] = 2.0f * (PSYS_FRAND(p + 19) - 0.5f); normalize_qt(r_rot); - mat4_to_quat(rot, ob->obmat); - mul_qt_qtqt(r_rot, r_rot, rot); + mat4_to_quat(rot,ob->obmat); + mul_qt_qtqt(r_rot,r_rot,rot); } if (part->phystype==PART_PHYS_BOIDS && pa->boid) { float dvec[3], q[4], mat[3][3]; - copy_v3_v3(state->co, loc); + copy_v3_v3(state->co,loc); /* boids don't get any initial velocity */ zero_v3(state->vel); @@ -1721,7 +1721,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P cross_v3_v3v3(mat[1], mat[2], mat[0]); /* apply rotation */ - mat3_to_quat_is_ok(q, mat); + mat3_to_quat_is_ok( q,mat); copy_qt_qt(state->rot, q); } else { @@ -1775,7 +1775,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P mul_v3_v3fl(state->vel, vel, ptex.ivel); /* -location from emitter */ - copy_v3_v3(state->co, loc); + copy_v3_v3(state->co,loc); /* -rotation */ unit_qt(state->rot); @@ -1803,19 +1803,19 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P /* create rotation quat */ negate_v3(rot_vec); - vec_to_quat(q2, rot_vec, OB_POSX, OB_POSZ); + vec_to_quat( q2,rot_vec, OB_POSX, OB_POSZ); /* randomize rotation quat */ if (part->randrotfac!=0.0f) interp_qt_qtqt(rot, q2, r_rot, part->randrotfac); else - copy_qt_qt(rot, q2); + copy_qt_qt(rot,q2); /* rotation phase */ phasefac = part->phasefac; if (part->randphasefac != 0.0f) phasefac += part->randphasefac * PSYS_FRAND(p + 20); - axis_angle_to_quat(q_phase, x_vec, phasefac*(float)M_PI); + axis_angle_to_quat( q_phase,x_vec, phasefac*(float)M_PI); /* combine base rotation & phase */ mul_qt_qtqt(state->rot, rot, q_phase); @@ -2133,7 +2133,7 @@ static void psys_update_effectors(ParticleSimulationData *sim) static void integrate_particle(ParticleSettings *part, ParticleData *pa, float dtime, float *external_acceleration, void (*force_func)(void *forcedata, ParticleKey *state, float *force, float *impulse), void *forcedata) { ParticleKey states[5]; - float force[3], acceleration[3], impulse[3], dx[4][3], dv[4][3], oldpos[3]; + float force[3],acceleration[3],impulse[3],dx[4][3],dv[4][3],oldpos[3]; float pa_mass= (part->flag & PART_SIZEMASS ? part->mass * pa->size : part->mass); int i, steps=1; int integrator = part->integrator; @@ -2538,10 +2538,10 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa u = dot_v3v3(vec, dv); if (u < 0.f && visc > 0.f) - madd_v3_v3fl(force, vec, 0.5f * q * visc * u); + madd_v3_v3fl(force, vec, 0.5f * q * visc * u ); if (u > 0.f && stiff_visc > 0.f) - madd_v3_v3fl(force, vec, 0.5f * q * stiff_visc * u); + madd_v3_v3fl(force, vec, 0.5f * q * stiff_visc * u ); } if (spring_constant > 0.f) { @@ -2714,23 +2714,23 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa time=(cfra-pa->time)/pa->lifetime; CLAMP(time, 0.0f, 1.0f); - copy_v3_v3(tkey.co, pa->state.co); - copy_v3_v3(tkey.vel, pa->state.vel); + copy_v3_v3(tkey.co,pa->state.co); + copy_v3_v3(tkey.vel,pa->state.vel); tkey.time=pa->state.time; if (part->type != PART_HAIR) { if (do_guides(sim->psys->effectors, &tkey, p, time)) { - copy_v3_v3(pa->state.co, tkey.co); + copy_v3_v3(pa->state.co,tkey.co); /* guides don't produce valid velocity */ sub_v3_v3v3(pa->state.vel, tkey.co, pa->prev_state.co); - mul_v3_fl(pa->state.vel, 1.0f/dtime); + mul_v3_fl(pa->state.vel,1.0f/dtime); pa->state.time=tkey.time; } } } static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, float timestep) { - float rotfac, rot1[4], rot2[4]={1.0, 0.0, 0.0, 0.0}, dtime=dfra*timestep; + float rotfac, rot1[4], rot2[4]={1.0,0.0,0.0,0.0}, dtime=dfra*timestep; if ((part->flag & PART_ROTATIONS)==0) { pa->state.rot[0]=1.0f; @@ -2758,15 +2758,15 @@ static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, f } rotfac = len_v3(pa->state.ave); - if (rotfac == 0.0f) { /* unit_qt(in VecRotToQuat) doesn't give unit quat [1, 0, 0, 0]?? */ + if (rotfac == 0.0f) { /* unit_qt(in VecRotToQuat) doesn't give unit quat [1,0,0,0]?? */ rot1[0]=1.0f; rot1[1]=rot1[2]=rot1[3]=0; } else { - axis_angle_to_quat(rot1, pa->state.ave, rotfac*dtime); + axis_angle_to_quat(rot1,pa->state.ave,rotfac*dtime); } - mul_qt_qtqt(pa->state.rot, rot1, pa->prev_state.rot); - mul_qt_qtqt(pa->state.rot, rot2, pa->state.rot); + mul_qt_qtqt(pa->state.rot,rot1,pa->prev_state.rot); + mul_qt_qtqt(pa->state.rot,rot2,pa->state.rot); /* keep rotation quat in good health */ normalize_qt(pa->state.rot); @@ -3257,8 +3257,8 @@ static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeR float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_frand() - 0.5f); float distance, nor[3], dot; - CLAMP(damp, 0.0f, 1.0f); - CLAMP(frict, 0.0f, 1.0f); + CLAMP(damp,0.0f, 1.0f); + CLAMP(frict,0.0f, 1.0f); /* get exact velocity right before collision */ madd_v3_v3v3fl(v0, col->ve1, col->acc, dt1); @@ -3604,7 +3604,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim) psys_mat_hair_to_object(sim->ob, sim->psmd->dm, psys->part->from, pa, hairmat); - for (k=0, key=pa->hair; k<pa->totkey; k++, key++) { + for (k=0, key=pa->hair; k<pa->totkey; k++,key++) { /* create fake root before actual root to resist bending */ if (k==0) { @@ -3870,7 +3870,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) } /* initialize all particles for dynamics */ LOOP_SHOWN_PARTICLES { - copy_particle_key(&pa->prev_state, &pa->state, 1); + copy_particle_key(&pa->prev_state,&pa->state,1); psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra); @@ -3949,7 +3949,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) SPHData sphdata; sph_solver_init(sim, &sphdata); - #pragma omp parallel for firstprivate (sphdata) private (pa) schedule(dynamic, 5) + #pragma omp parallel for firstprivate (sphdata) private (pa) schedule(dynamic,5) LOOP_DYNAMIC_PARTICLES { /* do global forces & effectors */ basic_integrate(sim, p, pa->state.time, cfra); @@ -4086,7 +4086,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) gzf = BLI_gzopen(filename, "rb"); if (!gzf) { - BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "readFsPartData::error - Unable to open file for reading '%s'\n", filename); + BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer),"readFsPartData::error - Unable to open file for reading '%s'\n", filename); // XXX bad level call elbeemDebugOut(debugStrBuffer); return; } @@ -4107,23 +4107,23 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) for (p=0, pa=psys->particles; p<totpart; p++, pa++) { int ptype=0; - gzread(gzf, &ptype, sizeof(ptype)); + gzread(gzf, &ptype, sizeof( ptype )); if (ptype&readMask) { activeParts++; - gzread(gzf, &(pa->size), sizeof(float)); + gzread(gzf, &(pa->size), sizeof( float )); pa->size /= 10.0f; for (j=0; j<3; j++) { float wrf; - gzread(gzf, &wrf, sizeof(wrf)); + gzread(gzf, &wrf, sizeof( wrf )); pa->state.co[j] = wrf; - //fprintf(stderr, "Rj%d ", j); + //fprintf(stderr,"Rj%d ",j); } for (j=0; j<3; j++) { float wrf; - gzread(gzf, &wrf, sizeof(wrf)); + gzread(gzf, &wrf, sizeof( wrf )); pa->state.vel[j] = wrf; } @@ -4135,7 +4135,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) pa->dietime = sim->scene->r.efra + 1; pa->lifetime = sim->scene->r.efra; pa->alive = PARS_ALIVE; - //if (a < 25) fprintf(stderr, "FSPARTICLE debug set %s, a%d = %f, %f, %f, life=%f\n", filename, a, pa->co[0], pa->co[1], pa->co[2], pa->lifetime ); + //if (a < 25) fprintf(stderr,"FSPARTICLE debug set %s , a%d = %f,%f,%f , life=%f\n", filename, a, pa->co[0],pa->co[1],pa->co[2], pa->lifetime ); } else { // skip... @@ -4148,7 +4148,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) gzclose(gzf); totpart = psys->totpart = activeParts; - BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d\n", psys->totpart, activeParts, fileParts, readMask); + BLI_snprintf(debugStrBuffer,sizeof(debugStrBuffer),"readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d\n", psys->totpart,activeParts,fileParts,readMask); // bad level call // XXX elbeemDebugOut(debugStrBuffer); @@ -4303,7 +4303,7 @@ static void system_step(ParticleSimulationData *sim, float cfra) dynamics_step(sim, cfra+dframe+t_frac - 1.f); psys->cfra = cfra+dframe+t_frac - 1.f; #if 0 - printf("%f, %f, %f, %f\n", cfra+dframe+t_frac - 1.f, t_frac, dt_frac, sim->courant_num); + printf("%f,%f,%f,%f\n", cfra+dframe+t_frac - 1.f, t_frac, dt_frac, sim->courant_num); #endif if (part->time_flag & PART_TIME_AUTOSF) dt_frac = update_timestep(psys, sim, t_frac); @@ -4590,7 +4590,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) if (part->phystype == PART_PHYS_KEYED) { psys_count_keyed_targets(&sim); set_keyed_keys(&sim); - psys_update_path_cache(&sim, (int)cfra); + psys_update_path_cache(&sim,(int)cfra); } break; } diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c index a7df6b10f06..3a66ec23412 100644 --- a/source/blender/blenkernel/intern/report.c +++ b/source/blender/blenkernel/intern/report.c @@ -63,9 +63,9 @@ void BKE_reports_init(ReportList *reports, int flag) memset(reports, 0, sizeof(ReportList)); - reports->storelevel= RPT_INFO; - reports->printlevel= RPT_ERROR; - reports->flag= flag; + reports->storelevel = RPT_INFO; + reports->printlevel = RPT_ERROR; + reports->flag = flag; } void BKE_reports_clear(ReportList *reports) @@ -75,16 +75,16 @@ void BKE_reports_clear(ReportList *reports) if (!reports) return; - report= reports->list.first; + report = reports->list.first; while (report) { - report_next= report->next; + report_next = report->next; MEM_freeN((void *)report->message); MEM_freeN(report); - report= report_next; + report = report_next; } - reports->list.first= reports->list.last= NULL; + reports->list.first = reports->list.last = NULL; } void BKE_report(ReportList *reports, ReportType type, const char *message) @@ -101,15 +101,15 @@ void BKE_report(ReportList *reports, ReportType type, const char *message) if (reports && (reports->flag & RPT_STORE) && (type >= reports->storelevel)) { char *message_alloc; - report= MEM_callocN(sizeof(Report), "Report"); - report->type= type; - report->typestr= report_type_str(type); - - len= strlen(message); - message_alloc= MEM_callocN(sizeof(char)*(len+1), "ReportMessage"); - memcpy(message_alloc, message, sizeof(char)*(len+1)); - report->message= message_alloc; - report->len= len; + report = MEM_callocN(sizeof(Report), "Report"); + report->type = type; + report->typestr = report_type_str(type); + + len = strlen(message); + message_alloc = MEM_callocN(sizeof(char) * (len + 1), "ReportMessage"); + memcpy(message_alloc, message, sizeof(char) * (len + 1)); + report->message = message_alloc; + report->len = len; BLI_addtail(&reports->list, report); } } @@ -129,19 +129,19 @@ void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...) } if (reports && (reports->flag & RPT_STORE) && (type >= reports->storelevel)) { - report= MEM_callocN(sizeof(Report), "Report"); + report = MEM_callocN(sizeof(Report), "Report"); - ds= BLI_dynstr_new(); + ds = BLI_dynstr_new(); va_start(args, format); BLI_dynstr_vappendf(ds, format, args); va_end(args); - report->message= BLI_dynstr_get_cstring(ds); - report->len= BLI_dynstr_get_len(ds); + report->message = BLI_dynstr_get_cstring(ds); + report->len = BLI_dynstr_get_len(ds); BLI_dynstr_free(ds); - report->type= type; - report->typestr= report_type_str(type); + report->type = type; + report->typestr = report_type_str(type); BLI_addtail(&reports->list, report); } @@ -155,15 +155,15 @@ void BKE_reports_prepend(ReportList *reports, const char *prepend) if (!reports) return; - for (report=reports->list.first; report; report=report->next) { - ds= BLI_dynstr_new(); + for (report = reports->list.first; report; report = report->next) { + ds = BLI_dynstr_new(); BLI_dynstr_append(ds, prepend); BLI_dynstr_append(ds, report->message); MEM_freeN((void *)report->message); - report->message= BLI_dynstr_get_cstring(ds); - report->len= BLI_dynstr_get_len(ds); + report->message = BLI_dynstr_get_cstring(ds); + report->len = BLI_dynstr_get_len(ds); BLI_dynstr_free(ds); } @@ -178,8 +178,8 @@ void BKE_reports_prependf(ReportList *reports, const char *prepend, ...) if (!reports) return; - for (report=reports->list.first; report; report=report->next) { - ds= BLI_dynstr_new(); + for (report = reports->list.first; report; report = report->next) { + ds = BLI_dynstr_new(); va_start(args, prepend); BLI_dynstr_vappendf(ds, prepend, args); va_end(args); @@ -187,8 +187,8 @@ void BKE_reports_prependf(ReportList *reports, const char *prepend, ...) BLI_dynstr_append(ds, report->message); MEM_freeN((void *)report->message); - report->message= BLI_dynstr_get_cstring(ds); - report->len= BLI_dynstr_get_len(ds); + report->message = BLI_dynstr_get_cstring(ds); + report->len = BLI_dynstr_get_len(ds); BLI_dynstr_free(ds); } @@ -207,7 +207,7 @@ void BKE_report_print_level_set(ReportList *reports, ReportType level) if (!reports) return; - reports->printlevel= level; + reports->printlevel = level; } ReportType BKE_report_store_level(ReportList *reports) @@ -223,7 +223,7 @@ void BKE_report_store_level_set(ReportList *reports, ReportType level) if (!reports) return; - reports->storelevel= level; + reports->storelevel = level; } char *BKE_reports_string(ReportList *reports, ReportType level) @@ -235,15 +235,15 @@ char *BKE_reports_string(ReportList *reports, ReportType level) if (!reports || !reports->list.first) return NULL; - ds= BLI_dynstr_new(); - for (report=reports->list.first; report; report=report->next) + ds = BLI_dynstr_new(); + for (report = reports->list.first; report; report = report->next) if (report->type >= level) BLI_dynstr_appendf(ds, "%s: %s\n", report->typestr, report->message); if (BLI_dynstr_get_len(ds)) - cstring= BLI_dynstr_get_cstring(ds); + cstring = BLI_dynstr_get_cstring(ds); else - cstring= NULL; + cstring = NULL; BLI_dynstr_free(ds); return cstring; @@ -265,7 +265,7 @@ Report *BKE_reports_last_displayable(ReportList *reports) { Report *report; - for (report= reports->list.last; report; report=report->prev) { + for (report = reports->list.last; report; report = report->prev) { if (ELEM3(report->type, RPT_ERROR, RPT_WARNING, RPT_INFO)) return report; } @@ -277,7 +277,7 @@ int BKE_reports_contain(ReportList *reports, ReportType level) { Report *report; if (reports != NULL) { - for (report=reports->list.first; report; report=report->next) + for (report = reports->list.first; report; report = report->next) if (report->type >= level) return TRUE; } diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 9358b786472..ca851fd4c81 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -74,10 +74,11 @@ enum { GlowA = 3 }; -static struct ImBuf *prepare_effect_imbufs( - SeqRenderData context, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3){ +static ImBuf *prepare_effect_imbufs( + SeqRenderData context, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) +{ struct ImBuf *out; int x = context.rectx; int y = context.recty; @@ -282,7 +283,7 @@ static ImBuf *IMB_cast_away_list(ImBuf *i) return (ImBuf *) (((void **) i) + 2); } -static struct ImBuf *do_plugin_effect( +static ImBuf *do_plugin_effect( SeqRenderData context, Sequence *seq, float cfra, float facf0, float facf1, struct ImBuf *ibuf1, struct ImBuf *ibuf2, @@ -541,7 +542,7 @@ static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, } } -static struct ImBuf *do_alphaover_effect( +static ImBuf *do_alphaover_effect( SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, struct ImBuf *ibuf1, struct ImBuf *ibuf2, @@ -719,7 +720,7 @@ static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, } } -static struct ImBuf *do_alphaunder_effect( +static ImBuf *do_alphaunder_effect( SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, struct ImBuf *ibuf1, struct ImBuf *ibuf2, @@ -845,7 +846,7 @@ static void do_cross_effect_float(float facf0, float facf1, int x, int y, /* careful: also used by speed effect! */ -static struct ImBuf *do_cross_effect( +static ImBuf *do_cross_effect( SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, struct ImBuf *ibuf1, struct ImBuf *ibuf2, @@ -1111,7 +1112,7 @@ static void do_gammacross_effect_float(float facf0, float UNUSED(facf1), } } -static struct ImBuf *do_gammacross_effect( +static ImBuf *do_gammacross_effect( SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, @@ -1231,11 +1232,12 @@ static void do_add_effect_float(float facf0, float facf1, int x, int y, } } -static struct ImBuf *do_add_effect(SeqRenderData context, - Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3){ +static ImBuf *do_add_effect(SeqRenderData context, + Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) +{ struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { @@ -1347,11 +1349,12 @@ static void do_sub_effect_float(float facf0, float facf1, int x, int y, } } -static struct ImBuf *do_sub_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3){ +static ImBuf *do_sub_effect( + SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) +{ struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { @@ -1560,7 +1563,7 @@ static void do_mul_effect_float(float facf0, float facf1, int x, int y, } } -static struct ImBuf *do_mul_effect( +static ImBuf *do_mul_effect( SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, struct ImBuf *ibuf1, struct ImBuf *ibuf2, @@ -2008,11 +2011,12 @@ static void do_wipe_effect_float(Sequence *seq, float facf0, float UNUSED(facf1) } } -static struct ImBuf *do_wipe_effect( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3){ +static ImBuf *do_wipe_effect( + SeqRenderData context, Sequence *seq, float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) +{ struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { @@ -2155,11 +2159,12 @@ static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x } -static struct ImBuf *do_transform_effect( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float UNUSED(facf1), - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3){ +static ImBuf *do_transform_effect( + SeqRenderData context, Sequence *seq, float UNUSED(cfra), + float facf0, float UNUSED(facf1), + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) +{ struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); do_transform(context.scene, seq, facf0, @@ -2671,7 +2676,7 @@ static void do_glow_effect_float(Sequence *seq, int render_size, float facf0, fl RVAddBitmaps_float(inbuf, outbuf, outbuf, x, y); } -static struct ImBuf *do_glow_effect( +static ImBuf *do_glow_effect( SeqRenderData context, Sequence *seq, float UNUSED(cfra), float facf0, float facf1, struct ImBuf *ibuf1, struct ImBuf *ibuf2, @@ -2736,11 +2741,12 @@ static int early_out_color(struct Sequence *UNUSED(seq), return -1; } -static struct ImBuf *do_solid_color( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3){ +static ImBuf *do_solid_color( + SeqRenderData context, Sequence *seq, float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, + struct ImBuf *ibuf3) +{ struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); SolidColorVars *cv = (SolidColorVars *)seq->effectdata; @@ -2833,11 +2839,12 @@ static int early_out_multicam(struct Sequence *UNUSED(seq), float UNUSED(facf0), return -1; } -static struct ImBuf *do_multicam( - SeqRenderData context, Sequence *seq, float cfra, - float UNUSED(facf0), float UNUSED(facf1), - struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), - struct ImBuf *UNUSED(ibuf3)){ +static ImBuf *do_multicam( + SeqRenderData context, Sequence *seq, float cfra, + float UNUSED(facf0), float UNUSED(facf1), + struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), + struct ImBuf *UNUSED(ibuf3)) +{ struct ImBuf *i; struct ImBuf *out; Editing *ed; @@ -2887,8 +2894,8 @@ static int early_out_adjustment(struct Sequence *UNUSED(seq), float UNUSED(facf0 return -1; } -static struct ImBuf *do_adjustment_impl(SeqRenderData context, Sequence *seq, - float cfra){ +static ImBuf *do_adjustment_impl(SeqRenderData context, Sequence *seq, float cfra) +{ Editing *ed; ListBase *seqbasep; struct ImBuf *i = NULL; @@ -2920,11 +2927,12 @@ static struct ImBuf *do_adjustment_impl(SeqRenderData context, Sequence *seq, return i; } -static struct ImBuf *do_adjustment( - SeqRenderData context, Sequence *seq, float cfra, - float UNUSED(facf0), float UNUSED(facf1), - struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), - struct ImBuf *UNUSED(ibuf3)){ +static ImBuf *do_adjustment( + SeqRenderData context, Sequence *seq, float cfra, + float UNUSED(facf0), float UNUSED(facf1), + struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), + struct ImBuf *UNUSED(ibuf3)) +{ struct ImBuf *i = NULL; struct ImBuf *out; Editing *ed; @@ -3214,13 +3222,14 @@ static void get_default_fac_fade(struct Sequence *seq, float cfra, *facf1 /= seq->len; } -static struct ImBuf *do_overdrop_effect(SeqRenderData context, - Sequence *UNUSED(seq), - float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, - struct ImBuf *ibuf2, - struct ImBuf *ibuf3){ +static ImBuf *do_overdrop_effect(SeqRenderData context, + Sequence *UNUSED(seq), + float UNUSED(cfra), + float facf0, float facf1, + struct ImBuf *ibuf1, + struct ImBuf *ibuf2, + struct ImBuf *ibuf3) +{ struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); int x = context.rectx; int y = context.recty; @@ -3250,7 +3259,8 @@ static struct ImBuf *do_overdrop_effect(SeqRenderData context, return out; } -static struct SeqEffectHandle get_sequence_effect_impl(int seq_type){ +static struct SeqEffectHandle get_sequence_effect_impl(int seq_type) +{ struct SeqEffectHandle rval; int sequence_type = seq_type; diff --git a/source/blender/blenkernel/intern/sketch.c b/source/blender/blenkernel/intern/sketch.c index 32681c3a041..707d97a1cf1 100644 --- a/source/blender/blenkernel/intern/sketch.c +++ b/source/blender/blenkernel/intern/sketch.c @@ -55,7 +55,7 @@ void freeSketch(SK_Sketch *sketch) MEM_freeN(sketch); } -SK_Sketch* createSketch(void) +SK_Sketch *createSketch(void) { SK_Sketch *sketch; @@ -101,7 +101,7 @@ void sk_freeStroke(SK_Stroke *stk) MEM_freeN(stk); } -SK_Stroke* sk_createStroke(void) +SK_Stroke *sk_createStroke(void) { SK_Stroke *stk; @@ -261,13 +261,13 @@ void sk_polygonizeStroke(SK_Stroke *stk, int start, int end) int i; /* find first exact points outside of range */ - for (;start > 0; start--) { + for (; start > 0; start--) { if (stk->points[start].type == PT_EXACT) { break; } } - for (;end < stk->nb_points - 1; end++) { + for (; end < stk->nb_points - 1; end++) { if (stk->points[end].type == PT_EXACT) { break; } @@ -382,7 +382,7 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) work = 0; ls = start; - le = start+1; + le = start + 1; /* while not over interval */ while (ls < end) { @@ -400,7 +400,7 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) v1[0] = old_points[ls].p2d[1] - old_points[le].p2d[1]; - for ( i = ls + 1; i < le; i++ ) { + for (i = ls + 1; i < le; i++) { float mul; float dist; short v2[2]; @@ -412,9 +412,9 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) continue; } - mul = (float)(v1[0]*v2[0] + v1[1]*v2[1]) / (float)(v2[0]*v2[0] + v2[1]*v2[1]); + mul = (float)(v1[0] * v2[0] + v1[1] * v2[1]) / (float)(v2[0] * v2[0] + v2[1] * v2[1]); - dist = mul * mul * (v2[0]*v2[0] + v2[1]*v2[1]); + dist = mul * mul * (v2[0] * v2[0] + v2[1] * v2[1]); if (dist > max_dist) { max_dist = dist; @@ -457,7 +457,7 @@ void sk_filterLastContinuousStroke(SK_Stroke *stk) { int start, end; - end = stk->nb_points -1; + end = stk->nb_points - 1; for (start = end - 1; start > 0 && stk->points[start].type == PT_CONTINUOUS; start--) { /* nothing to do here*/ diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index ee70d4228de..1041fb12305 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3233,9 +3233,9 @@ static void springs_from_mesh(Object *ob) sb= ob->soft; if (me && sb) { /* using bp->origS as a container for spring calcualtions here - ** will be overwritten sbObjectStep() to receive - ** actual modifier stack positions - */ + * will be overwritten sbObjectStep() to receive + * actual modifier stack positions + */ if (me->totvert) { bp= ob->soft->bpoint; for (a=0; a<me->totvert; a++, bp++) { @@ -3283,10 +3283,10 @@ static void mesh_to_softbody(Scene *scene, Object *ob) for (a=0; a<me->totvert; a++, bp++) { /* get scalar values needed *per vertex* from vertex group functions, - so we can *paint* them nicly .. - they are normalized [0.0..1.0] so may be we need amplitude for scale - which can be done by caller but still .. i'd like it to go this way - */ + * so we can *paint* them nicly .. + * they are normalized [0.0..1.0] so may be we need amplitude for scale + * which can be done by caller but still .. i'd like it to go this way + */ if ((ob->softflag & OB_SB_GOAL) && sb->vertgroup) { /* even this is a deprecated evil hack */ /* I'd like to have it .. if (sb->namedVG_Goal[0]) */ @@ -3306,8 +3306,8 @@ static void mesh_to_softbody(Scene *scene, Object *ob) } /* to proove the concept - this enables per vertex *mass painting* - */ + * this enables per vertex *mass painting* + */ if (sb->namedVG_Mass[0]) { int grp= defgroup_name_index (ob, sb->namedVG_Mass); @@ -3411,9 +3411,9 @@ static void reference_to_scratch(Object *ob) } /* -helper function to get proper spring length -when object is rescaled -*/ + * helper function to get proper spring length + * when object is rescaled + */ static float globallen(float *v1, float *v2, Object *ob) { float p1[3], p2[3]; @@ -3669,7 +3669,7 @@ static void sb_new_scratch(SoftBody *sb) { if (!sb) return; sb->scratch = MEM_callocN(sizeof(SBScratch), "SBScratch"); - sb->scratch->colliderhash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "sb_new_scratch gh"); + sb->scratch->colliderhash = BLI_ghash_ptr_new("sb_new_scratch gh"); sb->scratch->bodyface = NULL; sb->scratch->totface = 0; sb->scratch->aabbmax[0]=sb->scratch->aabbmax[1]=sb->scratch->aabbmax[2] = 1.0e30f; @@ -3793,7 +3793,7 @@ static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCo /* vertexCos came from local world, go global */ mul_m4_v3(ob->obmat, bp->origE); /* just to be save give bp->origT a defined value - will be calulated in interpolate_exciter()*/ + * will be calulated in interpolate_exciter()*/ copy_v3_v3(bp->origT, bp->origE); } } diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 52007f1f43e..28fb75db41c 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -173,6 +173,7 @@ void sound_force_device(int device) void sound_init_once(void) { AUD_initOnce(); + atexit(sound_exit); } void sound_init(struct Main *bmain) diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 2c05029e82e..127f5369ca5 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -414,9 +414,7 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result, /* make a map from original faces to CCGFaces */ faceMap = MEM_mallocN(totface * sizeof(*faceMap), "facemapuv"); - - fi = ccgSubSurf_getFaceIterator(uvss); - for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { + for (fi = ccgSubSurf_getFaceIterator(uvss); !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { CCGFace *f = ccgFaceIterator_getCurrent(fi); faceMap[GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f))] = f; } @@ -664,9 +662,9 @@ static void ccgDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; - CCGVertIterator *vi = ccgSubSurf_getVertIterator(ss); - CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); - CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss); + CCGVertIterator *vi; + CCGEdgeIterator *ei; + CCGFaceIterator *fi; CCGKey key; int i, edgeSize = ccgSubSurf_getEdgeSize(ss); int gridSize = ccgSubSurf_getGridSize(ss); @@ -676,22 +674,24 @@ static void ccgDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) if (!ccgSubSurf_getNumVerts(ss)) min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0; - for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { + for (vi = ccgSubSurf_getVertIterator(ss); !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { CCGVert *v = ccgVertIterator_getCurrent(vi); float *co = ccgSubSurf_getVertData(ss, v); minmax_v3_v3v3(co, min_r, max_r); } + ccgVertIterator_free(vi); - for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { + for (ei = ccgSubSurf_getEdgeIterator(ss); !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); for (i = 0; i < edgeSize; i++) minmax_v3_v3v3(CCG_elem_offset_co(&key, edgeData, i), min_r, max_r); } + ccgEdgeIterator_free(ei); - for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { + for (fi = ccgSubSurf_getFaceIterator(ss); !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { CCGFace *f = ccgFaceIterator_getCurrent(fi); int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f); @@ -703,10 +703,7 @@ static void ccgDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) minmax_v3_v3v3(CCG_grid_elem_co(&key, faceGridData, x, y), min_r, max_r); } } - ccgFaceIterator_free(fi); - ccgEdgeIterator_free(ei); - ccgVertIterator_free(vi); } static int ccgDM_getNumVerts(DerivedMesh *dm) @@ -1048,7 +1045,7 @@ void subsurf_copy_grid_hidden(DerivedMesh *dm, const MPoly *mpoly, } /* Translate GridPaintMask into vertex paint masks. Assumes vertices - are in the order output by ccgDM_copyFinalVertArray. */ + * are in the order output by ccgDM_copyFinalVertArray. */ void subsurf_copy_grid_paint_mask(DerivedMesh *dm, const MPoly *mpoly, float *paint_mask, const GridPaintMask *grid_paint_mask) @@ -1399,8 +1396,7 @@ static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3]) totvert = ccgSubSurf_getNumVerts(ss); vertMap2 = MEM_mallocN(totvert * sizeof(*vertMap2), "vertmap"); - vi = ccgSubSurf_getVertIterator(ss); - for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { + for (vi = ccgSubSurf_getVertIterator(ss); !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { CCGVert *v = ccgVertIterator_getCurrent(vi); vertMap2[GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v))] = v; @@ -1409,8 +1405,7 @@ static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3]) totedge = ccgSubSurf_getNumEdges(ss); edgeMap2 = MEM_mallocN(totedge * sizeof(*edgeMap2), "edgemap"); - ei = ccgSubSurf_getEdgeIterator(ss); - for (i = 0; !ccgEdgeIterator_isStopped(ei); i++, ccgEdgeIterator_next(ei)) { + for (ei = ccgSubSurf_getEdgeIterator(ss), i = 0; !ccgEdgeIterator_isStopped(ei); i++, ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); edgeMap2[GET_INT_FROM_POINTER(ccgSubSurf_getEdgeEdgeHandle(e))] = e; @@ -1418,8 +1413,7 @@ static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3]) totface = ccgSubSurf_getNumFaces(ss); faceMap2 = MEM_mallocN(totface * sizeof(*faceMap2), "facemap"); - fi = ccgSubSurf_getFaceIterator(ss); - for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { + for (fi = ccgSubSurf_getFaceIterator(ss); !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { CCGFace *f = ccgFaceIterator_getCurrent(fi); faceMap2[GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f))] = f; @@ -1473,11 +1467,11 @@ static void ccgDM_foreachMappedVert( void *userData) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; - CCGVertIterator *vi = ccgSubSurf_getVertIterator(ccgdm->ss); + CCGVertIterator *vi; CCGKey key; CCG_key_top_level(&key, ccgdm->ss); - for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { + for (vi = ccgSubSurf_getVertIterator(ccgdm->ss); !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { CCGVert *v = ccgVertIterator_getCurrent(vi); CCGElem *vd = ccgSubSurf_getVertData(ccgdm->ss, v); int index = ccgDM_getVertMapIndex(ccgdm->ss, v); @@ -1496,13 +1490,13 @@ static void ccgDM_foreachMappedEdge( { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; - CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); + CCGEdgeIterator *ei; CCGKey key; int i, edgeSize = ccgSubSurf_getEdgeSize(ss); CCG_key_top_level(&key, ss); - for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { + for (ei = ccgSubSurf_getEdgeIterator(ss); !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); int index = ccgDM_getEdgeMapIndex(ss, e); @@ -1527,15 +1521,13 @@ static void ccgDM_drawVerts(DerivedMesh *dm) CCGFaceIterator *fi; glBegin(GL_POINTS); - vi = ccgSubSurf_getVertIterator(ss); - for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { + for (vi = ccgSubSurf_getVertIterator(ss); !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { CCGVert *v = ccgVertIterator_getCurrent(vi); glVertex3fv(ccgSubSurf_getVertData(ss, v)); } ccgVertIterator_free(vi); - ei = ccgSubSurf_getEdgeIterator(ss); - for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { + for (ei = ccgSubSurf_getEdgeIterator(ss); !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); int x; @@ -1544,8 +1536,7 @@ static void ccgDM_drawVerts(DerivedMesh *dm) } ccgEdgeIterator_free(ei); - fi = ccgSubSurf_getFaceIterator(ss); - for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { + for (fi = ccgSubSurf_getFaceIterator(ss); !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { CCGFace *f = ccgFaceIterator_getCurrent(fi); int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f); @@ -1805,26 +1796,27 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, doDraw = 0; matnr = -1; -#define PASSATTRIB(dx, dy, vert) { \ - if (attribs.totorco) { \ - index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \ - glVertexAttrib3fvARB(attribs.orco.gl_index, attribs.orco.array[index]); \ - } \ - for (b = 0; b < attribs.tottface; b++) { \ - MTFace *tf = &attribs.tface[b].array[a]; \ - glVertexAttrib2fvARB(attribs.tface[b].gl_index, tf->uv[vert]); \ - } \ - for (b = 0; b < attribs.totmcol; b++) { \ - MCol *cp = &attribs.mcol[b].array[a * 4 + vert]; \ - GLubyte col[4]; \ - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, col); \ - } \ - if (attribs.tottang) { \ - float *tang = attribs.tang.array[a * 4 + vert]; \ - glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ - } \ -} +#define PASSATTRIB(dx, dy, vert) { \ + if (attribs.totorco) { \ + index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \ + glVertexAttrib3fvARB(attribs.orco.gl_index, \ + attribs.orco.array[index]); \ + } \ + for (b = 0; b < attribs.tottface; b++) { \ + MTFace *tf = &attribs.tface[b].array[a]; \ + glVertexAttrib2fvARB(attribs.tface[b].gl_index, tf->uv[vert]); \ + } \ + for (b = 0; b < attribs.totmcol; b++) { \ + MCol *cp = &attribs.mcol[b].array[a * 4 + vert]; \ + GLubyte col[4]; \ + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; \ + glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, col); \ + } \ + if (attribs.tottang) { \ + float *tang = attribs.tang.array[a * 4 + vert]; \ + glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ + } \ +} (void)0 totface = ccgSubSurf_getNumFaces(ss); for (a = 0, i = 0; i < totface; i++) { @@ -1934,7 +1926,9 @@ static void ccgDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial) } /* Only used by non-editmesh types */ -static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void *userData, int, void *attribs), int (*setFace)(void *userData, int index), void *userData) +static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, + void (*setMaterial)(void *userData, int, void *attribs), + int (*setFace)(void *userData, int index), void *userData) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; @@ -1952,32 +1946,33 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void * matnr = -1; -#define PASSATTRIB(dx, dy, vert) { \ - if (attribs.totorco) { \ - index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \ - if (attribs.orco.gl_texco) \ - glTexCoord3fv(attribs.orco.array[index]); \ - else \ - glVertexAttrib3fvARB(attribs.orco.gl_index, attribs.orco.array[index]); \ - } \ - for (b = 0; b < attribs.tottface; b++) { \ - MTFace *tf = &attribs.tface[b].array[a]; \ - if (attribs.tface[b].gl_texco) \ - glTexCoord2fv(tf->uv[vert]); \ - else \ - glVertexAttrib2fvARB(attribs.tface[b].gl_index, tf->uv[vert]); \ - } \ - for (b = 0; b < attribs.totmcol; b++) { \ - MCol *cp = &attribs.mcol[b].array[a * 4 + vert]; \ - GLubyte col[4]; \ - col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, col); \ - } \ - if (attribs.tottang) { \ - float *tang = attribs.tang.array[a * 4 + vert]; \ - glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ - } \ -} +#define PASSATTRIB(dx, dy, vert) { \ + if (attribs.totorco) { \ + index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \ + if (attribs.orco.gl_texco) \ + glTexCoord3fv(attribs.orco.array[index]); \ + else \ + glVertexAttrib3fvARB(attribs.orco.gl_index, \ + attribs.orco.array[index]); \ + } \ + for (b = 0; b < attribs.tottface; b++) { \ + MTFace *tf = &attribs.tface[b].array[a]; \ + if (attribs.tface[b].gl_texco) \ + glTexCoord2fv(tf->uv[vert]); \ + else \ + glVertexAttrib2fvARB(attribs.tface[b].gl_index, tf->uv[vert]); \ + } \ + for (b = 0; b < attribs.totmcol; b++) { \ + MCol *cp = &attribs.mcol[b].array[a * 4 + vert]; \ + GLubyte col[4]; \ + col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; \ + glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, col); \ + } \ + if (attribs.tottang) { \ + float *tang = attribs.tang.array[a * 4 + vert]; \ + glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ + } \ +} (void)0 totface = ccgSubSurf_getNumFaces(ss); for (a = 0, i = 0; i < totface; i++) { @@ -2422,14 +2417,14 @@ static void ccgDM_drawMappedEdges(DerivedMesh *dm, { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; - CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); + CCGEdgeIterator *ei; CCGKey key; int i, useAging, edgeSize = ccgSubSurf_getEdgeSize(ss); CCG_key_top_level(&key, ss); ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL); - for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { + for (ei = ccgSubSurf_getEdgeIterator(ss); !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); int index = ccgDM_getEdgeMapIndex(ss, e); @@ -2460,13 +2455,13 @@ static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm, CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; CCGKey key; - CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); + CCGEdgeIterator *ei; int i, useAging, edgeSize = ccgSubSurf_getEdgeSize(ss); CCG_key_top_level(&key, ss); ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL); - for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { + for (ei = ccgSubSurf_getEdgeIterator(ss); !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); int index = ccgDM_getEdgeMapIndex(ss, e); @@ -2498,11 +2493,11 @@ static void ccgDM_foreachMappedFaceCenter( CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm; CCGSubSurf *ss = ccgdm->ss; CCGKey key; - CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss); + CCGFaceIterator *fi; CCG_key_top_level(&key, ss); - for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { + for (fi = ccgSubSurf_getFaceIterator(ss); !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { CCGFace *f = ccgFaceIterator_getCurrent(fi); int index = ccgDM_getFaceMapIndex(ss, f); @@ -3168,8 +3163,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, totvert = ccgSubSurf_getNumVerts(ss); ccgdm->vertMap = MEM_mallocN(totvert * sizeof(*ccgdm->vertMap), "vertMap"); - vi = ccgSubSurf_getVertIterator(ss); - for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { + for (vi = ccgSubSurf_getVertIterator(ss); !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { CCGVert *v = ccgVertIterator_getCurrent(vi); ccgdm->vertMap[GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v))].vert = v; @@ -3178,8 +3172,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, totedge = ccgSubSurf_getNumEdges(ss); ccgdm->edgeMap = MEM_mallocN(totedge * sizeof(*ccgdm->edgeMap), "edgeMap"); - ei = ccgSubSurf_getEdgeIterator(ss); - for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { + for (ei = ccgSubSurf_getEdgeIterator(ss); !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { CCGEdge *e = ccgEdgeIterator_getCurrent(ei); ccgdm->edgeMap[GET_INT_FROM_POINTER(ccgSubSurf_getEdgeEdgeHandle(e))].edge = e; @@ -3187,8 +3180,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, totface = ccgSubSurf_getNumFaces(ss); ccgdm->faceMap = MEM_mallocN(totface * sizeof(*ccgdm->faceMap), "faceMap"); - fi = ccgSubSurf_getFaceIterator(ss); - for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { + for (fi = ccgSubSurf_getFaceIterator(ss); !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { CCGFace *f = ccgFaceIterator_getCurrent(fi); ccgdm->faceMap[GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f))].face = f; @@ -3237,7 +3229,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, has_edge_origindex = CustomData_has_layer(&ccgdm->dm.edgeData, CD_ORIGINDEX); - loopindex = loopindex2 = 0; //current loop index + loopindex = loopindex2 = 0; /* current loop index */ for (index = 0; index < totface; index++) { CCGFace *f = ccgdm->faceMap[index].face; int numVerts = ccgSubSurf_getFaceNumVerts(f); @@ -3587,8 +3579,7 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3]) ss_sync_from_derivedmesh(ss, dm, NULL, 0); - vi = ccgSubSurf_getVertIterator(ss); - for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { + for (vi = ccgSubSurf_getVertIterator(ss); !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) { CCGVert *v = ccgVertIterator_getCurrent(vi); int idx = GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v)); int N = ccgSubSurf_getVertNumEdges(v); @@ -3596,8 +3587,8 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3]) float *co; int i; - edge_sum[0] = edge_sum[1] = edge_sum[2] = 0.0; - face_sum[0] = face_sum[1] = face_sum[2] = 0.0; + zero_v3(edge_sum); + zero_v3(face_sum); for (i = 0; i < N; i++) { CCGEdge *e = ccgSubSurf_getVertEdge(v, i); diff --git a/source/blender/blenkernel/intern/suggestions.c b/source/blender/blenkernel/intern/suggestions.c index 8b3138066d3..99e33594a3e 100644 --- a/source/blender/blenkernel/intern/suggestions.c +++ b/source/blender/blenkernel/intern/suggestions.c @@ -50,8 +50,8 @@ static char *documentation = NULL; static int txttl_cmp(const char *first, const char *second, int len) { int cmp, i; - for (cmp=0, i=0; i<len; i++) { - if ( (cmp= toupper(first[i])-toupper(second[i])) ) { + for (cmp = 0, i = 0; i < len; i++) { + if ( (cmp = toupper(first[i]) - toupper(second[i])) ) { break; } } @@ -61,7 +61,7 @@ static int txttl_cmp(const char *first, const char *second, int len) static void txttl_free_suggest(void) { SuggItem *item, *prev; - for (item = suggestions.last; item; item=prev) { + for (item = suggestions.last; item; item = prev) { prev = item->prev; MEM_freeN(item); } @@ -104,7 +104,7 @@ void texttool_text_clear(void) short texttool_text_is_active(Text *text) { - return activeToolText==text ? 1 : 0; + return activeToolText == text ? 1 : 0; } /***************************/ @@ -135,7 +135,7 @@ void texttool_suggest_add(const char *name, char type) } else { cmp = -1; - for (item=suggestions.last; item; item=item->prev) { + for (item = suggestions.last; item; item = item->prev) { cmp = txttl_cmp(name, item->name, len); /* Newitem comes after this item, insert here */ @@ -160,7 +160,7 @@ void texttool_suggest_add(const char *name, char type) } } suggestions.firstmatch = suggestions.lastmatch = suggestions.selected = NULL; - suggestions.top= 0; + suggestions.top = 0; } void texttool_suggest_prefix(const char *prefix) @@ -169,22 +169,22 @@ void texttool_suggest_prefix(const char *prefix) int cmp, len = strlen(prefix), top = 0; if (!suggestions.first) return; - if (len==0) { + if (len == 0) { suggestions.selected = suggestions.firstmatch = suggestions.first; suggestions.lastmatch = suggestions.last; return; } first = last = NULL; - for (match=suggestions.first; match; match=match->next) { + for (match = suggestions.first; match; match = match->next) { cmp = txttl_cmp(prefix, match->name, len); - if (cmp==0) { + if (cmp == 0) { if (!first) { first = match; suggestions.top = top; } } - else if (cmp<0) { + else if (cmp < 0) { if (!last) { last = match->prev; break; @@ -254,13 +254,13 @@ void texttool_docs_show(const char *docs) } /* Ensure documentation ends with a '\n' */ - if (docs[len-1] != '\n') { - documentation = MEM_mallocN(len+2, "Documentation"); + if (docs[len - 1] != '\n') { + documentation = MEM_mallocN(len + 2, "Documentation"); strncpy(documentation, docs, len); documentation[len++] = '\n'; } else { - documentation = MEM_mallocN(len+1, "Documentation"); + documentation = MEM_mallocN(len + 1, "Documentation"); strncpy(documentation, docs, len); } documentation[len] = '\0'; diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 4e2b4be474b..8339e973d43 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -768,7 +768,7 @@ static TracksMap *tracks_map_new(const char *object_name, int is_camera, int num if (customdata_size) map->customdata = MEM_callocN(customdata_size*num_tracks, "TracksMap customdata"); - map->hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "TracksMap hash"); + map->hash = BLI_ghash_ptr_new("TracksMap hash"); return map; } diff --git a/source/blender/blenkernel/intern/writeavi.c b/source/blender/blenkernel/intern/writeavi.c index 841a0f84fed..cd19f8a987c 100644 --- a/source/blender/blenkernel/intern/writeavi.c +++ b/source/blender/blenkernel/intern/writeavi.c @@ -73,9 +73,9 @@ bMovieHandle *BKE_movie_handle_get(const char imtype) static bMovieHandle mh; /* set the default handle, as builtin */ - mh.start_movie= start_avi; - mh.append_movie= append_avi; - mh.end_movie= end_avi; + mh.start_movie = start_avi; + mh.append_movie = append_avi; + mh.end_movie = end_avi; mh.get_next_frame = NULL; mh.get_movie_path = filepath_avi; @@ -89,9 +89,9 @@ bMovieHandle *BKE_movie_handle_get(const char imtype) #endif #ifdef WITH_QUICKTIME if (imtype == R_IMF_IMTYPE_QUICKTIME) { - mh.start_movie= start_qt; - mh.append_movie= append_qt; - mh.end_movie= end_qt; + mh.start_movie = start_qt; + mh.append_movie = append_qt; + mh.end_movie = end_qt; mh.get_movie_path = filepath_qt; } #endif @@ -121,11 +121,11 @@ bMovieHandle *BKE_movie_handle_get(const char imtype) /* ****************************************************************** */ -static AviMovie *avi=NULL; +static AviMovie *avi = NULL; -static void filepath_avi (char *string, RenderData *rd) +static void filepath_avi(char *string, RenderData *rd) { - if (string==NULL) return; + if (string == NULL) return; strcpy(string, rd->pic); BLI_path_abs(string, G.main->name); @@ -153,30 +153,30 @@ static int start_avi(Scene *scene, RenderData *rd, int rectx, int recty, ReportL x = rectx; y = recty; - quality= rd->im_format.quality; - framerate= (double) rd->frs_sec / (double) rd->frs_sec_base; + quality = rd->im_format.quality; + framerate = (double) rd->frs_sec / (double) rd->frs_sec_base; - avi = MEM_mallocN (sizeof(AviMovie), "avimovie"); + avi = MEM_mallocN(sizeof(AviMovie), "avimovie"); - if (rd->im_format.imtype != R_IMF_IMTYPE_AVIJPEG ) format = AVI_FORMAT_AVI_RGB; + if (rd->im_format.imtype != R_IMF_IMTYPE_AVIJPEG) format = AVI_FORMAT_AVI_RGB; else format = AVI_FORMAT_MJPEG; - if (AVI_open_compress (name, avi, 1, format) != AVI_ERROR_NONE) { + if (AVI_open_compress(name, avi, 1, format) != AVI_ERROR_NONE) { BKE_report(reports, RPT_ERROR, "Cannot open or start AVI movie file."); - MEM_freeN (avi); + MEM_freeN(avi); avi = NULL; return 0; } - AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &x); - AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_HEIGHT, &y); - AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_QUALITY, &quality); - AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_FRAMERATE, &framerate); - - avi->interlace= 0; - avi->odd_fields= 0; -/* avi->interlace= rd->mode & R_FIELDS; */ -/* avi->odd_fields= (rd->mode & R_ODDFIELD)?1:0; */ + AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &x); + AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_HEIGHT, &y); + AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_QUALITY, &quality); + AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_FRAMERATE, &framerate); + + avi->interlace = 0; + avi->odd_fields = 0; +/* avi->interlace= rd->mode & R_FIELDS; */ +/* avi->odd_fields= (rd->mode & R_ODDFIELD)?1:0; */ printf("Created avi: %s\n", name); return 1; @@ -193,26 +193,26 @@ static int append_avi(RenderData *UNUSED(rd), int start_frame, int frame, int *p return 0; /* note that libavi free's the buffer... stupid interface - zr */ - rectot= MEM_mallocN(rectx*recty*sizeof(int), "rectot"); - rt1= rectot; - rt2= (unsigned int*)pixels + (recty-1)*rectx; + rectot = MEM_mallocN(rectx * recty * sizeof(int), "rectot"); + rt1 = rectot; + rt2 = (unsigned int *)pixels + (recty - 1) * rectx; /* flip y and convert to abgr */ - for (y=0; y < recty; y++, rt1+= rectx, rt2-= rectx) { - memcpy (rt1, rt2, rectx*sizeof(int)); + for (y = 0; y < recty; y++, rt1 += rectx, rt2 -= rectx) { + memcpy(rt1, rt2, rectx * sizeof(int)); - cp= (char *)rt1; - for (x= rectx; x>0; x--) { - rt= cp[0]; - cp[0]= cp[3]; - cp[3]= rt; - rt= cp[1]; - cp[1]= cp[2]; - cp[2]= rt; - cp+= 4; + cp = (char *)rt1; + for (x = rectx; x > 0; x--) { + rt = cp[0]; + cp[0] = cp[3]; + cp[3] = rt; + rt = cp[1]; + cp[1] = cp[2]; + cp[2] = rt; + cp += 4; } } - AVI_write_frame (avi, (frame-start_frame), AVI_FORMAT_RGB32, rectot, rectx*recty*4); + AVI_write_frame(avi, (frame - start_frame), AVI_FORMAT_RGB32, rectot, rectx * recty * 4); // printf ("added frame %3d (frame %3d in avi): ", frame, frame-start_frame); return 1; @@ -222,17 +222,17 @@ static void end_avi(void) { if (avi == NULL) return; - AVI_close_compress (avi); - MEM_freeN (avi); - avi= NULL; + AVI_close_compress(avi); + MEM_freeN(avi); + avi = NULL; } /* similar to BKE_makepicstring() */ void BKE_movie_filepath_get(char *string, RenderData *rd) { - bMovieHandle *mh= BKE_movie_handle_get(rd->im_format.imtype); + bMovieHandle *mh = BKE_movie_handle_get(rd->im_format.imtype); if (mh->get_movie_path) mh->get_movie_path(string, rd); else - string[0]= '\0'; + string[0] = '\0'; } diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index a29de3b0157..a3fdb41fe37 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -80,30 +80,30 @@ static int ffmpeg_gop_size = 12; static int ffmpeg_autosplit = 0; static int ffmpeg_autosplit_count = 0; -static AVFormatContext* outfile = 0; -static AVStream* video_stream = 0; -static AVStream* audio_stream = 0; -static AVFrame* current_frame = 0; +static AVFormatContext *outfile = 0; +static AVStream *video_stream = 0; +static AVStream *audio_stream = 0; +static AVFrame *current_frame = 0; static struct SwsContext *img_convert_ctx = 0; -static uint8_t* video_buffer = 0; +static uint8_t *video_buffer = 0; static int video_buffersize = 0; -static uint8_t* audio_input_buffer = 0; +static uint8_t *audio_input_buffer = 0; static int audio_input_samples = 0; -static uint8_t* audio_output_buffer = 0; +static uint8_t *audio_output_buffer = 0; static int audio_outbuf_size = 0; static double audio_time = 0.0f; #ifdef WITH_AUDASPACE -static AUD_Device* audio_mixdown_device = 0; +static AUD_Device *audio_mixdown_device = 0; #endif #define FFMPEG_AUTOSPLIT_SIZE 2000000000 /* Delete a picture buffer */ -static void delete_picture(AVFrame* f) +static void delete_picture(AVFrame *f) { if (f) { if (f->data[0]) MEM_freeN(f->data[0]); @@ -114,7 +114,7 @@ static void delete_picture(AVFrame* f) #ifdef WITH_AUDASPACE static int write_audio_frame(void) { - AVCodecContext* c = NULL; + AVCodecContext *c = NULL; AVPacket pkt; c = audio_stream->codec; @@ -138,7 +138,7 @@ static int write_audio_frame(void) if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE) { pkt.pts = av_rescale_q(c->coded_frame->pts, - c->time_base, audio_stream->time_base); + c->time_base, audio_stream->time_base); fprintf(stderr, "Audio Frame PTS: %d\n", (int)pkt.pts); } @@ -155,10 +155,10 @@ static int write_audio_frame(void) #endif // #ifdef WITH_AUDASPACE /* Allocate a temporary frame */ -static AVFrame* alloc_picture(int pix_fmt, int width, int height) +static AVFrame *alloc_picture(int pix_fmt, int width, int height) { - AVFrame* f; - uint8_t* buf; + AVFrame *f; + uint8_t *buf; int size; /* allocate space for the struct */ @@ -171,82 +171,82 @@ static AVFrame* alloc_picture(int pix_fmt, int width, int height) free(f); return NULL; } - avpicture_fill((AVPicture*)f, buf, pix_fmt, width, height); + avpicture_fill((AVPicture *)f, buf, pix_fmt, width, height); return f; } /* Get the correct file extensions for the requested format, * first is always desired guess_format parameter */ -static const char** get_file_extensions(int format) +static const char **get_file_extensions(int format) { switch (format) { - case FFMPEG_DV: { - static const char * rv[] = { ".dv", NULL }; - return rv; - } - case FFMPEG_MPEG1: { - static const char * rv[] = { ".mpg", ".mpeg", NULL }; - return rv; - } - case FFMPEG_MPEG2: { - static const char * rv[] = { ".dvd", ".vob", ".mpg", ".mpeg", - NULL }; - return rv; - } - case FFMPEG_MPEG4: { - static const char * rv[] = { ".mp4", ".mpg", ".mpeg", NULL }; - return rv; - } - case FFMPEG_AVI: { - static const char * rv[] = { ".avi", NULL }; - return rv; - } - case FFMPEG_MOV: { - static const char * rv[] = { ".mov", NULL }; - return rv; - } - case FFMPEG_H264: { - /* FIXME: avi for now... */ - static const char * rv[] = { ".avi", NULL }; - return rv; - } + case FFMPEG_DV: { + static const char *rv[] = { ".dv", NULL }; + return rv; + } + case FFMPEG_MPEG1: { + static const char *rv[] = { ".mpg", ".mpeg", NULL }; + return rv; + } + case FFMPEG_MPEG2: { + static const char *rv[] = { ".dvd", ".vob", ".mpg", ".mpeg", + NULL }; + return rv; + } + case FFMPEG_MPEG4: { + static const char *rv[] = { ".mp4", ".mpg", ".mpeg", NULL }; + return rv; + } + case FFMPEG_AVI: { + static const char *rv[] = { ".avi", NULL }; + return rv; + } + case FFMPEG_MOV: { + static const char *rv[] = { ".mov", NULL }; + return rv; + } + case FFMPEG_H264: { + /* FIXME: avi for now... */ + static const char *rv[] = { ".avi", NULL }; + return rv; + } - case FFMPEG_XVID: { - /* FIXME: avi for now... */ - static const char * rv[] = { ".avi", NULL }; - return rv; - } - case FFMPEG_FLV: { - static const char * rv[] = { ".flv", NULL }; - return rv; - } - case FFMPEG_MKV: { - static const char * rv[] = { ".mkv", NULL }; - return rv; - } - case FFMPEG_OGG: { - static const char * rv[] = { ".ogg", ".ogv", NULL }; - return rv; - } - case FFMPEG_MP3: { - static const char * rv[] = { ".mp3", NULL }; - return rv; - } - case FFMPEG_WAV: { - static const char * rv[] = { ".wav", NULL }; - return rv; - } - default: - return NULL; + case FFMPEG_XVID: { + /* FIXME: avi for now... */ + static const char *rv[] = { ".avi", NULL }; + return rv; + } + case FFMPEG_FLV: { + static const char *rv[] = { ".flv", NULL }; + return rv; + } + case FFMPEG_MKV: { + static const char *rv[] = { ".mkv", NULL }; + return rv; + } + case FFMPEG_OGG: { + static const char *rv[] = { ".ogg", ".ogv", NULL }; + return rv; + } + case FFMPEG_MP3: { + static const char *rv[] = { ".mp3", NULL }; + return rv; + } + case FFMPEG_WAV: { + static const char *rv[] = { ".wav", NULL }; + return rv; + } + default: + return NULL; } } /* Write a frame to the output file */ -static int write_video_frame(RenderData *rd, int cfra, AVFrame* frame, ReportList *reports) +static int write_video_frame(RenderData *rd, int cfra, AVFrame *frame, ReportList *reports) { int outsize = 0; - int ret, success= 1; - AVCodecContext* c = video_stream->codec; + int ret, success = 1; + AVCodecContext *c = video_stream->codec; frame->pts = cfra; @@ -255,7 +255,7 @@ static int write_video_frame(RenderData *rd, int cfra, AVFrame* frame, ReportLis } outsize = avcodec_encode_video(c, video_buffer, video_buffersize, - frame); + frame); if (outsize > 0) { AVPacket packet; @@ -263,8 +263,8 @@ static int write_video_frame(RenderData *rd, int cfra, AVFrame* frame, ReportLis if (c->coded_frame->pts != AV_NOPTS_VALUE) { packet.pts = av_rescale_q(c->coded_frame->pts, - c->time_base, - video_stream->time_base); + c->time_base, + video_stream->time_base); fprintf(stderr, "Video Frame PTS: %d\n", (int)packet.pts); } else { @@ -289,14 +289,14 @@ static int write_video_frame(RenderData *rd, int cfra, AVFrame* frame, ReportLis } /* read and encode a frame of audio from the buffer */ -static AVFrame* generate_video_frame(uint8_t* pixels, ReportList *reports) +static AVFrame *generate_video_frame(uint8_t *pixels, ReportList *reports) { - uint8_t* rendered_frame; + uint8_t *rendered_frame; - AVCodecContext* c = video_stream->codec; + AVCodecContext *c = video_stream->codec; int width = c->width; int height = c->height; - AVFrame* rgb_frame; + AVFrame *rgb_frame; if (c->pix_fmt != PIX_FMT_BGR32) { rgb_frame = alloc_picture(PIX_FMT_BGR32, width, height); @@ -317,9 +317,9 @@ static AVFrame* generate_video_frame(uint8_t* pixels, ReportList *reports) if (ENDIAN_ORDER == L_ENDIAN) { int y; for (y = 0; y < height; y++) { - uint8_t* target = rgb_frame->data[0] + width * 4 * (height - y - 1); - uint8_t* src = rendered_frame + width * 4 * y; - uint8_t* end = src + width * 4; + uint8_t *target = rgb_frame->data[0] + width * 4 * (height - y - 1); + uint8_t *src = rendered_frame + width * 4 * y; + uint8_t *end = src + width * 4; while (src != end) { target[3] = src[3]; target[2] = src[2]; @@ -334,9 +334,9 @@ static AVFrame* generate_video_frame(uint8_t* pixels, ReportList *reports) else { int y; for (y = 0; y < height; y++) { - uint8_t* target = rgb_frame->data[0] + width * 4 * (height - y - 1); - uint8_t* src = rendered_frame + width * 4 * y; - uint8_t* end = src + width * 4; + uint8_t *target = rgb_frame->data[0] + width * 4 * (height - y - 1); + uint8_t *src = rendered_frame + width * 4 * y; + uint8_t *end = src + width * 4; while (src != end) { target[3] = src[0]; target[2] = src[1]; @@ -350,7 +350,7 @@ static AVFrame* generate_video_frame(uint8_t* pixels, ReportList *reports) } if (c->pix_fmt != PIX_FMT_BGR32) { - sws_scale(img_convert_ctx, (const uint8_t * const*) rgb_frame->data, + sws_scale(img_convert_ctx, (const uint8_t *const *) rgb_frame->data, rgb_frame->linesize, 0, c->height, current_frame->data, current_frame->linesize); delete_picture(rgb_frame); @@ -358,11 +358,11 @@ static AVFrame* generate_video_frame(uint8_t* pixels, ReportList *reports) return current_frame; } -static void set_ffmpeg_property_option(AVCodecContext* c, IDProperty * prop) +static void set_ffmpeg_property_option(AVCodecContext *c, IDProperty *prop) { char name[128]; - char * param; - const AVOption * rv = NULL; + char *param; + const AVOption *rv = NULL; fprintf(stderr, "FFMPEG expert option: %s: ", prop->name); @@ -375,56 +375,56 @@ static void set_ffmpeg_property_option(AVCodecContext* c, IDProperty * prop) } switch (prop->type) { - case IDP_STRING: - fprintf(stderr, "%s.\n", IDP_String(prop)); - av_set_string3(c, prop->name, IDP_String(prop), 1, &rv); - break; - case IDP_FLOAT: - fprintf(stderr, "%g.\n", IDP_Float(prop)); - rv = av_set_double(c, prop->name, IDP_Float(prop)); - break; - case IDP_INT: - fprintf(stderr, "%d.\n", IDP_Int(prop)); - - if (param) { - if (IDP_Int(prop)) { - av_set_string3(c, name, param, 1, &rv); + case IDP_STRING: + fprintf(stderr, "%s.\n", IDP_String(prop)); + av_set_string3(c, prop->name, IDP_String(prop), 1, &rv); + break; + case IDP_FLOAT: + fprintf(stderr, "%g.\n", IDP_Float(prop)); + rv = av_set_double(c, prop->name, IDP_Float(prop)); + break; + case IDP_INT: + fprintf(stderr, "%d.\n", IDP_Int(prop)); + + if (param) { + if (IDP_Int(prop)) { + av_set_string3(c, name, param, 1, &rv); + } + else { + return; + } } else { - return; + rv = av_set_int(c, prop->name, IDP_Int(prop)); } - } - else { - rv = av_set_int(c, prop->name, IDP_Int(prop)); - } - break; + break; } if (!rv) { fprintf(stderr, "ffmpeg-option not supported: %s! Skipping.\n", - prop->name); + prop->name); } } static int ffmpeg_proprty_valid(AVCodecContext *c, const char *prop_name, IDProperty *curr) { - int valid= 1; + int valid = 1; - if (strcmp(prop_name, "video")==0) { - if (strcmp(curr->name, "bf")==0) { + if (strcmp(prop_name, "video") == 0) { + if (strcmp(curr->name, "bf") == 0) { /* flash codec doesn't support b frames */ - valid&= c->codec_id!=CODEC_ID_FLV1; + valid &= c->codec_id != CODEC_ID_FLV1; } } return valid; } -static void set_ffmpeg_properties(RenderData *rd, AVCodecContext *c, const char * prop_name) +static void set_ffmpeg_properties(RenderData *rd, AVCodecContext *c, const char *prop_name) { - IDProperty * prop; - void * iter; - IDProperty * curr; + IDProperty *prop; + void *iter; + IDProperty *curr; if (!rd->ffcodecdata.properties) { return; @@ -445,12 +445,12 @@ static void set_ffmpeg_properties(RenderData *rd, AVCodecContext *c, const char /* prepare a video stream for the output file */ -static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContext* of, - int rectx, int recty) +static AVStream *alloc_video_stream(RenderData *rd, int codec_id, AVFormatContext *of, + int rectx, int recty) { - AVStream* st; - AVCodecContext* c; - AVCodec* codec; + AVStream *st; + AVCodecContext *c; + AVCodec *codec; st = av_new_stream(of, 0); if (!st) return NULL; @@ -472,7 +472,7 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex c->time_base.num = 100; } else if ((double) ((int) rd->frs_sec_base) == - rd->frs_sec_base) { + rd->frs_sec_base) { c->time_base.den = rd->frs_sec; c->time_base.num = (int) rd->frs_sec_base; } @@ -482,9 +482,9 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex } c->gop_size = ffmpeg_gop_size; - c->bit_rate = ffmpeg_video_bitrate*1000; - c->rc_max_rate = rd->ffcodecdata.rc_max_rate*1000; - c->rc_min_rate = rd->ffcodecdata.rc_min_rate*1000; + c->bit_rate = ffmpeg_video_bitrate * 1000; + c->rc_max_rate = rd->ffcodecdata.rc_max_rate * 1000; + c->rc_min_rate = rd->ffcodecdata.rc_min_rate * 1000; c->rc_buffer_size = rd->ffcodecdata.rc_buffer_size * 1024; c->rc_initial_buffer_occupancy = rd->ffcodecdata.rc_buffer_size * 3 / 4; c->rc_buffer_aggressivity = 1.0; @@ -506,13 +506,13 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex if (ffmpeg_type == FFMPEG_XVID) { /* arghhhh ... */ c->pix_fmt = PIX_FMT_YUV420P; - c->codec_tag = (('D'<<24) + ('I'<<16) + ('V'<<8) + 'X'); + c->codec_tag = (('D' << 24) + ('I' << 16) + ('V' << 8) + 'X'); } if (codec_id == CODEC_ID_H264) { /* correct wrong default ffmpeg param which crash x264 */ - c->qmin=10; - c->qmax=51; + c->qmin = 10; + c->qmax = 51; } // Keep lossless encodes in the RGB domain. @@ -534,7 +534,7 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex #endif } - if (codec_id == CODEC_ID_QTRLE ) { + if (codec_id == CODEC_ID_QTRLE) { if (rd->im_format.planes == R_IMF_PLANES_RGBA) { c->pix_fmt = PIX_FMT_ARGB; } @@ -544,7 +544,7 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex // || !strcmp(of->oformat->name, "mp4") // || !strcmp(of->oformat->name, "mov") // || !strcmp(of->oformat->name, "3gp") - ) { + ) { fprintf(stderr, "Using global header\n"); c->flags |= CODEC_FLAG_GLOBAL_HEADER; } @@ -559,7 +559,7 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex /* xasp & yasp got float lately... */ st->sample_aspect_ratio = c->sample_aspect_ratio = av_d2q( - ((double) rd->xasp / (double) rd->yasp), 255); + ((double) rd->xasp / (double) rd->yasp), 255); set_ffmpeg_properties(rd, c, "video"); @@ -569,7 +569,7 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex return NULL; } - if ( codec_id == CODEC_ID_QTRLE ) { + if (codec_id == CODEC_ID_QTRLE) { // normally it should be enough to have buffer with actual image size, // but some codecs like QTRLE might store extra information in this buffer, // so it should be a way larger @@ -577,32 +577,32 @@ static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex // maximum video buffer size is 6-bytes per pixel, plus DPX header size (1664) // (from FFmpeg sources) int size = c->width * c->height; - video_buffersize = 7*size + 10000; + video_buffersize = 7 * size + 10000; } else video_buffersize = avpicture_get_size(c->pix_fmt, c->width, c->height); - video_buffer = (uint8_t*)MEM_mallocN(video_buffersize*sizeof(uint8_t), - "FFMPEG video buffer"); + video_buffer = (uint8_t *)MEM_mallocN(video_buffersize * sizeof(uint8_t), + "FFMPEG video buffer"); current_frame = alloc_picture(c->pix_fmt, c->width, c->height); img_convert_ctx = sws_getContext(c->width, c->height, - PIX_FMT_BGR32, - c->width, c->height, - c->pix_fmt, - SWS_BICUBIC, - NULL, NULL, NULL); + PIX_FMT_BGR32, + c->width, c->height, + c->pix_fmt, + SWS_BICUBIC, + NULL, NULL, NULL); return st; } /* Prepare an audio stream for the output file */ -static AVStream* alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContext* of) +static AVStream *alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContext *of) { - AVStream* st; - AVCodecContext* c; - AVCodec* codec; + AVStream *st; + AVCodecContext *c; + AVCodec *codec; st = av_new_stream(of, 1); if (!st) return NULL; @@ -612,7 +612,7 @@ static AVStream* alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContex c->codec_type = AVMEDIA_TYPE_AUDIO; c->sample_rate = rd->ffcodecdata.audio_mixrate; - c->bit_rate = ffmpeg_audio_bitrate*1000; + c->bit_rate = ffmpeg_audio_bitrate * 1000; c->sample_fmt = SAMPLE_FMT_S16; c->channels = rd->ffcodecdata.audio_channels; codec = avcodec_find_encoder(c->codec_id); @@ -630,8 +630,8 @@ static AVStream* alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContex /* need to prevent floating point exception when using vorbis audio codec, * initialize this value in the same way as it's done in FFmpeg iteslf (sergey) */ - st->codec->time_base.num= 1; - st->codec->time_base.den= st->codec->sample_rate; + st->codec->time_base.num = 1; + st->codec->time_base.den = st->codec->sample_rate; audio_outbuf_size = FF_MIN_BUFFER_SIZE; @@ -643,11 +643,11 @@ static AVStream* alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContex audio_outbuf_size = c->frame_size * c->channels * sizeof(int16_t) * 4; } - audio_output_buffer = (uint8_t*)av_malloc( - audio_outbuf_size); + audio_output_buffer = (uint8_t *)av_malloc( + audio_outbuf_size); - audio_input_buffer = (uint8_t*)av_malloc( - audio_input_samples * c->channels * sizeof(int16_t)); + audio_input_buffer = (uint8_t *)av_malloc( + audio_input_samples * c->channels * sizeof(int16_t)); audio_time = 0.0f; @@ -658,10 +658,10 @@ static AVStream* alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContex static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, ReportList *reports) { /* Handle to the output file */ - AVFormatContext* of; - AVOutputFormat* fmt; + AVFormatContext *of; + AVOutputFormat *fmt; char name[256]; - const char ** exts; + const char **exts; ffmpeg_type = rd->ffcodecdata.type; ffmpeg_codec = rd->ffcodecdata.codec; @@ -670,20 +670,20 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report ffmpeg_audio_bitrate = rd->ffcodecdata.audio_bitrate; ffmpeg_gop_size = rd->ffcodecdata.gop_size; ffmpeg_autosplit = rd->ffcodecdata.flags - & FFMPEG_AUTOSPLIT_OUTPUT; + & FFMPEG_AUTOSPLIT_OUTPUT; do_init_ffmpeg(); /* Determine the correct filename */ BKE_ffmpeg_filepath_get(name, rd); fprintf(stderr, "Starting output to %s(ffmpeg)...\n" - " Using type=%d, codec=%d, audio_codec=%d,\n" - " video_bitrate=%d, audio_bitrate=%d,\n" - " gop_size=%d, autosplit=%d\n" - " render width=%d, render height=%d\n", - name, ffmpeg_type, ffmpeg_codec, ffmpeg_audio_codec, - ffmpeg_video_bitrate, ffmpeg_audio_bitrate, - ffmpeg_gop_size, ffmpeg_autosplit, rectx, recty); + " Using type=%d, codec=%d, audio_codec=%d,\n" + " video_bitrate=%d, audio_bitrate=%d,\n" + " gop_size=%d, autosplit=%d\n" + " render width=%d, render height=%d\n", + name, ffmpeg_type, ffmpeg_codec, ffmpeg_audio_codec, + ffmpeg_video_bitrate, ffmpeg_audio_bitrate, + ffmpeg_gop_size, ffmpeg_autosplit, rectx, recty); exts = get_file_extensions(ffmpeg_type); if (!exts) { @@ -703,7 +703,7 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report } of->oformat = fmt; - of->packet_size= rd->ffcodecdata.mux_packet_size; + of->packet_size = rd->ffcodecdata.mux_packet_size; if (ffmpeg_audio_codec != CODEC_ID_NONE) { of->mux_rate = rd->ffcodecdata.mux_rate; } @@ -711,49 +711,49 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report of->mux_rate = 0; } - of->preload = (int)(0.5*AV_TIME_BASE); - of->max_delay = (int)(0.7*AV_TIME_BASE); + of->preload = (int)(0.5 * AV_TIME_BASE); + of->max_delay = (int)(0.7 * AV_TIME_BASE); fmt->audio_codec = ffmpeg_audio_codec; BLI_snprintf(of->filename, sizeof(of->filename), "%s", name); /* set the codec to the user's selection */ switch (ffmpeg_type) { - case FFMPEG_AVI: - case FFMPEG_MOV: - case FFMPEG_MKV: - fmt->video_codec = ffmpeg_codec; - break; - case FFMPEG_OGG: - fmt->video_codec = CODEC_ID_THEORA; - break; - case FFMPEG_DV: - fmt->video_codec = CODEC_ID_DVVIDEO; - break; - case FFMPEG_MPEG1: - fmt->video_codec = CODEC_ID_MPEG1VIDEO; - break; - case FFMPEG_MPEG2: - fmt->video_codec = CODEC_ID_MPEG2VIDEO; - break; - case FFMPEG_H264: - fmt->video_codec = CODEC_ID_H264; - break; - case FFMPEG_XVID: - fmt->video_codec = CODEC_ID_MPEG4; - break; - case FFMPEG_FLV: - fmt->video_codec = CODEC_ID_FLV1; - break; - case FFMPEG_MP3: - fmt->audio_codec = CODEC_ID_MP3; - case FFMPEG_WAV: - fmt->video_codec = CODEC_ID_NONE; - break; - case FFMPEG_MPEG4: - default: - fmt->video_codec = CODEC_ID_MPEG4; - break; + case FFMPEG_AVI: + case FFMPEG_MOV: + case FFMPEG_MKV: + fmt->video_codec = ffmpeg_codec; + break; + case FFMPEG_OGG: + fmt->video_codec = CODEC_ID_THEORA; + break; + case FFMPEG_DV: + fmt->video_codec = CODEC_ID_DVVIDEO; + break; + case FFMPEG_MPEG1: + fmt->video_codec = CODEC_ID_MPEG1VIDEO; + break; + case FFMPEG_MPEG2: + fmt->video_codec = CODEC_ID_MPEG2VIDEO; + break; + case FFMPEG_H264: + fmt->video_codec = CODEC_ID_H264; + break; + case FFMPEG_XVID: + fmt->video_codec = CODEC_ID_MPEG4; + break; + case FFMPEG_FLV: + fmt->video_codec = CODEC_ID_FLV1; + break; + case FFMPEG_MP3: + fmt->audio_codec = CODEC_ID_MP3; + case FFMPEG_WAV: + fmt->video_codec = CODEC_ID_NONE; + break; + case FFMPEG_MPEG4: + default: + fmt->video_codec = CODEC_ID_MPEG4; + break; } if (fmt->video_codec == CODEC_ID_DVVIDEO) { if (rectx != 720) { @@ -838,7 +838,7 @@ void flush_ffmpeg(void) int outsize = 0; int ret = 0; - AVCodecContext* c = video_stream->codec; + AVCodecContext *c = video_stream->codec; /* get the delayed frames */ while (1) { AVPacket packet; @@ -854,8 +854,8 @@ void flush_ffmpeg(void) } if (c->coded_frame->pts != AV_NOPTS_VALUE) { packet.pts = av_rescale_q(c->coded_frame->pts, - c->time_base, - video_stream->time_base); + c->time_base, + video_stream->time_base); fprintf(stderr, "Video Frame PTS: %d\n", (int)packet.pts); } else { @@ -881,12 +881,12 @@ void flush_ffmpeg(void) * ********************************************************************** */ /* Get the output filename-- similar to the other output formats */ -void BKE_ffmpeg_filepath_get(char* string, RenderData* rd) +void BKE_ffmpeg_filepath_get(char *string, RenderData *rd) { char autosplit[20]; - const char ** exts = get_file_extensions(rd->ffcodecdata.type); - const char ** fe = exts; + const char **exts = get_file_extensions(rd->ffcodecdata.type); + const char **fe = exts; if (!string || !exts) return; @@ -903,7 +903,7 @@ void BKE_ffmpeg_filepath_get(char* string, RenderData* rd) while (*fe) { if (BLI_strcasecmp(string + strlen(string) - strlen(*fe), - *fe) == 0) { + *fe) == 0) { break; } fe++; @@ -931,7 +931,7 @@ int BKE_ffmpeg_start(struct Scene *scene, RenderData *rd, int rectx, int recty, success = start_ffmpeg_impl(rd, rectx, recty, reports); #ifdef WITH_AUDASPACE if (audio_stream) { - AVCodecContext* c = audio_stream->codec; + AVCodecContext *c = audio_stream->codec; AUD_DeviceSpecs specs; specs.channels = c->channels; specs.format = AUD_FORMAT_S16; @@ -955,7 +955,7 @@ static void write_audio_frames(double to_pts) while (audio_stream && !finished) { if ((audio_time >= to_pts) || - (write_audio_frame())) { + (write_audio_frame())) { finished = 1; } } @@ -964,19 +964,19 @@ static void write_audio_frames(double to_pts) int BKE_ffmpeg_append(RenderData *rd, int start_frame, int frame, int *pixels, int rectx, int recty, ReportList *reports) { - AVFrame* avframe; + AVFrame *avframe; int success = 1; fprintf(stderr, "Writing frame %i, " - "render width=%d, render height=%d\n", frame, - rectx, recty); + "render width=%d, render height=%d\n", frame, + rectx, recty); // why is this done before writing the video frame and again at end_ffmpeg? // write_audio_frames(frame / (((double)rd->frs_sec) / rd->frs_sec_base)); if (video_stream) { - avframe= generate_video_frame((unsigned char*) pixels, reports); - success= (avframe && write_video_frame(rd, frame - start_frame, avframe, reports)); + avframe = generate_video_frame((unsigned char *) pixels, reports); + success = (avframe && write_video_frame(rd, frame - start_frame, avframe, reports)); if (ffmpeg_autosplit) { if (avio_tell(outfile->pb) > FFMPEG_AUTOSPLIT_SIZE) { @@ -1000,8 +1000,8 @@ void BKE_ffmpeg_end(void) fprintf(stderr, "Closing ffmpeg...\n"); /* if (audio_stream) { SEE UPPER - write_audio_frames(); - }*/ + write_audio_frames(); + }*/ #ifdef WITH_AUDASPACE if (audio_mixdown_device) { @@ -1012,7 +1012,7 @@ void BKE_ffmpeg_end(void) if (video_stream && video_stream->codec) { fprintf(stderr, "Flushing delayed frames...\n"); - flush_ffmpeg (); + flush_ffmpeg(); } if (outfile) { @@ -1074,7 +1074,7 @@ void BKE_ffmpeg_end(void) void BKE_ffmpeg_property_del(RenderData *rd, void *type, void *prop_) { struct IDProperty *prop = (struct IDProperty *) prop_; - IDProperty * group; + IDProperty *group; if (!rd->ffcodecdata.properties) { return; @@ -1091,10 +1091,10 @@ void BKE_ffmpeg_property_del(RenderData *rd, void *type, void *prop_) IDProperty *BKE_ffmpeg_property_add(RenderData *rd, const char *type, int opt_index, int parent_index) { AVCodecContext c; - const AVOption * o; - const AVOption * parent; - IDProperty * group; - IDProperty * prop; + const AVOption *o; + const AVOption *parent; + IDProperty *group; + IDProperty *prop; IDPropertyTemplate val; int idp_type; char name[256]; @@ -1125,7 +1125,7 @@ IDProperty *BKE_ffmpeg_property_add(RenderData *rd, const char *type, int opt_in } fprintf(stderr, "ffmpeg_property_add: %s %d %d %s\n", - type, parent_index, opt_index, name); + type, parent_index, opt_index, name); prop = IDP_GetPropertyFromGroup(group, name); if (prop) { @@ -1133,28 +1133,28 @@ IDProperty *BKE_ffmpeg_property_add(RenderData *rd, const char *type, int opt_in } switch (o->type) { - case FF_OPT_TYPE_INT: - case FF_OPT_TYPE_INT64: - val.i = FFMPEG_DEF_OPT_VAL_INT(o); - idp_type = IDP_INT; - break; - case FF_OPT_TYPE_DOUBLE: - case FF_OPT_TYPE_FLOAT: - val.f = FFMPEG_DEF_OPT_VAL_DOUBLE(o); - idp_type = IDP_FLOAT; - break; - case FF_OPT_TYPE_STRING: - val.string.str = (char *)" "; - val.string.len = 80; + case FF_OPT_TYPE_INT: + case FF_OPT_TYPE_INT64: + val.i = FFMPEG_DEF_OPT_VAL_INT(o); + idp_type = IDP_INT; + break; + case FF_OPT_TYPE_DOUBLE: + case FF_OPT_TYPE_FLOAT: + val.f = FFMPEG_DEF_OPT_VAL_DOUBLE(o); + idp_type = IDP_FLOAT; + break; + case FF_OPT_TYPE_STRING: + val.string.str = (char *)" "; + val.string.len = 80; /* val.str = (char *)" ";*/ - idp_type = IDP_STRING; - break; - case FF_OPT_TYPE_CONST: - val.i = 1; - idp_type = IDP_INT; - break; - default: - return NULL; + idp_type = IDP_STRING; + break; + case FF_OPT_TYPE_CONST: + val.i = 1; + idp_type = IDP_INT; + break; + default: + return NULL; } prop = IDP_New(idp_type, &val, name); IDP_AddToGroup(group, prop); @@ -1166,10 +1166,10 @@ IDProperty *BKE_ffmpeg_property_add(RenderData *rd, const char *type, int opt_in static const AVOption *my_av_find_opt(void *v, const char *name, const char *unit, int mask, int flags) { - AVClass *c= *(AVClass**)v; - const AVOption *o= c->option; + AVClass *c = *(AVClass **)v; + const AVOption *o = c->option; - for (;o && o->name; o++) { + for (; o && o->name; o++) { if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags) @@ -1180,15 +1180,15 @@ static const AVOption *my_av_find_opt(void *v, const char *name, return NULL; } -int BKE_ffmpeg_property_add_string(RenderData *rd, const char * type, const char * str) +int BKE_ffmpeg_property_add_string(RenderData *rd, const char *type, const char *str) { AVCodecContext c; - const AVOption * o = 0; - const AVOption * p = 0; + const AVOption *o = 0; + const AVOption *p = 0; char name_[128]; - char * name; - char * param; - IDProperty * prop; + char *name; + char *param; + IDProperty *prop; avcodec_get_context_defaults(&c); @@ -1217,12 +1217,12 @@ int BKE_ffmpeg_property_add_string(RenderData *rd, const char * type, const char if (param && o->type != FF_OPT_TYPE_CONST && o->unit) { p = my_av_find_opt(&c, param, o->unit, 0, 0); prop = BKE_ffmpeg_property_add(rd, - (char*) type, p - c.av_class->option, - o - c.av_class->option); + (char *) type, p - c.av_class->option, + o - c.av_class->option); } else { prop = BKE_ffmpeg_property_add(rd, - (char*) type, o - c.av_class->option, 0); + (char *) type, o - c.av_class->option, 0); } @@ -1232,15 +1232,15 @@ int BKE_ffmpeg_property_add_string(RenderData *rd, const char * type, const char if (param && !p) { switch (prop->type) { - case IDP_INT: - IDP_Int(prop) = atoi(param); - break; - case IDP_FLOAT: - IDP_Float(prop) = atof(param); - break; - case IDP_STRING: - strncpy(IDP_String(prop), param, prop->len); - break; + case IDP_INT: + IDP_Int(prop) = atoi(param); + break; + case IDP_FLOAT: + IDP_Float(prop) = atof(param); + break; + case IDP_STRING: + strncpy(IDP_String(prop), param, prop->len); + break; } } return 1; @@ -1296,7 +1296,7 @@ static void ffmpeg_set_expert_options(RenderData *rd) if (rd->ffcodecdata.flags & FFMPEG_LOSSLESS_OUTPUT) BKE_ffmpeg_property_add_string(rd, "video", "cqp:0"); } -#if 0 /* disabled for after release */ +#if 0 /* disabled for after release */ else if (codec_id == CODEC_ID_DNXHD) { if (rd->ffcodecdata.flags & FFMPEG_LOSSLESS_OUTPUT) ffmpeg_property_add_string(rd, "video", "mbd:rd"); @@ -1312,86 +1312,86 @@ void BKE_ffmpeg_preset_set(RenderData *rd, int preset) IDP_FreeProperty(rd->ffcodecdata.properties); switch (preset) { - case FFMPEG_PRESET_VCD: - rd->ffcodecdata.type = FFMPEG_MPEG1; - rd->ffcodecdata.video_bitrate = 1150; - rd->xsch = 352; - rd->ysch = isntsc ? 240 : 288; - rd->ffcodecdata.gop_size = isntsc ? 18 : 15; - rd->ffcodecdata.rc_max_rate = 1150; - rd->ffcodecdata.rc_min_rate = 1150; - rd->ffcodecdata.rc_buffer_size = 40*8; - rd->ffcodecdata.mux_packet_size = 2324; - rd->ffcodecdata.mux_rate = 2352 * 75 * 8; - break; - - case FFMPEG_PRESET_SVCD: - rd->ffcodecdata.type = FFMPEG_MPEG2; - rd->ffcodecdata.video_bitrate = 2040; - rd->xsch = 480; - rd->ysch = isntsc ? 480 : 576; - rd->ffcodecdata.gop_size = isntsc ? 18 : 15; - rd->ffcodecdata.rc_max_rate = 2516; - rd->ffcodecdata.rc_min_rate = 0; - rd->ffcodecdata.rc_buffer_size = 224*8; - rd->ffcodecdata.mux_packet_size = 2324; - rd->ffcodecdata.mux_rate = 0; - break; - - case FFMPEG_PRESET_DVD: - rd->ffcodecdata.type = FFMPEG_MPEG2; - rd->ffcodecdata.video_bitrate = 6000; - - /* Don't set resolution, see [#21351] - * rd->xsch = 720; - * rd->ysch = isntsc ? 480 : 576; */ - - rd->ffcodecdata.gop_size = isntsc ? 18 : 15; - rd->ffcodecdata.rc_max_rate = 9000; - rd->ffcodecdata.rc_min_rate = 0; - rd->ffcodecdata.rc_buffer_size = 224*8; - rd->ffcodecdata.mux_packet_size = 2048; - rd->ffcodecdata.mux_rate = 10080000; - break; - - case FFMPEG_PRESET_DV: - rd->ffcodecdata.type = FFMPEG_DV; - rd->xsch = 720; - rd->ysch = isntsc ? 480 : 576; - break; - - case FFMPEG_PRESET_H264: - rd->ffcodecdata.type = FFMPEG_AVI; - rd->ffcodecdata.codec = CODEC_ID_H264; - rd->ffcodecdata.video_bitrate = 6000; - rd->ffcodecdata.gop_size = isntsc ? 18 : 15; - rd->ffcodecdata.rc_max_rate = 9000; - rd->ffcodecdata.rc_min_rate = 0; - rd->ffcodecdata.rc_buffer_size = 224*8; - rd->ffcodecdata.mux_packet_size = 2048; - rd->ffcodecdata.mux_rate = 10080000; - - break; - - case FFMPEG_PRESET_THEORA: - case FFMPEG_PRESET_XVID: - if (preset == FFMPEG_PRESET_XVID) { + case FFMPEG_PRESET_VCD: + rd->ffcodecdata.type = FFMPEG_MPEG1; + rd->ffcodecdata.video_bitrate = 1150; + rd->xsch = 352; + rd->ysch = isntsc ? 240 : 288; + rd->ffcodecdata.gop_size = isntsc ? 18 : 15; + rd->ffcodecdata.rc_max_rate = 1150; + rd->ffcodecdata.rc_min_rate = 1150; + rd->ffcodecdata.rc_buffer_size = 40 * 8; + rd->ffcodecdata.mux_packet_size = 2324; + rd->ffcodecdata.mux_rate = 2352 * 75 * 8; + break; + + case FFMPEG_PRESET_SVCD: + rd->ffcodecdata.type = FFMPEG_MPEG2; + rd->ffcodecdata.video_bitrate = 2040; + rd->xsch = 480; + rd->ysch = isntsc ? 480 : 576; + rd->ffcodecdata.gop_size = isntsc ? 18 : 15; + rd->ffcodecdata.rc_max_rate = 2516; + rd->ffcodecdata.rc_min_rate = 0; + rd->ffcodecdata.rc_buffer_size = 224 * 8; + rd->ffcodecdata.mux_packet_size = 2324; + rd->ffcodecdata.mux_rate = 0; + break; + + case FFMPEG_PRESET_DVD: + rd->ffcodecdata.type = FFMPEG_MPEG2; + rd->ffcodecdata.video_bitrate = 6000; + + /* Don't set resolution, see [#21351] + * rd->xsch = 720; + * rd->ysch = isntsc ? 480 : 576; */ + + rd->ffcodecdata.gop_size = isntsc ? 18 : 15; + rd->ffcodecdata.rc_max_rate = 9000; + rd->ffcodecdata.rc_min_rate = 0; + rd->ffcodecdata.rc_buffer_size = 224 * 8; + rd->ffcodecdata.mux_packet_size = 2048; + rd->ffcodecdata.mux_rate = 10080000; + break; + + case FFMPEG_PRESET_DV: + rd->ffcodecdata.type = FFMPEG_DV; + rd->xsch = 720; + rd->ysch = isntsc ? 480 : 576; + break; + + case FFMPEG_PRESET_H264: rd->ffcodecdata.type = FFMPEG_AVI; - rd->ffcodecdata.codec = CODEC_ID_MPEG4; - } - else if (preset == FFMPEG_PRESET_THEORA) { - rd->ffcodecdata.type = FFMPEG_OGG; // XXX broken - rd->ffcodecdata.codec = CODEC_ID_THEORA; - } + rd->ffcodecdata.codec = CODEC_ID_H264; + rd->ffcodecdata.video_bitrate = 6000; + rd->ffcodecdata.gop_size = isntsc ? 18 : 15; + rd->ffcodecdata.rc_max_rate = 9000; + rd->ffcodecdata.rc_min_rate = 0; + rd->ffcodecdata.rc_buffer_size = 224 * 8; + rd->ffcodecdata.mux_packet_size = 2048; + rd->ffcodecdata.mux_rate = 10080000; + + break; - rd->ffcodecdata.video_bitrate = 6000; - rd->ffcodecdata.gop_size = isntsc ? 18 : 15; - rd->ffcodecdata.rc_max_rate = 9000; - rd->ffcodecdata.rc_min_rate = 0; - rd->ffcodecdata.rc_buffer_size = 224*8; - rd->ffcodecdata.mux_packet_size = 2048; - rd->ffcodecdata.mux_rate = 10080000; - break; + case FFMPEG_PRESET_THEORA: + case FFMPEG_PRESET_XVID: + if (preset == FFMPEG_PRESET_XVID) { + rd->ffcodecdata.type = FFMPEG_AVI; + rd->ffcodecdata.codec = CODEC_ID_MPEG4; + } + else if (preset == FFMPEG_PRESET_THEORA) { + rd->ffcodecdata.type = FFMPEG_OGG; // XXX broken + rd->ffcodecdata.codec = CODEC_ID_THEORA; + } + + rd->ffcodecdata.video_bitrate = 6000; + rd->ffcodecdata.gop_size = isntsc ? 18 : 15; + rd->ffcodecdata.rc_max_rate = 9000; + rd->ffcodecdata.rc_min_rate = 0; + rd->ffcodecdata.rc_buffer_size = 224 * 8; + rd->ffcodecdata.mux_packet_size = 2048; + rd->ffcodecdata.mux_rate = 10080000; + break; } @@ -1400,13 +1400,13 @@ void BKE_ffmpeg_preset_set(RenderData *rd, int preset) void BKE_ffmpeg_image_type_verify(RenderData *rd, ImageFormatData *imf) { - int audio= 0; + int audio = 0; if (imf->imtype == R_IMF_IMTYPE_FFMPEG) { if (rd->ffcodecdata.type <= 0 || - rd->ffcodecdata.codec <= 0 || - rd->ffcodecdata.audio_codec <= 0 || - rd->ffcodecdata.video_bitrate <= 1) { + rd->ffcodecdata.codec <= 0 || + rd->ffcodecdata.audio_codec <= 0 || + rd->ffcodecdata.video_bitrate <= 1) { rd->ffcodecdata.codec = CODEC_ID_MPEG2VIDEO; @@ -1416,24 +1416,24 @@ void BKE_ffmpeg_image_type_verify(RenderData *rd, ImageFormatData *imf) rd->ffcodecdata.type = FFMPEG_MPEG2; } - audio= 1; + audio = 1; } else if (imf->imtype == R_IMF_IMTYPE_H264) { if (rd->ffcodecdata.codec != CODEC_ID_H264) { BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_H264); - audio= 1; + audio = 1; } } else if (imf->imtype == R_IMF_IMTYPE_XVID) { if (rd->ffcodecdata.codec != CODEC_ID_MPEG4) { BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_XVID); - audio= 1; + audio = 1; } } else if (imf->imtype == R_IMF_IMTYPE_THEORA) { if (rd->ffcodecdata.codec != CODEC_ID_THEORA) { BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_THEORA); - audio= 1; + audio = 1; } } |