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-06-30 16:58:04 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-06-30 16:58:04 +0400
commite6d55c97ddea01ba08c9f01888adf715ab2c6ef0 (patch)
tree759b6a339e96ce9dd88bd41e71f5a5f3727b5f6e
parent3e99ec8d3d9e6eccf1b891a0e66432026fc622c5 (diff)
add support for passing lists of verts/edges/faces to bmesh operators
-rw-r--r--source/blender/bmesh/intern/bmesh_opdefines.c2
-rw-r--r--source/blender/bmesh/intern/bmesh_operator_api.h2
-rw-r--r--source/blender/bmesh/intern/bmesh_operators.c8
-rw-r--r--source/blender/python/bmesh/bmesh_py_ops.c49
4 files changed, 47 insertions, 14 deletions
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index f606347baf6..e281e759098 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1034,7 +1034,7 @@ static BMOpDefine bmo_bevel_def = {
{{BMO_OP_SLOT_ELEMENT_BUF, "geom"}, /* input edges and vertices */
{BMO_OP_SLOT_ELEMENT_BUF, "face_spans"}, /* new geometry */
{BMO_OP_SLOT_ELEMENT_BUF, "face_holes"}, /* new geometry */
- {BMO_OP_SLOT_BOOL, "use_lengths"}, /* grab edge lengths from a PROP_FLT customdata laye */
+ {BMO_OP_SLOT_BOOL, "use_lengths"}, /* grab edge lengths from a PROP_FLT customdata layer */
{BMO_OP_SLOT_BOOL, "use_even"}, /* corner vert placement: use shell/angle calculations */
{BMO_OP_SLOT_BOOL, "use_dist"}, /* corner vert placement: evaluate percent as a distance,
* modifier uses this. We could do this as another float setting */
diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h
index c6dd33b7a4b..aa005d1769b 100644
--- a/source/blender/bmesh/intern/bmesh_operator_api.h
+++ b/source/blender/bmesh/intern/bmesh_operator_api.h
@@ -352,6 +352,8 @@ int BMO_vert_edge_flags_count(BMesh *bm, BMVert *v, const short oflag);
void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, const char *slot_name,
const char hflag, const short oflag);
+void *BMO_slot_buffer_alloc(BMOperator *op, const char *slot_name, const int len);
+
void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, const char *slot_name,
const char htype);
diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c
index 48d3cc3721a..7cd73c6f065 100644
--- a/source/blender/bmesh/intern/bmesh_operators.c
+++ b/source/blender/bmesh/intern/bmesh_operators.c
@@ -625,7 +625,7 @@ void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, const char *slot_name,
}
}
-static void *bmo_slot_buffer_alloc(BMOperator *op, const char *slot_name, int len)
+void *BMO_slot_buffer_alloc(BMOperator *op, const char *slot_name, const int len)
{
BMOpSlot *slot = BMO_slot_get(op, slot_name);
BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
@@ -658,7 +658,7 @@ void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, const char *slot_name,
BMIter iter;
BMHeader *ele;
- bmo_slot_buffer_alloc(op, slot_name, totelement);
+ BMO_slot_buffer_alloc(op, slot_name, totelement);
/* TODO - collapse these loops into one */
@@ -709,7 +709,7 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *sl
BMIter iter;
BMElem *ele;
- bmo_slot_buffer_alloc(op, slot_name, totelement);
+ BMO_slot_buffer_alloc(op, slot_name, totelement);
/* TODO - collapse these loops into one */
@@ -821,7 +821,7 @@ static void bmo_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slo
BMHeader *ele;
BMHeader **ele_array;
- bmo_slot_buffer_alloc(op, slot_name, totelement);
+ BMO_slot_buffer_alloc(op, slot_name, totelement);
ele_array = (BMHeader **)slot->data.p;
diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c
index d64c1206d99..b71f5d9e085 100644
--- a/source/blender/python/bmesh/bmesh_py_ops.c
+++ b/source/blender/python/bmesh/bmesh_py_ops.c
@@ -200,27 +200,58 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *
"%.200s: keyword \"%.200s\" " type_string " are from another bmesh", \
self->opname, slot_name, slot->slot_type); \
return NULL; \
- }
+ } (void)0
if (BPy_BMVertSeq_Check(value)) {
- BPY_BM_GENERIC_MESH_TEST("verts")
+ BPY_BM_GENERIC_MESH_TEST("verts");
BMO_slot_buffer_from_all(bm, &bmop, slot_name, BM_VERT);
}
else if (BPy_BMEdgeSeq_Check(value)) {
- BPY_BM_GENERIC_MESH_TEST("edges")
+ BPY_BM_GENERIC_MESH_TEST("edges");
BMO_slot_buffer_from_all(bm, &bmop, slot_name, BM_EDGE);
}
else if (BPy_BMFaceSeq_Check(value)) {
- BPY_BM_GENERIC_MESH_TEST("faces")
+ BPY_BM_GENERIC_MESH_TEST("faces");
BMO_slot_buffer_from_all(bm, &bmop, slot_name, BM_FACE);
}
else if (BPy_BMElemSeq_Check(value)) {
- BPY_BM_GENERIC_MESH_TEST("elements")
+ BMIter iter;
+ BMHeader *ele;
+ int tot;
+ unsigned int i;
- PyErr_Format(PyExc_NotImplementedError,
- "%.200s: keyword \"%.200s\" parsing element lists not working yet!",
- self->opname, slot_name, slot->slot_type);
- return NULL;
+ BPY_BM_GENERIC_MESH_TEST("elements");
+
+ /* this will loop over all elements which is a shame but
+ * we need to know this before alloc */
+ /* calls bpy_bmelemseq_length() */
+ tot = Py_TYPE(value)->tp_as_sequence->sq_length((PyObject *)self);
+
+ BMO_slot_buffer_alloc(&bmop, slot_name, tot);
+
+ i = 0;
+ BM_ITER_BPY_BM_SEQ (ele, &iter, ((BPy_BMElemSeq *)value)) {
+ ((void **)slot->data.buf)[i] = (void *)ele;
+ i++;
+ }
+ }
+ /* keep this last */
+ else if (PySequence_Check(value)) {
+ BMElem **elem_array = NULL;
+ int elem_array_len;
+
+ elem_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
+ &elem_array_len, BM_VERT | BM_EDGE | BM_FACE,
+ TRUE, TRUE, slot_name);
+
+ /* error is set above */
+ if (elem_array == NULL) {
+ return NULL;
+ }
+
+ BMO_slot_buffer_alloc(&bmop, slot_name, elem_array_len);
+ memcpy(slot->data.buf, elem_array, sizeof(void *) * elem_array_len);
+ PyMem_FREE(elem_array);
}
else {
PyErr_Format(PyExc_TypeError,