added operator slot iterators
This commit is contained in:
@@ -107,7 +107,7 @@ typedef struct BMNode {
|
||||
void *data;
|
||||
} BMNode;
|
||||
|
||||
struct Scene;
|
||||
struct bmop_error;
|
||||
typedef struct BMesh {
|
||||
ListBase verts, edges, polys;
|
||||
struct BLI_mempool *vpool;
|
||||
@@ -126,6 +126,7 @@ typedef struct BMesh {
|
||||
struct BLI_mempool *flagpool; /*memory pool for dynamically allocated flag layers*/
|
||||
int stackdepth; /*current depth of operator stack*/
|
||||
int totflags, walkers; /*total number of tool flag layers*/
|
||||
ListBase errorstack; /*privately used by the operator error reporting system*/
|
||||
} BMesh;
|
||||
|
||||
typedef struct BMVert {
|
||||
|
||||
@@ -30,6 +30,30 @@ typedef struct BMOpSlot{
|
||||
} data;
|
||||
}BMOpSlot;
|
||||
|
||||
/*these macros are used for iterating over slot buffers.
|
||||
for example:
|
||||
int i;
|
||||
|
||||
for (ptr=BMOS_IterNewP(i, slot); ptr; ptr=BMOS_IterStepP(i, slot)) {
|
||||
}
|
||||
|
||||
int ival;
|
||||
for (ival=BMOS_IterNewI(i, slot); !BMOS_IterDoneI(i, slot); ival=BMOS_IterStepI(i, slot) {
|
||||
}
|
||||
*/
|
||||
/*remember, the ',' operator executes all expressions seperated by ','
|
||||
(left to right) but uses the value of the right-most one.*/
|
||||
#define BMOS_IterNewP(stateint, slot) (stateint = 0, slot->len>0 ? *(void**)slot->data.p : NULL)
|
||||
#define BMOS_IterStepP(stateint, slot) (stateint++,stateint>=slot->len ? NULL : ((void**)slot->data.buf)[stateint])
|
||||
|
||||
#define BMOS_IterNewF(stateint, slot) (stateint = 0, slot->len>0 ? *(float*)slot->data.p : NULL)
|
||||
#define BMOS_IterDoneF(stateint, slot) (stateint >= slot->len)
|
||||
#define BMOS_IterStepF(stateint, slot) (stateint++,stateint>=slot->len ? NULL : ((float*)slot->data.buf)[stateint])
|
||||
|
||||
#define BMOS_IterNewI(stateint, slot) (stateint = 0, slot->len>0 ? *(int*)slot->data.p : NULL)
|
||||
#define BMOS_IterDoneI(stateint, slot) (stateint >= slot->len)
|
||||
#define BMOS_IterStepI(stateint, slot) (stateint++,stateint>=slot->len ? NULL : ((int*)slot->data.buf)[stateint])
|
||||
|
||||
/*operators represent logical, executable mesh modules.*/
|
||||
#define BMOP_MAX_SLOTS 16 /*way more than probably needed*/
|
||||
|
||||
@@ -73,6 +97,26 @@ void BMO_Flag_To_Slot(struct BMesh *bm, struct BMOperator *op, int slotcode, int
|
||||
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);
|
||||
|
||||
/*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*/
|
||||
int BMOP_GetError(BMesh *bm, char **msg);
|
||||
/*returns 1 if there was an error*/
|
||||
int BMOP_CheckError(BMesh *bm);
|
||||
int BMOP_PopError(BMesh *bm, char **msg);
|
||||
|
||||
/*------ error code defines -------*/
|
||||
|
||||
/*error messages*/
|
||||
#define BMERR_SELF_INTERSECTING 1
|
||||
|
||||
static char *bmop_error_messages[] = {
|
||||
0,
|
||||
"Self intersection error",
|
||||
};
|
||||
|
||||
#define BMERR_TOTAL (sizeof(error_messages) / sizeof(void*) - 1)
|
||||
|
||||
/*------------begin operator defines (see bmesh_opdefines.c too)------------*/
|
||||
/*split op*/
|
||||
#define BMOP_SPLIT 0
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "BLI_memarena.h"
|
||||
#include "BLI_mempool.h"
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
#include "BKE_utildefines.h"
|
||||
|
||||
@@ -31,6 +32,46 @@ const int BMOP_OPSLOT_TYPEINFO[BMOP_OPSLOT_TYPES] = {
|
||||
sizeof(void*) /* pointer buffer */
|
||||
};
|
||||
|
||||
/*error system*/
|
||||
typedef struct bmop_error {
|
||||
struct bmop_error *next, *prev;
|
||||
int errorcode;
|
||||
char *msg;
|
||||
} bmop_error;
|
||||
|
||||
void BMOP_RaiseError(BMesh *bm, int errcode, char *msg)
|
||||
{
|
||||
bmop_error *err = MEM_callocN(sizeof(bmop_error), "bmop_error");
|
||||
err->errorcode = errcode;
|
||||
err->msg = msg;
|
||||
BLI_addhead(&bm->errorstack, err);
|
||||
}
|
||||
|
||||
/*returns error code or 0 if no error*/
|
||||
int BMOP_GetError(BMesh *bm, char **msg)
|
||||
{
|
||||
bmop_error *err = bm->errorstack.first;
|
||||
if (!err) return 0;
|
||||
|
||||
if (msg) *msg = err->msg;
|
||||
|
||||
return err->errorcode;
|
||||
}
|
||||
|
||||
int BMOP_CheckError(BMesh *bm)
|
||||
{
|
||||
return bm->errorstack.first != NULL;
|
||||
}
|
||||
|
||||
int BMOP_PopError(BMesh *bm, char **msg)
|
||||
{
|
||||
int errorcode = BMOP_GetError(bm, msg);
|
||||
if (errorcode)
|
||||
BLI_remlink(&bm->errorstack, &bm->errorstack.first);
|
||||
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/*
|
||||
* BMESH OPSTACK PUSH
|
||||
*
|
||||
|
||||
@@ -43,8 +43,7 @@ void dissolveverts_exec(BMesh *bmesh, BMOperator *op)
|
||||
}
|
||||
*/
|
||||
|
||||
for (i=0; i<vinput->len; i++) {
|
||||
vert = ((BMVert**)vinput->data.p)[i];
|
||||
for (vert=BMOS_IterNewP(i, vinput); vert; vert = BMOS_IterStepP(i, vinput)) {
|
||||
BM_Dissolve_Disk(bmesh, vert);
|
||||
}
|
||||
}
|
||||
@@ -250,8 +250,7 @@ void esubdivide_exec(BMesh *bmesh, BMOperator *op)
|
||||
einput = BMO_GetSlot(op, BMOP_ESUBDIVIDE_EDGES);
|
||||
|
||||
/*first go through and split edges*/
|
||||
for (i=0; i<einput->len; i++) {
|
||||
edge = ((BMEdge**)einput->data.p)[i];
|
||||
for (edge=BMOS_IterNewP(i, einput); edge; edge = BMOS_IterStepP(i, einput)) {
|
||||
v1 = BM_Split_Edge(bmesh, edge->v1, edge, &nedge, 0.5, 1);
|
||||
BMO_SetFlag(bmesh, v1, SUBD_SPLIT);
|
||||
BMO_SetFlag(bmesh, nedge, SUBD_SPLIT);
|
||||
|
||||
@@ -19,10 +19,8 @@ void triangulate_exec(BMesh *bmesh, BMOperator *op)
|
||||
int i, count = 0;
|
||||
|
||||
finput = BMO_GetSlot(op, BMOP_ESUBDIVIDE_EDGES);
|
||||
|
||||
for (i=0; i<finput->len; i++) {
|
||||
face = ((BMFace**)finput->data.p)[i];
|
||||
|
||||
|
||||
for (face=BMOS_IterNewP(i, finput); face; face=BMOS_IterStepP(i, finput)) {
|
||||
/*HACK! need to discuss with Briggs why the function takes an
|
||||
externally-allocated array of vert coordinates in the first place.*/
|
||||
if (face->len > 400) projverts = MEM_callocN(sizeof(float)*3*face->len, "projverts");
|
||||
|
||||
Reference in New Issue
Block a user