[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12366] branches/cloth/blender/source/ blender: Another WIP commit.
Daniel Genrich
daniel.genrich at gmx.net
Wed Oct 24 00:38:08 CEST 2007
Revision: 12366
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12366
Author: genscher
Date: 2007-10-24 00:38:07 +0200 (Wed, 24 Oct 2007)
Log Message:
-----------
Another WIP commit. Building up bounding volume API
Modified Paths:
--------------
branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h
branches/cloth/blender/source/blender/blenkernel/intern/kdop.c
branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
branches/cloth/blender/source/blender/src/buttons_object.c
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h 2007-10-23 21:31:59 UTC (rev 12365)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h 2007-10-23 22:38:07 UTC (rev 12366)
@@ -89,7 +89,8 @@
/////////////////////////////////////////////////
// builds bounding volume hierarchy
-BVH *bvh_build (MFace *mfaces, unsigned int numfaces, MVert *x, MVert *xnew, unsigned int numverts, float epsilon);
+BVH *bvh_build_from_mvert (MFace *mfaces, unsigned int numfaces, MVert *x, unsigned int numverts, float epsilon);
+
// frees the same
void bvh_free ( BVH *bvh );
@@ -97,7 +98,7 @@
int bvh_traverse(CollisionTree *tree1, CollisionTree *tree2, LinkNode *collision_list);
// update bounding volumes, needs updated positions in bvh->x
-void bvh_update(BVH * bvh, int moving);
+void bvh_update_from_mvert(BVH * bvh, MVert *x, unsigned int numverts, MVert *xnew, int moving);
LinkNode *BLI_linklist_append_fast (LinkNode **listp, void *ptr);
Modified: branches/cloth/blender/source/blender/blenkernel/intern/kdop.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/kdop.c 2007-10-23 21:31:59 UTC (rev 12365)
+++ branches/cloth/blender/source/blender/blenkernel/intern/kdop.c 2007-10-23 22:38:07 UTC (rev 12366)
@@ -330,6 +330,11 @@
BLI_linklist_free(bvh->tree,NULL);
bvh->tree = NULL;
+ if(bvh->x)
+ MEM_freeN(bvh->x);
+ if(bvh->xnew)
+ MEM_freeN(bvh->xnew);
+
MEM_freeN(bvh);
bvh = NULL;
}
@@ -520,44 +525,14 @@
// mfaces is allowed to be null
// just vertexes are used if mfaces=NULL
-BVH *bvh_build (MFace *mfaces, unsigned int numfaces, MVert *x, MVert *xnew, unsigned int numverts, float epsilon)
+BVH *bvh_build (BVH *bvh, MFace *mfaces, unsigned int numfaces)
{
unsigned int i = 0, j = 0;
CollisionTree **face_list=NULL;
- BVH *bvh=NULL;
CollisionTree *tree=NULL;
LinkNode *nlink = NULL;
MFace *mface = NULL;
- bvh = MEM_callocN(sizeof(BVH), "BVH");
- if (bvh == NULL)
- {
- printf("bvh: Out of memory.\n");
- return NULL;
- }
-
- bvh->flags = 0;
- bvh->leaf_tree = NULL;
- bvh->leaf_root = NULL;
- bvh->tree = NULL;
-
- bvh->epsilon = epsilon;
- bvh->numfaces = numfaces;
- mface = bvh->mfaces = mfaces;
-
- // we have no faces, we save seperate points
- if(!bvh->mfaces)
- {
- bvh->numfaces = numverts;
- }
-
- bvh->numverts = numverts;
- bvh->xnew = xnew;
- bvh->x = x;
- tree = (CollisionTree *)MEM_callocN(sizeof(CollisionTree), "CollisionTree");
- // TODO: check succesfull alloc
- BLI_linklist_append(&bvh->tree, tree);
-
nlink = bvh->tree;
if (tree == NULL)
@@ -686,6 +661,46 @@
return bvh;
}
+BVH *bvh_build_from_mvert (MFace *mfaces, unsigned int numfaces, MVert *x, unsigned int numverts, float epsilon)
+{
+ unsigned int i = 0, j = 0;
+ CollisionTree **face_list=NULL;
+ BVH *bvh=NULL;
+ CollisionTree *tree=NULL;
+ LinkNode *nlink = NULL;
+ MFace *mface = NULL;
+
+ bvh = MEM_callocN(sizeof(BVH), "BVH");
+ if (bvh == NULL)
+ {
+ printf("bvh: Out of memory.\n");
+ return NULL;
+ }
+
+ bvh->flags = 0;
+ bvh->leaf_tree = NULL;
+ bvh->leaf_root = NULL;
+ bvh->tree = NULL;
+
+ bvh->epsilon = epsilon;
+ bvh->numfaces = numfaces;
+
+ // we have no faces, we save seperate points
+ if(!mfaces)
+ {
+ bvh->numfaces = numverts;
+ }
+
+ bvh->numverts = numverts;
+ bvh->xnew = MEM_dupallocN(x);
+ bvh->x = MEM_dupallocN(x);
+ tree = (CollisionTree *)MEM_callocN(sizeof(CollisionTree), "CollisionTree");
+ // TODO: check succesfull alloc
+ BLI_linklist_append(&bvh->tree, tree);
+
+ return bvh_build(bvh, mfaces, numfaces);
+}
+
// bvh_overlap - is it possbile for 2 bv's to collide ?
int bvh_overlap(float *bv1, float *bv2)
{
@@ -850,3 +865,20 @@
}
}
+void bvh_update_from_mvert(BVH * bvh, MVert *x, unsigned int numverts, MVert *xnew, int moving)
+{
+ if(!bvh)
+ return;
+
+ if(numverts!=bvh->numverts)
+ return;
+
+ if(x)
+ memcpy(bvh->x, x, sizeof(MVert) * numverts);
+
+ if(xnew)
+ memcpy(bvh->xnew, xnew, sizeof(MVert) * numverts);
+
+ bvh_update(bvh, moving);
+}
+
Modified: branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/modifier.c 2007-10-23 21:31:59 UTC (rev 12365)
+++ branches/cloth/blender/source/blender/blenkernel/intern/modifier.c 2007-10-23 22:38:07 UTC (rev 12366)
@@ -5066,7 +5066,7 @@
// TODO: epsilon
// create bounding box hierarchy
- collmd->tree = bvh_build(dm->getFaceArray(dm), dm->getNumFaces(dm), collmd->current_x, collmd->current_xnew, numverts, ob->pd->pdef_sbift);
+ collmd->tree = bvh_build_from_mvert(dm->getFaceArray(dm), dm->getNumFaces(dm), collmd->current_x, numverts, ob->pd->pdef_sbift);
}
else if(numverts == collmd->numverts)
{
@@ -5086,7 +5086,8 @@
memcpy(collmd->current_xnew, dm->getVertArray(dm), numverts*sizeof(MVert));
memcpy(collmd->current_x, dm->getVertArray(dm), numverts*sizeof(MVert));
- bvh_update(collmd->tree, 0); // recalc static bounding boxes
+ // recalc static bounding boxes
+ bvh_update_from_mvert(collmd->tree, collmd->current_x, numverts, NULL, 0);
}
collmd->time = current_time;
Modified: branches/cloth/blender/source/blender/src/buttons_object.c
===================================================================
--- branches/cloth/blender/source/blender/src/buttons_object.c 2007-10-23 21:31:59 UTC (rev 12365)
+++ branches/cloth/blender/source/blender/src/buttons_object.c 2007-10-23 22:38:07 UTC (rev 12366)
@@ -3268,38 +3268,29 @@
static void object_panel_cloth_III(Object *ob)
{
uiBlock *block;
- static int val;
- uiBut *but;
ClothModifierData *clmd = NULL;
clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
if(clmd)
- {
- if (!(clmd->sim_parms.flags & CLOTH_SIMSETTINGS_FLAG_COLLOBJ))
- {
- Cloth *cloth = clmd->clothObject;
- char str[128];
-
- block= uiNewBlock(&curarea->uiblocks, "object_panel_cloth_III", UI_EMBOSS, UI_HELV, curarea->win);
- uiNewPanelTabbed("Cloth", "Physics");
- if(uiNewPanel(curarea, block, "Cloth Collisions", "Physics", 651, 0, 318, 204)==0) return;
+ {
+ block= uiNewBlock(&curarea->uiblocks, "object_panel_cloth_III", UI_EMBOSS, UI_HELV, curarea->win);
+ uiNewPanelTabbed("Cloth", "Physics");
+ if(uiNewPanel(curarea, block, "Cloth Collisions", "Physics", 651, 0, 318, 204)==0) return;
+
+ uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
- uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
-
- uiBlockBeginAlign(block);
- uiDefButBitI(block, TOG, CLOTH_COLLISIONSETTINGS_FLAG_ENABLED, REDRAWVIEW3D, "Enable collisions", 10,70,130,20, &clmd->coll_parms.flags, 0, 0, 0, 0, "Enable collisions with this object");
- if (clmd->coll_parms.flags & CLOTH_COLLISIONSETTINGS_FLAG_ENABLED)
- {
- // uiDefBut(block, LABEL, 0, "",10,10,300,20, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
- uiDefButF(block, NUM, B_CLOTH_RENEW, "Min Distance:", 10,30,150,20, &clmd->coll_parms.epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in");
- uiDefBut(block, LABEL, 0, "",160,30,150,20, NULL, 0.0, 0, 0, 0, "");
- }
- else
- uiDefBut(block, LABEL, 0, "",140,10,170,20, NULL, 0.0, 0, 0, 0, "");
- uiBlockEndAlign(block);
+ uiBlockBeginAlign(block);
+ uiDefButBitI(block, TOG, CLOTH_COLLISIONSETTINGS_FLAG_ENABLED, REDRAWVIEW3D, "Enable collisions", 10,70,130,20, &clmd->coll_parms.flags, 0, 0, 0, 0, "Enable collisions with this object");
+ if (clmd->coll_parms.flags & CLOTH_COLLISIONSETTINGS_FLAG_ENABLED)
+ {
+ // uiDefBut(block, LABEL, 0, "",10,10,300,20, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
+ uiDefButF(block, NUM, B_CLOTH_RENEW, "Min Distance:", 10,30,150,20, &clmd->coll_parms.epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in");
+ uiDefBut(block, LABEL, 0, "",160,30,150,20, NULL, 0.0, 0, 0, 0, "");
}
+ else
+ uiDefBut(block, LABEL, 0, "",140,10,170,20, NULL, 0.0, 0, 0, 0, "");
+ uiBlockEndAlign(block);
}
- // uiBlockEndAlign(block);
}
More information about the Bf-blender-cvs
mailing list