[Bf-blender-cvs] [df36ca1] gooseberry: General support for export to/import from Alembic files based on Cache Libraries.

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


Commit: df36ca1ff706668f31524834dc0360d29ffc4e17
Author: Lukas Tönne
Date:   Tue Feb 24 20:54:21 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBdf36ca1ff706668f31524834dc0360d29ffc4e17

General support for export to/import from Alembic files based on Cache
Libraries.

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

M	release/scripts/startup/bl_ui/properties_scene.py
M	source/blender/editors/io/CMakeLists.txt
M	source/blender/editors/io/io_cache_library.c
M	source/blender/makesdna/DNA_cache_library_types.h
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/intern/export.cpp
M	source/blender/pointcache/intern/export.h

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

diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py
index 36d3143..a702b2a 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -413,7 +413,6 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
         item = cachelib.cache_item_find(ob, type, index)
         if not item:
             sub = layout.row()
-            sub.context_pointer_set("cache_library", cachelib)
             sub.context_pointer_set("cache_object", ob)
             props = sub.operator("cachelibrary.item_enable", text="", icon='ZOOMIN', emboss=True)
             props.type = type
@@ -462,6 +461,7 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
                     self.draw_cache_item(context, sub, cachelib, ob, 'HAIR', index)
                     self.draw_cache_item(context, sub, cachelib, ob, 'HAIR_PATHS', index)
 
+            layout.operator("cachelibrary.bake")
 
 
     def draw(self, context):
@@ -470,6 +470,8 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
         layout.operator("cachelibrary.new")
         for cachelib in context.blend_data.cache_libraries:
             box = layout.box()
