[Bf-blender-cvs] [04c7d9d] master: Depsgraph: tag relations for update when aterial slots changes

Sergey Sharybin noreply at git.blender.org
Fri Aug 12 15:01:46 CEST 2016


Commit: 04c7d9d56674f97d14c393488439c93a343823b4
Author: Sergey Sharybin
Date:   Fri Aug 12 14:59:11 2016 +0200
Branches: master
https://developer.blender.org/rB04c7d9d56674f97d14c393488439c93a343823b4

Depsgraph: tag relations for update when aterial slots changes

New dependency graph puts materials to the graph in order to deal with animation
assigned to them and things like that. This leads us to a requirement to update
relations when slots changes.

This fixes: T49075 Assignment of a keyframed material using the frame_change_pre handler
                   doesn't update the keyframe using the new dependency graph

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

M	source/blender/blenkernel/BKE_material.h
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/makesrna/intern/rna_ID.c

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

diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index df73999..8ae5c2b 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -49,7 +49,7 @@ void BKE_material_free(struct Material *ma);
 void BKE_material_free_ex(struct Material *ma, bool do_id_user);
 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_resize_object(struct Main *bmain, 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);
 void BKE_material_remap_object_calc(struct  Object *ob_dst, struct Object *ob_src, short *remap_src_to_dst);
@@ -90,10 +90,10 @@ void BKE_texpaint_slot_refresh_cache(struct Scene *scene, struct Material *ma);
 void BKE_texpaint_slots_refresh_object(struct Scene *scene, struct Object *ob);
 
 /* rna api */
-void BKE_material_resize_id(struct ID *id, short totcol, bool do_id_user);
-void BKE_material_append_id(struct ID *id, struct Material *ma);
-struct Material *BKE_material_pop_id(struct ID *id, int index, bool update_data); /* index is an int because of RNA */
-void BKE_material_clear_id(struct ID *id, bool update_data);
+void BKE_material_resize_id(struct Main *bmain, struct ID *id, short totcol, bool do_id_user);
+void BKE_material_append_id(struct Main *bmain, struct ID *id, struct Material *ma);
+struct Material *BKE_material_pop_id(struct Main *bmain, struct ID *id, int index, bool update_data); /* index is an int because of RNA */
+void BKE_material_clear_id(struct Main *bmain, struct ID *id, bool update_data);
 /* rendering */
 
 void init_render_material(struct Material *, int, float *);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 4701085..5494524 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -58,6 +58,7 @@
 #include "BKE_animsys.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
+#include "BKE_depsgraph.h"
 #include "BKE_icons.h"
 #include "BKE_image.h"
 #include "BKE_library.h"
@@ -398,7 +399,7 @@ static void material_data_index_clear_id(ID *id)
 	}
 }
 
-void BKE_material_resize_id(struct ID *id, short totcol, bool do_id_user)
+void BKE_material_resize_id(Main *bmain, ID *id, short totcol, bool do_id_user)
 {
 	Material ***matar = give_matarar_id(id);
 	short *totcolp = give_totcolp_id(id);
@@ -424,9 +425,11 @@ void BKE_material_resize_id(struct ID *id, short totcol, bool do_id_user)
 		*matar = MEM_recallocN(*matar, sizeof(void *) * totcol);
 	}
 	*totcolp = totcol;
+
+	DAG_relations_tag_update(bmain);
 }
 
-void BKE_material_append_id(ID *id, Material *ma)
+void BKE_material_append_id(Main *bmain, ID *id, Material *ma)
 {
 	Material ***matar;
 	if ((matar = give_matarar_id(id))) {
@@ -439,11 +442,12 @@ void BKE_material_append_id(ID *id, Material *ma)
 		(*matar)[(*totcol)++] = ma;
 
 		id_us_plus((ID *)ma);
-		test_all_objects_materials(G.main, id);
+		test_all_objects_materials(bmain, id);
+		DAG_relations_tag_update(bmain);
 	}
 }
 
