[Bf-blender-cvs] [3cef6156459] hair_guides hair_guides_grooming: Handle hair cache dependencies internally during invalidation to make partial updates more flexible.

Lukas Tönne noreply at git.blender.org
Thu May 24 11:33:39 CEST 2018


Commit: 3cef6156459ae10ce05dd112875cea0234db5c23
Author: Lukas Tönne
Date:   Thu May 24 10:15:04 2018 +0100
Branches: hair_guides hair_guides_grooming
https://developer.blender.org/rB3cef6156459ae10ce05dd112875cea0234db5c23

Handle hair cache dependencies internally during invalidation to make partial updates more flexible.

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

M	intern/cycles/blender/blender_util.h
M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c

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

diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 8acbfa4af37..af0d0aa1c69 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -37,7 +37,7 @@ void BKE_image_user_file_path(void *iuser, void *ima, char *path);
 unsigned char *BKE_image_get_pixels_for_frame(void *image, int frame);
 float *BKE_image_get_float_pixels_for_frame(void *image, int frame);
 void* BKE_hair_export_cache_new(void);
-int BKE_hair_export_cache_update_mesh(void *cache, const void *hsys, int subdiv, void *scalp, int data);
+int BKE_hair_export_cache_update_mesh(void *cache, const void *hsys, int subdiv, void *scalp, int requested_data);
 void BKE_hair_export_cache_free(void *hcache);
 void BKE_hair_render_get_buffer_size(void* hcache, int *r_totcurves, int *r_totverts);
 void BKE_hair_render_fill_buffers(void* hcache, int vertco_stride, int *r_curvestart, int *r_curvelen, float *r_vertco);
diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index a51c5a6e075..657ab4b3a0b 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -135,13 +135,7 @@ typedef struct HairExportCache
 	const struct HairFollicle *follicles;
 } HairExportCache;
 
-/* Identifiers for data stored in hair export caches.
- * Note some flags include dependent parts, which automatically
- * invalidates those parts when their dependencies are invalidated.
- * 
- * In particular: guide vertex locations can be changed without having to update fiber base data,
- * which allows animation of guide curves without rebuilding fiber data apart from final locations.
- */
+/* Identifiers for data stored in hair export caches */
 typedef enum eHairExportCacheUpdateFlags
 {
 	/* Follicle placement on the scalp mesh */
@@ -149,18 +143,25 @@ typedef enum eHairExportCacheUpdateFlags
 	/* Fiber vertex counts */
 	HAIR_EXPORT_FIBER_VERTEX_COUNTS     = (1 << 1),
 	/* Follicle parent indices and weights */
-	HAIR_EXPORT_FOLLICLE_BINDING        = (1 << 2) | HAIR_EXPORT_FIBER_ROOT_POSITIONS | HAIR_EXPORT_FIBER_VERTEX_COUNTS,
+	HAIR_EXPORT_FOLLICLE_BINDING        = (1 << 2),
 	/* Guide vertex positions (deform only) */
 	HAIR_EXPORT_GUIDE_VERTICES          = (1 << 3),
 	/* Guide curve number and vertex counts (topology changes) */
-	HAIR_EXPORT_GUIDE_CURVES            = (1 << 4) | HAIR_EXPORT_GUIDE_VERTICES | HAIR_EXPORT_FOLLICLE_BINDING,
+	HAIR_EXPORT_GUIDE_CURVES            = (1 << 4),
 	
 	HAIR_EXPORT_ALL                     =
 	    HAIR_EXPORT_FIBER_ROOT_POSITIONS |
 	    HAIR_EXPORT_FIBER_VERTEX_COUNTS |
 	    HAIR_EXPORT_FOLLICLE_BINDING |
 	    HAIR_EXPORT_GUIDE_VERTICES |
-	    HAIR_EXPORT_GUIDE_CURVES
+	    HAIR_EXPORT_GUIDE_CURVES,
+	HAIR_EXPORT_GUIDES                  =
+	    HAIR_EXPORT_GUIDE_VERTICES |
+	    HAIR_EXPORT_GUIDE_CURVES,
+	HAIR_EXPORT_FOLLICLES               =
+	    HAIR_EXPORT_FIBER_ROOT_POSITIONS |
+	    HAIR_EXPORT_FIBER_VERTEX_COUNTS |
+	    HAIR_EXPORT_FOLLICLE_BINDING,
 } eHairExportCacheUpdateFlags;
 
 /* Create a new export cache.
@@ -168,29 +169,29 @@ typedef enum eHairExportCacheUpdateFlags
  */
 struct HairExportCache* BKE_hair_export_cache_new(void);
 
