Commit: 07ce06d2124120e04038d67b9d40014c230db0e3
Author: Martin Felke
Date:   Thu May 21 12:02:33 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rB07ce06d2124120e04038d67b9d40014c230db0e3

dynamic fracture: fix for loss of rotation, and transferring speeds of parent 
shards to children now

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

M       intern/rigidbody/RBI_api.h
M       intern/rigidbody/rb_bullet_api.cpp
M       source/blender/blenkernel/intern/rigidbody.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 1ee95a1..68a3d0d 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -224,6 +224,9 @@ void RB_body_get_orientation(rbRigidBody *body, float 
v_out[4]);
 
 void RB_body_apply_central_force(rbRigidBody *body, const float v_in[3]);
 
+void RB_body_apply_impulse(rbRigidBody* object, const float impulse[3], const 
float pos[3]);
+void RB_body_apply_force(rbRigidBody* object, const float force[3], const 
float pos[3]);
+
 /* ********************************** */
 /* Collision Shape Methods */
 
diff --git a/intern/rigidbody/rb_bullet_api.cpp 
b/intern/rigidbody/rb_bullet_api.cpp
index 5ce75e7..f372a20 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -893,6 +893,20 @@ void RB_body_apply_central_force(rbRigidBody *object, 
const float v_in[3])
        body->applyCentralForce(btVector3(v_in[0], v_in[1], v_in[2]));
 }
 
+void RB_body_apply_impulse(rbRigidBody* object, const float impulse[3], const 
float pos[3])
+{
+       btRigidBody *body = object->body;
+
+       body->applyImpulse(btVector3(impulse[0], impulse[1], impulse[2]), 
btVector3(pos[0], pos[1], pos[2]));
+}
+
+void RB_body_apply_force(rbRigidBody* object, const float force[3], const 
float pos[3])
+{
+       btRigidBody *body = object->body;
+
+       body->applyForce(btVector3(force[0], force[1], force[2]), 
btVector3(pos[0], pos[1], pos[2]));
+}
+
 /* ********************************** */
 /* Collision Shape Methods */
 
diff --git a/source/blender/blenkernel/intern/rigidbody.c 
b/source/blender/blenkernel/intern/rigidbody.c
index 1a45e17..f2ba8d5 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1145,6 +1145,31 @@ 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
@@ -1212,8 +1237,12 @@ void BKE_rigidbody_validate_sim_shard(RigidBodyWorld 
*rbw, MeshIsland *mi, Objec
        }
 
        if (rbw && rbw->physics_world && rbo->physics_object)
+       {
                RB_dworld_add_body(rbw->physics_world, rbo->physics_object, 
rbo->col_groups, mi, ob, mi->linear_index);
 
+               apply_movement_update(rbo, mi);
+       }
+
        rbo->flag &= ~RBO_FLAG_NEEDS_VALIDATE;
        rbo->flag &= ~RBO_FLAG_KINEMATIC_REBUILD;
 }
@@ -1863,6 +1892,32 @@ static bool check_shard_size(FractureModifierData *fmd, 
int id)
        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;
@@ -1904,6 +1959,7 @@ static void check_fracture(rbContactPoint* cp, 
RigidBodyWorld *rbw)
                                                
BLI_addtail(&fmd1->fracture_ids, fid1);
                                                //fmd1->refresh = true;
                                                rbw->refresh_modifiers = true;
+                                               update_movement(fmd1, 
linear_index1, force, cp->contact_pos_world_onA, cp->contact_pos_world_onB);
                                        }
                                }
                        }
@@ -1928,6 +1984,7 @@ static void check_fracture(rbContactPoint* cp, 
RigidBodyWorld *rbw)
                                                
BLI_addtail(&fmd2->fracture_ids, fid2);
                                                //fmd2->refresh = true;
                                                rbw->refresh_modifiers = true;
