Commit: 52ef935b7d7b3898dc2d8c9d28288fec5f1a1781
Author: Martin Felke
Date:   Thu Jun 4 10:28:04 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rB52ef935b7d7b3898dc2d8c9d28288fec5f1a1781

dynamic fracture: relocated some functions and removed speed transfer from 
parent to child shards, it looked unrealistic, but TODO, animation often stops 
in case of fracture events....

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

M       source/blender/blenkernel/BKE_fracture.h
M       source/blender/blenkernel/intern/fracture.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/makesdna/DNA_modifier_types.h
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 5fdcc8c..4b4ae6a 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -41,6 +41,7 @@ struct FractureModifierData;
 struct DerivedMesh;
 struct Object;
 struct Group;
+struct MeshIsland;
 
 struct BoundBox;
 struct MVert;
@@ -90,4 +91,10 @@ void BKE_fracture_shard_by_points(struct FracMesh *fmesh, 
ShardID id, struct Fra
 void BKE_fracture_shard_by_planes(struct FractureModifierData *fmd, struct 
Object *obj, short inner_material_index, float mat[4][4]);
 void BKE_fracture_shard_by_greasepencil(struct FractureModifierData *fmd, 
struct Object *obj, short inner_material_index, float mat[4][4]);
 
+void BKE_match_vertex_coords(struct MeshIsland* mi, struct MeshIsland *par, 
struct Object *ob, int frame, bool is_parent);
+bool BKE_lookup_mesh_state(struct FractureModifierData *fmd, int frame, int 
do_lookup);
+void BKE_get_prev_entries(struct FractureModifierData *fmd);
+void BKE_get_next_entries(struct FractureModifierData *fmd);
+void BKE_free_constraints(struct FractureModifierData *fmd);
+
 #endif /* BKE_FRACTURE_H */
diff --git a/source/blender/blenkernel/intern/fracture.c 
b/source/blender/blenkernel/intern/fracture.c
index fbdd953..163f065 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -42,6 +42,7 @@
 #include "BKE_global.h"
 #include "BKE_mesh.h"
 #include "BKE_object.h"
+#include "BKE_rigidbody.h"
 
 #include "BLI_kdtree.h"
 #include "BLI_listbase.h"
@@ -52,11 +53,13 @@
 #include "BLI_sort.h"
 #include "BLI_utildefines.h"
 
+#include "DNA_scene_types.h"
 #include "DNA_fracture_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_group_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
+#include "DNA_rigidbody_types.h"
 
 #include "bmesh.h"
 
@@ -1618,3 +1621,189 @@ DerivedMesh *BKE_shard_create_dm(Shard *s, bool 
doCustomData)
 
        return dm;
 }
