diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/modifiers_bmesh.c | 20 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_construct.c | 10 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmesh_select.c | 826 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmesh_selecthistory.c | 8 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmesh_tools.c | 1756 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmeshutils.c | 238 | ||||
-rw-r--r-- | source/blender/editors/mesh/editbmesh_add.c | 5 | ||||
-rwxr-xr-x | source/blender/editors/mesh/knifetool.c | 473 |
8 files changed, 1707 insertions, 1629 deletions
diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index 8fe400dcbe4..48680d19892 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -101,8 +101,8 @@ #include "RE_shader_ext.h" #include "LOD_decimation.h" -/*converts a cddm to a BMEditMesh. if existing is non-NULL, the - new geometry will be put in there.*/ +/* converts a cddm to a BMEditMesh. if existing is non-NULL, the + * new geometry will be put in there.*/ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int do_tesselate) { int allocsize[4] = {512, 512, 2048, 512}; @@ -112,8 +112,8 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int MEdge *me, *medge; MPoly *mpoly, *mp; MLoop *mloop, *ml; - BMVert *v, **vtable, **verts=NULL; - BMEdge *e, **etable, **edges=NULL; + BMVert *v, **vtable, **verts = NULL; + BMEdge *e, **etable, **edges = NULL; BMFace *f; BMIter liter; BLI_array_declare(verts); @@ -140,7 +140,7 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int /*do verts*/ mv = mvert = dm->dupVertArray(dm); - for (i=0; i<totvert; i++, mv++) { + for (i = 0; i < totvert; i++, mv++) { v = BM_Make_Vert(bm, mv->co, NULL); normal_short_to_float_v3(v->no, mv->no); v->head.hflag = BM_Vert_Flag_From_MEFlag(mv->flag); @@ -152,7 +152,7 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int /*do edges*/ me = medge = dm->dupEdgeArray(dm); - for (i=0; i<totedge; i++, me++) { + for (i = 0; i < totedge; i++, me++) { e = BM_Make_Edge(bm, vtable[me->v1], vtable[me->v2], NULL, FALSE); e->head.hflag = BM_Edge_Flag_From_MEFlag(me->flag); @@ -165,7 +165,7 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int /*do faces*/ mpoly = mp = dm->getPolyArray(dm); mloop = dm->getLoopArray(dm); - for (i=0; i<dm->numPolyData; i++, mp++) { + for (i = 0; i < dm->numPolyData; i++, mp++) { BMLoop *l; BLI_array_empty(verts); @@ -192,12 +192,11 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f); k = mp->loopstart; - for (j=0; l; l=BMIter_Step(&liter), k++) { + for (j = 0; l; l = BMIter_Step(&liter), k++) { CustomData_to_bmesh_block(&dm->loopData, &bm->ldata, k, &l->head.data); } - CustomData_to_bmesh_block(&dm->polyData, &bm->pdata, - i, &f->head.data); + CustomData_to_bmesh_block(&dm->polyData, &bm->pdata, i, &f->head.data); } MEM_freeN(vtable); @@ -217,4 +216,3 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int return em; } - diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index ca3c5fc067a..9b522fc222e 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -296,7 +296,7 @@ BMFace *BM_Make_Ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, int len, /* ok, edges are in correct order, now ensure they are going * in the correct direction */ - v1found = reverse = 0; + v1found = reverse = FALSE; for (i = 0; i < len; i++) { if (BM_Vert_In_Edge(edges2[i], v1)) { /* see if v1 and v2 are in the same edge */ @@ -304,16 +304,16 @@ BMFace *BM_Make_Ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, int len, /* if v1 is shared by the *next* edge, then the winding * is incorrect */ if (BM_Vert_In_Edge(edges2[(i + 1) % len], v1)) { - reverse = 1; + reverse = TRUE; break; } } - v1found = 1; + v1found = TRUE; } - if (!v1found && BM_Vert_In_Edge(edges2[i], v2)) { - reverse = 1; + if ((v1found == FALSE) && BM_Vert_In_Edge(edges2[i], v2)) { + reverse = TRUE; break; } } diff --git a/source/blender/editors/mesh/bmesh_select.c b/source/blender/editors/mesh/bmesh_select.c index 1cfb066ab2c..c2f0d8c89ed 100644 --- a/source/blender/editors/mesh/bmesh_select.c +++ b/source/blender/editors/mesh/bmesh_select.c @@ -119,7 +119,7 @@ void EDBM_select_mirrored(Object *UNUSED(obedit), BMEditMesh *em, int extend) if (!BM_TestHFlag(v1, BM_TMP_TAG) || BM_TestHFlag(v1, BM_HIDDEN)) continue; - v2= EDBM_GetMirrorVert(em, v1); + v2 = EDBM_GetMirrorVert(em, v1); if (v2 && !BM_TestHFlag(v2, BM_HIDDEN)) { BM_Select(em->bm, v2, TRUE); } @@ -133,9 +133,9 @@ void EDBM_automerge(Scene *scene, Object *obedit, int update) BMEditMesh *em; if ((scene->toolsettings->automerge) && - (obedit && obedit->type==OB_MESH)) + (obedit && obedit->type == OB_MESH)) { - em = ((Mesh*)obedit->data)->edit_btmesh; + em = ((Mesh *)obedit->data)->edit_btmesh; if (!em) return; @@ -148,49 +148,49 @@ void EDBM_automerge(Scene *scene, Object *obedit, int update) /* ****************************** SELECTION ROUTINES **************** */ -unsigned int bm_solidoffs=0, bm_wireoffs=0, bm_vertoffs=0; /* set in drawobject.c ... for colorindices */ +unsigned int bm_solidoffs = 0, bm_wireoffs = 0, bm_vertoffs = 0; /* set in drawobject.c ... for colorindices */ /* facilities for border select and circle select */ -static char *selbuf= NULL; +static char *selbuf = NULL; /* opengl doesn't support concave... */ static void draw_triangulated(int mcords[][2], short tot) { - ListBase lb={NULL, NULL}; + ListBase lb = {NULL, NULL}; DispList *dl; float *fp; int a; /* make displist */ - dl= MEM_callocN(sizeof(DispList), "poly disp"); - dl->type= DL_POLY; - dl->parts= 1; - dl->nr= tot; - dl->verts= fp= MEM_callocN(tot*3*sizeof(float), "poly verts"); + dl = MEM_callocN(sizeof(DispList), "poly disp"); + dl->type = DL_POLY; + dl->parts = 1; + dl->nr = tot; + dl->verts = fp = MEM_callocN(tot * 3 * sizeof(float), "poly verts"); BLI_addtail(&lb, dl); - for(a=0; a<tot; a++, fp+=3) { - fp[0]= (float)mcords[a][0]; - fp[1]= (float)mcords[a][1]; + for (a = 0; a < tot; a++, fp += 3) { + fp[0] = (float)mcords[a][0]; + fp[1] = (float)mcords[a][1]; } /* do the fill */ filldisplist(&lb, &lb, 0); /* do the draw */ - dl= lb.first; /* filldisplist adds in head of list */ - if (dl->type==DL_INDEX3) { + dl = lb.first; /* filldisplist adds in head of list */ + if (dl->type == DL_INDEX3) { int *index; - a= dl->parts; - fp= dl->verts; - index= dl->index; + a = dl->parts; + fp = dl->verts; + index = dl->index; glBegin(GL_TRIANGLES); - while(a--) { - glVertex3fv(fp+3*index[0]); - glVertex3fv(fp+3*index[1]); - glVertex3fv(fp+3*index[2]); - index+= 3; + while (a--) { + glVertex3fv(fp + 3 * index[0]); + glVertex3fv(fp + 3 * index[1]); + glVertex3fv(fp + 3 * index[2]); + index += 3; } glEnd(); } @@ -207,21 +207,23 @@ int EDBM_init_backbuf_border(ViewContext *vc, short xmin, short ymin, short xmax unsigned int *dr; int a; - if (vc->obedit==NULL || vc->v3d->drawtype<OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT)==0) return 0; + if (vc->obedit == NULL || vc->v3d->drawtype < OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT) == 0) { + return 0; + } - buf= view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); - if (buf==NULL) return 0; - if (bm_vertoffs==0) return 0; + buf = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); + if (buf == NULL) return 0; + if (bm_vertoffs == 0) return 0; dr = buf->rect; /* build selection lookup */ - selbuf= MEM_callocN(bm_vertoffs+1, "selbuf"); + selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); - a= (xmax-xmin+1)*(ymax-ymin+1); - while(a--) { - if (*dr>0 && *dr<=bm_vertoffs) - selbuf[*dr]= 1; + a = (xmax - xmin + 1) * (ymax-ymin + 1); + while (a--) { + if (*dr > 0 && *dr <= bm_vertoffs) + selbuf[*dr] = 1; dr++; } IMB_freeImBuf(buf); @@ -230,8 +232,8 @@ int EDBM_init_backbuf_border(ViewContext *vc, short xmin, short ymin, short xmax int EDBM_check_backbuf(unsigned int index) { - if (selbuf==NULL) return 1; - if (index>0 && index<=bm_vertoffs) + if (selbuf == NULL) return 1; + if (index > 0 && index <= bm_vertoffs) return selbuf[index]; return 0; } @@ -239,7 +241,7 @@ int EDBM_check_backbuf(unsigned int index) void EDBM_free_backbuf(void) { if (selbuf) MEM_freeN(selbuf); - selbuf= NULL; + selbuf = NULL; } /* mcords is a polygon mask @@ -255,16 +257,18 @@ int EDBM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, s int a; /* method in use for face selecting too */ - if (vc->obedit==NULL) { + if (vc->obedit == NULL) { if (paint_facesel_test(vc->obact)); else if (paint_vertsel_test(vc->obact)); else return 0; } - else if (vc->v3d->drawtype<OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT)==0) return 0; + else if (vc->v3d->drawtype < OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT) == 0) { + return 0; + } - buf= view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); - if (buf==NULL) return 0; - if (bm_vertoffs==0) return 0; + buf = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); + if (buf == NULL) return 0; + if (bm_vertoffs == 0) return 0; dr = buf->rect; @@ -275,31 +279,35 @@ int EDBM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, s /* yah, opengl doesn't do concave... tsk! */ ED_region_pixelspace(vc->ar); - draw_triangulated(mcords, tot); + draw_triangulated(mcords, tot); - glBegin(GL_LINE_LOOP); /* for zero sized masks, lines */ - for(a=0; a<tot; a++) glVertex2iv(mcords[a]); + glBegin(GL_LINE_LOOP); /* for zero sized masks, lines */ + for (a = 0; a < tot; a++) { + glVertex2iv(mcords[a]); + } glEnd(); glFinish(); /* to be sure readpixels sees mask */ /* grab mask */ - bufmask= view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); + bufmask = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); drm = bufmask->rect; - if (bufmask==NULL) return 0; /* only when mem alloc fails, go crash somewhere else! */ + if (bufmask == NULL) { + return 0; /* only when mem alloc fails, go crash somewhere else! */ + } /* build selection lookup */ - selbuf= MEM_callocN(bm_vertoffs+1, "selbuf"); + selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); - a= (xmax-xmin+1)*(ymax-ymin+1); - while(a--) { - if (*dr>0 && *dr<=bm_vertoffs && *drm==0) selbuf[*dr]= 1; + a = (xmax - xmin + 1) * (ymax - ymin + 1); + while (a--) { + if (*dr > 0 && *dr <= bm_vertoffs && *drm == 0) selbuf[*dr] = 1; dr++; drm++; } IMB_freeImBuf(buf); IMB_freeImBuf(bufmask); + return 1; - } /* circle shaped sample area */ @@ -311,28 +319,28 @@ int EDBM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) int radsq; /* method in use for face selecting too */ - if (vc->obedit==NULL) { + if (vc->obedit == NULL) { if (paint_facesel_test(vc->obact)); else if (paint_vertsel_test(vc->obact)); else return 0; } - else if (vc->v3d->drawtype<OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT)==0) return 0; + else if (vc->v3d->drawtype < OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT) == 0) return 0; - xmin= xs-rads; xmax= xs+rads; - ymin= ys-rads; ymax= ys+rads; - buf= view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); - if (bm_vertoffs==0) return 0; - if (buf==NULL) return 0; + xmin = xs - rads; xmax = xs + rads; + ymin = ys - rads; ymax = ys + rads; + buf = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); + if (bm_vertoffs == 0) return 0; + if (buf == NULL) return 0; dr = buf->rect; /* build selection lookup */ - selbuf= MEM_callocN(bm_vertoffs+1, "selbuf"); - radsq= rads*rads; - for(yc= -rads; yc<=rads; yc++) { - for(xc= -rads; xc<=rads; xc++, dr++) { - if (xc*xc + yc*yc < radsq) { - if (*dr>0 && *dr<=bm_vertoffs) selbuf[*dr]= 1; + selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); + radsq = rads * rads; + for (yc = -rads; yc <= rads; yc++) { + for (xc = -rads; xc <= rads; xc++, dr++) { + if (xc * xc + yc * yc < radsq) { + if (*dr > 0 && *dr <= bm_vertoffs) selbuf[*dr] = 1; } } } @@ -346,16 +354,16 @@ static void findnearestvert__doClosest(void *userData, BMVert *eve, int x, int y { struct { short mval[2], pass, select, strict; int dist, lastIndex, closestIndex; BMVert *closest; } *data = userData; - if (data->pass==0) { - if (index<=data->lastIndex) + if (data->pass == 0) { + if (index <= data->lastIndex) return; } else { - if (index>data->lastIndex) + if (index > data->lastIndex) return; } - if (data->dist>3) { + if (data->dist > 3) { int temp = abs(data->mval[0] - x) + abs(data->mval[1]- y); if (BM_TestHFlag(eve, BM_SELECT) == data->select) { if (data->strict == 1) @@ -364,7 +372,7 @@ static void findnearestvert__doClosest(void *userData, BMVert *eve, int x, int y temp += 5; } - if (temp<data->dist) { + if (temp < data->dist) { data->dist = temp; data->closest = eve; data->closestIndex = index; @@ -377,11 +385,11 @@ static void findnearestvert__doClosest(void *userData, BMVert *eve, int x, int y static unsigned int findnearestvert__backbufIndextest(void *handle, unsigned int index) { - BMEditMesh *em= (BMEditMesh *)handle; - BMVert *eve = BM_Vert_AtIndex(em->bm, index-1); + BMEditMesh *em = (BMEditMesh *)handle; + BMVert *eve = BM_Vert_AtIndex(em->bm, index - 1); if (eve && BM_TestHFlag(eve, BM_SELECT)) return 0; - return 1; + return 1; } /** * findnearestvert @@ -394,15 +402,21 @@ static unsigned int findnearestvert__backbufIndextest(void *handle, unsigned int */ BMVert *EDBM_findnearestvert(ViewContext *vc, int *dist, short sel, short strict) { - if (vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { + if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { int distance; unsigned int index; BMVert *eve; - if (strict) index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_wireoffs, 0xFFFFFF, &distance, strict, vc->em, findnearestvert__backbufIndextest); - else index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_wireoffs, 0xFFFFFF, &distance, 0, NULL, NULL); + if (strict) { + index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_wireoffs, 0xFFFFFF, &distance, + strict, vc->em, findnearestvert__backbufIndextest); + } + else { + index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_wireoffs, 0xFFFFFF, &distance, + 0, NULL, NULL); + } - eve = BM_Vert_AtIndex(vc->em->bm, index-1); + eve = BM_Vert_AtIndex(vc->em->bm, index - 1); if (eve && distance < *dist) { *dist = distance; @@ -415,8 +429,8 @@ BMVert *EDBM_findnearestvert(ViewContext *vc, int *dist, short sel, short strict } else { struct { short mval[2], pass, select, strict; int dist, lastIndex, closestIndex; BMVert *closest; } data; - static int lastSelectedIndex=0; - static BMVert *lastSelected=NULL; + static int lastSelectedIndex = 0; + static BMVert *lastSelected = NULL; if (lastSelected && BM_Vert_AtIndex(vc->em->bm, lastSelectedIndex) != lastSelected) { lastSelectedIndex = 0; @@ -438,7 +452,7 @@ BMVert *EDBM_findnearestvert(ViewContext *vc, int *dist, short sel, short strict mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, V3D_CLIP_TEST_RV3D_CLIPPING); - if (data.dist>3) { + if (data.dist > 3) { data.pass = 1; mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, V3D_CLIP_TEST_RV3D_CLIPPING); } @@ -451,18 +465,18 @@ BMVert *EDBM_findnearestvert(ViewContext *vc, int *dist, short sel, short strict } } -/* returns labda for closest distance v1 to line-piece v2-v3 */ +/* returns labda for closest distance v1 to line-piece v2 - v3 */ float labda_PdistVL2Dfl(const float v1[3], const float v2[3], const float v3[3]) { float rc[2], len; - rc[0]= v3[0]-v2[0]; - rc[1]= v3[1]-v2[1]; - len= rc[0]*rc[0]+ rc[1]*rc[1]; - if (len==0.0f) + rc[0] = v3[0] - v2[0]; + rc[1] = v3[1] - v2[1]; + len = rc[0] * rc[0] + rc[1] * rc[1]; + if (len == 0.0f) return 0.0f; - return ( rc[0]*(v1[0]-v2[0]) + rc[1]*(v1[1]-v2[1]) )/len; + return (rc[0] * (v1[0] - v2[0]) + rc[1] * (v1[1] - v2[1]) ) / len; } /* note; uses v3d, so needs active 3d window */ @@ -477,20 +491,23 @@ static void findnearestedge__doClosest(void *userData, BMEdge *eed, int x0, int v2[0] = x1; v2[1] = y1; - distance= dist_to_line_segment_v2(data->mval, v1, v2); + distance = dist_to_line_segment_v2(data->mval, v1, v2); - if (BM_TestHFlag(eed, BM_SELECT)) distance+=5; + if (BM_TestHFlag(eed, BM_SELECT)) { + distance += 5; + } + if (distance < data->dist) { if (data->vc.rv3d->rflag & RV3D_CLIPPING) { - float labda= labda_PdistVL2Dfl(data->mval, v1, v2); + float labda = labda_PdistVL2Dfl(data->mval, v1, v2); float vec[3]; - vec[0]= eed->v1->co[0] + labda*(eed->v2->co[0] - eed->v1->co[0]); - vec[1]= eed->v1->co[1] + labda*(eed->v2->co[1] - eed->v1->co[1]); - vec[2]= eed->v1->co[2] + labda*(eed->v2->co[2] - eed->v1->co[2]); + vec[0] = eed->v1->co[0] + labda * (eed->v2->co[0] - eed->v1->co[0]); + vec[1] = eed->v1->co[1] + labda * (eed->v2->co[1] - eed->v1->co[1]); + vec[2] = eed->v1->co[2] + labda * (eed->v2->co[2] - eed->v1->co[2]); mul_m4_v3(data->vc.obedit->obmat, vec); - if (ED_view3d_test_clipping(data->vc.rv3d, vec, 1)==0) { + if (ED_view3d_test_clipping(data->vc.rv3d, vec, 1) == 0) { data->dist = distance; data->closest = eed; } @@ -504,7 +521,7 @@ static void findnearestedge__doClosest(void *userData, BMEdge *eed, int x0, int BMEdge *EDBM_findnearestedge(ViewContext *vc, int *dist) { - if (vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { + if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { int distance; unsigned int index; BMEdge *eed; @@ -512,9 +529,9 @@ BMEdge *EDBM_findnearestedge(ViewContext *vc, int *dist) view3d_validate_backbuf(vc); index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_solidoffs, bm_wireoffs, &distance,0, NULL, NULL); - eed = BM_Edge_AtIndex(vc->em->bm, index-1); + eed = BM_Edge_AtIndex(vc->em->bm, index - 1); - if (eed && distance<*dist) { + if (eed && distance < *dist) { *dist = distance; return eed; } @@ -525,7 +542,7 @@ BMEdge *EDBM_findnearestedge(ViewContext *vc, int *dist) else { struct { ViewContext vc; float mval[2]; int dist; BMEdge *closest; } data; - data.vc= *vc; + data.vc = *vc; data.mval[0] = vc->mval[0]; data.mval[1] = vc->mval[1]; data.dist = *dist; @@ -543,10 +560,10 @@ static void findnearestface__getDistance(void *userData, BMFace *efa, int x, int { struct { short mval[2]; int dist; BMFace *toFace; } *data = userData; - if (efa==data->toFace) { - int temp = abs(data->mval[0]-x) + abs(data->mval[1]-y); + if (efa == data->toFace) { + int temp = abs(data->mval[0] - x) + abs(data->mval[1] - y); - if (temp<data->dist) + if (temp < data->dist) data->dist = temp; } } @@ -554,19 +571,19 @@ static void findnearestface__doClosest(void *userData, BMFace *efa, int x, int y { struct { short mval[2], pass; int dist, lastIndex, closestIndex; BMFace *closest; } *data = userData; - if (data->pass==0) { - if (index<=data->lastIndex) + if (data->pass == 0) { + if (index <= data->lastIndex) return; } else { - if (index>data->lastIndex) + if (index > data->lastIndex) return; } - if (data->dist>3) { - int temp = abs(data->mval[0]-x) + abs(data->mval[1]-y); + if (data->dist > 3) { + int temp = abs(data->mval[0] - x) + abs(data->mval[1] - y); - if (temp<data->dist) { + if (temp < data->dist) { data->dist = temp; data->closest = efa; data->closestIndex = index; @@ -577,14 +594,14 @@ static void findnearestface__doClosest(void *userData, BMFace *efa, int x, int y BMFace *EDBM_findnearestface(ViewContext *vc, int *dist) { - if (vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { + if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { unsigned int index; BMFace *efa; view3d_validate_backbuf(vc); index = view3d_sample_backbuf(vc, vc->mval[0], vc->mval[1]); - efa = BM_Face_AtIndex(vc->em->bm, index-1); + efa = BM_Face_AtIndex(vc->em->bm, index - 1); if (efa) { struct { short mval[2]; int dist; BMFace *toFace; } data; @@ -596,8 +613,8 @@ BMFace *EDBM_findnearestface(ViewContext *vc, int *dist) mesh_foreachScreenFace(vc, findnearestface__getDistance, &data); - if (vc->em->selectmode == SCE_SELECT_FACE || data.dist<*dist) { /* only faces, no dist check */ - *dist= data.dist; + if (vc->em->selectmode == SCE_SELECT_FACE || data.dist < *dist) { /* only faces, no dist check */ + *dist = data.dist; return efa; } } @@ -606,8 +623,8 @@ BMFace *EDBM_findnearestface(ViewContext *vc, int *dist) } else { struct { short mval[2], pass; int dist, lastIndex, closestIndex; BMFace *closest; } data; - static int lastSelectedIndex=0; - static BMFace *lastSelected=NULL; + static int lastSelectedIndex = 0; + static BMFace *lastSelected = NULL; if (lastSelected && BM_Face_AtIndex(vc->em->bm, lastSelectedIndex) != lastSelected) { lastSelectedIndex = 0; @@ -625,7 +642,7 @@ BMFace *EDBM_findnearestface(ViewContext *vc, int *dist) data.pass = 0; mesh_foreachScreenFace(vc, findnearestface__doClosest, &data); - if (data.dist>3) { + if (data.dist > 3) { data.pass = 1; ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); mesh_foreachScreenFace(vc, findnearestface__doClosest, &data); @@ -646,31 +663,31 @@ BMFace *EDBM_findnearestface(ViewContext *vc, int *dist) */ static int unified_findnearest(ViewContext *vc, BMVert **eve, BMEdge **eed, BMFace **efa) { - BMEditMesh *em= vc->em; - int dist= 75; + BMEditMesh *em = vc->em; + int dist = 75; - *eve= NULL; - *eed= NULL; - *efa= NULL; + *eve = NULL; + *eed = NULL; + *efa = NULL; /* no afterqueue (yet), so we check it now, otherwise the em_xxxofs indices are bad */ view3d_validate_backbuf(vc); if (em->selectmode & SCE_SELECT_VERTEX) - *eve= EDBM_findnearestvert(vc, &dist, BM_SELECT, 0); + *eve = EDBM_findnearestvert(vc, &dist, BM_SELECT, 0); if (em->selectmode & SCE_SELECT_FACE) - *efa= EDBM_findnearestface(vc, &dist); + *efa = EDBM_findnearestface(vc, &dist); dist-= 20; /* since edges select lines, we give dots advantage of 20 pix */ if (em->selectmode & SCE_SELECT_EDGE) - *eed= EDBM_findnearestedge(vc, &dist); + *eed = EDBM_findnearestedge(vc, &dist); /* return only one of 3 pointers, for frontbuffer redraws */ if (*eed) { - *efa= NULL; *eve= NULL; + *efa = NULL; *eve = NULL; } else if (*efa) { - *eve= NULL; + *eve = NULL; } return (*eve || *eed || *efa); @@ -706,7 +723,7 @@ static EnumPropertyItem prop_similar_types[] = { static int similar_face_select_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; /* get the type from RNA */ @@ -747,7 +764,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) static int similar_edge_select_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; /* get the type from RNA */ @@ -794,7 +811,7 @@ VERT GROUP static int similar_vert_select_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; /* get the type from RNA */ int type = RNA_enum_get(op->ptr, "type"); @@ -829,7 +846,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) static int select_similar_exec(bContext *C, wmOperator *op) { - int type= RNA_enum_get(op->ptr, "type"); + int type = RNA_enum_get(op->ptr, "type"); if (type < 100) return similar_vert_select_exec(C, op); @@ -839,33 +856,34 @@ static int select_similar_exec(bContext *C, wmOperator *op) return similar_face_select_exec(C, op); } -static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) +static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), + int *free) { Object *obedit = CTX_data_edit_object(C); if (obedit && obedit->type == OB_MESH) { - EnumPropertyItem *item= NULL; - int a, totitem= 0; - BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh; + EnumPropertyItem *item = NULL; + int a, totitem = 0; + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; if (em->selectmode & SCE_SELECT_VERTEX) { - for (a=SIMVERT_NORMAL; a<SIMEDGE_LENGTH; a++) { + for (a = SIMVERT_NORMAL; a < SIMEDGE_LENGTH; a++) { RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a); } } else if (em->selectmode & SCE_SELECT_EDGE) { - for (a=SIMEDGE_LENGTH; a<SIMFACE_MATERIAL; a++) { + for (a = SIMEDGE_LENGTH; a < SIMFACE_MATERIAL; a++) { RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a); } } else if (em->selectmode & SCE_SELECT_FACE) { - for (a=SIMFACE_MATERIAL; a<=SIMFACE_COPLANAR; a++) { + for (a = SIMFACE_MATERIAL; a <= SIMFACE_COPLANAR; a++) { RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a); } } RNA_enum_item_end(&item, &totitem); - *free= 1; + *free = 1; return item; } @@ -878,20 +896,20 @@ void MESH_OT_select_similar(wmOperatorType *ot) PropertyRNA *prop; /* identifiers */ - ot->name= "Select Similar"; - ot->idname= "MESH_OT_select_similar"; + ot->name = "Select Similar"; + ot->idname = "MESH_OT_select_similar"; /* api callbacks */ - ot->invoke= WM_menu_invoke; - ot->exec= select_similar_exec; - ot->poll= ED_operator_editmesh; - ot->description= "Select similar vertices, edges or faces by property types"; + ot->invoke = WM_menu_invoke; + ot->exec = select_similar_exec; + ot->poll = ED_operator_editmesh; + ot->description = "Select similar vertices, edges or faces by property types"; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ - prop= ot->prop= RNA_def_enum(ot->srna, "type", prop_similar_types, SIMVERT_NORMAL, "Type", ""); + prop = ot->prop = RNA_def_enum(ot->srna, "type", prop_similar_types, SIMVERT_NORMAL, "Type", ""); RNA_def_enum_funcs(prop, select_similar_type_itemf); } @@ -920,17 +938,17 @@ static void walker_select(BMEditMesh *em, int walkercode, void *start, int selec static int loop_multiselect(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMEdge *eed; BMEdge **edarray; int edindex; - int looptype= RNA_boolean_get(op->ptr, "ring"); + int looptype = RNA_boolean_get(op->ptr, "ring"); BMIter iter; int totedgesel = 0; - for(eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); + for (eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); eed; eed = BMIter_Step(&iter)) { if (BM_TestHFlag(eed, BM_SELECT)) { @@ -939,11 +957,13 @@ static int loop_multiselect(bContext *C, wmOperator *op) } - edarray = MEM_mallocN(sizeof(BMEdge*)*totedgesel,"edge array"); + edarray = MEM_mallocN(sizeof(BMEdge *)*totedgesel,"edge array"); edindex = 0; - for(eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - eed; eed = BMIter_Step(&iter)) { + for (eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); + eed; + eed = BMIter_Step(&iter)) + { if (BM_TestHFlag(eed, BM_SELECT)) { edarray[edindex] = eed; @@ -952,14 +972,14 @@ static int loop_multiselect(bContext *C, wmOperator *op) } if (looptype) { - for(edindex = 0; edindex < totedgesel; edindex +=1) { + for (edindex = 0; edindex < totedgesel; edindex += 1) { eed = edarray[edindex]; walker_select(em, BMW_EDGERING, eed, 1); } EDBM_selectmode_flush(em); } else{ - for(edindex = 0; edindex < totedgesel; edindex +=1) { + for (edindex = 0; edindex < totedgesel; edindex += 1) { eed = edarray[edindex]; walker_select(em, BMW_LOOP, eed, 1); } @@ -970,22 +990,22 @@ static int loop_multiselect(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_loop_multi_select(wmOperatorType *ot) { /* identifiers */ - ot->name= "Multi Select Loops"; - ot->idname= "MESH_OT_loop_multi_select"; + ot->name = "Multi Select Loops"; + ot->idname = "MESH_OT_loop_multi_select"; /* api callbacks */ - ot->exec= loop_multiselect; - ot->poll= ED_operator_editmesh; - ot->description= "Select a loop of connected edges by connection type"; + ot->exec = loop_multiselect; + ot->poll = ED_operator_editmesh; + ot->description = "Select a loop of connected edges by connection type"; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ RNA_def_boolean(ot->srna, "ring", 0, "Ring", ""); @@ -1002,26 +1022,28 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short ring) ViewContext vc; BMEditMesh *em; BMEdge *eed; - int select= 1; + int select = TRUE; int dist = 50; em_setup_viewcontext(C, &vc); - vc.mval[0]= mval[0]; - vc.mval[1]= mval[1]; - em= vc.em; + vc.mval[0] = mval[0]; + vc.mval[1] = mval[1]; + em = vc.em; /* no afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad */ view3d_validate_backbuf(&vc); eed = EDBM_findnearestedge(&vc, &dist); if (eed) { - if (extend==0) EDBM_clear_flag_all(em, BM_SELECT); + if (extend == 0) { + EDBM_clear_flag_all(em, BM_SELECT); + } - if (BM_TestHFlag(eed, BM_SELECT)==0) { - select=1; + if (BM_TestHFlag(eed, BM_SELECT) == 0) { + select = TRUE; } else if (extend) { - select=0; + select = FALSE; } if (em->selectmode & SCE_SELECT_FACE) { @@ -1048,16 +1070,16 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short ring) if (select) { if (em->selectmode & SCE_SELECT_VERTEX) { /* TODO: would be nice if the edge vertex chosen here - was the one closer to the selection pointer, instead - of arbitrarily selecting the first one */ + * was the one closer to the selection pointer, instead + * of arbitrarily selecting the first one */ EDBM_store_selection(em, eed->v1); } else if (em->selectmode & SCE_SELECT_EDGE) { EDBM_store_selection(em, eed); } /* TODO: would be nice if the nearest face that - belongs to the selected edge could be set to - active here in face select mode */ + * belongs to the selected edge could be set to + * active here in face select mode */ } WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit); @@ -1079,17 +1101,17 @@ static int mesh_select_loop_invoke(bContext *C, wmOperator *op, wmEvent *event) void MESH_OT_loop_select(wmOperatorType *ot) { /* identifiers */ - ot->name= "Loop Select"; - ot->idname= "MESH_OT_loop_select"; - ot->description= "Select a loop"; + ot->name = "Loop Select"; + ot->idname = "MESH_OT_loop_select"; + ot->description = "Select a loop"; /* api callbacks */ - ot->invoke= mesh_select_loop_invoke; - ot->poll= ED_operator_editmesh_region_view3d; - ot->description= "Select a loop of connected edges"; + ot->invoke = mesh_select_loop_invoke; + ot->poll = ED_operator_editmesh_region_view3d; + ot->description = "Select a loop of connected edges"; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "Extend the selection"); @@ -1099,16 +1121,16 @@ void MESH_OT_loop_select(wmOperatorType *ot) void MESH_OT_edgering_select (wmOperatorType *ot) { /* description */ - ot->name= "Edge Ring Select"; - ot->idname= "MESH_OT_edgering_select"; - ot->description= "Select an edge ring"; + ot->name = "Edge Ring Select"; + ot->idname = "MESH_OT_edgering_select"; + ot->description = "Select an edge ring"; /* callbacks */ - ot->invoke= mesh_select_loop_invoke; - ot->poll= ED_operator_editmesh_region_view3d; + ot->invoke = mesh_select_loop_invoke; + ot->poll = ED_operator_editmesh_region_view3d; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection"); RNA_def_boolean(ot->srna, "ring", 1, "Select Ring", "Select ring"); @@ -1116,22 +1138,22 @@ void MESH_OT_edgering_select (wmOperatorType *ot) /* ******************* edgetag_shortest_path and helpers ****************** */ -static float edgetag_cut_cost(BMEditMesh *UNUSED(em), BMEdge *e1, BMEdge *e2, BMVert* v) +static float edgetag_cut_cost(BMEditMesh *UNUSED(em), BMEdge *e1, BMEdge *e2, BMVert *v) { BMVert *v1 = (e1->v1 == v) ? e1->v2 : e1->v1; BMVert *v2 = (e2->v1 == v) ? e2->v2 : e2->v1; float cost, d1[3], d2[3]; - /*The cost is based on the simple sum of the length of the two edgees...*/ + /* The cost is based on the simple sum of the length of the two edgees... */ sub_v3_v3v3(d1, v->co, v1->co); sub_v3_v3v3(d2, v2->co, v->co); cost = len_v3(d1); cost += len_v3(d2); - /*...but is biased to give higher values to sharp turns, so that it will take - paths with fewer "turns" when selecting between equal-weighted paths between - the two edges*/ - cost = cost + 0.5f*cost*(2.0f - sqrt(fabs(dot_v3v3(d1, d2)))); + /*.but is biased to give higher values to sharp turns, so that it will take + * paths with fewer "turns" when selecting between equal-weighted paths between + * the two edges */ + cost = cost + 0.5f * cost * (2.0f - sqrt(fabs(dot_v3v3(d1, d2)))); return cost; } @@ -1141,7 +1163,7 @@ static void edgetag_add_adjacent(BMEditMesh *em, SmallHash *visithash, Heap *hea { BMEdge *e1 = EDBM_get_edge_for_index(em, mednum); BMVert *v = EDBM_get_vert_for_index(em, vertnum); - int startadj, endadj = nedges[vertnum+1]; + int startadj, endadj = nedges[vertnum + 1]; for (startadj = nedges[vertnum]; startadj < endadj; startadj++) { int adjnum = edges[startadj]; @@ -1177,7 +1199,7 @@ static void edgetag_context_set(BMEditMesh *em, Scene *scene, BMEdge *e, int val case EDGE_MODE_TAG_SHARP: if (val) {BM_SetHFlag(e, BM_SEAM);} else {BM_ClearHFlag(e, BM_SEAM);} - break; + break; case EDGE_MODE_TAG_CREASE: { float *crease = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_CREASE); @@ -1221,13 +1243,13 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B Heap *heap; SmallHash visithash; float *cost; - int i, totvert=0, totedge=0, *nedges, *edges, *prevedge, mednum = -1, nedgeswap = 0; + int i, totvert = 0, totedge = 0, *nedges, *edges, *prevedge, mednum = -1, nedgeswap = 0; int targetnum; BLI_smallhash_init(&visithash); /* note, would pass BM_EDGE except we are looping over all edges anyway */ - BM_ElemIndex_Ensure(em->bm, BM_VERT /* | BM_EDGE */ ); + BM_ElemIndex_Ensure(em->bm, BM_VERT /* | BM_EDGE */); BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { e->head.flags[0].f = 0; @@ -1242,28 +1264,28 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B /* alloc */ totvert = em->bm->totvert; - nedges = MEM_callocN(sizeof(*nedges)*totvert+1, "SeamPathNEdges"); - edges = MEM_mallocN(sizeof(*edges)*totedge*2, "SeamPathEdges"); - prevedge = MEM_mallocN(sizeof(*prevedge)*totedge, "SeamPathPrevious"); - cost = MEM_mallocN(sizeof(*cost)*totedge, "SeamPathCost"); + nedges = MEM_callocN(sizeof(*nedges) * totvert + 1, "SeamPathNEdges"); + edges = MEM_mallocN(sizeof(*edges) * totedge * 2, "SeamPathEdges"); + prevedge = MEM_mallocN(sizeof(*prevedge) * totedge, "SeamPathPrevious"); + cost = MEM_mallocN(sizeof(*cost) * totedge, "SeamPathCost"); /* count edges, compute adjacent edges offsets and fill adjacent */ BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { - nedges[BM_GetIndex(e->v1)+1]++; - nedges[BM_GetIndex(e->v2)+1]++; + nedges[BM_GetIndex(e->v1) + 1]++; + nedges[BM_GetIndex(e->v2) + 1]++; } for (i = 1; i < totvert; i++) { - int newswap = nedges[i+1]; - nedges[i+1] = nedgeswap + nedges[i]; + int newswap = nedges[i + 1]; + nedges[i + 1] = nedgeswap + nedges[i]; nedgeswap = newswap; } nedges[0] = nedges[1] = 0; i = 0; BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { - edges[nedges[BM_GetIndex(e->v1)+1]++] = i; - edges[nedges[BM_GetIndex(e->v2)+1]++] = i; + edges[nedges[BM_GetIndex(e->v1) + 1]++] = i; + edges[nedges[BM_GetIndex(e->v2) + 1]++] = i; cost[i] = 1e20f; prevedge[i] = -1; @@ -1273,8 +1295,8 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B /* * Arrays are now filled as follows: * - * nedges[n] = sum of the # of edges incident to all vertices numbered 0 thru n-1 - * edges[edges[n]..edges[n-1]] = the indices of of the edges incident to vertex n + * nedges[n] = sum of the # of edges incident to all vertices numbered 0 thru n - 1 + * edges[edges[n]..edges[n - 1]] = the indices of of the edges incident to vertex n * * As the search continues, prevedge[n] will be the previous edge on the shortest * path found so far to edge n. The visitedhash will of course contain entries @@ -1286,9 +1308,9 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B #if 0 /* UNUSED */ /* this block does nothing, not sure why its here? - campbell */ for (i = 0; i < totvert; i++) { - int start = nedges[i], end = nedges[i+1], cur; + int start = nedges[i], end = nedges[i + 1], cur; for (cur = start; cur < end; cur++) { - BMEdge* e = EDBM_get_edge_for_index(em, edges[cur]); + BMEdge *e = EDBM_get_edge_for_index(em, edges[cur]); } } #endif @@ -1319,8 +1341,8 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B if (mednum == targetnum) { short allseams = 1; - /*Check whether the path is already completely tagged. - if it is, the tags will be cleared instead of set.*/ + /* Check whether the path is already completely tagged. + * if it is, the tags will be cleared instead of set. */ mednum = targetnum; do { e = EDBM_get_edge_for_index(em, mednum); @@ -1331,7 +1353,7 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B mednum = prevedge[mednum]; } while (mednum != BM_GetIndex(source)); - /*Follow path back and source and add or remove tags*/ + /* Follow path back and source and add or remove tags */ mednum = targetnum; do { e = EDBM_get_edge_for_index(em, mednum); @@ -1363,20 +1385,20 @@ static void mouse_mesh_shortest_path(bContext *C, int mval[2]) ViewContext vc; BMEditMesh *em; BMEdge *e; - int dist= 50; + int dist = 50; em_setup_viewcontext(C, &vc); - vc.mval[0]= mval[0]; - vc.mval[1]= mval[1]; - em= vc.em; + vc.mval[0] = mval[0]; + vc.mval[1] = mval[1]; + em = vc.em; - e= EDBM_findnearestedge(&vc, &dist); + e = EDBM_findnearestedge(&vc, &dist); if (e) { - Mesh *me= vc.obedit->data; + Mesh *me = vc.obedit->data; int path = 0; if (em->bm->selected.last) { - BMEditSelection *ese= em->bm->selected.last; + BMEditSelection *ese = em->bm->selected.last; if (ese && ese->htype == BM_EDGE) { BMEdge *e_act; @@ -1389,15 +1411,15 @@ static void mouse_mesh_shortest_path(bContext *C, int mval[2]) } } } - if (path==0) { - int act = (edgetag_context_check(vc.scene, em, e)==0); + if (path == 0) { + int act = (edgetag_context_check(vc.scene, em, e) == 0); edgetag_context_set(em, vc.scene, e, act); /* switch the edge option */ } EDBM_selectmode_flush(em); /* even if this is selected it may not be in the selection list */ - if (edgetag_context_check(vc.scene, em, e)==0) + if (edgetag_context_check(vc.scene, em, e) == 0) EDBM_remove_selection(em, e); else EDBM_store_selection(em, e); @@ -1438,16 +1460,16 @@ static int mesh_shortest_path_select_invoke(bContext *C, wmOperator *UNUSED(op), void MESH_OT_select_shortest_path(wmOperatorType *ot) { /* identifiers */ - ot->name= "Shortest Path Select"; - ot->idname= "MESH_OT_select_shortest_path"; + ot->name = "Shortest Path Select"; + ot->idname = "MESH_OT_select_shortest_path"; /* api callbacks */ - ot->invoke= mesh_shortest_path_select_invoke; - ot->poll= ED_operator_editmesh; - ot->description= "Select shortest path between two selections"; + ot->invoke = mesh_shortest_path_select_invoke; + ot->poll = ED_operator_editmesh; + ot->description = "Select shortest path between two selections"; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); @@ -1465,12 +1487,12 @@ int mouse_mesh(bContext *C, const int mval[2], short extend) /* setup view context for argument to callbacks */ em_setup_viewcontext(C, &vc); - vc.mval[0]= mval[0]; - vc.mval[1]= mval[1]; + vc.mval[0] = mval[0]; + vc.mval[1] = mval[1]; if (unified_findnearest(&vc, &eve, &eed, &efa)) { - if (extend==0) EDBM_clear_flag_all(vc.em, BM_SELECT); + if (extend == 0) EDBM_clear_flag_all(vc.em, BM_SELECT); if (efa) { /* set the last selected face */ @@ -1510,9 +1532,9 @@ int mouse_mesh(bContext *C, const int mval[2], short extend) // if (EM_texFaceCheck()) { - if (efa && efa->mat_nr != vc.obedit->actcol-1) { - vc.obedit->actcol= efa->mat_nr+1; - vc.em->mat_nr= efa->mat_nr; + if (efa && efa->mat_nr != vc.obedit->actcol - 1) { + vc.obedit->actcol = efa->mat_nr + 1; + vc.em->mat_nr = efa->mat_nr; // BIF_preview_changed(ID_MA); } @@ -1529,23 +1551,23 @@ static void EDBM_strip_selections(BMEditMesh *em) if (!(em->selectmode & SCE_SELECT_VERTEX)) { ese = em->bm->selected.first; - while(ese) { - nextese = ese->next; - if (ese->htype == BM_VERT) BLI_freelinkN(&(em->bm->selected),ese); + while (ese) { + nextese = ese->next; + if (ese->htype == BM_VERT) BLI_freelinkN(&(em->bm->selected), ese); ese = nextese; } } if (!(em->selectmode & SCE_SELECT_EDGE)) { - ese=em->bm->selected.first; - while(ese) { + ese = em->bm->selected.first; + while (ese) { nextese = ese->next; if (ese->htype == BM_EDGE) BLI_freelinkN(&(em->bm->selected), ese); ese = nextese; } } if (!(em->selectmode & SCE_SELECT_FACE)) { - ese=em->bm->selected.first; - while(ese) { + ese = em->bm->selected.first; + while (ese) { nextese = ese->next; if (ese->htype == BM_FACE) BLI_freelinkN(&(em->bm->selected), ese); ese = nextese; @@ -1564,7 +1586,7 @@ void EDBM_selectmode_set(BMEditMesh *em) em->bm->selectmode = em->selectmode; - EDBM_strip_selections(em); /*strip BMEditSelections from em->selected that are not relevant to new mode*/ + EDBM_strip_selections(em); /* strip BMEditSelections from em->selected that are not relevant to new mode */ if (em->selectmode & SCE_SELECT_VERTEX) { EDBM_select_flush(em); @@ -1572,10 +1594,10 @@ void EDBM_selectmode_set(BMEditMesh *em) else if (em->selectmode & SCE_SELECT_EDGE) { /* deselect vertices, and select again based on edge select */ eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for ( ; eve; eve=BMIter_Step(&iter)) BM_Select(em->bm, eve, FALSE); + for ( ; eve; eve = BMIter_Step(&iter)) BM_Select(em->bm, eve, FALSE); eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - for ( ; eed; eed=BMIter_Step(&iter)) { + for ( ; eed; eed = BMIter_Step(&iter)) { if (BM_TestHFlag(eed, BM_SELECT)) { BM_Select(em->bm, eed, TRUE); } @@ -1587,10 +1609,10 @@ void EDBM_selectmode_set(BMEditMesh *em) else if (em->selectmode & SCE_SELECT_FACE) { /* deselect eges, and select again based on face select */ eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - for ( ; eed; eed=BMIter_Step(&iter)) BM_Select(em->bm, eed, FALSE); + for ( ; eed; eed = BMIter_Step(&iter)) BM_Select(em->bm, eed, FALSE); efa = BMIter_New(&iter, em->bm, BM_FACES_OF_MESH, NULL); - for ( ; efa; efa=BMIter_Step(&iter)) { + for ( ; efa; efa = BMIter_Step(&iter)) { if (BM_TestHFlag(efa, BM_SELECT)) { BM_Select(em->bm, efa, TRUE); } @@ -1604,12 +1626,12 @@ void EDBM_convertsel(BMEditMesh *em, short oldmode, short selectmode) BMFace *efa; BMIter iter; - /*have to find out what the selectionmode was previously*/ + /* have to find out what the selectionmode was previously */ if (oldmode == SCE_SELECT_VERTEX) { if (selectmode == SCE_SELECT_EDGE) { - /*select all edges associated with every selected vertex*/ + /* select all edges associated with every selected vertex */ eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - for ( ; eed; eed=BMIter_Step(&iter)) { + for ( ; eed; eed = BMIter_Step(&iter)) { if ( (BM_TestHFlag(eed->v1, BM_SELECT) || BM_TestHFlag(eed->v2, BM_SELECT))) { @@ -1621,11 +1643,11 @@ void EDBM_convertsel(BMEditMesh *em, short oldmode, short selectmode) BMIter liter; BMLoop *l; - /*select all faces associated with every selected vertex*/ + /* select all faces associated with every selected vertex */ efa = BMIter_New(&iter, em->bm, BM_FACES_OF_MESH, NULL); - for ( ; efa; efa=BMIter_Step(&iter)) { + for ( ; efa; efa = BMIter_Step(&iter)) { l = BMIter_New(&liter, em->bm, BM_LOOPS_OF_FACE, efa); - for (; l; l=BMIter_Step(&liter)) { + for (; l; l = BMIter_Step(&liter)) { if (BM_TestHFlag(l->v, BM_SELECT)) { BM_Select(em->bm, efa, TRUE); break; @@ -1640,11 +1662,11 @@ void EDBM_convertsel(BMEditMesh *em, short oldmode, short selectmode) BMIter liter; BMLoop *l; - /*select all faces associated with every selected vertex*/ + /* select all faces associated with every selected vertex */ efa = BMIter_New(&iter, em->bm, BM_FACES_OF_MESH, NULL); - for ( ; efa; efa=BMIter_Step(&iter)) { + for ( ; efa; efa = BMIter_Step(&iter)) { l = BMIter_New(&liter, em->bm, BM_LOOPS_OF_FACE, efa); - for (; l; l=BMIter_Step(&liter)) { + for (; l; l = BMIter_Step(&liter)) { if (BM_TestHFlag(l->v, BM_SELECT)) { BM_Select(em->bm, efa, TRUE); break; @@ -1705,10 +1727,10 @@ void EDBM_select_swap(BMEditMesh *em) /* exported for UV */ static void linked_limit_default(bContext *C, wmOperator *op) { - if(!RNA_struct_property_is_set(op->ptr, "limit")) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; - if(em->selectmode == SCE_SELECT_FACE) + if (!RNA_struct_property_is_set(op->ptr, "limit")) { + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; + if (em->selectmode == SCE_SELECT_FACE) RNA_boolean_set(op->ptr, "limit", TRUE); else RNA_boolean_set(op->ptr, "limit", FALSE); @@ -1717,7 +1739,7 @@ static void linked_limit_default(bContext *C, wmOperator *op) static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event) { - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); ViewContext vc; BMesh *bm; BMWalker walker; @@ -1725,7 +1747,7 @@ static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event BMVert *eve; BMEdge *e, *eed; BMFace *efa; - int sel= !RNA_boolean_get(op->ptr, "deselect"); + int sel = !RNA_boolean_get(op->ptr, "deselect"); int limit; @@ -1740,17 +1762,17 @@ static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event em_setup_viewcontext(C, &vc); em = vc.em; - if (em->bm->totedge==0) + if (em->bm->totedge == 0) return OPERATOR_CANCELLED; - bm= em->bm; + bm = em->bm; - vc.mval[0]= event->mval[0]; - vc.mval[1]= event->mval[1]; + vc.mval[0] = event->mval[0]; + vc.mval[1] = event->mval[1]; /* return warning! */ - if ( unified_findnearest(&vc, &eve, &eed, &efa)==0 ) { + if (unified_findnearest(&vc, &eve, &eed, &efa) == 0) { WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); return OPERATOR_CANCELLED; @@ -1775,7 +1797,7 @@ static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event BMW_NIL_LAY); e = BMW_Begin(&walker, efa); - for (; efa; efa=BMW_Step(&walker)) { + for (; efa; efa = BMW_Step(&walker)) { BM_Select(bm, efa, sel); } BMW_End(&walker); @@ -1796,29 +1818,29 @@ static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event BMW_NIL_LAY); e = BMW_Begin(&walker, eed->v1); - for (; e; e=BMW_Step(&walker)) { + for ( ; e; e = BMW_Step(&walker)) { BM_Select(bm, e, sel); } BMW_End(&walker); } WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_select_linked_pick(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Linked"; - ot->idname= "MESH_OT_select_linked_pick"; + ot->name = "Select Linked"; + ot->idname = "MESH_OT_select_linked_pick"; /* api callbacks */ - ot->invoke= select_linked_pick_invoke; - ot->poll= ED_operator_editmesh; - ot->description= "select/deselect all vertices linked to the edge under the mouse cursor"; + ot->invoke = select_linked_pick_invoke; + ot->poll = ED_operator_editmesh; + ot->description = "select/deselect all vertices linked to the edge under the mouse cursor"; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", ""); RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", ""); @@ -1827,9 +1849,9 @@ void MESH_OT_select_linked_pick(wmOperatorType *ot) static int select_linked_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh; - BMesh *bm= em->bm; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; + BMesh *bm = em->bm; BMIter iter; BMVert *v; BMEdge *e; @@ -1867,7 +1889,7 @@ static int select_linked_exec(bContext *C, wmOperator *op) BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (BM_TestHFlag(efa, BM_TMP_TAG)) { e = BMW_Begin(&walker, efa); - for (; efa; efa=BMW_Step(&walker)) { + for (; efa; efa = BMW_Step(&walker)) { BM_Select(bm, efa, TRUE); } } @@ -1890,7 +1912,7 @@ static int select_linked_exec(bContext *C, wmOperator *op) BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_TestHFlag(v, BM_TMP_TAG)) { e = BMW_Begin(&walker, v); - for (; e; e=BMW_Step(&walker)) { + for (; e; e = BMW_Step(&walker)) { BM_Select(em->bm, e->v1, TRUE); BM_Select(em->bm, e->v2, TRUE); } @@ -1902,22 +1924,22 @@ static int select_linked_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_select_linked(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Linked All"; - ot->idname= "MESH_OT_select_linked"; + ot->name = "Select Linked All"; + ot->idname = "MESH_OT_select_linked"; /* api callbacks */ - ot->exec= select_linked_exec; - ot->poll= ED_operator_editmesh; - ot->description= "Select all vertices linked to the active mesh"; + ot->exec = select_linked_exec; + ot->poll = ED_operator_editmesh; + ot->description = "Select all vertices linked to the active mesh"; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", ""); } @@ -1926,8 +1948,8 @@ void MESH_OT_select_linked(wmOperatorType *ot) static int select_more(bContext *C, wmOperator *UNUSED(op)) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; EDBM_select_more(em); @@ -1938,22 +1960,22 @@ static int select_more(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_select_more(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select More"; - ot->idname= "MESH_OT_select_more"; - ot->description= "Select more vertices, edges or faces connected to initial selection"; + ot->name = "Select More"; + ot->idname = "MESH_OT_select_more"; + ot->description = "Select more vertices, edges or faces connected to initial selection"; /* api callbacks */ - ot->exec= select_more; - ot->poll= ED_operator_editmesh; + ot->exec = select_more; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int select_less(bContext *C, wmOperator *UNUSED(op)) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; EDBM_select_less(em); @@ -1964,16 +1986,16 @@ static int select_less(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_select_less(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Less"; - ot->idname= "MESH_OT_select_less"; - ot->description= "Deselect vertices, edges or faces at the boundary of each selection region"; + ot->name = "Select Less"; + ot->idname = "MESH_OT_select_less"; + ot->description = "Deselect vertices, edges or faces at the boundary of each selection region"; /* api callbacks */ - ot->exec= select_less; - ot->poll= ED_operator_editmesh; + ot->exec = select_less; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } /* Walk all reachable elements of the same type as h_act in breadth-first @@ -1986,15 +2008,15 @@ static void walker_deselect_nth(BMEditMesh *em, int nth, int offset, BMHeader *h BMWalker walker; BMIter iter; int walktype = 0, itertype = 0, flushtype = 0; - short mask_vert=0, mask_edge=0, mask_loop=0, mask_face=0; + short mask_vert = 0, mask_edge = 0, mask_loop = 0, mask_face = 0; /* No active element from which to start - nothing to do */ - if (h_act==NULL) { + if (h_act == NULL) { return; } /* Determine which type of iter, walker, and select flush to use - based on type of the elements being deselected */ + * based on type of the elements being deselected */ switch (h_act->htype) { case BM_VERT: itertype = BM_VERTS_OF_MESH; @@ -2053,23 +2075,23 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **v_p, BMEdge **e_p, BMFa BMIter iter; BMEditSelection *ese; - *v_p= NULL; - *e_p= NULL; - *f_p= NULL; + *v_p = NULL; + *e_p = NULL; + *f_p = NULL; EDBM_selectmode_flush(em); - ese= (BMEditSelection*)em->bm->selected.last; + ese = (BMEditSelection *)em->bm->selected.last; if (ese) { switch(ese->htype) { case BM_VERT: - *v_p= (BMVert *)ese->data; + *v_p = (BMVert *)ese->data; return; case BM_EDGE: - *e_p= (BMEdge *)ese->data; + *e_p = (BMEdge *)ese->data; return; case BM_FACE: - *f_p= (BMFace *)ese->data; + *f_p = (BMFace *)ese->data; return; } } @@ -2091,9 +2113,9 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **v_p, BMEdge **e_p, BMFa } } else if (em->selectmode & SCE_SELECT_FACE) { - f= BM_get_actFace(em->bm, TRUE); + f = BM_get_actFace(em->bm, TRUE); if (f) { - *f_p= f; + *f_p = f; return; } } @@ -2125,10 +2147,10 @@ static int EM_deselect_nth(BMEditMesh *em, int nth, int offset) static int mesh_select_nth_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; - int nth= RNA_int_get(op->ptr, "nth"); - int offset= RNA_int_get(op->ptr, "offset"); + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; + int nth = RNA_int_get(op->ptr, "nth"); + int offset = RNA_int_get(op->ptr, "offset"); offset = MIN2(nth, offset); @@ -2147,16 +2169,16 @@ static int mesh_select_nth_exec(bContext *C, wmOperator *op) void MESH_OT_select_nth(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Nth"; - ot->description= ""; - ot->idname= "MESH_OT_select_nth"; + ot->name = "Select Nth"; + ot->description = ""; + ot->idname = "MESH_OT_select_nth"; /* api callbacks */ - ot->exec= mesh_select_nth_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_select_nth_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_int(ot->srna, "nth", 2, 2, 100, "Nth Selection", "", 1, INT_MAX); RNA_def_int(ot->srna, "offset", 0, 0, 100, "Offset", "", 0, INT_MAX); @@ -2167,8 +2189,8 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc) view3d_set_viewcontext(C, vc); if (vc->obedit) { - Mesh *me= vc->obedit->data; - vc->em= me->edit_btmesh; + Mesh *me = vc->obedit->data; + vc->em = me->edit_btmesh; } } @@ -2187,8 +2209,8 @@ static int select_sharp_edges_exec(bContext *C, wmOperator *op) * check the angle between those faces, and if angle is * small enough, select the edge */ - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMIter iter; BMEdge *e; BMLoop *l1, *l2; @@ -2223,16 +2245,16 @@ static int select_sharp_edges_exec(bContext *C, wmOperator *op) void MESH_OT_edges_select_sharp(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Sharp Edges"; - ot->description= "Marked selected edges as sharp"; - ot->idname= "MESH_OT_edges_select_sharp"; + ot->name = "Select Sharp Edges"; + ot->description = "Marked selected edges as sharp"; + ot->idname = "MESH_OT_edges_select_sharp"; /* api callbacks */ - ot->exec= select_sharp_edges_exec; - ot->poll= ED_operator_editmesh; + ot->exec = select_sharp_edges_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_float(ot->srna, "sharpness", 1.0f, 0.01f, FLT_MAX, "sharpness", "", 1.0f, 180.0f); @@ -2240,8 +2262,8 @@ void MESH_OT_edges_select_sharp(wmOperatorType *ot) static int select_linked_flat_faces_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMIter iter, liter, liter2; BMFace *f, **stack = NULL; BLI_array_declare(stack); @@ -2263,10 +2285,10 @@ static int select_linked_flat_faces_exec(bContext *C, wmOperator *op) i = 1; BLI_array_growone(stack); - stack[i-1] = f; + stack[i - 1] = f; while (i) { - f = stack[i-1]; + f = stack[i - 1]; i--; BM_Select(em->bm, f, TRUE); @@ -2281,10 +2303,10 @@ static int select_linked_flat_faces_exec(bContext *C, wmOperator *op) continue; /* edge has exactly two neighboring faces, check angle */ - angle = saacos(f->no[0]*l2->f->no[0]+f->no[1]*l2->f->no[1]+f->no[2]*l2->f->no[2]); + angle = angle_normalized_v3v3(f->no, l2->f->no); /* invalidate: edge too sharp */ - if (fabs(angle) < sharp) { + if (angle < sharp) { BLI_array_growone(stack); stack[i] = l2->f; i++; @@ -2304,16 +2326,16 @@ static int select_linked_flat_faces_exec(bContext *C, wmOperator *op) void MESH_OT_faces_select_linked_flat(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Linked Flat Faces"; - ot->description= "Select linked faces by angle"; - ot->idname= "MESH_OT_faces_select_linked_flat"; + ot->name = "Select Linked Flat Faces"; + ot->description = "Select linked faces by angle"; + ot->idname = "MESH_OT_faces_select_linked_flat"; /* api callbacks */ - ot->exec= select_linked_flat_faces_exec; - ot->poll= ED_operator_editmesh; + ot->exec = select_linked_flat_faces_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_float(ot->srna, "sharpness", 1.0f, 0.01f, FLT_MAX, "sharpness", "", 1.0f, 180.0f); @@ -2321,8 +2343,8 @@ void MESH_OT_faces_select_linked_flat(wmOperatorType *ot) static int select_non_manifold_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMVert *v; BMEdge *e; BMIter iter; @@ -2331,7 +2353,7 @@ static int select_non_manifold_exec(bContext *C, wmOperator *op) * faces */ - if (em->selectmode==SCE_SELECT_FACE) { + if (em->selectmode == SCE_SELECT_FACE) { BKE_report(op->reports, RPT_ERROR, "Doesn't work in face selection mode"); return OPERATOR_CANCELLED; } @@ -2350,35 +2372,35 @@ static int select_non_manifold_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_select_non_manifold(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Non Manifold"; - ot->description= "Select all non-manifold vertices or edges"; - ot->idname= "MESH_OT_select_non_manifold"; + ot->name = "Select Non Manifold"; + ot->description = "Select all non-manifold vertices or edges"; + ot->idname = "MESH_OT_select_non_manifold"; /* api callbacks */ - ot->exec= select_non_manifold_exec; - ot->poll= ED_operator_editmesh; + ot->exec = select_non_manifold_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int mesh_select_random_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMVert *eve; BMEdge *eed; BMFace *efa; BMIter iter; float randfac = RNA_float_get(op->ptr, "percent")/100.0f; - BLI_srand( BLI_rand() ); /* random seed */ + BLI_srand(BLI_rand()); /* random seed */ if (!RNA_boolean_get(op->ptr, "extend")) EDBM_clear_flag_all(em, BM_SELECT); @@ -2410,32 +2432,34 @@ static int mesh_select_random_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_select_random(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Random"; - ot->description= "Randomly select vertices"; - ot->idname= "MESH_OT_select_random"; + ot->name = "Select Random"; + ot->description = "Randomly select vertices"; + ot->idname = "MESH_OT_select_random"; /* api callbacks */ - ot->exec= mesh_select_random_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_select_random_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ - RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of elements to select randomly", 0.f, 100.0f); - RNA_def_boolean(ot->srna, "extend", 0, "Extend Selection", "Extend selection instead of deselecting everything first"); + RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, + "Percent", "Percentage of elements to select randomly", 0.f, 100.0f); + RNA_def_boolean(ot->srna, "extend", 0, + "Extend Selection", "Extend selection instead of deselecting everything first"); } static int select_next_loop(bContext *C, wmOperator *UNUSED(op)) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; BMFace *f; BMVert *v; BMIter iter; @@ -2469,23 +2493,23 @@ static int select_next_loop(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_select_next_loop(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Next Loop"; - ot->idname= "MESH_OT_select_next_loop"; - ot->description= ""; + ot->name = "Select Next Loop"; + ot->idname = "MESH_OT_select_next_loop"; + ot->description = ""; /* api callbacks */ - ot->exec= select_next_loop; - ot->poll= ED_operator_editmesh; + ot->exec = select_next_loop; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int region_to_loop(bContext *C, wmOperator *UNUSED(op)) { Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)obedit->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMFace *f; BMEdge *e; BMIter iter; @@ -2502,7 +2526,7 @@ static int region_to_loop(bContext *C, wmOperator *UNUSED(op)) BMIter liter1, liter2; BM_ITER(l1, &liter1, em->bm, BM_LOOPS_OF_FACE, f) { - int tot=0, totsel=0; + int tot = 0, totsel = 0; BM_ITER(l2, &liter2, em->bm, BM_LOOPS_OF_EDGE, l1->e) { tot++; @@ -2537,15 +2561,15 @@ static int region_to_loop(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_region_to_loop(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Boundary Loop"; - ot->idname= "MESH_OT_region_to_loop"; + ot->name = "Select Boundary Loop"; + ot->idname = "MESH_OT_region_to_loop"; /* api callbacks */ - ot->exec= region_to_loop; - ot->poll= ED_operator_editmesh; + ot->exec = region_to_loop; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int loop_find_region(BMEditMesh *em, BMLoop *l, int flag, @@ -2588,16 +2612,16 @@ static int loop_find_region(BMEditMesh *em, BMLoop *l, int flag, static int verg_radial(const void *va, const void *vb) { - BMEdge *e1 = *((void**)va); - BMEdge *e2 = *((void**)vb); + BMEdge *e1 = *((void **)va); + BMEdge *e2 = *((void **)vb); int a, b; a = BM_Edge_FaceCount(e1); b = BM_Edge_FaceCount(e2); - if (a > b) return -1; - if (a == b) return 0; - if (a < b) return 1; + if (a > b) return -1; + if (a == b) return 0; + if (a < b) return 1; return -1; } @@ -2606,7 +2630,7 @@ static int loop_find_regions(BMEditMesh *em, int selbigger) { SmallHash visithash; BMIter iter; - BMEdge *e, **edges=NULL; + BMEdge *e, **edges = NULL; BLI_array_declare(edges); BMFace *f; int count = 0, i; @@ -2627,14 +2651,14 @@ static int loop_find_regions(BMEditMesh *em, int selbigger) } } - /*sort edges by radial cycle length*/ - qsort(edges, BLI_array_count(edges), sizeof(void*), verg_radial); + /* sort edges by radial cycle length */ + qsort(edges, BLI_array_count(edges), sizeof(void *), verg_radial); - for (i=0; i<BLI_array_count(edges); i++) { + for (i = 0; i < BLI_array_count(edges); i++) { BMIter liter; BMLoop *l; - BMFace **region=NULL, **r; - int c, tot=0; + BMFace **region = NULL, **r; + int c, tot = 0; e = edges[i]; @@ -2666,7 +2690,7 @@ static int loop_find_regions(BMEditMesh *em, int selbigger) if (region) { int j; - for (j=0; j<tot; j++) { + for (j = 0; j < tot; j++) { BM_SetHFlag(region[j], BM_TMP_TAG); BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, region[j]) { BM_ClearHFlag(l->e, BM_TMP_TAG); @@ -2688,13 +2712,13 @@ static int loop_find_regions(BMEditMesh *em, int selbigger) static int loop_to_region(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)obedit->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMIter iter; BMFace *f; int selbigger = RNA_boolean_get(op->ptr, "select_bigger"); int a, b; - /*find the set of regions with smallest number of total faces*/ + /* find the set of regions with smallest number of total faces */ a = loop_find_regions(em, selbigger); b = loop_find_regions(em, !selbigger); @@ -2717,15 +2741,15 @@ static int loop_to_region(bContext *C, wmOperator *op) void MESH_OT_loop_to_region(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Loop Inner-Region"; - ot->idname= "MESH_OT_loop_to_region"; + ot->name = "Select Loop Inner-Region"; + ot->idname = "MESH_OT_loop_to_region"; /* api callbacks */ - ot->exec= loop_to_region; - ot->poll= ED_operator_editmesh; + ot->exec = loop_to_region; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "select_bigger", 0, "Select Bigger", "Select bigger regions instead of smaller ones"); } diff --git a/source/blender/editors/mesh/bmesh_selecthistory.c b/source/blender/editors/mesh/bmesh_selecthistory.c index 29707e832a1..2145fc1dbe8 100644 --- a/source/blender/editors/mesh/bmesh_selecthistory.c +++ b/source/blender/editors/mesh/bmesh_selecthistory.c @@ -85,10 +85,10 @@ #include "BLO_sys_types.h" // for intptr_t support -/*these wrap equivilent bmesh functions. I'm in two minds of it we should - just use the bm functions directly; on the one hand, there's no real - need (at the moment) to wrap them, but on the other hand having these - wrapped avoids a confusing mess of mixing BM_ and EDBM_ namespaces.*/ +/* these wrap equivilent bmesh functions. I'm in two minds of it we should + * just use the bm functions directly; on the one hand, there's no real + * need (at the moment) to wrap them, but on the other hand having these + * wrapped avoids a confusing mess of mixing BM_ and EDBM_ namespaces. */ void EDBM_editselection_center(BMEditMesh *em, float *center, BMEditSelection *ese) { diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index 1e268cd58fd..52b0a4a03d3 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -110,12 +110,12 @@ static void add_normal_aligned(float nor[3], const float add[3]) static int subdivide_exec(bContext *C, wmOperator *op) { ToolSettings *ts = CTX_data_tool_settings(C); - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; - int cuts= RNA_int_get(op->ptr,"number_cuts"); - float smooth= 0.292f*RNA_float_get(op->ptr, "smoothness"); - float fractal= RNA_float_get(op->ptr, "fractal")/2.5; - int flag= 0; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; + int cuts = RNA_int_get(op->ptr,"number_cuts"); + float smooth = 0.292f * RNA_float_get(op->ptr, "smoothness"); + float fractal = RNA_float_get(op->ptr, "fractal")/2.5; + int flag = 0; if (smooth != 0.0f) flag |= B_SMOOTH; @@ -125,7 +125,7 @@ static int subdivide_exec(bContext *C, wmOperator *op) if (RNA_boolean_get(op->ptr, "quadtri") && RNA_enum_get(op->ptr, "quadcorner") == SUBD_STRAIGHT_CUT) { - RNA_enum_set(op->ptr, "quadcorner", SUBD_INNERVERT); + RNA_enum_set(op->ptr, "quadcorner", SUBD_INNERVERT); } BM_esubdivideflag(obedit, em->bm, BM_SELECT, @@ -153,16 +153,16 @@ static EnumPropertyItem prop_mesh_cornervert_types[] = { void MESH_OT_subdivide(wmOperatorType *ot) { /* identifiers */ - ot->name= "Subdivide"; - ot->description= "Subdivide selected edges"; - ot->idname= "MESH_OT_subdivide"; + ot->name = "Subdivide"; + ot->description = "Subdivide selected edges"; + ot->idname = "MESH_OT_subdivide"; /* api callbacks */ - ot->exec= subdivide_exec; - ot->poll= ED_operator_editmesh; + ot->exec = subdivide_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of Cuts", "", 1, 10); @@ -170,7 +170,8 @@ void MESH_OT_subdivide(wmOperatorType *ot) RNA_def_float(ot->srna, "smoothness", 0.0f, 0.0f, FLT_MAX, "Smoothness", "Smoothness factor (BMESH TODO)", 0.0f, 1.0f); RNA_def_boolean(ot->srna, "quadtri", 0, "Quad/Tri Mode", "Tries to prevent ngons"); - RNA_def_enum(ot->srna, "quadcorner", prop_mesh_cornervert_types, SUBD_STRAIGHT_CUT, "Quad Corner Type", "How to subdivide quad corners (anything other then Straight Cut will prevent ngons)"); + RNA_def_enum(ot->srna, "quadcorner", prop_mesh_cornervert_types, SUBD_STRAIGHT_CUT, + "Quad Corner Type", "How to subdivide quad corners (anything other then Straight Cut will prevent ngons)"); RNA_def_float(ot->srna, "fractal", 0.0f, 0.0f, FLT_MAX, "Fractal", "Fractal randomness factor", 0.0f, 1000.0f); RNA_def_int(ot->srna, "seed", 0, 0, 10000, "Random Seed", "Seed for the random number generator", 0, 50); @@ -208,7 +209,7 @@ static short EDBM_Extrude_face_indiv(BMEditMesh *em, wmOperator *op, const char EDBM_InitOpf(em, &bmop, op, "extrude_face_indiv faces=%hf", hflag); - /*deselect original verts*/ + /* deselect original verts */ EDBM_clear_flag_all(em, BM_SELECT); BMO_Exec_Op(em->bm, &bmop); @@ -216,7 +217,7 @@ static short EDBM_Extrude_face_indiv(BMEditMesh *em, wmOperator *op, const char BMO_ITER(f, &siter, em->bm, &bmop, "faceout", BM_FACE) { BM_Select(em->bm, f, TRUE); - /*set face vertex normals to face normal*/ + /* set face vertex normals to face normal */ BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, f) { copy_v3_v3(l->v->no, f->no); } @@ -236,7 +237,7 @@ static short EDBM_Extrude_edges_indiv(BMEditMesh *em, wmOperator *op, const char EDBM_InitOpf(em, &bmop, op, "extrude_edge_only edges=%he", hflag); - /*deselect original verts*/ + /* deselect original verts */ EDBM_clear_flag_all(em, BM_SELECT); BMO_Exec_Op(em->bm, &bmop); @@ -256,7 +257,7 @@ static short EDBM_Extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char EDBM_InitOpf(em, &bmop, op, "extrude_vert_indiv verts=%hv", hflag); - /*deselect original verts*/ + /* deselect original verts */ BMO_UnHeaderFlag_Buffer(em->bm, &bmop, "verts", BM_SELECT, BM_VERT); BMO_Exec_Op(em->bm, &bmop); @@ -269,7 +270,7 @@ static short EDBM_Extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char return 'g'; // g is grab } -static short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, float *nor) +static short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, float nor[3]) { BMesh *bm = em->bm; BMIter iter; @@ -288,9 +289,9 @@ static short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, * of the cases above to handle edges on the line of symmetry. */ md = obedit->modifiers.first; - for (; md; md=md->next) { - if ((md->type==eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) { - MirrorModifierData *mmd = (MirrorModifierData*) md; + for (; md; md = md->next) { + if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) { + MirrorModifierData *mmd = (MirrorModifierData *) md; if (mmd->flag & MOD_MIR_CLIPPING) { float mtx[4][4]; @@ -300,8 +301,9 @@ static short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, mult_m4_m4m4(mtx, imtx, obedit->obmat); } - for (edge=BMIter_New(&iter,bm,BM_EDGES_OF_MESH,NULL); - edge; edge=BMIter_Step(&iter)) + for (edge = BMIter_New(&iter, bm, BM_EDGES_OF_MESH, NULL); + edge; + edge = BMIter_Step(&iter)) { if (BM_TestHFlag(edge, hflag)) { float co1[3], co2[3]; @@ -314,20 +316,27 @@ static short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, mul_v3_m4v3(co2, mtx, co2); } - if (mmd->flag & MOD_MIR_AXIS_X) + if (mmd->flag & MOD_MIR_AXIS_X) { if ( (fabs(co1[0]) < mmd->tolerance) && (fabs(co2[0]) < mmd->tolerance) ) + { BMO_Insert_MapPointer(bm, &extop, "exclude", edge, NULL); - - if (mmd->flag & MOD_MIR_AXIS_Y) + } + } + if (mmd->flag & MOD_MIR_AXIS_Y) { if ( (fabs(co1[1]) < mmd->tolerance) && (fabs(co2[1]) < mmd->tolerance) ) + { BMO_Insert_MapPointer(bm, &extop, "exclude", edge, NULL); - - if (mmd->flag & MOD_MIR_AXIS_Z) + } + } + if (mmd->flag & MOD_MIR_AXIS_Z) { if ( (fabs(co1[2]) < mmd->tolerance) && (fabs(co2[2]) < mmd->tolerance) ) + { BMO_Insert_MapPointer(bm, &extop, "exclude", edge, NULL); + } + } } } } @@ -344,7 +353,7 @@ static short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, BM_Select(bm, el, TRUE); if (el->htype == BM_FACE) { - f = (BMFace*)el; + f = (BMFace *)el; add_normal_aligned(nor, f->no); }; } @@ -353,7 +362,7 @@ static short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, BMO_Finish_Op(bm, &extop); - if (nor[0]==0.0 && nor[1]==0.0 && nor[2]==0.0) return 'g'; // grab + if (nor[0] == 0.0f && nor[1] == 0.0f && nor[2] == 0.0f) return 'g'; // grab return 'n'; // normal constraint } @@ -362,9 +371,9 @@ static short EDBM_Extrude_vert(Object *obedit, BMEditMesh *em, const char hflag, BMIter iter; BMEdge *eed; - /*ensure vert flags are consistent for edge selections*/ + /* ensure vert flags are consistent for edge selections */ eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - for ( ; eed; eed=BMIter_Step(&iter)) { + for ( ; eed; eed = BMIter_Step(&iter)) { if (BM_TestHFlag(eed, hflag)) { if (hflag & BM_SELECT) { BM_Select(em->bm, eed->v1, TRUE); @@ -390,34 +399,29 @@ static short EDBM_Extrude_vert(Object *obedit, BMEditMesh *em, const char hflag, static int extrude_repeat_mesh(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; - RegionView3D *rv3d = CTX_wm_region_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); int steps = RNA_int_get(op->ptr,"steps"); float offs = RNA_float_get(op->ptr,"offset"); - float dvec[3], tmat[3][3], bmat[3][3], nor[3]= {0.0, 0.0, 0.0}; + float dvec[3], tmat[3][3], bmat[3][3], nor[3] = {0.0, 0.0, 0.0}; short a; /* dvec */ - dvec[0]= rv3d->persinv[2][0]; - dvec[1]= rv3d->persinv[2][1]; - dvec[2]= rv3d->persinv[2][2]; - normalize_v3(dvec); - dvec[0]*= offs; - dvec[1]*= offs; - dvec[2]*= offs; + normalize_v3_v3(dvec, rv3d->persinv[2]); + mul_v3_fl(dvec, offs); /* base correction */ copy_m3_m4(bmat, obedit->obmat); invert_m3_m3(tmat, bmat); mul_m3_v3(tmat, dvec); - for(a=0; a<steps; a++) { + for (a = 0; a < steps; a++) { EDBM_Extrude_edge(obedit, em, BM_SELECT, nor); //BMO_CallOpf(em->bm, "extrudefaceregion edgefacein=%hef", BM_SELECT); - BMO_CallOpf(em->bm, "translate vec=%v verts=%hv", (float*)dvec, BM_SELECT); + BMO_CallOpf(em->bm, "translate vec=%v verts=%hv", (float *)dvec, BM_SELECT); //extrudeflag(obedit, em, SELECT, nor); //translateflag(em, SELECT, dvec); } @@ -433,16 +437,16 @@ static int extrude_repeat_mesh(bContext *C, wmOperator *op) void MESH_OT_extrude_repeat(wmOperatorType *ot) { /* identifiers */ - ot->name= "Extrude Repeat Mesh"; - ot->description= "Extrude selected vertices, edges or faces repeatedly"; - ot->idname= "MESH_OT_extrude_repeat"; + ot->name = "Extrude Repeat Mesh"; + ot->description = "Extrude selected vertices, edges or faces repeatedly"; + ot->idname = "MESH_OT_extrude_repeat"; /* api callbacks */ - ot->exec= extrude_repeat_mesh; - ot->poll= ED_operator_editmesh; + ot->exec = extrude_repeat_mesh; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_float(ot->srna, "offset", 2.0f, 0.0f, 100.0f, "Offset", "", 0.0f, FLT_MAX); @@ -452,52 +456,52 @@ void MESH_OT_extrude_repeat(wmOperatorType *ot) /* generic extern called extruder */ static int EDBM_Extrude_Mesh(Scene *scene, Object *obedit, BMEditMesh *em, wmOperator *op, float *norin) { - short nr, transmode= 0; + short nr, transmode = 0; float stacknor[3] = {0.0f, 0.0f, 0.0f}; float *nor = norin ? norin : stacknor; nor[0] = nor[1] = nor[2] = 0.0f; if (em->selectmode & SCE_SELECT_VERTEX) { - if (em->bm->totvertsel==0) nr= 0; - else if (em->bm->totvertsel==1) nr= 4; - else if (em->bm->totedgesel==0) nr= 4; - else if (em->bm->totfacesel==0) - nr= 3; // pupmenu("Extrude %t|Only Edges%x3|Only Vertices%x4"); - else if (em->bm->totfacesel==1) - nr= 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3|Only Vertices%x4"); + if (em->bm->totvertsel == 0) nr = 0; + else if (em->bm->totvertsel == 1) nr = 4; + else if (em->bm->totedgesel == 0) nr = 4; + else if (em->bm->totfacesel == 0) + nr = 3; // pupmenu("Extrude %t|Only Edges%x3|Only Vertices%x4"); + else if (em->bm->totfacesel == 1) + nr = 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3|Only Vertices%x4"); else - nr= 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3|Only Vertices%x4"); + nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3|Only Vertices%x4"); } else if (em->selectmode & SCE_SELECT_EDGE) { - if (em->bm->totedgesel==0) nr = 0; + if (em->bm->totedgesel == 0) nr = 0; nr = 1; - /*else if (em->totedgesel==1) nr = 3; - else if (em->totfacesel==0) nr = 3; - else if (em->totfacesel==1) - nr= 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3"); + /* else if (em->totedgesel == 1) nr = 3; + else if (em->totfacesel == 0) nr = 3; + else if (em->totfacesel == 1) + nr = 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3"); else - nr= 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3"); + nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3"); */ } else { if (em->bm->totfacesel == 0) nr = 0; else if (em->bm->totfacesel == 1) nr = 1; else - nr= 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2"); + nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2"); } - if (nr<1) return 'g'; + if (nr < 1) return 'g'; - if (nr==1 && em->selectmode & SCE_SELECT_VERTEX) - transmode= EDBM_Extrude_vert(obedit, em, BM_SELECT, nor); - else if (nr == 1) transmode= EDBM_Extrude_edge(obedit, em, BM_SELECT, nor); - else if (nr==4) transmode= EDBM_Extrude_verts_indiv(em, op, BM_SELECT, nor); - else if (nr==3) transmode= EDBM_Extrude_edges_indiv(em, op, BM_SELECT, nor); - else transmode= EDBM_Extrude_face_indiv(em, op, BM_SELECT, nor); + if (nr == 1 && em->selectmode & SCE_SELECT_VERTEX) + transmode = EDBM_Extrude_vert(obedit, em, BM_SELECT, nor); + else if (nr == 1) transmode = EDBM_Extrude_edge(obedit, em, BM_SELECT, nor); + else if (nr == 4) transmode = EDBM_Extrude_verts_indiv(em, op, BM_SELECT, nor); + else if (nr == 3) transmode = EDBM_Extrude_edges_indiv(em, op, BM_SELECT, nor); + else transmode = EDBM_Extrude_face_indiv(em, op, BM_SELECT, nor); - if (transmode==0) { + if (transmode == 0) { BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude"); } else { @@ -508,18 +512,18 @@ static int EDBM_Extrude_Mesh(Scene *scene, Object *obedit, BMEditMesh *em, wmOpe * This shouldn't be necessary, derived queries should be * automatically building this data if invalid. Or something. */ -// DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); +// DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); object_handle_update(scene, obedit); /* individual faces? */ // BIF_TransformSetUndo("Extrude"); - if (nr==2) { + if (nr == 2) { // initTransform(TFM_SHRINKFATTEN, CTX_NO_PET|CTX_NO_MIRROR); // Transform(); } else { // initTransform(TFM_TRANSLATION, CTX_NO_PET|CTX_NO_MIRROR); - if (transmode=='n') { + if (transmode == 'n') { mul_m4_v3(obedit->obmat, nor); sub_v3_v3v3(nor, nor, obedit->obmat[3]); // BIF_setSingleAxisConstraint(nor, "along normal"); @@ -535,64 +539,64 @@ static int EDBM_Extrude_Mesh(Scene *scene, Object *obedit, BMEditMesh *em, wmOpe static int mesh_extrude_region_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; EDBM_Extrude_Mesh(scene, obedit, em, op, NULL); - /*This normally happens when pushing undo but modal operators - like this one don't push undo data until after modal mode is - done.*/ + /* This normally happens when pushing undo but modal operators + * like this one don't push undo data until after modal mode is + * done.*/ EDBM_RecalcNormals(em); BMEdit_RecalcTesselation(em); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_extrude_region(wmOperatorType *ot) { /* identifiers */ - ot->name= "Extrude Region"; - ot->idname= "MESH_OT_extrude_region"; + ot->name = "Extrude Region"; + ot->idname = "MESH_OT_extrude_region"; /* api callbacks */ - //ot->invoke= mesh_extrude_region_invoke; - ot->exec= mesh_extrude_region_exec; - ot->poll= ED_operator_editmesh; + //ot->invoke = mesh_extrude_region_invoke; + ot->exec = mesh_extrude_region_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); } static int mesh_extrude_verts_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; float nor[3]; EDBM_Extrude_verts_indiv(em, op, BM_SELECT, nor); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_extrude_verts_indiv(wmOperatorType *ot) { /* identifiers */ - ot->name= "Extrude Only Vertices"; - ot->idname= "MESH_OT_extrude_verts_indiv"; + ot->name = "Extrude Only Vertices"; + ot->idname = "MESH_OT_extrude_verts_indiv"; /* api callbacks */ - ot->exec= mesh_extrude_verts_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_extrude_verts_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* to give to transform */ RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); @@ -600,29 +604,29 @@ void MESH_OT_extrude_verts_indiv(wmOperatorType *ot) static int mesh_extrude_edges_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; float nor[3]; EDBM_Extrude_edges_indiv(em, op, BM_SELECT, nor); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_extrude_edges_indiv(wmOperatorType *ot) { /* identifiers */ - ot->name= "Extrude Only Edges"; - ot->idname= "MESH_OT_extrude_edges_indiv"; + ot->name = "Extrude Only Edges"; + ot->idname = "MESH_OT_extrude_edges_indiv"; /* api callbacks */ - ot->exec= mesh_extrude_edges_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_extrude_edges_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* to give to transform */ RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); @@ -630,29 +634,29 @@ void MESH_OT_extrude_edges_indiv(wmOperatorType *ot) static int mesh_extrude_faces_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; float nor[3]; EDBM_Extrude_face_indiv(em, op, BM_SELECT, nor); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_extrude_faces_indiv(wmOperatorType *ot) { /* identifiers */ - ot->name= "Extrude Individual Faces"; - ot->idname= "MESH_OT_extrude_faces_indiv"; + ot->name = "Extrude Individual Faces"; + ot->idname = "MESH_OT_extrude_faces_indiv"; /* api callbacks */ - ot->exec= mesh_extrude_faces_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_extrude_faces_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); } @@ -669,8 +673,8 @@ void EDBM_toggle_select_all(BMEditMesh *em) /* exported for UV */ static int mesh_select_all_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; int action = RNA_enum_get(op->ptr, "action"); switch (action) { @@ -696,16 +700,16 @@ static int mesh_select_all_exec(bContext *C, wmOperator *op) void MESH_OT_select_all(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select/Deselect All"; - ot->idname= "MESH_OT_select_all"; - ot->description= "(de)select all vertices, edges or faces"; + ot->name = "Select/Deselect All"; + ot->idname = "MESH_OT_select_all"; + ot->description = "(de)select all vertices, edges or faces"; /* api callbacks */ - ot->exec= mesh_select_all_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_select_all_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; WM_operator_properties_select_all(ot); } @@ -718,37 +722,37 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) BMVert *v1; BMIter iter; float min[3], max[3]; - int done= 0; + int done = 0; short use_proj; em_setup_viewcontext(C, &vc); - use_proj= (vc.scene->toolsettings->snap_flag & SCE_SNAP) && (vc.scene->toolsettings->snap_mode==SCE_SNAP_MODE_FACE); + use_proj = (vc.scene->toolsettings->snap_flag & SCE_SNAP) && (vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE); INIT_MINMAX(min, max); BM_ITER(v1, &iter, vc.em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_TestHFlag(v1, BM_SELECT)) { DO_MINMAX(v1->co, min, max); - done= 1; + done = 1; } } /* call extrude? */ if (done) { - const short rot_src= RNA_boolean_get(op->ptr, "rotate_source"); + const short rot_src = RNA_boolean_get(op->ptr, "rotate_source"); BMEdge *eed; float vec[3], cent[3], mat[3][3]; - float nor[3]= {0.0, 0.0, 0.0}; + float nor[3] = {0.0, 0.0, 0.0}; /* 2D normal calc */ float mval_f[2]; - mval_f[0]= (float)event->mval[0]; - mval_f[1]= (float)event->mval[1]; + mval_f[0] = (float)event->mval[0]; + mval_f[1] = (float)event->mval[1]; /* check for edges that are half selected, use for rotation */ - done= 0; + done = 0; BM_ITER(eed, &iter, vc.em->bm, BM_EDGES_OF_MESH, NULL) { if (BM_TestHFlag(eed, BM_SELECT)) { float co1[3], co2[3]; @@ -771,7 +775,7 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) nor[1] += -(co2[0] - co1[0]); } } - done= 1; + done = 1; } if (done) { @@ -806,24 +810,24 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) copy_v3_v3(vec, min); normalize_v3(vec); - dot= dot_v3v3(vec, nor); + dot = dot_v3v3(vec, nor); - if ( fabs(dot)<0.999) { + if (fabsf(dot) < 0.999f) { float cross[3], si, q1[4]; cross_v3_v3v3(cross, nor, vec); normalize_v3(cross); - dot= 0.5f*saacos(dot); + dot = 0.5f * saacos(dot); /* halve the rotation if its applied twice */ if (rot_src) dot *= 0.5f; - si= (float)sin(dot); - q1[0]= (float)cos(dot); - q1[1]= cross[0]*si; - q1[2]= cross[1]*si; - q1[3]= cross[2]*si; - quat_to_mat3( mat,q1); + si = sinf(dot); + q1[0] = cosf(dot); + q1[1] = cross[0] * si; + q1[2] = cross[1] * si; + q1[3] = cross[2] * si; + quat_to_mat3(mat, q1); } } @@ -843,14 +847,14 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) BM_SELECT, min); } else { - float *curs= give_cursor(vc.scene, vc.v3d); + float *curs = give_cursor(vc.scene, vc.v3d); BMOperator bmop; BMOIter oiter; copy_v3_v3(min, curs); view3d_get_view_aligned_coordinate(&vc, min, event->mval, 0); - invert_m4_m4(vc.obedit->imat, vc.obedit->obmat); + invert_m4_m4(vc.obedit->imat, vc.obedit->obmat); mul_m4_v3(vc.obedit->imat, min); // back in object space EDBM_InitOpf(vc.em, &bmop, op, "makevert co=%v", min); @@ -868,13 +872,13 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) if (use_proj) EMBM_project_snap_verts(C, vc.ar, vc.obedit, vc.em); - /*This normally happens when pushing undo but modal operators - like this one don't push undo data until after modal mode is - done.*/ + /* This normally happens when pushing undo but modal operators + * like this one don't push undo data until after modal mode is + * done. */ EDBM_RecalcNormals(vc.em); BMEdit_RecalcTesselation(vc.em); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, vc.obedit->data); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, vc.obedit->data); DAG_id_tag_update(vc.obedit->data, OB_RECALC_DATA); return OPERATOR_FINISHED; @@ -883,38 +887,38 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot) { /* identifiers */ - ot->name= "Duplicate or Extrude at 3D Cursor"; - ot->idname= "MESH_OT_dupli_extrude_cursor"; + ot->name = "Duplicate or Extrude at 3D Cursor"; + ot->idname = "MESH_OT_dupli_extrude_cursor"; /* api callbacks */ - ot->invoke= dupli_extrude_cursor; - ot->description= "Duplicate and extrude selected vertices, edges or faces towards the mouse cursor"; - ot->poll= ED_operator_editmesh; + ot->invoke = dupli_extrude_cursor; + ot->description = "Duplicate and extrude selected vertices, edges or faces towards the mouse cursor"; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "rotate_source", 1, "Rotate Source", "Rotate initial selection giving better shape"); } static int delete_mesh(bContext *C, Object *obedit, wmOperator *op, int event, Scene *UNUSED(scene)) { - BMEditMesh *bem = ((Mesh*)obedit->data)->edit_btmesh; + BMEditMesh *bem = ((Mesh *)obedit->data)->edit_btmesh; - if (event<1) return OPERATOR_CANCELLED; + if (event < 1) return OPERATOR_CANCELLED; - if (event==10 ) { + if (event == 10) { //"Erase Vertices"; if (!EDBM_CallOpf(bem, op, "del geom=%hv context=%i", BM_SELECT, DEL_VERTS)) return OPERATOR_CANCELLED; } - else if (event==11) { + else if (event == 11) { //"Edge Loop" if (!EDBM_CallOpf(bem, op, "dissolveedgeloop edges=%he", BM_SELECT)) return OPERATOR_CANCELLED; } - else if (event==7) { + else if (event == 7) { int use_verts = RNA_boolean_get(op->ptr, "use_verts"); //"Dissolve" if (bem->selectmode & SCE_SELECT_FACE) { @@ -926,26 +930,26 @@ static int delete_mesh(bContext *C, Object *obedit, wmOperator *op, int event, S return OPERATOR_CANCELLED; } else if (bem->selectmode & SCE_SELECT_VERTEX) { - if (!EDBM_CallOpf(bem, op, "dissolveverts verts=%hv",BM_SELECT)) + if (!EDBM_CallOpf(bem, op, "dissolveverts verts=%hv", BM_SELECT)) return OPERATOR_CANCELLED; } } - else if (event==4) { + else if (event == 4) { //Edges and Faces if (!EDBM_CallOpf(bem, op, "del geom=%hef context=%i", BM_SELECT, DEL_EDGESFACES)) return OPERATOR_CANCELLED; } - else if (event==1) { + else if (event == 1) { //"Erase Edges" if (!EDBM_CallOpf(bem, op, "del geom=%he context=%i", BM_SELECT, DEL_EDGES)) return OPERATOR_CANCELLED; } - else if (event==2) { + else if (event == 2) { //"Erase Faces"; if (!EDBM_CallOpf(bem, op, "del geom=%hf context=%i", BM_SELECT, DEL_FACES)) return OPERATOR_CANCELLED; } - else if (event==5) { + else if (event == 5) { //"Erase Only Faces"; if (!EDBM_CallOpf(bem, op, "del geom=%hf context=%d", BM_SELECT, DEL_ONLYFACES)) @@ -973,8 +977,8 @@ static EnumPropertyItem prop_mesh_delete_types[] = { static int delete_mesh_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; Scene *scene = CTX_data_scene(C); int type = RNA_enum_get(op->ptr, "type"); @@ -997,20 +1001,20 @@ static int delete_mesh_exec(bContext *C, wmOperator *op) void MESH_OT_delete(wmOperatorType *ot) { /* identifiers */ - ot->name= "Delete"; - ot->description= "Delete selected vertices, edges or faces"; - ot->idname= "MESH_OT_delete"; + ot->name = "Delete"; + ot->description = "Delete selected vertices, edges or faces"; + ot->idname = "MESH_OT_delete"; /* api callbacks */ - ot->invoke= WM_menu_invoke; - ot->exec= delete_mesh_exec; + ot->invoke = WM_menu_invoke; + ot->exec = delete_mesh_exec; - ot->poll= ED_operator_editmesh; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; - /*props */ + /* props */ ot->prop = RNA_def_enum(ot->srna, "type", prop_mesh_delete_types, 10, "Type", "Method used for deleting mesh data"); /* TODO, move dissolve into its own operator so this doesnt confuse non-dissolve options */ @@ -1022,8 +1026,8 @@ void MESH_OT_delete(wmOperatorType *ot) static int addedgeface_mesh_exec(bContext *C, wmOperator *op) { BMOperator bmop; - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; if (!EDBM_InitOpf(em, &bmop, op, "contextual_create geom=%hfev", BM_SELECT)) return OPERATOR_CANCELLED; @@ -1044,32 +1048,32 @@ static int addedgeface_mesh_exec(bContext *C, wmOperator *op) void MESH_OT_edge_face_add(wmOperatorType *ot) { /* identifiers */ - ot->name= "Make Edge/Face"; - ot->description= "Add an edge or face to selected"; - ot->idname= "MESH_OT_edge_face_add"; + ot->name = "Make Edge/Face"; + ot->description = "Add an edge or face to selected"; + ot->idname = "MESH_OT_edge_face_add"; /* api callbacks */ - ot->exec= addedgeface_mesh_exec; - ot->poll= ED_operator_editmesh; + ot->exec = addedgeface_mesh_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } /* ************************* SEAMS AND EDGES **************** */ static int editbmesh_mark_seam(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - Mesh *me= ((Mesh *)obedit->data); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + Mesh *me = ((Mesh *)obedit->data); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMesh *bm = em->bm; BMEdge *eed; BMIter iter; int clear = RNA_boolean_get(op->ptr, "clear"); /* auto-enable seams drawing */ - if (clear==0) { + if (clear == 0) { me->drawflag |= ME_DRAWSEAMS; } @@ -1098,25 +1102,25 @@ static int editbmesh_mark_seam(bContext *C, wmOperator *op) void MESH_OT_mark_seam(wmOperatorType *ot) { /* identifiers */ - ot->name= "Mark Seam"; - ot->idname= "MESH_OT_mark_seam"; - ot->description= "(un)mark selected edges as a seam"; + ot->name = "Mark Seam"; + ot->idname = "MESH_OT_mark_seam"; + ot->description = "(un)mark selected edges as a seam"; /* api callbacks */ - ot->exec= editbmesh_mark_seam; - ot->poll= ED_operator_editmesh; + ot->exec = editbmesh_mark_seam; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "clear", 0, "Clear", ""); } static int editbmesh_mark_sharp(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - Mesh *me= ((Mesh *)obedit->data); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + Mesh *me = ((Mesh *)obedit->data); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMesh *bm = em->bm; BMEdge *eed; BMIter iter; @@ -1154,16 +1158,16 @@ static int editbmesh_mark_sharp(bContext *C, wmOperator *op) void MESH_OT_mark_sharp(wmOperatorType *ot) { /* identifiers */ - ot->name= "Mark Sharp"; - ot->idname= "MESH_OT_mark_sharp"; - ot->description= "(un)mark selected edges as sharp"; + ot->name = "Mark Sharp"; + ot->idname = "MESH_OT_mark_sharp"; + ot->description = "(un)mark selected edges as sharp"; /* api callbacks */ - ot->exec= editbmesh_mark_sharp; - ot->poll= ED_operator_editmesh; + ot->exec = editbmesh_mark_sharp; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "clear", 0, "Clear", ""); } @@ -1171,8 +1175,8 @@ void MESH_OT_mark_sharp(wmOperatorType *ot) static int editbmesh_vert_connect(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMesh *bm = em->bm; BMOperator bmop; int len = 0; @@ -1195,21 +1199,21 @@ static int editbmesh_vert_connect(bContext *C, wmOperator *op) void MESH_OT_vert_connect(wmOperatorType *ot) { /* identifiers */ - ot->name= "Vertex Connect"; - ot->idname= "MESH_OT_vert_connect"; + ot->name = "Vertex Connect"; + ot->idname = "MESH_OT_vert_connect"; /* api callbacks */ - ot->exec= editbmesh_vert_connect; - ot->poll= ED_operator_editmesh; + ot->exec = editbmesh_vert_connect; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int editbmesh_edge_split(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMesh *bm = em->bm; BMOperator bmop; int len = 0; @@ -1233,15 +1237,15 @@ static int editbmesh_edge_split(bContext *C, wmOperator *op) void MESH_OT_edge_split(wmOperatorType *ot) { /* identifiers */ - ot->name= "Edge Split"; - ot->idname= "MESH_OT_edge_split"; + ot->name = "Edge Split"; + ot->idname = "MESH_OT_edge_split"; /* api callbacks */ - ot->exec= editbmesh_edge_split; - ot->poll= ED_operator_editmesh; + ot->exec = editbmesh_edge_split; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_int(ot->srna, "number_cuts", 1, 1, 10, "Number of Cuts", "", 1, INT_MAX); } @@ -1250,8 +1254,8 @@ void MESH_OT_edge_split(wmOperatorType *ot) static int mesh_duplicate_exec(bContext *C, wmOperator *op) { - Object *ob= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh*)ob->data)->edit_btmesh; + Object *ob = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; EDBM_InitOpf(em, &bmop, op, "dupe geom=%hvef", BM_SELECT); @@ -1283,15 +1287,15 @@ static int mesh_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(ev void MESH_OT_duplicate(wmOperatorType *ot) { /* identifiers */ - ot->name= "Duplicate"; - ot->description= "Duplicate selected vertices, edges or faces"; - ot->idname= "MESH_OT_duplicate"; + ot->name = "Duplicate"; + ot->description = "Duplicate selected vertices, edges or faces"; + ot->idname = "MESH_OT_duplicate"; /* api callbacks */ - ot->invoke= mesh_duplicate_invoke; - ot->exec= mesh_duplicate_exec; + ot->invoke = mesh_duplicate_invoke; + ot->exec = mesh_duplicate_exec; - ot->poll= ED_operator_editmesh; + ot->poll = ED_operator_editmesh; /* to give to transform */ RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX); @@ -1299,8 +1303,8 @@ void MESH_OT_duplicate(wmOperatorType *ot) static int flip_normals(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; if (!EDBM_CallOpf(em, op, "reversefaces faces=%hf", BM_SELECT)) return OPERATOR_CANCELLED; @@ -1314,16 +1318,16 @@ static int flip_normals(bContext *C, wmOperator *op) void MESH_OT_flip_normals(wmOperatorType *ot) { /* identifiers */ - ot->name= "Flip Normals"; - ot->description= "Flip the direction of selected face's vertex and face normals"; - ot->idname= "MESH_OT_flip_normals"; + ot->name = "Flip Normals"; + ot->description = "Flip the direction of selected face's vertex and face normals"; + ot->idname = "MESH_OT_flip_normals"; /* api callbacks */ - ot->exec= flip_normals; - ot->poll= ED_operator_editmesh; + ot->exec = flip_normals; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } float *bm_get_cd_float(CustomData *cdata, void *data, int type) @@ -1333,7 +1337,7 @@ float *bm_get_cd_float(CustomData *cdata, void *data, int type) return f; } -static const EnumPropertyItem direction_items[]= { +static const EnumPropertyItem direction_items[] = { {DIRECTION_CW, "CW", 0, "Clockwise", ""}, {DIRECTION_CCW, "CCW", 0, "Counter Clockwise", ""}, {0, NULL, 0, NULL, NULL}}; @@ -1341,20 +1345,20 @@ static const EnumPropertyItem direction_items[]= { /* only accepts 1 selected edge, or 2 selected faces */ static int edge_rotate_selected(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMOperator bmop; BMEdge *eed; BMIter iter; const int do_ccw = RNA_enum_get(op->ptr, "direction") == 1; - int do_deselect= FALSE; /* do we deselect */ + int do_deselect = FALSE; /* do we deselect */ if (!(em->bm->totfacesel == 2 || em->bm->totedgesel == 1)) { BKE_report(op->reports, RPT_ERROR, "Select one edge or two adjacent faces"); return OPERATOR_CANCELLED; } - /*first see if we have two adjacent faces*/ + /* first see if we have two adjacent faces */ BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { if (BM_Edge_FaceCount(eed) == 2) { if ((BM_TestHFlag(eed->l->f, BM_SELECT) && BM_TestHFlag(eed->l->radial_next->f, BM_SELECT)) @@ -1365,8 +1369,8 @@ static int edge_rotate_selected(bContext *C, wmOperator *op) } } - /*ok, we don't have two adjacent faces, but we do have two selected ones. - that's an error condition.*/ + /* ok, we don't have two adjacent faces, but we do have two selected ones. + * that's an error condition.*/ if (!eed && em->bm->totfacesel == 2) { BKE_report(op->reports, RPT_ERROR, "Select one edge or two adjacent faces"); return OPERATOR_CANCELLED; @@ -1382,7 +1386,7 @@ static int edge_rotate_selected(bContext *C, wmOperator *op) } } - /*this should never happen*/ + /* this should never happen */ if (!eed) return OPERATOR_CANCELLED; @@ -1409,16 +1413,16 @@ static int edge_rotate_selected(bContext *C, wmOperator *op) void MESH_OT_edge_rotate(wmOperatorType *ot) { /* identifiers */ - ot->name= "Rotate Selected Edge"; - ot->description= "Rotate selected edge or adjoining faces"; - ot->idname= "MESH_OT_edge_rotate"; + ot->name = "Rotate Selected Edge"; + ot->description = "Rotate selected edge or adjoining faces"; + ot->idname = "MESH_OT_edge_rotate"; /* api callbacks */ - ot->exec= edge_rotate_selected; - ot->poll= ED_operator_editmesh; + ot->exec = edge_rotate_selected; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "direction", "direction to rotate edge around"); @@ -1431,7 +1435,7 @@ void EDBM_hide_mesh(BMEditMesh *em, int swap) BMHeader *h; int itermode; - if (em==NULL) return; + if (em == NULL) return; if (em->selectmode & SCE_SELECT_VERTEX) itermode = BM_VERTS_OF_MESH; @@ -1447,8 +1451,8 @@ void EDBM_hide_mesh(BMEditMesh *em, int swap) EDBM_selectmode_flush(em); - /*original hide flushing comment (OUTDATED): - hide happens on least dominant select mode, and flushes up, not down! (helps preventing errors in subsurf) */ + /* original hide flushing comment (OUTDATED): + * hide happens on least dominant select mode, and flushes up, not down! (helps preventing errors in subsurf) */ /* - vertex hidden, always means edge is hidden too - edge hidden, always means face is hidden too - face hidden, only set face hide @@ -1459,30 +1463,30 @@ void EDBM_hide_mesh(BMEditMesh *em, int swap) static int hide_mesh_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; EDBM_hide_mesh(em, RNA_boolean_get(op->ptr, "unselected")); DAG_id_tag_update(obedit->data, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_hide(wmOperatorType *ot) { /* identifiers */ - ot->name= "Hide Selection"; - ot->idname= "MESH_OT_hide"; + ot->name = "Hide Selection"; + ot->idname = "MESH_OT_hide"; /* api callbacks */ - ot->exec= hide_mesh_exec; - ot->poll= ED_operator_editmesh; - ot->description= "Hide (un)selected vertices, edges or faces"; + ot->exec = hide_mesh_exec; + ot->poll = ED_operator_editmesh; + ot->description = "Hide (un)selected vertices, edges or faces"; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected"); @@ -1537,39 +1541,39 @@ void EDBM_reveal_mesh(BMEditMesh *em) static int reveal_mesh_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; EDBM_reveal_mesh(em); DAG_id_tag_update(obedit->data, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_reveal(wmOperatorType *ot) { /* identifiers */ - ot->name= "Reveal Hidden"; - ot->idname= "MESH_OT_reveal"; - ot->description= "Reveal all hidden vertices, edges and faces"; + ot->name = "Reveal Hidden"; + ot->idname = "MESH_OT_reveal"; + ot->description = "Reveal all hidden vertices, edges and faces"; /* api callbacks */ - ot->exec= reveal_mesh_exec; - ot->poll= ED_operator_editmesh; + ot->exec = reveal_mesh_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int normals_make_consistent_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; /* doflip has to do with bmesh_rationalize_normals, it's an internal - * thing*/ + * thing */ if (!EDBM_CallOpf(em, op, "righthandfaces faces=%hf doflip=%d", BM_SELECT, 1)) return OPERATOR_CANCELLED; @@ -1579,22 +1583,22 @@ static int normals_make_consistent_exec(bContext *C, wmOperator *op) DAG_id_tag_update(obedit->data, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_normals_make_consistent(wmOperatorType *ot) { /* identifiers */ - ot->name= "Make Normals Consistent"; - ot->description= "Make face and vertex normals point either outside or inside the mesh"; - ot->idname= "MESH_OT_normals_make_consistent"; + ot->name = "Make Normals Consistent"; + ot->description = "Make face and vertex normals point either outside or inside the mesh"; + ot->idname = "MESH_OT_normals_make_consistent"; /* api callbacks */ - ot->exec= normals_make_consistent_exec; - ot->poll= ED_operator_editmesh; + ot->exec = normals_make_consistent_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "inside", 0, "Inside", ""); } @@ -1603,10 +1607,10 @@ void MESH_OT_normals_make_consistent(wmOperatorType *ot) static int do_smooth_vertex(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; ModifierData *md; - int mirrx=0, mirry=0, mirrz=0; + int mirrx = 0, mirry = 0, mirrz = 0; int i, repeat; float clipdist = 0.0f; @@ -1618,9 +1622,9 @@ static int do_smooth_vertex(bContext *C, wmOperator *op) /* if there is a mirror modifier with clipping, flag the verts that * are within tolerance of the plane(s) of reflection */ - for(md=obedit->modifiers.first; md; md=md->next) { - if (md->type==eModifierType_Mirror && (md->mode & eModifierMode_Realtime)) { - MirrorModifierData *mmd = (MirrorModifierData*) md; + for (md = obedit->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Mirror && (md->mode & eModifierMode_Realtime)) { + MirrorModifierData *mmd = (MirrorModifierData *)md; if (mmd->flag & MOD_MIR_CLIPPING) { if (mmd->flag & MOD_MIR_AXIS_X) @@ -1639,7 +1643,7 @@ static int do_smooth_vertex(bContext *C, wmOperator *op) if (!repeat) repeat = 1; - for (i=0; i<repeat; i++) { + for (i = 0; i < repeat; i++) { if (!EDBM_CallOpf(em, op, "vertexsmooth verts=%hv mirror_clip_x=%d mirror_clip_y=%d mirror_clip_z=%d clipdist=%f", BM_SELECT, mirrx, mirry, mirrz, clipdist)) @@ -1663,16 +1667,16 @@ static int do_smooth_vertex(bContext *C, wmOperator *op) void MESH_OT_vertices_smooth(wmOperatorType *ot) { /* identifiers */ - ot->name= "Smooth Vertex"; - ot->description= "Flatten angles of selected vertices"; - ot->idname= "MESH_OT_vertices_smooth"; + ot->name = "Smooth Vertex"; + ot->description = "Flatten angles of selected vertices"; + ot->idname = "MESH_OT_vertices_smooth"; /* api callbacks */ - ot->exec= do_smooth_vertex; - ot->poll= ED_operator_editmesh; + ot->exec = do_smooth_vertex; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Number of times to smooth the mesh", "", 1, INT_MAX); } @@ -1680,15 +1684,15 @@ void MESH_OT_vertices_smooth(wmOperatorType *ot) static int bm_test_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMBVHTree *tree = BMBVH_NewBVH(em, 0, NULL, NULL); BMIter iter; BMEdge *e; - /*hide all back edges*/ + /* hide all back edges */ BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { if (!BM_TestHFlag(e, BM_SELECT)) continue; @@ -1705,7 +1709,7 @@ static int bm_test_exec(bContext *C, wmOperator *UNUSED(op)) BMLoop *l, *l2; MLoopUV *luv; BMWalker walker; - int i=0; + int i = 0; BM_ITER(f, &iter, em->bm, BM_FACES_OF_MESH, NULL) { BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, f) { @@ -1720,7 +1724,7 @@ static int bm_test_exec(bContext *C, wmOperator *UNUSED(op)) luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); if (luv->flag & MLOOPUV_VERTSEL) { l2 = BMW_Begin(&walker, l); - for (; l2; l2=BMW_Step(&walker)) { + for (; l2; l2 = BMW_Step(&walker)) { luv = CustomData_bmesh_get(&em->bm->ldata, l2->head.data, CD_MLOOPUV); luv->flag |= MLOOPUV_VERTSEL; } @@ -1739,15 +1743,15 @@ static int bm_test_exec(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_bm_test(wmOperatorType *ot) { /* identifiers */ - ot->name= "BMesh Test Operator"; - ot->idname= "MESH_OT_bm_test"; + ot->name = "BMesh Test Operator"; + ot->idname = "MESH_OT_bm_test"; /* api callbacks */ - ot->exec= bm_test_exec; - ot->poll= ED_operator_editmesh; + ot->exec = bm_test_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; //RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Number of times to smooth the mesh", "", 1, INT_MAX); } @@ -1759,7 +1763,7 @@ static void mesh_set_smooth_faces(BMEditMesh *em, short smooth) BMIter iter; BMFace *efa; - if (em==NULL) return; + if (em == NULL) return; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (BM_TestHFlag(efa, BM_SELECT)) { @@ -1773,8 +1777,8 @@ static void mesh_set_smooth_faces(BMEditMesh *em, short smooth) static int mesh_faces_shade_smooth_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; mesh_set_smooth_faces(em, 1); @@ -1787,22 +1791,22 @@ static int mesh_faces_shade_smooth_exec(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_faces_shade_smooth(wmOperatorType *ot) { /* identifiers */ - ot->name= "Shade Smooth"; - ot->description= "Display faces smooth (using vertex normals)"; - ot->idname= "MESH_OT_faces_shade_smooth"; + ot->name = "Shade Smooth"; + ot->description = "Display faces smooth (using vertex normals)"; + ot->idname = "MESH_OT_faces_shade_smooth"; /* api callbacks */ - ot->exec= mesh_faces_shade_smooth_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_faces_shade_smooth_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int mesh_faces_shade_flat_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; mesh_set_smooth_faces(em, 0); @@ -1815,23 +1819,23 @@ static int mesh_faces_shade_flat_exec(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_faces_shade_flat(wmOperatorType *ot) { /* identifiers */ - ot->name= "Shade Flat"; - ot->description= "Display faces flat"; - ot->idname= "MESH_OT_faces_shade_flat"; + ot->name = "Shade Flat"; + ot->description = "Display faces flat"; + ot->idname = "MESH_OT_faces_shade_flat"; /* api callbacks */ - ot->exec= mesh_faces_shade_flat_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_faces_shade_flat_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } /********************** UV/Color Operators *************************/ -static const EnumPropertyItem axis_items[]= { +static const EnumPropertyItem axis_items[] = { {OPUVC_AXIS_X, "X", 0, "X", ""}, {OPUVC_AXIS_Y, "Y", 0, "Y", ""}, {0, NULL, 0, NULL, NULL}}; @@ -1839,7 +1843,7 @@ static const EnumPropertyItem axis_items[]= { static int mesh_rotate_uvs(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; /* get the direction from RNA */ @@ -1867,7 +1871,7 @@ static int mesh_rotate_uvs(bContext *C, wmOperator *op) static int mesh_reverse_uvs(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ @@ -1892,7 +1896,7 @@ static int mesh_reverse_uvs(bContext *C, wmOperator *op) static int mesh_rotate_colors(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; /* get the direction from RNA */ @@ -1923,7 +1927,7 @@ static int mesh_rotate_colors(bContext *C, wmOperator *op) static int mesh_reverse_colors(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ @@ -1947,15 +1951,15 @@ static int mesh_reverse_colors(bContext *C, wmOperator *op) void MESH_OT_uvs_rotate(wmOperatorType *ot) { /* identifiers */ - ot->name= "Rotate UVs"; - ot->idname= "MESH_OT_uvs_rotate"; + ot->name = "Rotate UVs"; + ot->idname = "MESH_OT_uvs_rotate"; /* api callbacks */ - ot->exec= mesh_rotate_uvs; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_rotate_uvs; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "Direction", "Direction to rotate UVs around"); @@ -1965,15 +1969,15 @@ void MESH_OT_uvs_rotate(wmOperatorType *ot) void MESH_OT_uvs_reverse(wmOperatorType *ot) { /* identifiers */ - ot->name= "Reverse UVs"; - ot->idname= "MESH_OT_uvs_reverse"; + ot->name = "Reverse UVs"; + ot->idname = "MESH_OT_uvs_reverse"; /* api callbacks */ - ot->exec= mesh_reverse_uvs; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_reverse_uvs; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ //RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror UVs around"); @@ -1982,15 +1986,15 @@ void MESH_OT_uvs_reverse(wmOperatorType *ot) void MESH_OT_colors_rotate(wmOperatorType *ot) { /* identifiers */ - ot->name= "Rotate Colors"; - ot->idname= "MESH_OT_colors_rotate"; + ot->name = "Rotate Colors"; + ot->idname = "MESH_OT_colors_rotate"; /* api callbacks */ - ot->exec= mesh_rotate_colors; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_rotate_colors; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CCW, "Direction", "Direction to rotate edge around"); @@ -1999,15 +2003,15 @@ void MESH_OT_colors_rotate(wmOperatorType *ot) void MESH_OT_colors_reverse(wmOperatorType *ot) { /* identifiers */ - ot->name= "Reverse Colors"; - ot->idname= "MESH_OT_colors_reverse"; + ot->name = "Reverse Colors"; + ot->idname = "MESH_OT_colors_reverse"; /* api callbacks */ - ot->exec= mesh_reverse_colors; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_reverse_colors; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ //RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror colors around"); @@ -2022,11 +2026,11 @@ static int merge_firstlast(BMEditMesh *em, int first, int uvmerge, wmOperator *w /* do sanity check in mergemenu in edit.c ?*/ if (first == 0) { ese = em->bm->selected.last; - mergevert= (BMVert*)ese->data; + mergevert = (BMVert *)ese->data; } else{ ese = em->bm->selected.first; - mergevert = (BMVert*)ese->data; + mergevert = (BMVert *)ese->data; } if (!BM_TestHFlag(mergevert, BM_SELECT)) @@ -2048,7 +2052,7 @@ static int merge_target(BMEditMesh *em, Scene *scene, View3D *v3d, Object *ob, { BMIter iter; BMVert *v; - float *vco=NULL, co[3], cent[3] = {0.0f, 0.0f, 0.0f}; + float *vco = NULL, co[3], cent[3] = {0.0f, 0.0f, 0.0f}; if (target) { vco = give_cursor(scene, v3d); @@ -2090,11 +2094,11 @@ static int merge_target(BMEditMesh *em, Scene *scene, View3D *v3d, Object *ob, static int merge_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); + Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; - int status= 0, uvs= RNA_boolean_get(op->ptr, "uvs"); + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; + int status = 0, uvs = RNA_boolean_get(op->ptr, "uvs"); switch(RNA_enum_get(op->ptr, "type")) { case 3: @@ -2125,7 +2129,7 @@ static int merge_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static EnumPropertyItem merge_type_items[]= { +static EnumPropertyItem merge_type_items[] = { {6, "FIRST", 0, "At First", ""}, {1, "LAST", 0, "At Last", ""}, {3, "CENTER", 0, "At Center", ""}, @@ -2136,26 +2140,30 @@ static EnumPropertyItem merge_type_items[]= { static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { Object *obedit; - EnumPropertyItem *item= NULL; - int totitem= 0; + EnumPropertyItem *item = NULL; + int totitem = 0; if (!C) /* needed for docs */ return merge_type_items; - obedit= CTX_data_edit_object(C); + obedit = CTX_data_edit_object(C); if (obedit && obedit->type == OB_MESH) { - BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; if (em->selectmode & SCE_SELECT_VERTEX) { - if (em->bm->selected.first && em->bm->selected.last && - ((BMEditSelection*)em->bm->selected.first)->htype == BM_VERT && ((BMEditSelection*)em->bm->selected.last)->htype == BM_VERT) { + if ( em->bm->selected.first && em->bm->selected.last && + ((BMEditSelection *)em->bm->selected.first)->htype == BM_VERT && + ((BMEditSelection *)em->bm->selected.last)->htype == BM_VERT) + { RNA_enum_items_add_value(&item, &totitem, merge_type_items, 6); RNA_enum_items_add_value(&item, &totitem, merge_type_items, 1); } - else if (em->bm->selected.first && ((BMEditSelection*)em->bm->selected.first)->htype == BM_VERT) + else if (em->bm->selected.first && ((BMEditSelection *)em->bm->selected.first)->htype == BM_VERT) { RNA_enum_items_add_value(&item, &totitem, merge_type_items, 1); - else if (em->bm->selected.last && ((BMEditSelection*)em->bm->selected.last)->htype == BM_VERT) + } + else if (em->bm->selected.last && ((BMEditSelection *)em->bm->selected.last)->htype == BM_VERT) { RNA_enum_items_add_value(&item, &totitem, merge_type_items, 6); + } } RNA_enum_items_add_value(&item, &totitem, merge_type_items, 3); @@ -2163,7 +2171,7 @@ static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *UNUSED(ptr), RNA_enum_items_add_value(&item, &totitem, merge_type_items, 5); RNA_enum_item_end(&item, &totitem); - *free= 1; + *free = 1; return item; } @@ -2174,19 +2182,19 @@ static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *UNUSED(ptr), void MESH_OT_merge(wmOperatorType *ot) { /* identifiers */ - ot->name= "Merge"; - ot->idname= "MESH_OT_merge"; + ot->name = "Merge"; + ot->idname = "MESH_OT_merge"; /* api callbacks */ - ot->exec= merge_exec; - ot->invoke= WM_menu_invoke; - ot->poll= ED_operator_editmesh; + ot->exec = merge_exec; + ot->invoke = WM_menu_invoke; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ - ot->prop= RNA_def_enum(ot->srna, "type", merge_type_items, 3, "Type", "Merge method to use"); + ot->prop = RNA_def_enum(ot->srna, "type", merge_type_items, 3, "Type", "Merge method to use"); RNA_def_enum_funcs(ot->prop, merge_type_itemf); RNA_def_boolean(ot->srna, "uvs", 1, "UVs", "Move UVs according to merge"); } @@ -2194,8 +2202,8 @@ void MESH_OT_merge(wmOperatorType *ot) static int removedoublesflag_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMOperator bmop; /* int count; */ /* UNUSED */ @@ -2214,8 +2222,9 @@ static int removedoublesflag_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /*we need a better way of reporting this, since this doesn't work - with the last operator panel correctly. + /* we need a better way of reporting this, since this doesn't work + * with the last operator panel correctly. + if (count) { sprintf(msg, "Removed %d vertices", count); @@ -2232,15 +2241,15 @@ static int removedoublesflag_exec(bContext *C, wmOperator *op) void MESH_OT_remove_doubles(wmOperatorType *ot) { /* identifiers */ - ot->name= "Remove Doubles"; - ot->idname= "MESH_OT_remove_doubles"; + ot->name = "Remove Doubles"; + ot->idname = "MESH_OT_remove_doubles"; /* api callbacks */ - ot->exec= removedoublesflag_exec; - ot->poll= ED_operator_editmesh; + ot->exec = removedoublesflag_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_float(ot->srna, "mergedist", 0.0001f, 0.000001f, 50.0f, "Merge Distance", @@ -2266,7 +2275,7 @@ typedef struct PathEdge { static int select_vertex_path_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; BMEditSelection *sv, *ev; @@ -2274,10 +2283,10 @@ static int select_vertex_path_exec(bContext *C, wmOperator *op) int type = RNA_enum_get(op->ptr, "type"); sv = em->bm->selected.last; - if ( sv != NULL ) + if (sv != NULL) ev = sv->prev; else return OPERATOR_CANCELLED; - if ( ev == NULL ) + if (ev == NULL) return OPERATOR_CANCELLED; if ((sv->htype != BM_VERT) || (ev->htype != BM_VERT)) @@ -2322,15 +2331,15 @@ void MESH_OT_select_vertex_path(wmOperatorType *ot) {0, NULL, 0, NULL, NULL}}; /* identifiers */ - ot->name= "Select Vertex Path"; - ot->idname= "MESH_OT_select_vertex_path"; + ot->name = "Select Vertex Path"; + ot->idname = "MESH_OT_select_vertex_path"; /* api callbacks */ - ot->exec= select_vertex_path_exec; - ot->poll= ED_operator_editmesh; + ot->exec = select_vertex_path_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ RNA_def_enum(ot->srna, "type", type_items, VPATH_SELECT_EDGE_LENGTH, "Type", "Method to compute distance"); @@ -2344,8 +2353,8 @@ static float mesh_rip_edgedist(ARegion *ar, float mat[][4], float *co1, float *c ED_view3d_project_float(ar, co1, vec1, mat); ED_view3d_project_float(ar, co2, vec2, mat); - mvalf[0]= (float)mval[0]; - mvalf[1]= (float)mval[1]; + mvalf[0] = (float)mval[0]; + mvalf[1] = (float)mval[1]; return dist_to_line_segment_v2(mvalf, vec1, vec2); } @@ -2353,11 +2362,11 @@ static float mesh_rip_edgedist(ARegion *ar, float mat[][4], float *co1, float *c /* based on mouse cursor position, it defines how is being ripped */ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) { - Object *obedit= CTX_data_edit_object(C); - ARegion *ar= CTX_wm_region(C); + Object *obedit = CTX_data_edit_object(C); + ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + RegionView3D *rv3d = CTX_wm_region_view3d(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMesh *bm = em->bm; BMOperator bmop; BMBVHTree *bvhtree; @@ -2381,19 +2390,19 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) } } - /*handle case of one vert selected. identify - closest edge around that vert to mouse cursor, - then rip two adjacent edges in the vert fan.*/ + /* handle case of one vert selected. identify + * closest edge around that vert to mouse cursor, + * then rip two adjacent edges in the vert fan. */ if (bm->totvertsel == 1 && bm->totedgesel == 0 && bm->totfacesel == 0) { singlesel = 1; - /*find selected vert*/ + /* find selected vert */ BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { if (BM_TestHFlag(v, BM_SELECT)) break; } - /*this should be impossible, but sanity checks are a good thing*/ + /* this should be impossible, but sanity checks are a good thing */ if (!v) return OPERATOR_CANCELLED; @@ -2402,7 +2411,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_CANCELLED; } - /*find closest edge to mouse cursor*/ + /* find closest edge to mouse cursor */ e2 = NULL; BM_ITER(e, &iter, bm, BM_EDGES_OF_VERT, v) { d = mesh_rip_edgedist(ar, projectMat, e->v1->co, e->v2->co, event->mval); @@ -2415,7 +2424,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) if (!e2) return OPERATOR_CANCELLED; - /*rip two adjacent edges*/ + /* rip two adjacent edges */ if (BM_Edge_FaceCount(e2) == 1 || BM_Vert_FaceCount(v) == 2) { l = e2->l; ripvert = BM_Rip_Vertex(bm, l->f, v); @@ -2440,7 +2449,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) dist = FLT_MAX; } else { - /*expand edge selection*/ + /* expand edge selection */ BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { e2 = NULL; i = 0; @@ -2469,10 +2478,10 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) BMO_Exec_Op(bm, &bmop); - /*build bvh tree for edge visibility tests*/ + /* build bvh tree for edge visibility tests */ bvhtree = BMBVH_NewBVH(em, 0, NULL, NULL); - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) { BMO_ITER(e, &siter, bm, &bmop, i ? "edgeout2":"edgeout1", BM_EDGE) { float cent[3] = {0, 0, 0}, mid[3], vec[3]; @@ -2522,7 +2531,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) } } - /*constrict edge selection again*/ + /* constrict edge selection again */ BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { e2 = NULL; i = 0; @@ -2566,15 +2575,15 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) void MESH_OT_rip(wmOperatorType *ot) { /* identifiers */ - ot->name= "Rip"; - ot->idname= "MESH_OT_rip"; + ot->name = "Rip"; + ot->idname = "MESH_OT_rip"; /* api callbacks */ - ot->invoke= mesh_rip_invoke; - ot->poll= EM_view3d_poll; + ot->invoke = mesh_rip_invoke; + ot->poll = EM_view3d_poll; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* to give to transform */ Transform_Properties(ot, P_PROPORTIONAL); @@ -2583,7 +2592,7 @@ void MESH_OT_rip(wmOperatorType *ot) /************************ Shape Operators *************************/ -/*BMESH_TODO this should be properly encapsulated in a bmop. but later.*/ +/* BMESH_TODO this should be properly encapsulated in a bmop. but later.*/ static void shape_propagate(Object *obedit, BMEditMesh *em, wmOperator *op) { BMIter iter; @@ -2600,7 +2609,7 @@ static void shape_propagate(Object *obedit, BMEditMesh *em, wmOperator *op) if (!BM_TestHFlag(eve, BM_SELECT) || BM_TestHFlag(eve, BM_HIDDEN)) continue; - for (i=0; i<totshape; i++) { + for (i = 0; i < totshape; i++) { co = CustomData_bmesh_get_n(&em->bm->vdata, eve->head.data, CD_SHAPEKEY, i); copy_v3_v3(co, eve->co); } @@ -2608,7 +2617,7 @@ static void shape_propagate(Object *obedit, BMEditMesh *em, wmOperator *op) #if 0 //TAG Mesh Objects that share this data - for(base = scene->base.first; base; base = base->next) { + for (base = scene->base.first; base; base = base->next) { if (base->object && base->object->data == me) { base->object->recalc = OB_RECALC_DATA; } @@ -2621,9 +2630,9 @@ static void shape_propagate(Object *obedit, BMEditMesh *em, wmOperator *op) static int shape_propagate_to_all_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - Mesh *me= obedit->data; - BMEditMesh *em= me->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + Mesh *me = obedit->data; + BMEditMesh *em = me->edit_btmesh; shape_propagate(obedit, em, op); @@ -2637,33 +2646,33 @@ static int shape_propagate_to_all_exec(bContext *C, wmOperator *op) void MESH_OT_shape_propagate_to_all(wmOperatorType *ot) { /* identifiers */ - ot->name= "Shape Propagate"; - ot->description= "Apply selected vertex locations to all other shape keys"; - ot->idname= "MESH_OT_shape_propagate_to_all"; + ot->name = "Shape Propagate"; + ot->description = "Apply selected vertex locations to all other shape keys"; + ot->idname = "MESH_OT_shape_propagate_to_all"; /* api callbacks */ - ot->exec= shape_propagate_to_all_exec; - ot->poll= ED_operator_editmesh; + ot->exec = shape_propagate_to_all_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } -/*BMESH_TODO this should be properly encapsulated in a bmop. but later.*/ +/* BMESH_TODO this should be properly encapsulated in a bmop. but later.*/ static int blend_from_shape_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - Mesh *me= obedit->data; - BMEditMesh *em= me->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + Mesh *me = obedit->data; + BMEditMesh *em = me->edit_btmesh; BMVert *eve; BMIter iter; float co[3], *sco; - float blend= RNA_float_get(op->ptr, "blend"); - int shape= RNA_enum_get(op->ptr, "shape"); - int add= RNA_boolean_get(op->ptr, "add"); + float blend = RNA_float_get(op->ptr, "blend"); + int shape = RNA_enum_get(op->ptr, "shape"); + int add = RNA_boolean_get(op->ptr, "add"); int totshape; - /*sanity check*/ + /* sanity check */ totshape = CustomData_number_of_layers(&em->bm->vdata, CD_SHAPEKEY); if (totshape == 0 || shape < 0 || shape >= totshape) return OPERATOR_CANCELLED; @@ -2694,23 +2703,23 @@ static int blend_from_shape_exec(bContext *C, wmOperator *op) static EnumPropertyItem *shape_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { - Object *obedit= CTX_data_edit_object(C); - Mesh *me= (obedit) ? obedit->data : NULL; + Object *obedit = CTX_data_edit_object(C); + Mesh *me = (obedit) ? obedit->data : NULL; BMEditMesh *em = me->edit_btmesh; - EnumPropertyItem *item= NULL; - int totitem= 0; + EnumPropertyItem *item = NULL; + int totitem = 0; if (obedit && obedit->type == OB_MESH && CustomData_has_layer(&em->bm->vdata, CD_SHAPEKEY)) { - EnumPropertyItem tmp= {0, "", 0, "", ""}; + EnumPropertyItem tmp = {0, "", 0, "", ""}; int a; - for (a=0; a<em->bm->vdata.totlayer; a++) { + for (a = 0; a < em->bm->vdata.totlayer; a++) { if (em->bm->vdata.layers[a].type != CD_SHAPEKEY) continue; - tmp.value= totitem; - tmp.identifier= em->bm->vdata.layers[a].name; - tmp.name= em->bm->vdata.layers[a].name; + tmp.value = totitem; + tmp.identifier = em->bm->vdata.layers[a].name; + tmp.name = em->bm->vdata.layers[a].name; RNA_enum_item_add(&item, &totitem, &tmp); totitem++; @@ -2718,7 +2727,7 @@ static EnumPropertyItem *shape_itemf(bContext *C, PointerRNA *UNUSED(ptr), Prop } RNA_enum_item_end(&item, &totitem); - *free= 1; + *free = 1; return item; } @@ -2726,23 +2735,23 @@ static EnumPropertyItem *shape_itemf(bContext *C, PointerRNA *UNUSED(ptr), Prop void MESH_OT_blend_from_shape(wmOperatorType *ot) { PropertyRNA *prop; - static EnumPropertyItem shape_items[]= {{0, NULL, 0, NULL, NULL}}; + static EnumPropertyItem shape_items[] = {{0, NULL, 0, NULL, NULL}}; /* identifiers */ - ot->name= "Blend From Shape"; - ot->description= "Blend in shape from a shape key"; - ot->idname= "MESH_OT_blend_from_shape"; + ot->name = "Blend From Shape"; + ot->description = "Blend in shape from a shape key"; + ot->idname = "MESH_OT_blend_from_shape"; /* api callbacks */ - ot->exec= blend_from_shape_exec; - ot->invoke= WM_operator_props_popup; - ot->poll= ED_operator_editmesh; + ot->exec = blend_from_shape_exec; + ot->invoke = WM_operator_props_popup; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ - prop= RNA_def_enum(ot->srna, "shape", shape_items, 0, "Shape", "Shape key to use for blending"); + prop = RNA_def_enum(ot->srna, "shape", shape_items, 0, "Shape", "Shape key to use for blending"); RNA_def_enum_funcs(prop, shape_itemf); RNA_def_float(ot->srna, "blend", 1.0f, -FLT_MAX, FLT_MAX, "Blend", "Blending factor", -2.0f, 2.0f); RNA_def_boolean(ot->srna, "add", 1, "Add", "Add rather then blend between shapes"); @@ -2751,25 +2760,25 @@ void MESH_OT_blend_from_shape(wmOperatorType *ot) /* BMESH_TODO - some way to select on an arbitrary axis */ static int select_axis_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMEditSelection *ese = em->bm->selected.last; - int axis= RNA_enum_get(op->ptr, "axis"); - int mode= RNA_enum_get(op->ptr, "mode"); /* -1==aligned, 0==neg, 1==pos*/ + int axis = RNA_enum_get(op->ptr, "axis"); + int mode = RNA_enum_get(op->ptr, "mode"); /* -1 == aligned, 0 == neg, 1 == pos */ - if (ese==NULL || ese->htype != BM_VERT) { + if (ese == NULL || ese->htype != BM_VERT) { BKE_report(op->reports, RPT_WARNING, "This operator requires an active vertex (last selected)"); return OPERATOR_CANCELLED; } else { - BMVert *ev, *act_vert= (BMVert*)ese->data; + BMVert *ev, *act_vert = (BMVert *)ese->data; BMIter iter; - float value= act_vert->co[axis]; - float limit= CTX_data_tool_settings(C)->doublimit; // XXX + float value = act_vert->co[axis]; + float limit = CTX_data_tool_settings(C)->doublimit; // XXX - if (mode==0) + if (mode == 0) value -= limit; - else if (mode==1) + else if (mode == 1) value += limit; BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { @@ -2813,16 +2822,16 @@ void MESH_OT_select_axis(wmOperatorType *ot) {0, NULL, 0, NULL, NULL}}; /* identifiers */ - ot->name= "Select Axis"; - ot->description= "Select all data in the mesh on a single axis"; - ot->idname= "MESH_OT_select_axis"; + ot->name = "Select Axis"; + ot->description = "Select all data in the mesh on a single axis"; + ot->idname = "MESH_OT_select_axis"; /* api callbacks */ - ot->exec= select_axis_exec; - ot->poll= ED_operator_editmesh; + ot->exec = select_axis_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ RNA_def_enum(ot->srna, "mode", axis_mode_items, 0, "Axis Mode", "Axis side to use when selecting"); @@ -2831,13 +2840,13 @@ void MESH_OT_select_axis(wmOperatorType *ot) static int solidify_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); Mesh *me = obedit->data; BMEditMesh *em = me->edit_btmesh; BMesh *bm = em->bm; BMOperator bmop; - float thickness= RNA_float_get(op->ptr, "thickness"); + float thickness = RNA_float_get(op->ptr, "thickness"); if (!EDBM_InitOpf(em, &bmop, op, "solidify geom=%hf thickness=%f", BM_SELECT, thickness)) { return OPERATOR_CANCELLED; @@ -2869,18 +2878,18 @@ void MESH_OT_solidify(wmOperatorType *ot) { PropertyRNA *prop; /* identifiers */ - ot->name= "Solidify"; - ot->description= "Create a solid skin by extruding, compensating for sharp angles"; - ot->idname= "MESH_OT_solidify"; + ot->name = "Solidify"; + ot->description = "Create a solid skin by extruding, compensating for sharp angles"; + ot->idname = "MESH_OT_solidify"; /* api callbacks */ - ot->exec= solidify_exec; - ot->poll= ED_operator_editmesh; + ot->exec = solidify_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; - prop= RNA_def_float(ot->srna, "thickness", 0.01f, -FLT_MAX, FLT_MAX, "thickness", "", -10.0f, 10.0f); + prop = RNA_def_float(ot->srna, "thickness", 0.01f, -FLT_MAX, FLT_MAX, "thickness", "", -10.0f, 10.0f); RNA_def_property_ui_range(prop, -10, 10, 0.1, 4); } @@ -2891,7 +2900,7 @@ void MESH_OT_solidify(wmOperatorType *ot) #define TRAIL_MIDPOINTS 8 typedef struct CutCurve { - float x; + float x; float y; } CutCurve; @@ -2919,7 +2928,7 @@ typedef struct CutCurve { #define KNIFE_MIDPOINT 2 #define KNIFE_MULTICUT 3 -static EnumPropertyItem knife_items[]= { +static EnumPropertyItem knife_items[] = { {KNIFE_EXACT, "EXACT", 0, "Exact", ""}, {KNIFE_MIDPOINT, "MIDPOINTS", 0, "Midpoints", ""}, {KNIFE_MULTICUT, "MULTICUT", 0, "Multicut", ""}, @@ -2932,131 +2941,131 @@ static float bm_seg_intersect(BMEdge *e, CutCurve *c, int len, char mode, struct GHash *gh, int *isected) { #define MAXSLOPE 100000 - float x11, y11, x12=0, y12=0, x2max, x2min, y2max; - float y2min, dist, lastdist=0, xdiff2, xdiff1; + float x11, y11, x12 = 0, y12 = 0, x2max, x2min, y2max; + float y2min, dist, lastdist = 0, xdiff2, xdiff1; float m1, b1, m2, b2, x21, x22, y21, y22, xi; - float yi, x1min, x1max, y1max, y1min, perc=0; + float yi, x1min, x1max, y1max, y1min, perc = 0; float *scr; float threshold = 0.0; int i; - //threshold = 0.000001; /*tolerance for vertex intersection*/ + //threshold = 0.000001; /* tolerance for vertex intersection */ // XXX threshold = scene->toolsettings->select_thresh / 100; /* Get screen coords of verts */ scr = BLI_ghash_lookup(gh, e->v1); - x21=scr[0]; - y21=scr[1]; + x21 = scr[0]; + y21 = scr[1]; scr = BLI_ghash_lookup(gh, e->v2); - x22=scr[0]; - y22=scr[1]; + x22 = scr[0]; + y22 = scr[1]; - xdiff2=(x22-x21); + xdiff2 = (x22 - x21); if (xdiff2) { - m2=(y22-y21)/xdiff2; - b2= ((x22*y21)-(x21*y22))/xdiff2; + m2 = (y22 - y21) / xdiff2; + b2 = ((x22 * y21) - (x21 * y22)) / xdiff2; } else { - m2=MAXSLOPE; /* Verticle slope */ - b2=x22; + m2 = MAXSLOPE; /* Verticle slope */ + b2 = x22; } *isected = 0; - /*check for *exact* vertex intersection first*/ - if (mode!=KNIFE_MULTICUT) { - for (i=0; i<len; i++) { - if (i>0) { - x11=x12; - y11=y12; + /* check for *exact* vertex intersection first */ + if (mode != KNIFE_MULTICUT) { + for (i = 0; i < len; i++) { + if (i > 0) { + x11 = x12; + y11 = y12; } else { - x11=c[i].x; - y11=c[i].y; + x11 = c[i].x; + y11 = c[i].y; } - x12=c[i].x; - y12=c[i].y; + x12 = c[i].x; + y12 = c[i].y; - /*test e->v1*/ + /* test e->v1*/ if ((x11 == x21 && y11 == y21) || (x12 == x21 && y12 == y21)) { perc = 0; *isected = 1; - return(perc); + return perc; } - /*test e->v2*/ + /* test e->v2*/ else if ((x11 == x22 && y11 == y22) || (x12 == x22 && y12 == y22)) { perc = 0; *isected = 2; - return(perc); + return perc; } } } - /*now check for edge interesect (may produce vertex intersection as well)*/ - for (i=0; i<len; i++) { - if (i>0) { - x11=x12; - y11=y12; + /* now check for edge interesect (may produce vertex intersection as well)*/ + for (i = 0; i < len; i++) { + if (i > 0) { + x11 = x12; + y11 = y12; } else { - x11=c[i].x; - y11=c[i].y; + x11 = c[i].x; + y11 = c[i].y; } - x12=c[i].x; - y12=c[i].y; + x12 = c[i].x; + y12 = c[i].y; /* Perp. Distance from point to line */ - if (m2!=MAXSLOPE) dist=(y12-m2*x12-b2);/* /sqrt(m2*m2+1); Only looking for */ + if (m2 != MAXSLOPE) dist = (y12 - m2 * x12 - b2);/* /sqrt(m2 * m2 + 1); Only looking for */ /* change in sign. Skip extra math */ - else dist=x22-x12; + else dist = x22 - x12; - if (i==0) lastdist=dist; + if (i == 0) lastdist = dist; - /* if dist changes sign, and intersect point in edge's Bound Box*/ - if ((lastdist*dist)<=0) { - xdiff1=(x12-x11); /* Equation of line between last 2 points */ + /* if dist changes sign, and intersect point in edge's Bound Box */ + if ((lastdist * dist) <= 0) { + xdiff1 = (x12 - x11); /* Equation of line between last 2 points */ if (xdiff1) { - m1=(y12-y11)/xdiff1; - b1= ((x12*y11)-(x11*y12))/xdiff1; + m1 = (y12 - y11) / xdiff1; + b1 = ((x12 * y11) - (x11 * y12)) / xdiff1; } else{ - m1=MAXSLOPE; - b1=x12; + m1 = MAXSLOPE; + b1 = x12; } - x2max=MAX2(x21,x22)+0.001; /* prevent missed edges */ - x2min=MIN2(x21,x22)-0.001; /* due to round off error */ - y2max=MAX2(y21,y22)+0.001; - y2min=MIN2(y21,y22)-0.001; + x2max = MAX2(x21, x22) + 0.001; /* prevent missed edges */ + x2min = MIN2(x21, x22) - 0.001; /* due to round off error */ + y2max = MAX2(y21, y22) + 0.001; + y2min = MIN2(y21, y22) - 0.001; /* Found an intersect, calc intersect point */ - if (m1==m2) { /* co-incident lines */ - /* cut at 50% of overlap area*/ - x1max=MAX2(x11, x12); - x1min=MIN2(x11, x12); - xi= (MIN2(x2max,x1max)+MAX2(x2min,x1min))/2.0; + if (m1 == m2) { /* co-incident lines */ + /* cut at 50% of overlap area */ + x1max = MAX2(x11, x12); + x1min = MIN2(x11, x12); + xi = (MIN2(x2max, x1max) + MAX2(x2min, x1min)) / 2.0; - y1max=MAX2(y11, y12); - y1min=MIN2(y11, y12); - yi= (MIN2(y2max,y1max)+MAX2(y2min,y1min))/2.0; - } - else if (m2==MAXSLOPE) { - xi=x22; - yi=m1*x22+b1; + y1max = MAX2(y11, y12); + y1min = MIN2(y11, y12); + yi = (MIN2(y2max, y1max) + MAX2(y2min, y1min)) / 2.0; + } + else if (m2 == MAXSLOPE) { + xi = x22; + yi = m1 * x22 + b1; } - else if (m1==MAXSLOPE) { - xi=x12; - yi=m2*x12+b2; + else if (m1 == MAXSLOPE) { + xi = x12; + yi = m2 * x12 + b2; } else { - xi=(b1-b2)/(m2-m1); - yi=(b1*m2-m1*b2)/(m2-m1); + xi = (b1 - b2) / (m2 - m1); + yi = (b1 * m2 - m1 * b2) / (m2 - m1); } /* Intersect inside bounding box of edge?*/ - if ((xi>=x2min)&&(xi<=x2max)&&(yi<=y2max)&&(yi>=y2min)) { - /*test for vertex intersect that may be 'close enough'*/ - if (mode!=KNIFE_MULTICUT) { + if ((xi >= x2min) && (xi <= x2max) && (yi <= y2max) && (yi >= y2min)) { + /* test for vertex intersect that may be 'close enough'*/ + if (mode != KNIFE_MULTICUT) { if (xi <= (x21 + threshold) && xi >= (x21 - threshold)) { if (yi <= (y21 + threshold) && yi >= (y21 - threshold)) { *isected = 1; @@ -3072,14 +3081,14 @@ static float bm_seg_intersect(BMEdge *e, CutCurve *c, int len, char mode, } } } - if ((m2<=1.0)&&(m2>=-1.0)) perc = (xi-x21)/(x22-x21); - else perc=(yi-y21)/(y22-y21); /*lower slope more accurate*/ - //isect=32768.0*(perc+0.0000153); /* Percentage in 1/32768ths */ + if ((m2 <= 1.0f) && (m2 >= -1.0f)) perc = (xi - x21) / (x22 - x21); + else perc = (yi - y21) / (y22 - y21); /* lower slope more accurate */ + //isect = 32768.0 * (perc + 0.0000153); /* Percentage in 1 / 32768ths */ break; } } - lastdist=dist; + lastdist = dist; } return(perc); } @@ -3088,20 +3097,20 @@ static float bm_seg_intersect(BMEdge *e, CutCurve *c, int len, char mode, static int knife_cut_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; BMesh *bm = em->bm; - ARegion *ar= CTX_wm_region(C); + ARegion *ar = CTX_wm_region(C); BMVert *bv; BMIter iter; BMEdge *be; BMOperator bmop; CutCurve curve[MAX_CUTS]; struct GHash *gh; - float isect=0.0; + float isect = 0.0f; float *scr, co[4]; - int len=0, isected; - short numcuts=1, mode= RNA_int_get(op->ptr, "type"); + int len = 0, isected; + short numcuts = 1, mode = RNA_int_get(op->ptr, "type"); /* edit-object needed for matrix, and ar->regiondata for projections to work */ if (ELEM3(NULL, obedit, ar, ar->regiondata)) @@ -3117,20 +3126,20 @@ static int knife_cut_exec(bContext *C, wmOperator *op) RNA_float_get_array(&itemptr, "loc", (float *)&curve[len]); len++; - if (len>= MAX_CUTS) break; + if (len >= MAX_CUTS) break; } RNA_END; - if (len<2) { + if (len < 2) { return OPERATOR_CANCELLED; } - /*the floating point coordinates of verts in screen space will be stored in a hash table according to the vertices pointer*/ + /* the floating point coordinates of verts in screen space will be stored in a hash table according to the vertices pointer */ gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife cut exec"); - for(bv=BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL);bv;bv=BMIter_Step(&iter)) { + for (bv = BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL); bv; bv = BMIter_Step(&iter)) { scr = MEM_mallocN(sizeof(float)*2, "Vertex Screen Coordinates"); copy_v3_v3(co, bv->co); - co[3]= 1.0; + co[3] = 1.0f; mul_m4_v4(obedit->obmat, co); project_float(ar, co, scr); BLI_ghash_insert(gh, bv, scr); @@ -3140,16 +3149,16 @@ static int knife_cut_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /*store percentage of edge cut for KNIFE_EXACT here.*/ - for (be=BMIter_New(&iter, bm, BM_EDGES_OF_MESH, NULL); be; be=BMIter_Step(&iter)) { - if ( BM_Selected(bm, be) ) { - isect= bm_seg_intersect(be, curve, len, mode, gh, &isected); + /* store percentage of edge cut for KNIFE_EXACT here.*/ + for (be = BMIter_New(&iter, bm, BM_EDGES_OF_MESH, NULL); be; be = BMIter_Step(&iter)) { + if (BM_Selected(bm, be)) { + isect = bm_seg_intersect(be, curve, len, mode, gh, &isected); if (isect != 0.0f) { if (mode != KNIFE_MULTICUT && mode != KNIFE_MIDPOINT) { - BMO_Insert_MapFloat(bm, &bmop, - "edgepercents", - be, isect); + BMO_Insert_MapFloat(bm, &bmop, + "edgepercents", + be, isect); } BMO_SetFlag(bm, be, 1); @@ -3192,21 +3201,21 @@ void MESH_OT_knife_cut(wmOperatorType *ot) { PropertyRNA *prop; - ot->name= "Knife Cut"; - ot->description= "Cut selected edges and faces into parts"; - ot->idname= "MESH_OT_knife_cut"; + ot->name = "Knife Cut"; + ot->description = "Cut selected edges and faces into parts"; + ot->idname = "MESH_OT_knife_cut"; - ot->invoke= WM_gesture_lines_invoke; - ot->modal= WM_gesture_lines_modal; - ot->exec= knife_cut_exec; + ot->invoke = WM_gesture_lines_invoke; + ot->modal = WM_gesture_lines_modal; + ot->exec = knife_cut_exec; - ot->poll= EM_view3d_poll; + ot->poll = EM_view3d_poll; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_enum(ot->srna, "type", knife_items, KNIFE_EXACT, "Type", ""); - prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE); + prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath); /* internal */ @@ -3239,7 +3248,7 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO CustomData_bmesh_init_pool(&bmnew->ldata, allocsize[2]); CustomData_bmesh_init_pool(&bmnew->pdata, allocsize[3]); - basenew= ED_object_add_duplicate(bmain, scene, editbase, USER_DUP_MESH); /* 0 = fully linked */ + basenew = ED_object_add_duplicate(bmain, scene, editbase, USER_DUP_MESH); /* 0 = fully linked */ assign_matarar(basenew->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */ ED_base_object_select(basenew, BA_DESELECT); @@ -3247,7 +3256,7 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO EDBM_CallOpf(em, wmop, "dupe geom=%hvef dest=%p", BM_SELECT, bmnew); EDBM_CallOpf(em, wmop, "del geom=%hvef context=%i", BM_SELECT, DEL_FACES); - /*clean up any loose edges*/ + /* clean up any loose edges */ BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { if (BM_TestHFlag(e, BM_HIDDEN)) continue; @@ -3258,7 +3267,7 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO } EDBM_CallOpf(em, wmop, "del geom=%hvef context=%i", BM_SELECT, DEL_EDGES); - /*clean up any loose verts*/ + /* clean up any loose verts */ BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_TestHFlag(v, BM_HIDDEN)) continue; @@ -3274,7 +3283,7 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO BMO_CallOpf(bmnew, "bmesh_to_mesh mesh=%p object=%p", basenew->object->data, basenew->object); BM_Free_Mesh(bmnew); - ((Mesh*)basenew->object->data)->edit_btmesh = NULL; + ((Mesh *)basenew->object->data)->edit_btmesh = NULL; return 1; } @@ -3306,16 +3315,15 @@ static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase, wmOper } /* Flush the selection to clear edge/face selections to match - * selected vertices*/ + * selected vertices */ EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); - /* A "while(true)" loop should work here as each iteration should + /* A "while (true)" loop should work here as each iteration should * select and remove at least one vertex and when all vertices * are selected the loop will break out. But guard against bad * behavior by limiting iterations to the number of vertices in the * original mesh.*/ - for(i=0; i<max_iter; i++) - { + for (i = 0; i < max_iter; i++) { /* Get a seed vertex to start the walk */ v_seed = NULL; BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { @@ -3328,24 +3336,24 @@ static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase, wmOper break; } - /*Select the seed explicitly, in case it has no edges*/ + /* Select the seed explicitly, in case it has no edges */ BM_Select(bm, v_seed, TRUE); /* Walk from the single vertex, selecting everything connected - * to it*/ + * to it */ BMW_Init(&walker, bm, BMW_SHELL, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_NIL_LAY); e = BMW_Begin(&walker, v_seed); - for (; e; e=BMW_Step(&walker)) { + for (; e; e = BMW_Step(&walker)) { BM_Select(bm, e->v1, TRUE); BM_Select(bm, e->v2, TRUE); } BMW_End(&walker); /* Flush the selection to get edge/face selections matching - * the vertex selection*/ + * the vertex selection */ EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); if (bm->totvert == bm->totvertsel) { @@ -3353,7 +3361,7 @@ static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase, wmOper break; } - /*Move selection into a separate object*/ + /* Move selection into a separate object */ result |= mesh_separate_selected(bmain, scene, editbase, wmop); } @@ -3363,16 +3371,16 @@ static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase, wmOper static int mesh_separate_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Scene *scene= CTX_data_scene(C); - Base *base= CTX_data_active_base(C); - int retval= 0, type= RNA_enum_get(op->ptr, "type"); + Scene *scene = CTX_data_scene(C); + Base *base = CTX_data_active_base(C); + int retval = 0, type = RNA_enum_get(op->ptr, "type"); if (type == 0) - retval= mesh_separate_selected(bmain, scene, base, op); + retval = mesh_separate_selected(bmain, scene, base, op); else if (type == 1) - retval= mesh_separate_material (bmain, scene, base, op); + retval = mesh_separate_material (bmain, scene, base, op); else if (type == 2) - retval= mesh_separate_loose(bmain, scene, base, op); + retval = mesh_separate_loose(bmain, scene, base, op); if (retval) { DAG_id_tag_update(base->object->data, OB_RECALC_DATA); @@ -3395,17 +3403,17 @@ static EnumPropertyItem prop_separate_types[] = { void MESH_OT_separate(wmOperatorType *ot) { /* identifiers */ - ot->name= "Separate"; - ot->description= "Separate selected geometry into a new mesh"; - ot->idname= "MESH_OT_separate"; + ot->name = "Separate"; + ot->description = "Separate selected geometry into a new mesh"; + ot->idname = "MESH_OT_separate"; /* api callbacks */ - ot->invoke= WM_menu_invoke; - ot->exec= mesh_separate_exec; - ot->poll= ED_operator_editmesh; + ot->invoke = WM_menu_invoke; + ot->exec = mesh_separate_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; ot->prop = RNA_def_enum(ot->srna, "type", prop_separate_types, 0, "Type", ""); } @@ -3413,8 +3421,8 @@ void MESH_OT_separate(wmOperatorType *ot) static int fill_mesh_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMOperator bmop; if (!EDBM_InitOpf(em, &bmop, op, "triangle_fill edges=%he", BM_SELECT)) @@ -3422,7 +3430,7 @@ static int fill_mesh_exec(bContext *C, wmOperator *op) BMO_Exec_Op(em->bm, &bmop); - /*select new geometry*/ + /* select new geometry */ BMO_HeaderFlag_Buffer(em->bm, &bmop, "geomout", BM_SELECT, BM_FACE|BM_EDGE); if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { @@ -3439,21 +3447,21 @@ static int fill_mesh_exec(bContext *C, wmOperator *op) void MESH_OT_fill(wmOperatorType *ot) { /* identifiers */ - ot->name= "Fill"; - ot->idname= "MESH_OT_fill"; + ot->name = "Fill"; + ot->idname = "MESH_OT_fill"; /* api callbacks */ - ot->exec= fill_mesh_exec; - ot->poll= ED_operator_editmesh; + ot->exec = fill_mesh_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int beautify_fill_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; if (!EDBM_CallOpf(em, op, "beautify_fill faces=%hf", BM_SELECT)) return OPERATOR_CANCELLED; @@ -3467,23 +3475,23 @@ static int beautify_fill_exec(bContext *C, wmOperator *op) void MESH_OT_beautify_fill(wmOperatorType *ot) { /* identifiers */ - ot->name= "Beautify Fill"; - ot->idname= "MESH_OT_beautify_fill"; + ot->name = "Beautify Fill"; + ot->idname = "MESH_OT_beautify_fill"; /* api callbacks */ - ot->exec= beautify_fill_exec; - ot->poll= ED_operator_editmesh; + ot->exec = beautify_fill_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } /********************** Quad/Tri Operators *************************/ static int quads_convert_to_tris_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; if (!EDBM_CallOpf(em, op, "triangulate faces=%hf", BM_SELECT)) return OPERATOR_CANCELLED; @@ -3497,21 +3505,21 @@ static int quads_convert_to_tris_exec(bContext *C, wmOperator *op) void MESH_OT_quads_convert_to_tris(wmOperatorType *ot) { /* identifiers */ - ot->name= "Quads to Tris"; - ot->idname= "MESH_OT_quads_convert_to_tris"; + ot->name = "Quads to Tris"; + ot->idname = "MESH_OT_quads_convert_to_tris"; /* api callbacks */ - ot->exec= quads_convert_to_tris_exec; - ot->poll= ED_operator_editmesh; + ot->exec = quads_convert_to_tris_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int tris_convert_to_quads_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; int dosharp, douvs, dovcols, domaterials; float limit = RNA_float_get(op->ptr, "limit"); @@ -3538,17 +3546,18 @@ void MESH_OT_tris_convert_to_quads(wmOperatorType *ot) PropertyRNA *prop; /* identifiers */ - ot->name= "Tris to Quads"; - ot->idname= "MESH_OT_tris_convert_to_quads"; + ot->name = "Tris to Quads"; + ot->idname = "MESH_OT_tris_convert_to_quads"; /* api callbacks */ - ot->exec= tris_convert_to_quads_exec; - ot->poll= ED_operator_editmesh; + ot->exec = tris_convert_to_quads_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; - prop= RNA_def_float_rotation(ot->srna, "limit", 0, NULL, 0.0f, DEG2RADF(180.0f), "Max Angle", "Angle Limit in Degrees", 0.0f, DEG2RADF(180.0f)); + prop = RNA_def_float_rotation(ot->srna, "limit", 0, NULL, 0.0f, DEG2RADF(180.0f), + "Max Angle", "Angle Limit in Degrees", 0.0f, DEG2RADF(180.0f)); RNA_def_property_float_default(prop, DEG2RADF(40.0f)); RNA_def_boolean(ot->srna, "uvs", 0, "Compare UVs", ""); @@ -3561,8 +3570,8 @@ void MESH_OT_tris_convert_to_quads(wmOperatorType *ot) static int edge_flip_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) { #if 0 - Object *obedit= CTX_data_edit_object(C); - EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); + Object *obedit = CTX_data_edit_object(C); + EditMesh *em = BKE_mesh_get_editmesh((Mesh *)obedit->data); edge_flip(em); @@ -3577,21 +3586,21 @@ static int edge_flip_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) void MESH_OT_edge_flip(wmOperatorType *ot) { /* identifiers */ - ot->name= "Edge Flip"; - ot->idname= "MESH_OT_edge_flip"; + ot->name = "Edge Flip"; + ot->idname = "MESH_OT_edge_flip"; /* api callbacks */ - ot->exec= edge_flip_exec; - ot->poll= ED_operator_editmesh; + ot->exec = edge_flip_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int split_mesh_exec(bContext *C, wmOperator *op) { - Object *ob= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh*)ob->data)->edit_btmesh; + Object *ob = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)ob->data)->edit_btmesh; BMOperator bmop; EDBM_InitOpf(em, &bmop, op, "split geom=%hvef", BM_SELECT); @@ -3602,7 +3611,7 @@ static int split_mesh_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /*Geometry has changed, need to recalc normals and looptris*/ + /* Geometry has changed, need to recalc normals and looptris */ BMEdit_RecalcTesselation(em); EDBM_RecalcNormals(em); @@ -3615,24 +3624,24 @@ static int split_mesh_exec(bContext *C, wmOperator *op) void MESH_OT_split(wmOperatorType *ot) { /* identifiers */ - ot->name= "Split"; - ot->idname= "MESH_OT_split"; + ot->name = "Split"; + ot->idname = "MESH_OT_split"; /* api callbacks */ - ot->exec= split_mesh_exec; - ot->poll= ED_operator_editmesh; + ot->exec = split_mesh_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int spin_mesh_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - ToolSettings *ts= CTX_data_tool_settings(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; - BMesh *bm= em->bm; + Object *obedit = CTX_data_edit_object(C); + ToolSettings *ts = CTX_data_tool_settings(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; + BMesh *bm = em->bm; BMOperator spinop; float cent[3], axis[3], imat[3][3]; float d[3] = {0.0f, 0.0f, 0.0f}; @@ -3643,7 +3652,7 @@ static int spin_mesh_exec(bContext *C, wmOperator *op) RNA_float_get_array(op->ptr, "axis", axis); steps = RNA_int_get(op->ptr, "steps"); degr = RNA_float_get(op->ptr, "degrees"); - if (ts->editbutflag & B_CLOCKWISE) degr= -degr; + if (ts->editbutflag & B_CLOCKWISE) degr = -degr; dupli = RNA_boolean_get(op->ptr, "dupli"); /* undo object transformation */ @@ -3675,7 +3684,7 @@ static int spin_mesh_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d= ED_view3d_context_rv3d(C); + RegionView3D *rv3d = ED_view3d_context_rv3d(C); RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d)); RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]); @@ -3686,16 +3695,16 @@ static int spin_mesh_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) void MESH_OT_spin(wmOperatorType *ot) { /* identifiers */ - ot->name= "Spin"; - ot->idname= "MESH_OT_spin"; + ot->name = "Spin"; + ot->idname = "MESH_OT_spin"; /* api callbacks */ - ot->invoke= spin_mesh_invoke; - ot->exec= spin_mesh_exec; - ot->poll= EM_view3d_poll; + ot->invoke = spin_mesh_invoke; + ot->exec = spin_mesh_exec; + ot->poll = EM_view3d_poll; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX); @@ -3709,9 +3718,9 @@ void MESH_OT_spin(wmOperatorType *ot) static int screw_mesh_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; - BMesh *bm= em->bm; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; + BMesh *bm = em->bm; BMEdge *eed; BMVert *eve, *v1, *v2; BMIter iter, eiter; @@ -3722,8 +3731,8 @@ static int screw_mesh_exec(bContext *C, wmOperator *op) int valence; - turns= RNA_int_get(op->ptr, "turns"); - steps= RNA_int_get(op->ptr, "steps"); + turns = RNA_int_get(op->ptr, "turns"); + steps = RNA_int_get(op->ptr, "steps"); RNA_float_get_array(op->ptr, "center", cent); RNA_float_get_array(op->ptr, "axis", axis); @@ -3734,15 +3743,15 @@ static int screw_mesh_exec(bContext *C, wmOperator *op) mul_m3_v3(imat, axis); - /* find two vertices with valence count==1, more or less is wrong */ + /* find two vertices with valence count == 1, more or less is wrong */ v1 = NULL; v2 = NULL; - for(eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL); + for (eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL); eve; eve = BMIter_Step(&iter)) { valence = 0; - for(eed = BMIter_New(&eiter, em->bm, BM_EDGES_OF_VERT, eve); + for (eed = BMIter_New(&eiter, em->bm, BM_EDGES_OF_VERT, eve); eed; eed = BMIter_Step(&eiter)) { if (BM_TestHFlag(eed, BM_SELECT)) { @@ -3752,30 +3761,35 @@ static int screw_mesh_exec(bContext *C, wmOperator *op) } if (valence == 1) { - if (v1==NULL) v1 = eve; - else if (v2==NULL) v2= eve; + if (v1 == NULL) { + v1 = eve; + } + else if (v2 == NULL) { + v2 = eve; + } else { - v1= NULL; + v1 = NULL; break; } } } - if (v1==NULL || v2==NULL) { + if (v1 == NULL || v2 == NULL) { BKE_report(op->reports, RPT_ERROR, "You have to select a string of connected vertices too"); return OPERATOR_CANCELLED; } /* calculate dvec */ sub_v3_v3v3(dvec, v1->co, v2->co); - mul_v3_fl(dvec, 1.0f/steps); + mul_v3_fl(dvec, 1.0f / steps); - if (dot_v3v3(nor, dvec)>0.000) + if (dot_v3v3(nor, dvec) > 0.000f) negate_v3(dvec); if (!EDBM_InitOpf(em, &spinop, op, - "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%d ang=%f dupli=0", - BM_SELECT, cent, axis, dvec, turns*steps, 360.0f*turns)) { + "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%d ang=%f dupli=0", + BM_SELECT, cent, axis, dvec, turns * steps, 360.0f * turns)) + { return OPERATOR_CANCELLED; } BMO_Exec_Op(bm, &spinop); @@ -3796,7 +3810,7 @@ static int screw_mesh_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event) { Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d= ED_view3d_context_rv3d(C); + RegionView3D *rv3d = ED_view3d_context_rv3d(C); RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d)); RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[1]); @@ -3807,35 +3821,37 @@ static int screw_mesh_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event) void MESH_OT_screw(wmOperatorType *ot) { /* identifiers */ - ot->name= "Screw"; - ot->idname= "MESH_OT_screw"; + ot->name = "Screw"; + ot->idname = "MESH_OT_screw"; /* api callbacks */ - ot->invoke= screw_mesh_invoke; - ot->exec= screw_mesh_exec; - ot->poll= EM_view3d_poll; + ot->invoke = screw_mesh_invoke; + ot->exec = screw_mesh_exec; + ot->poll = EM_view3d_poll; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; - /*props */ + /* props */ RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256); RNA_def_int(ot->srna, "turns", 1, 0, INT_MAX, "Turns", "Turns", 0, 256); - RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX); - RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX); + RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, + "Center", "Center in global view space", -FLT_MAX, FLT_MAX); + RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, + "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX); } static int select_by_number_vertices_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMFace *efa; BMIter iter; - int numverts= RNA_int_get(op->ptr, "number"); + int numverts = RNA_int_get(op->ptr, "number"); int type = RNA_enum_get(op->ptr, "type"); - for(efa = BMIter_New(&iter, em->bm, BM_FACES_OF_MESH, NULL); + for (efa = BMIter_New(&iter, em->bm, BM_FACES_OF_MESH, NULL); efa; efa = BMIter_Step(&iter)) { int select = 0; @@ -3869,16 +3885,16 @@ void MESH_OT_select_by_number_vertices(wmOperatorType *ot) }; /* identifiers */ - ot->name= "Select by Number of Vertices"; - ot->description= "Select vertices or faces by vertex count"; - ot->idname= "MESH_OT_select_by_number_vertices"; + ot->name = "Select by Number of Vertices"; + ot->description = "Select vertices or faces by vertex count"; + ot->idname = "MESH_OT_select_by_number_vertices"; /* api callbacks */ - ot->exec= select_by_number_vertices_exec; - ot->poll= ED_operator_editmesh; + ot->exec = select_by_number_vertices_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ RNA_def_int(ot->srna, "number", 4, 3, INT_MAX, "Number of Vertices", "", 3, INT_MAX); @@ -3888,12 +3904,12 @@ void MESH_OT_select_by_number_vertices(wmOperatorType *ot) static int select_loose_verts_exec(bContext *C, wmOperator *UNUSED(op)) { Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)obedit->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; BMVert *eve; BMEdge *eed; BMIter iter; - for(eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL); + for (eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL); eve; eve = BMIter_Step(&iter)) { if (!eve->e) { @@ -3901,7 +3917,7 @@ static int select_loose_verts_exec(bContext *C, wmOperator *UNUSED(op)) } } - for(eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); + for (eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL); eed; eed = BMIter_Step(&iter)) { if (!eed->l) { @@ -3932,9 +3948,9 @@ void MESH_OT_select_loose_verts(wmOperatorType *ot) static int select_mirror_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; - int extend= RNA_boolean_get(op->ptr, "extend"); + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; + int extend = RNA_boolean_get(op->ptr, "extend"); EDBM_select_mirrored(obedit, em, extend); EDBM_selectmode_flush(em); @@ -3946,16 +3962,16 @@ static int select_mirror_exec(bContext *C, wmOperator *op) void MESH_OT_select_mirror(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Mirror"; - ot->description= "Select mesh items at mirrored locations"; - ot->idname= "MESH_OT_select_mirror"; + ot->name = "Select Mirror"; + ot->description = "Select mesh items at mirrored locations"; + ot->idname = "MESH_OT_select_mirror"; /* api callbacks */ - ot->exec= select_mirror_exec; - ot->poll= ED_operator_editmesh; + ot->exec = select_mirror_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection"); @@ -3975,10 +3991,10 @@ typedef struct xvertsort { static int vergxco(const void *v1, const void *v2) { - const xvertsort *x1=v1, *x2=v2; + const xvertsort *x1 = v1, *x2 = v2; - if ( x1->x > x2->x ) return 1; - else if ( x1->x < x2->x) return -1; + if (x1->x > x2->x ) return 1; + else if (x1->x < x2->x) return -1; return 0; } @@ -3989,10 +4005,10 @@ struct facesort { static int vergface(const void *v1, const void *v2) { - const struct facesort *x1=v1, *x2=v2; + const struct facesort *x1 = v1, *x2 = v2; - if ( x1->x > x2->x ) return 1; - else if ( x1->x < x2->x) return -1; + if (x1->x > x2->x) return 1; + else if (x1->x < x2->x) return -1; return 0; } #endif @@ -4011,7 +4027,7 @@ static void xsortvert_flag__doSetX(void *userData, EditVert *UNUSED(eve), int x, /* all verts with (flag & 'flag') are sorted */ static void xsortvert_flag(bContext *UNUSED(C), int UNUSED(flag)) { - /*BMESH_TODO*/ + /* BMESH_TODO */ #if 0 //hrm, geometry isn't in linked lists anymore. . . ViewContext vc; BMEditMesh *em; @@ -4037,8 +4053,8 @@ static void xsortvert_flag(bContext *UNUSED(C), int UNUSED(flag)) qsort(sortblock, amount, sizeof(xvertsort), vergxco); /* make temporal listbase */ - tbase.first= tbase.last= 0; - for (i=0; i<amount; i++) { + tbase.first = tbase.last = 0; + for (i = 0; i < amount; i++) { eve = sortblock[i].v1; if (eve) { @@ -4063,17 +4079,17 @@ static int mesh_vertices_sort_exec(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_vertices_sort(wmOperatorType *ot) { /* identifiers */ - ot->name= "Vertex Sort"; - ot->description= "Sort vertex order"; - ot->idname= "MESH_OT_vertices_sort"; + ot->name = "Vertex Sort"; + ot->description = "Sort vertex order"; + ot->idname = "MESH_OT_vertices_sort"; /* api callbacks */ - ot->exec= mesh_vertices_sort_exec; + ot->exec = mesh_vertices_sort_exec; - ot->poll= EM_view3d_poll; /* uses view relative X axis to sort verts */ + ot->poll = EM_view3d_poll; /* uses view relative X axis to sort verts */ /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } /* ********************** SORT FACES ******************* */ @@ -4104,23 +4120,23 @@ static int float_sort(const void *v1, const void *v2) x1 = face_sort_floats[((int *) v1)[0]]; x2 = face_sort_floats[((int *) v2)[0]]; - if ( x1 > x2 ) return 1; - else if ( x1 < x2 ) return -1; + if (x1 > x2) return 1; + else if (x1 < x2) return -1; return 0; } static int sort_faces_exec(bContext *C, wmOperator *op) { - RegionView3D *rv3d= ED_view3d_context_rv3d(C); - View3D *v3d= CTX_wm_view3d(C); - Object *ob= CTX_data_edit_object(C); - Scene *scene= CTX_data_scene(C); + RegionView3D *rv3d = ED_view3d_context_rv3d(C); + View3D *v3d = CTX_wm_view3d(C); + Object *ob = CTX_data_edit_object(C); + Scene *scene = CTX_data_scene(C); Mesh *me; CustomDataLayer *layer; int i, j, *index; int event; float reverse = 1; - // XXX int ctrl= 0; + // XXX int ctrl = 0; if (!v3d) return OPERATOR_CANCELLED; @@ -4130,20 +4146,20 @@ static int sort_faces_exec(bContext *C, wmOperator *op) */ ED_object_exit_editmode(C, EM_FREEDATA); - me= ob->data; - if (me->totpoly==0) { + me = ob->data; + if (me->totpoly == 0) { ED_object_enter_editmode(C, 0); return OPERATOR_FINISHED; } - event= RNA_enum_get(op->ptr, "type"); + event = RNA_enum_get(op->ptr, "type"); // XXX //if (ctrl) // reverse = -1; /* create index list */ - index= (int *)MEM_mallocN(sizeof(int) * me->totpoly, "sort faces"); + index = (int *)MEM_mallocN(sizeof(int) * me->totpoly, "sort faces"); for (i = 0; i < me->totpoly; i++) { index[i] = i; } @@ -4155,10 +4171,10 @@ static int sort_faces_exec(bContext *C, wmOperator *op) */ if (event == 5) { /* Random */ - for(i=0; i<me->totpoly; i++) { + for (i = 0; i < me->totpoly; i++) { face_sort_floats[i] = BLI_frand(); } - qsort(index, me->totpoly, sizeof(int), float_sort); + qsort(index, me->totpoly, sizeof(int), float_sort); } else { MPoly *mp; @@ -4171,7 +4187,7 @@ static int sort_faces_exec(bContext *C, wmOperator *op) if (event == 1) mult_m4_m4m4(mat, rv3d->viewmat, OBACT->obmat); /* apply the view matrix to the object matrix */ else if (event == 2) { /* sort from cursor */ - if ( v3d && v3d->localvd ) { + if (v3d && v3d->localvd) { copy_v3_v3(cur, v3d->cursor); } else { @@ -4181,14 +4197,14 @@ static int sort_faces_exec(bContext *C, wmOperator *op) mul_m4_v3(mat, cur); } - mp= me->mpoly; + mp = me->mpoly; - for(i=0; i<me->totpoly; i++, mp++) { - if (event==3) { + for (i = 0; i < me->totpoly; i++, mp++) { + if (event == 3) { face_sort_floats[i] = ((float)mp->mat_nr)*reverse; } - else if (event==4) { - /*selected first*/ + else if (event == 4) { + /* selected first */ if (mp->flag & ME_FACE_SEL) face_sort_floats[i] = 0.0; else @@ -4196,10 +4212,10 @@ static int sort_faces_exec(bContext *C, wmOperator *op) } else { /* find the face's center */ - ml = me->mloop+mp->loopstart; + ml = me->mloop + mp->loopstart; zero_v3(vec); for (j = 0; j < mp->totloop; j++, ml++) { - mv = me->mvert+ml->v; + mv = me->mvert + ml->v; add_v3_v3(vec, mv->co); } mul_v3_fl(vec, 1.0f / (float)mp->totloop); @@ -4208,7 +4224,7 @@ static int sort_faces_exec(bContext *C, wmOperator *op) mul_m4_v3(mat, vec); face_sort_floats[i] = vec[2] * reverse; } - else if (event == 2) { /* distance from cursor*/ + else if (event == 2) { /* distance from cursor */ face_sort_floats[i] = len_v3v3(cur, vec) * reverse; /* back to front */ } } @@ -4217,7 +4233,7 @@ static int sort_faces_exec(bContext *C, wmOperator *op) } MEM_freeN(face_sort_floats); - for(i = 0; i < me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { layer = &me->pdata.layers[i]; permutate(layer->data, me->totpoly, CustomData_sizeof(layer->type), index); } @@ -4233,7 +4249,7 @@ static int sort_faces_exec(bContext *C, wmOperator *op) void MESH_OT_sort_faces(wmOperatorType *ot) { - static EnumPropertyItem type_items[]= { + static EnumPropertyItem type_items[] = { { 1, "VIEW_AXIS", 0, "View Axis", "" }, { 2, "CURSOR_DISTANCE", 0, "Cursor Distance", "" }, { 3, "MATERIAL", 0, "Material", "" }, @@ -4242,20 +4258,20 @@ void MESH_OT_sort_faces(wmOperatorType *ot) { 0, NULL, 0, NULL, NULL }}; /* identifiers */ - ot->name= "Sort Faces"; // XXX (Ctrl to reverse)%t| - ot->description= "The faces of the active Mesh Object are sorted, based on the current view"; - ot->idname= "MESH_OT_sort_faces"; + ot->name = "Sort Faces"; // XXX (Ctrl to reverse)%t| + ot->description = "The faces of the active Mesh Object are sorted, based on the current view"; + ot->idname = "MESH_OT_sort_faces"; /* api callbacks */ - ot->invoke= WM_menu_invoke; - ot->exec= sort_faces_exec; - ot->poll= ED_operator_editmesh; + ot->invoke = WM_menu_invoke; + ot->exec = sort_faces_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ - ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", ""); + ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", ""); } #if 0 @@ -4269,43 +4285,43 @@ static void hashvert_flag(EditMesh *em, int flag) int amount, a, b; /* count */ - eve= em->verts.first; - amount= 0; - while(eve) { + eve = em->verts.first; + amount = 0; + while (eve) { if (eve->f & flag) amount++; - eve= eve->next; + eve = eve->next; } - if (amount==0) return; + if (amount == 0) return; /* allocate memory */ - sb= sortblock= (struct xvertsort *)MEM_mallocN(sizeof(struct xvertsort)*amount,"sortremovedoub"); - eve= em->verts.first; - while(eve) { + sb = sortblock = (struct xvertsort *)MEM_mallocN(sizeof(struct xvertsort)*amount,"sortremovedoub"); + eve = em->verts.first; + while (eve) { if (eve->f & flag) { - sb->v1= eve; + sb->v1 = eve; sb++; } - eve= eve->next; + eve = eve->next; } BLI_srand(1); - sb= sortblock; - for(a=0; a<amount; a++, sb++) { - b= (int)(amount*BLI_drand()); - if (b>=0 && b<amount) { - newsort= sortblock+b; - onth= *sb; - *sb= *newsort; - *newsort= onth; + sb = sortblock; + for (a = 0; a < amount; a++, sb++) { + b = (int)(amount * BLI_drand()); + if (b >= 0 && b < amount) { + newsort = sortblock + b; + onth = *sb; + *sb = *newsort; + *newsort = onth; } } /* make temporal listbase */ - tbase.first= tbase.last= 0; - sb= sortblock; - while(amount--) { - eve= sb->v1; + tbase.first = tbase.last = 0; + sb = sortblock; + while (amount--) { + eve = sb->v1; BLI_remlink(&em->verts, eve); BLI_addtail(&tbase, eve); sb++; @@ -4320,9 +4336,9 @@ static void hashvert_flag(EditMesh *em, int flag) static int mesh_vertices_randomize_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; -#if 1 /*BMESH TODO*/ + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; +#if 1 /* BMESH TODO */ (void)em; #else hashvert_flag(em, SELECT); @@ -4333,17 +4349,17 @@ static int mesh_vertices_randomize_exec(bContext *C, wmOperator *UNUSED(op)) void MESH_OT_vertices_randomize(wmOperatorType *ot) { /* identifiers */ - ot->name= "Vertex Randomize"; - ot->description= "Randomize vertex order"; - ot->idname= "MESH_OT_vertices_randomize"; + ot->name = "Vertex Randomize"; + ot->description = "Randomize vertex order"; + ot->idname = "MESH_OT_vertices_randomize"; /* api callbacks */ - ot->exec= mesh_vertices_randomize_exec; + ot->exec = mesh_vertices_randomize_exec; - ot->poll= ED_operator_editmesh; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } /******end of qsort stuff ****/ @@ -4351,33 +4367,33 @@ void MESH_OT_vertices_randomize(wmOperatorType *ot) static int mesh_noise_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; Material *ma; Tex *tex; BMVert *eve; BMIter iter; - float fac= RNA_float_get(op->ptr, "factor"); + float fac = RNA_float_get(op->ptr, "factor"); - if (em==NULL) return OPERATOR_FINISHED; + if (em == NULL) return OPERATOR_FINISHED; - ma= give_current_material(obedit, obedit->actcol); - if (ma==0 || ma->mtex[0]==0 || ma->mtex[0]->tex==0) { + ma = give_current_material(obedit, obedit->actcol); + if (ma == 0 || ma->mtex[0] == 0 || ma->mtex[0]->tex == 0) { BKE_report(op->reports, RPT_WARNING, "Mesh has no material or texture assigned"); return OPERATOR_FINISHED; } - tex= give_current_material_texture(ma); + tex = give_current_material_texture(ma); - if (tex->type==TEX_STUCCI) { + if (tex->type == TEX_STUCCI) { float b2, vec[3]; - float ofs= tex->turbul/200.0; + float ofs = tex->turbul / 200.0; BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_TestHFlag(eve, BM_SELECT) && !BM_TestHFlag(eve, BM_HIDDEN)) { - b2= BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]); - if (tex->stype) ofs*=(b2*b2); - vec[0]= fac*(b2-BLI_hnoise(tex->noisesize, eve->co[0]+ofs, eve->co[1], eve->co[2])); - vec[1]= fac*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1]+ofs, eve->co[2])); - vec[2]= fac*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]+ofs)); + b2 = BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]); + if (tex->stype) ofs *= (b2 * b2); + vec[0] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0] + ofs, eve->co[1], eve->co[2])); + vec[1] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1] + ofs, eve->co[2])); + vec[2] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2] + ofs)); add_v3_v3(eve->co, vec); } @@ -4388,7 +4404,7 @@ static int mesh_noise_exec(bContext *C, wmOperator *op) if (BM_TestHFlag(eve, BM_SELECT) && !BM_TestHFlag(eve, BM_HIDDEN)) { float tin, dum; externtex(ma->mtex[0], eve->co, &tin, &dum, &dum, &dum, &dum, 0); - eve->co[2]+= fac*tin; + eve->co[2] += fac * tin; } } } @@ -4404,32 +4420,32 @@ static int mesh_noise_exec(bContext *C, wmOperator *op) void MESH_OT_noise(wmOperatorType *ot) { /* identifiers */ - ot->name= "Noise"; - ot->description= "Use vertex coordinate as texture coordinate"; - ot->idname= "MESH_OT_noise"; + ot->name = "Noise"; + ot->description = "Use vertex coordinate as texture coordinate"; + ot->idname = "MESH_OT_noise"; /* api callbacks */ - ot->exec= mesh_noise_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_noise_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_float(ot->srna, "factor", 0.1f, -FLT_MAX, FLT_MAX, "Factor", "", 0.0f, 1.0f); } -/*bevel! yay!!*/ +/* bevel! yay!!*/ static int mesh_bevel_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = (((Mesh *)obedit->data))->edit_btmesh; BMIter iter; BMEdge *eed; BMOperator bmop; - float factor= RNA_float_get(op->ptr, "percent"), fac=factor /*, dfac */ /* UNUSED */, df, s; + float factor = RNA_float_get(op->ptr, "percent"), fac = factor /*, dfac */ /* UNUSED */, df, s; int i, recursion = RNA_int_get(op->ptr, "recursion"); - const int use_even= RNA_boolean_get(op->ptr, "use_even"); - const int use_dist= RNA_boolean_get(op->ptr, "use_dist"); + const int use_even = RNA_boolean_get(op->ptr, "use_even"); + const int use_dist = RNA_boolean_get(op->ptr, "use_dist"); float *w = NULL, ftot; int li; @@ -4443,14 +4459,16 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op) *dv = d; } - if (em==NULL) return OPERATOR_CANCELLED; + if (em == NULL) { + return OPERATOR_CANCELLED; + } w = MEM_mallocN(sizeof(float) * recursion, "bevel weights"); - /*ugh, stupid math depends somewhat on angles!*/ - /* dfac = 1.0/(float)(recursion+1); */ /* UNUSED */ + /* ugh, stupid math depends somewhat on angles!*/ + /* dfac = 1.0/(float)(recursion + 1); */ /* UNUSED */ df = 1.0; - for (i=0, ftot=0.0f; i<recursion; i++) { + for (i = 0, ftot = 0.0f; i < recursion; i++) { s = powf(df, 1.25f); w[i] = s; @@ -4462,11 +4480,15 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op) mul_vn_fl(w, recursion, 1.0f / (float)ftot); fac = factor; - for (i=0; i < recursion; i++) { - fac = w[recursion-i-1]*factor; + for (i = 0; i < recursion; i++) { + fac = w[recursion - i - 1] * factor; - if (!EDBM_InitOpf(em, &bmop, op, "bevel geom=%hev percent=%f lengthlayer=%i use_lengths=%i use_even=%i use_dist=%i", BM_SELECT, fac, li, 1, use_even, use_dist)) + if (!EDBM_InitOpf(em, &bmop, op, + "bevel geom=%hev percent=%f lengthlayer=%i use_lengths=%i use_even=%i use_dist=%i", + BM_SELECT, fac, li, 1, use_even, use_dist)) + { return OPERATOR_CANCELLED; + } BMO_Exec_Op(em->bm, &bmop); if (!EDBM_FinishOp(em, &bmop, op, TRUE)) @@ -4488,16 +4510,16 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op) void MESH_OT_bevel(wmOperatorType *ot) { /* identifiers */ - ot->name= "Bevel"; - ot->description= "Edge/Vertex Bevel"; - ot->idname= "MESH_OT_bevel"; + ot->name = "Bevel"; + ot->description = "Edge/Vertex Bevel"; + ot->idname = "MESH_OT_bevel"; /* api callbacks */ - ot->exec= mesh_bevel_exec; - ot->poll= ED_operator_editmesh; + ot->exec = mesh_bevel_exec; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_float(ot->srna, "percent", 0.5f, -FLT_MAX, FLT_MAX, "Percentage", "", 0.0f, 1.0f); RNA_def_int(ot->srna, "recursion", 1, 1, 50, "Recursion Level", "Recursion Level", 1, 8); @@ -4519,7 +4541,7 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) MPoly *mpoly, *mp; MTexPoly *mtexpoly; MLoopUV *luv, *mloopuv; - /*MLoopCol *mloopcol;*/ + /* MLoopCol *mloopcol;*/ FILE *file, *matfile; int *face_mat_group; struct {Material *mat; MTexPoly poly; int end;} **matlists; @@ -4579,7 +4601,7 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) matlists = MEM_callocN(sizeof(*matlists)*MAX2(me->totcol, ob->totcol), "matlists"); else matlists = NULL; - for (i=0; i<MAX2(ob->totcol, me->totcol); i++) { + for (i = 0; i < MAX2(ob->totcol, me->totcol); i++) { matlists[i] = MEM_callocN(sizeof(**matlists), "matlists[i]"); matlists[i][0].end = 1; } @@ -4593,9 +4615,9 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) /* mloopcol = CustomData_get_layer(&dm->loopData, CD_MLOOPCOL); */ /* UNUSED */ if (matlists) { - /*build material list*/ + /* build material list */ mp = mpoly; - for (i=0; i<dm->numPolyData; i++, (mtexpoly ? mtexpoly++ : NULL), mp++) { + for (i = 0; i < dm->numPolyData; i++, (mtexpoly ? mtexpoly++ : NULL), mp++) { int found = 0; j = 0; @@ -4618,10 +4640,10 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) } if (!found) { - matlists[mp->mat_nr] = MEM_reallocN(matlists[mp->mat_nr], sizeof(**matlists)*(j+2)); + matlists[mp->mat_nr] = MEM_reallocN(matlists[mp->mat_nr], sizeof(**matlists) * (j + 2)); - /*add sentinal*/ - matlists[mp->mat_nr][j+1].end = 1; + /* add sentinal */ + matlists[mp->mat_nr][j + 1].end = 1; matlists[mp->mat_nr][j].end = 0; if (ob->matbits && ob->matbits[mp->mat_nr]) { @@ -4639,21 +4661,21 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) } } - /*write material references*/ + /* write material references */ fprintf(file, "mtllib %s_materials.mtl\n", str); - fprintf(file, "o %s\n", (ob->id.name+2)); + fprintf(file, "o %s\n", (ob->id.name + 2)); - for (mv=mvert, i=0; i<dm->numVertData; i++, mv++) { + for (mv = mvert, i = 0; i < dm->numVertData; i++, mv++) { fprintf(file, "v %.8f\t%.8f\t%.8f\n", mv->co[0], mv->co[1], mv->co[2]); - fprintf(file, "vn %.5f\t%.5f\t%.5f\n", (float)mv->no[0]/65535.0f, (float)mv->no[1]/65535.0f, (float)mv->no[2]/65535.0f); + fprintf(file, "vn %.5f\t%.5f\t%.5f\n", (float)mv->no[0] / 65535.0f, (float)mv->no[1] / 65535.0f, (float)mv->no[2] / 65535.0f); } - /*write texture coordinates*/ + /* write texture coordinates */ if (mloopuv) { fprintf(file, "\n"); - for (mp=mpoly, i=0; i<dm->numPolyData; i++, mp++) { + for (mp = mpoly, i = 0; i < dm->numPolyData; i++, mp++) { luv = mloopuv + mp->loopstart; - for (j=0; j<mp->totloop; j++, luv++) { + for (j = 0; j < mp->totloop; j++, luv++) { fprintf(file, "vt %.8f\t%.8f\n", luv->uv[0], luv->uv[1]); } } @@ -4661,7 +4683,7 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) fprintf(file, "\n"); c = 0; - for (mp=mpoly, i=0; i<dm->numPolyData; i++, mp++) { + for (mp = mpoly, i = 0; i < dm->numPolyData; i++, mp++) { char matname[256]; if (mp->flag & ME_SMOOTH) { @@ -4673,14 +4695,14 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) if (matlists) { if (matlists[mp->mat_nr][face_mat_group[i]].mat && matlists[mp->mat_nr][face_mat_group[i]].poly.tpage) { - sprintf(matname, "%s__%s", matlists[mp->mat_nr][face_mat_group[i]].mat->id.name+2, - matlists[mp->mat_nr][face_mat_group[i]].poly.tpage->id.name+2); + sprintf(matname, "%s__%s", matlists[mp->mat_nr][face_mat_group[i]].mat->id.name + 2, + matlists[mp->mat_nr][face_mat_group[i]].poly.tpage->id.name + 2); } else if (matlists[mp->mat_nr][face_mat_group[i]].mat) { - sprintf(matname, "%s", matlists[mp->mat_nr][face_mat_group[i]].mat->id.name+2); + sprintf(matname, "%s", matlists[mp->mat_nr][face_mat_group[i]].mat->id.name + 2); } else if (matlists[mp->mat_nr][face_mat_group[i]].poly.tpage != NULL) { - sprintf(matname, "texture_%s", matlists[mp->mat_nr][face_mat_group[i]].poly.tpage->id.name+2); + sprintf(matname, "texture_%s", matlists[mp->mat_nr][face_mat_group[i]].poly.tpage->id.name + 2); } else { sprintf(matname, "__null_material_%d_%d", mp->mat_nr, face_mat_group[mp->mat_nr]); @@ -4693,12 +4715,12 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) ml = mloop + mp->loopstart; luv = mloopuv ? mloopuv + mp->loopstart : NULL; - for (j=0; j<mp->totloop; j++, ml++, (luv ? luv++ : NULL), c++) { + for (j = 0; j < mp->totloop; j++, ml++, (luv ? luv++ : NULL), c++) { if (luv) { - fprintf(file, "%d/%d ", ml->v+1, c+1); + fprintf(file, "%d/%d ", ml->v + 1, c + 1); } else { - fprintf(file, "%d ", ml->v+1); + fprintf(file, "%d ", ml->v + 1); } } fprintf(file, "\n"); @@ -4706,9 +4728,9 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) fclose(file); - /*write material library*/ + /* write material library */ fprintf(matfile, "#Blender MTL File\n\n"); - for (i=0; i<MAX2(ob->totcol, me->totcol); i++) { + for (i = 0; i < MAX2(ob->totcol, me->totcol); i++) { Material *mat; char basedir[FILE_MAX], filename[FILE_MAX], str3[FILE_MAX]; @@ -4717,14 +4739,14 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) mat = matlists[i][j].mat; if (mat && matlists[i][j].poly.tpage) { - fprintf(matfile, "newmtl %s__%s\n", mat->id.name+2, - matlists[i][j].poly.tpage->id.name+2); + fprintf(matfile, "newmtl %s__%s\n", mat->id.name + 2, + matlists[i][j].poly.tpage->id.name + 2); } else if (mat) { - fprintf(matfile, "newmtl %s\n", mat->id.name+2); + fprintf(matfile, "newmtl %s\n", mat->id.name + 2); } else if (matlists[i][j].poly.tpage != NULL) { - fprintf(matfile, "newmtl texture_%s\n", matlists[i][j].poly.tpage->id.name+2); + fprintf(matfile, "newmtl texture_%s\n", matlists[i][j].poly.tpage->id.name + 2); } else { fprintf(matfile, "newmtl __null_material_%d_%d\n", i, j); @@ -4733,7 +4755,7 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) if (mat) { fprintf(matfile, "Kd %.6f %.6f %.6f\n", mat->r, mat->g, mat->b); fprintf(matfile, "Ks %.6f %.6f %.6f\n", mat->specr, mat->specg, mat->specb); - fprintf(matfile, "Ns %.6f\n", mat->spec*1000.0f); + fprintf(matfile, "Ns %.6f\n", mat->spec * 1000.0f); } else { fprintf(matfile, "Kd %.6f %.6f %.6f\n", 0.45f, 0.45f, 0.45f); @@ -4763,8 +4785,8 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) } } - fprintf(matfile, "map_Ka %s%s\n", rel, (str3+2*RNA_boolean_get(op->ptr, "relpaths"))); - fprintf(matfile, "map_Kd %s%s\n", rel, (str3+2*RNA_boolean_get(op->ptr, "relpaths"))); + fprintf(matfile, "map_Ka %s%s\n", rel, (str3 + 2 * RNA_boolean_get(op->ptr, "relpaths"))); + fprintf(matfile, "map_Kd %s%s\n", rel, (str3 + 2 * RNA_boolean_get(op->ptr, "relpaths"))); } } @@ -4775,7 +4797,7 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) fclose(matfile); - for (i=0; i<MAX2(ob->totcol, me->totcol); i++) { + for (i = 0; i < MAX2(ob->totcol, me->totcol); i++) { MEM_freeN(matlists[i]); } @@ -4796,7 +4818,7 @@ static int mesh_export_obj_exec(bContext *C, wmOperator *op) static void export_obj_filesel(bContext *C, wmOperator *op, const char *path) { RNA_string_set(op->ptr, "filepath", path); - WM_event_add_fileselect(C, op); + WM_event_add_fileselect(C, op); } @@ -4818,17 +4840,17 @@ static int export_obj_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event) void EXPORT_MESH_OT_wavefront(wmOperatorType *ot) { /* identifiers */ - ot->name= "Export Wavefront OBJ"; - ot->description= "Export Wavefront (obj)"; - ot->idname= "EXPORT_MESH_OT_wavefront"; + ot->name = "Export Wavefront OBJ"; + ot->description = "Export Wavefront (obj)"; + ot->idname = "EXPORT_MESH_OT_wavefront"; /* api callbacks */ - ot->exec= mesh_export_obj_exec; - ot->invoke= export_obj_invoke; - ot->poll= ED_operator_object_active; + ot->exec = mesh_export_obj_exec; + ot->invoke = export_obj_invoke; + ot->poll = ED_operator_object_active; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); @@ -4839,8 +4861,8 @@ void EXPORT_MESH_OT_wavefront(wmOperatorType *ot) static int bridge_edge_loops(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; if (!EDBM_CallOpf(em, op, "bridge_loops edges=%he", BM_SELECT)) return OPERATOR_CANCELLED; @@ -4848,22 +4870,22 @@ static int bridge_edge_loops(bContext *C, wmOperator *op) DAG_id_tag_update(obedit->data, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_bridge_edge_loops(wmOperatorType *ot) { /* identifiers */ - ot->name= "Bridge edge loops"; - ot->description= "Make faces between two edge loops"; - ot->idname= "MESH_OT_bridge_edge_loops"; + ot->name = "Bridge edge loops"; + ot->description = "Make faces between two edge loops"; + ot->idname = "MESH_OT_bridge_edge_loops"; /* api callbacks */ - ot->exec= bridge_edge_loops; - ot->poll= ED_operator_editmesh; + ot->exec = bridge_edge_loops; + ot->poll = ED_operator_editmesh; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_boolean(ot->srna, "inside", 0, "Inside", ""); } diff --git a/source/blender/editors/mesh/bmeshutils.c b/source/blender/editors/mesh/bmeshutils.c index 7696995126e..a5ffe1c54f9 100644 --- a/source/blender/editors/mesh/bmeshutils.c +++ b/source/blender/editors/mesh/bmeshutils.c @@ -96,10 +96,10 @@ void EDBM_RecalcNormals(BMEditMesh *em) void EDBM_ClearMesh(BMEditMesh *em) { - /*clear bmesh*/ + /* clear bmesh */ BM_Clear_Mesh(em->bm); - /*free derived meshes*/ + /* free derived meshes */ if (em->derivedCage) { em->derivedCage->needsFree = 1; em->derivedCage->release(em->derivedCage); @@ -111,7 +111,7 @@ void EDBM_ClearMesh(BMEditMesh *em) em->derivedCage = em->derivedFinal = NULL; - /*free tesselation data*/ + /* free tesselation data */ em->tottri = 0; if (em->looptris) MEM_freeN(em->looptris); @@ -134,9 +134,9 @@ void EDBM_stats_update(BMEditMesh *em) em->bm->totvertsel = em->bm->totedgesel = em->bm->totfacesel = 0; - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { ele = BMIter_New(&iter, em->bm, iter_types[i], NULL); - for ( ; ele; ele=BMIter_Step(&iter)) { + for ( ; ele; ele = BMIter_Step(&iter)) { if (BM_TestHFlag(ele, BM_SELECT)) { (*tots[i])++; } @@ -168,7 +168,7 @@ int EDBM_InitOpf(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const char *f } -/*returns 0 on error, 1 on success. executes and finishes a bmesh operator*/ +/* returns 0 on error, 1 on success. executes and finishes a bmesh operator */ int EDBM_FinishOp(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const int report) { const char *errmsg; @@ -283,7 +283,7 @@ void EDBM_selectmode_to_scene(bContext *C) { Scene *scene = CTX_data_scene(C); Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = ((Mesh*)obedit->data)->edit_btmesh; + BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh; if (!em) return; @@ -302,7 +302,7 @@ void EDBM_MakeEditBMesh(ToolSettings *ts, Scene *UNUSED(scene), Object *ob) if (!me->mpoly && me->totface) { fprintf(stderr, "%s: bmesh conversion issue! may lose lots of geometry! (bmesh internal error)\n", __func__); - /*BMESH_TODO need to write smarter code here*/ + /* BMESH_TODO need to write smarter code here */ bm = BKE_mesh_to_bmesh(me, ob); } else { @@ -323,7 +323,7 @@ void EDBM_MakeEditBMesh(ToolSettings *ts, Scene *UNUSED(scene), Object *ob) me->edit_btmesh = BMEdit_Create(bm, FALSE); #endif - me->edit_btmesh->selectmode= me->edit_btmesh->bm->selectmode= ts->selectmode; + me->edit_btmesh->selectmode = me->edit_btmesh->bm->selectmode = ts->selectmode; me->edit_btmesh->me = me; me->edit_btmesh->ob = ob; } @@ -348,12 +348,12 @@ void EDBM_init_index_arrays(BMEditMesh *tm, int forvert, int foredge, int forfac if (forvert) { BMIter iter; BMVert *ele; - int i=0; + int i = 0; - tm->vert_index = MEM_mallocN(sizeof(void**)*tm->bm->totvert, "tm->vert_index"); + tm->vert_index = MEM_mallocN(sizeof(void **) * tm->bm->totvert, "tm->vert_index"); ele = BMIter_New(&iter, tm->bm, BM_VERTS_OF_MESH, NULL); - for ( ; ele; ele=BMIter_Step(&iter)) { + for ( ; ele; ele = BMIter_Step(&iter)) { tm->vert_index[i++] = ele; } } @@ -361,12 +361,12 @@ void EDBM_init_index_arrays(BMEditMesh *tm, int forvert, int foredge, int forfac if (foredge) { BMIter iter; BMEdge *ele; - int i=0; + int i = 0; - tm->edge_index = MEM_mallocN(sizeof(void**)*tm->bm->totedge, "tm->edge_index"); + tm->edge_index = MEM_mallocN(sizeof(void **) * tm->bm->totedge, "tm->edge_index"); ele = BMIter_New(&iter, tm->bm, BM_EDGES_OF_MESH, NULL); - for ( ; ele; ele=BMIter_Step(&iter)) { + for ( ; ele; ele = BMIter_Step(&iter)) { tm->edge_index[i++] = ele; } } @@ -374,12 +374,12 @@ void EDBM_init_index_arrays(BMEditMesh *tm, int forvert, int foredge, int forfac if (forface) { BMIter iter; BMFace *ele; - int i=0; + int i = 0; - tm->face_index = MEM_mallocN(sizeof(void**)*tm->bm->totface, "tm->face_index"); + tm->face_index = MEM_mallocN(sizeof(void **) * tm->bm->totface, "tm->face_index"); ele = BMIter_New(&iter, tm->bm, BM_FACES_OF_MESH, NULL); - for ( ; ele; ele=BMIter_Step(&iter)) { + for ( ; ele; ele = BMIter_Step(&iter)) { tm->face_index[i++] = ele; } } @@ -415,7 +415,7 @@ BMEdge *EDBM_get_edge_for_index(BMEditMesh *tm, int index) BMFace *EDBM_get_face_for_index(BMEditMesh *tm, int index) { - return (tm->face_index && index<tm->bm->totface && index>=0) ? tm->face_index[index] : NULL; + return (tm->face_index && index < tm->bm->totface && index >= 0) ? tm->face_index[index] : NULL; } void EDBM_selectmode_flush_ex(BMEditMesh *em, int selectmode) @@ -498,8 +498,8 @@ int EDBM_get_actSelection(BMEditMesh *em, BMEditSelection *ese) } } else if (efa) { /* no */ - ese->data= (void *)efa; - ese->htype= BM_FACE; + ese->data = (void *)efa; + ese->htype = BM_FACE; } else { ese->data = NULL; @@ -520,7 +520,7 @@ void EDBM_clear_flag_all(BMEditMesh *em, const char hflag) if (hflag & BM_SELECT) BM_clear_selection_history(em->bm); - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { BM_ITER(ele, &iter, em->bm, iter_types[i], NULL) { if (hflag & BM_SELECT) BM_Select(em->bm, ele, FALSE); BM_ClearHFlag(ele, hflag); @@ -537,9 +537,9 @@ void EDBM_set_flag_all(BMEditMesh *em, const char hflag) BMHeader *ele; int i; - for (i=0; i<3; i++) { - ele= BMIter_New(&iter, em->bm, iter_types[i], NULL); - for ( ; ele; ele=BMIter_Step(&iter)) { + for (i = 0; i < 3; i++) { + ele = BMIter_New(&iter, em->bm, iter_types[i], NULL); + for ( ; ele; ele = BMIter_Step(&iter)) { if (hflag & BM_SELECT) { BM_Select(em->bm, ele, TRUE); } @@ -556,9 +556,9 @@ void EDBM_set_flag_all(BMEditMesh *em, const char hflag) static void *getEditMesh(bContext *C) { - Object *obedit= CTX_data_edit_object(C); - if (obedit && obedit->type==OB_MESH) { - Mesh *me= obedit->data; + Object *obedit = CTX_data_edit_object(C); + if (obedit && obedit->type == OB_MESH) { + Mesh *me = obedit->data; return me->edit_btmesh; } return NULL; @@ -567,25 +567,25 @@ static void *getEditMesh(bContext *C) typedef struct undomesh { Mesh me; int selectmode; - char obname[MAX_ID_NAME-2]; + char obname[MAX_ID_NAME - 2]; } undomesh; -/*undo simply makes copies of a bmesh*/ +/* undo simply makes copies of a bmesh */ static void *editbtMesh_to_undoMesh(void *emv, void *obdata) { BMEditMesh *em = emv; Mesh *obme = obdata; undomesh *um = MEM_callocN(sizeof(undomesh), "undo Mesh"); - BLI_strncpy(um->obname, em->bm->ob->id.name+2, sizeof(um->obname)); + BLI_strncpy(um->obname, em->bm->ob->id.name + 2, sizeof(um->obname)); - /*make sure shape keys work*/ + /* make sure shape keys work */ um->me.key = obme->key ? copy_key_nolib(obme->key) : NULL; #ifdef BMESH_EM_UNDO_RECALC_TESSFACE_WORKAROUND - /*we recalc the tesselation here, to avoid seeding calls to - BMEdit_RecalcTesselation throughout the code.*/ + /* we recalc the tesselation here, to avoid seeding calls to + * BMEdit_RecalcTesselation throughout the code. */ BMEdit_RecalcTesselation(em); #endif @@ -604,7 +604,7 @@ static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata)) BMesh *bm; int allocsize[4] = {512, 512, 2048, 512}; - ob = (Object*)find_id("OB", um->obname); + ob = (Object *)find_id("OB", um->obname); ob->shapenr = em->bm->shapenr; BMEdit_Free(em); @@ -623,10 +623,9 @@ static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata)) static void free_undo(void *umv) { - if (((Mesh*)umv)->key) - { - free_key(((Mesh*)umv)->key); - MEM_freeN(((Mesh*)umv)->key); + if (((Mesh *)umv)->key) { + free_key(((Mesh *)umv)->key); + MEM_freeN(((Mesh *)umv)->key); } free_mesh(umv, 0); @@ -639,7 +638,7 @@ void undo_push_mesh(bContext *C, const char *name) undo_editmode_push(C, name, getEditMesh, free_undo, undoMesh_to_editbtMesh, editbtMesh_to_undoMesh, NULL); } -/*write comment here*/ +/* write comment here */ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_array, float *limit) { BMVert *ev; @@ -659,7 +658,7 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a BM_ElemIndex_Ensure(em->bm, BM_VERT); - totverts= em->bm->totvert; + totverts = em->bm->totvert; totuv = 0; /* generate UvMapVert array */ @@ -668,20 +667,20 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a totuv += efa->len; } - if (totuv==0) { + if (totuv == 0) { if (do_face_idx_array) EDBM_free_index_arrays(em); return NULL; } - vmap= (UvVertMap*)MEM_callocN(sizeof(*vmap), "UvVertMap"); + vmap = (UvVertMap *)MEM_callocN(sizeof(*vmap), "UvVertMap"); if (!vmap) { if (do_face_idx_array) EDBM_free_index_arrays(em); return NULL; } - vmap->vert= (UvMapVert**)MEM_callocN(sizeof(*vmap->vert)*totverts, "UvMapVert*"); - buf= vmap->buf= (UvMapVert*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert"); + vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert)*totverts, "UvMapVert_pt"); + buf = vmap->buf = (UvMapVert *)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert"); if (!vmap->vert || !vmap->buf) { free_uv_vert_map(vmap); @@ -695,12 +694,12 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a if (!selected || ((!BM_TestHFlag(efa, BM_HIDDEN)) && BM_TestHFlag(efa, BM_SELECT))) { i = 0; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { - buf->tfindex= i; - buf->f= a; + buf->tfindex = i; + buf->f = a; buf->separate = 0; - buf->next= vmap->vert[BM_GetIndex(l->v)]; - vmap->vert[BM_GetIndex(l->v)]= buf; + buf->next = vmap->vert[BM_GetIndex(l->v)]; + vmap->vert[BM_GetIndex(l->v)] = buf; buf++; i++; @@ -713,53 +712,53 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a /* sort individual uvs for each vert */ a = 0; BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { - UvMapVert *newvlist= NULL, *vlist=vmap->vert[a]; + UvMapVert *newvlist = NULL, *vlist = vmap->vert[a]; UvMapVert *iterv, *v, *lastv, *next; float *uv, *uv2, uvdiff[2]; - while(vlist) { - v= vlist; - vlist= vlist->next; - v->next= newvlist; - newvlist= v; + while (vlist) { + v = vlist; + vlist = vlist->next; + v->next = newvlist; + newvlist = v; efa = EDBM_get_face_for_index(em, v->f); /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, efa, v->tfindex); luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - uv = luv->uv; + uv = luv->uv; - lastv= NULL; - iterv= vlist; + lastv = NULL; + iterv = vlist; - while(iterv) { - next= iterv->next; + while (iterv) { + next = iterv->next; efa = EDBM_get_face_for_index(em, iterv->f); /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex); luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - uv2 = luv->uv; + uv2 = luv->uv; sub_v2_v2v2(uvdiff, uv2, uv); - if(fabs(uvdiff[0]) < limit[0] && fabs(uvdiff[1]) < limit[1]) { - if(lastv) lastv->next= next; - else vlist= next; - iterv->next= newvlist; - newvlist= iterv; + if (fabs(uvdiff[0]) < limit[0] && fabs(uvdiff[1]) < limit[1]) { + if (lastv) lastv->next = next; + else vlist = next; + iterv->next = newvlist; + newvlist = iterv; } else - lastv=iterv; + lastv = iterv; - iterv= next; + iterv = next; } newvlist->separate = 1; } - vmap->vert[a]= newvlist; + vmap->vert[a] = newvlist; a++; } @@ -804,20 +803,20 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla /* generate UvElement array */ BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - if(!selected || ((!BM_TestHFlag(efa, BM_HIDDEN)) && BM_TestHFlag(efa, BM_SELECT))) + if (!selected || ((!BM_TestHFlag(efa, BM_HIDDEN)) && BM_TestHFlag(efa, BM_SELECT))) totuv += efa->len; } - if(totuv == 0) { + if (totuv == 0) { return NULL; } - element_map = (UvElementMap*)MEM_callocN(sizeof(*element_map), "UvElementMap"); + element_map = (UvElementMap *)MEM_callocN(sizeof(*element_map), "UvElementMap"); if (!element_map) { return NULL; } element_map->totalUVs = totuv; - element_map->vert = (UvElement**)MEM_callocN(sizeof(*element_map->vert)*totverts, "UvElementVerts"); - buf = element_map->buf = (UvElement*)MEM_callocN(sizeof(*element_map->buf)*totuv, "UvElement"); + element_map->vert = (UvElement **)MEM_callocN(sizeof(*element_map->vert) * totverts, "UvElementVerts"); + buf = element_map->buf = (UvElement *)MEM_callocN(sizeof(*element_map->buf) * totuv, "UvElement"); if (!element_map->vert || !element_map->buf) { EDBM_free_uv_element_map(element_map); @@ -825,7 +824,7 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla } BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - if(!selected || ((!BM_TestHFlag(efa, BM_HIDDEN)) && BM_TestHFlag(efa, BM_SELECT))) { + if (!selected || ((!BM_TestHFlag(efa, BM_HIDDEN)) && BM_TestHFlag(efa, BM_SELECT))) { i = 0; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { buf->tfindex = i; @@ -845,15 +844,15 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla /* sort individual uvs for each vert */ i = 0; BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { - UvElement *newvlist= NULL, *vlist=element_map->vert[i]; + UvElement *newvlist = NULL, *vlist = element_map->vert[i]; UvElement *iterv, *v, *lastv, *next; float *uv, *uv2, uvdiff[2]; - while(vlist) { - v= vlist; - vlist= vlist->next; - v->next= newvlist; - newvlist= v; + while (vlist) { + v = vlist; + vlist = vlist->next; + v->next = newvlist; + newvlist = v; efa = v->face; /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ @@ -862,11 +861,11 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); uv = luv->uv; - lastv= NULL; - iterv= vlist; + lastv = NULL; + iterv = vlist; - while(iterv) { - next= iterv->next; + while (iterv) { + next = iterv->next; efa = iterv->face; /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ @@ -876,48 +875,49 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla sub_v2_v2v2(uvdiff, uv2, uv); - if(fabsf(uvdiff[0]) < STD_UV_CONNECT_LIMIT && fabsf(uvdiff[1]) < STD_UV_CONNECT_LIMIT) { - if(lastv) lastv->next= next; - else vlist= next; - iterv->next= newvlist; - newvlist= iterv; + if (fabsf(uvdiff[0]) < STD_UV_CONNECT_LIMIT && fabsf(uvdiff[1]) < STD_UV_CONNECT_LIMIT) { + if (lastv) lastv->next = next; + else vlist = next; + iterv->next = newvlist; + newvlist = iterv; + } + else { + lastv = iterv; } - else - lastv=iterv; - iterv= next; + iterv = next; } newvlist->separate = 1; } - element_map->vert[i]= newvlist; + element_map->vert[i] = newvlist; i++; } if (do_islands) { /* at this point, every UvElement in vert points to a UvElement sharing the same vertex. Now we should sort uv's in islands. */ int *island_number; - /* map holds the map from current vmap->buf to the new, sorted map*/ + /* map holds the map from current vmap->buf to the new, sorted map */ map = MEM_mallocN(sizeof(*map)*totuv, "uvelement_remap"); stack = MEM_mallocN(sizeof(*stack)*em->bm->totface, "uv_island_face_stack"); islandbuf = MEM_callocN(sizeof(*islandbuf)*totuv, "uvelement_island_buffer"); island_number = MEM_mallocN(sizeof(*stack)*em->bm->totface, "uv_island_number_face"); - for(i = 0; i < totuv; i++) { + for (i = 0; i < totuv; i++) { if (element_map->buf[i].island == INVALID_ISLAND) { element_map->buf[i].island = nislands; stack[0] = element_map->buf[i].face; island_number[BM_GetIndex(stack[0])] = nislands; - stacksize=1; + stacksize = 1; - while(stacksize > 0) { + while (stacksize > 0) { efa = stack[--stacksize]; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { UvElement *element, *initelement = element_map->vert[BM_GetIndex(l->v)]; - for(element = initelement; element; element = element->next) { + for (element = initelement; element; element = element->next) { if (element->separate) initelement = element; @@ -931,7 +931,7 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla islandbuf[islandbufsize].island = nislands; islandbufsize++; - for(element = initelement; element; element = element->next) { + for (element = initelement; element; element = element->next) { if (element->separate && element != initelement) break; @@ -951,14 +951,14 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla } /* remap */ - for(i = 0; i < em->bm->totvert; i++) { + for (i = 0; i < em->bm->totvert; i++) { /* important since we may do selection only. Some of these may be NULL */ - if(element_map->vert[i]) + if (element_map->vert[i]) element_map->vert[i] = &islandbuf[map[element_map->vert[i] - element_map->buf]]; } element_map->islandIndices = MEM_callocN(sizeof(*element_map->islandIndices)*nislands,"UvElementMap_island_indices"); - if(!element_map->islandIndices) { + if (!element_map->islandIndices) { MEM_freeN(islandbuf); MEM_freeN(stack); MEM_freeN(map); @@ -967,7 +967,7 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla } j = 0; - for(i = 0; i < totuv; i++) { + for (i = 0; i < totuv; i++) { UvElement *element = element_map->buf[i].next; if (element == NULL) islandbuf[map[i]].next = NULL; @@ -1029,11 +1029,11 @@ MTexPoly *EDBM_get_active_mtexpoly(BMEditMesh *em, BMFace **act_efa, int sloppy) efa = BM_get_actFace(em->bm, sloppy); if (efa) { - if (act_efa) *act_efa = efa; + if (act_efa) *act_efa = efa; return CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); } - if (act_efa) *act_efa= NULL; + if (act_efa) *act_efa = NULL; return NULL; } @@ -1053,7 +1053,7 @@ int EDBM_vertColorCheck(BMEditMesh *em) static BMVert *cache_mirr_intptr_as_bmvert(intptr_t *index_lookup, int index) { - intptr_t eve_i= index_lookup[index]; + intptr_t eve_i = index_lookup[index]; return (eve_i == -1) ? NULL : (BMVert *)eve_i; } @@ -1070,8 +1070,8 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) int li, topo = 0; /* one or the other is used depending if topo is enabled */ - BMBVHTree *tree= NULL; - MirrTopoStore_t mesh_topo_store= {NULL, -1, -1, -1}; + BMBVHTree *tree = NULL; + MirrTopoStore_t mesh_topo_store = {NULL, -1, -1, -1}; if (me && (me->editflag & ME_EDIT_MIRROR_TOPO)) { topo = 1; @@ -1086,7 +1086,7 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) BM_add_data_layer_named(bm, &bm->vdata, CD_PROP_INT, BM_CD_LAYER_ID); } - li= CustomData_get_named_layer_index(&bm->vdata, CD_PROP_INT, BM_CD_LAYER_ID); + li = CustomData_get_named_layer_index(&bm->vdata, CD_PROP_INT, BM_CD_LAYER_ID); bm->vdata.layers[li].flag |= CD_FLAG_TEMPORARY; @@ -1096,7 +1096,7 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) ED_mesh_mirrtopo_init(me, -1, &mesh_topo_store, TRUE); } else { - tree= BMBVH_NewBVH(em, 0, NULL, NULL); + tree = BMBVH_NewBVH(em, 0, NULL, NULL); } BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { @@ -1110,11 +1110,11 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) int *idx = CustomData_bmesh_get_layer_n(&bm->vdata, v->head.data, li); if (topo) { - mirr= cache_mirr_intptr_as_bmvert(mesh_topo_store.index_lookup, BM_GetIndex(v)); + mirr = cache_mirr_intptr_as_bmvert(mesh_topo_store.index_lookup, BM_GetIndex(v)); } else { float co[3] = {-v->co[0], v->co[1], v->co[2]}; - mirr= BMBVH_FindClosestVert(tree, co, BM_SEARCH_MAXDIST_MIRR); + mirr = BMBVH_FindClosestVert(tree, co, BM_SEARCH_MAXDIST_MIRR); } if (mirr && mirr != v) { @@ -1137,7 +1137,7 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) BMBVH_FreeBVH(tree); } - em->mirror_cdlayer= li; + em->mirror_cdlayer = li; } BMVert *EDBM_GetMirrorVert(BMEditMesh *em, BMVert *v) @@ -1146,10 +1146,10 @@ BMVert *EDBM_GetMirrorVert(BMEditMesh *em, BMVert *v) BLI_assert(em->mirror_cdlayer != -1); /* invalid use */ - if (mirr && *mirr >=0 && *mirr < em->bm->totvert) { + if (mirr && *mirr >= 0 && *mirr < em->bm->totvert) { if (!em->vert_index) { printf("err: should only be called between " - "EDBM_CacheMirrorVerts and EDBM_EndMirrorCache"); + "EDBM_CacheMirrorVerts and EDBM_EndMirrorCache"); return NULL; } @@ -1166,7 +1166,7 @@ void EDBM_ClearMirrorVert(BMEditMesh *em, BMVert *v) BLI_assert(em->mirror_cdlayer != -1); /* invalid use */ if (mirr) { - *mirr= -1; + *mirr = -1; } } @@ -1177,7 +1177,7 @@ void EDBM_EndMirrorCache(BMEditMesh *em) em->vert_index = NULL; } - em->mirror_cdlayer= -1; + em->mirror_cdlayer = -1; } void EDBM_ApplyMirrorCache(BMEditMesh *em, const int sel_from, const int sel_to) @@ -1189,7 +1189,7 @@ void EDBM_ApplyMirrorCache(BMEditMesh *em, const int sel_from, const int sel_to) BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_TestHFlag(v, BM_SELECT) == sel_from) { - BMVert *mirr= EDBM_GetMirrorVert(em, v); + BMVert *mirr = EDBM_GetMirrorVert(em, v); if (mirr) { if (BM_TestHFlag(mirr, BM_SELECT) == sel_to) { copy_v3_v3(mirr->co, v->co); diff --git a/source/blender/editors/mesh/editbmesh_add.c b/source/blender/editors/mesh/editbmesh_add.c index 98462647db9..90b6c00a0f8 100644 --- a/source/blender/editors/mesh/editbmesh_add.c +++ b/source/blender/editors/mesh/editbmesh_add.c @@ -115,9 +115,8 @@ static float new_primitive_matrix(bContext *C, float *loc, float *rot, float pri sub_v3_v3(primmat[3], obedit->obmat[3]); invert_m3_m3(imat, mat); mul_m3_v3(imat, primmat[3]); - - if(v3d) return v3d->grid; - return 1.0f; + + return v3d ? v3d->grid : 1.0f; } /* ********* add primitive operators ************* */ diff --git a/source/blender/editors/mesh/knifetool.c b/source/blender/editors/mesh/knifetool.c index 95bc1d006dc..529ed597783 100755 --- a/source/blender/editors/mesh/knifetool.c +++ b/source/blender/editors/mesh/knifetool.c @@ -43,7 +43,7 @@ #include "BLI_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_dynstr.h" /*for WM_operator_pystring */ +#include "BLI_dynstr.h" /* for WM_operator_pystring */ #include "BLI_editVert.h" #include "BLI_array.h" #include "BLI_ghash.h" @@ -85,17 +85,17 @@ #include "mesh_intern.h" #include "editbmesh_bvh.h" -/* this code here is kindof messy. . .I might need to eventually rework it - joeedh*/ +/* this code here is kindof messy. . .I might need to eventually rework it - joeedh */ #define MAXGROUP 30 -#define KMAXDIST 10 /*max mouse distance from edge before not detecting it*/ +#define KMAXDIST 10 /* max mouse distance from edge before not detecting it */ /* knifetool operator */ typedef struct KnifeVert { - BMVert *v; /*non-NULL if this is an original vert*/ + BMVert *v; /* non-NULL if this is an original vert */ ListBase edges; - float co[3], cageco[3], sco[3]; /*sco is screen coordinates for cageco*/ + float co[3], cageco[3], sco[3]; /* sco is screen coordinates for cageco */ short flag, draw, isface, inspace; } KnifeVert; @@ -106,21 +106,21 @@ typedef struct Ref { typedef struct KnifeEdge { KnifeVert *v1, *v2; - BMFace *basef; /*face to restrict face fill to*/ + BMFace *basef; /* face to restrict face fill to */ ListBase faces; int draw; - BMEdge *e, *oe; /*non-NULL if this is an original edge*/ + BMEdge *e, *oe; /* non-NULL if this is an original edge */ } KnifeEdge; typedef struct BMEdgeHit { KnifeEdge *kfe; float hit[3], cagehit[3]; - float realhit[3]; /*used in midpoint mode*/ + float realhit[3]; /* used in midpoint mode */ float schit[3]; - float l; /*lambda along cut line*/ - float perc; /*lambda along hit line*/ - KnifeVert *v; //set if snapped to a vert + float l; /* lambda along cut line */ + float perc; /* lambda along hit line */ + KnifeVert *v; /* set if snapped to a vert */ BMFace *f; } BMEdgeHit; @@ -152,13 +152,13 @@ typedef struct knifetool_opdata { float vertco[3], vertcage[3]; float prevco[3], prevcage[3]; - /*used for drag-cutting*/ + /* used for drag-cutting */ BMEdgeHit *linehits; int totlinehit; - /*if curedge is NULL, attach to curvert; - if curvert is NULL, attach to curbmface, - otherwise create null vert*/ + /* if curedge is NULL, attach to curvert; + * if curvert is NULL, attach to curbmface, + * otherwise create null vert */ KnifeEdge *curedge, *prevedge; KnifeVert *curvert, *prevvert; BMFace *curbmface, *prevbmface; @@ -191,7 +191,7 @@ typedef struct knifetool_opdata { ANGLE_135 } angle_snapping; - int is_space, prev_is_space; /*1 if current cut location, vertco, isn't on the mesh*/ + int is_space, prev_is_space; /*1 if current cut location, vertco, isn't on the mesh */ float (*cagecos)[3]; } knifetool_opdata; @@ -239,7 +239,7 @@ static KnifeVert *new_knife_vert(knifetool_opdata *kcd, float *co, float *cageco return kfv; } -/*get a KnifeVert wrapper for an existing BMVert*/ +/* get a KnifeVert wrapper for an existing BMVert */ static KnifeVert *get_bm_knife_vert(knifetool_opdata *kcd, BMVert *v) { KnifeVert *kfv = BLI_ghash_lookup(kcd->origvertmap, v); @@ -253,7 +253,7 @@ static KnifeVert *get_bm_knife_vert(knifetool_opdata *kcd, BMVert *v) return kfv; } -/*get a KnifeEdge wrapper for an existing BMEdge*/ +/* get a KnifeEdge wrapper for an existing BMEdge */ static KnifeEdge *get_bm_knife_edge(knifetool_opdata *kcd, BMEdge *e) { KnifeEdge *kfe = BLI_ghash_lookup(kcd->origedgemap, e); @@ -276,8 +276,8 @@ static KnifeEdge *get_bm_knife_edge(knifetool_opdata *kcd, BMEdge *e) ref->ref = f; BLI_addtail(&kfe->faces, ref); - /*ensures the kedges lst for this f is initialized, - it automatically adds kfe by itself*/ + /* ensures the kedges lst for this f is initialized, + * it automatically adds kfe by itself */ knife_get_face_kedges(kcd, f); } } @@ -320,7 +320,7 @@ static Ref *find_ref(ListBase *lb, void *ref) { Ref *ref1; - for (ref1=lb->first; ref1; ref1=ref1->next) { + for (ref1 = lb->first; ref1; ref1 = ref1->next) { if (ref1->ref == ref) return ref1; } @@ -351,7 +351,7 @@ static ListBase *knife_get_face_kedges(knifetool_opdata *kcd, BMFace *f) return lst; } -/*finds the proper face to restrict face fill to*/ +/* finds the proper face to restrict face fill to */ static void knife_find_basef(knifetool_opdata *kcd, KnifeEdge *kfe) { if (!kfe->basef) { @@ -362,14 +362,15 @@ static void knife_find_basef(knifetool_opdata *kcd, KnifeEdge *kfe) kfe->basef = kcd->curbmface; else kfe->basef = kcd->prevbmface; - } else { - for (r1=kfe->v1->edges.first; r1 && !kfe->basef; r1=r1->next) { + } + else { + for (r1 = kfe->v1->edges.first; r1 && !kfe->basef; r1 = r1->next) { KnifeEdge *ke1 = r1->ref; - for (r2=ke1->faces.first; r2 && !kfe->basef; r2=r2->next) { - for (r3=kfe->v2->edges.first; r3 && !kfe->basef; r3=r3->next) { + for (r2 = ke1->faces.first; r2 && !kfe->basef; r2 = r2->next) { + for (r3 = kfe->v2->edges.first; r3 && !kfe->basef; r3 = r3->next) { KnifeEdge *ke2 = r3->ref; - for (r4=ke2->faces.first; r4 && !kfe->basef; r4=r4->next) { + for (r4 = ke2->faces.first; r4 && !kfe->basef; r4 = r4->next) { if (r2->ref == r4->ref) { kfe->basef = r2->ref; } @@ -378,8 +379,7 @@ static void knife_find_basef(knifetool_opdata *kcd, KnifeEdge *kfe) } } } - /*ok, at this point kfe->basef should be set if any valid possibility - exists*/ + /* ok, at this point kfe->basef should be set if any valid possibility exists */ } } @@ -416,7 +416,7 @@ static KnifeVert *knife_split_edge(knifetool_opdata *kcd, KnifeEdge *kfe, float kfe->v1 = newkfe->v2; BLI_addtail(&kfe->v1->edges, ref); - for (ref=kfe->faces.first; ref; ref=ref->next) + for (ref = kfe->faces.first; ref; ref = ref->next) knife_edge_append_face(kcd, newkfe, ref->ref); knife_add_to_vert_edges(kcd, newkfe); @@ -434,15 +434,15 @@ static void knife_copy_edge_facelist(knifetool_opdata *kcd, KnifeEdge *dest, Kni { Ref *ref, *ref2; - for (ref2 = source->faces.first; ref2; ref2=ref2->next) { + for (ref2 = source->faces.first; ref2; ref2 = ref2->next) { ListBase *lst = knife_get_face_kedges(kcd, ref2->ref); - /*add new edge to face knife edge list*/ + /* add new edge to face knife edge list */ ref = BLI_mempool_calloc(kcd->refs); ref->ref = dest; BLI_addtail(lst, ref); - /*add face to new edge's face list*/ + /* add face to new edge's face list */ ref = BLI_mempool_calloc(kcd->refs); ref->ref = ref2->ref; BLI_addtail(&dest->faces, ref); @@ -463,9 +463,11 @@ static void knife_add_single_cut(knifetool_opdata *kcd) if (kcd->prevvert) { kfe->v1 = kcd->prevvert; - } else if (kcd->prevedge) { + } + else if (kcd->prevedge) { kfe->v1 = knife_split_edge(kcd, kcd->prevedge, kcd->prevco, &kfe2); - } else { + } + else { kfe->v1 = new_knife_vert(kcd, kcd->prevco, kcd->prevco); kfe->v1->draw = kfe->draw = !kcd->prev_is_space; kfe->v1->inspace = kcd->prev_is_space; @@ -475,11 +477,13 @@ static void knife_add_single_cut(knifetool_opdata *kcd) if (kcd->curvert) { kfe->v2 = kcd->curvert; - } else if (kcd->curedge) { + } + else if (kcd->curedge) { kfe->v2 = knife_split_edge(kcd, kcd->curedge, kcd->vertco, &kfe3); kcd->curvert = kfe->v2; - } else { + } + else { kfe->v2 = new_knife_vert(kcd, kcd->vertco, kcd->vertco); kfe->v2->draw = !kcd->is_space; kfe->v2->isface = 1; @@ -498,7 +502,7 @@ static void knife_add_single_cut(knifetool_opdata *kcd) if (kfe->basef && !find_ref(&kfe->faces, kfe->basef)) knife_edge_append_face(kcd, kfe, kfe->basef); - /*sanity check to make sure we're in the right edge/face lists*/ + /* sanity check to make sure we're in the right edge/face lists */ if (kcd->curbmface) { if (!find_ref(&kfe->faces, kcd->curbmface)) { knife_edge_append_face(kcd, kfe, kcd->curbmface); @@ -511,7 +515,7 @@ static void knife_add_single_cut(knifetool_opdata *kcd) } } - /*set up for next cut*/ + /* set up for next cut */ kcd->prevbmface = kcd->curbmface; kcd->prevvert = kcd->curvert; kcd->prevedge = kcd->curedge; @@ -524,7 +528,7 @@ static void knife_add_single_cut(knifetool_opdata *kcd) static int verge_linehit(const void *vlh1, const void *vlh2) { - const BMEdgeHit *lh1=vlh1, *lh2=vlh2; + const BMEdgeHit *lh1 = vlh1, *lh2 = vlh2; if (lh1->l < lh2->l) return -1; else if (lh1->l > lh2->l) return 1; @@ -559,7 +563,8 @@ static void knife_get_vert_faces(knifetool_opdata *kcd, KnifeVert* kfv, BMFace * ref = BLI_mempool_calloc(kcd->refs); ref->ref = facef; BLI_addtail(lst, ref); - } else if (kfv->v) { + } + else if (kfv->v) { BMesh *bm = kcd->em->bm; BM_ITER(f, &bmiter, bm, BM_FACES_OF_VERT, kfv->v) { ref = BLI_mempool_calloc(kcd->refs); @@ -606,14 +611,15 @@ static void knife_cut_through(knifetool_opdata *kcd) } qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); - splitkfe = MEM_callocN(kcd->totlinehit * sizeof(KnifeEdge*), "knife_cut_through"); + splitkfe = MEM_callocN(kcd->totlinehit * sizeof(KnifeEdge *), "knife_cut_through"); if (kcd->prevvert) { if (kcd->prevvert == kcd->curvert) return; firstv = kcd->prevvert; knife_get_vert_faces(kcd, firstv, kcd->prevbmface, &firstfaces); - } else if (kcd->prevedge) { + } + else if (kcd->prevedge) { if (kcd->prevedge == kcd->curedge) return; firstv = knife_split_edge(kcd, kcd->prevedge, kcd->prevco, &kfe3); @@ -623,7 +629,8 @@ static void knife_cut_through(knifetool_opdata *kcd) if (kcd->curvert) { lastv = kcd->curvert; knife_get_vert_faces(kcd, lastv, kcd->curbmface, &lastfaces); - } else if (kcd->curedge) { + } + else if (kcd->curedge) { lastv = knife_split_edge(kcd, kcd->curedge, kcd->vertco, &kfe3); knife_get_edge_faces(kcd, kcd->curedge, &lastfaces); } @@ -664,7 +671,7 @@ static void knife_cut_through(knifetool_opdata *kcd) for (r = kfe->faces.first; r; r = r->next) { f = r->ref; found = 0; - for (j = i+1, lh2 = lh+1; j < kcd->totlinehit; j++, lh2++) { + for (j = i + 1, lh2 = lh + 1; j < kcd->totlinehit; j++, lh2++) { kfe2 = lh2->kfe; for (r2 = kfe2->faces.first; r2; r2 = r2->next) { if (r2->ref == f) { @@ -706,12 +713,13 @@ static void knife_cut_through(knifetool_opdata *kcd) static void knife_add_cut(knifetool_opdata *kcd) { - /*BMEditMesh *em = kcd->em;*/ /*UNUSED*/ + /* BMEditMesh *em = kcd->em;*/ /* UNUSED */ knifetool_opdata oldkcd = *kcd; if (kcd->cut_through) { knife_cut_through(kcd); - } else if (kcd->linehits) { + } + else if (kcd->linehits) { BMEdgeHit *lh, *lastlh, *firstlh; int i; @@ -719,19 +727,20 @@ static void knife_add_cut(knifetool_opdata *kcd) lh = kcd->linehits; lastlh = firstlh = NULL; - for (i=0; i<kcd->totlinehit; i++, (lastlh=lh), lh++) { + for (i = 0; i < kcd->totlinehit; i++, (lastlh = lh), lh++) { BMFace *f = lastlh ? lastlh->f : lh->f; if (lastlh && len_v3v3(lastlh->hit, lh->hit) == 0.0f) { if (!firstlh) firstlh = lastlh; continue; - } else if (lastlh && firstlh) { + } + else if (lastlh && firstlh) { if (firstlh->v || lastlh->v) { KnifeVert *kfv = firstlh->v ? firstlh->v : lastlh->v; kcd->prevvert = kfv; - copy_v3_v3(kcd->prevco, firstlh->hit); + copy_v3_v3(kcd->prevco, firstlh->hit); copy_v3_v3(kcd->prevcage, firstlh->cagehit); kcd->prevedge = NULL; kcd->prevbmface = f; @@ -739,9 +748,9 @@ static void knife_add_cut(knifetool_opdata *kcd) lastlh = firstlh = NULL; } - if (len_v3v3(kcd->prevcage, lh->realhit) < FLT_EPSILON*80) + if (len_v3v3(kcd->prevcage, lh->realhit) < FLT_EPSILON * 80) continue; - if (len_v3v3(kcd->vertcage, lh->realhit) < FLT_EPSILON*80) + if (len_v3v3(kcd->vertcage, lh->realhit) < FLT_EPSILON * 80) continue; if (kcd->prev_is_space || kcd->is_space) { @@ -775,7 +784,8 @@ static void knife_add_cut(knifetool_opdata *kcd) MEM_freeN(kcd->linehits); kcd->linehits = NULL; kcd->totlinehit = 0; - } else { + } + else { knife_add_single_cut(kcd); } } @@ -821,17 +831,19 @@ static void knifetool_draw_angle_snapping(knifetool_opdata *kcd) if (dy > dx) { u1[0] = wminx; u1[1] = u[1] - dx; - } else { + } + else { u1[0] = u[0] - dy; u1[1] = wminy; } - /*clip against right or top */ + /* clip against right or top */ dx = wmaxx - u[0]; dy = wmaxy - u[1]; if (dy > dx) { u2[0] = wmaxx; u2[1] = u[1] + dx; - } else { + } + else { u2[0] = u[0] + dy; u2[1] = wmaxy; } @@ -843,17 +855,19 @@ static void knifetool_draw_angle_snapping(knifetool_opdata *kcd) if (dy > dx) { u1[0] = wmaxx; u1[1] = u[1] - dx; - } else { + } + else { u1[0] = u[0] + dy; u1[1] = wminy; } - /*clip against left or top */ + /* clip against left or top */ dx = u[0] - wminx; dy = wmaxy - u[1]; if (dy > dx) { u2[0] = wminx; u2[1] = u[1] + dx; - } else { + } + else { u2[0] = u[0] - dy; u2[1] = wmaxy; } @@ -898,11 +912,11 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glLineWidth(2.0); glBegin(GL_LINES); - glVertex3fv(kcd->prevcage); + glVertex3fv(kcd->prevcage); glVertex3fv(kcd->vertcage); glEnd(); - glLineWidth(1.0); + glLineWidth(1.0); } if (kcd->curedge) { @@ -910,12 +924,13 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glLineWidth(2.0); glBegin(GL_LINES); - glVertex3fv(kcd->curedge->v1->cageco); + glVertex3fv(kcd->curedge->v1->cageco); glVertex3fv(kcd->curedge->v2->cageco); glEnd(); glLineWidth(1.0); - } else if (kcd->curvert) { + } + else if (kcd->curvert) { glColor3f(0.8, 0.2, 0.1); glPointSize(11); @@ -940,23 +955,24 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /*draw any snapped verts first*/ + /* draw any snapped verts first */ glColor4f(0.8, 0.2, 0.1, 0.4); glPointSize(11); glBegin(GL_POINTS); lh = kcd->linehits; - for (i=0; i<kcd->totlinehit; i++, lh++) { + for (i = 0; i < kcd->totlinehit; i++, lh++) { float sv1[3], sv2[3]; knife_project_v3(kcd, lh->kfe->v1->cageco, sv1); knife_project_v3(kcd, lh->kfe->v2->cageco, sv2); knife_project_v3(kcd, lh->cagehit, lh->schit); - if (len_v2v2(lh->schit, sv1) < kcd->vthresh/4) { + if (len_v2v2(lh->schit, sv1) < kcd->vthresh / 4.0f) { copy_v3_v3(lh->cagehit, lh->kfe->v1->cageco); glVertex3fv(lh->cagehit); lh->v = lh->kfe->v1; - } else if (len_v2v2(lh->schit, sv2) < kcd->vthresh/4) { + } + else if (len_v2v2(lh->schit, sv2) < kcd->vthresh / 4.0f) { copy_v3_v3(lh->cagehit, lh->kfe->v2->cageco); glVertex3fv(lh->cagehit); lh->v = lh->kfe->v2; @@ -964,12 +980,12 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void } glEnd(); - /*now draw the rest*/ + /* now draw the rest */ glColor4f(0.1, 0.8, 0.05, 0.4); glPointSize(7); glBegin(GL_POINTS); lh = kcd->linehits; - for (i=0; i<kcd->totlinehit; i++, lh++) { + for (i = 0; i < kcd->totlinehit; i++, lh++) { glVertex3fv(lh->cagehit); } glEnd(); @@ -984,7 +1000,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glBegin(GL_LINES); BLI_mempool_iternew(kcd->kedges, &iter); - for (kfe=BLI_mempool_iterstep(&iter); kfe; kfe=BLI_mempool_iterstep(&iter)) { + for (kfe = BLI_mempool_iterstep(&iter); kfe; kfe = BLI_mempool_iterstep(&iter)) { if (!kfe->draw) continue; @@ -994,8 +1010,8 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glVertex3fv(kfe->v2->cageco); } - glEnd(); - glLineWidth(1.0); + glEnd(); + glLineWidth(1.0); } if (kcd->totkvert > 0) { @@ -1006,7 +1022,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glBegin(GL_POINTS); BLI_mempool_iternew(kcd->kverts, &iter); - for (kfv=BLI_mempool_iterstep(&iter); kfv; kfv=BLI_mempool_iterstep(&iter)) { + for (kfv = BLI_mempool_iterstep(&iter); kfv; kfv = BLI_mempool_iterstep(&iter)) { if (!kfv->draw) continue; @@ -1015,7 +1031,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glVertex3fv(kfv->cageco); } - glEnd(); + glEnd(); } glPopMatrix(); @@ -1039,7 +1055,7 @@ static int UNUSED_FUNCTION(point_on_line)(float p[3], float v1[3], float v2[3]) d = len_v3v3(p, v1) / d; - if (d >= -FLT_EPSILON*10 || d <= 1.0+FLT_EPSILON*10) + if (d >= -FLT_EPSILON * 10 || d <= 1.0 + FLT_EPSILON * 10) return 1; } @@ -1048,9 +1064,9 @@ static int UNUSED_FUNCTION(point_on_line)(float p[3], float v1[3], float v2[3]) static float len_v3_tri_side_max(const float v1[3], const float v2[3], const float v3[3]) { - const float s1= len_v3v3(v1, v2); - const float s2= len_v3v3(v2, v3); - const float s3= len_v3v3(v3, v1); + const float s1 = len_v3v3(v1, v2); + const float s2 = len_v3v3(v2, v3); + const float s3 = len_v3v3(v3, v1); return MAX3(s1, s2, s3); } @@ -1059,44 +1075,44 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, const float v1[3], const float v2[3], const float v3[3], SmallHash *ehash, bglMats *mats, int *count) { - BVHTree *tree2 = BLI_bvhtree_new(3, FLT_EPSILON*4, 8, 8), *tree = BMBVH_BVHTree(bmtree); + BVHTree *tree2 = BLI_bvhtree_new(3, FLT_EPSILON * 4, 8, 8), *tree = BMBVH_BVHTree(bmtree); BMEdgeHit *edges = NULL; BLI_array_declare(edges); BVHTreeOverlap *results, *result; BMLoop **ls; float cos[9], uv[3], lambda; - unsigned int tot=0; + unsigned int tot = 0; int i, j; /* for comparing distances, error of intersection depends on triangle scale. * need to scale down before squaring for accurate comparison */ - const float depsilon= 50*FLT_EPSILON * len_v3_tri_side_max(v1, v2, v3); + const float depsilon = 50 * FLT_EPSILON * len_v3_tri_side_max(v1, v2, v3); const float depsilon_squared = depsilon * depsilon; - copy_v3_v3(cos, v1); - copy_v3_v3(cos+3, v2); - copy_v3_v3(cos+6, v3); + copy_v3_v3(cos + 0, v1); + copy_v3_v3(cos + 3, v2); + copy_v3_v3(cos + 6, v3); BLI_bvhtree_insert(tree2, 0, cos, 3); BLI_bvhtree_balance(tree2); result = results = BLI_bvhtree_overlap(tree, tree2, &tot); - for (i=0; i<tot; i++, result++) { + for (i = 0; i < tot; i++, result++) { float p[3]; ls = (BMLoop**)kcd->em->looptris[result->indexA]; - for (j=0; j<3; j++) { + for (j = 0; j < 3; j++) { BMLoop *l1 = ls[j]; BMFace *hitf; ListBase *lst = knife_get_face_kedges(kcd, l1->f); Ref *ref; - for (ref=lst->first; ref; ref=ref->next) { + for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; - //if (kfe == kcd->curedge || kfe== kcd->prevedge) + //if (kfe == kcd->curedge || kfe == kcd->prevedge) // continue; if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, uv)) { @@ -1120,22 +1136,23 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, if (kcd->cut_through) { hitf = FALSE; - } else { - /*check if this point is visible in the viewport*/ + } + else { + /* check if this point is visible in the viewport */ sub_v3_v3(view, p); normalize_v3(view); copy_v3_v3(no, view); mul_v3_fl(no, 0.003); - /*go towards view a bit*/ + /* go towards view a bit */ add_v3_v3(p, no); - /*ray cast*/ + /* ray cast */ hitf = BMBVH_RayCast(bmtree, p, no, NULL, NULL); } - /*ok, if visible add the new point*/ + /* ok, if visible add the new point */ if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { BMEdgeHit hit; @@ -1173,7 +1190,8 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, interp_v3_v3v3(hit.hit, kfe->v1->co, kfe->v2->co, perc); interp_v3_v3v3(hit.cagehit, kfe->v1->cageco, kfe->v2->cageco, perc); - } else { + } + else { copy_v3_v3(hit.hit, p); } knife_project_v3(kcd, hit.cagehit, hit.schit); @@ -1222,14 +1240,14 @@ static void knife_find_line_hits(knifetool_opdata *kcd) copy_v3_v3(v1, kcd->prevcage); copy_v3_v3(v2, kcd->vertcage); - /*project screen line's 3d coordinates back into 2d*/ + /* project screen line's 3d coordinates back into 2d */ knife_project_v3(kcd, v1, s1); knife_project_v3(kcd, v2, s2); if (len_v2v2(s1, s2) < 1) - return; + return; - /*unproject screen line*/ + /* unproject screen line */ ED_view3d_win_to_segment_clip(kcd->ar, kcd->vc.v3d, s1, v1, v3); ED_view3d_win_to_segment_clip(kcd->ar, kcd->vc.v3d, s2, v2, v4); @@ -1240,23 +1258,24 @@ static void knife_find_line_hits(knifetool_opdata *kcd) BLI_smallhash_init(ehash); - /*test two triangles of sceen line's plane*/ + /* test two triangles of sceen line's plane */ e1 = knife_edge_tri_isect(kcd, kcd->bmbvh, v1, v2, v3, ehash, &mats, &c1); e2 = knife_edge_tri_isect(kcd, kcd->bmbvh, v2, v3, v4, ehash, &mats, &c2); if (c1 && c2) { - e1 = MEM_reallocN(e1, sizeof(BMEdgeHit)*(c1+c2)); - memcpy(e1+c1, e2, sizeof(BMEdgeHit)*c2); + e1 = MEM_reallocN(e1, sizeof(BMEdgeHit) * (c1 + c2)); + memcpy(e1 + c1, e2, sizeof(BMEdgeHit) * c2); MEM_freeN(e2); - } else if (c2) { + } + else if (c2) { e1 = e2; } kcd->linehits = e1; - kcd->totlinehit = c1+c2; + kcd->totlinehit = c1 + c2; - /*find position along screen line, used for sorting*/ - for (i=0; i<kcd->totlinehit; i++) { - BMEdgeHit *lh = e1+i; + /* find position along screen line, used for sorting */ + for (i = 0; i < kcd->totlinehit; i++) { + BMEdgeHit *lh = e1 + i; lh->l = len_v2v2(lh->schit, s1) / len_v2v2(s2, s1); } @@ -1275,16 +1294,18 @@ static void knife_input_ray_cast(knifetool_opdata *kcd, const int mval_i[2], mval[0] = (float)mval_i[0]; mval[1] = (float)mval_i[1]; - /*unproject to find view ray*/ + /* unproject to find view ray */ view3d_unproject(&mats, r_origin, mval[0], mval[1], 0.0f); - if(kcd->is_ortho) + if (kcd->is_ortho) { negate_v3_v3(r_ray, kcd->vc.rv3d->viewinv[2]); - else + } + else { sub_v3_v3v3(r_ray, r_origin, kcd->vc.rv3d->viewinv[3]); + } normalize_v3(r_ray); - /*transform into object space*/ + /* transform into object space */ invert_m4_m4(kcd->ob->imat, kcd->ob->obmat); copy_m3_m4(imat, kcd->ob->obmat); invert_m3(imat); @@ -1297,21 +1318,21 @@ static void knife_input_ray_cast(knifetool_opdata *kcd, const int mval_i[2], static BMFace *knife_find_closest_face(knifetool_opdata *kcd, float co[3], float cageco[3], int *is_space) { BMFace *f; - int dist = KMAXDIST; + int dist = KMAXDIST; float origin[3]; float ray[3]; - /*unproject to find view ray*/ + /* unproject to find view ray */ knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); add_v3_v3v3(co, origin, ray); f = BMBVH_RayCast(kcd->bmbvh, origin, ray, co, cageco); if (is_space) - *is_space = !f; + *is_space = !f; if (!f) { - /*try to use backbuffer selection method if ray casting failed*/ + /* try to use backbuffer selection method if ray casting failed */ f = EDBM_findnearestface(&kcd->vc, &dist); /* cheat for now; just put in the origin instead @@ -1323,8 +1344,8 @@ static BMFace *knife_find_closest_face(knifetool_opdata *kcd, float co[3], float return f; } -/*find the 2d screen space density of vertices within a radius. used to scale snapping - distance for picking edges/verts.*/ +/* find the 2d screen space density of vertices within a radius. used to scale snapping + * distance for picking edges/verts.*/ static int knife_sample_screen_density(knifetool_opdata *kcd, float radius) { BMFace *f; @@ -1342,27 +1363,28 @@ static int knife_sample_screen_density(knifetool_opdata *kcd, float radius) knife_project_v3(kcd, cageco, sco); lst = knife_get_face_kedges(kcd, f); - for (ref=lst->first; ref; ref=ref->next) { + for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; int i; - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) { KnifeVert *kfv = i ? kfe->v2 : kfe->v1; knife_project_v3(kcd, kfv->cageco, kfv->sco); dis = len_v2v2(kfv->sco, sco); if (dis < radius) { - if(kcd->vc.rv3d->rflag & RV3D_CLIPPING) { + if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) { float vec[3]; copy_v3_v3(vec, kfv->cageco); mul_m4_v3(kcd->vc.obedit->obmat, vec); - if(ED_view3d_test_clipping(kcd->vc.rv3d, vec, 1)==0) { + if (ED_view3d_test_clipping(kcd->vc.rv3d, vec, 1) == 0) { c++; } - } else { + } + else { c++; } } @@ -1375,18 +1397,18 @@ static int knife_sample_screen_density(knifetool_opdata *kcd, float radius) return 0; } -/*returns snapping distance for edges/verts, scaled by the density of the - surrounding mesh (in screen space)*/ +/* returns snapping distance for edges/verts, scaled by the density of the + * surrounding mesh (in screen space)*/ static float knife_snap_size(knifetool_opdata *kcd, float maxsize) { - float density = (float)knife_sample_screen_density(kcd, maxsize*2.0f); + float density = (float)knife_sample_screen_density(kcd, maxsize * 2.0f); density = MAX2(density, 1); - return MIN2(maxsize / (density*0.5f), maxsize); + return MIN2(maxsize / (density * 0.5f), maxsize); } -/*p is closest point on edge to the mouse cursor*/ +/* p is closest point on edge to the mouse cursor */ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], float cagep[3], BMFace **fptr, int *is_space) { BMFace *f; @@ -1398,7 +1420,7 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo f = knife_find_closest_face(kcd, co, cageco, NULL); *is_space = !f; - /*set p to co, in case we don't find anything, means a face cut*/ + /* set p to co, in case we don't find anything, means a face cut */ copy_v3_v3(p, co); copy_v3_v3(cagep, cageco); @@ -1408,37 +1430,38 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo KnifeEdge *cure = NULL; ListBase *lst; Ref *ref; - float dis, curdis=FLT_MAX; + float dis, curdis = FLT_MAX; knife_project_v3(kcd, cageco, sco); - /*look through all edges associated with this face*/ + /* look through all edges associated with this face */ lst = knife_get_face_kedges(kcd, f); - for (ref=lst->first; ref; ref=ref->next) { + for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; - /*project edge vertices into screen space*/ + /* project edge vertices into screen space */ knife_project_v3(kcd, kfe->v1->cageco, kfe->v1->sco); knife_project_v3(kcd, kfe->v2->cageco, kfe->v2->sco); dis = dist_to_line_segment_v2(sco, kfe->v1->sco, kfe->v2->sco); if (dis < curdis && dis < maxdist) { - if(kcd->vc.rv3d->rflag & RV3D_CLIPPING) { - float labda= labda_PdistVL2Dfl(sco, kfe->v1->sco, kfe->v2->sco); + if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) { + float labda = labda_PdistVL2Dfl(sco, kfe->v1->sco, kfe->v2->sco); float vec[3]; - vec[0]= kfe->v1->cageco[0] + labda*(kfe->v2->cageco[0] - kfe->v1->cageco[0]); - vec[1]= kfe->v1->cageco[1] + labda*(kfe->v2->cageco[1] - kfe->v1->cageco[1]); - vec[2]= kfe->v1->cageco[2] + labda*(kfe->v2->cageco[2] - kfe->v1->cageco[2]); + vec[0] = kfe->v1->cageco[0] + labda*(kfe->v2->cageco[0] - kfe->v1->cageco[0]); + vec[1] = kfe->v1->cageco[1] + labda*(kfe->v2->cageco[1] - kfe->v1->cageco[1]); + vec[2] = kfe->v1->cageco[2] + labda*(kfe->v2->cageco[2] - kfe->v1->cageco[2]); mul_m4_v3(kcd->vc.obedit->obmat, vec); - if(ED_view3d_test_clipping(kcd->vc.rv3d, vec, 1)==0) { + if (ED_view3d_test_clipping(kcd->vc.rv3d, vec, 1) == 0) { cure = kfe; curdis = dis; } - } else { + } + else { cure = kfe; - curdis = dis; + curdis = dis; } } } @@ -1451,14 +1474,16 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo if (kcd->snap_midpoints) { mid_v3_v3v3(p, cure->v1->co, cure->v2->co); mid_v3_v3v3(cagep, cure->v1->cageco, cure->v2->cageco); - } else { + } + else { float d; closest_to_line_segment_v3(cagep, cageco, cure->v1->cageco, cure->v2->cageco); d = len_v3v3(cagep, cure->v1->cageco) / len_v3v3(cure->v1->cageco, cure->v2->cageco); interp_v3_v3v3(p, cure->v1->co, cure->v2->co, d); } - } else { + } + else { return NULL; } } @@ -1472,7 +1497,7 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo return NULL; } -/*find a vertex near the mouse cursor, if it exists*/ +/* find a vertex near the mouse cursor, if it exists */ static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], float cagep[3], BMFace **fptr, int *is_space) { BMFace *f; @@ -1483,7 +1508,7 @@ static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], flo f = knife_find_closest_face(kcd, co, cageco, is_space); - /*set p to co, in case we don't find anything, means a face cut*/ + /* set p to co, in case we don't find anything, means a face cut */ copy_v3_v3(p, co); copy_v3_v3(cagep, p); kcd->curbmface = f; @@ -1492,35 +1517,36 @@ static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], flo ListBase *lst; Ref *ref; KnifeVert *curv = NULL; - float dis, curdis=FLT_MAX; + float dis, curdis = FLT_MAX; knife_project_v3(kcd, cageco, sco); lst = knife_get_face_kedges(kcd, f); - for (ref=lst->first; ref; ref=ref->next) { + for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; int i; - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) { KnifeVert *kfv = i ? kfe->v2 : kfe->v1; knife_project_v3(kcd, kfv->cageco, kfv->sco); dis = len_v2v2(kfv->sco, sco); if (dis < curdis && dis < maxdist) { - if(kcd->vc.rv3d->rflag & RV3D_CLIPPING) { + if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) { float vec[3]; copy_v3_v3(vec, kfv->cageco); mul_m4_v3(kcd->vc.obedit->obmat, vec); - if(ED_view3d_test_clipping(kcd->vc.rv3d, vec, 1)==0) { + if (ED_view3d_test_clipping(kcd->vc.rv3d, vec, 1) == 0) { curv = kfv; curdis = dis; } - } else { + } + else { curv = kfv; - curdis = dis; + curdis = dis; } } } @@ -1536,7 +1562,8 @@ static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], flo } return curv; - } else { + } + else { if (fptr) *fptr = f; @@ -1565,21 +1592,24 @@ static void knife_snap_angle(knifetool_opdata *kcd) if (abs_tan <= 0.4142f) { /* tan(22.5 degrees) = 0.4142 */ kcd->angle_snapping = ANGLE_0; kcd->vc.mval[1] = kcd->prevmval[1]; - } else if (abs_tan < 2.4142f) { /* tan(67.5 degrees) = 2.4142 */ + } + else if (abs_tan < 2.4142f) { /* tan(67.5 degrees) = 2.4142 */ if (w > 0) { kcd->angle_snapping = ANGLE_45; kcd->vc.mval[1] = kcd->prevmval[1] + dx; - } else { + } + else { kcd->angle_snapping = ANGLE_135; kcd->vc.mval[1] = kcd->prevmval[1] - dx; } - } else { + } + else { kcd->angle_snapping = ANGLE_90; kcd->vc.mval[0] = kcd->prevmval[0]; } } -/*update active knife edge/vert pointers*/ +/* update active knife edge/vert pointers */ static int knife_update_active(knifetool_opdata *kcd) { if (kcd->angle_snapping != ANGLE_FREE && kcd->mode == MODE_DRAGGING) @@ -1596,7 +1626,7 @@ static int knife_update_active(knifetool_opdata *kcd) * get a point at the mouse ray closest to the previous point. * Note that drawing lines in `free-space` isn't properly supported * but theres no guarantee (0,0,0) has any geometry either - campell */ - if(kcd->curvert == NULL && kcd->curedge == NULL) { + if (kcd->curvert == NULL && kcd->curedge == NULL) { float origin[3], ray[3], co[3]; knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); @@ -1628,7 +1658,7 @@ static void rnd_offset_co(float co[3], float scale) { int i; - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { co[i] += (BLI_drand()-0.5)*scale; } } @@ -1636,7 +1666,7 @@ static void rnd_offset_co(float co[3], float scale) static void remerge_faces(knifetool_opdata *kcd) { BMesh *bm = kcd->em->bm; - SmallHash svisit, *visit=&svisit; + SmallHash svisit, *visit = &svisit; BMIter iter; BMFace *f; BMFace **stack = NULL; @@ -1712,7 +1742,7 @@ static void remerge_faces(knifetool_opdata *kcd) BLI_array_free(faces); } -/*use edgenet to fill faces. this is a bit annoying and convoluted.*/ +/* use edgenet to fill faces. this is a bit annoying and convoluted.*/ static void knifenet_fill_faces(knifetool_opdata *kcd) { BMesh *bm = kcd->em->bm; @@ -1724,11 +1754,11 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) KnifeEdge *kfe; facenet_entry *entry; ListBase *face_nets = MEM_callocN(sizeof(ListBase)*bm->totface, "face_nets"); - BMFace **faces = MEM_callocN(sizeof(BMFace*)*bm->totface, "faces knife"); - MemArena *arena = BLI_memarena_new(1<<16, "knifenet_fill_faces"); + BMFace **faces = MEM_callocN(sizeof(BMFace *) * bm->totface, "faces knife"); + MemArena *arena = BLI_memarena_new(1 << 16, "knifenet_fill_faces"); SmallHash shash, *hash = &shash; - /* SmallHash shash2, *visited = &shash2; */ /*UNUSED*/ - int i, j, k=0, totface=bm->totface; + /* SmallHash shash2, *visited = &shash2; */ /* UNUSED */ + int i, j, k = 0, totface = bm->totface; BMO_push(bm, NULL); bmesh_begin_edit(bm, BMOP_UNTAN_MULTIRES); @@ -1746,15 +1776,16 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BMO_SetFlag(bm, e, BOUNDARY); } - /*turn knife verts into real verts, as necassary*/ + /* turn knife verts into real verts, as necassary */ BLI_mempool_iternew(kcd->kverts, &iter); - for (kfv=BLI_mempool_iterstep(&iter); kfv; kfv=BLI_mempool_iterstep(&iter)) { + for (kfv = BLI_mempool_iterstep(&iter); kfv; kfv = BLI_mempool_iterstep(&iter)) { if (!kfv->v) { /* shouldn't we be at least copying the normal? - if not some comment here should explain why - campbell */ kfv->v = BM_Make_Vert(bm, kfv->co, NULL); kfv->flag = 1; BMO_SetFlag(bm, kfv->v, DEL); - } else { + } + else { kfv->flag = 0; BMO_SetFlag(bm, kfv->v, VERT_ORIG); } @@ -1762,11 +1793,11 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BMO_SetFlag(bm, kfv->v, MARK); } - /*we want to only do changed faces. first, go over new edges and add to - face net lists.*/ - i=0; j=0; k=0; + /* we want to only do changed faces. first, go over new edges and add to + * face net lists.*/ + i = j = k = 0; BLI_mempool_iternew(kcd->kedges, &iter); - for (kfe=BLI_mempool_iterstep(&iter); kfe; kfe=BLI_mempool_iterstep(&iter)) { + for (kfe = BLI_mempool_iterstep(&iter); kfe; kfe = BLI_mempool_iterstep(&iter)) { Ref *ref; if (!kfe->v1 || !kfe->v2 || kfe->v1->inspace || kfe->v2->inspace) continue; @@ -1791,18 +1822,18 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) kfe->e = BM_Make_Edge(bm, kfe->v1->v, kfe->v2->v, NULL, TRUE); BMO_SetFlag(bm, kfe->e, BOUNDARY); - for (ref=kfe->faces.first; ref; ref=ref->next) { + for (ref = kfe->faces.first; ref; ref = ref->next) { f = ref->ref; entry = BLI_memarena_alloc(arena, sizeof(*entry)); entry->kfe = kfe; - BLI_addtail(face_nets+BM_GetIndex(f), entry); + BLI_addtail(face_nets + BM_GetIndex(f), entry); } } - /*go over original edges, and add to faces with new geometry*/ + /* go over original edges, and add to faces with new geometry */ BLI_mempool_iternew(kcd->kedges, &iter); - for (kfe=BLI_mempool_iterstep(&iter); kfe; kfe=BLI_mempool_iterstep(&iter)) { + for (kfe = BLI_mempool_iterstep(&iter); kfe; kfe = BLI_mempool_iterstep(&iter)) { Ref *ref; if (!kfe->v1 || !kfe->v2 || kfe->v1->inspace || kfe->v2->inspace) @@ -1815,22 +1846,22 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BMO_SetFlag(bm, kfe->e, BOUNDARY); kfe->oe = kfe->e; - for (ref=kfe->faces.first; ref; ref=ref->next) { + for (ref = kfe->faces.first; ref; ref = ref->next) { f = ref->ref; if (face_nets[BM_GetIndex(f)].first) { entry = BLI_memarena_alloc(arena, sizeof(*entry)); entry->kfe = kfe; - BLI_addtail(face_nets+BM_GetIndex(f), entry); + BLI_addtail(face_nets + BM_GetIndex(f), entry); } } } - for (i=0; i<totface; i++) { + for (i = 0; i < totface; i++) { EditFace *efa; EditVert *eve, *lasteve; int j; - float rndscale = FLT_EPSILON*25; + float rndscale = FLT_EPSILON * 25; f = faces[i]; BLI_smallhash_init(hash); @@ -1840,7 +1871,7 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BLI_begin_edgefill(); - for (entry=face_nets[i].first; entry; entry=entry->next) { + for (entry = face_nets[i].first; entry; entry = entry->next) { if (!BLI_smallhash_haskey(hash, (intptr_t)entry->kfe->v1)) { eve = BLI_addfillvert(entry->kfe->v1->v->co); eve->xs = 0; @@ -1858,7 +1889,7 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) } } - for (j=0, entry=face_nets[i].first; entry; entry=entry->next, j++) { + for (j = 0, entry = face_nets[i].first; entry; entry = entry->next, j++) { lasteve = BLI_smallhash_lookup(hash, (intptr_t)entry->kfe->v1); eve = BLI_smallhash_lookup(hash, (intptr_t)entry->kfe->v2); @@ -1866,7 +1897,7 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) lasteve->xs++; } - for (j=0, entry=face_nets[i].first; entry; entry=entry->next, j++) { + for (j = 0, entry = face_nets[i].first; entry; entry = entry->next, j++) { lasteve = BLI_smallhash_lookup(hash, (intptr_t)entry->kfe->v1); eve = BLI_smallhash_lookup(hash, (intptr_t)entry->kfe->v2); @@ -1878,7 +1909,8 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BMO_ClearFlag(bm, entry->kfe->e->v1, DEL); BMO_ClearFlag(bm, entry->kfe->e->v2, DEL); - } else { + } + else { if (lasteve->xs < 2) BLI_remlink(&fillvertbase, lasteve); if (eve->xs < 2) @@ -1888,14 +1920,14 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BLI_edgefill(0); - for (efa=fillfacebase.first; efa; efa=efa->next) { - BMVert *v1=efa->v3->tmp.p, *v2=efa->v2->tmp.p, *v3=efa->v1->tmp.p; + for (efa = fillfacebase.first; efa; efa = efa->next) { + BMVert *v1 = efa->v3->tmp.p, *v2 = efa->v2->tmp.p, *v3 = efa->v1->tmp.p; BMFace *f2; BMLoop *l; BMVert *verts[3] = {v1, v2, v3}; if (v1 == v2 || v2 == v3 || v1 == v3) - continue; + continue; if (BM_Face_Exists(bm, verts, 3, &f2)) continue; @@ -1928,7 +1960,7 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) /* interpolate customdata */ BM_ITER(f, &bmiter, bm, BM_FACES_OF_MESH, NULL) { BMLoop *l1; - BMFace *f2; + BMFace *f2; BMIter liter1; if (!BMO_TestFlag(bm, f, FACE_NEW)) @@ -1946,10 +1978,10 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) } } - /*merge triangles back into faces*/ + /* merge triangles back into faces */ remerge_faces(kcd); - /*delete left over faces*/ + /* delete left over faces */ BMO_CallOpf(bm, "del geom=%ff context=%i", DEL, DEL_ONLYFACES); BMO_CallOpf(bm, "del geom=%fe context=%i", DEL, DEL_EDGES); BMO_CallOpf(bm, "del geom=%fv context=%i", DEL, DEL_VERTS); @@ -1959,18 +1991,18 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) if (faces) MEM_freeN(faces); BLI_memarena_free(arena); - BLI_smallhash_release(hash); + BLI_smallhash_release(hash); - BMO_ClearStack(bm); /*remerge_faces sometimes raises errors, so make sure to clear them*/ + BMO_ClearStack(bm); /* remerge_faces sometimes raises errors, so make sure to clear them */ bmesh_end_edit(bm, BMOP_UNTAN_MULTIRES); BMO_pop(bm); } -/*called on tool confirmation*/ +/* called on tool confirmation */ static void knifetool_finish(bContext *C, wmOperator *op) { - knifetool_opdata *kcd= op->customdata; + knifetool_opdata *kcd = op->customdata; knifenet_fill_faces(kcd); @@ -1978,10 +2010,10 @@ static void knifetool_finish(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM|ND_DATA, kcd->ob->data); } -/*copied from paint_image.c*/ +/* copied from paint_image.c */ static int project_knife_view_clip(View3D *v3d, RegionView3D *rv3d, float *clipsta, float *clipend) { - int orth= ED_view3d_clip_range_get(v3d, rv3d, clipsta, clipend); + int orth = ED_view3d_clip_range_get(v3d, rv3d, clipsta, clipend); if (orth) { /* only needed for ortho */ float fac = 2.0f / ((*clipend) - (*clipsta)); @@ -2010,7 +2042,7 @@ static void knife_recalc_projmat(knifetool_opdata *kcd) /* called when modal loop selection is done... */ static void knifetool_exit (bContext *UNUSED(C), wmOperator *op) { - knifetool_opdata *kcd= op->customdata; + knifetool_opdata *kcd = op->customdata; if (!kcd) return; @@ -2038,7 +2070,7 @@ static void knifetool_exit (bContext *UNUSED(C), wmOperator *op) /* destroy kcd itself */ MEM_freeN(kcd); - op->customdata= NULL; + op->customdata = NULL; } static void cage_mapped_verts_callback(void *userData, int index, float *co, @@ -2066,21 +2098,21 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) void *data[3]; /* alloc new customdata */ - kcd= op->customdata= MEM_callocN(sizeof(knifetool_opdata), "knifetool Modal Op Data"); + kcd = op->customdata = MEM_callocN(sizeof(knifetool_opdata), "knifetool Modal Op Data"); /* assign the drawing handle for drawing preview line... */ kcd->ob = obedit; - kcd->ar= CTX_wm_region(C); + kcd->ar = CTX_wm_region(C); kcd->C = C; - kcd->draw_handle= ED_region_draw_cb_activate(kcd->ar->type, knifetool_draw, kcd, REGION_DRAW_POST_VIEW); + kcd->draw_handle = ED_region_draw_cb_activate(kcd->ar->type, knifetool_draw, kcd, REGION_DRAW_POST_VIEW); em_setup_viewcontext(C, &kcd->vc); - kcd->em= ((Mesh *)kcd->ob->data)->edit_btmesh; + kcd->em = ((Mesh *)kcd->ob->data)->edit_btmesh; BM_ElemIndex_Ensure(kcd->em->bm, BM_VERT); cage = editbmesh_get_derived_cage_and_final(scene, obedit, kcd->em, &final, CD_MASK_DERIVEDMESH); - kcd->cagecos = MEM_callocN(sizeof(float)*3*kcd->em->bm->totvert, "knife cagecos"); + kcd->cagecos = MEM_callocN(sizeof(float) * 3 * kcd->em->bm->totvert, "knife cagecos"); data[0] = kcd->em; data[1] = kcd->cagecos; data[2] = &shash; @@ -2090,8 +2122,8 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) BLI_smallhash_release(&shash); kcd->bmbvh = BMBVH_NewBVH(kcd->em, BMBVH_USE_CAGE|BMBVH_RETURN_ORIG, scene, obedit); - kcd->arena = BLI_memarena_new(1<<15, "knife"); - kcd->vthresh = KMAXDIST-1; + kcd->arena = BLI_memarena_new(1 << 15, "knife"); + kcd->vthresh = KMAXDIST - 1; kcd->ethresh = KMAXDIST; kcd->extend = 1; @@ -2141,7 +2173,7 @@ static int knifetool_invoke (bContext *C, wmOperator *op, wmEvent *evt) } enum { - KNF_MODAL_CANCEL=1, + KNF_MODAL_CANCEL = 1, KNF_MODAL_CONFIRM, KNF_MODAL_MIDPOINT_ON, KNF_MODAL_MIDPOINT_OFF, @@ -2167,12 +2199,12 @@ wmKeyMap* knifetool_modal_keymap(wmKeyConfig *keyconf) {0, NULL, 0, NULL, NULL}}; - wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Knife Tool Modal Map"); + wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Knife Tool Modal Map"); /* this function is called for each spacetype, only needs to add map once */ - if(keymap) return NULL; + if (keymap) return NULL; - keymap= WM_modalkeymap_add(keyconf, "Knife Tool Modal Map", modal_items); + keymap = WM_modalkeymap_add(keyconf, "Knife Tool Modal Map", modal_items); /* items for modal map */ WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, KNF_MODAL_CONFIRM); @@ -2202,14 +2234,14 @@ wmKeyMap* knifetool_modal_keymap(wmKeyConfig *keyconf) static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) { Object *obedit; - knifetool_opdata *kcd= op->customdata; + knifetool_opdata *kcd = op->customdata; if (!C) { return OPERATOR_FINISHED; } obedit = CTX_data_edit_object(C); - if (!obedit || obedit->type != OB_MESH || ((Mesh*)obedit->data)->edit_btmesh != kcd->em) { + if (!obedit || obedit->type != OB_MESH || ((Mesh *)obedit->data)->edit_btmesh != kcd->em) { knifetool_exit(C, op); return OPERATOR_FINISHED; } @@ -2276,7 +2308,8 @@ static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) knife_finish_cut(kcd); kcd->mode = MODE_IDLE; } - } else if (kcd->mode != MODE_PANNING) { + } + else if (kcd->mode != MODE_PANNING) { knife_start_cut(kcd); kcd->mode = MODE_DRAGGING; } @@ -2284,7 +2317,8 @@ static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) ED_region_tag_redraw(kcd->ar); break; } - } else { /*non-modal-mapped events*/ + } + else { /* non-modal-mapped events */ switch (event->type) { case WHEELUPMOUSE: case WHEELDOWNMOUSE: @@ -2294,7 +2328,8 @@ static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) if (kcd->mode != MODE_PANNING) kcd->prevmode = kcd->mode; kcd->mode = MODE_PANNING; - } else { + } + else { kcd->mode = kcd->prevmode; } @@ -2322,16 +2357,16 @@ static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) void MESH_OT_knifetool (wmOperatorType *ot) { /* description */ - ot->name= "Knife Topology Tool"; - ot->idname= "MESH_OT_knifetool"; - ot->description= "Cut new topology"; + ot->name = "Knife Topology Tool"; + ot->idname = "MESH_OT_knifetool"; + ot->description = "Cut new topology"; /* callbacks */ - ot->invoke= knifetool_invoke; - ot->modal= knifetool_modal; - ot->cancel= knifetool_cancel; - ot->poll= ED_operator_editmesh_view3d; + ot->invoke = knifetool_invoke; + ot->modal = knifetool_modal; + ot->cancel = knifetool_cancel; + ot->poll = ED_operator_editmesh_view3d; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; } |