diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-03-30 21:30:24 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-03-30 21:30:24 +0400 |
commit | bbbbe1b00ea9dc46a4d837239748bfeceeda65e7 (patch) | |
tree | 6568053fe72620357039691885f4d62863b94942 /source/blender | |
parent | d5ffec12a078050dc2572d5c85b9ba2b235f92aa (diff) |
Add BMO function to append to a buffer slot.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operator_api.h | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 32 |
2 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index e840026b540..e2062bdf8f8 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -289,6 +289,10 @@ void BMO_slot_mat3_set(BMOperator *op, const char *slotname, float r_mat[3][3]); void BMO_mesh_flag_disable_all(BMesh *bm, BMOperator *op, const char htype, const short oflag); +/* copies the values from another slot to the end of the output slot */ +void BMO_slot_buffer_append(BMOperator *output_op, const char *output_op_slot, + BMOperator *other_op, const char *other_op_slot); + /* puts every element of type type (which is a bitmask) with tool flag flag, * into a slot. */ void BMO_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname, diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 3c348b91f78..58c38def33f 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -725,6 +725,38 @@ void BMO_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *slotname, } /** + * Copies the values from another slot to the end of the output slot. + */ +void BMO_slot_buffer_append(BMOperator *output_op, const char *output_slot_name, + BMOperator *other_op, const char *other_slot_name) +{ + BMOpSlot *output_slot = BMO_slot_get(output_op, output_slot_name); + BMOpSlot *other_slot = BMO_slot_get(other_op, other_slot_name); + + BLI_assert(output_slot->slottype == BMO_OP_SLOT_ELEMENT_BUF && + other_slot->slottype == BMO_OP_SLOT_ELEMENT_BUF); + + if (output_slot->len == 0) { + /* output slot is empty, copy rather than append */ + BMO_slot_copy(other_op, output_op, other_slot_name, output_slot_name); + } + else if (other_slot->len != 0) { + int elem_size = BMO_OPSLOT_TYPEINFO[output_slot->slottype]; + int alloc_size = elem_size * (output_slot->len + other_slot->len); + /* allocate new buffer */ + void *buf = BLI_memarena_alloc(output_op->arena, alloc_size); + + /* copy slot data */ + memcpy(buf, output_slot->data.buf, elem_size * output_slot->len); + memcpy(((char*)buf) + elem_size * output_slot->len, + other_slot->data.buf, elem_size * other_slot->len); + + output_slot->data.buf = buf; + output_slot->len += other_slot->len; + } +} + +/** * \brief BMO_FLAG_TO_SLOT * * Copies elements of a certain type, which have a certain flag set |