Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/material.c
| Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_array_utils.h" | |||||
| #include "BKE_animsys.h" | #include "BKE_animsys.h" | ||||
| #include "BKE_displist.h" | #include "BKE_displist.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_icons.h" | #include "BKE_icons.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_editmesh.h" | |||||
| #include "BKE_font.h" | |||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| /* used in UI and render */ | /* used in UI and render */ | ||||
| Material defmaterial; | Material defmaterial; | ||||
| /* called on startup, creator.c */ | /* called on startup, creator.c */ | ||||
| void init_def_material(void) | void init_def_material(void) | ||||
| ▲ Show 20 Lines • Show All 840 Lines • ▼ Show 20 Lines | else { /* in data */ | ||||
| (*matarar)[act - 1] = ma; | (*matarar)[act - 1] = ma; | ||||
| } | } | ||||
| if (ma) | if (ma) | ||||
| id_us_plus((ID *)ma); | id_us_plus((ID *)ma); | ||||
| test_object_materials(G.main, ob->data); | test_object_materials(G.main, ob->data); | ||||
| } | } | ||||
| void BKE_material_id_remap(Object *ob, unsigned int remap[]) | |||||
| { | |||||
| short mat_nr_max = ob->totcol; | |||||
| BLI_array_permute(ob->mat, ob->totcol, remap); | |||||
| if (ob->matbits) | |||||
| BLI_array_permute(ob->matbits, ob->totcol, remap); | |||||
| Material ***matarrar = give_matarar(ob); | |||||
| if(matarrar) | |||||
| BLI_array_permute(*matarrar, ob->totcol, remap); | |||||
campbellbarton: think it would be better to get the array from `give_matarar`, then this can be done at the… | |||||
| /* Now reassign the new material order to the affected items in the object*/ | |||||
| if (ob->type == OB_MESH) { | |||||
| if (ob->mode == OB_MODE_EDIT) { | |||||
| BMEditMesh *em = BKE_editmesh_from_object(ob); | |||||
| BMFace *efa; | |||||
| BMIter iter; | |||||
| if (em) { | |||||
| BM_ITER_MESH(efa, &iter, em->bm, BM_FACES_OF_MESH) { | |||||
| if (remap[efa->mat_nr] < mat_nr_max) | |||||
| efa->mat_nr = remap[efa->mat_nr]; | |||||
| } | |||||
| } | |||||
| } | |||||
| else { | |||||
| Mesh *me = ob->data; | |||||
| for (int index = 0; index < me->totpoly; index++) | |||||
| if (remap[me->mpoly[index].mat_nr] < mat_nr_max) | |||||
| me->mpoly[index].mat_nr = remap[me->mpoly[index].mat_nr]; | |||||
| } | |||||
| } | |||||
| else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { | |||||
| Nurb *nu; | |||||
| ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data); | |||||
| if (nurbs) { | |||||
| for (nu = nurbs->first; nu; nu = nu->next) | |||||
| if (remap[nu->charidx] < mat_nr_max) | |||||
| nu->mat_nr = remap[nu->charidx]; | |||||
| } | |||||
| } | |||||
| else if (ob->type == OB_FONT) { | |||||
| EditFont *ef = ((Curve *)ob->data)->editfont; | |||||
Not Done Inline Actionsmaterial arrays are ignored here, using give_matarar at the beginning will resolve. campbellbarton: material arrays are ignored here, using `give_matarar` at the beginning will resolve. | |||||
| if (ef) { | |||||
Not Done Inline Actionsall of these mat_nr accesses need bounds checks, its possible they are larger then the array. campbellbarton: all of these `mat_nr` accesses need bounds checks, its possible they are larger then the array. | |||||
| for (int i = 0; i <= ef->len; i++) | |||||
| if (remap[ef->textbufinfo[i].mat_nr] < mat_nr_max) | |||||
| ef->textbufinfo[i].mat_nr = remap[ef->textbufinfo[i].mat_nr]; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* XXX - this calls many more update calls per object then are needed, could be optimized */ | /* 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) | void assign_matarar(struct Object *ob, struct Material ***matar, short totcol) | ||||
| { | { | ||||
| int actcol_orig = ob->actcol; | int actcol_orig = ob->actcol; | ||||
| short i; | short i; | ||||
| while (object_remove_material_slot(ob)) {} | while (object_remove_material_slot(ob)) {} | ||||
| Show All 23 Lines | short find_material_index(Object *ob, Material *ma) | ||||
| for (a = 0; a < *totcolp; a++) | for (a = 0; a < *totcolp; a++) | ||||
| if ((*matarar)[a] == ma) | if ((*matarar)[a] == ma) | ||||
| break; | break; | ||||
| if (a < *totcolp) | if (a < *totcolp) | ||||
| return a + 1; | return a + 1; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| bool object_add_material_slot(Object *ob) | bool object_add_material_slot(Object *ob) | ||||
Not Done Inline Actions@ideasman42: I am not entirely sure about this part. Maybe its wrong to use BKE_vfont_select_get() in this context? gaiaclary: @ideasman42: I am not entirely sure about this part. Maybe its wrong to use… | |||||
| { | { | ||||
| if (ob == NULL) return false; | if (ob == NULL) return false; | ||||
| if (ob->totcol >= MAXMAT) return false; | if (ob->totcol >= MAXMAT) return false; | ||||
Not Done Inline Actionschecking selection is incorrect here, it should remap all. campbellbarton: checking selection is incorrect here, it should remap all. | |||||
| assign_material(ob, NULL, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF); | assign_material(ob, NULL, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF); | ||||
| ob->actcol = ob->totcol; | ob->actcol = ob->totcol; | ||||
| return true; | return true; | ||||
| } | } | ||||
| static void do_init_render_material(Material *ma, int r_mode, float *amb) | static void do_init_render_material(Material *ma, int r_mode, float *amb) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 1,325 Lines • Show Last 20 Lines | |||||
think it would be better to get the array from give_matarar, then this can be done at the start along with matbits.