[Bf-blender-cvs] [d75dcf8] alembic_pointcache: Store object pointers for the dupli objects we generate from caches.

Lukas Tönne noreply at git.blender.org
Thu Mar 12 17:05:53 CET 2015


Commit: d75dcf88d2e713df87266b35f67c5fc98423ac22
Author: Lukas Tönne
Date:   Thu Mar 12 16:40:18 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rBd75dcf88d2e713df87266b35f67c5fc98423ac22

Store object pointers for the dupli objects we generate from caches.

This is necessary for the current viewport drawing and rendering code,
which expected each dupli instance to represent a copy of data in the
DNA.

The code maps base-level objects in the cache to DNA Objects inside the
dupligroup by name. Only objects that can be found in the blend data
will be allowed for DupliObjects.

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

M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/pointcache/alembic/abc_group.cpp

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

diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 65a0ea8..4f3f6e2 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -79,7 +79,7 @@ int count_duplilist(struct Object *ob);
 void BKE_object_dupli_cache_update(struct Scene *scene, struct Object *ob, struct EvaluationContext *eval_ctx);
 void BKE_object_dupli_cache_clear(struct Object *ob);
 
-struct DupliObjectData *BKE_dupli_cache_add_mesh(struct DupliCache *dupcache, struct DerivedMesh *dm);
+struct DupliObjectData *BKE_dupli_cache_add_mesh(struct DupliCache *dupcache, struct Object *ob, struct DerivedMesh *dm);
 void BKE_dupli_cache_add_instance(struct DupliCache *dupcache, float obmat[4][4], struct DupliObjectData *data);
 
 typedef struct DupliExtraData {
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 033f058..ebe9b83 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1362,10 +1362,11 @@ void BKE_object_dupli_cache_clear(Object *ob)
 	}
 }
 
-DupliObjectData *BKE_dupli_cache_add_mesh(DupliCache *dupcache, DerivedMesh *dm)
+DupliObjectData *BKE_dupli_cache_add_mesh(DupliCache *dupcache, Object *ob, DerivedMesh *dm)
 {
 	DupliObjectData *data = dupli_cache_add_object_data(dupcache);
 	
+	data->ob = ob;
 	data->cache_dm = dm;
 	
 	return data;
@@ -1378,7 +1379,7 @@ void BKE_dupli_cache_add_instance(DupliCache *dupcache, float obmat[4][4], Dupli
 	/* data must have been created correctly */
 	BLI_assert(dupli_cache_contains_object_data(dupcache, data));
 	
-	dob->ob = NULL;
+	dob->ob = data->ob;
 	copy_m4_m4(dob->mat, obmat);
 	
 	dob->data = data;
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 8dc95c0..146fe71 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -335,6 +335,11 @@ typedef struct DupliObject {
 
 /* data that can be shared by multiple DupliObject instances */
 typedef struct DupliObjectData {
+	/* XXX eventually it should be possible to construct dupli instances
+	 * entirely without Objects in the DNA, but current drawing code and
+	 * others make this too difficult
+	 */
+	struct Object *ob;
 	struct DerivedMesh *cache_dm;
 } DupliObjectData;
 
diff --git a/source/blender/pointcache/alembic/abc_group.cpp b/source/blender/pointcache/alembic/abc_group.cpp
index 12b3fa8..80b319f 100644
--- a/source/blender/pointcache/alembic/abc_group.cpp
+++ b/source/blender/pointcache/alembic/abc_group.cpp
@@ -32,7 +32,9 @@ extern "C" {
 #include "DNA_object_types.h"
 
 #include "BKE_anim.h"
+#include "BKE_global.h"
 #include "BKE_group.h"
+#include "BKE_library.h"
 }
 
 namespace PTC {
@@ -120,8 +122,8 @@ struct DupliGroupContext {
 	};
 	typedef std::vector<Transform> TransformStack;
 	
-	DupliMap dupli_map;
-	DupliCache *dupli_cache;
+	typedef std::map<std::string, Object*> ObjectMap;
+	typedef std::pair<std::string, Object*> ObjectPair;
 	
 	/* constructor */
 	DupliGroupContext(DupliCache *dupli_cache) :
@@ -130,6 +132,7 @@ struct DupliGroupContext {
 		tfm_stack.push_back(Transform(I));
 	}
 	
+	
 	DupliObjectData *find_dupli_data(ObjectReaderPtr ptr) const
 	{
 		DupliMap::const_iterator it = dupli_map.find(ptr);
@@ -144,10 +147,55 @@ struct DupliGroupContext {
 		dupli_map.insert(DupliPair(ptr, data));
 	}
 	
-	TransformStack tfm_stack;
 	
 	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);
+			}
+		}
+	}
 };
 
 static void read_dupligroup_object(DupliGroupContext &ctx, IObject object, float frame)
@@ -157,9 +205,13 @@ static void read_dupligroup_object(DupliGroupContext &ctx, IObject object, float
 		if (object.isInstanceDescendant())
 			return;
 		
+		Object *b_ob = ctx.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, dm);
+		DupliObjectData *data = BKE_dupli_cache_add_mesh(ctx.dupli_cache, b_ob, dm);
 		ctx.insert_dupli_data(object.getPtr(), data);
 	}
 }
@@ -199,6 +251,12 @@ PTCReadSampleResult abc_read_dupligroup(ReaderArchive *_archive, float frame, Gr
 	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);
+	
 	IObject top = archive->archive.getTop();
 	size_t num_child = top.getNumChildren();




More information about the Bf-blender-cvs mailing list