[Bf-blender-cvs] [b01037b] alembic_pointcache: Take cache library items into account when baking caches.

Lukas Tönne noreply at git.blender.org
Fri Mar 20 15:41:48 CET 2015


Commit: b01037b81d0969b977d136b59572d78c4015e6f4
Author: Lukas Tönne
Date:   Fri Mar 20 15:40:51 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rBb01037b81d0969b977d136b59572d78c4015e6f4

Take cache library items into account when baking caches.

This means we don't bluntly store all the data in a group, but use the
selection from the cache library. It also helps to avoid issues with
object visibility which is not yet stored in the cache.

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

M	source/blender/editors/io/io_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/abc_object.cpp
M	source/blender/pointcache/alembic/abc_object.h
M	source/blender/pointcache/alembic/alembic.cpp
M	source/blender/pointcache/intern/ptc_types.h

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

diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 7ea59e1..c1be8cb 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -268,7 +268,7 @@ static void cache_library_bake_do(CacheLibraryBakeJob *data, short *stop, short
 	if ((*stop) || (G.is_break))
 		return;
 	
-	data->writer = PTC_writer_dupligroup(data->group->id.name, &data->eval_ctx, scene, data->group);
+	data->writer = PTC_writer_dupligroup(data->group->id.name, &data->eval_ctx, scene, data->group, data->cachelib);
 	PTC_writer_init(data->writer, data->archive);
 	
 	/* XXX where to get this from? */
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index 69fa21a..30ac05a 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -213,9 +213,9 @@ char *PTC_get_archive_info(PTCReaderArchive *_archive)
 }
 
 
-PTCWriter *PTC_writer_dupligroup(const char *name, struct EvaluationContext *eval_ctx, struct Scene *scene, struct Group *group)
+PTCWriter *PTC_writer_dupligroup(const char *name, struct EvaluationContext *eval_ctx, struct Scene *scene, struct Group *group, struct CacheLibrary *cachelib)
 {
-	return (PTCWriter *)PTC::Factory::alembic->create_writer_dupligroup(name, eval_ctx, scene, group);
+	return (PTCWriter *)PTC::Factory::alembic->create_writer_dupligroup(name, eval_ctx, scene, group, cachelib);
 }
 
 PTCReader *PTC_reader_duplicache(const char *name, struct Group *group, struct DupliCache *dupcache)
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 88542e0..03063c0 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -87,7 +87,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);
+struct PTCWriter *PTC_writer_dupligroup(const char *name, struct EvaluationContext *eval_ctx, struct Scene *scene, struct Group *group, struct CacheLibrary *cachelib);
 struct PTCReader *PTC_reader_duplicache(const char *name, struct Group *group, struct DupliCache *dupcache);
 struct PTCReader *PTC_reader_duplicache_object(const char *name, struct Object *ob, struct DupliObjectData *data);
 
diff --git a/source/blender/pointcache/alembic/abc_group.cpp b/source/blender/pointcache/alembic/abc_group.cpp
index 8722f40..1f137fb 100644
--- a/source/blender/pointcache/alembic/abc_group.cpp
+++ b/source/blender/pointcache/alembic/abc_group.cpp
@@ -34,6 +34,7 @@ extern "C" {
 #include "DNA_object_types.h"
 
 #include "BKE_anim.h"
+#include "BKE_cache_library.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
 #include "BKE_library.h"
@@ -100,10 +101,11 @@ PTCReadSampleResult AbcGroupReader::read_sample(float frame)
 
 /* ========================================================================= */
 
-AbcDupligroupWriter::AbcDupligroupWriter(const std::string &name, EvaluationContext *eval_ctx, Scene *scene, Group *group) :
+AbcDupligroupWriter::AbcDupligroupWriter(const std::string &name, EvaluationContext *eval_ctx, Scene *scene, Group *group, CacheLibrary *cachelib) :
     GroupWriter(group, name),
     m_eval_ctx(eval_ctx),
-    m_scene(scene)
+    m_scene(scene),
+    m_cachelib(cachelib)
 {
 }
 
@@ -123,11 +125,21 @@ void AbcDupligroupWriter::init_abc()
 	m_abc_group = abc_archive()->add_id_object<OObject>((ID *)m_group);
 }
 
