[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19539] trunk/blender/source/gameengine: Made KX_MeshProxy use PyAttributeDef.
Campbell Barton
ideasman42 at gmail.com
Sat Apr 4 17:54:08 CEST 2009
Revision: 19539
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19539
Author: campbellbarton
Date: 2009-04-04 17:54:07 +0200 (Sat, 04 Apr 2009)
Log Message:
-----------
Made KX_MeshProxy use PyAttributeDef. simplified getting the 'materials' attribute (no need to differentiate between types)
Added KX_GameObject 'meshes' attribute to replace getMesh(i)
Modified Paths:
--------------
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp
trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h
trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-04 15:26:12 UTC (rev 19538)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-04 15:54:07 UTC (rev 19539)
@@ -1009,7 +1009,6 @@
{"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS},
{"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS},
{"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS},
- {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS},
{"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS},
{"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS},
{"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_O},
@@ -1030,6 +1029,7 @@
{"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS},
{"getVisible",(PyCFunction) KX_GameObject::sPyGetVisible, METH_NOARGS},
{"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_NOARGS},
+ {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS},
{NULL,NULL} //Sentinel
};
@@ -1043,6 +1043,7 @@
KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_scaling, pyattr_set_scaling),
KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset),
KX_PYATTRIBUTE_RW_FUNCTION("state", KX_GameObject, pyattr_get_state, pyattr_set_state),
+ KX_PYATTRIBUTE_RO_FUNCTION("meshes", KX_GameObject, pyattr_get_meshes),
KX_PYATTRIBUTE_RO_FUNCTION("__dict__", KX_GameObject, pyattr_get_dir_dict),
{NULL} //Sentinel
};
@@ -1416,6 +1417,22 @@
return 0;
}
+PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+ PyObject *meshes= PyList_New(self->m_meshes.size());
+ int i;
+
+ for(i=0; i < self->m_meshes.size(); i++)
+ {
+ KX_MeshProxy* meshproxy = new KX_MeshProxy(self->m_meshes[i]);
+ PyList_SET_ITEM(meshes, i, meshproxy);
+ }
+
+ return meshes;
+}
+
+
/* __dict__ only for the purpose of giving useful dir() results */
PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
@@ -1758,6 +1775,8 @@
PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args)
{
+ ShowDeprecationWarning("getMesh()", "the meshes property");
+
int mesh = 0;
if (!PyArg_ParseTuple(args, "|i:getMesh", &mesh))
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-04-04 15:26:12 UTC (rev 19538)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-04-04 15:54:07 UTC (rev 19539)
@@ -821,10 +821,13 @@
static int pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+ static PyObject* pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
/* for dir(), python3 uses __dir__() */
static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+
+
/* getitem/setitem */
static Py_ssize_t Map_Len(PyObject* self);
static PyMappingMethods Mapping;
Modified: trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp 2009-04-04 15:26:12 UTC (rev 19538)
+++ trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp 2009-04-04 15:54:07 UTC (rev 19539)
@@ -87,6 +87,7 @@
};
PyAttributeDef KX_MeshProxy::Attributes[] = {
+ KX_PYATTRIBUTE_RO_FUNCTION("materials", KX_MeshProxy, pyattr_get_materials),
{ NULL } //Sentinel
};
@@ -96,30 +97,12 @@
}
-PyObject*
-KX_MeshProxy::py_getattro(PyObject *attr)
+PyObject* KX_MeshProxy::py_getattro(PyObject *attr)
{
- char *attr_str= PyString_AsString(attr);
+ PyObject* object = py_getattro_self(Attributes, this, attr);
+ if (object != NULL)
+ return object;
- if (!strcmp(attr_str, "materials"))
- {
- PyObject *materials = PyList_New(0);
- list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial();
- for(; mit != m_meshobj->GetLastMaterial(); ++mit)
- {
- RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial();
-
- if(polymat->GetFlag() & RAS_BLENDERMAT)
- {
- KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial*>(polymat);
- PyList_Append(materials, mat);
- }else
- {
- PyList_Append(materials, static_cast<KX_PolygonMaterial*>(polymat));
- }
- }
- return materials;
- }
py_getattro_up(SCA_IObject);
}
@@ -280,3 +263,23 @@
//this needs to be reviewed, it is dependend on Sumo/Solid. Who is using this ?
Py_RETURN_NONE;//(KX_ReInstanceShapeFromMesh(m_meshobj)) ? Py_RETURN_TRUE : 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);
+
+ int tot= self->m_meshobj->NumMaterials();
+ int i;
+
+ PyObject *materials = PyList_New( tot );
+
+ list<RAS_MeshMaterial>::iterator mit= self->m_meshobj->GetFirstMaterial();
+
+ /* Can be a KX_PolygonMaterial or KX_BlenderMaterial, since both are cast to a PyObject * we dont need to care */
+ for(i=0; i<tot; mit++, i++) {
+ PyObject *py_mat = (PyObject *)mit->m_bucket->GetPolyMaterial();
+ PyList_SET_ITEM(materials, i, py_mat);
+ Py_INCREF(py_mat);
+ }
+ return materials;
+}
Modified: trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h 2009-04-04 15:26:12 UTC (rev 19538)
+++ trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h 2009-04-04 15:54:07 UTC (rev 19539)
@@ -65,6 +65,8 @@
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);
};
#endif //__KX_MESHPROXY
Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2009-04-04 15:26:12 UTC (rev 19538)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2009-04-04 15:54:07 UTC (rev 19539)
@@ -26,6 +26,9 @@
@type timeOffset: float
@ivar state: the game object's state bitmask.
@type state: int
+ @ivar meshes: a list of L{KX_MeshProxy} objects.
+ B{Note}: Changes to this list will not update the KX_GameObject
+ @type meshes: list
"""
def endObject(visible):
"""
More information about the Bf-blender-cvs
mailing list