[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40958] branches/bmesh/blender/source/ blender/bmesh: Fix for not correctly removing doubles after adding builtin primitive meshes (e.g.
Andrew Wiggin
ender79bl at gmail.com
Wed Oct 12 16:16:06 CEST 2011
Revision: 40958
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40958
Author: ender79
Date: 2011-10-12 14:16:05 +0000 (Wed, 12 Oct 2011)
Log Message:
-----------
Fix for not correctly removing doubles after adding builtin primitive meshes (e.g. uvsphere)
Modified Paths:
--------------
branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c
Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h 2011-10-12 13:53:03 UTC (rev 40957)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h 2011-10-12 14:16:05 UTC (rev 40958)
@@ -217,7 +217,10 @@
plus EDBM_CallOpf in bmeshutils.c.*/
int BMO_VInitOpf(BMesh *bm, BMOperator *op, const char *fmt, va_list vlist);
-/*get a point to a slot. this may be removed layer on from the public API.*/
+/*test whether a named slot exists*/
+int BMO_HasSlot(struct BMOperator *op, const char *slotname);
+
+/*get a pointer to a slot. this may be removed layer on from the public API.*/
BMOpSlot *BMO_GetSlot(struct BMOperator *op, const char *slotname);
/*copies the data of a slot from one operator to another. src and dst are the
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c 2011-10-12 13:53:03 UTC (rev 40957)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c 2011-10-12 14:16:05 UTC (rev 40958)
@@ -18,6 +18,7 @@
static void free_flag_layer(BMesh *bm);
static void clear_flag_layer(BMesh *bm);
static int bmesh_name_to_slotcode(BMOpDefine *def, const char *name);
+static int bmesh_name_to_slotcode_check(BMOpDefine *def, const char *name);
static int bmesh_opname_to_opcode(const char *opname);
static const char *bmop_error_messages[] = {
@@ -48,6 +49,9 @@
sizeof(element_mapping)
};
+/* Dummy slot so there is something to return when slot name lookup fails */
+static BMOpSlot BMOpEmptySlot = { 0 };
+
void BMO_Set_OpFlag(BMesh *UNUSED(bm), BMOperator *op, int flag)
{
op->flag |= flag;
@@ -176,6 +180,20 @@
}
/*
+ * BMESH OPSTACK HAS SLOT
+ *
+ * Returns 1 if the named slot exists on the given operator,
+ * otherwise returns 0.
+ *
+*/
+
+int BMO_HasSlot(BMOperator *op, const char *slotname)
+{
+ int slotcode = bmesh_name_to_slotcode(opdefines[op->type], slotname);
+ return (slotcode >= 0);
+}
+
+/*
* BMESH OPSTACK GET SLOT
*
* Returns a pointer to the slot of
@@ -185,8 +203,12 @@
BMOpSlot *BMO_GetSlot(BMOperator *op, const char *slotname)
{
- int slotcode = bmesh_name_to_slotcode(opdefines[op->type], slotname);
+ int slotcode = bmesh_name_to_slotcode_check(opdefines[op->type], slotname);
+ if (slotcode < 0) {
+ return &BMOpEmptySlot;
+ }
+
return &(op->slots[slotcode]);
}
@@ -500,16 +522,16 @@
}
static void *alloc_slot_buffer(BMOperator *op, const char *slotname, int len){
- int slotcode = bmesh_name_to_slotcode(opdefines[op->type], slotname);
+ BMOpSlot *slot = BMO_GetSlot(op, slotname);
/*check if its actually a buffer*/
- if( !(op->slots[slotcode].slottype > BMOP_OPSLOT_VEC) )
+ if( !(slot->slottype > BMOP_OPSLOT_VEC) )
return NULL;
- op->slots[slotcode].len = len;
+ slot->len = len;
if(len)
- op->slots[slotcode].data.buf = BLI_memarena_alloc(op->arena, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode].type] * len);
- return op->slots[slotcode].data.buf;
+ slot->data.buf = BLI_memarena_alloc(op->arena, BMOP_OPSLOT_TYPEINFO[slot->slottype] * len);
+ return slot->data.buf;
}
@@ -1071,20 +1093,17 @@
if (!strcmp(name, def->slottypes[i].name)) return i;
}
- fprintf(stderr, "%s: ! could not find bmesh slot for name %s! (bmesh internal error)\n", __func__, name);
- return 0;
+ return -1;
}
static int bmesh_name_to_slotcode_check(BMOpDefine *def, const char *name)
{
- int i;
-
- for (i=0; def->slottypes[i].type; i++) {
- if (!strcmp(name, def->slottypes[i].name)) return i;
+ int i = bmesh_name_to_slotcode(def, name);
+ if (i < 0) {
+ fprintf(stderr, "%s: ! could not find bmesh slot for name %s! (bmesh internal error)\n", __func__, name);
}
- fprintf(stderr, "%s: ! could not find bmesh slot for name %s! (bmesh internal error)\n", __func__, name);
- return -1;
+ return i;
}
static int bmesh_opname_to_opcode(const char *opname) {
Modified: branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c 2011-10-12 13:53:03 UTC (rev 40957)
+++ branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c 2011-10-12 14:16:05 UTC (rev 40958)
@@ -452,7 +452,7 @@
BMVert **verts=NULL;
BLI_array_declare(verts);
float dist, dist3;
- int i, j, len, keepvert;
+ int i, j, len, keepvert = 0;
dist = BMO_Get_Float(op, "dist");
dist3 = dist * 3.0f;
@@ -463,13 +463,19 @@
verts[i++] = v;
}
- keepvert = BMO_IterNew(&oiter, bm, op, "keepverts", BM_VERT) != NULL;
+ /* Test whether keepverts arg exists and is non-empty */
+ if (BMO_HasSlot(op, "keepverts")) {
+ keepvert = BMO_IterNew(&oiter, bm, op, "keepverts", BM_VERT) != NULL;
+ }
/*sort by vertex coordinates added together*/
qsort(verts, BLI_array_count(verts), sizeof(void*), vergaverco);
-
- BMO_Flag_Buffer(bm, op, "keepverts", VERT_KEEP, BM_VERT);
+ /* Flag keepverts */
+ if (keepvert) {
+ BMO_Flag_Buffer(bm, op, "keepverts", VERT_KEEP, BM_VERT);
+ }
+
len = BLI_array_count(verts);
for (i=0; i<len; i++) {
v = verts[i];
More information about the Bf-blender-cvs
mailing list