[Bf-blender-cvs] [489d5e998ac] hair_guides_grooming: Support material slots in Groom type objects.

Lukas Tönne noreply at git.blender.org
Sun Jun 3 19:03:33 CEST 2018


Commit: 489d5e998ac5b537eccd3714abb550dfe888680e
Author: Lukas Tönne
Date:   Sun Jun 3 18:03:14 2018 +0100
Branches: hair_guides_grooming
https://developer.blender.org/rB489d5e998ac5b537eccd3714abb550dfe888680e

Support material slots in Groom type objects.

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

M	source/blender/blenkernel/intern/groom.c
M	source/blender/blenkernel/intern/library_query.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/object/object_relations.c
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/editors/space_outliner/outliner_tree.c
M	source/blender/makesdna/DNA_groom_types.h
M	source/blender/makesdna/DNA_object_types.h

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

diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index bc77942bea9..4972649d444 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -158,6 +158,8 @@ void BKE_groom_free(Groom *groom)
 	
 	groom_bundles_free(&groom->bundles);
 	
+	MEM_SAFE_FREE(groom->mat);
+	
 	BKE_animdata_free(&groom->id, false);
 }
 
@@ -212,6 +214,8 @@ void BKE_groom_copy_data(Main *UNUSED(bmain), Groom *groom_dst, const Groom *gro
 	{
 		groom_dst->hair_draw_settings = BKE_hair_draw_settings_copy(groom_dst->hair_draw_settings);
 	}
+	
+	groom_dst->mat = MEM_dupallocN(groom_src->mat);
 }
 
 Groom *BKE_groom_copy(Main *bmain, const Groom *groom)
diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c
index e447cf8ef53..26ef20d6508 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -635,6 +635,9 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
 			{
 				Groom *groom = (Groom *) id;
 				CALLBACK_INVOKE(groom->scalp_object, IDWALK_CB_NOP);
+				for (i = 0; i < groom->totcol; i++) {
+					CALLBACK_INVOKE(groom->mat[i], IDWALK_CB_USER);
+				}
 				break;
 			}
 
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 131d79c249f..28963cd8380 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -39,6 +39,7 @@
 #include "DNA_anim_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_group_types.h"
+#include "DNA_groom_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
@@ -231,6 +232,10 @@ Material ***give_matarar(Object *ob)
 		mb = ob->data;
 		return &(mb->mat);
 	}
+	else if (ob->type == OB_GROOM) {
+		Groom *groom = ob->data;
+		return &(groom->mat);
+	}
 	return NULL;
 }
 
@@ -252,6 +257,10 @@ short *give_totcolp(Object *ob)
 		mb = ob->data;
 		return &(mb->totcol);
 	}
+	else if (ob->type == OB_GROOM) {
+		Groom *groom = ob->data;
+		return &(groom->totcol);
+	}
 	return NULL;
 }
 
@@ -268,6 +277,8 @@ Material ***give_matarar_id(ID *id)
 			return &(((Curve *)id)->mat);
 		case ID_MB:
 			return &(((MetaBall *)id)->mat);
+		case ID_GM:
+			return &(((Groom *)id)->mat);
 		default:
 			break;
 	}
@@ -286,6 +297,8 @@ short *give_totcolp_id(ID *id)
 			return &(((Curve *)id)->totcol);
 		case ID_MB:
 			return &(((MetaBall *)id)->totcol);
+		case ID_GM:
+			return &(((Groom *)id)->totcol);
 		default:
 			break;
 	}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 61acd52a818..6bc2ce48ef6 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8193,6 +8193,10 @@ static void lib_link_groom(FileData *fd, Main *bmain)
 
 		groom->scalp_object = newlibadr(fd, id->lib, groom->scalp_object);
 
+		for (int a = 0; a < groom->totcol; a++) {
+			groom->mat[a] = newlibadr_us(fd, groom->id.lib, groom->mat[a]);
+		}
+
 		id->tag &= ~LIB_TAG_NEED_LINK;
 	}
 }
@@ -8219,6 +8223,9 @@ static void direct_link_groom(FileData *fd, Groom *groom)
 	direct_link_hair(fd, groom->hair_system);
 	groom->hair_draw_settings = newdataadr(fd, groom->hair_draw_settings);
 	
