~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to source/gameengine/Ketsji/KX_MeshProxy.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: KX_MeshProxy.cpp 14444 2008-04-16 22:40:48Z hos $
 
2
 * $Id: KX_MeshProxy.cpp 16395 2008-09-06 14:13:31Z sirdude $
3
3
 * ***** BEGIN GPL LICENSE BLOCK *****
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
35
35
#include "RAS_MeshObject.h"
36
36
 
37
37
#include "KX_VertexProxy.h"
 
38
#include "KX_PolyProxy.h"
38
39
 
39
40
#include "KX_PolygonMaterial.h"
40
41
#include "KX_BlenderMaterial.h"
42
43
#include "KX_PyMath.h"
43
44
#include "KX_ConvertPhysicsObject.h"
44
45
 
 
46
#include "PyObjectPlus.h" 
 
47
 
45
48
PyTypeObject KX_MeshProxy::Type = {
46
49
        PyObject_HEAD_INIT(&PyType_Type)
47
50
        0,
71
74
 
72
75
PyMethodDef KX_MeshProxy::Methods[] = {
73
76
{"getNumMaterials", (PyCFunction)KX_MeshProxy::sPyGetNumMaterials,METH_VARARGS},
 
77
{"getNumPolygons", (PyCFunction)KX_MeshProxy::sPyGetNumPolygons,METH_NOARGS},
74
78
{"getMaterialName", (PyCFunction)KX_MeshProxy::sPyGetMaterialName,METH_VARARGS},
75
79
{"getTextureName", (PyCFunction)KX_MeshProxy::sPyGetTextureName,METH_VARARGS},
76
80
{"getVertexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetVertexArrayLength,METH_VARARGS},
77
81
{"getVertex", (PyCFunction)KX_MeshProxy::sPyGetVertex,METH_VARARGS},
 
82
{"getPolygon", (PyCFunction)KX_MeshProxy::sPyGetPolygon,METH_VARARGS},
78
83
KX_PYMETHODTABLE(KX_MeshProxy, reinstancePhysicsMesh),
79
84
//{"getIndexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetIndexArrayLength,METH_VARARGS},
80
85
 
93
98
        if (attr == "materials")
94
99
        {
95
100
                PyObject *materials = PyList_New(0);
96
 
                RAS_MaterialBucket::Set::iterator mit = m_meshobj->GetFirstMaterial();
 
101
                list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial();
97
102
                for(; mit != m_meshobj->GetLastMaterial(); ++mit)
98
103
                {
99
 
                        RAS_IPolyMaterial *polymat = (*mit)->GetPolyMaterial();
 
104
                        RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial();
 
105
 
100
106
                        if(polymat->GetFlag() & RAS_BLENDERMAT)
101
107
                        {
102
108
                                KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial*>(polymat);
146
152
        return PyInt_FromLong(num);
147
153
}
148
154
 
 
155
PyObject* KX_MeshProxy::PyGetNumPolygons(PyObject* self)
 
156
{
 
157
        int num = m_meshobj->NumPolygons();
 
158
        return PyInt_FromLong(num);
 
159
}
 
160
 
149
161
PyObject* KX_MeshProxy::PyGetMaterialName(PyObject* self, 
150
162
                               PyObject* args, 
151
163
                               PyObject* kwds)
157
169
        {
158
170
                matname = m_meshobj->GetMaterialName(matid);
159
171
        }
 
172
        else {
 
173
                return NULL;
 
174
        }
160
175
 
161
176
        return PyString_FromString(matname.Ptr());
162
177
                
174
189
        {
175
190
                matname = m_meshobj->GetTextureName(matid);
176
191
        }
 
192
        else {
 
193
                return NULL;
 
194
        }
177
195
 
178
196
        return PyString_FromString(matname.Ptr());
179
197
                
189
207
        
190
208
        if (PyArg_ParseTuple(args,"i",&matid))
191
209
        {
192
 
                RAS_IPolyMaterial* mat = m_meshobj->GetMaterialBucket(matid)->GetPolyMaterial();
 
210
                RAS_MeshMaterial *mmat = m_meshobj->GetMeshMaterial(matid);
 
211
                RAS_IPolyMaterial* mat = mmat->m_bucket->GetPolyMaterial();
 
212
 
193
213
                if (mat)
194
 
                {
195
 
                        length = m_meshobj->GetVertexArrayLength(mat);
196
 
                }
 
214
                        length = m_meshobj->NumVertices(mat);
 
215
        }
 
216
        else {
 
217
                return NULL;
197
218
        }
198
219
 
199
220
        return PyInt_FromLong(length);
217
238
                        vertexob = new KX_VertexProxy(this, vertex);
218
239
                }
219
240
        }
 
241
        else {
 
242
                return NULL;
 
243
        }
220
244
 
221
245
        return vertexob;
222
246
                
223
247
}
224
248
 
 
249
PyObject* KX_MeshProxy::PyGetPolygon(PyObject* self,
 
250
                               PyObject* args, 
 
251
                               PyObject* kwds)
 
252
{
 
253
    int polyindex= 1;
 
254
        PyObject* polyob = NULL;
 
255
 
 
256
        if (!PyArg_ParseTuple(args,"i",&polyindex))
 
257
                return NULL;
 
258
 
 
259
        RAS_Polygon* polygon = m_meshobj->GetPolygon(polyindex);
 
260
        if (polygon)
 
261
        {
 
262
                polyob = new KX_PolyProxy(m_meshobj, polygon);
 
263
        }
 
264
        else
 
265
        {
 
266
                PyErr_SetString(PyExc_AttributeError, "Invalid polygon index");
 
267
        }
 
268
        return polyob;
 
269
}
 
270
 
225
271
KX_PYMETHODDEF_DOC(KX_MeshProxy, reinstancePhysicsMesh,
226
272
"Reinstance the physics mesh.")
227
273
{
228
274
        //this needs to be reviewed, it is dependend on Sumo/Solid. Who is using this ?
229
 
        return Py_None;//Py_Success(KX_ReInstanceShapeFromMesh(m_meshobj));
 
275
        Py_RETURN_NONE;//(KX_ReInstanceShapeFromMesh(m_meshobj)) ? Py_RETURN_TRUE : Py_RETURN_FALSE;
230
276
}