From d48991c6c62dd58203c19ea399aed661ee9beea2 Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Wed, 11 Aug 2010 10:36:16 +0000 Subject: Blender Py API: Implemented missing KX_PYATTRIBUTE_TODOs and -DUMMYs. --- source/gameengine/Expressions/PyObjectPlus.h | 3 - source/gameengine/GameLogic/SCA_ISensor.cpp | 17 +- source/gameengine/GameLogic/SCA_ISensor.h | 15 + source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 1 - source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 37 +- source/gameengine/Ketsji/KX_BlenderMaterial.h | 8 + source/gameengine/Ketsji/KX_ConstraintWrapper.cpp | 8 +- source/gameengine/Ketsji/KX_ConstraintWrapper.h | 2 + source/gameengine/Ketsji/KX_PolyProxy.cpp | 161 ++++---- source/gameengine/Ketsji/KX_PolyProxy.h | 10 + source/gameengine/Ketsji/KX_VertexProxy.cpp | 454 +++++++++++++-------- source/gameengine/Ketsji/KX_VertexProxy.h | 31 ++ 12 files changed, 483 insertions(+), 264 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 7afa85c8c31..625549a272e 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -319,9 +319,6 @@ typedef struct KX_PYATTRIBUTE_DEF { } m_typeCheck; } PyAttributeDef; -#define KX_PYATTRIBUTE_DUMMY(name) \ - { name, KX_PYATTRIBUTE_TYPE_DUMMY, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, 0, 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } - #define KX_PYATTRIBUTE_BOOL_RW(name,object,field) \ { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_BOOL_RW_CHECK(name,object,field,function) \ diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index bff02326c9c..fada69848b2 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -357,9 +357,8 @@ PyAttributeDef SCA_ISensor::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("triggered", SCA_ISensor, pyattr_get_triggered), KX_PYATTRIBUTE_RO_FUNCTION("positive", SCA_ISensor, pyattr_get_positive), KX_PYATTRIBUTE_RO_FUNCTION("status", SCA_ISensor, pyattr_get_status), - //KX_PYATTRIBUTE_TODO("links"), - //KX_PYATTRIBUTE_TODO("posTicks"), - //KX_PYATTRIBUTE_TODO("negTicks"), + KX_PYATTRIBUTE_RO_FUNCTION("pos_ticks", SCA_ISensor, pyattr_get_posTicks), + KX_PYATTRIBUTE_RO_FUNCTION("neg_ticks", SCA_ISensor, pyattr_get_negTicks), { NULL } //Sentinel }; @@ -401,6 +400,18 @@ PyObject* SCA_ISensor::pyattr_get_status(void *self_v, const KX_PYATTRIBUTE_DEF return PyLong_FromSsize_t(status); } +PyObject* SCA_ISensor::pyattr_get_posTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_ISensor* self= static_cast(self_v); + return PyLong_FromLong(self->GetPosTicks()); +} + +PyObject* SCA_ISensor::pyattr_get_negTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_ISensor* self= static_cast(self_v); + return PyLong_FromLong(self->GetNegTicks()); +} + int SCA_ISensor::pyattr_check_level(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_ISensor* self= static_cast(self_v); diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index 42d06d856b6..2d3a3ef08a0 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -167,6 +167,18 @@ public: return m_prev_state; } + /** get the number of ticks since the last positive pulse */ + int GetPosTicks() + { + return m_pos_ticks; + } + + /** get the number of ticks since the last negative pulse */ + int GetNegTicks() + { + return m_neg_ticks; + } + /** Resume sensing. */ void Resume(); @@ -185,6 +197,9 @@ public: static PyObject* pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_status(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_posTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_negTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_check_level(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_check_tap(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 5ab42ae7608..29a6a73b865 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -290,7 +290,6 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("numButtons", SCA_JoystickSensor, pyattr_get_num_buttons), KX_PYATTRIBUTE_RO_FUNCTION("numHats", SCA_JoystickSensor, pyattr_get_num_hats), KX_PYATTRIBUTE_RO_FUNCTION("connected", SCA_JoystickSensor, pyattr_get_connected), - //KX_PYATTRIBUTE_TODO("events"), { NULL } //Sentinel }; diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 2ef7e55429f..f5f52a3bd5e 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -794,9 +794,9 @@ PyMethodDef KX_BlenderMaterial::Methods[] = }; PyAttributeDef KX_BlenderMaterial::Attributes[] = { - //KX_PYATTRIBUTE_TODO("shader"), - //KX_PYATTRIBUTE_TODO("materialIndex"), - //KX_PYATTRIBUTE_TODO("blending"), + KX_PYATTRIBUTE_RO_FUNCTION("shader", KX_BlenderMaterial, pyattr_get_shader), + KX_PYATTRIBUTE_RO_FUNCTION("material_index", KX_BlenderMaterial, pyattr_get_materialIndex), + KX_PYATTRIBUTE_RW_FUNCTION("blending", KX_BlenderMaterial, pyattr_get_blending, pyattr_set_blending), { NULL } //Sentinel }; @@ -822,6 +822,37 @@ PyTypeObject KX_BlenderMaterial::Type = { py_base_new }; +PyObject* KX_BlenderMaterial::pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_BlenderMaterial* self= static_cast(self_v); + return self->PygetShader(NULL, NULL); +} + +PyObject* KX_BlenderMaterial::pyattr_get_materialIndex(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_BlenderMaterial* self= static_cast(self_v); + return PyLong_FromSsize_t(self->GetMaterialIndex()); +} + +PyObject* KX_BlenderMaterial::pyattr_get_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_BlenderMaterial* self= static_cast(self_v); + unsigned int* bfunc = self->getBlendFunc(); + return Py_BuildValue("(ll)", (long int)bfunc[0], (long int)bfunc[1]); +} + +int KX_BlenderMaterial::pyattr_set_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_BlenderMaterial* self= static_cast(self_v); + PyObject* obj = self->PysetBlending(value, NULL); + if(obj) + { + Py_DECREF(obj); + return 0; + } + return -1; +} + KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") { if( !GLEW_ARB_fragment_shader) { diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index 5bf62ff6b7c..239e334f68a 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -79,6 +79,9 @@ public: Image * getImage (unsigned int idx) { return (idx < MAXTEX && mMaterial) ? mMaterial->img[idx] : NULL; } + unsigned int* getBlendFunc() { + return mBlendFunc; + } // for ipos void UpdateIPO( MT_Vector4 rgba, MT_Vector3 specrgb, @@ -99,6 +102,11 @@ public: // -------------------------------- virtual PyObject* py_repr(void) { return PyUnicode_FromString(mMaterial->matname.ReadPtr()); } + static PyObject* pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_materialIndex(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader ); KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex ); KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture ); diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index 8af6e63f343..b1baa5fe9e1 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -110,8 +110,14 @@ PyMethodDef KX_ConstraintWrapper::Methods[] = { }; PyAttributeDef KX_ConstraintWrapper::Attributes[] = { - //KX_PYATTRIBUTE_TODO("constraintId"), + KX_PYATTRIBUTE_RO_FUNCTION("constraint_id", KX_ConstraintWrapper, pyattr_get_constraintId), { NULL } //Sentinel }; +PyObject* KX_ConstraintWrapper::pyattr_get_constraintId(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_ConstraintWrapper* self= static_cast(self_v); + return self->PyGetConstraintId(); +} + #endif // DISABLE_PYTHON diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.h b/source/gameengine/Ketsji/KX_ConstraintWrapper.h index 530ecf16fed..db9543c23ae 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.h +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.h @@ -44,6 +44,8 @@ public: KX_PYMETHOD_NOARGS(KX_ConstraintWrapper,GetConstraintId); KX_PYMETHOD(KX_ConstraintWrapper,SetParam); KX_PYMETHOD(KX_ConstraintWrapper,GetParam); + + static PyObject* pyattr_get_constraintId(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); #endif private: diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index 837c79c77b3..9395e57e68b 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -72,90 +72,19 @@ PyMethodDef KX_PolyProxy::Methods[] = { }; PyAttributeDef KX_PolyProxy::Attributes[] = { - /* All dummy's so they come up in a dir() */ - //KX_PYATTRIBUTE_TODO("DummyProps"), - KX_PYATTRIBUTE_DUMMY("matname"), - KX_PYATTRIBUTE_DUMMY("texture"), - KX_PYATTRIBUTE_DUMMY("material"), - KX_PYATTRIBUTE_DUMMY("matid"), - KX_PYATTRIBUTE_DUMMY("v1"), - KX_PYATTRIBUTE_DUMMY("v2"), - KX_PYATTRIBUTE_DUMMY("v3"), - KX_PYATTRIBUTE_DUMMY("v4"), - KX_PYATTRIBUTE_DUMMY("visible"), - KX_PYATTRIBUTE_DUMMY("collide"), + KX_PYATTRIBUTE_RO_FUNCTION("material_name", KX_PolyProxy, pyattr_get_material_name), + KX_PYATTRIBUTE_RO_FUNCTION("texture_name", KX_PolyProxy, pyattr_get_texture_name), + KX_PYATTRIBUTE_RO_FUNCTION("material", KX_PolyProxy, pyattr_get_material), + KX_PYATTRIBUTE_RO_FUNCTION("material_id", KX_PolyProxy, pyattr_get_material_id), + KX_PYATTRIBUTE_RO_FUNCTION("v1", KX_PolyProxy, pyattr_get_v1), + KX_PYATTRIBUTE_RO_FUNCTION("v2", KX_PolyProxy, pyattr_get_v2), + KX_PYATTRIBUTE_RO_FUNCTION("v3", KX_PolyProxy, pyattr_get_v3), + KX_PYATTRIBUTE_RO_FUNCTION("v4", KX_PolyProxy, pyattr_get_v4), + KX_PYATTRIBUTE_RO_FUNCTION("visible", KX_PolyProxy, pyattr_get_visible), + KX_PYATTRIBUTE_RO_FUNCTION("collide", KX_PolyProxy, pyattr_get_collide), { NULL } //Sentinel }; -#if 0 -PyObject* KX_PolyProxy::py_getattro(PyObject *attr) -{ - char *attr_str= _PyUnicode_AsString(attr); - if (!strcmp(attr_str, "matname")) - { - return PyUnicode_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetMaterialName()); - } - if (!strcmp(attr_str, "texture")) - { - return PyUnicode_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetTextureName()); - } - if (!strcmp(attr_str, "material")) - { - RAS_IPolyMaterial *polymat = m_polygon->GetMaterial()->GetPolyMaterial(); - if(polymat->GetFlag() & RAS_BLENDERMAT) - { - KX_BlenderMaterial* mat = static_cast(polymat); - return mat->GetProxy(); - } - else - { - KX_PolygonMaterial* mat = static_cast(polymat); - return mat->GetProxy(); - } - } - if (!strcmp(attr_str, "matid")) - { - // we'll have to scan through the material bucket of the mes and compare with - // the one of the polygon - RAS_MaterialBucket* polyBucket = m_polygon->GetMaterial(); - unsigned int matid; - for (matid=0; matid<(unsigned int)m_mesh->NumMaterials(); matid++) - { - RAS_MeshMaterial* meshMat = m_mesh->GetMeshMaterial(matid); - if (meshMat->m_bucket == polyBucket) - // found it - break; - } - return PyLong_FromSsize_t(matid); - } - if (!strcmp(attr_str, "v1")) - { - return PyLong_FromSsize_t(m_polygon->GetVertexOffsetAbs(m_mesh, 0)); - } - if (!strcmp(attr_str, "v2")) - { - return PyLong_FromSsize_t(m_polygon->GetVertexOffsetAbs(m_mesh, 1)); - } - if (!strcmp(attr_str, "v3")) - { - return PyLong_FromSsize_t(m_polygon->GetVertexOffsetAbs(m_mesh, 2)); - } - if (!strcmp(attr_str, "v4")) - { - return PyLong_FromSsize_t(((m_polygon->VertexCount()>3)?m_polygon->GetVertexOffsetAbs(m_mesh, 3):0)); - } - if (!strcmp(attr_str, "visible")) - { - return PyLong_FromSsize_t(m_polygon->IsVisible()); - } - if (!strcmp(attr_str, "collide")) - { - return PyLong_FromSsize_t(m_polygon->IsCollider()); - } - // py_getattro_up(CValue); // XXX -- todo, make all these attributes -} -#endif - KX_PolyProxy::KX_PolyProxy(const RAS_MeshObject*mesh, RAS_Polygon* polygon) : m_polygon(polygon), m_mesh((RAS_MeshObject*)mesh) @@ -179,7 +108,75 @@ CValue* KX_PolyProxy::GetReplica() { return NULL;} // stuff for python integration -KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterialIndex, +PyObject* KX_PolyProxy::pyattr_get_material_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + return self->PygetMaterialName(); +} + +PyObject* KX_PolyProxy::pyattr_get_texture_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + return self->PygetTextureName(); +} + +PyObject* KX_PolyProxy::pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + return self->PygetMaterial(); +} + +PyObject* KX_PolyProxy::pyattr_get_material_id(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + return self->PygetMaterialIndex(); +} + +PyObject* KX_PolyProxy::pyattr_get_v1(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + + return PyLong_FromSsize_t(self->m_polygon->GetVertexOffsetAbs(self->m_mesh, 0)); +} + +PyObject* KX_PolyProxy::pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + + return PyLong_FromSsize_t(self->m_polygon->GetVertexOffsetAbs(self->m_mesh, 1)); +} + +PyObject* KX_PolyProxy::pyattr_get_v3(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + + return PyLong_FromSsize_t(self->m_polygon->GetVertexOffsetAbs(self->m_mesh, 2)); +} + +PyObject* KX_PolyProxy::pyattr_get_v4(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + + if (3 < self->m_polygon->VertexCount()) + { + return PyLong_FromSsize_t(self->m_polygon->GetVertexOffsetAbs(self->m_mesh, 3)); + } + return PyLong_FromSsize_t(0); +} + +PyObject* KX_PolyProxy::pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + return self->PyisVisible(); +} + +PyObject* KX_PolyProxy::pyattr_get_collide(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolyProxy* self= static_cast(self_v); + return self->PyisCollider(); +} + +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterialIndex, "getMaterialIndex() : return the material index of the polygon in the mesh\n") { RAS_MaterialBucket* polyBucket = m_polygon->GetMaterial(); diff --git a/source/gameengine/Ketsji/KX_PolyProxy.h b/source/gameengine/Ketsji/KX_PolyProxy.h index 97d89b37435..3e669630e30 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.h +++ b/source/gameengine/Ketsji/KX_PolyProxy.h @@ -54,6 +54,16 @@ public: // stuff for python integration + static PyObject* pyattr_get_material_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_texture_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_material_id(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_v1(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_v3(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_v4(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_collide(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getMaterialIndex) KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getNumVertex) diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index 652bf5eafed..09630ad2851 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -73,247 +73,359 @@ PyMethodDef KX_VertexProxy::Methods[] = { }; PyAttributeDef KX_VertexProxy::Attributes[] = { - //KX_PYATTRIBUTE_TODO("DummyProps"), + 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), - KX_PYATTRIBUTE_DUMMY("x"), - KX_PYATTRIBUTE_DUMMY("y"), - KX_PYATTRIBUTE_DUMMY("z"), + 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), - KX_PYATTRIBUTE_DUMMY("r"), - KX_PYATTRIBUTE_DUMMY("g"), - KX_PYATTRIBUTE_DUMMY("b"), - KX_PYATTRIBUTE_DUMMY("a"), + 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), - KX_PYATTRIBUTE_DUMMY("u"), - KX_PYATTRIBUTE_DUMMY("v"), + 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), - KX_PYATTRIBUTE_DUMMY("u2"), - KX_PYATTRIBUTE_DUMMY("v2"), + 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), - KX_PYATTRIBUTE_DUMMY("XYZ"), - KX_PYATTRIBUTE_DUMMY("UV"), - - KX_PYATTRIBUTE_DUMMY("color"), - KX_PYATTRIBUTE_DUMMY("colour"), - - KX_PYATTRIBUTE_DUMMY("normal"), + 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), { NULL } //Sentinel }; -#if 0 -PyObject* -KX_VertexProxy::py_getattro(PyObject *attr) -{ - char *attr_str= _PyUnicode_AsString(attr); - if (attr_str[1]=='\0') { // Group single letters - // pos - if (attr_str[0]=='x') - return PyFloat_FromDouble(m_vertex->getXYZ()[0]); - if (attr_str[0]=='y') - return PyFloat_FromDouble(m_vertex->getXYZ()[1]); - if (attr_str[0]=='z') - return PyFloat_FromDouble(m_vertex->getXYZ()[2]); - - // Col - if (attr_str[0]=='r') - return PyFloat_FromDouble(m_vertex->getRGBA()[0]/255.0); - if (attr_str[0]=='g') - return PyFloat_FromDouble(m_vertex->getRGBA()[1]/255.0); - if (attr_str[0]=='b') - return PyFloat_FromDouble(m_vertex->getRGBA()[2]/255.0); - if (attr_str[0]=='a') - return PyFloat_FromDouble(m_vertex->getRGBA()[3]/255.0); - - // UV - if (attr_str[0]=='u') - return PyFloat_FromDouble(m_vertex->getUV1()[0]); - if (attr_str[0]=='v') - return PyFloat_FromDouble(m_vertex->getUV1()[1]); - } - - - if (!strcmp(attr_str, "XYZ")) - return PyObjectFrom(MT_Vector3(m_vertex->getXYZ())); - - if (!strcmp(attr_str, "UV")) - return PyObjectFrom(MT_Point2(m_vertex->getUV1())); - - if (!strcmp(attr_str, "color") || !strcmp(attr_str, "colour")) - { - const unsigned char *colp = 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_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_VertexProxy* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_vertex->getXYZ()[0]); +} - if (!strcmp(attr_str, "normal")) - { - return PyObjectFrom(MT_Vector3(m_vertex->getNormal())); - } +PyObject* KX_VertexProxy::pyattr_get_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_VertexProxy* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_vertex->getXYZ()[1]); +} - py_getattro_up(CValue); +PyObject* KX_VertexProxy::pyattr_get_z(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_VertexProxy* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_vertex->getXYZ()[2]); } -#endif +PyObject* KX_VertexProxy::pyattr_get_r(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_VertexProxy* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_vertex->getRGBA()[0]/255.0); +} -#if 0 -int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) +PyObject* KX_VertexProxy::pyattr_get_g(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { - char *attr_str= _PyUnicode_AsString(attr); - if (PySequence_Check(pyvalue)) - { - if (!strcmp(attr_str, "XYZ")) - { - MT_Point3 vec; - if (PyVecTo(pyvalue, vec)) - { - m_vertex->SetXYZ(vec); - m_mesh->SetMeshModified(true); - return PY_SET_ATTR_SUCCESS; - } - return PY_SET_ATTR_FAIL; - } + KX_VertexProxy* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_vertex->getRGBA()[1]/255.0); +} - if (!strcmp(attr_str, "UV")) - { - MT_Point2 vec; - if (PyVecTo(pyvalue, vec)) - { - m_vertex->SetUV(vec); - m_mesh->SetMeshModified(true); - return PY_SET_ATTR_SUCCESS; - } - return PY_SET_ATTR_FAIL; - } +PyObject* KX_VertexProxy::pyattr_get_b(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_VertexProxy* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_vertex->getRGBA()[2]/255.0); +} - if (!strcmp(attr_str, "color") || !strcmp(attr_str, "colour")) - { - MT_Vector4 vec; - if (PyVecTo(pyvalue, vec)) - { - m_vertex->SetRGBA(vec); - m_mesh->SetMeshModified(true); - return PY_SET_ATTR_SUCCESS; - } - return PY_SET_ATTR_FAIL; - } +PyObject* KX_VertexProxy::pyattr_get_a(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_VertexProxy* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_vertex->getRGBA()[3]/255.0); +} - if (!strcmp(attr_str, "normal")) - { - MT_Vector3 vec; - if (PyVecTo(pyvalue, vec)) - { - m_vertex->SetNormal(vec); - m_mesh->SetMeshModified(true); - return PY_SET_ATTR_SUCCESS; - } - return PY_SET_ATTR_FAIL; - } - } - - if (PyFloat_Check(pyvalue)) - { - float val = PyFloat_AsDouble(pyvalue); - // pos - MT_Point3 pos(m_vertex->getXYZ()); - if (!strcmp(attr_str, "x")) +PyObject* KX_VertexProxy::pyattr_get_u(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_VertexProxy* self= static_cast(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(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(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(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(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(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(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(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(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + MT_Point3 pos(self->m_vertex->getXYZ()); pos.x() = val; - m_vertex->SetXYZ(pos); - m_mesh->SetMeshModified(true); + self->m_vertex->SetXYZ(pos); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } + return PY_SET_ATTR_FAIL; +} - if (!strcmp(attr_str, "y")) +int KX_VertexProxy::pyattr_set_y(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_VertexProxy* self= static_cast(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + MT_Point3 pos(self->m_vertex->getXYZ()); pos.y() = val; - m_vertex->SetXYZ(pos); - m_mesh->SetMeshModified(true); + self->m_vertex->SetXYZ(pos); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } + return PY_SET_ATTR_FAIL; +} - if (!strcmp(attr_str, "z")) +int KX_VertexProxy::pyattr_set_z(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_VertexProxy* self= static_cast(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + MT_Point3 pos(self->m_vertex->getXYZ()); pos.z() = val; - m_vertex->SetXYZ(pos); - m_mesh->SetMeshModified(true); + self->m_vertex->SetXYZ(pos); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } + return PY_SET_ATTR_FAIL; +} - // uv - MT_Point2 uv = m_vertex->getUV1(); - if (!strcmp(attr_str, "u")) +int KX_VertexProxy::pyattr_set_u(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_VertexProxy* self= static_cast(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + MT_Point2 uv = self->m_vertex->getUV1(); uv[0] = val; - m_vertex->SetUV(uv); - m_mesh->SetMeshModified(true); + self->m_vertex->SetUV(uv); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } + return PY_SET_ATTR_FAIL; +} - if (!strcmp(attr_str, "v")) +int KX_VertexProxy::pyattr_set_v(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_VertexProxy* self= static_cast(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + MT_Point2 uv = self->m_vertex->getUV1(); uv[1] = val; - m_vertex->SetUV(uv); - m_mesh->SetMeshModified(true); + self->m_vertex->SetUV(uv); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } + return PY_SET_ATTR_FAIL; +} - // uv - MT_Point2 uv2 = m_vertex->getUV2(); - if (!strcmp(attr_str, "u2")) +int KX_VertexProxy::pyattr_set_u2(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_VertexProxy* self= static_cast(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + MT_Point2 uv = self->m_vertex->getUV2(); uv[0] = val; - m_vertex->SetUV2(uv); - m_mesh->SetMeshModified(true); - return 0; + self->m_vertex->SetUV2(uv); + self->m_mesh->SetMeshModified(true); + return PY_SET_ATTR_SUCCESS; } + return PY_SET_ATTR_FAIL; +} - if (!strcmp(attr_str, "v2")) +int KX_VertexProxy::pyattr_set_v2(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_VertexProxy* self= static_cast(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + MT_Point2 uv = self->m_vertex->getUV2(); uv[1] = val; - m_vertex->SetUV2(uv); - m_mesh->SetMeshModified(true); + self->m_vertex->SetUV2(uv); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } + return PY_SET_ATTR_FAIL; +} - // col - unsigned int icol = *((const unsigned int *)m_vertex->getRGBA()); - unsigned char *cp = (unsigned char*) &icol; - val *= 255.0; - if (!strcmp(attr_str, "r")) +int KX_VertexProxy::pyattr_set_r(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_VertexProxy* self= static_cast(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA()); + unsigned char *cp = (unsigned char*) &icol; + val *= 255.0; cp[0] = (unsigned char) val; - m_vertex->SetRGBA(icol); - m_mesh->SetMeshModified(true); + self->m_vertex->SetRGBA(icol); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } - if (!strcmp(attr_str, "g")) + 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(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA()); + unsigned char *cp = (unsigned char*) &icol; + val *= 255.0; cp[1] = (unsigned char) val; - m_vertex->SetRGBA(icol); - m_mesh->SetMeshModified(true); + self->m_vertex->SetRGBA(icol); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } - if (!strcmp(attr_str, "b")) + 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(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA()); + unsigned char *cp = (unsigned char*) &icol; + val *= 255.0; cp[2] = (unsigned char) val; - m_vertex->SetRGBA(icol); - m_mesh->SetMeshModified(true); + self->m_vertex->SetRGBA(icol); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } - if (!strcmp(attr_str, "a")) + 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(self_v); + if (PyFloat_Check(value)) { + float val = PyFloat_AsDouble(value); + unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA()); + unsigned char *cp = (unsigned char*) &icol; + val *= 255.0; cp[3] = (unsigned char) val; - m_vertex->SetRGBA(icol); - m_mesh->SetMeshModified(true); + self->m_vertex->SetRGBA(icol); + self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } - } + return PY_SET_ATTR_FAIL; +} - return CValue::py_setattro(attr, pyvalue); +int KX_VertexProxy::pyattr_set_XYZ(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_VertexProxy* self= static_cast(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(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(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(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; } -#endif KX_VertexProxy::KX_VertexProxy(KX_MeshProxy*mesh, RAS_TexVert* vertex) : m_vertex(vertex), diff --git a/source/gameengine/Ketsji/KX_VertexProxy.h b/source/gameengine/Ketsji/KX_VertexProxy.h index 08fe0e7e2f8..b39d3ecb7d4 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.h +++ b/source/gameengine/Ketsji/KX_VertexProxy.h @@ -56,6 +56,37 @@ public: // stuff for python integration + static PyObject* pyattr_get_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_z(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_r(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_g(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_b(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_a(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_u(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_v(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_u2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_XYZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_UV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_normal(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_x(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_y(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_z(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_u(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_v(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_u2(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_v2(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_r(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_g(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_b(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_a(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_XYZ(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_UV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_color(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_normal(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + KX_PYMETHOD_NOARGS(KX_VertexProxy,GetXYZ); KX_PYMETHOD_O(KX_VertexProxy,SetXYZ); KX_PYMETHOD_NOARGS(KX_VertexProxy,GetUV); -- cgit v1.2.3