[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18882] branches/bmesh/blender/source/ blender: Added a new slot type, that maps geometric elements to
Joseph Eagar
joeedh at gmail.com
Mon Feb 9 07:37:00 CET 2009
Revision: 18882
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18882
Author: joeedh
Date: 2009-02-09 07:36:59 +0100 (Mon, 09 Feb 2009)
Log Message:
-----------
Added a new slot type, that maps geometric elements to
client-defined data. Made edge subdivide use it.
Also removed the float and int slot buffer types, as per
discussion with Briggs, until such a time as we see
a use for them.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.h
branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c
branches/bmesh/blender/source/blender/editors/mesh/editmesh_loop.c
Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h 2009-02-09 04:47:34 UTC (rev 18881)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h 2009-02-09 06:36:59 UTC (rev 18882)
@@ -2,6 +2,7 @@
#define BM_OPERATORS_H
#include "BLI_memarena.h"
+#include "BLI_ghash.h"
#define BMOP_OPSLOT_INT 0
#define BMOP_OPSLOT_FLT 1
@@ -12,14 +13,15 @@
dynamically allocated arrays. we
leave a space in the identifiers
for future growth.*/
-#define BMOP_OPSLOT_INT_BUF 7
-#define BMOP_OPSLOT_FLT_BUF 8
-#define BMOP_OPSLOT_PNT_BUF 9
-#define BMOP_OPSLOT_TYPES 10
+#define BMOP_OPSLOT_PNT_BUF 7
+#define BMOP_OPSLOT_MAPPING 8
+#define BMOP_OPSLOT_TYPES 9
+
typedef struct BMOpSlot{
int slottype;
int len;
+ int flag;
int index; /*index within slot array*/
union {
int i;
@@ -27,9 +29,14 @@
void *p;
float vec[3]; /*vector*/
void *buf; /*buffer*/
+ GHash *ghash;
} data;
}BMOpSlot;
+/*BMOpSlot->flag*/
+/*is a dynamically-allocated array. set at runtime.*/
+#define BMOS_DYNAMIC_ARRAY 1
+
/*operators represent logical, executable mesh modules.*/
#define BMOP_MAX_SLOTS 16 /*way more than probably needed*/
@@ -54,6 +61,10 @@
//doesn't do anything at the moment.
/*API for operators*/
+
+/*data types that use pointers (arrays, etc) should never
+ have it set directly. and never use BMO_Set_Pnt to
+ pass in a list of edges or any arrays, really.*/
void BMO_Init_Op(struct BMOperator *op, int opcode);
void BMO_Exec_Op(struct BMesh *bm, struct BMOperator *op);
void BMO_Finish_Op(struct BMesh *bm, struct BMOperator *op);
@@ -61,8 +72,6 @@
void BMO_CopySlot(struct BMOperator *source_op, struct BMOperator *dest_op, int src, int dst);
void BMO_Set_Float(struct BMOperator *op, int slotcode, float f);
void BMO_Set_Int(struct BMOperator *op, int slotcode, int i);
-void BMO_Set_PntBuf(struct BMOperator *op, int slotcode, void *p, int len);
-void BMO_Set_FltBuf(BMOperator *op, int slotcode, float *p, int len);
void BMO_Set_Pnt(struct BMOperator *op, int slotcode, void *p);
void BMO_Set_Vec(struct BMOperator *op, int slotcode, float *vec);
void BMO_SetFlag(struct BMesh *bm, void *element, int flag);
@@ -72,7 +81,19 @@
void BMO_Flag_To_Slot(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag, int type);
void BMO_Flag_Buffer(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag);
void BMO_HeaderFlag_To_Slot(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag, int type);
+int BMO_CountSlotBuf(struct BMesh *bm, struct BMOperator *op, int slotcode);
+void BMO_Insert_Mapping(BMesh *bm, BMOperator *op, int slotcode,
+ void *element, void *data, int len);
+void BMO_Insert_MapFloat(BMesh *bm, BMOperator *op, int slotcode,
+ void *element, float val);
+void *BMO_Get_MapData(BMesh *bm, BMOperator *op, int slotcode,
+ void *element);
+float BMO_Get_MapFloat(BMesh *bm, BMOperator *op, int slotcode,
+ void *element);
+void BMO_Mapping_To_Flag(struct BMesh *bm, struct BMOperator *op,
+ int slotcode, int flag);
+
/*if msg is null, then the default message for the errorcode is used*/
void BMOP_RaiseError(BMesh *bm, int errcode, char *msg);
/*returns error code or 0 if no error*/
@@ -159,12 +180,20 @@
BMOP_ESUBDIVIDE_RADIUS,
BMOP_ESUBDIVIDE_SELACTION,
- BMOP_ESUBDIVIDE_CUSTOMFILL_FACES,
- BMOP_ESUBDIVIDE_CUSTOMFILL_PATTERNS,
+ BMOP_ESUBDIVIDE_CUSTOMFILL_FACEMAP,
+ BMOP_ESUBDIVIDE_PERCENT_EDGEMAP,
- BMOP_ESUBDIVIDE_PERCENT_EDGES,
- BMOP_ESUBDIVIDE_PERCENT_VALUES,
+ /*inner verts/new faces of completely filled faces, e.g.
+ fully selected face.*/
+ BMOP_ESUBDIVIDE_INNER_MULTOUT,
+ /*new edges and vertices from splitting original edges,
+ doesn't include edges creating by connecting verts.*/
+ BMOP_ESUBDIVIDE_SPLIT_MULTOUT,
+
+ /*edges created by connecting verts, except for those created
+ by fully-filled faces (e.g. fully selected faces).*/
+ BMOP_ESUBDIVIDE_CONNECT_MULTOUT,
BMOP_ESUBDIVIDE_TOTSLOT,
};
/*
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2009-02-09 04:47:34 UTC (rev 18881)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2009-02-09 06:36:59 UTC (rev 18882)
@@ -39,10 +39,12 @@
BMOP_OPSLOT_INT,
BMOP_OPSLOT_FLT,
BMOP_OPSLOT_INT,
+ BMOP_OPSLOT_MAPPING,
+ BMOP_OPSLOT_MAPPING,
BMOP_OPSLOT_PNT_BUF,
BMOP_OPSLOT_PNT_BUF,
BMOP_OPSLOT_PNT_BUF,
- BMOP_OPSLOT_FLT_BUF},
+ },
esubdivide_exec,
BMOP_ESUBDIVIDE_TOTSLOT,
0
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c 2009-02-09 04:47:34 UTC (rev 18881)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c 2009-02-09 06:36:59 UTC (rev 18882)
@@ -17,18 +17,24 @@
typedef void (*opexec)(struct BMesh *bm, struct BMOperator *op);
+/*mappings map elements to data, which
+ follows the mapping struct in memory.*/
+typedef struct element_mapping {
+ BMHeader *element;
+ int len;
+} element_mapping;
+
+
/*operator slot type information - size of one element of the type given.*/
-const int BMOP_OPSLOT_TYPEINFO[BMOP_OPSLOT_TYPES] = {
+const int BMOP_OPSLOT_TYPEINFO[] = {
sizeof(int),
sizeof(float),
sizeof(void*),
0, /* unused */
0, /* unused */
0, /* unused */
- sizeof(float)*3,
- sizeof(int), /* int buffer */
- sizeof(float), /* float buffer */
- sizeof(void*) /* pointer buffer */
+ sizeof(void*), /* pointer buffer */
+ sizeof(element_mapping)
};
/*
@@ -132,6 +138,17 @@
void BMO_Finish_Op(BMesh *bm, BMOperator *op)
{
+ BMOpSlot *slot;
+ int i;
+
+ for (i=0; i<opdefines[op->type]->totslot; i++) {
+ slot = &op->slots[i];
+ if (slot->slottype == BMOP_OPSLOT_MAPPING) {
+ if (slot->data.ghash)
+ BLI_ghash_free(slot->data.ghash, NULL, NULL);
+ }
+ }
+
BLI_memarena_free(op->arena);
}
@@ -203,30 +220,13 @@
}
-void BMO_Set_PntBuf(BMOperator *op, int slotcode, void *p, int len)
-{
- if( !(op->slots[slotcode].slottype == BMOP_OPSLOT_PNT_BUF) )
- return;
-
- op->slots[slotcode].data.p = p;
- op->slots[slotcode].len = len;
-}
-
-void BMO_Set_FltBuf(BMOperator *op, int slotcode, float *p, int len)
-{
- if( !(op->slots[slotcode].slottype == BMOP_OPSLOT_FLT_BUF) )
- return;
-
- op->slots[slotcode].data.p = p;
- op->slots[slotcode].len = len;
-}
-
void BMO_Set_Pnt(BMOperator *op, int slotcode, void *p)
{
if( !(op->slots[slotcode].slottype == BMOP_OPSLOT_PNT) )
return;
op->slots[slotcode].data.p = p;
}
+
void BMO_Set_Vec(BMOperator *op, int slotcode, float *vec)
{
if( !(op->slots[slotcode].slottype == BMOP_OPSLOT_VEC) )
@@ -312,6 +312,119 @@
return count;
}
+int BMO_CountSlotBuf(struct BMesh *bm, struct BMOperator *op, int slotcode)
+{
+ BMOpSlot *slot = &op->slots[slotcode];
+
+ /*check if its actually a buffer*/
+ if( !(slot->slottype > BMOP_OPSLOT_VEC) )
+ return 0;
+
+ return slot->len;
+}
+
+#if 0
+void *BMO_Grow_Array(BMesh *bm, BMOperator *op, int slotcode, int totadd) {
+ BMOpSlot *slot = &op->slots[slotcode];
+ void *tmp;
+
+ /*check if its actually a buffer*/
+ if( !(slot->slottype > BMOP_OPSLOT_VEC) )
+ return NULL;
+
+ if (slot->flag & BMOS_DYNAMIC_ARRAY) {
+ if (slot->len >= slot->size) {
+ slot->size = (slot->size+1+totadd)*2;
+
+ tmp = slot->data.buf;
+ slot->data.buf = MEM_callocN(BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * slot->size, "opslot dynamic array");
+ memcpy(slot->data.buf, tmp, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * slot->size);
+ MEM_freeN(tmp);
+ }
+
+ slot->len += totadd;
+ } else {
+ slot->flag |= BMOS_DYNAMIC_ARRAY;
+ slot->len += totadd;
+ slot->size = slot->len+2;
+ tmp = slot->data.buf;
+ slot->data.buf = MEM_callocN(BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * slot->len, "opslot dynamic array");
+ memcpy(slot->data.buf, tmp, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * slot->len);
+ }
+
+ return slot->data.buf;
+}
+#endif
+
+void BMO_Insert_Mapping(BMesh *bm, BMOperator *op, int slotcode,
+ void *element, void *data, int len) {
+ element_mapping *mapping;
+ BMOpSlot *slot = &op->slots[slotcode];
+
+ /*sanity check*/
+ if (slot->slottype != BMOP_OPSLOT_MAPPING) return;
+
+ mapping = BLI_memarena_alloc(op->arena, sizeof(*mapping) + len);
+
+ mapping->element = element;
+ mapping->len = len;
+ memcpy(mapping+1, data, len);
+
+ if (!slot->data.ghash) {
+ slot->data.ghash = BLI_ghash_new(BLI_ghashutil_ptrhash,
+ BLI_ghashutil_ptrcmp);
+ }
+
+ BLI_ghash_insert(slot->data.ghash, element, mapping);
+}
+
+void BMO_Mapping_To_Flag(struct BMesh *bm, struct BMOperator *op,
+ int slotcode, int flag)
+{
+ GHashIterator it;
+ BMOpSlot *slot = &op->slots[slotcode];
+ BMHeader *ele;
+
+ /*sanity check*/
+ if (slot->slottype != BMOP_OPSLOT_MAPPING) return;
+ if (!slot->data.ghash) return;
+
+ BLI_ghashIterator_init(&it, slot->data.ghash);
+ for (;ele=BLI_ghashIterator_getKey(&it);BLI_ghashIterator_step(&it)) {
+ BMO_SetFlag(bm, ele, flag);
+ }
+}
+
+void BMO_Insert_MapFloat(BMesh *bm, BMOperator *op, int slotcode,
+ void *element, float val)
+{
+ BMO_Insert_Mapping(bm, op, slotcode, element, &val, sizeof(float));
+}
+
+void *BMO_Get_MapData(BMesh *bm, BMOperator *op, int slotcode,
+ void *element)
+{
+ element_mapping *mapping;
+ BMOpSlot *slot = &op->slots[slotcode];
+
+ /*sanity check*/
+ if (slot->slottype != BMOP_OPSLOT_MAPPING) return NULL;
+ if (!slot->data.ghash) return NULL;
+
+ mapping = BLI_ghash_lookup(slot->data.ghash, element);
+
+ return mapping + 1;
+}
+
+float BMO_Get_MapFloat(BMesh *bm, BMOperator *op, int slotcode,
+ void *element)
+{
+ float *val = BMO_Get_MapData(bm, op, slotcode, element);
+ if (val) return *val;
+
+ return 0.0f;
+}
+
static void *alloc_slot_buffer(BMOperator *op, int slotcode, int len){
/*check if its actually a buffer*/
Modified: branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c 2009-02-09 04:47:34 UTC (rev 18881)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list