diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2018-06-19 09:08:19 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2018-06-19 09:08:19 +0300 |
commit | c307b13be1c0f9bbf53fe80db28af1a30a821a68 (patch) | |
tree | 5df3ffc0176b777fb8ede93e7120443efba0152e /source/blender/blenkernel/intern/material.c | |
parent | 446cc6f3b6dac654b0730f74ea42b831ae9ac4e9 (diff) | |
parent | a927dbd17a83d64e97461851f390f55cb38b43d4 (diff) |
Merge branch 'hair_guides' into hair_guides_grooming
Diffstat (limited to 'source/blender/blenkernel/intern/material.c')
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 463bfe1a8bc..0b9afa5747f 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -50,8 +50,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" @@ -91,10 +91,10 @@ void init_def_material(void) void BKE_material_free(Material *ma) { BKE_animdata_free((ID *)ma, false); - + /* Free gpu material before the ntree */ GPU_material_free(&ma->gpumaterial); - + /* is no lib link block, but material extension */ if (ma->nodetree) { ntreeFreeTree(ma->nodetree); @@ -118,7 +118,7 @@ void BKE_material_init(Material *ma) ma->spec = 0.5; ma->roughness = 0.25f; - + ma->pr_lamp = 3; /* two lamps, is bits */ ma->pr_type = MA_SPHERE; @@ -132,9 +132,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; } @@ -219,7 +219,7 @@ Material ***give_matarar(Object *ob) Mesh *me; Curve *cu; MetaBall *mb; - + if (ob->type == OB_MESH) { me = ob->data; return &(me->mat); @@ -244,7 +244,7 @@ short *give_totcolp(Object *ob) Mesh *me; Curve *cu; MetaBall *mb; - + if (ob->type == OB_MESH) { me = ob->data; return &(me->totcol); @@ -426,7 +426,7 @@ Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i, bool update_data DEG_relations_tag_update(bmain); } } - + return ret; } @@ -460,7 +460,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; @@ -486,12 +486,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; } @@ -634,18 +634,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"); @@ -689,7 +689,7 @@ void assign_material(Main *bmain, Object *ob, Material *ma, short act, int assig break; } } - + /* do it */ ob->matbits[act - 1] = bit; @@ -824,14 +824,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; @@ -844,7 +844,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; @@ -857,7 +857,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; } @@ -871,10 +871,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); @@ -886,21 +886,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) { @@ -913,14 +913,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); @@ -945,7 +945,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; @@ -957,7 +957,7 @@ static bNode *nodetree_uv_node_recursive(bNode *node) } } } - + return NULL; } @@ -980,7 +980,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) ma->paint_clone_slot = 0; return; } - + bNode *node, *active_node; if (!(ma->nodetree)) { @@ -1008,10 +1008,10 @@ 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 */ bNode *uvnode = nodetree_uv_node_recursive(node); - + if (uvnode) { NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage; ma->texpaintslot[index].uvname = storage->uv_map; @@ -1027,8 +1027,8 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) } ma->tot_slots = count; - - + + if (ma->paint_active_slot >= count) { ma->paint_active_slot = count - 1; } @@ -1055,7 +1055,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]; |