diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-07-26 03:16:45 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-07-26 03:16:45 +0400 |
commit | 777a0d78e79d25c385eac4dd4835f8ca65317b26 (patch) | |
tree | a3b5213e6ac6572ca966448044affec198b3e0e5 /source/gameengine/Ketsji | |
parent | 756488fbe2c0beaf205cb28d6f4ca1e62a64588a (diff) | |
parent | e9ca43521f99c6b9baf6d9278f85323086fcade2 (diff) |
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r21899:21908
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_ConvertPhysicsObject.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 41 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 24 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 1 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_MeshProxy.cpp | 12 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_MeshProxy.h | 1 |
6 files changed, 66 insertions, 15 deletions
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index 9d3b9cdaf74..147bd238009 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -164,7 +164,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, 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 diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 64b5760de28..04e82d21cf4 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -628,5 +628,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<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 diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index bf80eec36d9..75688a63530 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -66,6 +66,7 @@ typedef unsigned long uint_ptr; #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" @@ -1389,6 +1390,7 @@ PyMethodDef KX_GameObject::Methods[] = { {"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), @@ -1486,6 +1488,28 @@ PyObject* KX_GameObject::PyEndObject() } +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() { diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 947cc9959ff..118e17128f0 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -856,6 +856,7 @@ public: 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); diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 606ba0e16c2..ea9bc3e0fbc 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -84,7 +84,6 @@ PyMethodDef KX_MeshProxy::Methods[] = { {"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 @@ -243,17 +242,6 @@ PyObject* KX_MeshProxy::PyGetPolygon(PyObject* args, PyObject* kwds) 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); diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index 4b6543677ad..55684aa5ee9 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -66,7 +66,6 @@ public: 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); |