diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-05-01 10:50:43 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-05-01 10:50:43 +0400 |
commit | 9fe1fe0aa8a82ff59932db40b36ff46644297f0b (patch) | |
tree | d1b7943ecdf528caba4c67557240ac59f02435af | |
parent | ae4fda82b026ae6e2b003c1105f329b7e76582b0 (diff) |
bmesh py api:
add mtexpoly image access
-rw-r--r-- | source/blender/collada/MeshImporter.cpp | 1 | ||||
-rw-r--r-- | source/blender/gpu/GPU_extensions.h | 2 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types_customdata.c | 6 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types_meshdata.c | 92 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types_meshdata.h | 7 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 25 |
6 files changed, 127 insertions, 6 deletions
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 0bf33206fa7..73b2a1c23ad 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -845,7 +845,6 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri prim.mface++; // bind texture images to faces if (texture_face && (*color_texture)) { - texture_face->mode = TF_TEX; texture_face->tpage = (Image*)(*color_texture)->tex->ima; texture_face++; } diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index d5ca95acae8..b04da04258e 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -178,7 +178,7 @@ typedef enum GPUBuiltinShader { } GPUBuiltinShader; GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader); -void GPU_shader_free_builtin_shaders(); +void GPU_shader_free_builtin_shaders(void); /* Vertex attributes for shaders */ diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index 86cfa727e97..f25222c89da 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c @@ -989,8 +989,7 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer) } case CD_MTEXPOLY: { - ret = Py_NotImplemented; /* TODO */ - Py_INCREF(ret); + ret = BPy_BMTexPoly_CreatePyObject(value); break; } case CD_MLOOPUV: @@ -1083,8 +1082,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj } case CD_MTEXPOLY: { - PyErr_SetString(PyExc_AttributeError, "readonly"); /* could make this writeable later */ - ret = -1; + ret = BPy_BMTexPoly_AssignPyObject(value, py_value); break; } case CD_MLOOPUV: diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c index 39336abe944..aa78dc64f6b 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c @@ -41,9 +41,100 @@ #include "BLI_math_vector.h" #include "BKE_deform.h" +#include "BKE_library.h" #include "bmesh_py_types_meshdata.h" + +/* Mesh BMTexPoly + * ************** */ + +#define BPy_BMTexPoly_Check(v) (Py_TYPE(v) == &BPy_BMTexPoly_Type) + +typedef struct BPy_BMTexPoly { + PyObject_VAR_HEAD + MTexPoly *data; +} BPy_BMTexPoly; + +extern PyObject *pyrna_id_CreatePyObject(ID *id); +extern int pyrna_id_FromPyObject(PyObject *obj, ID **id); + +PyDoc_STRVAR(bpy_bmtexpoly_image_doc, +"Image or None.\n\n:type: :class:`bpy.types.Image`" +); +static PyObject *bpy_bmtexpoly_image_get(BPy_BMTexPoly *self, void *UNUSED(closure)) +{ + return pyrna_id_CreatePyObject((ID *)self->data->tpage); +} + +static int bpy_bmtexpoly_image_set(BPy_BMTexPoly *self, PyObject *value, void *UNUSED(closure)) +{ + ID *id; + + if (value == Py_None) { + id = NULL; + } + else if (pyrna_id_FromPyObject(value, &id) && id && GS(id->name) == ID_IM) { + /* pass */ + } + else { + PyErr_Format(PyExc_KeyError, "BMTexPoly.image = x" + "expected an image or None, not '%.200s'", + Py_TYPE(value)->tp_name); + return -1; + } + + id_lib_extern(id); + self->data->tpage = (struct Image *)id; + + return 0; +} + +static PyGetSetDef bpy_bmtexpoly_getseters[] = { + /* attributes match rna_def_mtpoly */ + {(char *)"image", (getter)bpy_bmtexpoly_image_get, (setter)bpy_bmtexpoly_image_set, (char *)bpy_bmtexpoly_image_doc, NULL}, + + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ +}; + +PyTypeObject BPy_BMTexPoly_Type = {{{0}}}; /* bm.loops.layers.uv.active */ + +static void bm_init_types_bmtexpoly(void) +{ + BPy_BMTexPoly_Type.tp_basicsize = sizeof(BPy_BMTexPoly); + + BPy_BMTexPoly_Type.tp_name = "BMTexPoly"; + + BPy_BMTexPoly_Type.tp_doc = NULL; // todo + + BPy_BMTexPoly_Type.tp_getset = bpy_bmtexpoly_getseters; + + BPy_BMTexPoly_Type.tp_flags = Py_TPFLAGS_DEFAULT; + + PyType_Ready(&BPy_BMTexPoly_Type); +} + +int BPy_BMTexPoly_AssignPyObject(struct MTexPoly *mtpoly, PyObject *value) +{ + if (UNLIKELY(!BPy_BMTexPoly_Check(value))) { + PyErr_Format(PyExc_TypeError, "expected BMTexPoly, not a %.200s", Py_TYPE(value)->tp_name); + return -1; + } + else { + *((MTexPoly *)mtpoly) = *(((BPy_BMTexPoly *)value)->data); + return 0; + } +} + +PyObject *BPy_BMTexPoly_CreatePyObject(struct MTexPoly *mtpoly) +{ + BPy_BMTexPoly *self = PyObject_New(BPy_BMTexPoly, &BPy_BMTexPoly_Type); + self->data = mtpoly; + return (PyObject *)self; +} + +/* --- End Mesh BMTexPoly --- */ + /* Mesh Loop UV * ************ */ @@ -597,6 +688,7 @@ PyObject *BPy_BMDeformVert_CreatePyObject(struct MDeformVert *dvert) /* call to init all types */ void BPy_BM_init_types_meshdata(void) { + bm_init_types_bmtexpoly(); bm_init_types_bmloopuv(); bm_init_types_bmloopcol(); bm_init_types_bmdvert(); diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.h b/source/blender/python/bmesh/bmesh_py_types_meshdata.h index 4636f800ed3..c9e8dce97a0 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.h +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.h @@ -40,10 +40,17 @@ typedef struct BPy_BMGenericMeshData { void *data; } BPy_BMGenericMeshData; +struct MTexPoly; struct MLoopUV; struct MLoopCol; struct MDeformVert; +int BPy_BMTexPoly_AssignPyObject(struct MTexPoly *mloopuv, PyObject *value); +PyObject *BPy_BMTexPoly_CreatePyObject(struct MTexPoly *mloopuv); + +int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *data, PyObject *value); +PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *data); + int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *data, PyObject *value); PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *data); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 12f0d45396d..2174241eeda 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -6254,6 +6254,31 @@ PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop) return (PyObject *)pyrna; } +/* utility func to be used by external modules, *sneaky!* */ +PyObject *pyrna_id_CreatePyObject(ID *id) +{ + if (id) { + PointerRNA ptr; + RNA_id_pointer_create(id, &ptr); + return pyrna_struct_CreatePyObject(&ptr); + } + else { + Py_RETURN_NONE; + } +} + +int pyrna_id_FromPyObject(PyObject *obj, ID **id) +{ + if (BPy_StructRNA_Check(obj) && (RNA_struct_is_ID(((BPy_StructRNA *)obj)->ptr.type))) { + *id = ((BPy_StructRNA *)obj)->ptr.id.data; + return TRUE; + } + else { + *id = NULL; + return FALSE; + } +} + void BPY_rna_init(void) { #ifdef USE_MATHUTILS // register mathutils callbacks, ok to run more then once. |