Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pointcache.c
| Show First 20 Lines • Show All 3,503 Lines • ▼ Show 20 Lines | PointCache *BKE_ptcache_copy_list(ListBase *ptcaches_new, const ListBase *ptcaches_old, const int flag) | ||||
| return ptcaches_new->first; | return ptcaches_new->first; | ||||
| } | } | ||||
| /* Disabled this code; this is being called on scene_update_tagged, and that in turn gets called on | /* Disabled this code; this is being called on scene_update_tagged, and that in turn gets called on | ||||
| * every user action changing stuff, and then it runs a complete bake??? (ton) */ | * every user action changing stuff, and then it runs a complete bake??? (ton) */ | ||||
| /* Baking */ | /* Baking */ | ||||
| void BKE_ptcache_quick_cache_all(Main *bmain, Scene *scene, SceneLayer *scene_layer) | void BKE_ptcache_quick_cache_all(Main *bmain, Scene *scene, ViewLayer *view_layer) | ||||
| { | { | ||||
| PTCacheBaker baker; | PTCacheBaker baker; | ||||
| memset(&baker, 0, sizeof(baker)); | memset(&baker, 0, sizeof(baker)); | ||||
| baker.main = bmain; | baker.main = bmain; | ||||
| baker.scene = scene; | baker.scene = scene; | ||||
| baker.scene_layer = scene_layer; | baker.view_layer = view_layer; | ||||
| baker.bake = 0; | baker.bake = 0; | ||||
| baker.render = 0; | baker.render = 0; | ||||
| baker.anim_init = 0; | baker.anim_init = 0; | ||||
| baker.quick_step = scene->physics_settings.quick_cache_step; | baker.quick_step = scene->physics_settings.quick_cache_step; | ||||
| BKE_ptcache_bake(&baker); | BKE_ptcache_bake(&baker); | ||||
| } | } | ||||
| Show All 9 Lines | else | ||||
| sprintf(str, "%is", ((int)dtime) % 60); | sprintf(str, "%is", ((int)dtime) % 60); | ||||
| } | } | ||||
| /* if bake is not given run simulations to current frame */ | /* if bake is not given run simulations to current frame */ | ||||
| void BKE_ptcache_bake(PTCacheBaker *baker) | void BKE_ptcache_bake(PTCacheBaker *baker) | ||||
| { | { | ||||
| Main *bmain = baker->main; | Main *bmain = baker->main; | ||||
| Scene *scene = baker->scene; | Scene *scene = baker->scene; | ||||
| SceneLayer *scene_layer = baker->scene_layer; | ViewLayer *view_layer = baker->view_layer; | ||||
| struct Depsgraph *depsgraph = baker->depsgraph; | struct Depsgraph *depsgraph = baker->depsgraph; | ||||
| Scene *sce_iter; /* SETLOOPER macro only */ | Scene *sce_iter; /* SETLOOPER macro only */ | ||||
| Base *base; | Base *base; | ||||
| ListBase pidlist; | ListBase pidlist; | ||||
| PTCacheID *pid = &baker->pid; | PTCacheID *pid = &baker->pid; | ||||
| PointCache *cache = NULL; | PointCache *cache = NULL; | ||||
| float frameleno = scene->r.framelen; | float frameleno = scene->r.framelen; | ||||
| int cfrao = CFRA; | int cfrao = CFRA; | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if ((cache->flag & PTCACHE_BAKED)==0) { | ||||
| else { | else { | ||||
| endframe = MIN2(endframe, cache->endframe); | endframe = MIN2(endframe, cache->endframe); | ||||
| } | } | ||||
| cache->flag &= ~PTCACHE_BAKED; | cache->flag &= ~PTCACHE_BAKED; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (SETLOOPER_SCENE_LAYER(scene, scene_layer, sce_iter, base)) { | for (SETLOOPER_VIEW_LAYER(scene, view_layer, sce_iter, base)) { | ||||
| /* cache/bake everything in the scene */ | /* cache/bake everything in the scene */ | ||||
| BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR); | BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR); | ||||
| for (pid=pidlist.first; pid; pid=pid->next) { | for (pid=pidlist.first; pid; pid=pid->next) { | ||||
| cache = pid->cache; | cache = pid->cache; | ||||
| if ((cache->flag & PTCACHE_BAKED)==0) { | if ((cache->flag & PTCACHE_BAKED)==0) { | ||||
| if (pid->type==PTCACHE_TYPE_PARTICLES) { | if (pid->type==PTCACHE_TYPE_PARTICLES) { | ||||
| ParticleSystem *psys = (ParticleSystem*)pid->calldata; | ParticleSystem *psys = (ParticleSystem*)pid->calldata; | ||||
| Show All 39 Lines | void BKE_ptcache_bake(PTCacheBaker *baker) | ||||
| bool use_timer = false; | bool use_timer = false; | ||||
| double stime, ptime, ctime, fetd; | double stime, ptime, ctime, fetd; | ||||
| char run[32], cur[32], etd[32]; | char run[32], cur[32], etd[32]; | ||||
| int cancel = 0; | int cancel = 0; | ||||
| stime = ptime = PIL_check_seconds_timer(); | stime = ptime = PIL_check_seconds_timer(); | ||||
| for (int fr = CFRA; fr <= endframe; fr += baker->quick_step, CFRA = fr) { | for (int fr = CFRA; fr <= endframe; fr += baker->quick_step, CFRA = fr) { | ||||
| BKE_scene_graph_update_for_newframe(G.main->eval_ctx, depsgraph, bmain, scene, scene_layer); | BKE_scene_graph_update_for_newframe(G.main->eval_ctx, depsgraph, bmain, scene, view_layer); | ||||
| if (baker->update_progress) { | if (baker->update_progress) { | ||||
| float progress = ((float)(CFRA - startframe)/(float)(endframe - startframe)); | float progress = ((float)(CFRA - startframe)/(float)(endframe - startframe)); | ||||
| baker->update_progress(baker->bake_job, progress, &cancel); | baker->update_progress(baker->bake_job, progress, &cancel); | ||||
| } | } | ||||
| if (G.background) { | if (G.background) { | ||||
| printf("bake: frame %d :: %d\n", CFRA, endframe); | printf("bake: frame %d :: %d\n", CFRA, endframe); | ||||
| Show All 38 Lines | if (pid) { | ||||
| if (bake) { | if (bake) { | ||||
| cache->flag |= PTCACHE_BAKED; | cache->flag |= PTCACHE_BAKED; | ||||
| /* write info file */ | /* write info file */ | ||||
| if (cache->flag & PTCACHE_DISK_CACHE) | if (cache->flag & PTCACHE_DISK_CACHE) | ||||
| BKE_ptcache_write(pid, 0); | BKE_ptcache_write(pid, 0); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (SETLOOPER_SCENE_LAYER(scene, scene_layer, sce_iter, base)) { | for (SETLOOPER_VIEW_LAYER(scene, view_layer, sce_iter, base)) { | ||||
| BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR); | BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR); | ||||
| for (pid=pidlist.first; pid; pid=pid->next) { | for (pid=pidlist.first; pid; pid=pid->next) { | ||||
| /* skip hair particles */ | /* skip hair particles */ | ||||
| if (pid->type==PTCACHE_TYPE_PARTICLES && ((ParticleSystem*)pid->calldata)->part->type == PART_HAIR) | if (pid->type==PTCACHE_TYPE_PARTICLES && ((ParticleSystem*)pid->calldata)->part->type == PART_HAIR) | ||||
| continue; | continue; | ||||
| cache = pid->cache; | cache = pid->cache; | ||||
| Show All 14 Lines | for (SETLOOPER_VIEW_LAYER(scene, view_layer, sce_iter, base)) { | ||||
| BLI_freelistN(&pidlist); | BLI_freelistN(&pidlist); | ||||
| } | } | ||||
| } | } | ||||
| scene->r.framelen = frameleno; | scene->r.framelen = frameleno; | ||||
| CFRA = cfrao; | CFRA = cfrao; | ||||
| if (bake) { /* already on cfra unless baking */ | if (bake) { /* already on cfra unless baking */ | ||||
| BKE_scene_graph_update_for_newframe(bmain->eval_ctx, depsgraph, bmain, scene, scene_layer); | BKE_scene_graph_update_for_newframe(bmain->eval_ctx, depsgraph, bmain, scene, view_layer); | ||||
| } | } | ||||
| /* TODO: call redraw all windows somehow */ | /* TODO: call redraw all windows somehow */ | ||||
| } | } | ||||
| /* Helpers */ | /* Helpers */ | ||||
| void BKE_ptcache_disk_to_mem(PTCacheID *pid) | void BKE_ptcache_disk_to_mem(PTCacheID *pid) | ||||
| { | { | ||||
| PointCache *cache = pid->cache; | PointCache *cache = pid->cache; | ||||
| ▲ Show 20 Lines • Show All 344 Lines • Show Last 20 Lines | |||||