fix [#28725] No way to control fluid simulator from Python API?
authorCampbell Barton <ideasman42@gmail.com>
Wed, 28 Sep 2011 06:26:46 +0000 (06:26 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 28 Sep 2011 06:26:46 +0000 (06:26 +0000)
now exec() blocks while doing fluid bake, invoke starts a background job (texture bake also works this way).

source/blender/editors/physics/physics_fluid.c

index 11796d0162075547838f82025131f21c72b91ac5..2f62e55bcd8480fc4eb7726bec2a360d91fcf035 100644 (file)
@@ -844,7 +844,7 @@ static void fluidsim_delete_until_lastframe(FluidsimSettings *fss)
        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 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
        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,12 +1081,25 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
        /* 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 @@ FluidsimSettings* fluidsimSettingsCopy(FluidsimSettings *UNUSED(fss))
 }
 
 /* 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,13 +1141,21 @@ static int fluidsimBake(bContext *UNUSED(C), ReportList *UNUSED(reports), Object
 
 /***************************** 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;
@@ -1150,6 +1169,7 @@ void FLUID_OT_bake(wmOperatorType *ot)
        ot->idname= "FLUID_OT_bake";
        
        /* api callbacks */
+       ot->invoke= fluid_bake_invoke;
        ot->exec= fluid_bake_exec;
        ot->poll= ED_operator_object_active_editable;
 }