[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13398] branches/cloth/blender/source/ blender: New: load cached data on file load; Fixed: Don' t destroy cache on fileload, calculate normals correctly, don' t reset all data when pressing partial free, making also cache free buttons available when cache is protected, duplicating cloth with shift-d should work properly now

Daniel Genrich daniel.genrich at gmx.net
Fri Jan 25 09:55:28 CET 2008


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

Log Message:
-----------
New: load cached data on file load; Fixed: Don't destroy cache on fileload, calculate normals correctly, don't reset all data when pressing partial free, making also cache free buttons available when cache is protected, duplicating cloth with shift-d should work properly now

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/implicit.c
    branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
    branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
    branches/cloth/blender/source/blender/src/buttons_object.c

Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h	2008-01-25 04:38:08 UTC (rev 13397)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h	2008-01-25 08:55:27 UTC (rev 13398)
@@ -128,17 +128,19 @@
 /* These are the bits used in SimSettings.flags. */
 typedef enum
 {
-    CLOTH_SIMSETTINGS_FLAG_RESET = ( 1 << 1 ),		// The CM object requires a reinitializaiton.
-    CLOTH_SIMSETTINGS_FLAG_COLLOBJ = ( 1 << 2 ), 	// object is only collision object, no cloth simulation is done
-    CLOTH_SIMSETTINGS_FLAG_GOAL = ( 1 << 3 ), 		// we have goals enabled
-    CLOTH_SIMSETTINGS_FLAG_TEARING = ( 1 << 4 ), // true if tearing is enabled
+    CLOTH_SIMSETTINGS_FLAG_RESET = ( 1 << 1 ),	// The CM object requires a reinitializaiton.
+    CLOTH_SIMSETTINGS_FLAG_COLLOBJ = ( 1 << 2 ),// object is only collision object, no cloth simulation is done
+    CLOTH_SIMSETTINGS_FLAG_GOAL = ( 1 << 3 ), 	// we have goals enabled
+    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_FLAGS;
 
-/* SPRING FLAGS */
+/* COLLISION FLAGS */
 typedef enum
 {
-    CLOTH_COLLISIONSETTINGS_FLAG_ENABLED = ( 1 << 1 ),
+    CLOTH_COLLSETTINGS_FLAG_ENABLED = ( 1 << 1 ), /* enables cloth - object collisions */
+    CLOTH_COLLSETTINGS_FLAG_SELF = ( 1 << 2 ), /* unused */
 } CLOTH_COLLISIONSETTINGS_FLAGS;
 
 /* Spring types as defined in the paper.*/
@@ -205,6 +207,9 @@
 // needed for editmesh.c
 void cloth_write_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 04:38:08 UTC (rev 13397)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c	2008-01-25 08:55:27 UTC (rev 13398)
@@ -153,7 +153,7 @@
 	clmd->sim_parms->mass = 1.0f;
 	clmd->sim_parms->stepsPerFrame = 5;
 	clmd->sim_parms->sim_time = 1.0;
-	clmd->sim_parms->flags = CLOTH_SIMSETTINGS_FLAG_RESET;
+	clmd->sim_parms->flags = CLOTH_SIMSETTINGS_FLAG_NEW;
 	clmd->sim_parms->solver_type = 0;
 	clmd->sim_parms->preroll = 0;
 	clmd->sim_parms->maxspringlen = 10;
@@ -166,7 +166,7 @@
 	clmd->coll_parms->friction = 10.0;
 	clmd->coll_parms->loop_count = 1;
 	clmd->coll_parms->epsilon = 0.01f;
-	clmd->coll_parms->flags = CLOTH_COLLISIONSETTINGS_FLAG_ENABLED;
+	clmd->coll_parms->flags = CLOTH_COLLSETTINGS_FLAG_ENABLED;
 
 	/* These defaults are copied from softbody.c's
 	* softbody_calc_forces() function.
@@ -533,7 +533,8 @@
 {
 	int stack_index = -1;
 	
-	if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT))
+	/* 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))
 	{
 		stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
 		
@@ -635,8 +636,6 @@
 		return result;
 	}
 	
-	// printf("ct: %f, st: %f, r.cfra: %f, dt: %f\n", current_time, clmd->sim_parms->sim_time, ( float ) G.scene->r.cfra, deltaTime);
-
 	// unused in the moment, calculated seperately in implicit.c
 	clmd->sim_parms->dt = 1.0f / clmd->sim_parms->stepsPerFrame;
 
@@ -659,6 +658,8 @@
 		{
 			cloth_clear_cache(ob, clmd, 0);
 			
+			// printf("v1: %d, v2: %d\n", numverts, clmd->clothObject->numverts);
+			
 			if ( !cloth_from_object ( ob, clmd, result, framenr ) )
 				return result;
 
@@ -718,6 +719,9 @@
 		else
 		{
 			cloth_clear_cache(ob, clmd, 0);
+			
+			if ( !cloth_from_object ( ob, clmd, result, framenr ) )
+				return result;
 		}
 	}
 	
@@ -743,9 +747,9 @@
 			cloth_clear_cache ( ob, clmd, 0 );
 			
 			// If our solver provides a free function, call it
-			if ( cloth->old_solver_type < 255 && solvers [cloth->old_solver_type].free )
+			if ( solvers [clmd->sim_parms->solver_type].free )
 			{
-				solvers [cloth->old_solver_type].free ( clmd );
+				solvers [clmd->sim_parms->solver_type].free ( clmd );
 			}
 
 			// Free the verts.
@@ -805,9 +809,9 @@
 	if ( cloth )
 	{	
 		// If our solver provides a free function, call it
-		if ( cloth->old_solver_type < 255 && solvers [cloth->old_solver_type].free )
+		if ( solvers [clmd->sim_parms->solver_type].free )
 		{
-			solvers [cloth->old_solver_type].free ( clmd );
+			solvers [clmd->sim_parms->solver_type].free ( clmd );
 		}
 
 		// Free the verts.
@@ -972,7 +976,9 @@
 
 	// If we have a clothObject, free it. 
 	if ( clmd->clothObject != NULL )
+	{
 		cloth_free_modifier ( ob, clmd );
+	}
 
 	// Allocate a new cloth object.
 	clmd->clothObject = MEM_callocN ( sizeof ( Cloth ), "cloth" );
@@ -1041,9 +1047,10 @@
 			solvers [clmd->sim_parms->solver_type].init ( ob, clmd );
 
 		clmd->clothObject->tree = bvh_build_from_cloth ( clmd, clmd->coll_parms->epsilon );
-
-		cloth_write_cache(ob, clmd, framenr-1);
 		
+		if(!cloth_read_cache(ob, clmd, framenr))
+			cloth_write_cache(ob, clmd, framenr);
+		
 		return 1;
 	}
 	return 0;

Modified: branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/implicit.c	2008-01-25 04:38:08 UTC (rev 13397)
+++ branches/cloth/blender/source/blender/blenkernel/intern/implicit.c	2008-01-25 08:55:27 UTC (rev 13398)
@@ -1389,7 +1389,7 @@
 		
 		add_lfvector_lfvectorS(id->Xnew, id->X, id->Vnew, dt, numverts);
 		
-		if(clmd->coll_parms->flags & CLOTH_COLLISIONSETTINGS_FLAG_ENABLED)
+		if(clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)
 		{
 			// collisions 
 			// itstart();

Modified: branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/modifier.c	2008-01-25 04:38:08 UTC (rev 13397)
+++ branches/cloth/blender/source/blender/blenkernel/intern/modifier.c	2008-01-25 08:55:27 UTC (rev 13398)
@@ -4972,6 +4972,7 @@
 
 	if(result)
 	{
+		CDDM_calc_normals(result);
 		return result;
 	}
 	return derivedData;
@@ -5020,7 +5021,23 @@
 	return dataMask;
 }
 
+static void clothModifier_copyData(ModifierData *md, ModifierData *target)
+{
+	ClothModifierData *clmd = (ClothModifierData*) md;
+	ClothModifierData *tclmd = (ClothModifierData*) target;
+	
+	if(tclmd->sim_parms)
+		MEM_freeN(tclmd->sim_parms);
+	if(tclmd->coll_parms)
+		MEM_freeN(tclmd->coll_parms);	
+	
+	tclmd->sim_parms = MEM_dupallocN(clmd->sim_parms);
+	tclmd->coll_parms = MEM_dupallocN(clmd->coll_parms);
+	
+	tclmd->sim_parms->lastcachedframe = 0;
+}
 
+
 static int clothModifier_dependsOnTime(ModifierData *md)
 {
 	return 1;
@@ -5035,8 +5052,10 @@
 		
 		cloth_free_modifier_extern (clmd);
 		
-		MEM_freeN(clmd->sim_parms);
-		MEM_freeN(clmd->coll_parms);
+		if(clmd->sim_parms)
+			MEM_freeN(clmd->sim_parms);
+		if(clmd->coll_parms)
+			MEM_freeN(clmd->coll_parms);	
 	}
 }
 
@@ -7033,8 +7052,7 @@
 		mti->dependsOnTime = clothModifier_dependsOnTime;
 		mti->freeData = clothModifier_freeData; 
 		mti->requiredDataMask = clothModifier_requiredDataMask;
-		// mti->copyData = clothModifier_copyData;
-		// mti->deformVerts = clothModifier_deformVerts;
+		mti->copyData = clothModifier_copyData;
 		mti->applyModifier = clothModifier_applyModifier;
 		mti->updateDepgraph = clothModifier_updateDepgraph;
 		

Modified: branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
===================================================================
--- branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h	2008-01-25 04:38:08 UTC (rev 13397)
+++ branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h	2008-01-25 08:55:27 UTC (rev 13398)
@@ -69,7 +69,7 @@
 	float	eff_force_scale;/* Scaling of effector forces (see softbody_calc_forces).*/
 	float	eff_wind_scale;	/* Scaling of effector wind (see softbody_calc_forces).	*/
 	float 	sim_time_old;
-	struct	LinkNode *cache;
+	struct	LinkNode *cache; /* UNUSED atm */
 	float	defgoal;
 	int	goalfrict;
 	float	goalspring;
@@ -113,7 +113,7 @@
 	unsigned int		numverts;		/* The number of verts == m * n. */
 	unsigned int		numsprings;		/* The count of springs. */
 	unsigned int		numfaces;
-	unsigned char 		old_solver_type;
+	unsigned char 		old_solver_type;	/* unused, only 1 solver here */
 	unsigned char 		pad2;
 	short 			pad3;
 	struct BVH		*tree;			/* collision tree for this cloth object */

Modified: branches/cloth/blender/source/blender/src/buttons_object.c
===================================================================
--- branches/cloth/blender/source/blender/src/buttons_object.c	2008-01-25 04:38:08 UTC (rev 13397)
+++ branches/cloth/blender/source/blender/src/buttons_object.c	2008-01-25 08:55:27 UTC (rev 13398)
@@ -2320,7 +2320,8 @@
 		ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
 		if(clmd)
 		{
-			cloth_clear_cache(ob, clmd, MAX2(1.0,G.scene->r.cfra + 1.0));
+			cloth_clear_cache(ob, clmd, MAX2(1.0,G.scene->r.cfra)); 
+			// MAX2(1.0,G.scene->r.cfra + 1.0)
 			allqueue(REDRAWBUTSOBJECT, 0);
 		}
 	}
@@ -5071,18 +5072,12 @@
 		uiBlockBeginAlign(block);
 		uiDefButF(block, NUM, B_CLOTH_RENEW, "StructStiff:",	   10,170,150,20, &clmd->sim_parms->structural, 1.0, 10000.0, 100, 0, "Overall stiffness of structure");
 		uiDefButF(block, NUM, B_CLOTH_RENEW, "BendStiff:",	   160,170,150,20, &clmd->sim_parms->bending, 0.0, 10000.0, 1000, 0, "Wrinkle coefficient (higher = less smaller but more big wrinkles)");
-		uiDefButI(block, NUM, B_CLOTH_RENEW, "Quality:",	   10,150,150,20, &clmd->sim_parms->stepsPerFrame, 1.0, 100.0, 5, 0, "Quality of the simulation (higher=better=slower)");
-		uiBlockEndAlign(block);
-		uiBlockBeginAlign(block);
+		uiDefButI(block, NUM, B_CLOTH_RENEW, "Quality:",	   10,150,150,20, &clmd->sim_parms->stepsPerFrame, 4.0, 100.0, 5, 0, "Quality of the simulation (higher=better=slower)");
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list