Commit: e90424544aecf7d009a17576a1be26d2903ac412
Author: Martin Felke
Date:   Sat Dec 8 20:13:10 2018 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rBe90424544aecf7d009a17576a1be26d2903ac412

added new cluster trigger propagation feature and a couple of fixes

fixes for example for split to island crashs

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

M       source/blender/blenkernel/BKE_fracture.h
M       source/blender/blenkernel/intern/fracture.c
M       source/blender/blenkernel/intern/fracture_prefractured.c
M       source/blender/blenkernel/intern/fracture_rigidbody.c
M       source/blender/depsgraph/intern/builder/deg_builder_relations.cc

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

diff --git a/source/blender/blenkernel/BKE_fracture.h 
b/source/blender/blenkernel/BKE_fracture.h
index 5d793f25753..f6ebc0a4540 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -171,12 +171,13 @@ void BKE_fracture_meshisland_vertexgroups_do(struct 
FractureModifierData *fmd, s
 void BKE_fracture_meshislands_pack(struct FractureModifierData *fmd, struct 
Object* obj, struct Main* bmain, struct Scene* scene);
 
 void BKE_fracture_postprocess_meshisland(struct FractureModifierData *fmd, 
struct Object* ob, struct Shard* mi,
-                                         struct Mesh** temp_meshs, int count, 
struct Scene* scene, int frame, struct Shard **shards);
+                                         struct Mesh ***temp_meshs, int count, 
struct Scene* scene, int frame,
+                                         struct Shard **shards);
 
 void BKE_fracture_meshisland_normals_fix(struct FractureModifierData *fmd, 
struct Shard* mi, struct Mesh* orig_me);
 
-void BKE_fracture_copy_customdata(struct CustomData* src, struct CustomData* 
dst, CustomDataMask mask, int src_ofs, int dst_ofs,
-                              int copyelem, int totelem);
+void BKE_fracture_copy_customdata(struct CustomData* src, struct CustomData* 
dst, CustomDataMask mask, int src_ofs,
+                                  int dst_ofs, int copyelem, int totelem);
 
 bool BKE_fracture_check_valid_shard(struct FractureModifierData *fmd, struct 
Shard *mi, struct Scene *scene);
 void BKE_fracture_duplis_to_shards(struct FractureModifierData *fmd, struct 
Object *ob, struct Scene *scene,
diff --git a/source/blender/blenkernel/intern/fracture.c 
b/source/blender/blenkernel/intern/fracture.c
index 5d3792ab11d..3a4223d0c49 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -214,8 +214,9 @@ bool BKE_fracture_mesh_center_centroid_area(Mesh *shard, 
float cent[3])
 
 static void init_random(FractureModifierData *fmd) {
        /* Random generator, only init once. */
-       uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
-       rng_seed ^= POINTER_AS_UINT(fmd);
+       //uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
+       //rng_seed ^= POINTER_AS_UINT(fmd);
+       uint rng_seed = (unsigned int)fmd->point_seed;
        fmd->shared->rng = BLI_rng_new(rng_seed);
 }
 
@@ -541,7 +542,7 @@ static void process_cells(FractureModifierData* fmd, Shard* 
mii, Object* ob, Sce
                }
        }
 
-       BKE_fracture_postprocess_meshisland(fmd, ob, mii, temp_meshs, count, 
scene, frame, islands);
+       BKE_fracture_postprocess_meshisland(fmd, ob, mii, &temp_meshs, count, 
scene, frame, islands);
 
        BLI_kdtree_balance(tree);
 
@@ -876,25 +877,34 @@ static void intersect_mesh_by_mesh(FractureModifierData* 
fmd, Object* ob, Mesh*
        }
 }
 
