[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13323] branches/cloth/blender/source/ blender: Restructured many collision things again, GUI cleanup
Daniel Genrich
daniel.genrich at gmx.net
Mon Jan 21 03:23:05 CET 2008
Revision: 13323
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13323
Author: genscher
Date: 2008-01-21 03:23:03 +0100 (Mon, 21 Jan 2008)
Log Message:
-----------
Restructured many collision things again, GUI cleanup
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/kdop.c
branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
branches/cloth/blender/source/blender/src/buttons_object.c
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2008-01-21 00:41:29 UTC (rev 13322)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2008-01-21 02:23:03 UTC (rev 13323)
@@ -129,38 +129,39 @@
void clothModifier_do ( ClothModifierData *clmd, Object *ob, DerivedMesh *dm, float ( *vertexCos ) [3], int numverts );
// used in collision.c
-typedef struct Tree
+typedef struct CollisionTree
{
- struct Tree *nodes[4]; // 4 children --> quad-tree
- struct Tree *parent;
- struct Tree *nextLeaf;
- struct Tree *prevLeaf;
+ struct CollisionTree *nodes[4]; // 4 children --> quad-tree
+ struct CollisionTree *parent;
+ struct CollisionTree *nextLeaf;
+ struct CollisionTree *prevLeaf;
float bv[26]; // Bounding volume of all nodes / we have 7 axes on a 14-DOP
unsigned int tri_index; // this saves the index of the face
+ // int point_index[4]; // supports up to 4 points in a leaf
int count_nodes; // how many nodes are used
int traversed; // how many nodes already traversed until this level?
int isleaf;
}
-Tree;
+CollisionTree;
-typedef struct Tree TreeNode;
-
typedef struct BVH
{
unsigned int numfaces;
unsigned int numverts;
- ClothVertex *verts; // just a pointer to the original datastructure
+ // ClothVertex *verts; // just a pointer to the original datastructure
+ MVert *current_x; // e.g. txold in clothvertex
+ MVert *current_xold; // e.g. tx in clothvertex
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 */
}
BVH;
-typedef void ( *CM_COLLISION_RESPONSE ) ( ClothModifierData *clmd, ClothModifierData *coll_clmd, Tree * tree1, Tree * tree2 );
+typedef void ( *CM_COLLISION_RESPONSE ) ( ClothModifierData *clmd, ClothModifierData *coll_clmd, CollisionTree * tree1, CollisionTree * tree2 );
/////////////////////////////////////////////////
@@ -168,9 +169,15 @@
////////////////////////////////////////////////
// needed for implicit.c
-void bvh_collision_response ( ClothModifierData *clmd, ClothModifierData *coll_clmd, Tree * tree1, Tree * tree2 );
+void bvh_collision_response ( ClothModifierData *clmd, ClothModifierData *coll_clmd, CollisionTree * tree1, CollisionTree * tree2 );
int cloth_bvh_objcollision ( ClothModifierData * clmd, float step, float dt );
+// needed for modifier.c
+BVH *bvh_build_from_mvert (MFace *mfaces, unsigned int numfaces, MVert *x, unsigned int numverts, float epsilon);
+
+// needed for collision.c
+void bvh_update_from_mvert(BVH * bvh, MVert *x, unsigned int numverts, MVert *xnew, int moving);
+
////////////////////////////////////////////////
@@ -180,13 +187,12 @@
// needed for cloth.c
void bvh_free ( BVH * bvh );
-BVH *bvh_build ( ClothModifierData *clmd, float epsilon );
+void bvh_build (BVH *bvh);
LinkNode *BLI_linklist_append_fast ( LinkNode **listp, void *ptr );
// needed for collision.c
-int bvh_traverse ( ClothModifierData * clmd, ClothModifierData * coll_clmd, Tree * tree1, Tree * tree2, float step, CM_COLLISION_RESPONSE collision_response );
-void bvh_update ( ClothModifierData * clmd, BVH * bvh, int moving );
-
+int bvh_traverse ( ClothModifierData * clmd, ClothModifierData * coll_clmd, CollisionTree * tree1, CollisionTree * tree2, float step, CM_COLLISION_RESPONSE collision_response );
+void bvh_update(BVH * bvh, int moving);
////////////////////////////////////////////////
@@ -199,6 +205,9 @@
void cloth_deform_verts ( struct Object *ob, float framenr, float ( *vertexCos ) [3], int numVerts, void *derivedData, ClothModifierData *clmd );
void cloth_update_normals ( ClothVertex *verts, int nVerts, MFace *face, int totface );
+// needed for collision.c
+void bvh_update_from_cloth(ClothModifierData *clmd, int moving);
+
////////////////////////////////////////////////
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h 2008-01-21 00:41:29 UTC (rev 13322)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h 2008-01-21 02:23:03 UTC (rev 13323)
@@ -79,6 +79,7 @@
}
BVH;
+
/* used for collisions in kdop.c and also collision.c*/
typedef struct CollisionPair
{
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-01-21 00:41:29 UTC (rev 13322)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-01-21 02:23:03 UTC (rev 13323)
@@ -160,6 +160,7 @@
clmd->sim_parms.maxspringlen = 10;
clmd->sim_parms.firstframe = 1;
clmd->sim_parms.lastframe = 250;
+ clmd->sim_parms.vgroup_mass = 0;
clmd->coll_parms.self_friction = 5.0;
clmd->coll_parms.friction = 10.0;
clmd->coll_parms.loop_count = 1;
@@ -175,13 +176,91 @@
// also from softbodies
clmd->sim_parms.maxgoal = 1.0f;
clmd->sim_parms.mingoal = 0.0f;
- clmd->sim_parms.defgoal = 0.7f;
+ clmd->sim_parms.defgoal = 0.0f;
clmd->sim_parms.goalspring = 100.0f;
clmd->sim_parms.goalfrict = 0.0f;
clmd->sim_parms.cache = NULL;
}
+
+BVH *bvh_build_from_cloth (ClothModifierData *clmd, float epsilon)
+{
+ unsigned int i = 0;
+ BVH *bvh=NULL;
+ Cloth *cloth = clmd->clothObject;
+ ClothVertex *verts = NULL;
+
+ if(!clmd)
+ return NULL;
+
+ cloth = clmd->clothObject;
+
+ if(!cloth)
+ return NULL;
+
+ verts = cloth->verts;
+
+ bvh = MEM_callocN(sizeof(BVH), "BVH");
+ if (bvh == NULL)
+ {
+ printf("bvh: Out of memory.\n");
+ return NULL;
+ }
+
+ // springs = cloth->springs;
+ // numsprings = cloth->numsprings;
+
+ bvh->flags = 0;
+ bvh->leaf_tree = NULL;
+ bvh->leaf_root = NULL;
+ bvh->tree = NULL;
+
+ bvh->epsilon = epsilon;
+ bvh->numfaces = cloth->numfaces;
+ bvh->mfaces = cloth->mfaces;
+
+ bvh->numverts = cloth->numverts;
+
+ bvh->current_x = MEM_callocN ( sizeof ( MVert ) * bvh->numverts, "bvh->current_x" );
+ bvh->current_xold = MEM_callocN ( sizeof ( MVert ) * bvh->numverts, "bvh->current_xold" );
+
+ for(i = 0; i < bvh->numverts; i++)
+ {
+ VECCOPY(bvh->current_x[i].co, verts[i].tx);
+ VECCOPY(bvh->current_xold[i].co, verts[i].txold);
+ }
+
+ bvh_build (bvh);
+
+ return bvh;
+}
+
+void bvh_update_from_cloth(ClothModifierData *clmd, int moving)
+{
+ unsigned int i = 0;
+ Cloth *cloth = clmd->clothObject;
+ BVH *bvh = cloth->tree;
+ ClothVertex *verts = cloth->verts;
+
+ if(!bvh)
+ return;
+
+ if(cloth->numverts!=bvh->numverts)
+ return;
+
+ if(cloth->verts)
+ {
+ for(i = 0; i < bvh->numverts; i++)
+ {
+ VECCOPY(bvh->current_x[i].co, verts[i].tx);
+ VECCOPY(bvh->current_xold[i].co, verts[i].txold);
+ }
+ }
+
+ bvh_update(bvh, moving);
+}
+
// unused in the moment, cloth needs quads from mesh
DerivedMesh *CDDM_convert_to_triangle ( DerivedMesh *dm )
{
@@ -433,9 +512,9 @@
for(a = 0; a < cloth->numverts; a++)
{
- fwrite(&cloth->verts[a].x, sizeof(float),4,fp);
- fwrite(&cloth->verts[a].xconst, sizeof(float),4,fp);
- fwrite(&cloth->verts[a].v, sizeof(float),4,fp);
+ fwrite(&cloth->verts[a].x, sizeof(float),3,fp);
+ fwrite(&cloth->verts[a].xconst, sizeof(float),3,fp);
+ fwrite(&cloth->verts[a].v, sizeof(float),3,fp);
}
fclose(fp);
@@ -458,17 +537,17 @@
else {
for(a = 0; a < cloth->numverts; a++)
{
- if(fread(&cloth->verts[a].x, sizeof(float), 4, fp) != 4)
+ if(fread(&cloth->verts[a].x, sizeof(float), 3, fp) != 3)
{
ret = 0;
break;
}
- if(fread(&cloth->verts[a].xconst, sizeof(float), 4, fp) != 4)
+ if(fread(&cloth->verts[a].xconst, sizeof(float), 3, fp) != 3)
{
ret = 0;
break;
}
- if(fread(&cloth->verts[a].v, sizeof(float), 4, fp) != 4)
+ if(fread(&cloth->verts[a].v, sizeof(float), 3, fp) != 3)
{
ret = 0;
break;
@@ -656,7 +735,7 @@
solvers [clmd->sim_parms.solver_type].solver ( ob, framenr, clmd, effectors );
tend();
- printf ( "Cloth simulation time: %f\n", ( float ) tval() );
+ // printf ( "Cloth simulation time: %f\n", ( float ) tval() );
cloth_write_cache(ob, clmd, framenr);
@@ -830,7 +909,13 @@
{
verts->goal = dvert->dw [j].weight;
- goalfac= ABS ( clmd->sim_parms.maxgoal - clmd->sim_parms.mingoal );
+ goalfac= 1.0f;
+
+ /*
+ // Kicking goal factor to simplify things...who uses that anyway?
+ // ABS ( clmd->sim_parms.maxgoal - clmd->sim_parms.mingoal );
+ */
+
verts->goal = ( float ) pow ( verts->goal , 4.0f );
if ( dvert->dw [j].weight >=SOFTGOALSNAP )
@@ -905,7 +990,7 @@
verts->impulse_count = 0;
VECCOPY ( verts->impulse, tnull );
}
- clmd->clothObject->tree = bvh_build ( clmd,clmd->coll_parms.epsilon );
+ clmd->clothObject->tree = bvh_build_from_cloth ( clmd,clmd->coll_parms.epsilon );
}
@@ -1012,7 +1097,7 @@
if ( solvers [clmd->sim_parms.solver_type].init )
solvers [clmd->sim_parms.solver_type].init ( ob, clmd );
- clmd->clothObject->tree = bvh_build ( clmd, clmd->coll_parms.epsilon );
+ clmd->clothObject->tree = bvh_build_from_cloth ( clmd, clmd->coll_parms.epsilon );
cloth_write_cache(ob, clmd, framenr-1);
}
Modified: branches/cloth/blender/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/collision.c 2008-01-21 00:41:29 UTC (rev 13322)
+++ branches/cloth/blender/source/blender/blenkernel/intern/collision.c 2008-01-21 02:23:03 UTC (rev 13323)
@@ -70,8 +70,73 @@
#include "Bullet-C-Api.h"
+// step is limited from 0 (frame start position) to 1 (frame end position)
+void collision_move_object(CollisionModifierData *collmd, float step, float prevstep)
+{
+ float tv[3] = {0,0,0};
+ unsigned int i = 0;
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list