diff options
Diffstat (limited to 'source/blender/editors/physics/physics_pointcache.c')
-rw-r--r-- | source/blender/editors/physics/physics_pointcache.c | 81 |
1 files changed, 25 insertions, 56 deletions
diff --git a/source/blender/editors/physics/physics_pointcache.c b/source/blender/editors/physics/physics_pointcache.c index 51c5955d507..58bd761a2a9 100644 --- a/source/blender/editors/physics/physics_pointcache.c +++ b/source/blender/editors/physics/physics_pointcache.c @@ -42,6 +42,7 @@ #include "BKE_context.h" #include "BKE_screen.h" #include "BKE_global.h" +#include "BKE_layer.h" #include "BKE_main.h" #include "BKE_particle.h" #include "BKE_pointcache.h" @@ -68,6 +69,7 @@ static bool ptcache_poll(bContext *C) } typedef struct PointCacheJob { + wmWindowManager *wm; void *owner; short *stop, *do_update; float *progress; @@ -122,8 +124,7 @@ static void ptcache_job_startjob(void *customdata, short *stop, short *do_update /* XXX annoying hack: needed to prevent data corruption when changing * scene frame in separate threads */ - G.is_rendering = true; - BKE_spacedata_draw_locks(true); + WM_set_locked_interface(job->wm, true); BKE_ptcache_bake(job->baker); @@ -136,10 +137,7 @@ static void ptcache_job_endjob(void *customdata) PointCacheJob *job = customdata; Scene *scene = job->baker->scene; - G.is_rendering = false; - BKE_spacedata_draw_locks(false); - - WM_set_locked_interface(G_MAIN->wm.first, false); + WM_set_locked_interface(job->wm, false); WM_main_add_notifier(NC_SCENE | ND_FRAME, scene); WM_main_add_notifier(NC_OBJECT | ND_POINTCACHE, job->baker->pid.ob); @@ -165,6 +163,8 @@ static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all) baker->bmain = CTX_data_main(C); baker->scene = CTX_data_scene(C); + baker->view_layer = CTX_data_view_layer(C); + baker->depsgraph = CTX_data_depsgraph(C); baker->bake = RNA_boolean_get(op->ptr, "bake"); baker->render = 0; baker->anim_init = 0; @@ -174,18 +174,7 @@ static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all) PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache); Object *ob = ptr.id.data; PointCache *cache = ptr.data; - - ListBase pidlist; - BKE_ptcache_ids_from_object(baker->bmain, &pidlist, ob, baker->scene, MAX_DUPLI_RECUR); - - for (PTCacheID *pid = pidlist.first; pid; pid = pid->next) { - if (pid->cache == cache) { - baker->pid = *pid; - break; - } - } - - BLI_freelistN(&pidlist); + baker->pid = BKE_ptcache_id_find(ob, baker->scene, cache); } return baker; @@ -207,6 +196,7 @@ static int ptcache_bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE bool all = STREQ(op->type->idname, "PTCACHE_OT_bake_all"); PointCacheJob *job = MEM_mallocN(sizeof(PointCacheJob), "PointCacheJob"); + job->wm = CTX_wm_manager(C); job->baker = ptcache_baker_create(C, op, all); job->baker->bake_job = job; job->baker->update_progress = ptcache_job_update; @@ -253,23 +243,23 @@ static void ptcache_bake_cancel(bContext *C, wmOperator *op) static int ptcache_free_bake_all_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - Base *base; PTCacheID *pid; ListBase pidlist; - for (base = scene->base.first; base; base = base->next) { - BKE_ptcache_ids_from_object(bmain, &pidlist, base->object, scene, MAX_DUPLI_RECUR); + FOREACH_SCENE_OBJECT_BEGIN(scene, ob) + { + BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR); - for (pid=pidlist.first; pid; pid=pid->next) { + for (pid = pidlist.first; pid; pid = pid->next) { ptcache_free_bake(pid->cache); } BLI_freelistN(&pidlist); - WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, base->object); + WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob); } + FOREACH_SCENE_OBJECT_END; WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); @@ -384,27 +374,18 @@ void PTCACHE_OT_bake_from_cache(wmOperatorType *ot) static int ptcache_add_new_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); PointerRNA ptr= CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache); Object *ob= ptr.id.data; PointCache *cache= ptr.data; - PTCacheID *pid; - ListBase pidlist; - - BKE_ptcache_ids_from_object(bmain, &pidlist, ob, scene, MAX_DUPLI_RECUR); + PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache); - for (pid=pidlist.first; pid; pid=pid->next) { - if (pid->cache == cache) { - PointCache *cache_new = BKE_ptcache_add(pid->ptcaches); - cache_new->step = pid->default_step; - *(pid->cache_ptr) = cache_new; - break; - } + if (pid.cache) { + PointCache *cache_new = BKE_ptcache_add(pid.ptcaches); + cache_new->step = pid.default_step; + *(pid.cache_ptr) = cache_new; } - BLI_freelistN(&pidlist); - WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob); @@ -412,31 +393,19 @@ static int ptcache_add_new_exec(bContext *C, wmOperator *UNUSED(op)) } static int ptcache_remove_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); PointerRNA ptr= CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache); Scene *scene= CTX_data_scene(C); Object *ob= ptr.id.data; PointCache *cache= ptr.data; - PTCacheID *pid; - ListBase pidlist; - - BKE_ptcache_ids_from_object(bmain, &pidlist, ob, scene, MAX_DUPLI_RECUR); + PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache); - for (pid=pidlist.first; pid; pid=pid->next) { - if (pid->cache == cache) { - if (pid->ptcaches->first == pid->ptcaches->last) - continue; /* don't delete last cache */ - - BLI_remlink(pid->ptcaches, pid->cache); - BKE_ptcache_free(pid->cache); - *(pid->cache_ptr) = pid->ptcaches->first; - - break; - } + /* don't delete last cache */ + if (pid.cache && pid.ptcaches->first != pid.ptcaches->last) { + BLI_remlink(pid.ptcaches, pid.cache); + BKE_ptcache_free(pid.cache); + *(pid.cache_ptr) = pid.ptcaches->first; } - BLI_freelistN(&pidlist); - WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob); return OPERATOR_FINISHED; |