Commit: c582e186d90291a19a4e404111c492f1fd2c41a4
Author: Campbell Barton
Date:   Fri Jul 31 14:00:07 2015 +1000
Branches: master
https://developer.blender.org/rBc582e186d90291a19a4e404111c492f1fd2c41a4

Replace MFace w/ vert-tri's for collision modifier

Note that the collision modifier doesn't have any use for Loop indices,
so to avoid duplicating the loop array too,
MVertTri has been added which simply stores vertex indices (runtime only).

===================================================================

M       source/blender/blenkernel/BKE_DerivedMesh.h
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/DerivedMesh.c
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_meshdata_types.h
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/modifiers/intern/MOD_collision.c
M       source/blender/physics/BPH_mass_spring.h
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_DerivedMesh.h 
b/source/blender/blenkernel/BKE_DerivedMesh.h
index f331bcb..6a6e975 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -613,6 +613,7 @@ void DM_ensure_tessface(DerivedMesh *dm);
 
 void DM_ensure_looptri_data(DerivedMesh *dm);
 void DM_ensure_looptri(DerivedMesh *dm);
+void DM_verttri_from_looptri(MVertTri *verttri, const MLoop *mloop, const 
MLoopTri *looptri, int looptri_num);
 
 void DM_update_tessface_data(DerivedMesh *dm);
 void DM_generate_tangent_tessface_data(DerivedMesh *dm, bool generate);
diff --git a/source/blender/blenkernel/BKE_cloth.h 
b/source/blender/blenkernel/BKE_cloth.h
index 81621f9..b8ac6af 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -86,15 +86,15 @@ 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            tri_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 MVertTri         *tri;
        struct Implicit_Data    *implicit;              /* our implicit solver 
connects to this pointer */
        struct EdgeSet          *edgeset;               /* used for 
selfcollisions */
        int last_frame, pad4;
@@ -233,8 +233,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..d5b4a58 100644
--- a/source/blender/blenkernel/BKE_collision.h
+++ b/source/blender/blenkernel/BKE_collision.h
@@ -49,6 +49,7 @@ struct MFace;
 struct MVert;
 struct Object;
 struct Scene;
+struct MVertTri;
 
 ////////////////////////////////////////
 // used for collisions in collision.c
@@ -124,8 +125,15 @@ 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 MVertTri *tri, int tri_num,
+        float epsilon);
+void bvhtree_update_from_mvert(
+        BVHTree *bvhtree,
+        const struct MVert *mvert, const struct MVert *mvert_moving,
+        const struct MVertTri *tri, int tri_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/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 3156eb3..25f409b 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -493,6 +493,16 @@ void DM_ensure_looptri(DerivedMesh *dm)
        }
 }
 
+void DM_verttri_from_looptri(MVertTri *verttri, const MLoop *mloop, const 
MLoopTri *looptri, int looptri_num)
+{
+       int i;
+       for (i = 0; i < looptri_num; i++) {
+               verttri[i].tri[0] = mloop[looptri[i].tri[0]].v;
+               verttri[i].tri[1] = mloop[looptri[i].tri[1]].v;
+               verttri[i].tri[2] = mloop[looptri[i].tri[2]].v;
+       }
+}
+
 /* Update tessface CD data from loop/poly ones. Needed when not retessellating 
after modstack evaluation. */
 /* NOTE: Assumes dm has valid tessellated data! */
 void DM_update_tessface_data(DerivedMesh *dm)
diff --git a/source/blender/blenkernel/intern/cloth.c 
b/source/blender/blenkernel/intern/cloth.c
index e3ff968..1b23377 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,7 @@ static BVHTree *bvhtree_build_from_cloth (ClothModifierData 
*clmd, float epsilon
        BVHTree *bvhtree;
        Cloth *cloth;
        ClothVertex *verts;
-       MFace *mfaces;
-       float co[12];
+       const MVertTri *vt;
 
        if (!clmd)
                return NULL;
@@ -187,25 +186,24 @@ static BVHTree *bvhtree_build_from_cloth 
(ClothModifierData *clmd, float epsilon
                return NULL;
        
        verts = cloth->verts;
-       mfaces = cloth->mfaces;
+       vt = cloth->tri;
        
        /* in the moment, return zero if no faces there */
-       if (!cloth->numfaces)
+       if (!cloth->tri_num)
                return NULL;
 
        /* create quadtree with k=26 */
-       bvhtree = BLI_bvhtree_new(cloth->numfaces, epsilon, 4, 26);
+       bvhtree = BLI_bvhtree_new(cloth->tri_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->tri_num; i++, vt++) {
+               float co[3][3];
 
-               if (mfaces->v4)
-                       copy_v3_v3(&co[3*3], verts[mfaces->v4].xold);
+               copy_v3_v3(co[0], verts[vt->tri[0]].xold);
+               copy_v3_v3(co[1], verts[vt->tri[1]].xold);
+               copy_v3_v3(co[2], verts[vt->tri[2]].xold);
 
-               BLI_bvhtree_insert(bvhtree, i, co, (mfaces->v4 ? 4 : 3));
+               BLI_bvhtree_insert(bvhtree, i, co[0], 3);
        }
 
        /* balance tree */
@@ -214,90 +212,87 @@ 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 MVertTri *vt;
        
        if (!bvhtree)
                return;
        
-       mfaces = cloth->mfaces;
+       vt = cloth->tri;
        
-       // 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 && vt) {
+               for (i = 0; i < cloth->tri_num; i++, vt++) {
+                       float co[3][3], co_moving[3][3];
+                       bool ret;
+
+                       copy_v3_v3(co[0], verts[vt->tri[0]].txold);
+                       copy_v3_v3(co[1], verts[vt->tri[1]].txold);
+                       copy_v3_v3(co[2], verts[vt->tri[2]].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[vt->tri[0]].tx);
+                               copy_v3_v3(co_moving[1], verts[vt->tri[1]].tx);
+                               copy_v3_v3(co_moving[2], verts[vt->tri[2]].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], c

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to