[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43234] trunk/blender/source/blender: Fix #29793: Physics go crazy if frames get skipped

Sergey Sharybin sergey.vfx at gmail.com
Mon Jan 9 15:08:08 CET 2012


Revision: 43234
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43234
Author:   nazgul
Date:     2012-01-09 14:08:06 +0000 (Mon, 09 Jan 2012)
Log Message:
-----------
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)

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_cloth.h
    trunk/blender/source/blender/blenkernel/intern/cloth.c
    trunk/blender/source/blender/blenkernel/intern/softbody.c
    trunk/blender/source/blender/makesdna/DNA_object_force.h

Modified: trunk/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_cloth.h	2012-01-09 10:38:22 UTC (rev 43233)
+++ trunk/blender/source/blender/blenkernel/BKE_cloth.h	2012-01-09 14:08:06 UTC (rev 43234)
@@ -85,6 +85,7 @@
 	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;
 
 /**

Modified: trunk/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/cloth.c	2012-01-09 10:38:22 UTC (rev 43233)
+++ trunk/blender/source/blender/blenkernel/intern/cloth.c	2012-01-09 14:08:06 UTC (rev 43234)
@@ -47,7 +47,6 @@
 #include "BKE_modifier.h"
 #include "BKE_pointcache.h"
 
-
 #ifdef _WIN32
 void tstart ( void )
 {}
@@ -377,6 +376,8 @@
 		}
 	
 		implicit_set_positions(clmd);
+
+		clmd->clothObject->last_frame= MINFRAME-1;
 	}
 
 	return 1;
@@ -477,6 +478,8 @@
 		do_step_cloth(ob, clmd, dm, framenr);
 		cloth_to_object(ob, clmd, result);
 
+		clmd->clothObject->last_frame= framenr;
+
 		return result;
 	}
 
@@ -498,6 +501,7 @@
 		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 @@
 		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 @@
 		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 @@
 		BKE_ptcache_write(&pid, framenr);
 
 	cloth_to_object (ob, clmd, result);
+	clmd->clothObject->last_frame= framenr;
 
 	return result;
 }

Modified: trunk/blender/source/blender/blenkernel/intern/softbody.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/softbody.c	2012-01-09 10:38:22 UTC (rev 43233)
+++ trunk/blender/source/blender/blenkernel/intern/softbody.c	2012-01-09 14:08:06 UTC (rev 43234)
@@ -3728,6 +3728,8 @@
 	if(!sb->effector_weights)
 		sb->effector_weights = BKE_add_effector_weights(NULL);
 
+	sb->last_frame= MINFRAME-1;
+
 	return sb;
 }
 
@@ -4108,6 +4110,7 @@
 		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 @@
 
 		BKE_ptcache_validate(cache, framenr);
 		cache->flag &= ~PTCACHE_REDO_NEEDED;
+
+		sb->last_frame = framenr;
+
 		return;
 	}
 
@@ -4137,6 +4143,8 @@
 		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 @@
 		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 @@
 
 	BKE_ptcache_validate(cache, framenr);
 	BKE_ptcache_write(&pid, framenr);
+
+	sb->last_frame = framenr;
 }
 

Modified: trunk/blender/source/blender/makesdna/DNA_object_force.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_object_force.h	2012-01-09 10:38:22 UTC (rev 43233)
+++ trunk/blender/source/blender/makesdna/DNA_object_force.h	2012-01-09 14:08:06 UTC (rev 43234)
@@ -337,8 +337,8 @@
 	float lcom[3];
 	float lrot[3][3];
 	float lscale[3][3];
-	char  pad4[4];
 
+	int last_frame;
 } SoftBody;
 
 



More information about the Bf-blender-cvs mailing list