-/* Update an existing export cache when data is invalidated.
+/* Update an existing export cache to ensure it contains the requested data.
  * Returns flags for data that has been updated.
  */
 int BKE_hair_export_cache_update(struct HairExportCache *cache, const struct HairSystem *hsys,
-                                 int subdiv, struct DerivedMesh *scalp, int data);
+                                 int subdiv, struct DerivedMesh *scalp, int requested_data);
 
-/* Update an existing export cache when data is invalidated.
+/* Update an existing export cache to ensure it contains the requested data.
  * Returns flags for data that has been updated.
  * XXX Mesh-based version for Cycles export, until DerivedMesh->Mesh conversion is done.
  */
 int BKE_hair_export_cache_update_mesh(struct HairExportCache *cache, const struct HairSystem *hsys,
-                                      int subdiv, struct  Mesh *scalp, int data);
+                                      int subdiv, struct  Mesh *scalp, int requested_data);
 
 /* Free the given export cache */
 void BKE_hair_export_cache_free(struct HairExportCache *cache);
 
-/* Returns flags for missing data parts */
-int BKE_hair_export_cache_get_required_updates(const struct HairExportCache *cache);
-
 /* Invalidate all data in a hair export cache */
 void BKE_hair_export_cache_clear(struct HairExportCache *cache);
 
-/* Invalidate part of the data in a hair export cache */
+/* Invalidate part of the data in a hair export cache.
+ *
+ * Note some parts may get invalidated automatically based on internal dependencies.
+ */
 void BKE_hair_export_cache_invalidate(struct HairExportCache *cache, int invalidate);
 
 /* === Draw Cache === */
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 40f2cbb0de9..e2307311c92 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -556,15 +556,61 @@ HairExportCache* BKE_hair_export_cache_new(void)
 	return cache;
 }
 
-/* Update an existing export cache when data is invalidated.
+/* Returns flags for missing data parts */
+
+static int hair_export_cache_get_required_updates(const HairExportCache *cache)
+{
+	int data = 0;
+	if (!cache->guide_curves)
+	{
+		data |= HAIR_EXPORT_GUIDE_CURVES;
+	}
+	if (!cache->guide_verts || !cache->guide_normals || !cache->guide_tangents)
+	{
+		data |= HAIR_EXPORT_GUIDE_VERTICES;
+	}
+	if (!cache->follicles)
+	{
+		data |= HAIR_EXPORT_FOLLICLE_BINDING;
+	}
+	if (!cache->fiber_root_position)
+	{
+		data |= HAIR_EXPORT_FIBER_ROOT_POSITIONS;
+	}
+	if (!cache->fiber_numverts)
+	{
+		data |= HAIR_EXPORT_FIBER_VERTEX_COUNTS;
+	}
+	return data;
+}
+
+/* Include data dependencies of the given flags */
+
+static int hair_export_cache_get_dependencies(int data)
+{
+	/* Ordering here is important to account for recursive dependencies */
+	
+	if (data & HAIR_EXPORT_GUIDE_CURVES)
+		data |= HAIR_EXPORT_GUIDE_VERTICES | HAIR_EXPORT_FOLLICLE_BINDING;
+	
+	if (data & HAIR_EXPORT_FOLLICLE_BINDING)
+		data |= HAIR_EXPORT_FIBER_ROOT_POSITIONS | HAIR_EXPORT_FIBER_VERTEX_COUNTS;
+	
+	return data;
+}
+
+/* Update an existing export cache to ensure it contains the requested data.
  * Returns flags for data that has been updated.
  */
 
 int BKE_hair_export_cache_update(HairExportCache *cache, const HairSystem *hsys,
-                                 int subdiv, DerivedMesh *scalp, int data)
+                                 int subdiv, DerivedMesh *scalp, int requested_data)
 {
-	/* Check for missing data */
-	data |= BKE_hair_export_cache_get_required_updates(cache);
+	/* Only update invalidated parts */
+	int data = requested_data & hair_export_cache_get_required_updates(cache);
+	
+	/* Invalid data should already include all dependencies */
+	BLI_assert(data == hair_export_cache_get_dependencies(data));
 	
 	if (data & HAIR_EXPORT_GUIDE_CURVES)
 	{
@@ -689,16 +735,16 @@ int BKE_hair_export_cache_update(HairExportCache *cache, const HairSystem *hsys,
 }
 
 
-/* Update an existing export cache when data is invalidated.
+/* Update an existing export cache to ensure it contains the requested data.
  * Returns flags for data that has been updated.
  * XXX Mesh-based version for Cycles export, until DerivedMesh->Mesh conversion is done.
  */
 
 int BKE_hair_export_cache_update_mesh(HairExportCache *cache, const HairSystem *hsys,
-                                      int subdiv, struct Mesh *scalp, int data)
+                                      int subdiv, struct Mesh *scalp, int requested_data)
 {
 	DerivedMesh *dm = CDDM_from_mesh(scalp);
-	int result = BKE_hair_export_cache_update(cache, hsys, subdiv, dm, data);
+	int result = BKE_hair_export_cache_update(cache, hsys, subdiv, dm, requested_data);
 	dm->release(dm);
 	return result;
 }
@@ -734,34 +780,6 @@ void BKE_hair_export_cache_free(HairExportCache *cache)
 	MEM_freeN(cache);
 }
 
