[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12406] branches/cloth/blender/source/ blender: Weekend commit: Enabled bounding box check for cloth again, but there's a bug in it (no collisions detected)
Daniel Genrich
daniel.genrich at gmx.net
Fri Oct 26 17:13:50 CEST 2007
Revision: 12406
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12406
Author: genscher
Date: 2007-10-26 17:13:50 +0200 (Fri, 26 Oct 2007)
Log Message:
-----------
Weekend commit: Enabled bounding box check for cloth again, but there's a bug in it (no collisions detected)
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/kdop.c
branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2007-10-26 11:40:34 UTC (rev 12405)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2007-10-26 15:13:50 UTC (rev 12406)
@@ -124,6 +124,9 @@
// from cloth.c, needed for modifier.c
DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *dm, int useRenderParams, int isFinalCalc);
+// needed in implicit.c
+int cloth_bvh_objcollision(ClothModifierData * clmd, float step, float prevstep, float dt);
+
////////////////////////////////////////////////
@@ -175,6 +178,8 @@
float time; /* we need float since we want to support sub-frames */
float (*x)[3];
float (*xold)[3];
+ float (*v)[3];
+ float (*current_xold)[3];
}
Frame;
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h 2007-10-26 11:40:34 UTC (rev 12405)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h 2007-10-26 15:13:50 UTC (rev 12406)
@@ -68,9 +68,9 @@
MVert *x; // position of verts at time n-1
MFace *mfaces; // just a pointer to the original datastructure
struct LinkNode *tree;
- TreeNode *root; // TODO: saving the root --> is this really needed? YES!
- TreeNode *leaf_tree; /* Tail of the leaf linked list. */
- TreeNode *leaf_root; /* Head of the leaf linked list. */
+ CollisionTree *root; // TODO: saving the root --> is this really needed? YES!
+ CollisionTree *leaf_tree; /* Tail of the leaf linked list. */
+ CollisionTree *leaf_root; /* Head of the leaf linked list. */
float epsilon; /* epslion is used for inflation of the k-dop */
int flags; /* bvhFlags */
}
@@ -90,6 +90,7 @@
// builds bounding volume hierarchy
BVH *bvh_build_from_mvert (MFace *mfaces, unsigned int numfaces, MVert *x, unsigned int numverts, float epsilon);
+BVH *bvh_build_from_float3 (MFace *mfaces, unsigned int numfaces, float (*x)[3], unsigned int numverts, float epsilon);
// frees the same
void bvh_free ( BVH *bvh );
@@ -99,12 +100,13 @@
// update bounding volumes, needs updated positions in bvh->x
void bvh_update_from_mvert(BVH * bvh, MVert *x, unsigned int numverts, MVert *xnew, int moving);
+void bvh_update_from_float3(BVH * bvh, float (*x)[3], unsigned int numverts, float (*xnew)[3], int moving);
LinkNode *BLI_linklist_append_fast (LinkNode **listp, void *ptr);
// move Collision modifier object inter-frame with step = [0,1]
// defined in collisions.c
-void collision_move_object(CollisionModifierData *collmd, float step);
+void collision_move_object(CollisionModifierData *collmd, float step, float prevstep);
/////////////////////////////////////////////////
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-10-26 11:40:34 UTC (rev 12405)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-10-26 15:13:50 UTC (rev 12406)
@@ -515,6 +515,10 @@
memcpy ( clmd->clothObject->xold, frame->xold, sizeof ( float ) *frame->numverts * 3);
+ memcpy ( clmd->clothObject->v, frame->v, sizeof ( float ) *frame->numverts * 3);
+
+ memcpy ( clmd->clothObject->current_xold, frame->current_xold, sizeof ( float ) *frame->numverts * 3);
+
implicit_set_positions ( clmd );
return;
@@ -565,6 +569,29 @@
return;
}
+ frame->v = MEM_dupallocN ( clmd->clothObject->v );
+
+ if ( !frame->v )
+ {
+ MEM_freeN ( frame->verts );
+ MEM_freeN ( frame->x );
+ MEM_freeN ( frame->xold );
+ MEM_freeN ( frame );
+ return;
+ }
+
+ frame->current_xold= MEM_dupallocN ( clmd->clothObject->current_xold );
+
+ if ( !frame->current_xold )
+ {
+ MEM_freeN ( frame->verts );
+ MEM_freeN ( frame->x );
+ MEM_freeN ( frame->xold );
+ MEM_freeN ( frame->v );
+ MEM_freeN ( frame );
+ return;
+ }
+
BLI_linklist_append ( &clmd->sim_parms.cache, frame );
}
@@ -606,6 +633,14 @@
{
MEM_freeN ( frame->xold );
}
+ if ( frame->v )
+ {
+ MEM_freeN ( frame->v );
+ }
+ if ( frame->current_xold )
+ {
+ MEM_freeN ( frame->current_xold );
+ }
MEM_freeN ( frame );
lastsearch->next = search->next;
@@ -825,6 +860,10 @@
// Free the verts.
if ( cloth->xold != NULL )
MEM_freeN ( cloth->xold );
+
+ // Free the verts.
+ if ( cloth->v != NULL )
+ MEM_freeN ( cloth->v );
// Free the verts.
if ( cloth->current_x != NULL )
@@ -833,6 +872,10 @@
// Free the verts.
if ( cloth->current_xold != NULL )
MEM_freeN ( cloth->current_xold );
+
+ // Free the verts.
+ if ( cloth->current_v != NULL )
+ MEM_freeN ( cloth->current_v );
cloth->verts = NULL;
cloth->numverts = -1;
@@ -991,7 +1034,7 @@
if ( !dm )
return 0;
- cloth_from_mesh (ob, clmd, dm, framenr);
+ cloth_from_mesh (ob, clmd, dm, framenr);
if ( clmd->clothObject != NULL )
{
@@ -1020,7 +1063,7 @@
VECCOPY(clmd->clothObject->xold[i], clmd->clothObject->x[i]);
VECCOPY(clmd->clothObject->verts [i].xconst, clmd->clothObject->x[i]);
VECCOPY(clmd->clothObject->current_xold[i], clmd->clothObject->x[i]);
- VecMulf(clmd->clothObject->verts [i].v, 0.0f);
+ VecMulf(clmd->clothObject->v[i], 0.0f);
clmd->clothObject->verts [i].impulse_count = 0;
VECCOPY ( clmd->clothObject->verts [i].impulse, tnull );
@@ -1034,7 +1077,7 @@
if (solvers [clmd->sim_parms.solver_type].init)
solvers [clmd->sim_parms.solver_type].init (ob, clmd);
- clmd->clothObject->tree = NULL; // bvh_build(clmd, clmd->coll_parms.epsilon);
+ clmd->clothObject->tree = bvh_build_from_float3(CDDM_get_faces(dm), dm->getNumFaces(dm), clmd->clothObject->x, numverts, clmd->coll_parms.epsilon);
// cloth_cache_set_frame(clmd, 1);
}
@@ -1079,6 +1122,14 @@
return;
}
+ clmd->clothObject->v = MEM_callocN ( sizeof ( float ) * clmd->clothObject->numverts * 3, "Cloth MVert_v" );
+ if ( clmd->clothObject->v == NULL )
+ {
+ cloth_free_modifier ( clmd );
+ modifier_setError ( & ( clmd->modifier ), "Out of memory on allocating clmd->clothObject->v." );
+ return;
+ }
+
clmd->clothObject->current_x = MEM_callocN ( sizeof ( float ) * clmd->clothObject->numverts * 3, "Cloth MVert_current_x" );
if ( clmd->clothObject->current_x == NULL )
{
@@ -1094,6 +1145,14 @@
modifier_setError ( & ( clmd->modifier ), "Out of memory on allocating clmd->clothObject->current_xold." );
return;
}
+
+ clmd->clothObject->current_v = MEM_callocN ( sizeof ( float ) * clmd->clothObject->numverts * 3, "Cloth MVert_current_v" );
+ if ( clmd->clothObject->current_v == NULL )
+ {
+ cloth_free_modifier ( clmd );
+ modifier_setError ( & ( clmd->modifier ), "Out of memory on allocating clmd->clothObject->current_v." );
+ return;
+ }
// save face information
clmd->clothObject->numfaces = numfaces;
Modified: branches/cloth/blender/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/collision.c 2007-10-26 11:40:34 UTC (rev 12405)
+++ branches/cloth/blender/source/blender/blenkernel/intern/collision.c 2007-10-26 15:13:50 UTC (rev 12406)
@@ -73,17 +73,15 @@
// step is limited from 0 (frame start position) to 1 (frame end position)
-void collision_move_object(CollisionModifierData *collmd, float step)
+void collision_move_object(CollisionModifierData *collmd, float step, float prevstep)
{
float tv[3] = {0,0,0};
unsigned int i = 0;
- MVert *tempVert = collmd->current_x;
- collmd->current_x = collmd->current_xnew;
- collmd->current_xnew = tempVert;
-
+
for ( i = 0; i < collmd->numverts; i++ )
{
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);
}
}
Modified: branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/implicit.c 2007-10-26 11:40:34 UTC (rev 12405)
+++ branches/cloth/blender/source/blender/blenkernel/intern/implicit.c 2007-10-26 15:13:50 UTC (rev 12406)
@@ -1164,7 +1164,6 @@
float bending_force[3] = {0,0,0};
float damping_force[3] = {0,0,0};
float nulldfdx[3][3]={ {0,0,0}, {0,0,0}, {0,0,0}};
- Cloth *cloth = clmd->clothObject;
VECCOPY(s->f, nullf);
cp_fmatrix(s->dfdx, nulldfdx);
@@ -1486,33 +1485,29 @@
}
VECCOPY(cloth->current_x[i], id->Xnew[i]);
-
- VECSUB(verts[i].tv, cloth->current_x[i], cloth->current_xold[i]);
- VECCOPY(verts[i].v, verts[i].tv);
+ VECSUB(cloth->current_v[i], cloth->current_x[i], cloth->current_xold[i]);
+ VECCOPY(cloth->v[i], cloth->current_v[i]);
}
-
+
// call collision function
- result = 0; // cloth_bvh_objcollision(clmd, step + dt, dt);
-
+ result = cloth_bvh_objcollision(clmd, step + dt, step, dt);
+
// copy corrected positions back to simulation
- for(i = 0; i < numverts; i++)
- {
- if(result)
- {
- // VECADD(verts[i].tx, verts[i].txold, verts[i].tv);
-
- VECCOPY(cloth->current_xold[i], cloth->current_x[i]);
-
- VECCOPY(id->Xnew[i], cloth->current_x[i]);
-
- VECCOPY(id->Vnew[i], verts[i].tv);
+ memcpy(cloth->current_xold, cloth->current_x, sizeof(lfVector) * numverts);
+ memcpy(id->Xnew, cloth->current_x, sizeof(lfVector) * numverts);
+
+ if(result)
+ {
+ for(i = 0; i < numverts; i++)
+ {
+ VECCOPY(id->Vnew[i], cloth->current_v[i]);
VecMulf(id->Vnew[i], 1.0f / dt);
}
- else
- {
- VECCOPY(cloth->current_xold[i], id->Xnew[i]);
- }
}
+ else
+ {
+ memcpy(cloth->current_xold, id->Xnew, sizeof(lfVector) * numverts);
+ }
// X = Xnew;
cp_lfvector(id->X, id->Xnew, numverts);
@@ -1544,46 +1539,42 @@
if(effectors) pdEndEffectors(effectors);
}
-
- for(i = 0; i < numverts; i++)
- {
- if(clmd->sim_parms.flags & CLOTH_SIMSETTINGS_FLAG_GOAL)
+
+ if(clmd->sim_parms.flags & CLOTH_SIMSETTINGS_FLAG_GOAL)
+ {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list