code cleanup: use *(*var)[2] for pairs in bmesh code rather then a 1d array stepping by 2.
This commit is contained in:
@@ -45,18 +45,18 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op)
|
|||||||
{
|
{
|
||||||
BMIter iter, liter;
|
BMIter iter, liter;
|
||||||
BMFace *f, *nf;
|
BMFace *f, *nf;
|
||||||
BMLoop **loops = NULL, *lastl = NULL;
|
BMLoop *(*loops_split)[2] = NULL;
|
||||||
BLI_array_declare(loops);
|
BLI_array_declare(loops_split);
|
||||||
BMLoop *l, *nl;
|
BMLoop *l, *nl, *lastl = NULL;
|
||||||
BMVert **verts = NULL;
|
BMVert *(*verts_pair)[2] = NULL;
|
||||||
BLI_array_declare(verts);
|
BLI_array_declare(verts_pair);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
BMO_slot_buffer_flag_enable(bm, op, "verts", BM_VERT, VERT_INPUT);
|
BMO_slot_buffer_flag_enable(bm, op, "verts", BM_VERT, VERT_INPUT);
|
||||||
|
|
||||||
for (f = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); f; f = BM_iter_step(&iter)) {
|
for (f = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); f; f = BM_iter_step(&iter)) {
|
||||||
BLI_array_empty(loops);
|
BLI_array_empty(loops_split);
|
||||||
BLI_array_empty(verts);
|
BLI_array_empty(verts_pair);
|
||||||
|
|
||||||
if (BMO_elem_flag_test(bm, f, FACE_NEW)) {
|
if (BMO_elem_flag_test(bm, f, FACE_NEW)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -72,50 +72,44 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lastl != l->prev && lastl != l->next) {
|
if (lastl != l->prev && lastl != l->next) {
|
||||||
BLI_array_grow_one(loops);
|
BLI_array_grow_one(loops_split);
|
||||||
loops[BLI_array_count(loops) - 1] = lastl;
|
loops_split[BLI_array_count(loops_split) - 1][0] = lastl;
|
||||||
|
loops_split[BLI_array_count(loops_split) - 1][1] = l;
|
||||||
BLI_array_grow_one(loops);
|
|
||||||
loops[BLI_array_count(loops) - 1] = l;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
lastl = l;
|
lastl = l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BLI_array_count(loops) == 0) {
|
if (BLI_array_count(loops_split) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BLI_array_count(loops) > 2) {
|
if (BLI_array_count(loops_split) > 1) {
|
||||||
BLI_array_grow_one(loops);
|
BLI_array_grow_one(loops_split);
|
||||||
loops[BLI_array_count(loops) - 1] = loops[BLI_array_count(loops) - 2];
|
loops_split[BLI_array_count(loops_split) - 1][0] = loops_split[BLI_array_count(loops_split) - 2][1];
|
||||||
|
loops_split[BLI_array_count(loops_split) - 1][1] = loops_split[0][0];
|
||||||
BLI_array_grow_one(loops);
|
|
||||||
loops[BLI_array_count(loops) - 1] = loops[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BM_face_legal_splits(bm, f, (BMLoop *(*)[2])loops, BLI_array_count(loops) / 2);
|
BM_face_legal_splits(bm, f, loops_split, BLI_array_count(loops_split));
|
||||||
|
|
||||||
for (i = 0; i < BLI_array_count(loops) / 2; i++) {
|
for (i = 0; i < BLI_array_count(loops_split); i++) {
|
||||||
if (loops[i * 2] == NULL) {
|
if (loops_split[i][0] == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BLI_array_grow_one(verts);
|
BLI_array_grow_one(verts_pair);
|
||||||
verts[BLI_array_count(verts) - 1] = loops[i * 2]->v;
|
verts_pair[BLI_array_count(verts_pair) - 1][0] = loops_split[i][0]->v;
|
||||||
|
verts_pair[BLI_array_count(verts_pair) - 1][1] = loops_split[i][1]->v;
|
||||||
BLI_array_grow_one(verts);
|
|
||||||
verts[BLI_array_count(verts) - 1] = loops[i * 2 + 1]->v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < BLI_array_count(verts) / 2; i++) {
|
for (i = 0; i < BLI_array_count(verts_pair); i++) {
|
||||||
nf = BM_face_split(bm, f, verts[i * 2], verts[i * 2 + 1], &nl, NULL, FALSE);
|
nf = BM_face_split(bm, f, verts_pair[i][0], verts_pair[i][1], &nl, NULL, FALSE);
|
||||||
f = nf;
|
f = nf;
|
||||||
|
|
||||||
if (!nl || !nf) {
|
if (!nl || !nf) {
|
||||||
BMO_error_raise(bm, op, BMERR_CONNECTVERT_FAILED, NULL);
|
BMO_error_raise(bm, op, BMERR_CONNECTVERT_FAILED, NULL);
|
||||||
BLI_array_free(loops);
|
BLI_array_free(loops_split);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BMO_elem_flag_enable(bm, nf, FACE_NEW);
|
BMO_elem_flag_enable(bm, nf, FACE_NEW);
|
||||||
@@ -125,8 +119,8 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op)
|
|||||||
|
|
||||||
BMO_slot_buffer_from_enabled_flag(bm, op, "edgeout", BM_EDGE, EDGE_OUT);
|
BMO_slot_buffer_from_enabled_flag(bm, op, "edgeout", BM_EDGE, EDGE_OUT);
|
||||||
|
|
||||||
BLI_array_free(loops);
|
BLI_array_free(loops_split);
|
||||||
BLI_array_free(verts);
|
BLI_array_free(verts_pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BMVert *get_outer_vert(BMesh *bm, BMEdge *e)
|
static BMVert *get_outer_vert(BMesh *bm, BMEdge *e)
|
||||||
|
@@ -308,7 +308,7 @@ static void quad_1edge_split(BMesh *bm, BMFace *UNUSED(face),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SubDPattern quad_1edge = {
|
static const SubDPattern quad_1edge = {
|
||||||
{1, 0, 0, 0},
|
{1, 0, 0, 0},
|
||||||
quad_1edge_split,
|
quad_1edge_split,
|
||||||
4,
|
4,
|
||||||
@@ -337,7 +337,7 @@ static void quad_2edge_split_path(BMesh *bm, BMFace *UNUSED(face), BMVert **vert
|
|||||||
connect_smallest_face(bm, verts[numcuts * 2 + 3], verts[numcuts * 2 + 1], &nf);
|
connect_smallest_face(bm, verts[numcuts * 2 + 3], verts[numcuts * 2 + 1], &nf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SubDPattern quad_2edge_path = {
|
static const SubDPattern quad_2edge_path = {
|
||||||
{1, 1, 0, 0},
|
{1, 1, 0, 0},
|
||||||
quad_2edge_split_path,
|
quad_2edge_split_path,
|
||||||
4,
|
4,
|
||||||
@@ -379,7 +379,7 @@ static void quad_2edge_split_innervert(BMesh *bm, BMFace *UNUSED(face), BMVert *
|
|||||||
connect_smallest_face(bm, lastv, verts[numcuts * 2 + 2], &nf);
|
connect_smallest_face(bm, lastv, verts[numcuts * 2 + 2], &nf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SubDPattern quad_2edge_innervert = {
|
static const SubDPattern quad_2edge_innervert = {
|
||||||
{1, 1, 0, 0},
|
{1, 1, 0, 0},
|
||||||
quad_2edge_split_innervert,
|
quad_2edge_split_innervert,
|
||||||
4,
|
4,
|
||||||
@@ -410,7 +410,7 @@ static void quad_2edge_split_fan(BMesh *bm, BMFace *UNUSED(face), BMVert **verts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SubDPattern quad_2edge_fan = {
|
static const SubDPattern quad_2edge_fan = {
|
||||||
{1, 1, 0, 0},
|
{1, 1, 0, 0},
|
||||||
quad_2edge_split_fan,
|
quad_2edge_split_fan,
|
||||||
4,
|
4,
|
||||||
@@ -449,7 +449,7 @@ static void quad_3edge_split(BMesh *bm, BMFace *UNUSED(face), BMVert **verts,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SubDPattern quad_3edge = {
|
static const SubDPattern quad_3edge = {
|
||||||
{1, 1, 1, 0},
|
{1, 1, 1, 0},
|
||||||
quad_3edge_split,
|
quad_3edge_split,
|
||||||
4,
|
4,
|
||||||
@@ -559,7 +559,7 @@ static void tri_1edge_split(BMesh *bm, BMFace *UNUSED(face), BMVert **verts,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SubDPattern tri_1edge = {
|
static const SubDPattern tri_1edge = {
|
||||||
{1, 0, 0},
|
{1, 0, 0},
|
||||||
tri_1edge_split,
|
tri_1edge_split,
|
||||||
3,
|
3,
|
||||||
@@ -660,51 +660,55 @@ cleanup:
|
|||||||
MEM_freeN(lines);
|
MEM_freeN(lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SubDPattern tri_3edge = {
|
static const SubDPattern tri_3edge = {
|
||||||
{1, 1, 1},
|
{1, 1, 1},
|
||||||
tri_3edge_subdivide,
|
tri_3edge_subdivide,
|
||||||
3,
|
3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static SubDPattern quad_4edge = {
|
static const SubDPattern quad_4edge = {
|
||||||
{1, 1, 1, 1},
|
{1, 1, 1, 1},
|
||||||
quad_4edge_subdivide,
|
quad_4edge_subdivide,
|
||||||
4,
|
4,
|
||||||
};
|
};
|
||||||
|
|
||||||
static SubDPattern *patterns[] = {
|
static const SubDPattern *patterns[] = {
|
||||||
NULL, //quad single edge pattern is inserted here
|
NULL, /* quad single edge pattern is inserted here */
|
||||||
NULL, //quad corner vert pattern is inserted here
|
NULL, /* quad corner vert pattern is inserted here */
|
||||||
NULL, //tri single edge pattern is inserted here
|
NULL, /* tri single edge pattern is inserted here */
|
||||||
NULL,
|
NULL,
|
||||||
&quad_3edge,
|
&quad_3edge,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PLEN (sizeof(patterns) / sizeof(void *))
|
#define PATTERNS_TOT (sizeof(patterns) / sizeof(void *))
|
||||||
|
|
||||||
typedef struct SubDFaceData {
|
typedef struct SubDFaceData {
|
||||||
BMVert *start; SubDPattern *pat;
|
BMVert *start;
|
||||||
int totedgesel; //only used if pat was NULL, e.g. no pattern was found
|
const SubDPattern *pat;
|
||||||
|
int totedgesel; /* only used if pat was NULL, e.g. no pattern was found */
|
||||||
BMFace *face;
|
BMFace *face;
|
||||||
} SubDFaceData;
|
} SubDFaceData;
|
||||||
|
|
||||||
void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
|
void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
|
||||||
{
|
{
|
||||||
BMOpSlot *einput;
|
BMOpSlot *einput;
|
||||||
SubDPattern *pat;
|
const SubDPattern *pat;
|
||||||
SubDParams params;
|
SubDParams params;
|
||||||
SubDFaceData *facedata = NULL;
|
SubDFaceData *facedata = NULL;
|
||||||
|
BLI_array_declare(facedata);
|
||||||
BMIter viter, fiter, liter;
|
BMIter viter, fiter, liter;
|
||||||
BMVert *v, **verts = NULL;
|
BMVert *v, **verts = NULL;
|
||||||
BMEdge *edge, **edges = NULL;
|
BMEdge *edge;
|
||||||
BMLoop *nl, *l, **splits = NULL, **loops = NULL;
|
BMEdge **edges = NULL;
|
||||||
BMFace *face;
|
|
||||||
BLI_array_declare(splits);
|
|
||||||
BLI_array_declare(loops);
|
|
||||||
BLI_array_declare(facedata);
|
|
||||||
BLI_array_declare(edges);
|
BLI_array_declare(edges);
|
||||||
|
BMLoop *(*loops_split)[2] = NULL;
|
||||||
|
BLI_array_declare(loops_split);
|
||||||
|
BMLoop **loops = NULL;
|
||||||
|
BLI_array_declare(loops);
|
||||||
|
BMLoop *nl, *l;
|
||||||
|
BMFace *face;
|
||||||
BLI_array_declare(verts);
|
BLI_array_declare(verts);
|
||||||
float smooth, fractal, along_normal;
|
float smooth, fractal, along_normal;
|
||||||
int use_sphere, cornertype, use_singleedge, use_gridfill;
|
int use_sphere, cornertype, use_singleedge, use_gridfill;
|
||||||
@@ -726,7 +730,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
|
|||||||
BLI_srandom(seed);
|
BLI_srandom(seed);
|
||||||
|
|
||||||
patterns[1] = NULL;
|
patterns[1] = NULL;
|
||||||
//straight cut is patterns[1] == NULL
|
/* straight cut is patterns[1] == NULL */
|
||||||
switch (cornertype) {
|
switch (cornertype) {
|
||||||
case SUBD_PATH:
|
case SUBD_PATH:
|
||||||
patterns[1] = &quad_2edge_path;
|
patterns[1] = &quad_2edge_path;
|
||||||
@@ -861,7 +865,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < PLEN; i++) {
|
for (i = 0; i < PATTERNS_TOT; i++) {
|
||||||
pat = patterns[i];
|
pat = patterns[i];
|
||||||
if (!pat) {
|
if (!pat) {
|
||||||
continue;
|
continue;
|
||||||
@@ -935,7 +939,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
|
|||||||
|
|
||||||
/* ok, no pattern. we still may be able to do something */
|
/* ok, no pattern. we still may be able to do something */
|
||||||
BLI_array_empty(loops);
|
BLI_array_empty(loops);
|
||||||
BLI_array_empty(splits);
|
BLI_array_empty(loops_split);
|
||||||
|
|
||||||
/* for case of two edges, connecting them shouldn't be too hard */
|
/* for case of two edges, connecting them shouldn't be too hard */
|
||||||
BLI_array_grow_items(loops, face->len);
|
BLI_array_grow_items(loops, face->len);
|
||||||
@@ -971,10 +975,10 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
|
|||||||
|
|
||||||
b += numcuts - 1;
|
b += numcuts - 1;
|
||||||
|
|
||||||
BLI_array_grow_items(splits, numcuts * 2);
|
BLI_array_grow_items(loops_split, numcuts);
|
||||||
for (j = 0; j < numcuts; j++) {
|
for (j = 0; j < numcuts; j++) {
|
||||||
splits[j * 2 + 0] = loops[a];
|
loops_split[j][0] = loops[a];
|
||||||
splits[j * 2 + 1] = loops[b];
|
loops_split[j][1] = loops[b];
|
||||||
|
|
||||||
b = (b - 1) % vlen;
|
b = (b - 1) % vlen;
|
||||||
a = (a + 1) % vlen;
|
a = (a + 1) % vlen;
|
||||||
@@ -985,12 +989,12 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
|
|||||||
* - concave corner of an ngon.
|
* - concave corner of an ngon.
|
||||||
* - 2 edges being used in 2+ ngons.
|
* - 2 edges being used in 2+ ngons.
|
||||||
*/
|
*/
|
||||||
// BM_face_legal_splits(bm, face, (BMLoop *(*)[2])splits, BLI_array_count(splits) / 2);
|
BM_face_legal_splits(bm, face, loops_split, BLI_array_count(loops_split));
|
||||||
|
|
||||||
for (j = 0; j < BLI_array_count(splits) / 2; j++) {
|
for (j = 0; j < BLI_array_count(loops_split); j++) {
|
||||||
if (splits[j * 2]) {
|
if (loops_split[j][0]) {
|
||||||
/* BMFace *nf = */ /* UNUSED */
|
/* BMFace *nf = */ /* UNUSED */
|
||||||
BM_face_split(bm, face, splits[j * 2]->v, splits[j * 2 + 1]->v, &nl, NULL, FALSE);
|
BM_face_split(bm, face, loops_split[j][0]->v, loops_split[j][1]->v, &nl, NULL, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1030,7 +1034,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op)
|
|||||||
if (facedata) BLI_array_free(facedata);
|
if (facedata) BLI_array_free(facedata);
|
||||||
if (edges) BLI_array_free(edges);
|
if (edges) BLI_array_free(edges);
|
||||||
if (verts) BLI_array_free(verts);
|
if (verts) BLI_array_free(verts);
|
||||||
BLI_array_free(splits);
|
BLI_array_free(loops_split);
|
||||||
BLI_array_free(loops);
|
BLI_array_free(loops);
|
||||||
|
|
||||||
BMO_slot_buffer_from_enabled_flag(bm, op, "outinner", BM_ALL, ELE_INNER);
|
BMO_slot_buffer_from_enabled_flag(bm, op, "outinner", BM_ALL, ELE_INNER);
|
||||||
|
Reference in New Issue
Block a user