[Bf-blender-cvs] [09701e0] alembic: Apply child strand deformation only when using the cache result for viewport or render display.

Lukas Tönne noreply at git.blender.org
Tue Apr 14 11:06:23 CEST 2015


Commit: 09701e0cccdc85b0a597a7a02e5cf52e49ddd8e3
Author: Lukas Tönne
Date:   Mon Apr 13 12:01:13 2015 +0200
Branches: alembic
https://developer.blender.org/rB09701e0cccdc85b0a597a7a02e5cf52e49ddd8e3

Apply child strand deformation only when using the cache result for
viewport or render display.

This way the strands can be cleanly written to subsequent output caches
without accumulating deformations.

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

M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/editors/io/io_cache_library.c
M	source/blender/pointcache/alembic/abc_particles.cpp

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

diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 0bb06c8..9184a97 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -74,9 +74,9 @@ void BKE_cache_archive_output_path(struct CacheLibrary *cachelib, char *result,
 void BKE_cache_library_dag_recalc_tag(struct EvaluationContext *eval_ctx, struct Main *bmain);
 
 bool BKE_cache_read_dupli_cache(struct CacheLibrary *cachelib, struct DupliCache *dupcache,
-                                struct Scene *scene, struct Group *dupgroup, float frame, eCacheLibrary_EvalMode eval_mode, bool read_all);
+                                struct Scene *scene, struct Group *dupgroup, float frame, eCacheLibrary_EvalMode eval_mode, bool for_display);
 bool BKE_cache_read_dupli_object(struct CacheLibrary *cachelib, struct DupliObjectData *data,
-                                 struct Scene *scene, struct Object *ob, float frame, eCacheLibrary_EvalMode eval_mode, bool read_all);
+                                 struct Scene *scene, struct Object *ob, float frame, eCacheLibrary_EvalMode eval_mode, bool for_display);
 
 void BKE_cache_process_dupli_cache(struct CacheLibrary *cachelib, struct CacheProcessData *data,
                                    struct Scene *scene, struct Group *dupgroup, float frame_prev, float frame, eCacheLibrary_EvalMode eval_mode);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index b8b11a0..ee60206 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -350,14 +350,10 @@ static struct PTCReaderArchive *find_active_cache(Scene *scene, CacheLibrary *ca
 	return archive;
 }
 
