[Bf-blender-cvs] [3b83c58] gooseberry: Store and apply dupli object transforms in the Alembic cache.

Lukas Tönne noreply at git.blender.org
Mon Mar 23 13:03:36 CET 2015


Commit: 3b83c585e23f09e4d956cbb3ad6c4b35081ed47e
Author: Lukas Tönne
Date:   Sat Mar 14 15:58:02 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB3b83c585e23f09e4d956cbb3ad6c4b35081ed47e

Store and apply dupli object transforms in the Alembic cache.

Note that the cache stores dupli matrices without the final parent
transform, since it only knows about the group itself. The duplicator
obmat is applied to the duplis after reading the cache.

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

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

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

diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 5b83e35..b8695d4 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1240,9 +1240,19 @@ ListBase *object_duplilist_ex(EvaluationContext *eval_ctx, Scene *scene, Object
 #endif
 	
 	if (ob->dup_cache) {
-		/* XXX current use of duplilist expects a one-time list copy */
+		/* Note: duplis in the cache don't have the main duplicator obmat applied.
+		 * duplilist also should return a full copy of duplis, so we copy
+		 * the cached list and apply the obmat to each.
+		 */
 		ListBase *duplilist = MEM_callocN(sizeof(ListBase), "duplilist");
+		DupliObject *dob;
+		
 		BLI_duplicatelist(duplilist, &ob->dup_cache->duplilist);
+		
+		for (dob = duplilist->first; dob; dob = dob->next) {
+			mul_m4_m4m4(dob->mat, ob->obmat, dob->mat);
+		}
+		
 		return duplilist;
 	}
 	else {
diff --git a/source/blender/pointcache/alembic/abc_group.cpp b/source/blender/pointcache/alembic/abc_group.cpp
index 65e807e..142e3c9 100644
--- a/source/blender/pointcache/alembic/abc_group.cpp
+++ b/source/blender/pointcache/alembic/abc_group.cpp
@@ -21,6 +21,7 @@
 #include <string>
 
 #include <Alembic/Abc/IObject.h>
+#include <Alembic/Abc/OObject.h>
 
 #include "abc_mesh.h"
 #include "abc_group.h"
@@ -152,14 +153,25 @@ void AbcDupligroupWriter::write_sample_dupli(DupliObject *dob, int index)
 	std::string name = ss.str();
 	
 	OObject abc_dupli = m_abc_group.getChild(name);
+	OCompoundProperty props;
+	OM44fProperty prop_matrix;
 	if (!abc_dupli) {
 		abc_dupli = OObject(m_abc_group, name, 0);
-		m_writers.push_back(abc_dupli.getPtr());
+		m_object_writers.push_back(abc_dupli.getPtr());
+		props = abc_dupli.getProperties();
 		
 		abc_dupli.addChildInstance(abc_object, "object");
 		
-		// TODO dupli offset, layers, etc.
+		prop_matrix = OM44fProperty(props, "matrix", 0);
+		m_property_writers.push_back(prop_matrix.getPtr());
 	}
+	else {
+		props = abc_dupli.getProperties();
+		
+		prop_matrix = OM44fProperty(props.getProperty("matrix").getPtr()->asScalarPtr(), kWrapExisting);
+	}
+	
+	prop_matrix.set(M44f(dob->mat));
 }
 
 void AbcDupligroupWriter::write_sample()
@@ -300,7 +312,7 @@ protected:
 	}
 };
 
