BGE API cleanup: ReplaceMeshActuator mesh attributes now returns a KX_MeshProxy....
authorBenoit Bolsee <benoit.bolsee@online.be>
Wed, 1 Apr 2009 08:59:36 +0000 (08:59 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Wed, 1 Apr 2009 08:59:36 +0000 (08:59 +0000)
source/gameengine/Ketsji/KX_MeshProxy.cpp
source/gameengine/Ketsji/KX_MeshProxy.h
source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py

index a0c0a496c064bf1b5484da6a20db4f53e9ae805b..f40c307315e2edbf24d09a404afceb91329129f0 100644 (file)
@@ -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)
 {
 }
 
index 34f60a54a3aa0f34e53accf59a30316be3ab13a4..9e08937de0726360fb17d715cc2651b2f0dbb5b8 100644 (file)
@@ -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);
index 2f971084a396df540eeea592f3d9162822184336..58d6f659135b28b1676d599f6170edb8546162d7 100644 (file)
@@ -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<KX_SCA_ReplaceMeshActuator*>(self);
        if (!actuator->m_mesh)
                Py_RETURN_NONE;
-       return PyString_FromString(const_cast<char *>(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<KX_SCA_ReplaceMeshActuator*>(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;
 }
index 1faf215ed56f1c35e1ebbed26d4ba1135b6f71ee..1013dd53cb966aa52680d5c1a9eabedeca8d0f86 100644 (file)
@@ -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):
                """