Commit: a3d433acb81baf4a6c056d6919b7622cb667572b
Author: Martin Felke
Date:   Wed Aug 8 19:54:54 2018 +0200
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rBa3d433acb81baf4a6c056d6919b7622cb667572b

split rigidbody.c to regular and fractured part

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

M       source/blender/blenkernel/BKE_rigidbody.h
M       source/blender/blenkernel/CMakeLists.txt
A       source/blender/blenkernel/intern/fracture_rigidbody.c
M       source/blender/blenkernel/intern/rigidbody.c

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

diff --git a/source/blender/blenkernel/BKE_rigidbody.h 
b/source/blender/blenkernel/BKE_rigidbody.h
index da18de93b99..f60646876cd 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -45,6 +45,9 @@ struct Group;
 struct MeshIsland;
 struct FractureModifierData;
 struct Main;
+struct rbCollisionShape;
+struct rbContactPoint;
+struct ModifierData;
 
 /* -------------- */
 /* Memory Management */
@@ -130,6 +133,36 @@ void BKE_rigidbody_cache_reset(struct RigidBodyWorld *rbw);
 void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, struct Scene 
*scene, float ctime);
 void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, struct Scene 
*scene, float ctime);
 
+
+// other misc stuff (implemented in rigidbody.c or fracture_rigidbody.c
+struct rbCollisionShape *BKE_rigidbody_get_shape_trimesh_from_mesh(struct 
Object *ob, struct MeshIsland* mi);
+struct rbCollisionShape *BKE_rigidbody_get_shape_convexhull_from_mesh(struct 
Mesh *dm, float margin, bool *can_embed);
+void BKE_rigidbody_update_sim_ob(struct Scene *scene, struct RigidBodyWorld 
*rbw, struct Object *ob,
+                                   struct RigidBodyOb *rbo, float centroid[3], 
struct MeshIsland *mi, float size[3],
+                                   struct FractureModifierData *fmd, struct 
Depsgraph *depsgraph);
+
+struct MeshIsland* BKE_rigidbody_closest_meshisland_to_point(struct 
FractureModifierData* fmd, struct Object *ob,
+                                                             struct Object 
*ob2, struct Scene* scene, struct RigidBodyCon *con);
+
+int BKE_rigidbody_filter_callback(void* world, void* island1, void* island2, 
void *blenderOb1, void* blenderOb2, bool activate);
+void BKE_rigidbody_contact_callback(struct rbContactPoint* cp, void* world);
+void BKE_rigidbody_id_callback(void *world, void* island, int* objectId, int* 
islandId);
+
+bool BKE_rigidbody_modifier_active(struct FractureModifierData *rmd);
+void BKE_rigidbody_shard_validate(struct RigidBodyWorld *rbw, struct 
MeshIsland *mi, struct Object *ob,
+                                  int rebuild, int transfer_speed, float 
size[3]);
+
+void BKE_rigidbody_activate(struct RigidBodyOb* rbo, struct RigidBodyWorld 
*rbw, struct MeshIsland *mi, struct Object *ob);
+bool BKE_rigidbody_modifier_update(struct Scene* scene, struct Object* ob, 
struct RigidBodyWorld *rbw,  bool rebuild,
+                                   struct Depsgraph *depsgraph);
+
+bool BKE_rigidbody_modifier_sync(struct ModifierData *md, struct Object *ob, 
struct Scene *scene, float ctime);
+void BKE_rigidbody_passive_hook(struct FractureModifierData *fmd, struct 
MeshIsland *mi, struct Object* ob,
+                                struct Scene* scene, struct Depsgraph 
*depsgraph);
+
+void BKE_rigidbody_passive_fake_parenting(struct FractureModifierData *fmd, 
struct Object *ob, struct RigidBodyOb *rbo,
+                                          float imat[4][4]);
+
 /* -------------------- */
 /* Depsgraph evaluation */
 