+	groom->mat = newdataadr(fd, groom->mat);
+	test_pointer_array(fd, (void **)&groom->mat);
+	
 	groom->bb = NULL;
 	groom->editgroom = NULL;
 	groom->batch_cache = NULL;
@@ -9348,6 +9355,10 @@ static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSetting
 static void expand_groom(FileData *fd, Main *mainvar, Groom *groom)
 {
 	expand_doit(fd, mainvar, groom->scalp_object);
+
+	for (int a = 0; a < groom->totcol; a++) {
+		expand_doit(fd, mainvar, groom->mat[a]);
+	}
 }
 
 static void expand_collection(FileData *fd, Main *mainvar, Collection *collection)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index b4b729bb357..6bd1e749002 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3664,6 +3664,8 @@ static void write_groom(WriteData *wd, Groom *groom)
 	{
 		writestruct(wd, DATA, HairDrawSettings, 1, groom->hair_draw_settings);
 	}
+	
+	writedata(wd, DATA, sizeof(void *) * groom->totcol, groom->mat);
 }
 
 /* Keep it last of write_foodata functions. */
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 37b71e4b696..00e34101547 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -38,6 +38,7 @@
 #include "DNA_armature_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_constraint_types.h"
+#include "DNA_groom_types.h"
 #include "DNA_group_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_lattice_types.h"
@@ -1911,6 +1912,10 @@ static void single_mat_users_expand(Main *bmain)
 	for (mb = bmain->mball.first; mb; mb = mb->id.next)
 		if (mb->id.tag & LIB_TAG_NEW)
 			new_id_matar(bmain, mb->mat, mb->totcol);
+	
+	for (Groom *groom = bmain->grooms.first; groom; groom = groom->id.next)
+		if (groom->id.tag & LIB_TAG_NEW)
+			new_id_matar(bmain, groom->mat, groom->totcol);
 }
 
 /* used for copying scenes */
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index 5ae6cec84ba..62a368cebd3 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -34,6 +34,7 @@
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_gpencil_types.h"
+#include "DNA_groom_types.h"
 #include "DNA_group_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_linestyle_types.h"
@@ -179,6 +180,11 @@ static void unlink_material_cb(
 		totcol = mb->totcol;
 		matar = mb->mat;
 	}
+	else if (GS(tsep->id->name) == ID_GM) {
+		Groom *groom = (Groom *)tsep->id;
+		totcol = groom->totcol;
+		matar = groom->mat;
+	}
 	else {
 		BLI_assert(0);
 	}
diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c
index 1cb05573dc0..931cec7027f 100644
--- a/source/blender/editors/space_outliner/outliner_tree.c
+++ b/source/blender/editors/space_outliner/outliner_tree.c
@@ -659,6 +659,9 @@ static void outliner_add_id_contents(SpaceOops *soops, TreeElement *te, TreeStor
 			
 			if (outliner_animdata_test(groom->adt))
 				outliner_add_element(soops, &te->subtree, groom, te, TSE_ANIM_DATA, 0);
+			
+			for (int a = 0; a < groom->totcol; a++)
+				outliner_add_element(soops, &te->subtree, groom->mat[a], te, 0, a);
 			break;
 		}
 		case ID_MA:
diff --git a/source/blender/makesdna/DNA_groom_types.h b/source/blender/makesdna/DNA_groom_types.h
index f3363d077d7..2832efb363e 100644
--- a/source/blender/makesdna/DNA_groom_types.h
+++ b/source/blender/makesdna/DNA_groom_types.h
@@ -135,6 +135,11 @@ typedef struct Groom {
 	
 	struct Object *scalp_object;                    /* Surface for attaching hairs */
 	
+	struct Material **mat;      /* Material slots */
+	short totcol;               /* Number of material slots */
+	short pad3;
+	int pad4;
+	
 	struct BoundBox *bb;
 	
 	EditGroom *editgroom;
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index a46daabf819..b29f0d6e3fe 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -382,7 +382,7 @@ enum {
 
 /* check if the object type supports materials */
 #define OB_TYPE_SUPPORT_MATERIAL(_type) \
-	((_type) >= OB_MESH && (_type) <= OB_MBALL)
+	(ELEM(_type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_GROOM))
 #define OB_TYPE_SUPPORT_VGROUP(_type) \
 	(ELEM(_type, OB_MESH, OB_LATTICE))
 #define OB_TYPE_SUPPORT_EDITMODE(_type) \



More information about the Bf-blender-cvs mailing list