2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_VertexProxy.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2004-07-17 05:28:23 +00:00
|
|
|
#include "KX_VertexProxy.h"
|
|
|
|
#include "KX_MeshProxy.h"
|
|
|
|
#include "RAS_TexVert.h"
|
|
|
|
|
2004-05-30 11:09:46 +00:00
|
|
|
#include "KX_PyMath.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
PyTypeObject KX_VertexProxy::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2002-10-12 11:37:38 +00:00
|
|
|
"KX_VertexProxy",
|
2009-04-20 15:06:46 +00:00
|
|
|
sizeof(PyObjectPlus_Proxy),
|
2002-10-12 11:37:38 +00:00
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_dealloc,
|
2002-10-12 11:37:38 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_repr,
|
2009-06-29 12:06:46 +00:00
|
|
|
0,0,0,0,0,0,0,0,0,
|
2009-06-28 11:22:26 +00:00
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
2009-06-29 12:06:46 +00:00
|
|
|
&CValue::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_VertexProxy::Methods[] = {
|
2009-02-23 06:41:10 +00:00
|
|
|
{"getXYZ", (PyCFunction)KX_VertexProxy::sPyGetXYZ,METH_NOARGS},
|
|
|
|
{"setXYZ", (PyCFunction)KX_VertexProxy::sPySetXYZ,METH_O},
|
|
|
|
{"getUV", (PyCFunction)KX_VertexProxy::sPyGetUV,METH_NOARGS},
|
|
|
|
{"setUV", (PyCFunction)KX_VertexProxy::sPySetUV,METH_O},
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2009-02-23 06:41:10 +00:00
|
|
|
{"getUV2", (PyCFunction)KX_VertexProxy::sPyGetUV2,METH_NOARGS},
|
2006-01-06 03:46:54 +00:00
|
|
|
{"setUV2", (PyCFunction)KX_VertexProxy::sPySetUV2,METH_VARARGS},
|
|
|
|
|
2009-02-23 06:41:10 +00:00
|
|
|
{"getRGBA", (PyCFunction)KX_VertexProxy::sPyGetRGBA,METH_NOARGS},
|
|
|
|
{"setRGBA", (PyCFunction)KX_VertexProxy::sPySetRGBA,METH_O},
|
|
|
|
{"getNormal", (PyCFunction)KX_VertexProxy::sPyGetNormal,METH_NOARGS},
|
|
|
|
{"setNormal", (PyCFunction)KX_VertexProxy::sPySetNormal,METH_O},
|
2002-10-12 11:37:38 +00:00
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_VertexProxy::Attributes[] = {
|
2010-08-16 12:14:09 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("x", KX_VertexProxy, pyattr_get_x, pyattr_set_x),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("y", KX_VertexProxy, pyattr_get_y, pyattr_set_y),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("z", KX_VertexProxy, pyattr_get_z, pyattr_set_z),
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("r", KX_VertexProxy, pyattr_get_r, pyattr_set_r),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("g", KX_VertexProxy, pyattr_get_g, pyattr_set_g),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("b", KX_VertexProxy, pyattr_get_b, pyattr_set_b),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("a", KX_VertexProxy, pyattr_get_a, pyattr_set_a),
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("u", KX_VertexProxy, pyattr_get_u, pyattr_set_u),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("v", KX_VertexProxy, pyattr_get_v, pyattr_set_v),
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("u2", KX_VertexProxy, pyattr_get_u2, pyattr_set_u2),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("v2", KX_VertexProxy, pyattr_get_v2, pyattr_set_v2),
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("XYZ", KX_VertexProxy, pyattr_get_XYZ, pyattr_set_XYZ),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("UV", KX_VertexProxy, pyattr_get_UV, pyattr_set_UV),
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("color", KX_VertexProxy, pyattr_get_color, pyattr_set_color),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("normal", KX_VertexProxy, pyattr_get_normal, pyattr_set_normal),
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
PyObject* KX_VertexProxy::pyattr_get_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getXYZ()[0]);
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
PyObject* KX_VertexProxy::pyattr_get_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getXYZ()[1]);
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
PyObject* KX_VertexProxy::pyattr_get_z(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getXYZ()[2]);
|
2009-06-08 20:08:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
PyObject* KX_VertexProxy::pyattr_get_r(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getRGBA()[0]/255.0);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
PyObject* KX_VertexProxy::pyattr_get_g(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getRGBA()[1]/255.0);
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
PyObject* KX_VertexProxy::pyattr_get_b(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getRGBA()[2]/255.0);
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
PyObject* KX_VertexProxy::pyattr_get_a(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getRGBA()[3]/255.0);
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
PyObject* KX_VertexProxy::pyattr_get_u(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getUV1()[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* KX_VertexProxy::pyattr_get_v(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getUV1()[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* KX_VertexProxy::pyattr_get_u2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getUV2()[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* KX_VertexProxy::pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_vertex->getUV2()[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* KX_VertexProxy::pyattr_get_XYZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyObjectFrom(MT_Vector3(self->m_vertex->getXYZ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* KX_VertexProxy::pyattr_get_UV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyObjectFrom(MT_Point2(self->m_vertex->getUV1()));
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* KX_VertexProxy::pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
const unsigned char *colp = self->m_vertex->getRGBA();
|
|
|
|
MT_Vector4 color(colp[0], colp[1], colp[2], colp[3]);
|
|
|
|
color /= 255.0;
|
|
|
|
return PyObjectFrom(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* KX_VertexProxy::pyattr_get_normal(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
return PyObjectFrom(MT_Vector3(self->m_vertex->getNormal()));
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_VertexProxy::pyattr_set_x(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
MT_Point3 pos(self->m_vertex->getXYZ());
|
2004-05-30 11:09:46 +00:00
|
|
|
pos.x() = val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetXYZ(pos);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
int KX_VertexProxy::pyattr_set_y(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
MT_Point3 pos(self->m_vertex->getXYZ());
|
2004-05-30 11:09:46 +00:00
|
|
|
pos.y() = val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetXYZ(pos);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
int KX_VertexProxy::pyattr_set_z(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
MT_Point3 pos(self->m_vertex->getXYZ());
|
2004-05-30 11:09:46 +00:00
|
|
|
pos.z() = val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetXYZ(pos);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
int KX_VertexProxy::pyattr_set_u(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
MT_Point2 uv = self->m_vertex->getUV1();
|
2004-05-30 11:09:46 +00:00
|
|
|
uv[0] = val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetUV(uv);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
int KX_VertexProxy::pyattr_set_v(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
MT_Point2 uv = self->m_vertex->getUV1();
|
2004-05-30 11:09:46 +00:00
|
|
|
uv[1] = val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetUV(uv);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
int KX_VertexProxy::pyattr_set_u2(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2006-01-06 03:46:54 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
MT_Point2 uv = self->m_vertex->getUV2();
|
2006-01-06 03:46:54 +00:00
|
|
|
uv[0] = val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetUV2(uv);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2006-01-06 03:46:54 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
int KX_VertexProxy::pyattr_set_v2(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2006-01-06 03:46:54 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
MT_Point2 uv = self->m_vertex->getUV2();
|
2006-01-06 03:46:54 +00:00
|
|
|
uv[1] = val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetUV2(uv);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2006-01-06 03:46:54 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
int KX_VertexProxy::pyattr_set_r(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA());
|
|
|
|
unsigned char *cp = (unsigned char*) &icol;
|
|
|
|
val *= 255.0;
|
2004-05-30 11:09:46 +00:00
|
|
|
cp[0] = (unsigned char) val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetRGBA(icol);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_VertexProxy::pyattr_set_g(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA());
|
|
|
|
unsigned char *cp = (unsigned char*) &icol;
|
|
|
|
val *= 255.0;
|
2004-05-30 11:09:46 +00:00
|
|
|
cp[1] = (unsigned char) val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetRGBA(icol);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_VertexProxy::pyattr_set_b(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA());
|
|
|
|
unsigned char *cp = (unsigned char*) &icol;
|
|
|
|
val *= 255.0;
|
2004-05-30 11:09:46 +00:00
|
|
|
cp[2] = (unsigned char) val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetRGBA(icol);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_VertexProxy::pyattr_set_a(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PyFloat_Check(value))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2010-08-16 12:14:09 +00:00
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA());
|
|
|
|
unsigned char *cp = (unsigned char*) &icol;
|
|
|
|
val *= 255.0;
|
2004-05-30 11:09:46 +00:00
|
|
|
cp[3] = (unsigned char) val;
|
2010-08-16 12:14:09 +00:00
|
|
|
self->m_vertex->SetRGBA(icol);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2010-08-16 12:14:09 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2010-08-16 12:14:09 +00:00
|
|
|
int KX_VertexProxy::pyattr_set_XYZ(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PySequence_Check(value))
|
|
|
|
{
|
|
|
|
MT_Point3 vec;
|
|
|
|
if (PyVecTo(value, vec))
|
|
|
|
{
|
|
|
|
self->m_vertex->SetXYZ(vec);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_VertexProxy::pyattr_set_UV(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PySequence_Check(value))
|
|
|
|
{
|
|
|
|
MT_Point2 vec;
|
|
|
|
if (PyVecTo(value, vec))
|
|
|
|
{
|
|
|
|
self->m_vertex->SetUV(vec);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_VertexProxy::pyattr_set_color(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PySequence_Check(value))
|
|
|
|
{
|
|
|
|
MT_Vector4 vec;
|
|
|
|
if (PyVecTo(value, vec))
|
|
|
|
{
|
|
|
|
self->m_vertex->SetRGBA(vec);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_VertexProxy::pyattr_set_normal(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
|
|
|
|
if (PySequence_Check(value))
|
|
|
|
{
|
|
|
|
MT_Vector3 vec;
|
|
|
|
if (PyVecTo(value, vec))
|
|
|
|
{
|
|
|
|
self->m_vertex->SetNormal(vec);
|
|
|
|
self->m_mesh->SetMeshModified(true);
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PY_SET_ATTR_FAIL;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
KX_VertexProxy::KX_VertexProxy(KX_MeshProxy*mesh, RAS_TexVert* vertex)
|
|
|
|
: m_vertex(vertex),
|
|
|
|
m_mesh(mesh)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-10-06 16:07:05 +00:00
|
|
|
/* see bug [#27071] */
|
|
|
|
Py_INCREF(m_mesh->GetProxy());
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KX_VertexProxy::~KX_VertexProxy()
|
|
|
|
{
|
2011-10-06 16:07:05 +00:00
|
|
|
/* see bug [#27071] */
|
|
|
|
Py_DECREF(m_mesh->GetProxy());
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// stuff for cvalue related things
|
2004-07-17 05:28:23 +00:00
|
|
|
CValue* KX_VertexProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;}
|
2009-06-28 11:22:26 +00:00
|
|
|
CValue* KX_VertexProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;}
|
2002-10-12 11:37:38 +00:00
|
|
|
STR_String sVertexName="vertex";
|
|
|
|
const STR_String & KX_VertexProxy::GetText() {return sVertexName;};
|
2009-04-20 15:06:46 +00:00
|
|
|
double KX_VertexProxy::GetNumber() { return -1;}
|
2009-06-08 20:08:19 +00:00
|
|
|
STR_String& KX_VertexProxy::GetName() { return sVertexName;}
|
|
|
|
void KX_VertexProxy::SetName(const char *) { };
|
2002-10-12 11:37:38 +00:00
|
|
|
CValue* KX_VertexProxy::GetReplica() { return NULL;}
|
|
|
|
|
|
|
|
// stuff for python integration
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PyGetXYZ()
|
2004-07-17 05:28:23 +00:00
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return PyObjectFrom(MT_Point3(m_vertex->getXYZ()));
|
2004-07-17 05:28:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PySetXYZ(PyObject* value)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-07-17 05:28:23 +00:00
|
|
|
MT_Point3 vec;
|
2009-02-23 06:41:10 +00:00
|
|
|
if (!PyVecTo(value, vec))
|
|
|
|
return NULL;
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-02-23 06:41:10 +00:00
|
|
|
m_vertex->SetXYZ(vec);
|
|
|
|
m_mesh->SetMeshModified(true);
|
|
|
|
Py_RETURN_NONE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PyGetNormal()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-07-17 05:28:23 +00:00
|
|
|
return PyObjectFrom(MT_Vector3(m_vertex->getNormal()));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PySetNormal(PyObject* value)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-07-17 05:28:23 +00:00
|
|
|
MT_Vector3 vec;
|
2009-02-23 06:41:10 +00:00
|
|
|
if (!PyVecTo(value, vec))
|
|
|
|
return NULL;
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-02-23 06:41:10 +00:00
|
|
|
m_vertex->SetNormal(vec);
|
|
|
|
m_mesh->SetMeshModified(true);
|
|
|
|
Py_RETURN_NONE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PyGetRGBA()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-07-17 05:28:23 +00:00
|
|
|
int *rgba = (int *) m_vertex->getRGBA();
|
2009-06-29 02:25:54 +00:00
|
|
|
return PyLong_FromSsize_t(*rgba);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PySetRGBA(PyObject* value)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-06-29 02:25:54 +00:00
|
|
|
if PyLong_Check(value) {
|
|
|
|
int rgba = PyLong_AsSsize_t(value);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_vertex->SetRGBA(rgba);
|
2006-04-02 21:04:20 +00:00
|
|
|
m_mesh->SetMeshModified(true);
|
2009-02-21 12:43:24 +00:00
|
|
|
Py_RETURN_NONE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
else {
|
2009-02-23 06:41:10 +00:00
|
|
|
MT_Vector4 vec;
|
|
|
|
if (PyVecTo(value, vec))
|
|
|
|
{
|
|
|
|
m_vertex->SetRGBA(vec);
|
|
|
|
m_mesh->SetMeshModified(true);
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
}
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "vert.setRGBA(value): KX_VertexProxy, expected a 4D vector or an int");
|
2005-01-16 06:02:06 +00:00
|
|
|
return NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PyGetUV()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-07-17 05:28:23 +00:00
|
|
|
return PyObjectFrom(MT_Vector2(m_vertex->getUV1()));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PySetUV(PyObject* value)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-07-17 05:28:23 +00:00
|
|
|
MT_Point2 vec;
|
2009-02-23 06:41:10 +00:00
|
|
|
if (!PyVecTo(value, vec))
|
|
|
|
return NULL;
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-02-23 06:41:10 +00:00
|
|
|
m_vertex->SetUV(vec);
|
|
|
|
m_mesh->SetMeshModified(true);
|
|
|
|
Py_RETURN_NONE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PyGetUV2()
|
2006-01-06 03:46:54 +00:00
|
|
|
{
|
|
|
|
return PyObjectFrom(MT_Vector2(m_vertex->getUV2()));
|
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VertexProxy::PySetUV2(PyObject* args)
|
2006-01-06 03:46:54 +00:00
|
|
|
{
|
|
|
|
MT_Point2 vec;
|
2009-06-08 20:08:19 +00:00
|
|
|
unsigned int unit= RAS_TexVert::SECOND_UV;
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-02-23 06:41:10 +00:00
|
|
|
PyObject* list= NULL;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!PyArg_ParseTuple(args, "O|i:setUV2", &list, &unit))
|
2009-02-23 06:41:10 +00:00
|
|
|
return NULL;
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-02-23 06:41:10 +00:00
|
|
|
if (!PyVecTo(list, vec))
|
|
|
|
return NULL;
|
2009-06-28 11:22:26 +00:00
|
|
|
|
2009-02-23 06:41:10 +00:00
|
|
|
m_vertex->SetFlag((m_vertex->getFlag()|RAS_TexVert::SECOND_UV));
|
|
|
|
m_vertex->SetUnit(unit);
|
|
|
|
m_vertex->SetUV2(vec);
|
|
|
|
m_mesh->SetMeshModified(true);
|
|
|
|
Py_RETURN_NONE;
|
2006-01-06 03:46:54 +00:00
|
|
|
}
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|