+            box.context_pointer_set("cache_library", cachelib)
+            
             box.prop(cachelib, "filepath")
             box.template_ID(cachelib, "group")
             self.draw_cachelib(context, box, cachelib)
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index 6c455c2..c7d257a 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -26,6 +26,7 @@ set(INC
 	../../bmesh
 	../../makesdna
 	../../makesrna
+	../../pointcache
 	../../windowmanager
 	../../collada
 	../../../../intern/guardedalloc
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 7f0903f..2013a39 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -34,9 +34,11 @@
 #include "BLF_translation.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_listbase.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_cache_library_types.h"
+#include "DNA_listBase.h"
 #include "DNA_object_types.h"
 
 #include "BKE_depsgraph.h"
@@ -62,6 +64,8 @@
 
 #include "io_cache_library.h"
 
+#include "PTC_api.h"
+
 /********************** new cache library operator *********************/
 
 static int new_cachelib_exec(bContext *C, wmOperator *UNUSED(op))
@@ -179,6 +183,10 @@ typedef struct CacheLibraryBakeJob {
 	struct Main *bmain;
 	struct Scene *scene;
 	EvaluationContext eval_ctx;
+	struct CacheLibrary *cachelib;
+	
+	struct PTCWriterArchive *archive;
+	ListBase writers;
 	
 	int origfra;                            /* original frame to reset scene after export */
 	float origframelen;                     /* original frame length to reset scene after export */
@@ -208,10 +216,12 @@ static void cache_library_bake_startjob(void *customdata, short *stop, short *do
 	
 	G.is_break = false;
 	
+	data->archive = PTC_cachlib_writers(scene, data->cachelib, &data->writers);
+	
 	/* XXX where to get this from? */
 	start_frame = scene->r.sfra;
 	end_frame = scene->r.efra;
-//	PTC_bake(data->bmain, scene, &data->eval_ctx, data->writer, start_frame, end_frame, stop, do_update, progress);
+	PTC_bake(data->bmain, scene, &data->eval_ctx, &data->writers, start_frame, end_frame, stop, do_update, progress);
 	
 	*do_update = true;
 	*stop = 0;
@@ -225,18 +235,7 @@ static void cache_library_bake_endjob(void *customdata)
 	G.is_rendering = false;
 	BKE_spacedata_draw_locks(false);
 	
-#if 0
-	/* free the cache writer (closes output file) */
-	if (RNA_struct_is_a(data->user_ptr.type, &RNA_PointCacheModifier)) {
-		Object *ob = (Object *)data->user_ptr.id.data;
-		PointCacheModifierData *pcmd = (PointCacheModifierData *)data->user_ptr.data;
-		
-		PTC_mod_point_cache_set_mode(scene, ob, pcmd, MOD_POINTCACHE_MODE_NONE);
-	}
-	else {
-		PTC_writer_free(data->writer);
-	}
-#endif
+	PTC_cachlib_writers_free(data->archive, &data->writers);
 	
 	/* reset scene frame */
 	scene->r.cfra = data->origfra;
@@ -244,7 +243,7 @@ static void cache_library_bake_endjob(void *customdata)
 	BKE_scene_update_for_newframe(&data->eval_ctx, data->bmain, scene, scene->lay);
 }
 
-static int cache_library_bake_exec(bContext *C, wmOperator *op)
+static int cache_library_bake_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	CacheLibrary *cachelib = CTX_data_pointer_get_type(C, "cache_library", &RNA_CacheLibrary).data;
 	Main *bmain = CTX_data_main(C);
@@ -252,25 +251,6 @@ static int cache_library_bake_exec(bContext *C, wmOperator *op)
 	CacheLibraryBakeJob *data;
 	wmJob *wm_job;
 	
-#if 0
-	/* special case: point cache modifier uses internal writer
-	 * and needs to be set up for baking.
-	 */
-	if (RNA_struct_is_a(user_ptr.type, &RNA_PointCacheModifier)) {
-		Object *ob = (Object *)user_ptr.id.data;
-		PointCacheModifierData *pcmd = (PointCacheModifierData *)user_ptr.data;
-		
-		PTC_mod_point_cache_set_mode(scene, ob, pcmd, MOD_POINTCACHE_MODE_WRITE);
-	}
-	else {
-		writer = PTC_writer_from_rna(scene, &user_ptr);
-		if (!writer) {
-			BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT, "%s is not a valid point cache user type", RNA_struct_identifier(user_ptr.type));
-			return OPERATOR_CANCELLED;
-		}
-	}
-#endif
-	
 	/* XXX annoying hack: needed to prevent data corruption when changing
 	 * scene frame in separate threads
 	 */
@@ -288,8 +268,7 @@ static int cache_library_bake_exec(bContext *C, wmOperator *op)
 	data = MEM_callocN(sizeof(CacheLibraryBakeJob), "Cache Library Bake Job");
 	data->bmain = bmain;
 	data->scene = scene;
-//	data->cache = cache;
-//	data->writer = writer;
+	data->cachelib = cachelib;
 	
 	WM_jobs_customdata_set(wm_job, data, cache_library_bake_freejob);
 	WM_jobs_timer(wm_job, 0.1, NC_SCENE|ND_FRAME, NC_SCENE|ND_FRAME);
diff --git a/source/blender/makesdna/DNA_cache_library_types.h b/source/blender/makesdna/DNA_cache_library_types.h
index bfc5280..dba34e0 100644
--- a/source/blender/makesdna/DNA_cache_library_types.h
+++ b/source/blender/makesdna/DNA_cache_library_types.h
@@ -54,10 +54,6 @@ typedef struct CacheItem {
 	
 	int flag;
 	int pad;
-	
-	/* runtime */
-	struct PTCReader *reader;
-	struct PTCWriter *writer;
 } CacheItem;
 
 typedef enum eCacheItem_Flag {
@@ -72,10 +68,6 @@ typedef struct CacheLibrary {
 	
 	ListBase items;				/* cached items */
 	struct GHash *items_hash;	/* runtime: cached items hash for fast lookup */
-	
-	/* runtime */
-	struct PTCReaderArchive *reader_archive;
-	struct PTCWriterArchive *writer_archive;
 } CacheLibrary;
 
 #endif
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index 3ffed41..d62f77e 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -16,6 +16,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include "MEM_guardedalloc.h"
+
 #include "PTC_api.h"
 
 #include "util/util_error_handler.h"
@@ -26,10 +28,14 @@
 
 #include "alembic.h"
 #include "ptc_types.h"
+#include "util_path.h"
 
 extern "C" {
+#include "BLI_listbase.h"
 #include "BLI_math.h"
 
+#include "DNA_cache_library_types.h"
+#include "DNA_listBase.h"
 #include "DNA_modifier_types.h"
 
 #include "BKE_modifier.h"
@@ -121,12 +127,11 @@ void PTC_write_sample(struct PTCWriter *_writer)
 	writer->write_sample();
 }
 
-void PTC_bake(struct Main *bmain, struct Scene *scene, struct EvaluationContext *evalctx, struct PTCWriter *_writer, int start_frame, int end_frame,
+void PTC_bake(struct Main *bmain, struct Scene *scene, struct EvaluationContext *evalctx, struct ListBase *writers, int start_frame, int end_frame,
               short *stop, short *do_update, float *progress)
 {
-	PTC::Writer *writer = (PTC::Writer *)_writer;
 	PTC::Exporter exporter(bmain, scene, evalctx, stop, do_update, progress);
-	exporter.bake(writer, start_frame, end_frame);
+	exporter.bake(writers, start_frame, end_frame);
 }
 
 
@@ -220,6 +225,96 @@ PTCReader *PTC_reader_from_rna(Scene *scene, PointerRNA *ptr)
 }
 
 
+PTCReaderArchive *PTC_cachlib_readers(Scene *scene, CacheLibrary *cachelib, ListBase *readers)
+{
+	std::string filename = ptc_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib);
+	PTCReaderArchive *archive = PTC_open_reader_archive(scene, filename.c_str());
+	
+	BLI_listbase_clear(readers);
+	
+	for (CacheItem *item = (CacheItem *)cachelib->items.first; item; item = item->next) {
+		if (!(item->flag & CACHE_ITEM_ENABLED))
+			continue;
+		
+		PTCReader *reader = NULL;
+		switch (item->type) {
+			case CACHE_TYPE_DERIVED_MESH:
+//				reader = PTC_reader_point_cache(archive, )
+				break;
+			default:
+				break;
+		}
+		
+		if (reader) {
+			LinkData *link = (LinkData *)MEM_callocN(sizeof(LinkData), "cachelib readers link");
+			link->data = reader;
+			BLI_addtail(readers, link);
+		}
+	}
+	
+	return archive;
+}
+
+void PTC_cachlib_readers_free(PTCReaderArchive *archive, ListBase *readers)
+{
+	for (LinkData *link = (LinkData *)readers->first; link; link = link->next) {
+		PTCReader *reader = (PTCReader *)link->data;
+		PTC_reader_free(reader);
+	}
+	BLI_freelistN(readers);
+	
+	PTC_close_reader_archive(archive);
+}
+
+PTCWriterArchive *PTC_cachlib_writers(Scene *scene, CacheLibrary *cachelib, ListBase *writers)
+{
+	std::string filename = ptc_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib);
+	PTCWriterArchive *archive = PTC_open_writer_archive(scene, filename.c_str());
+	
+	BLI_listbase_clear(writers);
+	
+	for (CacheItem *item = (CacheItem *)cachelib->items.first; item; item = item->next) {
+		if (!(item->flag & CACHE_ITEM_ENABLED))
+			continue;
+		
+		PTCWriter *writer = NULL;
+		switch (item->type) {
+			case CACHE_TYPE_DERIVED_MESH:
+//				writer = PTC_writer_point_cache(archive, )
+				break;
+			case CACHE_TYPE_HAIR: {
+				ParticleSystem *psys = (ParticleSystem *)BLI_findlink(&item->ob->particlesystem, item->index);
+				if (psys && psys->part && psys->part->type == PART_HAIR && psys->clmd) {
+					writer = PTC_writer_cloth(archive, item-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list