Commit: 3c545143544f6fd8429926ca364732009fb99552
Author: Martin Felke
Date:   Mon Nov 2 14:12:15 2015 +0100
Branches: fracture_modifier
https://developer.blender.org/rB3c545143544f6fd8429926ca364732009fb99552

dynamic fracture should be bake and saveable now, but still has rotation 
glitches and glitches with change in mesh island sequence.

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

M       source/blender/blenkernel/BKE_rigidbody.h
M       source/blender/blenkernel/intern/fracture.c
M       source/blender/blenkernel/intern/pointcache.c
M       source/blender/blenkernel/intern/rigidbody.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c
M       source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/source/blender/blenkernel/BKE_rigidbody.h 
b/source/blender/blenkernel/BKE_rigidbody.h
index 6fe4de1..13aec5e 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -100,6 +100,7 @@ float BKE_rigidbody_calc_min_con_dist(struct Object* ob);
 void BKE_rigidbody_start_dist_angle(struct RigidBodyShardCon* con);
 void BKE_rigidbody_remove_shard_con(struct Scene* scene, struct 
RigidBodyShardCon* con);
 void BKE_rigidbody_remove_shard(struct Scene* scene, struct MeshIsland *mi);
+void BKE_rigidbody_update_ob_array(struct RigidBodyWorld *rbw);
 /* -------------- */
 /* Utility Macros */
 
