BGE bug #18762 fixed: softbody. An incompatibility between the soft body deformer and other types of deformer was causing the soft body to disappear in the game. This was the case when the soft body had an armature or simply vertex groups.

This commit is contained in:
Benoit Bolsee 2009-05-19 06:48:36 +00:00
parent def33757e3
commit 5bd4b25dd1
3 changed files with 51 additions and 23 deletions

@ -90,6 +90,10 @@ public:
{ {
m_lastArmaUpdate = -1.0; m_lastArmaUpdate = -1.0;
}; };
virtual bool ShareVertexArray()
{
return false;
}
protected: protected:
BL_ArmatureObject* m_armobj; // Our parent object BL_ArmatureObject* m_armobj; // Our parent object

@ -54,6 +54,10 @@ public:
{ {
return false; return false;
} }
virtual bool ShareVertexArray()
{
return true;
}
virtual bool UseVertexArray() virtual bool UseVertexArray()
{ {
return true; return true;

@ -284,35 +284,55 @@ void RAS_MeshSlot::AddPolygonVertex(int offset)
void RAS_MeshSlot::SetDeformer(RAS_Deformer* deformer) void RAS_MeshSlot::SetDeformer(RAS_Deformer* deformer)
{ {
if (deformer && m_pDeformer != deformer) { if (deformer && m_pDeformer != deformer) {
// we create local copy of RAS_DisplayArray when we have a deformer:
// this way we can avoid conflict between the vertex cache of duplicates
RAS_DisplayArrayList::iterator it; RAS_DisplayArrayList::iterator it;
for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) { if (deformer->ShareVertexArray()) {
if (deformer->UseVertexArray()) { // this deformer uses the base vertex array, first release the current ones
// the deformer makes use of vertex array, make sure we have our local copy for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
if ((*it)->m_users > 1) {
// only need to copy if there are other users
// note that this is the usual case as vertex arrays are held by the material base slot
RAS_DisplayArray *newarray = new RAS_DisplayArray(*(*it));
newarray->m_users = 1;
(*it)->m_users--;
*it = newarray;
}
} else {
// the deformer is not using vertex array (Modifier), release them
(*it)->m_users--; (*it)->m_users--;
if((*it)->m_users == 0) if((*it)->m_users == 0)
delete *it; delete *it;
} }
}
if (!deformer->UseVertexArray()) {
m_displayArrays.clear(); m_displayArrays.clear();
m_startarray = 0; // then hook to the base ones
m_startvertex = 0; RAS_MeshMaterial *mmat = m_mesh->GetMeshMaterial(m_bucket->GetPolyMaterial());
m_startindex = 0; if (mmat && mmat->m_baseslot) {
m_endarray = 0; m_displayArrays = mmat->m_baseslot->m_displayArrays;
m_endvertex = 0; for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
m_endindex = 0; (*it)->m_users++;
}
}
}
else {
// no sharing
// we create local copy of RAS_DisplayArray when we have a deformer:
// this way we can avoid conflict between the vertex cache of duplicates
for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
if (deformer->UseVertexArray()) {
// the deformer makes use of vertex array, make sure we have our local copy
if ((*it)->m_users > 1) {
// only need to copy if there are other users
// note that this is the usual case as vertex arrays are held by the material base slot
RAS_DisplayArray *newarray = new RAS_DisplayArray(*(*it));
newarray->m_users = 1;
(*it)->m_users--;
*it = newarray;
}
} else {
// the deformer is not using vertex array (Modifier), release them
(*it)->m_users--;
if((*it)->m_users == 0)
delete *it;
}
}
if (!deformer->UseVertexArray()) {
m_displayArrays.clear();
m_startarray = 0;
m_startvertex = 0;
m_startindex = 0;
m_endarray = 0;
m_endvertex = 0;
m_endindex = 0;
}
} }
} }
m_pDeformer = deformer; m_pDeformer = deformer;