From e9ca43521f99c6b9baf6d9278f85323086fcade2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 25 Jul 2009 22:57:29 +0000 Subject: BGE Physics Add support back for reinstancePhysics mesh, a frequently requested feature in the BGE forums. from what I can tell Sumo supported this but bullet never did. Currently only accessible via python at the moment. - rigid body, dynamic, static types work. - instanced physics meshes are modified too. - compound shapes are not supported. Physics mesh can be re-instanced from... * shape keys & armature deformations * subsurf (any other modifiers too) * RAS_TexVert's (can be modified from python) Moved the reinstancePhysicsMesh functions from RAS_MeshObject into KX_GameObject since the physics data is stored here. video and blend file demo. http://www.graphicall.org/ftp/ideasman42/reinstance.ogv http://www.graphicall.org/ftp/ideasman42/reinstance_demo.blend --- .../gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp') diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 51c41c0686d..cc8a00e8454 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -1220,5 +1220,44 @@ void KX_ClearBulletSharedShapes() { } -#endif +/* Refresh the physics object from either an object or a mesh. + * gameobj must be valid + * from_gameobj and from_meshobj can be NULL + * + * when setting the mesh, the following vars get priority + * 1) from_meshobj - creates the phys mesh from RAS_MeshObject + * 2) from_gameobj - creates the phys mesh from the DerivedMesh where possible, else the RAS_MeshObject + * 3) gameobj - update the phys mesh from DerivedMesh or RAS_MeshObject + * + * Most of the logic behind this is in shapeInfo->UpdateMesh(...) + */ +bool KX_ReInstanceBulletShapeFromMesh(KX_GameObject *gameobj, KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj) +{ + KX_BulletPhysicsController *spc= static_cast((gameobj->GetPhysicsController())); + CcdShapeConstructionInfo *shapeInfo; + + /* if this is the child of a compound shape this can happen + * dont support compound shapes for now */ + if(spc==NULL) + return false; + + shapeInfo = spc->GetShapeInfo(); + + if(shapeInfo->m_shapeType != PHY_SHAPE_MESH || spc->GetSoftBody()) + return false; + + spc->DeleteControllerShape(); + + if(from_gameobj==NULL && from_meshobj==NULL) + from_gameobj= gameobj; + + /* updates the arrays used for making the new bullet mesh */ + shapeInfo->UpdateMesh(from_gameobj, from_meshobj); + /* create the new bullet mesh */ + btCollisionShape* bm= shapeInfo->CreateBulletShape(spc->getConstructionInfo().m_margin); + + spc->ReplaceControllerShape(bm); + return true; +} +#endif -- cgit v1.2.3