diff --git a/source/blender/blenkernel/intern/fracture.c 
b/source/blender/blenkernel/intern/fracture.c
index 41389d5..f0fe7ab 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1855,7 +1855,7 @@ bool BKE_lookup_mesh_state(FractureModifierData *fmd, int 
frame, int do_lookup)
                                   (fmd->current_mi_entry->next->is_new == 
false) &&
                                   frame > fmd->current_mi_entry->frame)
                        {
-                               printf("Jumping forward because %d is 
greater/equal than %d\n", frame, fmd->current_mi_entry->frame);
+                               printf("Jumping forward because %d is greater 
than %d\n", frame, fmd->current_mi_entry->frame);
                                changed = true;
                                BKE_free_constraints(fmd);
                                BKE_get_next_entries(fmd);
diff --git a/source/blender/blenkernel/intern/pointcache.c 
b/source/blender/blenkernel/intern/pointcache.c
index c0bc065..1e1b518 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -72,6 +72,7 @@
 #include "BKE_smoke.h"
 #include "BKE_softbody.h"
 #include "BKE_rigidbody.h"
+#include "BKE_fracture.h"
 
 #include "BIK_api.h"
 
@@ -1095,10 +1096,15 @@ static void ptcache_rigidbody_read(int index, void 
*rb_v, void **data, float cfr
                        //TODO, need to speed this up.... array, hash ?
 
                        //modifier should have "switched" this to current set 
of meshislands already.... so access it
-                       MeshIsland *mi = BLI_findlink(&fmd->meshIslands, 
rbo->meshisland_index);
+                       MeshIsland *mi = NULL;
                        int frame = (int)floor(cfra);
+
+                       mi = BLI_findlink(&fmd->meshIslands, 
rbo->meshisland_index);
                        frame = frame - mi->start_frame;
 
+                       if (frame < 0)
+                               frame = 0; //grrr, why does this happen ?!
+
                        //printf("Reading frame %d %d %d %d\n", (int)cfra, 
mi->start_frame, frame, fmd->last_frame);
 
                        rbo->pos[0] = mi->locs[3*frame];
diff --git a/source/blender/blenkernel/intern/rigidbody.c 
b/source/blender/blenkernel/intern/rigidbody.c
index 53b843b..f13ef0f 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -75,6 +75,7 @@
 
 #ifdef WITH_BULLET
 
+static void resetDynamic(RigidBodyWorld *rbw);
 static void validateShard(RigidBodyWorld *rbw, MeshIsland *mi, Object *ob, int 
rebuild, int transfer_speed);
 
 static void activateRigidbody(RigidBodyOb* rbo, RigidBodyWorld *UNUSED(rbw), 
MeshIsland *UNUSED(mi), Object *UNUSED(ob))
@@ -2640,7 +2641,7 @@ static int rigidbody_group_count_items(const ListBase 
*group, int *r_num_objects
 /* Simulation Interface - Bullet */
 
 /* Update object array and rigid body count so they're in sync with the rigid 
body group */
-static void rigidbody_update_ob_array(RigidBodyWorld *rbw)
+void BKE_rigidbody_update_ob_array(RigidBodyWorld *rbw)
 {
        GroupObject *go;
        ModifierData *md;
@@ -2724,7 +2725,9 @@ static void rigidbody_update_sim_world(Scene *scene, 
RigidBodyWorld *rbw)
 
        /* update object array in case there are changes */
        if (!(rbw->flag & RBW_FLAG_REFRESH_MODIFIERS))
-               rigidbody_update_ob_array(rbw);
+       {
+               BKE_rigidbody_update_ob_array(rbw);
+       }
 }
 
 static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object 
*ob, RigidBodyOb *rbo, float centroid[3], MeshIsland *mi)
@@ -3047,7 +3050,7 @@ static bool do_update_modifier(Scene* scene, Object* ob, 
RigidBodyWorld *rbw, bo
                        int frame = (int)BKE_scene_frame_get(scene);
                        if (BKE_lookup_mesh_state(fmd, frame, true))
                        {
-                               rigidbody_update_ob_array(rbw);
+                               BKE_rigidbody_update_ob_array(rbw);
                        }
                }
 
@@ -3378,16 +3381,19 @@ static bool do_sync_modifier(ModifierData *md, Object 
*ob, RigidBodyWorld *rbw,
                                }
                        }
 
-                       if (!is_zero_m4(fmd->origmat) && rbw && !(rbw->flag & 
RBW_FLAG_OBJECT_CHANGED)) {
+                       if (!is_zero_m4(fmd->origmat) && rbw && !(rbw->flag & 
RBW_FLAG_OBJECT_CHANGED))
+                       {
+                               //if (fmd->fracture_mode == 
MOD_FRACTURE_PREFRACTURED)
                                copy_m4_m4(ob->obmat, fmd->origmat);
                        }
 
                        if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
                        {
                                int frame = (int)ctime;
+
                                if (BKE_lookup_mesh_state(fmd, frame, true))
                                {
-                                       rigidbody_update_ob_array(rbw);
+                                       BKE_rigidbody_update_ob_array(rbw);
                                }
                        }
 
@@ -3577,11 +3583,32 @@ static bool restoreKinematic(RigidBodyWorld *rbw)
        return did_it;
 }
 
+static void resetDynamic(RigidBodyWorld *rbw)
+{
+       GroupObject *go;
+       for (go = rbw->group->gobject.first; go; go = go->next)
+       {
+               FractureModifierData *fmd = modifiers_findByType(go->ob, 
eModifierType_Fracture);
+               if (fmd && fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
+               {
+                       Scene *scene = fmd->modifier.scene;
+                       fmd->last_frame = INT_MAX;
+                       fmd->refresh = true;
+
+                       //need really to trigger modifier stack evaluation here 
at once, next depgraph tag is too late
+                       //apparently
+                       makeDerivedMesh(scene, go->ob, NULL, 
scene->customdata_mask | CD_MASK_BAREMESH, 0);
+               }
+       }
+}
+
 void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw)
 {
        if (rbw) {
                rbw->pointcache->flag |= PTCACHE_OUTDATED;
                //restoreKinematic(rbw);
+               if (!(rbw->pointcache->flag & PTCACHE_BAKED))
+                       resetDynamic(rbw);
        }
 }
 
@@ -3615,6 +3642,10 @@ void BKE_rigidbody_rebuild_world(Scene *scene, float 
ctime)
 
        if (ctime == startframe + 1 && rbw->ltime == startframe) {
                if (cache->flag & PTCACHE_OUTDATED) {
+                       //if we destroy the cache, also reset dynamic data (if 
not baked)
+                       if (!(cache->flag & PTCACHE_BAKED))
+                               resetDynamic(rbw);
+
                        BKE_ptcache_id_reset(scene, &pid, 
PTCACHE_RESET_OUTDATED);
                        rigidbody_update_simulation(scene, rbw, true);
                        BKE_ptcache_validate(cache, (int)ctime);
@@ -3641,7 +3672,9 @@ void BKE_rigidbody_do_simulation(Scene *scene, float 
ctime)
        if ((rbw->flag & RBW_FLAG_OBJECT_CHANGED))
        {
                rbw->flag &= ~RBW_FLAG_OBJECT_CHANGED;
-               rigidbody_update_simulation(scene, rbw, true);
+               if (!(cache->flag & PTCACHE_BAKED))
+                       /* dont mess with baked data */
+                       rigidbody_update_simulation(scene, rbw, true);
                rbw->flag &= ~RBW_FLAG_REFRESH_MODIFIERS;
        }
 
@@ -3667,7 +3700,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float 
ctime)
        if (rbw->physics_world == NULL && !(cache->flag & PTCACHE_BAKED))
                return;
        else if ((rbw->objects == NULL) || (rbw->cache_index_map == NULL))
-               rigidbody_update_ob_array(rbw);
+               BKE_rigidbody_update_ob_array(rbw);
 
        /* try to read from cache */
        // RB_TODO deal with interpolated, old and baked results
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 45d087e..773e7382 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4871,9 +4871,13 @@ static int initialize_meshisland(FractureModifierData* 
fmd, MeshIsland** mii, MV
                if (mi->vertex_indices) {
                        mi->vertex_indices[k] = vertstart + k;
                }
-               mi->vertco[k*3] = v->co[0];
-               mi->vertco[k*3+1] = v->co[1];
-               mi->vertco[k*3+2] = v->co[2];
+
+               if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
+               {
+                       mi->vertco[k*3] = v->co[0];
+                       mi->vertco[k*3+1] = v->co[1];
+                       mi->vertco[k*3+2] = v->co[2];
+               }
 
                if (mi->vertno != NULL && fmd->fix_normals) {
                        short sno[3];
@@ -4885,6 +4889,7 @@ static int initialize_meshisland(FractureModifierData* 
fmd, MeshIsland** mii, MV
                }
        }
 
+#if 0
        if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
        {
                MeshIslandSequence *prev = NULL;
@@ -4915,6 +4920,7 @@ static int initialize_meshisland(FractureModifierData* 
fmd, MeshIsland** mii, MV
                        }
                }
        }
+#endif
 
        return mi->vertex_count;
 }
