diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-11-27 13:21:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-11-27 13:21:57 +0400 |
commit | a9855c227e6bfc955a6b2f15e8ee656218c3f916 (patch) | |
tree | 8e49eb73516a927b9cfb1516d764d14c857a9af1 /source/blender/bmesh | |
parent | 0cd26e6066a071ecd230aa9b865b9223ea4ba13a (diff) |
py/bmesh api - add support for single item buffers (odd feature but used quite a bit with bmesh operators).
also add utility functions BMO_slot_buffer_from_single(), BMO_slot_buffer_get_single()
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_opdefines.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operator_api.h | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 28 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_removedoubles.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_slide.c | 17 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_utils.c | 12 |
6 files changed, 41 insertions, 24 deletions
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 75f187e3837..2a7757dbfa1 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -1546,7 +1546,7 @@ static BMOpDefine bmo_slide_vert_def = { "slide_vert", /* slots_in */ {{"vert", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT | BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE}}, - {"edge", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE | BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE}}, + {"edges", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}}, {"distance_t", BMO_OP_SLOT_FLT}, {{'\0'}}, }, diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index 1bb83a12e48..bebd3215d93 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -417,6 +417,10 @@ void BMO_slot_buffer_from_disabled_hflag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const char htype, const char hflag); +void BMO_slot_buffer_from_single(BMOperator *op, BMOpSlot *slot, BMHeader *ele); +void *BMO_slot_buffer_get_single(BMOpSlot *slot); + + /* counts number of elements inside a slot array. */ int BMO_slot_buffer_count(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name); int BMO_slot_map_count(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name); diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 20fffe71636..54866c756cb 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -867,6 +867,29 @@ void BMO_slot_buffer_from_disabled_hflag(BMesh *bm, BMOperator *op, bmo_slot_buffer_from_hflag(bm, op, slot_args, slot_name, htype, hflag, FALSE); } +void BMO_slot_buffer_from_single(BMOperator *op, BMOpSlot *slot, BMHeader *ele) +{ + BMO_ASSERT_SLOT_IN_OP(slot, op); + BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF); + BLI_assert(slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE); + BLI_assert(slot->len == 0 || slot->len == 1); + + BLI_assert(slot->slot_subtype.elem & ele->htype); + + slot->data.buf = BLI_memarena_alloc(op->arena, sizeof(void *) * 4); /* XXX, why 'x4' ? */ + slot->len = 1; + *slot->data.buf = ele; +} + +void *BMO_slot_buffer_get_single(BMOpSlot *slot) +{ + BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF); + BLI_assert(slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE); + BLI_assert(slot->len == 0 || slot->len == 1); + + return slot->len ? (BMHeader *)slot->data.buf[0] : NULL; +} + /** * Copies the values from another slot to the end of the output slot. */ @@ -1580,12 +1603,11 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, v } case 'e': { + /* XXX we have 'e' but no equivalent for verts/faces - why? we could use (V/E/P)*/ BMHeader *ele = va_arg(vlist, void *); BMOpSlot *slot = BMO_slot_get(op->slots_in, slot_name); - slot->data.buf = BLI_memarena_alloc(op->arena, sizeof(void *) * 4); - slot->len = 1; - *slot->data.buf = ele; + BMO_slot_buffer_from_single(op, slot, ele); state = 1; break; diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index 06d11c7b19d..7fb78d2d160 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -263,7 +263,7 @@ void bmo_pointmerge_facedata_exec(BMesh *bm, BMOperator *op) float fac; int i, tot; - snapv = BMO_iter_new(&siter, op->slots_in, "snapv", BM_VERT); + snapv = BMO_slot_buffer_get_single(BMO_slot_get(op->slots_in, "snapv")); tot = BM_vert_face_count(snapv); if (!tot) diff --git a/source/blender/bmesh/operators/bmo_slide.c b/source/blender/bmesh/operators/bmo_slide.c index 9dde2461364..040c2d41e9c 100644 --- a/source/blender/bmesh/operators/bmo_slide.c +++ b/source/blender/bmesh/operators/bmo_slide.c @@ -56,8 +56,7 @@ void bmo_slide_vert_exec(BMesh *bm, BMOperator *op) const float distance_t = BMO_slot_float_get(op->slots_in, "distance_t"); /* Get start vertex */ - vertex = BMO_iter_new(&oiter, op->slots_in, "vert", BM_VERT); - + vertex = BMO_slot_buffer_get_single(BMO_slot_get(op->slots_in, "vert")); if (!vertex) { if (G.debug & G_DEBUG) { @@ -67,15 +66,13 @@ void bmo_slide_vert_exec(BMesh *bm, BMOperator *op) return; } + /* BMESH_TODO - this is odd, it only uses one edge, why take a list at all? */ /* Count selected edges */ - BMO_ITER (h, &oiter, op->slots_in, "edge", BM_VERT | BM_EDGE) { - switch (h->htype) { - case BM_EDGE: - selected_edges++; - /* Mark all selected edges (cast BMHeader->BMEdge) */ - BMO_elem_flag_enable(bm, (BMElemF *)h, EDGE_MARK); - break; - } + BMO_ITER (h, &oiter, op->slots_in, "edges", BM_EDGE) { + selected_edges++; + /* Mark all selected edges (cast BMHeader->BMEdge) */ + BMO_elem_flag_enable(bm, (BMElemF *)h, EDGE_MARK); + break; } /* Only allow sliding if an edge is selected */ diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c index 203acff8332..c7ab8f62f40 100644 --- a/source/blender/bmesh/operators/bmo_utils.c +++ b/source/blender/bmesh/operators/bmo_utils.c @@ -701,9 +701,8 @@ typedef struct ElemNode { void bmo_shortest_path_exec(BMesh *bm, BMOperator *op) { - BMOIter vs_iter /* , vs2_iter */; /* selected verts iterator */ BMIter v_iter; /* mesh verts iterator */ - BMVert *vs, *sv, *ev; /* starting vertex, ending vertex */ + BMVert *sv, *ev; /* starting vertex, ending vertex */ BMVert *v; /* mesh vertex */ Heap *h = NULL; @@ -712,13 +711,8 @@ void bmo_shortest_path_exec(BMesh *bm, BMOperator *op) int num_total = 0 /*, num_sels = 0 */, i = 0; const int type = BMO_slot_int_get(op->slots_in, "type"); - /* BMESH_TODO use BMO_slot_buffer_elem_first here? */ - BMO_ITER (vs, &vs_iter, op->slots_in, "startv", BM_VERT) { - sv = vs; - } - BMO_ITER (vs, &vs_iter, op->slots_in, "endv", BM_VERT) { - ev = vs; - } + sv = BMO_slot_buffer_get_single(BMO_slot_get(op->slots_in, "startv")); + ev = BMO_slot_buffer_get_single(BMO_slot_get(op->slots_in, "endv")); num_total = BM_mesh_elem_count(bm, BM_VERT); |