add support for passing lists of verts/edges/faces to bmesh operators
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -200,28 +200,59 @@ 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);
|
||||
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,
|
||||
"%.200s: keyword \"%.200s\" expected "
|
||||
|
||||
Reference in New Issue
Block a user