[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13650] trunk/blender/source/blender: Cloth: New: *simple* (OpenMP enabled) Selfcollisions available
Daniel Genrich
daniel.genrich at gmx.net
Tue Feb 12 12:05:00 CET 2008
Revision: 13650
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13650
Author: genscher
Date: 2008-02-12 12:04:58 +0100 (Tue, 12 Feb 2008)
Log Message:
-----------
Cloth: New: *simple* (OpenMP enabled) Selfcollisions available
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_cloth.h
trunk/blender/source/blender/blenkernel/BKE_collision.h
trunk/blender/source/blender/blenkernel/intern/cloth.c
trunk/blender/source/blender/blenkernel/intern/collision.c
trunk/blender/source/blender/blenkernel/intern/implicit.c
trunk/blender/source/blender/blenkernel/intern/kdop.c
trunk/blender/source/blender/blenkernel/intern/modifier.c
trunk/blender/source/blender/makesdna/DNA_cloth_types.h
trunk/blender/source/blender/src/buttons_object.c
Modified: trunk/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_cloth.h 2008-02-12 00:34:53 UTC (rev 13649)
+++ trunk/blender/source/blender/blenkernel/BKE_cloth.h 2008-02-12 11:04:58 UTC (rev 13650)
@@ -94,10 +94,11 @@
float goal; /* goal, from SB */
float impulse[3]; /* used in collision.c */
unsigned int impulse_count; /* same as above */
- float avg_spring_len; /* average length of connected springs, UNUSED ATM */
+ float avg_spring_len; /* average length of connected springs */
float struct_stiff;
float bend_stiff;
float shear_stiff;
+ int spring_count; /* how many springs attached? */
}
ClothVertex;
@@ -153,7 +154,7 @@
typedef enum
{
CLOTH_COLLSETTINGS_FLAG_ENABLED = ( 1 << 1 ), /* enables cloth - object collisions */
- CLOTH_COLLSETTINGS_FLAG_SELF = ( 1 << 2 ), /* unused */
+ CLOTH_COLLSETTINGS_FLAG_SELF = ( 1 << 2 ), /* enables selfcollisions */
} CLOTH_COLLISIONSETTINGS_FLAGS;
/* Spring types as defined in the paper.*/
Modified: trunk/blender/source/blender/blenkernel/BKE_collision.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_collision.h 2008-02-12 00:34:53 UTC (rev 13649)
+++ trunk/blender/source/blender/blenkernel/BKE_collision.h 2008-02-12 11:04:58 UTC (rev 13650)
@@ -73,6 +73,8 @@
int count_nodes; // how many nodes are used
int traversed; // how many nodes already traversed until this level?
int isleaf;
+ float alpha; /* for selfcollision */
+ float normal[3]; /* for selfcollision */
}
CollisionTree;
@@ -103,11 +105,11 @@
typedef void ( *CM_COLLISION_RESPONSE ) ( ModifierData *md1, ModifierData *md2, CollisionTree *tree1, CollisionTree *tree2 );
// needed for collision.c
-int bvh_traverse ( ModifierData * md1, ModifierData * md2, CollisionTree * tree1, CollisionTree * tree2, float step, CM_COLLISION_RESPONSE collision_response);
-int bvh_traverse_mt ( ModifierData * md1, ModifierData * md2, CollisionTree * tree1, CollisionTree * tree2, float step, CM_COLLISION_RESPONSE collision_response);
-////////////////////////////////////////////////
+int bvh_traverse ( ModifierData * md1, ModifierData * md2, CollisionTree * tree1, CollisionTree * tree2, float step, CM_COLLISION_RESPONSE collision_response, int selfcollision);
+
////////////////////////////////////////
+
////////////////////////////////////////
// used for collisions in kdop.c and also collision.c
////////////////////////////////////////
Modified: trunk/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/cloth.c 2008-02-12 00:34:53 UTC (rev 13649)
+++ trunk/blender/source/blender/blenkernel/intern/cloth.c 2008-02-12 11:04:58 UTC (rev 13650)
@@ -165,6 +165,7 @@
clmd->sim_parms->editedframe = 0;
clmd->sim_parms->autoprotect = 25;
clmd->sim_parms->firstcachedframe = -1.0;
+ clmd->sim_parms->avg_spring_len = 0.0;
clmd->coll_parms->self_friction = 5.0;
clmd->coll_parms->friction = 5.0;
@@ -172,6 +173,8 @@
clmd->coll_parms->epsilon = 0.015f;
clmd->coll_parms->flags = CLOTH_COLLSETTINGS_FLAG_ENABLED;
clmd->coll_parms->collision_list = NULL;
+ clmd->coll_parms->self_loop_count = 1.0;
+ clmd->coll_parms->selfepsilon = 0.75;
/* These defaults are copied from softbody.c's
* softbody_calc_forces() function.
@@ -269,130 +272,6 @@
bvh_update(bvh, moving);
}
-// unused in the moment, cloth needs quads from mesh
-DerivedMesh *CDDM_convert_to_triangle ( DerivedMesh *dm )
-{
- DerivedMesh *result = NULL;
- int i;
- int numverts = dm->getNumVerts ( dm );
- int numedges = dm->getNumEdges ( dm );
- int numfaces = dm->getNumFaces ( dm );
-
- MVert *mvert = CDDM_get_verts ( dm );
- MEdge *medge = CDDM_get_edges ( dm );
- MFace *mface = CDDM_get_faces ( dm );
-
- MVert *mvert2;
- MFace *mface2;
- unsigned int numtris=0;
- unsigned int numquads=0;
- int a = 0;
- int random = 0;
- int firsttime = 0;
- float vec1[3], vec2[3], vec3[3], vec4[3], vec5[3];
- float mag1=0, mag2=0;
-
- for ( i = 0; i < numfaces; i++ )
- {
- if ( mface[i].v4 )
- numquads++;
- else
- numtris++;
- }
-
- result = CDDM_from_template ( dm, numverts, 0, numtris + 2*numquads );
-
- if ( !result )
- return NULL;
-
- // do verts
- mvert2 = CDDM_get_verts ( result );
- for ( a=0; a<numverts; a++ )
- {
- MVert *inMV;
- MVert *mv = &mvert2[a];
-
- inMV = &mvert[a];
-
- 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];
-
- /*
- DM_copy_face_data(dm, result, a, i, 1);
-
- *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;
- }
-
- mf->v4 = 0;
- mf->flag |= ME_SMOOTH;
-
- test_index_face ( mf, NULL, 0, 3 );
-
- if ( mface[a].v4 )
- {
- MFace *mf2;
-
- 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;
-
- test_index_face ( mf2, NULL, 0, 3 );
- }
-
- i++;
- }
-
- CDDM_calc_edges ( result );
- CDDM_calc_normals ( result );
-
- return result;
-
-}
-
-
DerivedMesh *CDDM_create_tearing ( ClothModifierData *clmd, DerivedMesh *dm )
{
DerivedMesh *result = NULL;
@@ -922,6 +801,11 @@
// we save our faces for collision objects
if ( cloth->mfaces )
MEM_freeN ( cloth->mfaces );
+
+ if(cloth->edgehash)
+ BLI_edgehash_free ( cloth->edgehash, NULL );
+
+
/*
if(clmd->clothObject->facemarks)
MEM_freeN(clmd->clothObject->facemarks);
@@ -988,6 +872,11 @@
// we save our faces for collision objects
if ( cloth->mfaces )
MEM_freeN ( cloth->mfaces );
+
+ if(cloth->edgehash)
+ BLI_edgehash_free ( cloth->edgehash, NULL );
+
+
/*
if(clmd->clothObject->facemarks)
MEM_freeN(clmd->clothObject->facemarks);
@@ -1136,6 +1025,7 @@
clmd->clothObject->old_solver_type = 255;
// clmd->clothObject->old_collision_type = 255;
cloth = clmd->clothObject;
+ clmd->clothObject->edgehash = NULL;
}
else if ( !clmd->clothObject )
{
@@ -1236,8 +1126,7 @@
MFace *mface = CDDM_get_faces(dm);
unsigned int i = 0;
- /* Allocate our vertices.
- */
+ /* Allocate our vertices. */
clmd->clothObject->numverts = numverts;
clmd->clothObject->verts = MEM_callocN ( sizeof ( ClothVertex ) * clmd->clothObject->numverts, "clothVertex" );
if ( clmd->clothObject->verts == NULL )
@@ -1349,7 +1238,11 @@
spring->kl = medge[i].v2;
VECSUB ( temp, cloth->verts[spring->kl].x, cloth->verts[spring->ij].x );
spring->restlen = sqrt ( INPR ( temp, temp ) );
- clmd->coll_parms->avg_spring_len += spring->restlen;
+ clmd->sim_parms->avg_spring_len += spring->restlen;
+ cloth->verts[spring->ij].avg_spring_len += spring->restlen;
+ cloth->verts[spring->kl].avg_spring_len += spring->restlen;
+ cloth->verts[spring->ij].spring_count++;
+ cloth->verts[spring->kl].spring_count++;
spring->type = CLOTH_SPRING_TYPE_STRUCTURAL;
spring->flags = 0;
spring->stiffness = (cloth->verts[spring->kl].struct_stiff + cloth->verts[spring->ij].struct_stiff) / 2.0;
@@ -1363,8 +1256,13 @@
}
}
- clmd->coll_parms->avg_spring_len /= struct_springs;
+ clmd->sim_parms->avg_spring_len /= struct_springs;
+ for(i = 0; i < numverts; i++)
+ {
+ cloth->verts[i].avg_spring_len = cloth->verts[i].avg_spring_len * 0.49 / ((float)cloth->verts[i].spring_count);
+ }
+
// shear springs
for ( i = 0; i < numfaces; i++ )
{
@@ -1452,10 +1350,10 @@
if ( edgelist )
MEM_freeN ( edgelist );
- BLI_edgehash_free ( edgehash, NULL );
+ cloth->edgehash = edgehash;
if(G.rt>0)
- printf("avg_len: %f\n",clmd->coll_parms->avg_spring_len);
+ printf("avg_len: %f\n",clmd->sim_parms->avg_spring_len);
return 1;
Modified: trunk/blender/source/blender/blenkernel/intern/collision.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/collision.c 2008-02-12 00:34:53 UTC (rev 13649)
+++ trunk/blender/source/blender/blenkernel/intern/collision.c 2008-02-12 11:04:58 UTC (rev 13650)
@@ -948,6 +948,29 @@
cloth_collision_moving_tris(coll_clmd, clmd, tree2, tree1);
}
+void cloth_collision_self_static(ModifierData *md1, ModifierData *md2, CollisionTree *tree1, CollisionTree *tree2)
+{
+ ClothModifierData *clmd = (ClothModifierData *)md1;
+ CollisionModifierData *collmd = (CollisionModifierData *)md2;
+ CollPair *collpair = NULL;
+ Cloth *cloth1=NULL;
+ MFace *face1=NULL, *face2=NULL;
+ ClothVertex *verts1=NULL;
+ double distance = 0;
+ float epsilon = clmd->coll_parms->epsilon;
+ unsigned int i = 0;
+
+
+}
+
+/* aye this belongs to arith.c */
+static void Vec3PlusStVec(float *v, float s, float *v1)
+{
+ v[0] += s*v1[0];
+ v[1] += s*v1[1];
+ v[2] += s*v1[2];
+}
+
// cloth - object collisions
int cloth_bvh_objcollision(ClothModifierData * clmd, float step, float dt)
{
@@ -956,12 +979,13 @@
Cloth *cloth=NULL;
Object *coll_ob=NULL;
BVH *cloth_bvh=NULL;
- unsigned int i=0, j = 0, numfaces = 0, numverts = 0;
+ long i=0, j = 0, numfaces = 0, numverts = 0;
unsigned int result = 0, ic = 0, rounds = 0; // result counts applied collisions; ic is for debug output;
ClothVertex *verts = NULL;
float tnull[3] = {0,0,0};
int ret = 0;
ClothModifierData *tclmd;
+ int collisions = 0, count = 0;
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COLLOBJ) || !(((Cloth *)clmd->clothObject)->tree))
{
@@ -1006,7 +1030,7 @@
collision_move_object(collmd, step + dt, step);
- bvh_traverse((ModifierData *)clmd, (ModifierData *)collmd, cloth_bvh->root, coll_bvh->root, step, cloth_collision_static);
+ bvh_traverse((ModifierData *)clmd, (ModifierData *)collmd, cloth_bvh->root, coll_bvh->root, step, cloth_collision_static, 0);
}
else
printf ("cloth_bvh_objcollision: found a collision object with clothObject or collData NULL.\n");
@@ -1068,7 +1092,7 @@
{
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list