diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-08 15:36:25 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-08 19:11:20 +0300 |
commit | ab993e373cf31c1790f7283b52bbd29b4849fbe7 (patch) | |
tree | a4bfc1772f30985fb9aecef5b0b2b965cbffaad2 /source/blender/blenkernel | |
parent | 71f5df9f44dd6dfd125d6ea7f7f6542e6f9e7faa (diff) |
Rework/split test_object_materials().
Now test_object_materials only handles one object. New test_all_objects_materials
checks the whole bmain->object list for cases where it is actually needed.
Should avoid some useless looping over all objects!
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_material.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 24 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 6 |
3 files changed, 23 insertions, 10 deletions
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 852564c8d90..d79214f3076 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -47,7 +47,8 @@ struct Scene; void init_def_material(void); void BKE_material_free(struct Material *ma); void BKE_material_free_ex(struct Material *ma, bool do_id_user); -void test_object_materials(struct Main *bmain, struct ID *id); +void test_object_materials(struct Object *ob, struct ID *id); +void test_all_objects_materials(struct Main *bmain, struct ID *id); void BKE_material_resize_object(struct Object *ob, const short totcol, bool do_id_user); void BKE_material_init(struct Material *ma); void BKE_material_remap_object(struct Object *ob, const unsigned int *remap); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 7231620550e..5e1dc66d859 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -611,7 +611,7 @@ void BKE_material_append_id(ID *id, Material *ma) (*matar)[(*totcol)++] = ma; id_us_plus((ID *)ma); - test_object_materials(G.main, id); + test_all_objects_materials(G.main, id); } } @@ -637,7 +637,7 @@ Material *BKE_material_pop_id(ID *id, int index_i, bool update_data) (*totcol)--; *matar = MEM_reallocN(*matar, sizeof(void *) * (*totcol)); - test_object_materials(G.main, id); + test_all_objects_materials(G.main, id); } if (update_data) { @@ -776,7 +776,19 @@ void BKE_material_resize_object(Object *ob, const short totcol, bool do_id_user) if (ob->actcol > ob->totcol) ob->actcol = ob->totcol; } -void test_object_materials(Main *bmain, ID *id) +void test_object_materials(Object *ob, ID *id) +{ + /* make the ob mat-array same size as 'ob->data' mat-array */ + const short *totcol; + + if (id == NULL || (totcol = give_totcolp_id(id)) == NULL) { + return; + } + + BKE_material_resize_object(ob, *totcol, false); +} + +void test_all_objects_materials(Main *bmain, ID *id) { /* make the ob mat-array same size as 'ob->data' mat-array */ Object *ob; @@ -787,7 +799,7 @@ void test_object_materials(Main *bmain, ID *id) } BKE_main_lock(bmain); - for (ob = bmain->object.first; ob; ob = ob->id.next) { + for (bmain = bmain->object.first; ob; ob = ob->id.next) { if (ob->data == id) { BKE_material_resize_object(ob, *totcol, false); } @@ -839,7 +851,7 @@ void assign_material_id(ID *id, Material *ma, short act) if (ma) id_us_plus(&ma->id); - test_object_materials(G.main, id); + test_all_objects_materials(G.main, id); } void assign_material(Object *ob, Material *ma, short act, int assign_type) @@ -924,7 +936,7 @@ void assign_material(Object *ob, Material *ma, short act, int assign_type) if (ma) id_us_plus(&ma->id); - test_object_materials(G.main, ob->data); + test_object_materials(ob, ob->data); } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 129f89c2b8e..6eaa8863172 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1010,7 +1010,7 @@ void BKE_mesh_assign_object(Object *ob, Mesh *me) id_us_plus((ID *)me); } - test_object_materials(G.main, (ID *)me); + test_object_materials(ob, (ID *)me); test_object_modifiers(ob); } @@ -2518,8 +2518,8 @@ Mesh *BKE_mesh_new_from_object( BKE_mesh_tessface_ensure(tmpmesh); } - /* make sure materials get updated in objects */ - test_object_materials(bmain, &tmpmesh->id); + /* make sure materials get updated in object */ + test_object_materials(tmpobj ? tmpobj : ob, &tmpmesh->id); return tmpmesh; } |