style cleanup for blenkernel, no functional changes.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 23 Feb 2012 02:17:50 +0000 (02:17 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 23 Feb 2012 02:17:50 +0000 (02:17 +0000)
22 files changed:
source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/boids.c
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/mball.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/mesh_validate.c
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/ocean.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/softbody.c
source/blender/blenkernel/intern/sound.c
source/blender/blenkernel/intern/text.c
source/blender/blenkernel/intern/unit.c

index 3ab52a7..8f0d5e2 100644 (file)
@@ -13,9 +13,9 @@
 #include "BLO_sys_types.h" // for intptr_t support
 
 #ifdef _MSC_VER
-#define CCG_INLINE __inline
+#  define CCG_INLINE __inline
 #else
-#define CCG_INLINE inline
+#  define CCG_INLINE inline
 #endif
 
 /* copied from BKE_utildefines.h ugh */
@@ -59,22 +59,24 @@ typedef struct _EHash {
 
 #define EHASH_hash(eh, item)   (((uintptr_t) (item))%((unsigned int) (eh)->curSize))
 
-static EHash *_ehash_new(int estimatedNumEntries, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator) {
+static EHash *_ehash_new(int estimatedNumEntries, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator)
+{
        EHash *eh = allocatorIFC->alloc(allocator, sizeof(*eh));
        eh->allocatorIFC = *allocatorIFC;
        eh->allocator = allocator;
        eh->numEntries = 0;
        eh->curSizeIdx = 0;
-       while (kHashSizes[eh->curSizeIdx]<estimatedNumEntries)
+       while (kHashSizes[eh->curSizeIdx] < estimatedNumEntries)
                eh->curSizeIdx++;
        eh->curSize = kHashSizes[eh->curSizeIdx];
-       eh->buckets = EHASH_alloc(eh, eh->curSize*sizeof(*eh->buckets));
-       memset(eh->buckets, 0, eh->curSize*sizeof(*eh->buckets));
+       eh->buckets = EHASH_alloc(eh, eh->curSize * sizeof(*eh->buckets));
+       memset(eh->buckets, 0, eh->curSize * sizeof(*eh->buckets));
 
        return eh;
 }
 typedef void (*EHEntryFreeFP)(EHEntry *, void *);
-static void _ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *userData) {
+static void _ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *userData)
+{
        int numBuckets = eh->curSize;
 
        while (numBuckets--) {
@@ -93,19 +95,20 @@ static void _ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *userData) {
        EHASH_free(eh, eh);
 }
 
-static void _ehash_insert(EHash *eh, EHEntry *entry) {
+static void _ehash_insert(EHash *eh, EHEntry *entry)
+{
        int numBuckets = eh->curSize;
        int hash = EHASH_hash(eh, entry->key);
        entry->next = eh->buckets[hash];
        eh->buckets[hash] = entry;
        eh->numEntries++;
 
-       if (eh->numEntries > (numBuckets*3)) {
+       if (eh->numEntries > (numBuckets * 3)) {
                EHEntry **oldBuckets = eh->buckets;
                eh->curSize = kHashSizes[++eh->curSizeIdx];
                
-               eh->buckets = EHASH_alloc(eh, eh->curSize*sizeof(*eh->buckets));
-               memset(eh->buckets, 0, eh->curSize*sizeof(*eh->buckets));
+               eh->buckets = EHASH_alloc(eh, eh->curSize * sizeof(*eh->buckets));
+               memset(eh->buckets, 0, eh->curSize * sizeof(*eh->buckets));
 
                while (numBuckets--) {
                        for (entry = oldBuckets[numBuckets]; entry;) {
@@ -123,13 +126,14 @@ static void _ehash_insert(EHash *eh, EHEntry *entry) {
        }
 }
 
-static void *_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r) {
+static void *_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r)
+{
        int hash = EHASH_hash(eh, key);
        void **prevp = (void**) &eh->buckets[hash];
        EHEntry *entry;
        
        for (; (entry = *prevp); prevp = (void**) &entry->next) {
-               if (entry->key==key) {
+               if (entry->key == key) {
                        *prevp_r = (void**) prevp;
                        return entry;
                }
@@ -138,12 +142,13 @@ static void *_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r) {
        return NULL;
 }
 
-static void *_ehash_lookup(EHash *eh, void *key) {
+static void *_ehash_lookup(EHash *eh, void *key)
+{
        int hash = EHASH_hash(eh, key);
        EHEntry *entry;
        
        for (entry = eh->buckets[hash]; entry; entry = entry->next)
-               if (entry->key==key)
+               if (entry->key == key)
                        break;
        
        return entry;
@@ -157,55 +162,64 @@ typedef struct _EHashIterator {
        EHEntry *curEntry;
 } EHashIterator;
 
-static EHashIterator *_ehashIterator_new(EHash *eh) {
+static EHashIterator *_ehashIterator_new(EHash *eh)
+{
        EHashIterator *ehi = EHASH_alloc(eh, sizeof(*ehi));
        ehi->eh = eh;
        ehi->curEntry = NULL;
        ehi->curBucket = -1;
        while (!ehi->curEntry) {
                ehi->curBucket++;
-               if (ehi->curBucket==ehi->eh->curSize)
+               if (ehi->curBucket == ehi->eh->curSize)
                        break;
                ehi->curEntry = ehi->eh->buckets[ehi->curBucket];
        }
        return ehi;
 }
-static void _ehashIterator_free(EHashIterator *ehi) {
+static void _ehashIterator_free(EHashIterator *ehi)
+{
        EHASH_free(ehi->eh, ehi);
 }
 
-static void *_ehashIterator_getCurrent(EHashIterator *ehi) {
+static void *_ehashIterator_getCurrent(EHashIterator *ehi)
+{
        return ehi->curEntry;
 }
 
-static void _ehashIterator_next(EHashIterator *ehi) {
+static void _ehashIterator_next(EHashIterator *ehi)
+{
        if (ehi->curEntry) {
                ehi->curEntry = ehi->curEntry->next;
                while (!ehi->curEntry) {
                        ehi->curBucket++;
-                       if (ehi->curBucket==ehi->eh->curSize)
+                       if (ehi->curBucket == ehi->eh->curSize)
                                break;
                        ehi->curEntry = ehi->eh->buckets[ehi->curBucket];
                }
        }
 }
-static int _ehashIterator_isStopped(EHashIterator *ehi) {
+static int _ehashIterator_isStopped(EHashIterator *ehi)
+{
        return !ehi->curEntry;
 }
 
 /***/
 
-static void *_stdAllocator_alloc(CCGAllocatorHDL UNUSED(a), int numBytes) {
+static void *_stdAllocator_alloc(CCGAllocatorHDL UNUSED(a), int numBytes)
+{
        return malloc(numBytes);
 }
-static void *_stdAllocator_realloc(CCGAllocatorHDL UNUSED(a), void *ptr, int newSize, int UNUSED(oldSize)) {
+static void *_stdAllocator_realloc(CCGAllocatorHDL UNUSED(a), void *ptr, int newSize, int UNUSED(oldSize))
+{
        return realloc(ptr, newSize);
 }
-static void _stdAllocator_free(CCGAllocatorHDL UNUSED(a), void *ptr) {
+static void _stdAllocator_free(CCGAllocatorHDL UNUSED(a), void *ptr)
+{
        free(ptr);
 }
 
-static CCGAllocatorIFC *_getStandardAllocatorIFC(void) {
+static CCGAllocatorIFC *_getStandardAllocatorIFC(void)
+{
        static CCGAllocatorIFC ifc;
 
        ifc.alloc = _stdAllocator_alloc;
@@ -218,24 +232,25 @@ static CCGAllocatorIFC *_getStandardAllocatorIFC(void) {
 
 /***/
 
-static int VertDataEqual(const float *a, const float *b) {
-       return a[0]==b[0] && a[1]==b[1] && a[2]==b[2];
+static int VertDataEqual(const float *a, const float *b)
+{
+       return a[0] == b[0] && a[1] == b[1] && a[2] == b[2];
 }
-#define VertDataZero(av)                               { float *_a = (float*) av; _a[0] = _a[1] = _a[2] = 0.0f; }
-#define VertDataCopy(av, bv)                   { float *_a = (float*) av, *_b = (float*) bv; _a[0] =_b[0]; _a[1] =_b[1]; _a[2] =_b[2]; }
-#define VertDataAdd(av, bv)                            { float *_a = (float*) av, *_b = (float*) bv; _a[0]+=_b[0]; _a[1]+=_b[1]; _a[2]+=_b[2]; }
-#define VertDataSub(av, bv)                            { float *_a = (float*) av, *_b = (float*) bv; _a[0]-=_b[0]; _a[1]-=_b[1]; _a[2]-=_b[2]; }
-#define VertDataMulN(av, n)                            { float *_a = (float*) av; _a[0]*=n; _a[1]*=n; _a[2]*=n; }
+#define VertDataZero(av)     { float *_a = (float *)av; _a[0] = _a[1] = _a[2] = 0.0f; }
+#define VertDataCopy(av, bv) { float *_a = (float *)av, *_b = (float *) bv; _a[0]  = _b[0]; _a[1]  = _b[1]; _a[2]  = _b[2]; }
+#define VertDataAdd(av, bv)  { float *_a = (float *)av, *_b = (float *) bv; _a[0] += _b[0]; _a[1] += _b[1]; _a[2] += _b[2]; }
+#define VertDataSub(av, bv)  { float *_a = (float *)av, *_b = (float *) bv; _a[0] -= _b[0]; _a[1] -= _b[1]; _a[2] -= _b[2]; }
+#define VertDataMulN(av, n)  { float *_a = (float *)av; _a[0]*=n; _a[1]*=n; _a[2] *=n; }
 #define VertDataAvg4(tv, av, bv, cv, dv) \
        { \
-               float *_t = (float*) tv, *_a = (float*) av, *_b = (float*) bv, *_c = (float*) cv, *_d = (float*) dv; \
-               _t[0] = (_a[0]+_b[0]+_c[0]+_d[0])*.25f; \
-               _t[1] = (_a[1]+_b[1]+_c[1]+_d[1])*.25f; \
-               _t[2] = (_a[2]+_b[2]+_c[2]+_d[2])*.25f; \
+               float *_t = (float *) tv, *_a = (float *) av, *_b = (float *) bv, *_c = (float *) cv, *_d = (float *) dv; \
+               _t[0] = (_a[0] + _b[0] + _c[0] + _d[0]) * 0.25f; \
+               _t[1] = (_a[1] + _b[1] + _c[1] + _d[1]) * 0.25f; \
+               _t[2] = (_a[2] + _b[2] + _c[2] + _d[2]) * 0.25f; \
        }
-#define NormZero(av)                                   { float *_a = (float*) av; _a[0] = _a[1] = _a[2] = 0.0f; }
-#define NormCopy(av, bv)                               { float *_a = (float*) av, *_b = (float*) bv; _a[0] =_b[0]; _a[1] =_b[1]; _a[2] =_b[2]; }
-#define NormAdd(av, bv)                                        { float *_a = (float*) av, *_b = (float*) bv; _a[0]+=_b[0]; _a[1]+=_b[1]; _a[2]+=_b[2]; }
+#define NormZero(av)     { float *_a = (float *) av; _a[0] = _a[1] = _a[2] = 0.0f; }
+#define NormCopy(av, bv) { float *_a = (float *) av, *_b = (float *) bv; _a[0]  = _b[0]; _a[1]  = _b[1]; _a[2]  = _b[2]; }
+#define NormAdd(av, bv)  { float *_a = (float *) av, *_b = (float *) bv; _a[0] += _b[0]; _a[1] += _b[1]; _a[2] += _b[2]; }
 
 
 static int _edge_isBoundary(const CCGEdge *e);
@@ -243,15 +258,15 @@ static int _edge_isBoundary(const CCGEdge *e);
 /***/
 
 enum {
-       Vert_eEffected=         (1<<0),
-       Vert_eChanged=          (1<<1),
-       Vert_eSeam=                     (1<<2),
+       Vert_eEffected =    (1 << 0),
+       Vert_eChanged =     (1 << 1),
+       Vert_eSeam =        (1 << 2)
 } /*VertFlags*/;
 enum {
-       Edge_eEffected=         (1<<0),
+       Edge_eEffected =    (1 << 0)
 } /*CCGEdgeFlags*/;
 enum {
-       Face_eEffected=         (1<<0),
+       Face_eEffected =    (1 << 0)
 } /*FaceFlags*/;
 
 struct _CCGVert {
@@ -265,7 +280,7 @@ struct _CCGVert {
 //     byte *levelData;
 //     byte *userData;
 };
-#define VERT_getLevelData(v)           ((byte*) &(v)[1])
+#define VERT_getLevelData(v)           ((byte *) &(v)[1])
 
 struct _CCGEdge {
        CCGEdge         *next;  /* EHData.next */
@@ -280,7 +295,7 @@ struct _CCGEdge {
 //     byte *levelData;
 //     byte *userData;
 };
-#define EDGE_getLevelData(e)           ((byte*) &(e)[1])
+#define EDGE_getLevelData(e)           ((byte *) &(e)[1])
 
 struct _CCGFace {
        CCGFace         *next;  /* EHData.next */
@@ -296,14 +311,14 @@ struct _CCGFace {
 };
 #define FACE_getVerts(f)               ((CCGVert**) &(f)[1])
 #define FACE_getEdges(f)               ((CCGEdge**) &(FACE_getVerts(f)[(f)->numVerts]))
-#define FACE_getCenterData(f)  ((byte*) &(FACE_getEdges(f)[(f)->numVerts]))
+#define FACE_getCenterData(f)  ((byte *) &(FACE_getEdges(f)[(f)->numVerts]))
 
 typedef enum {
        eSyncState_None = 0,
        eSyncState_Vert,
        eSyncState_Edge,
        eSyncState_Face,
-       eSyncState_Partial,
+       eSyncState_Partial
 } SyncState;
 
 struct _CCGSubSurf {
@@ -350,8 +365,9 @@ struct _CCGSubSurf {
 
 /***/
 
-static CCGVert *_vert_new(CCGVertHDL vHDL, CCGSubSurf *ss) {
-       CCGVert *v = CCGSUBSURF_alloc(ss, sizeof(CCGVert) + ss->meshIFC.vertDataSize * (ss->subdivLevels+1) + ss->meshIFC.vertUserSize);
+static CCGVert *_vert_new(CCGVertHDL vHDL, CCGSubSurf *ss)
+{
+       CCGVert *v = CCGSUBSURF_alloc(ss, sizeof(CCGVert) + ss->meshIFC.vertDataSize * (ss->subdivLevels + 1) + ss->meshIFC.vertUserSize);
        byte *userData;
 
        v->vHDL = vHDL;
@@ -366,71 +382,87 @@ static CCGVert *_vert_new(CCGVertHDL vHDL, CCGSubSurf *ss) {
 
        return v;
 }
-static void _vert_remEdge(CCGVert *v, CCGEdge *e) {
+static void _vert_remEdge(CCGVert *v, CCGEdge *e)
+{
        int i;
-       for (i=0; i<v->numEdges; i++) {
-               if (v->edges[i]==e) {
+       for (i = 0; i < v->numEdges; i++) {
+               if (v->edges[i] == e) {
                        v->edges[i] = v->edges[--v->numEdges];
                        break;
                }
        }
 }
-static void _vert_remFace(CCGVert *v, CCGFace *f) {
+static void _vert_remFace(CCGVert *v, CCGFace *f)
+{
        int i;
-       for (i=0; i<v->numFaces; i++) {
-               if (v->faces[i]==f) {
+       for (i = 0; i < v->numFaces; i++) {
+               if (v->faces[i] == f) {
                        v->faces[i] = v->faces[--v->numFaces];
                        break;
                }
        }
 }
-static void _vert_addEdge(CCGVert *v, CCGEdge *e, CCGSubSurf *ss) {
-       v->edges = CCGSUBSURF_realloc(ss, v->edges, (v->numEdges+1)*sizeof(*v->edges), v->numEdges*sizeof(*v->edges));
+static void _vert_addEdge(CCGVert *v, CCGEdge *e, CCGSubSurf *ss)
+{
+       v->edges = CCGSUBSURF_realloc(ss, v->edges, (v->numEdges + 1) * sizeof(*v->edges), v->numEdges * sizeof(*v->edges));
        v->edges[v->numEdges++] = e;
 }
-static void _vert_addFace(CCGVert *v, CCGFace *f, CCGSubSurf *ss) {
-       v->faces = CCGSUBSURF_realloc(ss, v->faces, (v->numFaces+1)*sizeof(*v->faces), v->numFaces*sizeof(*v->faces));
+static void _vert_addFace(CCGVert *v, CCGFace *f, CCGSubSurf *ss)
+{
+       v->faces = CCGSUBSURF_realloc(ss, v->faces, (v->numFaces + 1) * sizeof(*v->faces), v->numFaces * sizeof(*v->faces));
        v->faces[v->numFaces++] = f;
 }
-static CCGEdge *_vert_findEdgeTo(const CCGVert *v, const CCGVert *vQ) {
+static CCGEdge *_vert_findEdgeTo(const CCGVert *v, const CCGVert *vQ)
+{
        int i;
-       for (i=0; i<v->numEdges; i++) {
-               CCGEdge *e = v->edges[v->numEdges-1-i]; // XXX, note reverse
-               if (    (e->v0==v && e->v1==vQ) ||
-                               (e->v1==v && e->v0==vQ))
+       for (i = 0; i < v->numEdges; i++) {
+               CCGEdge *e = v->edges[v->numEdges - 1 - i]; // XXX, note reverse
+               if ((e->v0 == v && e->v1 == vQ) ||
+                   (e->v1 == v && e->v0 == vQ))
+               {
                        return e;
+               }
        }
        return NULL;
 }
-static int _vert_isBoundary(const CCGVert *v) {
+static int _vert_isBoundary(const CCGVert *v)
+{
        int i;
-       for (i=0; i<v->numEdges; i++)
+       for (i = 0; i < v->numEdges; i++)
                if (_edge_isBoundary(v->edges[i]))
                        return 1;
        return 0;
 }
 
-static void *_vert_getCo(CCGVert *v, int lvl, int dataSize) {
-       return &VERT_getLevelData(v)[lvl*dataSize];
+static void *_vert_getCo(CCGVert *v, int lvl, int dataSize)
+{
+       return &VERT_getLevelData(v)[lvl * dataSize];
 }
-static float *_vert_getNo(CCGVert *v, int lvl, int dataSize, int normalDataOffset) {
-       return (float*) &VERT_getLevelData(v)[lvl*dataSize + normalDataOffset];
+static float *_vert_getNo(CCGVert *v, int lvl, int dataSize, int normalDataOffset)
+{
+       return (float *) &VERT_getLevelData(v)[lvl * dataSize + normalDataOffset];
 }
 
-static void _vert_free(CCGVert *v, CCGSubSurf *ss) {
+static void _vert_free(CCGVert *v, CCGSubSurf *ss)
+{
        CCGSUBSURF_free(ss, v->edges);
        CCGSUBSURF_free(ss, v->faces);
        CCGSUBSURF_free(ss, v);
 }
 
-static int VERT_seam(const CCGVert *v) {
+static int VERT_seam(const CCGVert *v)
+{
        return ((v->flags & Vert_eSeam) != 0);
 }
 
 /***/
 
-static CCGEdge *_edge_new(CCGEdgeHDL eHDL, CCGVert *v0, CCGVert *v1, float crease, CCGSubSurf *ss) {
-       CCGEdge *e = CCGSUBSURF_alloc(ss, sizeof(CCGEdge) + ss->meshIFC.vertDataSize *((ss->subdivLevels+1) + (1<<(ss->subdivLevels+1))-1) + ss->meshIFC.edgeUserSize);
+static CCGEdge *_edge_new(CCGEdgeHDL eHDL, CCGVert *v0, CCGVert *v1, float crease, CCGSubSurf *ss)
+{
+       CCGEdge *e = CCGSUBSURF_alloc(ss,
+                                     sizeof(CCGEdge) +
+                                     ss->meshIFC.vertDataSize * ((ss->subdivLevels + 1) + (1 << (ss->subdivLevels + 1)) - 1) +
+                                     ss->meshIFC.edgeUserSize);
        byte *userData;
 
        e->eHDL = eHDL;
@@ -449,53 +481,64 @@ static CCGEdge *_edge_new(CCGEdgeHDL eHDL, CCGVert *v0, CCGVert *v1, float creas
 
        return e;
 }
-static void _edge_remFace(CCGEdge *e, CCGFace *f) {
+static void _edge_remFace(CCGEdge *e, CCGFace *f)
+{
        int i;
-       for (i=0; i<e->numFaces; i++) {
-               if (e->faces[i]==f) {
+       for (i = 0; i < e->numFaces; i++) {
+               if (e->faces[i] == f) {
                        e->faces[i] = e->faces[--e->numFaces];
                        break;
                }
        }
 }
-static void _edge_addFace(CCGEdge *e, CCGFace *f, CCGSubSurf *ss) {
-       e->faces = CCGSUBSURF_realloc(ss, e->faces, (e->numFaces+1)*sizeof(*e->faces), e->numFaces*sizeof(*e->faces));
+static void _edge_addFace(CCGEdge *e, CCGFace *f, CCGSubSurf *ss)
+{
+       e->faces = CCGSUBSURF_realloc(ss, e->faces, (e->numFaces + 1) * sizeof(*e->faces), e->numFaces * sizeof(*e->faces));
        e->faces[e->numFaces++] = f;
 }
-static int _edge_isBoundary(const CCGEdge *e) {
+static int _edge_isBoundary(const CCGEdge *e)
+{
        return e->numFaces<2;
 }
 
-static CCGVert *_edge_getOtherVert(CCGEdge *e, CCGVert *vQ) {
-       if (vQ==e->v0) {
+static CCGVert *_edge_getOtherVert(CCGEdge *e, CCGVert *vQ)
+{
+       if (vQ == e->v0) {
                return e->v1;
-       } else {
+       }
+       else {
                return e->v0;
        }
 }
 
-static void *_edge_getCo(CCGEdge *e, int lvl, int x, int dataSize) {
-       int levelBase = lvl + (1<<lvl) - 1;
-       return &EDGE_getLevelData(e)[dataSize*(levelBase + x)];
+static void *_edge_getCo(CCGEdge *e, int lvl, int x, int dataSize)
+{
+       int levelBase = lvl + (1 << lvl) - 1;
+       return &EDGE_getLevelData(e)[dataSize * (levelBase + x)];
 }
-static float *_edge_getNo(CCGEdge *e, int lvl, int x, int dataSize, int normalDataOffset) {
-       int levelBase = lvl + (1<<lvl) - 1;
-       return (float*) &EDGE_getLevelData(e)[dataSize*(levelBase + x) + normalDataOffset];
+static float *_edge_getNo(CCGEdge *e, int lvl, int x, int dataSize, int normalDataOffset)
+{
+       int levelBase = lvl + (1 << lvl) - 1;
+       return (float *) &EDGE_getLevelData(e)[dataSize * (levelBase + x) + normalDataOffset];
 }
-static void *_edge_getCoVert(CCGEdge *e, CCGVert *v, int lvl, int x, int dataSize) {
-       int levelBase = lvl + (1<<lvl) - 1;
-       if (v==e->v0) {
-               return &EDGE_getLevelData(e)[dataSize*(levelBase + x)];
-       } else {
-               return &EDGE_getLevelData(e)[dataSize*(levelBase + (1<<lvl) - x)];              
+static void *_edge_getCoVert(CCGEdge *e, CCGVert *v, int lvl, int x, int dataSize)
+{
+       int levelBase = lvl + (1 << lvl) - 1;
+       if (v == e->v0) {
+               return &EDGE_getLevelData(e)[dataSize * (levelBase + x)];
+       }
+       else {
+               return &EDGE_getLevelData(e)[dataSize * (levelBase + (1 << lvl) - x)];
        }
 }
 
-static void _edge_free(CCGEdge *e, CCGSubSurf *ss) {
+static void _edge_free(CCGEdge *e, CCGSubSurf *ss)
+{
        CCGSUBSURF_free(ss, e->faces);
        CCGSUBSURF_free(ss, e);
 }
-static void _edge_unlinkMarkAndFree(CCGEdge *e, CCGSubSurf *ss) {
+static void _edge_unlinkMarkAndFree(CCGEdge *e, CCGSubSurf *ss)
+{
        _vert_remEdge(e->v0, e);
        _vert_remEdge(e->v1, e);
        e->v0->flags |= Vert_eEffected;
@@ -503,7 +546,8 @@ static void _edge_unlinkMarkAndFree(CCGEdge *e, CCGSubSurf *ss) {
        _edge_free(e, ss);
 }
 
-static float EDGE_getSharpness(CCGEdge *e, int lvl) {
+static float EDGE_getSharpness(CCGEdge *e, int lvl)
+{
        if (!lvl)
                return e->crease;
        else if (!e->crease)
@@ -514,9 +558,15 @@ static float EDGE_getSharpness(CCGEdge *e, int lvl) {
                return e->crease - lvl;
 }
 
-static CCGFace *_face_new(CCGFaceHDL fHDL, CCGVert **verts, CCGEdge **edges, int numVerts, CCGSubSurf *ss) {
-       int maxGridSize = 1 + (1<<(ss->subdivLevels-1));
-       CCGFace *f = CCGSUBSURF_alloc(ss, sizeof(CCGFace) + sizeof(CCGVert*)*numVerts + sizeof(CCGEdge*)*numVerts + ss->meshIFC.vertDataSize *(1 + numVerts*maxGridSize + numVerts*maxGridSize*maxGridSize) + ss->meshIFC.faceUserSize);
+static CCGFace *_face_new(CCGFaceHDL fHDL, CCGVert **verts, CCGEdge **edges, int numVerts, CCGSubSurf *ss)
+{
+       int maxGridSize = 1 + (1 << (ss->subdivLevels - 1));
+       CCGFace *f = CCGSUBSURF_alloc(ss,
+                                     sizeof(CCGFace) +
+                                     sizeof(CCGVert*) * numVerts +
+                                     sizeof(CCGEdge*) * numVerts +
+                                     ss->meshIFC.vertDataSize * (1 + numVerts * maxGridSize + numVerts * maxGridSize * maxGridSize) +
+                                     ss->meshIFC.faceUserSize);
        byte *userData;
        int i;
 
@@ -524,7 +574,7 @@ static CCGFace *_face_new(CCGFaceHDL fHDL, CCGVert **verts, CCGEdge **edges, int
        f->fHDL = fHDL;
        f->flags = 0;
 
-       for (i=0; i<numVerts; i++) {
+       for (i = 0; i < numVerts; i++) {
                FACE_getVerts(f)[i] = verts[i];
                FACE_getEdges(f)[i] = edges[i];
                _vert_addFace(verts[i], f, ss);
@@ -538,102 +588,115 @@ static CCGFace *_face_new(CCGFaceHDL fHDL, CCGVert **verts, CCGEdge **edges, int
        return f;
 }
 
-static CCG_INLINE void *_face_getIECo(CCGFace *f, int lvl, int S, int x, int levels, int dataSize) {
-       int maxGridSize = 1 + (1<<(levels-1));
-       int spacing = 1<<(levels-lvl);
-       byte *gridBase = FACE_getCenterData(f) + dataSize*(1 + S*(maxGridSize + maxGridSize*maxGridSize));
-       return &gridBase[dataSize*x*spacing];
+static CCG_INLINE void *_face_getIECo(CCGFace *f, int lvl, int S, int x, int levels, int dataSize)
+{
+       int maxGridSize = 1 + (1 << (levels - 1));
+       int spacing = 1 << (levels - lvl);
+       byte *gridBase = FACE_getCenterData(f) + dataSize * (1 + S * (maxGridSize + maxGridSize * maxGridSize));
+       return &gridBase[dataSize * x * spacing];
 }
-static CCG_INLINE void *_face_getIENo(CCGFace *f, int lvl, int S, int x, int levels, int dataSize, int normalDataOffset) {
-       int maxGridSize = 1 + (1<<(levels-1));
-       int spacing = 1<<(levels-lvl);
-       byte *gridBase = FACE_getCenterData(f) + dataSize*(1 + S*(maxGridSize + maxGridSize*maxGridSize));
-       return &gridBase[dataSize*x*spacing + normalDataOffset];
+static CCG_INLINE void *_face_getIENo(CCGFace *f, int lvl, int S, int x, int levels, int dataSize, int normalDataOffset)
+{
+       int maxGridSize = 1 + (1 << (levels - 1));
+       int spacing = 1 << (levels - lvl);
+       byte *gridBase = FACE_getCenterData(f) + dataSize * (1 + S * (maxGridSize + maxGridSize * maxGridSize));
+       return &gridBase[dataSize * x * spacing + normalDataOffset];
 }
-static CCG_INLINE void *_face_getIFCo(CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize) {
-       int maxGridSize = 1 + (1<<(levels-1));
-       int spacing = 1<<(levels-lvl);
-       byte *gridBase = FACE_getCenterData(f) + dataSize*(1 + S*(maxGridSize + maxGridSize*maxGridSize));
-       return &gridBase[dataSize*(maxGridSize + (y*maxGridSize + x)*spacing)];
+static CCG_INLINE void *_face_getIFCo(CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize)
+{
+       int maxGridSize = 1 + (1 << (levels - 1));
+       int spacing = 1 << (levels - lvl);
+       byte *gridBase = FACE_getCenterData(f) + dataSize * (1 + S * (maxGridSize + maxGridSize * maxGridSize));
+       return &gridBase[dataSize * (maxGridSize + (y * maxGridSize + x) * spacing)];
 }
-static CCG_INLINE float *_face_getIFNo(CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize, int normalDataOffset) {
-       int maxGridSize = 1 + (1<<(levels-1));
-       int spacing = 1<<(levels-lvl);
-       byte *gridBase = FACE_getCenterData(f) + dataSize*(1 + S*(maxGridSize + maxGridSize*maxGridSize));
-       return (float*) &gridBase[dataSize*(maxGridSize + (y*maxGridSize + x)*spacing) + normalDataOffset];
+static CCG_INLINE float *_face_getIFNo(CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize, int normalDataOffset)
+{
+       int maxGridSize = 1 + (1 << (levels - 1));
+       int spacing = 1 << (levels - lvl);
+       byte *gridBase = FACE_getCenterData(f) + dataSize * (1 + S * (maxGridSize + maxGridSize * maxGridSize));
+       return (float *) &gridBase[dataSize * (maxGridSize + (y * maxGridSize + x) * spacing) + normalDataOffset];
 }
-static int _face_getVertIndex(CCGFace *f, CCGVert *v) {
+static int _face_getVertIndex(CCGFace *f, CCGVert *v)
+{
        int i;
-       for (i=0; i<f->numVerts; i++)
-               if (FACE_getVerts(f)[i]==v)
+       for (i = 0; i < f->numVerts; i++)
+               if (FACE_getVerts(f)[i] == v)
                        return i;
        return -1;
 }
-static CCG_INLINE void *_face_getIFCoEdge(CCGFace *f, CCGEdge *e, int lvl, int eX, int eY, int levels, int dataSize) {
-       int maxGridSize = 1 + (1<<(levels-1));
-       int spacing = 1<<(levels-lvl);
+static CCG_INLINE void *_face_getIFCoEdge(CCGFace *f, CCGEdge *e, int lvl, int eX, int eY, int levels, int dataSize)
+{
+       int maxGridSize = 1 + (1 << (levels - 1));
+       int spacing = 1 << (levels - lvl);
        int S, x, y, cx, cy;
 
-       for (S=0; S<f->numVerts; S++)
-               if (FACE_getEdges(f)[S]==e)
+       for (S = 0; S < f->numVerts; S++)
+               if (FACE_getEdges(f)[S] == e)
                        break;
 
-       eX = eX*spacing;
-       eY = eY*spacing;
+       eX = eX * spacing;
+       eY = eY * spacing;
        if (e->v0!=FACE_getVerts(f)[S]) {
-               eX = (maxGridSize*2 - 1)-1 - eX;
+               eX = (maxGridSize * 2 - 1) - 1 - eX;
        }
        y = maxGridSize - 1 - eX;
        x = maxGridSize - 1 - eY;
        if (x<0) {
-               S = (S+f->numVerts-1)%f->numVerts;
+               S = (S + f->numVerts - 1) % f->numVerts;
                cx = y;
                cy = -x;
-       } else if (y<0) {
-               S = (S+1)%f->numVerts;
+       }
+       else if (y < 0) {
+               S = (S + 1) % f->numVerts;
                cx = -y;
                cy = x;
-       } else {
+       }
+       else {
                cx = x;
                cy = y;
        }
        return _face_getIFCo(f, levels, S, cx, cy, levels, dataSize);
 }
-static float *_face_getIFNoEdge(CCGFace *f, CCGEdge *e, int lvl, int eX, int eY, int levels, int dataSize, int normalDataOffset) {
-       return (float*) ((byte*) _face_getIFCoEdge(f, e, lvl, eX, eY, levels, dataSize) + normalDataOffset);
+static float *_face_getIFNoEdge(CCGFace *f, CCGEdge *e, int lvl, int eX, int eY, int levels, int dataSize, int normalDataOffset)
+{
+       return (float *) ((byte *) _face_getIFCoEdge(f, e, lvl, eX, eY, levels, dataSize) + normalDataOffset);
 }
-static void _face_calcIFNo(CCGFace *f, int lvl, int S, int x, int y, float *no, int levels, int dataSize) {
-       float *a = _face_getIFCo(f, lvl, S, x+0, y+0, levels, dataSize);
-       float *b = _face_getIFCo(f, lvl, S, x+1, y+0, levels, dataSize);
-       float *c = _face_getIFCo(f, lvl, S, x+1, y+1, levels, dataSize);
-       float *d = _face_getIFCo(f, lvl, S, x+0, y+1, levels, dataSize);
+static void _face_calcIFNo(CCGFace *f, int lvl, int S, int x, int y, float *no, int levels, int dataSize)
+{
+       float *a = _face_getIFCo(f, lvl, S, x + 0, y + 0, levels, dataSize);
+       float *b = _face_getIFCo(f, lvl, S, x + 1, y + 0, levels, dataSize);
+       float *c = _face_getIFCo(f, lvl, S, x + 1, y + 1, levels, dataSize);
+       float *d = _face_getIFCo(f, lvl, S, x + 0, y + 1, levels, dataSize);
        float a_cX = c[0]-a[0], a_cY = c[1]-a[1], a_cZ = c[2]-a[2];
        float b_dX = d[0]-b[0], b_dY = d[1]-b[1], b_dZ = d[2]-b[2];
        float length;
 
-       no[0] = b_dY*a_cZ - b_dZ*a_cY;
-       no[1] = b_dZ*a_cX - b_dX*a_cZ;
-       no[2] = b_dX*a_cY - b_dY*a_cX;
+       no[0] = b_dY * a_cZ - b_dZ * a_cY;
+       no[1] = b_dZ * a_cX - b_dX * a_cZ;
+       no[2] = b_dX * a_cY - b_dY * a_cX;
 
-       length = sqrt(no[0]*no[0] + no[1]*no[1] + no[2]*no[2]);
+       length = sqrt(no[0] * no[0] + no[1] * no[1] + no[2] * no[2]);
 
-       if (length>EPSILON) {
+       if (length > EPSILON) {
                float invLength = 1.f/length;
 
                no[0] *= invLength;
                no[1] *= invLength;
                no[2] *= invLength;
-       } else {
+       }
+       else {
                NormZero(no);
        }
 }
 
-static void _face_free(CCGFace *f, CCGSubSurf *ss) {
+static void _face_free(CCGFace *f, CCGSubSurf *ss)
+{
        CCGSUBSURF_free(ss, f);
 }
-static void _face_unlinkMarkAndFree(CCGFace *f, CCGSubSurf *ss) {
+static void _face_unlinkMarkAndFree(CCGFace *f, CCGSubSurf *ss)
+{
        int j;
-       for (j=0; j<f->numVerts; j++) {
+       for (j = 0; j < f->numVerts; j++) {
                _vert_remFace(FACE_getVerts(f)[j], f);
                _edge_remFace(FACE_getEdges(f)[j], f);
                FACE_getVerts(f)[j]->flags |= Vert_eEffected;
@@ -643,7 +706,8 @@ static void _face_unlinkMarkAndFree(CCGFace *f, CCGSubSurf *ss) {
 
 /***/
 
-CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int subdivLevels, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator) {
+CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int subdivLevels, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator)
+{
        if (!allocatorIFC) {
                allocatorIFC = _getStandardAllocatorIFC();
                allocator = NULL;
@@ -651,7 +715,8 @@ CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int subdivLevels, CCGAllocatorIFC *a
 
        if (subdivLevels<1) {
                return NULL;
-       } else {
+       }
+       else {
                CCGSubSurf *ss = allocatorIFC->alloc(allocator, sizeof(*ss));
 
                ss->allocatorIFC = *allocatorIFC;
@@ -691,7 +756,8 @@ CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int subdivLevels, CCGAllocatorIFC *a
        }
 }
 
-void ccgSubSurf_free(CCGSubSurf *ss) {
+void ccgSubSurf_free(CCGSubSurf *ss)
+{
        CCGAllocatorIFC allocatorIFC = ss->allocatorIFC;
        CCGAllocatorHDL allocator = ss->allocator;
 
@@ -719,7 +785,8 @@ void ccgSubSurf_free(CCGSubSurf *ss) {
        }
 }
 
-CCGError ccgSubSurf_setAllowEdgeCreation(CCGSubSurf *ss, int allowEdgeCreation, float defaultCreaseValue, void *defaultUserData) {
+CCGError ccgSubSurf_setAllowEdgeCreation(CCGSubSurf *ss, int allowEdgeCreation, float defaultCreaseValue, void *defaultUserData)
+{
        if (ss->defaultEdgeUserData) {
                CCGSUBSURF_free(ss, ss->defaultEdgeUserData);
        }
@@ -730,13 +797,15 @@ CCGError ccgSubSurf_setAllowEdgeCreation(CCGSubSurf *ss, int allowEdgeCreation,
 
        if (defaultUserData) {
                memcpy(ss->defaultEdgeUserData, defaultUserData, ss->meshIFC.edgeUserSize);
-       } else {
+       }
+       else {
                memset(ss->defaultEdgeUserData, 0, ss->meshIFC.edgeUserSize);
        }
 
        return eCCGError_None;
 }
-void ccgSubSurf_getAllowEdgeCreation(CCGSubSurf *ss, int *allowEdgeCreation_r, float *defaultCreaseValue_r, void *defaultUserData_r) {
+void ccgSubSurf_getAllowEdgeCreation(CCGSubSurf *ss, int *allowEdgeCreation_r, float *defaultCreaseValue_r, void *defaultUserData_r)
+{
        if (allowEdgeCreation_r) *allowEdgeCreation_r = ss->allowEdgeCreation;
        if (ss->allowEdgeCreation) {
                if (defaultCreaseValue_r) *defaultCreaseValue_r = ss->defaultCreaseValue;
@@ -744,10 +813,12 @@ void ccgSubSurf_getAllowEdgeCreation(CCGSubSurf *ss, int *allowEdgeCreation_r, f
        }
 }
 
-CCGError ccgSubSurf_setSubdivisionLevels(CCGSubSurf *ss, int subdivisionLevels) {
+CCGError ccgSubSurf_setSubdivisionLevels(CCGSubSurf *ss, int subdivisionLevels)
+{
        if (subdivisionLevels<=0) {
                return eCCGError_InvalidValue;
-       } else if (subdivisionLevels!=ss->subdivLevels) {
+       }
+       else if (subdivisionLevels!=ss->subdivLevels) {
                ss->numGrids = 0;
                ss->subdivLevels = subdivisionLevels;
                _ehash_free(ss->vMap, (EHEntryFreeFP) _vert_free, ss);
@@ -770,19 +841,23 @@ void ccgSubSurf_getUseAgeCounts(CCGSubSurf *ss, int *useAgeCounts_r, int *vertUs
        if (faceUserOffset_r) *faceUserOffset_r = ss->faceUserAgeOffset;
 }
 
-CCGError ccgSubSurf_setUseAgeCounts(CCGSubSurf *ss, int useAgeCounts, int vertUserOffset, int edgeUserOffset, int faceUserOffset) {
+CCGError ccgSubSurf_setUseAgeCounts(CCGSubSurf *ss, int useAgeCounts, int vertUserOffset, int edgeUserOffset, int faceUserOffset)
+{
        if (useAgeCounts) {
-               if (    (vertUserOffset+4>ss->meshIFC.vertUserSize) ||
-                               (edgeUserOffset+4>ss->meshIFC.edgeUserSize) ||
-                               (faceUserOffset+4>ss->meshIFC.faceUserSize)) {
+               if ((vertUserOffset + 4 > ss->meshIFC.vertUserSize) ||
+                   (edgeUserOffset + 4 > ss->meshIFC.edgeUserSize) ||
+                   (faceUserOffset + 4 > ss->meshIFC.faceUserSize))
+               {
                        return eCCGError_InvalidValue;
-               }  else {
+               }
+               else {
                        ss->useAgeCounts = 1;
                        ss->vertUserAgeOffset = vertUserOffset;
                        ss->edgeUserAgeOffset = edgeUserOffset;
                        ss->faceUserAgeOffset = faceUserOffset;
                }
-       } else {
+       }
+       else {
                ss->useAgeCounts = 0;
                ss->vertUserAgeOffset = ss->edgeUserAgeOffset = ss->faceUserAgeOffset = 0;
        }
@@ -790,15 +865,18 @@ CCGError ccgSubSurf_setUseAgeCounts(CCGSubSurf *ss, int useAgeCounts, int vertUs
        return eCCGError_None;
 }
 
-CCGError ccgSubSurf_setCalcVertexNormals(CCGSubSurf *ss, int useVertNormals, int normalDataOffset) {
+CCGError ccgSubSurf_setCalcVertexNormals(CCGSubSurf *ss, int useVertNormals, int normalDataOffset)
+{
        if (useVertNormals) {
-               if (normalDataOffset<0 || normalDataOffset+12>ss->meshIFC.vertDataSize) {
+               if (normalDataOffset<0 || normalDataOffset + 12>ss->meshIFC.vertDataSize) {
                        return eCCGError_InvalidValue;
-               } else {
+               }
+               else {
                        ss->calcVertNormals = 1;
                        ss->normalDataOffset = normalDataOffset;
                }
-       } else {
+       }
+       else {
                ss->calcVertNormals = 0;
                ss->normalDataOffset = 0;
        }
@@ -808,7 +886,8 @@ CCGError ccgSubSurf_setCalcVertexNormals(CCGSubSurf *ss, int useVertNormals, int
 
 /***/
 
-CCGError ccgSubSurf_initFullSync(CCGSubSurf *ss) {
+CCGError ccgSubSurf_initFullSync(CCGSubSurf *ss)
+{
        if (ss->syncState!=eSyncState_None) {
                return eCCGError_InvalidSyncState;
        }
@@ -826,15 +905,16 @@ CCGError ccgSubSurf_initFullSync(CCGSubSurf *ss) {
        ss->numGrids = 0;
 
        ss->lenTempArrays = 12;
-       ss->tempVerts = MEM_mallocN(sizeof(*ss->tempVerts)*ss->lenTempArrays, "CCGSubsurf tempVerts");
-       ss->tempEdges = MEM_mallocN(sizeof(*ss->tempEdges)*ss->lenTempArrays, "CCGSubsurf tempEdges");
+       ss->tempVerts = MEM_mallocN(sizeof(*ss->tempVerts) * ss->lenTempArrays, "CCGSubsurf tempVerts");
+       ss->tempEdges = MEM_mallocN(sizeof(*ss->tempEdges) * ss->lenTempArrays, "CCGSubsurf tempEdges");
 
        ss->syncState = eSyncState_Vert;
 
        return eCCGError_None;
 }
 
-CCGError ccgSubSurf_initPartialSync(CCGSubSurf *ss) {
+CCGError ccgSubSurf_initPartialSync(CCGSubSurf *ss)
+{
        if (ss->syncState!=eSyncState_None) {
                return eCCGError_InvalidSyncState;
        }
@@ -846,16 +926,19 @@ CCGError ccgSubSurf_initPartialSync(CCGSubSurf *ss) {
        return eCCGError_None;
 }
 
-CCGError ccgSubSurf_syncVertDel(CCGSubSurf *ss, CCGVertHDL vHDL) {
+CCGError ccgSubSurf_syncVertDel(CCGSubSurf *ss, CCGVertHDL vHDL)
+{
        if (ss->syncState!=eSyncState_Partial) {
                return eCCGError_InvalidSyncState;
-       } else {
+       }
+       else {
                void **prevp;
                CCGVert *v = _ehash_lookupWithPrev(ss->vMap, vHDL, &prevp);
 
                if (!v || v->numFaces || v->numEdges) {
                        return eCCGError_InvalidValue;
-               } else {
+               }
+               else {
                        *prevp = v->next;
                        _vert_free(v, ss);
                }
@@ -864,16 +947,19 @@ CCGError ccgSubSurf_syncVertDel(CCGSubSurf *ss, CCGVertHDL vHDL) {
        return eCCGError_None;
 }
 
-CCGError ccgSubSurf_syncEdgeDel(CCGSubSurf *ss, CCGEdgeHDL eHDL) {
+CCGError ccgSubSurf_syncEdgeDel(CCGSubSurf *ss, CCGEdgeHDL eHDL)
+{
        if (ss->syncState!=eSyncState_Partial) {
                return eCCGError_InvalidSyncState;
-       } else {
+       }
+       else {
                void **prevp;
                CCGEdge *e = _ehash_lookupWithPrev(ss->eMap, eHDL, &prevp);
 
                if (!e || e->numFaces) {
                        return eCCGError_InvalidValue;
-               } else {
+               }
+               else {
                        *prevp = e->next;
                        _edge_unlinkMarkAndFree(e, ss);
                }
@@ -882,16 +968,19 @@ CCGError ccgSubSurf_syncEdgeDel(CCGSubSurf *ss, CCGEdgeHDL eHDL) {
        return eCCGError_None;
 }
 
-CCGError ccgSubSurf_syncFaceDel(CCGSubSurf *ss, CCGFaceHDL fHDL) {
+CCGError ccgSubSurf_syncFaceDel(CCGSubSurf *ss, CCGFaceHDL fHDL)
+{
        if (ss->syncState!=eSyncState_Partial) {
                return eCCGError_InvalidSyncState;
-       } else {
+       }
+       else {
                void **prevp;
                CCGFace *f = _ehash_lookupWithPrev(ss->fMap, fHDL, &prevp);
 
                if (!f) {
                        return eCCGError_InvalidValue;
-               } else {
+               }
+               else {
                        *prevp = f->next;
                        _face_unlinkMarkAndFree(f, ss);
                }
@@ -900,37 +989,40 @@ CCGError ccgSubSurf_syncFaceDel(CCGSubSurf *ss, CCGFaceHDL fHDL) {
        return eCCGError_None;
 }
 
-CCGError ccgSubSurf_syncVert(CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertData, int seam, CCGVert **v_r) {
+CCGError ccgSubSurf_syncVert(CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertData, int seam, CCGVert **v_r)
+{
        void **prevp;
        CCGVert *v = NULL;
        short seamflag = (seam)? Vert_eSeam: 0;
        
-       if (ss->syncState==eSyncState_Partial) {
+       if (ss->syncState == eSyncState_Partial) {
                v = _ehash_lookupWithPrev(ss->vMap, vHDL, &prevp);
                if (!v) {
                        v = _vert_new(vHDL, ss);
                        VertDataCopy(_vert_getCo(v,0,ss->meshIFC.vertDataSize), vertData);
                        _ehash_insert(ss->vMap, (EHEntry*) v);
                        v->flags = Vert_eEffected|seamflag;
-               } else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize)) || ((v->flags & Vert_eSeam) != seamflag)) {
+               }
+               else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize)) || ((v->flags & Vert_eSeam) != seamflag)) {
                        int i, j;
 
                        VertDataCopy(_vert_getCo(v,0,ss->meshIFC.vertDataSize), vertData);
                        v->flags = Vert_eEffected|seamflag;
 
-                       for (i=0; i<v->numEdges; i++) {
+                       for (i = 0; i < v->numEdges; i++) {
                                CCGEdge *e = v->edges[i];
                                e->v0->flags |= Vert_eEffected;
                                e->v1->flags |= Vert_eEffected;
                        }
-                       for (i=0; i<v->numFaces; i++) {
+                       for (i = 0; i < v->numFaces; i++) {
                                CCGFace *f = v->faces[i];
-                               for (j=0; j<f->numVerts; j++) {
+                               for (j = 0; j < f->numVerts; j++) {
                                        FACE_getVerts(f)[j]->flags |= Vert_eEffected;
                                }
                        }
                }
-       } else {
+       }
+       else {
                if (ss->syncState!=eSyncState_Vert) { 
                        return eCCGError_InvalidSyncState;
                }
@@ -941,12 +1033,14 @@ CCGError ccgSubSurf_syncVert(CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertDa
                        VertDataCopy(_vert_getCo(v,0,ss->meshIFC.vertDataSize), vertData);
                        _ehash_insert(ss->vMap, (EHEntry*) v);
                        v->flags = Vert_eEffected|seamflag;
-               } else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize)) || ((v->flags & Vert_eSeam) != seamflag)) {
+               }
+               else if (!VertDataEqual(vertData, _vert_getCo(v, 0, ss->meshIFC.vertDataSize)) || ((v->flags & Vert_eSeam) != seamflag)) {
                        *prevp = v->next;
                        _ehash_insert(ss->vMap, (EHEntry*) v);
                        VertDataCopy(_vert_getCo(v,0,ss->meshIFC.vertDataSize), vertData);
                        v->flags = Vert_eEffected|Vert_eChanged|seamflag;
-               } else {
+               }
+               else {
                        *prevp = v->next;
                        _ehash_insert(ss->vMap, (EHEntry*) v);
                        v->flags = 0;
@@ -957,11 +1051,12 @@ CCGError ccgSubSurf_syncVert(CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertDa
        return eCCGError_None;
 }
 
-CCGError ccgSubSurf_syncEdge(CCGSubSurf *ss, CCGEdgeHDL eHDL, CCGVertHDL e_vHDL0, CCGVertHDL e_vHDL1, float crease, CCGEdge **e_r) {
+CCGError ccgSubSurf_syncEdge(CCGSubSurf *ss, CCGEdgeHDL eHDL, CCGVertHDL e_vHDL0, CCGVertHDL e_vHDL1, float crease, CCGEdge **e_r)
+{
        void **prevp;
        CCGEdge *e = NULL, *eNew;
 
-       if (ss->syncState==eSyncState_Partial) {
+       if (ss->syncState == eSyncState_Partial) {
                e = _ehash_lookupWithPrev(ss->eMap, eHDL, &prevp);
                if (!e || e->v0->vHDL!=e_vHDL0 || e->v1->vHDL!=e_vHDL1 || crease!=e->crease) {
                        CCGVert *v0 = _ehash_lookup(ss->vMap, e_vHDL0);
@@ -974,17 +1069,20 @@ CCGError ccgSubSurf_syncEdge(CCGSubSurf *ss, CCGEdgeHDL eHDL, CCGVertHDL e_vHDL0
                                eNew->next = e->next;
 
                                _edge_unlinkMarkAndFree(e, ss);
-                       } else {
+                       }
+                       else {
                                _ehash_insert(ss->eMap, (EHEntry*) eNew);
                        }
 
                        eNew->v0->flags |= Vert_eEffected;
                        eNew->v1->flags |= Vert_eEffected;
                }
-       } else {
-               if (ss->syncState==eSyncState_Vert) {
+       }
+       else {
+               if (ss->syncState == eSyncState_Vert) {
                        ss->syncState = eSyncState_Edge;
-               } else if (ss->syncState!=eSyncState_Edge) {
+               }
+               else if (ss->syncState!=eSyncState_Edge) {
                        return eCCGError_InvalidSyncState;
                }
 
@@ -996,7 +1094,8 @@ CCGError ccgSubSurf_syncEdge(CCGSubSurf *ss, CCGEdgeHDL eHDL, CCGVertHDL e_vHDL0
                        _ehash_insert(ss->eMap, (EHEntry*) e);
                        e->v0->flags |= Vert_eEffected;
                        e->v1->flags |= Vert_eEffected;
-               } else {
+               }
+               else {
                        *prevp = e->next;
                        _ehash_insert(ss->eMap, (EHEntry*) e);
                        e->flags = 0;
@@ -1011,31 +1110,32 @@ CCGError ccgSubSurf_syncEdge(CCGSubSurf *ss, CCGEdgeHDL eHDL, CCGVertHDL e_vHDL0
        return eCCGError_None;
 }
 
-CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGVertHDL *vHDLs, CCGFace **f_r) {
+CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGVertHDL *vHDLs, CCGFace **f_r)
+{
        void **prevp;
        CCGFace *f = NULL, *fNew;
        int j, k, topologyChanged = 0;
 
-       if (numVerts>ss->lenTempArrays) {
-               ss->lenTempArrays = (numVerts<ss->lenTempArrays*2)?ss->lenTempArrays*2:numVerts;
-               ss->tempVerts = MEM_reallocN(ss->tempVerts, sizeof(*ss->tempVerts)*ss->lenTempArrays);
-               ss->tempEdges = MEM_reallocN(ss->tempEdges, sizeof(*ss->tempEdges)*ss->lenTempArrays);
+       if (numVerts > ss->lenTempArrays) {
+               ss->lenTempArrays = (numVerts < ss->lenTempArrays * 2) ? ss->lenTempArrays * 2 : numVerts;
+               ss->tempVerts = MEM_reallocN(ss->tempVerts, sizeof(*ss->tempVerts) * ss->lenTempArrays);
+               ss->tempEdges = MEM_reallocN(ss->tempEdges, sizeof(*ss->tempEdges) * ss->lenTempArrays);
        }
 
-       if (ss->syncState==eSyncState_Partial) {
+       if (ss->syncState == eSyncState_Partial) {
                f = _ehash_lookupWithPrev(ss->fMap, fHDL, &prevp);
 
-               for (k=0; k<numVerts; k++) {
+               for (k = 0; k < numVerts; k++) {
                        ss->tempVerts[k] = _ehash_lookup(ss->vMap, vHDLs[k]);
                }
-               for (k=0; k<numVerts; k++) {
-                       ss->tempEdges[k] = _vert_findEdgeTo(ss->tempVerts[k], ss->tempVerts[(k+1)%numVerts]);
+               for (k = 0; k < numVerts; k++) {
+                       ss->tempEdges[k] = _vert_findEdgeTo(ss->tempVerts[k], ss->tempVerts[(k + 1) % numVerts]);
                }
 
                if (f) {
                        if (    f->numVerts!=numVerts ||
-                                       memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts)*numVerts) ||
-                                       memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges)*numVerts))
+                                       memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts) * numVerts) ||
+                                       memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges) * numVerts))
                                topologyChanged = 1;
                }
 
@@ -1049,42 +1149,46 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGV
                                fNew->next = f->next;
 
                                _face_unlinkMarkAndFree(f, ss);
-                       } else {
+                       }
+                       else {
                                ss->numGrids += numVerts;
                                _ehash_insert(ss->fMap, (EHEntry*) fNew);
                        }
 
-                       for (k=0; k<numVerts; k++)
+                       for (k = 0; k < numVerts; k++)
                                FACE_getVerts(fNew)[k]->flags |= Vert_eEffected;
                }
-       } else {
-               if (ss->syncState==eSyncState_Vert || ss->syncState==eSyncState_Edge) {
+       }
+       else {
+               if (ss->syncState == eSyncState_Vert || ss->syncState == eSyncState_Edge) {
                        ss->syncState = eSyncState_Face;
-               } else if (ss->syncState!=eSyncState_Face) {
+               }
+               else if (ss->syncState!=eSyncState_Face) {
                        return eCCGError_InvalidSyncState;
                }
 
                f = _ehash_lookupWithPrev(ss->oldFMap, fHDL, &prevp);
 
-               for (k=0; k<numVerts; k++) {
+               for (k = 0; k < numVerts; k++) {
                        ss->tempVerts[k] = _ehash_lookup(ss->vMap, vHDLs[k]);
 
                        if (!ss->tempVerts[k])
                                return eCCGError_InvalidValue;
                }
-               for (k=0; k<numVerts; k++) {
-                       ss->tempEdges[k] = _vert_findEdgeTo(ss->tempVerts[k], ss->tempVerts[(k+1)%numVerts]);
+               for (k = 0; k < numVerts; k++) {
+                       ss->tempEdges[k] = _vert_findEdgeTo(ss->tempVerts[k], ss->tempVerts[(k + 1) % numVerts]);
 
                        if (!ss->tempEdges[k]) {
                                if (ss->allowEdgeCreation) {
-                                       CCGEdge *e = ss->tempEdges[k] = _edge_new((CCGEdgeHDL) -1, ss->tempVerts[k], ss->tempVerts[(k+1)%numVerts], ss->defaultCreaseValue, ss);
+                                       CCGEdge *e = ss->tempEdges[k] = _edge_new((CCGEdgeHDL) -1, ss->tempVerts[k], ss->tempVerts[(k + 1) % numVerts], ss->defaultCreaseValue, ss);
                                        _ehash_insert(ss->eMap, (EHEntry*) e);
                                        e->v0->flags |= Vert_eEffected;
                                        e->v1->flags |= Vert_eEffected;
                                        if (ss->meshIFC.edgeUserSize) {
                                                memcpy(ccgSubSurf_getEdgeUserData(ss, e), ss->defaultEdgeUserData, ss->meshIFC.edgeUserSize);
                                        }
-                               } else {
+                               }
+                               else {
                                        return eCCGError_InvalidValue;
                                }
                        }
@@ -1092,8 +1196,8 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGV
 
                if (f) {
                        if (    f->numVerts!=numVerts ||
-                                       memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts)*numVerts) ||
-                                       memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges)*numVerts))
+                                       memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts) * numVerts) ||
+                                       memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges) * numVerts))
                                topologyChanged = 1;
                }
 
@@ -1102,17 +1206,18 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGV
                        _ehash_insert(ss->fMap, (EHEntry*) f);
                        ss->numGrids += numVerts;
 
-                       for (k=0; k<numVerts; k++)
+                       for (k = 0; k < numVerts; k++)
                                FACE_getVerts(f)[k]->flags |= Vert_eEffected;
-               } else {
+               }
+               else {
                        *prevp = f->next;
                        _ehash_insert(ss->fMap, (EHEntry*) f);
                        f->flags = 0;
                        ss->numGrids += f->numVerts;
 
-                       for (j=0; j<f->numVerts; j++) {
-                               if (FACE_getVerts(f)[j]->flags&Vert_eChanged) {
-                                       for (k=0; k<f->numVerts; k++)
+                       for (j = 0; j < f->numVerts; j++) {
+                               if (FACE_getVerts(f)[j]->flags & Vert_eChanged) {
+                                       for (k = 0; k < f->numVerts; k++)
                                                FACE_getVerts(f)[k]->flags |= Vert_eEffected;
                                        break;
                                }
@@ -1125,12 +1230,14 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGV
 }
 
 static void ccgSubSurf__sync(CCGSubSurf *ss);
-CCGError ccgSubSurf_processSync(CCGSubSurf *ss) {
-       if (ss->syncState==eSyncState_Partial) {
+CCGError ccgSubSurf_processSync(CCGSubSurf *ss)
+{
+       if (ss->syncState == eSyncState_Partial) {
                ss->syncState = eSyncState_None;
 
                ccgSubSurf__sync(ss);
-       } else if (ss->syncState) {
+       }
+       else if (ss->syncState) {
                _ehash_free(ss->oldFMap, (EHEntryFreeFP) _face_unlinkMarkAndFree, ss);
                _ehash_free(ss->oldEMap, (EHEntryFreeFP) _edge_unlinkMarkAndFree, ss);
                _ehash_free(ss->oldVMap, (EHEntryFreeFP) _vert_free, ss);
@@ -1146,7 +1253,8 @@ CCGError ccgSubSurf_processSync(CCGSubSurf *ss) {
                ss->syncState = eSyncState_None;
 
                ccgSubSurf__sync(ss);
-       } else {
+       }
+       else {
                return eCCGError_InvalidSyncState;
        }
 
@@ -1164,130 +1272,133 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss,
        int i,ptrIdx;
        int subdivLevels = ss->subdivLevels;
        int lvl = ss->subdivLevels;
-       int edgeSize = 1 + (1<<lvl);
-       int gridSize = 1 + (1<<(lvl-1));
+       int edgeSize = 1 + (1 << lvl);
+       int gridSize = 1 + (1 << (lvl - 1));
        int normalDataOffset = ss->normalDataOffset;
        int vertDataSize = ss->meshIFC.vertDataSize;
 
-       #pragma omp parallel for private(ptrIdx) if(numEffectedF*edgeSize*edgeSize*4 >= CCG_OMP_LIMIT)
-       for (ptrIdx=0; ptrIdx<numEffectedF; ptrIdx++) {
+       #pragma omp parallel for private(ptrIdx) if (numEffectedF * edgeSize * edgeSize * 4 >= CCG_OMP_LIMIT)
+       for (ptrIdx = 0; ptrIdx < numEffectedF; ptrIdx++) {
                CCGFace *f = (CCGFace*) effectedF[ptrIdx];
                int S, x, y;
                float no[3];
 
-               for (S=0; S<f->numVerts; S++) {
-                       for (y=0; y<gridSize-1; y++)
-                               for (x=0; x<gridSize-1; x++)
+               for (S = 0; S < f->numVerts; S++) {
+                       for (y = 0; y < gridSize - 1; y++)
+                               for (x = 0; x < gridSize - 1; x++)
                                        NormZero(FACE_getIFNo(f, lvl, S, x, y));
 
-                       if (FACE_getEdges(f)[(S-1+f->numVerts)%f->numVerts]->flags&Edge_eEffected)
-                               for (x=0; x<gridSize-1; x++)
-                                       NormZero(FACE_getIFNo(f, lvl, S, x, gridSize-1));
+                       if (FACE_getEdges(f)[(S - 1+f->numVerts)%f->numVerts]->flags&Edge_eEffected)
+                               for (x = 0; x < gridSize - 1; x++)
+                                       NormZero(FACE_getIFNo(f, lvl, S, x, gridSize - 1));
                        if (FACE_getEdges(f)[S]->flags&Edge_eEffected)
-                               for (y=0; y<gridSize-1; y++)
-                                       NormZero(FACE_getIFNo(f, lvl, S, gridSize-1, y));
+                               for (y = 0; y < gridSize - 1; y++)
+                                       NormZero(FACE_getIFNo(f, lvl, S, gridSize - 1, y));
                        if (FACE_getVerts(f)[S]->flags&Vert_eEffected)
-                               NormZero(FACE_getIFNo(f, lvl, S, gridSize-1, gridSize-1));
+                               NormZero(FACE_getIFNo(f, lvl, S, gridSize - 1, gridSize - 1));
                }
 
-               for (S=0; S<f->numVerts; S++) {
-                       int yLimit = !(FACE_getEdges(f)[(S-1+f->numVerts)%f->numVerts]->flags&Edge_eEffected);
+               for (S = 0; S < f->numVerts; S++) {
+                       int yLimit = !(FACE_getEdges(f)[(S - 1 + f->numVerts) % f->numVerts]->flags & Edge_eEffected);
                        int xLimit = !(FACE_getEdges(f)[S]->flags&Edge_eEffected);
                        int yLimitNext = xLimit;
                        int xLimitPrev = yLimit;
                        
-                       for (y=0; y<gridSize - 1; y++) {
-                               for (x=0; x<gridSize - 1; x++) {
-                                       int xPlusOk = (!xLimit || x<gridSize-2);
-                                       int yPlusOk = (!yLimit || y<gridSize-2);
+                       for (y = 0; y < gridSize - 1; y++) {
+                               for (x = 0; x < gridSize - 1; x++) {
+                                       int xPlusOk = (!xLimit || x < gridSize - 2);
+                                       int yPlusOk = (!yLimit || y < gridSize - 2);
 
                                        FACE_calcIFNo(f, lvl, S, x, y, no);
 
-                                       NormAdd(FACE_getIFNo(f, lvl, S, x+0, y+0), no);
+                                       NormAdd(FACE_getIFNo(f, lvl, S, x + 0, y + 0), no);
                                        if (xPlusOk)
-                                               NormAdd(FACE_getIFNo(f, lvl, S, x+1, y+0), no);
+                                               NormAdd(FACE_getIFNo(f, lvl, S, x + 1, y + 0), no);
                                        if (yPlusOk)
-                                               NormAdd(FACE_getIFNo(f, lvl, S, x+0, y+1), no);
+                                               NormAdd(FACE_getIFNo(f, lvl, S, x + 0, y + 1), no);
                                        if (xPlusOk && yPlusOk) {
-                                               if (x<gridSize-2 || y<gridSize-2 || FACE_getVerts(f)[S]->flags&Vert_eEffected) {
-                                                       NormAdd(FACE_getIFNo(f, lvl, S, x+1, y+1), no);
+                                               if (x < gridSize - 2 || y < gridSize - 2 || FACE_getVerts(f)[S]->flags & Vert_eEffected) {
+                                                       NormAdd(FACE_getIFNo(f, lvl, S, x + 1, y + 1), no);
                                                }
                                        }
 
-                                       if (x==0 && y==0) {
+                                       if (x == 0 && y == 0) {
                                                int K;
 
-                                               if (!yLimitNext || 1<gridSize-1)
-                                                       NormAdd(FACE_getIFNo(f, lvl, (S+1)%f->numVerts, 0, 1), no);
-                                               if (!xLimitPrev || 1<gridSize-1)
-                                                       NormAdd(FACE_getIFNo(f, lvl, (S-1+f->numVerts)%f->numVerts, 1, 0), no);
+                                               if (!yLimitNext || 1<gridSize - 1)
+                                                       NormAdd(FACE_getIFNo(f, lvl, (S + 1) % f->numVerts, 0, 1), no);
+                                               if (!xLimitPrev || 1<gridSize - 1)
+                                                       NormAdd(FACE_getIFNo(f, lvl, (S - 1 + f->numVerts) % f->numVerts, 1, 0), no);
 
-                                               for (K=0; K<f->numVerts; K++) {
+                                               for (K = 0; K < f->numVerts; K++) {
                                                        if (K!=S) {
                                                                NormAdd(FACE_getIFNo(f, lvl, K, 0, 0), no);
                                                        }
                                                }
-                                       } else if (y==0) {
-                                               NormAdd(FACE_getIFNo(f, lvl, (S+1)%f->numVerts, 0, x), no);
-                                               if (!yLimitNext || x<gridSize-2)
-                                                       NormAdd(FACE_getIFNo(f, lvl, (S+1)%f->numVerts, 0, x+1), no);
-                                       } else if (x==0) {
-                                               NormAdd(FACE_getIFNo(f, lvl, (S-1+f->numVerts)%f->numVerts, y, 0), no);
-                                               if (!xLimitPrev || y<gridSize-2)
-                                                       NormAdd(FACE_getIFNo(f, lvl, (S-1+f->numVerts)%f->numVerts, y+1, 0), no);
+                                       }
+                                       else if (y == 0) {
+                                               NormAdd(FACE_getIFNo(f, lvl, (S + 1) % f->numVerts, 0, x), no);
+                                               if (!yLimitNext || x < gridSize - 2)
+                                                       NormAdd(FACE_getIFNo(f, lvl, (S + 1) % f->numVerts, 0, x + 1), no);
+                                       }
+                                       else if (x == 0) {
+                                               NormAdd(FACE_getIFNo(f, lvl, (S - 1 + f->numVerts) % f->numVerts, y, 0), no);
+                                               if (!xLimitPrev || y < gridSize - 2)
+                                                       NormAdd(FACE_getIFNo(f, lvl, (S - 1 + f->numVerts) % f->numVerts, y + 1, 0), no);
                                        }
                                }
                        }
                }
        }
                // XXX can I reduce the number of normalisations here?
-       for (ptrIdx=0; ptrIdx<numEffectedV; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
                CCGVert *v = (CCGVert*) effectedV[ptrIdx];
                float length, *no = _vert_getNo(v, lvl, vertDataSize, normalDataOffset);
 
                NormZero(no);
 
-               for (i=0; i<v->numFaces; i++) {
+               for (i = 0; i < v->numFaces; i++) {
                        CCGFace *f = v->faces[i];
-                       NormAdd(no, FACE_getIFNo(f, lvl, _face_getVertIndex(f,v), gridSize-1, gridSize-1));
+                       NormAdd(no, FACE_getIFNo(f, lvl, _face_getVertIndex(f,v), gridSize - 1, gridSize - 1));
                }
 
-               length = sqrt(no[0]*no[0] + no[1]*no[1] + no[2]*no[2]);
+               length = sqrt(no[0] * no[0] + no[1] * no[1] + no[2] * no[2]);
 
-               if (length>EPSILON) {
+               if (length > EPSILON) {
                        float invLength = 1.0f/length;
                        no[0] *= invLength;
                        no[1] *= invLength;
                        no[2] *= invLength;
-               } else {
+               }
+               else {
                        NormZero(no);
                }
 
-               for (i=0; i<v->numFaces; i++) {
+               for (i = 0; i < v->numFaces; i++) {
                        CCGFace *f = v->faces[i];
-                       NormCopy(FACE_getIFNo(f, lvl, _face_getVertIndex(f,v), gridSize-1, gridSize-1), no);
+                       NormCopy(FACE_getIFNo(f, lvl, _face_getVertIndex(f,v), gridSize - 1, gridSize - 1), no);
                }
        }
-       for (ptrIdx=0; ptrIdx<numEffectedE; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
                CCGEdge *e = (CCGEdge*) effectedE[ptrIdx];
 
                if (e->numFaces) {
-                       CCGFace *fLast = e->faces[e->numFaces-1];
+                       CCGFace *fLast = e->faces[e->numFaces - 1];
                        int x;
 
-                       for (i=0; i<e->numFaces-1; i++) {
+                       for (i = 0; i < e->numFaces - 1; i++) {
                                CCGFace *f = e->faces[i];
 
-                               for (x=1; x<edgeSize-1; x++) {
+                               for (x = 1; x < edgeSize - 1; x++) {
                                        NormAdd(_face_getIFNoEdge(fLast, e, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset),
                                                        _face_getIFNoEdge(f, e, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset));
                                }
                        }
 
-                       for (i=0; i<e->numFaces-1; i++) {
+                       for (i = 0; i < e->numFaces - 1; i++) {
                                CCGFace *f = e->faces[i];
 
-                               for (x=1; x<edgeSize-1; x++) {
+                               for (x = 1; x < edgeSize - 1; x++) {
                                        NormCopy(_face_getIFNoEdge(f, e, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset),
                                                        _face_getIFNoEdge(fLast, e, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset));
                                }
@@ -1295,50 +1406,51 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss,
                }
        }
 
-       #pragma omp parallel for private(ptrIdx) if(numEffectedF*edgeSize*edgeSize*4 >= CCG_OMP_LIMIT)
-       for (ptrIdx=0; ptrIdx<numEffectedF; ptrIdx++) {
+       #pragma omp parallel for private(ptrIdx) if (numEffectedF * edgeSize * edgeSize * 4 >= CCG_OMP_LIMIT)
+       for (ptrIdx = 0; ptrIdx < numEffectedF; ptrIdx++) {
                CCGFace *f = (CCGFace*) effectedF[ptrIdx];
                int S, x, y;
 
-               for (S=0; S<f->numVerts; S++) {
-                       NormCopy(FACE_getIFNo(f, lvl, (S+1)%f->numVerts, 0, gridSize-1),
-                                        FACE_getIFNo(f, lvl, S, gridSize-1, 0));
+               for (S = 0; S < f->numVerts; S++) {
+                       NormCopy(FACE_getIFNo(f, lvl, (S + 1) % f->numVerts, 0, gridSize - 1),
+                                FACE_getIFNo(f, lvl, S, gridSize - 1, 0));
                }
 
-               for (S=0; S<f->numVerts; S++) {
-                       for (y=0; y<gridSize; y++) {
-                               for (x=0; x<gridSize; x++) {
+               for (S = 0; S < f->numVerts; S++) {
+                       for (y = 0; y < gridSize; y++) {
+                               for (x = 0; x < gridSize; x++) {
                                        float *no = FACE_getIFNo(f, lvl, S, x, y);
-                                       float length = sqrt(no[0]*no[0] + no[1]*no[1] + no[2]*no[2]);
+                                       float length = sqrt(no[0] * no[0] + no[1] * no[1] + no[2] * no[2]);
 
-                                       if (length>EPSILON) {
+                                       if (length > EPSILON) {
                                                float invLength = 1.0f/length;
                                                no[0] *= invLength;
                                                no[1] *= invLength;
                                                no[2] *= invLength;
-                                       } else {
+                                       }
+                                       else {
                                                NormZero(no);
                                        }
                                }
                        }
 
-                       VertDataCopy((float*)((byte*)FACE_getCenterData(f) + normalDataOffset),
+                       VertDataCopy((float *)((byte *)FACE_getCenterData(f) + normalDataOffset),
                                FACE_getIFNo(f, lvl, S, 0, 0));
 
-                       for (x=1; x<gridSize-1; x++)
+                       for (x = 1; x < gridSize - 1; x++)
                                NormCopy(FACE_getIENo(f, lvl, S, x),
                                        FACE_getIFNo(f, lvl, S, x, 0));
                }
        }
 
-       for (ptrIdx=0; ptrIdx<numEffectedE; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
                CCGEdge *e = (CCGEdge*) effectedE[ptrIdx];
 
                if (e->numFaces) {
                        CCGFace *f = e->faces[0];
                        int x;
 
-                       for (x=0; x<edgeSize; x++)
+                       for (x = 0; x < edgeSize; x++)
                                NormCopy(EDGE_getNo(e, lvl, x),
                                        _face_getIFNoEdge(f, e, lvl, x, 0, subdivLevels, vertDataSize, normalDataOffset));
                }
@@ -1349,7 +1461,7 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss,
                         * most likely not used so just zero out. */
                        int x;
 
-                       for (x=0; x<edgeSize; x++) {
+                       for (x = 0; x < edgeSize; x++) {
                                NormZero(EDGE_getNo(e, lvl, x));
                        }
                }
@@ -1361,34 +1473,36 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss,
 #define EDGE_getCo(e, lvl, x)                  _edge_getCo(e, lvl, x, vertDataSize)
 #define FACE_getIECo(f, lvl, S, x)             _face_getIECo(f, lvl, S, x, subdivLevels, vertDataSize)
 #define FACE_getIFCo(f, lvl, S, x, y)  _face_getIFCo(f, lvl, S, x, y, subdivLevels, vertDataSize)
+
 static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
-       CCGVert **effectedV, CCGEdge **effectedE, CCGFace **effectedF,
-       int numEffectedV, int numEffectedE, int numEffectedF, int curLvl) {
+                                        CCGVert **effectedV, CCGEdge **effectedE, CCGFace **effectedF,
+                                        int numEffectedV, int numEffectedE, int numEffectedF, int curLvl)
+{
        int subdivLevels = ss->subdivLevels;
-       int edgeSize = 1 + (1<<curLvl);
-       int gridSize = 1 + (1<<(curLvl-1));
-       int nextLvl = curLvl+1;
+       int edgeSize = 1 + (1 << curLvl);
+       int gridSize = 1 + (1 << (curLvl - 1));
+       int nextLvl = curLvl + 1;
        int ptrIdx, cornerIdx, i;
        int vertDataSize = ss->meshIFC.vertDataSize;
        void *q = ss->q, *r = ss->r;
 
-       #pragma omp parallel for private(ptrIdx) if(numEffectedF*edgeSize*edgeSize*4 >= CCG_OMP_LIMIT)
-       for (ptrIdx=0; ptrIdx<numEffectedF; ptrIdx++) {
+       #pragma omp parallel for private(ptrIdx) if (numEffectedF * edgeSize * edgeSize * 4 >= CCG_OMP_LIMIT)
+       for (ptrIdx = 0; ptrIdx < numEffectedF; ptrIdx++) {
                CCGFace *f = (CCGFace*) effectedF[ptrIdx];
                int S, x, y;
 
                        /* interior face midpoints
                         *  o old interior face points
                         */
-               for (S=0; S<f->numVerts; S++) {
-                       for (y=0; y<gridSize-1; y++) {
-                               for (x=0; x<gridSize-1; x++) {
+               for (S = 0; S < f->numVerts; S++) {
+                       for (y = 0; y < gridSize - 1; y++) {
+                               for (x = 0; x < gridSize - 1; x++) {
                                        int fx = 1 + 2*x;
                                        int fy = 1 + 2*y;
-                                       void *co0 = FACE_getIFCo(f, curLvl, S, x+0, y+0);
-                                       void *co1 = FACE_getIFCo(f, curLvl, S, x+1, y+0);
-                                       void *co2 = FACE_getIFCo(f, curLvl, S, x+1, y+1);
-                                       void *co3 = FACE_getIFCo(f, curLvl, S, x+0, y+1);
+                                       void *co0 = FACE_getIFCo(f, curLvl, S, x + 0, y + 0);
+                                       void *co1 = FACE_getIFCo(f, curLvl, S, x + 1, y + 0);
+                                       void *co2 = FACE_getIFCo(f, curLvl, S, x + 1, y + 1);
+                                       void *co3 = FACE_getIFCo(f, curLvl, S, x + 0, y + 1);
                                        void *co = FACE_getIFCo(f, nextLvl, S, fx, fy);
 
                                        VertDataAvg4(co, co0, co1, co2, co3);
@@ -1400,14 +1514,14 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                         *  o old interior edge points
                         *  o new interior face midpoints
                         */
-               for (S=0; S<f->numVerts; S++) {
-                       for (x=0; x<gridSize-1; x++) {
-                               int fx = x*2 + 1;
-                               void *co0 = FACE_getIECo(f, curLvl, S, x+0);
-                               void *co1 = FACE_getIECo(f, curLvl, S, x+1);
-                               void *co2 = FACE_getIFCo(f, nextLvl, (S+1)%f->numVerts, 1, fx);
+               for (S = 0; S < f->numVerts; S++) {
+                       for (x = 0; x < gridSize - 1; x++) {
+                               int fx = x * 2 + 1;
+                               void *co0 = FACE_getIECo(f, curLvl, S, x + 0);
+                               void *co1 = FACE_getIECo(f, curLvl, S, x + 1);
+                               void *co2 = FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 1, fx);
                                void *co3 = FACE_getIFCo(f, nextLvl, S, fx, 1);
-                               void *co = FACE_getIECo(f, nextLvl, S, fx);
+                               void *co  = FACE_getIECo(f, nextLvl, S, fx);
                                
                                VertDataAvg4(co, co0, co1, co2, co3);
                        }
@@ -1418,30 +1532,30 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                                         */
 
                                /* vertical */
-                       for (x=1; x<gridSize-1; x++) {
-                               for (y=0; y<gridSize-1; y++) {
-                                       int fx = x*2;
-                                       int fy = y*2+1;
-                                       void *co0 = FACE_getIFCo(f, curLvl, S, x, y+0);
-                                       void *co1 = FACE_getIFCo(f, curLvl, S, x, y+1);
-                                       void *co2 = FACE_getIFCo(f, nextLvl, S, fx-1, fy);
-                                       void *co3 = FACE_getIFCo(f, nextLvl, S, fx+1, fy);
-                                       void *co = FACE_getIFCo(f, nextLvl, S, fx, fy);
+                       for (x = 1; x < gridSize - 1; x++) {
+                               for (y = 0; y < gridSize - 1; y++) {
+                                       int fx = x * 2;
+                                       int fy = y * 2 + 1;
+                                       void *co0 = FACE_getIFCo(f, curLvl, S, x, y + 0);
+                                       void *co1 = FACE_getIFCo(f, curLvl, S, x, y + 1);
+                                       void *co2 = FACE_getIFCo(f, nextLvl, S, fx - 1, fy);
+                                       void *co3 = FACE_getIFCo(f, nextLvl, S, fx + 1, fy);
+                                       void *co  = FACE_getIFCo(f, nextLvl, S, fx, fy);
 
                                        VertDataAvg4(co, co0, co1, co2, co3);
                                }
                        }
 
                                /* horizontal */
-                       for (y=1; y<gridSize-1; y++) {
-                               for (x=0; x<gridSize-1; x++) {
-                                       int fx = x*2+1;
-                                       int fy = y*2;
-                                       void *co0 = FACE_getIFCo(f, curLvl, S, x+0, y);
-                                       void *co1 = FACE_getIFCo(f, curLvl, S, x+1, y);
-                                       void *co2 = FACE_getIFCo(f, nextLvl, S, fx, fy-1);
-                                       void *co3 = FACE_getIFCo(f, nextLvl, S, fx, fy+1);
-                                       void *co = FACE_getIFCo(f, nextLvl, S, fx, fy);
+                       for (y = 1; y < gridSize - 1; y++) {
+                               for (x = 0; x < gridSize - 1; x++) {
+                                       int fx = x * 2 + 1;
+                                       int fy = y * 2;
+                                       void *co0 = FACE_getIFCo(f, curLvl, S, x + 0, y);
+                                       void *co1 = FACE_getIFCo(f, curLvl, S, x + 1, y);
+                                       void *co2 = FACE_getIFCo(f, nextLvl, S, fx, fy - 1);
+                                       void *co3 = FACE_getIFCo(f, nextLvl, S, fx, fy + 1);
+                                       void *co  = FACE_getIFCo(f, nextLvl, S, fx, fy);
 
                                        VertDataAvg4(co, co0, co1, co2, co3);
                                }
@@ -1453,40 +1567,41 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                 *  o old exterior edge points
                 *  o new interior face midpoints
                 */
-       for (ptrIdx=0; ptrIdx<numEffectedE; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
                CCGEdge *e = (CCGEdge*) effectedE[ptrIdx];
                float sharpness = EDGE_getSharpness(e, curLvl);
                int x, j;
 
                if (_edge_isBoundary(e) || sharpness > 1.0f) {
-                       for (x=0; x<edgeSize-1; x++) {
-                               int fx = x*2 + 1;
-                               void *co0 = EDGE_getCo(e, curLvl, x+0);
-                               void *co1 = EDGE_getCo(e, curLvl, x+1);
-                               void *co = EDGE_getCo(e, nextLvl, fx);
+                       for (x = 0; x < edgeSize - 1; x++) {
+                               int fx = x * 2 + 1;
+                               void *co0 = EDGE_getCo(e, curLvl, x + 0);
+                               void *co1 = EDGE_getCo(e, curLvl, x + 1);
+                               void *co  = EDGE_getCo(e, nextLvl, fx);
 
                                VertDataCopy(co, co0);
                                VertDataAdd(co, co1);
                                VertDataMulN(co, 0.5f);
                        }
-               } else {
-                       for (x=0; x<edgeSize-1; x++) {
-                               int fx = x*2 + 1;
-                               void *co0 = EDGE_getCo(e, curLvl, x+0);
-                               void *co1 = EDGE_getCo(e, curLvl, x+1);
-                               void *co = EDGE_getCo(e, nextLvl, fx);
+               }
+               else {
+                       for (x = 0; x < edgeSize - 1; x++) {
+                               int fx = x * 2 + 1;
+                               void *co0 = EDGE_getCo(e, curLvl, x + 0);
+                               void *co1 = EDGE_getCo(e, curLvl, x + 1);
+                               void *co  = EDGE_getCo(e, nextLvl, fx);
                                int numFaces = 0;
 
                                VertDataCopy(q, co0);
                                VertDataAdd(q, co1);
 
-                               for (j=0; j<e->numFaces; j++) {
+                               for (j = 0; j < e->numFaces; j++) {
                                        CCGFace *f = e->faces[j];
                                        VertDataAdd(q, _face_getIFCoEdge(f, e, nextLvl, fx, 1, subdivLevels, vertDataSize));
                                        numFaces++;
                                }
 
-                               VertDataMulN(q, 1.0f/(2.0f+numFaces));
+                               VertDataMulN(q, 1.0f / (2.0f + numFaces));
 
                                VertDataCopy(r, co0);
                                VertDataAdd(r, co1);
@@ -1505,7 +1620,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                 *  o old exterior edge points
                 *  o new interior face midpoints
                 */
-       for (ptrIdx=0; ptrIdx<numEffectedV; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
                CCGVert *v = (CCGVert*) effectedV[ptrIdx];
                void *co = VERT_getCo(v, curLvl);
                void *nCo = VERT_getCo(v, nextLvl);
@@ -1513,7 +1628,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                float avgSharpness = 0.0;
                int j, seam = VERT_seam(v), seamEdges = 0;
 
-               for (j=0; j<v->numEdges; j++) {
+               for (j = 0; j < v->numEdges; j++) {
                        CCGEdge *e = v->edges[j];
                        float sharpness = EDGE_getSharpness(e, curLvl);
 
@@ -1523,12 +1638,13 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                        if (sharpness!=0.0f) {
                                sharpCount++;
                                avgSharpness += sharpness;
-                       } else {
+                       }
+                       else {
                                allSharp = 0;
                        }
                }
 
-               if(sharpCount) {
+               if (sharpCount) {
                        avgSharpness /= sharpCount;
                        if (avgSharpness > 1.0f) {
                                avgSharpness = 1.0f;
@@ -1540,11 +1656,12 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
 
                if (!v->numEdges) {
                        VertDataCopy(nCo, co);
-               } else if (_vert_isBoundary(v)) {
+               }
+               else if (_vert_isBoundary(v)) {
                        int numBoundary = 0;
 
                        VertDataZero(r);
-                       for (j=0; j<v->numEdges; j++) {
+                       for (j = 0; j < v->numEdges; j++) {
                                CCGEdge *e = v->edges[j];
                                if (_edge_isBoundary(e)) {
                                        VertDataAdd(r, _edge_getCoVert(e, v, curLvl, 1, vertDataSize));
@@ -1556,19 +1673,20 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                        VertDataMulN(nCo, 0.75f);
                        VertDataMulN(r, 0.25f/numBoundary);
                        VertDataAdd(nCo, r);
-               } else {
-                       int cornerIdx = (1 + (1<<(curLvl))) - 2;
+               }
+               else {
+                       int cornerIdx = (1 + (1 << (curLvl))) - 2;
                        int numEdges = 0, numFaces = 0;
 
                        VertDataZero(q);
-                       for (j=0; j<v->numFaces; j++) {
+                       for (j = 0; j < v->numFaces; j++) {
                                CCGFace *f = v->faces[j];
                                VertDataAdd(q, FACE_getIFCo(f, nextLvl, _face_getVertIndex(f,v), cornerIdx, cornerIdx));
                                numFaces++;
                        }
                        VertDataMulN(q, 1.0f/numFaces);
                        VertDataZero(r);
-                       for (j=0; j<v->numEdges; j++) {
+                       for (j = 0; j < v->numEdges; j++) {
                                CCGEdge *e = v->edges[j];
                                VertDataAdd(r, _edge_getCoVert(e, v, curLvl, 1,vertDataSize));
                                numEdges++;
@@ -1576,7 +1694,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                        VertDataMulN(r, 1.0f/numEdges);
 
                        VertDataCopy(nCo, co);
-                       VertDataMulN(nCo, numEdges-2.0f);
+                       VertDataMulN(nCo, numEdges - 2.0f);
                        VertDataAdd(nCo, q);
                        VertDataAdd(nCo, r);
                        VertDataMulN(nCo, 1.0f/numEdges);
@@ -1591,14 +1709,15 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                                allSharp = 1;
                        }
 
-                       for (j=0; j<v->numEdges; j++) {
+                       for (j = 0; j < v->numEdges; j++) {
                                CCGEdge *e = v->edges[j];
                                float sharpness = EDGE_getSharpness(e, curLvl);
 
                                if (seam) {
                                        if (_edge_isBoundary(e))
                                                VertDataAdd(q, _edge_getCoVert(e, v, curLvl, 1, vertDataSize));
-                               } else if (sharpness != 0.0f) {
+                               }
+                               else if (sharpness != 0.0f) {
                                        VertDataAdd(q, _edge_getCoVert(e, v, curLvl, 1, vertDataSize));
                                }
                        }
@@ -1606,7 +1725,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                        VertDataMulN(q, (float) 1/sharpCount);
 
                        if (sharpCount!=2 || allSharp) {
-                                       // q = q + (co-q)*avgSharpness
+                                       // q = q + (co-q) * avgSharpness
                                VertDataCopy(r, co);
                                VertDataSub(r, q);
                                VertDataMulN(r, avgSharpness);
@@ -1619,7 +1738,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                        VertDataMulN(q, .25f);
                        VertDataAdd(r, q);
 
-                               // nCo = nCo  + (r-nCo)*avgSharpness
+                               // nCo = nCo  + (r-nCo) * avgSharpness
                        VertDataSub(r, nCo);
                        VertDataMulN(r, avgSharpness);
                        VertDataAdd(nCo, r);
@@ -1631,7 +1750,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                 *  o old exterior edge midpoints
                 *  o new interior face midpoints
                 */
-       for (ptrIdx=0; ptrIdx<numEffectedE; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
                CCGEdge *e = (CCGEdge*) effectedE[ptrIdx];
                float sharpness = EDGE_getSharpness(e, curLvl);
                int sharpCount = 0;
@@ -1645,57 +1764,59 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                        if (avgSharpness > 1.0f) {
                                avgSharpness = 1.0f;
                        }
-               } else {
+               }
+               else {
                        sharpCount = 0;
                        avgSharpness = 0;
                }
 
                if (_edge_isBoundary(e) && (!e->numFaces || sharpCount<2)) {
-                       for (x=1; x<edgeSize-1; x++) {
-                               int fx = x*2;
+                       for (x = 1; x < edgeSize - 1; x++) {
+                               int fx = x * 2;
                                void *co = EDGE_getCo(e, curLvl, x);
                                void *nCo = EDGE_getCo(e, nextLvl, fx);
-                               VertDataCopy(r, EDGE_getCo(e, curLvl, x-1));
-                               VertDataAdd(r, EDGE_getCo(e, curLvl, x+1));
+                               VertDataCopy(r, EDGE_getCo(e, curLvl, x - 1));
+                               VertDataAdd(r, EDGE_getCo(e, curLvl, x + 1));
                                VertDataMulN(r, 0.5f);
                                VertDataCopy(nCo, co);
                                VertDataMulN(nCo, 0.75f);
                                VertDataMulN(r, 0.25f);
                                VertDataAdd(nCo, r);
                        }
-               } else {
-                       for (x=1; x<edgeSize-1; x++) {
-                               int fx = x*2;
+               }
+               else {
+                       for (x = 1; x < edgeSize - 1; x++) {
+                               int fx = x * 2;
                                void *co = EDGE_getCo(e, curLvl, x);
                                void *nCo = EDGE_getCo(e, nextLvl, fx);
                                int numFaces = 0;
 
                                VertDataZero(q);
                                VertDataZero(r);
-                               VertDataAdd(r, EDGE_getCo(e, curLvl, x-1));
-                               VertDataAdd(r, EDGE_getCo(e, curLvl, x+1));
-                               for (j=0; j<e->numFaces; j++) {
+                               VertDataAdd(r, EDGE_getCo(e, curLvl, x - 1));
+                               VertDataAdd(r, EDGE_getCo(e, curLvl, x + 1));
+                               for (j = 0; j < e->numFaces; j++) {
                                        CCGFace *f = e->faces[j];
-                                       VertDataAdd(q, _face_getIFCoEdge(f, e, nextLvl, fx-1, 1, subdivLevels, vertDataSize));
-                                       VertDataAdd(q, _face_getIFCoEdge(f, e, nextLvl, fx+1, 1, subdivLevels, vertDataSize));
+                                       VertDataAdd(q, _face_getIFCoEdge(f, e, nextLvl, fx - 1, 1, subdivLevels, vertDataSize));
+                                       VertDataAdd(q, _face_getIFCoEdge(f, e, nextLvl, fx + 1, 1, subdivLevels, vertDataSize));
 
                                        VertDataAdd(r, _face_getIFCoEdge(f, e, curLvl, x, 1, subdivLevels, vertDataSize));
                                        numFaces++;
                                }
-                               VertDataMulN(q, 1.0f/(numFaces*2.0f));
-                               VertDataMulN(r, 1.0f/(2.0f + numFaces));
+                               VertDataMulN(q, 1.0f / (numFaces * 2.0f));
+                               VertDataMulN(r, 1.0f / (2.0f + numFaces));
 
                                VertDataCopy(nCo, co);
                                VertDataMulN(nCo, (float) numFaces);
                                VertDataAdd(nCo, q);
                                VertDataAdd(nCo, r);
-                               VertDataMulN(nCo, 1.0f/(2+numFaces));
+                               VertDataMulN(nCo, 1.0f / (2 + numFaces));
 
-                               if (sharpCount==2) {
+                               if (sharpCount == 2) {
                                        VertDataCopy(q, co);
                                        VertDataMulN(q, 6.0f);
-                                       VertDataAdd(q, EDGE_getCo(e, curLvl, x-1));
-                                       VertDataAdd(q, EDGE_getCo(e, curLvl, x+1));
+                                       VertDataAdd(q, EDGE_getCo(e, curLvl, x - 1));
+                                       VertDataAdd(q, EDGE_getCo(e, curLvl, x + 1));
                                        VertDataMulN(q, 1/8.0f);
 
                                        VertDataSub(q, nCo);
@@ -1706,7 +1827,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                }
        }
 
-       #pragma omp parallel private(ptrIdx) if(numEffectedF*edgeSize*edgeSize*4 >= CCG_OMP_LIMIT)
+       #pragma omp parallel private(ptrIdx) if (numEffectedF * edgeSize * edgeSize * 4 >= CCG_OMP_LIMIT)
        {
                void *q, *r;
 
@@ -1717,7 +1838,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                }
 
                #pragma omp for schedule(static)
-               for (ptrIdx=0; ptrIdx<numEffectedF; ptrIdx++) {
+               for (ptrIdx = 0; ptrIdx < numEffectedF; ptrIdx++) {
                        CCGFace *f = (CCGFace*) effectedF[ptrIdx];
                        int S, x, y;
 
@@ -1727,43 +1848,45 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                                 *  o new interior face midpoints
                                 */
                        VertDataZero(q);
-                       for (S=0; S<f->numVerts; S++) {
+                       for (S = 0; S < f->numVerts; S++) {
                                VertDataAdd(q, FACE_getIFCo(f, nextLvl, S, 1, 1));
                        }
                        VertDataMulN(q, 1.0f/f->numVerts);
                        VertDataZero(r);
-                       for (S=0; S<f->numVerts; S++) {
+                       for (S = 0; S < f->numVerts; S++) {
                                VertDataAdd(r, FACE_getIECo(f, curLvl, S, 1));
                        }
                        VertDataMulN(r, 1.0f/f->numVerts);
 
-                       VertDataMulN(FACE_getCenterData(f), f->numVerts-2.0f);
+                       VertDataMulN(FACE_getCenterData(f), f->numVerts - 2.0f);
                        VertDataAdd(FACE_getCenterData(f), q);
                        VertDataAdd(FACE_getCenterData(f), r);
                        VertDataMulN(FACE_getCenterData(f), 1.0f/f->numVerts);
 
-                       for (S=0; S<f->numVerts; S++) {
+                       for (S = 0; S < f->numVerts; S++) {
                                        /* interior face shift
                                         *  o old interior face point (shifting)
                                         *  o new interior edge midpoints
                                         *  o new interior face midpoints
                                         */
-                               for (x=1; x<gridSize-1; x++) {
-                                       for (y=1; y<gridSize-1; y++) {
-                                               int fx = x*2;
-                                               int fy = y*2;
+                               for (x = 1; x < gridSize - 1; x++) {
+                                       for (y = 1; y < gridSize - 1; y++) {
+                                               int fx = x * 2;
+                                               int fy = y * 2;
                                                void *co = FACE_getIFCo(f, curLvl, S, x, y);
                                                void *nCo = FACE_getIFCo(f, nextLvl, S, fx, fy);
                                                
-                                               VertDataAvg4(q, 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),
-                                                       FACE_getIFCo(f, nextLvl, S, fx-1, fy+1));
-
-                                               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));
+                                               VertDataAvg4(q,
+                                                            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),
+                                                            FACE_getIFCo(f, nextLvl, S, fx - 1, fy + 1));
+
+                                               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));
 
                                                VertDataCopy(nCo, co);
                                                VertDataSub(nCo, q);
@@ -1777,20 +1900,22 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
                                         *  o new interior edge midpoints
                                         *  o new interior face midpoints
                                         */
-                               for (x=1; x<gridSize-1; x++) {
-                                       int fx = x*2;
+                               for (x = 1; x < gridSize - 1; x++) {
+                                       int fx = x * 2;
                                        void *co = FACE_getIECo(f, curLvl, S, x);
                                        void *nCo = FACE_getIECo(f, nextLvl, S, fx);
                                        
-                                       VertDataAvg4(q, FACE_getIFCo(f, nextLvl, (S+1)%f->numVerts, 1, fx-1),
-                                               FACE_getIFCo(f, nextLvl, (S+1)%f->numVerts, 1, fx+1),
-                                               FACE_getIFCo(f, nextLvl, S, fx+1, +1),
-                                               FACE_getIFCo(f, nextLvl, S, fx-1, +1));
-
-                                       VertDataAvg4(r, FACE_getIECo(f, nextLvl, S, fx-1),
-                                               FACE_getIECo(f, nextLvl, S, fx+1),
-                                               FACE_getIFCo(f, nextLvl, (S+1)%f->numVerts, 1, fx),
-                                               FACE_getIFCo(f, nextLvl, S, fx, 1));
+                                       VertDataAvg4(q,
+                                                    FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 1, fx - 1),
+                                                    FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 1, fx + 1),
+                                                    FACE_getIFCo(f, nextLvl, S, fx + 1, + 1),
+                                                    FACE_getIFCo(f, nextLvl, S, fx - 1, + 1));
+
+                                       VertDataAvg4(r,
+                                                    FACE_getIECo(f, nextLvl, S, fx - 1),
+                                                    FACE_getIECo(f, nextLvl, S, fx + 1),
+                                                    FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 1, fx),
+                                                    FACE_getIFCo(f, nextLvl, S, fx, 1));
 
                                        VertDataCopy(nCo, co);
                                        VertDataSub(nCo, q);
@@ -1808,37 +1933,37 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
        }
 
                /* copy down */
-       edgeSize = 1 + (1<<(nextLvl));
-       gridSize = 1 + (1<<((nextLvl)-1));
-       cornerIdx = gridSize-1;
+       edgeSize = 1 + (1 << (nextLvl));
+       gridSize = 1 + (1 << ((nextLvl)-1));
+       cornerIdx = gridSize - 1;
 
-       #pragma omp parallel for private(i) if(numEffectedF*edgeSize*edgeSize*4 >= CCG_OMP_LIMIT)
-       for (i=0; i<numEffectedE; i++) {
+       #pragma omp parallel for private(i) if (numEffectedF * edgeSize * edgeSize * 4 >= CCG_OMP_LIMIT)
+       for (i = 0; i < numEffectedE; i++) {
                CCGEdge *e = effectedE[i];
                VertDataCopy(EDGE_getCo(e, nextLvl, 0), VERT_getCo(e->v0, nextLvl));
-               VertDataCopy(EDGE_getCo(e, nextLvl, edgeSize-1), VERT_getCo(e->v1, nextLvl));
+               VertDataCopy(EDGE_getCo(e, nextLvl, edgeSize - 1), VERT_getCo(e->v1, nextLvl));
        }
 
-       #pragma omp parallel for private(i) if(numEffectedF*edgeSize*edgeSize*4 >= CCG_OMP_LIMIT)
-       for (i=0; i<numEffectedF; i++) {
+       #pragma omp parallel for private(i) if (numEffectedF * edgeSize * edgeSize * 4 >= CCG_OMP_LIMIT)
+       for (i = 0; i < numEffectedF; i++) {
                CCGFace *f = effectedF[i];
                int S, x;
 
-               for (S=0; S<f->numVerts; S++) {
+               for (S = 0; S < f->numVerts; S++) {
                        CCGEdge *e = FACE_getEdges(f)[S];
-                       CCGEdge *prevE = FACE_getEdges(f)[(S+f->numVerts-1)%f->numVerts];
+                       CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts];
 
                        VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), FACE_getCenterData(f));
                        VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), FACE_getCenterData(f));
                        VertDataCopy(FACE_getIFCo(f, nextLvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], nextLvl));
                        VertDataCopy(FACE_getIECo(f, nextLvl, S, cornerIdx), EDGE_getCo(FACE_getEdges(f)[S], nextLvl, cornerIdx));
-                       for (x=1; x<gridSize-1; x++) {
+                       for (x = 1; x < gridSize - 1; x++) {
                                void *co = FACE_getIECo(f, nextLvl, S, x);
                                VertDataCopy(FACE_getIFCo(f, nextLvl, S, x, 0), co);
-                               VertDataCopy(FACE_getIFCo(f, nextLvl, (S+1)%f->numVerts, 0, x), co);
+                               VertDataCopy(FACE_getIFCo(f, nextLvl, (S + 1) % f->numVerts, 0, x), co);
                        }
-                       for (x=0; x<gridSize-1; x++) {
-                               int eI = gridSize-1-x;
+                       for (x = 0; x < gridSize - 1; x++) {
+                               int eI = gridSize - 1 - x;
                                VertDataCopy(FACE_getIFCo(f, nextLvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], nextLvl, eI,vertDataSize));
                                VertDataCopy(FACE_getIFCo(f, nextLvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], nextLvl, eI,vertDataSize));
                        }
@@ -1847,7 +1972,8 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss,
 }
 
 
-static void ccgSubSurf__sync(CCGSubSurf *ss) {
+static void ccgSubSurf__sync(CCGSubSurf *ss)
+{
        CCGVert **effectedV;
        CCGEdge **effectedE;
        CCGFace **effectedF;
@@ -1858,17 +1984,17 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
        int curLvl, nextLvl;
        void *q = ss->q, *r = ss->r;
 
-       effectedV = MEM_mallocN(sizeof(*effectedV)*ss->vMap->numEntries, "CCGSubsurf effectedV");
-       effectedE = MEM_mallocN(sizeof(*effectedE)*ss->eMap->numEntries, "CCGSubsurf effectedE");
-       effectedF = MEM_mallocN(sizeof(*effectedF)*ss->fMap->numEntries, "CCGSubsurf effectedF");
+       effectedV = MEM_mallocN(sizeof(*effectedV) * ss->vMap->numEntries, "CCGSubsurf effectedV");
+       effectedE = MEM_mallocN(sizeof(*effectedE) * ss->eMap->numEntries, "CCGSubsurf effectedE");
+       effectedF = MEM_mallocN(sizeof(*effectedF) * ss->fMap->numEntries, "CCGSubsurf effectedF");
        numEffectedV = numEffectedE = numEffectedF = 0;
-       for (i=0; i<ss->vMap->curSize; i++) {
+       for (i = 0; i < ss->vMap->curSize; i++) {
                CCGVert *v = (CCGVert*) ss->vMap->buckets[i];
                for (; v; v = v->next) {
                        if (v->flags&Vert_eEffected) {
                                effectedV[numEffectedV++] = v;
 
-                               for (j=0; j<v->numEdges; j++) {
+                               for (j = 0; j < v->numEdges; j++) {
                                        CCGEdge *e = v->edges[j];
                                        if (!(e->flags&Edge_eEffected)) {
                                                effectedE[numEffectedE++] = e;
@@ -1876,7 +2002,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                                        }
                                }
 
-                               for (j=0; j<v->numFaces; j++) {
+                               for (j = 0; j < v->numFaces; j++) {
                                        CCGFace *f = v->faces[j];
                                        if (!(f->flags&Face_eEffected)) {
                                                effectedF[numEffectedF++] = f;
@@ -1888,20 +2014,20 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
        }
 
        curLvl = 0;
-       nextLvl = curLvl+1;
+       nextLvl = curLvl + 1;
 
-       for (ptrIdx=0; ptrIdx<numEffectedF; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedF; ptrIdx++) {
                CCGFace *f = effectedF[ptrIdx];
                void *co = FACE_getCenterData(f);
                VertDataZero(co);
-               for (i=0; i<f->numVerts; i++) {
+               for (i = 0; i < f->numVerts; i++) {
                        VertDataAdd(co, VERT_getCo(FACE_getVerts(f)[i], curLvl));
                }
                VertDataMulN(co, 1.0f/f->numVerts);
 
                f->flags = 0;
        }
-       for (ptrIdx=0; ptrIdx<numEffectedE; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
                CCGEdge *e = effectedE[ptrIdx];
                void *co = EDGE_getCo(e, nextLvl, 1);
                float sharpness = EDGE_getSharpness(e, curLvl);
@@ -1910,16 +2036,17 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        VertDataCopy(co, VERT_getCo(e->v0, curLvl));
                        VertDataAdd(co, VERT_getCo(e->v1, curLvl));
                        VertDataMulN(co, 0.5f);
-               } else {
+               }
+               else {
                        int numFaces = 0;
                        VertDataCopy(q, VERT_getCo(e->v0, curLvl));
                        VertDataAdd(q, VERT_getCo(e->v1, curLvl));
-                       for (i=0; i<e->numFaces; i++) {
+                       for (i = 0; i < e->numFaces; i++) {
                                CCGFace *f = e->faces[i];
                                VertDataAdd(q, FACE_getCenterData(f));
                                numFaces++;
                        }
-                       VertDataMulN(q, 1.0f/(2.0f+numFaces));
+                       VertDataMulN(q, 1.0f / (2.0f + numFaces));
 
                        VertDataCopy(r, VERT_getCo(e->v0, curLvl));
                        VertDataAdd(r, VERT_getCo(e->v1, curLvl));
@@ -1933,7 +2060,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
 
                // edge flags cleared later
        }
-       for (ptrIdx=0; ptrIdx<numEffectedV; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
                CCGVert *v = effectedV[ptrIdx];
                void *co = VERT_getCo(v, curLvl);
                void *nCo = VERT_getCo(v, nextLvl);
@@ -1941,7 +2068,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                float avgSharpness = 0.0;
                int seam = VERT_seam(v), seamEdges = 0;
 
-               for (i=0; i<v->numEdges; i++) {
+               for (i = 0; i < v->numEdges; i++) {
                        CCGEdge *e = v->edges[i];
                        float sharpness = EDGE_getSharpness(e, curLvl);
 
@@ -1951,12 +2078,13 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        if (sharpness!=0.0f) {
                                sharpCount++;
                                avgSharpness += sharpness;
-                       } else {
+                       }
+                       else {
                                allSharp = 0;
                        }
                }
 
-               if(sharpCount) {
+               if (sharpCount) {
                        avgSharpness /= sharpCount;
                        if (avgSharpness > 1.0f) {
                                avgSharpness = 1.0f;
@@ -1968,11 +2096,12 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
 
                if (!v->numEdges) {
                        VertDataCopy(nCo, co);
-               } else if (_vert_isBoundary(v)) {
+               }
+               else if (_vert_isBoundary(v)) {
                        int numBoundary = 0;
 
                        VertDataZero(r);
-                       for (i=0; i<v->numEdges; i++) {
+                       for (i = 0; i < v->numEdges; i++) {
                                CCGEdge *e = v->edges[i];
                                if (_edge_isBoundary(e)) {
                                        VertDataAdd(r, VERT_getCo(_edge_getOtherVert(e, v), curLvl));
@@ -1983,18 +2112,19 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        VertDataMulN(nCo, 0.75f);
                        VertDataMulN(r, 0.25f/numBoundary);
                        VertDataAdd(nCo, r);
-               } else {
+               }
+               else {
                        int numEdges = 0, numFaces = 0;
 
                        VertDataZero(q);
-                       for (i=0; i<v->numFaces; i++) {
+                       for (i = 0; i < v->numFaces; i++) {
                                CCGFace *f = v->faces[i];
                                VertDataAdd(q, FACE_getCenterData(f));
                                numFaces++;
                        }
                        VertDataMulN(q, 1.0f/numFaces);
                        VertDataZero(r);
-                       for (i=0; i<v->numEdges; i++) {
+                       for (i = 0; i < v->numEdges; i++) {
                                CCGEdge *e = v->edges[i];
                                VertDataAdd(r, VERT_getCo(_edge_getOtherVert(e, v), curLvl));
                                numEdges++;
@@ -2002,7 +2132,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        VertDataMulN(r, 1.0f/numEdges);
 
                        VertDataCopy(nCo, co);
-                       VertDataMulN(nCo, numEdges-2.0f);
+                       VertDataMulN(nCo, numEdges - 2.0f);
                        VertDataAdd(nCo, q);
                        VertDataAdd(nCo, r);
                        VertDataMulN(nCo, 1.0f/numEdges);
@@ -2017,7 +2147,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                                allSharp = 1;
                        }
 
-                       for (i=0; i<v->numEdges; i++) {
+                       for (i = 0; i < v->numEdges; i++) {
                                CCGEdge *e = v->edges[i];
                                float sharpness = EDGE_getSharpness(e, curLvl);
 
@@ -2026,7 +2156,8 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                                                CCGVert *oV = _edge_getOtherVert(e, v);
                                                VertDataAdd(q, VERT_getCo(oV, curLvl));
                                        }
-                               } else if (sharpness != 0.0f) {
+                               }
+                               else if (sharpness != 0.0f) {
                                        CCGVert *oV = _edge_getOtherVert(e, v);
                                        VertDataAdd(q, VERT_getCo(oV, curLvl));
                                }
@@ -2035,7 +2166,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        VertDataMulN(q, (float) 1/sharpCount);
 
                        if (sharpCount!=2 || allSharp) {
-                                       // q = q + (co-q)*avgSharpness
+                                       // q = q + (co-q) * avgSharpness
                                VertDataCopy(r, co);
                                VertDataSub(r, q);
                                VertDataMulN(r, avgSharpness);
@@ -2048,7 +2179,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        VertDataMulN(q, 0.25f);
                        VertDataAdd(r, q);
 
-                               // nCo = nCo  + (r-nCo)*avgSharpness
+                               // nCo = nCo  + (r-nCo) * avgSharpness
                        VertDataSub(r, nCo);
                        VertDataMulN(r, avgSharpness);
                        VertDataAdd(nCo, r);
@@ -2058,35 +2189,35 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
        }
 
        if (ss->useAgeCounts) {
-               for (i=0; i<numEffectedV; i++) {
+               for (i = 0; i < numEffectedV; i++) {
                        CCGVert *v = effectedV[i];
                        byte *userData = ccgSubSurf_getVertUserData(ss, v);
                        *((int*) &userData[ss->vertUserAgeOffset]) = ss->currentAge;
                }
 
-               for (i=0; i<numEffectedE; i++) {
+               for (i = 0; i < numEffectedE; i++) {
                        CCGEdge *e = effectedE[i];
                        byte *userData = ccgSubSurf_getEdgeUserData(ss, e);
                        *((int*) &userData[ss->edgeUserAgeOffset]) = ss->currentAge;
                }
 
-               for (i=0; i<numEffectedF; i++) {
+               for (i = 0; i < numEffectedF; i++) {
                        CCGFace *f = effectedF[i];
                        byte *userData = ccgSubSurf_getFaceUserData(ss, f);
                        *((int*) &userData[ss->faceUserAgeOffset]) = ss->currentAge;
                }
        }
 
-       for (i=0; i<numEffectedE; i++) {
+       for (i = 0; i < numEffectedE; i++) {
                CCGEdge *e = effectedE[i];
                VertDataCopy(EDGE_getCo(e, nextLvl, 0), VERT_getCo(e->v0, nextLvl));
                VertDataCopy(EDGE_getCo(e, nextLvl, 2), VERT_getCo(e->v1, nextLvl));
        }
-       for (i=0; i<numEffectedF; i++) {
+       for (i = 0; i < numEffectedF; i++) {
                CCGFace *f = effectedF[i];
-               for (S=0; S<f->numVerts; S++) {
+               for (S = 0; S < f->numVerts; S++) {
                        CCGEdge *e = FACE_getEdges(f)[S];
-                       CCGEdge *prevE = FACE_getEdges(f)[(S+f->numVerts-1)%f->numVerts];
+                       CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts];
 
                        VertDataCopy(FACE_getIFCo(f, nextLvl, S, 0, 0), FACE_getCenterData(f));
                        VertDataCopy(FACE_getIECo(f, nextLvl, S, 0), FACE_getCenterData(f));
@@ -2098,7 +2229,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                }
        }
 
-       for (curLvl=1; curLvl<subdivLevels; curLvl++) {
+       for (curLvl = 1; curLvl < subdivLevels; curLvl++) {
                ccgSubSurf__calcSubdivLevel(ss,
                        effectedV, effectedE, effectedF,
                        numEffectedV, numEffectedE, numEffectedF, curLvl);
@@ -2109,11 +2240,11 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        effectedV, effectedE, effectedF,
                        numEffectedV, numEffectedE, numEffectedF);
 
-       for (ptrIdx=0; ptrIdx<numEffectedV; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedV; ptrIdx++) {
                CCGVert *v = effectedV[ptrIdx];
                v->flags = 0;
        }
-       for (ptrIdx=0; ptrIdx<numEffectedE; ptrIdx++) {
+       for (ptrIdx = 0; ptrIdx < numEffectedE; ptrIdx++) {
                CCGEdge *e = effectedE[ptrIdx];
                e->flags = 0;
        }
@@ -2128,10 +2259,10 @@ static void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces
        CCGFace **array;
        int i, num;
 
-       if(!*faces) {
-               array = MEM_mallocN(sizeof(*array)*ss->fMap->numEntries, "CCGSubsurf allFaces");
+       if (!*faces) {
+               array = MEM_mallocN(sizeof(*array) * ss->fMap->numEntries, "CCGSubsurf allFaces");
                num = 0;
-               for (i=0; i<ss->fMap->curSize; i++) {
+               for (i = 0; i < ss->fMap->curSize; i++) {
                        CCGFace *f = (CCGFace*) ss->fMap->buckets[i];
 
                        for (; f; f = f->next)
@@ -2140,10 +2271,11 @@ static void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces
 
                *faces = array;
                *numFaces = num;
-               *freeFaces= 1;
+               *freeFaces = 1;
+       }
+       else {
+               *freeFaces = 0;
        }
-       else
-               *freeFaces= 0;
 }
 
 static void ccgSubSurf__effectedFaceNeighbours(CCGSubSurf *ss, CCGFace **faces, int numFaces, CCGVert ***verts, int *numVerts, CCGEdge ***edges, int *numEdges)
@@ -2152,39 +2284,39 @@ static void ccgSubSurf__effectedFaceNeighbours(CCGSubSurf *ss, CCGFace **faces,
        CCGEdge **arrayE;
        int numV, numE, i, j;
 
-       arrayV = MEM_mallocN(sizeof(*arrayV)*ss->vMap->numEntries, "CCGSubsurf arrayV");
-       arrayE = MEM_mallocN(sizeof(*arrayE)*ss->eMap->numEntries, "CCGSubsurf arrayV");
+       arrayV = MEM_mallocN(sizeof(*arrayV) * ss->vMap->numEntries, "CCGSubsurf arrayV");
+       arrayE = MEM_mallocN(sizeof(*arrayE) * ss->eMap->numEntries, "CCGSubsurf arrayV");
        numV = numE = 0;
 
-       for (i=0; i<numFaces; i++) {
+       for (i = 0; i < numFaces; i++) {
                CCGFace *f = faces[i];
                f->flags |= Face_eEffected;
        }
 
-       for (i=0; i<ss->vMap->curSize; i++) {
+       for (i = 0; i < ss->vMap->curSize; i++) {
                CCGVert *v = (CCGVert*) ss->vMap->buckets[i];
 
                for (; v; v = v->next) {
-                       for(j=0; j<v->numFaces; j++)
-                               if(!(v->faces[j]->flags & Face_eEffected))
+                       for (j = 0; j < v->numFaces; j++)
+                               if (!(v->faces[j]->flags & Face_eEffected))
                                        break;
                        
-                       if(j == v->numFaces) {
+                       if (j == v->numFaces) {
                                arrayV[numV++] = v;
                                v->flags |= Vert_eEffected;
                        }
                }
        }
 
-       for (i=0; i<ss->eMap->curSize; i++) {
+       for (i = 0; i < ss->eMap->curSize; i++) {
                CCGEdge *e = (CCGEdge*) ss->eMap->buckets[i];
 
                for (; e; e = e->next) {
-                       for(j=0; j<e->numFaces; j++)
-                               if(!(e->faces[j]->flags & Face_eEffected))
+                       for (j = 0; j < e->numFaces; j++)
+                               if (!(e->faces[j]->flags & Face_eEffected))
                                        break;
                        
-                       if(j == e->numFaces) {
+                       if (j == e->numFaces) {
                                e->flags |= Edge_eEffected;
                                arrayE[numE++] = e;
                        }
@@ -2205,33 +2337,33 @@ CCGError ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF
 
        subdivLevels = ss->subdivLevels;
        lvl = (lvl)? lvl: subdivLevels;
-       gridSize = 1 + (1<<(lvl-1));
-       cornerIdx = gridSize-1;
+       gridSize = 1 + (1 << (lvl - 1));
+       cornerIdx = gridSize - 1;
 
        ccgSubSurf__allFaces(ss, &effectedF, &numEffectedF, &freeF);
 
-       for (i=0; i<numEffectedF; i++) {
+       for (i = 0; i < numEffectedF; i++) {
                CCGFace *f = effectedF[i];
 
-               for (S=0; S<f->numVerts; S++) {
+               for (S = 0; S < f->numVerts; S++) {
                        CCGEdge *e = FACE_getEdges(f)[S];
-                       CCGEdge *prevE = FACE_getEdges(f)[(S+f->numVerts-1)%f->numVerts];
+                       CCGEdge *prevE = FACE_getEdges(f)[(S + f->numVerts - 1) % f->numVerts];
 
                        VertDataCopy(FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0));
                        VertDataCopy(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx));
 
-                       for (x=0; x<gridSize; x++)
+                       for (x = 0; x < gridSize; x++)
                                VertDataCopy(FACE_getIECo(f, lvl, S, x), FACE_getIFCo(f, lvl, S, x, 0));
 
-                       for (x=0; x<gridSize; x++) {
-                               int eI = gridSize-1-x;
+                       for (x = 0; x < gridSize; x++) {
+                               int eI = gridSize - 1 - x;
                                VertDataCopy(_edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI,vertDataSize), FACE_getIFCo(f, lvl, S, cornerIdx, x));
                                VertDataCopy(_edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI,vertDataSize), FACE_getIFCo(f, lvl, S, x, cornerIdx));
                        }
                }
        }
 
-       if(freeF) MEM_freeN(effectedF);
+       if (freeF) MEM_freeN(effectedF);
 
        return eCCGError_None;
 }
@@ -2244,26 +2376,26 @@ CCGError ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF,
 
        subdivLevels = ss->subdivLevels;
        lvl = (lvl)? lvl: subdivLevels;
-       gridSize = 1 + (1<<(lvl-1));
-       cornerIdx = gridSize-1;
+       gridSize = 1 + (1 << (lvl - 1));
+       cornerIdx = gridSize - 1;
 
        ccgSubSurf__allFaces(ss, &effectedF, &numEffectedF, &freeF);
 
-       for (i=0; i<numEffectedF; i++) {
+       for (i = 0; i < numEffectedF; i++) {
                CCGFace *f = effectedF[i];
 
-               for (S=0; S<f->numVerts; S++) {
-                       int prevS = (S+f->numVerts-1)%f->numVerts;
+               for (S = 0; S < f->numVerts; S++) {
+                       int prevS = (S + f->numVerts - 1) % f->numVerts;
                        CCGEdge *e = FACE_getEdges(f)[S];
                        CCGEdge *prevE = FACE_getEdges(f)[prevS];
 
-                       for (x=0; x<gridSize; x++) {
-                               int eI = gridSize-1-x;
+                       for (x = 0; x < gridSize; x++) {
+                               int eI = gridSize - 1 - x;
                                VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI,vertDataSize));
                                VertDataCopy(FACE_getIFCo(f, lvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI,vertDataSize));
                        }
 
-                       for (x=1; x<gridSize-1; x++) {
+                       for (x = 1; x < gridSize - 1; x++) {
                                VertDataCopy(FACE_getIFCo(f, lvl, S, 0, x), FACE_getIECo(f, lvl, prevS, x));
                                VertDataCopy(FACE_getIFCo(f, lvl, S, x, 0), FACE_getIECo(f, lvl, S, x));
                        }
@@ -2273,7 +2405,7 @@ CCGError ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF,
                }
        }
 
-       if(freeF) MEM_freeN(effectedF);
+       if (freeF) MEM_freeN(effectedF);
 
        return eCCGError_None;
 }
@@ -2290,41 +2422,41 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in
 
        subdivLevels = ss->subdivLevels;
        lvl = (lvl)? lvl: subdivLevels;
-       gridSize = 1 + (1<<(lvl-1));
-       edgeSize = 1 + (1<<lvl);
-       cornerIdx = gridSize-1;
+       gridSize = 1 + (1 << (lvl - 1));
+       edgeSize = 1 + (1 << lvl);
+       cornerIdx = gridSize - 1;
 
        ccgSubSurf__allFaces(ss, &effectedF, &numEffectedF, &freeF);
        ccgSubSurf__effectedFaceNeighbours(ss, effectedF, numEffectedF,
                &effectedV, &numEffectedV, &effectedE, &numEffectedE);
 
        /* zero */
-       for (i=0; i<numEffectedV; i++) {
+       for (i = 0; i < numEffectedV; i++) {
                CCGVert *v = effectedV[i];
-               if(v->numFaces)
+               if (v->numFaces)
                        VertDataZero(VERT_getCo(v, lvl));
        }
 
-       for (i=0; i<numEffectedE; i++) {
+       for (i = 0; i < numEffectedE; i++) {
                CCGEdge *e = effectedE[i];
 
-               if(e->numFaces)
-                       for (x=0; x<edgeSize; x++)
+               if (e->numFaces)
+                       for (x = 0; x < edgeSize; x++)
                                VertDataZero(EDGE_getCo(e, lvl, x));
        }
 
        /* add */
-       for (i=0; i<numEffectedF; i++) {
+       for (i = 0; i < numEffectedF; i++) {
                CCGFace *f = effectedF[i];
 
                VertDataZero(FACE_getCenterData(f));
 
-               for (S=0; S<f->numVerts; S++)
-                       for (x=0; x<gridSize; x++)
+               for (S = 0; S < f->numVerts; S++)
+                       for (x = 0; x < gridSize; x++)
                                VertDataZero(FACE_getIECo(f, lvl, S, x));
 
-               for (S=0; S<f->numVerts; S++) {
-                       int prevS = (S+f->numVerts-1)%f->numVerts;
+               for (S = 0; S < f->numVerts; S++) {
+                       int prevS = (S + f->numVerts - 1) % f->numVerts;
                        CCGEdge *e = FACE_getEdges(f)[S];
                        CCGEdge *prevE = FACE_getEdges(f)[prevS];
 
@@ -2332,90 +2464,91 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in
                        if (FACE_getVerts(f)[S]->flags&Vert_eEffected)
                                VertDataAdd(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx));
 
-                       for (x=1; x<gridSize-1; x++) {
+                       for (x = 1; x < gridSize - 1; x++) {
                                VertDataAdd(FACE_getIECo(f, lvl, S, x), FACE_getIFCo(f, lvl, S, x, 0));
                                VertDataAdd(FACE_getIECo(f, lvl, prevS, x), FACE_getIFCo(f, lvl, S, 0, x));
                        }
 
-                       for (x=0; x<gridSize-1; x++) {
-                               int eI = gridSize-1-x;
+                       for (x = 0; x < gridSize - 1; x++) {
+                               int eI = gridSize - 1 - x;
                                if (FACE_getEdges(f)[S]->flags&Edge_eEffected)
                                        VertDataAdd(_edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI,vertDataSize), FACE_getIFCo(f, lvl, S, cornerIdx, x));
                                if (FACE_getEdges(f)[prevS]->flags&Edge_eEffected)
-                                       if(x != 0)
+                                       if (x != 0)
                                                VertDataAdd(_edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI,vertDataSize), FACE_getIFCo(f, lvl, S, x, cornerIdx));
                        }
                }
        }
 
        /* average */
-       for (i=0; i<numEffectedV; i++) {
+       for (i = 0; i < numEffectedV; i++) {
                CCGVert *v = effectedV[i];
-               if(v->numFaces)
+               if (v->numFaces)
                        VertDataMulN(VERT_getCo(v, lvl), 1.0f/v->numFaces);
        }
 
-       for (i=0; i<numEffectedE; i++) {
+       for (i = 0; i < numEffectedE; i++) {
                CCGEdge *e = effectedE[i];
 
                VertDataCopy(EDGE_getCo(e, lvl, 0), VERT_getCo(e->v0, lvl));
-               VertDataCopy(EDGE_getCo(e, lvl, edgeSize-1), VERT_getCo(e->v1, lvl));
+               VertDataCopy(EDGE_getCo(e, lvl, edgeSize - 1), VERT_getCo(e->v1, lvl));
 
-               if(e->numFaces)
-                       for (x=1; x<edgeSize-1; x++)
+               if (e->numFaces)
+                       for (x = 1; x < edgeSize - 1; x++)
                                VertDataMulN(EDGE_getCo(e, lvl, x), 1.0f/e->numFaces);
        }
 
        /* copy */
-       for (i=0; i<numEffectedF; i++) {
+       for (i = 0; i < numEffectedF; i++) {
                CCGFace *f = effectedF[i];
 
                VertDataMulN(FACE_getCenterData(f), 1.0f/f->numVerts);
 
-               for (S=0; S<f->numVerts; S++)
-                       for (x=1; x<gridSize-1; x++)
+               for (S = 0; S < f->numVerts; S++)
+                       for (x = 1; x < gridSize - 1; x++)
                                VertDataMulN(FACE_getIECo(f, lvl, S, x), 0.5f);
 
-               for (S=0; S<f->numVerts; S++) {
-                       int prevS = (S+f->numVerts-1)%f->numVerts;
+               for (S = 0; S < f->numVerts; S++) {
+                       int prevS = (S + f->numVerts - 1) % f->numVerts;
                        CCGEdge *e = FACE_getEdges(f)[S];
                        CCGEdge *prevE = FACE_getEdges(f)[prevS];
 
                        VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), FACE_getCenterData(f));
                        VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], lvl));
 
-                       for (x=1; x<gridSize-1; x++) {
+                       for (x = 1; x < gridSize - 1; x++) {
                                VertDataCopy(FACE_getIFCo(f, lvl, S, x, 0), FACE_getIECo(f, lvl, S, x));
                                VertDataCopy(FACE_getIFCo(f, lvl, S, 0, x), FACE_getIECo(f, lvl, prevS, x));
                        }
 
-                       for (x=0; x<gridSize-1; x++) {
-                               int eI = gridSize-1-x;
+                       for (x = 0; x < gridSize - 1; x++) {
+                               int eI = gridSize - 1 - x;
                                VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI,vertDataSize));
                                VertDataCopy(FACE_getIFCo(f, lvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI,vertDataSize));
                        }
 
                        VertDataCopy(FACE_getIECo(f, lvl, S, 0), FACE_getCenterData(f));
-                       VertDataCopy(FACE_getIECo(f, lvl, S, gridSize-1), FACE_getIFCo(f, lvl, S, gridSize-1, 0));
+                       VertDataCopy(FACE_getIECo(f, lvl, S, gridSize - 1), FACE_getIFCo(f, lvl, S, gridSize - 1, 0));
                }
        }
 
-       for (i=0; i<numEffectedV; i++)
+       for (i = 0; i < numEffectedV; i++)
                effectedV[i]->flags = 0;
-       for (i=0; i<numEffectedE; i++)
+       for (i = 0; i < numEffectedE; i++)
                effectedE[i]->flags = 0;
-       for (i=0; i<numEffectedF; i++)
+       for (i = 0; i < numEffectedF; i++)
                effectedF[i]->flags = 0;
 
        MEM_freeN(effectedE);
        MEM_freeN(effectedV);
-       if(freeF) MEM_freeN(effectedF);
+       if (freeF) MEM_freeN(effectedF);
 
        return eCCGError_None;
 }
 
 /* update normals for specified faces */
-CCGError ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **effectedF, int numEffectedF) {
+CCGError ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **effectedF, int numEffectedF)
+{
        CCGVert **effectedV;
        CCGEdge **effectedE;
        int i, numEffectedV, numEffectedE, freeF;
@@ -2429,16 +2562,16 @@ CCGError ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **effectedF, int numEf
                        effectedV, effectedE, effectedF,
                        numEffectedV, numEffectedE, numEffectedF);
 
-       for (i=0; i<numEffectedV; i++)
+       for (i = 0; i < numEffectedV; i++)
                effectedV[i]->flags = 0;
-       for (i=0; i<numEffectedE; i++)
+       for (i = 0; i < numEffectedE; i++)
                effectedE[i]->flags = 0;
-       for (i=0; i<numEffectedF; i++)
+       for (i = 0; i < numEffectedF; i++)
                effectedF[i]->flags = 0;
 
        MEM_freeN(effectedE);
        MEM_freeN(effectedV);
-       if(freeF) MEM_freeN(effectedF);
+       if (freeF) MEM_freeN(effectedF);
 
        return eCCGError_None;
 }
@@ -2457,22 +2590,22 @@ CCGError ccgSubSurf_updateLevels(CCGSubSurf *ss, int lvl, CCGFace **effectedF, i
        ccgSubSurf__effectedFaceNeighbours(ss, effectedF, numEffectedF,
                &effectedV, &numEffectedV, &effectedE, &numEffectedE);
 
-       for (curLvl=lvl; curLvl<subdivLevels; curLvl++) {
+       for (curLvl = lvl; curLvl < subdivLevels; curLvl++) {
                ccgSubSurf__calcSubdivLevel(ss,
                        effectedV, effectedE, effectedF,
                        numEffectedV, numEffectedE, numEffectedF, curLvl);
        }
 
-       for (i=0; i<numEffectedV; i++)
+       for (i = 0; i < numEffectedV; i++)
                effectedV[i]->flags = 0;
-       for (i=0; i<numEffectedE; i++)
+       for (i = 0; i < numEffectedE; i++)
                effectedE[i]->flags = 0;
-       for (i=0; i<numEffectedF; i++)
+       for (i = 0; i < numEffectedF; i++)
                effectedF[i]->flags = 0;
 
        MEM_freeN(effectedE);
        MEM_freeN(effectedV);
-       if(freeF) MEM_freeN(effectedF);
+       if (freeF) MEM_freeN(effectedF);
 
        return eCCGError_None;
 }
@@ -2484,272 +2617,352 @@ CCGError ccgSubSurf_updateLevels(CCGSubSurf *ss, int lvl, CCGFace **effectedF, i
 
 /*** External API accessor functions ***/
 
-int ccgSubSurf_getNumVerts(const CCGSubSurf *ss) {
+int ccgSubSurf_getNumVerts(const CCGSubSurf *ss)
+{
        return ss->vMap->numEntries;
 }
-int ccgSubSurf_getNumEdges(const CCGSubSurf *ss) {
+int ccgSubSurf_getNumEdges(const CCGSubSurf *ss)
+{
        return ss->eMap->numEntries;
 }
-int ccgSubSurf_getNumFaces(const CCGSubSurf *ss) {
+int ccgSubSurf_getNumFaces(const CCGSubSurf *ss)
+{
        return ss->fMap->numEntries;
 }
 
-CCGVert *ccgSubSurf_getVert(CCGSubSurf *ss, CCGVertHDL v) {
+CCGVert *ccgSubSurf_getVert(CCGSubSurf *ss, CCGVertHDL v)
+{
        return (CCGVert*) _ehash_lookup(ss->vMap, v);
 }
-CCGEdge *ccgSubSurf_getEdge(CCGSubSurf *ss, CCGEdgeHDL e) {
+CCGEdge *ccgSubSurf_getEdge(CCGSubSurf *ss, CCGEdgeHDL e)
+{
        return (CCGEdge*) _ehash_lookup(ss->eMap, e);
 }
-CCGFace *ccgSubSurf_getFace(CCGSubSurf *ss, CCGFaceHDL f) {
+CCGFace *ccgSubSurf_getFace(CCGSubSurf *ss, CCGFaceHDL f)
+{
        return (CCGFace*) _ehash_lookup(ss->fMap, f);
 }
 
-int ccgSubSurf_getSubdivisionLevels(const CCGSubSurf *ss) {
+int ccgSubSurf_getSubdivisionLevels(const CCGSubSurf *ss)
+{
        return ss->subdivLevels;
 }
-int ccgSubSurf_getEdgeSize(const CCGSubSurf *ss) {
+int ccgSubSurf_getEdgeSize(const CCGSubSurf *ss)
+{
        return ccgSubSurf_getEdgeLevelSize(ss, ss->subdivLevels);
 }
-int ccgSubSurf_getEdgeLevelSize(const CCGSubSurf *ss, int level) {
-       if (level<1 || level>ss->subdivLevels) {
+int ccgSubSurf_getEdgeLevelSize(const CCGSubSurf *ss, int level)
+{
+       if (level<1 || level > ss->subdivLevels) {
                return -1;
-       } else {
-               return 1 + (1<<level);
+       }
+       else {
+               return 1 + (1 << level);
        }
 }
-int ccgSubSurf_getGridSize(const CCGSubSurf *ss) {
+int ccgSubSurf_getGridSize(const CCGSubSurf *ss)
+{
        return ccgSubSurf_getGridLevelSize(ss, ss->subdivLevels);
 }
-int ccgSubSurf_getGridLevelSize(const CCGSubSurf *ss, int level) {
-       if (level<1 || level>ss->subdivLevels) {
+int ccgSubSurf_getGridLevelSize(const CCGSubSurf *ss, int level)
+{
+       if (level<1 || level > ss->subdivLevels) {
                return -1;
-       } else {
-               return 1 + (1<<(level-1));
+       }
+       else {
+               return 1 + (1 << (level - 1));
        }
 }
 
 /* Vert accessors */
 
-CCGVertHDL ccgSubSurf_getVertVertHandle(CCGVert *v) {
+CCGVertHDL ccgSubSurf_getVertVertHandle(CCGVert *v)
+{
        return v->vHDL;
 }
-int ccgSubSurf_getVertAge(CCGSubSurf *ss, CCGVert *v) {
+int ccgSubSurf_getVertAge(CCGSubSurf *ss, CCGVert *v)
+{
        if (ss->useAgeCounts) {
                byte *userData = ccgSubSurf_getVertUserData(ss, v);
                return ss->currentAge - *((int*) &userData[ss->vertUserAgeOffset]);
-       } else {
+       }
+       else {
                return 0;
        }
 }
-void *ccgSubSurf_getVertUserData(CCGSubSurf *ss, CCGVert *v) {
-       return VERT_getLevelData(v) + ss->meshIFC.vertDataSize*(ss->subdivLevels+1);
+void *ccgSubSurf_getVertUserData(CCGSubSurf *ss, CCGVert *v)
+{
+       return VERT_getLevelData(v) + ss->meshIFC.vertDataSize * (ss->subdivLevels + 1);
 }
-int ccgSubSurf_getVertNumFaces(CCGVert *v) {
+int ccgSubSurf_getVertNumFaces(CCGVert *v)
+{
        return v->numFaces;
 }
-CCGFace *ccgSubSurf_getVertFace(CCGVert *v, int index) {
+CCGFace *ccgSubSurf_getVertFace(CCGVert *v, int index)
+{
        if (index<0 || index>=v->numFaces) {
                return NULL;
-       } else {
+       }
+       else {
                return v->faces[index];
        }
 }
-int ccgSubSurf_getVertNumEdges(CCGVert *v) {
+int ccgSubSurf_getVertNumEdges(CCGVert *v)
+{
        return v->numEdges;
 }
-CCGEdge *ccgSubSurf_getVertEdge(CCGVert *v, int index) {
+CCGEdge *ccgSubSurf_getVertEdge(CCGVert *v, int index)
+{
        if (index<0 || index>=v->numEdges) {
                return NULL;
-       } else {
+       }
+       else {
                return v->edges[index];
        }
 }
-void *ccgSubSurf_getVertData(CCGSubSurf *ss, CCGVert *v) {
+void *ccgSubSurf_getVertData(CCGSubSurf *ss, CCGVert *v)
+{
        return ccgSubSurf_getVertLevelData(ss, v, ss->subdivLevels);
 }
-void *ccgSubSurf_getVertLevelData(CCGSubSurf *ss, CCGVert *v, int level) {
-       if (level<0 || level>ss->subdivLevels) {
+void *ccgSubSurf_getVertLevelData(CCGSubSurf *ss, CCGVert *v, int level)
+{
+       if (level<0 || level > ss->subdivLevels) {
                return NULL;
-       } else {
+       }
+       else {
                return _vert_getCo(v, level, ss->meshIFC.vertDataSize);
        }
 }
 
 /* Edge accessors */
 
-CCGEdgeHDL ccgSubSurf_getEdgeEdgeHandle(CCGEdge *e) {
+CCGEdgeHDL ccgSubSurf_getEdgeEdgeHandle(CCGEdge *e)
+{
        return e->eHDL;
 }
-int ccgSubSurf_getEdgeAge(CCGSubSurf *ss, CCGEdge *e) {
+int ccgSubSurf_getEdgeAge(CCGSubSurf *ss, CCGEdge *e)
+{
        if (ss->useAgeCounts) {
                byte *userData = ccgSubSurf_getEdgeUserData(ss, e);
                return ss->currentAge - *((int*) &userData[ss->edgeUserAgeOffset]);
-       } else {
+       }
+       else {
                return 0;
        }
 }
-void *ccgSubSurf_getEdgeUserData(CCGSubSurf *ss, CCGEdge *e) {
-       return EDGE_getLevelData(e) + ss->meshIFC.vertDataSize *((ss->subdivLevels+1) + (1<<(ss->subdivLevels+1))-1);
+void *ccgSubSurf_getEdgeUserData(CCGSubSurf *ss, CCGEdge *e)
+{
+       return EDGE_getLevelData(e) + ss->meshIFC.vertDataSize * ((ss->subdivLevels + 1) + (1 << (ss->subdivLevels + 1)) - 1);
 }
-int ccgSubSurf_getEdgeNumFaces(CCGEdge *e) {
+int ccgSubSurf_getEdgeNumFaces(CCGEdge *e)
+{
        return e->numFaces;
 }
-CCGFace *ccgSubSurf_getEdgeFace(CCGEdge *e, int index) {
+CCGFace *ccgSubSurf_getEdgeFace(CCGEdge *e, int index)
+{
        if (index<0 || index>=e->numFaces) {
                return NULL;
-       } else {
+       }
+       else {
                return e->faces[index];
        }
 }
-CCGVert *ccgSubSurf_getEdgeVert0(CCGEdge *e) {
+CCGVert *ccgSubSurf_getEdgeVert0(CCGEdge *e)
+{
        return e->v0;
 }
-CCGVert *ccgSubSurf_getEdgeVert1(CCGEdge *e) {
+CCGVert *ccgSubSurf_getEdgeVert1(CCGEdge *e)
+{
        return e->v1;
 }
-void *ccgSubSurf_getEdgeDataArray(CCGSubSurf *ss, CCGEdge *e) {
+void *ccgSubSurf_getEdgeDataArray(CCGSubSurf *ss, CCGEdge *e)
+{
        return ccgSubSurf_getEdgeData(ss, e, 0);
 }
-void *ccgSubSurf_getEdgeData(CCGSubSurf *ss, CCGEdge *e, int x) {
+void *ccgSubSurf_getEdgeData(CCGSubSurf *ss, CCGEdge *e, int x)
+{
        return ccgSubSurf_getEdgeLevelData(ss, e, x, ss->subdivLevels);
 }
-void *ccgSubSurf_getEdgeLevelData(CCGSubSurf *ss, CCGEdge *e, int x, int level) {
-       if (level<0 || level>ss->subdivLevels) {
+void *ccgSubSurf_getEdgeLevelData(CCGSubSurf *ss, CCGEdge *e, int x, int level)
+{
+       if (level<0 || level > ss->subdivLevels) {
                return NULL;
-       } else {
+       }
+       else {
                return _edge_getCo(e, level, x, ss->meshIFC.vertDataSize);
        }
 }
-float ccgSubSurf_getEdgeCrease(CCGEdge *e) {
+float ccgSubSurf_getEdgeCrease(CCGEdge *e)
+{
        return e->crease;
 }
 
 /* Face accessors */
 
-CCGFaceHDL ccgSubSurf_getFaceFaceHandle(CCGSubSurf *UNUSED(ss), CCGFace *f) {
+CCGFaceHDL ccgSubSurf_getFaceFaceHandle(CCGSubSurf *UNUSED(ss), CCGFace *f)
+{
        return f->fHDL;
 }
-int ccgSubSurf_getFaceAge(CCGSubSurf *ss, CCGFace *f) {
+int ccgSubSurf_getFaceAge(CCGSubSurf *ss, CCGFace *f)
+{
        if (ss->useAgeCounts) {
                byte *userData = ccgSubSurf_getFaceUserData(ss, f);
                return ss->currentAge - *((int*) &userData[ss->faceUserAgeOffset]);
-       } else {
+       }
+       else {
                return 0;
        }
 }
-void *ccgSubSurf_getFaceUserData(CCGSubSurf *ss, CCGFace *f) {
-       int maxGridSize = 1 + (1<<(ss->subdivLevels-1));
-       return FACE_getCenterData(f) + ss->meshIFC.vertDataSize *(1 + f->numVerts*maxGridSize + f->numVerts*maxGridSize*maxGridSize);
+void *ccgSubSurf_getFaceUserData(CCGSubSurf *ss, CCGFace *f)
+{
+       int maxGridSize = 1 + (1 << (ss->subdivLevels - 1));
+       return FACE_getCenterData(f) + ss->meshIFC.vertDataSize * (1 + f->numVerts * maxGridSize + f->numVerts * maxGridSize * maxGridSize);
 }
-int ccgSubSurf_getFaceNumVerts(CCGFace *f) {
+int ccgSubSurf_getFaceNumVerts(CCGFace *f)
+{
        return f->numVerts;
 }
-CCGVert *ccgSubSurf_getFaceVert(CCGSubSurf *UNUSED(ss), CCGFace *f, int index) {
+CCGVert *ccgSubSurf_getFaceVert(CCGSubSurf *UNUSED(ss), CCGFace *f, int index)
+{
        if (index<0 || index>=f->numVerts) {
                return NULL;
-       } else {
+       }
+       else {
                return FACE_getVerts(f)[index];
        }
 }
-CCGEdge *ccgSubSurf_getFaceEdge(CCGSubSurf *UNUSED(ss), CCGFace *f, int index) {
+CCGEdge *ccgSubSurf_getFaceEdge(CCGSubSurf *UNUSED(ss), CCGFace *f, int index)
+{
        if (index<0 || index>=f->numVerts) {
                return NULL;
-       } else {
+       }
+       else {
                return FACE_getEdges(f)[index];
        }
 }
-int ccgSubSurf_getFaceEdgeIndex(CCGFace *f, CCGEdge *e) {
+int ccgSubSurf_getFaceEdgeIndex(CCGFace *f, CCGEdge *e)
+{
        int i;
 
-       for (i=0; i<f->numVerts; i++)
-               if (FACE_getEdges(f)[i]==e)
+       for (i = 0; i < f->numVerts; i++) {
+               if (FACE_getEdges(f)[i] == e) {
                        return i;
-
+               }
+       }
        return -1;
 }
-void *ccgSubSurf_getFaceCenterData(CCGFace *f) {
+void *ccgSubSurf_getFaceCenterData(CCGFace *f)
+{
        return FACE_getCenterData(f);
 }
-void *ccgSubSurf_getFaceGridEdgeDataArray(CCGSubSurf *ss, CCGFace *f, int gridIndex) {
+void *ccgSubSurf_getFaceGridEdgeDataArray(CCGSubSurf *ss, CCGFace *f, int gridIndex)
+{
        return ccgSubSurf_getFaceGridEdgeData(ss, f, gridIndex, 0);
 }
-void *ccgSubSurf_getFaceGridEdgeData(CCGSubSurf *ss, CCGFace *f, int gridIndex, int x) {
+void *ccgSubSurf_getFaceGridEdgeData(CCGSubSurf *ss, CCGFace *f, int gridIndex, int x)
+{
        return _face_getIECo(f, ss->subdivLevels, gridIndex, x, ss->subdivLevels, ss->meshIFC.vertDataSize);
 }
-void *ccgSubSurf_getFaceGridDataArray(CCGSubSurf *ss, CCGFace *f, int gridIndex) {
+void *ccgSubSurf_getFaceGridDataArray(CCGSubSurf *ss, CCGFace *f, int gridIndex)
+{
        return ccgSubSurf_getFaceGridData(ss, f, gridIndex, 0, 0);
 }
-void *ccgSubSurf_getFaceGridData(CCGSubSurf *ss, CCGFace *f, int gridIndex, int x, int y) {
+void *ccgSubSurf_getFaceGridData(CCGSubSurf *ss, CCGFace *f, int gridIndex, int x, int y)
+{
        return _face_getIFCo(f, ss->subdivLevels, gridIndex, x, y, ss->subdivLevels, ss->meshIFC.vertDataSize);
 }
 
 /*** External API iterator functions ***/
 
-CCGVertIterator *ccgSubSurf_getVertIterator(CCGSubSurf *ss) {
+CCGVertIterator *ccgSubSurf_getVertIterator(CCGSubSurf *ss)
+{
        return (CCGVertIterator*) _ehashIterator_new(ss->vMap);
 }
-CCGEdgeIterator *ccgSubSurf_getEdgeIterator(CCGSubSurf *ss) {
+CCGEdgeIterator *ccgSubSurf_getEdgeIterator(CCGSubSurf *ss)
+{
        return (CCGEdgeIterator*) _ehashIterator_new(ss->eMap);
 }
-CCGFaceIterator *ccgSubSurf_getFaceIterator(CCGSubSurf *ss) {
+CCGFaceIterator *ccgSubSurf_getFaceIterator(CCGSubSurf *ss)
+{
        return (CCGFaceIterator*) _ehashIterator_new(ss->fMap);
 }
 
-CCGVert *ccgVertIterator_getCurrent(CCGVertIterator *vi) {
+CCGVert *ccgVertIterator_getCurrent(CCGVertIterator *vi)
+{
        return (CCGVert*) _ehashIterator_getCurrent((EHashIterator*) vi);
 }
-int ccgVertIterator_isStopped(CCGVertIterator *vi) {
+int ccgVertIterator_isStopped(CCGVertIterator *vi)
+{
        return _ehashIterator_isStopped((EHashIterator*) vi);
 }
-void ccgVertIterator_next(CCGVertIterator *vi) {
+void ccgVertIterator_next(CCGVertIterator *vi)
+{
        _ehashIterator_next((EHashIterator*) vi); 
 }
-void ccgVertIterator_free(CCGVertIterator *vi) {
+void ccgVertIterator_free(CCGVertIterator *vi)
+{
        _ehashIterator_free((EHashIterator*) vi);
 }
 
-CCGEdge *ccgEdgeIterator_getCurrent(CCGEdgeIterator *vi) {
+CCGEdge *ccgEdgeIterator_getCurrent(CCGEdgeIterator *vi)
+{
        return (CCGEdge*) _ehashIterator_getCurrent((EHashIterator*) vi);
 }
-int ccgEdgeIterator_isStopped(CCGEdgeIterator *vi) {
+int ccgEdgeIterator_isStopped(CCGEdgeIterator *vi)
+{
        return _ehashIterator_isStopped((EHashIterator*) vi);
 }
-void ccgEdgeIterator_next(CCGEdgeIterator *vi) {
+void ccgEdgeIterator_next(CCGEdgeIterator *vi)
+{
        _ehashIterator_next((EHashIterator*) vi); 
 }
-void ccgEdgeIterator_free(CCGEdgeIterator *vi) {
+void ccgEdgeIterator_free(CCGEdgeIterator *vi)
+{
        _ehashIterator_free((EHashIterator*) vi);
 }
 
-CCGFace *ccgFaceIterator_getCurrent(CCGFaceIterator *vi) {
+CCGFace *ccgFaceIterator_getCurrent(CCGFaceIterator *vi)
+{
        return (CCGFace*) _ehashIterator_getCurrent((EHashIterator*) vi);
 }
-int ccgFaceIterator_isStopped(CCGFaceIterator *vi) {
+int ccgFaceIterator_isStopped(CCGFaceIterator *vi)
+{
        return _ehashIterator_isStopped((EHashIterator*) vi);
 }
-void ccgFaceIterator_next(CCGFaceIterator *vi) {
+void ccgFaceIterator_next(CCGFaceIterator *vi)
+{
        _ehashIterator_next((EHashIterator*) vi); 
 }
-void ccgFaceIterator_free(CCGFaceIterator *vi) {
+void ccgFaceIterator_free(CCGFaceIterator *vi)
+{
        _ehashIterator_free((EHashIterator*) vi);
 }
 
 /*** Extern API final vert/edge/face interface ***/
 
-int ccgSubSurf_getNumFinalVerts(const CCGSubSurf *ss) {
-       int edgeSize = 1 + (1<<ss->subdivLevels);
-       int gridSize = 1 + (1<<(ss->subdivLevels-1));
-       int numFinalVerts = ss->vMap->numEntries + ss->eMap->numEntries*(edgeSize-2) + ss->fMap->numEntries + ss->numGrids*((gridSize-2) + ((gridSize-2)*(gridSize-2)));
+int ccgSubSurf_getNumFinalVerts(const CCGSubSurf *ss)
+{
+       int edgeSize = 1 + (1 << ss->subdivLevels);
+       int gridSize = 1 + (1 << (ss->subdivLevels - 1));
+       int numFinalVerts = (ss->vMap->numEntries +
+                            ss->eMap->numEntries * (edgeSize - 2) +
+                            ss->fMap->numEntries +
+                            ss->numGrids * ((gridSize - 2) + ((gridSize - 2) * (gridSize - 2))));
+
        return numFinalVerts;
 }
-int ccgSubSurf_getNumFinalEdges(const CCGSubSurf *ss) {
-       int edgeSize = 1 + (1<<ss->subdivLevels);
-       int gridSize = 1 + (1<<(ss->subdivLevels-1));
-       int numFinalEdges = ss->eMap->numEntries*(edgeSize-1) + ss->numGrids*((gridSize-1) + 2*((gridSize-2)*(gridSize-1)));
+int ccgSubSurf_getNumFinalEdges(const CCGSubSurf *ss)
+{
+       int edgeSize = 1 + (1 << ss->subdivLevels);
+       int gridSize = 1 + (1 << (ss->subdivLevels - 1));
+       int numFinalEdges = (ss->eMap->numEntries * (edgeSize - 1) +
+                            ss->numGrids * ((gridSize - 1) + 2 * ((gridSize - 2) * (gridSize - 1))));
+
        return numFinalEdges;
 }
-int ccgSubSurf_getNumFinalFaces(const CCGSubSurf *ss) {
-       int gridSize = 1 + (1<<(ss->subdivLevels-1));
-       int numFinalFaces = ss->numGrids*((gridSize-1)*(gridSize-1));
+int ccgSubSurf_getNumFinalFaces(const CCGSubSurf *ss)
+{
+       int gridSize = 1 + (1 << (ss->subdivLevels - 1));
+       int numFinalFaces = ss->numGrids * ((gridSize - 1) * (gridSize - 1));
        return numFinalFaces;
 }
index ca453cc..0a6d8b7 100644 (file)
@@ -869,22 +869,22 @@ void weight_to_rgb(float r_rgb[3], const float weight)
 {
        const float blend= ((weight/2.0f)+0.5f);
 
-       if (weight<=0.25f)    // blue->cyan
+       if (weight<=0.25f) {    // blue->cyan
                r_rgb[0]= 0.0f;
                r_rgb[1]= blend*weight*4.0f;
                r_rgb[2]= blend;
        }
-       else if (weight<=0.50f)       // cyan->green
+       else if (weight<=0.50f) {       // cyan->green
                r_rgb[0]= 0.0f;
                r_rgb[1]= blend;
                r_rgb[2]= blend*(1.0f-((weight-0.25f)*4.0f));
        }
-       else if (weight <= 0.75f)     // green->yellow
+       else if (weight <= 0.75f) {     // green->yellow
                r_rgb[0]= blend * ((weight-0.50f)*4.0f);
                r_rgb[1]= blend;
                r_rgb[2]= 0.0f;
        }
-       else if (weight <= 1.0f){ // yellow->red
+       else if (weight <= 1.0f) { // yellow->red
                r_rgb[0]= blend;
                r_rgb[1]= blend * (1.0f-((weight-0.75f)*4.0f));
                r_rgb[2]= 0.0f;
index 767401a..000d74f 100644 (file)
@@ -1199,7 +1199,7 @@ static void blend_pose_strides(bPose *dst, bPose *src, float srcweight, short mo
 {
        float dstweight;
        
-       switch (mode){
+       switch (mode) {
                case ACTSTRIPMODE_BLEND:
                        dstweight = 1.0F - srcweight;
                        break;
@@ -1489,7 +1489,7 @@ static void do_nla(Scene *scene, Object *ob, int blocktype)
        }
        
        /* and now go over all strips */
-       for (strip=ob->nlastrips.first; strip; strip=strip->next){
+       for (strip=ob->nlastrips.first; strip; strip=strip->next) {
                doit=dostride= 0;
                
                if (strip->act && !(strip->flag & ACTSTRIP_MUTE)) {     /* so theres an action */
@@ -1500,7 +1500,7 @@ static void do_nla(Scene *scene, Object *ob, int blocktype)
                        striptime = (scene_cfra-(strip->start)) / length;
                        stripframe = (scene_cfra-(strip->start)) ;
 
-                       if (striptime>=0.0){
+                       if (striptime>=0.0) {
                                
                                if(blocktype==ID_AR) 
                                        rest_pose(tpose);
@@ -1509,14 +1509,14 @@ static void do_nla(Scene *scene, Object *ob, int blocktype)
                                if (striptime < 1.0f + 0.1f/length) {
                                        
                                        /* Handle path */
-                                       if ((strip->flag & ACTSTRIP_USESTRIDE) && (blocktype==ID_AR) && (ob->ipoflag & OB_DISABLE_PATH)==0){
+                                       if ((strip->flag & ACTSTRIP_USESTRIDE) && (blocktype==ID_AR) && (ob->ipoflag & OB_DISABLE_PATH)==0) {
                                                Object *parent= get_parent_path(ob);
                                                
                                                if (parent) {
                                                        Curve *cu = parent->data;
                                                        float ctime, pdist;
                                                        
-                                                       if (cu->flag & CU_PATH){
+                                                       if (cu->flag & CU_PATH) {
                                                                /* Ensure we have a valid path */
                                                                if(cu->path==NULL || cu->path->data==NULL) makeDispListCurveTypes(scene, parent, 0);
                                                                if(cu->path) {
@@ -1590,7 +1590,7 @@ static void do_nla(Scene *scene, Object *ob, int blocktype)
                                }
                                /* Handle extend */
                                else {
-                                       if (strip->flag & ACTSTRIP_HOLDLASTFRAME){
+                                       if (strip->flag & ACTSTRIP_HOLDLASTFRAME) {
                                                /* we want the strip to hold on the exact fraction of the repeat value */
                                                
                                                frametime = actlength * (strip->repeat-(int)strip->repeat);
@@ -1616,13 +1616,13 @@ static void do_nla(Scene *scene, Object *ob, int blocktype)
                                }
                                
                                /* Handle blendin & blendout */
-                               if (doit){
+                               if (doit) {
                                        /* Handle blendin */
                                        
-                                       if (strip->blendin>0.0 && stripframe<=strip->blendin && scene_cfra>=strip->start){
+                                       if (strip->blendin>0.0 && stripframe<=strip->blendin && scene_cfra>=strip->start) {
                                                blendfac = stripframe/strip->blendin;
                                        }
-                                       else if (strip->blendout>0.0 && stripframe>=(length-strip->blendout) && scene_cfra<=strip->end){
+                                       else if (strip->blendout>0.0 && stripframe>=(length-strip->blendout) && scene_cfra<=strip->end) {
                                                blendfac = (length-stripframe)/(strip->blendout);
                                        }
                                        else
index d454bef..f3f4d7c 100644 (file)
@@ -291,7 +291,7 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues *
                        }
                }
        }
-       if(ptn){ MEM_freeN(ptn); ptn=NULL; }
+       if (ptn) { MEM_freeN(ptn); ptn=NULL; }
 
        /* check boids in other systems */
        for(pt=bbd->sim->psys->targets.first; pt; pt=pt->next) {
@@ -337,7 +337,7 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues *
                                }
                        }
 
-                       if(ptn){ MEM_freeN(ptn); ptn=NULL; }
+                       if (ptn) { MEM_freeN(ptn); ptn=NULL; }
                }
        }
 
@@ -364,7 +364,7 @@ static int rule_separate(BoidRule *UNUSED(rule), BoidBrainData *bbd, BoidValues
                len = ptn[1].dist;
                ret = 1;
        }
-       if(ptn){ MEM_freeN(ptn); ptn=NULL; }
+       if (ptn) { MEM_freeN(ptn); ptn=NULL; }
 
        /* check other boid systems */
        for(pt=bbd->sim->psys->targets.first; pt; pt=pt->next) {
@@ -382,7 +382,7 @@ static int rule_separate(BoidRule *UNUSED(rule), BoidBrainData *bbd, BoidValues
                                ret = 1;
                        }
 
-                       if(ptn){ MEM_freeN(ptn); ptn=NULL; }
+                       if (ptn) { MEM_freeN(ptn); ptn=NULL; }
                }
        }
        return ret;
@@ -487,7 +487,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va
                float vec2[3], t, t_min = 3.0f;
 
                /* first check we're not blocking any leaders */
-               for(i = 0; i< bbd->sim->psys->totpart; i+=n){
+               for(i = 0; i< bbd->sim->psys->totpart; i+=n) {
                        copy_v3_v3(vec, bbd->sim->psys->particles[i].prev_state.vel);
 
                        sub_v3_v3v3(loc, pa->prev_state.co, bbd->sim->psys->particles[i].prev_state.co);
@@ -626,7 +626,7 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti
 
        f_strength += bbd->part->boids->strength * health;
 
-       if(ptn){ MEM_freeN(ptn); ptn=NULL; }
+       if (ptn) { MEM_freeN(ptn); ptn=NULL; }
 
        /* add other friendlies and calculate enemy strength and find closest enemy */
        for(pt=bbd->sim->psys->targets.first; pt; pt=pt->next) {
@@ -653,7 +653,7 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti
                        else if(pt->mode==PTARGET_MODE_FRIEND)
                                f_strength += epsys->part->boids->strength * health;
 
-                       if(ptn){ MEM_freeN(ptn); ptn=NULL; }
+                       if (ptn) { MEM_freeN(ptn); ptn=NULL; }
                }
        }
        /* decide action if enemy presence found */
@@ -779,7 +779,7 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float grou
                hit.dist = col.original_ray_length = len_v3(ray_dir);
                col.pce.inside = 0;
 
-               for(coll = bbd->sim->colliders->first; coll; coll = coll->next){
+               for(coll = bbd->sim->colliders->first; coll; coll = coll->next) {
                        col.current = coll->ob;
                        col.md = coll->collmd;
                        col.fac1 = col.fac2 = 0.f;
@@ -804,7 +804,7 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float grou
                hit.index = -1;
                hit.dist = col.original_ray_length = len_v3(ray_dir);
 
-               for(coll = bbd->sim->colliders->first; coll; coll = coll->next){
+               for(coll = bbd->sim->colliders->first; coll; coll = coll->next) {
                        col.current = coll->ob;
                        col.md = coll->collmd;
 
@@ -1325,7 +1325,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
                                        boid_climb(boids, pa, ground_co, ground_nor);
                                }
                                /* land boid when really near ground */
-                               else if(pa->state.co[2] <= ground_co[2] + 1.01f * pa->size * boids->height){
+                               else if(pa->state.co[2] <= ground_co[2] + 1.01f * pa->size * boids->height) {
                                        pa->state.co[2] = ground_co[2] + pa->size * boids->height;
                                        pa->state.vel[2] = 0.0f;
                                        bpa->data.mode = eBoidMode_OnLand;
index f2514c1..f5c39f3 100644 (file)
@@ -543,7 +543,7 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
 
        if (flt) {
                copy_v3_v3(brush_rgb, brush->rgb);
-               if(use_color_correction){
+               if (use_color_correction) {
                        srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
                }
 
@@ -1048,9 +1048,9 @@ void brush_jitter_pos(const Scene *scene, Brush *brush, float pos[2], float jitt
 
        /* jitter-ed brush gives weird and unpredictable result for this
           kinds of stroke, so manyally disable jitter usage (sergey) */
-       use_jitter&= (brush->flag & (BRUSH_RESTORE_MESH|BRUSH_ANCHORED)) == 0;
+       use_jitter &= (brush->flag & (BRUSH_RESTORE_MESH|BRUSH_ANCHORED)) == 0;
 
-       if(use_jitter){
+       if (use_jitter) {
                float rand_pos[2];
                const int radius= brush_size(scene, brush);
                const int diameter= 2*radius;
index 9f3c9fc..c1d6165 100644 (file)
@@ -1846,7 +1846,7 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
        MLoopUV *mloopuv;
        int i, j, hasWCol = CustomData_has_layer(&bm->ldata, CD_WEIGHT_MLOOPCOL);
 
-       for(i=0; i < numTex; i++){
+       for (i=0; i < numTex; i++) {
                texface = CustomData_get_n(facedata, CD_MTFACE, cdindex, i);
                texpoly = CustomData_bmesh_get_n(&bm->pdata, f->head.data, CD_MTEXPOLY, i);
                
@@ -1859,7 +1859,7 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
                }
        }
 
-       for(i=0; i < numCol; i++){
+       for (i=0; i < numCol; i++) {
                mcol = CustomData_get_n(facedata, CD_MCOL, cdindex, i);
                
                for (j=0; j<3; j++) {
index e8c6ec8..e8cd152 100644 (file)
@@ -2317,7 +2317,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
                
                /* Vector object -> target */
                sub_v3_v3v3(vec, ct->matrix[3], cob->matrix[3]);
-               switch (data->lockflag){
+               switch (data->lockflag) {
                case LOCK_X: /* LOCK X */
                {
                        switch (data->trackflag) {
index b2aaa65..01216ce 100644 (file)
@@ -644,16 +644,17 @@ static void layerInterp_mloopcol(void **sources, float *weights,
        col.a = col.r = col.g = col.b = 0;
 
        sub_weight = sub_weights;
-       for(i = 0; i < count; ++i){
+       for (i = 0; i < count; ++i) {
                float weight = weights ? weights[i] : 1;
                MLoopCol *src = sources[i];
-               if(sub_weights){
+               if (sub_weights) {
                        col.a += src->a * (*sub_weight) * weight;
                        col.r += src->r * (*sub_weight) * weight;
                        col.g += src->g * (*sub_weight) * weight;
                        col.b += src->b * (*sub_weight) * weight;
                        sub_weight++;
-               } else {
+               }
+               else {
                        col.a += src->a * weight;
                        col.r += src->r * weight;
                        col.g += src->g * weight;
index 5e4d8d2..79922e4 100644 (file)
 
 void calc_lat_fudu(int flag, int res, float *fu, float *du)
 {
-       if(res==1) {
+       if (res==1) {
                *fu= 0.0;
                *du= 0.0;
        }
-       else if(flag & LT_GRID) {
+       else if (flag & LT_GRID) {
                *fu= -0.5f*(res-1);
                *du= 1.0f;
        }
@@ -91,14 +91,14 @@ void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
        float *co, (*vertexCos)[3] = NULL;
        
        /* vertex weight groups are just freed all for now */
-       if(lt->dvert) {
+       if (lt->dvert) {
                free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
                lt->dvert= NULL;
        }
        
        while(uNew*vNew*wNew > 32000) {
-               if( uNew>=vNew && uNew>=wNew) uNew--;
-               else if( vNew>=uNew && vNew>=wNew) vNew--;
+               if ( uNew>=vNew && uNew>=wNew) uNew--;
+               else if ( vNew>=uNew && vNew>=wNew) vNew--;
                else wNew--;
        }
 
@@ -131,9 +131,9 @@ void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
        }
 
        co = vertexCos[0];
-       for(w=0,wc=fw; w<wNew; w++,wc+=dw) {
-               for(v=0,vc=fv; v<vNew; v++,vc+=dv) {
-                       for(u=0,uc=fu; u<uNew; u++,co+=3,uc+=du) {
+       for (w=0,wc=fw; w<wNew; w++,wc+=dw) {
+               for (v=0,vc=fv; v<vNew; v++,vc+=dv) {
+                       for (u=0,uc=fu; u<uNew; u++,co+=3,uc+=du) {
                                co[0] = uc;
                                co[1] = vc;
                                co[2] = wc;
@@ -208,9 +208,9 @@ Lattice *copy_lattice(Lattice *lt)
        ltn->def= MEM_dupallocN(lt->def);
 
        ltn->key= copy_key(ltn->key);
-       if(ltn->key) ltn->key->from= (ID *)ltn;
+       if (ltn->key) ltn->key->from= (ID *)ltn;
        
-       if(lt->dvert) {
+       if (lt->dvert) {
                int tot= lt->pntsu*lt->pntsv*lt->pntsw;
                ltn->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert");
                copy_dverts(ltn->dvert, lt->dvert, tot);
@@ -223,13 +223,13 @@ Lattice *copy_lattice(Lattice *lt)
 
 void free_lattice(Lattice *lt)
 {
-       if(lt->def) MEM_freeN(lt->def);
-       if(lt->dvert) free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
-       if(lt->editlatt) {
+       if (lt->def) MEM_freeN(lt->def);
+       if (lt->dvert) free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
+       if (lt->editlatt) {
                Lattice *editlt= lt->editlatt->latt;
 
-               if(editlt->def) MEM_freeN(editlt->def);
-               if(editlt->dvert) free_dverts(editlt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
+               if (editlt->def) MEM_freeN(editlt->def);
+               if (editlt->dvert) free_dverts(editlt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
 
                MEM_freeN(editlt);
                MEM_freeN(lt->editlatt);
@@ -254,32 +254,32 @@ void make_local_lattice(Lattice *lt)
         * - mixed: make copy
         */
        
-       if(lt->id.lib==NULL) return;
-       if(lt->id.us==1) {
+       if (lt->id.lib==NULL) return;
+       if (lt->id.us==1) {
                id_clear_lib_data(bmain, &lt->id);
                return;
        }
        
-       for(ob= bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob= ob->id.next) {
-               if(ob->data==lt) {
-                       if(ob->id.lib) is_lib= TRUE;
+       for (ob= bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob= ob->id.next) {
+               if (ob->data==lt) {
+                       if (ob->id.lib) is_lib= TRUE;
                        else is_local= TRUE;
                }
        }
        
-       if(is_local && is_lib==FALSE) {
+       if (is_local && is_lib==FALSE) {
                id_clear_lib_data(bmain, &lt->id);
        }
-       else if(is_local && is_lib) {
+       else if (is_local && is_lib) {
                Lattice *lt_new= copy_lattice(lt);
                lt_new->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
                BKE_id_lib_local_paths(bmain, lt->id.lib, &lt_new->id);
 
-               for(ob= bmain->object.first; ob; ob= ob->id.next) {
-                       if(ob->data==lt) {
-                               if(ob->id.lib==NULL) {
+               for (ob= bmain->object.first; ob; ob= ob->id.next) {
+                       if (ob->data==lt) {
+                               if (ob->id.lib==NULL) {
                                        ob->data= lt_new;
                                        lt_new->id.us++;
                                        lt->id.us--;
@@ -300,13 +300,13 @@ void init_latt_deform(Object *oblatt, Object *ob)
        float fu, fv, fw;
        int u, v, w;
 
-       if(lt->editlatt) lt= lt->editlatt->latt;
+       if (lt->editlatt) lt= lt->editlatt->latt;
        bp = lt->def;
        
        fp= lt->latticedata= MEM_mallocN(sizeof(float)*3*lt->pntsu*lt->pntsv*lt->pntsw, "latticedata");
        
                /* for example with a particle system: ob==0 */
-       if(ob==NULL) {
+       if (ob==NULL) {
                /* in deformspace, calc matrix  */
                invert_m4_m4(lt->latmat, oblatt->obmat);
        
@@ -322,9 +322,9 @@ void init_latt_deform(Object *oblatt, Object *ob)
                invert_m4_m4(imat, lt->latmat);
        }
        
-       for(w=0,fw=lt->fw; w<lt->pntsw; w++,fw+=lt->dw) {
-               for(v=0,fv=lt->fv; v<lt->pntsv; v++, fv+=lt->dv) {
-                       for(u=0,fu=lt->fu; u<lt->pntsu; u++, bp++, co+=3, fp+=3, fu+=lt->du) {
+       for (w=0,fw=lt->fw; w<lt->pntsw; w++,fw+=lt->dw) {
+               for (v=0,fv=lt->fv; v<lt->pntsv; v++, fv+=lt->dv) {
+                       for (u=0,fu=lt->fu; u<lt->pntsu; u++, bp++, co+=3, fp+=3, fu+=lt->du) {
                                if (dl) {
                                        fp[0] = co[0] - fu;
                                        fp[1] = co[1] - fv;
@@ -355,10 +355,10 @@ void calc_latt_deform(Object *ob, float *co, float weight)
        MDeformVert *dvert= lattice_get_deform_verts(ob);
 
 
-       if(lt->editlatt) lt= lt->editlatt->latt;
-       if(lt->latticedata==NULL) return;
+       if (lt->editlatt) lt= lt->editlatt->latt;
+       if (lt->latticedata==NULL) return;
 
-       if(lt->vgroup[0] && dvert) {
+       if (lt->vgroup[0] && dvert) {
                defgroup_nr= defgroup_name_index(ob, lt->vgroup);
                copy_v3_v3(co_prev, co);
        }
@@ -368,7 +368,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
 
        /* u v w coords */
 
-       if(lt->pntsu>1) {
+       if (lt->pntsu>1) {
                u= (vec[0]-lt->fu)/lt->du;
                ui= (int)floor(u);
                u -= ui;
@@ -379,7 +379,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
                ui= 0;
        }
 
-       if(lt->pntsv>1) {
+       if (lt->pntsv>1) {
                v= (vec[1]-lt->fv)/lt->dv;
                vi= (int)floor(v);
                v -= vi;
@@ -390,7 +390,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
                vi= 0;
        }
 
-       if(lt->pntsw>1) {
+       if (lt->pntsw>1) {
                w= (vec[2]-lt->fw)/lt->dw;
                wi= (int)floor(w);
                w -= wi;
@@ -401,39 +401,39 @@ void calc_latt_deform(Object *ob, float *co, float weight)
                wi= 0;
        }
 
-       for(ww= wi-1; ww<=wi+2; ww++) {
+       for (ww= wi-1; ww<=wi+2; ww++) {
                w= tw[ww-wi+1];
 
-               if(w != 0.0f) {
-                       if(ww>0) {
-                               if(ww<lt->pntsw) idx_w= ww*lt->pntsu*lt->pntsv;
+               if (w != 0.0f) {
+                       if (ww>0) {
+                               if (ww<lt->pntsw) idx_w= ww*lt->pntsu*lt->pntsv;
                                else idx_w= (lt->pntsw-1)*lt->pntsu*lt->pntsv;
                        }
                        else idx_w= 0;
 
-                       for(vv= vi-1; vv<=vi+2; vv++) {
+                       for (vv= vi-1; vv<=vi+2; vv++) {
                                v= w*tv[vv-vi+1];
 
-                               if(v != 0.0f) {
-                                       if(vv>0) {
-                                               if(vv<lt->pntsv) idx_v= idx_w + vv*lt->pntsu;
+                               if (v != 0.0f) {
+                                       if (vv>0) {
+                                               if (vv<lt->pntsv) idx_v= idx_w + vv*lt->pntsu;
                                                else idx_v= idx_w + (lt->pntsv-1)*lt->pntsu;
                                        }
                                        else idx_v= idx_w;
 
-                                       for(uu= ui-1; uu<=ui+2; uu++) {
+                                       for (uu= ui-1; uu<=ui+2; uu++) {
                                                u= weight*v*tu[uu-ui+1];
 
-                                               if(u != 0.0f) {
-                                                       if(uu>0) {
-                                                               if(uu<lt->pntsu) idx_u= idx_v + uu;
+                                               if (u != 0.0f) {
+                                                       if (uu>0) {
+                                                               if (uu<lt->pntsu) idx_u= idx_v + uu;
                                                                else idx_u= idx_v + (lt->pntsu-1);
                                                        }
                                                        else idx_u= idx_v;
 
                                                        madd_v3_v3fl(co, &lt->latticedata[idx_u * 3], u);
 
-                                                       if(defgroup_nr != -1)
+                                                       if (defgroup_nr != -1)
                                                                weight_blend += (u * defvert_find_weight(dvert + idx_u, defgroup_nr));
                                                }
                                        }
@@ -442,7 +442,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
                }
        }
 
-       if(defgroup_nr != -1)
+       if (defgroup_nr != -1)
                interp_v3_v3v3(co, co_prev, co, weight_blend);
 
 }
@@ -451,9 +451,9 @@ void end_latt_deform(Object *ob)
 {
        Lattice *lt= ob->data;
        
-       if(lt->editlatt) lt= lt->editlatt->latt;
+       if (lt->editlatt) lt= lt->editlatt->latt;
        
-       if(lt->latticedata)
+       if (lt->latticedata)
                MEM_freeN(lt->latticedata);
        lt->latticedata= NULL;
 }
@@ -490,33 +490,33 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir
        /* test for cyclic */
        bl= cu->bev.first;
        if (!bl->nr) return 0;
-       if(bl && bl->poly> -1) cycl= 1;
+       if (bl && bl->poly> -1) cycl= 1;
 
-       if(cycl==0) {
+       if (cycl==0) {
                ctime1= CLAMPIS(ctime, 0.0f, 1.0f);
        }
        else ctime1= ctime;
        
        /* vec needs 4 items */
-       if(where_on_path(ob, ctime1, vec, dir, quat, radius, NULL)) {
+       if (where_on_path(ob, ctime1, vec, dir, quat, radius, NULL)) {
                
-               if(cycl==0) {
+               if (cycl==0) {
                        Path *path= cu->path;
                        float dvec[3];
                        
-                       if(ctime < 0.0f) {
+                       if (ctime < 0.0f) {
                                sub_v3_v3v3(dvec, path->data[1].vec, path->data[0].vec);
                                mul_v3_fl(dvec, ctime*(float)path->len);
                                add_v3_v3(vec, dvec);
-                               if(quat) copy_qt_qt(quat, path->data[0].quat);
-                               if(radius) *radius= path->data[0].radius;
+                               if (quat) copy_qt_qt(quat, path->data[0].quat);
+                               if (radius) *radius= path->data[0].radius;
                        }
-                       else if(ctime > 1.0f) {
+                       else if (ctime > 1.0f) {
                                sub_v3_v3v3(dvec, path->data[path->len-1].vec, path->data[path->len-2].vec);
                                mul_v3_fl(dvec, (ctime-1.0f)*(float)path->len);
                                add_v3_v3(vec, dvec);
-                               if(quat) copy_qt_qt(quat, path->data[path->len-1].quat);
-                               if(radius) *radius= path->data[path->len-1].radius;
+                               if (quat) copy_qt_qt(quat, path->data[path->len-1].quat);
+                               if (radius) *radius= path->data[path->len-1].radius;
                                /* weight - not used but could be added */
                        }
                }
@@ -539,31 +539,31 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3],
        const int is_neg_axis = (axis > 2);
 
        /* to be sure, mostly after file load */
-       if(cu->path==NULL) {
+       if (cu->path==NULL) {
                makeDispListCurveTypes(scene, par, 0);
-               if(cu->path==NULL) return 0;    // happens on append...
+               if (cu->path==NULL) return 0;   // happens on append...
        }
        
        /* options */
        if (is_neg_axis) {
                index = axis - 3;
-               if(cu->flag & CU_STRETCH)
+               if (cu->flag & CU_STRETCH)
                        fac= (-co[index]-cd->dmax[index])/(cd->dmax[index] - cd->dmin[index]);
                else
                        fac= - (co[index]-cd->dmax[index])/(cu->path->totdist);
        }
        else {
                index = axis;
-               if(cu->flag & CU_STRETCH)
+               if (cu->flag & CU_STRETCH)
                        fac= (co[index]-cd->dmin[index])/(cd->dmax[index] - cd->dmin[index]);
                else
                        fac= + (co[index]-cd->dmin[index])/(cu->path->totdist);
        }
        
-       if( where_on_path_deform(par, fac, loc, dir, new_quat, &radius)) {      /* returns OK */
+       if ( where_on_path_deform(par, fac, loc, dir, new_quat, &radius)) {     /* returns OK */
                float quat[4], cent[3];
 
-               if(cd->no_rot_axis) {   /* set by caller */
+               if (cd->no_rot_axis) {  /* set by caller */
 
                        /* this is not exactly the same as 2.4x, since the axis is having rotation removed rather than
                         * changing the axis before calculating the tilt but serves much the same purpose */
@@ -603,7 +603,7 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3],
 
 
                /* scale if enabled */
-               if(cu->flag & CU_PATH_RADIUS)
+               if (cu->flag & CU_PATH_RADIUS)
                        mul_v3_fl(cent, radius);
                
                /* local rotation */
@@ -613,7 +613,7 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3],
                /* translation */
                add_v3_v3v3(co, cent, loc);
 
-               if(quat_r)
+               if (quat_r)
                        copy_qt_qt(quat_r, quat);
 
                return 1;
@@ -631,7 +631,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
        int use_vgroups;
        const int is_neg_axis = (defaxis > 2);
 
-       if(cuOb->type != OB_CURVE)
+       if (cuOb->type != OB_CURVE)
                return;
 
        cu = cuOb->data;
@@ -641,7 +641,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
        init_curve_deform(cuOb, target, &cd);
 
        /* dummy bounds, keep if CU_DEFORM_BOUNDS_OFF is set */
-       if(is_neg_axis == FALSE) {
+       if (is_neg_axis == FALSE) {
                cd.dmin[0]= cd.dmin[1]= cd.dmin[2]= 0.0f;
                cd.dmax[0]= cd.dmax[1]= cd.dmax[2]= 1.0f;
        }
@@ -655,32 +655,32 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
         * we want either a Mesh with no derived data, or derived data with
         * deformverts
         */
-       if(target && target->type==OB_MESH) {
+       if (target && target->type==OB_MESH) {
                /* if there's derived data without deformverts, don't use vgroups */
-               if(dm && !dm->getVertData(dm, 0, CD_MDEFORMVERT))
+               if (dm && !dm->getVertData(dm, 0, CD_MDEFORMVERT))
                        use_vgroups = 0;
                else
                        use_vgroups = 1;
        } else
                use_vgroups = 0;
        
-       if(vgroup && vgroup[0] && use_vgroups) {
+       if (vgroup && vgroup[0] && use_vgroups) {
                Mesh *me= target->data;
                int index= defgroup_name_index(target, vgroup);
 
-               if(index != -1 && (me->dvert || dm)) {
+               if (index != -1 && (me->dvert || dm)) {
                        MDeformVert *dvert = me->dvert;
                        float vec[3];
                        float weight;
        
 
-                       if(cu->flag & CU_DEFORM_BOUNDS_OFF) {
+                       if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
                                dvert = me->dvert;
-                               for(a = 0; a < numVerts; a++, dvert++) {
-                                       if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
+                               for (a = 0; a < numVerts; a++, dvert++) {
+                                       if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
                                        weight= defvert_find_weight(dvert, index);
        
-                                       if(weight > 0.0f) {
+                                       if (weight > 0.0f) {
                                                mul_m4_v3(cd.curvespace, vertexCos[a]);
                                                copy_v3_v3(vec, vertexCos[a]);
                                                calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
@@ -693,22 +693,22 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
                                /* set mesh min/max bounds */
                                INIT_MINMAX(cd.dmin, cd.dmax);
        
-                               for(a = 0; a < numVerts; a++, dvert++) {
-                                       if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
+                               for (a = 0; a < numVerts; a++, dvert++) {
+                                       if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
                                        
-                                       if(defvert_find_weight(dvert, index) > 0.0f) {
+                                       if (defvert_find_weight(dvert, index) > 0.0f) {
                                                mul_m4_v3(cd.curvespace, vertexCos[a]);
                                                DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax);
                                        }
                                }
        
                                dvert = me->dvert;
-                               for(a = 0; a < numVerts; a++, dvert++) {
-                                       if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
+                               for (a = 0; a < numVerts; a++, dvert++) {
+                                       if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
                                        
                                        weight= defvert_find_weight(dvert, index);
        
-                                       if(weight > 0.0f) {
+                                       if (weight > 0.0f) {
                                                /* already in 'cd.curvespace', prev for loop */
                                                copy_v3_v3(vec, vertexCos[a]);
                                                calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
@@ -720,8 +720,8 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
                }
        }
        else {
-               if(cu->flag & CU_DEFORM_BOUNDS_OFF) {
-                       for(a = 0; a < numVerts; a++) {
+               if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
+                       for (a = 0; a < numVerts; a++) {
                                mul_m4_v3(cd.curvespace, vertexCos[a]);
                                calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
                                mul_m4_v3(cd.objectspace, vertexCos[a]);
@@ -731,12 +731,12 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
                        /* set mesh min max bounds */
                        INIT_MINMAX(cd.dmin, cd.dmax);
                                
-                       for(a = 0; a < numVerts; a++) {
+                       for (a = 0; a < numVerts; a++) {
                                mul_m4_v3(cd.curvespace, vertexCos[a]);
                                DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax);
                        }
        
-                       for(a = 0; a < numVerts; a++) {
+                       for (a = 0; a < numVerts; a++) {
                                /* already in 'cd.curvespace', prev for loop */
                                calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
                                mul_m4_v3(cd.objectspace, vertexCos[a]);
@@ -755,7 +755,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
        CurveDeform cd;
        float quat[4];
        
-       if(cuOb->type != OB_CURVE) {
+       if (cuOb->type != OB_CURVE) {
                unit_m3(mat);
                return;
        }
@@ -768,7 +768,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
 
        mul_m4_v3(cd.curvespace, vec);
        
-       if(calc_curve_deform(scene, cuOb, vec, target->trackflag, &cd, quat)) {
+       if (calc_curve_deform(scene, cuOb, vec, target->trackflag, &cd, quat)) {
                float qmat[3][3];
                
                quat_to_mat3( qmat,quat);
@@ -787,7 +787,7 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
        int a;
        int use_vgroups;
 
-       if(laOb->type != OB_LATTICE)
+       if (laOb->type != OB_LATTICE)
                return;
 
        init_latt_deform(laOb, target);
@@ -796,34 +796,34 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
         * we want either a Mesh with no derived data, or derived data with
         * deformverts
         */
-       if(target && target->type==OB_MESH) {
+       if (target && target->type==OB_MESH) {
                /* if there's derived data without deformverts, don't use vgroups */
-               if(dm && !dm->getVertData(dm, 0, CD_MDEFORMVERT))
+               if (dm && !dm->getVertData(dm, 0, CD_MDEFORMVERT))
                        use_vgroups = 0;
                else
                        use_vgroups = 1;
        } else
                use_vgroups = 0;
        
-       if(vgroup && vgroup[0] && use_vgroups) {
+       if (vgroup && vgroup[0] && use_vgroups) {
                Mesh *me = target->data;
                int index = defgroup_name_index(target, vgroup);
                float weight;
 
-               if(index >= 0 && (me->dvert || dm)) {
+               if (index >= 0 && (me->dvert || dm)) {
                        MDeformVert *dvert = me->dvert;
                        
-                       for(a = 0; a < numVerts; a++, dvert++) {
-                               if(dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
+                       for (a = 0; a < numVerts; a++, dvert++) {
+                               if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
 
                                weight= defvert_find_weight(dvert, index);
 
-                               if(weight > 0.0f)
+                               if (weight > 0.0f)
                                        calc_latt_deform(laOb, vertexCos[a], weight);
                        }
                }
        } else {
-               for(a = 0; a < numVerts; a++) {
+               for (a = 0; a < numVerts; a++) {
                        calc_latt_deform(laOb, vertexCos[a], 1.0f);
                }
        }
@@ -832,7 +832,7 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
 
 int object_deform_mball(Object *ob, ListBase *dispbase)
 {
-       if(ob->parent && ob->parent->type==OB_LATTICE && ob->partype==PARSKEL) {
+       if (ob->parent && ob->parent->type==OB_LATTICE && ob->partype==PARSKEL) {
                DispList *dl;
 
                for (dl=dispbase->first; dl; dl=dl->next) {
@@ -857,19 +857,19 @@ void outside_lattice(Lattice *lt)
        int u, v, w;
        float fac1, du=0.0, dv=0.0, dw=0.0;
 
-       if(lt->flag & LT_OUTSIDE) {
+       if (lt->flag & LT_OUTSIDE) {
                bp= lt->def;
 
-               if(lt->pntsu>1) du= 1.0f/((float)lt->pntsu-1);
-               if(lt->pntsv>1) dv= 1.0f/((float)lt->pntsv-1);
-               if(lt->pntsw>1) dw= 1.0f/((float)lt->pntsw-1);
+               if (lt->pntsu>1) du= 1.0f/((float)lt->pntsu-1);
+               if (lt->pntsv>1) dv= 1.0f/((float)lt->pntsv-1);
+               if (lt->pntsw>1) dw= 1.0f/((float)lt->pntsw-1);
                        
-               for(w=0; w<lt->pntsw; w++) {
+               for (w=0; w<lt->pntsw; w++) {
                        
-                       for(v=0; v<lt->pntsv; v++) {
+                       for (v=0; v<lt->pntsv; v++) {
                        
-                               for(u=0; u<lt->pntsu; u++, bp++) {
-                                       if(u==0 || v==0 || w==0 || u==lt->pntsu-1 || v==lt->pntsv-1 || w==lt->pntsw-1);
+                               for (u=0; u<lt->pntsu; u++, bp++) {
+                                       if (u==0 || v==0 || w==0 || u==lt->pntsu-1 || v==lt->pntsv-1 || w==lt->pntsw-1);
                                        else {
                                        
                                                bp->hide= 1;
@@ -914,9 +914,9 @@ void outside_lattice(Lattice *lt)
        else {
                bp= lt->def;
 
-               for(w=0; w<lt->pntsw; w++)
-                       for(v=0; v<lt->pntsv; v++)
-                               for(u=0; u<lt->pntsu; u++, bp++)
+               for (w=0; w<lt->pntsw; w++)
+                       for (v=0; v<lt->pntsv; v++)
+                               for (u=0; u<lt->pntsu; u++, bp++)
                                        bp->hide= 0;
        }
 }
@@ -927,7 +927,7 @@ float (*lattice_getVertexCos(struct Object *ob, int *numVerts_r))[3]
        int i, numVerts;
        float (*vertexCos)[3];
 
-       if(lt->editlatt) lt= lt->editlatt->latt;
+       if (lt->editlatt) lt= lt->editlatt->latt;
        numVerts = *numVerts_r = lt->pntsu*lt->pntsv*lt->pntsw;
        
        vertexCos = MEM_mallocN(sizeof(*vertexCos)*numVerts,"lt_vcos");
@@ -990,6 +990,6 @@ struct MDeformVert* lattice_get_deform_verts(struct Object *oblatt)
 {
        Lattice *lt = (Lattice*)oblatt->data;
        BLI_assert(oblatt->type == OB_LATTICE);
-       if(lt->editlatt) lt= lt->editlatt->latt;
+       if (lt->editlatt) lt= lt->editlatt->latt;
        return lt->dvert;
 }
index f685d0e..4327044 100644 (file)
@@ -82,29 +82,29 @@ void free_material(Material *ma)
        MTex *mtex;
        int a;
        
-       for(a=0; a<MAX_MTEX; a++) {
+       for (a=0; a<MAX_MTEX; a++) {
                mtex= ma->mtex[a];
-               if(mtex && mtex->tex) mtex->tex->id.us--;
-               if(mtex) MEM_freeN(mtex);
+               if (mtex && mtex->tex) mtex->tex->id.us--;
+               if (mtex) MEM_freeN(mtex);
        }
        
-       if(ma->ramp_col) MEM_freeN(ma->ramp_col);
-       if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
+       if (ma->ramp_col) MEM_freeN(ma->ramp_col);
+       if (ma->ramp_spec) MEM_freeN(ma->ramp_spec);
        
        BKE_free_animdata((ID *)ma);
        
-       if(ma->preview)
+       if (ma->preview)
                BKE_previewimg_free(&ma->preview);
        BKE_icon_delete((struct ID*)ma);
        ma->id.icon_id = 0;
        
        /* is no lib link block, but material extension */
-       if(ma->nodetree) {
+       if (ma->nodetree) {
                ntreeFreeTree(ma->nodetree);
                MEM_freeN(ma->nodetree);
        }
 
-       if(ma->gpumaterial.first)
+       if (ma->gpumaterial.first)
                GPU_material_free(ma);
 }
 
@@ -220,20 +220,20 @@ Material *copy_material(Material *ma)
        
        id_lib_extern((ID *)man->group);
        
-       for(a=0; a<MAX_MTEX; a++) {
-               if(ma->mtex[a]) {
+       for (a=0; a<MAX_MTEX; a++) {
+               if (ma->mtex[a]) {
                        man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
                        memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
                        id_us_plus((ID *)man->mtex[a]->tex);
                }
        }
        
-       if(ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col);
-       if(ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec);
+       if (ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col);
+       if (ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec);
        
        if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview);
 
-       if(ma->nodetree) {
+       if (ma->nodetree) {
                man->nodetree= ntreeCopyTree(ma->nodetree);     /* 0 == full new tree */
        }
 
@@ -252,19 +252,19 @@ Material *localize_material(Material *ma)
        BLI_remlink(&G.main->mat, man);
 
        /* no increment for texture ID users, in previewrender.c it prevents decrement */
-       for(a=0; a<MAX_MTEX; a++) {
-               if(ma->mtex[a]) {
+       for (a=0; a<MAX_MTEX; a++) {
+               if (ma->mtex[a]) {
                        man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
                        memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
                }
        }
        
-       if(ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col);
-       if(ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec);
+       if (ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col);
+       if (ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec);
        
        man->preview = NULL;
        
-       if(ma->nodetree)
+       if (ma->nodetree)
                man->nodetree= ntreeLocalize(ma->nodetree);
        
        man->gpumaterial.first= man->gpumaterial.last= NULL;
@@ -275,8 +275,8 @@ Material *localize_material(Material *ma)
 static void extern_local_material(Material *ma)
 {
        int i;
-       for(i=0; i < MAX_MTEX; i++) {
-               if(ma->mtex[i]) id_lib_extern((ID *)ma->mtex[i]->tex);
+       for (i=0; i < MAX_MTEX; i++) {
+               if (ma->mtex[i]) id_lib_extern((ID *)ma->mtex[i]->tex);
        }
 }
 
@@ -294,10 +294,10 @@ void make_local_material(Material *ma)
                * - mixed: make copy
                */
        
-       if(ma->id.lib==NULL) return;
+       if (ma->id.lib==NULL) return;
 
        /* One local user; set flag and return. */
-       if(ma->id.us==1) {
+       if (ma->id.us==1) {
                id_clear_lib_data(bmain, &ma->id);
                extern_local_material(ma);
                return;
@@ -308,10 +308,10 @@ void make_local_material(Material *ma)
        /* test objects */
        ob= bmain->object.first;
        while(ob) {
-               if(ob->mat) {
-                       for(a=0; a<ob->totcol; a++) {
-                               if(ob->mat[a]==ma) {
-                                       if(ob->id.lib) is_lib= TRUE;
+               if (ob->mat) {
+                       for (a=0; a<ob->totcol; a++) {
+                               if (ob->mat[a]==ma) {
+                                       if (ob->id.lib) is_lib= TRUE;
                                        else is_local= TRUE;
                                }
                        }
@@ -321,10 +321,10 @@ void make_local_material(Material *ma)
        /* test meshes */
        me= bmain->mesh.first;
        while(me) {
-               if(me->mat) {
-                       for(a=0; a<me->totcol; a++) {
-                               if(me->mat[a]==ma) {
-                                       if(me->id.lib) is_lib= TRUE;
+               if (me->mat) {
+                       for (a=0; a<me->totcol; a++) {
+                               if (me->mat[a]==ma) {
+                                       if (me->id.lib) is_lib= TRUE;
                                        else is_local= TRUE;
                                }
                        }
@@ -334,10 +334,10 @@ void make_local_material(Material *ma)
        /* test curves */
        cu= bmain->curve.first;
        while(cu) {
-               if(cu->mat) {
-                       for(a=0; a<cu->totcol; a++) {
-                               if(cu->mat[a]==ma) {
-                                       if(cu->id.lib) is_lib= TRUE;
+               if (cu->mat) {
+                       for (a=0; a<cu->totcol; a++) {
+                               if (cu->mat[a]==ma) {
+                                       if (cu->id.lib) is_lib= TRUE;
                                        else is_local= TRUE;
                                }
                        }
@@ -347,10 +347,10 @@ void make_local_material(Material *ma)
        /* test mballs */
        mb= bmain->mball.first;
        while(mb) {
-               if(mb->mat) {
-                       for(a=0; a<mb->totcol; a++) {
-                               if(mb->mat[a]==ma) {
-                                       if(mb->id.lib) is_lib= TRUE;
+               if (mb->mat) {
+                       for (a=0; a<mb->totcol; a++) {
+                               if (mb->mat[a]==ma) {
+                                       if (mb->id.lib) is_lib= TRUE;
                                        else is_local= TRUE;
                                }
                        }
@@ -359,12 +359,12 @@ void make_local_material(Material *ma)
        }
 
        /* Only local users. */
-       if(is_local && is_lib == FALSE) {
+       if (is_local && is_lib == FALSE) {
                id_clear_lib_data(bmain, &ma->id);
                extern_local_material(ma);
        }
        /* Both user and local, so copy. */
-       else if(is_local && is_lib) {
+       else if (is_local && is_lib) {
                Material *ma_new= copy_material(ma);
 
                ma_new->id.us= 0;
@@ -375,10 +375,10 @@ void make_local_material(Material *ma)
                /* do objects */
                ob= bmain->object.first;
                while(ob) {
-                       if(ob->mat) {
-                               for(a=0; a<ob->totcol; a++) {
-                                       if(ob->mat[a]==ma) {
-                                               if(ob->id.lib==NULL) {
+                       if (ob->mat) {
+                               for (a=0; a<ob->totcol; a++) {
+                                       if (ob->mat[a]==ma) {
+                                               if (ob->id.lib==NULL) {
                                                        ob->mat[a]= ma_new;
                                                        ma_new->id.us++;
                                                        ma->id.us--;
@@ -391,10 +391,10 @@ void make_local_material(Material *ma)
                /* do meshes */
                me= bmain->mesh.first;
                while(me) {
-                       if(me->mat) {
-                               for(a=0; a<me->totcol; a++) {
-                                       if(me->mat[a]==ma) {
-                                               if(me->id.lib==NULL) {
+                       if (me->mat) {
+                               for (a=0; a<me->totcol; a++) {
+                                       if (me->mat[a]==ma) {
+                                               if (me->id.lib==NULL) {
                                                        me->mat[a]= ma_new;
                                                        ma_new->id.us++;
                                                        ma->id.us--;
@@ -407,10 +407,10 @@ void make_local_material(Material *ma)
                /* do curves */
                cu= bmain->curve.first;
                while(cu) {
-                       if(cu->mat) {
-                               for(a=0; a<cu->totcol; a++) {
-                                       if(cu->mat[a]==ma) {
-                                               if(cu->id.lib==NULL) {
+                       if (cu->mat) {
+                               for (a=0; a<cu->totcol; a++) {
+                                       if (cu->mat[a]==ma) {
+                                               if (cu->id.lib==NULL) {
                                                        cu->mat[a]= ma_new;
                                                        ma_new->id.us++;
                                                        ma->id.us--;
@@ -423,10 +423,10 @@ void make_local_material(Material *ma)
                /* do mballs */
                mb= bmain->mball.first;
                while(mb) {
-                       if(mb->mat) {
-                               for(a=0; a<mb->totcol; a++) {
-                                       if(mb->mat[a]==ma) {
-                                               if(mb->id.lib==NULL) {
+                       if (mb->mat) {
+                               for (a=0; a<mb->totcol; a++) {
+                                       if (mb->mat[a]==ma) {
+                                               if (mb->id.lib==NULL) {
                                                        mb->mat[a]= ma_new;
                                                        ma_new->id.us++;
                                                        ma->id.us--;
@@ -443,7 +443,7 @@ void make_local_material(Material *ma)
 void extern_local_matarar(struct Material **matar, short totcol)
 {
        short i;
-       for(i= 0; i < totcol; i++) {
+       for (i= 0; i < totcol; i++) {
                id_lib_extern((ID *)matar[i]);
        }
 }
@@ -454,7 +454,7 @@ Material ***give_matarar(Object *ob)
        Curve *cu;
        MetaBall *mb;
        
-       if(ob->type==OB_MESH) {
+       if (ob->type==OB_MESH) {
                me= ob->data;
                return &(me->mat);
        }
@@ -462,7 +462,7 @@ Material ***give_matarar(Object *ob)
                cu= ob->data;
                return &(cu->mat);
        }
-       else if(ob->type==OB_MBALL) {
+       else if (ob->type==OB_MBALL) {
                mb= ob->data;
                return &(mb->mat);
        }
@@ -475,7 +475,7 @@ short *give_totcolp(Object *ob)
        Curve *cu;
        MetaBall *mb;
        
-       if(ob->type==OB_MESH) {
+       if (ob->type==OB_MESH) {
                me= ob->data;
                return &(me->totcol);
        }
@@ -483,7 +483,7 @@ short *give_totcolp(Object *ob)
                cu= ob->data;
                return &(cu->totcol);
        }
-       else if(ob->type==OB_MBALL) {
+       else if (ob->type==OB_MBALL) {
                mb= ob->data;
                return &(mb->totcol);
        }
@@ -541,11 +541,11 @@ static void data_delete_material_index_id(ID *id, short index)
 void material_append_id(ID *id, Material *ma)
 {
        Material ***matar;
-       if((matar= give_matarar_id(id))) {
+       if ((matar= give_matarar_id(id))) {
                short *totcol= give_totcolp_id(id);
                Material **mat= MEM_callocN(sizeof(void *) * ((*totcol) + 1), "newmatar");
-               if(*totcol) memcpy(mat, *matar, sizeof(void *) * (*totcol));
-               if(*matar) MEM_freeN(*matar);
+               if (*totcol) memcpy(mat, *matar, sizeof(void *) * (*totcol));
+               if (*matar) MEM_freeN(*matar);
 
                *matar= mat;
                (*matar)[(*totcol)++]= ma;
@@ -560,21 +560,21 @@ Material *material_pop_id(ID *id, int index_i, int remove_material_slot)
        short index= (short)index_i;
        Material *ret= NULL;
        Material ***matar;
-       if((matar= give_matarar_id(id))) {
+       if ((matar= give_matarar_id(id))) {
                short *totcol= give_totcolp_id(id);
-               if(index >= 0 && index < (*totcol)) {
+               if (index >= 0 && index < (*totcol)) {
                        ret= (*matar)[index];
                        id_us_min((ID *)ret);
 
                        if (remove_material_slot) {
-                               if(*totcol <= 1) {
+                               if (*totcol <= 1) {
                                        *totcol= 0;
                                        MEM_freeN(*matar);
                                        *matar= NULL;
                                }
                                else {
                                        Material **mat;
-                                       if(index + 1 != (*totcol))
+                                       if (index + 1 != (*totcol))
                                                memmove((*matar)+index, (*matar)+(index+1), sizeof(void *) * ((*totcol) - (index + 1)));
 
                                        (*totcol)--;
@@ -605,32 +605,32 @@ Material *give_current_material(Object *ob, short act)
        Material ***matarar, *ma;
        short *totcolp;
        
-       if(ob==NULL) return NULL;
+       if (ob==NULL) return NULL;
        
        /* if object cannot have material, totcolp==NULL */
        totcolp= give_totcolp(ob);
-       if(totcolp==NULL || ob->totcol==0) return NULL;
+       if (totcolp==NULL || ob->totcol==0) return NULL;
        
-       if(act<0) {
+       if (act<0) {
                printf("no!\n");
        }
        
-       if(act>ob->totcol) act= ob->totcol;
-       else if(act<=0) act= 1;
+       if (act>ob->totcol) act= ob->totcol;
+       else if (act<=0) act= 1;
 
-       if(ob->matbits && ob->matbits[act-1]) { /* in object */
+       if (ob->matbits && ob->matbits[act-1]) {        /* in object */
                ma= ob->mat[act-1];
        }
        else {                                                          /* in data */
 
                /* check for inconsistency */
-               if(*totcolp < ob->totcol)
+               if (*totcolp < ob->totcol)
                        ob->totcol= *totcolp;
-               if(act>ob->totcol) act= ob->totcol;
+               if (act>ob->totcol) act= ob->totcol;
 
                matarar= give_matarar(ob);
                
-               if(matarar && *matarar) ma= (*matarar)[act-1];
+               if (matarar && *matarar) ma= (*matarar)[act-1];
                else ma= NULL;
                
        }
@@ -641,21 +641,21 @@ Material *give_current_material(Object *ob, short act)
 ID *material_from(Object *ob, short act)
 {
 
-       if(ob==NULL) return NULL;
+       if (ob==NULL) return NULL;
 
-       if(ob->totcol==0) return ob->data;
-       if(act==0) act= 1;
+       if (ob->totcol==0) return ob->data;
+       if (act==0) act= 1;
 
-       if(ob->matbits[act-1]) return (ID *)ob;
+       if (ob->matbits[act-1]) return (ID *)ob;
        else return ob->data;
 }
 
 Material *give_node_material(Material *ma)
 {
-       if(ma && ma->use_nodes && ma->nodetree) {
+       if (ma && ma->use_nodes && ma->nodetree) {
                bNode *node= nodeGetActiveID(ma->nodetree, ID_MA);
 
-               if(node)
+               if (node)
                        return (Material *)node->id;
        }
 
@@ -680,18 +680,18 @@ void resize_object_material(Object *ob, const short totcol)
        Material **newmatar;
        char *newmatbits;
 
-       if(totcol==0) {
-               if(ob->totcol) {
+       if (totcol==0) {
+               if (ob->totcol) {
                        MEM_freeN(ob->mat);
                        MEM_freeN(ob->matbits);
                        ob->mat= NULL;
                        ob->matbits= NULL;
                }
        }
-       else if(ob->totcol<totcol) {
+       else if (ob->totcol<totcol) {
                newmatar= MEM_callocN(sizeof(void *)*totcol, "newmatar");
                newmatbits= MEM_callocN(sizeof(char)*totcol, "newmatbits");
-               if(ob->totcol) {
+               if (ob->totcol) {
                        memcpy(newmatar, ob->mat, sizeof(void *)*ob->totcol);
                        memcpy(newmatbits, ob->matbits, sizeof(char)*ob->totcol);
                        MEM_freeN(ob->mat);
@@ -701,8 +701,8 @@ void resize_object_material(Object *ob, const short totcol)
                ob->matbits= newmatbits;
        }
        ob->totcol= totcol;
-       if(ob->totcol && ob->actcol==0) ob->actcol= 1;
-       if(ob->actcol>ob->totcol) ob->actcol= ob->totcol;
+       if (ob->totcol && ob->actcol==0) ob->actcol= 1;
+       if (ob->actcol>ob->totcol) ob->actcol= ob->totcol;
 }
 
 void test_object_materials(ID *id)
@@ -711,12 +711,12 @@ void test_object_materials(ID *id)
        Object *ob;
        short *totcol;
 
-       if(id==NULL || (totcol=give_totcolp_id(id))==NULL) {
+       if (id==NULL || (totcol=give_totcolp_id(id))==NULL) {
                return;
        }
 
-       for(ob= G.main->object.first; ob; ob= ob->id.next) {
-               if(ob->data==id) {
+       for (ob= G.main->object.first; ob; ob= ob->id.next) {
+               if (ob->data==id) {
                        resize_object_material(ob, *totcol);
                }
        }
@@ -727,24 +727,24 @@ void assign_material_id(ID *id, Material *ma, short act)
        Material *mao, **matar, ***matarar;
        short *totcolp;
 
-       if(act>MAXMAT) return;
-       if(act<1) act= 1;
+       if (act>MAXMAT) return;
+       if (act<1) act= 1;
 
        /* prevent crashing when using accidentally */
        BLI_assert(id->lib == NULL);
-       if(id->lib) return;
+       if (id->lib) return;
 
        /* test arraylens */
 
        totcolp= give_totcolp_id(id);
        matarar= give_matarar_id(id);
 
-       if(totcolp==NULL || matarar==NULL) return;
+       if (totcolp==NULL || matarar==NULL) return;
 
-       if(act > *totcolp) {
+       if (act > *totcolp) {
                matar= MEM_callocN(sizeof(void *)*act, "matarray1");
 
-               if(*totcolp) {
+               if (*totcolp) {
                        memcpy(matar, *matarar, sizeof(void *)*(*totcolp));
                        MEM_freeN(*matarar);
                }
@@ -755,10 +755,10 @@ void assign_material_id(ID *id, Material *ma, short act)
 
        /* in data */
        mao= (*matarar)[act-1];
-       if(mao) mao->id.us--;
+       if (mao) mao->id.us--;
        (*matarar)[act-1]= ma;
 
-       if(ma)
+       if (ma)
                id_us_plus((ID *)ma);
 
        test_object_materials(id);
@@ -770,24 +770,24 @@ void assign_material(Object *ob, Material *ma, short act)
        char *matbits;
        short *totcolp;
 
-       if(act>MAXMAT) return;
-       if(act<1) act= 1;
+       if (act>MAXMAT) return;
+       if (act<1) act= 1;
        
        /* prevent crashing when using accidentally */
        BLI_assert(ob->id.lib == NULL);
-       if(ob->id.lib) return;
+       if (ob->id.lib) return;
        
        /* test arraylens */
        
        totcolp= give_totcolp(ob);
        matarar= give_matarar(ob);
        
-       if(totcolp==NULL || matarar==NULL) return;
+       if (totcolp==NULL || matarar==NULL) return;
        
-       if(act > *totcolp) {
+       if (act > *totcolp) {
                matar= MEM_callocN(sizeof(void *)*act, "matarray1");
 
-               if(*totcolp) {
+               if (*totcolp) {
                        memcpy(matar, *matarar, sizeof(void *)*(*totcolp));
                        MEM_freeN(*matarar);
                }
@@ -796,10 +796,10 @@ void assign_material(Object *ob, Material *ma, short act)
                *totcolp= act;
        }
        
-       if(act > ob->totcol) {
+       if (act > ob->totcol) {
                matar= MEM_callocN(sizeof(void *)*act, "matarray2");
                matbits= MEM_callocN(sizeof(char)*act, "matbits1");
-               if( ob->totcol) {
+               if ( ob->totcol) {
                        memcpy(matar, ob->mat, sizeof(void *)*( ob->totcol ));
                        memcpy(matbits, ob->matbits, sizeof(char)*(*totcolp));
                        MEM_freeN(ob->mat);
@@ -810,7 +810,7 @@ void assign_material(Object *ob, Material *ma, short act)
                ob->totcol= act;
 
                /* copy object/mesh linking, or assign based on userpref */
-               if(ob->actcol)
+               if (ob->actcol)
                        ob->matbits[act-1]= ob->matbits[ob->actcol-1];
                else
                        ob->matbits[act-1]= (U.flag & USER_MAT_ON_OB)? 1: 0;
@@ -818,18 +818,18 @@ void assign_material(Object *ob, Material *ma, short act)
        
        /* do it */
 
-       if(ob->matbits[act-1]) {        /* in object */
+       if (ob->matbits[act-1]) {       /* in object */
                mao= ob->mat[act-1];
-               if(mao) mao->id.us--;
+               if (mao) mao->id.us--;
                ob->mat[act-1]= ma;
        }
        else {  /* in data */
                mao= (*matarar)[act-1];
-               if(mao) mao->id.us--;
+               if (mao) mao->id.us--;
                (*matarar)[act-1]= ma;
        }
 
-       if(ma)
+       if (ma)
                id_us_plus((ID *)ma);
        test_object_materials(ob->data);
 }
@@ -843,10 +843,10 @@ void assign_matarar(struct Object *ob, struct Material ***matar, short totcol)
        while(object_remove_material_slot(ob)) {};
 
        /* now we have the right number of slots */
-       for(i=0; i<totcol; i++)
+       for (i=0; i<totcol; i++)
                assign_material(ob, (*matar)[i], i+1);
 
-       if(actcol_orig > ob->totcol)
+       if (actcol_orig > ob->totcol)
                actcol_orig= ob->totcol;
 
        ob->actcol= actcol_orig;
@@ -858,25 +858,25 @@ short find_material_index(Object *ob, Material *ma)
        Material ***matarar;
        short a, *totcolp;
        
-       if(ma==NULL) return 0;
+       if (ma==NULL) return 0;
        
        totcolp= give_totcolp(ob);
        matarar= give_matarar(ob);
        
-       if(totcolp==NULL || matarar==NULL) return 0;
+       if (totcolp==NULL || matarar==NULL) return 0;
        
-       for(a=0; a<*totcolp; a++)
-               if((*matarar)[a]==ma)
+       for (a=0; a<*totcolp; a++)
+               if ((*matarar)[a]==ma)
                   break;
-       if(a<*totcolp)
+       if (a<*totcolp)
                return a+1;
        return 0;          
 }
 
 int object_add_material_slot(Object *ob)
 {
-       if(ob==NULL) return FALSE;
-       if(ob->totcol>=MAXMAT) return FALSE;
+       if (ob==NULL) return FALSE;
+       if (ob->totcol>=MAXMAT) return FALSE;
        
        assign_material(ob, NULL, ob->totcol+1);
        ob->actcol= ob->totcol;
@@ -888,51 +888,51 @@ static void do_init_render_material(Material *ma, int r_mode, float *amb)
        MTex *mtex;
        int a, needuv=0, needtang=0;
        
-       if(ma->flarec==0) ma->flarec= 1;
+       if (ma->flarec==0) ma->flarec= 1;
 
        /* add all texcoflags from mtex, texco and mapto were cleared in advance */
-       for(a=0; a<MAX_MTEX; a++) {
+       for (a=0; a<MAX_MTEX; a++) {
                
                /* separate tex switching */
-               if(ma->septex & (1<<a)) continue;
+               if (ma->septex & (1<<a)) continue;
 
                mtex= ma->mtex[a];
-               if(mtex && mtex->tex && (mtex->tex->type | (mtex->tex->use_nodes && mtex->tex->nodetree) )) {
+               if (mtex && mtex->tex && (mtex->tex->type | (mtex->tex->use_nodes && mtex->tex->nodetree) )) {
                        
                        ma->texco |= mtex->texco;
                        ma->mapto |= mtex->mapto;
 
                        /* always get derivatives for these textures */
                        if ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) ma->texco |= TEXCO_OSA;
-                       else if(mtex->texflag & (MTEX_COMPAT_BUMP|MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP)) ma->texco |= TEXCO_OSA;
+                       else if (mtex->texflag & (MTEX_COMPAT_BUMP|MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP)) ma->texco |= TEXCO_OSA;
                        
-                       if(ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1;
-                       else if(ma->texco & (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT|TEXCO_SPEED)) needuv= 1;
-                       else if(ma->texco & (TEXCO_LAVECTOR|TEXCO_VIEW|TEXCO_STICKY)) needuv= 1;
+                       if (ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1;
+                       else if (ma->texco & (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT|TEXCO_SPEED)) needuv= 1;
+                       else if (ma->texco & (TEXCO_LAVECTOR|TEXCO_VIEW|TEXCO_STICKY)) needuv= 1;
 
-                       if((ma->mapto & MAP_NORM) && (mtex->normapspace == MTEX_NSPACE_TANGENT))
+                       if ((ma->mapto & MAP_NORM) && (mtex->normapspace == MTEX_NSPACE_TANGENT))
                                needtang= 1;
                }
        }
 
-       if(needtang) ma->mode |= MA_NORMAP_TANG;
+       if (needtang) ma->mode |= MA_NORMAP_TANG;
        else ma->mode &= ~MA_NORMAP_TANG;
        
-       if(ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) {
+       if (ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) {
                needuv= 1;
-               if(r_mode & R_OSA) ma->texco |= TEXCO_OSA;              /* for texfaces */
+               if (r_mode & R_OSA) ma->texco |= TEXCO_OSA;             /* for texfaces */
        }
-       if(needuv) ma->texco |= NEED_UV;
+       if (needuv) ma->texco |= NEED_UV;
        
        /* since the raytracer doesnt recalc O structs for each ray, we have to preset them all */
-       if(r_mode & R_RAYTRACE) {
-               if((ma->mode & (MA_RAYMIRROR|MA_SHADOW_TRA)) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_RAYTRANSP))) {
+       if (r_mode & R_RAYTRACE) {
+               if ((ma->mode & (MA_RAYMIRROR|MA_SHADOW_TRA)) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_RAYTRANSP))) {
                        ma->texco |= NEED_UV|TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM;
-                       if(r_mode & R_OSA) ma->texco |= TEXCO_OSA;
+                       if (r_mode & R_OSA) ma->texco |= TEXCO_OSA;
                }
        }
        
-       if(amb) {
+       if (amb) {
                ma->ambr= ma->amb*amb[0];
                ma->ambg= ma->amb*amb[1];
                ma->ambb= ma->amb*amb[2];
@@ -941,11 +941,11 @@ static void do_init_render_material(Material *ma, int r_mode, float *amb)
        ma->mode_l= ma->mode;
        ma->mode_l &= ~MA_SHLESS;
 
-       if(ma->strand_surfnor > 0.0f)
+       if (ma->strand_surfnor > 0.0f)
                ma->mode_l |= MA_STR_SURFDIFF;
 
        /* parses the geom+tex nodes */
-       if(ma->nodetree && ma->use_nodes)
+       if (ma->nodetree && ma->use_nodes)
                ntreeShaderGetTexcoMode(ma->nodetree, r_mode, &ma->texco, &ma->mode_l);
 }
 
@@ -953,17 +953,17 @@ static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode
 {
        bNode *node;
        
-       for(node=ntree->nodes.first; node; node= node->next) {
-               if(node->id) {
-                       if(GS(node->id->name)==ID_MA) {
+       for (node=ntree->nodes.first; node; node= node->next) {
+               if (node->id) {
+                       if (GS(node->id->name)==ID_MA) {
                                Material *ma= (Material *)node->id;
-                               if(ma!=basemat) {
+                               if (ma!=basemat) {
                                        do_init_render_material(ma, r_mode, amb);
                                        basemat->texco |= ma->texco;
                                        basemat->mode_l |= ma->mode_l & ~(MA_TRANSP|MA_ZTRANSP|MA_RAYTRANSP); 
                                }
                        }
-                       else if(node->type==NODE_GROUP)
+                       else if (node->type==NODE_GROUP)
                                init_render_nodetree((bNodeTree *)node->id, basemat, r_mode, amb);
                }
        }
@@ -974,7 +974,7 @@ void init_render_material(Material *mat, int r_mode, float *amb)
        
        do_init_render_material(mat, r_mode, amb);
        
-       if(mat->nodetree && mat->use_nodes) {
+       if (mat->nodetree && mat->use_nodes) {
                init_render_nodetree(mat->nodetree, mat, r_mode, amb);
                
                if (!mat->nodetree->execdata)
@@ -989,18 +989,18 @@ void init_render_materials(Main *bmain, int r_mode, float *amb)
        /* clear these flags before going over materials, to make sure they
         * are cleared only once, otherwise node materials contained in other
         * node materials can go wrong */
-       for(ma= bmain->mat.first; ma; ma= ma->id.next) {
-               if(ma->id.us) {
+       for (ma= bmain->mat.first; ma; ma= ma->id.next) {
+               if (ma->id.us) {
                        ma->texco= 0;
                        ma->mapto= 0;
                }
        }
 
        /* two steps, first initialize, then or the flags for layers */
-       for(ma= bmain->mat.first; ma; ma= ma->id.next) {
+       for (ma= bmain->mat.first; ma; ma= ma->id.next) {
                /* is_used flag comes back in convertblender.c */
                ma->flag &= ~MA_IS_USED;
-               if(ma->id.us) 
+               if (ma->id.us) 
                        init_render_material(ma, r_mode, amb);
        }
        
@@ -1010,7 +1010,7 @@ void init_render_materials(Main *bmain, int r_mode, float *amb)
 /* only needed for nodes now */
 void end_render_material(Material *mat)
 {
-       if(mat && mat->nodetree && mat->use_nodes) {
+       if (mat && mat->nodetree && mat->use_nodes) {
                if (mat->nodetree->execdata)
                        ntreeShaderEndExecTree(mat->nodetree->execdata, 1);
        }
@@ -1019,8 +1019,8 @@ void end_render_material(Material *mat)
 void end_render_materials(Main *bmain)
 {
        Material *ma;
-       for(ma= bmain->mat.first; ma; ma= ma->id.next)
-               if(ma->id.us) 
+       for (ma= bmain->mat.first; ma; ma= ma->id.next)
+               if (ma->id.us) 
                        end_render_material(ma);
 }
 
@@ -1028,13 +1028,13 @@ static int material_in_nodetree(bNodeTree *ntree, Material *mat)
 {
        bNode *node;
 
-       for(node=ntree->nodes.first; node; node= node->next) {
-               if(node->id && GS(node->id->name)==ID_MA) {
-                       if(node->id==(ID*)mat)
+       for (node=ntree->nodes.first; node; node= node->next) {
+               if (node->id && GS(node->id->name)==ID_MA) {
+                       if (node->id==(ID*)mat)
                                return 1;
                }
-               else if(node->type==NODE_GROUP)
-                       if(material_in_nodetree((bNodeTree*)node->id, mat))
+               else if (node->type==NODE_GROUP)
+                       if (material_in_nodetree((bNodeTree*)node->id, mat))
                                return 1;
        }
 
@@ -1043,9 +1043,9 @@ static int material_in_nodetree(bNodeTree *ntree, Material *mat)
 
 int material_in_material(Material *parmat, Material *mat)
 {
-       if(parmat==mat)
+       if (parmat==mat)
                return 1;
-       else if(parmat->nodetree && parmat->use_nodes)
+       else if (parmat->nodetree && parmat->use_nodes)
                return material_in_nodetree(parmat->nodetree, mat);
        else
                return 0;
@@ -1086,15 +1086,15 @@ void automatname(Material *ma)
        int nr, r, g, b;
        float ref;
        
-       if(ma==NULL) return;
-       if(ma->mode & MA_SHLESS) ref= 1.0;
+       if (ma==NULL) return;
+       if (ma->mode & MA_SHLESS) ref= 1.0;
        else ref= ma->ref;
        
        r= (int)(4.99f*(ref*ma->r));
        g= (int)(4.99f*(ref*ma->g));
        b= (int)(4.99f*(ref*ma->b));
        nr= r + 5*g + 25*b;
-       if(nr>124) nr= 124;
+       if (nr>124) nr= 124;
        new_id(&G.main->mat, (ID *)ma, colname_array[nr]);
        
 }
@@ -1127,17 +1127,17 @@ int object_remove_material_slot(Object *ob)
        totcolp= give_totcolp(ob);
        matarar= give_matarar(ob);
 
-       if(*matarar==NULL) return FALSE;
+       if (*matarar==NULL) return FALSE;
 
        /* we delete the actcol */
        mao= (*matarar)[ob->actcol-1];
-       if(mao) mao->id.us--;
+       if (mao) mao->id.us--;
        
-       for(a=ob->actcol; a<ob->totcol; a++)
+       for (a=ob->actcol; a<ob->totcol; a++)
                (*matarar)[a-1]= (*matarar)[a];
        (*totcolp)--;
        
-       if(*totcolp==0) {
+       if (*totcolp==0) {
                MEM_freeN(*matarar);
                *matarar= NULL;
        }
@@ -1146,20 +1146,20 @@ int object_remove_material_slot(Object *ob)
        obt= G.main->object.first;
        while(obt) {
        
-               if(obt->data==ob->data) {
+               if (obt->data==ob->data) {
                        
                        /* WATCH IT: do not use actcol from ob or from obt (can become zero) */
                        mao= obt->mat[actcol-1];
-                       if(mao) mao->id.us--;
+                       if (mao) mao->id.us--;
                
-                       for(a=actcol; a<obt->totcol; a++) {
+                       for (a=actcol; a<obt->totcol; a++) {
                                obt->mat[a-1]= obt->mat[a];
                                obt->matbits[a-1]= obt->matbits[a];
                        }
                        obt->totcol--;
-                       if(obt->actcol > obt->totcol) obt->actcol= obt->totcol;
+                       if (obt->actcol > obt->totcol) obt->actcol= obt->totcol;
                        
-                       if(obt->totcol==0) {
+                       if (obt->totcol==0) {
                                MEM_freeN(obt->mat);
                                MEM_freeN(obt->matbits);
                                obt->mat= NULL;
@@ -1206,15 +1206,15 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
                        r_col[2] = 1.0f - (facm + fac*(1.0f - col[2])) * (1.0f - r_col[2]);
                        break;
                case MA_RAMP_OVERLAY:
-                       if(r_col[0] < 0.5f)
+                       if (r_col[0] < 0.5f)
                                r_col[0] *= (facm + 2.0f*fac*col[0]);
                        else
                                r_col[0] = 1.0f - (facm + 2.0f*fac*(1.0f - col[0])) * (1.0f - r_col[0]);
-                       if(r_col[1] < 0.5f)
+                       if (r_col[1] < 0.5f)
                                r_col[1] *= (facm + 2.0f*fac*col[1]);
                        else
                                r_col[1] = 1.0f - (facm + 2.0f*fac*(1.0f - col[1])) * (1.0f - r_col[1]);
-                       if(r_col[2] < 0.5f)
+                       if (r_col[2] < 0.5f)
                                r_col[2] *= (facm + 2.0f*fac*col[2]);
                        else
                                r_col[2] = 1.0f - (facm + 2.0f*fac*(1.0f - col[2])) * (1.0f - r_col[2]);
@@ -1225,11 +1225,11 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
                        r_col[2] -= fac*col[2];
                        break;
                case MA_RAMP_DIV:
-                       if(col[0]!=0.0f)
+                       if (col[0]!=0.0f)
                                r_col[0] = facm*(r_col[0]) + fac*(r_col[0])/col[0];
-                       if(col[1]!=0.0f)
+                       if (col[1]!=0.0f)
                                r_col[1] = facm*(r_col[1]) + fac*(r_col[1])/col[1];
-                       if(col[2]!=0.0f)
+                       if (col[2]!=0.0f)
                                r_col[2] = facm*(r_col[2]) + fac*(r_col[2])/col[2];
                        break;
                case MA_RAMP_DIFF:
@@ -1239,42 +1239,42 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
                        break;
                case MA_RAMP_DARK:
                        tmp=col[0]+((1-col[0])*facm);
-                       if(tmp < r_col[0]) r_col[0]= tmp;
+                       if (tmp < r_col[0]) r_col[0]= tmp;
                        tmp=col[1]+((1-col[1])*facm);
-                       if(tmp < r_col[1]) r_col[1]= tmp;
+                       if (tmp < r_col[1]) r_col[1]= tmp;
                        tmp=col[2]+((1-col[2])*facm);
-                       if(tmp < r_col[2]) r_col[2]= tmp;
+                       if (tmp < r_col[2]) r_col[2]= tmp;
                        break;
                case MA_RAMP_LIGHT:
                        tmp= fac*col[0];
-                       if(tmp > r_col[0]) r_col[0]= tmp;
+                       if (tmp > r_col[0]) r_col[0]= tmp;
                                tmp= fac*col[1];
-                               if(tmp > r_col[1]) r_col[1]= tmp;
+                               if (tmp > r_col[1]) r_col[1]= tmp;
                                tmp= fac*col[2];
-                               if(tmp > r_col[2]) r_col[2]= tmp;
+                               if (tmp > r_col[2]) r_col[2]= tmp;
                                break;
                case MA_RAMP_DODGE:
-                       if(r_col[0] !=0.0f){
+                       if (r_col[0] != 0.0f) {
                                tmp = 1.0f - fac*col[0];
-                               if(tmp <= 0.0f)
+                               if (tmp <= 0.0f)
                                        r_col[0] = 1.0f;
                                else if ((tmp = (r_col[0]) / tmp)> 1.0f)
                                        r_col[0] = 1.0f;
                                else
                                        r_col[0] = tmp;
                        }
-                       if(r_col[1] !=0.0f){
+                       if (r_col[1] != 0.0f) {
                                tmp = 1.0f - fac*col[1];
-                               if(tmp <= 0.0f )
+                               if (tmp <= 0.0f )
                                        r_col[1] = 1.0f;
                                else if ((tmp = (r_col[1]) / tmp) > 1.0f )
                                        r_col[1] = 1.0f;
                                else
                                        r_col[1] = tmp;
                        }
-                       if(r_col[2] !=0.0f){
+                       if (r_col[2] != 0.0f) {
                                tmp = 1.0f - fac*col[2];
-                               if(tmp <= 0.0f)
+                               if (tmp <= 0.0f)
                                        r_col[2] = 1.0f;
                                else if ((tmp = (r_col[2]) / tmp) > 1.0f )
                                        r_col[2] = 1.0f;
@@ -1285,7 +1285,7 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
                case MA_RAMP_BURN:
                        tmp = facm + fac*col[0];
 
-                       if(tmp <= 0.0f)
+                       if (tmp <= 0.0f)
                                r_col[0] = 0.0f;
                        else if (( tmp = (1.0f - (1.0f - (r_col[0])) / tmp )) < 0.0f)
                                        r_col[0] = 0.0f;
@@ -1295,21 +1295,21 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
                                r_col[0] = tmp;
 
                        tmp = facm + fac*col[1];
-                       if(tmp <= 0.0f)
+                       if (tmp <= 0.0f)
                                r_col[1] = 0.0f;
                        else if (( tmp = (1.0f - (1.0f - (r_col[1])) / tmp )) < 0.0f )
                                        r_col[1] = 0.0f;
-                       else if(tmp >1.0f)
+                       else if (tmp >1.0f)
                                r_col[1]=1.0f;
                        else
                                r_col[1] = tmp;
 
                                tmp = facm + fac*col[2];
-                               if(tmp <= 0.0f)
+                               if (tmp <= 0.0f)
                                r_col[2] = 0.0f;
                        else if (( tmp = (1.0f - (1.0f - (r_col[2])) / tmp )) < 0.0f  )
                                        r_col[2] = 0.0f;
-                       else if(tmp >1.0f)
+                       else if (tmp >1.0f)
                                r_col[2]= 1.0f;
                        else
                                r_col[2] = tmp;
@@ -1320,7 +1320,7 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
                                float colH,colS,colV;
                                float tmpr,tmpg,tmpb;
                                rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
-                               if(colS!=0 ){
+                               if (colS != 0) {
                                        rgb_to_hsv(r_col[0],r_col[1],r_col[2],&rH,&rS,&rV);
                                        hsv_to_rgb( colH , rS, rV, &tmpr, &tmpg, &tmpb);
                                        r_col[0] = facm*(r_col[0]) + fac*tmpr;
@@ -1334,7 +1334,7 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
                                float rH,rS,rV;
                                float colH,colS,colV;
                                rgb_to_hsv(r_col[0],r_col[1],r_col[2],&rH,&rS,&rV);
-                               if(rS!=0){
+                               if (rS != 0) {
                                        rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
                                        hsv_to_rgb( rH, (facm*rS +fac*colS), rV, r_col+0, r_col+1, r_col+2);
                                }
@@ -1355,7 +1355,7 @@ void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
                                float colH,colS,colV;
                                float tmpr,tmpg,tmpb;
                                rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
-                               if(colS!=0){
+                               if (colS != 0) {
                                        rgb_to_hsv(r_col[0],r_col[1],r_col[2],&rH,&rS,&rV);
                                        hsv_to_rgb( colH, colS, rV, &tmpr, &tmpg, &tmpb);
                                        r_col[0] = facm*(r_col[0]) + fac*tmpr;
@@ -1409,20 +1409,20 @@ void free_matcopybuf(void)
 {
        int a;
 
-       for(a=0; a<MAX_MTEX; a++) {
-               if(matcopybuf.mtex[a]) {
+       for (a=0; a<MAX_MTEX; a++) {
+               if (matcopybuf.mtex[a]) {
                        MEM_freeN(matcopybuf.mtex[a]);
                        matcopybuf.mtex[a]= NULL;
                }
        }
 
-       if(matcopybuf.ramp_col) MEM_freeN(matcopybuf.ramp_col);
-       if(matcopybuf.ramp_spec) MEM_freeN(matcopybuf.ramp_spec);
+       if (matcopybuf.ramp_col) MEM_freeN(matcopybuf.ramp_col);
+       if (matcopybuf.ramp_spec) MEM_freeN(matcopybuf.ramp_spec);
 
        matcopybuf.ramp_col= NULL;
        matcopybuf.ramp_spec= NULL;
 
-       if(matcopybuf.nodetree) {
+       if (matcopybuf.nodetree) {
                ntreeFreeTree(matcopybuf.nodetree);
                MEM_freeN(matcopybuf.nodetree);
                matcopybuf.nodetree= NULL;
@@ -1436,16 +1436,16 @@ void copy_matcopybuf(Material *ma)
        int a;
        MTex *mtex;
 
-       if(matcopied)
+       if (matcopied)
                free_matcopybuf();
 
        memcpy(&matcopybuf, ma, sizeof(Material));
-       if(matcopybuf.ramp_col) matcopybuf.ramp_col= MEM_dupallocN(matcopybuf.ramp_col);
-       if(matcopybuf.ramp_spec) matcopybuf.ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec);
+       if (matcopybuf.ramp_col) matcopybuf.ramp_col= MEM_dupallocN(matcopybuf.ramp_col);
+       if (matcopybuf.ramp_spec) matcopybuf.ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec);
 
-       for(a=0; a<MAX_MTEX; a++) {
+       for (a=0; a<MAX_MTEX; a++) {
                mtex= matcopybuf.mtex[a];
-               if(mtex) {
+               if (mtex) {
                        matcopybuf.mtex[a]= MEM_dupallocN(mtex);
                }
        }
@@ -1461,18 +1461,18 @@ void paste_matcopybuf(Material *ma)
        MTex *mtex;
        ID id;
 
-       if(matcopied==0)
+       if (matcopied==0)
                return;
        /* free current mat */
-       if(ma->ramp_col) MEM_freeN(ma->ramp_col);
-       if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
-       for(a=0; a<MAX_MTEX; a++) {
+       if (ma->ramp_col) MEM_freeN(ma->ramp_col);
+       if (ma->ramp_spec) MEM_freeN(ma->ramp_spec);
+       for (a=0; a<MAX_MTEX; a++) {
                mtex= ma->mtex[a];
-               if(mtex && mtex->tex) mtex->tex->id.us--;
-               if(mtex) MEM_freeN(mtex);
+               if (mtex && mtex->tex) mtex->tex->id.us--;
+               if (mtex) MEM_freeN(mtex);
        }
 
-       if(ma->nodetree) {
+       if (ma->nodetree) {
                ntreeFreeTree(ma->nodetree);
                MEM_freeN(ma->nodetree);
        }
@@ -1483,14 +1483,14 @@ void paste_matcopybuf(Material *ma)
        memcpy(ma, &matcopybuf, sizeof(Material));
        (ma->id)= id;
 
-       if(matcopybuf.ramp_col) ma->ramp_col= MEM_dupallocN(matcopybuf.ramp_col);
-       if(matcopybuf.ramp_spec) ma->ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec);
+       if (matcopybuf.ramp_col) ma->ramp_col= MEM_dupallocN(matcopybuf.ramp_col);
+       if (matcopybuf.ramp_spec) ma->ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec);
 
-       for(a=0; a<MAX_MTEX; a++) {
+       for (a=0; a<MAX_MTEX; a++) {
                mtex= ma->mtex[a];
-               if(mtex) {
+               if (mtex) {
                        ma->mtex[a]= MEM_dupallocN(mtex);
-                       if(mtex->tex) id_us_plus((ID *)mtex->tex);
+                       if (mtex->tex) id_us_plus((ID *)mtex->tex);
                }
        }
 
@@ -1600,7 +1600,7 @@ static int integer_getdigits(int number)
        int i=0;
        if (number == 0) return 1;
 
-       while (number != 0){
+       while (number != 0) {
                number = (int)(number/10);
                i++;
        }
@@ -1645,11 +1645,11 @@ static short mesh_addmaterial(Mesh *me, Material *ma)
 
 static void set_facetexture_flags(Material *ma, Image *image)
 {
-       if(image) {
+       if (image) {
                ma->mode |= MA_FACETEXTURE;
                /* we could check if the texture has alpha, but then more meshes sharing the same
                 * material may need it. Let's make it simple. */
-               if(BKE_image_has_alpha(image))
+               if (BKE_image_has_alpha(image))
                        ma->mode |= MA_FACETEXTURE_ALPHA;
        }
 }
@@ -1667,7 +1667,7 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag)
        if ((ma= BLI_findstring(&main->mat, idname+2, offsetof(ID, name)+2))) {
                mat_nr= mesh_getmaterialnumber(me, ma);
                /* assign the material to the mesh */
-               if(mat_nr == -1) mat_nr= mesh_addmaterial(me, ma);
+               if (mat_nr == -1) mat_nr= mesh_addmaterial(me, ma);
 
                /* if needed set "Face Textures [Alpha]" Material options */
                set_facetexture_flags(ma, tf->tpage);
@@ -1676,7 +1676,7 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag)
        else {
                ma= add_material(idname+2);
 
-               if(ma){
+               if (ma) {
                        printf("TexFace Convert: Material \"%s\" created.\n", idname+2);
                        mat_nr= mesh_addmaterial(me, ma);
                        
@@ -1711,10 +1711,10 @@ static void convert_tfacematerial(Main *main, Material *ma)
        CustomDataLayer *cdl;
        char idname[MAX_ID_NAME];
 
-       for(me=main->mesh.first; me; me=me->id.next){
+       for (me=main->mesh.first; me; me=me->id.next) {
                /* check if this mesh uses this material */
-               for(a=0;a<me->totcol;a++)
-                       if(me->mat[a] == ma) break;
+               for (a=0;a<me->totcol;a++)
+                       if (me->mat[a] == ma) break;
                        
                /* no material found */
                if (a == me->totcol) continue;
@@ -1725,8 +1725,8 @@ static void convert_tfacematerial(Main *main, Material *ma)
                if (!cdl) continue;
 
                /* loop over all the faces and stop at the ones that use the material*/
-               for(a=0, mf=me->mface; a<me->totface; a++, mf++) {
-                       if(me->mat[mf->mat_nr] != ma) continue;
+               for (a=0, mf=me->mface; a<me->totface; a++, mf++) {
+                       if (me->mat[mf->mat_nr] != ma) continue;
 
                        /* texface data for this face */
                        tf = ((MTFace*)cdl->data) + a;
@@ -1739,12 +1739,12 @@ static void convert_tfacematerial(Main *main, Material *ma)
                                /* material already existent, see if the mesh has it */
                                mat_nr = mesh_getmaterialnumber(me, mat_new);
                                /* material is not in the mesh, add it */
-                               if(mat_nr == -1) mat_nr= mesh_addmaterial(me, mat_new);
+                               if (mat_nr == -1) mat_nr= mesh_addmaterial(me, mat_new);
                        }
                        /* create a new material */
                        else {
                                mat_new=copy_material(ma);
-                               if(mat_new){
+                               if (mat_new) {
                                        /* rename the material*/
                                        strcpy(mat_new->id.name, idname);
                                        id_us_min((ID *)mat_new);       
@@ -1763,15 +1763,15 @@ static void convert_tfacematerial(Main *main, Material *ma)
                         * set "Face Textures [Alpha]" Material options 
                         * actually we need to run it always, because of old behavior
                         * of using face texture if any texture channel was present (multitex) */
-                       //if((!mat_new->mtex[0]) && (!mat_new->mtex[0]->tex))
+                       //if ((!mat_new->mtex[0]) && (!mat_new->mtex[0]->tex))
                        set_facetexture_flags(mat_new, tf->tpage);
 
                        /* set the material number to the face*/
                        mf->mat_nr = mat_nr;
                }
                /* remove material from mesh */
-               for(a=0;a<me->totcol;)
-                       if(me->mat[a] == ma) material_pop_id(&me->id, a, 1);else a++;
+               for (a=0;a<me->totcol;)
+                       if (me->mat[a] == ma) material_pop_id(&me->id, a, 1);else a++;
        }
 }
 
@@ -1805,7 +1805,7 @@ int do_version_tface(Main *main, int fileload)
         */
        
        /* 1st part: marking mesh materials to update */
-       for(me=main->mesh.first; me; me=me->id.next){
+       for (me=main->mesh.first; me; me=me->id.next) {
                if (me->id.lib) continue;
 
                /* get the active tface layer */
@@ -1816,7 +1816,7 @@ int do_version_tface(Main *main, int fileload)
                nomaterialslots = (me->totcol==0?1:0);
                
                /* loop over all the faces*/
-               for(a=0, mf=me->mface; a<me->totface; a++, mf++) {
+               for (a=0, mf=me->mface; a<me->totface; a++, mf++) {
                        /* texface data for this face */
                        tf = ((MTFace*)cdl->data) + a;
 
@@ -1824,12 +1824,12 @@ int do_version_tface(Main *main, int fileload)
                        if (fileload)
                                tf->mode &= ~TF_CONVERTED;
                        else {
-                               if((tf->mode & TF_CONVERTED)) continue;
+                               if ((tf->mode & TF_CONVERTED)) continue;
                                else tf->mode |= TF_CONVERTED;
                        }
                        
                        /* no material slots */
-                       if(nomaterialslots) {
+                       if (nomaterialslots) {
                                flag = encode_tfaceflag(tf, 1);
                                
                                /* create/find a new material and assign to the face */
@@ -1841,11 +1841,11 @@ int do_version_tface(Main *main, int fileload)
                                        mf->mat_nr = -1;
                                }
                        }
-                       else if(mf->mat_nr < me->totcol) {
+                       else if (mf->mat_nr < me->totcol) {
                                ma= me->mat[mf->mat_nr];
                                
                                /* no material create one if necessary */
-                               if(!ma) {
+                               if (!ma) {
                                        /* find a new material and assign to the face */
                                        flag = encode_tfaceflag(tf, 1);
 
@@ -1860,11 +1860,11 @@ int do_version_tface(Main *main, int fileload)
                                 * at doversion time: direct_link might not have happened on it,
                                 * so ma->mtex is not pointing to valid memory yet.
                                 * later we could, but it's better not */
-                               else if(ma->id.lib)
+                               else if (ma->id.lib)
                                        continue;
                                
                                /* material already marked as disputed */
-                               else if(ma->game.flag == MAT_BGE_DISPUTED)
+                               else if (ma->game.flag == MAT_BGE_DISPUTED)
                                        continue;
 
                                /* found a material */
@@ -1889,20 +1889,21 @@ int do_version_tface(Main *main, int fileload)
                                                 * channel which not neccessarly the tf->tpage image. But the game engine
                                                 * was enabling it. Now it's required to set "Face Texture [Alpha] in the
                                                 * material settings. */
-                                               if(!fileload)
+                                               if (!fileload)
                                                        set_facetexture_flags(ma, tf->tpage);
                                        }
                                }
                        }
-                       else
+                       else {
                                continue;
+                       }
                }
 
                /* if we didn't have material slot and now we do, we need to
                 * make sure the materials are correct */
-               if(nomaterialslots) {
+               if (nomaterialslots) {
                        if (me->totcol>0) {
-                               for(a=0, mf=me->mface; a<me->totface; a++, mf++) {
+                               for (a=0, mf=me->mface; a<me->totface; a++, mf++) {
                                        if (mf->mat_nr == -1) {
                                                /* texface data for this face */
                                                tf = ((MTFace*)cdl->data) + a;
@@ -1911,7 +1912,7 @@ int do_version_tface(Main *main, int fileload)
                                }
                        }
                        else {
-                               for(a=0, mf=me->mface; a<me->totface; a++, mf++) {
+                               for (a=0, mf=me->mface; a<me->totface; a++, mf++) {
                                        mf->mat_nr=0;
                                }
                        }
@@ -1946,10 +1947,10 @@ int do_version_tface(Main *main, int fileload)
                        /* material is good make sure all faces using
                         * this material are set to converted */
                        if (fileload) {
-                               for(me=main->mesh.first; me; me=me->id.next){
+                               for (me=main->mesh.first; me; me=me->id.next) {
                                        /* check if this mesh uses this material */
-                                       for(a=0;a<me->totcol;a++)
-                                               if(me->mat[a] == ma) break;
+                                       for (a=0;a<me->totcol;a++)
+                                               if (me->mat[a] == ma) break;
                                                
                                        /* no material found */
                                        if (a == me->totcol) continue;
@@ -1972,9 +1973,11 @@ int do_version_tface(Main *main, int fileload)
                }
                /* material is not used by faces with texface
                 * set the default flag - do it only once */
-               else
-                        if (fileload)
-                                       ma->game.flag = GEMAT_BACKCULL;
+               else {
+                       if (fileload) {
+                               ma->game.flag = GEMAT_BACKCULL;
+                       }
+               }
        }
 
        return nowarning;
index fe2c10d..7f05aae 100644 (file)
@@ -78,7 +78,7 @@ void unlink_mball(MetaBall *mb)
        int a;
        
        for(a=0; a<mb->totcol; a++) {
-               if(mb->mat[a]) mb->mat[a]->id.us--;
+               if (mb->mat[a]) mb->mat[a]->id.us--;
                mb->mat[a]= NULL;
        }
 }
@@ -89,14 +89,14 @@ void free_mball(MetaBall *mb)
 {
        unlink_mball(mb);       
        
-       if(mb->adt) {
+       if (mb->adt) {
                BKE_free_animdata((ID *)mb);
                mb->adt = NULL;
        }
-       if(mb->mat) MEM_freeN(mb->mat);
-       if(mb->bb) MEM_freeN(mb->bb);
+       if (mb->mat) MEM_freeN(mb->mat);
+       if (mb->bb) MEM_freeN(mb->bb);
        BLI_freelistN(&mb->elems);
-       if(mb->disp.first) freedisplist(&mb->disp);
+       if (mb->disp.first) freedisplist(&mb->disp);
 }
 
 MetaBall *add_mball(const char *name)
@@ -138,7 +138,7 @@ MetaBall *copy_mball(MetaBall *mb)
 
 static void extern_local_mball(MetaBall *mb)
 {
-       if(mb->mat) {
+       if (mb->mat) {
                extern_local_matarar(mb->mat, mb->totcol);
        }
 }
@@ -154,8 +154,8 @@ void make_local_mball(MetaBall *mb)
         * - mixed: make copy
         */
        
-       if(mb->id.lib==NULL) return;
-       if(mb->id.us==1) {
+       if (mb->id.lib==NULL) return;
+       if (mb->id.us==1) {
                id_clear_lib_data(bmain, &mb->id);
                extern_local_mball(mb);
                
@@ -163,17 +163,17 @@ void make_local_mball(MetaBall *mb)
        }
 
        for(ob= G.main->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) {
-               if(ob->data == mb) {
-                       if(ob->id.lib) is_lib= TRUE;
+               if (ob->data == mb) {
+                       if (ob->id.lib) is_lib= TRUE;
                   &nbs