mesh proxy attributes from andrecastelo
authorCampbell Barton <ideasman42@gmail.com>
Mon, 13 Apr 2009 03:43:16 +0000 (03:43 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 13 Apr 2009 03:43:16 +0000 (03:43 +0000)
source/gameengine/Ketsji/KX_MeshProxy.cpp
source/gameengine/Ketsji/KX_MeshProxy.h
source/gameengine/PyDoc/KX_MeshProxy.py

index e7f562bda8e367ce6de921c7b224aff0e2da02cd..0710d301c14b7b2185f49c374b30d85c8eaae8dd 100644 (file)
@@ -73,8 +73,11 @@ PyParentObject KX_MeshProxy::Parents[] = {
 };
 
 PyMethodDef KX_MeshProxy::Methods[] = {
+// Deprecated ----->
 {"getNumMaterials", (PyCFunction)KX_MeshProxy::sPyGetNumMaterials,METH_VARARGS},
 {"getNumPolygons", (PyCFunction)KX_MeshProxy::sPyGetNumPolygons,METH_NOARGS},
+// <-----
+
 {"getMaterialName", (PyCFunction)KX_MeshProxy::sPyGetMaterialName,METH_VARARGS},
 {"getTextureName", (PyCFunction)KX_MeshProxy::sPyGetTextureName,METH_VARARGS},
 {"getVertexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetVertexArrayLength,METH_VARARGS},
@@ -88,6 +91,9 @@ KX_PYMETHODTABLE(KX_MeshProxy, reinstancePhysicsMesh),
 
 PyAttributeDef KX_MeshProxy::Attributes[] = {
        KX_PYATTRIBUTE_RO_FUNCTION("materials",         KX_MeshProxy, pyattr_get_materials),
+       KX_PYATTRIBUTE_RO_FUNCTION("numPolygons",       KX_MeshProxy, pyattr_get_materials),
+       KX_PYATTRIBUTE_RO_FUNCTION("numMaterials",      KX_MeshProxy, pyattr_get_materials),
+
        { NULL }        //Sentinel
 };
 
@@ -102,6 +108,10 @@ PyObject* KX_MeshProxy::py_getattro(PyObject *attr)
        py_getattro_up(SCA_IObject);
 }
 
+int KX_MeshProxy::py_setattro(PyObject *attr, PyObject* value)
+{
+       py_setattro_up(SCA_IObject);
+}
 
 
 KX_MeshProxy::KX_MeshProxy(RAS_MeshObject* mesh)
@@ -134,12 +144,14 @@ PyObject* KX_MeshProxy::PyGetNumMaterials(PyObject* self,
                               PyObject* kwds)
 {
        int num = m_meshobj->NumMaterials();
+       ShowDeprecationWarning("getNumMaterials()", "the numMaterials property");
        return PyInt_FromLong(num);
 }
 
 PyObject* KX_MeshProxy::PyGetNumPolygons(PyObject* self)
 {
        int num = m_meshobj->NumPolygons();
+       ShowDeprecationWarning("getNumPolygons()", "the numPolygons property");
        return PyInt_FromLong(num);
 }
 
@@ -296,3 +308,15 @@ PyObject* KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_
        }       
        return materials;
 }
+
+PyObject * KX_MeshProxy::pyattr_get_numMaterials(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) {
+       KX_MeshProxy * self = static_cast<KX_MeshProxy *> (selfv);
+       int num = self->m_meshobj->NumMaterials();
+       return PyInt_FromLong(num);
+}
+
+PyObject * KX_MeshProxy::pyattr_get_numPolygons(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) {
+       KX_MeshProxy * self = static_cast<KX_MeshProxy *> (selfv);
+       int num = self->m_meshobj->NumPolygons();
+       return PyInt_FromLong(num);
+}
index 3b72099eebbe999066cefddb3cad647422d9c033..dfc498801a743656d6e82954a98f712a8e427e6d 100644 (file)
@@ -55,10 +55,12 @@ public:
 
 // stuff for python integration
        virtual PyObject*  py_getattro(PyObject *attr);
-       KX_PYMETHOD(KX_MeshProxy,GetNumMaterials);
+       virtual int py_setattro(PyObject *attr, PyObject* value);
+
+       KX_PYMETHOD(KX_MeshProxy,GetNumMaterials);      // Deprecated
        KX_PYMETHOD(KX_MeshProxy,GetMaterialName);
        KX_PYMETHOD(KX_MeshProxy,GetTextureName);
-       KX_PYMETHOD_NOARGS(KX_MeshProxy,GetNumPolygons);
+       KX_PYMETHOD_NOARGS(KX_MeshProxy,GetNumPolygons); // Deprecated
        
        // both take materialid (int)
        KX_PYMETHOD(KX_MeshProxy,GetVertexArrayLength);
@@ -67,6 +69,8 @@ public:
        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);
+       static PyObject * pyattr_get_numPolygons(void * self, const KX_PYATTRIBUTE_DEF * attrdef);
 };
 
 #endif //__KX_MESHPROXY
index c6855d3b0a5a3fb94da0b5a327e462dd8da8c213..e8839ac484c59a514f49496fe3ee2afab3189aea 100644 (file)
@@ -47,6 +47,12 @@ class KX_MeshProxy:
        
        @ivar materials: 
        @type materials: list of L{KX_BlenderMaterial} or L{KX_PolygonMaterial} types
+
+       @ivar numPolygons:
+       @type numPolygons: integer
+
+       @ivar numMaterials:
+       @type numMaterials: integer
        """
        
        def getNumMaterials():