Commit: 22f67557d14e38c7d83a5770e1c725bd34df5f33 Author: Luca Rood Date: Fri Jan 13 20:10:22 2017 -0200 Branches: cloth-improvements https://developer.blender.org/rB22f67557d14e38c7d83a5770e1c725bd34df5f33
Make caching a bit more sane (fixes plasticity issue) This cleans up the cloth caching logic a bit. Now, a simulation step only occurs if the current time is exactly one frame after the last simulated step, thus preventing time gaps and runtime data corruption. Also, now the cloth is only re-initialized if the cache is actually outdated, instead of always being reset when on the first frame. This solves a bug where the cache was freed when moving the time to a point within the cached period. These changes also fix the issue of non-cached runtime simulation state properties (e.g. plasticity) being reset when going to the first frame or retaining a future state when simulating over an existing cache with time gaps. =================================================================== M source/blender/blenkernel/intern/cloth.c =================================================================== diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 27addb1434..f2d96f3588 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -449,7 +449,6 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived /* simulation is only active during a specific period */ if (framenr < startframe) { - BKE_ptcache_invalidate(cache); return; } else if (framenr > endframe) { @@ -460,17 +459,20 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived if (!do_init_cloth(ob, clmd, dm, framenr)) return; - if (framenr == startframe) { + if (framenr == startframe && ((cache->flag & PTCACHE_OUTDATED) || (cache->last_exact < startframe))) { BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); do_init_cloth(ob, clmd, dm, framenr); BKE_ptcache_validate(cache, framenr); cache->flag &= ~PTCACHE_REDO_NEEDED; clmd->clothObject->last_frame= framenr; + BKE_ptcache_write(&pid, startframe); return; } /* try to read from cache */ - bool can_simulate = (framenr == clmd->clothObject->last_frame+1) && !(cache->flag & PTCACHE_BAKED); + bool can_simulate = (framenr == clmd->clothObject->last_frame + 1) && + (framenr == cache->last_exact + 1) && + !(cache->flag & PTCACHE_BAKED); cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe, can_simulate); @@ -500,10 +502,6 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived if (!can_simulate) return; - /* if on second frame, write cache for first frame */ - if (cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0)) - BKE_ptcache_write(&pid, startframe); - clmd->sim_parms->timescale *= framenr - cache->simframe; /* do simulation */ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs