[Bf-blender-cvs] [ab993e3] master: Rework/split test_object_materials().

Bastien Montagne noreply at git.blender.org
Fri Jul 8 18:20:01 CEST 2016


Commit: ab993e373cf31c1790f7283b52bbd29b4849fbe7
Author: Bastien Montagne
Date:   Fri Jul 8 14:36:25 2016 +0200
Branches: master
https://developer.blender.org/rBab993e373cf31c1790f7283b52bbd29b4849fbe7

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!

===================================================================

M	source/blender/blenkernel/BKE_material.h
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/editors/mesh/meshtools.c
M	source/blender/editors/object/object_relations.c
M	source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
M	source/blender/makesrna/intern/rna_main_api.c
M	source/blender/makesrna/intern/rna_object.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index 852564c..d79214f 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 7231620..5e1dc66 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 129f89c..6eaa886 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;
 }
diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c
index 123f701..05145f7 100644
--- a/source/blender/editors/mesh/meshtools.c
+++ b/source/blender/editors/mesh/meshtools.c
@@ -540,7 +540,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
 	if (matmap) MEM_freeN(matmap);
 	
 	/* other mesh users */
-	test_object_materials(bmain, (ID *)me);
+	test_all_objects_materials(bmain, (ID *)me);
 	
 	/* free temp copy of destination shapekeys (if applicable) */
 	if (nkey) {
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 9a6fe5a..af1c840 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -1564,7 +1564,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
 						ob_dst->data = obdata_id;
 
 						/* if amount of material indices changed: */
-						test_object_materials(bmain, ob_dst->data);
+						test_object_materials(ob_dst, ob_dst->data);
 
 						DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
 						break;
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
index 5c361de..f63cf77 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
@@ -907,7 +907,7 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
 		material_index++;
 	} // loop over strokes
 
-	test_object_materials(freestyle_bmain, (ID *)mesh);
+	test_object_materials(object_mesh, (ID *)mesh);
 
 #if 0 // XXX
 	BLI_assert(mesh->totvert == vertex_index);
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 334ba06..0083207 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -227,7 +227,7 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char
 	id_us_min(&ob->id);
 
 	ob->data = data;
-	test_object_materials(bmain, ob->data);
+	test_object_materials(ob, ob->data);
 
 	return ob;
 }
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 5dc4bbd..f156252 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -398,7 +398,7 @@ static void rna_Object_data_set(PointerRNA *ptr, PointerRNA value)
 		id_us_plus(id);
 
 		ob->data = id;
-		test_object_materials(G.main, id);
+		test_object_materials(ob, id);
 
 		if (GS(id->name) == ID_CU)
 			BKE_curve_type_test(ob);




More information about the Bf-blender-cvs mailing list