[Bf-blender-cvs] [be1a684] master: Fix T45695: Assigning material reverts MaterialSlot.link

Campbell Barton noreply at git.blender.org
Thu Aug 6 10:12:49 CEST 2015


Commit: be1a684755905fd022be5ceecf9a7b2687475793
Author: Campbell Barton
Date:   Thu Aug 6 18:04:13 2015 +1000
Branches: master
https://developer.blender.org/rBbe1a684755905fd022be5ceecf9a7b2687475793

Fix T45695: Assigning material reverts MaterialSlot.link

Setting the material was resetting the link bit, this is OK from the UI,
confusing for scripts.

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

M	source/blender/blenkernel/BKE_material.h
M	source/blender/blenkernel/intern/material.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 0cfa1ae..bbac607 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -69,6 +69,8 @@ struct Material ***give_matarar_id(struct ID *id); /* same but for ID's */
 short *give_totcolp_id(struct ID *id);
 
 enum {
+	/* use existing link option */
+	BKE_MAT_ASSIGN_EXISTING,
 	BKE_MAT_ASSIGN_USERPREF,
 	BKE_MAT_ASSIGN_OBDATA,
 	BKE_MAT_ASSIGN_OBJECT
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 283c7a6..dd69de4 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -879,8 +879,20 @@ void assign_material(Object *ob, Material *ma, short act, int assign_type)
 		*totcolp = act;
 	}
 
+	if (act > ob->totcol) {
+		/* Need more space in the material arrays */
+		ob->mat = MEM_recallocN_id(ob->mat, sizeof(void *) * act, "matarray2");
+		ob->matbits = MEM_recallocN_id(ob->matbits, sizeof(char) * act, "matbits1");
+		ob->totcol = act;
+	}
+
 	/* Determine the object/mesh linking */
-	if (assign_type == BKE_MAT_ASSIGN_USERPREF && ob->totcol && ob->actcol) {
+	if (assign_type == BKE_MAT_ASSIGN_EXISTING) {
+		/* keep existing option (avoid confusion in scripts),
+		 * intentionally ignore userpref (default to obdata). */
+		bit = ob->matbits[act - 1];
+	}
+	else if (assign_type == BKE_MAT_ASSIGN_USERPREF && ob->totcol && ob->actcol) {
 		/* copy from previous material */
 		bit = ob->matbits[ob->actcol - 1];
 	}
@@ -898,13 +910,6 @@ void assign_material(Object *ob, Material *ma, short act, int assign_type)
 				break;
 		}
 	}
-
-	if (act > ob->totcol) {
-		/* Need more space in the material arrays */
-		ob->mat = MEM_recallocN_id(ob->mat, sizeof(void *) * act, "matarray2");
-		ob->matbits = MEM_recallocN_id(ob->matbits, sizeof(char) * act, "matbits1");
-		ob->totcol = act;
-	}
 	
 	/* do it */
 
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 7e1b0df..54f1798 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -710,7 +710,7 @@ static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value)
 	Object *ob = (Object *)ptr->id.data;
 
 	DAG_id_tag_update(value.data, 0);
-	assign_material(ob, value.data, ob->actcol, BKE_MAT_ASSIGN_USERPREF);
+	assign_material(ob, value.data, ob->actcol, BKE_MAT_ASSIGN_EXISTING);
 }
 
 static int rna_Object_active_material_editable(PointerRNA *ptr)
@@ -882,7 +882,7 @@ static void rna_MaterialSlot_material_set(PointerRNA *ptr, PointerRNA value)
 	Object *ob = (Object *)ptr->id.data;
 	int index = (Material **)ptr->data - ob->mat;
 
-	assign_material(ob, value.data, index + 1, BKE_MAT_ASSIGN_USERPREF);
+	assign_material(ob, value.data, index + 1, BKE_MAT_ASSIGN_EXISTING);
 }
 
 static int rna_MaterialSlot_link_get(PointerRNA *ptr)




More information about the Bf-blender-cvs mailing list