forked from bartvdbraak/blender
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).
This commit is contained in:
parent
018fa1540e
commit
ba58bc51fd
@ -844,7 +844,7 @@ static void fluidsim_delete_until_lastframe(FluidsimSettings *fss)
|
|||||||
return;
|
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);
|
Scene *scene= CTX_data_scene(C);
|
||||||
int i;
|
int i;
|
||||||
@ -871,12 +871,10 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
|
|||||||
ListBase *fobjects = MEM_callocN(sizeof(ListBase), "fluid objects");
|
ListBase *fobjects = MEM_callocN(sizeof(ListBase), "fluid objects");
|
||||||
FluidsimModifierData *fluidmd = NULL;
|
FluidsimModifierData *fluidmd = NULL;
|
||||||
Mesh *mesh = NULL;
|
Mesh *mesh = NULL;
|
||||||
|
|
||||||
wmJob *steve;
|
|
||||||
FluidBakeJob *fb;
|
FluidBakeJob *fb;
|
||||||
elbeemSimulationSettings *fsset= MEM_callocN(sizeof(elbeemSimulationSettings), "Fluid sim settings");
|
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");
|
fb= MEM_callocN(sizeof(FluidBakeJob), "fluid bake job");
|
||||||
|
|
||||||
if(getenv(strEnvName)) {
|
if(getenv(strEnvName)) {
|
||||||
@ -1083,12 +1081,25 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
|
|||||||
/* custom data for fluid bake job */
|
/* custom data for fluid bake job */
|
||||||
fb->settings = fsset;
|
fb->settings = fsset;
|
||||||
|
|
||||||
/* setup job */
|
if(do_job) {
|
||||||
WM_jobs_customdata(steve, fb, fluidbake_free);
|
wmJob *steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Fluid Simulation", WM_JOB_PROGRESS);
|
||||||
WM_jobs_timer(steve, 0.1, NC_SCENE|ND_FRAME, NC_SCENE|ND_FRAME);
|
|
||||||
WM_jobs_callbacks(steve, fluidbake_startjob, NULL, NULL, fluidbake_endjob);
|
/* setup job */
|
||||||
|
WM_jobs_customdata(steve, fb, fluidbake_free);
|
||||||
WM_jobs_start(CTX_wm_manager(C), steve);
|
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 ******** */
|
/* ******** free stored animation data ******** */
|
||||||
fluidbake_free_data(channels, fobjects, NULL, NULL);
|
fluidbake_free_data(channels, fobjects, NULL, NULL);
|
||||||
@ -1121,7 +1132,7 @@ FluidsimSettings* fluidsimSettingsCopy(FluidsimSettings *UNUSED(fss))
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* only compile dummy functions */
|
/* 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;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1130,13 +1141,21 @@ static int fluidsimBake(bContext *UNUSED(C), ReportList *UNUSED(reports), Object
|
|||||||
|
|
||||||
/***************************** Operators ******************************/
|
/***************************** 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 */
|
/* only one bake job at a time */
|
||||||
if(WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C)))
|
if(WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C)))
|
||||||
return 0;
|
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_CANCELLED;
|
||||||
|
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
@ -1150,6 +1169,7 @@ void FLUID_OT_bake(wmOperatorType *ot)
|
|||||||
ot->idname= "FLUID_OT_bake";
|
ot->idname= "FLUID_OT_bake";
|
||||||
|
|
||||||
/* api callbacks */
|
/* api callbacks */
|
||||||
|
ot->invoke= fluid_bake_invoke;
|
||||||
ot->exec= fluid_bake_exec;
|
ot->exec= fluid_bake_exec;
|
||||||
ot->poll= ED_operator_object_active_editable;
|
ot->poll= ED_operator_object_active_editable;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user