Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-03-18 03:22:44 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-03-18 03:22:44 +0400
commit560d8ad12cbef8573bbc48da4e56917ccfc75031 (patch)
treed4bdb36139ce6ec85ffbcf492b5b21a37865fdb8 /source/blender
parent05612c041964dd2950136af5486db9369969e2ae (diff)
bmesh py api:
use different types for bm.verts.layers, bm.faces.layers, otherwise the layers look to have customdata type that isnt compatible, UV's on edges for eg.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c5
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_customdata.c135
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_customdata.h7
3 files changed, 126 insertions, 21 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 84aadb9b8f6..c8e4c818262 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -2787,7 +2787,10 @@ PyObject *BPyInit_bmesh_types(void)
mod_type_add(submodule, BPy_BMEditSelSeq_Type);
mod_type_add(submodule, BPy_BMEditSelIter_Type);
/* bmesh_py_types_customdata.c */
- mod_type_add(submodule, BPy_BMLayerAccess_Type);
+ mod_type_add(submodule, BPy_BMLayerAccessVert_Type);
+ mod_type_add(submodule, BPy_BMLayerAccessEdge_Type);
+ mod_type_add(submodule, BPy_BMLayerAccessFace_Type);
+ mod_type_add(submodule, BPy_BMLayerAccessLoop_Type);
mod_type_add(submodule, BPy_BMLayerCollection_Type);
mod_type_add(submodule, BPy_BMLayerItem_Type);
/* bmesh_py_types_meshdata.c */
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 901b1d9fd5f..c7b271248de 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -81,6 +81,24 @@ static PyObject *bpy_bmlayeraccess_collection_get(BPy_BMLayerAccess *self, void
return BPy_BMLayerCollection_CreatePyObject(self->bm, self->htype, type);
}
+static PyObject *bpy_bmlayercollection_active_get(BPy_BMLayerItem *self, void *UNUSED(flag))
+{
+ CustomData *data;
+ int index;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ index = CustomData_get_active_layer_index(data, self->type);
+
+ if (index != -1) {
+ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
+}
+
static PyObject *bpy_bmlayeritem_name_get(BPy_BMLayerItem *self, void *UNUSED(flag))
{
CustomDataLayer *layer;
@@ -91,20 +109,55 @@ static PyObject *bpy_bmlayeritem_name_get(BPy_BMLayerItem *self, void *UNUSED(fl
return PyUnicode_FromString(layer->name);
}
-static PyGetSetDef bpy_bmlayeraccess_getseters[] = {
+static PyGetSetDef bpy_bmlayeraccess_vert_getseters[] = {
{(char *)"deform", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_MDEFORMVERT},
{(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_FLT},
{(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_INT},
{(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_STR},
+ {(char *)"shape", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_SHAPEKEY},
+ {(char *)"bevel_weight", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_BWEIGHT},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+};
+
+static PyGetSetDef bpy_bmlayeraccess_edge_getseters[] = {
+ {(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_FLT},
+ {(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_INT},
+ {(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_STR},
+
+ {(char *)"bevel_weight", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_BWEIGHT},
+ {(char *)"crease", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_CREASE},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+};
+
+static PyGetSetDef bpy_bmlayeraccess_face_getseters[] = {
+ {(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_FLT},
+ {(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_INT},
+ {(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_STR},
+
{(char *)"tex", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_MTEXPOLY},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+};
+
+static PyGetSetDef bpy_bmlayeraccess_loop_getseters[] = {
+ {(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_FLT},
+ {(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_INT},
+ {(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_PROP_STR},
+
{(char *)"uv", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_MLOOPUV},
{(char *)"color", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_MLOOPCOL},
- {(char *)"shape", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_SHAPEKEY},
- {(char *)"bevel_weight", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_BWEIGHT},
- {(char *)"crease", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)NULL, (void *)CD_CREASE},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+};
+
+
+static PyGetSetDef bpy_bmlayercollection_getseters[] = {
+ /* BMESH_TODO, make writeable */
+ {(char *)"active", (getter)bpy_bmlayercollection_active_get, (setter)NULL, (char *)NULL, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
@@ -474,14 +527,33 @@ static PyObject *bpy_bmlayercollection_iter(BPy_BMLayerCollection *self)
return iter;
}
-PyTypeObject BPy_BMLayerAccess_Type = {{{0}}}; /* bm.verts.layers */
-PyTypeObject BPy_BMLayerCollection_Type = {{{0}}}; /* bm.verts.layers.uv */
-PyTypeObject BPy_BMLayerItem_Type = {{{0}}}; /* bm.verts.layers.uv["UVMap"] */
+PyTypeObject BPy_BMLayerAccessVert_Type = {{{0}}}; /* bm.verts.layers */
+PyTypeObject BPy_BMLayerAccessEdge_Type = {{{0}}}; /* bm.edges.layers */
+PyTypeObject BPy_BMLayerAccessFace_Type = {{{0}}}; /* bm.faces.layers */
+PyTypeObject BPy_BMLayerAccessLoop_Type = {{{0}}}; /* bm.loops.layers */
+PyTypeObject BPy_BMLayerCollection_Type = {{{0}}}; /* bm.loops.layers.uv */
+PyTypeObject BPy_BMLayerItem_Type = {{{0}}}; /* bm.loops.layers.uv["UVMap"] */
PyObject *BPy_BMLayerAccess_CreatePyObject(BMesh *bm, const char htype)
{
- BPy_BMLayerAccess *self = PyObject_New(BPy_BMLayerAccess, &BPy_BMLayerAccess_Type);
+ BPy_BMLayerAccess *self;
+ PyTypeObject *type;
+
+ switch (htype) {
+ case BM_VERT: type = &BPy_BMLayerAccessVert_Type; break;
+ case BM_EDGE: type = &BPy_BMLayerAccessEdge_Type; break;
+ case BM_FACE: type = &BPy_BMLayerAccessFace_Type; break;
+ case BM_LOOP: type = &BPy_BMLayerAccessLoop_Type; break;
+ default:
+ {
+ BLI_assert(0);
+ type = NULL;
+ break;
+ }
+ }
+
+ self = PyObject_New(BPy_BMLayerAccess, type);
self->bm = bm;
self->htype = htype;
return (PyObject *)self;
@@ -509,24 +581,40 @@ PyObject *BPy_BMLayerItem_CreatePyObject(BMesh *bm, const char htype, int type,
void BPy_BM_init_types_customdata(void)
{
- BPy_BMLayerAccess_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
+ BPy_BMLayerAccessVert_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
+ BPy_BMLayerAccessEdge_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
+ BPy_BMLayerAccessFace_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
+ BPy_BMLayerAccessLoop_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
BPy_BMLayerCollection_Type.tp_basicsize = sizeof(BPy_BMLayerCollection);
BPy_BMLayerItem_Type.tp_basicsize = sizeof(BPy_BMLayerItem);
- BPy_BMLayerAccess_Type.tp_name = "BMLayerAccess";
+ BPy_BMLayerAccessVert_Type.tp_name = "BMLayerAccessVert";
+ BPy_BMLayerAccessEdge_Type.tp_name = "BMLayerAccessEdge";
+ BPy_BMLayerAccessFace_Type.tp_name = "BMLayerAccessFace";
+ BPy_BMLayerAccessLoop_Type.tp_name = "BMLayerAccessLoop";
BPy_BMLayerCollection_Type.tp_name = "BMLayerCollection";
BPy_BMLayerItem_Type.tp_name = "BMLayerItem";
- BPy_BMLayerAccess_Type.tp_doc = NULL; // todo
+ /* todo */
+ BPy_BMLayerAccessVert_Type.tp_doc = NULL;
+ BPy_BMLayerAccessEdge_Type.tp_doc = NULL;
+ BPy_BMLayerAccessFace_Type.tp_doc = NULL;
+ BPy_BMLayerAccessLoop_Type.tp_doc = NULL;
BPy_BMLayerCollection_Type.tp_doc = NULL;
BPy_BMLayerItem_Type.tp_doc = NULL;
- BPy_BMLayerAccess_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerAccessVert_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerAccessEdge_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerAccessFace_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerAccessLoop_Type.tp_repr = (reprfunc)NULL;
BPy_BMLayerCollection_Type.tp_repr = (reprfunc)NULL;
BPy_BMLayerItem_Type.tp_repr = (reprfunc)NULL;
- BPy_BMLayerAccess_Type.tp_getset = bpy_bmlayeraccess_getseters;
- BPy_BMLayerCollection_Type.tp_getset = NULL;
+ BPy_BMLayerAccessVert_Type.tp_getset = bpy_bmlayeraccess_vert_getseters;
+ BPy_BMLayerAccessEdge_Type.tp_getset = bpy_bmlayeraccess_edge_getseters;
+ BPy_BMLayerAccessFace_Type.tp_getset = bpy_bmlayeraccess_face_getseters;
+ BPy_BMLayerAccessLoop_Type.tp_getset = bpy_bmlayeraccess_loop_getseters;
+ BPy_BMLayerCollection_Type.tp_getset = bpy_bmlayercollection_getseters;
BPy_BMLayerItem_Type.tp_getset = bpy_bmlayeritem_getseters;
@@ -539,17 +627,26 @@ void BPy_BM_init_types_customdata(void)
BPy_BMLayerCollection_Type.tp_iter = (getiterfunc)bpy_bmlayercollection_iter;
- BPy_BMLayerAccess_Type.tp_dealloc = NULL; //(destructor)bpy_bmeditselseq_dealloc;
- BPy_BMLayerCollection_Type.tp_dealloc = NULL; //(destructor)bpy_bmvert_dealloc;
- BPy_BMLayerItem_Type.tp_dealloc = NULL; //(destructor)bpy_bmvert_dealloc;
+ BPy_BMLayerAccessVert_Type.tp_dealloc = NULL;
+ BPy_BMLayerAccessEdge_Type.tp_dealloc = NULL;
+ BPy_BMLayerAccessFace_Type.tp_dealloc = NULL;
+ BPy_BMLayerAccessLoop_Type.tp_dealloc = NULL;
+ BPy_BMLayerCollection_Type.tp_dealloc = NULL;
+ BPy_BMLayerItem_Type.tp_dealloc = NULL;
- BPy_BMLayerAccess_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerAccessVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerAccessEdge_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerAccessFace_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerAccessLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT;
BPy_BMLayerCollection_Type.tp_flags = Py_TPFLAGS_DEFAULT;
BPy_BMLayerItem_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- PyType_Ready(&BPy_BMLayerAccess_Type);
+ PyType_Ready(&BPy_BMLayerAccessVert_Type);
+ PyType_Ready(&BPy_BMLayerAccessEdge_Type);
+ PyType_Ready(&BPy_BMLayerAccessFace_Type);
+ PyType_Ready(&BPy_BMLayerAccessLoop_Type);
PyType_Ready(&BPy_BMLayerCollection_Type);
PyType_Ready(&BPy_BMLayerItem_Type);
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.h b/source/blender/python/bmesh/bmesh_py_types_customdata.h
index 6ec947f98fa..c777150b25f 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.h
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.h
@@ -30,7 +30,12 @@
#ifndef __BMESH_PY_TYPES_CUSTOMDATA_H__
#define __BMESH_PY_TYPES_CUSTOMDATA_H__
-extern PyTypeObject BPy_BMLayerAccess_Type;
+/* all use BPy_BMLayerAccess struct */
+extern PyTypeObject BPy_BMLayerAccessVert_Type;
+extern PyTypeObject BPy_BMLayerAccessEdge_Type;
+extern PyTypeObject BPy_BMLayerAccessFace_Type;
+extern PyTypeObject BPy_BMLayerAccessLoop_Type;
+
extern PyTypeObject BPy_BMLayerCollection_Type;
extern PyTypeObject BPy_BMLayerItem_Type;