diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-06-17 18:05:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-06-17 18:05:51 +0300 |
commit | 6fc8a74886a30f89562bb542ef3b24cc64b3208a (patch) | |
tree | df0503b6cf4f6b762eca66b90f4360c495d624aa /source/blender/blenkernel/intern/material.c | |
parent | a262ea8c47f8106f66e16935c556f383ef306861 (diff) |
Cleanup: trailing space for blenkernel
Diffstat (limited to 'source/blender/blenkernel/intern/material.c')
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 3283619587e..74866fd1d94 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -49,8 +49,8 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "BLI_math.h" -#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_listbase.h" #include "BLI_utildefines.h" #include "BLI_string.h" #include "BLI_array_utils.h" @@ -90,14 +90,14 @@ void BKE_material_free(Material *ma) int a; BKE_animdata_free((ID *)ma, false); - + for (a = 0; a < MAX_MTEX; a++) { MEM_SAFE_FREE(ma->mtex[a]); } - + MEM_SAFE_FREE(ma->ramp_col); MEM_SAFE_FREE(ma->ramp_spec); - + /* is no lib link block, but material extension */ if (ma->nodetree) { ntreeFreeTree(ma->nodetree); @@ -154,13 +154,13 @@ void BKE_material_init(Material *ma) ma->tx_falloff = 1.0; ma->shad_alpha = 1.0f; ma->vcol_alpha = 0; - + 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 */ @@ -197,11 +197,11 @@ void BKE_material_init(Material *ma) ma->vol.ms_spread = 0.2f; ma->vol.ms_diff = 1.f; ma->vol.ms_intensity = 1.f; - + ma->game.flag = GEMAT_BACKCULL; 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->mode2 = MA_CASTSHADOW; ma->shade_flag = MA_APPROX_OCCLUSION; @@ -213,9 +213,9 @@ Material *BKE_material_add(Main *bmain, const char *name) Material *ma; ma = BKE_libblock_alloc(bmain, ID_MA, name, 0); - + BKE_material_init(ma); - + return ma; } @@ -282,7 +282,7 @@ Material *BKE_material_localize(Material *ma) Material *man; int a; - + man = BKE_libblock_copy_nolib(&ma->id, false); /* no increment for texture ID users, in previewrender.c it prevents decrement */ @@ -292,18 +292,18 @@ Material *BKE_material_localize(Material *ma) 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); man->texpaintslot = NULL; man->preview = NULL; - + if (ma->nodetree) man->nodetree = ntreeLocalize(ma->nodetree); - + BLI_listbase_clear(&man->gpumaterial); - + return man; } @@ -317,7 +317,7 @@ Material ***give_matarar(Object *ob) Mesh *me; Curve *cu; MetaBall *mb; - + if (ob->type == OB_MESH) { me = ob->data; return &(me->mat); @@ -338,7 +338,7 @@ short *give_totcolp(Object *ob) Mesh *me; Curve *cu; MetaBall *mb; - + if (ob->type == OB_MESH) { me = ob->data; return &(me->totcol); @@ -512,7 +512,7 @@ Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i, bool update_data DAG_relations_tag_update(bmain); } } - + return ret; } @@ -546,7 +546,7 @@ Material *give_current_material(Object *ob, short act) const short *totcolp; if (ob == NULL) return NULL; - + /* if object cannot have material, (totcolp == NULL) */ totcolp = give_totcolp(ob); if (totcolp == NULL || ob->totcol == 0) return NULL; @@ -572,12 +572,12 @@ Material *give_current_material(Object *ob, short act) if (act > ob->totcol) act = ob->totcol; matarar = give_matarar(ob); - + if (matarar && *matarar) ma = (*matarar)[act - 1]; else ma = NULL; - + } - + return ma; } @@ -720,18 +720,18 @@ void assign_material(Main *bmain, Object *ob, Material *ma, short act, int assig if (act > MAXMAT) return; if (act < 1) act = 1; - + /* prevent crashing when using accidentally */ BLI_assert(!ID_IS_LINKED(ob)); if (ID_IS_LINKED(ob)) return; - + /* test arraylens */ - + totcolp = give_totcolp(ob); matarar = give_matarar(ob); - + if (totcolp == NULL || matarar == NULL) return; - + if (act > *totcolp) { matar = MEM_callocN(sizeof(void *) * act, "matarray1"); @@ -775,7 +775,7 @@ void assign_material(Main *bmain, Object *ob, Material *ma, short act, int assig break; } } - + /* do it */ ob->matbits[act - 1] = bit; @@ -910,14 +910,14 @@ short BKE_object_material_slot_find_index(Object *ob, Material *ma) { Material ***matarar; short a, *totcolp; - + if (ma == NULL) return 0; - + totcolp = give_totcolp(ob); matarar = give_matarar(ob); - + if (totcolp == NULL || matarar == NULL) return 0; - + for (a = 0; a < *totcolp; a++) if ((*matarar)[a] == ma) break; @@ -930,7 +930,7 @@ bool BKE_object_material_slot_add(Main *bmain, Object *ob) { if (ob == NULL) return false; if (ob->totcol >= MAXMAT) return false; - + assign_material(bmain, ob, NULL, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF); ob->actcol = ob->totcol; return true; @@ -940,25 +940,25 @@ static void do_init_render_material(Main *bmain, Material *ma, int r_mode, float { MTex *mtex; int a, needuv = 0, needtang = 0; - + 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++) { - + /* separate tex switching */ if (ma->septex & (1 << a)) continue; mtex = ma->mtex[a]; 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 (ELEM(mtex->tex->type, TEX_IMAGE, 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; - + 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)) needuv = 1; @@ -970,13 +970,13 @@ static void do_init_render_material(Main *bmain, Material *ma, int r_mode, float 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 (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))) { @@ -984,7 +984,7 @@ static void do_init_render_material(Main *bmain, Material *ma, int r_mode, float if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; } } - + if (amb) { ma->ambr = ma->amb * amb[0]; ma->ambg = ma->amb * amb[1]; @@ -1050,9 +1050,9 @@ static void init_render_nodetree(Main *bmain, bNodeTree *ntree, Material *basema void init_render_material(Main *bmain, Material *mat, int r_mode, float *amb) { - + do_init_render_material(bmain, mat, r_mode, amb); - + if (mat->nodetree && mat->use_nodes) { /* mode_l will take the pipeline options from the main material, and the or-ed * result of non-pipeline options from the nodes. shadeless is an exception, @@ -1061,7 +1061,7 @@ void init_render_material(Main *bmain, Material *mat, int r_mode, float *amb) mat->mode2_l = mat->mode2 & MA_MODE2_PIPELINE; mat->nmap_tangent_names_count = 0; init_render_nodetree(bmain, mat->nodetree, mat, r_mode, amb); - + if (!mat->nodetree->execdata) mat->nodetree->execdata = ntreeShaderBeginExecTree(mat->nodetree); } @@ -1077,7 +1077,7 @@ void init_render_material(Main *bmain, Material *mat, int r_mode, float *amb) void init_render_materials(Main *bmain, int r_mode, float *amb, bool do_default_material) { Material *ma; - + /* 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 */ @@ -1092,7 +1092,7 @@ void init_render_materials(Main *bmain, int r_mode, float *amb, bool do_default_ 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(bmain, ma, r_mode, amb); } @@ -1114,7 +1114,7 @@ void end_render_materials(Main *bmain) { Material *ma; for (ma = bmain->mat.first; ma; ma = ma->id.next) - if (ma->id.us) + if (ma->id.us) end_render_material(ma); } @@ -1162,7 +1162,7 @@ static void material_node_drivers_update(Scene *scene, bNodeTree *ntree, float c if (ntree->adt && ntree->adt->drivers.first) { BKE_animsys_evaluate_animdata(scene, &ntree->id, ntree->adt, ctime, ADT_RECALC_DRIVERS); } - + /* nodes */ for (node = ntree->nodes.first; node; node = node->next) { if (node->id) { @@ -1176,7 +1176,7 @@ static void material_node_drivers_update(Scene *scene, bNodeTree *ntree, float c } } -/* Calculate all drivers for materials +/* Calculate all drivers for materials * FIXME: this is really a terrible method which may result in some things being calculated * multiple times. However, without proper despgraph support for these things, we are forced * into this sort of thing... @@ -1185,7 +1185,7 @@ void material_drivers_update(Scene *scene, Material *ma, float ctime) { //if (G.f & G_DEBUG) // printf("material_drivers_update(%s, %s)\n", scene->id.name, ma->id.name); - + /* Prevent infinite recursion by checking (and tagging the material) as having been visited already * (see BKE_scene_update_tagged()). This assumes ma->id.tag & LIB_TAG_DOIT isn't set by anything else * in the meantime... [#32017] @@ -1194,12 +1194,12 @@ void material_drivers_update(Scene *scene, Material *ma, float ctime) return; ma->id.tag |= LIB_TAG_DOIT; - + /* material itself */ if (ma->adt && ma->adt->drivers.first) { BKE_animsys_evaluate_animdata(scene, &ma->id, ma->adt, ctime, ADT_RECALC_DRIVERS); } - + /* nodes */ if (ma->nodetree) { material_node_drivers_update(scene, ma->nodetree, ctime); @@ -1213,7 +1213,7 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob) Material *mao, ***matarar; short *totcolp; short a, actcol; - + if (ob == NULL || ob->totcol == 0) { return false; } @@ -1227,10 +1227,10 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob) /* take a mesh/curve/mball as starting point, remove 1 index, * AND with all objects that share the ob->data - * + * * after that check indices in mesh/curve/mball!!! */ - + totcolp = give_totcolp(ob); matarar = give_matarar(ob); @@ -1242,21 +1242,21 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob) if (ob->actcol > ob->totcol) { ob->actcol = ob->totcol; } - + /* we delete the actcol */ mao = (*matarar)[ob->actcol - 1]; if (mao) id_us_min(&mao->id); - + for (a = ob->actcol; a < ob->totcol; a++) (*matarar)[a - 1] = (*matarar)[a]; (*totcolp)--; - + if (*totcolp == 0) { MEM_freeN(*matarar); *matarar = NULL; } - + actcol = ob->actcol; for (Object *obt = bmain->object.first; obt; obt = obt->id.next) { @@ -1269,14 +1269,14 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob) mao = obt->mat[actcol - 1]; if (mao) id_us_min(&mao->id); - + 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->totcol == 0) { MEM_freeN(obt->mat); MEM_freeN(obt->matbits); @@ -1308,7 +1308,7 @@ static bNode *nodetree_uv_node_recursive(bNode *node) { bNode *inode; bNodeSocket *sock; - + for (sock = node->inputs.first; sock; sock = sock->next) { if (sock->link) { inode = sock->link->fromnode; @@ -1320,7 +1320,7 @@ static bNode *nodetree_uv_node_recursive(bNode *node) } } } - + return NULL; } @@ -1332,7 +1332,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) bool use_nodes = BKE_scene_use_new_shading_nodes(scene); bool is_bi = BKE_scene_uses_blender_internal(scene) || BKE_scene_uses_blender_game(scene); - + if (!ma) return; @@ -1347,7 +1347,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) ma->paint_clone_slot = 0; return; } - + if (use_nodes || ma->use_nodes) { bNode *node, *active_node; @@ -1376,11 +1376,11 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) if (active_node == node) ma->paint_active_slot = index; ma->texpaintslot[index].ima = (Image *)node->id; - + /* for new renderer, we need to traverse the treeback in search of a UV node */ if (use_nodes) { bNode *uvnode = nodetree_uv_node_recursive(node); - + if (uvnode) { NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage; ma->texpaintslot[index].uvname = storage->uv_map; @@ -1419,7 +1419,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) ma->texpaintslot[index].ima = (*mtex)->tex->ima; ma->texpaintslot[index].uvname = (*mtex)->uvname; ma->texpaintslot[index].index = i; - + index++; } } @@ -1428,12 +1428,12 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) ma->paint_active_slot = 0; ma->paint_clone_slot = 0; return; - } + } ma->tot_slots = count; - - + + if (ma->paint_active_slot >= count) { ma->paint_active_slot = count - 1; } @@ -1460,7 +1460,7 @@ void BKE_texpaint_slots_refresh_object(Scene *scene, struct Object *ob) void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) { float tmp, facm = 1.0f - fac; - + switch (type) { case MA_RAMP_BLEND: r_col[0] = facm * (r_col[0]) + fac * col[0]; @@ -1806,10 +1806,10 @@ static int encode_tfaceflag(MTFace *tf, int convertall) /* light tface flag is ignored in GLSL mode */ flag &= ~TF_LIGHT; - + /* 15 is how big the flag can be - hardcoded here and in decode_tfaceflag() */ flag |= tf->transp << 15; - + /* increase 1 so flag 0 is different than no flag yet */ return flag + 1; } @@ -1825,25 +1825,25 @@ static void decode_tfaceflag(Material *ma, int flag, int convertall) alphablend = flag >> 15; /* encoded in the encode_tfaceflag function */ (*game).flag = 0; - + /* General Material Options */ if ((flag & TF_DYNAMIC) == 0) (*game).flag |= GEMAT_NOPHYSICS; - + /* Material Offline Rendering Properties */ if (convertall) { if (flag & TF_OBCOL) ma->shade_flag |= MA_OBCOLOR; } - + /* Special Face Properties */ 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 */ if (flag & TF_BILLBOARD) (*game).face_orientation |= GEMAT_HALO; else if (flag & TF_BILLBOARD2) (*game).face_orientation |= GEMAT_BILLBOARD; else if (flag & TF_SHADOW) (*game).face_orientation |= GEMAT_SHADOW; - + /* Alpha Blend */ if (flag & TF_ALPHASORT && ELEM(alphablend, TF_ALPHA, TF_ADD)) (*game).alpha_blend = GEMAT_ALPHA_SORT; else if (alphablend & TF_ALPHA) (*game).alpha_blend = GEMAT_ALPHA; @@ -1867,7 +1867,7 @@ static int check_tfaceneedmaterial(int flag) /* light tface flag is ignored in GLSL mode */ flag &= ~TF_LIGHT; - + /* automatic detected if tex image has alpha */ flag &= ~(TF_ALPHA << 15); /* automatic detected if using texture */ @@ -1948,7 +1948,7 @@ static short convert_tfacenomaterial(Main *bmain, Mesh *me, MTFace *tf, int flag Material *ma; char idname[MAX_ID_NAME]; short mat_nr = -1; - + /* new material, the name uses the flag*/ BLI_snprintf(idname, sizeof(idname), "MAMaterial.TF.%0*d", integer_getdigits(flag), flag); @@ -1967,7 +1967,7 @@ static short convert_tfacenomaterial(Main *bmain, Mesh *me, MTFace *tf, int flag if (ma) { printf("TexFace Convert: Material \"%s\" created.\n", idname + 2); mat_nr = mesh_addmaterial(bmain, me, ma); - + /* if needed set "Face Textures [Alpha]" Material options */ set_facetexture_flags(ma, tf->tpage); @@ -2005,7 +2005,7 @@ static void convert_tfacematerial(Main *bmain, Material *ma) /* check if this mesh uses this material */ for (a = 0; a < me->totcol; a++) if (me->mat[a] == ma) break; - + /* no material found */ if (a == me->totcol) continue; @@ -2048,9 +2048,9 @@ static void convert_tfacematerial(Main *bmain, Material *ma) continue; } } - + /* if the material has a texture but no texture channel - * set "Face Textures [Alpha]" Material options + * 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)) @@ -2084,7 +2084,7 @@ int do_version_tface(Main *main) int a; int flag; int index; - + /* Operator in help menu has been removed for 2.7x */ int fileload = 1; @@ -2100,9 +2100,9 @@ int do_version_tface(Main *main) /* mark all the materials to conversion with a flag * if there is tface create a complete flag for that storing in flag * if there is tface and flag > 0: creates a new flag based on this face - * if flags are different set flag to -1 + * if flags are different set flag to -1 */ - + /* 1st part: marking mesh materials to update */ for (me = main->mesh.first; me; me = me->id.next) { if (ID_IS_LINKED(me)) continue; @@ -2113,7 +2113,7 @@ int do_version_tface(Main *main) if (!cdl) continue; nomaterialslots = (me->totcol == 0 ? 1 : 0); - + /* loop over all the faces*/ for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { /* texface data for this face */ @@ -2126,11 +2126,11 @@ int do_version_tface(Main *main) if ((tf->mode & TF_CONVERTED)) continue; else tf->mode |= TF_CONVERTED; } - + /* no material slots */ if (nomaterialslots) { flag = encode_tfaceflag(tf, 1); - + /* create/find a new material and assign to the face */ if (check_tfaceneedmaterial(flag)) { mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag); @@ -2142,7 +2142,7 @@ int do_version_tface(Main *main) } else if (mf->mat_nr < me->totcol) { ma = me->mat[mf->mat_nr]; - + /* no material create one if necessary */ if (!ma) { /* find a new material and assign to the face */ @@ -2161,7 +2161,7 @@ int do_version_tface(Main *main) * later we could, but it's better not */ else if (ID_IS_LINKED(ma)) continue; - + /* material already marked as disputed */ else if (ma->game.flag == MAT_BGE_DISPUTED) continue; @@ -2173,17 +2173,17 @@ int do_version_tface(Main *main) /* first time changing this material */ if (ma->game.flag == 0) ma->game.flag = -flag; - + /* mark material as disputed */ else if (ma->game.flag != -flag) { ma->game.flag = MAT_BGE_DISPUTED; continue; } - + /* material ok so far */ else { ma->game.flag = -flag; - + /* some people uses multitexture with TexFace by creating a texture * channel which not necessarily the tf->tpage image. But the game engine * was enabling it. Now it's required to set "Face Texture [Alpha] in the @@ -2218,7 +2218,7 @@ int do_version_tface(Main *main) } } - + /* 2nd part - conversion */ /* skip library files */ @@ -2238,7 +2238,7 @@ int do_version_tface(Main *main) } continue; } - + /* no conflicts in this material - 90% of cases * convert from tface system to material */ else if (ma->game.flag < 0) { @@ -2251,15 +2251,15 @@ int do_version_tface(Main *main) /* check if this mesh uses this material */ 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]; if (!cdl) continue; - + /* loop over all the faces and stop at the ones that use the material*/ for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { if (me->mat[mf->mat_nr] == ma) { |