[Bf-blender-cvs] [7677f39] alembic_pointcache: Moved the dupli cache reading code into a AbcDupligroupReader class.

Lukas Tönne noreply at git.blender.org
Sat Mar 14 17:43:42 CET 2015


Commit: 7677f393b43a8d1feb7f81397b14e6f7d60c9e35
Author: Lukas Tönne
Date:   Sat Mar 14 17:39:57 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB7677f393b43a8d1feb7f81397b14e6f7d60c9e35

Moved the dupli cache reading code into a AbcDupligroupReader class.

This is more in line with how readers work in the Blender Alembic
implementation elsewhere.

Generally, readers are less persistent than writers: they are created
whenever cache results need to be updated (e.g. on frame changes) and
discarded afterward. Writers OTOH stay alive during the whole baking
job, since they keep the references to Alembic Writer instances and can
only be deleted once the writing for that part is done.

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

M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/alembic/abc_group.cpp
M	source/blender/pointcache/alembic/abc_group.h
M	source/blender/pointcache/alembic/alembic.cpp
M	source/blender/pointcache/intern/ptc_types.h

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

diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 1f4ed63..0b63ad5 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -1229,13 +1229,18 @@ bool BKE_cache_read_dupligroup(Main *bmain, Scene *scene, float frame, eCacheLib
 		if (cachelib->group == dupgroup) {
 			char filename[FILE_MAX];
 			struct PTCReaderArchive *archive;
+			struct PTCReader *reader;
 			eCacheReadSampleResult result;
 			
 			BKE_cache_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
 			archive = PTC_open_reader_archive(scene, filename);
 			
-			result = BKE_cache_read_result(PTC_read_dupligroup(archive, frame, dupgroup, dupcache));
+			reader = PTC_reader_dupligroup(dupgroup->id.name, dupgroup, dupcache);
+			PTC_reader_set_archive(reader, archive);
 			
+			result = BKE_cache_read_result(PTC_read_sample(reader, frame));
+			
+			PTC_reader_free(reader);
 			PTC_close_reader_archive(archive);
 			
 			return true;
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index 810bb32..b2a9a56 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -216,9 +216,9 @@ PTCWriter *PTC_writer_dupligroup(const char *name, struct EvaluationContext *eva
 	return (PTCWriter *)PTC::Factory::alembic->create_writer_dupligroup(name, eval_ctx, scene, group);
 }
 
-PTCReadSampleResult PTC_read_dupligroup(PTCReaderArchive *archive, float frame, Group *dupgroup, DupliCache *dupcache)
+PTCReader *PTC_reader_dupligroup(const char *name, struct Group *group, struct DupliCache *dupcache)
 {
-	return PTC::Factory::alembic->read_dupligroup((PTC::ReaderArchive *)archive, frame, dupgroup, dupcache);
+	return (PTCReader *)PTC::Factory::alembic->create_reader_dupligroup(name, group, dupcache);
 }
 
 
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 18c975a..105dabb 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -86,7 +86,7 @@ PTCReadSampleResult PTC_test_sample(struct PTCReader *reader, float frame);
 char *PTC_get_archive_info(struct PTCReaderArchive *archive);
 
 struct PTCWriter *PTC_writer_dupligroup(const char *name, struct EvaluationContext *eval_ctx, struct Scene *scene, struct Group *group);
-PTCReadSampleResult PTC_read_dupligroup(struct PTCReaderArchive *archive, float frame, struct Group *dupgroup, struct DupliCache *dupcache);
+struct PTCReader *PTC_reader_dupligroup(const char *name, struct Group *group, struct DupliCache *dupcache);
 
 /* get writer/reader from RNA type */
 struct PTCWriter *PTC_writer_from_rna(struct Scene *scene, struct PointerRNA *ptr);
diff --git a/source/blender/pointcache/alembic/abc_group.cpp b/source/blender/pointcache/alembic/abc_group.cpp
index 142e3c9..b2be672 100644
--- a/source/blender/pointcache/alembic/abc_group.cpp
+++ b/source/blender/pointcache/alembic/abc_group.cpp
@@ -217,120 +217,46 @@ Writer *AbcDupligroupWriter::find_id_writer(ID *id) const
 
 /* ------------------------------------------------------------------------- */
 
-typedef float Matrix[4][4];
-
-typedef float (*MatrixPtr)[4];
+AbcDupligroupReader::AbcDupligroupReader(const std::string &name, Group *group, DupliCache *dupli_cache) :
+    GroupReader(group, name),
+    dupli_cache(dupli_cache)
+{
+	/* XXX this mapping allows fast lookup of existing objects in Blender data
+	 * to associate with duplis. Later i may be possible to create instances of
+	 * non-DNA data, but for the time being this is a requirement due to other code parts (drawing, rendering)
+	 */
+	build_object_map(G.main, group);
+}
 
-static Matrix I = {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}};
+AbcDupligroupReader::~AbcDupligroupReader()
+{
+}
 
-struct DupliGroupContext {
-	typedef std::map<ObjectReaderPtr, DupliObjectData*> DupliMap;
-	typedef std::pair<ObjectReaderPtr, DupliObjectData*> DupliPair;
-	
-	struct Transform {
-		Transform() {}
-		Transform(float (*value)[4]) { copy_m4_m4(matrix, value); }
-		Transform(const Transform &tfm) { memcpy(matrix, tfm.matrix, sizeof(Matrix)); }
-		
-		Matrix matrix;
-	};
-	typedef std::vector<Transform> TransformStack;
-	
-	typedef std::map<std::string, Object*> ObjectMap;
-	typedef std::pair<std::string, Object*> ObjectPair;
-	
-	/* constructor */
-	DupliGroupContext(DupliCache *dupli_cache) :
-	    dupli_cache(dupli_cache)
-	{
-		tfm_stack.push_back(Transform(I));
-	}
-	
-	
-	DupliObjectData *find_dupli_data(ObjectReaderPtr ptr) const
-	{
-		DupliMap::const_iterator it = dupli_map.find(ptr);
-		if (it == dupli_map.end())
-			return NULL;
-		else
-			return it->second;
-	}
-	
-	void insert_dupli_data(ObjectReaderPtr ptr, DupliObjectData *data)
-	{
-		dupli_map.insert(DupliPair(ptr, data));
-	}
-	
-	
-	MatrixPtr get_transform() { return tfm_stack.back().matrix; }
-//	void push_transform(float mat[4][4])
-	
-	
-	void build_object_map(Main *bmain, Group *group)
-	{
-		BKE_main_id_tag_idcode(bmain, ID_OB, false);
-		BKE_main_id_tag_idcode(bmain, ID_GR, false);
-		object_map.clear();
-		
-		build_object_map_add_group(group);
-	}
-	
-	Object *find_object(const std::string &name) const
-	{
-		ObjectMap::const_iterator it = object_map.find(name);
-		if (it == object_map.end())
-			return NULL;
-		else
-			return it->second;
-	}
-	
-	DupliMap dupli_map;
-	DupliCache *dupli_cache;
-	
-	TransformStack tfm_stack;
-	
-	ObjectMap object_map;
-	
-protected:
-	void build_object_map_add_group(Group *group)
-	{
-		if (group->id.flag & LIB_DOIT)
-			return;
-		group->id.flag |= LIB_DOIT;
-		
-		for (GroupObject *gob = (GroupObject *)group->gobject.first; gob; gob = gob->next) {
-			Object *ob = gob->ob;
-			if (ob->id.flag & LIB_DOIT)
-				continue;
-			ob->id.flag |= LIB_DOIT;
-			object_map.insert(ObjectPair(ob->id.name, ob));
-			
-			if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) {
-				build_object_map_add_group(ob->dup_group);
-			}
-		}
-	}
-};
+void AbcDupligroupReader::open_archive(ReaderArchive *archive)
+{
+	BLI_assert(dynamic_cast<AbcReaderArchive*>(archive));
+	AbcReader::abc_archive(static_cast<AbcReaderArchive*>(archive));
+}
 
