Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObject.h2
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp41
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp24
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h1
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.cpp12
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.h1
6 files changed, 66 insertions, 15 deletions
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
index 74042366bae..cf50e0ccd06 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
@@ -194,7 +194,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 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<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 b266095c715..36a9efe5b91 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"
@@ -1183,6 +1184,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),
@@ -1280,6 +1282,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 ff5c8a01e6e..d2450d342c1 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -872,6 +872,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 ee5813ad854..c6989a81c6d 100644
--- a/source/gameengine/Ketsji/KX_MeshProxy.cpp
+++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp
@@ -87,7 +87,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
@@ -262,17 +261,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 bfdd4be4118..cbdce3c2745 100644
--- a/source/gameengine/Ketsji/KX_MeshProxy.h
+++ b/source/gameengine/Ketsji/KX_MeshProxy.h
@@ -69,7 +69,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);