diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2008-09-24 07:12:10 +0400 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2008-09-24 07:12:10 +0400 |
commit | 3b09c0b0d5a5bea78f0832532f8c206280ae6456 (patch) | |
tree | 42b036ffaa18d7ddf3b65a581ed49bb73130551f /source/gameengine/Ketsji | |
parent | 7eae8d0c7ba8d352faca05e6de4886f3ebd3f169 (diff) |
Created a KX_SoftBodyDeformer for real-time soft bodies.
Added SetDeformer/GetDeformer() to KX_GameObject.
Store mapping between graphics/soft body vertices (work-in-progress)
Real-time soft body integration is still very premature, but
for a quick preview, see this testfile:
http://bulletphysics.com/ftp/pub/test/index.php?dir=blender/&file=soft_test.blend
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 110 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 8 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.cpp | 12 |
3 files changed, 123 insertions, 7 deletions
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 46b53d07efc..c4411a58856 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -38,6 +38,8 @@ #include "RAS_MeshObject.h" #include "KX_Scene.h" #include "SYS_System.h" +#include "BL_SkinMeshObject.h" +#include "BulletSoftBody/btSoftBody.h" #include "PHY_Pro.h" //todo cleanup #include "KX_ClientObjectInfo.h" @@ -765,7 +767,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, } case KX_BOUNDMESH: { - if (!ci.m_mass) + if (!ci.m_mass ||objprop->m_softbody) { // mesh shapes can be shared, check first if we already have a shape on that mesh class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, false); @@ -988,6 +990,112 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, physicscontroller->SetObject(gameobj->GetSGNode()); + class KX_SoftBodyDeformer : public RAS_Deformer + { + btSoftBody* m_softBody; + class BL_SkinMeshObject* m_pMeshObject; + class BL_DeformableGameObject* m_gameobj; + + + public: + KX_SoftBodyDeformer(btSoftBody* softBody,BL_SkinMeshObject* pMeshObject,BL_DeformableGameObject* gameobj) + : m_softBody(softBody), + m_pMeshObject(pMeshObject), + m_gameobj(gameobj) + { + //printf("KX_SoftBodyDeformer\n"); + }; + + virtual ~KX_SoftBodyDeformer() + { + //printf("~KX_SoftBodyDeformer\n"); + }; + virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map) + { + //printf("relink\n"); + } + virtual bool Apply(class RAS_IPolyMaterial *polymat) + { + //printf("apply\n"); + RAS_MeshSlot::iterator it; + RAS_MeshMaterial *mmat; + RAS_MeshSlot *slot; + size_t i; + + // 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 + // cycling through the objects, the entire mesh cache cannot be updated in one shot. + mmat = m_pMeshObject->GetMeshMaterial(polymat); + if(!mmat->m_slots[(void*)m_gameobj]) + return true; + + slot = *mmat->m_slots[(void*)m_gameobj]; + + // for each array + for(slot->begin(it); !slot->end(it); slot->next(it)) + { + // for each vertex + // copy the untransformed data from the original mvert + int count = 0; + { + + for(i=it.startvertex; i<it.endvertex; i++,count++) + { + } + } + btSoftBody::tNodeArray& nodes(m_softBody->m_nodes); + + if (count == m_softBody->m_userIndexMapping.size()) + { + int index = 0; + for(i=it.startvertex; i<it.endvertex; i++,index++) { + RAS_TexVert& v = it.vertex[i]; + + MT_Point3 pt ( + nodes[m_softBody->m_userIndexMapping[index]].m_x.getX(), + nodes[m_softBody->m_userIndexMapping[index]].m_x.getY(), + nodes[m_softBody->m_userIndexMapping[index]].m_x.getZ()); + v.SetXYZ(pt); + + //(m_transverts[v.getOrigIndex()]); + } + } + + } + + return true; + } + virtual bool Update(void) + { + //printf("update\n"); + return true;//?? + } + virtual RAS_Deformer *GetReplica() + { + //printf("getReplica\n"); + return 0; + } + protected: + //class RAS_MeshObject *m_pMesh; + }; + + ///test for soft bodies + if (objprop->m_softbody && physicscontroller) + { + btSoftBody* softBody = physicscontroller->GetSoftBody(); + if (softBody && gameobj->GetMesh(0)) + { + //should be a mesh then, so add a soft body deformer + KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer(softBody, (BL_SkinMeshObject*)gameobj->GetMesh(0),(BL_DeformableGameObject*)gameobj); + gameobj->SetDeformer(softbodyDeformer); + + } + } + } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 2da0be4df25..12e29cf3294 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -332,6 +332,14 @@ public: m_pPhysicsController1 = physicscontroller; } + virtual class RAS_Deformer* GetDeformer() + { + return 0; + } + virtual void SetDeformer(class RAS_Deformer* deformer) + { + + } /** * @section Coordinate system manipulation functions diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 04db96c298c..6eeb732c1e3 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -977,10 +977,10 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj) { BL_DeformableGameObject* newobj = static_cast<BL_DeformableGameObject*>( gameobj ); - if (newobj->m_pDeformer) + if (newobj->GetDeformer()) { - delete newobj->m_pDeformer; - newobj->m_pDeformer = NULL; + delete newobj->GetDeformer(); + newobj->SetDeformer(NULL); } if (mesh->IsDeformed()) @@ -1030,7 +1030,7 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj) NULL ); } - newobj->m_pDeformer = shapeDeformer; + newobj->SetDeformer( shapeDeformer); } else if (bHasArmature) { @@ -1042,14 +1042,14 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj) static_cast<BL_ArmatureObject*>( parentobj ) ); releaseParent= false; - newobj->m_pDeformer = skinDeformer; + newobj->SetDeformer(skinDeformer); } else if (bHasDvert) { BL_MeshDeformer* meshdeformer = new BL_MeshDeformer( newobj, oldblendobj, static_cast<BL_SkinMeshObject*>(mesh) ); - newobj->m_pDeformer = meshdeformer; + newobj->SetDeformer(meshdeformer); } // release parent reference if its not being used |