-/* Returns flags for missing data parts */
-
-int BKE_hair_export_cache_get_required_updates(const HairExportCache *cache)
-{
-	int data = 0;
-	if (!cache->guide_curves)
-	{
-		data |= HAIR_EXPORT_GUIDE_CURVES;
-	}
-	if (!cache->guide_verts || !cache->guide_normals || !cache->guide_tangents)
-	{
-		data |= HAIR_EXPORT_GUIDE_VERTICES;
-	}
-	if (!cache->follicles)
-	{
-		data |= HAIR_EXPORT_FOLLICLE_BINDING;
-	}
-	if (!cache->fiber_root_position)
-	{
-		data |= HAIR_EXPORT_FIBER_ROOT_POSITIONS;
-	}
-	if (!cache->fiber_numverts)
-	{
-		data |= HAIR_EXPORT_FIBER_VERTEX_COUNTS;
-	}
-	return data;
-}
-
 /* Invalidate all data in a hair export cache */
 
 void BKE_hair_export_cache_clear(HairExportCache *cache)
@@ -770,11 +788,17 @@ void BKE_hair_export_cache_clear(HairExportCache *cache)
 	BKE_hair_export_cache_invalidate(cache, HAIR_EXPORT_ALL);
 }
 
-/* Invalidate part of the data in a hair export cache */
+/* Invalidate part of the data in a hair export cache.
+ *
+ * Note some parts may get invalidated automatically based on internal dependencies.
+ */
 
 void BKE_hair_export_cache_invalidate(HairExportCache *cache, int invalidate)
 {
-	if (invalidate & HAIR_EXPORT_GUIDE_CURVES)
+	/* Include dependencies */
+	int data = hair_export_cache_get_dependencies(invalidate);
+
+	if (data & HAIR_EXPORT_GUIDE_CURVES)
 	{
 		if (cache->guide_curves)
 		{
@@ -782,7 +806,7 @@ void BKE_hair_export_cache_invalidate(HairExportCache *cache, int invalidate)
 			cache->guide_curves = 0;
 		}
 	}
-	if (invalidate & HAIR_EXPORT_GUIDE_VERTICES)
+	if (data & HAIR_EXPORT_GUIDE_VERTICES)
 	{
 		if (cache->guide_verts)
 		{
@@ -800,11 +824,11 @@ void BKE_hair_export_cache_invalidate(HairExportCache *cache, int invalidate)
 			cache->guide_tangents = NULL;
 		}
 	}
-	if (invalidate & HAIR_EXPORT_FOLLICLE_BINDING)
+	if (data & HAIR_EXPORT_FOLLICLE_BINDING)
 	{
 		cache->follicles = NULL;
 	}
-	if (invalidate & HAIR_EXPORT_FIBER_ROOT_POSITIONS)
+	if (data & HAIR_EXPORT_FIBER_ROOT_POSITIONS)
 	{
 		if (cache->fiber_root_position)
 		{
@@ -812,7 +836,7 @@ void BKE_hair_export_cache_invalidate(HairExp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list