[Bf-blender-cvs] [366fc83] alembic: Fixed DupliCache writers/readers to support subsequent stages of cache manipulation.

Lukas Tönne noreply at git.blender.org
Thu Apr 2 13:37:07 CEST 2015


Commit: 366fc83f6d1d5baa1d557b6bc3ba4f8d82dc8ce7
Author: Lukas Tönne
Date:   Thu Apr 2 13:35:07 2015 +0200
Branches: alembic
https://developer.blender.org/rB366fc83f6d1d5baa1d557b6bc3ba4f8d82dc8ce7

Fixed DupliCache writers/readers to support subsequent stages of
cache manipulation.

Strand data in caches is now stored in a named list, so we can avoid
adding strand data in every frame.

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

M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/blenkernel/intern/strands.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/pointcache/alembic/abc_group.cpp
M	source/blender/pointcache/alembic/abc_group.h
M	source/blender/pointcache/alembic/abc_particles.cpp
M	source/blender/pointcache/alembic/abc_particles.h

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

diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 886f494..07af4af 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -90,7 +90,8 @@ void BKE_dupli_object_data_init(struct DupliObjectData *data, struct Object *ob)
 /* does not free data itself */
 void BKE_dupli_object_data_clear(struct DupliObjectData *data);
 void BKE_dupli_object_data_set_mesh(struct DupliObjectData *data, struct DerivedMesh *dm);
