[Bf-blender-cvs] [fd21b31] temp-looptri-collision: Work in progress, move collision modifier to looptri
Campbell Barton
noreply at git.blender.org
Thu Jul 30 14:21:14 CEST 2015
Commit: fd21b31024c52cffe0a16220c10d15dc10c637ba
Author: Campbell Barton
Date: Thu Jul 30 22:16:01 2015 +1000
Branches: temp-looptri-collision
https://developer.blender.org/rBfd21b31024c52cffe0a16220c10d15dc10c637ba
Work in progress, move collision modifier to looptri
Theres still some unresolved issues so committing to temp branch
===================================================================
M source/blender/blenkernel/BKE_cloth.h
M source/blender/blenkernel/BKE_collision.h
M source/blender/blenkernel/BKE_particle.h
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/collision.c
M source/blender/blenkernel/intern/particle_system.c
M source/blender/blenkernel/intern/pointcache.c
M source/blender/blenkernel/intern/softbody.c
M source/blender/blenloader/intern/readfile.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/modifiers/intern/MOD_collision.c
M source/blender/physics/intern/BPH_mass_spring.cpp
M source/blender/physics/intern/implicit.h
M source/blender/physics/intern/implicit_blender.c
M source/blender/physics/intern/implicit_eigen.cpp
===================================================================
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 81621f9..e7dde61 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -86,15 +86,17 @@ typedef struct ClothSolverResult {
typedef struct Cloth {
struct ClothVertex *verts; /* The vertices that represent this cloth. */
struct LinkNode *springs; /* The springs connecting the mesh. */
- unsigned int numverts; /* The number of verts == m * n. */
unsigned int numsprings; /* The count of springs. */
- unsigned int numfaces;
+ unsigned int mvert_num; /* The number of verts == m * n. */
+ unsigned int mloop_num;
+ unsigned int looptri_num;
unsigned char old_solver_type; /* unused, only 1 solver here */
unsigned char pad2;
short pad3;
struct BVHTree *bvhtree; /* collision tree for this cloth object */
struct BVHTree *bvhselftree; /* collision tree for this cloth object */
- struct MFace *mfaces;
+ struct MLoop *mloop;
+ struct MLoopTri *looptri;
struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */
struct EdgeSet *edgeset; /* used for selfcollisions */
int last_frame, pad4;
@@ -233,8 +235,8 @@ void clothModifier_do (struct ClothModifierData *clmd, struct Scene *scene, stru
int cloth_uses_vgroup(struct ClothModifierData *clmd);
// needed for collision.c
-void bvhtree_update_from_cloth (struct ClothModifierData *clmd, int moving );
-void bvhselftree_update_from_cloth (struct ClothModifierData *clmd, int moving );
+void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving);
+void bvhselftree_update_from_cloth(struct ClothModifierData *clmd, bool moving);
// needed for button_object.c
void cloth_clear_cache (struct Object *ob, struct ClothModifierData *clmd, float framenr );
diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h
index bdc2032..f1edcce 100644
--- a/source/blender/blenkernel/BKE_collision.h
+++ b/source/blender/blenkernel/BKE_collision.h
@@ -47,6 +47,8 @@ struct CollisionModifierData;
struct Group;
struct MFace;
struct MVert;
+struct MLoop;
+struct MLoopTri;
struct Object;
struct Scene;
@@ -124,8 +126,17 @@ FaceCollPair;
// used in modifier.c from collision.c
/////////////////////////////////////////////////
-BVHTree *bvhtree_build_from_mvert(struct MFace *mfaces, unsigned int numfaces, struct MVert *x, unsigned int numverts, float epsilon);
-void bvhtree_update_from_mvert(BVHTree *bvhtree, struct MFace *faces, int numfaces, struct MVert *x, struct MVert *xnew, int numverts, int moving);
+BVHTree *bvhtree_build_from_mvert(
+ const struct MVert *mvert,
+ const struct MLoop *mloop,
+ const struct MLoopTri *looptri, int looptri_num,
+ float epsilon);
+void bvhtree_update_from_mvert(
+ BVHTree *bvhtree,
+ const struct MVert *mvert, const struct MVert *mvert_moving,
+ const struct MLoop *mloop,
+ const struct MLoopTri *looptri, int looptri_num,
+ bool moving);
/////////////////////////////////////////////////
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index e03789f..3232570 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -179,7 +179,7 @@ typedef struct ParticleBillboardData {
typedef struct ParticleCollisionElement {
/* pointers to original data */
- float *x[4], *v[4];
+ float *x[3], *v[3];
/* values interpolated from original data*/
float x0[3], x1[3], x2[3], p[3];
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index e3ff968..62fbfca 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -137,7 +137,6 @@ static BVHTree *bvhselftree_build_from_cloth (ClothModifierData *clmd, float eps
BVHTree *bvhtree;
Cloth *cloth;
ClothVertex *verts;
- float co[12];
if (!clmd)
return NULL;
@@ -149,21 +148,22 @@ static BVHTree *bvhselftree_build_from_cloth (ClothModifierData *clmd, float eps
verts = cloth->verts;
- // in the moment, return zero if no faces there
- if (!cloth->numverts)
+ /* in the moment, return zero if no faces there */
+ if (!cloth->mvert_num)
return NULL;
- // create quadtree with k=26
- bvhtree = BLI_bvhtree_new(cloth->numverts, epsilon, 4, 6);
+ /* create quadtree with k=26 */
+ bvhtree = BLI_bvhtree_new(cloth->mvert_num, epsilon, 4, 6);
- // fill tree
- for (i = 0; i < cloth->numverts; i++, verts++) {
- copy_v3_v3(&co[0*3], verts->xold);
+ /* fill tree */
+ for (i = 0; i < cloth->mvert_num; i++, verts++) {
+ const float *co;
+ co = verts->xold;
BLI_bvhtree_insert(bvhtree, i, co, 1);
}
- // balance tree
+ /* balance tree */
BLI_bvhtree_balance(bvhtree);
return bvhtree;
@@ -175,8 +175,8 @@ static BVHTree *bvhtree_build_from_cloth (ClothModifierData *clmd, float epsilon
BVHTree *bvhtree;
Cloth *cloth;
ClothVertex *verts;
- MFace *mfaces;
- float co[12];
+ const MLoop *mloop;
+ const MLoopTri *lt;
if (!clmd)
return NULL;
@@ -187,25 +187,25 @@ static BVHTree *bvhtree_build_from_cloth (ClothModifierData *clmd, float epsilon
return NULL;
verts = cloth->verts;
- mfaces = cloth->mfaces;
+ mloop = cloth->mloop;
+ lt = cloth->looptri;
/* in the moment, return zero if no faces there */
- if (!cloth->numfaces)
+ if (!cloth->looptri_num)
return NULL;
/* create quadtree with k=26 */
- bvhtree = BLI_bvhtree_new(cloth->numfaces, epsilon, 4, 26);
+ bvhtree = BLI_bvhtree_new(cloth->looptri_num, epsilon, 4, 26);
/* fill tree */
- for (i = 0; i < cloth->numfaces; i++, mfaces++) {
- copy_v3_v3(&co[0*3], verts[mfaces->v1].xold);
- copy_v3_v3(&co[1*3], verts[mfaces->v2].xold);
- copy_v3_v3(&co[2*3], verts[mfaces->v3].xold);
+ for (i = 0; i < cloth->looptri_num; i++, lt++) {
+ float co[3][3];
- if (mfaces->v4)
- copy_v3_v3(&co[3*3], verts[mfaces->v4].xold);
+ copy_v3_v3(co[0], verts[mloop[lt->tri[0]].v].xold);
+ copy_v3_v3(co[1], verts[mloop[lt->tri[1]].v].xold);
+ copy_v3_v3(co[2], verts[mloop[lt->tri[2]].v].xold);
- BLI_bvhtree_insert(bvhtree, i, co, (mfaces->v4 ? 4 : 3));
+ BLI_bvhtree_insert(bvhtree, i, co[0], 3);
}
/* balance tree */
@@ -214,90 +214,91 @@ static BVHTree *bvhtree_build_from_cloth (ClothModifierData *clmd, float epsilon
return bvhtree;
}
-void bvhtree_update_from_cloth(ClothModifierData *clmd, int moving)
+void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving)
{
unsigned int i = 0;
Cloth *cloth = clmd->clothObject;
BVHTree *bvhtree = cloth->bvhtree;
ClothVertex *verts = cloth->verts;
- MFace *mfaces;
- float co[12], co_moving[12];
- bool ret = false;
+ const MLoop *mloop;
+ const MLoopTri *lt;
if (!bvhtree)
return;
- mfaces = cloth->mfaces;
+ mloop = cloth->mloop;
+ lt = cloth->looptri;
- // update vertex position in bvh tree
- if (verts && mfaces) {
- for (i = 0; i < cloth->numfaces; i++, mfaces++) {
- copy_v3_v3(&co[0*3], verts[mfaces->v1].txold);
- copy_v3_v3(&co[1*3], verts[mfaces->v2].txold);
- copy_v3_v3(&co[2*3], verts[mfaces->v3].txold);
-
- if (mfaces->v4)
- copy_v3_v3(&co[3*3], verts[mfaces->v4].txold);
-
- // copy new locations into array
+ /* update vertex position in bvh tree */
+ if (verts && lt) {
+ for (i = 0; i < cloth->looptri_num; i++, lt++) {
+ float co[3][3], co_moving[3][3];
+ bool ret;
+
+ copy_v3_v3(co[0], verts[mloop[lt->tri[0]].v].txold);
+ copy_v3_v3(co[1], verts[mloop[lt->tri[1]].v].txold);
+ copy_v3_v3(co[2], verts[mloop[lt->tri[2]].v].txold);
+
+ /* copy new locations into array */
if (moving) {
- // update moving positions
- copy_v3_v3(&co_moving[0*3], verts[mfaces->v1].tx);
- copy_v3_v3(&co_moving[1*3], verts[mfaces->v2].tx);
- copy_v3_v3(&co_moving[2*3], verts[mfaces->v3].tx);
-
- if (mfaces->v4)
- copy_v3_v3(&co_moving[3*3], verts[mfaces->v4].tx);
-
- ret = BLI_bvhtree_update_node(bvhtree, i, co, co_moving, (mfaces->v4 ? 4 : 3));
+ /* update moving positions */
+ copy_v3_v3(co_moving[0], verts[mloop[lt->tri[0]].v].tx);
+ copy_v3_v3(co_moving[1], verts[mloop[lt->tri[1]].v].tx);
+ copy_v3_v3(co_moving[2], verts[mloop[lt->tri[2]].v].tx);
+
+ ret = BLI_bvhtree_update_node(bvhtree, i, co[0], co_moving[0], 3);
}
else {
- ret = BLI_bvhtree_update_node(bvhtree, i, co, NULL, (mfaces->v4 ? 4 : 3));
+ ret = BLI_bvhtree_update_node(bvhtree, i, co[0], NULL, 3);
}
- // check if tree is already full
- if (!ret)
+ /* check if tree is already full */
+ if (ret == false) {
break;
+ }
}
BLI_bvhtree_update_tree(bvhtree);
}
}
-void bvhselftree_update_from_cloth(ClothModifierData *clmd, int moving)
+void bvhselftree_update_from_cloth(ClothModifierData *clmd, bool moving)
{
unsigned int i = 0;
Cloth *cloth = clmd->clothObject;
BVHTree *bvhtree = cloth->bvhselftree;
ClothVertex *verts = cloth->verts;
- MFace *mfaces;
- float co[12], co_moving[12];
- int ret = 0;
+ const MLoop *mloop;
+ const MLoopTri *looptri;
if (!bvhtree)
return;
- mfaces = cloth->mfaces;
+ mloop = cloth->mloop;
+ looptri = cloth->looptri;
- // update vertex position in bvh tree
- if (verts && mfaces) {
- for (i = 0; i < cloth->numverts; i++, verts++) {
- copy_v3_v3(&co[0*3], verts->txold);
+ /* update vertex position in bvh tree */
+ if (verts && mloop && looptri) {
+ for (i = 0; i < cloth->mvert_num; i++, verts++) {
+ const float *co, *co_moving;
+ bool ret;
- // copy new locations into array
- if (moving) {
- // update moving positions
- copy_v3_v3(&co_moving[0*3], verts->tx);
+ co = verts->txold;
+ /* copy new locations into array */
+ if (moving) {
+ /* update moving positions */
+ co_moving = verts->tx;
ret = BLI_bvhtree_update_node(bvhtree, i, co, co_moving, 1);
}
else {
ret = BLI_bvhtree_update_node(bvhtree, i, co, NULL, 1);
}
- // check if tree is already full
- if (!ret)
+ /* check if tree is already full */
+ if (ret == false) {
break;
+ }
}
BLI_bvhtree_update_tree(bvhtree);
@@ -360
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list