From 53ee7908d6c5a8bbdbec5202196d6dae86972e4c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 12 May 2012 16:11:34 +0000 Subject: style cleanup: whitespace --- source/blender/blenkernel/intern/CCGSubSurf.c | 67 +- source/blender/blenkernel/intern/anim_sys.c | 578 +++--- source/blender/blenkernel/intern/customdata.c | 445 ++-- source/blender/blenkernel/intern/customdata_file.c | 162 +- source/blender/blenkernel/intern/dynamicpaint.c | 2123 ++++++++++---------- source/blender/blenkernel/intern/idcode.c | 94 +- source/blender/blenkernel/intern/nla.c | 348 ++-- source/blender/blenkernel/intern/report.c | 76 +- source/blender/blenkernel/intern/sketch.c | 18 +- source/blender/blenkernel/intern/suggestions.c | 26 +- source/blender/blenkernel/intern/writeavi.c | 88 +- source/blender/blenkernel/intern/writeffmpeg.c | 716 +++---- source/blender/quicktime/apple/quicktime_export.c | 339 ++-- source/blender/quicktime/apple/quicktime_import.c | 278 +-- 14 files changed, 2680 insertions(+), 2678 deletions(-) diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c index 42c9fa84a91..7676a645e7f 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; } @@ -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); @@ -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); } } diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index de70ffcaaef..b66a90ab911 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: @@ -94,7 +94,7 @@ short id_type_can_have_animdata(ID *id) return 1; } - /* no AnimData */ + /* no AnimData */ default: return 0; } @@ -105,14 +105,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 @@ -123,24 +123,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; @@ -174,7 +174,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) { @@ -182,14 +182,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; } } @@ -211,8 +211,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) { @@ -234,7 +234,7 @@ void BKE_free_animdata(ID *id) /* free animdata now */ MEM_freeN(adt); - iat->adt= NULL; + iat->adt = NULL; } } } @@ -242,19 +242,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); @@ -268,7 +268,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; @@ -286,7 +286,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; @@ -294,15 +294,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); } } } @@ -313,7 +313,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); @@ -336,7 +336,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); } @@ -355,17 +355,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 @@ -381,7 +381,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); @@ -395,13 +395,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; } @@ -450,7 +450,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; @@ -475,7 +475,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 */ @@ -499,15 +499,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... */ @@ -519,7 +519,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) { @@ -547,10 +547,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); @@ -562,30 +562,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 */ @@ -598,7 +598,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 */ @@ -620,15 +620,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); } } @@ -639,29 +639,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)); } @@ -674,12 +674,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); @@ -692,7 +692,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 <["><"]> - * 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) @@ -706,12 +706,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 */ @@ -724,7 +724,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 */ @@ -741,18 +741,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); \ @@ -812,12 +812,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 <["><"]> - * 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 @@ -825,21 +825,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 */ @@ -901,7 +901,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; @@ -912,20 +912,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) { @@ -944,19 +944,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); @@ -974,7 +974,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; @@ -998,27 +998,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); @@ -1050,11 +1050,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); } } @@ -1070,8 +1070,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); } } @@ -1086,10 +1086,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); } @@ -1106,25 +1106,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; @@ -1135,13 +1135,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) : "", - path, array_index, array_len-1); + (ptr && ptr->id.data) ? (((ID *)ptr->id.data)->name + 2) : "", + path, array_index, array_len - 1); } return 0; @@ -1198,7 +1198,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)); } @@ -1213,26 +1213,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) : "", - path, array_index); + (ptr && ptr->id.data) ? (((ID *)ptr->id.data)->name + 2) : "", + 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) @@ -1245,16 +1245,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); } @@ -1266,25 +1266,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; @@ -1304,7 +1304,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; @@ -1317,7 +1317,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; @@ -1326,7 +1326,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); } } } @@ -1340,7 +1340,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); @@ -1349,9 +1349,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); } @@ -1363,7 +1363,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); @@ -1375,18 +1375,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); } @@ -1397,13 +1397,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) { @@ -1422,23 +1422,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; } @@ -1447,22 +1447,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; } @@ -1472,9 +1472,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; } @@ -1491,15 +1491,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... @@ -1528,12 +1528,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); @@ -1546,7 +1546,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; @@ -1555,7 +1555,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 @@ -1570,10 +1570,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; @@ -1584,50 +1584,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; } @@ -1664,13 +1664,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; @@ -1679,12 +1679,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 @@ -1705,39 +1705,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; @@ -1748,21 +1748,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; @@ -1781,16 +1781,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; @@ -1798,7 +1798,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) @@ -1809,7 +1809,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); } @@ -1819,7 +1819,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}; @@ -1837,12 +1837,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' @@ -1852,18 +1852,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); @@ -1875,11 +1875,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; @@ -1895,8 +1895,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; @@ -1918,7 +1918,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 @@ -1958,11 +1958,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)) { @@ -2000,23 +2000,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) 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) @@ -2026,11 +2026,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 @@ -2038,14 +2038,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 */ @@ -2054,17 +2054,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 */ @@ -2084,7 +2084,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 */ @@ -2095,9 +2095,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... @@ -2119,7 +2119,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; @@ -2129,12 +2129,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); } @@ -2169,7 +2169,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 @@ -2238,7 +2238,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 @@ -2261,25 +2261,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); \ @@ -2344,10 +2344,10 @@ void BKE_animsys_evaluate_all_animation(Main *main, Scene *scene, float ctime) EVAL_ANIM_IDS(main->movieclip.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/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; itypemap[i] = -1; } - for (i=0; itotlayer; 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; itotlayer; 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; itotlayer; 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; itotlayer; 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; itotlayer; 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; itotlayer; 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; itotlayer; 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; itotlayer; 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; itotlayer; 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; itotlayer; 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; atotlayer; 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; atotlayer; 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; atotlayer; 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; areadf) { 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; atotlayer; 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/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 2bde31cfd63..4d6d6a990f9 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,11 @@ int dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface) } /* get currently active surface (in user interface) */ -struct DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas) -{ +struct 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 +275,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 +291,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 +324,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 +351,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 +372,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,7 +418,7 @@ 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; @@ -428,12 +428,12 @@ static void blendColors(float t_color[3], float t_alpha, float s_color[3], float { 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 +451,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 +477,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 +505,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 +528,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 +538,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 +575,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 +615,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 +625,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 +662,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 +699,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 +711,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) /* calculate canvas dimensions */ #pragma omp parallel for schedule(static) - for (i=0; itotal_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 +721,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) } /* get final dimensions */ - for (i=0; igrid_bounds, grid_bounds[i].min); boundInsert(&grid->grid_bounds, grid_bounds[i].max); } @@ -732,8 +732,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]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 +771,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; itotal_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; is_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; is_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; itotal_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 +812,17 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) { int x; #pragma omp parallel for schedule(static) - for (x=0; xdim[0]; x++) { + for (x = 0; x < grid->dim[0]; x++) { int y; - for (y=0; ydim[1]; y++) { + for (y = 0; y < grid->dim[1]; y++) { int z; - for (z=0; zdim[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 +857,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 +919,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 +989,12 @@ 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) -{ - DynamicPaintSurface *surface= MEM_callocN(sizeof(DynamicPaintSurface), "DynamicPaintSurface"); + * 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){ + DynamicPaintSurface *surface = MEM_callocN(sizeof(DynamicPaintSurface), "DynamicPaintSurface"); if (!surface) return NULL; surface->canvas = canvas; @@ -1009,7 +1008,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 +1063,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 +1211,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 +1260,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 +1297,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for struct MLoop *mloop = dm->getLoopArray(dm); /* count number of edges per vertex */ - for (i=0; in_num[edge[i].v1]++; ad->n_num[edge[i].v2]++; @@ -1307,17 +1306,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 vertex is on mesh edge */ - for (i=0; itotal_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 +1329,29 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for /* order n_index array */ n_pos = 0; - for (i=0; itotal_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; in_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 +1360,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 +1373,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; itotal_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 +1394,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; iformat == 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; itotal_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 +1461,37 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) if (!col) return; #pragma omp parallel for schedule(static) - for (i=0; iformat == 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; itotal_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 +1576,27 @@ 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; itotal_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 -*/ + * Apply canvas data to the object derived mesh + */ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object *ob, - DerivedMesh *dm) -{ + DerivedMesh *dm){ DerivedMesh *result = CDDM_copy(dm); if (pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) { @@ -1607,7 +1605,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 +1618,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; itotal_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 +1647,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 +1655,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData if (col) { #pragma omp parallel for schedule(static) - for (i=0; itype == 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 +1752,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; itotal_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 +1764,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 +1777,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; itotal_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 +1825,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 +1840,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 +1901,9 @@ 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) -{ +struct 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 +1917,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 +1939,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 +1986,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 +2004,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; iface_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 +2057,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 +2071,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 +2101,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 +2116,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 +2162,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 +2172,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 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 +2235,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 (point[sample][0])) continue; @@ -2267,55 +2264,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 +2324,23 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* Add b-weights per anti-aliasing sample */ - for (j=0; jface_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 +2349,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 +2369,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 +2402,39 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* Add b-weights per anti-aliasing sample */ - for (j=0; jneighbour_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 +2444,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; itotal_points = w*h; + sData->total_points = w * h; dynamicPaint_initAdjacencyData(surface, 1); if (sData->adj_data) { @@ -2467,16 +2464,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 +2495,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 +2517,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); @@ -2548,17 +2545,17 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) #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 +2566,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 +2592,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 +2677,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 +2685,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; iob_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 +2718,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; itot; i++) { + for (i = 0; i < bMats->tot; i++) { RE_free_sample_material(bMats->ob_mats[i]); } MEM_freeN(bMats->ob_mats); @@ -2732,8 +2729,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 +2742,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 +2755,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 +2791,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 +2833,18 @@ 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 -*/ + * 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) { - 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 +2865,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->wetnesswetness = MIN_WETNESS; + if (pPoint->wetness < MIN_WETNESS) pPoint->wetness = MIN_WETNESS; pPoint->state = DPAINT_PAINT_NEW; } @@ -2884,9 +2879,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 +2932,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 +3076,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; iobmat, 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 +3134,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 +3173,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; iiobmat, mvert[ii].co); boundInsert(&mesh_bb, mvert[ii].co); @@ -3196,7 +3191,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 +3200,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_indexgrid_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; ssflags & 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 +3530,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 +3548,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 +3559,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; ptotpart; 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 +3600,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 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 +3663,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; nparticles + nearest[n].index; float s_range; @@ -3712,14 +3709,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 +3743,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 +3755,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 +3786,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 +3798,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 +3823,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 +3840,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 +3864,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 +3882,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 +3896,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 +3904,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int int i; int numOfNeighs = adj_data->n_num[index]; - for (i=0; in_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 +3913,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 +3923,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int int i; int numOfNeighs = adj_data->n_num[index]; - for (i=0; iaverage_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 +3937,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; iadj_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; iadj_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_dot0.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 +3975,28 @@ 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; + closest_d[0] *= acosf(temp) / 1.57079633f; + closest_d[1] *= acosf(temp) / 1.57079633f; } 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]) / 1.57079633f; } } @@ -4011,20 +4012,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; steptotal_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 +4034,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 +4052,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 +4065,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 +4085,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 +4103,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 +4138,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 +4147,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 +4162,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 +4172,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; iadj_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].distwetness, 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->wetnesswetness || ePoint->wetnesswetness < 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 +4214,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; iadj_data->n_index[index]+i; - float speed_scale = (bNeighs[n_index].distadj_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 +4239,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 +4262,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 +4280,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 +4331,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 +4343,30 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) int i; int numOfNeighs = sData->adj_data->n_num[index]; - for (i=0; iadj_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; sstype_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 +4375,13 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) if (wPoint->state > 0) continue; /* calculate force from surrounding points */ - for (i=0; iadj_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 (diststate > 0) continue; + if (dist < min_dist) dist = min_dist; avg_dist += dist; numOfN++; @@ -4390,28 +4391,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 +4420,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 +4438,10 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time int index; #pragma omp parallel for schedule(static) - for (index=0; indextotal_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 +4449,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 +4467,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 +4502,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 +4527,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; iprev_verts[i].co[j] != mvert[i].co[j]) { ret = 1; break; @@ -4585,18 +4586,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 +4609,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 +4630,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; indexobmat, canvas_verts[index].v); boundInsert(&bData->mesh_bounds, canvas_verts[index].v); @@ -4652,7 +4653,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; indextotal_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 +4663,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; sss_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 +4685,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 +4693,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 +4702,14 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } /* calculate position for each sample */ - for (ss=0; sss_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 +4723,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 +4731,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 +4760,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 +4802,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 +4810,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 +4818,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 +4831,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 +4851,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 +4904,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 +4940,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/idcode.c b/source/blender/blenkernel/intern/idcode.c index cd246681f3c..ca10f39246c 100644 --- a/source/blender/blenkernel/intern/idcode.c +++ b/source/blender/blenkernel/intern/idcode.c @@ -43,61 +43,61 @@ 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_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_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; @@ -105,34 +105,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/nla.c b/source/blender/blenkernel/intern/nla.c index 96c62a32139..02d44badc65 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):(""), sizeof(strip->name)); + BLI_strncpy(strip->name, (strip->act) ? (strip->act->id.name + 2) : (""), 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_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "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/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/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/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; iprev; 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/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; } } diff --git a/source/blender/quicktime/apple/quicktime_export.c b/source/blender/quicktime/apple/quicktime_export.c index e25fc0f04bd..a071c0be611 100644 --- a/source/blender/quicktime/apple/quicktime_export.c +++ b/source/blender/quicktime/apple/quicktime_export.c @@ -79,52 +79,52 @@ #include /* file permissions */ #endif /* __APPLE__ */ -#define kMyCreatorType FOUR_CHAR_CODE('TVOD') -#define kTrackStart 0 -#define kMediaStart 0 - -static void QT_StartAddVideoSamplesToMedia (const Rect *trackFrame, int rectx, int recty, struct ReportList *reports); -static void QT_DoAddVideoSamplesToMedia (int frame, int *pixels, int rectx, int recty, struct ReportList *reports); -static void QT_EndAddVideoSamplesToMedia (void); -static void QT_CreateMyVideoTrack (int rectx, int recty, struct ReportList *reports); -static void QT_EndCreateMyVideoTrack (struct ReportList *reports); +#define kMyCreatorType FOUR_CHAR_CODE('TVOD') +#define kTrackStart 0 +#define kMediaStart 0 + +static void QT_StartAddVideoSamplesToMedia(const Rect *trackFrame, int rectx, int recty, struct ReportList *reports); +static void QT_DoAddVideoSamplesToMedia(int frame, int *pixels, int rectx, int recty, struct ReportList *reports); +static void QT_EndAddVideoSamplesToMedia(void); +static void QT_CreateMyVideoTrack(int rectx, int recty, struct ReportList *reports); +static void QT_EndCreateMyVideoTrack(struct ReportList *reports); static void check_renderbutton_framerate(struct RenderData *rd, struct ReportList *reports); static int get_qtcodec_settings(struct RenderData *rd, struct ReportList *reports); typedef struct QuicktimeExport { - FSSpec theSpec; - short resRefNum; - Str255 qtfilename; + FSSpec theSpec; + short resRefNum; + Str255 qtfilename; - Media theMedia; - Movie theMovie; - Track theTrack; + Media theMedia; + Movie theMovie; + Track theTrack; - GWorldPtr theGWorld; - PixMapHandle thePixMap; - ImageDescription **anImageDescription; + GWorldPtr theGWorld; + PixMapHandle thePixMap; + ImageDescription **anImageDescription; - ImBuf *ibuf; //imagedata for Quicktime's Gworld - ImBuf *ibuf2; //copy of renderdata, to be Y-flipped + ImBuf *ibuf; //imagedata for Quicktime's Gworld + ImBuf *ibuf2; //copy of renderdata, to be Y-flipped } QuicktimeExport; typedef struct QuicktimeComponentData { - ComponentInstance theComponent; + ComponentInstance theComponent; SCTemporalSettings gTemporalSettings; SCSpatialSettings gSpatialSettings; SCDataRateSettings aDataRateSetting; - TimeValue duration; - long kVideoTimeScale; + TimeValue duration; + long kVideoTimeScale; } QuicktimeComponentData; static struct QuicktimeExport *qtexport; static struct QuicktimeComponentData *qtdata; -static int sframe; +static int sframe; /* RNA functions */ @@ -141,7 +141,8 @@ static QuicktimeCodecTypeDesc qtVideoCodecList[] = { {kMPEG4VisualCodecType, 10, "MPEG4"}, {kH263CodecType, 11, "H.263"}, {kH264CodecType, 12, "H.264"}, - {0, 0, NULL}}; + {0, 0, NULL} +}; static int qtVideoCodecCount = 12; @@ -150,9 +151,9 @@ int quicktime_get_num_videocodecs() return qtVideoCodecCount; } -QuicktimeCodecTypeDesc* quicktime_get_videocodecType_desc(int indexValue) +QuicktimeCodecTypeDesc *quicktime_get_videocodecType_desc(int indexValue) { - if ((indexValue>=0) && (indexValue < qtVideoCodecCount)) + if ((indexValue >= 0) && (indexValue < qtVideoCodecCount)) return &qtVideoCodecList[indexValue]; else return NULL; @@ -161,7 +162,7 @@ QuicktimeCodecTypeDesc* quicktime_get_videocodecType_desc(int indexValue) int quicktime_rnatmpvalue_from_videocodectype(int codecType) { int i; - for (i=0;iqtcodecdata; @@ -210,9 +211,9 @@ static OSErr QT_SaveCodecSettingsToScene(RenderData *rd, ReportList *reports) } // obtain all current codec settings - SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); - SCSetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); - SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); + SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + SCSetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); + SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); // retreive codecdata from quicktime in a atomcontainer myErr = SCGetSettingsAsAtomContainer(qtdata->theComponent, &myContainer); @@ -234,7 +235,7 @@ static OSErr QT_SaveCodecSettingsToScene(RenderData *rd, ReportList *reports) memcpy(qcd->cdParms, myPtr, mySize); qcd->cdSize = mySize; - GetCodecInfo (&ci, qtdata->gSpatialSettings.codecType, 0); + GetCodecInfo(&ci, qtdata->gSpatialSettings.codecType, 0); } else { BKE_reportf(reports, RPT_ERROR, "Quicktime: QT_SaveCodecSettingsToScene failed\n"); @@ -252,8 +253,8 @@ bail: static OSErr QT_GetCodecSettingsFromScene(RenderData *rd, ReportList *reports) { - Handle myHandle = NULL; - ComponentResult myErr = noErr; + Handle myHandle = NULL; + ComponentResult myErr = noErr; QuicktimeCodecData *qcd = rd->qtcodecdata; @@ -272,9 +273,9 @@ static OSErr QT_GetCodecSettingsFromScene(RenderData *rd, ReportList *reports) } // update runtime codecsettings for use with the codec dialog - SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); - SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); - SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); + SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); + SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); //Fill the render QuicktimeCodecSettigns struct @@ -304,12 +305,12 @@ bail: } -static OSErr QT_AddUserDataTextToMovie (Movie theMovie, char *theText, OSType theType) +static OSErr QT_AddUserDataTextToMovie(Movie theMovie, char *theText, OSType theType) { - UserData myUserData = NULL; - Handle myHandle = NULL; - long myLength = strlen(theText); - OSErr myErr = noErr; + UserData myUserData = NULL; + Handle myHandle = NULL; + long myLength = strlen(theText); + OSErr myErr = noErr; // get the movie's user data list myUserData = GetMovieUserData(theMovie); @@ -343,10 +344,10 @@ static void QT_CreateMyVideoTrack(int rectx, int recty, ReportList *reports) trackFrame.bottom = recty; trackFrame.right = rectx; - qtexport->theTrack = NewMovieTrack (qtexport->theMovie, - FixRatio(trackFrame.right, 1), - FixRatio(trackFrame.bottom, 1), - 0); + qtexport->theTrack = NewMovieTrack(qtexport->theMovie, + FixRatio(trackFrame.right, 1), + FixRatio(trackFrame.bottom, 1), + 0); CheckError(GetMoviesError(), "NewMovieTrack error", reports); // SetIdentityMatrix(&myMatrix); @@ -354,17 +355,17 @@ static void QT_CreateMyVideoTrack(int rectx, int recty, ReportList *reports) // TranslateMatrix(&myMatrix, 0, Long2Fix(trackFrame.bottom)); // SetMovieMatrix(qtexport->theMovie, &myMatrix); - qtexport->theMedia = NewTrackMedia (qtexport->theTrack, - VideoMediaType, - qtdata->kVideoTimeScale, - nil, - 0); + qtexport->theMedia = NewTrackMedia(qtexport->theTrack, + VideoMediaType, + qtdata->kVideoTimeScale, + nil, + 0); CheckError(GetMoviesError(), "NewTrackMedia error", reports); - err = BeginMediaEdits (qtexport->theMedia); + err = BeginMediaEdits(qtexport->theMedia); CheckError(err, "BeginMediaEdits error", reports); - QT_StartAddVideoSamplesToMedia (&trackFrame, rectx, recty, reports); + QT_StartAddVideoSamplesToMedia(&trackFrame, rectx, recty, reports); } @@ -372,40 +373,40 @@ static void QT_EndCreateMyVideoTrack(ReportList *reports) { OSErr err = noErr; - QT_EndAddVideoSamplesToMedia (); + QT_EndAddVideoSamplesToMedia(); - err = EndMediaEdits (qtexport->theMedia); + err = EndMediaEdits(qtexport->theMedia); CheckError(err, "EndMediaEdits error", reports); - err = InsertMediaIntoTrack (qtexport->theTrack, - kTrackStart, /* track start time */ - kMediaStart, /* media start time */ - GetMediaDuration (qtexport->theMedia), - fixed1); + err = InsertMediaIntoTrack(qtexport->theTrack, + kTrackStart, /* track start time */ + kMediaStart, /* media start time */ + GetMediaDuration(qtexport->theMedia), + fixed1); CheckError(err, "InsertMediaIntoTrack error", reports); } -static void QT_StartAddVideoSamplesToMedia (const Rect *trackFrame, int rectx, int recty, ReportList *reports) +static void QT_StartAddVideoSamplesToMedia(const Rect *trackFrame, int rectx, int recty, ReportList *reports) { SCTemporalSettings gTemporalSettings; OSErr err = noErr; - qtexport->ibuf = IMB_allocImBuf (rectx, recty, 32, IB_rect); - qtexport->ibuf2 = IMB_allocImBuf (rectx, recty, 32, IB_rect); + qtexport->ibuf = IMB_allocImBuf(rectx, recty, 32, IB_rect); + qtexport->ibuf2 = IMB_allocImBuf(rectx, recty, 32, IB_rect); - err = NewGWorldFromPtr( &qtexport->theGWorld, - k32ARGBPixelFormat, - trackFrame, - NULL, NULL, 0, - (Ptr)qtexport->ibuf->rect, - rectx * 4 ); - CheckError (err, "NewGWorldFromPtr error", reports); + err = NewGWorldFromPtr(&qtexport->theGWorld, + k32ARGBPixelFormat, + trackFrame, + NULL, NULL, 0, + (Ptr)qtexport->ibuf->rect, + rectx * 4); + CheckError(err, "NewGWorldFromPtr error", reports); qtexport->thePixMap = GetGWorldPixMap(qtexport->theGWorld); LockPixels(qtexport->thePixMap); - SCDefaultPixMapSettings (qtdata->theComponent, qtexport->thePixMap, true); + SCDefaultPixMapSettings(qtdata->theComponent, qtexport->thePixMap, true); // workaround for crash with H.264, which requires an upgrade to // the new callback based api for proper encoding, but that's not @@ -418,32 +419,32 @@ static void QT_StartAddVideoSamplesToMedia (const Rect *trackFrame, int rectx, i } } - SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &gTemporalSettings); - SCSetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); - SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); + SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &gTemporalSettings); + SCSetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); + SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); err = SCCompressSequenceBegin(qtdata->theComponent, qtexport->thePixMap, NULL, &qtexport->anImageDescription); - CheckError (err, "SCCompressSequenceBegin error", reports ); + CheckError(err, "SCCompressSequenceBegin error", reports); } -static void QT_DoAddVideoSamplesToMedia (int frame, int *pixels, int rectx, int recty, ReportList *reports) +static void QT_DoAddVideoSamplesToMedia(int frame, int *pixels, int rectx, int recty, ReportList *reports) { - OSErr err = noErr; - Rect imageRect; + OSErr err = noErr; + Rect imageRect; - int index; - int boxsize; + int index; + int boxsize; unsigned char *from, *to; - short syncFlag; - long dataSize; - Handle compressedData; - Ptr myPtr; + short syncFlag; + long dataSize; + Handle compressedData; + Ptr myPtr; //copy and flip renderdata - memcpy(qtexport->ibuf2->rect, pixels, 4*rectx*recty); + memcpy(qtexport->ibuf2->rect, pixels, 4 * rectx * recty); IMB_flipy(qtexport->ibuf2); //get pointers to parse bitmapdata @@ -455,42 +456,42 @@ static void QT_DoAddVideoSamplesToMedia (int frame, int *pixels, int rectx, int //parse RGBA bitmap into Quicktime's ARGB GWorld boxsize = rectx * recty; - for ( index = 0; index < boxsize; index++) { + for (index = 0; index < boxsize; index++) { to[0] = from[3]; to[1] = from[0]; to[2] = from[1]; to[3] = from[2]; - to +=4, from += 4; + to += 4, from += 4; } err = SCCompressSequenceFrame(qtdata->theComponent, - qtexport->thePixMap, - &imageRect, - &compressedData, - &dataSize, - &syncFlag); + qtexport->thePixMap, + &imageRect, + &compressedData, + &dataSize, + &syncFlag); CheckError(err, "SCCompressSequenceFrame error", reports); err = AddMediaSample(qtexport->theMedia, - compressedData, - 0, - dataSize, - qtdata->duration, - (SampleDescriptionHandle)qtexport->anImageDescription, - 1, - syncFlag, - NULL); + compressedData, + 0, + dataSize, + qtdata->duration, + (SampleDescriptionHandle)qtexport->anImageDescription, + 1, + syncFlag, + NULL); CheckError(err, "AddMediaSample error", reports); } -static void QT_EndAddVideoSamplesToMedia (void) +static void QT_EndAddVideoSamplesToMedia(void) { SCCompressSequenceEnd(qtdata->theComponent); UnlockPixels(qtexport->thePixMap); if (qtexport->theGWorld) - DisposeGWorld (qtexport->theGWorld); + DisposeGWorld(qtexport->theGWorld); if (qtexport->ibuf) IMB_freeImBuf(qtexport->ibuf); @@ -504,7 +505,7 @@ void filepath_qt(char *string, RenderData *rd) { char txt[64]; - if (string==0) return; + if (string == 0) return; strcpy(string, rd->pic); BLI_path_abs(string, G.main->name); @@ -526,12 +527,12 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R char theFullPath[255]; #ifdef __APPLE__ - int myFile; - FSRef myRef; + int myFile; + FSRef myRef; #else - char *qtname; + char *qtname; #endif - int success= 1; + int success = 1; if (qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport"); @@ -561,7 +562,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R sprintf(theFullPath, "%s", name); /* hack: create an empty file to make FSPathMakeRef() happy */ - myFile = open(theFullPath, O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRUSR|S_IWUSR); + myFile = open(theFullPath, O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRUSR | S_IWUSR); if (myFile < 0) { BKE_reportf(reports, RPT_ERROR, "error while creating movie file!\n"); /* do something? */ @@ -582,17 +583,17 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R err = FSMakeFSSpec(0, 0L, qtexport->qtfilename, &qtexport->theSpec); #endif - err = CreateMovieFile (&qtexport->theSpec, - kMyCreatorType, - smCurrentScript, - createMovieFileDeleteCurFile | createMovieFileDontCreateResFile, - &qtexport->resRefNum, - &qtexport->theMovie ); + err = CreateMovieFile(&qtexport->theSpec, + kMyCreatorType, + smCurrentScript, + createMovieFileDeleteCurFile | createMovieFileDontCreateResFile, + &qtexport->resRefNum, + &qtexport->theMovie); CheckError(err, "CreateMovieFile error", reports); if (err != noErr) { BKE_reportf(reports, RPT_ERROR, "Unable to create Quicktime movie: %s", name); - success= 0; + success = 0; #ifdef __APPLE__ ExitMoviesOnThread(); #endif @@ -622,7 +623,7 @@ void end_qt(void) if (qtexport->theMovie) { QT_EndCreateMyVideoTrack(NULL); - err = AddMovieResource (qtexport->theMovie, qtexport->resRefNum, &resId, qtexport->qtfilename); + err = AddMovieResource(qtexport->theMovie, qtexport->resRefNum, &resId, qtexport->qtfilename); CheckError(err, "AddMovieResource error", NULL); err = QT_AddUserDataTextToMovie(qtexport->theMovie, "Made with Blender", kUserDataTextInformation); @@ -639,7 +640,7 @@ void end_qt(void) } #ifdef __APPLE__ - ExitMoviesOnThread(); + ExitMoviesOnThread(); #endif if (qtexport) { @@ -662,36 +663,36 @@ void free_qtcomponentdata(void) static void check_renderbutton_framerate(RenderData *rd, ReportList *reports) { // to keep float framerates consistent between the codec dialog and frs/sec button. - OSErr err; + OSErr err; - err = SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + err = SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); CheckError(err, "SCGetInfo fr error", reports); if ( (rd->frs_sec == 24 || rd->frs_sec == 30 || rd->frs_sec == 60) && - (qtdata->gTemporalSettings.frameRate == 1571553 || - qtdata->gTemporalSettings.frameRate == 1964113 || - qtdata->gTemporalSettings.frameRate == 3928227)) + (qtdata->gTemporalSettings.frameRate == 1571553 || + qtdata->gTemporalSettings.frameRate == 1964113 || + qtdata->gTemporalSettings.frameRate == 3928227)) { /* do nothing */ } else { if (rd->frs_sec_base > 0) qtdata->gTemporalSettings.frameRate = - ((float)(rd->frs_sec << 16) / rd->frs_sec_base); + ((float)(rd->frs_sec << 16) / rd->frs_sec_base); } - err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); CheckError(err, "SCSetInfo error", reports); - if (qtdata->gTemporalSettings.frameRate == 1571553) { // 23.98 fps + if (qtdata->gTemporalSettings.frameRate == 1571553) { // 23.98 fps qtdata->kVideoTimeScale = 24000; qtdata->duration = 1001; } - else if (qtdata->gTemporalSettings.frameRate == 1964113) { // 29.97 fps + else if (qtdata->gTemporalSettings.frameRate == 1964113) { // 29.97 fps qtdata->kVideoTimeScale = 30000; qtdata->duration = 1001; } - else if (qtdata->gTemporalSettings.frameRate == 3928227) { // 59.94 fps + else if (qtdata->gTemporalSettings.frameRate == 3928227) { // 59.94 fps qtdata->kVideoTimeScale = 60000; qtdata->duration = 1001; } @@ -704,14 +705,14 @@ static void check_renderbutton_framerate(RenderData *rd, ReportList *reports) void quicktime_verify_image_type(RenderData *rd, ImageFormatData *imf) { if (imf->imtype == R_IMF_IMTYPE_QUICKTIME) { - if ((rd->qtcodecsettings.codecType== 0) || - (rd->qtcodecsettings.codecSpatialQuality <0) || - (rd->qtcodecsettings.codecSpatialQuality > 100)) { + if ((rd->qtcodecsettings.codecType == 0) || + (rd->qtcodecsettings.codecSpatialQuality < 0) || + (rd->qtcodecsettings.codecSpatialQuality > 100)) { rd->qtcodecsettings.codecType = kJPEGCodecType; rd->qtcodecsettings.codec = (int)anyCodec; - rd->qtcodecsettings.codecSpatialQuality = (codecHighQuality*100)/codecLosslessQuality; - rd->qtcodecsettings.codecTemporalQuality = (codecHighQuality*100)/codecLosslessQuality; + rd->qtcodecsettings.codecSpatialQuality = (codecHighQuality * 100) / codecLosslessQuality; + rd->qtcodecsettings.codecTemporalQuality = (codecHighQuality * 100) / codecLosslessQuality; rd->qtcodecsettings.keyFrameRate = 25; rd->qtcodecsettings.bitRate = 5000000; //5 Mbps } @@ -721,7 +722,7 @@ void quicktime_verify_image_type(RenderData *rd, ImageFormatData *imf) int get_qtcodec_settings(RenderData *rd, ReportList *reports) { OSErr err = noErr; - // erase any existing codecsetting + // erase any existing codecsetting if (qtdata) { if (qtdata->theComponent) CloseComponent(qtdata->theComponent); free_qtcomponentdata(); @@ -736,14 +737,14 @@ int get_qtcodec_settings(RenderData *rd, ReportList *reports) QT_GetCodecSettingsFromScene(rd, reports); } else { - SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); - SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); - SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); + SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); + SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); qtdata->gSpatialSettings.codecType = rd->qtcodecsettings.codecType; qtdata->gSpatialSettings.codec = (CodecComponent)rd->qtcodecsettings.codec; - qtdata->gSpatialSettings.spatialQuality = (rd->qtcodecsettings.codecSpatialQuality * codecLosslessQuality) /100; - qtdata->gTemporalSettings.temporalQuality = (rd->qtcodecsettings.codecTemporalQuality * codecLosslessQuality) /100; + qtdata->gSpatialSettings.spatialQuality = (rd->qtcodecsettings.codecSpatialQuality * codecLosslessQuality) / 100; + qtdata->gTemporalSettings.temporalQuality = (rd->qtcodecsettings.codecTemporalQuality * codecLosslessQuality) / 100; qtdata->gTemporalSettings.keyFrameRate = rd->qtcodecsettings.keyFrameRate; qtdata->aDataRateSetting.dataRate = rd->qtcodecsettings.bitRate; qtdata->gSpatialSettings.depth = rd->qtcodecsettings.colorDepth; @@ -751,14 +752,14 @@ int get_qtcodec_settings(RenderData *rd, ReportList *reports) qtdata->aDataRateSetting.minTemporalQuality = (rd->qtcodecsettings.minTemporalQuality * codecLosslessQuality) / 100; qtdata->aDataRateSetting.frameDuration = rd->frs_sec; - SetMovieTimeScale(qtexport->theMovie, rd->frs_sec_base*1000); + SetMovieTimeScale(qtexport->theMovie, rd->frs_sec_base * 1000); - err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); CheckError(err, "SCSetInfo1 error", reports); - err = SCSetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); + err = SCSetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); CheckError(err, "SCSetInfo2 error", reports); - err = SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); + err = SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); CheckError(err, "SCSetInfo3 error", reports); } @@ -769,7 +770,7 @@ int get_qtcodec_settings(RenderData *rd, ReportList *reports) static int request_qtcodec_settings(bContext *C, wmOperator *op) { - OSErr err = noErr; + OSErr err = noErr; Scene *scene = CTX_data_scene(C); RenderData *rd = &scene->r; @@ -788,14 +789,14 @@ static int request_qtcodec_settings(bContext *C, wmOperator *op) QT_GetCodecSettingsFromScene(rd, op->reports); } else { - SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); - SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); - SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); + SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); + SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); qtdata->gSpatialSettings.codecType = rd->qtcodecsettings.codecType; qtdata->gSpatialSettings.codec = (CodecComponent)rd->qtcodecsettings.codec; - qtdata->gSpatialSettings.spatialQuality = (rd->qtcodecsettings.codecSpatialQuality * codecLosslessQuality) /100; - qtdata->gTemporalSettings.temporalQuality = (rd->qtcodecsettings.codecTemporalQuality * codecLosslessQuality) /100; + qtdata->gSpatialSettings.spatialQuality = (rd->qtcodecsettings.codecSpatialQuality * codecLosslessQuality) / 100; + qtdata->gTemporalSettings.temporalQuality = (rd->qtcodecsettings.codecTemporalQuality * codecLosslessQuality) / 100; qtdata->gTemporalSettings.keyFrameRate = rd->qtcodecsettings.keyFrameRate; qtdata->gTemporalSettings.frameRate = ((float)(rd->frs_sec << 16) / rd->frs_sec_base); qtdata->aDataRateSetting.dataRate = rd->qtcodecsettings.bitRate; @@ -805,29 +806,29 @@ static int request_qtcodec_settings(bContext *C, wmOperator *op) qtdata->aDataRateSetting.frameDuration = rd->frs_sec; - err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); CheckError(err, "SCSetInfo1 error", op->reports); - err = SCSetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); + err = SCSetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); CheckError(err, "SCSetInfo2 error", op->reports); - err = SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); + err = SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); CheckError(err, "SCSetInfo3 error", op->reports); } - // put up the dialog box - it needs to be called from the main thread + // put up the dialog box - it needs to be called from the main thread err = SCRequestSequenceSettings(qtdata->theComponent); if (err == scUserCancelled) { return OPERATOR_FINISHED; } - // update runtime codecsettings for use with the codec dialog - SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); - SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); - SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); + // update runtime codecsettings for use with the codec dialog + SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); + SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); + SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); - //Fill the render QuicktimeCodecSettings struct + //Fill the render QuicktimeCodecSettings struct rd->qtcodecsettings.codecTemporalQuality = (qtdata->gTemporalSettings.temporalQuality * 100) / codecLosslessQuality; - //Do not override scene frame rate (qtdata->gTemporalSettings.framerate) + //Do not override scene frame rate (qtdata->gTemporalSettings.framerate) rd->qtcodecsettings.keyFrameRate = qtdata->gTemporalSettings.keyFrameRate; rd->qtcodecsettings.codecType = qtdata->gSpatialSettings.codecType; @@ -838,26 +839,26 @@ static int request_qtcodec_settings(bContext *C, wmOperator *op) rd->qtcodecsettings.bitRate = qtdata->aDataRateSetting.dataRate; rd->qtcodecsettings.minSpatialQuality = (qtdata->aDataRateSetting.minSpatialQuality * 100) / codecLosslessQuality; rd->qtcodecsettings.minTemporalQuality = (qtdata->aDataRateSetting.minTemporalQuality * 100) / codecLosslessQuality; - //Frame duration is already known (qtdata->aDataRateSetting.frameDuration) + //Frame duration is already known (qtdata->aDataRateSetting.frameDuration) QT_SaveCodecSettingsToScene(rd, op->reports); // framerate jugglin' - if (qtdata->gTemporalSettings.frameRate == 1571553) { // 23.98 fps + if (qtdata->gTemporalSettings.frameRate == 1571553) { // 23.98 fps qtdata->kVideoTimeScale = 24000; qtdata->duration = 1001; rd->frs_sec = 24; rd->frs_sec_base = 1.001; } - else if (qtdata->gTemporalSettings.frameRate == 1964113) { // 29.97 fps + else if (qtdata->gTemporalSettings.frameRate == 1964113) { // 29.97 fps qtdata->kVideoTimeScale = 30000; qtdata->duration = 1001; rd->frs_sec = 30; rd->frs_sec_base = 1.001; } - else if (qtdata->gTemporalSettings.frameRate == 3928227) { // 59.94 fps + else if (qtdata->gTemporalSettings.frameRate == 3928227) { // 59.94 fps qtdata->kVideoTimeScale = 60000; qtdata->duration = 1001; @@ -917,7 +918,7 @@ void SCENE_OT_render_data_set_quicktime_codec(wmOperatorType *ot) ot->poll = ED_operator_setqtcodec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } #endif /* USE_QTKIT */ diff --git a/source/blender/quicktime/apple/quicktime_import.c b/source/blender/quicktime/apple/quicktime_import.c index 3e4e53418ac..f3e71feec58 100644 --- a/source/blender/quicktime/apple/quicktime_import.c +++ b/source/blender/quicktime/apple/quicktime_import.c @@ -58,35 +58,35 @@ #include "quicktime_import.h" #include "quicktime_export.h" -#define RECT_WIDTH(r) (r.right-r.left) -#define RECT_HEIGHT(r) (r.bottom-r.top) +#define RECT_WIDTH(r) (r.right - r.left) +#define RECT_HEIGHT(r) (r.bottom - r.top) #define QTIME_DEBUG 0 typedef struct _QuicktimeMovie { - GWorldPtr offscreenGWorld; - PixMapHandle offscreenPixMap; - Movie movie; - Rect movieBounds; - short movieRefNum; - short movieResId; - int movWidth, movHeight; + GWorldPtr offscreenGWorld; + PixMapHandle offscreenPixMap; + Movie movie; + Rect movieBounds; + short movieRefNum; + short movieResId; + int movWidth, movHeight; - int framecount; + int framecount; - ImBuf *ibuf; + ImBuf *ibuf; - TimeValue *frameIndex; - Media theMedia; - Track theTrack; - long trackIndex; - short depth; + TimeValue *frameIndex; + Media theMedia; + Track theTrack; + long trackIndex; + short depth; - int have_gw; //ugly + int have_gw; /* ugly */ } QuicktimeMovie; @@ -105,7 +105,7 @@ void quicktime_init(void) #endif /* _WIN32 */ /* Initialize QuickTime */ -#if defined(_WIN32) || defined (__APPLE__) +#if defined(_WIN32) || defined(__APPLE__) nerr = EnterMovies(); if (nerr != noErr) G.have_quicktime = FALSE; @@ -113,7 +113,7 @@ void quicktime_init(void) #endif /* _WIN32 || __APPLE__ */ #ifdef __linux__ /* inititalize quicktime codec registry */ - lqt_registry_init(); + lqt_registry_init(); #endif G.have_quicktime = TRUE; } @@ -141,7 +141,7 @@ char *get_valid_qtname(char *name) TCHAR Buffer[MAX_PATH]; DWORD dwRet; char *qtname; - DynStr *ds= BLI_dynstr_new(); + DynStr *ds = BLI_dynstr_new(); dwRet = GetCurrentDirectory(MAX_PATH, Buffer); @@ -166,7 +166,7 @@ char *get_valid_qtname(char *name) BLI_dynstr_append(ds, name); } - qtname= BLI_dynstr_get_cstring(ds); + qtname = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); return qtname; @@ -176,33 +176,33 @@ char *get_valid_qtname(char *name) int anim_is_quicktime(const char *name) { - FSSpec theFSSpec; - char theFullPath[255]; + FSSpec theFSSpec; + char theFullPath[255]; - Boolean isMovieFile = false; - AliasHandle myAlias = NULL; - Component myImporter = NULL; + Boolean isMovieFile = false; + AliasHandle myAlias = NULL; + Component myImporter = NULL; #ifdef __APPLE__ - FInfo myFinderInfo; - FSRef myRef; + FInfo myFinderInfo; + FSRef myRef; #else char *qtname; - Str255 dst; + Str255 dst; #endif - OSErr err = noErr; + OSErr err = noErr; // don't let quicktime movie import handle these - if ( BLI_testextensie(name, ".swf") || - BLI_testextensie(name, ".txt") || - BLI_testextensie(name, ".mpg") || - BLI_testextensie(name, ".avi") || // wouldnt be appropriate ;) - BLI_testextensie(name, ".tga") || - BLI_testextensie(name, ".png") || - BLI_testextensie(name, ".bmp") || - BLI_testextensie(name, ".jpg") || - BLI_testextensie(name, ".wav") || - BLI_testextensie(name, ".zip") || - BLI_testextensie(name, ".mp3")) + if (BLI_testextensie(name, ".swf") || + BLI_testextensie(name, ".txt") || + BLI_testextensie(name, ".mpg") || + BLI_testextensie(name, ".avi") || /* wouldnt be appropriate ;) */ + BLI_testextensie(name, ".tga") || + BLI_testextensie(name, ".png") || + BLI_testextensie(name, ".bmp") || + BLI_testextensie(name, ".jpg") || + BLI_testextensie(name, ".wav") || + BLI_testextensie(name, ".zip") || + BLI_testextensie(name, ".mp3")) { return 0; } @@ -245,7 +245,7 @@ int anim_is_quicktime(const char *name) } } - if ((err == noErr) && (myImporter != NULL)) { // this file is a movie file + if ((err == noErr) && (myImporter != NULL)) { /* this file is a movie file */ isMovieFile = true; } @@ -268,8 +268,8 @@ void free_anim_quicktime(struct anim *anim) DisposeMovie(anim->qtime->movie); CloseMovieFile(anim->qtime->movieRefNum); - if (anim->qtime->frameIndex) MEM_freeN (anim->qtime->frameIndex); - if (anim->qtime) MEM_freeN (anim->qtime); + if (anim->qtime->frameIndex) MEM_freeN(anim->qtime->frameIndex); + if (anim->qtime) MEM_freeN(anim->qtime); anim->qtime = NULL; @@ -280,17 +280,17 @@ void free_anim_quicktime(struct anim *anim) static OSErr QT_get_frameIndexes(struct anim *anim) { int i; - OSErr anErr = noErr; - OSType media = VideoMediaType; + OSErr anErr = noErr; + OSType media = VideoMediaType; TimeValue nextTime = 0; - TimeValue startPoint; - TimeValue tmpstartPoint; + TimeValue startPoint; + TimeValue tmpstartPoint; long sampleCount = 0; startPoint = -1; - GetMovieNextInterestingTime(anim->qtime->movie, nextTimeMediaSample+nextTimeEdgeOK, (TimeValue)1, &media, 0, - 1, &startPoint, NULL); + GetMovieNextInterestingTime(anim->qtime->movie, nextTimeMediaSample + nextTimeEdgeOK, (TimeValue)1, &media, 0, + 1, &startPoint, NULL); tmpstartPoint = startPoint; @@ -320,16 +320,16 @@ static OSErr QT_get_frameIndexes(struct anim *anim) } -ImBuf * qtime_fetchibuf (struct anim *anim, int position) +ImBuf *qtime_fetchibuf(struct anim *anim, int position) { - PixMapHandle myPixMap = NULL; - Ptr myPtr; + PixMapHandle myPixMap = NULL; + Ptr myPtr; - register int index; - register int boxsize; + register int index; + register int boxsize; - register uint32_t *readPos; - register uint32_t *changePos; + register uint32_t *readPos; + register uint32_t *changePos; ImBuf *ibuf = NULL; unsigned int *rect; @@ -344,7 +344,7 @@ ImBuf * qtime_fetchibuf (struct anim *anim, int position) return (NULL); } - ibuf = IMB_allocImBuf (anim->x, anim->y, 32, IB_rect); + ibuf = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect); rect = ibuf->rect; SetMovieTimeValue(anim->qtime->movie, anim->qtime->frameIndex[position]); @@ -356,8 +356,8 @@ ImBuf * qtime_fetchibuf (struct anim *anim, int position) myPtr = GetPixBaseAddr(myPixMap); if (myPtr == NULL) { - printf ("Error reading frame from Quicktime"); - IMB_freeImBuf (ibuf); + printf("Error reading frame from Quicktime"); + IMB_freeImBuf(ibuf); return NULL; } @@ -367,10 +367,10 @@ ImBuf * qtime_fetchibuf (struct anim *anim, int position) #ifdef __APPLE__ // Swap alpha byte to the end, so ARGB become RGBA; - from= (unsigned char *)readPos; - to= (unsigned char *)changePos; + from = (unsigned char *)readPos; + to = (unsigned char *)changePos; - for ( index = 0; index < boxsize; index++, from+=4, to+=4 ) { + for (index = 0; index < boxsize; index++, from += 4, to += 4) { to[3] = from[0]; to[0] = from[1]; to[1] = from[2]; @@ -379,14 +379,14 @@ ImBuf * qtime_fetchibuf (struct anim *anim, int position) #endif #ifdef _WIN32 - for ( index = 0; index < boxsize; index++, changePos++, readPos++ ) - *( changePos ) = *(readPos ); + for (index = 0; index < boxsize; index++, changePos++, readPos++) + *(changePos) = *(readPos); if (anim->qtime->depth < 32) { //add alpha to ibuf boxsize = anim->x * anim->y * 4; crect = (unsigned char *) rect; - for ( index = 0; index < boxsize; index+=4, crect+=4 ) { + for (index = 0; index < boxsize; index += 4, crect += 4) { crect[3] = 0xFF; } } @@ -403,12 +403,12 @@ ImBuf * qtime_fetchibuf (struct anim *anim, int position) static int GetFirstVideoMedia(struct anim *anim) { - long numTracks; - OSType mediaType; + long numTracks; + OSType mediaType; numTracks = GetMovieTrackCount(anim->qtime->movie); - for (anim->qtime->trackIndex=1; anim->qtime->trackIndex<=numTracks; (anim->qtime->trackIndex)++) { + for (anim->qtime->trackIndex = 1; anim->qtime->trackIndex <= numTracks; (anim->qtime->trackIndex)++) { anim->qtime->theTrack = GetMovieIndTrack(anim->qtime->movie, anim->qtime->trackIndex); if (anim->qtime->theTrack) @@ -425,7 +425,7 @@ static int GetFirstVideoMedia(struct anim *anim) static short GetFirstVideoTrackPixelDepth(struct anim *anim) { - SampleDescriptionHandle imageDescH = (SampleDescriptionHandle)NewHandle(sizeof(Handle)); + SampleDescriptionHandle imageDescH = (SampleDescriptionHandle)NewHandle(sizeof(Handle)); // long trackIndex = 0; /*unused*/ if (!GetFirstVideoMedia(anim)) @@ -440,19 +440,19 @@ static short GetFirstVideoTrackPixelDepth(struct anim *anim) int startquicktime(struct anim *anim) { - FSSpec theFSSpec; + FSSpec theFSSpec; - OSErr err = noErr; - char theFullPath[255]; + OSErr err = noErr; + char theFullPath[255]; #ifdef __APPLE__ - FSRef myRef; + FSRef myRef; #else - char *qtname; - Str255 dst; + char *qtname; + Str255 dst; #endif short depth = 0; - anim->qtime = MEM_callocN (sizeof(QuicktimeMovie), "animqt"); + anim->qtime = MEM_callocN(sizeof(QuicktimeMovie), "animqt"); anim->qtime->have_gw = FALSE; if (anim->qtime == NULL) { @@ -481,8 +481,8 @@ int startquicktime(struct anim *anim) if (err == noErr) { if (QTIME_DEBUG) printf("qt: movie opened\n"); err = NewMovieFromFile(&anim->qtime->movie, - anim->qtime->movieRefNum, - &anim->qtime->movieResId, NULL, newMovieActive, NULL); + anim->qtime->movieRefNum, + &anim->qtime->movieResId, NULL, newMovieActive, NULL); } if (err) { @@ -506,22 +506,22 @@ int startquicktime(struct anim *anim) return -1; } - anim->qtime->ibuf = IMB_allocImBuf (anim->x, anim->y, 32, IB_rect); + anim->qtime->ibuf = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect); #ifdef _WIN32 err = NewGWorldFromPtr(&anim->qtime->offscreenGWorld, - k32RGBAPixelFormat, - &anim->qtime->movieBounds, - NULL, NULL, 0, - (unsigned char *)anim->qtime->ibuf->rect, - anim->x * 4); + k32RGBAPixelFormat, + &anim->qtime->movieBounds, + NULL, NULL, 0, + (unsigned char *)anim->qtime->ibuf->rect, + anim->x * 4); #else err = NewGWorldFromPtr(&anim->qtime->offscreenGWorld, - k32ARGBPixelFormat, - &anim->qtime->movieBounds, - NULL, NULL, 0, - (unsigned char *)anim->qtime->ibuf->rect, - anim->x * 4); + k32ARGBPixelFormat, + &anim->qtime->movieBounds, + NULL, NULL, 0, + (unsigned char *)anim->qtime->ibuf->rect, + anim->x * 4); #endif /* _WIN32 */ if (err == noErr) { @@ -554,29 +554,29 @@ int startquicktime(struct anim *anim) anim->curposition = 0; if (QTIME_DEBUG) printf("qt: load %s %dx%dx%d frames %d\n", anim->name, anim->qtime->movWidth, - anim->qtime->movHeight, anim->qtime->depth, anim->qtime->framecount); + anim->qtime->movHeight, anim->qtime->depth, anim->qtime->framecount); return 0; } -int imb_is_a_quicktime (char *name) +int imb_is_a_quicktime(char *name) { - GraphicsImportComponent theImporter = NULL; + GraphicsImportComponent theImporter = NULL; - FSSpec theFSSpec; + FSSpec theFSSpec; #ifdef _WIN32 - Str255 dst; /*unused*/ + Str255 dst; /*unused*/ #endif - char theFullPath[255]; + char theFullPath[255]; // Boolean isMovieFile = false; /*unused*/ // AliasHandle myAlias = NULL; /*unused*/ // Component myImporter = NULL; /*unused*/ #ifdef __APPLE__ // FInfo myFinderInfo; /*unused*/ - FSRef myRef; + FSRef myRef; #endif - OSErr err = noErr; + OSErr err = noErr; if (!G.have_quicktime) return 0; @@ -587,7 +587,7 @@ int imb_is_a_quicktime (char *name) BLI_testextensie(name, ".txt") || BLI_testextensie(name, ".mpg") || BLI_testextensie(name, ".wav") || - BLI_testextensie(name, ".mov") || // not as image, doesn't work + BLI_testextensie(name, ".mov") || // not as image, doesn't work BLI_testextensie(name, ".avi") || BLI_testextensie(name, ".mp3")) { @@ -616,30 +616,30 @@ int imb_is_a_quicktime (char *name) ImBuf *imb_quicktime_decode(unsigned char *mem, int size, int flags) { - Rect myRect; - OSErr err = noErr; - GraphicsImportComponent gImporter = NULL; + Rect myRect; + OSErr err = noErr; + GraphicsImportComponent gImporter = NULL; - ImageDescriptionHandle desc; + ImageDescriptionHandle desc; - ComponentInstance dataHandler; + ComponentInstance dataHandler; PointerDataRef dataref; int x, y, depth; int have_gw = FALSE; ImBuf *ibuf = NULL; // ImBuf *imbuf = NULL; /*unused*/ - GWorldPtr offGWorld; - PixMapHandle myPixMap = NULL; + GWorldPtr offGWorld; + PixMapHandle myPixMap = NULL; #ifdef __APPLE__ - Ptr myPtr; + Ptr myPtr; - register int index; - register int boxsize; + register int index; + register int boxsize; - register uint32_t *readPos; - register uint32_t *changePos; + register uint32_t *readPos; + register uint32_t *changePos; ImBuf *wbuf = NULL; unsigned int *rect; @@ -651,17 +651,17 @@ ImBuf *imb_quicktime_decode(unsigned char *mem, int size, int flags) if (QTIME_DEBUG) printf("qt: attempt to load mem as image\n"); - dataref= (PointerDataRef)NewHandle(sizeof(PointerDataRefRecord)); + dataref = (PointerDataRef)NewHandle(sizeof(PointerDataRefRecord)); (**dataref).data = mem; (**dataref).dataLength = size; err = OpenADataHandler((Handle)dataref, - PointerDataHandlerSubType, - nil, - (OSType)0, - nil, - kDataHCanRead, - &dataHandler); + PointerDataHandlerSubType, + nil, + (OSType)0, + nil, + kDataHCanRead, + &dataHandler); if (err != noErr) { if (QTIME_DEBUG) printf("no datahandler\n"); goto bail; @@ -679,7 +679,7 @@ ImBuf *imb_quicktime_decode(unsigned char *mem, int size, int flags) goto bail; } - err = GraphicsImportGetImageDescription (gImporter, &desc ); + err = GraphicsImportGetImageDescription(gImporter, &desc); if (err != noErr) { if (QTIME_DEBUG) printf("no imagedescription\n"); goto bail; @@ -693,26 +693,26 @@ ImBuf *imb_quicktime_decode(unsigned char *mem, int size, int flags) ibuf = IMB_allocImBuf(x, y, depth, 0); ibuf->ftype = QUICKTIME; DisposeHandle((Handle)dataref); - if (gImporter != NULL) CloseComponent(gImporter); + if (gImporter != NULL) CloseComponent(gImporter); return ibuf; } #ifdef __APPLE__ - ibuf = IMB_allocImBuf (x, y, 32, IB_rect); - wbuf = IMB_allocImBuf (x, y, 32, IB_rect); + ibuf = IMB_allocImBuf(x, y, 32, IB_rect); + wbuf = IMB_allocImBuf(x, y, 32, IB_rect); err = NewGWorldFromPtr(&offGWorld, - k32ARGBPixelFormat, - &myRect, NULL, NULL, 0, - (unsigned char *)wbuf->rect, x * 4); + k32ARGBPixelFormat, + &myRect, NULL, NULL, 0, + (unsigned char *)wbuf->rect, x * 4); #else - ibuf = IMB_allocImBuf (x, y, 32, IB_rect); + ibuf = IMB_allocImBuf(x, y, 32, IB_rect); err = NewGWorldFromPtr(&offGWorld, - k32RGBAPixelFormat, - &myRect, NULL, NULL, 0, - (unsigned char *)ibuf->rect, x * 4); + k32RGBAPixelFormat, + &myRect, NULL, NULL, 0, + (unsigned char *)ibuf->rect, x * 4); #endif if (err != noErr) { @@ -734,8 +734,8 @@ ImBuf *imb_quicktime_decode(unsigned char *mem, int size, int flags) myPtr = GetPixBaseAddr(myPixMap); if (myPtr == NULL) { - printf ("Error reading frame from Quicktime"); - IMB_freeImBuf (ibuf); + printf("Error reading frame from Quicktime"); + IMB_freeImBuf(ibuf); return NULL; } @@ -744,10 +744,10 @@ ImBuf *imb_quicktime_decode(unsigned char *mem, int size, int flags) changePos = (uint32_t *) rect; // Swap alpha byte to the end, so ARGB become RGBA; - from= (unsigned char *)readPos; - to= (unsigned char *)changePos; + from = (unsigned char *)readPos; + to = (unsigned char *)changePos; - for ( index = 0; index < boxsize; index++, from+=4, to+=4 ) { + for (index = 0; index < boxsize; index++, from += 4, to += 4) { to[3] = from[0]; to[0] = from[1]; to[1] = from[2]; @@ -763,17 +763,17 @@ bail: #ifdef __APPLE__ if (wbuf) { - IMB_freeImBuf (wbuf); + IMB_freeImBuf(wbuf); wbuf = NULL; } #endif - if (gImporter != NULL) CloseComponent(gImporter); + if (gImporter != NULL) CloseComponent(gImporter); if (err != noErr) { if (QTIME_DEBUG) printf("quicktime import unsuccesfull\n"); if (ibuf) { - IMB_freeImBuf (ibuf); + IMB_freeImBuf(ibuf); ibuf = NULL; } } @@ -788,8 +788,8 @@ bail: int box = x * y; unsigned char *arect = (unsigned char *) ibuf->rect; - if ( depth < 32 && (**desc).cType != kGIFCodecType) { - for (i = 0; i < box; i++, arect+=4) + if (depth < 32 && (**desc).cType != kGIFCodecType) { + for (i = 0; i < box; i++, arect += 4) arect[3] = 0xFF; } #endif -- cgit v1.2.3