style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / editors / object / object_bake.c
index 4f64a64607e92a6420ce94d2d64eacb53cb313b8..deefcfd698988eae52d0ed533cf84f068006f101 100644 (file)
@@ -161,10 +161,11 @@ static void multiresbake_get_normal(const MResolvePixelData *data, float norm[],
                                 data->mface[face_num].v3, data->mface[face_num].v4};
        const int smoothnormal= (data->mface[face_num].flag & ME_SMOOTH);
 
-       if(!smoothnormal) { /* flat */
-               if(data->precomputed_normals) {
+       if (!smoothnormal) { /* flat */
+               if (data->precomputed_normals) {
                        copy_v3_v3(norm, &data->precomputed_normals[3*face_num]);
-               } else {
+               }
+               else {
                        float nor[3];
                        float *p0, *p1, *p2;
                        const int iGetNrVerts= data->mface[face_num].v4!=0 ? 4 : 3;
@@ -173,16 +174,18 @@ static void multiresbake_get_normal(const MResolvePixelData *data, float norm[],
                        p1= data->mvert[indices[1]].co;
                        p2= data->mvert[indices[2]].co;
 
-                       if(iGetNrVerts==4) {
+                       if (iGetNrVerts==4) {
                                float *p3= data->mvert[indices[3]].co;
                                normal_quad_v3(nor, p0, p1, p2, p3);
-                       } else {
+                       }
+                       else {
                                normal_tri_v3(nor, p0, p1, p2);
                        }
 
                        copy_v3_v3(norm, nor);
                }
-       } else {
+       }
+       else {
                short *no= data->mvert[indices[vert_index]].no;
 
                normal_short_to_float_v3(norm, no);
@@ -239,7 +242,7 @@ static void flush_pixel(const MResolvePixelData *data, const int x, const int y)
 
        /* this sequence of math is designed specifically as is with great care
         * to be compatible with our shader. Please don't change without good reason. */
-       for(r= 0; r<3; r++) {
+       for (r= 0; r<3; r++) {
                from_tang[0][r]= tang0[r]*u + tang1[r]*v + tang2[r]*w;
                from_tang[2][r]= no0[r]*u + no1[r]*v + no2[r]*w;
        }
@@ -258,8 +261,8 @@ static void set_rast_triangle(const MBakeRast *bake_rast, const int x, const int
        const int w= bake_rast->w;
        const int h= bake_rast->h;
 
-       if(x>=0 && x<w && y>=0 && y<h) {
-               if((bake_rast->texels[y*w+x])==0) {
+       if (x>=0 && x<w && y>=0 && y<h) {
+               if ((bake_rast->texels[y*w+x])==0) {
                        flush_pixel(bake_rast->data, x, y);
                        bake_rast->texels[y*w+x]= FILTER_MASK_USED;
                }
@@ -277,29 +280,29 @@ static void rasterize_half(const MBakeRast *bake_rast,
        const int h= bake_rast->h;
        int y, y0, y1;
 
-       if(y1_in<=0 || y0_in>=h)
+       if (y1_in<=0 || y0_in>=h)
                return;
 
        y0= y0_in<0 ? 0 : y0_in;
        y1= y1_in>=h ? h : y1_in;
 
-       for(y= y0; y<y1; y++) {
+       for (y= y0; y<y1; y++) {
                /*-b(x-x0) + a(y-y0) = 0 */
                int iXl, iXr, x;
                float x_l= s_stable!=0 ? (s0_s + (((s1_s-s0_s)*(y-t0_s))/(t1_s-t0_s))) : s0_s;
                float x_r= l_stable!=0 ? (s0_l + (((s1_l-s0_l)*(y-t0_l))/(t1_l-t0_l))) : s0_l;
 
-               if(is_mid_right!=0)
+               if (is_mid_right!=0)
                        SWAP(float, x_l, x_r);
 
                iXl= (int)ceilf(x_l);
                iXr= (int)ceilf(x_r);
 
-               if(iXr>0 && iXl<w) {
+               if (iXr>0 && iXl<w) {
                        iXl= iXl<0?0:iXl;
                        iXr= iXr>=w?w:iXr;
 
-                       for(x= iXl; x<iXr; x++)
+                       for (x= iXl; x<iXr; x++)
                                set_rast_triangle(bake_rast, x, y);
                }
        }
@@ -318,19 +321,20 @@ static void bake_rasterize(const MBakeRast *bake_rast, const float st0_in[2], co
        int is_mid_right= 0, ylo, yhi, yhi_beg;
 
        /* skip degenerates */
-       if((slo==smi && tlo==tmi) || (slo==shi && tlo==thi) || (smi==shi && tmi==thi))
+       if ((slo==smi && tlo==tmi) || (slo==shi && tlo==thi) || (smi==shi && tmi==thi))
                return;
 
        /* sort by T */
-       if(tlo>tmi && tlo>thi) {
+       if (tlo>tmi && tlo>thi) {
                SWAP(float, shi, slo);
                SWAP(float, thi, tlo);
-       } else if(tmi>thi) {
+       }
+       else if (tmi>thi) {
                SWAP(float, shi, smi);
                SWAP(float, thi, tmi);
        }
 
-       if(tlo>tmi) {
+       if (tlo>tmi) {
                SWAP(float, slo, smi);
                SWAP(float, tlo, tmi);
        }
@@ -348,7 +352,7 @@ static void bake_rasterize(const MBakeRast *bake_rast, const float st0_in[2], co
 
 static int multiresbake_test_break(MultiresBakeRender *bkr)
 {
-       if(!bkr->stop) {
+       if (!bkr->stop) {
                /* this means baker is executed outside from job system */
                return 0;
        }
@@ -368,12 +372,12 @@ static void do_multires_bake(MultiresBakeRender *bkr, Image* ima, MPassKnownData
        MTFace *mtface= dm->getTessFaceDataArray(dm, CD_MTFACE);
        float *pvtangent= NULL;
 
-       if(CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1)
+       if (CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1)
                DM_add_tangent_layer(dm);
 
        pvtangent= DM_get_tessface_data_layer(dm, CD_TANGENT);
 
-       if(tot_face > 0) {  /* sanity check */
+       if (tot_face > 0) {  /* sanity check */
                int f= 0;
                MBakeRast bake_rast;
                MResolvePixelData data={NULL};
@@ -390,19 +394,19 @@ static void do_multires_bake(MultiresBakeRender *bkr, Image* ima, MPassKnownData
                data.lvl= lvl;
                data.pass_data= passKnownData;
 
-               if(initBakeData)
+               if (initBakeData)
                        data.bake_data= initBakeData(bkr, ima);
 
                init_bake_rast(&bake_rast, ibuf, &data, flush_pixel);
 
-               for(f= 0; f<tot_face; f++) {
+               for (f= 0; f<tot_face; f++) {
                        MTFace *mtfate= &mtface[f];
                        int verts[3][2], nr_tris, t;
 
-                       if(multiresbake_test_break(bkr))
+                       if (multiresbake_test_break(bkr))
                                break;
 
-                       if(mtfate->tpage!=ima)
+                       if (mtfate->tpage!=ima)
                                continue;
 
                        data.face_index= f;
@@ -418,7 +422,7 @@ static void do_multires_bake(MultiresBakeRender *bkr, Image* ima, MPassKnownData
                        verts[2][1]=3;
 
                        nr_tris= mface[f].v4!=0 ? 2 : 1;
-                       for(t= 0; t<nr_tris; t++) {
+                       for (t= 0; t<nr_tris; t++) {
                                data.i0 = verts[0][t];
                                data.i1 = verts[1][t];
                                data.i2 = verts[2][t];
@@ -428,17 +432,17 @@ static void do_multires_bake(MultiresBakeRender *bkr, Image* ima, MPassKnownData
 
                        bkr->baked_faces++;
 
-                       if(bkr->do_update)
+                       if (bkr->do_update)
                                *bkr->do_update= 1;
 
-                       if(bkr->progress)
+                       if (bkr->progress)
                                *bkr->progress= ((float)bkr->baked_objects + (float)bkr->baked_faces / tot_face) / bkr->tot_obj;
                }
 
-               if(applyBakeData)
+               if (applyBakeData)
                        applyBakeData(data.bake_data);
 
-               if(freeBakeData)
+               if (freeBakeData)
                        freeBakeData(data.bake_data);
        }
 }
@@ -486,12 +490,13 @@ static void interp_bilinear_grid(DMGridData *grid, int grid_size, float crn_x, f
        u= crn_x-x0;
        v= crn_y-y0;
 
-       if(mode == 0) {
+       if (mode == 0) {
                copy_v3_v3(data[0], grid[y0 * grid_size + x0].no);
                copy_v3_v3(data[1], grid[y0 * grid_size + x1].no);
                copy_v3_v3(data[2], grid[y1 * grid_size + x1].no);
                copy_v3_v3(data[3], grid[y1 * grid_size + x0].no);
-       } else {
+       }
+       else {
                copy_v3_v3(data[0], grid[y0 * grid_size + x0].co);
                copy_v3_v3(data[1], grid[y0 * grid_size + x1].co);
                copy_v3_v3(data[2], grid[y1 * grid_size + x1].co);
@@ -517,10 +522,11 @@ static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm, const int *orig
 
        face_side= (grid_size<<1)-1;
 
-       if(lvl==0) {
+       if (lvl==0) {
                g_index= grid_offset[face_index];
                S= mdisp_rot_face_to_crn(mface.v4 ? 4 : 3, face_side, u*(face_side-1), v*(face_side-1), &crn_x, &crn_y);
-       } else {
+       }
+       else {
                int side= (1 << (lvl-1)) + 1;
                int grid_index= origindex[face_index];
                int loc_offs= face_index % (1<<(2*lvl));
@@ -539,10 +545,10 @@ static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm, const int *orig
        CLAMP(crn_x, 0.0f, grid_size);
        CLAMP(crn_y, 0.0f, grid_size);
 
-       if(n != NULL)
+       if (n != NULL)
                interp_bilinear_grid(grid_data[g_index + S], grid_size, crn_x, crn_y, 0, n);
 
-       if(co != NULL)
+       if (co != NULL)
                interp_bilinear_grid(grid_data[g_index + S], grid_size, crn_x, crn_y, 1, co);
 }
 
@@ -552,12 +558,13 @@ static void interp_bilinear_mface(DerivedMesh *dm, MFace *mface, const float u,
 {
        float data[4][3];
 
-       if(mode == 0) {
+       if (mode == 0) {
                dm->getVertNo(dm, mface->v1, data[0]);
                dm->getVertNo(dm, mface->v2, data[1]);
                dm->getVertNo(dm, mface->v3, data[2]);
                dm->getVertNo(dm, mface->v4, data[3]);
-       } else {
+       }
+       else {
                dm->getVertCo(dm, mface->v1, data[0]);
                dm->getVertCo(dm, mface->v2, data[1]);
                dm->getVertCo(dm, mface->v3, data[2]);
@@ -573,11 +580,12 @@ static void interp_barycentric_mface(DerivedMesh *dm, MFace *mface, const float
 {
        float data[3][3];
 
-       if(mode == 0) {
+       if (mode == 0) {
                dm->getVertNo(dm, mface->v1, data[0]);
                dm->getVertNo(dm, mface->v2, data[1]);
                dm->getVertNo(dm, mface->v3, data[2]);
-       } else {
+       }
+       else {
                dm->getVertCo(dm, mface->v1, data[0]);
                dm->getVertCo(dm, mface->v2, data[1]);
                dm->getVertCo(dm, mface->v3, data[2]);
@@ -599,7 +607,7 @@ static void *init_heights_data(MultiresBakeRender *bkr, Image *ima)
        height_data->height_max= -FLT_MAX;
        height_data->height_min= FLT_MAX;
 
-       if(!bkr->use_lores_mesh) {
+       if (!bkr->use_lores_mesh) {
                SubsurfModifierData smd= {{NULL}};
                int ss_lvl= bkr->tot_lvl - bkr->lvl;
 
@@ -608,7 +616,7 @@ static void *init_heights_data(MultiresBakeRender *bkr, Image *ima)
                smd.levels= smd.renderLevels= ss_lvl;
                smd.flags|= eSubsurfModifierFlag_SubsurfUv;
 
-               if(bkr->simple)
+               if (bkr->simple)
                        smd.subdivType= ME_SIMPLE_SUBSURF;
 
                height_data->ssdm= subsurf_make_derived_from_derived(bkr->lores_dm, &smd, 0, NULL, 0, 0, 0);
@@ -646,24 +654,25 @@ static void apply_heights_data(void *bake_data)
        float height, *heights= height_data->heights;
        float min= height_data->height_min, max= height_data->height_max;
 
-       for(x= 0; x<ibuf->x; x++) {
-               for(y =0; y<ibuf->y; y++) {
+       for (x= 0; x<ibuf->x; x++) {
+               for (y =0; y<ibuf->y; y++) {
                        i= ibuf->x*y + x;
 
-                       if(((char*)ibuf->userdata)[i] != FILTER_MASK_USED)
+                       if (((char*)ibuf->userdata)[i] != FILTER_MASK_USED)
                                continue;
 
-                       if(ibuf->rect_float) {
+                       if (ibuf->rect_float) {
                                float *rrgbf= ibuf->rect_float + i*4;
 
-                               if(max-min > 1e-5f) height= (heights[i]-min)/(max-min);
+                               if (max-min > 1e-5f) height= (heights[i]-min)/(max-min);
                                else height= 0;
 
                                rrgbf[0]=rrgbf[1]=rrgbf[2]= height;
-                       } else {
+                       }
+                       else {
                                char *rrgb= (char*)ibuf->rect + i*4;
 
-                               if(max-min > 1e-5f) height= (heights[i]-min)/(max-min);
+                               if (max-min > 1e-5f) height= (heights[i]-min)/(max-min);
                                else height= 0;
 
                                rrgb[0]=rrgb[1]=rrgb[2]= FTOCHAR(height);
@@ -678,7 +687,7 @@ static void free_heights_data(void *bake_data)
 {
        MHeightBakeData *height_data= (MHeightBakeData*)bake_data;
 
-       if(height_data->ssdm)
+       if (height_data->ssdm)
                height_data->ssdm->release(height_data->ssdm);
 
        MEM_freeN(height_data->heights);
@@ -710,10 +719,11 @@ static void apply_heights_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
        st1= mtface[face_index].uv[1];
        st2= mtface[face_index].uv[2];
 
-       if(mface.v4) {
+       if (mface.v4) {
                st3= mtface[face_index].uv[3];
                resolve_quad_uv(uv, st, st0, st1, st2, st3);
-       } else
+       }
+       else
                resolve_tri_uv(uv, st, st0, st1, st2);
 
        CLAMP(uv[0], 0.0f, 1.0f);
@@ -721,15 +731,17 @@ static void apply_heights_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
 
        get_ccgdm_data(lores_dm, hires_dm, height_data->origindex, lvl, face_index, uv[0], uv[1], p1, 0);
 
-       if(height_data->ssdm) {
+       if (height_data->ssdm) {
                get_ccgdm_data(lores_dm, height_data->ssdm, height_data->origindex, 0, face_index, uv[0], uv[1], p0, n);
-       } else {
+       }
+       else {
                lores_dm->getTessFace(lores_dm, face_index, &mface);
 
-               if(mface.v4) {
+               if (mface.v4) {
                        interp_bilinear_mface(lores_dm, &mface, uv[0], uv[1], 1, p0);
                        interp_bilinear_mface(lores_dm, &mface, uv[0], uv[1], 0, n);
-               } else {
+               }
+               else {
                        interp_barycentric_mface(lores_dm, &mface, uv[0], uv[1], 1, p0);
                        interp_barycentric_mface(lores_dm, &mface, uv[0], uv[1], 0, n);
                }
@@ -739,15 +751,16 @@ static void apply_heights_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
        len= dot_v3v3(n, vec);
 
        height_data->heights[pixel]= len;
-       if(len<height_data->height_min) height_data->height_min= len;
-       if(len>height_data->height_max) height_data->height_max= len;
+       if (len<height_data->height_min) height_data->height_min= len;
+       if (len>height_data->height_max) height_data->height_max= len;
 
-       if(ibuf->rect_float) {
+       if (ibuf->rect_float) {
                float *rrgbf= ibuf->rect_float + pixel*4;
                rrgbf[3]= 1.0f;
 
                ibuf->userflags= IB_RECT_INVALID;
-       } else {
+       }
+       else {
                char *rrgb= (char*)ibuf->rect + pixel*4;
                rrgb[3]= 255;
        }
@@ -777,10 +790,11 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
        st1= mtface[face_index].uv[1];
        st2= mtface[face_index].uv[2];
 
-       if(mface.v4) {
+       if (mface.v4) {
                st3= mtface[face_index].uv[3];
                resolve_quad_uv(uv, st, st0, st1, st2, st3);
-       } else
+       }
+       else
                resolve_tri_uv(uv, st, st0, st1, st2);
 
        CLAMP(uv[0], 0.0f, 1.0f);
@@ -793,7 +807,7 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
        mul_v3_fl(vec, 0.5);
        add_v3_v3(vec, tmp);
 
-       if(ibuf->rect_float) {
+       if (ibuf->rect_float) {
                float *rrgbf= ibuf->rect_float + pixel*4;
                rrgbf[0]= vec[0];
                rrgbf[1]= vec[1];
@@ -801,7 +815,8 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
                rrgbf[3]= 1.0f;
 
                ibuf->userflags= IB_RECT_INVALID;
-       } else {
+       }
+       else {
                unsigned char *rrgb= (unsigned char *)ibuf->rect + pixel*4;
                rgb_float_to_uchar(rrgb, vec);
                rrgb[3]= 255;
@@ -819,12 +834,12 @@ static void count_images(MultiresBakeRender *bkr)
 
        totface= dm->getNumTessFaces(dm);
 
-       for(a= 0; a<totface; a++)
+       for (a= 0; a<totface; a++)
                mtface[a].tpage->id.flag&= ~LIB_DOIT;
 
-       for(a= 0; a<totface; a++) {
+       for (a= 0; a<totface; a++) {
                Image *ima= mtface[a].tpage;
-               if((ima->id.flag&LIB_DOIT)==0) {
+               if ((ima->id.flag&LIB_DOIT)==0) {
                        LinkData *data= BLI_genericNodeN(ima);
                        BLI_addtail(&bkr->image, data);
                        bkr->tot_image++;
@@ -832,7 +847,7 @@ static void count_images(MultiresBakeRender *bkr)
                }
        }
 
-       for(a= 0; a<totface; a++)
+       for (a= 0; a<totface; a++)
                mtface[a].tpage->id.flag&= ~LIB_DOIT;
 }
 
@@ -840,11 +855,11 @@ static void bake_images(MultiresBakeRender *bkr)
 {
        LinkData *link;
 
-       for(link= bkr->image.first; link; link= link->next) {
+       for (link= bkr->image.first; link; link= link->next) {
                Image *ima= (Image*)link->data;
                ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
 
-               if(ibuf->x>0 && ibuf->y>0) {
+               if (ibuf->x>0 && ibuf->y>0) {
                        ibuf->userdata= MEM_callocN(ibuf->y*ibuf->x, "MultiresBake imbuf mask");
 
                        switch(bkr->mode) {
@@ -866,26 +881,26 @@ static void finish_images(MultiresBakeRender *bkr)
 {
        LinkData *link;
 
-       for(link= bkr->image.first; link; link= link->next) {
+       for (link= bkr->image.first; link; link= link->next) {
                Image *ima= (Image*)link->data;
                ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
 
-               if(ibuf->x<=0 || ibuf->y<=0)
+               if (ibuf->x<=0 || ibuf->y<=0)
                        continue;
 
                RE_bake_ibuf_filter(ibuf, (char *)ibuf->userdata, bkr->bake_filter);
 
                ibuf->userflags|= IB_BITMAPDIRTY;
 
-               if(ibuf->rect_float)
+               if (ibuf->rect_float)
                        ibuf->userflags|= IB_RECT_INVALID;
 
-               if(ibuf->mipmap[0]) {
+               if (ibuf->mipmap[0]) {
                        ibuf->userflags|= IB_MIPMAP_INVALID;
                        imb_freemipmapImBuf(ibuf);
                }
 
-               if(ibuf->userdata) {
+               if (ibuf->userdata) {
                        MEM_freeN(ibuf->userdata);
                        ibuf->userdata= NULL;
                }
@@ -910,7 +925,7 @@ static int multiresbake_check(bContext *C, wmOperator *op)
        CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
                ob= base->object;
 
-               if(ob->type != OB_MESH) {
+               if (ob->type != OB_MESH) {
                        BKE_report(op->reports, RPT_ERROR, "Basking of multires data only works with active object which is a mesh");
 
                        ok= 0;
@@ -921,25 +936,26 @@ static int multiresbake_check(bContext *C, wmOperator *op)
                mmd= get_multires_modifier(scene, ob, 0);
 
                /* Multi-resolution should be and be last in the stack */
-               if(ok && mmd) {
+               if (ok && mmd) {
                        ModifierData *md;
 
                        ok= mmd->totlvl>0;
 
-                       for(md = (ModifierData*)mmd->modifier.next; md && ok; md = md->next) {
+                       for (md = (ModifierData*)mmd->modifier.next; md && ok; md = md->next) {
                                if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) {
                                        ok= 0;
                                }
                        }
-               } else ok= 0;
+               }
+               else ok= 0;
 
-               if(!ok) {
+               if (!ok) {
                        BKE_report(op->reports, RPT_ERROR, "Multires data baking requires multi-resolution object");
 
                        break;
                }
 
-               if(!me->mtpoly) {
+               if (!me->mtpoly) {
                        BKE_report(op->reports, RPT_ERROR, "Mesh should be unwrapped before multires data baking");
 
                        ok= 0;
@@ -949,7 +965,7 @@ static int multiresbake_check(bContext *C, wmOperator *op)
                        while (ok && a--) {
                                Image *ima = me->mtpoly[a].tpage;
 
-                               if(!ima) {
+                               if (!ima) {
                                        BKE_report(op->reports, RPT_ERROR, "You should have active texture to use multires baker");
 
                                        ok= 0;
@@ -957,25 +973,26 @@ static int multiresbake_check(bContext *C, wmOperator *op)
                                else {
                                        ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
 
-                                       if(!ibuf) {
+                                       if (!ibuf) {
                                                BKE_report(op->reports, RPT_ERROR, "Baking should happend to image with image buffer");
 
                                                ok= 0;
-                                       } else {
-                                               if(ibuf->rect==NULL && ibuf->rect_float==NULL)
+                                       }
+                                       else {
+                                               if (ibuf->rect==NULL && ibuf->rect_float==NULL)
                                                        ok= 0;
 
-                                               if(ibuf->rect_float && !(ibuf->channels==0 || ibuf->channels==4))
+                                               if (ibuf->rect_float && !(ibuf->channels==0 || ibuf->channels==4))
                                                        ok= 0;
 
-                                               if(!ok)
+                                               if (!ok)
                                                        BKE_report(op->reports, RPT_ERROR, "Baking to unsupported image type");
                                        }
                                }
                        }
                }
 
-               if(!ok)
+               if (!ok)
                        break;
        }
        CTX_DATA_END;
@@ -991,11 +1008,12 @@ static DerivedMesh *multiresbake_create_loresdm(Scene *scene, Object *ob, int *l
 
        *lvl= mmd->lvl;
 
-       if(*lvl==0) {
+       if (*lvl==0) {
                DerivedMesh *tmp_dm= CDDM_from_mesh(me, ob);
                dm= CDDM_copy(tmp_dm);
                tmp_dm->release(tmp_dm);
-       } else {
+       }
+       else {
                MultiresModifierData tmp_mmd= *mmd;
                DerivedMesh *cddm= CDDM_from_mesh(me, ob);
 
@@ -1033,13 +1051,13 @@ static void clear_images(MTFace *mtface, int totface)
        const float vec_alpha[4]= {0.0f, 0.0f, 0.0f, 0.0f};
        const float vec_solid[4]= {0.0f, 0.0f, 0.0f, 1.0f};
 
-       for(a= 0; a<totface; a++)
+       for (a= 0; a<totface; a++)
                mtface[a].tpage->id.flag&= ~LIB_DOIT;
 
-       for(a= 0; a<totface; a++) {
+       for (a= 0; a<totface; a++) {
                Image *ima= mtface[a].tpage;
 
-               if((ima->id.flag&LIB_DOIT)==0) {
+               if ((ima->id.flag&LIB_DOIT)==0) {
                        ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
 
                        IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid);
@@ -1047,7 +1065,7 @@ static void clear_images(MTFace *mtface, int totface)
                }
        }
 
-       for(a= 0; a<totface; a++)
+       for (a= 0; a<totface; a++)
                mtface[a].tpage->id.flag&= ~LIB_DOIT;
 }
 
@@ -1057,10 +1075,10 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        int objects_baked= 0;
 
-       if(!multiresbake_check(C, op))
+       if (!multiresbake_check(C, op))
                return OPERATOR_CANCELLED;
 
-       if(scene->r.bake_flag&R_BAKE_CLEAR) {  /* clear images */
+       if (scene->r.bake_flag&R_BAKE_CLEAR) {  /* clear images */
                CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
                        Mesh *me;
 
@@ -1087,7 +1105,7 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
                /* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
                bkr.lores_dm= multiresbake_create_loresdm(scene, ob, &bkr.lvl);
 
-               if(!bkr.lores_dm)
+               if (!bkr.lores_dm)
                        continue;
 
                bkr.hires_dm= multiresbake_create_hiresdm(scene, ob, &bkr.tot_lvl, &bkr.simple);
@@ -1103,7 +1121,7 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
        }
        CTX_DATA_END;
 
-       if(!objects_baked)
+       if (!objects_baked)
                BKE_report(op->reports, RPT_ERROR, "No objects found to bake from");
 
        return OPERATOR_FINISHED;
@@ -1130,7 +1148,7 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
                multires_force_update(ob);
 
                lores_dm = multiresbake_create_loresdm(scene, ob, &lvl);
-               if(!lores_dm)
+               if (!lores_dm)
                        continue;
 
                data= MEM_callocN(sizeof(MultiresBakerJobData), "multiresBaker derivedMesh_data");
@@ -1151,8 +1169,8 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa
 
        tot_obj= BLI_countlist(&bkj->data);
 
-       if(bkj->bake_clear) {  /* clear images */
-               for(data= bkj->data.first; data; data= data->next) {
+       if (bkj->bake_clear) {  /* clear images */
+               for (data= bkj->data.first; data; data= data->next) {
                        DerivedMesh *dm= data->lores_dm;
                        MTFace *mtface= CustomData_get_layer(&dm->faceData, CD_MTFACE);
 
@@ -1160,7 +1178,7 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa
                }
        }
 
-       for(data= bkj->data.first; data; data= data->next) {
+       for (data= bkj->data.first; data; data= data->next) {
                MultiresBakeRender bkr= {0};
 
                /* copy data stored in job descriptor */
@@ -1214,13 +1232,13 @@ static int multiresbake_image_exec(bContext *C, wmOperator *op)
        MultiresBakeJob *bkr;
        wmJob *steve;
 
-       if(!multiresbake_check(C, op))
+       if (!multiresbake_check(C, op))
                return OPERATOR_CANCELLED;
 
        bkr= MEM_callocN(sizeof(MultiresBakeJob), "MultiresBakeJob data");
        init_multiresbake_job(C, bkr);
 
-       if(!bkr->data.first) {
+       if (!bkr->data.first) {
                BKE_report(op->reports, RPT_ERROR, "No objects found to bake from");
                return OPERATOR_CANCELLED;
        }
@@ -1278,10 +1296,10 @@ static int test_bake_internal(bContext *C, ReportList *reports)
 {
        Scene *scene= CTX_data_scene(C);
 
-       if((scene->r.bake_flag & R_BAKE_TO_ACTIVE) && CTX_data_active_object(C)==NULL) {
+       if ((scene->r.bake_flag & R_BAKE_TO_ACTIVE) && CTX_data_active_object(C)==NULL) {
                BKE_report(reports, RPT_ERROR, "No active object");
        }
-       else if(scene->r.bake_mode==RE_BAKE_AO && scene->world==NULL) {
+       else if (scene->r.bake_mode==RE_BAKE_AO && scene->world==NULL) {
                BKE_report(reports, RPT_ERROR, "No world set up");
        }
        else {
@@ -1304,12 +1322,12 @@ static void init_bake_internal(BakeRender *bkr, bContext *C)
        bkr->actob= (scene->r.bake_flag & R_BAKE_TO_ACTIVE) ? OBACT : NULL;
        bkr->re= RE_NewRender("_Bake View_");
 
-       if(scene->r.bake_mode==RE_BAKE_AO) {
+       if (scene->r.bake_mode==RE_BAKE_AO) {
                /* If raytracing or AO is disabled, switch it on temporarily for baking. */
                bkr->prev_wo_amb_occ = (scene->world->mode & WO_AMB_OCC) != 0;
                scene->world->mode |= WO_AMB_OCC;
        }
-       if(scene->r.bake_mode==RE_BAKE_AO || bkr->actob) {
+       if (scene->r.bake_mode==RE_BAKE_AO || bkr->actob) {
                bkr->prev_r_raytrace = (scene->r.mode & R_RAYTRACE) != 0;
                scene->r.mode |= R_RAYTRACE;
        }
@@ -1320,22 +1338,22 @@ static void finish_bake_internal(BakeRender *bkr)
        RE_Database_Free(bkr->re);
 
        /* restore raytrace and AO */
-       if(bkr->scene->r.bake_mode==RE_BAKE_AO)
-               if(bkr->prev_wo_amb_occ == 0)
+       if (bkr->scene->r.bake_mode==RE_BAKE_AO)
+               if (bkr->prev_wo_amb_occ == 0)
                        bkr->scene->world->mode &= ~WO_AMB_OCC;
 
-       if(bkr->scene->r.bake_mode==RE_BAKE_AO || bkr->actob)
-               if(bkr->prev_r_raytrace == 0)
+       if (bkr->scene->r.bake_mode==RE_BAKE_AO || bkr->actob)
+               if (bkr->prev_r_raytrace == 0)
                        bkr->scene->r.mode &= ~R_RAYTRACE;
 
-       if(bkr->result==BAKE_RESULT_OK) {
+       if (bkr->result==BAKE_RESULT_OK) {
                Image *ima;
                /* force OpenGL reload and mipmap recalc */
-               for(ima= G.main->image.first; ima; ima= ima->id.next) {
-                       if(ima->ok==IMA_OK_LOADED) {
+               for (ima= G.main->image.first; ima; ima= ima->id.next) {
+                       if (ima->ok==IMA_OK_LOADED) {
                                ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
-                               if(ibuf) {
-                                       if(ibuf->userflags & IB_BITMAPDIRTY) {
+                               if (ibuf) {
+                                       if (ibuf->userflags & IB_BITMAPDIRTY) {
                                                GPU_free_image(ima);
                                                imb_freemipmapImBuf(ibuf);
                                        }
@@ -1384,9 +1402,9 @@ static void bake_update(void *bkv)
 {
        BakeRender *bkr= bkv;
 
-       if(bkr->sa && bkr->sa->spacetype==SPACE_IMAGE) { /* in case the user changed while baking */
+       if (bkr->sa && bkr->sa->spacetype==SPACE_IMAGE) { /* in case the user changed while baking */
                SpaceImage *sima= bkr->sa->spacedata.first;
-               if(sima)
+               if (sima)
                        sima->image= RE_bake_shade_get_image();
        }
 }
@@ -1396,9 +1414,9 @@ static void bake_freejob(void *bkv)
        BakeRender *bkr= bkv;
        finish_bake_internal(bkr);
 
-       if(bkr->result==BAKE_RESULT_NO_OBJECTS)
+       if (bkr->result==BAKE_RESULT_NO_OBJECTS)
                BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
-       else if(bkr->result==BAKE_RESULT_FEEDBACK_LOOP)
+       else if (bkr->result==BAKE_RESULT_FEEDBACK_LOOP)
                BKE_report(bkr->reports, RPT_WARNING, "Feedback loop detected");
 
        MEM_freeN(bkr);
@@ -1409,7 +1427,7 @@ static void bake_freejob(void *bkv)
 static int objects_bake_render_modal(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 {
        /* no running blender, remove handler and pass through */
-       if(0==WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C)))
+       if (0==WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C)))
                return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH;
 
        /* running render */
@@ -1434,14 +1452,15 @@ static int objects_bake_render_invoke(bContext *C, wmOperator *op, wmEvent *UNUS
        Scene *scene= CTX_data_scene(C);
        int result= OPERATOR_CANCELLED;
 
-       if(is_multires_bake(scene)) {
+       if (is_multires_bake(scene)) {
                result= multiresbake_image_exec(C, op);
-       } else {
+       }
+       else {
                /* only one render job at a time */
-               if(WM_jobs_test(CTX_wm_manager(C), scene))
+               if (WM_jobs_test(CTX_wm_manager(C), scene))
                        return OPERATOR_CANCELLED;
 
-               if(test_bake_internal(C, op->reports)==0) {
+               if (test_bake_internal(C, op->reports)==0) {
                        return OPERATOR_CANCELLED;
                }
                else {
@@ -1483,10 +1502,11 @@ static int bake_image_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        int result= OPERATOR_CANCELLED;
 
-       if(is_multires_bake(scene)) {
+       if (is_multires_bake(scene)) {
                result= multiresbake_image_exec_locked(C, op);
-       } else  {
-               if(test_bake_internal(C, op->reports)==0) {
+       }
+       else {
+               if (test_bake_internal(C, op->reports)==0) {
                        return OPERATOR_CANCELLED;
                }
                else {
@@ -1506,9 +1526,9 @@ static int bake_image_exec(bContext *C, wmOperator *op)
                        bkr.ready= 0;
                        BLI_insert_thread(&threads, &bkr);
 
-                       while(bkr.ready==0) {
+                       while (bkr.ready==0) {
                                PIL_sleep_ms(50);
-                               if(bkr.ready)
+                               if (bkr.ready)
                                        break;
 
                                /* used to redraw in 2.4x but this is just for exec in 2.5 */
@@ -1517,9 +1537,9 @@ static int bake_image_exec(bContext *C, wmOperator *op)
                        }
                        BLI_end_threads(&threads);
 
-                       if(bkr.result==BAKE_RESULT_NO_OBJECTS)
+                       if (bkr.result==BAKE_RESULT_NO_OBJECTS)
                                BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
-                       else if(bkr.result==BAKE_RESULT_FEEDBACK_LOOP)
+                       else if (bkr.result==BAKE_RESULT_FEEDBACK_LOOP)
                                BKE_report(op->reports, RPT_ERROR, "Feedback loop detected");
 
                        finish_bake_internal(&bkr);