Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/material.c
| Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_build.h" | #include "DEG_depsgraph_build.h" | ||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| /* used in UI and render */ | /* used in UI and render */ | ||||
| Material defmaterial; | Material defmaterial; | ||||
| Material defgpencil_material; | |||||
| static CLG_LogRef LOG = {"bke.material"}; | static CLG_LogRef LOG = {"bke.material"}; | ||||
| /* called on startup, creator.c */ | /* called on startup, creator.c */ | ||||
| void init_def_material(void) | void init_def_material(void) | ||||
| { | { | ||||
| BKE_material_init(&defmaterial); | BKE_material_init(&defmaterial); | ||||
| BKE_material_gpencil_init(&defgpencil_material); | |||||
| } | |||||
| /* Free the GPencil data of the deafult material, creator.c */ | |||||
| void BKE_material_gpencil_default_free(void) | |||||
| { | |||||
| MEM_SAFE_FREE(defgpencil_material.gp_style); | |||||
| } | } | ||||
| /** Free (or release) any data used by this material (does not free the material itself). */ | /** Free (or release) any data used by this material (does not free the material itself). */ | ||||
| void BKE_material_free(Material *ma) | void BKE_material_free(Material *ma) | ||||
| { | { | ||||
| BKE_animdata_free((ID *)ma, false); | BKE_animdata_free((ID *)ma, false); | ||||
| /* Free gpu material before the ntree */ | /* Free gpu material before the ntree */ | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | void BKE_material_init(Material *ma) | ||||
| ma->preview = NULL; | ma->preview = NULL; | ||||
| ma->alpha_threshold = 0.5f; | ma->alpha_threshold = 0.5f; | ||||
| ma->blend_shadow = MA_BS_SOLID; | ma->blend_shadow = MA_BS_SOLID; | ||||
| } | } | ||||
| void BKE_material_gpencil_init(Material *ma) | |||||
| { | |||||
| BKE_material_init(ma); | |||||
| /* grease pencil settings */ | |||||
| strcpy(ma->id.name, "MADefault GPencil"); | |||||
| BKE_material_init_gpencil_settings(ma); | |||||
| ma->gp_style->stroke_rgba[0] = 0.8f; | |||||
| ma->gp_style->stroke_rgba[2] = 0.8f; | |||||
| } | |||||
| Material *BKE_material_add(Main *bmain, const char *name) | Material *BKE_material_add(Main *bmain, const char *name) | ||||
| { | { | ||||
| Material *ma; | Material *ma; | ||||
| ma = BKE_libblock_alloc(bmain, ID_MA, name, 0); | ma = BKE_libblock_alloc(bmain, ID_MA, name, 0); | ||||
| BKE_material_init(ma); | BKE_material_init(ma); | ||||
| ▲ Show 20 Lines • Show All 420 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| Material *give_current_material(Object *ob, short act) | Material *give_current_material(Object *ob, short act) | ||||
| { | { | ||||
| Material **ma_p = give_current_material_p(ob, act); | Material **ma_p = give_current_material_p(ob, act); | ||||
| return ma_p ? *ma_p : NULL; | return ma_p ? *ma_p : NULL; | ||||
| } | } | ||||
| Material *BKE_material_gpencil_get(Object *ob, short act) | |||||
| { | |||||
| Material *ma = give_current_material(ob, act); | |||||
| if (ma != NULL) { | |||||
| return ma; | |||||
| } | |||||
| else { | |||||
| return &defgpencil_material; | |||||
| } | |||||
| } | |||||
| MaterialGPencilStyle *BKE_material_gpencil_settings_get(Object *ob, short act) | MaterialGPencilStyle *BKE_material_gpencil_settings_get(Object *ob, short act) | ||||
| { | { | ||||
| Material *ma = give_current_material(ob, act); | Material *ma = give_current_material(ob, act); | ||||
| if (ma != NULL) { | if (ma != NULL) { | ||||
| if (ma->gp_style == NULL) { | if (ma->gp_style == NULL) { | ||||
| BKE_material_init_gpencil_settings(ma); | BKE_material_init_gpencil_settings(ma); | ||||
| } | } | ||||
| return ma->gp_style; | return ma->gp_style; | ||||
| } | } | ||||
| else { | else { | ||||
| return NULL; | return defgpencil_material.gp_style; | ||||
| } | } | ||||
| } | } | ||||
| Material *give_node_material(Material *ma) | 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); | bNode *node = nodeGetActiveID(ma->nodetree, ID_MA); | ||||
| ▲ Show 20 Lines • Show All 464 Lines • ▼ Show 20 Lines | if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) { | ||||
| if (ob->runtime.curve_cache) { | if (ob->runtime.curve_cache) { | ||||
| BKE_displist_free(&ob->runtime.curve_cache->disp); | BKE_displist_free(&ob->runtime.curve_cache->disp); | ||||
| } | } | ||||
| } | } | ||||
| /* check indices from gpencil */ | /* check indices from gpencil */ | ||||
| else if (ob->type == OB_GPENCIL) { | else if (ob->type == OB_GPENCIL) { | ||||
| /* need one color */ | /* need one color */ | ||||
| if (ob->totcol == 0) { | if (ob->totcol == 0) { | ||||
| BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob); | BKE_gpencil_object_material_ensure_from_active_input_material(ob); | ||||
| } | } | ||||
| BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1); | BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| static bNode *nodetree_uv_node_recursive(bNode *node) | static bNode *nodetree_uv_node_recursive(bNode *node) | ||||
| ▲ Show 20 Lines • Show All 520 Lines • Show Last 20 Lines | |||||