[Bf-blender-cvs] [f47f7383ce4] hair_guides: More meaningful flag names for hair system changes.

Lukas Tönne noreply at git.blender.org
Thu Nov 23 09:56:41 CET 2017


Commit: f47f7383ce4e7fd60877a78f000038a19ffa8d09
Author: Lukas Tönne
Date:   Thu Nov 23 08:55:55 2017 +0000
Branches: hair_guides
https://developer.blender.org/rBf47f7383ce4e7fd60877a78f000038a19ffa8d09

More meaningful flag names for hair system changes.

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

M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c
M	source/blender/makesdna/DNA_hair_types.h

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

diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index 7082a898576..48200a68dfb 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -86,7 +86,9 @@ void BKE_hair_draw_settings_free(struct HairDrawSettings *draw_settings);
 /* === Draw Cache === */
 
 enum {
-	BKE_HAIR_BATCH_DIRTY_ALL = 0,
+	BKE_HAIR_BATCH_DIRTY_FIBERS = (1 << 0),
+	BKE_HAIR_BATCH_DIRTY_STRANDS = (1 << 1),
+	BKE_HAIR_BATCH_DIRTY_ALL = 0xFFFF,
 };
 void BKE_hair_batch_cache_dirty(struct HairSystem* hsys, int mode);
 void BKE_hair_batch_cache_free(struct HairSystem* hsys);
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index e85ae68c9b7..3df3a430a73 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -163,6 +163,7 @@ void BKE_hair_generate_follicles(
 		BKE_mesh_sample_free_generator(gen);
 	}
 	
+	hsys->flag |= HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
 	BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
 }
 
@@ -173,12 +174,15 @@ void BKE_hair_guide_curves_begin(HairSystem *hsys, int totcurves, int totverts)
 	if (totcurves != hsys->totcurves)
 	{
 		hsys->curves = MEM_reallocN(hsys->curves, sizeof(HairGuideCurve) * totcurves);
-		hsys->flag |= HAIR_SYSTEM_CURVES_DIRTY;
+
+		hsys->flag |= HAIR_SYSTEM_UPDATE_GUIDE_VERT_OFFSET | HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
+		BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
 	}
 	if (totverts != hsys->totverts)
 	{
 		hsys->verts = MEM_reallocN(hsys->curves, sizeof(HairGuideCurve) * totverts);
-		hsys->flag |= HAIR_SYSTEM_VERTS_DIRTY;
+
+		BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
 	}
 }
 
@@ -190,7 +194,8 @@ void BKE_hair_set_guide_curve(HairSystem *hsys, int index, const MeshSample *mes
 	memcpy(&curve->mesh_sample, mesh_sample, sizeof(MeshSample));
 	curve->numverts = numverts;
 	
-	hsys->flag |= HAIR_SYSTEM_CURVES_DIRTY;
+	hsys->flag |= HAIR_SYSTEM_UPDATE_GUIDE_VERT_OFFSET | HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
+	BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
 }
 
 void BKE_hair_set_guide_vertex(HairSystem *hsys, int index, int flag, const float co[3])
@@ -201,20 +206,23 @@ void BKE_hair_set_guide_vertex(HairSystem *hsys, int index, int flag, const floa
 	vertex->flag = flag;
 	copy_v3_v3(vertex->co, co);
 	
-	hsys->flag |= HAIR_SYSTEM_VERTS_DIRTY;
+	BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
 }
 
 void BKE_hair_guide_curves_end(HairSystem *hsys)
 {
 	/* Recalculate vertex offsets */
-	if (hsys->flag & HAIR_SYSTEM_CURVES_DIRTY)
+	if (!(hsys->flag & HAIR_SYSTEM_UPDATE_GUIDE_VERT_OFFSET))
 	{
-		int vertstart = 0;
-		for (int i = 0; i < hsys->totcurves; ++i)
-		{
-			hsys->curves[i].vertstart = vertstart;
-			vertstart += hsys->curves[i].numverts;
-		}
+		return;
+	}
+	hsys->flag &= ~HAIR_SYSTEM_UPDATE_GUIDE_VERT_OFFSET;
+	
+	int vertstart = 0;
+	for (int i = 0; i < hsys->totcurves; ++i)
+	{
+		hsys->curves[i].vertstart = vertstart;
+		vertstart += hsys->curves[i].numverts;
 	}
 }
 
@@ -306,6 +314,12 @@ static void hair_fiber_find_closest_strand(
 
 void BKE_hair_bind_follicles(HairSystem *hsys, DerivedMesh *scalp)
 {
+	if (!(hsys->flag & HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING))
+	{
+		return;
+	}
+	hsys->flag &= ~HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
+	
 	HairPattern *pattern = hsys->pattern;
 	const int num_strands = hsys->totcurves;
 	if (num_strands == 0 || !pattern)
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index 4c8a986dcf0..661fe0de05c 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -92,10 +92,10 @@ typedef struct HairSystem {
 
 typedef enum eHairSystemFlag
 {
-	/* Guide curves have been changed */
-	HAIR_SYSTEM_CURVES_DIRTY = (1 << 8),
-	/* Guide curve vertices have been changed */
-	HAIR_SYSTEM_VERTS_DIRTY = (1 << 9),
+	/* Guide curves vertices have been changed, recalc buffer offsets */
+	HAIR_SYSTEM_UPDATE_GUIDE_VERT_OFFSET = (1 << 8),
+	/* Guide curve positions have changed, rebind hair follicles */
+	HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING = (1 << 9),
 } eHairSystemFlag;
 
 typedef struct HairDrawSettings



More information about the Bf-blender-cvs mailing list