From 53fece44cf08e730bba8b8581f8bd02361f37930 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 23 Feb 2012 02:17:50 +0000 Subject: style cleanup for blenkernel, no functional changes. --- source/blender/blenkernel/intern/material.c | 513 ++++++++++++++-------------- 1 file changed, 258 insertions(+), 255 deletions(-) (limited to 'source/blender/blenkernel/intern/material.c') diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index f685d0ec151..43270447dad 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -82,29 +82,29 @@ void free_material(Material *ma) MTex *mtex; int a; - for(a=0; amtex[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; amtex[a]) { + for (a=0; amtex[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; amtex[a]) { + for (a=0; amtex[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; atotcol; a++) { - if(ob->mat[a]==ma) { - if(ob->id.lib) is_lib= TRUE; + if (ob->mat) { + for (a=0; atotcol; 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; atotcol; a++) { - if(me->mat[a]==ma) { - if(me->id.lib) is_lib= TRUE; + if (me->mat) { + for (a=0; atotcol; 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; atotcol; a++) { - if(cu->mat[a]==ma) { - if(cu->id.lib) is_lib= TRUE; + if (cu->mat) { + for (a=0; atotcol; 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; atotcol; a++) { - if(mb->mat[a]==ma) { - if(mb->id.lib) is_lib= TRUE; + if (mb->mat) { + for (a=0; atotcol; 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; atotcol; a++) { - if(ob->mat[a]==ma) { - if(ob->id.lib==NULL) { + if (ob->mat) { + for (a=0; atotcol; 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; atotcol; a++) { - if(me->mat[a]==ma) { - if(me->id.lib==NULL) { + if (me->mat) { + for (a=0; atotcol; 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; atotcol; a++) { - if(cu->mat[a]==ma) { - if(cu->id.lib==NULL) { + if (cu->mat) { + for (a=0; atotcol; 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; atotcol; a++) { - if(mb->mat[a]==ma) { - if(mb->id.lib==NULL) { + if (mb->mat) { + for (a=0; atotcol; 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->totcoltotcoltotcol) { + 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 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; aseptex & (1<septex & (1<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; atotcol; a++) + for (a=ob->actcol; atotcol; 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; atotcol; a++) { + for (a=actcol; atotcol; 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; aramp_col) MEM_freeN(ma->ramp_col); - if(ma->ramp_spec) MEM_freeN(ma->ramp_spec); - for(a=0; aramp_col) MEM_freeN(ma->ramp_col); + if (ma->ramp_spec) MEM_freeN(ma->ramp_spec); + for (a=0; amtex[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; amtex[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;atotcol;a++) - if(me->mat[a] == ma) break; + for (a=0;atotcol;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; atotface; a++, mf++) { - if(me->mat[mf->mat_nr] != ma) continue; + for (a=0, mf=me->mface; atotface; 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;atotcol;) - if(me->mat[a] == ma) material_pop_id(&me->id, a, 1);else a++; + for (a=0;atotcol;) + 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; atotface; a++, mf++) { + for (a=0, mf=me->mface; atotface; 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; atotface; a++, mf++) { + for (a=0, mf=me->mface; atotface; 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; atotface; a++, mf++) { + for (a=0, mf=me->mface; atotface; 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;atotcol;a++) - if(me->mat[a] == ma) break; + for (a=0;atotcol;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; -- cgit v1.2.3