Skip to content

Commit 2f08b89

Browse files
authored
Updated Collision Filtering and loaded shaders for Softbodies (#238)
1 parent a5aef85 commit 2f08b89

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

adf_loader/version_1_0/adf_loader_1_0.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,7 @@ bool ADFLoader_1_0::loadSoftBodyAttribs(YAML::Node *a_node, afSoftBodyAttributes
15091509
YAML::Node colorNode = node["color"];
15101510
YAML::Node colorRGBANode = node["color rgba"];
15111511
YAML::Node colorComponentsNode = node["color components"];
1512+
YAML::Node collisionGroupsNode = node["collision groups"];
15121513

15131514
YAML::Node configDataNode = node["config"];
15141515

ambf_framework/afFramework.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,6 +2872,9 @@ bool afSoftBody::createFromAttribs(afSoftBodyAttributes *a_attribs)
28722872
return 0;
28732873
}
28742874

2875+
m_shaderAttribs = a_attribs->m_shaderAttribs;
2876+
loadShaderProgram();
2877+
28752878
if (m_collisionMesh->loadFromFile(a_attribs->m_collisionAttribs.m_meshFilepath.c_str())){
28762879
m_collisionMesh->removeDuplicateVertices();
28772880
m_collisionMesh->scale(m_scale);
@@ -2985,6 +2988,22 @@ bool afSoftBody::createFromAttribs(afSoftBodyAttributes *a_attribs)
29852988
softBody->randomizeConstraints();
29862989
}
29872990

2991+
for (uint gI = 0 ; gI < a_attribs->m_collisionAttribs.m_groups.size() ; gI++){
2992+
uint group = a_attribs->m_collisionAttribs.m_groups[gI];
2993+
// Sanity check for the group number
2994+
if (group >= 0 && group <= 999){
2995+
m_afWorld->m_collisionGroups[group].push_back(this);
2996+
m_collisionGroups.push_back(group);
2997+
// Print the soft body name and group
2998+
cout << "SoftBody Name: " << m_name << ", Group: " << group << endl;
2999+
}
3000+
else{
3001+
cerr << "WARNING! Body "
3002+
<< m_name
3003+
<< "'s group number is \"" << group << "\" which should be between [0 - 999], ignoring\n";
3004+
}
3005+
}
3006+
29883007
addChildSceneObject(m_visualMesh, cTransform());
29893008
((btSoftRigidDynamicsWorld*)m_afWorld->m_bulletWorld)->addSoftBody(m_bulletSoftBody);
29903009
m_afWorld->m_bulletSoftBodyWorldInfo->m_sparsesdf.Reset();
@@ -6018,14 +6037,32 @@ void afWorld::buildCollisionGroups(){
60186037
afInertialObjectPtr bodyA = grpA[aBodyIdx];
60196038
for(uint bBodyIdx = 0 ; bBodyIdx < grpB.size() ; bBodyIdx++){
60206039
afInertialObjectPtr bodyB = grpB[bBodyIdx];
6021-
if (bodyA != bodyB && !bodyB->isCommonCollisionGroupIdx(bodyA->m_collisionGroups))
6022-
bodyA->m_bulletRigidBody->setIgnoreCollisionCheck(bodyB->m_bulletRigidBody, true);
6040+
if (bodyA != bodyB && !bodyB->isCommonCollisionGroupIdx(bodyA->m_collisionGroups)){
6041+
if (bodyA->m_bulletRigidBody && bodyB->m_bulletRigidBody) {
6042+
bodyA->m_bulletRigidBody->setIgnoreCollisionCheck(bodyB->m_bulletRigidBody, true);
6043+
//cout << "Ignoring collision between rigid bodies: " << bodyA << " and " << bodyB << endl;
6044+
}
6045+
// Handle Soft Body
6046+
else if (bodyA->m_bulletSoftBody && bodyB->m_bulletRigidBody) {
6047+
bodyB->m_bulletRigidBody->setIgnoreCollisionCheck(bodyA->m_bulletSoftBody, true);
6048+
//cout << "Ignoring collision between soft body: " << bodyA << " and rigid body: " << bodyB << endl;
6049+
}
6050+
else if (bodyA->m_bulletRigidBody && bodyB->m_bulletSoftBody) {
6051+
bodyA->m_bulletRigidBody->setIgnoreCollisionCheck(bodyB->m_bulletSoftBody, true);
6052+
//cout << "Ignoring collision between rigid body: " << bodyA << " and soft body: " << bodyB << endl;
6053+
}
6054+
else if (bodyA->m_bulletSoftBody && bodyB->m_bulletSoftBody) {
6055+
// Set ignore collision for both soft bodies
6056+
bodyA->m_bulletSoftBody->setIgnoreCollisionCheck(bodyB->m_bulletSoftBody, true);
6057+
//cout << "Ignoring collision between soft bodies: " << bodyA << " and " << bodyB << endl;
6058+
}
60236059
}
60246060
}
60256061
}
60266062
}
60276063
}
60286064
}
6065+
}
60296066

60306067

60316068

0 commit comments

Comments
 (0)