+                                               update_movement(fmd2, id, 
force, cp->contact_pos_world_onB, cp->contact_pos_world_onA);
                                        }
                                }
                        }
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index b32d186..f574742 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4872,7 +4872,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 ? */
-       fmd->fracture_mode = MOD_FRACTURE_PREFRACTURED;
+       //fmd->fracture_mode = MOD_FRACTURE_PREFRACTURED;
 
        if (fm == NULL || fmd->dm_group) {
                fmd->dm = NULL;
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index f9b8e6d..e6ecb5b 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1388,9 +1388,11 @@ typedef struct MeshIsland {
        float centroid[3], start_co[3];
        float rot[4]; /*hrm, need this for constraints probably */
        float thresh_weight, ground_weight;
+       float impulse[3], impulse_loc[3];
+       float lin_vel[3], ang_vel[3];
        int linear_index;  /* index in rigidbody world */
        int particle_index;
-       //char pad[4];
+       //char pad[2];
 } MeshIsland;
 
 
diff --git a/source/blender/modifiers/intern/MOD_fracture.c 
b/source/blender/modifiers/intern/MOD_fracture.c
index 1a46956..6925a5b 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -2810,14 +2810,15 @@ static void do_match_vertex_coords(MeshIsland* mi, 
MeshIsland *par, Object *ob,
 
        mul_m4_v3(ob->imat, loc);
        mat4_to_quat(irot, ob->imat);
-
+       //mul_qt_qtqt(rot, irot, rot);
 #if 0
        OUT("mi->centroid",mi->id, mi->centroid);
        OUT("par->centroid",par->id,  par->centroid);
        OUT("centr", par->id, centr);
        OUT("loc", par->id, loc);
-       OUT4("rot", par->id, rot);
 #endif
+       OUT4("rot", par->id, rot);
+       OUT4("par->rot", par->id, par->rot);
 
        if (is_parent)
        {
@@ -2830,6 +2831,8 @@ static void do_match_vertex_coords(MeshIsland* mi, 
MeshIsland *par, Object *ob,
                copy_v3_v3(centr, loc);
        }
 
+       mul_qt_qtqt(rot, par->rot, rot);
+
        for (j = 0; j < mi->vertex_count; j++)
        {
                float co[3];
@@ -2857,7 +2860,6 @@ static void do_match_vertex_coords(MeshIsland* mi, 
MeshIsland *par, Object *ob,
        //init rigidbody properly ?
        copy_v3_v3(mi->centroid, centr);
        copy_qt_qt(mi->rot, rot);
-       mul_qt_qtqt(rot, irot, rot);
 }
 
 static void do_handle_parent_mi(FractureModifierData *fmd, MeshIsland *mi, 
MeshIsland *par, Object* ob, int frame, bool is_parent)
@@ -2865,9 +2867,20 @@ static void do_handle_parent_mi(FractureModifierData 
*fmd, MeshIsland *mi, MeshI
        frame -= par->start_frame;
        do_match_vertex_coords(mi, par, ob, frame, is_parent);
 
+       if (par->rigidbody->physics_object)
+       {
+               RB_body_get_linear_velocity(par->rigidbody->physics_object, 
par->lin_vel);
+               RB_body_get_angular_velocity(par->rigidbody->physics_object, 
par->ang_vel);
+       }
+
        BKE_rigidbody_remove_shard(fmd->modifier.scene, par);
        fmd->modifier.scene->rigidbody_world->object_changed = true;
        par->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
+
+       copy_v3_v3(mi->lin_vel, par->lin_vel);
+       copy_v3_v3(mi->ang_vel, par->ang_vel);
+       copy_v3_v3(mi->impulse, par->impulse);
+       copy_v3_v3(mi->impulse_loc, par->impulse_loc);
 }
 
 static MeshIsland* find_meshisland(ListBase* meshIslands, int id)
@@ -2955,14 +2968,17 @@ static void do_island_from_shard(FractureModifierData 
*fmd, Object *ob, Shard* s
                MeshIslandSequence *prev = NULL;
 
                /*also take over the UNFRACTURED last shards transformation !!! 
*/
-               mi->locs[0] = mi->centroid[0];
-               mi->locs[1] = mi->centroid[1];
-               mi->locs[2] = mi->centroid[2];
-
-               mi->rots[0] = mi->rot[0];
-               mi->rots[1] = mi->rot[1];
-               mi->rots[2] = mi->rot[2];
-               mi->rots[3] = mi->rot[3];
+               if (s->parent_id == 0)
+               {
+                       mi->locs[0] = mi->centroid[0];
+                       mi->locs[1] = mi->centroid[1];
+                       mi->locs[2] = mi->centroid[2];
+
+                       mi->rots[0] = mi->rot[0];
+                       mi->rots[1] = mi->rot[1];
+                       mi->rots[2] = mi->rot[2];
+                       mi->rots[3] = mi->rot[3];
+               }
 
                if (fmd->current_mi_entry) {
                        prev = fmd->current_mi_entry->prev;

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

Reply via email to