diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-09-28 10:26:46 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-09-28 10:26:46 +0400 |
commit | ba58bc51fda66daf84e8a5dd8b54fd0e9834e6b2 (patch) | |
tree | f4f69fbc69850b6ed4ba453d35789ceb17120c2c | |
parent | 018fa1540eaef603b28c04fd5b8533d21122e36f (diff) |
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).
-rw-r--r-- | source/blender/editors/physics/physics_fluid.c | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index 11796d01620..2f62e55bcd8 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -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; } |