[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40642] trunk/blender/source/blender/ editors/physics/physics_fluid.c: fix [#28725] No way to control fluid simulator from Python API?

Campbell Barton ideasman42 at gmail.com
Wed Sep 28 08:26:47 CEST 2011


Revision: 40642
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40642
Author:   campbellbarton
Date:     2011-09-28 06:26:46 +0000 (Wed, 28 Sep 2011)
Log Message:
-----------
fix [#28725] No way to control fluid simulator from Python API?

now exec() blocks while doing fluid bake, invoke starts a background job (texture bake also works this way).

Modified Paths:
--------------
    trunk/blender/source/blender/editors/physics/physics_fluid.c

Modified: trunk/blender/source/blender/editors/physics/physics_fluid.c
===================================================================
--- trunk/blender/source/blender/editors/physics/physics_fluid.c	2011-09-28 05:53:40 UTC (rev 40641)
+++ trunk/blender/source/blender/editors/physics/physics_fluid.c	2011-09-28 06:26:46 UTC (rev 40642)
@@ -844,7 +844,7 @@
 	return;
 }
 
-static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
+static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, short do_job)
 {
 	Scene *scene= CTX_data_scene(C);
 	int i;
@@ -871,12 +871,10 @@
 	ListBase *fobjects = MEM_callocN(sizeof(ListBase), "fluid objects");
 	FluidsimModifierData *fluidmd = NULL;
 	Mesh *mesh = NULL;
-	
-	wmJob *steve;
+
 	FluidBakeJob *fb;
 	elbeemSimulationSettings *fsset= MEM_callocN(sizeof(elbeemSimulationSettings), "Fluid sim settings");
-	
-	steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Fluid Simulation", WM_JOB_PROGRESS);
+
 	fb= MEM_callocN(sizeof(FluidBakeJob), "fluid bake job");
 	
 	if(getenv(strEnvName)) {
@@ -1083,13 +1081,26 @@
 	/* custom data for fluid bake job */
 	fb->settings = fsset;
 	
-	/* setup job */
-	WM_jobs_customdata(steve, fb, fluidbake_free);
-	WM_jobs_timer(steve, 0.1, NC_SCENE|ND_FRAME, NC_SCENE|ND_FRAME);
-	WM_jobs_callbacks(steve, fluidbake_startjob, NULL, NULL, fluidbake_endjob);
-	
-	WM_jobs_start(CTX_wm_manager(C), steve);
+	if(do_job) {
+		wmJob *steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Fluid Simulation", WM_JOB_PROGRESS);
 
+		/* setup job */
+		WM_jobs_customdata(steve, fb, fluidbake_free);
+		WM_jobs_timer(steve, 0.1, NC_SCENE|ND_FRAME, NC_SCENE|ND_FRAME);
+		WM_jobs_callbacks(steve, fluidbake_startjob, NULL, NULL, fluidbake_endjob);
+
+		WM_jobs_start(CTX_wm_manager(C), steve);
+	}
+	else {
+		short dummy_stop, dummy_do_update;
+		float dummy_progress;
+
+		/* blocking, use with exec() */
+		fluidbake_startjob((void *)fb, &dummy_stop, &dummy_do_update, &dummy_progress);
+		fluidbake_endjob((void *)fb);
+		fluidbake_free((void *)fb);
+	}
+
 	/* ******** free stored animation data ******** */
 	fluidbake_free_data(channels, fobjects, NULL, NULL);
 
@@ -1121,7 +1132,7 @@
 }
 
 /* only compile dummy functions */
-static int fluidsimBake(bContext *UNUSED(C), ReportList *UNUSED(reports), Object *UNUSED(ob))
+static int fluidsimBake(bContext *UNUSED(C), ReportList *UNUSED(reports), Object *UNUSED(ob), short UNUSED(do_job))
 {
 	return 0;
 }
@@ -1130,18 +1141,26 @@
 
 /***************************** Operators ******************************/
 
-static int fluid_bake_exec(bContext *C, wmOperator *op)
+static int fluid_bake_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {
 	/* only one bake job at a time */
 	if(WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C)))
 		return 0;
 
-	if(!fluidsimBake(C, op->reports, CTX_data_active_object(C)))
+	if(!fluidsimBake(C, op->reports, CTX_data_active_object(C), TRUE))
 		return OPERATOR_CANCELLED;
 
 	return OPERATOR_FINISHED;
 }
 
+static int fluid_bake_exec(bContext *C, wmOperator *op)
+{
+	if(!fluidsimBake(C, op->reports, CTX_data_active_object(C), FALSE))
+		return OPERATOR_CANCELLED;
+
+	return OPERATOR_FINISHED;
+}
+
 void FLUID_OT_bake(wmOperatorType *ot)
 {
 	/* identifiers */
@@ -1150,6 +1169,7 @@
 	ot->idname= "FLUID_OT_bake";
 	
 	/* api callbacks */
+	ot->invoke= fluid_bake_invoke;
 	ot->exec= fluid_bake_exec;
 	ot->poll= ED_operator_object_active_editable;
 }




More information about the Bf-blender-cvs mailing list