-void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* 
ob, Shard* mi, Mesh** temp_meshs, int count,
+void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* 
ob, Shard* mi, Mesh*** temp_meshs, int count,
                                                                                
 Scene* scene, int frame, Shard** shards)
 {
        int count_new = count+1;
-       int j = 1, i = 0;
+       int j = 1, i = 0, k = 0;
        float size[3];
+       bool* deletemap = MEM_callocN(sizeof(bool) * count_new, "deletemap");
        mat4_to_size(size, ob->obmat);
 
        if (fmd->flag & MOD_FRACTURE_USE_SPLIT_TO_ISLANDS)
        {
                for (i = 0; i < count+1; i++)
                {
-                       if (temp_meshs[i]) {
+                       if ((*temp_meshs)[i] && !deletemap[i]) {
                                int oldcount = count_new;
                                double start = PIL_check_seconds_timer();
 
-                               BKE_fracture_split_islands(fmd, ob, 
temp_meshs[i], &temp_meshs, &count_new );
-                               BKE_fracture_mesh_free(temp_meshs[i]);
-                               temp_meshs[i] = NULL;
+                               BKE_fracture_split_islands(fmd, ob, 
(*temp_meshs)[i], temp_meshs, &count_new );
+                               //BKE_fracture_mesh_free((*temp_meshs)[i]);
+                               //(*temp_meshs)[i] = NULL;
+                               deletemap[i] = true;
+
+                               //expand deletemap, too since the tempmesh 
array grows and deletemap[i] might point "somewhere" then
+                               //giving garbage values
+                               deletemap = MEM_reallocN(deletemap, 
sizeof(bool) * count_new);
+                               for (k = oldcount; k < count_new; k++) {
+                                       deletemap[k] = false;
+                               }
 
                                if ((i < count) && shards && shards[i]) {
                                        //flag as being freed, set null here ! 
so no other free attempt happens
@@ -908,12 +918,12 @@ void 
BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob,
 
        for (i = 0; i < count_new; i++)
        {
-               if (temp_meshs[i])
+               if ((*temp_meshs)[i] && !deletemap[i])
                {
-                       if (temp_meshs[i]->totvert > 0)
+                       if (((*temp_meshs)[i]->totvert > 0))
                        {       /* skip invalid cells, e.g. those which are 
eliminated by bisect */
                                float loc[3], rot[4], qrot[4], centr[3];
-                               Shard *result = 
BKE_fracture_mesh_island_create(temp_meshs[i], scene, ob, frame);
+                               Shard *result = 
BKE_fracture_mesh_island_create((*temp_meshs)[i], scene, ob, frame);
 
                                fracture_meshisland_add(fmd, result);
                                result->id = mi->id + j;
@@ -957,8 +967,7 @@ void 
BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob,
 
                                //validate already here at once... dynamic 
somehow doesnt get updated else
                                
//BKE_rigidbody_shard_validate(scene->rigidbody_world, result, ob, fmd, true,
-                               //                                              
         true, size, frame);
-
+                               //                                              
                 true, size, frame);
 
                                // try with delayed validation; next frame 
before next bullet step from rigidbody depsgraph eval thread
                                if (!(result->rigidbody->flag & 
RBO_FLAG_KINEMATIC))
@@ -976,10 +985,17 @@ void 
BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob,
                                j++;
                        }
                        else {
-                               BKE_fracture_mesh_free(temp_meshs[i]);
+                               BKE_fracture_mesh_free((*temp_meshs)[i]);
+                               (*temp_meshs)[i] = NULL;
                        }
                }
+               else if ((*temp_meshs)[i]) {
+                       BKE_fracture_mesh_free((*temp_meshs)[i]);
+                       (*temp_meshs)[i] = NULL;
+               }
        }
+
+       MEM_freeN(deletemap);
 }
 
 static Shard* fracture_cutter_process(FractureModifierData* fmd, Object *obA, 
Mesh* meA, Object* obB,
@@ -1017,7 +1033,7 @@ static Shard* 
fracture_cutter_process(FractureModifierData* fmd, Object *obA, Me
                temp_meshs[1] = NULL;
        }
 
-       BKE_fracture_postprocess_meshisland(fmd, obB, miB, temp_meshs, 2, 
scene, frame, NULL);
+       BKE_fracture_postprocess_meshisland(fmd, obB, miB, &temp_meshs, 2, 
scene, frame, NULL);
 
        MEM_freeN(temp_meshs);
 
@@ -1251,6 +1267,15 @@ void BKE_fracture_clear_cache(FractureModifierData* fmd, 
Scene *scene)
        Shard *mi, *next;
        bool dynamic = false;
 
+       if (fmd->flag & MOD_FRACTURE_USE_DUPLI)
+       {
+               BKE_fracture_meshislands_free(fmd, scene);
+               if (fmd->shared->dupli_shard_map) {
+                       BLI_ghash_free(fmd->shared->dupli_shard_map, NULL, 
NULL);
+                               fmd->shared->dupli_shard_map = NULL;
+               }
+       }
+
        BLI_listbase_clear(&fmd->shared->dynamic_fracture_queue);
 
        if (rbw && rbw->shared) {
@@ -3356,8 +3381,11 @@ void 
BKE_fracture_external_constraints_setup(FractureModifierData *fmd, Scene *s
                                mi->rigidbody->flag |= RBO_FLAG_IS_GHOST;
                        }
 
-                       ob->rigidbody_object->flag |= RBO_FLAG_KINEMATIC;
-                       ob->rigidbody_object->flag |= RBO_FLAG_IS_GHOST;
+                       if (ob->rigidbody_object)
+                       {
+                               ob->rigidbody_object->flag |= 
RBO_FLAG_KINEMATIC;
+                               ob->rigidbody_object->flag |= RBO_FLAG_IS_GHOST;
+                       }
                }
 
                if (pfmd && pob) {
diff --git a/source/blender/blenkernel/intern/fracture_prefractured.c 
b/source/blender/blenkernel/intern/fracture_prefractured.c
index b828e171cbc..dc9890ddac6 100644
--- a/source/blender/blenkernel/intern/fracture_prefractured.c
+++ b/source/blender/blenkernel/intern/fracture_prefractured.c
@@ -80,7 +80,7 @@ Shard *BKE_fracture_mesh_island_create(Mesh* me, Scene 
*scene, Object *ob, int f
        }
 
        mi->rigidbody = BKE_rigidbody_create_shard(ob, NULL, mi, scene);
-       mi->rigidbody->type = RBO_TYPE_ACTIVE;
+       mi->rigidbody->type = ob->rigidbody_object->type; //RBO_TYPE_ACTIVE;
        mi->rigidbody->flag = ob->rigidbody_object->flag;
        mi->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
        mi->rigidbody->flag |= RBO_FLAG_NEEDS_RESHAPE;
diff --git a/source/blender/blenkernel/intern/fracture_rigidbody.c 
b/source/blender/blenkernel/intern/fracture_rigidbody.c
index f22b113c75b..6ecd0808e38 100644
--- a/source/blender/blenkernel/intern/fracture_rigidbody.c
+++ b/source/blender/blenkernel/intern/fracture_rigidbody.c
@@ -74,6 +74,8 @@
 static void check_fracture(rbContactPoint *cp, Scene *scene);
 static void test_deactivate_rigidbody(RigidBodyOb *rbo, Shard *mi);
 static float box_volume(float size[3]);
+bool check_cluster_propagate(FractureModifierData *fmd1, FractureModifierData 
*fmd2,
+                             Object *ob1, Object* ob2, Shard *mi1, Shard *mi2);
 
 
 void BKE_rigidbody_activate(RigidBodyOb* rbo, RigidBodyWorld *UNUSED(rbw), 
Shard *mi, Object *ob)
@@ -799,7 +801,7 @@ static void 
rigidbody_create_shard_physics_constraint(FractureModifierData* fmd,
        rbRigidBody *rb1;
        rbRigidBody *rb2;
 
-       if (rbc && rbc->mi1 && rbc->mi2)
+       if (rbc && rbc->mi1 && rbc->mi2 && rbc->mi1->rigidbody && 
rbc->mi2->rigidbody)
        {
                rb1 = rbc->mi1->rigidbody->shared->physics_object;
                rb2 = rbc->mi2->rigidbody->shared->physics_object;
@@ -1033,19 +1035,22 @@ static bool colgroup_check(int group1, int group2)
 
 static bool do_activate(Object* ob, Object *ob2, Shard *mi_compare, 
RigidBodyWorld *rbw, Shard *mi_trigger, bool activate)
 {
-       FractureModifierData *fmd;
+       FractureModifierData *fmd, *fmd2;
        bool valid = true;
        bool antiValid = ob2->rigidbody_object->flag & RBO_FLAG_ANTI_TRIGGER;
        bool wouldActivate = false;
        Shard *mi;
 
        fmd = (FractureModifierData*)modifiers_findByType(ob, 
eModifierType_Fracture);
+       fmd2 = (FractureModifierData*)modifiers_findByType(ob2, 
eModifierType_Fracture);
+
        valid = valid && (fmd != NULL);
        antiValid = antiValid && (fmd != NULL);
 
        valid = valid && (ob->rigidbody_object->flag & RBO_FLAG_IS_TRIGGERED);
-       valid = valid && ((ob2->rigidbody_object->flag & RBO_FLAG_IS_TRIGGER) 
|| ((ob2->rigidbody_object->flag & RBO_FLAG_PROPAGATE_TRIGGER) &&
-                       ((mi_trigger) && (mi_trigger->rigidbody->flag & 
RBO_FLAG_PROPAGATE_TRIGGER))));
+       valid = valid && ((ob2->rigidbody_object->flag & RBO_FLAG_IS_TRIGGER) ||
+               ((ob2->rigidbody_object->flag & RBO_FLAG_PROPAGATE_TRIGGER) &&
+               ((mi_trigger) && (mi_trigger->rigidbody->flag & R

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to