From 48e4a4834092a8772141e6240e5e70d67110f126 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 1 Apr 2009 08:59:36 +0000 Subject: BGE API cleanup: ReplaceMeshActuator mesh attributes now returns a KX_MeshProxy. Fix a bug in KX_MeshProxy where the Python type was not set right. --- source/gameengine/Ketsji/KX_MeshProxy.cpp | 2 +- source/gameengine/Ketsji/KX_MeshProxy.h | 1 + .../gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 19 +++++++++++-------- source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index a0c0a496c06..f40c307315e 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -124,7 +124,7 @@ KX_MeshProxy::_getattr(const char *attr) KX_MeshProxy::KX_MeshProxy(RAS_MeshObject* mesh) - : m_meshobj(mesh) + : SCA_IObject(&Type), m_meshobj(mesh) { } diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index 34f60a54a3a..9e08937de07 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -47,6 +47,7 @@ public: virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); virtual const STR_String & GetText(); virtual float GetNumber(); + virtual RAS_MeshObject* GetMesh() { return m_meshobj; } virtual STR_String GetName(); virtual void SetName(STR_String name); // Set the name of the value virtual void ReplicaSetName(STR_String name); diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 2f971084a39..58d6f659135 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -36,6 +36,7 @@ // Please look here for revision history. #include "KX_SCA_ReplaceMeshActuator.h" +#include "KX_MeshProxy.h" #include "PyObjectPlus.h" @@ -115,7 +116,8 @@ PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct K KX_SCA_ReplaceMeshActuator* actuator = static_cast(self); if (!actuator->m_mesh) Py_RETURN_NONE; - return PyString_FromString(const_cast(actuator->m_mesh->GetName().ReadPtr())); + KX_MeshProxy* meshproxy = new KX_MeshProxy(actuator->m_mesh); + return meshproxy; } int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) @@ -123,18 +125,19 @@ int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYAT KX_SCA_ReplaceMeshActuator* actuator = static_cast(self); if (value == Py_None) { actuator->m_mesh = NULL; - } else { - char* meshname = PyString_AsString(value); - if (!meshname) { - PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh or None"); - return 1; - } - void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname)); + } else if (PyString_Check(value)) { + void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(PyString_AsString(value))); if (mesh==NULL) { PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist"); return 1; } actuator->m_mesh= (class RAS_MeshObject*)mesh; + } else if PyObject_TypeCheck(value, &KX_MeshProxy::Type) { + KX_MeshProxy* proxy = (KX_MeshProxy*)value; + actuator->m_mesh= proxy->GetMesh(); + } else { + PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh, a mesh proxy or None"); + return 1; } return 0; } diff --git a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py index 1faf215ed56..1013dd53cb9 100644 --- a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py @@ -57,9 +57,9 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): C{ERROR: GameObject I{OBName} ReplaceMeshActuator I{ActuatorName} without object} Properties: - @ivar mesh: the name of the mesh that will replace the current one + @ivar mesh: L{KX_MeshProxy} or the name of the mesh that will replace the current one Set to None to disable actuator - @type mesh: string or None if no mesh is set + @type mesh: L{KX_MeshProxy} or None if no mesh is set """ def setMesh(name): """ -- cgit v1.2.3