-static void cache_get_read_flags(CacheLibrary *cachelib, eCacheLibrary_EvalMode eval_mode, bool read_all,
+static void cache_get_read_flags(CacheLibrary *cachelib, eCacheLibrary_EvalMode eval_mode, bool for_display,
                                  bool *read_strands_motion, bool *read_strands_children)
 {
-	if (read_all) {
-		*read_strands_motion = true;
-		*read_strands_children = true;
-	}
-	else {
+	if (for_display) {
 		switch (eval_mode) {
 			case CACHE_LIBRARY_EVAL_REALTIME:
 				*read_strands_motion = cachelib->display_flag & CACHE_LIBRARY_DISPLAY_MOTION;
@@ -373,10 +369,14 @@ static void cache_get_read_flags(CacheLibrary *cachelib, eCacheLibrary_EvalMode
 				break;
 		}
 	}
+	else {
+		*read_strands_motion = true;
+		*read_strands_children = true;
+	}
 }
 
 bool BKE_cache_read_dupli_cache(CacheLibrary *cachelib, DupliCache *dupcache,
-                                Scene *scene, Group *dupgroup, float frame, eCacheLibrary_EvalMode eval_mode, bool read_all)
+                                Scene *scene, Group *dupgroup, float frame, eCacheLibrary_EvalMode eval_mode, bool for_display)
 {
 	bool read_strands_motion, read_strands_children, read_simdebug = G.debug & G_DEBUG_SIMDATA;
 	struct PTCReaderArchive *archive;
@@ -398,7 +398,7 @@ bool BKE_cache_read_dupli_cache(CacheLibrary *cachelib, DupliCache *dupcache,
 	
 	PTC_reader_archive_use_render(archive, eval_mode == CACHE_LIBRARY_EVAL_RENDER);
 	
-	cache_get_read_flags(cachelib, eval_mode, read_all, &read_strands_motion, &read_strands_children);
+	cache_get_read_flags(cachelib, eval_mode, for_display, &read_strands_motion, &read_strands_children);
 	// TODO duplicache reader should only overwrite data that is not sequentially generated by modifiers (simulations) ...
 	reader = PTC_reader_duplicache(dupgroup->id.name, dupgroup, dupcache,
 	                               read_strands_motion, read_strands_children, read_simdebug);
@@ -409,11 +409,29 @@ bool BKE_cache_read_dupli_cache(CacheLibrary *cachelib, DupliCache *dupcache,
 	PTC_reader_free(reader);
 	PTC_close_reader_archive(archive);
 	
+	/* Deform child strands to follow parent motion.
+	 * Note that this is an optional feature for viewport/render display,
+	 * strand motion is not usually applied to children in caches.
+	 */
+	if (for_display && read_strands_motion && read_strands_children) {
+		struct  DupliCacheIterator *it = BKE_dupli_cache_iter_new(dupcache);
+		for (; BKE_dupli_cache_iter_valid(it); BKE_dupli_cache_iter_next(it)) {
+			DupliObjectData *dobdata = BKE_dupli_cache_iter_get(it);
+			DupliObjectDataStrands *link;
+			
+			for (link = dobdata->strands.first; link; link = link->next) {
+				if (link->strands_children)
+					BKE_strands_children_deform_from_parents(link->strands_children, link->strands);
+			}
+		}
+		BKE_dupli_cache_iter_free(it);
+	}
+	
 	return (dupcache->result != CACHE_READ_SAMPLE_INVALID);
 }
 
 bool BKE_cache_read_dupli_object(CacheLibrary *cachelib, DupliObjectData *data,
-                                 Scene *scene, Object *ob, float frame, eCacheLibrary_EvalMode eval_mode, bool read_all)
+                                 Scene *scene, Object *ob, float frame, eCacheLibrary_EvalMode eval_mode, bool for_display)
 {
 	bool read_strands_motion, read_strands_children;
 	struct PTCReaderArchive *archive;
@@ -431,7 +449,7 @@ bool BKE_cache_read_dupli_object(CacheLibrary *cachelib, DupliObjectData *data,
 	
 	PTC_reader_archive_use_render(archive, eval_mode == CACHE_LIBRARY_EVAL_RENDER);
 	
-	cache_get_read_flags(cachelib, eval_mode, read_all, &read_strands_motion, &read_strands_children);
+	cache_get_read_flags(cachelib, eval_mode, for_display, &read_strands_motion, &read_strands_children);
 	reader = PTC_reader_duplicache_object(ob->id.name, ob, data, read_strands_motion, read_strands_children);
 	PTC_reader_init(reader, archive);
 	
@@ -440,6 +458,18 @@ bool BKE_cache_read_dupli_object(CacheLibrary *cachelib, DupliObjectData *data,
 	PTC_reader_free(reader);
 	PTC_close_reader_archive(archive);
 	
+	/* Deform child strands to follow parent motion.
+	 * Note that this is an optional feature for viewport/render display,
+	 * strand motion is not usually applied to children in caches.
+	 */
+	if (for_display && read_strands_motion && read_strands_children) {
+		DupliObjectDataStrands *link;
+		for (link = data->strands.first; link; link = link->next) {
+			if (link->strands_children)
+				BKE_strands_children_deform_from_parents(link->strands_children, link->strands);
+		}
+	}
+	
 	return true;
 }
 
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 64f60ed..870a9f8 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1707,7 +1707,7 @@ void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *
 			/* skip reading when the cachelib is baking, avoids unnecessary memory allocation */
 			if (!(ob->cache_library->flag & CACHE_LIBRARY_BAKING)) {
 				/* TODO at this point we could apply animation offset */
-				BKE_cache_read_dupli_cache(ob->cache_library, ob->dup_cache, scene, ob->dup_group, frame, eval_mode, false);
+				BKE_cache_read_dupli_cache(ob->cache_library, ob->dup_cache, scene, ob->dup_group, frame, eval_mode, true);
 			}
 			
 			ob->dup_cache->flag &= ~DUPCACHE_FLAG_DIRTY;
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index b434d0e..30914be 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -277,7 +277,7 @@ static void cache_library_bake_do(CacheLibraryBakeJob *data)
 				BKE_dupli_cache_from_group(scene, data->group, data->cachelib, process_data.dupcache, &data->eval_ctx);
 				break;
 			case CACHE_LIBRARY_SOURCE_CACHE:
-				BKE_cache_read_dupli_cache(data->cachelib, process_data.dupcache, scene, data->group, frame, data->cache_eval_mode, true);
+				BKE_cache_read_dupli_cache(data->cachelib, process_data.dupcache, scene, data->group, frame, data->cache_eval_mode, false);
 				break;
 		}
 		
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp b/source/blender/pointcache/alembic/abc_particles.cpp
index f25ba97..f5742e3 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -730,6 +730,8 @@ PTCReadSampleResult AbcStrandsChildrenReader::read_sample(float frame)
 		++time;
 	}
 	
+	BKE_strands_children_ensure_normals(m_strands);
+	
 	return PTC_READ_SAMPLE_EXACT;
 }
 
@@ -872,20 +874,6 @@ PTCReadSampleResult AbcStrandsReader::read_sample(float frame)
 	
 	if (m_read_children) {
 		m_child_reader.read_sample(frame);
-		
-		StrandsChildren *children = m_child_reader.get_result();
-		if (children) {
-			/* child deformation from parent motion */
-			/* XXX This is a quick solution, but needs better design:
-			 * For rendering it would be preferable to have the child deformation stored in caches directly.
-			 * While possible, this would make it difficult to disable the deformation on loading.
-			 */
-			if (m_read_motion && m_strands && m_strands->state) {
-				BKE_strands_children_deform_from_parents(children, m_strands);
-			}
-			
-			BKE_strands_children_ensure_normals(children);
-		}
 	}
 	
 	return PTC_READ_SAMPLE_EXACT;




More information about the Bf-blender-cvs mailing list