[Bf-blender-cvs] [98b67f1] alembic_pointcache: Added new operator for point cache 'Export'. This is basically the same as baking, naming may have to be adjusted later, for now they just exist side-by-side.

Lukas Tönne noreply at git.blender.org
Thu Oct 16 16:52:55 CEST 2014


Commit: 98b67f1d97b5dd372d85237d0e7dc34912fe936c
Author: Lukas Tönne
Date:   Sat Nov 23 15:11:31 2013 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB98b67f1d97b5dd372d85237d0e7dc34912fe936c

Added new operator for point cache 'Export'. This is basically the same as baking, naming may have to be adjusted later, for now they just exist side-by-side.

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

M	release/scripts/startup/bl_ui/properties_physics_common.py
M	source/blender/editors/physics/CMakeLists.txt
M	source/blender/editors/physics/physics_intern.h
M	source/blender/editors/physics/physics_ops.c
M	source/blender/editors/physics/physics_pointcache.c
M	source/blender/pointcache/CMakeLists.txt
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/windowmanager/WM_api.h

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_common.py b/release/scripts/startup/bl_ui/properties_physics_common.py
index 4b4c331..2c102a9 100644
--- a/release/scripts/startup/bl_ui/properties_physics_common.py
+++ b/release/scripts/startup/bl_ui/properties_physics_common.py
@@ -119,6 +119,8 @@ def point_cache_ui(self, context, cache, enabled, cachetype):
         if cachetype == 'SMOKE':
             row.prop(cache, "use_library_path", "Use Lib Path")
 
+        layout.context_pointer_set("point_cache_user", context.particle_system)
+
     if cache.use_external:
         split = layout.split(percentage=0.35)
         col = split.column()
@@ -211,6 +213,8 @@ def point_cache_ui(self, context, cache, enabled, cachetype):
         col.operator("ptcache.free_bake_all", text="Free All Bakes")
         col.operator("ptcache.bake_all", text="Update All To Frame").bake = False
 
+        col.operator("ptcache.export", text="Export")
+
 
 def effector_weights_ui(self, context, weights, weight_type):
     layout = self.layout
diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt
index 892d71b..6fd5977 100644
--- a/source/blender/editors/physics/CMakeLists.txt
+++ b/source/blender/editors/physics/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
 	../../blenlib
 	../../makesdna
 	../../makesrna
+	../../pointcache
 	../../windowmanager
 	../../../../intern/elbeem/extern
 	../../../../intern/guardedalloc
diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h
index 77ce5a3..2b8f4b5 100644
--- a/source/blender/editors/physics/physics_intern.h
+++ b/source/blender/editors/physics/physics_intern.h
@@ -105,6 +105,8 @@ void PTCACHE_OT_bake_from_cache(struct wmOperatorType *ot);
 void PTCACHE_OT_add(struct wmOperatorType *ot);
 void PTCACHE_OT_remove(struct wmOperatorType *ot);
 
+void PTCACHE_OT_export(struct wmOperatorType *ot);
+
 /* rigidbody_object.c */
 void RIGIDBODY_OT_object_add(struct wmOperatorType *ot);
 void RIGIDBODY_OT_object_remove(struct wmOperatorType *ot);
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index 444c87d..963fbd4 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -189,6 +189,8 @@ static void operatortypes_pointcache(void)
 	WM_operatortype_append(PTCACHE_OT_bake_from_cache);
 	WM_operatortype_append(PTCACHE_OT_add);
 	WM_operatortype_append(PTCACHE_OT_remove);
+
+	WM_operatortype_append(PTCACHE_OT_export);
 }
 
 /********************************* dynamic paint ***********************************/
diff --git a/source/blender/editors/physics/physics_pointcache.c b/source/blender/editors/physics/physics_pointcache.c
index 515ac33..4851927 100644
--- a/source/blender/editors/physics/physics_pointcache.c
+++ b/source/blender/editors/physics/physics_pointcache.c
@@ -47,7 +47,10 @@
 #include "BKE_pointcache.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
- 
+
+/**** NEW POINT CACHE ****/
+#include "PTC_api.h"
+/*************************/
 
 #include "ED_particle.h"
 
