[Bf-blender-cvs] [5c9626721ba] fracture_modifier: reordered all FM related functions to the end of file
Martin Felke
noreply at git.blender.org
Sat Aug 12 22:52:20 CEST 2017
Commit: 5c9626721ba79c7f2f6331a4245ec788042420f3
Author: Martin Felke
Date: Sat Aug 12 16:28:18 2017 +0200
Branches: fracture_modifier
https://developer.blender.org/rB5c9626721ba79c7f2f6331a4245ec788042420f3
reordered all FM related functions to the end of file
===================================================================
M source/blender/blenkernel/intern/rigidbody.c
===================================================================
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 33c0c09314a..99a60f2a6ae 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -78,5186 +78,5212 @@
#ifdef WITH_BULLET
+/* Fracture Modifier related prototypes */
+
static void resetDynamic(RigidBodyWorld *rbw, bool do_reset_always);
static void validateShard(RigidBodyWorld *rbw, MeshIsland *mi, Object *ob, int rebuild, int transfer_speed, float size[3]);
static void rigidbody_passive_fake_parenting(FractureModifierData *fmd, Object *ob, RigidBodyOb *rbo, float imat[4][4]);
static void rigidbody_passive_hook(FractureModifierData *fmd, MeshIsland *mi, Object* ob);
static void check_fracture(rbContactPoint *cp, RigidBodyWorld *rbw, Object *obA, Object *obB);
static MeshIsland* findMeshIsland(FractureModifierData *fmd, int id);
+static rbCollisionShape* rigidbody_get_shape_convexhull_from_mesh(Mesh *me, float hull_margin, bool* can_embed);
+static rbCollisionShape* rigidbody_get_shape_trimesh_from_mesh(Object* ob);
+static MeshIsland* find_closest_meshisland_to_point(FractureModifierData* fmd, Object *ob, Object *ob2, RigidBodyWorld* rbw, RigidBodyCon *con);
+static int filterCallback(void* world, void* island1, void* island2, void *blenderOb1, void* blenderOb2, bool activate);
+static void contactCallback(rbContactPoint* cp, void* world);
+static void idCallback(void *world, void* island, int* objectId, int* islandId);
+static void tickCallback(float timestep, void *scene);
+static bool isModifierActive(FractureModifierData *rmd);
+static void activateRigidbody(RigidBodyOb* rbo, RigidBodyWorld *UNUSED(rbw), MeshIsland *mi, Object *ob);
+static bool do_update_modifier(Scene* scene, Object* ob, RigidBodyWorld *rbw, bool rebuild);
+static bool do_sync_modifier(ModifierData *md, Object *ob, RigidBodyWorld *rbw, float ctime);
+static bool restoreKinematic(RigidBodyWorld *rbw);
+static void DM_mesh_boundbox(DerivedMesh *bm, float r_loc[3], float r_size[3]);
-static void activateRigidbody(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;
- }
+/* ************************************** */
+/* Memory Management */
- //RB_dworld_remove_body(rbw->physics_world, rbo->physics_object);
- RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
- RB_body_set_kinematic_state(rbo->physics_object, false);
- //RB_dworld_add_body(rbw->physics_world, rbo->physics_object, rbo->col_groups, mi, ob);
- RB_body_activate(rbo->physics_object);
- }
+/* Freeing Methods --------------------- */
- 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];
+/* Free rigidbody world */
+void BKE_rigidbody_free_world(RigidBodyWorld *rbw)
+{
+ /* sanity check */
+ if (!rbw)
+ return;
- different_cluster = ((con->mi1->particle_index != con->mi2->particle_index) ||
- ((con->mi1->particle_index == -1) && (con->mi2->particle_index == -1)));
+ if (rbw->physics_world) {
+ /* free physics references, we assume that all physics objects in will have been added to the world */
+ GroupObject *go;
+ if (rbw->constraints) {
+ for (go = rbw->constraints->gobject.first; go; go = go->next) {
+ if (go->ob && go->ob->rigidbody_constraint) {
+ RigidBodyCon *rbc = go->ob->rigidbody_constraint;
- if (con->physics_constraint && different_cluster) {
- if (dissolve_plastic) {
- con->flag |= RBC_FLAG_PLASTIC_ACTIVE;
+ if (rbc->physics_constraint)
+ RB_dworld_remove_constraint(rbw->physics_world, rbc->physics_constraint);
}
+ }
+ }
+ if (rbw->group) {
+ for (go = rbw->group->gobject.first; go; go = go->next) {
+ if (go->ob && go->ob->rigidbody_object) {
+ RigidBodyOb *rbo = go->ob->rigidbody_object;
- RB_constraint_set_enabled(con->physics_constraint, false);
+ if (rbo->physics_object)
+ RB_dworld_remove_body(rbw->physics_world, rbo->physics_object);
+ }
}
}
+ /* free dynamics world */
+ if (rbw->physics_world != NULL)
+ RB_dworld_delete(rbw->physics_world);
}
-}
+ if (rbw->objects)
+ MEM_freeN(rbw->objects);
-static bool isModifierActive(FractureModifierData *rmd) {
- return ((rmd != NULL) && (rmd->modifier.mode & (eModifierMode_Realtime | eModifierMode_Render)) && (rmd->refresh == false || rmd->fracture_mode == MOD_FRACTURE_DYNAMIC));
-}
+ if (rbw->cache_index_map) {
+ MEM_freeN(rbw->cache_index_map);
+ rbw->cache_index_map = NULL;
+ }
-static void calc_dist_angle(RigidBodyShardCon *con, float *dist, float *angle, bool exact)
-{
- float q1[4], q2[4], qdiff[4], axis[3];
- if ((con->mi1->rigidbody == NULL) || (con->mi2->rigidbody == NULL)) {
- *dist = 0;
- *angle = 0;
- return;
+ if (rbw->cache_offset_map) {
+ MEM_freeN(rbw->cache_offset_map);
+ rbw->cache_offset_map = NULL;
}
- 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)
- {
- 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);
- }
-}
+ /* free cache */
+ BKE_ptcache_free_list(&(rbw->ptcaches));
+ rbw->pointcache = NULL;
-void BKE_rigidbody_start_dist_angle(RigidBodyShardCon *con, bool exact)
-{
- /* store starting angle and distance per constraint*/
- float dist, angle;
- calc_dist_angle(con, &dist, &angle, exact);
+ /* free effector weights */
+ if (rbw->effector_weights)
+ MEM_freeN(rbw->effector_weights);
- //printf("Start Values(dist, angle) %f %f %f %f\n", con->start_dist, con->start_angle, dist, angle);
- con->start_dist = dist;
- con->start_angle = angle;
+ /* free rigidbody world itself */
+ MEM_freeN(rbw);
}
-float BKE_rigidbody_calc_max_con_mass(Object *ob)
+/* Free RigidBody settings and sim instances */
+void BKE_rigidbody_free_object(Object *ob)
{
- FractureModifierData *rmd;
- ModifierData *md;
- RigidBodyShardCon *con;
- float max_con_mass = 0, con_mass;
+ RigidBodyOb *rbo = (ob) ? ob->rigidbody_object : NULL;
- 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;
- }
- }
- }
+ /* sanity check */
+ if (rbo == NULL)
+ return;
- return max_con_mass;
- }
+ /* free physics references */
+ if (rbo->physics_object) {
+ RB_body_delete(rbo->physics_object);
+ rbo->physics_object = NULL;
}
- return 0;
+ if (rbo->physics_shape) {
+ RB_shape_delete(rbo->physics_shape);
+ rbo->physics_shape = NULL;
+ }
+
+ /* free data itself */
+ MEM_freeN(rbo);
+ ob->rigidbody_object = NULL;
}
-float BKE_rigidbody_calc_min_con_dist(Object *ob)
+/* Free RigidBody constraint and sim instance */
+void BKE_rigidbody_free_constraint(Object *ob)
{
- FractureModifierData *rmd;
- ModifierData *md;
- RigidBodyShardCon *con;
- float min_con_dist = FLT_MAX, con_dist, con_vec[3];
+ RigidBodyCon *rbc = (ob) ? ob->rigidbody_constraint : NULL;
- 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 < min_con_dist) {
- min_con_dist = con_dist;
- }
- }
- }
+ /* sanity check */
+ if (rbc == NULL)
+ return;
- return min_con_dist;
- }
+ /* free physics reference */
+ if (rbc->physics_constraint) {
+ RB_constraint_delete(rbc->physics_constraint);
+ rbc->physics_constraint = NULL;
}
- return FLT_MAX;
+ /* free data itself */
+ MEM_freeN(rbc);
+ ob->rigidbody_constraint = NULL;
}
+/* Copying Methods --------------------- */
-void BKE_rigidbody_calc_threshold(float max_con_mass, FractureModifierData *rmd, RigidBodyShardCon *con) {
+/* These just copy the data, clearing out references to physics objects.
+ * Anything that uses them MUST verify that the copied object will
+ * be added to relevant groups later...
+ */
- float max_thresh, thresh = 0.0f, con_mass;
- if ((max_con_mass == 0) && (rmd->use_mass_dependent_thresholds)) {
- return;
- }
+RigidBodyOb *BKE_rigidbody_copy_object(Object *ob)
+{
+ RigidBodyOb *rboN = NULL;
- if ((con->mi1 == NULL) || (con->mi2 == NULL)) {
- return;
+ if (ob->rigidbody_object) {
+ /* just duplicate the whole struct first (to catch all the settings) */
+ rboN = MEM_dupallocN(ob->rigidbody_object);
+
+ /* tag object as needing to be verified */
+ rboN->flag |= RBO_FLAG_NEEDS_VALIDATE;
+
+ /* clear out all the fields which need to be revalidated later */
+ rboN->physics_object = NULL;
+ rboN->physics_shape = NULL;
}
- max_thresh = thresh = rmd->breaking_threshold;
- if ((con->mi1->rigidbody != NULL) && (con->mi2->rigidbody != NULL)) {
+ /* return new copy of settings */
+ return rboN;
+}
- if (rmd->use_compounds)
- {
- float min_mass = MIN2(con->mi1->rigidbody-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list