+static bool do_cache_type(CacheLibrary *cachelib, Object *ob, int type, int index=-1)
+{
+	CacheItem *item = BKE_cache_library_find_item(cachelib, ob, type, index);
+	return item && (item->flag & CACHE_ITEM_ENABLED);
+}
+
 void AbcDupligroupWriter::write_sample_object(Object *ob)
 {
 	AbcWriter *ob_writer = find_id_writer((ID *)ob);
 	if (!ob_writer) {
-		ob_writer = new AbcObjectWriter(ob->id.name, m_scene, ob);
+		bool do_mesh = do_cache_type(m_cachelib, ob, CACHE_TYPE_DERIVED_MESH);
+//		bool do_hair = do_cache_type(m_cachelib, ob, CACHE_TYPE_HAIR, ); // TODO
+		bool do_hair = false;
+		
+		ob_writer = new AbcObjectWriter(ob->id.name, m_scene, ob, do_mesh, do_hair);
 		ob_writer->init(abc_archive());
 		m_id_writers.insert(IDWriterPair((ID *)ob, ob_writer));
 	}
diff --git a/source/blender/pointcache/alembic/abc_group.h b/source/blender/pointcache/alembic/abc_group.h
index 5818eba..688f1c5 100644
--- a/source/blender/pointcache/alembic/abc_group.h
+++ b/source/blender/pointcache/alembic/abc_group.h
@@ -25,6 +25,7 @@
 #include "abc_schema.h"
 #include "abc_writer.h"
 
+struct CacheLibrary;
 struct DupliCache;
 struct DupliObject;
 struct DupliObjectData;
@@ -69,7 +70,7 @@ public:
 	typedef std::map<ID*, AbcWriter*> IDWriterMap;
 	typedef std::pair<ID*, AbcWriter*> IDWriterPair;
 	
-	AbcDupligroupWriter(const std::string &name, EvaluationContext *eval_ctx, Scene *scene, Group *group);
+	AbcDupligroupWriter(const std::string &name, EvaluationContext *eval_ctx, Scene *scene, Group *group, CacheLibrary *cachelib);
 	~AbcDupligroupWriter();
 	
 	void init_abc();
@@ -83,6 +84,7 @@ public:
 private:
 	EvaluationContext *m_eval_ctx;
 	Scene *m_scene;
+	CacheLibrary *m_cachelib;
 	
 	Abc::OObject m_abc_group;
 	ObjectWriterList m_object_writers;
diff --git a/source/blender/pointcache/alembic/abc_object.cpp b/source/blender/pointcache/alembic/abc_object.cpp
index 3a36fb2..a188a13 100644
--- a/source/blender/pointcache/alembic/abc_object.cpp
+++ b/source/blender/pointcache/alembic/abc_object.cpp
@@ -31,12 +31,15 @@ namespace PTC {
 using namespace Abc;
 using namespace AbcGeom;
 
-AbcObjectWriter::AbcObjectWriter(const std::string &name, Scene *scene, Object *ob) :
+AbcObjectWriter::AbcObjectWriter(const std::string &name, Scene *scene, Object *ob, bool do_mesh, bool do_hair) :
     ObjectWriter(ob, name),
     m_scene(scene),
     m_final_dm(NULL),
-    m_dm_writer("mesh", ob, &m_final_dm)
+    m_dm_writer("mesh", ob, &m_final_dm),
+    m_do_mesh(do_mesh),
+    m_do_hair(do_hair)
 {
+	m_do_mesh &= m_ob->type == OB_MESH;
 }
 
 void AbcObjectWriter::init_abc()
@@ -46,9 +49,15 @@ void AbcObjectWriter::init_abc()
 	
 	m_abc_object = abc_archive()->add_id_object<OObject>((ID *)m_ob);
 	
-	/* XXX not nice */
-	m_dm_writer.init(abc_archive());
-	m_dm_writer.init_abc(m_abc_object);
+	if (m_do_mesh) {
+		/* XXX not nice */
+		m_dm_writer.init(abc_archive());
+		m_dm_writer.init_abc(m_abc_object);
+	}
+	
+	if (m_do_hair) {
+		/* TODO */
+	}
 }
 
 #if 0
@@ -67,7 +76,7 @@ void AbcObjectWriter::write_sample()
 	if (!m_abc_object)
 		return;
 	
-	if (m_ob->type == OB_MESH) {
+	if (m_do_mesh) {
 		if (abc_archive()->use_render()) {
 			m_final_dm = mesh_create_derived_render(m_scene, m_ob, CD_MASK_BAREMESH);
 			
diff --git a/source/blender/pointcache/alembic/abc_object.h b/source/blender/pointcache/alembic/abc_object.h
index 3624b52..3b65f46 100644
--- a/source/blender/pointcache/alembic/abc_object.h
+++ b/source/blender/pointcache/alembic/abc_object.h
@@ -39,7 +39,7 @@ namespace PTC {
 
 class AbcObjectWriter : public ObjectWriter, public AbcWriter {
 public:
-	AbcObjectWriter(const std::string &name, Scene *scene, Object *ob);
+	AbcObjectWriter(const std::string &name, Scene *scene, Object *ob, bool do_mesh, bool do_hair);
 	
 	void init_abc();
 #if 0
@@ -54,6 +54,8 @@ private:
 	
 	Abc::OObject m_abc_object;
 	AbcDerivedMeshWriter m_dm_writer;
+	
+	bool m_do_mesh, m_do_hair;
 };
 
 class AbcObjectReader : public ObjectReader, public AbcReader {
diff --git a/source/blender/pointcache/alembic/alembic.cpp b/source/blender/pointcache/alembic/alembic.cpp
index 0acb9e3..1781835 100644
--- a/source/blender/pointcache/alembic/alembic.cpp
+++ b/source/blender/pointcache/alembic/alembic.cpp
@@ -49,7 +49,7 @@ class AbcFactory : public Factory {
 	
 	Writer *create_writer_object(const std::string &name, Scene *scene, Object *ob)
 	{
-		return new AbcObjectWriter(name, scene, ob);
+		return new AbcObjectWriter(name, scene, ob, true, true);
 	}
 
 	Reader *create_reader_object(const std::string &name, Object *ob)
@@ -152,9 +152,9 @@ class AbcFactory : public Factory {
 	}
 	
 	
-	Writer *create_writer_dupligroup(const std::string &name, EvaluationContext *eval_ctx, Scene *scene, Group *group)
+	Writer *create_writer_dupligroup(const std::string &name, EvaluationContext *eval_ctx, Scene *scene, Group *group, CacheLibrary *cachelib)
 	{
-		return new AbcDupligroupWriter(name, eval_ctx, scene, group);
+		return new AbcDupligroupWriter(name, eval_ctx, scene, group, cachelib);
 	}
 	
 	Reader *create_reader_duplicache(const std::string &name, Group *group, DupliCache *dupcache)
diff --git a/source/blender/pointcache/intern/ptc_types.h b/source/blender/pointcache/intern/ptc_types.h
index 856b63f..aa2d8d0 100644
--- a/source/blender/pointcache/intern/ptc_types.h
+++ b/source/blender/pointcache/intern/ptc_types.h
@@ -30,6 +30,8 @@ extern "C" {
 #include "DNA_particle_types.h"
 }
 
+struct CacheLibrary;
+
 namespace PTC {
 
 class ClothWriter {
@@ -226,7 +228,7 @@ struct Factory {
 	virtual Writer *create_writer_cache_modifier_realtime(const std::string &name, Object *ob, CacheModifierData *cmd) = 0;
 	virtual Writer *create_writer_cache_modifier_render(const std::string &name, Scene *scene, Object *ob, CacheModifierData *cmd) = 0;
 	
-	virtual Writer *create_writer_dupligroup(const std::string &name, EvaluationContext *eval_ctx, Scene *scene, Group *group) = 0;
+	virtual Writer *create_writer_dupligroup(const std::string &name, EvaluationContext *eval_ctx, Scene *scene, Group *group, CacheLibrary *cachelib) = 0;
 	virtual Reader *create_reader_duplicache(const std::string &name, Group *group, DupliCache *dupcache) = 0;
 	virtual Reader *create_reader_duplicache_object(const std::string &name, Object *ob, DupliObjectData *data) = 0;




More information about the Bf-blender-cvs mailing list