[Bf-blender-cvs] [b212d62] fracture_modifier: some fixes for compound method, but still not very well controllable
Martin Felke
noreply at git.blender.org
Wed Oct 21 15:18:46 CEST 2015
Commit: b212d6234023674853f48cf7a970d1efdfc9f4d9
Author: Martin Felke
Date: Wed Oct 21 15:18:26 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rBb212d6234023674853f48cf7a970d1efdfc9f4d9
some fixes for compound method, but still not very well controllable
===================================================================
M extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp
M extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
M extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
M extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
===================================================================
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp
index e92dcb7..7457ed6 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp
@@ -81,18 +81,28 @@ void btFractureBody::recomputeConnectivityByConstraints(btCollisionWorld *world1
btFractureBody *obA = (btFractureBody*)&con->getRigidBodyA();
btFractureBody *obB = (btFractureBody*)&con->getRigidBodyB();
- world->m_idCallback(obA->getUserPointer(), &obIdA, &shardIdA);
- world->m_idCallback(obB->getUserPointer(), &obIdB, &shardIdB);
-
- if ((obIdA == obIdB) && (shardIdA != shardIdB))
+ //if (this == obA || this == obB)
{
- btConnection tmp;
- tmp.m_childIndex0 = shardIdA;
- tmp.m_childIndex1 = shardIdB;
- tmp.m_childShape0 = obA->getCollisionShape();
- tmp.m_childShape1 = obB->getCollisionShape();
- tmp.m_strength = con->getBreakingImpulseThreshold();
- m_connections.push_back(tmp);
+ int *index0 = NULL, *index1 = NULL;
+ world->m_idCallback(obA->getUserPointer(), &obIdA, &shardIdA);
+ world->m_idCallback(obB->getUserPointer(), &obIdB, &shardIdB);
+
+ index0 = world->m_childIndexHash->find(shardIdA);
+ index1 = world->m_childIndexHash->find(shardIdB);
+
+ if ((obIdA == obIdB) && (shardIdA != shardIdB) &&
+ index0 && index1 && *index0 > -1 && *index1 > -1)
+ {
+ btConnection tmp;
+ tmp.m_childIndex0 = *index0;
+ tmp.m_childIndex1 = *index1;
+ tmp.m_childShape0 = obA->getCollisionShape();
+ tmp.m_childShape1 = obB->getCollisionShape();
+ tmp.m_strength = con->getBreakingImpulseThreshold();
+ m_connections.push_back(tmp);
+ }
+
+ //break;
}
}
}
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
index 031a48e..3b088c6 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
@@ -32,14 +32,12 @@ public:
btDynamicsWorld* m_world;
btAlignedObjectArray<btScalar> m_masses;
btAlignedObjectArray<btConnection> m_connections;
- int m_childIndex;
btFractureBody( const btRigidBodyConstructionInfo& constructionInfo)
:btRigidBody(constructionInfo),
- m_world(0),
- m_childIndex(-1)
+ m_world(0)
{
m_masses.push_back(constructionInfo.m_mass);
m_internalType=CUSTOM_FRACTURE_TYPE+CO_RIGID_BODY;
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
index bcce589..848d011 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
@@ -12,7 +12,12 @@ m_fracturingMode(true),
m_idCallback(callback),
m_shapeBodyCallback(shapebodycallback)
{
+ m_childIndexHash = new btHashMap<btHashInt, int>();
+}
+btFractureDynamicsWorld::~btFractureDynamicsWorld()
+{
+ delete m_childIndexHash;
}
void btFractureDynamicsWorld::updateBodies()
@@ -35,9 +40,10 @@ void btFractureDynamicsWorld::updateBodies()
//find out to which body the shape belonged originally... and update it
- //int objectIndexA, shardIndexA, objectIndexB, shardIndexB;
- //m_idCallback(cshape->getUserPointer(), &objectIndexA, &shardIndexA);
+ int objectIndexA, shardIndexA; //, objectIndexB, shardIndexB;
+ m_idCallback(cshape->getUserPointer(), &objectIndexA, &shardIndexA);
//m_idCallback(body->getUserPointer(), &objectIndexB, &shardIndexB );
+ m_childIndexHash->insert(shardIndexA, j);
//if ((objectIndexA == objectIndexB) && (shardIndexA != shardIndexB))
btTransform trans;
@@ -301,10 +307,25 @@ void btFractureDynamicsWorld::glueCallback()
btVector3 localInertia;
newCompound->calculateLocalInertia(totalMass,localInertia);
btFractureBody* newBody = new btFractureBody(totalMass,0,newCompound,localInertia, &massArray[0], numChildren,this);
- newBody->recomputeConnectivity(this);
+ //newBody->recomputeConnectivity(this);
//newBody->recomputeConnectivityByConstraints(this);
newBody->setWorldTransform(fracObj->getWorldTransform()*shift);
+ int objectIndex, shardIndex;
+ //pass user pointer from old compound parent to new one
+ newBody->setUserPointer(fracObj->getUserPointer());
+ m_idCallback(newBody->getUserPointer(), &objectIndex, &shardIndex);
+
+ for (int i=0; i<numChildren; i++)
+ {
+ int obIndex, shIndex;
+ btCollisionShape *cshape = newCompound->getChildShape(i);
+ m_idCallback(cshape->getUserPointer(), &obIndex, &shIndex);
+ m_childIndexHash->insert(shIndex, i);
+ }
+
+ newBody->recomputeConnectivityByConstraints(this);
+
//now the linear/angular velocity is still zero, apply the impulses
for (int i=0;i<oldImpulses.size();i++)
@@ -316,6 +337,9 @@ void btFractureDynamicsWorld::glueCallback()
addRigidBody(newBody);
+ //newbody is a compound parent, hmmmm, so set its childindex to 0 or -1
+ m_childIndexHash->insert(shardIndex, -1);
+
}
@@ -383,8 +407,8 @@ btFractureBody* btFractureDynamicsWorld::addNewBody(const btTransform& oldTransf
//newCompound->calculateLocalInertia(totalMass,localInertia);
btFractureBody* newBody = new btFractureBody(totalMass,0,newCompound,localInertia, masses,newCompound->getNumChildShapes(), this);
- newBody->recomputeConnectivity(this);
- //newBody->recomputeConnectivityByConstraints(this);
+ //newBody->recomputeConnectivity(this);
+ newBody->recomputeConnectivityByConstraints(this);
newBody->setCollisionFlags(newBody->getCollisionFlags()|btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
newBody->setWorldTransform(oldTransform*shift);
@@ -491,12 +515,12 @@ void btFractureDynamicsWorld::breakDisconnectedParts( btFractureBody* fracObj)
for (i=0;i<fracObj->m_connections.size();i++)
{
btConnection& connection = fracObj->m_connections[i];
- if (connection.m_childIndex0 >= tags.size() ||
+ /*if (connection.m_childIndex0 >= tags.size() ||
connection.m_childIndex1 >= tags.size() )
{
//fracObj->m_connections.remove(connection);
continue;
- }
+ }*/
if (connection.m_strength > 0.)
{
@@ -554,10 +578,25 @@ void btFractureDynamicsWorld::breakDisconnectedParts( btFractureBody* fracObj)
}
if (numShapes)
{
+ int objectIndex, shardIndex;
btFractureBody* newBody = addNewBody(fracObj->getWorldTransform(),&masses[0],newCompound);
newBody->setLinearVelocity(fracObj->getLinearVelocity());
newBody->setAngularVelocity(fracObj->getAngularVelocity());
+ //pass user pointer from old compound parent to new one
+ newBody->setUserPointer(fracObj->getUserPointer());
+ m_idCallback(newBody->getUserPointer(), &objectIndex, &shardIndex);
+ m_childIndexHash->insert(shardIndex, -1);
+ int numChildren = newCompound->getNumChildShapes();
+
+ for (int i=0; i<numChildren; i++)
+ {
+ int obIndex, shIndex;
+ btCollisionShape *cshape = newCompound->getChildShape(i);
+ m_idCallback(cshape->getUserPointer(), &obIndex, &shIndex);
+ m_childIndexHash->insert(shIndex, i);
+ }
+
numIslands++;
}
}
@@ -573,6 +612,10 @@ void btFractureDynamicsWorld::breakDisconnectedParts( btFractureBody* fracObj)
#include <stdio.h>
+/*void btFractureDynamicsWorld::propagateWeaken(btFractureBody *body, btManifoldPoint *pt)
+{
+
+}*/
void btFractureDynamicsWorld::fractureCallback( )
{
@@ -748,13 +791,12 @@ void btFractureDynamicsWorld::fractureCallback( )
{
btConnection& connection = sFracturePairs[i].m_fracObj->m_connections[f];
if ((connection.m_childIndex0 == pt.m_index0) ||
- (connection.m_childIndex1 == pt.m_index1) ||
- (connection.m_childIndex0 == pt.m_index1) ||
- (connection.m_childIndex1 == pt.m_index0)
- )
+ (connection.m_childIndex1 == pt.m_index0))
+ //(connection.m_childIndex0 == pt.m_index1) ||
+ //(connection.m_childIndex1 == pt.m_index1))
{
connection.m_strength -= pt.m_appliedImpulse;
- printf("strength=%f\n",connection.m_strength);
+ printf("strength0=%f\n",connection.m_strength);
if (connection.m_strength<0)
{
@@ -766,16 +808,16 @@ void btFractureDynamicsWorld::fractureCallback( )
}
} else
{
+ //propagate
for (int f=0;f<sFracturePairs[i].m_fracObj->m_connections.size();f++)
{
btConnection& connection = sFracturePairs[i].m_fracObj->m_connections[f];
- if ((connection.m_childIndex0 == pt.m_index0) ||
- (connection.m_childIndex1 == pt.m_index1) ||
- (connection.m_childIndex0 == pt.m_index1) ||
- (connection.m_childIndex1 == pt.m_index0)
- )
+ if ((connection.m_childIndex0 == pt.m_index1) ||
+ (connection.m_childIndex1 == pt.m_index1))
+ // (connection.m_childIndex0 == pt.m_index0) ||
+ // (connection.m_childIndex1 == pt.m_index0))
{
- printf("strength=%f\n",connection.m_strength);
+ printf("strength1=%f\n",connection.m_strength);
connection.m_strength -= pt.m_appliedImpulse;
if (connection.m_strength<0)
{
@@ -792,6 +834,7 @@ void btFractureDynamicsWorld::fractureCallback( )
if (needsBreakingCheck)
{
breakDisconnectedParts(sFracturePairs[i].m_fracObj);
+ //glueCallback();
}
}
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
index 506ae30..c78ae84 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
@@ -4,6 +4,7 @@
#include "btBulletDynamicsCommon.h"
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
#include "LinearMath/btAlignedObjectArray.h"
+#include "LinearMath/btHashMap.h"
class btFractureB
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list