[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13399] branches/cloth/blender/source/ blender: Fix: clear cache button works again even with protected cache, edited cache doesn' t get saved to wrong frame anymore when moving frames forward in editmode

Daniel Genrich daniel.genrich at gmx.net
Fri Jan 25 11:33:19 CET 2008


Revision: 13399
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13399
Author:   genscher
Date:     2008-01-25 11:33:19 +0100 (Fri, 25 Jan 2008)

Log Message:
-----------
Fix: clear cache button works again even with protected cache, edited cache doesn't get saved to wrong frame anymore when moving frames forward in editmode

Modified Paths:
--------------
    branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
    branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
    branches/cloth/blender/source/blender/blenkernel/intern/collision.c
    branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
    branches/cloth/blender/source/blender/src/buttons_object.c
    branches/cloth/blender/source/blender/src/editmesh.c

Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h	2008-01-25 08:55:27 UTC (rev 13398)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h	2008-01-25 10:33:19 UTC (rev 13399)
@@ -134,6 +134,7 @@
     CLOTH_SIMSETTINGS_FLAG_TEARING = ( 1 << 4 ),// true if tearing is enabled
     CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT = ( 1 << 5 ), // true if tearing is enabled
     CLOTH_SIMSETTINGS_FLAG_NEW = ( 1 << 6 ), 	// unsued, true if cloth was just enabled
+    CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE = (1 << 7), /* force cache freeing */
 } CLOTH_SIMSETTINGS_FLAGS;
 
 /* COLLISION FLAGS */
@@ -206,6 +207,7 @@
 
 // needed for editmesh.c
 void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr);
+int cloth_read_cache(Object *ob, ClothModifierData *clmd, float framenr);
 
 // needed for button_object.c
 void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr);

Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c	2008-01-25 08:55:27 UTC (rev 13398)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c	2008-01-25 10:33:19 UTC (rev 13399)
@@ -145,9 +145,9 @@
 	clmd->sim_parms->gravity [0] = 0.0;
 	clmd->sim_parms->gravity [1] = 0.0;
 	clmd->sim_parms->gravity [2] = -9.81;
-	clmd->sim_parms->structural = 100.0;
-	clmd->sim_parms->shear = 100.0;
-	clmd->sim_parms->bending = 1.0;
+	clmd->sim_parms->structural = 200.0;
+	clmd->sim_parms->shear = 200.0;
+	clmd->sim_parms->bending = 0.1;
 	clmd->sim_parms->Cdis = 5.0;
 	clmd->sim_parms->Cvi = 1.0;
 	clmd->sim_parms->mass = 1.0f;
@@ -161,6 +161,7 @@
 	clmd->sim_parms->lastframe = 250;
 	clmd->sim_parms->vgroup_mass = 0;
 	clmd->sim_parms->lastcachedframe = 0;
+	clmd->sim_parms->editedframe = 0;
 	
 	clmd->coll_parms->self_friction = 5.0;
 	clmd->coll_parms->friction = 10.0;
@@ -485,7 +486,7 @@
 
 int modifiers_indexInObject(Object *ob, ModifierData *md_seek);
 
-static int cloth_read_cache(Object *ob, ClothModifierData *clmd, float framenr)
+int cloth_read_cache(Object *ob, ClothModifierData *clmd, float framenr)
 {
 	FILE *fp = NULL;
 	int stack_index = -1;
@@ -534,7 +535,7 @@
 	int stack_index = -1;
 	
 	/* clear cache if specific frame cleaning requested or cache is not protected */
-	if((!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT)) || (framenr > 1.0))
+	if((!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT)) || (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE))
 	{
 		stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
 		
@@ -545,6 +546,9 @@
 	{
 		cloth_read_cache(ob, clmd, framenr);
 	}
+	
+	/* delete cache free request */
+	clmd->sim_parms->flags &= ~CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
 }
 void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
 {

Modified: branches/cloth/blender/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/collision.c	2008-01-25 08:55:27 UTC (rev 13398)
+++ branches/cloth/blender/source/blender/blenkernel/intern/collision.c	2008-01-25 10:33:19 UTC (rev 13399)
@@ -694,7 +694,7 @@
 				Normalize(collpair->normal);
 				
 				collpair->distance = distance;
-				BLI_linklist_append(&clmd->coll_parms->collision_list, collpair);
+				BLI_linklist_prepend(&clmd->coll_parms->collision_list, collpair);
 				
 			}
 			else