@@ -404,3 +407,95 @@ void PTCACHE_OT_remove(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+
+/**** NEW POINT CACHE ****/
+
+typedef struct PTCacheExportJob {
+	short *stop, *do_update;
+	float *progress;
+	
+	struct Main *bmain;
+	struct Scene *scene;
+	struct PointCache *cache;
+	struct PTCWriter *writer;
+} PTCacheExportJob;
+
+static void ptcache_export_freejob(void *customdata)
+{
+	PTCacheExportJob *data= (PTCacheExportJob *)customdata;
+	MEM_freeN(data);
+}
+
+static void ptcache_export_startjob(void *customdata, short *stop, short *do_update, float *progress)
+{
+	PTCacheExportJob *data= (PTCacheExportJob *)customdata;
+	int start_frame, end_frame;
+	
+	data->stop = stop;
+	data->do_update = do_update;
+	data->progress = progress;
+	
+	/* XXX where to get this from? */
+	start_frame = data->scene->r.sfra;
+	end_frame = data->scene->r.efra;
+	PTC_bake(data->bmain, data->scene, data->writer, start_frame, end_frame);
+	
+	*do_update = TRUE;
+	*stop = 0;
+}
+
+static void ptcache_export_endjob(void *customdata)
+{
+	/*PTCacheExportJob *data = (PTCacheExportJob *)customdata;*/
+}
+
+static int ptcache_export_exec(bContext *C, wmOperator *op)
+{
+	PointerRNA ptcache_ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
+	PointerRNA user_ptr = CTX_data_pointer_get(C, "point_cache_user");
+	Main *bmain = CTX_data_main(C);
+	Scene *scene = CTX_data_scene(C);
+	PointCache *cache = ptcache_ptr.data;
+	struct PTCWriter *writer;
+	PTCacheExportJob *data;
+	wmJob *wm_job;
+	
+	writer = PTC_writer_from_rna(&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;
+	}
+	
+	wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Point Cache Export",
+	                     WM_JOB_PROGRESS, WM_JOB_TYPE_PTCACHE_EXPORT);
+	
+	/* setup job */
+	data = MEM_callocN(sizeof(PTCacheExportJob), "Point Cache Export Job");
+	data->bmain = bmain;
+	data->scene = scene;
+	data->cache = cache;
+	data->writer = writer;
+	
+	WM_jobs_customdata_set(wm_job, data, ptcache_export_freejob);
+	WM_jobs_timer(wm_job, 0.1, NC_SCENE|ND_FRAME, NC_SCENE|ND_FRAME);
+	WM_jobs_callbacks(wm_job, ptcache_export_startjob, NULL, NULL, ptcache_export_endjob);
+	
+	WM_jobs_start(CTX_wm_manager(C), wm_job);
+	
+	return OPERATOR_FINISHED;
+}
+
+void PTCACHE_OT_export(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Export";
+	ot->description = "Export point data";
+	ot->idname = "PTCACHE_OT_export";
+
+	/* api callbacks */
+	ot->exec = ptcache_export_exec;
+	ot->poll = ptcache_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+}
diff --git a/source/blender/pointcache/CMakeLists.txt b/source/blender/pointcache/CMakeLists.txt
index 930156c..cc36ad0 100644
--- a/source/blender/pointcache/CMakeLists.txt
+++ b/source/blender/pointcache/CMakeLists.txt
@@ -28,6 +28,7 @@ set(INC
 	../blenkernel
 	../blenlib
 	../makesdna
+	../makesrna
 	../../../intern/guardedalloc
 )
 
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index ec22d87..e3cf150 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -31,6 +31,8 @@ extern "C" {
 #include "DNA_object_force.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
+
+#include "RNA_access.h"
 }
 
 using namespace PTC;
@@ -67,6 +69,26 @@ void PTC_read_sample(struct PTCReader *_reader)
 	reader->read_sample();
 }
 
+/* get writer/reader from RNA type */
+PTCWriter *PTC_writer_from_rna(PointerRNA *ptr)
+{
+	if (RNA_struct_is_a(ptr->type, &RNA_ParticleSystem)) {
+		Object *ob = (Object *)ptr->id.data;
+		ParticleSystem *psys = (ParticleSystem *)ptr->data;
+		return PTC_writer_particles(ob, psys);
+	}
+	return NULL;
+}
+
+PTCReader *PTC_reader_from_rna(PointerRNA *ptr)
+{
+	if (RNA_struct_is_a(ptr->type, &RNA_ParticleSystem)) {
+		Object *ob = (Object *)ptr->id.data;
+		ParticleSystem *psys = (ParticleSystem *)ptr->data;
+		return PTC_reader_particles(ob, psys);
+	}
+	return NULL;
+}
 
 /* Particles */
 PTCWriter *PTC_writer_particles(Object *ob, ParticleSystem *psys)
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index be111c8..bf761e8 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -27,6 +27,7 @@ struct Main;
 struct Scene;
 struct Object;
 struct ParticleSystem;
+struct PointerRNA;
 
 void PTC_test_archive(void);
 
@@ -43,6 +44,10 @@ void PTC_read_sample(struct PTCReader *reader);
 void PTC_bake(struct Main *bmain, struct Scene *scene, struct PTCWriter *writer, int start_frame, int end_frame);
 
 
+/* get writer/reader from RNA type */
+struct PTCWriter *PTC_writer_from_rna(struct PointerRNA *ptr);
+struct PTCReader *PTC_reader_from_rna(struct PointerRNA *ptr);
+
 /* Particles */
 struct PTCWriter *PTC_writer_particles(struct Object *ob, struct ParticleSystem *psys);
 struct PTCReader *PTC_reader_particles(struct Object *ob, struct ParticleSystem *psys);
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 26294dd..90188fd 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -367,6 +367,7 @@ enum {
 	WM_JOB_TYPE_OBJECT_SIM_OCEAN,
 	WM_JOB_TYPE_OBJECT_SIM_FLUID,
 	WM_JOB_TYPE_OBJECT_BAKE_TEXTURE,
+	WM_JOB_TYPE_PTCACHE_EXPORT,
 	WM_JOB_TYPE_FILESEL_THUMBNAIL,
 	WM_JOB_TYPE_CLIP_BUILD_PROXY,
 	WM_JOB_TYPE_CLIP_TRACK_MARKERS,




More information about the Bf-blender-cvs mailing list