[Bf-blender-cvs] [5ad90a874f2] hair_guides: Add a hair system in the groom ID block for creating renderable hairs.

Lukas Tönne noreply at git.blender.org
Tue Jan 2 13:46:17 CET 2018


Commit: 5ad90a874f210e107caff30e5205f3b49dceaf35
Author: Lukas Tönne
Date:   Tue Jan 2 12:45:48 2018 +0000
Branches: hair_guides
https://developer.blender.org/rB5ad90a874f210e107caff30e5205f3b49dceaf35

Add a hair system in the groom ID block for creating renderable hairs.

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

M	source/blender/blenkernel/BKE_groom.h
M	source/blender/blenkernel/intern/groom.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/makesdna/DNA_groom_types.h

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

diff --git a/source/blender/blenkernel/BKE_groom.h b/source/blender/blenkernel/BKE_groom.h
index 8aeebe8ed1f..4ca88426cd6 100644
--- a/source/blender/blenkernel/BKE_groom.h
+++ b/source/blender/blenkernel/BKE_groom.h
@@ -95,4 +95,8 @@ typedef struct GroomIterator
 		     iter.isectionvertex < (bundle)->numloopverts; \
 		     ++iter.isectionvertex, ++iter.vertex)
 
+/* === Utility functions (DerivedMesh SOON TO BE DEPRECATED!) === */
+struct DerivedMesh;
+struct DerivedMesh* BKE_groom_get_scalp(struct Groom *groom);
+
 #endif /*  __BKE_GROOM_H__ */
diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index 2bbe3170455..79d2958cd06 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -50,6 +50,7 @@
 #include "BKE_animsys.h"
 #include "BKE_global.h"
 #include "BKE_groom.h"
+#include "BKE_hair.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
@@ -64,6 +65,9 @@ void BKE_groom_init(Groom *groom)
 	groom->bb = BKE_boundbox_alloc_unit();
 	
 	groom->curve_res = 12;
+	
+	groom->hair_system = BKE_hair_new();
+	groom->hair_draw_settings = BKE_hair_draw_settings_new();
 }
 
 void *BKE_groom_add(Main *bmain, const char *name)
@@ -116,6 +120,15 @@ void BKE_groom_free(Groom *groom)
 	
 	MEM_SAFE_FREE(groom->bb);
 	
+	if (groom->hair_system)
+	{
+		BKE_hair_free(groom->hair_system);
+	}
+	if (groom->hair_draw_settings)
+	{
+		BKE_hair_draw_settings_free(groom->hair_draw_settings);
+	}
+	
 	groom_bundles_free(&groom->bundles);
 	
 	BKE_animdata_free(&groom->id, false);
@@ -155,6 +168,15 @@ void BKE_groom_copy_data(Main *UNUSED(bmain), Groom *groom_dst, const Groom *gro
 	}
 	
 	groom_dst->editgroom = NULL;
+	
+	if (groom_dst->hair_system)
+	{
+		groom_dst->hair_system = BKE_hair_copy(groom_dst->hair_system);
+	}
+	if (groom_dst->hair_draw_settings)
+	{
+		groom_dst->hair_draw_settings = BKE_hair_draw_settings_copy(groom_dst->hair_draw_settings);
+	}
 }
 
 Groom *BKE_groom_copy(Main *bmain, const Groom *groom)
@@ -519,3 +541,12 @@ void BKE_groom_batch_cache_free(Groom *groom)
 		BKE_groom_batch_cache_free_cb(groom);
 	}
 }
+
+/* === Utility functions (DerivedMesh SOON TO BE DEPRECATED!) === */
+
+struct DerivedMesh* BKE_groom_get_scalp(struct Groom *groom)
+{
+	// TODO
+	UNUSED_VARS(groom);
+	return NULL;
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index acd2468a22e..a93d17ffada 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8406,6 +8406,10 @@ static void direct_link_groom(FileData *fd, Groom *groom)
 		bundle->totshapecache = 0;
 	}
 	