diff --git a/source/blender/blenkernel/CMakeLists.txt 
b/source/blender/blenkernel/CMakeLists.txt
index b0422aa2a86..ed2f2b0b240 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -83,7 +83,7 @@ set(SRC
        intern/blendfile.c
        intern/bmfont.c
        intern/boids.c
-        intern/boolean.c
+       intern/boolean.c
        intern/bpath.c
        intern/brush.c
        intern/bvhutils.c
@@ -117,11 +117,12 @@ set(SRC
        intern/fmodifier.c
        intern/font.c
        intern/fracture.c
-        intern/fracture_automerge.c
-        intern/fracture_constraints.c
-        intern/fracture_dynamic.c
-        intern/fracture_external.c
-        intern/fracture_prefractured.c
+       intern/fracture_automerge.c
+       intern/fracture_constraints.c
+       intern/fracture_dynamic.c
+       intern/fracture_external.c
+       intern/fracture_prefractured.c
+       intern/fracture_rigidbody.c
        intern/fracture_util.c
        intern/freestyle.c
        intern/gpencil.c
diff --git a/source/blender/blenkernel/intern/fracture_rigidbody.c 
b/source/blender/blenkernel/intern/fracture_rigidbody.c
new file mode 100644
index 00000000000..7ad5656a53f
--- /dev/null
+++ b/source/blender/blenkernel/intern/fracture_rigidbody.c
@@ -0,0 +1,2916 @@
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_kdtree.h"
+#include "BLI_math.h"
+#include "BLI_listbase.h"
+#include "BLI_threads.h"
+
+#include "DNA_defs.h"
+#include "DNA_object_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_rigidbody_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_ID.h"
+#include "DNA_fracture_types.h"
+
+#include "DEG_depsgraph.h"
+
+#ifdef WITH_BULLET
+#include "RBI_api.h"
+#endif
+
+#include "BKE_fracture.h"
+#include "BKE_rigidbody.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_runtime.h"
+#include "BKE_object.h"
+#include "BKE_modifier.h"
+#include "BKE_global.h"
+
+/*====================================================================================================================*/
+
+/* Fracture Modifier stuff */
+
+#ifdef WITH_BULLET
+
+/* Fracture Modifier related prototypes */
+
+//static void resetDynamic(RigidBodyWorld *rbw, bool do_reset_always, bool 
override_bind, struct Depsgraph *depsgraph);
+static void check_fracture(rbContactPoint *cp, RigidBodyWorld *rbw, Object 
*obA, Object *obB);
+static MeshIsland* findMeshIsland(FractureModifierData *fmd, int id);
+static void test_deactivate_rigidbody(RigidBodyOb *rbo, MeshIsland *mi);
+static float box_volume(float size[3]);
+
+
+void BKE_rigidbody_activate(RigidBodyOb* rbo, RigidBodyWorld *UNUSED(rbw), 
MeshIsland *mi, Object *ob)
+{
+       RigidBodyShardCon *con;
+       int i;
+
+       if (rbo->flag & RBO_FLAG_KINEMATIC && rbo->type == RBO_TYPE_ACTIVE)
+       {
+               rbo->flag &= ~RBO_FLAG_KINEMATIC;
+               rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
+
+               //propagate trigger on impact / activation
+               if (ob->rigidbody_object->flag & RBO_FLAG_PROPAGATE_TRIGGER) {
+                       rbo->flag |= RBO_FLAG_PROPAGATE_TRIGGER;
+               }
+
+               //RB_dworld_remove_body(rbw->physics_world, 
rbo->physics_object);
+        RB_body_set_mass(rbo->shared->physics_object, RBO_GET_MASS(rbo));
+        RB_body_set_kinematic_state(rbo->shared->physics_object, false);
+               //RB_dworld_add_body(rbw->physics_world, rbo->physics_object, 
rbo->col_groups, mi, ob);
+        RB_body_activate(rbo->shared->physics_object);
+       }
+
+       if (mi && ob->rigidbody_object->flag & RBO_FLAG_CONSTRAINT_DISSOLVE) {
+               for (i = 0; i < mi->participating_constraint_count; i++) {
+                       bool different_cluster = false;
+                       bool dissolve_plastic = (ob->rigidbody_object->flag & 
RBO_FLAG_PLASTIC_DISSOLVE);
+                       con = mi->participating_constraints[i];
+
+                       different_cluster = ((con->mi1->particle_index != 
con->mi2->particle_index) ||
+                                           ((con->mi1->particle_index == -1) 
&& (con->mi2->particle_index == -1)));
+
+                       if (con->physics_constraint && different_cluster) {
+                               if (dissolve_plastic) {
+                                       con->flag |= RBC_FLAG_PLASTIC_ACTIVE;
+                               }
+
+                               if (con->breaking_threshold >= 0)
+                               {
+                                       
RB_constraint_set_enabled(con->physics_constraint, false);
+                               }
+                       }
+               }
+       }
+}
+
+bool BKE_rigidbody_modifier_active(FractureModifierData *rmd)
+{
+       return ((rmd != NULL) && (rmd->modifier.mode & (eModifierMode_Realtime 
| eModifierMode_Render)) &&
+               (rmd->refresh == false || rmd->fracture_mode == 
MOD_FRACTURE_DYNAMIC));
+}
+
+static void calc_dist_angle(RigidBodyShardCon *con, float *dist, float *angle, 
bool exact)
+{
+       float q1[4], q2[4], qdiff[4], axis[3];
+
+       if (con == NULL || con->mi1 == NULL || con->mi2 == NULL ||
+           con->mi1->rigidbody == NULL || con->mi2->rigidbody == NULL)
+       {
+               *dist = 0;
+               *angle = 0;
+               return;
+       }
+
+       sub_v3_v3v3(axis, con->mi1->rigidbody->pos, con->mi2->rigidbody->pos);
+       *dist = len_v3(axis);
+
+       copy_qt_qt(q1, con->mi1->rigidbody->orn);
+       copy_qt_qt(q2, con->mi2->rigidbody->orn);
+
+       if (exact)
+       {
+               float iquat1[4], iquat2[4];
+               invert_qt_qt(iquat1, con->mi1->rot);
+               invert_qt_qt(iquat2, con->mi2->rot);
+               mul_qt_qtqt(q1, q1, iquat1);
+               mul_qt_qtqt(q2, q2, iquat2);
+               rotation_between_quats_to_quat(qdiff, q1, q2);
+               normalize_qt(qdiff);
+               *angle = 2.0f * saacos(qdiff[0]);
+               if (!isfinite(*angle)) {
+                       *angle = 0.0f;
+               }
+       }
+       else
+       {
+               //XXX TODO probably very wrong here
+               invert_qt(q1);
+               mul_qt_qtqt(qdiff, q1, q2);
+               quat_to_axis_angle(axis, angle, qdiff);
+       }
+}
+
+void BKE_rigidbody_start_dist_angle(RigidBodyShardCon *con, bool exact, bool 
both)
+{
+       /* store starting angle and distance per constraint*/
+       float dist, angle;
+       calc_dist_angle(con, &dist, &angle, exact);
+
+       if (both)
+       {
+               con->start_dist = dist;
+               con->start_angle = angle;
+               //printf("Start Values(dist, angle) %f %f %f %f\n", 
con->start_dist, con->start_angle, dist, angle);
+       }
+
+       con->start_dist_deform = dist;
+       con->start_angle_deform = angle;
+}
+
+float BKE_rigidbody_calc_max_con_mass(Object *ob)
+{
+       FractureModifierData *rmd;
+       ModifierData *md;
+       RigidBodyShardCon *con;
+       float max_con_mass = 0, con_mass;
+
+       for (md = ob->modifiers.first; md; md = md->next) {
+               if (md->type == eModifierType_Fracture) {
+                       rmd = (FractureModifierData *)md;
+                       for (con = rmd->meshConstraints.first; con; con = 
con->next) {
+                               if ((con->mi1 != NULL && con->mi1->rigidbody != 
NULL) &&
+                                   (con->mi2 != NULL && con->mi2->rigidbody != 
NULL)) {
+                                       con_mass = con->mi1->rigidbody->mass + 
con->mi2->rigidbody->mass;
+                                       if (con_mass > max_con_mass) {
+                                               max_con_mass = con_mass;
+                                       }
+                               }
+                       }
+
+                       return max_con_mass;
+               }
+       }
+
+       return 0;
+}
+
+float BKE_rigidbody_calc_min_con_dist(Object *ob)
+{
+       FractureModifierData *rmd;
+       ModifierData *md;
+       RigidBodyShardCon *con;
+       float min_con_dist = FLT_MAX, con_dist, con_vec[3];
+
+       for (md = ob->modifiers.first; md; md = md->next) {
+               if (md->type == eModifierType_Fracture) {
+                       rmd = (FractureModifierData *)md;
+                       for (con = rmd->meshConstraints.first; con; con = 
con->next) {
+                               if ((con->mi1 != NULL && con->mi1->rigidbody != 
NULL) &&
+                                   (con->mi2 != NULL && con->mi2->rigidbody != 
NULL)) {
+                                       sub_v3_v3v3(con_vec, 
con->mi1->centroid, con->mi2->centroid);
+                                       con_dist = len_v3(con_vec);
+                                       if (con_dist 

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