diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-05-06 19:15:33 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-05-06 19:15:33 +0400 |
commit | c93d7a193ab450f89664a70e0204c14531be4877 (patch) | |
tree | 7263e2b9b83922d766f59f3f7531157c0f71be35 /source/blender/blenkernel/intern/material.c | |
parent | 53b221960acaa63cc50bd8095d0ea11f9de539e1 (diff) |
style cleanup: BKE_*.c files which deal with library functions
Diffstat (limited to 'source/blender/blenkernel/intern/material.c')
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 1110 |
1 files changed, 555 insertions, 555 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 13cfb40a0eb..7507442a4d5 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -82,8 +82,8 @@ void BKE_material_free(Material *ma) MTex *mtex; int a; - for (a=0; a<MAX_MTEX; a++) { - mtex= ma->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); } @@ -95,7 +95,7 @@ void BKE_material_free(Material *ma) if (ma->preview) BKE_previewimg_free(&ma->preview); - BKE_icon_delete((struct ID*)ma); + BKE_icon_delete((struct ID *)ma); ma->id.icon_id = 0; /* is no lib link block, but material extension */ @@ -110,67 +110,67 @@ void BKE_material_free(Material *ma) void init_material(Material *ma) { - ma->r= ma->g= ma->b= ma->ref= 0.8; - ma->specr= ma->specg= ma->specb= 1.0; - ma->mirr= ma->mirg= ma->mirb= 1.0; - ma->spectra= 1.0; - ma->amb= 1.0; - ma->alpha= 1.0; - ma->spec= ma->hasize= 0.5; - ma->har= 50; - ma->starc= ma->ringc= 4; - ma->linec= 12; - ma->flarec= 1; - ma->flaresize= ma->subsize= 1.0; - ma->flareboost= 1; - ma->seed2= 6; - ma->friction= 0.5; - ma->refrac= 4.0; - ma->roughness= 0.5; - ma->param[0]= 0.5; - ma->param[1]= 0.1; - ma->param[2]= 0.5; - ma->param[3]= 0.1; - ma->rms= 0.1; - ma->darkness= 1.0; - - ma->strand_sta= ma->strand_end= 1.0f; - - ma->ang= 1.0; - ma->ray_depth= 2; - ma->ray_depth_tra= 2; - ma->fresnel_mir= 0.0; - ma->fresnel_tra= 0.0; - ma->fresnel_tra_i= 1.25; - ma->fresnel_mir_i= 1.25; - ma->tx_limit= 0.0; - ma->tx_falloff= 1.0; - ma->shad_alpha= 1.0f; - - ma->gloss_mir = ma->gloss_tra= 1.0; - ma->samp_gloss_mir = ma->samp_gloss_tra= 18; + ma->r = ma->g = ma->b = ma->ref = 0.8; + ma->specr = ma->specg = ma->specb = 1.0; + ma->mirr = ma->mirg = ma->mirb = 1.0; + ma->spectra = 1.0; + ma->amb = 1.0; + ma->alpha = 1.0; + ma->spec = ma->hasize = 0.5; + ma->har = 50; + ma->starc = ma->ringc = 4; + ma->linec = 12; + ma->flarec = 1; + ma->flaresize = ma->subsize = 1.0; + ma->flareboost = 1; + ma->seed2 = 6; + ma->friction = 0.5; + ma->refrac = 4.0; + ma->roughness = 0.5; + ma->param[0] = 0.5; + ma->param[1] = 0.1; + ma->param[2] = 0.5; + ma->param[3] = 0.1; + ma->rms = 0.1; + ma->darkness = 1.0; + + ma->strand_sta = ma->strand_end = 1.0f; + + ma->ang = 1.0; + ma->ray_depth = 2; + ma->ray_depth_tra = 2; + ma->fresnel_mir = 0.0; + ma->fresnel_tra = 0.0; + ma->fresnel_tra_i = 1.25; + ma->fresnel_mir_i = 1.25; + ma->tx_limit = 0.0; + ma->tx_falloff = 1.0; + ma->shad_alpha = 1.0f; + + ma->gloss_mir = ma->gloss_tra = 1.0; + ma->samp_gloss_mir = ma->samp_gloss_tra = 18; ma->adapt_thresh_mir = ma->adapt_thresh_tra = 0.005; ma->dist_mir = 0.0; ma->fadeto_mir = MA_RAYMIR_FADETOSKY; - ma->rampfac_col= 1.0; - ma->rampfac_spec= 1.0; - ma->pr_lamp= 3; /* two lamps, is bits */ - ma->pr_type= MA_SPHERE; - - ma->sss_radius[0]= 1.0f; - ma->sss_radius[1]= 1.0f; - ma->sss_radius[2]= 1.0f; - ma->sss_col[0]= 1.0f; - ma->sss_col[1]= 1.0f; - ma->sss_col[2]= 1.0f; - ma->sss_error= 0.05f; - ma->sss_scale= 0.1f; - ma->sss_ior= 1.3f; - ma->sss_colfac= 1.0f; - ma->sss_texfac= 0.0f; - ma->sss_front= 1.0f; - ma->sss_back= 1.0f; + ma->rampfac_col = 1.0; + ma->rampfac_spec = 1.0; + ma->pr_lamp = 3; /* two lamps, is bits */ + ma->pr_type = MA_SPHERE; + + ma->sss_radius[0] = 1.0f; + ma->sss_radius[1] = 1.0f; + ma->sss_radius[2] = 1.0f; + ma->sss_col[0] = 1.0f; + ma->sss_col[1] = 1.0f; + ma->sss_col[2] = 1.0f; + ma->sss_error = 0.05f; + ma->sss_scale = 0.1f; + ma->sss_ior = 1.3f; + ma->sss_colfac = 1.0f; + ma->sss_texfac = 0.0f; + ma->sss_front = 1.0f; + ma->sss_back = 1.0f; ma->vol.density = 1.0f; ma->vol.emission = 0.0f; @@ -191,11 +191,11 @@ void init_material(Material *ma) ma->vol.ms_intensity = 1.f; ma->game.flag = GEMAT_BACKCULL; - ma->game.alpha_blend=0; - ma->game.face_orientation=0; + ma->game.alpha_blend = 0; + ma->game.face_orientation = 0; - ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RAYBIAS|MA_TANGENT_STR|MA_ZTRANSP; - ma->shade_flag= MA_APPROX_OCCLUSION; + ma->mode = MA_TRACEBLE | MA_SHADBUF | MA_SHADOW | MA_RAYBIAS | MA_TANGENT_STR | MA_ZTRANSP; + ma->shade_flag = MA_APPROX_OCCLUSION; ma->preview = NULL; } @@ -203,7 +203,7 @@ Material *BKE_material_add(const char *name) { Material *ma; - ma= BKE_libblock_alloc(&G.main->mat, ID_MA, name); + ma = BKE_libblock_alloc(&G.main->mat, ID_MA, name); init_material(ma); @@ -216,28 +216,28 @@ Material *BKE_material_copy(Material *ma) Material *man; int a; - man= BKE_libblock_copy(&ma->id); + man = BKE_libblock_copy(&ma->id); id_lib_extern((ID *)man->group); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (ma->mtex[a]) { - man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial"); + 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) { - man->nodetree= ntreeCopyTree(ma->nodetree); /* 0 == full new tree */ + man->nodetree = ntreeCopyTree(ma->nodetree); /* 0 == full new tree */ } - man->gpumaterial.first= man->gpumaterial.last= NULL; + man->gpumaterial.first = man->gpumaterial.last = NULL; return man; } @@ -248,26 +248,26 @@ Material *localize_material(Material *ma) Material *man; int a; - man= BKE_libblock_copy(&ma->id); + man = BKE_libblock_copy(&ma->id); 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++) { + for (a = 0; a < MAX_MTEX; a++) { if (ma->mtex[a]) { - man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial"); + 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) - man->nodetree= ntreeLocalize(ma->nodetree); + man->nodetree = ntreeLocalize(ma->nodetree); - man->gpumaterial.first= man->gpumaterial.last= NULL; + man->gpumaterial.first = man->gpumaterial.last = NULL; return man; } @@ -275,29 +275,29 @@ Material *localize_material(Material *ma) static void extern_local_material(Material *ma) { int i; - for (i=0; i < MAX_MTEX; i++) { + for (i = 0; i < MAX_MTEX; i++) { if (ma->mtex[i]) id_lib_extern((ID *)ma->mtex[i]->tex); } } void BKE_material_make_local(Material *ma) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; Mesh *me; Curve *cu; MetaBall *mb; - int a, is_local= FALSE, is_lib= FALSE; + int a, is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - 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; @@ -306,56 +306,56 @@ void BKE_material_make_local(Material *ma) /* Check which other IDs reference this one to determine if it's used by * lib or local */ /* test objects */ - ob= bmain->object.first; + 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; - else is_local= TRUE; + for (a = 0; a < ob->totcol; a++) { + if (ob->mat[a] == ma) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - ob= ob->id.next; + ob = ob->id.next; } /* test meshes */ - me= bmain->mesh.first; + 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; - else is_local= TRUE; + for (a = 0; a < me->totcol; a++) { + if (me->mat[a] == ma) { + if (me->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - me= me->id.next; + me = me->id.next; } /* test curves */ - cu= bmain->curve.first; + 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; - else is_local= TRUE; + for (a = 0; a < cu->totcol; a++) { + if (cu->mat[a] == ma) { + if (cu->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - cu= cu->id.next; + cu = cu->id.next; } /* test mballs */ - mb= bmain->mball.first; + 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; - else is_local= TRUE; + for (a = 0; a < mb->totcol; a++) { + if (mb->mat[a] == ma) { + if (mb->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - mb= mb->id.next; + mb = mb->id.next; } /* Only local users. */ @@ -365,76 +365,76 @@ void BKE_material_make_local(Material *ma) } /* Both user and local, so copy. */ else if (is_local && is_lib) { - Material *ma_new= BKE_material_copy(ma); + Material *ma_new = BKE_material_copy(ma); - ma_new->id.us= 0; + ma_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, ma->id.lib, &ma_new->id); /* do objects */ - ob= bmain->object.first; + 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) { - ob->mat[a]= ma_new; + 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--; } } } } - ob= ob->id.next; + ob = ob->id.next; } /* do meshes */ - me= bmain->mesh.first; + 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) { - me->mat[a]= ma_new; + 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--; } } } } - me= me->id.next; + me = me->id.next; } /* do curves */ - cu= bmain->curve.first; + 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) { - cu->mat[a]= ma_new; + 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--; } } } } - cu= cu->id.next; + cu = cu->id.next; } /* do mballs */ - mb= bmain->mball.first; + 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) { - mb->mat[a]= ma_new; + 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--; } } } } - mb= mb->id.next; + mb = mb->id.next; } } } @@ -443,7 +443,7 @@ void BKE_material_make_local(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,16 +454,16 @@ Material ***give_matarar(Object *ob) Curve *cu; MetaBall *mb; - if (ob->type==OB_MESH) { - me= ob->data; + if (ob->type == OB_MESH) { + me = ob->data; return &(me->mat); } else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) { - cu= ob->data; + cu = ob->data; return &(cu->mat); } - else if (ob->type==OB_MBALL) { - mb= ob->data; + else if (ob->type == OB_MBALL) { + mb = ob->data; return &(mb->mat); } return NULL; @@ -475,16 +475,16 @@ short *give_totcolp(Object *ob) Curve *cu; MetaBall *mb; - if (ob->type==OB_MESH) { - me= ob->data; + if (ob->type == OB_MESH) { + me = ob->data; return &(me->totcol); } else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) { - cu= ob->data; + cu = ob->data; return &(cu->totcol); } - else if (ob->type==OB_MBALL) { - mb= ob->data; + else if (ob->type == OB_MBALL) { + mb = ob->data; return &(mb->totcol); } return NULL; @@ -494,15 +494,15 @@ short *give_totcolp(Object *ob) Material ***give_matarar_id(ID *id) { switch (GS(id->name)) { - case ID_ME: - return &(((Mesh *)id)->mat); - break; - case ID_CU: - return &(((Curve *)id)->mat); - break; - case ID_MB: - return &(((MetaBall *)id)->mat); - break; + case ID_ME: + return &(((Mesh *)id)->mat); + break; + case ID_CU: + return &(((Curve *)id)->mat); + break; + case ID_MB: + return &(((MetaBall *)id)->mat); + break; } return NULL; } @@ -510,15 +510,15 @@ Material ***give_matarar_id(ID *id) short *give_totcolp_id(ID *id) { switch (GS(id->name)) { - case ID_ME: - return &(((Mesh *)id)->totcol); - break; - case ID_CU: - return &(((Curve *)id)->totcol); - break; - case ID_MB: - return &(((MetaBall *)id)->totcol); - break; + case ID_ME: + return &(((Mesh *)id)->totcol); + break; + case ID_CU: + return &(((Curve *)id)->totcol); + break; + case ID_MB: + return &(((MetaBall *)id)->totcol); + break; } return NULL; } @@ -526,29 +526,29 @@ short *give_totcolp_id(ID *id) static void data_delete_material_index_id(ID *id, short index) { switch (GS(id->name)) { - case ID_ME: - BKE_mesh_delete_material_index((Mesh *)id, index); - break; - case ID_CU: - BKE_curve_delete_material_index((Curve *)id, index); - break; - case ID_MB: - /* meta-elems don't have materials atm */ - break; + case ID_ME: + BKE_mesh_delete_material_index((Mesh *)id, index); + break; + case ID_CU: + BKE_curve_delete_material_index((Curve *)id, index); + break; + case ID_MB: + /* meta-elems don't have materials atm */ + break; } } void material_append_id(ID *id, Material *ma) { Material ***matar; - if ((matar= give_matarar_id(id))) { - short *totcol= give_totcolp_id(id); - Material **mat= MEM_callocN(sizeof(void *) * ((*totcol) + 1), "newmatar"); + 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); - *matar= mat; - (*matar)[(*totcol)++]= ma; + *matar = mat; + (*matar)[(*totcol)++] = ma; id_us_plus((ID *)ma); test_object_materials(id); @@ -557,33 +557,33 @@ void material_append_id(ID *id, Material *ma) Material *material_pop_id(ID *id, int index_i, int remove_material_slot) { - short index= (short)index_i; - Material *ret= NULL; + short index = (short)index_i; + Material *ret = NULL; Material ***matar; - if ((matar= give_matarar_id(id))) { - short *totcol= give_totcolp_id(id); + if ((matar = give_matarar_id(id))) { + short *totcol = give_totcolp_id(id); if (index >= 0 && index < (*totcol)) { - ret= (*matar)[index]; + ret = (*matar)[index]; id_us_min((ID *)ret); if (remove_material_slot) { if (*totcol <= 1) { - *totcol= 0; + *totcol = 0; MEM_freeN(*matar); - *matar= NULL; + *matar = NULL; } else { Material **mat; if (index + 1 != (*totcol)) - memmove((*matar)+index, (*matar)+(index+1), sizeof(void *) * ((*totcol) - (index + 1))); + memmove((*matar) + index, (*matar) + (index + 1), sizeof(void *) * ((*totcol) - (index + 1))); (*totcol)--; - mat= MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); + mat = MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); memcpy(mat, *matar, sizeof(void *) * (*totcol)); MEM_freeN(*matar); - *matar= mat; + *matar = mat; test_object_materials(id); } @@ -593,7 +593,7 @@ Material *material_pop_id(ID *id, int index_i, int remove_material_slot) /* don't remove material slot, only clear it*/ else - (*matar)[index]= NULL; + (*matar)[index] = NULL; } } @@ -605,33 +605,33 @@ 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; + totcolp = give_totcolp(ob); + 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 */ - ma= ob->mat[act-1]; + if (ob->matbits && ob->matbits[act - 1]) { /* in object */ + ma = ob->mat[act - 1]; } - else { /* in data */ + else { /* in data */ /* check for inconsistency */ if (*totcolp < ob->totcol) - ob->totcol= *totcolp; - if (act>ob->totcol) act= ob->totcol; + ob->totcol = *totcolp; + if (act > ob->totcol) act = ob->totcol; - matarar= give_matarar(ob); + matarar = give_matarar(ob); - if (matarar && *matarar) ma= (*matarar)[act-1]; - else ma= NULL; + if (matarar && *matarar) ma = (*matarar)[act - 1]; + else ma = NULL; } @@ -641,19 +641,19 @@ 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) { - bNode *node= nodeGetActiveID(ma->nodetree, ID_MA); + bNode *node = nodeGetActiveID(ma->nodetree, ID_MA); if (node) return (Material *)node->id; @@ -670,7 +670,7 @@ Material *give_node_material(Material *ma) * well. I expect we'll sort it out soon... */ /* from blendef: */ -#define GS(a) (*((short *)(a))) +#define GS(a) (*((short *)(a))) /* from misc_util: flip the bytes from x */ /* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */ @@ -680,29 +680,29 @@ void resize_object_material(Object *ob, const short totcol) Material **newmatar; char *newmatbits; - if (totcol==0) { + if (totcol == 0) { if (ob->totcol) { MEM_freeN(ob->mat); MEM_freeN(ob->matbits); - ob->mat= NULL; - ob->matbits= NULL; + ob->mat = NULL; + ob->matbits = NULL; } } - else if (ob->totcol<totcol) { - newmatar= MEM_callocN(sizeof(void *)*totcol, "newmatar"); - newmatbits= MEM_callocN(sizeof(char)*totcol, "newmatbits"); + else if (ob->totcol < totcol) { + newmatar = MEM_callocN(sizeof(void *) * totcol, "newmatar"); + newmatbits = MEM_callocN(sizeof(char) * totcol, "newmatbits"); if (ob->totcol) { - memcpy(newmatar, ob->mat, sizeof(void *)*ob->totcol); - memcpy(newmatbits, ob->matbits, sizeof(char)*ob->totcol); + memcpy(newmatar, ob->mat, sizeof(void *) * ob->totcol); + memcpy(newmatbits, ob->matbits, sizeof(char) * ob->totcol); MEM_freeN(ob->mat); MEM_freeN(ob->matbits); } - ob->mat= newmatar; - ob->matbits= newmatbits; + ob->mat = newmatar; + ob->matbits = newmatbits; } - ob->totcol= totcol; - if (ob->totcol && ob->actcol==0) ob->actcol= 1; - if (ob->actcol>ob->totcol) ob->actcol= ob->totcol; + ob->totcol = 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,8 +727,8 @@ 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); @@ -736,27 +736,27 @@ void assign_material_id(ID *id, Material *ma, short act) /* test arraylens */ - totcolp= give_totcolp_id(id); - matarar= give_matarar_id(id); + 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) { - matar= MEM_callocN(sizeof(void *)*act, "matarray1"); + matar = MEM_callocN(sizeof(void *) * act, "matarray1"); if (*totcolp) { - memcpy(matar, *matarar, sizeof(void *)*(*totcolp)); + memcpy(matar, *matarar, sizeof(void *) * (*totcolp)); MEM_freeN(*matarar); } - *matarar= matar; - *totcolp= act; + *matarar = matar; + *totcolp = act; } /* in data */ - mao= (*matarar)[act-1]; + mao = (*matarar)[act - 1]; if (mao) mao->id.us--; - (*matarar)[act-1]= ma; + (*matarar)[act - 1] = ma; if (ma) id_us_plus((ID *)ma); @@ -770,8 +770,8 @@ 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); @@ -779,54 +779,54 @@ void assign_material(Object *ob, Material *ma, short act) /* test arraylens */ - totcolp= give_totcolp(ob); - matarar= give_matarar(ob); + totcolp = give_totcolp(ob); + matarar = give_matarar(ob); - if (totcolp==NULL || matarar==NULL) return; + if (totcolp == NULL || matarar == NULL) return; if (act > *totcolp) { - matar= MEM_callocN(sizeof(void *)*act, "matarray1"); + matar = MEM_callocN(sizeof(void *) * act, "matarray1"); if (*totcolp) { - memcpy(matar, *matarar, sizeof(void *)*(*totcolp)); + memcpy(matar, *matarar, sizeof(void *) * (*totcolp)); MEM_freeN(*matarar); } - *matarar= matar; - *totcolp= act; + *matarar = matar; + *totcolp = act; } if (act > ob->totcol) { - matar= MEM_callocN(sizeof(void *)*act, "matarray2"); - matbits= MEM_callocN(sizeof(char)*act, "matbits1"); - if ( ob->totcol) { + matar = MEM_callocN(sizeof(void *) * act, "matarray2"); + matbits = MEM_callocN(sizeof(char) * act, "matbits1"); + if (ob->totcol) { memcpy(matar, ob->mat, sizeof(void *) * ob->totcol); - memcpy(matbits, ob->matbits, sizeof(char)*(*totcolp)); + memcpy(matbits, ob->matbits, sizeof(char) * (*totcolp)); MEM_freeN(ob->mat); MEM_freeN(ob->matbits); } - ob->mat= matar; - ob->matbits= matbits; - ob->totcol= act; + ob->mat = matar; + ob->matbits = matbits; + ob->totcol = act; /* copy object/mesh linking, or assign based on userpref */ if (ob->actcol) - ob->matbits[act-1]= ob->matbits[ob->actcol-1]; + ob->matbits[act - 1] = ob->matbits[ob->actcol - 1]; else - ob->matbits[act-1]= (U.flag & USER_MAT_ON_OB)? 1: 0; + ob->matbits[act - 1] = (U.flag & USER_MAT_ON_OB) ? 1 : 0; } /* do it */ - if (ob->matbits[act-1]) { /* in object */ - mao= ob->mat[act-1]; + if (ob->matbits[act - 1]) { /* in object */ + mao = ob->mat[act - 1]; if (mao) mao->id.us--; - ob->mat[act-1]= ma; + ob->mat[act - 1] = ma; } - else { /* in data */ - mao= (*matarar)[act-1]; + else { /* in data */ + mao = (*matarar)[act - 1]; if (mao) mao->id.us--; - (*matarar)[act-1]= ma; + (*matarar)[act - 1] = ma; } if (ma) @@ -837,19 +837,19 @@ void assign_material(Object *ob, Material *ma, short act) /* XXX - this calls many more update calls per object then are needed, could be optimized */ void assign_matarar(struct Object *ob, struct Material ***matar, short totcol) { - int actcol_orig= ob->actcol; + int actcol_orig = ob->actcol; short i; while (object_remove_material_slot(ob)) {}; /* now we have the right number of slots */ - for (i=0; i<totcol; i++) - assign_material(ob, (*matar)[i], i+1); + for (i = 0; i < totcol; i++) + assign_material(ob, (*matar)[i], i + 1); if (actcol_orig > ob->totcol) - actcol_orig= ob->totcol; + actcol_orig = ob->totcol; - ob->actcol= actcol_orig; + ob->actcol = actcol_orig; } @@ -858,45 +858,45 @@ 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); + 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) - break; - if (a<*totcolp) - return a+1; + for (a = 0; a < *totcolp; a++) + if ((*matarar)[a] == ma) + break; + 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; + assign_material(ob, NULL, ob->totcol + 1); + ob->actcol = ob->totcol; return TRUE; } static void do_init_render_material(Material *ma, int r_mode, float *amb) { MTex *mtex; - int a, needuv=0, needtang=0; + 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]; + mtex = ma->mtex[a]; if (mtex && mtex->tex && (mtex->tex->type | (mtex->tex->use_nodes && mtex->tex->nodetree) )) { ma->texco |= mtex->texco; @@ -904,41 +904,41 @@ static void do_init_render_material(Material *ma, int r_mode, float *amb) /* 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)) - needtang= 1; + needtang = 1; } } if (needtang) ma->mode |= MA_NORMAP_TANG; else ma->mode &= ~MA_NORMAP_TANG; - if (ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { - needuv= 1; - if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */ + if (ma->mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) { + needuv = 1; + if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */ } 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))) { - ma->texco |= NEED_UV|TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM; + 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 (amb) { - ma->ambr= ma->amb*amb[0]; - ma->ambg= ma->amb*amb[1]; - ma->ambb= ma->amb*amb[2]; + ma->ambr = ma->amb * amb[0]; + ma->ambg = ma->amb * amb[1]; + ma->ambb = ma->amb * amb[2]; } /* will become or-ed result of all node modes */ - ma->mode_l= ma->mode; + ma->mode_l = ma->mode; ma->mode_l &= ~MA_SHLESS; if (ma->strand_surfnor > 0.0f) @@ -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) { + 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 (GS(node->id->name) == ID_MA) { + Material *ma = (Material *)node->id; + 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); + 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); } } @@ -989,15 +989,15 @@ 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) { + for (ma = bmain->mat.first; ma; ma = ma->id.next) { if (ma->id.us) { - ma->texco= 0; - ma->mapto= 0; + 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) @@ -1019,7 +1019,7 @@ void end_render_material(Material *mat) void end_render_materials(Main *bmain) { Material *ma; - for (ma= bmain->mat.first; ma; ma= ma->id.next) + 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,7 +1043,7 @@ 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) return material_in_nodetree(parmat->nodetree, mat); @@ -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; - 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 (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; new_id(&G.main->mat, (ID *)ma, colname_array[nr]); } @@ -1107,7 +1107,7 @@ int object_remove_material_slot(Object *ob) short *totcolp; short a, actcol; - if (ob==NULL || ob->totcol==0) { + if (ob == NULL || ob->totcol == 0) { return FALSE; } @@ -1124,54 +1124,54 @@ int object_remove_material_slot(Object *ob) * after that check indices in mesh/curve/mball!!! */ - totcolp= give_totcolp(ob); - matarar= give_matarar(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]; + mao = (*matarar)[ob->actcol - 1]; if (mao) mao->id.us--; - for (a=ob->actcol; a<ob->totcol; a++) - (*matarar)[a-1]= (*matarar)[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; + *matarar = NULL; } - actcol= ob->actcol; - obt= G.main->object.first; + actcol = ob->actcol; + 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]; + mao = obt->mat[actcol - 1]; if (mao) mao->id.us--; - for (a=actcol; a<obt->totcol; a++) { - obt->mat[a-1]= obt->mat[a]; - obt->matbits[a-1]= obt->matbits[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; - obt->matbits= NULL; + obt->mat = NULL; + obt->matbits = NULL; } } - obt= obt->id.next; + obt = obt->id.next; } /* check indices from mesh */ if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) { - data_delete_material_index_id((ID *)ob->data, actcol-1); + data_delete_material_index_id((ID *)ob->data, actcol - 1); freedisplist(&ob->disp); } @@ -1182,253 +1182,253 @@ int object_remove_material_slot(Object *ob) /* r_col = current value, col = new value, fac==0 is no change */ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) { - float tmp, facm= 1.0f-fac; + float tmp, facm = 1.0f - fac; switch (type) { case MA_RAMP_BLEND: - r_col[0] = facm*(r_col[0]) + fac*col[0]; - r_col[1] = facm*(r_col[1]) + fac*col[1]; - r_col[2] = facm*(r_col[2]) + fac*col[2]; + r_col[0] = facm * (r_col[0]) + fac * col[0]; + r_col[1] = facm * (r_col[1]) + fac * col[1]; + r_col[2] = facm * (r_col[2]) + fac * col[2]; break; case MA_RAMP_ADD: - r_col[0] += fac*col[0]; - r_col[1] += fac*col[1]; - r_col[2] += fac*col[2]; + r_col[0] += fac * col[0]; + r_col[1] += fac * col[1]; + r_col[2] += fac * col[2]; break; case MA_RAMP_MULT: - r_col[0] *= (facm + fac*col[0]); - r_col[1] *= (facm + fac*col[1]); - r_col[2] *= (facm + fac*col[2]); + r_col[0] *= (facm + fac * col[0]); + r_col[1] *= (facm + fac * col[1]); + r_col[2] *= (facm + fac * col[2]); break; case MA_RAMP_SCREEN: - r_col[0] = 1.0f - (facm + fac*(1.0f - col[0])) * (1.0f - r_col[0]); - r_col[1] = 1.0f - (facm + fac*(1.0f - col[1])) * (1.0f - r_col[1]); - r_col[2] = 1.0f - (facm + fac*(1.0f - col[2])) * (1.0f - r_col[2]); + r_col[0] = 1.0f - (facm + fac * (1.0f - col[0])) * (1.0f - r_col[0]); + r_col[1] = 1.0f - (facm + fac * (1.0f - col[1])) * (1.0f - r_col[1]); + 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) - r_col[0] *= (facm + 2.0f*fac*col[0]); + 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]); + r_col[0] = 1.0f - (facm + 2.0f * fac * (1.0f - col[0])) * (1.0f - r_col[0]); if (r_col[1] < 0.5f) - r_col[1] *= (facm + 2.0f*fac*col[1]); + 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]); + r_col[1] = 1.0f - (facm + 2.0f * fac * (1.0f - col[1])) * (1.0f - r_col[1]); if (r_col[2] < 0.5f) - r_col[2] *= (facm + 2.0f*fac*col[2]); + 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]); + r_col[2] = 1.0f - (facm + 2.0f * fac * (1.0f - col[2])) * (1.0f - r_col[2]); break; case MA_RAMP_SUB: - r_col[0] -= fac*col[0]; - r_col[1] -= fac*col[1]; - r_col[2] -= fac*col[2]; + r_col[0] -= fac * col[0]; + r_col[1] -= fac * col[1]; + r_col[2] -= fac * col[2]; break; case MA_RAMP_DIV: - if (col[0]!=0.0f) - r_col[0] = facm*(r_col[0]) + fac*(r_col[0])/col[0]; - if (col[1]!=0.0f) - r_col[1] = facm*(r_col[1]) + fac*(r_col[1])/col[1]; - if (col[2]!=0.0f) - r_col[2] = facm*(r_col[2]) + fac*(r_col[2])/col[2]; + if (col[0] != 0.0f) + r_col[0] = facm * (r_col[0]) + fac * (r_col[0]) / col[0]; + if (col[1] != 0.0f) + r_col[1] = facm * (r_col[1]) + fac * (r_col[1]) / col[1]; + if (col[2] != 0.0f) + r_col[2] = facm * (r_col[2]) + fac * (r_col[2]) / col[2]; break; case MA_RAMP_DIFF: - r_col[0] = facm*(r_col[0]) + fac*fabsf(r_col[0]-col[0]); - r_col[1] = facm*(r_col[1]) + fac*fabsf(r_col[1]-col[1]); - r_col[2] = facm*(r_col[2]) + fac*fabsf(r_col[2]-col[2]); + r_col[0] = facm * (r_col[0]) + fac *fabsf(r_col[0] - col[0]); + r_col[1] = facm * (r_col[1]) + fac *fabsf(r_col[1] - col[1]); + r_col[2] = facm * (r_col[2]) + fac *fabsf(r_col[2] - col[2]); break; case MA_RAMP_DARK: - tmp=col[0]+((1-col[0])*facm); - 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; - tmp=col[2]+((1-col[2])*facm); - if (tmp < r_col[2]) r_col[2]= tmp; + tmp = col[0] + ((1 - col[0]) * facm); + 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; + tmp = col[2] + ((1 - col[2]) * facm); + 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; - tmp= fac*col[1]; - if (tmp > r_col[1]) r_col[1]= tmp; - tmp= fac*col[2]; - if (tmp > r_col[2]) r_col[2]= tmp; - break; + tmp = fac * col[0]; + if (tmp > r_col[0]) r_col[0] = tmp; + tmp = fac * col[1]; + if (tmp > r_col[1]) r_col[1] = tmp; + tmp = fac * col[2]; + if (tmp > r_col[2]) r_col[2] = tmp; + break; case MA_RAMP_DODGE: if (r_col[0] != 0.0f) { - tmp = 1.0f - fac*col[0]; + tmp = 1.0f - fac * col[0]; if (tmp <= 0.0f) r_col[0] = 1.0f; - else if ((tmp = (r_col[0]) / tmp)> 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) { - tmp = 1.0f - fac*col[1]; - if (tmp <= 0.0f ) + tmp = 1.0f - fac * col[1]; + if (tmp <= 0.0f) r_col[1] = 1.0f; - else if ((tmp = (r_col[1]) / tmp) > 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) { - tmp = 1.0f - fac*col[2]; + tmp = 1.0f - fac * col[2]; if (tmp <= 0.0f) r_col[2] = 1.0f; - else if ((tmp = (r_col[2]) / tmp) > 1.0f ) + else if ((tmp = (r_col[2]) / tmp) > 1.0f) r_col[2] = 1.0f; else r_col[2] = tmp; } break; case MA_RAMP_BURN: - tmp = facm + fac*col[0]; + tmp = facm + fac * col[0]; 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; + else if ((tmp = (1.0f - (1.0f - (r_col[0])) / tmp)) < 0.0f) + r_col[0] = 0.0f; else if (tmp > 1.0f) - r_col[0]=1.0f; + r_col[0] = 1.0f; else r_col[0] = tmp; - tmp = facm + fac*col[1]; + tmp = facm + fac * col[1]; 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) - r_col[1]=1.0f; + else if ((tmp = (1.0f - (1.0f - (r_col[1])) / tmp)) < 0.0f) + r_col[1] = 0.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) + tmp = facm + fac * col[2]; + 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 - (1.0f - (r_col[2])) / tmp )) < 0.0f ) - r_col[2] = 0.0f; - else if (tmp >1.0f) - r_col[2]= 1.0f; + else if (tmp > 1.0f) + r_col[2] = 1.0f; else r_col[2] = tmp; break; case MA_RAMP_HUE: - { - float rH, rS, rV; - float colH, colS, colV; - float tmpr, tmpg, tmpb; - rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - 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; - r_col[1] = facm*(r_col[1]) + fac*tmpg; - r_col[2] = facm*(r_col[2]) + fac*tmpb; - } - } - break; - case MA_RAMP_SAT: - { - float rH, rS, rV; - float colH, colS, colV; + { + float rH, rS, rV; + float colH, colS, colV; + float tmpr, tmpg, tmpb; + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + if (colS != 0) { rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); - 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); - } + hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb); + r_col[0] = facm * (r_col[0]) + fac * tmpr; + r_col[1] = facm * (r_col[1]) + fac * tmpg; + r_col[2] = facm * (r_col[2]) + fac * tmpb; } - break; - case MA_RAMP_VAL: - { - float rH, rS, rV; - float colH, colS, colV; - rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + } + break; + case MA_RAMP_SAT: + { + 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) { rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - hsv_to_rgb(rH, rS, (facm*rV +fac*colV), r_col+0, r_col+1, r_col+2); + hsv_to_rgb(rH, (facm * rS + fac * colS), rV, r_col + 0, r_col + 1, r_col + 2); } - break; + } + break; + case MA_RAMP_VAL: + { + float rH, rS, rV; + float colH, colS, colV; + rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + hsv_to_rgb(rH, rS, (facm * rV + fac * colV), r_col + 0, r_col + 1, r_col + 2); + } + break; case MA_RAMP_COLOR: - { - float rH, rS, rV; - float colH, colS, colV; - float tmpr, tmpg, tmpb; - rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - 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; - r_col[1] = facm*(r_col[1]) + fac*tmpg; - r_col[2] = facm*(r_col[2]) + fac*tmpb; - } + { + float rH, rS, rV; + float colH, colS, colV; + float tmpr, tmpg, tmpb; + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + 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; + r_col[1] = facm * (r_col[1]) + fac * tmpg; + r_col[2] = facm * (r_col[2]) + fac * tmpb; } - break; + } + break; case MA_RAMP_SOFT: - { - float scr, scg, scb; + { + float scr, scg, scb; - /* first calculate non-fac based Screen mix */ - scr = 1.0f - (1.0f - col[0]) * (1.0f - r_col[0]); - scg = 1.0f - (1.0f - col[1]) * (1.0f - r_col[1]); - scb = 1.0f - (1.0f - col[2]) * (1.0f - r_col[2]); + /* first calculate non-fac based Screen mix */ + scr = 1.0f - (1.0f - col[0]) * (1.0f - r_col[0]); + scg = 1.0f - (1.0f - col[1]) * (1.0f - r_col[1]); + scb = 1.0f - (1.0f - col[2]) * (1.0f - r_col[2]); - r_col[0] = facm*(r_col[0]) + fac*(((1.0f - r_col[0]) * col[0] * (r_col[0])) + (r_col[0] * scr)); - r_col[1] = facm*(r_col[1]) + fac*(((1.0f - r_col[1]) * col[1] * (r_col[1])) + (r_col[1] * scg)); - r_col[2] = facm*(r_col[2]) + fac*(((1.0f - r_col[2]) * col[2] * (r_col[2])) + (r_col[2] * scb)); - } - break; + r_col[0] = facm * (r_col[0]) + fac * (((1.0f - r_col[0]) * col[0] * (r_col[0])) + (r_col[0] * scr)); + r_col[1] = facm * (r_col[1]) + fac * (((1.0f - r_col[1]) * col[1] * (r_col[1])) + (r_col[1] * scg)); + r_col[2] = facm * (r_col[2]) + fac * (((1.0f - r_col[2]) * col[2] * (r_col[2])) + (r_col[2] * scb)); + } + break; case MA_RAMP_LINEAR: if (col[0] > 0.5f) - r_col[0] = r_col[0] + fac*(2.0f*(col[0]-0.5f)); + r_col[0] = r_col[0] + fac * (2.0f * (col[0] - 0.5f)); else - r_col[0] = r_col[0] + fac*(2.0f*(col[0]) - 1.0f); + r_col[0] = r_col[0] + fac * (2.0f * (col[0]) - 1.0f); if (col[1] > 0.5f) - r_col[1] = r_col[1] + fac*(2.0f*(col[1]-0.5f)); + r_col[1] = r_col[1] + fac * (2.0f * (col[1] - 0.5f)); else - r_col[1] = r_col[1] + fac*(2.0f*(col[1]) -1.0f); + r_col[1] = r_col[1] + fac * (2.0f * (col[1]) - 1.0f); if (col[2] > 0.5f) - r_col[2] = r_col[2] + fac*(2.0f*(col[2]-0.5f)); + r_col[2] = r_col[2] + fac * (2.0f * (col[2] - 0.5f)); else - r_col[2] = r_col[2] + fac*(2.0f*(col[2]) - 1.0f); + r_col[2] = r_col[2] + fac * (2.0f * (col[2]) - 1.0f); break; } } /* copy/paste buffer, if we had a propper py api that would be better */ static Material matcopybuf; -static short matcopied= 0; +static short matcopied = 0; void clear_matcopybuf(void) { memset(&matcopybuf, 0, sizeof(Material)); - matcopied= 0; + matcopied = 0; } void free_matcopybuf(void) { int a; - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (matcopybuf.mtex[a]) { MEM_freeN(matcopybuf.mtex[a]); - matcopybuf.mtex[a]= NULL; + matcopybuf.mtex[a] = NULL; } } 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; + matcopybuf.ramp_col = NULL; + matcopybuf.ramp_spec = NULL; if (matcopybuf.nodetree) { ntreeFreeTree(matcopybuf.nodetree); MEM_freeN(matcopybuf.nodetree); - matcopybuf.nodetree= NULL; + matcopybuf.nodetree = NULL; } - matcopied= 0; + matcopied = 0; } void copy_matcopybuf(Material *ma) @@ -1440,19 +1440,19 @@ void copy_matcopybuf(Material *ma) 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++) { - mtex= matcopybuf.mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = matcopybuf.mtex[a]; if (mtex) { - matcopybuf.mtex[a]= MEM_dupallocN(mtex); + matcopybuf.mtex[a] = MEM_dupallocN(mtex); } } - matcopybuf.nodetree= ntreeCopyTree(ma->nodetree); - matcopybuf.preview= NULL; - matcopybuf.gpumaterial.first= matcopybuf.gpumaterial.last= NULL; - matcopied= 1; + matcopybuf.nodetree = ntreeCopyTree(ma->nodetree); + matcopybuf.preview = NULL; + matcopybuf.gpumaterial.first = matcopybuf.gpumaterial.last = NULL; + matcopied = 1; } void paste_matcopybuf(Material *ma) @@ -1461,13 +1461,13 @@ 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++) { - mtex= ma->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); } @@ -1479,22 +1479,22 @@ void paste_matcopybuf(Material *ma) GPU_material_free(ma); - id= (ma->id); + id = (ma->id); memcpy(ma, &matcopybuf, sizeof(Material)); - (ma->id)= id; + (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++) { - mtex= ma->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = ma->mtex[a]; if (mtex) { - ma->mtex[a]= MEM_dupallocN(mtex); + ma->mtex[a] = MEM_dupallocN(mtex); if (mtex->tex) id_us_plus((ID *)mtex->tex); } } - ma->nodetree= ntreeCopyTree(matcopybuf.nodetree); + ma->nodetree = ntreeCopyTree(matcopybuf.nodetree); } @@ -1530,7 +1530,7 @@ static int encode_tfaceflag(MTFace *tf, int convertall) static void decode_tfaceflag(Material *ma, int flag, int convertall) { int alphablend; - GameSettings *game= &ma->game; + GameSettings *game = &ma->game; /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */ flag -= 1; @@ -1539,7 +1539,7 @@ static void decode_tfaceflag(Material *ma, int flag, int convertall) (*game).flag = 0; /* General Material Options */ - if ((flag & TF_DYNAMIC)==0) (*game).flag |= GEMAT_NOPHYSICS; + if ((flag & TF_DYNAMIC) == 0) (*game).flag |= GEMAT_NOPHYSICS; /* Material Offline Rendering Properties */ if (convertall) { @@ -1547,8 +1547,8 @@ static void decode_tfaceflag(Material *ma, int flag, int convertall) } /* Special Face Properties */ - if ((flag & TF_TWOSIDE)==0) (*game).flag |= GEMAT_BACKCULL; - if (flag & TF_INVISIBLE)(*game).flag |= GEMAT_INVISIBLE; + if ((flag & TF_TWOSIDE) == 0) (*game).flag |= GEMAT_BACKCULL; + if (flag & TF_INVISIBLE) (*game).flag |= GEMAT_INVISIBLE; if (flag & TF_BMFONT) (*game).flag |= GEMAT_TEXT; /* Face Orientation */ @@ -1570,7 +1570,7 @@ static int check_tfaceneedmaterial(int flag) // also if only flags are visible and collision see if all objects using this mesh have this option in physics /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */ - flag -=1; + flag -= 1; // deprecated flags flag &= ~TF_OBCOL; @@ -1597,11 +1597,11 @@ static int check_tfaceneedmaterial(int flag) // XXX to be optmized or replaced by an equivalent blender internal function static int integer_getdigits(int number) { - int i=0; + int i = 0; if (number == 0) return 1; while (number != 0) { - number = (int)(number/10); + number = (int)(number / 10); i++; } return i; @@ -1615,7 +1615,7 @@ static void calculate_tface_materialname(char *matname, char *newname, int flag) int digits = integer_getdigits(flag); /* clamp the old name, remove the MA prefix and add the .TF.flag suffix * e.g. matname = "MALoooooooooooooongName"; newname = "Loooooooooooooon.TF.2" */ - BLI_snprintf(newname, MAX_ID_NAME, "%.*s.TF.%0*d", MAX_ID_NAME-(digits+5), matname, digits, flag); + BLI_snprintf(newname, MAX_ID_NAME, "%.*s.TF.%0*d", MAX_ID_NAME - (digits + 5), matname, digits, flag); } /* returns -1 if no match */ @@ -1623,7 +1623,7 @@ static short mesh_getmaterialnumber(Mesh *me, Material *ma) { short a; - for (a=0; a<me->totcol; a++) { + for (a = 0; a < me->totcol; a++) { if (me->mat[a] == ma) { return a; } @@ -1636,11 +1636,11 @@ static short mesh_getmaterialnumber(Mesh *me, Material *ma) static short mesh_addmaterial(Mesh *me, Material *ma) { material_append_id(&me->id, NULL); - me->mat[me->totcol-1]= ma; + me->mat[me->totcol - 1] = ma; id_us_plus(&ma->id); - return me->totcol-1; + return me->totcol - 1; } static void set_facetexture_flags(Material *ma, Image *image) @@ -1659,26 +1659,26 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag) { Material *ma; char idname[MAX_ID_NAME]; - short mat_nr= -1; + short mat_nr = -1; /* new material, the name uses the flag*/ BLI_snprintf(idname, sizeof(idname), "MAMaterial.TF.%0*d", integer_getdigits(flag), flag); - if ((ma= BLI_findstring(&main->mat, idname+2, offsetof(ID, name)+2))) { - mat_nr= mesh_getmaterialnumber(me, ma); + 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); } /* create a new material */ else { - ma= BKE_material_add(idname+2); + ma = BKE_material_add(idname + 2); if (ma) { - printf("TexFace Convert: Material \"%s\" created.\n", idname+2); - mat_nr= mesh_addmaterial(me, ma); + printf("TexFace Convert: Material \"%s\" created.\n", idname + 2); + mat_nr = mesh_addmaterial(me, ma); /* if needed set "Face Textures [Alpha]" Material options */ set_facetexture_flags(ma, tf->tpage); @@ -1690,7 +1690,7 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag) ma->game.flag = -flag; id_us_min((ID *)ma); } - else printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname+2, me->id.name+2); + else printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname + 2, me->id.name + 2); } /* set as converted, no need to go bad to this face */ @@ -1711,49 +1711,49 @@ 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++) + for (a = 0; a < me->totcol; a++) if (me->mat[a] == ma) break; /* no material found */ if (a == me->totcol) continue; /* get the active tface layer */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; 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++) { + 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; + tf = ((MTFace *)cdl->data) + a; flag = encode_tfaceflag(tf, 1); /* the name of the new material */ calculate_tface_materialname(ma->id.name, (char *)&idname, flag); - if ((mat_new= BLI_findstring(&main->mat, idname+2, offsetof(ID, name)+2))) { + if ((mat_new = BLI_findstring(&main->mat, idname + 2, offsetof(ID, name) + 2))) { /* 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=BKE_material_copy(ma); + mat_new = BKE_material_copy(ma); if (mat_new) { /* rename the material*/ strcpy(mat_new->id.name, idname); id_us_min((ID *)mat_new); - mat_nr= mesh_addmaterial(me, mat_new); + mat_nr = mesh_addmaterial(me, mat_new); decode_tfaceflag(mat_new, flag, 1); } else { - printf("Error: Unable to create Material \"%s\" for Mesh \"%s.", idname+2, me->id.name+2); + printf("Error: Unable to create Material \"%s\" for Mesh \"%s.", idname + 2, me->id.name + 2); mat_nr = mf->mat_nr; continue; } @@ -1770,8 +1770,8 @@ static void convert_tfacematerial(Main *main, Material *ma) 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,20 +1805,20 @@ 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 */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; if (!cdl) continue; - nomaterialslots = (me->totcol==0?1:0); + 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; + tf = ((MTFace *)cdl->data) + a; /* conversion should happen only once */ if (fileload) @@ -1834,7 +1834,7 @@ int do_version_tface(Main *main, int fileload) /* create/find a new material and assign to the face */ if (check_tfaceneedmaterial(flag)) { - mf->mat_nr= convert_tfacenomaterial(main, me, tf, flag); + mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag); } /* else mark them as no-material to be reverted to 0 later */ else { @@ -1842,7 +1842,7 @@ int do_version_tface(Main *main, int fileload) } } else if (mf->mat_nr < me->totcol) { - ma= me->mat[mf->mat_nr]; + ma = me->mat[mf->mat_nr]; /* no material create one if necessary */ if (!ma) { @@ -1851,7 +1851,7 @@ int do_version_tface(Main *main, int fileload) /* create/find a new material and assign to the face */ if (check_tfaceneedmaterial(flag)) - mf->mat_nr= convert_tfacenomaterial(main, me, tf, flag); + mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag); continue; } @@ -1869,11 +1869,11 @@ int do_version_tface(Main *main, int fileload) /* found a material */ else { - flag = encode_tfaceflag(tf, ((fileload)?0:1)); + flag = encode_tfaceflag(tf, ((fileload) ? 0 : 1)); /* first time changing this material */ if (ma->game.flag == 0) - ma->game.flag= -flag; + ma->game.flag = -flag; /* mark material as disputed */ else if (ma->game.flag != -flag) { @@ -1902,18 +1902,18 @@ int do_version_tface(Main *main, int fileload) /* if we didn't have material slot and now we do, we need to * make sure the materials are correct */ if (nomaterialslots) { - if (me->totcol>0) { - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + if (me->totcol > 0) { + 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; - mf->mat_nr= convert_tfacenomaterial(main, me, tf, encode_tfaceflag(tf, 1)); + tf = ((MTFace *)cdl->data) + a; + mf->mat_nr = convert_tfacenomaterial(main, me, tf, encode_tfaceflag(tf, 1)); } } } else { - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { - mf->mat_nr=0; + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { + mf->mat_nr = 0; } } } @@ -1924,14 +1924,14 @@ int do_version_tface(Main *main, int fileload) /* skip library files */ /* we shouldn't loop through the materials created in the loop. make the loop stop at its original length) */ - for (ma= main->mat.first, a=0; ma; ma= ma->id.next, a++) { + for (ma = main->mat.first, a = 0; ma; ma = ma->id.next, a++) { if (ma->id.lib) continue; /* disputed material */ if (ma->game.flag == MAT_BGE_DISPUTED) { ma->game.flag = 0; if (fileload) { - printf("Warning: material \"%s\" skipped - to convert old game texface to material go to the Help menu.\n", ma->id.name+2); + printf("Warning: material \"%s\" skipped - to convert old game texface to material go to the Help menu.\n", ma->id.name + 2); nowarning = 0; } else @@ -1947,24 +1947,24 @@ 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++) + for (a = 0; a < me->totcol; a++) if (me->mat[a] == ma) break; /* no material found */ if (a == me->totcol) continue; /* get the active tface layer */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; 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++) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { if (me->mat[mf->mat_nr] == ma) { /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; + tf = ((MTFace *)cdl->data) + a; tf->mode |= TF_CONVERTED; } } |