Modified: branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
===================================================================
--- branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h	2008-01-25 08:55:27 UTC (rev 13398)
+++ branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h	2008-01-25 10:33:19 UTC (rev 13399)
@@ -77,7 +77,7 @@
 	int 	lastframe; 	/* frame on which simulation stops */
 	int	firstframe;	/* frame on which simulation starts */
 	int 	lastcachedframe;
-	int pad3;
+	int 	editedframe; /* which frame is in buffer */
 }
 SimulationSettings;
 

Modified: branches/cloth/blender/source/blender/src/buttons_object.c
===================================================================
--- branches/cloth/blender/source/blender/src/buttons_object.c	2008-01-25 08:55:27 UTC (rev 13398)
+++ branches/cloth/blender/source/blender/src/buttons_object.c	2008-01-25 10:33:19 UTC (rev 13399)
@@ -2306,6 +2306,9 @@
 		ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
 		if(clmd)
 		{
+			/* force freeing because user wants */
+			clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
+			
 			CFRA= 1;
 			update_for_newframe_muted();
 			DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
@@ -2320,6 +2323,8 @@
 		ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
 		if(clmd)
 		{
+			/* force freeing because user wants */
+			clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
 			cloth_clear_cache(ob, clmd, MAX2(1.0,G.scene->r.cfra)); 
 			// MAX2(1.0,G.scene->r.cfra + 1.0)
 			allqueue(REDRAWBUTSOBJECT, 0);

Modified: branches/cloth/blender/source/blender/src/editmesh.c
===================================================================
--- branches/cloth/blender/source/blender/src/editmesh.c	2008-01-25 08:55:27 UTC (rev 13398)
+++ branches/cloth/blender/source/blender/src/editmesh.c	2008-01-25 10:33:19 UTC (rev 13399)
@@ -861,6 +861,8 @@
 			{
 				cloth_enabled = 1;
 				
+				clmd->sim_parms->editedframe = (float) G.scene->r.cfra;
+				
 				/* inverse matrix is not uptodate... */
 				Mat4Invert ( G.obedit->imat, G.obedit->obmat );
 			}
@@ -1092,7 +1094,7 @@
 			/* check if we have cache for this frame */
 			int stack_index = modifiers_indexInObject(G.obedit, (ModifierData *)clmd);
 		
-			if(BKE_ptcache_id_exist((ID *)G.obedit, (float) G.scene->r.cfra, stack_index))
+			if(BKE_ptcache_id_exist((ID *)G.obedit, clmd->sim_parms->editedframe, stack_index))
 			{
 				cloth_enabled = 1;
 				
@@ -1108,9 +1110,11 @@
 		
 		if(cloth_enabled)
 		{	
+			
 			VECCOPY(temp, cloth->verts[i].x);
 			VECCOPY(cloth->verts[i].x, eve->co);
 			Mat4MulVecfl ( G.obedit->obmat, cloth->verts[i].x );
+			
 			/*
 			// not physical correct but gives nicer results when commented
 			VECSUB(temp, cloth->verts[i].x, temp);
@@ -1154,7 +1158,15 @@
 	
 	/* burn changes to cache */
 	if(cloth_enabled)
-		cloth_write_cache(G.obedit, clmd, (float) G.scene->r.cfra);
+	{
+		cloth_write_cache(G.obedit, clmd, clmd->sim_parms->editedframe);
+		
+		/* in this case we have to get the data for the requested frame */
+		if(clmd->sim_parms->editedframe != (float) G.scene->r.cfra)
+		{
+			cloth_read_cache(G.obedit, clmd, (float) G.scene->r.cfra);
+		}
+	}
 
 	/* the edges */
 	a= 0;





More information about the Bf-blender-cvs mailing list