diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-02-10 22:09:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-02-10 22:09:19 +0400 |
commit | c1070b863bbf88bf65f5d7781ffd1f0a87c80749 (patch) | |
tree | 5f43d1660bd58a39d5692eb285d59fd80b9485ac /source/blender/editors/mesh/knifetool.c | |
parent | e25b59923b337dee7dae1ef77d171fc71e880d02 (diff) |
Style Cleanup
Diffstat (limited to 'source/blender/editors/mesh/knifetool.c')
-rwxr-xr-x | source/blender/editors/mesh/knifetool.c | 473 |
1 files changed, 254 insertions, 219 deletions
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; } |