[Bf-blender-cvs] [9ad7275] fracture_modifier: attempt to get more control over compound destruction behavior during simulation, with stability factor; recursive breaking of neighborhood happens if one connection breaks
Martin Felke
noreply at git.blender.org
Mon Jan 4 19:46:45 CET 2016
Commit: 9ad72754c6e110273711e865d15230cd6107c53b
Author: Martin Felke
Date: Mon Jan 4 19:46:13 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB9ad72754c6e110273711e865d15230cd6107c53b
attempt to get more control over compound destruction behavior during simulation, with stability factor; recursive breaking of neighborhood happens if one connection breaks
===================================================================
M extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
M extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
M extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
M intern/rigidbody/RBI_api.h
M intern/rigidbody/rb_bullet_api.cpp
M source/blender/blenkernel/intern/rigidbody.c
===================================================================
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
index cd5dbc2..6e785e4 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
@@ -39,6 +39,7 @@ struct btPropagationParameter
btScalar m_impulse_dampening;
btScalar m_directional_factor;
btScalar m_minimum_impulse;
+ btScalar m_stability_factor;
};
class btFractureBody : public btRigidBody
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
index 775cedb..a58e003 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
@@ -1,4 +1,7 @@
+#include <cstdlib>
+#include <ctime>
+
#include "btBulletDynamicsCommon.h"
#include "btFractureDynamicsWorld.h"
#include "btFractureBody.h"
@@ -926,6 +929,36 @@ void btFractureDynamicsWorld::propagateDamage(btFractureBody *body, btScalar *im
}
}
+void btFractureDynamicsWorld::breakNeighborhood(btFractureBody *body, int connection_index)
+{
+ if (body->m_connections.size() > connection_index)
+ {
+ btAlignedObjectArray<int> *adjacents = body->m_connection_map->find(connection_index);
+ if (adjacents)
+ {
+ int i, size = adjacents->size();
+ float thresh = (1.0f - body->m_propagationParameter.m_stability_factor);
+ //clamp size... else too much recursion going on, leading to crashes
+ //if (size > 2)
+ {
+ for (i=0;i<size;i++)
+ {
+ float rnd = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
+ if (rnd < thresh)
+ {
+ //printf("Breaking neighbor %d\n", i);
+ btConnection& con = body->m_connections[adjacents->at(i)];
+ con.m_strength = 0;
+ //*needsBreakingCheck = true;
+ body->m_connections.remove(con);
+ breakNeighborhood(body, adjacents->at(i));
+ }
+ }
+ }
+ }
+ }
+}
+
void btFractureDynamicsWorld::fractureCallback( )
{
@@ -942,6 +975,9 @@ void btFractureDynamicsWorld::fractureCallback( )
sFracturePairs.clear();
+ // seed for random from time
+ srand (static_cast <unsigned> (time(0)));
+
for (int i=0;i<numManifolds;i++)
{
@@ -1139,6 +1175,8 @@ void btFractureDynamicsWorld::fractureCallback( )
connection.m_strength=0.f;
needsBreakingCheck = true;
sFracturePairs[i].m_fracObj->m_connections.remove(connection);
+
+ breakNeighborhood(sFracturePairs[i].m_fracObj, pt.m_index0);
}
}
}
@@ -1159,6 +1197,8 @@ void btFractureDynamicsWorld::fractureCallback( )
connection.m_strength=0.f;
needsBreakingCheck = true;
sFracturePairs[i].m_fracObj->m_connections.remove(connection);
+
+ breakNeighborhood(sFracturePairs[i].m_fracObj, pt.m_index1);
}
}
}
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
index 55f00f5..5df2a19 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
@@ -73,6 +73,8 @@ public:
void propagateDamage(btFractureBody *body, btScalar *impulse, int connection_index, bool *needsBreakingCheck,
const btVector3 &direction, int *depth);
+ void breakNeighborhood(btFractureBody *body, int connection_index);
+
virtual void updateAabbs();
};
diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 71c90d6..69a8324 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -136,7 +136,8 @@ void RB_world_convex_sweep_test(
/* ............ */
/* Create new RigidBody instance */
-rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4], bool use_compounds, float dampening, float factor, float min_impulse);
+rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4], bool use_compounds, float dampening, float factor,
+ float min_impulse, float stability_factor);
/* Delete the given RigidBody instance */
void RB_body_delete(rbRigidBody *body);
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 07b3c35..2e9f543 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -612,7 +612,8 @@ void RB_world_convex_sweep_test(
/* ............ */
-rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4], bool use_compounds, float dampening, float factor, float min_impulse)
+rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4], bool use_compounds, float dampening, float factor,
+ float min_impulse, float stability_factor)
{
rbRigidBody *object = new rbRigidBody;
/* current transform */
@@ -632,6 +633,7 @@ rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const floa
param.m_impulse_dampening = dampening;
param.m_directional_factor = factor;
param.m_minimum_impulse = min_impulse;
+ param.m_stability_factor = stability_factor;
object->body = new btFractureBody(rbInfo, param);
}
else
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 0284ae9..297f55e 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1249,7 +1249,8 @@ void BKE_rigidbody_validate_sim_shard(RigidBodyWorld *rbw, MeshIsland *mi, Objec
copy_v3_v3(loc, rbo->pos);
copy_v4_v4(rot, rbo->orn);
- rbo->physics_object = RB_body_new(rbo->physics_shape, loc, rot, fmd->use_compounds, fmd->impulse_dampening, fmd->directional_factor, fmd->minimum_impulse);
+ rbo->physics_object = RB_body_new(rbo->physics_shape, loc, rot, fmd->use_compounds, fmd->impulse_dampening,
+ fmd->directional_factor, fmd->minimum_impulse, fmd->mass_threshold_factor);
RB_body_set_friction(rbo->physics_object, rbo->friction);
RB_body_set_restitution(rbo->physics_object, rbo->restitution);
@@ -1342,7 +1343,7 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool
mat4_to_loc_quat(loc, rot, ob->obmat);
- rbo->physics_object = RB_body_new(rbo->physics_shape, loc, rot, false, 0.0f, 0.0f, 0.0f);
+ rbo->physics_object = RB_body_new(rbo->physics_shape, loc, rot, false, 0.0f, 0.0f, 0.0f, 0.0f);
RB_body_set_friction(rbo->physics_object, rbo->friction);
RB_body_set_restitution(rbo->physics_object, rbo->restitution);
More information about the Bf-blender-cvs
mailing list