-void BKE_dupli_object_data_add_strands(struct DupliObjectData *data, struct Strands *strands);
+void BKE_dupli_object_data_add_strands(struct DupliObjectData *data, const char *name, struct Strands *strands);
+struct Strands *BKE_dupli_object_data_find_strands(struct DupliObjectData *data, const char *name);
 
 struct DupliCache *BKE_dupli_cache_new(void);
 void BKE_dupli_cache_free(struct DupliCache *dupcache);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 8c05d68..81501ab 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -577,10 +577,10 @@ static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *UNU
 	struct DupliCacheIterator *iter = BKE_dupli_cache_iter_new(data->dupcache);
 	for (; BKE_dupli_cache_iter_valid(iter); BKE_dupli_cache_iter_next(iter)) {
 		DupliObjectData *data = BKE_dupli_cache_iter_get(iter);
-		LinkData *link;
+		DupliObjectDataStrands *link;
 		
 		for (link = data->strands.first; link; link = link->next) {
-			Strands *strands = link->data;
+			Strands *strands = link->strands;
 			
 			struct Implicit_Data *solver_data;
 			int numsprings;
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 74ce841..9dccda9 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -38,6 +38,8 @@
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
 #include "BLI_string_utf8.h"
 
 #include "BLI_math.h"
@@ -68,6 +70,8 @@
 
 #include "BLI_strict_flags.h"
 
+#include "BLF_translation.h"
+
 /* Dupli-Geometry */
 
 typedef struct DupliContext {
@@ -1338,6 +1342,14 @@ static void dupli_cache_calc_boundbox(DupliObjectData *data)
 	BKE_boundbox_init_from_minmax(&data->bb, min, max);
 }
 
+static bool UNUSED_FUNCTION(dupli_object_data_strands_unique_name)(ListBase *lb, DupliObjectDataStrands *link)
+{
+	if (lb && link) {
+		return BLI_uniquename(lb, link, DATA_("Strands"), '.', offsetof(DupliObjectDataStrands, name), sizeof(link->name));
+	}
+	return false;
+}
+
 void BKE_dupli_object_data_init(DupliObjectData *data, Object *ob)
 {
 	data->ob = ob;
@@ -1351,7 +1363,7 @@ void BKE_dupli_object_data_init(DupliObjectData *data, Object *ob)
 
 void BKE_dupli_object_data_clear(DupliObjectData *data)
 {
-	LinkData *link;
+	DupliObjectDataStrands *link;
 	
 	if (data->dm) {
 		/* we lock DMs in the cache to prevent freeing outside,
@@ -1362,8 +1374,8 @@ void BKE_dupli_object_data_clear(DupliObjectData *data)
 	}
 	
 	for (link = data->strands.first; link; link = link->next) {
-		if (link->data)
-			BKE_strands_free(link->data);
+		if (link->strands)
+			BKE_strands_free(link->strands);
 	}
 	BLI_freelistN(&data->strands);
 }
@@ -1385,16 +1397,40 @@ void BKE_dupli_object_data_set_mesh(DupliObjectData *data, DerivedMesh *dm)
 	dupli_cache_calc_boundbox(data);
 }
 
-void BKE_dupli_object_data_add_strands(DupliObjectData *data, Strands *strands)
+void BKE_dupli_object_data_add_strands(DupliObjectData *data, const char *name, Strands *strands)
 {
-	LinkData *link = MEM_callocN(sizeof(LinkData), "strands link");
-	link->data = strands;
+	DupliObjectDataStrands *link = NULL;
+	for (link = data->strands.first; link; link = link->next) {
+		if (STREQ(link->name, name))
+			break;
+	}
 	
-	BLI_addtail(&data->strands, link);
+	if (!link) {
+		link = MEM_callocN(sizeof(DupliObjectDataStrands), "strands link");
+		BLI_strncpy(link->name, name, sizeof(link->name));
+		link->strands = strands;
+		
+		BLI_addtail(&data->strands, link);
+	}
+	else {
+		if (link->strands && link->strands != strands)
+			BKE_strands_free(link->strands);
+		link->strands = strands;
+	}
 	
 	dupli_cache_calc_boundbox(data);
 }
 
+Strands *BKE_dupli_object_data_find_strands(DupliObjectData *data, const char *name)
+{
+	DupliObjectDataStrands *link;
+	for (link = data->strands.first; link; link = link->next) {
+		if (STREQ(link->name, name))
+			return link->strands;
+	}
+	return NULL;
+}
+
 /* ------------------------------------------------------------------------- */
 
 static void dupli_object_data_free(DupliObjectData *data)
@@ -1544,7 +1580,7 @@ void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachel
 							++scurve;
 						}
 						
-						BKE_dupli_object_data_add_strands(data, strands);
+						BKE_dupli_object_data_add_strands(data, psys->name, strands);
 					}
 				}
 			}
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 21244ec..e91aed5 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -19,6 +19,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_math.h"
+#include "BLI_string.h"
 
 #include "BKE_strands.h"
 
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index c805b0a..75556db 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2015,10 +2015,10 @@ static void draw_dupli_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base
 	draw_object(scene, ar, v3d, base, dflag);
 	
 	if (dob_data) {
-		LinkData *link;
+		DupliObjectDataStrands *link;
 		
 		for (link = dob_data->strands.first; link; link = link->next) {
-			struct Strands *strands = link->data;
+			struct Strands *strands = link->strands;
 			
 			draw_strands(scene, v3d, ar, base->object, strands, dflag);
 		}
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 7b91711..30676d8 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -333,6 +333,13 @@ typedef struct DupliObject {
 	struct DupliObjectData *data;
 } DupliObject;
 
+typedef struct DupliObjectDataStrands {
+	struct DupliObjectDataStrands *next, *prev;
+	
+	char name[64]; /* MAX_NAME */
+	struct Strands *strands;
+} DupliObjectDataStrands;
+
 /* data that can be shared by multiple DupliObject instances */
 typedef struct DupliObjectData {
 	/* XXX eventually it should be possible to construct dupli instances
diff --git a/source/blender/pointcache/alembic/abc_group.cpp b/source/blender/pointcache/alembic/abc_group.cpp
index 14fbc39..1cd9ee9 100644
--- a/source/blender/pointcache/alembic/abc_group.cpp
+++ b/source/blender/pointcache/alembic/abc_group.cpp
@@ -40,6 +40,7 @@ extern "C" {
 #include "BKE_global.h"
 #include "BKE_group.h"
 #include "BKE_library.h"
+#include "BKE_strands.h"
 }
 
 namespace PTC {
@@ -373,7 +374,9 @@ void AbcDupliCacheReader::read_dupligroup_object(IObject object, float frame)
 				}
 			}
 			else if (ICurvesSchema::matches(metadata)) {
-				AbcStrandsReader strands_reader;
+				Strands *strands = BKE_dupli_object_data_find_strands(dupli_data, child.getName().c_str());
+				
+				AbcStrandsReader strands_reader(strands);
 				strands_reader.init(abc_archive());
 				strands_reader.init_abc(child);
 				if (strands_reader.read_sample(frame) != PTC_READ_SAMPLE_INVALID) {
@@ -382,7 +385,12 @@ void AbcDupliCacheReader::read_dupligroup_object(IObject object, float frame)
 						insert_dupli_data(object.getPtr(), dupli_data);
 					}
 					
-					BKE_dupli_object_data_add_strands(dupli_data, strands_reader.acquire_result());
+					Strands *newstrands = strands_reader.acquire_result();
+					if (strands && strands != newstrands) {
+						/* reader can replace strands internally if topology does not match */
+						BKE_strands_free(strands);
+					}
+					BKE_dupli_object_data_add_strands(dupli_data, child.getName().c_str(), newstrands);
 				}
 				else {
 					strands_reader.discard_result();
@@ -495,6 +503,7 @@ void AbcDupliCacheReader::build_object_map_add_group(Group *group)
 AbcDupliObjectWriter::AbcDupliObjectWriter(const std::string &name, DupliObjectData *dupdata, bool do_mesh, bool do_strands) :
     ObjectWriter(dupdata->ob, name),
     m_dupdata(dupdata),
+    m_do_strands(do_strands),
     m_dm_writer(0)
 {
 	if (do_mesh) {
@@ -502,19 +511,28 @@ AbcDupliObjectWriter::AbcDupliObjectWriter(const std::string &name, DupliObjectD
 			m_dm_writer = new AbcDerivedMeshWriter("mesh", dupdata->ob, &dupdata->dm);
 		}
 	}
-	
-	if (do_strands) {
-		int index = 0;
-		for (LinkData *link = (LinkData *)dupdata->strands.first; link; link = link->next) {
-			Strands *strands = (Strands *)link->data;
-			if (strands) {
-				std::stringstream ss;
-				ss << "strands" << index;
-				m_strands_writers.push_back(new AbcStrandsWriter(ss.str(), strands));
-				
-				++index;
-			}
-		}
+}
+
+AbcStrandsWriter *AbcDupliObjectWriter::find_strands_writer(const std::string &name) const
+{
+	StrandsWriters::const_iterator it = m_strands_writers.find(name);
+	return (it != m_strands_writers.end()) ? it->second : NULL;
+}
+
+AbcStrandsWriter *AbcDupliObjectWriter::add_strands_writer(const std::string &name)
+{
+	StrandsWriters::const_iterator it = m_strands_writers.find(name);
+	if (it != m_strands_writers.end()) {
+		return it->second;
+	}
+	else {
+		AbcStrandsWriter *writer = new AbcStrandsWriter(name, m_dupdata);
+		m_strands_writers.insert(StrandsWritersPair(name, writer));
+		
+		writer->init(abc_archive());
+		writer->init_abc(m_abc_object);
+		
+		return writer;
 	}
 }
 
@@ -522,9 +540,10 @@ AbcDupliObjectWriter::~AbcDupliObjectWriter()
 {
 	if (m_dm_writer)
 		delete m_dm_writer;
-	for (int i = 0; i < m_strands_writers.size(); ++i)
-		if (m_strands_writers[i])
-			delete m_strands_writers[i];
+	for (StrandsWriters::iterator it =

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list