@@ -4934,7 +4940,7 @@ static void load_fracture_modifier(FileData* fd, 
FractureModifierData *fmd, Obje
        fmd->vertex_island_map = NULL;
 
        /*HARDCODING this for now, until we can version it properly, say with 
2.75 ? */
-       if (fd->fileversion < 276) {
+       if (fd->fileversion < 275) {
                fmd->fracture_mode = MOD_FRACTURE_PREFRACTURED;
                fmd->shard_sequence.first = NULL;
                fmd->shard_sequence.last = NULL;
@@ -4944,6 +4950,9 @@ static void load_fracture_modifier(FileData* fd, 
FractureModifierData *fmd, Obje
                fmd->fracture_settings.first = NULL;
                fmd->fracture_settings.last = NULL;
                fmd->active_setting = -1;
+
+               fmd->current_mi_entry = NULL;
+               fmd->current_shard_entry = NULL;
        }
        else
        {
@@ -5028,7 +5037,6 @@ static void load_fracture_modifier(FileData* fd, 
FractureModifierData *fmd, Obje
                                vertstart += initialize_meshisland(fmd, &mi, 
mverts, vertstart, ob, -1, -1);
                        }
                }
-#if 0
                else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
                {
                        ShardSequence *ssq = NULL;
@@ -5097,7 +5105,6 @@ static void load_fracture_modifier(FileData* fd, 
FractureModifierData *fmd, Obje
                                fmd->current_mi_entry = msq;
                        }
                }
-#endif
 
                fmd->refresh_constraints = true;
                fmd->meshConstraints.first = NULL;
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index 9b7dcca..31629a7 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1721,7 +1721,6 @@ static void write_modifiers(WriteData *wd, ListBase 
*modbase)
                                        }
                                }
                        }
-#if 0
                        else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
                        {
                                ShardSequence *ssq;
@@ -1744,7 +1743,6 @@ static void write_modifiers(WriteData *wd, ListBase 
*modbase)
                                        }
                                }
                        }
-#endif
                }
        }
 }
diff --git a/source/blender/modifiers/intern/MOD_fracture.c 
b/source/blender/modifiers/intern/MOD_fracture.c
index d2541f7..23f697f 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -2914,7 +2914,6 @@ static void do_island_from_shard(FractureModifierData 
*fmd, 

@@ 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