[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12716] branches/cloth/blender/source/ blender: Fix: GUI cache reset should work again, same goes for collision modifier (enabled through 'deflection' panel

Daniel Genrich daniel.genrich at gmx.net
Thu Nov 29 13:29:32 CET 2007


Revision: 12716
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12716
Author:   genscher
Date:     2007-11-29 13:29:32 +0100 (Thu, 29 Nov 2007)

Log Message:
-----------
Fix: GUI cache reset should work again, same goes for collision modifier (enabled through 'deflection' panel

Modified Paths:
--------------
    branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
    branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h
    branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
    branches/cloth/blender/source/blender/blenkernel/intern/collision.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_modifier_types.h
    branches/cloth/blender/source/blender/src/buttons_editing.c
    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	2007-11-29 11:00:38 UTC (rev 12715)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h	2007-11-29 12:29:32 UTC (rev 12716)
@@ -72,10 +72,10 @@
 } ClothVertex;
 
 typedef struct ClothSpring {
-	int	ij;		/* Pij from the paper, one end of the spring.	*/
-	int	kl;		/* Pkl from the paper, one end of the spring.	*/
+	unsigned int	ij;		/* Pij from the paper, one end of the spring.	*/
+	unsigned int	kl;		/* Pkl from the paper, one end of the spring.	*/
 	float	restlen;	/* The original length of the spring.	*/
-	int	matrix_index; 	/* needed for implicit solver (fast lookup) */
+	unsigned int	matrix_index; 	/* needed for implicit solver (fast lookup) */
 	int	type;		/* types defined in BKE_cloth.h ("springType") */
 	int	flags; 		/* defined in BKE_cloth.h, e.g. deactivated due to tearing */
 	float dfdx[3][3];
@@ -152,6 +152,7 @@
     CLOTH_SPRING_TYPE_STRUCTURAL = 0,
     CLOTH_SPRING_TYPE_SHEAR,
     CLOTH_SPRING_TYPE_BENDING,
+    CLOTH_SPRING_TYPE_COLLISION,
 } CLOTH_SPRING_TYPES;
 
 /* SPRING FLAGS */

Modified: branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h	2007-11-29 11:00:38 UTC (rev 12715)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h	2007-11-29 12:29:32 UTC (rev 12716)
@@ -37,12 +37,14 @@
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
+
 /* types */
 #include "BLI_linklist.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_object.h"
-#include "BKE_DerivedMesh.h"
 
+#include "DNA_modifier_types.h"
+
 // used in kdop.c and collision.c
 typedef struct CollisionTree
 {
@@ -82,6 +84,8 @@
 {
 	int point_indexA[4], point_indexB[4];
 	float vector[3];
+	float normal[3]; // has to be calculated from vector
+	float distance;
 	float pa[3], pb[3];
 }
 CollisionPair;
@@ -115,6 +119,10 @@
 // defined in collisions.c
 void collision_move_object(CollisionModifierData *collmd, float step, float prevstep);
 
+// interface for collision functions
+void collisions_compute_barycentric (float pv[3], float p1[3], float p2[3], float p3[3], float *w1, float *w2, float *w3);
+void interpolateOnTriangle(float to[3], float v1[3], float v2[3], float v3[3], double w1, double w2, double w3);
+
 /////////////////////////////////////////////////
 
 #endif

Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c	2007-11-29 11:00:38 UTC (rev 12715)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c	2007-11-29 12:29:32 UTC (rev 12716)
@@ -1009,6 +1009,7 @@
 ***************************************************************************************/
 
 // be carefull: implicit solver has to be resettet when using this one!
+// --> only for implicit handling of this spring!
 int cloth_add_spring ( ClothModifierData *clmd, unsigned int indexA, unsigned int indexB, float restlength, int spring_type)
 {
 	Cloth *cloth = clmd->clothObject;

Modified: branches/cloth/blender/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/collision.c	2007-11-29 11:00:38 UTC (rev 12715)
+++ branches/cloth/blender/source/blender/blenkernel/intern/collision.c	2007-11-29 12:29:32 UTC (rev 12716)
@@ -71,7 +71,6 @@
 
 #include "Bullet-C-Api.h"
 
-
 // step is limited from 0 (frame start position) to 1 (frame end position)
 void collision_move_object(CollisionModifierData *collmd, float step, float prevstep)
 {
@@ -83,6 +82,7 @@
 		VECSUB(tv, collmd->xnew[i].co, collmd->x[i].co);
 		VECADDS(collmd->current_x[i].co, collmd->x[i].co, tv, prevstep);
 		VECADDS(collmd->current_xnew[i].co, collmd->x[i].co, tv, step);
+		VECSUB(collmd->current_v[i].co, collmd->current_xnew[i].co, collmd->current_x[i].co);
 	}
 }
 

Modified: branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/implicit.c	2007-11-29 11:00:38 UTC (rev 12715)
+++ branches/cloth/blender/source/blender/blenkernel/intern/implicit.c	2007-11-29 12:29:32 UTC (rev 12716)
@@ -63,6 +63,8 @@
 #include "BKE_global.h"
 #include  "BIF_editdeform.h"
 
+#include "Bullet-C-Api.h"
+
 #ifdef _WIN32
 #include <windows.h>
 static LARGE_INTEGER _itstart, _itend;
@@ -1123,6 +1125,17 @@
 	}
 	
 	
+	if(s->type == CLOTH_SPRING_TYPE_COLLISION)
+	{
+		if(length < L)
+		{
+			mul_fvector_S(stretch_force, dir, (100.0*(length-L))); 
+	
+			VECADD(s->f, s->f, stretch_force);
+		}
+		return;
+	}
+	
 	// calculate force of structural + shear springs
 	if(s->type != CLOTH_SPRING_TYPE_BENDING)
 	{
@@ -1415,6 +1428,19 @@
 	{ 		
 		effectors= pdInitEffectors(ob,NULL);
 		
+		// clear constraint matrix from collisions
+		if(clmd->coll_parms->flags & CLOTH_COLLISIONSETTINGS_FLAG_ENABLED)
+		{
+			for(i = 0; i < id->S[0].vcount; i++)
+			{
+				if(!(verts [id->S[i].r].goal >= SOFTGOALSNAP))
+				{
+					id->S[0].vcount = i-1;
+					break;
+				}
+			}
+		}
+		
 		// calculate 
 		cloth_calc_force(clmd, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step );
 		
@@ -1553,122 +1579,148 @@
 	memcpy(id->V, cloth->v, sizeof(lfVector) * numverts);	
 }
 
+unsigned int implicit_getcreate_S_index(ClothModifierData *clmd, unsigned int index)
+{
+	Cloth *cloth = clmd->clothObject;
+	Implicit_Data *id = cloth->implicit;
+	unsigned int i = 0, pinned = 0;
+	
+	pinned = id->S[0].vcount;
+	
+	for(i = 0; i < pinned; i++)
+	{
+		if(id->S[i].r == index)
+		{
+			return index;
+		}
+	}
+	
+	// create new PINNED entry in constraint matrix
+	id->S[0].vcount++;
+	id->S[pinned].c = id->S[pinned].r = index;
+	return pinned;
+}
 
-int collisions_collision_response_static(ClothModifierData *clmd, ClothModifierData *coll_clmd)
+int collisions_collision_response_static ( ClothModifierData *clmd, CollisionModifierData *collmd, CollisionPair *collpair )
 {
-	/*
+
 	unsigned int i = 0;
 	int result = 0;
 	LinkNode *search = NULL;
-	CollPair *collpair = NULL;
-	Cloth *cloth1, *cloth2;
+	Cloth *cloth1 = NULL;
 	float w1, w2, w3, u1, u2, u3;
 	float v1[3], v2[3], relativeVelocity[3];
-	float magrelVel;
-	
+	float magrelVel = 0.0;
+	float epsilon = clmd->coll_parms->epsilon;
+
 	cloth1 = clmd->clothObject;
-	cloth2 = coll_clmd->clothObject;
-
-	// search = clmd->coll_parms.collision_list;
 	
-	while(search)
-	{
-	collpair = search->link;
-		
-		// compute barycentric coordinates for both collision points
-	collisions_compute_barycentric(collpair->pa,
-	cloth1->verts[collpair->ap1].txold,
-	cloth1->verts[collpair->ap2].txold,
-	cloth1->verts[collpair->ap3].txold, 
-	&w1, &w2, &w3);
+	if(!collpair)
+		return 0;
 	
-	collisions_compute_barycentric(collpair->pb,
-	cloth2->verts[collpair->bp1].txold,
-	cloth2->verts[collpair->bp2].txold,
-	cloth2->verts[collpair->bp3].txold,
-	&u1, &u2, &u3);
-	
-		// Calculate relative "velocity".
-	interpolateOnTriangle(v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3);
-		
-	interpolateOnTriangle(v2, cloth2->verts[collpair->bp1].tv, cloth2->verts[collpair->bp2].tv, cloth2->verts[collpair->bp3].tv, u1, u2, u3);
-		
-	VECSUB(relativeVelocity, v1, v2);
+	// TODO: check distance & calc normal
+			// calc distance + normal 	
+	collpair->distance = plNearestPoints(
+		cloth1->current_xold[collpair->point_indexA[0]],
+		cloth1->current_xold[collpair->point_indexA[1]],
+		cloth1->current_xold[collpair->point_indexA[2]], 
+		collmd->current_x[collpair->point_indexB[0]].co,
+		collmd->current_x[collpair->point_indexB[1]].co,
+		collmd->current_x[collpair->point_indexB[2]].co, 
+		collpair->pa,collpair->pb,collpair->vector);
 			
-		// Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal').
-	magrelVel = INPR(relativeVelocity, collpair->normal);
-		
-		// printf("magrelVel: %f\n", magrelVel);
-				
-		// Calculate masses of points.
-		
-		// If v_n_mag < 0 the edges are approaching each other.
-	if(magrelVel < -ALMOST_ZERO) 
+	if (collpair->distance > (epsilon + ALMOST_ZERO))
 	{
-			// Calculate Impulse magnitude to stop all motion in normal direction.
-			// const double I_mag = v_n_mag / (1/m1 + 1/m2);
-	float magnitude_i = magrelVel / 2.0f; // TODO implement masses
-	float tangential[3], magtangent, magnormal, collvel[3];
-	float vrel_t_pre[3];
-	float vrel_t[3];
-	double impulse;
-	float epsilon = clmd->coll_parms.epsilon;
-	float overlap = (epsilon + ALMOST_ZERO-collpair->distance);
-			
-			// calculateFrictionImpulse(tangential, relativeVelocity, collpair->normal, magrelVel, clmd->coll_parms.friction*0.01, magrelVel);
-			
-			// magtangent = INPR(tangential, tangential);
-			
-			// Apply friction impulse.
-	if (magtangent < -ALMOST_ZERO) 
+		return 0;
+	}
+
+	// compute barycentric coordinates for both collision points
+	collisions_compute_barycentric (collpair->pa,
+					cloth1->current_xold[collpair->point_indexA[0]],
+					cloth1->current_xold[collpair->point_indexA[1]],
+					cloth1->current_xold[collpair->point_indexA[2]],
+					&w1, &w2, &w3 );
+
+	collisions_compute_barycentric (collpair->pb,
+					collmd->current_x[collpair->point_indexB[0]].co,
+					collmd->current_x[collpair->point_indexB[1]].co,
+					collmd->current_x[collpair->point_indexB[2]].co,
+					&u1, &u2, &u3 );
+
+	// Calculate relative "velocity".
+	interpolateOnTriangle ( v1, cloth1->current_v[collpair->point_indexA[0]], cloth1->current_v[collpair->point_indexA[1]], cloth1->current_v[collpair->point_indexA[2]], w1, w2, w3 );
+
+	interpolateOnTriangle ( v2, collmd->current_v[collpair->point_indexB[0]].co, collmd->current_v[collpair->point_indexB[1]].co, collmd->current_v[collpair->point_indexB[2]].co, u1, u2, u3 );
+
+	VECSUB ( relativeVelocity, v1, v2 );
+
+	// Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal').
+	magrelVel = INPR ( relativeVelocity, collpair->normal );
+
+	// printf("magrelVel: %f\n", magrelVel);
+
+	// Calculate masses of points.
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list