3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
33 #include "KX_VertexProxy.h"
34 #include "KX_MeshProxy.h"
35 #include "RAS_TexVert.h"
37 #include "KX_PyMath.h"
39 PyTypeObject KX_VertexProxy::Type = {
40 PyObject_HEAD_INIT(&PyType_Type)
43 sizeof(KX_VertexProxy),
51 0, //&cvalue_as_number,
58 PyParentObject KX_VertexProxy::Parents[] = {
59 &KX_VertexProxy::Type,
65 PyMethodDef KX_VertexProxy::Methods[] = {
66 {"getXYZ", (PyCFunction)KX_VertexProxy::sPyGetXYZ,METH_VARARGS},
67 {"setXYZ", (PyCFunction)KX_VertexProxy::sPySetXYZ,METH_VARARGS},
68 {"getUV", (PyCFunction)KX_VertexProxy::sPyGetUV,METH_VARARGS},
69 {"setUV", (PyCFunction)KX_VertexProxy::sPySetUV,METH_VARARGS},
71 {"getUV2", (PyCFunction)KX_VertexProxy::sPyGetUV2,METH_VARARGS},
72 {"setUV2", (PyCFunction)KX_VertexProxy::sPySetUV2,METH_VARARGS},
74 {"getRGBA", (PyCFunction)KX_VertexProxy::sPyGetRGBA,METH_VARARGS},
75 {"setRGBA", (PyCFunction)KX_VertexProxy::sPySetRGBA,METH_VARARGS},
76 {"getNormal", (PyCFunction)KX_VertexProxy::sPyGetNormal,METH_VARARGS},
77 {"setNormal", (PyCFunction)KX_VertexProxy::sPySetNormal,METH_VARARGS},
78 {NULL,NULL} //Sentinel
82 KX_VertexProxy::_getattr(const STR_String& attr)
85 return PyObjectFrom(MT_Vector3(m_vertex->getLocalXYZ()));
88 return PyObjectFrom(MT_Point2(m_vertex->getUV1()));
90 if (attr == "colour" || attr == "color")
92 const unsigned char *colp = m_vertex->getRGBA();
93 MT_Vector4 color(colp[0], colp[1], colp[2], colp[3]);
95 return PyObjectFrom(color);
100 return PyObjectFrom(MT_Vector3(m_vertex->getNormal()));
105 return PyFloat_FromDouble(m_vertex->getLocalXYZ()[0]);
107 return PyFloat_FromDouble(m_vertex->getLocalXYZ()[1]);
109 return PyFloat_FromDouble(m_vertex->getLocalXYZ()[2]);
113 return PyFloat_FromDouble(m_vertex->getRGBA()[0]/255.0);
115 return PyFloat_FromDouble(m_vertex->getRGBA()[1]/255.0);
117 return PyFloat_FromDouble(m_vertex->getRGBA()[2]/255.0);
119 return PyFloat_FromDouble(m_vertex->getRGBA()[3]/255.0);
123 return PyFloat_FromDouble(m_vertex->getUV1()[0]);
125 return PyFloat_FromDouble(m_vertex->getUV1()[1]);
127 _getattr_up(SCA_IObject);
130 int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue)
132 if (PySequence_Check(pyvalue))
137 if (PyVecTo(pyvalue, vec))
139 m_vertex->SetXYZ(vec);
140 m_mesh->SetMeshModified(true);
149 if (PyVecTo(pyvalue, vec))
151 m_vertex->SetUV(vec);
152 m_mesh->SetMeshModified(true);
158 if (attr == "colour" || attr == "color")
161 if (PyVecTo(pyvalue, vec))
163 m_vertex->SetRGBA(vec);
164 m_mesh->SetMeshModified(true);
170 if (attr == "normal")
173 if (PyVecTo(pyvalue, vec))
175 m_vertex->SetNormal(vec);
176 m_mesh->SetMeshModified(true);
183 if (PyFloat_Check(pyvalue))
185 float val = PyFloat_AsDouble(pyvalue);
187 MT_Point3 pos(m_vertex->getLocalXYZ());
191 m_vertex->SetXYZ(pos);
192 m_mesh->SetMeshModified(true);
199 m_vertex->SetXYZ(pos);
200 m_mesh->SetMeshModified(true);
207 m_vertex->SetXYZ(pos);
208 m_mesh->SetMeshModified(true);
213 MT_Point2 uv = m_vertex->getUV1();
218 m_mesh->SetMeshModified(true);
226 m_mesh->SetMeshModified(true);
231 MT_Point2 uv2 = m_vertex->getUV2();
235 m_vertex->SetUV2(uv);
236 m_mesh->SetMeshModified(true);
243 m_vertex->SetUV2(uv);
244 m_mesh->SetMeshModified(true);
249 unsigned int icol = *((const unsigned int *)m_vertex->getRGBA());
250 unsigned char *cp = (unsigned char*) &icol;
254 cp[0] = (unsigned char) val;
255 m_vertex->SetRGBA(icol);
256 m_mesh->SetMeshModified(true);
261 cp[1] = (unsigned char) val;
262 m_vertex->SetRGBA(icol);
263 m_mesh->SetMeshModified(true);
268 cp[2] = (unsigned char) val;
269 m_vertex->SetRGBA(icol);
270 m_mesh->SetMeshModified(true);
275 cp[3] = (unsigned char) val;
276 m_vertex->SetRGBA(icol);
277 m_mesh->SetMeshModified(true);
282 return SCA_IObject::_setattr(attr, pyvalue);
285 KX_VertexProxy::KX_VertexProxy(KX_MeshProxy*mesh, RAS_TexVert* vertex)
291 KX_VertexProxy::~KX_VertexProxy()
297 // stuff for cvalue related things
298 CValue* KX_VertexProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;}
299 CValue* KX_VertexProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;}
300 STR_String sVertexName="vertex";
301 const STR_String & KX_VertexProxy::GetText() {return sVertexName;};
302 float KX_VertexProxy::GetNumber() { return -1;}
303 STR_String KX_VertexProxy::GetName() { return sVertexName;}
304 void KX_VertexProxy::SetName(STR_String) { };
305 CValue* KX_VertexProxy::GetReplica() { return NULL;}
306 void KX_VertexProxy::ReplicaSetName(STR_String) {};
309 // stuff for python integration
311 PyObject* KX_VertexProxy::PyGetXYZ(PyObject*,
315 return PyObjectFrom(MT_Point3(m_vertex->getLocalXYZ()));
318 PyObject* KX_VertexProxy::PySetXYZ(PyObject*,
323 if (PyVecArgTo(args, vec))
325 m_vertex->SetXYZ(vec);
326 m_mesh->SetMeshModified(true);
333 PyObject* KX_VertexProxy::PyGetNormal(PyObject*,
337 return PyObjectFrom(MT_Vector3(m_vertex->getNormal()));
340 PyObject* KX_VertexProxy::PySetNormal(PyObject*,
345 if (PyVecArgTo(args, vec))
347 m_vertex->SetNormal(vec);
348 m_mesh->SetMeshModified(true);
356 PyObject* KX_VertexProxy::PyGetRGBA(PyObject*,
360 int *rgba = (int *) m_vertex->getRGBA();
361 return PyInt_FromLong(*rgba);
364 PyObject* KX_VertexProxy::PySetRGBA(PyObject*,
369 if (PyArg_ParseTuple(args, "(ffff)", &r, &g, &b, &a))
371 m_vertex->SetRGBA(MT_Vector4(r, g, b, a));
372 m_mesh->SetMeshModified(true);
378 if (PyArg_ParseTuple(args,"i",&rgba))
380 m_vertex->SetRGBA(rgba);
381 m_mesh->SetMeshModified(true);
389 PyObject* KX_VertexProxy::PyGetUV(PyObject*,
393 return PyObjectFrom(MT_Vector2(m_vertex->getUV1()));
396 PyObject* KX_VertexProxy::PySetUV(PyObject*,
401 if (PyVecArgTo(args, vec))
403 m_vertex->SetUV(vec);
404 m_mesh->SetMeshModified(true);
411 PyObject* KX_VertexProxy::PyGetUV2(PyObject*,
415 return PyObjectFrom(MT_Vector2(m_vertex->getUV2()));
418 PyObject* KX_VertexProxy::PySetUV2(PyObject*,
425 if(PyArg_ParseTuple(args, "Oi", &list, &unit))
427 if (PyVecTo(list, vec))
429 m_vertex->SetFlag((m_vertex->getFlag()|TV_2NDUV));
430 m_vertex->SetUnit(unit);
431 m_vertex->SetUV2(vec);
432 m_mesh->SetMeshModified(true);