[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21908] trunk/blender/source/gameengine: BGE Physics
Campbell Barton
ideasman42 at gmail.com
Sun Jul 26 00:57:29 CEST 2009
Revision: 21908
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21908
Author: campbellbarton
Date: 2009-07-26 00:57:29 +0200 (Sun, 26 Jul 2009)
Log Message:
-----------
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
Modified Paths:
--------------
trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
trunk/blender/source/gameengine/Converter/BL_MeshDeformer.h
trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp
trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
trunk/blender/source/gameengine/PyDoc/GameTypes.py
trunk/blender/source/gameengine/Rasterizer/RAS_Deformer.h
trunk/blender/source/gameengine/Rasterizer/RAS_MeshObject.cpp
trunk/blender/source/gameengine/Rasterizer/RAS_MeshObject.h
Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2009-07-25 22:57:29 UTC (rev 21908)
@@ -1040,7 +1040,10 @@
layer.face++;
}
}
- meshobj->m_sharedvertex_map.clear();
+ // keep meshobj->m_sharedvertex_map for reinstance phys mesh.
+ // 2.49a and before it did: meshobj->m_sharedvertex_map.clear();
+ // but this didnt save much ram. - Campbell
+ meshobj->EndConversion();
// pre calculate texture generation
for(list<RAS_MeshMaterial>::iterator mit = meshobj->GetFirstMaterial();
Modified: trunk/blender/source/gameengine/Converter/BL_MeshDeformer.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_MeshDeformer.h 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Converter/BL_MeshDeformer.h 2009-07-25 22:57:29 UTC (rev 21908)
@@ -68,6 +68,8 @@
virtual RAS_Deformer* GetReplica(){return NULL;};
virtual void ProcessReplica();
struct Mesh* GetMesh() { return m_bmesh; };
+ virtual class RAS_MeshObject* GetRasMesh() { return (RAS_MeshObject*)m_pMeshObject; };
+ virtual float (* GetTransVerts(int *tot))[3] { *tot= m_tvtot; return m_transverts; }
// virtual void InitDeform(double time){};
protected:
Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h 2009-07-25 22:57:29 UTC (rev 21908)
@@ -194,7 +194,7 @@
struct KX_ObjectProperties* objprop);
void KX_ClearBulletSharedShapes();
-//bool KX_ReInstanceShapeFromMesh(RAS_MeshObject* meshobj);
+bool KX_ReInstanceBulletShapeFromMesh(KX_GameObject *gameobj, KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj);
#endif
#endif //KX_CONVERTPHYSICSOBJECTS
Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp 2009-07-25 22:57:29 UTC (rev 21908)
@@ -1220,5 +1220,44 @@
{
}
+/* 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<KX_BulletPhysicsController*>((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
-
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-07-25 22:57:29 UTC (rev 21908)
@@ -66,6 +66,7 @@
#include "KX_PythonInit.h"
#include "KX_PyMath.h"
#include "KX_PythonSeq.h"
+#include "KX_ConvertPhysicsObject.h"
#include "SCA_IActuator.h"
#include "SCA_ISensor.h"
#include "SCA_IController.h"
@@ -1183,6 +1184,7 @@
{"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS},
{"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_O},
{"endObject",(PyCFunction) KX_GameObject::sPyEndObject, METH_NOARGS},
+ {"reinstancePhysicsMesh", (PyCFunction)KX_GameObject::sPyReinstancePhysicsMesh,METH_VARARGS},
KX_PYMETHODTABLE(KX_GameObject, rayCastTo),
KX_PYMETHODTABLE(KX_GameObject, rayCast),
@@ -1280,7 +1282,29 @@
}
+PyObject* KX_GameObject::PyReinstancePhysicsMesh(PyObject* args)
+{
+ KX_GameObject *gameobj= NULL;
+ RAS_MeshObject *mesh= NULL;
+
+ PyObject *gameobj_py= NULL;
+ PyObject *mesh_py= NULL;
+ if ( !PyArg_ParseTuple(args,"|OO:reinstancePhysicsMesh",&gameobj_py, &mesh_py) ||
+ (gameobj_py && !ConvertPythonToGameObject(gameobj_py, &gameobj, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject")) ||
+ (mesh_py && !ConvertPythonToMesh(mesh_py, &mesh, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject"))
+ ) {
+ return NULL;
+ }
+
+ /* gameobj and mesh can be NULL */
+ if(KX_ReInstanceBulletShapeFromMesh(this, gameobj, mesh))
+ Py_RETURN_TRUE;
+
+ Py_RETURN_FALSE;
+}
+
+
PyObject* KX_GameObject::PyGetPosition()
{
ShowDeprecationWarning("getPosition()", "the position property");
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-07-25 22:57:29 UTC (rev 21908)
@@ -872,6 +872,7 @@
KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo);
KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo);
KX_PYMETHOD_DOC_VARARGS(KX_GameObject, sendMessage);
+ KX_PYMETHOD_VARARGS(KX_GameObject, ReinstancePhysicsMesh);
/* Dict access */
KX_PYMETHOD_VARARGS(KX_GameObject,get);
Modified: trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp 2009-07-25 22:57:29 UTC (rev 21908)
@@ -87,7 +87,6 @@
{"getVertexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetVertexArrayLength,METH_VARARGS},
{"getVertex", (PyCFunction)KX_MeshProxy::sPyGetVertex,METH_VARARGS},
{"getPolygon", (PyCFunction)KX_MeshProxy::sPyGetPolygon,METH_VARARGS},
-KX_PYMETHODTABLE(KX_MeshProxy, reinstancePhysicsMesh),
//{"getIndexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetIndexArrayLength,METH_VARARGS},
{NULL,NULL} //Sentinel
@@ -262,17 +261,6 @@
return polyob;
}
-KX_PYMETHODDEF_DOC(KX_MeshProxy, reinstancePhysicsMesh,
-"Reinstance the physics mesh.")
-{
-#if 0
- //this needs to be reviewed, it is dependend on Sumo/Solid. Who is using this ?
- if(KX_ReInstanceShapeFromMesh(m_meshobj))
- Py_RETURN_TRUE;
-#endif
- Py_RETURN_FALSE;
-}
-
PyObject* KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_MeshProxy* self= static_cast<KX_MeshProxy*>(self_v);
Modified: trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h 2009-07-25 22:57:29 UTC (rev 21908)
@@ -69,7 +69,6 @@
KX_PYMETHOD(KX_MeshProxy,GetVertexArrayLength);
KX_PYMETHOD(KX_MeshProxy,GetVertex);
KX_PYMETHOD(KX_MeshProxy,GetPolygon);
- KX_PYMETHOD_DOC(KX_MeshProxy, reinstancePhysicsMesh);
static PyObject* pyattr_get_materials(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject * pyattr_get_numMaterials(void * self, const KX_PYATTRIBUTE_DEF * attrdef);
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 2009-07-25 22:53:25 UTC (rev 21907)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 2009-07-25 22:57:29 UTC (rev 21908)
@@ -22,6 +22,8 @@
#include "PHY_IMotionState.h"
#include "CcdPhysicsEnvironment.h"
#include "RAS_MeshObject.h"
+#include "KX_GameObject.h"
+
#include "BulletSoftBody/btSoftBody.h"
#include "BulletSoftBody//btSoftBodyInternals.h"
#include "BulletSoftBody/btSoftBodyHelpers.h"
@@ -529,7 +531,7 @@
}
-static void DeleteBulletShape(btCollisionShape* shape)
+static void DeleteBulletShape(btCollisionShape* shape, bool free)
{
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
@@ -539,21 +541,13 @@
if (meshInterface)
delete meshInterface;
}
- delete shape;
+ if(free) {
+ delete shape;
+ }
}
-CcdPhysicsController::~CcdPhysicsController()
+bool CcdPhysicsController::DeleteControllerShape( )
{
- //will be reference counted, due to sharing
- if (m_cci.m_physicsEnv)
- m_cci.m_physicsEnv->removeCcdPhysicsController(this);
-
- if (m_MotionState)
- delete m_MotionState;
- if (m_bulletMotionState)
- delete m_bulletMotionState;
- delete m_object;
-
if (m_collisionShape)
{
// collision shape is always unique to the controller, can delete it here
@@ -565,11 +559,64 @@
for (int i=numChild-1 ; i >= 0; i--)
{
btCollisionShape* childShape = compoundShape->getChildShape(i);
- DeleteBulletShape(childShape);
+ DeleteBulletShape(childShape, true);
}
}
- DeleteBulletShape(m_collisionShape);
+ DeleteBulletShape(m_collisionShape, true);
+
+ return true;
}
+
+ return false;
+}
+
+bool CcdPhysicsController::ReplaceControllerShape(btCollisionShape *newShape)
+{
+
+ /* Note, deleting the previous collision shape must be done alredy */
+ /* if (m_collisionShape) DeleteControllerShape(); */
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list