[Bf-blender-cvs] [d391ab8] alembic: GHash iterator wrapper for DupliCache, so cache modifiers can access all components in the cache.

Lukas Tönne noreply at git.blender.org
Wed Apr 1 10:00:41 CEST 2015


Commit: d391ab8d4a492ae1b92ff0738d9620541d632a30
Author: Lukas Tönne
Date:   Tue Mar 31 18:46:01 2015 +0200
Branches: alembic
https://developer.blender.org/rBd391ab8d4a492ae1b92ff0738d9620541d632a30

GHash iterator wrapper for DupliCache, so cache modifiers can access
all components in the cache.

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

M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/object_dupli.c

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

diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 52cf217..0539f25 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -47,6 +47,7 @@ struct DupliObject;
 struct DupliObjectData;
 struct DerivedMesh;
 struct Strands;
+struct DupliCacheIterator;
 
 /* ---------------------------------------------------- */
 /* Animation Visualization */
@@ -95,6 +96,12 @@ struct DupliCache *BKE_dupli_cache_new(void);
 struct DupliObjectData *BKE_dupli_cache_add_object(struct DupliCache *dupcache, struct Object *ob);
 void BKE_dupli_cache_add_instance(struct DupliCache *dupcache, float obmat[4][4], struct DupliObjectData *data);
 
+struct DupliCacheIterator *BKE_dupli_cache_iter_new(struct DupliCache *dupcache);
+void BKE_dupli_cache_iter_free(struct DupliCacheIterator *iter);
+bool BKE_dupli_cache_iter_valid(struct DupliCacheIterator *iter);
+void BKE_dupli_cache_iter_next(struct DupliCacheIterator *iter);
+struct DupliObjectData *BKE_dupli_cache_iter_get(struct DupliCacheIterator *iter);
+
 typedef struct DupliExtraData {
 	float obmat[4][4];
 	unsigned int lay;
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 33074f5..a6c5d47 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -58,6 +58,7 @@
 #include "BKE_modifier.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
+#include "BKE_strands.h"
 
 #include "BLF_translation.h"
 
@@ -564,6 +565,18 @@ static void hairsim_copy(HairSimCacheModifier *UNUSED(md), HairSimCacheModifier
 
 static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx, DupliCache *dupcache, int frame, int frame_prev)
 {
+	struct DupliCacheIterator *iter = BKE_dupli_cache_iter_new(dupcache);
+	for (; BKE_dupli_cache_iter_valid(iter); BKE_dupli_cache_iter_next(iter)) {
+		DupliObjectData *data = BKE_dupli_cache_iter_get(iter);
+		LinkData *link;
+		
+		for (link = data->strands.first; link; link = link->next) {
+			Strands *strands = link->data;
+			
+			BKE_strands_add_motion_state(strands);
+		}
+	}
+	BKE_dupli_cache_iter_free(iter);
 }
 
 CacheModifierTypeInfo cacheModifierType_HairSimulation = {
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index ac3621d..299ffe5 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1538,7 +1538,10 @@ DupliObjectData *BKE_dupli_cache_find_data(DupliCache *dupcache, Object *ob)
 
 DupliObjectData *BKE_dupli_cache_add_object(DupliCache *dupcache, Object *ob)
 {
-	DupliObjectData *data = dupli_cache_add_object_data(dupcache, ob);
+	DupliObjectData *data = BKE_dupli_cache_find_data(dupcache, ob);
+	if (!data) {
+		data = dupli_cache_add_object_data(dupcache, ob);
+	}
 	return data;
 }
 
@@ -1557,6 +1560,37 @@ void BKE_dupli_cache_add_instance(DupliCache *dupcache, float obmat[4][4], Dupli
 
 /* ------------------------------------------------------------------------- */
 
+typedef struct DupliCacheIterator {
+	int unused;
+} DupliCacheIterator;
+
+DupliCacheIterator *BKE_dupli_cache_iter_new(struct DupliCache *dupcache)
+{
+	return (DupliCacheIterator *)BLI_ghashIterator_new(dupcache->ghash);
+}
+
+void BKE_dupli_cache_iter_free(DupliCacheIterator *iter)
+{
+	BLI_ghashIterator_free((GHashIterator *)iter);
+}
+
+bool BKE_dupli_cache_iter_valid(DupliCacheIterator *iter)
+{
+	return !BLI_ghashIterator_done((GHashIterator *)iter);
+}
+
+void BKE_dupli_cache_iter_next(DupliCacheIterator *iter)
+{
+	BLI_ghashIterator_step((GHashIterator *)iter);
+}
+
+DupliObjectData *BKE_dupli_cache_iter_get(DupliCacheIterator *iter)
+{
+	return BLI_ghashIterator_getValue((GHashIterator *)iter);
+}
+
+/* ------------------------------------------------------------------------- */
+
 DupliApplyData *duplilist_apply(Object *ob, ListBase *duplilist)
 {
 	DupliApplyData *apply_data = NULL;




More information about the Bf-blender-cvs mailing list