Commit: afa33574deb1dea37e92559cad2e825b20a0ac4c
Author: Martin Felke
Date:   Thu Aug 17 17:34:37 2017 +0200
Branches: fracture_modifier
https://developer.blender.org/rBafa33574deb1dea37e92559cad2e825b20a0ac4c

fixes for centroid and volume calculation for non-manifolds, fix attempt for 
storage of merge info

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

M       source/blender/blenkernel/BKE_fracture.h
M       source/blender/blenkernel/intern/fracture.c
M       source/blender/blenkernel/intern/rigidbody.c
M       source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/source/blender/blenkernel/BKE_fracture.h 
b/source/blender/blenkernel/BKE_fracture.h
index eb748e1eac9..82f1b9031b4 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -80,6 +80,7 @@ struct Shard *BKE_custom_data_to_shard(struct Shard *s, 
struct DerivedMesh *dm);
 /* utility functions */
 bool BKE_fracture_shard_center_median(struct Shard *shard, float cent[3]);
 bool BKE_fracture_shard_center_centroid(struct Shard *shard, float cent[3]);
+bool BKE_fracture_shard_center_centroid_area(struct Shard *shard, float 
cent[3]);
 float BKE_shard_calc_minmax(struct Shard *shard);
 
 void BKE_fracmesh_free(struct FracMesh *fm, bool doCustomData);
diff --git a/source/blender/blenkernel/intern/fracture.c 
b/source/blender/blenkernel/intern/fracture.c
index 055848c35d3..61fc9679a6e 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -313,16 +313,15 @@ bool BKE_fracture_shard_center_centroid(Shard *shard, 
float r_cent[3])
                mul_v3_fl(r_cent, 0.25f / total_volume);
        }
 
-       /* this can happen for non-manifold objects, fallback to median */
-       if (UNLIKELY(!is_finite_v3(r_cent))) {
-               return BKE_fracture_shard_center_median(shard, r_cent);
+       /* this can happen for non-manifold objects, first fallback to old area 
based method, then fallback to median there */
+       if (!is_finite_v3(r_cent) || total_volume < 0.000001f) {
+               return BKE_fracture_shard_center_centroid_area(shard, r_cent);
        }
 
        copy_v3_v3(shard->centroid, r_cent);
        return (shard->totpoly != 0);
 }
 
-#if 0
 /* note, results won't be correct if polygon is non-planar */
 /* copied from mesh_evaluate.c */
 static float mesh_calc_poly_planar_area_centroid(
@@ -358,7 +357,7 @@ static float mesh_calc_poly_planar_area_centroid(
 
 // old method, keep for now in case new has different results
 /* modified from BKE_mesh_center_centroid */
-bool BKE_fracture_shard_center_centroid(Shard *shard, float cent[3])
+bool BKE_fracture_shard_center_centroid_area(Shard *shard, float cent[3])
 {
        int i = shard->totpoly;
        MPoly *mpoly;
@@ -390,7 +389,6 @@ bool BKE_fracture_shard_center_centroid(Shard *shard, float 
cent[3])
 
        return (shard->totpoly != 0);
 }
-#endif
 
 void BKE_shard_free(Shard *s, bool doCustomData)
 {
diff --git a/source/blender/blenkernel/intern/rigidbody.c 
b/source/blender/blenkernel/intern/rigidbody.c
index 3d5ec92bec5..c91cae77d8d 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2573,11 +2573,13 @@ void BKE_rigidbody_calc_threshold(float max_con_mass, 
FractureModifierData *rmd,
 
 static int DM_mesh_minmax(DerivedMesh *dm, float r_min[3], float r_max[3])
 {
-       MVert *v;
-       int i = 0;
-       for (i = 0; i < dm->numVertData; i++) {
-               v = CDDM_get_vert(dm, i);
-               minmax_v3v3_v3(r_min, r_max, v->co);
+       MVert *mvert;
+       int i = 0, totvert;
+
+       mvert = dm->getVertArray(dm);
+       totvert = dm->getNumVerts(dm);
+       for (i = 0; i < totvert; i++) {
+               minmax_v3v3_v3(r_min, r_max, mvert[i].co);
        }
 
        return (dm->numVertData != 0);
@@ -2609,16 +2611,19 @@ static float box_volume(float size[3])
        float volume = 0.0001f;
 
        volume = size[0] * size[1] * size[2];
-       if (size[0] == 0) {
+       if (size[0] < 0.000001f) {
                volume = size[1] * size[2];
        }
-       else if (size[1] == 0) {
+       else if (size[1] < 0.000001f) {
                volume = size[0] * size[2];
        }
-       else if (size[2] == 0) {
+       else if (size[2] < 0.000001f) {
                volume = size[0] * size[1];
        }
 
+       if (volume == 0.0f)
+               volume = 0.0001f;
+
        return volume;
 }
 
@@ -2704,8 +2709,11 @@ float BKE_rigidbody_calc_volume(DerivedMesh *dm, 
RigidBodyOb *rbo, Object* ob)
 
                                BKE_mesh_calc_volume(mvert, totvert, mlooptri, 
tottri, mloop, &volume, NULL);
 
-                               if (volume == 0.0f)
-                                       volume = 0.00001f;
+                               if (volume < 0.000001f)
+                               {
+                                       //fallback to boxvolume in case we get 
crap here
+                                       volume = box_volume(size);
+                               }
                        }
                        break;
                }
diff --git a/source/blender/modifiers/intern/MOD_fracture.c 
b/source/blender/modifiers/intern/MOD_fracture.c
index 65737110b3a..12be142b9ce 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -4288,7 +4288,7 @@ static void do_reset_automerge(FractureModifierData* fmd)
                RigidBodyWorld *rbw = sc->rigidbody_world;
                int frame = (int)BKE_scene_frame_get(sc);
                int start = (rbw && rbw->pointcache ) ? 
MAX2(rbw->pointcache->startframe, sc->r.sfra) : sc->r.sfra;
-               if (frame == start) {
+               if (frame == start || frame > fmd->last_frame + 1 || frame < 
fmd->last_frame - 1) {
                        reset_automerge(fmd);
                }
        }
@@ -4946,11 +4946,17 @@ static DerivedMesh *applyModifier(ModifierData *md, 
Object *ob,
        if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
        {
                bool init = false;
+
+               //just track the frames for resetting automerge data when 
jumping
+               int frame = (int)BKE_scene_frame_get(fmd->modifier.scene);
+
                //deactivate multiple settings for now, not working properly 
XXX TODO (also deactivated in RNA and python)
                final_dm = do_prefractured(fmd, ob, pack_dm);
 
                if (init)
                        fmd->shard_count = 10;
+
+               fmd->last_frame = frame;
        }
        else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
        {

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

Reply via email to