[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60442] branches/soc-2013-rigid_body_sim: rigidbody: Add impulse threshold for collision based activation
Sergej Reich
sergej.reich at googlemail.com
Mon Sep 30 14:59:53 CEST 2013
Revision: 60442
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60442
Author: sergof
Date: 2013-09-30 12:59:53 +0000 (Mon, 30 Sep 2013)
Log Message:
-----------
rigidbody: Add impulse threshold for collision based activation
Modified Paths:
--------------
branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h
branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp
branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c
branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h
branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c
Modified: branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h
===================================================================
--- branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h 2013-09-30 12:11:27 UTC (rev 60441)
+++ branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h 2013-09-30 12:59:53 UTC (rev 60442)
@@ -188,6 +188,7 @@
extern void RB_body_set_ghost(rbRigidBody *object, int ghost);
extern void RB_body_set_activation_type(rbRigidBody *object, int type);
extern void RB_body_set_activation_time(rbRigidBody *object, double time);
+extern void RB_body_set_activation_impulse(rbRigidBody *object, float impulse);
extern void RB_body_try_activation(rbRigidBody *object);
/* RigidBody Interface - Rigid Body Activation States */
Modified: branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp
===================================================================
--- branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp 2013-09-30 12:11:27 UTC (rev 60441)
+++ branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp 2013-09-30 12:59:53 UTC (rev 60442)
@@ -103,6 +103,7 @@
bool suspended;
float saved_mass;
double activation_time;
+ float activation_impulse;
int activation_type;
};
@@ -154,7 +155,7 @@
}
};
-static void activate(rbRigidBody *rb)
+static inline void activate(rbRigidBody *rb)
{
btRigidBody *body = rb->body;
rb->suspended = false;
@@ -164,6 +165,40 @@
body->activate();
}
+static inline void activate_on_impulse(btPersistentManifold *manifold, rbRigidBody *rb0, rbRigidBody *rb1)
+{
+ if (rb0->activation_impulse > 0.0f) {
+ float impulse = 0.0f;
+ /* use contact with highest impulse */
+ for (int i = 0; i < manifold->getNumContacts(); i++) {
+ btScalar velocity = (rb1->body->getLinearVelocity() + rb1->body->getAngularVelocity()).dot(-manifold->getContactPoint(i).m_normalWorldOnB);
+ impulse = (impulse < velocity) ? velocity : impulse;
+ }
+ impulse /= rb1->body->getInvMass();
+ if (impulse >= rb0->activation_impulse)
+ activate(rb0);
+ }
+ else {
+ activate(rb0);
+ }
+}
+
+static inline void handle_activation(btPersistentManifold *manifold, rbRigidBody *rb0, rbRigidBody *rb1)
+{
+ if (rb0->suspended) {
+ switch(rb0->activation_type) {
+ case ACTIVATION_COLLISION:
+ activate_on_impulse(manifold, rb0, rb1);
+ break;
+ case ACTIVATION_TRIGGER:
+ if (rb1->is_trigger) {
+ activate_on_impulse(manifold, rb0, rb1);
+ }
+ break;
+ }
+ }
+}
+
static void nearCallback(btBroadphasePair &collisionPair, btCollisionDispatcher &dispatcher, const btDispatcherInfo &dispatchInfo)
{
btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
@@ -193,32 +228,13 @@
dispatchInfo.m_timeOfImpact = toi;
}
- if (contactPointResult.getPersistentManifold() && contactPointResult.getPersistentManifold()->getNumContacts() > 0) {
+ btPersistentManifold *manifold = contactPointResult.getPersistentManifold();
+ if (manifold && manifold->getNumContacts() > 0) {
rbRigidBody *rb0 = (rbRigidBody *)((btRigidBody *)collisionPair.m_pProxy0->m_clientObject)->getUserPointer();
rbRigidBody *rb1 = (rbRigidBody *)((btRigidBody *)collisionPair.m_pProxy1->m_clientObject)->getUserPointer();
- if (rb1->suspended) {
- switch(rb1->activation_type) {
- case ACTIVATION_COLLISION:
- activate(rb1);
- break;
- case ACTIVATION_TRIGGER:
- if (rb0->is_trigger)
- activate(rb1);
- break;
- }
- }
- if (rb0->suspended) {
- switch(rb0->activation_type) {
- case ACTIVATION_COLLISION:
- activate(rb0);
- break;
- case ACTIVATION_TRIGGER:
- if (rb1->is_trigger)
- activate(rb0);
- break;
- }
- }
+ handle_activation(manifold, rb0, rb1);
+ handle_activation(manifold, rb1, rb0);
}
}
}
@@ -757,6 +773,11 @@
object->activation_time = time;
}
+void RB_body_set_activation_impulse(rbRigidBody *object, float impulse)
+{
+ object->activation_impulse = impulse;
+}
+
void RB_body_try_activation(rbRigidBody *object)
{
if (object->suspended && object->activation_time <= object->world->elapsed_time)
Modified: branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
===================================================================
--- branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py 2013-09-30 12:11:27 UTC (rev 60441)
+++ branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py 2013-09-30 12:59:53 UTC (rev 60442)
@@ -128,6 +128,8 @@
sub.prop(rbo, "activation_type", text="Type")
if rbo.activation_type == 'TIME':
sub.prop(rbo, "activation_time", text="Time")
+ elif rbo.activation_type in {'COLLISION', 'TRIGGER'}:
+ sub.prop(rbo, "activation_impulse", text="Threshold")
col = split.column()
col.label(text="Deactivation:")
Modified: branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c 2013-09-30 12:11:27 UTC (rev 60441)
+++ branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c 2013-09-30 12:59:53 UTC (rev 60442)
@@ -681,6 +681,7 @@
RB_body_set_ghost(rbo->physics_object, rbo->flag & RBO_FLAG_GHOST);
RB_body_set_activation_type(rbo->physics_object, rbo->activation_type);
RB_body_set_activation_time(rbo->physics_object, rbo->activation_time);
+ RB_body_set_activation_impulse(rbo->physics_object, rbo->activation_impulse);
}
if (rbw && rbw->physics_world && (rbo->flag & RBO_FLAG_COMPOUND_CHILD) == 0) // RB_TODO find better solution for compound shapes
Modified: branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h 2013-09-30 12:11:27 UTC (rev 60441)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h 2013-09-30 12:59:53 UTC (rev 60442)
@@ -123,6 +123,8 @@
float orn[4]; /* rigid body orientation */
float pos[3]; /* rigid body position */
float activation_time; /* time until body is activated */
+ float activation_impulse; /* impulse threshold that needs to be reached for body to get activated */
+ int pad;
struct EffectorWeights *effector_weights;
} RigidBodyOb;
Modified: branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c 2013-09-30 12:11:27 UTC (rev 60441)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c 2013-09-30 12:59:53 UTC (rev 60442)
@@ -854,6 +854,14 @@
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
+ prop = RNA_def_property(srna, "activation_impulse", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "activation_impulse");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_float_default(prop, 1.0f);
+ RNA_def_property_ui_text(prop, "Impulse Threshold", "Impulse that need to be reached for body to be activated");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
+
/* Dynamics Parameters - Deactivation */
prop = RNA_def_property(srna, "use_deactivation", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_USE_DEACTIVATION);
More information about the Bf-blender-cvs
mailing list