Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_MeshProxy.cpp
| Context not available. | |||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| #include "KX_MeshProxy.h" | #include "KX_MeshProxy.h" | ||||
| #include "KX_Scene.h" | |||||
| #include "RAS_IPolygonMaterial.h" | #include "RAS_IPolygonMaterial.h" | ||||
| #include "RAS_DisplayArray.h" | |||||
| #include "RAS_MeshObject.h" | #include "RAS_MeshObject.h" | ||||
| #include "RAS_BucketManager.h" | |||||
| #include "SCA_LogicManager.h" | |||||
| #include "KX_VertexProxy.h" | #include "KX_VertexProxy.h" | ||||
| #include "KX_PolyProxy.h" | #include "KX_PolyProxy.h" | ||||
| Context not available. | |||||
| #include "SCA_LogicManager.h" | #include "SCA_LogicManager.h" | ||||
| #include "EXP_PyObjectPlus.h" | #include "EXP_PyObjectPlus.h" | ||||
| #include "EXP_ListWrapper.h" | |||||
| PyTypeObject KX_MeshProxy::Type = { | PyTypeObject KX_MeshProxy::Type = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | ||||
| Context not available. | |||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0, 0, 0, 0, 0, 0, 0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &CValue::Type, | &CValue::Type, | ||||
| 0,0,0,0,0,0, | 0, 0, 0, 0, 0, 0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef KX_MeshProxy::Methods[] = { | PyMethodDef KX_MeshProxy::Methods[] = { | ||||
| {"getMaterialName", (PyCFunction)KX_MeshProxy::sPyGetMaterialName,METH_VARARGS}, | {"getMaterialName", (PyCFunction) KX_MeshProxy::sPyGetMaterialName, METH_VARARGS}, | ||||
| {"getTextureName", (PyCFunction)KX_MeshProxy::sPyGetTextureName,METH_VARARGS}, | {"getTextureName", (PyCFunction) KX_MeshProxy::sPyGetTextureName, METH_VARARGS}, | ||||
| {"getVertexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetVertexArrayLength,METH_VARARGS}, | {"getVertexArrayLength", (PyCFunction) KX_MeshProxy::sPyGetVertexArrayLength, METH_VARARGS}, | ||||
| {"getVertex", (PyCFunction)KX_MeshProxy::sPyGetVertex,METH_VARARGS}, | {"getVertex", (PyCFunction) KX_MeshProxy::sPyGetVertex, METH_VARARGS}, | ||||
| {"getPolygon", (PyCFunction)KX_MeshProxy::sPyGetPolygon,METH_VARARGS}, | {"getPolygon", (PyCFunction) KX_MeshProxy::sPyGetPolygon, METH_VARARGS}, | ||||
| {"transform", (PyCFunction)KX_MeshProxy::sPyTransform,METH_VARARGS}, | {"transform", (PyCFunction) KX_MeshProxy::sPyTransform, METH_VARARGS}, | ||||
| {"transformUV", (PyCFunction)KX_MeshProxy::sPyTransformUV,METH_VARARGS}, | {"transformUV", (PyCFunction) KX_MeshProxy::sPyTransformUV, METH_VARARGS}, | ||||
| //{"getIndexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetIndexArrayLength,METH_VARARGS}, | {"replaceMaterial", (PyCFunction) KX_MeshProxy::sPyReplaceMaterial, METH_VARARGS}, | ||||
| {NULL,NULL} //Sentinel | {NULL, NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef KX_MeshProxy::Attributes[] = { | PyAttributeDef KX_MeshProxy::Attributes[] = { | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("materials", KX_MeshProxy, pyattr_get_materials), | KX_PYATTRIBUTE_RO_FUNCTION("materials", KX_MeshProxy, pyattr_get_materials), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("numPolygons", KX_MeshProxy, pyattr_get_numPolygons), | KX_PYATTRIBUTE_RO_FUNCTION("numPolygons", KX_MeshProxy, pyattr_get_numPolygons), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("numMaterials", KX_MeshProxy, pyattr_get_numMaterials), | KX_PYATTRIBUTE_RO_FUNCTION("numMaterials", KX_MeshProxy, pyattr_get_numMaterials), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("polygons", KX_MeshProxy, pyattr_get_polygons), | |||||
| { NULL } //Sentinel | KX_PYATTRIBUTE_NULL //Sentinel | ||||
| }; | }; | ||||
| void KX_MeshProxy::SetMeshModified(bool v) | KX_MeshProxy::KX_MeshProxy(RAS_MeshObject *mesh) | ||||
| { | :CValue(), | ||||
| m_meshobj->SetMeshModified(v); | m_meshobj(mesh) | ||||
| } | |||||
| KX_MeshProxy::KX_MeshProxy(RAS_MeshObject* mesh) | |||||
| : CValue(), m_meshobj(mesh) | |||||
| { | { | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| } | } | ||||
| // stuff for cvalue related things | // stuff for cvalue related things | ||||
| CValue* KX_MeshProxy::Calc(VALUE_OPERATOR op, CValue *val) { return NULL;} | std::string KX_MeshProxy::GetName() | ||||
| CValue* KX_MeshProxy::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) { return NULL;} | { | ||||
| return m_meshobj->GetName(); | |||||
| const STR_String & KX_MeshProxy::GetText() {return m_meshobj->GetName();}; | } | ||||
| double KX_MeshProxy::GetNumber() { return -1;} | |||||
| STR_String& KX_MeshProxy::GetName() { return m_meshobj->GetName();} | |||||
| void KX_MeshProxy::SetName(const char *name) { }; | |||||
| CValue* KX_MeshProxy::GetReplica() { return NULL;} | |||||
| // stuff for python integration | // stuff for python integration | ||||
| static int kx_mesh_proxy_get_polygons_size_cb(void *self_v) | |||||
| { | |||||
| return ((KX_MeshProxy *)self_v)->GetMesh()->NumPolygons(); | |||||
| } | |||||
| static PyObject *kx_mesh_proxy_get_polygons_item_cb(void *self_v, int index) | |||||
| { | |||||
| KX_MeshProxy *self = static_cast<KX_MeshProxy *>(self_v); | |||||
| RAS_MeshObject *mesh = self->GetMesh(); | |||||
| RAS_Polygon *polygon = mesh->GetPolygon(index); | |||||
| PyObject *polyob = (new KX_PolyProxy(self, mesh, polygon))->NewProxy(true); | |||||
| return polyob; | |||||
| } | |||||
| PyObject *KX_MeshProxy::PyGetMaterialName(PyObject *args, PyObject *kwds) | PyObject *KX_MeshProxy::PyGetMaterialName(PyObject *args, PyObject *kwds) | ||||
| { | { | ||||
| int matid= 1; | int matid = 1; | ||||
| STR_String matname; | std::string matname; | ||||
| if (PyArg_ParseTuple(args,"i:getMaterialName",&matid)) | if (PyArg_ParseTuple(args, "i:getMaterialName", &matid)) { | ||||
| { | |||||
| matname = m_meshobj->GetMaterialName(matid); | matname = m_meshobj->GetMaterialName(matid); | ||||
| } | } | ||||
| else { | else { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| return PyUnicode_From_STR_String(matname); | return PyUnicode_FromStdString(matname); | ||||
| } | } | ||||
| PyObject *KX_MeshProxy::PyGetTextureName(PyObject *args, PyObject *kwds) | PyObject *KX_MeshProxy::PyGetTextureName(PyObject *args, PyObject *kwds) | ||||
| { | { | ||||
| int matid= 1; | int matid = 1; | ||||
| STR_String matname; | std::string matname; | ||||
| if (PyArg_ParseTuple(args,"i:getTextureName",&matid)) | if (PyArg_ParseTuple(args, "i:getTextureName", &matid)) { | ||||
| { | |||||
| matname = m_meshobj->GetTextureName(matid); | matname = m_meshobj->GetTextureName(matid); | ||||
| } | } | ||||
| else { | else { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| return PyUnicode_From_STR_String(matname); | return PyUnicode_FromStdString(matname); | ||||
| } | } | ||||
| PyObject *KX_MeshProxy::PyGetVertexArrayLength(PyObject *args, PyObject *kwds) | PyObject *KX_MeshProxy::PyGetVertexArrayLength(PyObject *args, PyObject *kwds) | ||||
| { | { | ||||
| int matid= 0; | int matid = 0; | ||||
| int length = 0; | int length = 0; | ||||
| if (!PyArg_ParseTuple(args, "i:getVertexArrayLength", &matid)) | |||||
| if (!PyArg_ParseTuple(args,"i:getVertexArrayLength",&matid)) | |||||
| return NULL; | return NULL; | ||||
| RAS_MeshMaterial *mmat = m_meshobj->GetMeshMaterial(matid); /* can be NULL*/ | RAS_MeshMaterial *mmat = m_meshobj->GetMeshMaterial(matid); /* can be NULL*/ | ||||
| if (mmat) | if (mmat) { | ||||
| { | RAS_IDisplayArray *array = mmat->m_baseslot->GetDisplayArray(); | ||||
| RAS_IPolyMaterial* mat = mmat->m_bucket->GetPolyMaterial(); | if (array) { | ||||
| if (mat) | length = array->GetVertexCount(); | ||||
| length = m_meshobj->NumVertices(mat); | } | ||||
| } | } | ||||
| return PyLong_FromLong(length); | return PyLong_FromLong(length); | ||||
| } | } | ||||
| PyObject *KX_MeshProxy::PyGetVertex(PyObject *args, PyObject *kwds) | PyObject *KX_MeshProxy::PyGetVertex(PyObject *args, PyObject *kwds) | ||||
| { | { | ||||
| int vertexindex; | int vertexindex; | ||||
| int matindex; | int matindex; | ||||
| if (!PyArg_ParseTuple(args,"ii:getVertex",&matindex,&vertexindex)) | if (!PyArg_ParseTuple(args, "ii:getVertex", &matindex, &vertexindex)) | ||||
| return NULL; | return NULL; | ||||
| RAS_TexVert* vertex = m_meshobj->GetVertex(matindex,vertexindex); | RAS_IDisplayArray *array = m_meshobj->GetDisplayArray(matindex); | ||||
| if (vertexindex < 0 || vertexindex >= array->GetVertexCount()) { | |||||
| if (vertex==NULL) { | |||||
| PyErr_SetString(PyExc_ValueError, "mesh.getVertex(mat_idx, vert_idx): KX_MeshProxy, could not get a vertex at the given indices"); | PyErr_SetString(PyExc_ValueError, "mesh.getVertex(mat_idx, vert_idx): KX_MeshProxy, could not get a vertex at the given indices"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| return (new KX_VertexProxy(this, vertex))->NewProxy(true); | RAS_ITexVert *vertex = array->GetVertex(vertexindex); | ||||
| return (new KX_VertexProxy(array, vertex))->NewProxy(true); | |||||
| } | } | ||||
| PyObject *KX_MeshProxy::PyGetPolygon(PyObject *args, PyObject *kwds) | PyObject *KX_MeshProxy::PyGetPolygon(PyObject *args, PyObject *kwds) | ||||
| { | { | ||||
| int polyindex= 1; | int polyindex = 1; | ||||
| PyObject *polyob = NULL; | PyObject *polyob = NULL; | ||||
| if (!PyArg_ParseTuple(args,"i:getPolygon",&polyindex)) | if (!PyArg_ParseTuple(args, "i:getPolygon", &polyindex)) | ||||
| return NULL; | return NULL; | ||||
| if (polyindex<0 || polyindex >= m_meshobj->NumPolygons()) | if (polyindex < 0 || polyindex >= m_meshobj->NumPolygons()) { | ||||
| { | |||||
| PyErr_SetString(PyExc_AttributeError, "mesh.getPolygon(int): KX_MeshProxy, invalid polygon index"); | PyErr_SetString(PyExc_AttributeError, "mesh.getPolygon(int): KX_MeshProxy, invalid polygon index"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| RAS_Polygon* polygon = m_meshobj->GetPolygon(polyindex); | RAS_Polygon *polygon = m_meshobj->GetPolygon(polyindex); | ||||
| if (polygon) | if (polygon) { | ||||
| { | polyob = (new KX_PolyProxy(this, m_meshobj, polygon))->NewProxy(true); | ||||
| polyob = (new KX_PolyProxy(m_meshobj, polygon))->NewProxy(true); | |||||
| } | } | ||||
| else { | else { | ||||
| PyErr_SetString(PyExc_AttributeError, "mesh.getPolygon(int): KX_MeshProxy, polygon is NULL, unknown reason"); | PyErr_SetString(PyExc_AttributeError, "mesh.getPolygon(int): KX_MeshProxy, polygon is NULL, unknown reason"); | ||||
| Context not available. | |||||
| MT_Matrix4x4 transform; | MT_Matrix4x4 transform; | ||||
| if (!PyArg_ParseTuple(args,"iO:transform", &matindex, &pymat) || | if (!PyArg_ParseTuple(args, "iO:transform", &matindex, &pymat) || | ||||
| !PyMatTo(pymat, transform)) | !PyMatTo(pymat, transform)) | ||||
| { | { | ||||
| return NULL; | return NULL; | ||||
| Context not available. | |||||
| /* transform mesh verts */ | /* transform mesh verts */ | ||||
| unsigned int mit_index = 0; | unsigned int mit_index = 0; | ||||
| for (list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial(); | for (std::vector<RAS_MeshMaterial *>::iterator mit = m_meshobj->GetFirstMaterial(); | ||||
| (mit != m_meshobj->GetLastMaterial()); | (mit != m_meshobj->GetLastMaterial()); | ||||
| ++mit, ++mit_index) | ++mit, ++mit_index) | ||||
| { | { | ||||
| Context not available. | |||||
| continue; | continue; | ||||
| } | } | ||||
| RAS_MeshSlot *slot = mit->m_baseslot; | RAS_MeshSlot *slot = (*mit)->m_baseslot; | ||||
| RAS_MeshSlot::iterator it; | RAS_IDisplayArray *array = slot->GetDisplayArray(); | ||||
| ok = true; | ok = true; | ||||
| for (slot->begin(it); !slot->end(it); slot->next(it)) { | for (unsigned int i = 0, size = array->GetVertexCount(); i < size; ++i) { | ||||
| size_t i; | RAS_ITexVert *vert = array->GetVertex(i); | ||||
| for (i = it.startvertex; i < it.endvertex; i++) { | vert->Transform(transform, ntransform); | ||||
| RAS_TexVert *vert = &it.vertex[i]; | |||||
| vert->Transform(transform, ntransform); | |||||
| } | |||||
| } | } | ||||
| array->AppendModifiedFlag(RAS_IDisplayArray::POSITION_MODIFIED | | |||||
| RAS_IDisplayArray::NORMAL_MODIFIED | | |||||
| RAS_IDisplayArray::TANGENT_MODIFIED); | |||||
| /* if we set a material index, quit when done */ | /* if we set a material index, quit when done */ | ||||
| if (matindex == mit_index) { | if (matindex == mit_index) { | ||||
| break; | break; | ||||
| Context not available. | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| m_meshobj->SetMeshModified(true); | |||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| Context not available. | |||||
| MT_Matrix4x4 transform; | MT_Matrix4x4 transform; | ||||
| if (!PyArg_ParseTuple(args,"iO|iii:transformUV", &matindex, &pymat, &uvindex, &uvindex_from) || | if (!PyArg_ParseTuple(args, "iO|iii:transformUV", &matindex, &pymat, &uvindex, &uvindex_from) || | ||||
| !PyMatTo(pymat, transform)) | !PyMatTo(pymat, transform)) | ||||
| { | { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (uvindex < -1 || uvindex > 1) { | if (uvindex < -1 || uvindex > RAS_Texture::MaxUnits) { | ||||
| PyErr_Format(PyExc_ValueError, | PyErr_Format(PyExc_ValueError, | ||||
| "mesh.transformUV(...): invalid uv_index %d", uvindex); | "mesh.transformUV(...): invalid uv_index %d", uvindex); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (uvindex_from < -1 || uvindex_from > 1) { | if (uvindex_from < -1 || uvindex_from > RAS_Texture::MaxUnits) { | ||||
| PyErr_Format(PyExc_ValueError, | PyErr_Format(PyExc_ValueError, | ||||
| "mesh.transformUV(...): invalid uv_index_from %d", uvindex); | "mesh.transformUV(...): invalid uv_index_from %d", uvindex); | ||||
| return NULL; | return NULL; | ||||
| Context not available. | |||||
| /* transform mesh verts */ | /* transform mesh verts */ | ||||
| unsigned int mit_index = 0; | unsigned int mit_index = 0; | ||||
| for (list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial(); | for (std::vector<RAS_MeshMaterial *>::iterator mit = m_meshobj->GetFirstMaterial(); | ||||
| (mit != m_meshobj->GetLastMaterial()); | (mit != m_meshobj->GetLastMaterial()); | ||||
| ++mit, ++mit_index) | ++mit, ++mit_index) | ||||
| { | { | ||||
| Context not available. | |||||
| continue; | continue; | ||||
| } | } | ||||
| RAS_MeshSlot *slot = mit->m_baseslot; | RAS_MeshSlot *slot = (*mit)->m_baseslot; | ||||
| RAS_MeshSlot::iterator it; | RAS_IDisplayArray *array = slot->GetDisplayArray(); | ||||
| ok = true; | ok = true; | ||||
| for (slot->begin(it); !slot->end(it); slot->next(it)) { | for (unsigned int i = 0, size = array->GetVertexCount(); i < size; ++i) { | ||||
| size_t i; | RAS_ITexVert *vert = array->GetVertex(i); | ||||
| if (uvindex_from != -1) { | |||||
| for (i = it.startvertex; i < it.endvertex; i++) { | vert->SetUV(uvindex, vert->getUV(uvindex_from)); | ||||
| RAS_TexVert *vert = &it.vertex[i]; | } | ||||
| if (uvindex_from != -1) { | |||||
| if (uvindex_from == 0) vert->SetUV(1, vert->getUV(0)); | |||||
| else vert->SetUV(0, vert->getUV(1)); | |||||
| } | |||||
| switch (uvindex) { | if (uvindex >= 0) { | ||||
| case 0: | vert->TransformUV(uvindex, transform); | ||||
| vert->TransformUV(0, transform); | } | ||||
| break; | else if (uvindex == -1) { | ||||
| case 1: | for (int i = 0; i < RAS_Texture::MaxUnits; ++i) { | ||||
| vert->TransformUV(1, transform); | vert->TransformUV(i, transform); | ||||
| break; | |||||
| case -1: | |||||
| vert->TransformUV(0, transform); | |||||
| vert->TransformUV(1, transform); | |||||
| break; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| array->AppendModifiedFlag(RAS_IDisplayArray::UVS_MODIFIED); | |||||
| /* if we set a material index, quit when done */ | /* if we set a material index, quit when done */ | ||||
| if (matindex == mit_index) { | if (matindex == mit_index) { | ||||
| break; | break; | ||||
| Context not available. | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| m_meshobj->SetMeshModified(true); | Py_RETURN_NONE; | ||||
| } | |||||
| PyObject *KX_MeshProxy::PyReplaceMaterial(PyObject *args, PyObject *kwds) | |||||
| { | |||||
| unsigned short matindex; | |||||
| PyObject *pymat; | |||||
| KX_BlenderMaterial *mat; | |||||
| if (!PyArg_ParseTuple(args, "hO:replaceMaterial", &matindex, &pymat) || | |||||
| !ConvertPythonToMaterial(pymat, &mat, false, "mesh.replaceMaterial(...): invalid material")) { | |||||
| return NULL; | |||||
| } | |||||
| RAS_MeshMaterial *meshmat = m_meshobj->GetMeshMaterial(matindex); | |||||
| if (!meshmat) { | |||||
| PyErr_Format(PyExc_ValueError, "Invalid material index %d", matindex); | |||||
| return NULL; | |||||
| } | |||||
| KX_Scene *scene = (KX_Scene *)meshmat->m_bucket->GetPolyMaterial()->GetScene(); | |||||
| if (scene != mat->GetScene()) { | |||||
| PyErr_Format(PyExc_ValueError, "Mesh successor scene doesn't match current mesh scene"); | |||||
| return NULL; | |||||
| } | |||||
| RAS_BucketManager *bucketmgr = scene->GetBucketManager(); | |||||
| bool created = false; | |||||
| RAS_MaterialBucket *bucket = bucketmgr->FindBucket(mat, created); | |||||
| // Must never create the material bucket. | |||||
| BLI_assert(created == false); | |||||
| // Avoid replacing the by the same material bucket. | |||||
| if (meshmat->m_bucket != bucket) { | |||||
| meshmat->m_bucket->MoveDisplayArrayBucket(meshmat, bucket); | |||||
| meshmat->m_bucket = bucket; | |||||
| } | |||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| PyObject *KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_MeshProxy* self = static_cast<KX_MeshProxy*>(self_v); | KX_MeshProxy *self = static_cast<KX_MeshProxy *>(self_v); | ||||
| int tot= self->m_meshobj->NumMaterials(); | int tot = self->m_meshobj->NumMaterials(); | ||||
| int i; | int i; | ||||
| PyObject *materials = PyList_New( tot ); | PyObject *materials = PyList_New(tot); | ||||
| list<RAS_MeshMaterial>::iterator mit= self->m_meshobj->GetFirstMaterial(); | std::vector<RAS_MeshMaterial *>::iterator mit = self->m_meshobj->GetFirstMaterial(); | ||||
| for (i = 0; i < tot; mit++, i++) { | |||||
| for (i=0; i<tot; mit++, i++) { | RAS_IPolyMaterial *polymat = (*mit)->m_bucket->GetPolyMaterial(); | ||||
| RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial(); | |||||
| KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial *>(polymat); | KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial *>(polymat); | ||||
| PyList_SET_ITEM(materials, i, mat->GetProxy()); | PyList_SET_ITEM(materials, i, mat->GetProxy()); | ||||
| } | } | ||||
| Context not available. | |||||
| PyObject *KX_MeshProxy::pyattr_get_numMaterials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *KX_MeshProxy::pyattr_get_numMaterials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_MeshProxy * self = static_cast<KX_MeshProxy *> (self_v); | KX_MeshProxy *self = static_cast<KX_MeshProxy *> (self_v); | ||||
| return PyLong_FromLong(self->m_meshobj->NumMaterials()); | return PyLong_FromLong(self->m_meshobj->NumMaterials()); | ||||
| } | } | ||||
| PyObject *KX_MeshProxy::pyattr_get_numPolygons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *KX_MeshProxy::pyattr_get_numPolygons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_MeshProxy * self = static_cast<KX_MeshProxy *> (self_v); | KX_MeshProxy *self = static_cast<KX_MeshProxy *> (self_v); | ||||
| return PyLong_FromLong(self->m_meshobj->NumPolygons()); | return PyLong_FromLong(self->m_meshobj->NumPolygons()); | ||||
| } | } | ||||
| PyObject *KX_MeshProxy::pyattr_get_polygons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | |||||
| { | |||||
| return (new CListWrapper(self_v, | |||||
| ((KX_MeshProxy *)self_v)->GetProxy(), | |||||
| NULL, | |||||
| kx_mesh_proxy_get_polygons_size_cb, | |||||
| kx_mesh_proxy_get_polygons_item_cb, | |||||
| NULL, | |||||
| NULL))->NewProxy(true); | |||||
| } | |||||
| /* a close copy of ConvertPythonToGameObject but for meshes */ | /* a close copy of ConvertPythonToGameObject but for meshes */ | ||||
| bool ConvertPythonToMesh(SCA_LogicManager *logicmgr, PyObject *value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix) | bool ConvertPythonToMesh(SCA_LogicManager *logicmgr, PyObject *value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix) | ||||
| { | { | ||||
| if (value==NULL) { | if (value == NULL) { | ||||
| PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix); | PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix); | ||||
| *object = NULL; | *object = NULL; | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (value==Py_None) { | if (value == Py_None) { | ||||
| *object = NULL; | *object = NULL; | ||||
| if (py_none_ok) { | if (py_none_ok) { | ||||
| return true; | return true; | ||||
| } else { | } | ||||
| else { | |||||
| PyErr_Format(PyExc_TypeError, "%s, expected KX_MeshProxy or a KX_MeshProxy name, None is invalid", error_prefix); | PyErr_Format(PyExc_TypeError, "%s, expected KX_MeshProxy or a KX_MeshProxy name, None is invalid", error_prefix); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| if (PyUnicode_Check(value)) { | if (PyUnicode_Check(value)) { | ||||
| *object = (RAS_MeshObject*)logicmgr->GetMeshByName(STR_String( _PyUnicode_AsString(value) )); | *object = (RAS_MeshObject*)logicmgr->GetMeshByName(std::string(_PyUnicode_AsString(value))); | ||||
| if (*object) { | if (*object) { | ||||
| return true; | return true; | ||||
| } else { | } | ||||
| else { | |||||
| PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_MeshProxy in this scene", error_prefix, _PyUnicode_AsString(value)); | PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_MeshProxy in this scene", error_prefix, _PyUnicode_AsString(value)); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| if (PyObject_TypeCheck(value, &KX_MeshProxy::Type)) { | if (PyObject_TypeCheck(value, &KX_MeshProxy::Type)) { | ||||
| KX_MeshProxy *kx_mesh = static_cast<KX_MeshProxy*>BGE_PROXY_REF(value); | KX_MeshProxy *kx_mesh = static_cast<KX_MeshProxy *>BGE_PROXY_REF(value); | ||||
| /* sets the error */ | /* sets the error */ | ||||
| if (kx_mesh==NULL) { | if (kx_mesh == NULL) { | ||||
| PyErr_Format(PyExc_SystemError, "%s, " BGE_PROXY_ERROR_MSG, error_prefix); | PyErr_Format(PyExc_SystemError, "%s, " BGE_PROXY_ERROR_MSG, error_prefix); | ||||
| return false; | return false; | ||||
| } | } | ||||
| *object = kx_mesh->GetMesh(); | *object = kx_mesh->GetMesh(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| *object = NULL; | *object = NULL; | ||||
| if (py_none_ok) { | if (py_none_ok) { | ||||
| PyErr_Format(PyExc_TypeError, "%s, expect a KX_MeshProxy, a string or None", error_prefix); | PyErr_Format(PyExc_TypeError, "%s, expect a KX_MeshProxy, a string or None", error_prefix); | ||||
| } else { | } | ||||
| else { | |||||
| PyErr_Format(PyExc_TypeError, "%s, expect a KX_MeshProxy or a string", error_prefix); | PyErr_Format(PyExc_TypeError, "%s, expect a KX_MeshProxy or a string", error_prefix); | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| Context not available. | |||||