don't apply vertex transformation for deformable game soft bodies.
set a fake world transform for game soft bodies, based on center of the AABB, so visiblity and some game logic works. note: this world transform is not smooth.
This commit is contained in:
@@ -672,11 +672,11 @@ void KX_ConvertODEEngineObject(KX_GameObject* gameobj,
|
||||
{
|
||||
btSoftBody* m_softBody;
|
||||
class RAS_MeshObject* m_pMeshObject;
|
||||
class BL_DeformableGameObject* m_gameobj;
|
||||
class KX_GameObject* m_gameobj;
|
||||
|
||||
|
||||
public:
|
||||
KX_SoftBodyDeformer(btSoftBody* softBody,RAS_MeshObject* pMeshObject,BL_DeformableGameObject* gameobj)
|
||||
KX_SoftBodyDeformer(btSoftBody* softBody,RAS_MeshObject* pMeshObject,KX_GameObject* gameobj)
|
||||
: m_softBody(softBody),
|
||||
m_pMeshObject(pMeshObject),
|
||||
m_gameobj(gameobj)
|
||||
@@ -703,6 +703,8 @@ void KX_ConvertODEEngineObject(KX_GameObject* gameobj,
|
||||
// update the vertex in m_transverts
|
||||
Update();
|
||||
|
||||
|
||||
|
||||
// The vertex cache can only be updated for this deformer:
|
||||
// Duplicated objects with more than one ploymaterial (=multiple mesh slot per object)
|
||||
// share the same mesh (=the same cache). As the rendering is done per polymaterial
|
||||
@@ -748,6 +750,12 @@ void KX_ConvertODEEngineObject(KX_GameObject* gameobj,
|
||||
//printf("getReplica\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual bool SkipVertexTransform()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
//class RAS_MeshObject *m_pMesh;
|
||||
};
|
||||
@@ -1089,7 +1097,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
|
||||
if (softBody && gameobj->GetMesh(0))//only the first mesh, if any
|
||||
{
|
||||
//should be a mesh then, so add a soft body deformer
|
||||
KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer(softBody, gameobj->GetMesh(0),(BL_DeformableGameObject*)gameobj);
|
||||
KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer(softBody, gameobj->GetMesh(0),gameobj);
|
||||
gameobj->SetDeformer(softbodyDeformer);
|
||||
|
||||
}
|
||||
|
||||
@@ -401,13 +401,17 @@ void CcdPhysicsController::CreateRigidbody()
|
||||
{
|
||||
startTrans = rbci.m_startWorldTransform;
|
||||
}
|
||||
startTrans.setIdentity();
|
||||
//startTrans.setIdentity();
|
||||
|
||||
m_object->setWorldTransform(startTrans);
|
||||
m_object->setInterpolationWorldTransform(startTrans);
|
||||
m_MotionState->setWorldPosition(0,0,0);
|
||||
//m_object->setWorldTransform(startTrans);
|
||||
//m_object->setInterpolationWorldTransform(startTrans);
|
||||
m_MotionState->setWorldPosition(startTrans.getOrigin().getX(),startTrans.getOrigin().getY(),startTrans.getOrigin().getZ());
|
||||
m_MotionState->setWorldOrientation(0,0,0,1);
|
||||
|
||||
// btVector3 wp = m_softBody->getWorldTransform().getOrigin();
|
||||
// MT_Point3 center(wp.getX(),wp.getY(),wp.getZ());
|
||||
// m_gameobj->NodeSetWorldPosition(center);
|
||||
|
||||
|
||||
} else
|
||||
{
|
||||
@@ -502,10 +506,22 @@ bool CcdPhysicsController::SynchronizeMotionStates(float time)
|
||||
{
|
||||
//sync non-static to motionstate, and static from motionstate (todo: add kinematic etc.)
|
||||
|
||||
btSoftBody* sb = GetSoftBody();
|
||||
if (sb)
|
||||
{
|
||||
btVector3 aabbMin,aabbMax;
|
||||
sb->getAabb(aabbMin,aabbMax);
|
||||
btVector3 worldPos = (aabbMax+aabbMin)*0.5f;
|
||||
m_MotionState->setWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
|
||||
m_MotionState->calculateWorldTransformations();
|
||||
return true;
|
||||
}
|
||||
|
||||
btRigidBody* body = GetRigidBody();
|
||||
|
||||
if (body && !body->isStaticObject())
|
||||
{
|
||||
|
||||
const btVector3& worldPos = body->getCenterOfMassPosition();
|
||||
m_MotionState->setWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
|
||||
|
||||
|
||||
@@ -45,6 +45,10 @@ public:
|
||||
virtual bool Apply(class RAS_IPolyMaterial *polymat)=0;
|
||||
virtual bool Update(void)=0;
|
||||
virtual RAS_Deformer *GetReplica()=0;
|
||||
virtual bool SkipVertexTransform()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
protected:
|
||||
class RAS_MeshObject *m_pMesh;
|
||||
};
|
||||
|
||||
@@ -539,7 +539,10 @@ void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRa
|
||||
ms.m_mesh->SortPolygons(ms, cameratrans*MT_Transform(ms.m_OpenGLMatrix));
|
||||
|
||||
rendertools->PushMatrix();
|
||||
rendertools->applyTransform(rasty,ms.m_OpenGLMatrix,m_material->GetDrawingMode());
|
||||
if (!ms.m_pDeformer || !ms.m_pDeformer->SkipVertexTransform())
|
||||
{
|
||||
rendertools->applyTransform(rasty,ms.m_OpenGLMatrix,m_material->GetDrawingMode());
|
||||
}
|
||||
|
||||
if(rasty->QueryLists())
|
||||
if(ms.m_DisplayList)
|
||||
|
||||
Reference in New Issue
Block a user