[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12653] branches/cloth/blender/source/ blender/blenkernel: Fixed numerical issues, hardened it again.
Daniel Genrich
daniel.genrich at gmx.net
Thu Nov 22 18:02:37 CET 2007
Revision: 12653
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12653
Author: genscher
Date: 2007-11-22 18:02:37 +0100 (Thu, 22 Nov 2007)
Log Message:
-----------
Fixed numerical issues, hardened it again.
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
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2007-11-22 16:30:14 UTC (rev 12652)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2007-11-22 17:02:37 UTC (rev 12653)
@@ -72,8 +72,8 @@
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][4];
- float dfdv[3][4];
+ float dfdx[3][3];
+ float dfdv[3][3];
float f[3];
} ClothSpring;
@@ -91,13 +91,13 @@
unsigned int numothersprings;
unsigned int numspringssave;
unsigned int old_solver_type;
- float (*x)[4]; /* The current position of all vertices.*/
- float (*xold)[4]; /* The previous position of all vertices.*/
- float (*current_x)[4]; /* The TEMPORARY current position of all vertices.*/
- float (*current_xold)[4]; /* The TEMPORARY previous position of all vertices.*/
+ float (*x)[3]; /* The current position of all vertices.*/
+ float (*xold)[3]; /* The previous position of all vertices.*/
+ float (*current_x)[3]; /* The TEMPORARY current position of all vertices.*/
+ float (*current_xold)[3]; /* The TEMPORARY previous position of all vertices.*/
float (*v)[4]; /* the current velocity of all vertices */
- float (*current_v)[4];
- float (*xconst)[4];
+ float (*current_v)[3];
+ float (*xconst)[3];
} Cloth;
/* goal defines */
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-11-22 16:30:14 UTC (rev 12652)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-11-22 17:02:37 UTC (rev 12653)
@@ -90,9 +90,9 @@
}
#else
#include <sys/time.h>
-static struct timeval _tstart, _tend;
-static struct timezone tz;
-void tstart ( void )
+ static struct timeval _tstart, _tend;
+ static struct timezone tz;
+ void tstart ( void )
{
gettimeofday ( &_tstart, &tz );
}
@@ -133,11 +133,11 @@
*
******************************************************************************/
/**
-* cloth_init - creates a new cloth simulation.
-*
-* 1. create object
-* 2. fill object with standard values or with the GUI settings if given
-*/
+ * cloth_init - creates a new cloth simulation.
+ *
+ * 1. create object
+ * 2. fill object with standard values or with the GUI settings if given
+ */
void cloth_init (ClothModifierData *clmd)
{
/* Initialize our new data structure to reasonable values. */
@@ -202,38 +202,38 @@
for(i = 0; i < numfaces; i++)
{
- if(mface[i].v4)
- numquads++;
- else
- numtris++;
- }
+ if(mface[i].v4)
+ numquads++;
+ else
+ numtris++;
+}
result = CDDM_from_template(dm, numverts, 0, numtris + 2*numquads);
if(!result)
- return NULL;
+ return NULL;
// do verts
mvert2 = CDDM_get_verts(result);
for(a=0; a<numverts; a++)
{
- MVert *inMV;
- MVert *mv = &mvert2[a];
+ MVert *inMV;
+ MVert *mv = &mvert2[a];
- inMV = &mvert[a];
+ inMV = &mvert[a];
- DM_copy_vert_data(dm, result, a, a, 1);
- *mv = *inMV;
- }
+ DM_copy_vert_data(dm, result, a, a, 1);
+ *mv = *inMV;
+}
// do faces
mface2 = CDDM_get_faces(result);
for(a=0, i=0; a<numfaces; a++)
{
- MFace *mf = &mface2[i];
- MFace *inMF;
- inMF = &mface[a];
+ MFace *mf = &mface2[i];
+ MFace *inMF;
+ inMF = &mface[a];
// DM_copy_face_data(dm, result, a, i, 1);
@@ -241,57 +241,57 @@
// *mf = *inMF;
- if(mface[a].v4 && random==1)
- {
- mf->v1 = mface[a].v2;
- mf->v2 = mface[a].v3;
- mf->v3 = mface[a].v4;
- }
- else
- {
- mf->v1 = mface[a].v1;
- mf->v2 = mface[a].v2;
- mf->v3 = mface[a].v3;
- }
+ if(mface[a].v4 && random==1)
+ {
+ mf->v1 = mface[a].v2;
+ mf->v2 = mface[a].v3;
+ mf->v3 = mface[a].v4;
+}
+ else
+ {
+ mf->v1 = mface[a].v1;
+ mf->v2 = mface[a].v2;
+ mf->v3 = mface[a].v3;
+}
- mf->v4 = 0;
- mf->flag |= ME_SMOOTH;
+ mf->v4 = 0;
+ mf->flag |= ME_SMOOTH;
- test_index_face(mf, NULL, 0, 3);
+ test_index_face(mf, NULL, 0, 3);
- if(mface[a].v4)
- {
- MFace *mf2;
+ if(mface[a].v4)
+ {
+ MFace *mf2;
- i++;
+ i++;
- mf2 = &mface2[i];
+ mf2 = &mface2[i];
// DM_copy_face_data(dm, result, a, i, 1);
// *mf2 = *inMF;
- if(random==1)
- {
- mf2->v1 = mface[a].v1;
- mf2->v2 = mface[a].v2;
- mf2->v3 = mface[a].v4;
- }
- else
- {
- mf2->v1 = mface[a].v4;
- mf2->v2 = mface[a].v1;
- mf2->v3 = mface[a].v3;
- }
- mf2->v4 = 0;
- mf2->flag |= ME_SMOOTH;
+ if(random==1)
+ {
+ mf2->v1 = mface[a].v1;
+ mf2->v2 = mface[a].v2;
+ mf2->v3 = mface[a].v4;
+}
+ else
+ {
+ mf2->v1 = mface[a].v4;
+ mf2->v2 = mface[a].v1;
+ mf2->v3 = mface[a].v3;
+}
+ mf2->v4 = 0;
+ mf2->flag |= ME_SMOOTH;
- test_index_face(mf2, NULL, 0, 3);
- }
+ test_index_face(mf2, NULL, 0, 3);
+}
- i++;
- }
+ i++;
+}
CDDM_calc_edges(result);
CDDM_calc_normals(result);
@@ -330,43 +330,43 @@
for(i = 0; i < numsprings; i++)
{
- if((springs[i].flags & CSPRING_FLAG_DEACTIVATE)
- &&(!BLI_edgehash_haskey(edgehash, springs[i].ij, springs[i].kl)))
- {
- BLI_edgehash_insert(edgehash, springs[i].ij, springs[i].kl, NULL);
- BLI_edgehash_insert(edgehash, springs[i].kl, springs[i].ij, NULL);
- j++;
- }
- }
+ if((springs[i].flags & CSPRING_FLAG_DEACTIVATE)
+ &&(!BLI_edgehash_haskey(edgehash, springs[i].ij, springs[i].kl)))
+ {
+ BLI_edgehash_insert(edgehash, springs[i].ij, springs[i].kl, NULL);
+ BLI_edgehash_insert(edgehash, springs[i].kl, springs[i].ij, NULL);
+ j++;
+}
+}
// printf("found %d tears\n", j);
result = CDDM_from_template(dm, numverts, 0, numfaces);
if(!result)
- return NULL;
+ return NULL;
// do verts
mvert2 = CDDM_get_verts(result);
for(a=0; a<numverts; a++)
{
- MVert *inMV;
- MVert *mv = &mvert2[a];
+ MVert *inMV;
+ MVert *mv = &mvert2[a];
- inMV = &mvert[a];
+ inMV = &mvert[a];
- DM_copy_vert_data(dm, result, a, a, 1);
- *mv = *inMV;
- }
+ DM_copy_vert_data(dm, result, a, a, 1);
+ *mv = *inMV;
+}
// do faces
mface2 = CDDM_get_faces(result);
for(a=0, i=0; a<numfaces; a++)
{
- MFace *mf = &mface2[i];
- MFace *inMF;
- inMF = &mface[a];
+ MFace *mf = &mface2[i];
+ MFace *inMF;
+ inMF = &mface[a];
// DM_copy_face_data(dm, result, a, i, 1);
@@ -374,21 +374,21 @@
// *mf = *inMF;
- if((!BLI_edgehash_haskey(edgehash, mface[a].v1, mface[a].v2))
- &&(!BLI_edgehash_haskey(edgehash, mface[a].v2, mface[a].v3))
- &&(!BLI_edgehash_haskey(edgehash, mface[a].v3, mface[a].v4))
- &&(!BLI_edgehash_haskey(edgehash, mface[a].v4, mface[a].v1)))
- {
- mf->v1 = mface[a].v1;
- mf->v2 = mface[a].v2;
- mf->v3 = mface[a].v3;
- mf->v4 = mface[a].v4;
+ if((!BLI_edgehash_haskey(edgehash, mface[a].v1, mface[a].v2))
+ &&(!BLI_edgehash_haskey(edgehash, mface[a].v2, mface[a].v3))
+ &&(!BLI_edgehash_haskey(edgehash, mface[a].v3, mface[a].v4))
+ &&(!BLI_edgehash_haskey(edgehash, mface[a].v4, mface[a].v1)))
+ {
+ mf->v1 = mface[a].v1;
+ mf->v2 = mface[a].v2;
+ mf->v3 = mface[a].v3;
+ mf->v4 = mface[a].v4;
- test_index_face(mf, NULL, 0, 4);
+ test_index_face(mf, NULL, 0, 4);
- i++;
- }
- }
+ i++;
+}
+}
CDDM_lower_num_faces(result, i);
CDDM_calc_edges(result);
@@ -527,40 +527,40 @@
/*
if ( clmd->clothObject )
{
- if ( clmd->sim_parms->cache )
- {
- if ( current_time < clmd->sim_parms->firstframe )
- {
- int frametime = cloth_cache_first_frame ( clmd );
- if ( cloth_cache_search_frame ( clmd, frametime ) )
- {
- cloth_cache_get_frame ( clmd, frametime );
- cloth_to_object ( ob, result, clmd );
- }
- return result;
- }
- else if ( current_time > clmd->sim_parms->lastframe )
- {
- int frametime = cloth_cache_last_frame ( clmd );
- if ( cloth_cache_search_frame ( clmd, frametime ) )
- {
- cloth_cache_get_frame ( clmd, frametime );
- cloth_to_object ( ob, result, clmd );
- }
- return result;
- }
- else if ( ABS ( deltaTime ) >= 2.0f ) // no timewarps allowed
- {
- if ( cloth_cache_search_frame ( clmd, framenr ) )
- {
- cloth_cache_get_frame ( clmd, framenr );
- cloth_to_object ( ob, result, clmd );
- }
- clmd->sim_parms->sim_time = current_time;
- return result;
- }
- }
- }
+ if ( clmd->sim_parms->cache )
+ {
+ if ( current_time < clmd->sim_parms->firstframe )
+ {
+ int frametime = cloth_cache_first_frame ( clmd );
+ if ( cloth_cache_search_frame ( clmd, frametime ) )
+ {
+ cloth_cache_get_frame ( clmd, frametime );
+ cloth_to_object ( ob, result, clmd );
+}
+ return result;
+}
+ else if ( current_time > clmd->sim_parms->lastframe )
+ {
+ int frametime = cloth_cache_last_frame ( clmd );
+ if ( cloth_cache_search_frame ( clmd, frametime ) )
+ {
+ cloth_cache_get_frame ( clmd, frametime );
+ cloth_to_object ( ob, result, clmd );
+}
+ return result;
+}
+ else if ( ABS ( deltaTime ) >= 2.0f ) // no timewarps allowed
+ {
+ if ( cloth_cache_search_frame ( clmd, framenr ) )
+ {
+ cloth_cache_get_frame ( clmd, framenr );
+ cloth_to_object ( ob, result, clmd );
+}
+ clmd->sim_parms->sim_time = current_time;
+ return result;
+}
+}
+}
*/
if(deltaTime == 1.0f)
@@ -737,10 +737,10 @@
******************************************************************************/
/**
-* cloth_to_object - copies the deformed vertices to the object.
-*
-* This function is a modified version of the softbody.c:softbody_to_object() function.
-**/
+ * cloth_to_object - copies the deformed vertices to the object.
+ *
+ * This function is a modified version of the softbody.c:softbody_to_object() function.
+ **/
static void cloth_to_object (Object *ob, DerivedMesh *dm, ClothModifierData *clmd)
{
unsigned int i = 0;
@@ -765,9 +765,9 @@
/**
-* cloth_apply_vgroup - applies a vertex group as specified by type
-*
-**/
+ * cloth_apply_vgroup - applies a vertex group as specified by type
+ *
+ **/
static void cloth_apply_vgroup(ClothModifierData *clmd, DerivedMesh *dm, short vgroup)
{
unsigned int i = 0;
@@ -862,52 +862,51 @@
/* create springs */
clmd->clothObject->springs = NULL;
clmd->clothObject->numsprings = -1;
+
+ /* set initial values */
+ for (i = 0; i < numverts; ++i)
+ {
+ VECCOPY (clmd->clothObject->x[i], mvert[i].co);
+ Mat4MulVecfl(ob->obmat, clmd->clothObject->x[i]);
+
+ clmd->clothObject->verts [i].mass = clmd->sim_parms->mass;
+ if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list