Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/rigidbody.c')
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 7cab0d7471f..24355149926 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -203,8 +203,6 @@ RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob)
/* just duplicate the whole struct first (to catch all the settings) */
rbcN = MEM_dupallocN(ob->rigidbody_constraint);
- // RB_TODO be more clever about copying constrained objects
-
/* tag object as needing to be verified */
rbcN->flag |= RBC_FLAG_NEEDS_VALIDATE;
@@ -216,6 +214,13 @@ RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob)
return rbcN;
}
+/* preserve relationships between constraints and rigid bodies after duplication */
+void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc)
+{
+ ID_NEW(rbc->ob1);
+ ID_NEW(rbc->ob2);
+}
+
/* ************************************** */
/* Setup Utilities - Validate Sim Instances */
@@ -354,7 +359,7 @@ void BKE_rigidbody_validate_sim_shape(Object *ob, short rebuild)
/* if automatically determining dimensions, use the Object's boundbox
* - assume that all quadrics are standing upright on local z-axis
* - assume even distribution of mass around the Object's pivot
- * (i.e. Object pivot is centralised in boundbox)
+ * (i.e. Object pivot is centralized in boundbox)
*/
// XXX: all dimensions are auto-determined now... later can add stored settings for this
/* get object dimensions without scaling */
@@ -416,6 +421,10 @@ void BKE_rigidbody_validate_sim_shape(Object *ob, short rebuild)
rbo->physics_shape = new_shape;
RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo));
}
+ else { /* otherwise fall back to box shape */
+ rbo->shape = RB_SHAPE_BOX;
+ BKE_rigidbody_validate_sim_shape(ob, true);
+ }
}
/* --------------------- */
@@ -853,7 +862,7 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob)
if (rbw->constraints) {
for (go = rbw->constraints->gobject.first; go; go = go->next) {
Object *obt = go->ob;
- if (obt) {
+ if (obt && obt->rigidbody_constraint) {
rbc = obt->rigidbody_constraint;
if (rbc->ob1 == ob) {
rbc->ob1 = NULL;
@@ -954,7 +963,7 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo) * MIN3(scale[0], scale[1], scale[2]));
/* make transformed objects temporarily kinmatic so that they can be moved by the user during simulation */
- if ((ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) || rbo->type == RBO_TYPE_PASSIVE) {
+ if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) {
RB_body_set_kinematic_state(rbo->physics_object, TRUE);
RB_body_set_mass(rbo->physics_object, 0.0f);
}
@@ -1114,6 +1123,9 @@ static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw)
if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) {
RB_body_set_kinematic_state(rbo->physics_object, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
+ /* deactivate passive objects so they don't interfere with deactivation of active objects */
+ if (rbo->type == RBO_TYPE_PASSIVE)
+ RB_body_deactivate(rbo->physics_object);
}
}
}
@@ -1174,8 +1186,12 @@ void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], flo
copy_qt_qt(rbo->orn, ob->quat);
copy_qt_qt(ob->quat, quat);
}
- if (rbo->physics_object)
+ if (rbo->physics_object) {
+ /* allow passive objects to return to original transform */
+ if (rbo->type == RBO_TYPE_PASSIVE)
+ RB_body_set_kinematic_state(rbo->physics_object, TRUE);
RB_body_set_loc_rot(rbo->physics_object, rbo->pos, rbo->orn);
+ }
// RB_TODO update rigid body physics object's loc/rot for dynamic objects here as well (needs to be done outside bullet's update loop)
}
@@ -1280,6 +1296,7 @@ void BKE_rigidbody_free_object(Object *ob) {}
void BKE_rigidbody_free_constraint(Object *ob) {}
struct RigidBodyOb *BKE_rigidbody_copy_object(Object *ob) { return NULL; }
struct RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob) { return NULL; }
+void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc) {}
void BKE_rigidbody_validate_sim_shape(Object *ob, short rebuild) {}
void BKE_rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, short rebuild) {}
void BKE_rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, short rebuild) {}