+
+void BKE_get_next_entries(FractureModifierData *fmd)
+{
+       /*meshislands and shards SHOULD be synchronized !!!!*/
+       if (fmd->current_mi_entry->next != NULL) { // && 
fmd->current_mi_entry->next->is_new == false) {
+
+               fmd->current_mi_entry = fmd->current_mi_entry->next;
+               fmd->current_shard_entry = fmd->current_shard_entry->next;
+
+               fmd->meshIslands = fmd->current_mi_entry->meshIslands;
+               fmd->frac_mesh = fmd->current_shard_entry->frac_mesh;
+               fmd->visible_mesh_cached = fmd->current_mi_entry->visible_dm;
+       }
+}
+
+void BKE_get_prev_entries(FractureModifierData *fmd)
+{
+       /*meshislands and shards SHOULD be synchronized !!!!*/
+       if (fmd->current_mi_entry->prev != NULL) {
+
+               fmd->current_mi_entry = fmd->current_mi_entry->prev;
+               fmd->current_shard_entry = fmd->current_shard_entry->prev;
+
+               fmd->meshIslands = fmd->current_mi_entry->meshIslands;
+               fmd->frac_mesh = fmd->current_shard_entry->frac_mesh;
+               fmd->visible_mesh_cached = fmd->current_mi_entry->visible_dm;
+       }
+}
+
+bool BKE_lookup_mesh_state(FractureModifierData *fmd, int frame, int do_lookup)
+{
+       bool changed = false;
+       bool forward = false;
+       bool backward = false;
+
+       backward = ((fmd->last_frame > frame) && fmd->current_mi_entry && 
fmd->current_mi_entry->prev);
+       forward = ((fmd->last_frame < frame) && (fmd->current_mi_entry) && 
(fmd->current_mi_entry->next != NULL) &&
+                  (fmd->current_mi_entry->next->is_new == false));
+
+       if (backward)
+       {
+               if (do_lookup)
+               {
+                       while (fmd->current_mi_entry && 
fmd->current_mi_entry->prev &&
+                                  frame <= fmd->current_mi_entry->prev->frame)
+                       {
+                               printf("Jumping backward because %d is smaller 
than %d\n", frame, fmd->current_mi_entry->prev->frame);
+                               changed = true;
+                               BKE_free_constraints(fmd);
+                               BKE_get_prev_entries(fmd);
+                       }
+               }
+       }
+       else if (forward)
+       {
+               if (do_lookup)
+               {
+                       while ((fmd->current_mi_entry) && 
(fmd->current_mi_entry->next != NULL) &&
+                                  (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);
+                               changed = true;
+                               BKE_free_constraints(fmd);
+                               BKE_get_next_entries(fmd);
+                       }
+               }
+       }
+
+       if (do_lookup)
+       {
+               return changed;
+       }
+       else
+       {
+               if (forward || backward)
+               {
+                       fmd->modifier.scene->rigidbody_world->refresh_modifiers 
= true;
+                       fmd->modifier.scene->rigidbody_world->object_changed = 
true;
+               }
+
+               return forward || backward;
+       }
+}
+
+void BKE_match_vertex_coords(MeshIsland* mi, MeshIsland *par, Object *ob, int 
frame, bool is_parent)
+{
+       float loc[3] = {0.0f, 0.0f, 0.0f};
+       float rot[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+       int j = 0;
+       //float irot[4];
+       float centr[3] = {0.0f, 0.0f, 0.0f};
+
+       invert_m4_m4(ob->imat, ob->obmat);
+
+       loc[0] = par->locs[3*frame];
+       loc[1] = par->locs[3*frame+1];
+       loc[2] = par->locs[3*frame+2];
+
+       rot[0] = par->rots[4*frame];
+       rot[1] = par->rots[4*frame+1];
+       rot[2] = par->rots[4*frame+2];
+       rot[3] = par->rots[4*frame+3];
+
+       mi->locs[0] = loc[0];
+       mi->locs[1] = loc[1];
+       mi->locs[2] = loc[2];
+
+       mi->rots[0] = rot[0];
+       mi->rots[1] = rot[1];
+       mi->rots[2] = rot[2];
+       mi->rots[3] = rot[3];
+
+       mul_m4_v3(ob->imat, loc);
+       //mat4_to_quat(irot, ob->imat);
+       //mul_qt_qtqt(rot, rot, irot);
+
+       mul_qt_qtqt(rot, rot, par->rot);
+
+       if (is_parent)
+       {
+               copy_v3_v3(centr, mi->centroid);
+               mul_qt_v3(rot, centr);
+               add_v3_v3(centr, loc);
+       }
+       else
+       {
+               copy_v3_v3(centr, loc);
+       }
+
+       for (j = 0; j < mi->vertex_count; j++)
+       {
+               float co[3];
+
+               //first add vert to centroid, then rotate
+               copy_v3_v3(co, mi->vertices_cached[j]->co);
+               sub_v3_v3(co, mi->centroid);
+               mul_qt_v3(rot, co);
+               add_v3_v3(co, centr);
+               copy_v3_v3(mi->vertices_cached[j]->co, co);
+
+               co[0] = mi->vertco[3*j];
+               co[1] = mi->vertco[3*j+1];
+               co[2] = mi->vertco[3*j+2];
+
+               sub_v3_v3(co, mi->centroid);
+               mul_qt_v3(rot, co);
+               add_v3_v3(co, centr);
+
+               mi->vertco[3*j]   = co[0];
+               mi->vertco[3*j+1] = co[1];
+               mi->vertco[3*j+2] = co[2];
+       }
+
+       //init rigidbody properly ?
+       copy_v3_v3(mi->centroid, centr);
+       copy_qt_qt(mi->rot, rot);
+}
+
+void BKE_free_constraints(FractureModifierData *fmd)
+{
+       MeshIsland *mi = NULL;
+       RigidBodyShardCon *rbsc = NULL;
+
+       for (mi = fmd->meshIslands.first; mi; mi = mi->next) {
+               if (mi->participating_constraints != NULL) {
+                       MEM_freeN(mi->participating_constraints);
+                       mi->participating_constraints = NULL;
+                       mi->participating_constraint_count = 0;
+               }
+       }
+
+       while (fmd->meshConstraints.first) {
+               rbsc = fmd->meshConstraints.first;
+               BLI_remlink(&fmd->meshConstraints, rbsc);
+               if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
+               {
+                       BKE_rigidbody_remove_shard_con(fmd->modifier.scene, 
rbsc);
+               }
+               MEM_freeN(rbsc);
+               rbsc = NULL;
+       }
+
+       fmd->meshConstraints.first = NULL;
+       fmd->meshConstraints.last = NULL;
+}
diff --git a/source/blender/blenkernel/intern/rigidbody.c 
b/source/blender/blenkernel/intern/rigidbody.c
index c6b10bd..2757a06 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1145,31 +1145,6 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland 
*mi, Object *ob, short re
                        break;
 #endif
 
-static void apply_movement_update(RigidBodyOb *rbo, MeshIsland *mi)
-{
-       if (rbo && rbo->physics_object && mi)
-       {
-               if (!is_zero_v3(mi->lin_vel))
-               {
-                       RB_body_set_linear_velocity(rbo->physics_object, 
mi->lin_vel);
-                       zero_v3(mi->lin_vel);
-               }
-
-               if (!is_zero_v3(mi->ang_vel))
-               {
-                       RB_body_set_angular_velocity(rbo->physics_object, 
mi->ang_vel);
-                       zero_v3(mi->ang_vel);
-               }
-#if 0
-               if (!is_zero_v3(mi->impulse))
-               {
-                       RB_body_apply_impulse(rbo->physics_object, mi->impulse, 
mi->impulse_loc);
-                       zero_v3(mi->impulse);
-               }
-#endif
-       }
-}
-
 /* --------------------- */
 
 /* Create physics sim representation of shard given RigidBody settings
@@ -1240,7 +1215,7 @@ void BKE_rigidbody_validate_sim_shard(RigidBodyWorld 
*rbw, MeshIsland *mi, Objec
        {
                RB_dworld_add_body(rbw->physics_world, rbo->physics_object, 
rbo->col_groups, mi, ob, mi->linear_index);
 
-               apply_movement_update(rbo, mi);
+               //apply_movement_update(rbo, mi);
        }
 
        rbo->flag &= ~RBO_FLAG_NEEDS_VALIDATE;
@@ -1899,32 +1874,6 @@ static bool check_shard_size(FractureModifierData *fmd, 
int id, float impact_loc
        return true;
 }
 
-static void update_movement(FractureModifierData *fmd, int id, float force, 
float pos1[3], float pos2[3])
-{
-       //store values for update in next frame !
-       MeshIsland *mi = NULL, *temp = fmd->meshIslands.first;
-       while (temp)
-       {
-               if (temp->id == id)
-               {
-                       mi = temp;
-                       break;
-               }
-               temp = temp->next;
-       }
-
-       if (mi != NULL)
-       {
-               float impulse[3];
-               add_v3_v3v3(impulse, pos1, pos2);
-               //mul_v3_fl(impulse, force);
-
-               // this is the OLD meshisland !!!
-               copy_v3_v3(mi->impulse, impulse);
-               copy_v3_v3(mi->impulse_loc, pos1);
-       }
-}
-
 static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
 {
        int linear_index1, linear_index2;
@@ -1970,10 +1919,7 @@ static void check_fracture(rbContactPoint* cp, 
RigidBodyWorld *rbw)
                                                FractureID* fid1 = 
MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid1");
                                                fid1->shardID = 
rbw->cache_index_map[linear_index1]->meshisland_index;
                                                
BLI_addtail(&fmd1->fracture_ids, fid1);
-                                               //fmd1->refresh = true;
-                                               //rbw->refresh_modifiers = true;
                                                fmd1->update_dynamic = true;
-                                               update_movement(fmd1, 
linear_index1, force, cp->contact_pos_world_onA, cp->contact_pos_world_onB);
                                        }
                                }
                        }
@@ -1996,10 +1942,7 @@ static void check_fracture(rbContactPoint* cp, 
RigidBodyWorld *rbw)
                                                FractureID* fid2 = 
MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid2");
                                                fid2->shardID = id;
                                                
BLI_addtail(&fmd2->fracture_ids, fid2);
-                                               //fmd2->refresh = true;
-                                               //rbw->refresh_modifiers = true;
                                                fmd2->update_dynamic = true;
-                                               update_movement(fmd2, id, 
force, cp->contact_pos_world_onB, cp->contact_pos_world_onA);
                                        }
                                }
                        }
@@ -2972,7 +2915,7 @@ static bool do_update_modifier(Scene* scene, Object* ob, 
RigidBodyWorld *rbw, bo
                if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
                {
                        int fr

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