[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14975] branches/cloth/blender/source/ blender/blenkernel/intern: -= Cloth =-
Daniel Genrich
daniel.genrich at gmx.net
Mon May 26 11:39:34 CEST 2008
Revision: 14975
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14975
Author: genscher
Date: 2008-05-26 11:39:32 +0200 (Mon, 26 May 2008)
Log Message:
-----------
-= Cloth =-
1. Fix selfcollisions (reported by nudelZ)
Modified Paths:
--------------
branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
branches/cloth/blender/source/blender/blenkernel/intern/collision.c
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-05-26 05:43:50 UTC (rev 14974)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-05-26 09:39:32 UTC (rev 14975)
@@ -499,15 +499,15 @@
Mat4MulVecfl(ob->obmat, verts->xconst);
}
- tstart();
+ // tstart();
/* call the solver. */
if(solvers [clmd->sim_parms->solver_type].solver)
- ret = solvers[clmd->sim_parms->solver_type].solver(ob, framenr, clmd, effectors);
+ BENCH(ret = solvers[clmd->sim_parms->solver_type].solver(ob, framenr, clmd, effectors));
- tend();
+ // tend();
- printf ( "Cloth simulation time: %f\n", ( float ) tval() );
+ // printf ( "Cloth simulation time: %f\n", ( float ) tval() );
return ret;
}
@@ -969,7 +969,6 @@
// has to be happen before springs are build!
cloth_apply_vgroup (clmd, dm);
-
if ( !cloth_build_springs ( clmd, dm ) )
{
cloth_free_modifier ( ob, clmd );
@@ -994,7 +993,7 @@
if(!first)
implicit_set_positions(clmd);
- BENCH(clmd->clothObject->bvhtree = bvhtree_build_from_cloth ( clmd, clmd->coll_parms->epsilon ));
+ clmd->clothObject->bvhtree = bvhtree_build_from_cloth ( clmd, clmd->coll_parms->epsilon );
for(i = 0; i < dm->getNumVerts(dm); i++)
{
Modified: branches/cloth/blender/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/collision.c 2008-05-26 05:43:50 UTC (rev 14974)
+++ branches/cloth/blender/source/blender/blenkernel/intern/collision.c 2008-05-26 09:39:32 UTC (rev 14975)
@@ -178,16 +178,16 @@
***********************************/
/**
- * gsl_poly_solve_cubic -
- *
- * copied from SOLVE_CUBIC.C --> GSL
- */
+* gsl_poly_solve_cubic -
+*
+* copied from SOLVE_CUBIC.C --> GSL
+*/
#define mySWAP(a,b) do { double tmp = b ; b = a ; a = tmp ; } while(0)
int
- gsl_poly_solve_cubic (double a, double b, double c,
- double *x0, double *x1, double *x2)
+gsl_poly_solve_cubic (double a, double b, double c,
+ double *x0, double *x1, double *x2)
{
double q = (a * a - 3 * b);
double r = (2 * a * a * a - 9 * a * b + 27 * c);
@@ -210,10 +210,10 @@
}
else if (CR2 == CQ3)
{
- /* this test is actually R2 == Q3, written in a form suitable
+ /* this test is actually R2 == Q3, written in a form suitable
for exact computation with integers */
- /* Due to finite precision some double roots may be missed, and
+ /* Due to finite precision some double roots may be missed, and
considered to be a pair of complex roots z = x +/- epsilon i
close to the real axis. */
@@ -242,20 +242,20 @@
*x0 = norm * cos (theta / 3) - a / 3;
*x1 = norm * cos ((theta + 2.0 * M_PI) / 3) - a / 3;
*x2 = norm * cos ((theta - 2.0 * M_PI) / 3) - a / 3;
-
+
/* Sort *x0, *x1, *x2 into increasing order */
if (*x0 > *x1)
mySWAP(*x0, *x1) ;
-
+
if (*x1 > *x2)
{
mySWAP(*x1, *x2) ;
-
+
if (*x0 > *x1)
mySWAP(*x0, *x1) ;
}
-
+
return 3;
}
else
@@ -271,13 +271,13 @@
/**
- * gsl_poly_solve_quadratic
- *
- * copied from GSL
- */
+* gsl_poly_solve_quadratic
+*
+* copied from GSL
+*/
int
- gsl_poly_solve_quadratic (double a, double b, double c,
- double *x0, double *x1)
+gsl_poly_solve_quadratic (double a, double b, double c,
+ double *x0, double *x1)
{
double disc = b * b - 4 * a * c;
@@ -338,55 +338,55 @@
/*
- * See Bridson et al. "Robust Treatment of Collision, Contact and Friction for Cloth Animation"
- * page 4, left column
- */
+* See Bridson et al. "Robust Treatment of Collision, Contact and Friction for Cloth Animation"
+* page 4, left column
+*/
int cloth_get_collision_time ( double a[3], double b[3], double c[3], double d[3], double e[3], double f[3], double solution[3] )
{
int num_sols = 0;
// x^0 - checked
double g = a[0] * c[1] * e[2] - a[0] * c[2] * e[1] +
- a[1] * c[2] * e[0] - a[1] * c[0] * e[2] +
- a[2] * c[0] * e[1] - a[2] * c[1] * e[0];
-
+ a[1] * c[2] * e[0] - a[1] * c[0] * e[2] +
+ a[2] * c[0] * e[1] - a[2] * c[1] * e[0];
+
// x^1
double h = -b[2] * c[1] * e[0] + b[1] * c[2] * e[0] - a[2] * d[1] * e[0] +
- a[1] * d[2] * e[0] + b[2] * c[0] * e[1] - b[0] * c[2] * e[1] +
- a[2] * d[0] * e[1] - a[0] * d[2] * e[1] - b[1] * c[0] * e[2] +
- b[0] * c[1] * e[2] - a[1] * d[0] * e[2] + a[0] * d[1] * e[2] -
- a[2] * c[1] * f[0] + a[1] * c[2] * f[0] + a[2] * c[0] * f[1] -
- a[0] * c[2] * f[1] - a[1] * c[0] * f[2] + a[0] * c[1] * f[2];
+ a[1] * d[2] * e[0] + b[2] * c[0] * e[1] - b[0] * c[2] * e[1] +
+ a[2] * d[0] * e[1] - a[0] * d[2] * e[1] - b[1] * c[0] * e[2] +
+ b[0] * c[1] * e[2] - a[1] * d[0] * e[2] + a[0] * d[1] * e[2] -
+ a[2] * c[1] * f[0] + a[1] * c[2] * f[0] + a[2] * c[0] * f[1] -
+ a[0] * c[2] * f[1] - a[1] * c[0] * f[2] + a[0] * c[1] * f[2];
// x^2
double i = -b[2] * d[1] * e[0] + b[1] * d[2] * e[0] +
- b[2] * d[0] * e[1] - b[0] * d[2] * e[1] -
- b[1] * d[0] * e[2] + b[0] * d[1] * e[2] -
- b[2] * c[1] * f[0] + b[1] * c[2] * f[0] -
- a[2] * d[1] * f[0] + a[1] * d[2] * f[0] +
- b[2] * c[0] * f[1] - b[0] * c[2] * f[1] +
- a[2] * d[0] * f[1] - a[0] * d[2] * f[1] -
- b[1] * c[0] * f[2] + b[0] * c[1] * f[2] -
- a[1] * d[0] * f[2] + a[0] * d[1] * f[2];
-
+ b[2] * d[0] * e[1] - b[0] * d[2] * e[1] -
+ b[1] * d[0] * e[2] + b[0] * d[1] * e[2] -
+ b[2] * c[1] * f[0] + b[1] * c[2] * f[0] -
+ a[2] * d[1] * f[0] + a[1] * d[2] * f[0] +
+ b[2] * c[0] * f[1] - b[0] * c[2] * f[1] +
+ a[2] * d[0] * f[1] - a[0] * d[2] * f[1] -
+ b[1] * c[0] * f[2] + b[0] * c[1] * f[2] -
+ a[1] * d[0] * f[2] + a[0] * d[1] * f[2];
+
// x^3 - checked
double j = -b[2] * d[1] * f[0] + b[1] * d[2] * f[0] +
- b[2] * d[0] * f[1] - b[0] * d[2] * f[1] -
- b[1] * d[0] * f[2] + b[0] * d[1] * f[2];
-
+ b[2] * d[0] * f[1] - b[0] * d[2] * f[1] -
+ b[1] * d[0] * f[2] + b[0] * d[1] * f[2];
+
/*
printf("r1: %lf\n", a[0] * c[1] * e[2] - a[0] * c[2] * e[1]);
printf("r2: %lf\n", a[1] * c[2] * e[0] - a[1] * c[0] * e[2]);
printf("r3: %lf\n", a[2] * c[0] * e[1] - a[2] * c[1] * e[0]);
-
+
printf("x1 x: %f, y: %f, z: %f\n", a[0], a[1], a[2]);
printf("x2 x: %f, y: %f, z: %f\n", c[0], c[1], c[2]);
printf("x3 x: %f, y: %f, z: %f\n", e[0], e[1], e[2]);
-
+
printf("v1 x: %f, y: %f, z: %f\n", b[0], b[1], b[2]);
printf("v2 x: %f, y: %f, z: %f\n", d[0], d[1], d[2]);
printf("v3 x: %f, y: %f, z: %f\n", f[0], f[1], f[2]);
-
+
printf("t^3: %lf, t^2: %lf, t^1: %lf, t^0: %lf\n", j, i, h, g);
*/
@@ -517,17 +517,17 @@
// compute barycentric coordinates for both collision points
collision_compute_barycentric ( collpair->pa,
- cloth1->verts[collpair->ap1].txold,
- cloth1->verts[collpair->ap2].txold,
- cloth1->verts[collpair->ap3].txold,
- &w1, &w2, &w3 );
+ cloth1->verts[collpair->ap1].txold,
+ cloth1->verts[collpair->ap2].txold,
+ cloth1->verts[collpair->ap3].txold,
+ &w1, &w2, &w3 );
// was: txold
collision_compute_barycentric ( collpair->pb,
- collmd->current_x[collpair->bp1].co,
- collmd->current_x[collpair->bp2].co,
- collmd->current_x[collpair->bp3].co,
- &u1, &u2, &u3 );
+ collmd->current_x[collpair->bp1].co,
+ collmd->current_x[collpair->bp2].co,
+ collmd->current_x[collpair->bp3].co,
+ &u1, &u2, &u3 );
// Calculate relative "velocity".
collision_interpolateOnTriangle ( v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3 );
@@ -696,7 +696,7 @@
#ifdef WITH_BULLET
// calc distance + normal
distance = plNearestPoints (
- verts1[collpair->ap1].txold, verts1[collpair->ap2].txold, verts1[collpair->ap3].txold, collmd->current_x[collpair->bp1].co, collmd->current_x[collpair->bp2].co, collmd->current_x[collpair->bp3].co, collpair->pa,collpair->pb,collpair->vector );
+ verts1[collpair->ap1].txold, verts1[collpair->ap2].txold, verts1[collpair->ap3].txold, collmd->current_x[collpair->bp1].co, collmd->current_x[collpair->bp2].co, collmd->current_x[collpair->bp3].co, collpair->pa,collpair->pb,collpair->vector );
#else
// just be sure that we don't add anything
distance = 2.0 * ( epsilon1 + epsilon2 + ALMOST_ZERO );
@@ -745,16 +745,16 @@
VECSUB ( temp, verts1[edgecollpair->p12].txold, verts2[edgecollpair->p22].co );
if ( ABS ( INPR ( temp, temp ) ) < ALMOST_ZERO )
return 1;
-
+
VECSUB ( temp, verts1[edgecollpair->p11].txold, verts1[edgecollpair->p12].txold );
if ( ABS ( INPR ( temp, temp ) ) < ALMOST_ZERO )
return 1;
-
+
VECSUB ( temp, verts2[edgecollpair->p21].co, verts2[edgecollpair->p22].co );
if ( ABS ( INPR ( temp, temp ) ) < ALMOST_ZERO )
return 1;
-
+
return 0;
}
@@ -771,23 +771,19 @@
for ( ; collpair != collision_end; collpair++ )
{
- // only handle static collisions here
- if ( collpair->flag & COLLISION_IN_FUTURE )
- continue;
-
// compute barycentric coordinates for both collision points
collision_compute_barycentric ( collpair->pa,
- cloth1->verts[collpair->ap1].txold,
- cloth1->verts[collpair->ap2].txold,
- cloth1->verts[collpair->ap3].txold,
- &w1, &w2, &w3 );
+ cloth1->verts[collpair->ap1].txold,
+ cloth1->verts[collpair->ap2].txold,
+ cloth1->verts[collpair->ap3].txold,
+ &w1, &w2, &w3 );
// was: txold
collision_compute_barycentric ( collpair->pb,
- collmd->current_x[collpair->bp1].co,
- collmd->current_x[collpair->bp2].co,
- collmd->current_x[collpair->bp3].co,
- &u1, &u2, &u3 );
+ collmd->current_x[collpair->bp1].co,
+ collmd->current_x[collpair->bp2].co,
+ collmd->current_x[collpair->bp3].co,
+ &u1, &u2, &u3 );
// Calculate relative "velocity".
collision_interpolateOnTriangle ( v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3 );
@@ -853,25 +849,250 @@
d = clmd->coll_parms->epsilon*8.0/9.0 + epsilon2*8.0/9.0 - collpair->distance;
if ( ( magrelVel < 0.1*d*clmd->sim_parms->stepsPerFrame ) && ( d > ALMOST_ZERO ) )
{
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list