-Material *BKE_material_pop_id(ID *id, int index_i, bool update_data)
+Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i, bool update_data)
 {
 	short index = (short)index_i;
 	Material *ret = NULL;
@@ -472,13 +476,15 @@ Material *BKE_material_pop_id(ID *id, int index_i, bool update_data)
 				/* decrease mat_nr index */
 				material_data_index_remove_id(id, index);
 			}
+
+			DAG_relations_tag_update(bmain);
 		}
 	}
 	
 	return ret;
 }
 
-void BKE_material_clear_id(struct ID *id, bool update_data)
+void BKE_material_clear_id(Main *bmain, ID *id, bool update_data)
 {
 	Material ***matar;
 	if ((matar = give_matarar_id(id))) {
@@ -497,6 +503,8 @@ void BKE_material_clear_id(struct ID *id, bool update_data)
 			/* decrease mat_nr index */
 			material_data_index_clear_id(id);
 		}
+
+		DAG_relations_tag_update(bmain);
 	}
 }
 
@@ -553,7 +561,7 @@ Material *give_node_material(Material *ma)
 	return NULL;
 }
 
-void BKE_material_resize_object(Object *ob, const short totcol, bool do_id_user)
+void BKE_material_resize_object(Main *bmain, Object *ob, const short totcol, bool do_id_user)
 {
 	Material **newmatar;
 	char *newmatbits;
@@ -590,6 +598,8 @@ void BKE_material_resize_object(Object *ob, const short totcol, bool do_id_user)
 	ob->totcol = totcol;
 	if (ob->totcol && ob->actcol == 0) ob->actcol = 1;
 	if (ob->actcol > ob->totcol) ob->actcol = ob->totcol;
+
+	DAG_relations_tag_update(bmain);
 }
 
 void test_object_materials(Object *ob, ID *id)
@@ -601,7 +611,7 @@ void test_object_materials(Object *ob, ID *id)
 		return;
 	}
 
-	BKE_material_resize_object(ob, *totcol, false);
+	BKE_material_resize_object(G.main, ob, *totcol, false);
 }
 
 void test_all_objects_materials(Main *bmain, ID *id)
@@ -617,7 +627,7 @@ void test_all_objects_materials(Main *bmain, ID *id)
 	BKE_main_lock(bmain);
 	for (ob = bmain->object.first; ob; ob = ob->id.next) {
 		if (ob->data == id) {
-			BKE_material_resize_object(ob, *totcol, false);
+			BKE_material_resize_object(bmain, ob, *totcol, false);
 		}
 	}
 	BKE_main_unlock(bmain);
