diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-04-05 11:41:03 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-04-05 11:41:03 +0400 |
commit | 77da8461f3ed620ec06d69315d24b22d514d26f4 (patch) | |
tree | afb858c53c0f1c0af683c3b128319b3a9f8596ed | |
parent | 3fa7717b57f5d0c9667caec856e214c7597ce42c (diff) |
Make materials use PyAttributeDef's
-rw-r--r-- | source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 232 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PolygonMaterial.h | 12 |
2 files changed, 105 insertions, 139 deletions
diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 6b9a6201d5c..c5bddd6d166 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -181,6 +181,28 @@ PyMethodDef KX_PolygonMaterial::Methods[] = { }; PyAttributeDef KX_PolygonMaterial::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("texture", KX_PolygonMaterial, pyattr_get_texture), + KX_PYATTRIBUTE_RO_FUNCTION("material", KX_PolygonMaterial, pyattr_get_material), /* should probably be .name ? */ + + KX_PYATTRIBUTE_INT_RW("tile", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tile), + KX_PYATTRIBUTE_INT_RW("tilexrep", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tilexrep), + KX_PYATTRIBUTE_INT_RW("tileyrep", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tileyrep), + KX_PYATTRIBUTE_INT_RW("drawingmode", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_drawingmode), + KX_PYATTRIBUTE_INT_RW("lightlayer", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_lightlayer), + + KX_PYATTRIBUTE_BOOL_RW("transparent", KX_PolygonMaterial, m_alpha), + KX_PYATTRIBUTE_BOOL_RW("zsort", KX_PolygonMaterial, m_zsort), + + KX_PYATTRIBUTE_FLOAT_RW("shininess", 0.0f, 1000.0f, KX_PolygonMaterial, m_shininess), + KX_PYATTRIBUTE_FLOAT_RW("specularity", 0.0f, 1000.0f, KX_PolygonMaterial, m_specularity), + + KX_PYATTRIBUTE_RW_FUNCTION("diffuse", KX_PolygonMaterial, pyattr_get_texture, pyattr_set_diffuse), + KX_PYATTRIBUTE_RW_FUNCTION("specular",KX_PolygonMaterial, pyattr_get_specular, pyattr_set_specular), + + KX_PYATTRIBUTE_RO_FUNCTION("tface", KX_PolygonMaterial, pyattr_get_tface), /* How the heck is this even useful??? - Campbell */ + KX_PYATTRIBUTE_RO_FUNCTION("gl_texture", KX_PolygonMaterial, pyattr_get_gl_texture), /* could be called 'bindcode' */ + + /* triangle used to be an attribute, removed for 2.49, nobody should be using it */ { NULL } //Sentinel }; @@ -211,151 +233,20 @@ PyParentObject KX_PolygonMaterial::Parents[] = { PyObject* KX_PolygonMaterial::py_getattro(PyObject *attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "texture")) - return PyString_FromString(m_texturename.ReadPtr()); - if (!strcmp(attr_str, "material")) - return PyString_FromString(m_materialname.ReadPtr()); - - if (!strcmp(attr_str, "tface")) - return PyCObject_FromVoidPtr(m_tface, NULL); - - if (!strcmp(attr_str, "gl_texture")) - { - Image *ima = m_tface->tpage; - int bind = 0; - if (ima) - bind = ima->bindcode; - - return PyInt_FromLong(bind); - } - - if (!strcmp(attr_str, "tile")) - return PyInt_FromLong(m_tile); - if (!strcmp(attr_str, "tilexrep")) - return PyInt_FromLong(m_tilexrep); - if (!strcmp(attr_str, "tileyrep")) - return PyInt_FromLong(m_tileyrep); - - if (!strcmp(attr_str, "drawingmode")) - return PyInt_FromLong(m_drawingmode); - if (!strcmp(attr_str, "transparent")) - return PyInt_FromLong(m_alpha); - if (!strcmp(attr_str, "zsort")) - return PyInt_FromLong(m_zsort); - if (!strcmp(attr_str, "lightlayer")) - return PyInt_FromLong(m_lightlayer); - if (!strcmp(attr_str, "triangle")) - // deprecated, triangle/quads shouldn't have been a material property - return 0; - - if (!strcmp(attr_str, "diffuse")) - return PyObjectFrom(m_diffuse); - if (!strcmp(attr_str, "shininess")) - return PyFloat_FromDouble(m_shininess); - if (!strcmp(attr_str, "specular")) - return PyObjectFrom(m_specular); - if (!strcmp(attr_str, "specularity")) - return PyFloat_FromDouble(m_specularity); + PyObject* object = py_getattro_self(Attributes, this, attr); + if (object != NULL) + return object; py_getattro_up(PyObjectPlus); } -int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *pyvalue) +int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *value) { - char *attr_str= PyString_AsString(attr); - if (PyFloat_Check(pyvalue)) - { - float value = PyFloat_AsDouble(pyvalue); - if (!strcmp(attr_str, "shininess")) - { - m_shininess = value; - return 0; - } - - if (!strcmp(attr_str, "specularity")) - { - m_specularity = value; - return 0; - } - } - - if (PyInt_Check(pyvalue)) - { - int value = PyInt_AsLong(pyvalue); - if (!strcmp(attr_str, "tile")) - { - m_tile = value; - return 0; - } - - if (!strcmp(attr_str, "tilexrep")) - { - m_tilexrep = value; - return 0; - } - - if (!strcmp(attr_str, "tileyrep")) - { - m_tileyrep = value; - return 0; - } - - if (!strcmp(attr_str, "drawingmode")) - { - m_drawingmode = value; - return 0; - } - - if (!strcmp(attr_str, "transparent")) - { - m_alpha = value; - return 0; - } - - if (!strcmp(attr_str, "zsort")) - { - m_zsort = value; - return 0; - } - - if (!strcmp(attr_str, "lightlayer")) - { - m_lightlayer = value; - return 0; - } - - // This probably won't work... - if (!strcmp(attr_str, "triangle")) - { - // deprecated, triangle/quads shouldn't have been a material property - return 0; - } - } - - if (PySequence_Check(pyvalue)) - { - if (PySequence_Size(pyvalue) == 3) - { - MT_Vector3 value; - if (PyVecTo(pyvalue, value)) - { - if (!strcmp(attr_str, "diffuse")) - { - m_diffuse = value; - return 0; - } - - if (!strcmp(attr_str, "specular")) - { - m_specular = value; - return 0; - } - } - } - } + int ret = py_setattro_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; - return PyObjectPlus::py_setattro(attr, pyvalue); + return PyObjectPlus::py_setattro(attr, value); } KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)") @@ -419,3 +310,66 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, activate, "activate(rasty, cachingInfo)") return NULL; } + +PyObject* KX_PolygonMaterial::pyattr_get_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v); + return PyString_FromString(self->m_texturename.ReadPtr()); +} + +PyObject* KX_PolygonMaterial::pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v); + return PyString_FromString(self->m_materialname.ReadPtr()); +} + +/* this does not seem useful */ +PyObject* KX_PolygonMaterial::pyattr_get_tface(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v); + return PyCObject_FromVoidPtr(self->m_tface, NULL); +} + +PyObject* KX_PolygonMaterial::pyattr_get_gl_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v); + Image *ima = self->m_tface->tpage; + return PyInt_FromLong(ima ? ima->bindcode:0); +} + + +PyObject* KX_PolygonMaterial::pyattr_get_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v); + return PyObjectFrom(self->m_diffuse); +} + +int KX_PolygonMaterial::pyattr_set_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v); + MT_Vector3 vec; + + if (!PyVecTo(value, vec)) + return -1; + + self->m_diffuse= vec; + return 0; +} + +PyObject* KX_PolygonMaterial::pyattr_get_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v); + return PyObjectFrom(self->m_specular); +} + +int KX_PolygonMaterial::pyattr_set_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v); + MT_Vector3 vec; + + if (!PyVecTo(value, vec)) + return -1; + + self->m_specular= vec; + return 0; +} diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h index f3eb1979f34..1e8ce5c3367 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.h +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h @@ -117,6 +117,18 @@ public: virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *pyvalue); + + + static PyObject* pyattr_get_texture(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_tface(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_gl_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + static PyObject* pyattr_get_diffuse(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_specular(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); }; #endif // __KX_POLYGONMATERIAL_H__ |