diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-01-09 18:08:06 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-01-09 18:08:06 +0400 |
commit | 8198880d44ca3a7af4f3bbd16097beceb30ec029 (patch) | |
tree | 593a1fc06bbbf21c1ef518d8ed3b3ad1fe43c727 /source | |
parent | ec58ff19adfc8c117a289139f3060a52277aaf47 (diff) |
Fix #29793: Physics go crazy if frames get skipped
Calculate cloth and softbody only for single frame time deltas
(like it's already done for smoke)
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_cloth.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cloth.c | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/softbody.c | 13 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_object_force.h | 2 |
4 files changed, 26 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index 2dfe9fd3402..62c3df7c6f4 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -85,6 +85,7 @@ typedef struct Cloth struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */ struct Implicit_Data *implicitEM; /* our implicit solver connects to this pointer */ struct EdgeHash *edgehash; /* used for selfcollisions */ + int last_frame, pad4; } Cloth; /** diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 4d5dce14b27..73428c889dc 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -47,7 +47,6 @@ #include "BKE_modifier.h" #include "BKE_pointcache.h" - #ifdef _WIN32 void tstart ( void ) {} @@ -377,6 +376,8 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul } implicit_set_positions(clmd); + + clmd->clothObject->last_frame= MINFRAME-1; } return 1; @@ -477,6 +478,8 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, do_step_cloth(ob, clmd, dm, framenr); cloth_to_object(ob, clmd, result); + clmd->clothObject->last_frame= framenr; + return result; } @@ -498,6 +501,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, do_init_cloth(ob, clmd, dm, framenr); BKE_ptcache_validate(cache, framenr); cache->flag &= ~PTCACHE_REDO_NEEDED; + clmd->clothObject->last_frame= framenr; return result; } @@ -513,6 +517,8 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, if(cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED) BKE_ptcache_write(&pid, framenr); + clmd->clothObject->last_frame= framenr; + return result; } else if(cache_result==PTCACHE_READ_OLD) { @@ -524,6 +530,9 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, return result; } + if(framenr!=clmd->clothObject->last_frame+1) + return result; + /* 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); @@ -540,6 +549,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, BKE_ptcache_write(&pid, framenr); cloth_to_object (ob, clmd, result); + clmd->clothObject->last_frame= framenr; return result; } diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index cab621eeff7..8d20a06d009 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3728,6 +3728,8 @@ SoftBody *sbNew(Scene *scene) if(!sb->effector_weights) sb->effector_weights = BKE_add_effector_weights(NULL); + sb->last_frame= MINFRAME-1; + return sb; } @@ -4108,6 +4110,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i softbody_update_positions(ob, sb, vertexCos, numVerts); softbody_step(scene, ob, sb, dtime); softbody_to_object(ob, vertexCos, numVerts, 0); + sb->last_frame = framenr; return; } @@ -4123,6 +4126,9 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i BKE_ptcache_validate(cache, framenr); cache->flag &= ~PTCACHE_REDO_NEEDED; + + sb->last_frame = framenr; + return; } @@ -4137,6 +4143,8 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i if(cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED) BKE_ptcache_write(&pid, framenr); + sb->last_frame = framenr; + return; } else if(cache_result==PTCACHE_READ_OLD) { @@ -4148,6 +4156,9 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i return; } + if(framenr!=sb->last_frame+1) + 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); @@ -4164,5 +4175,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i BKE_ptcache_validate(cache, framenr); BKE_ptcache_write(&pid, framenr); + + sb->last_frame = framenr; } diff --git a/source/blender/makesdna/DNA_object_force.h b/source/blender/makesdna/DNA_object_force.h index 5875ff30bcc..cb72e396356 100644 --- a/source/blender/makesdna/DNA_object_force.h +++ b/source/blender/makesdna/DNA_object_force.h @@ -337,8 +337,8 @@ typedef struct SoftBody { float lcom[3]; float lrot[3][3]; float lscale[3][3]; - char pad4[4]; + int last_frame; } SoftBody; |