-static void read_dupligroup_object(DupliGroupContext &ctx, IObject object, const ISampleSelector &ss)
+void AbcDupligroupReader::read_dupligroup_object(IObject object, const ISampleSelector &ss)
 {
 	if (GS(object.getName().c_str()) == ID_OB) {
 		/* instances are handled later, we create true object data here */
 		if (object.isInstanceDescendant())
 			return;
 		
-		Object *b_ob = ctx.find_object(object.getName());
+		Object *b_ob = find_object(object.getName());
 		if (!b_ob)
 			return;
 		
 		/* TODO load DM, from subobjects for IPolyMesh etc. */
 		DerivedMesh *dm = NULL;
-		DupliObjectData *data = BKE_dupli_cache_add_mesh(ctx.dupli_cache, b_ob, dm);
-		ctx.insert_dupli_data(object.getPtr(), data);
+		DupliObjectData *data = BKE_dupli_cache_add_mesh(dupli_cache, b_ob, dm);
+		insert_dupli_data(object.getPtr(), data);
 	}
 }
 
-static void read_dupligroup_group(DupliGroupContext &ctx, IObject abc_group, const ISampleSelector &ss)
+void AbcDupligroupReader::read_dupligroup_group(IObject abc_group, const ISampleSelector &ss)
 {
 	if (GS(abc_group.getName().c_str()) == ID_GR) {
 		size_t num_child = abc_group.getNumChildren();
@@ -346,42 +272,84 @@ static void read_dupligroup_group(DupliGroupContext &ctx, IObject abc_group, con
 			
 			IObject abc_dupli_object = abc_dupli.getChild("object");
 			if (abc_dupli_object.isInstanceRoot()) {
-				DupliObjectData *dupli_data = ctx.find_dupli_data(abc_dupli_object.getPtr());
+				DupliObjectData *dupli_data = find_dupli_data(abc_dupli_object.getPtr());
 				if (dupli_data) {
-					BKE_dupli_cache_add_instance(ctx.dupli_cache, matrix, dupli_data);
+					BKE_dupli_cache_add_instance(dupli_cache, matrix, dupli_data);
 				}
 			}
 		}
 	}
 }
 
-PTCReadSampleResult abc_read_dupligroup(ReaderArchive *_archive, float frame, Group *dupgroup, DupliCache *dupcache)
+PTCReadSampleResult AbcDupligroupReader::read_sample(float frame)
 {
-	AbcReaderArchive *archive = (AbcReaderArchive *)_archive;
-	DupliGroupContext ctx(dupcache);
-	
-	/* XXX this mapping allows fast lookup of existing objects in Blender data
-	 * to associate with duplis. Later i may be possible to create instances of
-	 * non-DNA data, but for the time being this is a requirement due to other code parts (drawing, rendering)
-	 */
-	ctx.build_object_map(G.main, dupgroup);
+	ISampleSelector ss = abc_archive()->get_frame_sample_selector(frame);
 	
-	ISampleSelector ss = archive->get_frame_sample_selector(frame);
-	
-	IObject abc_top = archive->archive.getTop();
-	IObject abc_group = archive->get_id_object((ID *)dupgroup);
+	IObject abc_top = abc_archive()->archive.getTop();
+	IObject abc_group = abc_archive()->get_id_object((ID *)m_group);
 	if (!abc_group)
 		return PTC_READ_SAMPLE_INVALID;
 	
 	/* first create shared object data */
 	for (size_t i = 0; i < abc_top.getNumChildren(); ++i) {
-		read_dupligroup_object(ctx, abc_top.getChild(i), ss);
+		read_dupligroup_object(abc_top.getChild(i), ss);
 	}
 	
-	/* now generate dupli instances for the dupgroup */
-	read_dupligroup_group(ctx, abc_group, ss);
+	/* now generate dupli instances for the group */
+	read_dupligroup_group(abc_group, ss);
 	
 	return PTC_READ_SAMPLE_EXACT;
 }
 
+DupliObjectData *AbcDupligroupReader::find_dupli_data(ObjectReaderPtr ptr) const
+{
+	DupliMap::const_iterator it = dupli_map.find(ptr);
+	if (it == dupli_map.end())
+		return NULL;
+	else
+		return it->second;
+}
+
+void AbcDupligroupReader::insert_dupli_data(ObjectReaderPtr ptr, DupliObjectData *data)
+{
+	dupli_map.insert(DupliPair(ptr, data));
+}
+
+void AbcDupligroupReader::build_object_map(Main *bmain, Group *group)
+{
+	BKE_main_id_tag_idcode(bmain, ID_OB, false);
+	BKE_main_id_tag_idcode(bmain, ID_GR, false);
+	object_map.clear();
+	
+	build_object_map_add_group(group);
+}
+
+Object *AbcDupligroupReader::find_object(const std::string &name) const
+{
+	ObjectMap::const_iterator it = object_map.find(name);
+	if (it

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list