-static void read_dupligroup_object(DupliGroupContext &ctx, IObject object, float frame)
+static void read_dupligroup_object(DupliGroupContext &ctx, IObject object, const ISampleSelector &ss)
 {
 	if (GS(object.getName().c_str()) == ID_OB) {
 		/* instances are handled later, we create true object data here */
@@ -318,21 +330,25 @@ static void read_dupligroup_object(DupliGroupContext &ctx, IObject object, float
 	}
 }
 
-static void read_dupligroup_group(DupliGroupContext &ctx, IObject abc_group, float frame)
+static void read_dupligroup_group(DupliGroupContext &ctx, IObject abc_group, const ISampleSelector &ss)
 {
 	if (GS(abc_group.getName().c_str()) == ID_GR) {
 		size_t num_child = abc_group.getNumChildren();
 		
 		for (size_t i = 0; i < num_child; ++i) {
 			IObject abc_dupli = abc_group.getChild(i);
+			ICompoundProperty props = abc_dupli.getProperties();
 			
-			// TODO dupli offset, layers, etc.
+			IM44fProperty prop_matrix(props, "matrix", 0);
+			M44f abc_matrix = prop_matrix.getValue(ss);
+			float matrix[4][4];
+			memcpy(matrix, abc_matrix.getValue(), sizeof(float)*4*4);
 			
 			IObject abc_dupli_object = abc_dupli.getChild("object");
 			if (abc_dupli_object.isInstanceRoot()) {
 				DupliObjectData *dupli_data = ctx.find_dupli_data(abc_dupli_object.getPtr());
 				if (dupli_data) {
-					BKE_dupli_cache_add_instance(ctx.dupli_cache, ctx.get_transform(), dupli_data);
+					BKE_dupli_cache_add_instance(ctx.dupli_cache, matrix, dupli_data);
 				}
 			}
 		}
@@ -350,6 +366,8 @@ PTCReadSampleResult abc_read_dupligroup(ReaderArchive *_archive, float frame, Gr
 	 */
 	ctx.build_object_map(G.main, dupgroup);
 	
+	ISampleSelector ss = archive->get_frame_sample_selector(frame);
+	
 	IObject abc_top = archive->archive.getTop();
 	IObject abc_group = archive->get_id_object((ID *)dupgroup);
 	if (!abc_group)
@@ -357,11 +375,11 @@ PTCReadSampleResult abc_read_dupligroup(ReaderArchive *_archive, float frame, Gr
 	
 	/* first create shared object data */
 	for (size_t i = 0; i < abc_top.getNumChildren(); ++i) {
-		read_dupligroup_object(ctx, abc_top.getChild(i), frame);
+		read_dupligroup_object(ctx, abc_top.getChild(i), ss);
 	}
 	
 	/* now generate dupli instances for the dupgroup */
-	read_dupligroup_group(ctx, abc_group, frame);
+	read_dupligroup_group(ctx, abc_group, ss);
 	
 	return PTC_READ_SAMPLE_EXACT;
 }
diff --git a/source/blender/pointcache/alembic/abc_group.h b/source/blender/pointcache/alembic/abc_group.h
index 594b624..92f28a3 100644
--- a/source/blender/pointcache/alembic/abc_group.h
+++ b/source/blender/pointcache/alembic/abc_group.h
@@ -19,9 +19,6 @@
 #ifndef PTC_ABC_GROUP_H
 #define PTC_ABC_GROUP_H
 
-#include <Alembic/AbcGeom/IXform.h>
-#include <Alembic/AbcGeom/OXform.h>
-
 #include "ptc_types.h"
 
 #include "abc_reader.h"
@@ -64,7 +61,8 @@ private:
 
 class AbcDupligroupWriter : public GroupWriter, public AbcWriter {
 public:
-	typedef std::vector<Abc::ObjectWriterPtr> WriterList;
+	typedef std::vector<Abc::ObjectWriterPtr> ObjectWriterList;
+	typedef std::vector<Abc::BasePropertyWriterPtr> PropertyWriterList;
 	
 	typedef std::map<ID*, Writer*> IDWriterMap;
 	typedef std::pair<ID*, Writer*> IDWriterPair;
@@ -85,7 +83,8 @@ private:
 	Scene *m_scene;
 	
 	Abc::OObject m_abc_group;
-	WriterList m_writers;
+	ObjectWriterList m_object_writers;
+	PropertyWriterList m_property_writers;
 	IDWriterMap m_id_writers;
 };




More information about the Bf-blender-cvs mailing list