+	groom->hair_system = newdataadr(fd, groom->hair_system);
+	direct_link_hair(fd, groom->hair_system);
+	groom->hair_draw_settings = newdataadr(fd, groom->hair_draw_settings);
+	
 	groom->bb = NULL;
 	groom->editgroom = NULL;
 	groom->batch_cache = NULL;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 6fc2ec195fd..2a603c85b10 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3828,6 +3828,15 @@ static void write_groom(WriteData *wd, Groom *groom)
 		writestruct(wd, DATA, GroomSection, bundle->totsections, bundle->sections);
 		writestruct(wd, DATA, GroomSectionVertex, bundle->totverts, bundle->verts);
 	}
+	
+	if (groom->hair_system) {
+		writestruct(wd, DATA, HairSystem, 1, groom->hair_system);
+		write_hair(wd, groom->hair_system);
+	}
+	if (groom->hair_draw_settings)
+	{
+		writestruct(wd, DATA, HairDrawSettings, 1, groom->hair_draw_settings);
+	}
 }
 
 /* Keep it last of write_foodata functions. */
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index d5015a09804..dc19ced7c47 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -30,6 +30,7 @@
 #include "BLI_alloca.h"
 
 #include "BKE_DerivedMesh.h"
+#include "BKE_groom.h"
 #include "BKE_particle.h"
 #include "BKE_paint.h"
 #include "BKE_pbvh.h"
@@ -37,6 +38,7 @@
 #include "DNA_world_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_view3d_types.h"
+#include "DNA_groom_types.h"
 #include "DNA_hair_types.h"
 
 #include "GPU_material.h"
@@ -1588,6 +1590,10 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sld
 			}
 		}
 	}
+	else if (ob->type == OB_GROOM) {
+		Groom *groom = ob->data;
+		material_hair(vedata, sldata, ob, groom->hair_system, BKE_groom_get_scalp(groom));
+	}
 }
 
 void EEVEE_materials_cache_finish(EEVEE_Data *vedata)
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 6f69a92f70f..e2263ef35f7 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -30,6 +30,7 @@
 #include "DNA_armature_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_curve_types.h"
+#include "DNA_groom_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meta_types.h"
 #include "DNA_modifier_types.h"
@@ -45,6 +46,7 @@
 #include "BKE_camera.h"
 #include "BKE_curve.h"
 #include "BKE_global.h"
+#include "BKE_groom.h"
 #include "BKE_mball.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
@@ -1871,12 +1873,15 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
 		{
 			Object *obedit = scene->obedit;
 			if (ob != obedit) {
+				Groom *groom = ob->data;
 				struct Gwn_Batch *geom = DRW_cache_groom_wire_get(ob);
 				if (theme_id == TH_UNDEFINED) {
 					theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
 				}
 				DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
 				DRW_shgroup_call_add(shgroup, geom, ob->obmat);
+				
+				DRW_shgroup_hair(ob, groom->hair_system, groom->hair_draw_settings, BKE_groom_get_scalp(groom), stl->g_data->hair_verts, stl->g_data->hair_edges);
 			}
 			break;
 		}
diff --git a/source/blender/makesdna/DNA_groom_types.h b/source/blender/makesdna/DNA_groom_types.h
index 09a92be55f4..2989a25ead0 100644
--- a/source/blender/makesdna/DNA_groom_types.h
+++ b/source/blender/makesdna/DNA_groom_types.h
@@ -120,6 +120,9 @@ typedef struct Groom {
 	
 	ListBase bundles;           /* List of GroomBundle */
 	
+	struct HairSystem *hair_system;         /* Renderable hair geometry */
+	struct HairDrawSettings *hair_draw_settings; /* Draw settings for hair geometry */
+	
 	EditGroom *editgroom;
 	void *batch_cache;
 } Groom;



More information about the Bf-blender-cvs mailing list