Add soft body anchor 'm_influence' to control the solver.
Thanks to Gregory Jaegy, see Issue 502 Avoid using btTransform to update btSoftBody (bounds are already in worldspace) Use btConvexHullComputer for soft body cluster debug rendering Fix soft body demo issue of invisible soft bodies (rendering was not enabled properly)
This commit is contained in:
@@ -1484,8 +1484,20 @@ void SoftDemo::renderme()
|
|||||||
btIDebugDraw* idraw=m_dynamicsWorld->getDebugDrawer();
|
btIDebugDraw* idraw=m_dynamicsWorld->getDebugDrawer();
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
m_dynamicsWorld->debugDrawWorld();
|
m_dynamicsWorld->debugDrawWorld();
|
||||||
|
|
||||||
|
btSoftRigidDynamicsWorld* softWorld = (btSoftRigidDynamicsWorld*)m_dynamicsWorld;
|
||||||
|
for ( int i=0;i<softWorld->getSoftBodyArray().size();i++)
|
||||||
|
{
|
||||||
|
btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i];
|
||||||
|
if (softWorld->getDebugDrawer() && !softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe))
|
||||||
|
{
|
||||||
|
btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer());
|
||||||
|
btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Bodies */
|
/* Bodies */
|
||||||
btVector3 ps(0,0,0);
|
btVector3 ps(0,0,0);
|
||||||
int nps=0;
|
int nps=0;
|
||||||
|
|||||||
@@ -357,14 +357,14 @@ void btSoftBody::appendTetra(int node0,
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
void btSoftBody::appendAnchor(int node,btRigidBody* body, bool disableCollisionBetweenLinkedBodies)
|
void btSoftBody::appendAnchor(int node,btRigidBody* body, bool disableCollisionBetweenLinkedBodies,btScalar influence)
|
||||||
{
|
{
|
||||||
btVector3 local = body->getWorldTransform().inverse()*m_nodes[node].m_x;
|
btVector3 local = body->getWorldTransform().inverse()*m_nodes[node].m_x;
|
||||||
appendAnchor(node,body,local,disableCollisionBetweenLinkedBodies);
|
appendAnchor(node,body,local,disableCollisionBetweenLinkedBodies,influence);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void btSoftBody::appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies)
|
void btSoftBody::appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies,btScalar influence)
|
||||||
{
|
{
|
||||||
if (disableCollisionBetweenLinkedBodies)
|
if (disableCollisionBetweenLinkedBodies)
|
||||||
{
|
{
|
||||||
@@ -379,6 +379,7 @@ void btSoftBody::appendAnchor(int node,btRigidBody* body, const btVector3& loc
|
|||||||
a.m_body = body;
|
a.m_body = body;
|
||||||
a.m_local = localPivot;
|
a.m_local = localPivot;
|
||||||
a.m_node->m_battach = 1;
|
a.m_node->m_battach = 1;
|
||||||
|
a.m_influence = influence;
|
||||||
m_anchors.push_back(a);
|
m_anchors.push_back(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2765,7 +2766,7 @@ void btSoftBody::PSolve_Anchors(btSoftBody* psb,btScalar kst,btScalar ti)
|
|||||||
const btVector3 va=a.m_body->getVelocityInLocalPoint(a.m_c1)*dt;
|
const btVector3 va=a.m_body->getVelocityInLocalPoint(a.m_c1)*dt;
|
||||||
const btVector3 vb=n.m_x-n.m_q;
|
const btVector3 vb=n.m_x-n.m_q;
|
||||||
const btVector3 vr=(va-vb)+(wa-n.m_x)*kAHR;
|
const btVector3 vr=(va-vb)+(wa-n.m_x)*kAHR;
|
||||||
const btVector3 impulse=a.m_c0*vr;
|
const btVector3 impulse=a.m_c0*vr*a.m_influence;
|
||||||
n.m_x+=impulse*a.m_c2;
|
n.m_x+=impulse*a.m_c2;
|
||||||
a.m_body->applyImpulse(-impulse,a.m_c1);
|
a.m_body->applyImpulse(-impulse,a.m_c1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,6 +282,7 @@ public:
|
|||||||
Node* m_node; // Node pointer
|
Node* m_node; // Node pointer
|
||||||
btVector3 m_local; // Anchor position in body space
|
btVector3 m_local; // Anchor position in body space
|
||||||
btRigidBody* m_body; // Body
|
btRigidBody* m_body; // Body
|
||||||
|
btScalar m_influence;
|
||||||
btMatrix3x3 m_c0; // Impulse matrix
|
btMatrix3x3 m_c0; // Impulse matrix
|
||||||
btVector3 m_c1; // Relative anchor
|
btVector3 m_c1; // Relative anchor
|
||||||
btScalar m_c2; // ima*dt
|
btScalar m_c2; // ima*dt
|
||||||
@@ -752,8 +753,8 @@ public:
|
|||||||
|
|
||||||
/* Append anchor */
|
/* Append anchor */
|
||||||
void appendAnchor( int node,
|
void appendAnchor( int node,
|
||||||
btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false);
|
btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1);
|
||||||
void appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false);
|
void appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1);
|
||||||
/* Append linear joint */
|
/* Append linear joint */
|
||||||
void appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1);
|
void appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1);
|
||||||
void appendLinearJoint(const LJoint::Specs& specs,Body body=Body());
|
void appendLinearJoint(const LJoint::Specs& specs,Body body=Body());
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ subject to the following restrictions:
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "btSoftBodyHelpers.h"
|
#include "btSoftBodyHelpers.h"
|
||||||
#include "LinearMath/btConvexHull.h"
|
#include "LinearMath/btConvexHull.h"
|
||||||
|
#include "LinearMath/btConvexHullComputer.h"
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
static void drawVertex( btIDebugDraw* idraw,
|
static void drawVertex( btIDebugDraw* idraw,
|
||||||
@@ -183,6 +185,35 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
|
|||||||
{
|
{
|
||||||
vertices[j]=psb->m_clusters[i]->m_nodes[j]->m_x;
|
vertices[j]=psb->m_clusters[i]->m_nodes[j]->m_x;
|
||||||
}
|
}
|
||||||
|
#define USE_NEW_CONVEX_HULL_COMPUTER
|
||||||
|
#ifdef USE_NEW_CONVEX_HULL_COMPUTER
|
||||||
|
btConvexHullComputer computer;
|
||||||
|
int stride = sizeof(btVector3);
|
||||||
|
int count = vertices.size();
|
||||||
|
btScalar shrink=0.f;
|
||||||
|
btScalar shrinkClamp=0.f;
|
||||||
|
computer.compute(&vertices[0].getX(),stride,count,shrink,shrinkClamp);
|
||||||
|
for (int i=0;i<computer.faces.size();i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
int face = computer.faces[i];
|
||||||
|
//printf("face=%d\n",face);
|
||||||
|
const btConvexHullComputer::Edge* firstEdge = &computer.edges[face];
|
||||||
|
const btConvexHullComputer::Edge* edge = firstEdge->getNextEdgeOfFace();
|
||||||
|
|
||||||
|
int v0 = firstEdge->getSourceVertex();
|
||||||
|
int v1 = firstEdge->getTargetVertex();
|
||||||
|
while (edge!=firstEdge)
|
||||||
|
{
|
||||||
|
int v2 = edge->getTargetVertex();
|
||||||
|
idraw->drawTriangle(computer.vertices[v0],computer.vertices[v1],computer.vertices[v2],color,1);
|
||||||
|
edge = edge->getNextEdgeOfFace();
|
||||||
|
v0=v1;
|
||||||
|
v1=v2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
HullDesc hdsc(QF_TRIANGLES,vertices.size(),&vertices[0]);
|
HullDesc hdsc(QF_TRIANGLES,vertices.size(),&vertices[0]);
|
||||||
HullResult hres;
|
HullResult hres;
|
||||||
HullLibrary hlib;
|
HullLibrary hlib;
|
||||||
@@ -201,6 +232,8 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
|
|||||||
color,1);
|
color,1);
|
||||||
}
|
}
|
||||||
hlib.ReleaseResult(hres);
|
hlib.ReleaseResult(hres);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
/* Velocities */
|
/* Velocities */
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
@@ -70,23 +70,9 @@ public:
|
|||||||
///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
|
///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
|
||||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
|
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
|
||||||
{
|
{
|
||||||
/* t should be identity, but better be safe than...fast? */
|
/* t should be identity */
|
||||||
const btVector3 mins=m_body->m_bounds[0];
|
aabbMin=m_body->m_bounds[0];
|
||||||
const btVector3 maxs=m_body->m_bounds[1];
|
aabbMax=m_body->m_bounds[1];
|
||||||
const btVector3 crns[]={t*btVector3(mins.x(),mins.y(),mins.z()),
|
|
||||||
t*btVector3(maxs.x(),mins.y(),mins.z()),
|
|
||||||
t*btVector3(maxs.x(),maxs.y(),mins.z()),
|
|
||||||
t*btVector3(mins.x(),maxs.y(),mins.z()),
|
|
||||||
t*btVector3(mins.x(),mins.y(),maxs.z()),
|
|
||||||
t*btVector3(maxs.x(),mins.y(),maxs.z()),
|
|
||||||
t*btVector3(maxs.x(),maxs.y(),maxs.z()),
|
|
||||||
t*btVector3(mins.x(),maxs.y(),maxs.z())};
|
|
||||||
aabbMin=aabbMax=crns[0];
|
|
||||||
for(int i=1;i<8;++i)
|
|
||||||
{
|
|
||||||
aabbMin.setMin(crns[i]);
|
|
||||||
aabbMax.setMax(crns[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user