[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12488] branches/cloth/blender/source/ blender: Bugfix for wrong springs (resulted in weird behaviour), Implemented two speedups: One for small bending/wrinkle values (1/ 3 speedup), another speedup is that cloth get automatically in sleep mode but wakes up every frame ([quality-1]/quality speedup)
Daniel Genrich
daniel.genrich at gmx.net
Tue Nov 6 03:30:53 CET 2007
Revision: 12488
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12488
Author: genscher
Date: 2007-11-06 03:30:53 +0100 (Tue, 06 Nov 2007)
Log Message:
-----------
Bugfix for wrong springs (resulted in weird behaviour), Implemented two speedups: One for small bending/wrinkle values (1/3 speedup), another speedup is that cloth get automatically in sleep mode but wakes up every frame ([quality-1]/quality speedup)
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/makesdna/DNA_cloth_types.h
Removed Paths:
-------------
branches/cloth/blender/source/blender/blenkernel/intern/verlet.c
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2007-11-05 21:06:27 UTC (rev 12487)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2007-11-06 02:30:53 UTC (rev 12488)
@@ -86,7 +86,9 @@
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_CCACHE_PROTECT = ( 1 << 5 ),
+ CLOTH_SIMSETTINGS_FLAG_BIG_FORCE = ( 1 << 6 ), // true if we have big spring force for bending
+ CLOTH_SIMSETTINGS_FLAG_SLEEP = ( 1 << 7 ), // true if we let the cloth go to sleep
} CLOTH_SIMSETTINGS_FLAGS;
/* SPRING FLAGS */
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-11-05 21:06:27 UTC (rev 12487)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-11-06 02:30:53 UTC (rev 12488)
@@ -114,7 +114,7 @@
static CM_SOLVER_DEF solvers [] =
{
{ "Implicit", CM_IMPLICIT, implicit_init, implicit_solver, implicit_free },
- { "Verlet", CM_VERLET, verlet_init, verlet_solver, verlet_free },
+ // { "Verlet", CM_VERLET, verlet_init, verlet_solver, verlet_free },
};
/* ********** cloth engine ******* */
@@ -504,8 +504,9 @@
// if(!cloth_cache_search_frame(clmd, framenr))
{
verts = cloth->verts;
- /*
+
// Force any pinned verts to their constrained location.
+ // has to be commented for verlet
for ( i = 0; i < clmd->clothObject->numverts; i++, verts++ )
{
// Save the previous position.
@@ -515,7 +516,7 @@
VECCOPY ( verts->xconst, mvert[i].co );
Mat4MulVecfl ( ob->obmat, verts->xconst );
}
- */
+
tstart();
/* Call the solver. */
@@ -1031,8 +1032,8 @@
{
spring = ( ClothSpring * ) MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" );
- spring->ij = mface[i].v1;
- spring->kl = mface[i].v3;
+ spring->ij = mface[i].v2;
+ spring->kl = mface[i].v4;
VECSUB ( temp, mvert[spring->kl].co, mvert[spring->ij].co );
spring->restlen = sqrt ( INPR ( temp, temp ) );
spring->type = CLOTH_SPRING_TYPE_SHEAR;
@@ -1045,7 +1046,7 @@
node = node2;
}
}
-
+
// bending springs
search2 = cloth->springs;
for ( i = struct_springs; i < struct_springs+shear_springs; i++ )
@@ -1083,9 +1084,10 @@
}
search2 = search2->next;
}
-
- cloth->numsprings = struct_springs + shear_springs + bend_springs;
-
+
+ cloth->numspringssave = cloth->numsprings = struct_springs + shear_springs + bend_springs;
+ cloth->numothersprings = struct_springs + shear_springs;
+
for ( i = 0; i < numverts; i++ )
{
BLI_linklist_free ( edgelist[i],NULL );
Modified: branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/implicit.c 2007-11-05 21:06:27 UTC (rev 12487)
+++ branches/cloth/blender/source/blender/blenkernel/intern/implicit.c 2007-11-06 02:30:53 UTC (rev 12488)
@@ -812,6 +812,31 @@
return 1;
}
+void cloth_bending_mode(ClothModifierData *clmd, int enabled)
+{
+ Cloth *cloth = clmd->clothObject;
+ Implicit_Data *id;
+
+ if(cloth)
+ {
+ id = cloth->implicit;
+
+ if(id)
+ {
+ if(enabled)
+ {
+ cloth->numsprings = cloth->numspringssave;
+ }
+ else
+ {
+ cloth->numsprings = cloth->numothersprings;
+ }
+
+ id->A[0].scount = id->dFdV[0].scount = id->dFdX[0].scount = id->P[0].scount = id->Pinv[0].scount = id->bigI[0].scount = cloth->numsprings;
+ }
+ }
+}
+
DO_INLINE float fb(float length, float L)
{
float x = length/L;
@@ -1223,37 +1248,48 @@
{
if(length < L)
{
+ // clmd->sim_parms.flags |= CLOTH_SIMSETTINGS_FLAG_BIG_FORCE;
+
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
k = clmd->sim_parms.bending;
mul_fvector_S(bending_force, dir, fbstar(length, L, k, cb));
VECADD(s->f, s->f, bending_force);
-
+
+ if(INPR(bending_force,bending_force) > 0.13*0.13)
+ {
+ clmd->sim_parms.flags |= CLOTH_SIMSETTINGS_FLAG_BIG_FORCE;
+ }
+
dfdx_spring_type2(s->dfdx, dir,length,L,k, cb);
}
}
}
-DO_INLINE void cloth_apply_spring_force(ClothModifierData *clmd, ClothSpring *s, lfVector *lF, lfVector *X, lfVector *V, fmatrix3x3 *dFdV, fmatrix3x3 *dFdX)
+DO_INLINE int cloth_apply_spring_force(ClothModifierData *clmd, ClothSpring *s, lfVector *lF, lfVector *X, lfVector *V, fmatrix3x3 *dFdV, fmatrix3x3 *dFdX)
{
if(s->flags & CLOTH_SPRING_FLAG_NEEDED)
{
+ VECADD(lF[s->ij], lF[s->ij], s->f);
+ VECSUB(lF[s->kl], lF[s->kl], s->f);
+
if(s->type != CLOTH_SPRING_TYPE_BENDING)
{
sub_fmatrix_fmatrix(dFdV[s->ij].m, dFdV[s->ij].m, s->dfdv);
sub_fmatrix_fmatrix(dFdV[s->kl].m, dFdV[s->kl].m, s->dfdv);
add_fmatrix_fmatrix(dFdV[s->matrix_index].m, dFdV[s->matrix_index].m, s->dfdv);
}
-
- VECADD(lF[s->ij], lF[s->ij], s->f);
- VECSUB(lF[s->kl], lF[s->kl], s->f);
-
+ else if(!(clmd->sim_parms.flags & CLOTH_SIMSETTINGS_FLAG_BIG_FORCE))
+ return 0;
+
sub_fmatrix_fmatrix(dFdX[s->ij].m, dFdX[s->ij].m, s->dfdx);
sub_fmatrix_fmatrix(dFdX[s->kl].m, dFdX[s->kl].m, s->dfdx);
add_fmatrix_fmatrix(dFdX[s->matrix_index].m, dFdX[s->matrix_index].m, s->dfdx);
- }
+ }
+
+ return 1;
}
DO_INLINE void calculateTriangleNormal(float to[3], lfVector *X, MFace mface)
@@ -1386,15 +1422,34 @@
search = search->next;
}
+ if(clmd->sim_parms.flags & CLOTH_SIMSETTINGS_FLAG_BIG_FORCE)
+ {
+ if(cloth->numspringssave != cloth->numsprings)
+ {
+ cloth_bending_mode(clmd, 1);
+ }
+ }
+ else
+ {
+ if(cloth->numspringssave == cloth->numsprings)
+ {
+ cloth_bending_mode(clmd, 0);
+ }
+ }
+
// apply spring forces
search = cloth->springs;
while(search)
{
// only handle active springs
// if(((clmd->sim_parms.flags & CSIMSETT_FLAG_TEARING_ENABLED) && !(springs[i].flags & CSPRING_FLAG_DEACTIVATE))|| !(clmd->sim_parms.flags & CSIMSETT_FLAG_TEARING_ENABLED))
- cloth_apply_spring_force(clmd, search->link, lF, lX, lV, dFdV, dFdX);
+ if(!cloth_apply_spring_force(clmd, search->link, lF, lX, lV, dFdV, dFdX))
+ break;
search = search->next;
}
+
+ clmd->sim_parms.flags &= ~CLOTH_SIMSETTINGS_FLAG_BIG_FORCE;
+
}
void simulate_implicit_euler(lfVector *Vnew, lfVector *lX, lfVector *lV, lfVector *lF, fmatrix3x3 *dFdV, fmatrix3x3 *dFdX, float dt, fmatrix3x3 *A, lfVector *B, lfVector *dV, fmatrix3x3 *S, lfVector *z, lfVector *olddV, fmatrix3x3 *P, fmatrix3x3 *Pinv)
@@ -1438,6 +1493,8 @@
float dt = 1.0f / clmd->sim_parms.stepsPerFrame;
Implicit_Data *id = cloth->implicit;
int result = 0;
+ float force = 0, lastforce = 0;
+ lfVector *dx;
if(clmd->sim_parms.flags & CLOTH_SIMSETTINGS_FLAG_GOAL) /* do goal stuff */
{
@@ -1457,11 +1514,28 @@
effectors= pdInitEffectors(ob,NULL);
// calculate
- cloth_calc_force(clmd, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step );
- simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt, id->A, id->B, id->dV, id->S, id->z, id->olddV, id->P, id->Pinv);
+ cloth_calc_force(clmd, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step );
- add_lfvector_lfvectorS(id->Xnew, id->X, id->Vnew, dt, numverts);
+ // check for sleeping
+ if(!(clmd->coll_parms.flags & CLOTH_SIMSETTINGS_FLAG_SLEEP))
+ {
+ simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt, id->A, id->B, id->dV, id->S, id->z, id->olddV, id->P, id->Pinv);
+ add_lfvector_lfvectorS(id->Xnew, id->X, id->Vnew, dt, numverts);
+ }
+
+ dx = create_lfvector(numverts);
+ sub_lfvector_lfvector(dx, id->Xnew, id->X, numverts);
+ force = dot_lfvector(dx, dx, numverts);
+ del_lfvector(dx);
+
+ if((force < 0.00001) && (lastforce >= force))
+ clmd->coll_parms.flags |= CLOTH_SIMSETTINGS_FLAG_SLEEP;
+ else if((lastforce*2 < force))
+ clmd->coll_parms.flags &= ~CLOTH_SIMSETTINGS_FLAG_SLEEP;
+
+ lastforce = force;
+
if(clmd->coll_parms.flags & CLOTH_COLLISIONSETTINGS_FLAG_ENABLED)
{
// collisions
Deleted: branches/cloth/blender/source/blender/blenkernel/intern/verlet.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/verlet.c 2007-11-05 21:06:27 UTC (rev 12487)
+++ branches/cloth/blender/source/blender/blenkernel/intern/verlet.c 2007-11-06 02:30:53 UTC (rev 12488)
@@ -1,170 +0,0 @@
-/* implicit.c
-*
-*
-* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version. The Blender
-* Foundation also sells licenses for use in proprietary software under
-* the Blender License. See http://www.blender.org/BL/ for information
-* about this.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software Foundation,
-* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-* The Original Code is Copyright (C) Blender Foundation
-* All rights reserved.
-*
-* The Original Code is: all of this file.
-*
-* Contributor(s): none yet.
-*
-* ***** END GPL/BL DUAL LICENSE BLOCK *****
-*/
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include "MEM_guardedalloc.h"
-/* types */
-#include "DNA_curve_types.h"
-#include "DNA_object_types.h"
-#include "DNA_object_force.h"
-#include "DNA_cloth_types.h"
-#include "DNA_key_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_lattice_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_modifier_types.h"
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list