@@ -1881,7 +1891,7 @@ static short mesh_getmaterialnumber(Mesh *me, Material *ma)
 /* append material */
 static short mesh_addmaterial(Mesh *me, Material *ma)
 {
-	BKE_material_append_id(&me->id, NULL);
+	BKE_material_append_id(G.main, &me->id, NULL);
 	me->mat[me->totcol - 1] = ma;
 
 	id_us_plus(&ma->id);
@@ -2020,7 +2030,7 @@ static void convert_tfacematerial(Main *main, Material *ma)
 		/* remove material from mesh */
 		for (a = 0; a < me->totcol; ) {
 			if (me->mat[a] == ma) {
-				BKE_material_pop_id(&me->id, a, true);
+				BKE_material_pop_id(main, &me->id, a, true);
 			}
 			else {
 				a++;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index eb94c91..161ab3a 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4774,7 +4774,7 @@ static void lib_link_object(FileData *fd, Main *main)
 				/* Only expand so as not to loose any object materials that might be set. */
 				if (totcol_data && (*totcol_data > ob->totcol)) {
 					/* printf("'%s' %d -> %d\n", ob->id.name, ob->totcol, *totcol_data); */
-					BKE_material_resize_object(ob, *totcol_data, false);
+					BKE_material_resize_object(main, ob, *totcol_data, false);
 				}
 			}
 			
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 1a14fad..999d5b2 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -3080,7 +3080,7 @@ static void bm_mesh_hflag_flush_vert(BMesh *bm, const char hflag)
  * \note This could be used for split-by-material for non mesh types.
  * \note This could take material data from another object or args.
  */
-static void mesh_separate_material_assign_mat_nr(Object *ob, const short mat_nr)
+static void mesh_separate_material_assign_mat_nr(Main *bmain, Object *ob, const short mat_nr)
 {
 	ID *obdata = ob->data;
 
@@ -3116,18 +3116,18 @@ static void mesh_separate_material_assign_mat_nr(Object *ob, const short mat_nr)
 			ma_obdata = NULL;
 		}
 
-		BKE_material_clear_id(obdata, true);
-		BKE_material_resize_object(ob, 1, true);
-		BKE_material_resize_id(obdata, 1, true);
+		BKE_material_clear_id(bmain, obdata, true);
+		BKE_material_resize_object(bmain, ob, 1, true);
+		BKE_material_resize_id(bmain, obdata, 1, true);
 
 		ob->mat[0] = ma_ob;
 		ob->matbits[0] = matbit;
 		(*matarar)[0] = ma_obdata;
 	}
 	else {
-		BKE_material_clear_id(obdata, true);
-		BKE_material_resize_object(ob, 0, true);
-		BKE_material_resize_id(obdata, 0, true);
+		BKE_material_clear_id(bmain, obdata, true);
+		BKE_material_resize_object(bmain, ob, 0, true);
+		BKE_material_resize_id(bmain, obdata, 0, true);
 	}
 }
 
@@ -3162,7 +3162,7 @@ static bool mesh_separate_material(Main *bmain, Scene *scene, Base *base_old, BM
 
 		/* leave the current object with some materials */
 		if (tot == bm_old->totface) {
-			mesh_separate_material_assign_mat_nr(base_old->object, mat_nr);
+			mesh_separate_material_assign_mat_nr(bmain, base_old->object, mat_nr);
 
 			/* since we're in editmode, must set faces here */
 			BM_ITER_MESH (f, &iter, bm_old, BM_FACES_OF_MESH) {
@@ -3174,7 +3174,7 @@ static bool mesh_separate_material(Main *bmain, Scene *scene, Base *base_old, BM
 		/* Move selection into a separate object */
 		base_new = mesh_separate_tagged(bmain, scene, base_old, bm_old);
 		if (base_new) {
-			mesh_separate_material_assign_mat_nr(base_new->object, mat_nr);
+			mesh_separate_material_assign_mat_nr(bmain, base_new->object, mat_nr);
 		}
 
 		result |= (base_new != NULL);
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index fdb93ac..ab124b3 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -386,15 +386,15 @@ int rna_IDMaterials_assign_int(PointerRNA *ptr, int key, const PointerRNA *assig
 	}
 }
 
-static void rna_IDMaterials_append_id(ID *id, Material *ma)
+static void rna_IDMaterials_append_id(ID *id, Main *bmain, Material *ma)
 {
-	BKE_material_append_id(id, ma);
+	BKE_material_append_id(bmain, id, ma);
 
 	WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
 	WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
 }
 
-static Material *rna_IDMaterials_pop_id(ID *id, ReportList *reports, int index_i, int remove_material_slot)
+static Material *rna_IDMaterials_pop_id(ID *id, Main *bmain, ReportList *reports, int index_i, int remove_material_slot)
 {
 	Material *ma;
 	short *totcol = give_totcolp_id(id);
@@ -408,7 +408,7 @@ static Material *rna_IDMaterials_pop_id(ID *id, ReportList *reports, int index_i
 		return NULL;
 	}
 
-	ma = BKE_material_pop_id(id, index_i, remove_material_slot);
+	ma = BKE_material_pop_id(bmain, id, index_i, remove_material_slot);
 
 	if (*totcol == totcol_orig) {
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list