diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-13 10:33:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-13 10:33:59 +0400 |
commit | b2667970d286761d31a7f9c9969a0b95428da200 (patch) | |
tree | 96f18e48268bf5c37bfb79b96d376f376efdbc00 /source/blender/editors | |
parent | 60d3b8f27b31fea67a91184868b20ed95bab458a (diff) |
style cleanup: uv editor
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/uvedit/uvedit_buttons.c | 40 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_draw.c | 150 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_ops.c | 774 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_parametrizer.c | 1044 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_smart_stitch.c | 170 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_unwrap_ops.c | 318 |
6 files changed, 1251 insertions, 1245 deletions
diff --git a/source/blender/editors/uvedit/uvedit_buttons.c b/source/blender/editors/uvedit/uvedit_buttons.c index 1b5cef6f07d..123fe58100f 100644 --- a/source/blender/editors/uvedit/uvedit_buttons.c +++ b/source/blender/editors/uvedit/uvedit_buttons.c @@ -58,7 +58,7 @@ #include "WM_api.h" #include "WM_types.h" -#define B_UVEDIT_VERTEX 3 +#define B_UVEDIT_VERTEX 3 /* UV Utilities */ @@ -138,27 +138,27 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block) } if (sima->flag & SI_COORDFLOATS) { - step= 1; - digits= 3; + step = 1; + digits = 3; } else { - step= 100; - digits= 2; + step = 100; + digits = 2; } uiBlockBeginAlign(block); - uiDefButF(block, NUM, B_UVEDIT_VERTEX, "X:", 10, 10, 145, 19, &uvedit_old_center[0], -10*imx, 10.0*imx, step, digits, ""); - uiDefButF(block, NUM, B_UVEDIT_VERTEX, "Y:", 165, 10, 145, 19, &uvedit_old_center[1], -10*imy, 10.0*imy, step, digits, ""); + uiDefButF(block, NUM, B_UVEDIT_VERTEX, "X:", 10, 10, 145, 19, &uvedit_old_center[0], -10 * imx, 10.0 * imx, step, digits, ""); + uiDefButF(block, NUM, B_UVEDIT_VERTEX, "Y:", 165, 10, 145, 19, &uvedit_old_center[1], -10 * imy, 10.0 * imy, step, digits, ""); uiBlockEndAlign(block); } } static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) { - SpaceImage *sima= CTX_wm_space_image(C); - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - Image *ima= sima->image; + SpaceImage *sima = CTX_wm_space_image(C); + Scene *scene = CTX_data_scene(C); + Object *obedit = CTX_data_edit_object(C); + Image *ima = sima->image; BMEditMesh *em; float center[2], delta[2]; int imx, imy; @@ -172,12 +172,12 @@ static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) uvedit_center(scene, em, ima, center); if (sima->flag & SI_COORDFLOATS) { - delta[0]= uvedit_old_center[0] - center[0]; - delta[1]= uvedit_old_center[1] - center[1]; + delta[0] = uvedit_old_center[0] - center[0]; + delta[1] = uvedit_old_center[1] - center[1]; } else { - delta[0]= uvedit_old_center[0]/imx - center[0]; - delta[1]= uvedit_old_center[1]/imy - center[1]; + delta[0] = uvedit_old_center[0] / imx - center[0]; + delta[1] = uvedit_old_center[1] / imy - center[1]; } uvedit_translate(scene, em, ima, delta); @@ -189,7 +189,7 @@ static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) static int image_panel_uv_poll(const bContext *C, PanelType *UNUSED(pt)) { - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); return ED_uvedit_test(obedit); } @@ -197,7 +197,7 @@ static void image_panel_uv(const bContext *C, Panel *pa) { uiBlock *block; - block= uiLayoutAbsoluteBlock(pa->layout); + block = uiLayoutAbsoluteBlock(pa->layout); uiBlockSetHandleFunc(block, do_uvedit_vertex, NULL); uvedit_vertex_buttons(C, block); @@ -207,11 +207,11 @@ void ED_uvedit_buttons_register(ARegionType *art) { PanelType *pt; - pt= MEM_callocN(sizeof(PanelType), "spacetype image panel uv"); + pt = MEM_callocN(sizeof(PanelType), "spacetype image panel uv"); strcpy(pt->idname, "IMAGE_PT_uv"); strcpy(pt->label, "UV Vertex"); - pt->draw= image_panel_uv; - pt->poll= image_panel_uv_poll; + pt->draw = image_panel_uv; + pt->poll = image_panel_uv_poll; BLI_addtail(&art->paneltypes, pt); } diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index ce5b6b92acb..c079388be1c 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -71,37 +71,37 @@ static void drawcursor_sima(SpaceImage *sima, ARegion *ar) ED_space_image_size(sima, &width, &height); ED_space_image_zoom(sima, ar, &zoomx, &zoomy); - w= zoomx*width/256.0f; - h= zoomy*height/256.0f; + w = zoomx * width / 256.0f; + h = zoomy * height / 256.0f; cpack(0xFFFFFF); glTranslatef(sima->cursor[0], sima->cursor[1], 0.0); - fdrawline(-0.05f/w, 0, 0, 0.05f/h); - fdrawline(0, 0.05f/h, 0.05f/w, 0.0f); - fdrawline(0.05f/w, 0.0f, 0.0f, -0.05f/h); - fdrawline(0.0f, -0.05f/h, -0.05f/w, 0.0f); + fdrawline(-0.05f / w, 0, 0, 0.05f / h); + fdrawline(0, 0.05f / h, 0.05f / w, 0.0f); + fdrawline(0.05f / w, 0.0f, 0.0f, -0.05f / h); + fdrawline(0.0f, -0.05f / h, -0.05f / w, 0.0f); setlinestyle(4); cpack(0xFF); - fdrawline(-0.05f/w, 0.0f, 0.0f, 0.05f/h); - fdrawline(0.0f, 0.05f/h, 0.05f/w, 0.0f); - fdrawline(0.05f/w, 0.0f, 0.0f, -0.05f/h); - fdrawline(0.0f, -0.05f/h, -0.05f/w, 0.0f); + fdrawline(-0.05f / w, 0.0f, 0.0f, 0.05f / h); + fdrawline(0.0f, 0.05f / h, 0.05f / w, 0.0f); + fdrawline(0.05f / w, 0.0f, 0.0f, -0.05f / h); + fdrawline(0.0f, -0.05f / h, -0.05f / w, 0.0f); setlinestyle(0.0f); cpack(0x0); - fdrawline(-0.020f/w, 0.0f, -0.1f/w, 0.0f); - fdrawline(0.1f/w, 0.0f, 0.020f/w, 0.0f); - fdrawline(0.0f, -0.020f/h, 0.0f, -0.1f/h); - fdrawline(0.0f, 0.1f/h, 0.0f, 0.020f/h); + fdrawline(-0.020f / w, 0.0f, -0.1f / w, 0.0f); + fdrawline(0.1f / w, 0.0f, 0.020f / w, 0.0f); + fdrawline(0.0f, -0.020f / h, 0.0f, -0.1f / h); + fdrawline(0.0f, 0.1f / h, 0.0f, 0.020f / h); setlinestyle(1); cpack(0xFFFFFF); - fdrawline(-0.020f/w, 0.0f, -0.1f/w, 0.0f); - fdrawline(0.1f/w, 0.0f, 0.020f/w, 0.0f); - fdrawline(0.0f, -0.020f/h, 0.0f, -0.1f/h); - fdrawline(0.0f, 0.1f/h, 0.0f, 0.020f/h); + fdrawline(-0.020f / w, 0.0f, -0.1f / w, 0.0f); + fdrawline(0.1f / w, 0.0f, 0.020f / w, 0.0f); + fdrawline(0.0f, -0.020f / h, 0.0f, -0.1f / h); + fdrawline(0.0f, 0.1f / h, 0.0f, 0.020f / h); glTranslatef(-sima->cursor[0], -sima->cursor[1], 0.0); setlinestyle(0); @@ -109,7 +109,7 @@ static void drawcursor_sima(SpaceImage *sima, ARegion *ar) static int draw_uvs_face_check(Scene *scene) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; /* checks if we are selecting only faces */ if (ts->uv_flag & UV_SYNC_SELECTION) { @@ -139,7 +139,7 @@ static void draw_uvs_shadow(Object *obedit) BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { glBegin(GL_LINE_LOOP); BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, efa) { - luv= CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); glVertex2fv(luv->uv); } @@ -168,7 +168,7 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe BMIter iter, liter; MTexPoly *tf; MLoopUV *luv; - Image *ima= sima->image; + Image *ima = sima->image; BLI_array_declare(tf_uv); BLI_array_declare(tf_uvorig); float aspx, aspy, col[4], (*tf_uv)[2] = NULL, (*tf_uvorig)[2] = NULL; @@ -176,13 +176,13 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe ED_space_image_uv_aspect(sima, &aspx, &aspy); - switch(sima->dt_uvstretch) { + switch (sima->dt_uvstretch) { case SI_UVDT_STRETCH_AREA: { - float totarea=0.0f, totuvarea=0.0f, areadiff, uvarea, area; + float totarea = 0.0f, totuvarea = 0.0f, areadiff, uvarea, area; BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); BLI_array_empty(tf_uv); BLI_array_empty(tf_uvorig); @@ -191,7 +191,7 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe i = 0; BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, efa) { - luv= CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(tf_uvorig[i], luv->uv); @@ -209,7 +209,7 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe } else { if (tf == activetf) - activetf= NULL; + activetf = NULL; BM_elem_flag_disable(efa, BM_ELEM_TAG); } } @@ -241,7 +241,7 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe i = 0; BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, efa) { - luv= CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(tf_uvorig[i], luv->uv); @@ -255,10 +255,10 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe if (area < FLT_EPSILON || uvarea < FLT_EPSILON) areadiff = 1.0f; - else if (area>uvarea) - areadiff = 1.0f-(uvarea/area); + else if (area > uvarea) + areadiff = 1.0f - (uvarea / area); else - areadiff = 1.0f-(area/uvarea); + areadiff = 1.0f - (area / uvarea); weight_to_rgb(col, areadiff); glColor3fv(col); @@ -278,8 +278,8 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe { float *uvang = NULL; float *ang = NULL; - float (* av)[3] = NULL; /* use for 2d and 3d angle vectors */ - float (* auv)[2] = NULL; + float (*av)[3] = NULL; /* use for 2d and 3d angle vectors */ + float (*auv)[2] = NULL; float a; BLI_array_declare(uvang); @@ -292,7 +292,7 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe glShadeModel(GL_SMOOTH); BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); if (uvedit_face_visible(scene, ima, efa, tf)) { nverts = efa->len; @@ -324,22 +324,22 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe j = i; } - for(i = 0; i < nverts; i++) { + for (i = 0; i < nverts; i++) { #if 0 /* Simple but slow, better reuse normalized vectors * (Not ported to bmesh, copied for reference) */ uvang1 = RAD2DEG(angle_v2v2v2(tf_uv[3], tf_uv[0], tf_uv[1])); ang1 = RAD2DEG(angle_v3v3v3(efa->v4->co, efa->v1->co, efa->v2->co)); #endif - uvang[i] = angle_normalized_v2v2(auv[i], auv[(i+1)%nverts]); - ang[i] = angle_normalized_v3v3(av[i], av[(i+1)%nverts]); + uvang[i] = angle_normalized_v2v2(auv[i], auv[(i + 1) % nverts]); + ang[i] = angle_normalized_v3v3(av[i], av[(i + 1) % nverts]); } glBegin(GL_POLYGON); BM_ITER_INDEX(l, &liter, bm, BM_LOOPS_OF_FACE, efa, i) { luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); - a = fabsf(uvang[i]-ang[i])/(float)M_PI; - weight_to_rgb(col, 1.0f-powf((1.0f-a), 2.0f)); + a = fabsf(uvang[i] - ang[i]) / (float)M_PI; + weight_to_rgb(col, 1.0f - powf((1.0f - a), 2.0f)); glColor3fv(col); glVertex2fv(luv->uv); } @@ -347,7 +347,7 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe } else { if (tf == activetf) - activetf= NULL; + activetf = NULL; BM_elem_flag_disable(efa, BM_ELEM_TAG); } } @@ -373,15 +373,15 @@ static void draw_uvs_other(Scene *scene, Object *obedit, Image *curimage) glColor3ub(96, 96, 96); - for (base=scene->base.first; base; base=base->next) { - Object *ob= base->object; + for (base = scene->base.first; base; base = base->next) { + Object *ob = base->object; if (!(base->flag & SELECT)) continue; if (!(base->lay & scene->lay)) continue; if (ob->restrictflag & OB_RESTRICT_VIEW) continue; - if ((ob->type==OB_MESH) && (ob!=obedit)) { - Mesh *me= ob->data; + if ((ob->type == OB_MESH) && (ob != obedit)) { + Mesh *me = ob->data; if (me->mtpoly) { MPoly *mpoly = me->mpoly; @@ -407,7 +407,7 @@ static void draw_uvs_other(Scene *scene, Object *obedit, Image *curimage) static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob) { - Mesh *me= ob->data; + Mesh *me = ob->data; Image *curimage = ED_space_image(sima); if (sima->flag & SI_DRAW_OTHER) @@ -416,17 +416,17 @@ static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob) glColor3ub(112, 112, 112); if (me->mtface) { - MPoly *mpoly= me->mpoly; - MTexPoly *tface= me->mtpoly; + MPoly *mpoly = me->mpoly; + MTexPoly *tface = me->mtpoly; MLoopUV *mloopuv; int a, b; - for (a=me->totpoly; a>0; a--, tface++, mpoly++) { + for (a = me->totpoly; a > 0; a--, tface++, mpoly++) { if (tface->tpage == curimage) { glBegin(GL_LINE_LOOP); mloopuv = me->mloopuv + mpoly->loopstart; - for (b=0; b<mpoly->totloop; b++, mloopuv++) { + for (b = 0; b < mpoly->totloop; b++, mloopuv++) { glVertex2fv(mloopuv->uv); } glEnd(); @@ -451,23 +451,23 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) unsigned char col1[4], col2[4]; float pointsize; int drawfaces, interpedges; - Image *ima= sima->image; + Image *ima = sima->image; StitchPreviewer *stitch_preview = uv_get_stitch_previewer(); - activetf= EDBM_mtexpoly_active_get(em, &efa_act, FALSE); /* will be set to NULL if hidden */ + activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE); /* will be set to NULL if hidden */ activef = BM_active_face_get(bm, FALSE); - ts= scene->toolsettings; + ts = scene->toolsettings; - drawfaces= draw_uvs_face_check(scene); + drawfaces = draw_uvs_face_check(scene); if (ts->uv_flag & UV_SYNC_SELECTION) - interpedges= (ts->selectmode & SCE_SELECT_VERTEX); + interpedges = (ts->selectmode & SCE_SELECT_VERTEX); else - interpedges= (ts->uv_selectmode == UV_SELECT_VERTEX); + interpedges = (ts->uv_selectmode == UV_SELECT_VERTEX); /* draw other uvs */ if (sima->flag & SI_DRAW_OTHER) { - Image *curimage= (activetf)? activetf->tpage: NULL; + Image *curimage = (activetf) ? activetf->tpage : NULL; draw_uvs_other(scene, obedit, curimage); } @@ -478,7 +478,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) /* first try existing derivedmesh */ if (!draw_uvs_dm_shadow(em->derivedFinal)) { /* create one if it does not exist */ - cagedm = editbmesh_get_derived_cage_and_final(scene, obedit, me->edit_btmesh, &finaldm, CD_MASK_BAREMESH|CD_MASK_MTFACE); + cagedm = editbmesh_get_derived_cage_and_final(scene, obedit, me->edit_btmesh, &finaldm, CD_MASK_BAREMESH | CD_MASK_MTFACE); /* when sync selection is enabled, all faces are drawn (except for hidden) * so if cage is the same as the final, theres no point in drawing this */ @@ -504,11 +504,11 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) glEnable(GL_BLEND); BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); if (uvedit_face_visible(scene, ima, efa, tf)) { BM_elem_flag_enable(efa, BM_ELEM_TAG); - if (tf==activetf) continue; /* important the temp boolean is set above */ + if (tf == activetf) continue; /* important the temp boolean is set above */ if (uvedit_face_selected(scene, em, efa)) glColor4ubv((GLubyte *)col2); @@ -524,7 +524,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) } else { if (tf == activetf) - activetf= NULL; + activetf = NULL; BM_elem_flag_disable(efa, BM_ELEM_TAG); } } @@ -534,14 +534,14 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) /* would be nice to do this within a draw loop but most below are optional, so it would involve too many checks */ BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); if (uvedit_face_visible(scene, ima, efa, tf)) { BM_elem_flag_enable(efa, BM_ELEM_TAG); } else { if (tf == activetf) - activetf= NULL; + activetf = NULL; BM_elem_flag_disable(efa, BM_ELEM_TAG); } } @@ -580,7 +580,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - switch(sima->dt_uv) { + switch (sima->dt_uv) { case SI_UVDT_DASH: BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) @@ -609,10 +609,10 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) #if 0 glBegin(GL_LINE_STRIP); - luv = CustomData_bmesh_get(&bm->ldata, efa->lbase->head.data, CD_MLOOPUV); - glVertex2fv(luv->uv); - luv = CustomData_bmesh_get(&bm->ldata, efa->lbase->next->head.data, CD_MLOOPUV); - glVertex2fv(luv->uv); + luv = CustomData_bmesh_get(&bm->ldata, efa->lbase->head.data, CD_MLOOPUV); + glVertex2fv(luv->uv); + luv = CustomData_bmesh_get(&bm->ldata, efa->lbase->next->head.data, CD_MLOOPUV); + glVertex2fv(luv->uv); glEnd(); #endif @@ -622,7 +622,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) break; case SI_UVDT_BLACK: /* black/white */ case SI_UVDT_WHITE: - if (sima->dt_uv==SI_UVDT_WHITE) glColor3f(1.0f, 1.0f, 1.0f); + if (sima->dt_uv == SI_UVDT_WHITE) glColor3f(1.0f, 1.0f, 1.0f); else glColor3f(0.0f, 0.0f, 0.0f); BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { @@ -670,7 +670,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) glBegin(GL_LINE_LOOP); BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, efa) { - sel = (uvedit_uv_selected(em, scene, l)? 1 : 0); + sel = (uvedit_uv_selected(em, scene, l) ? 1 : 0); glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); @@ -688,7 +688,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) glBegin(GL_LINES); BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, efa) { - sel = (uvedit_edge_selected(em, scene, l)? 1 : 0); + sel = (uvedit_edge_selected(em, scene, l) ? 1 : 0); if (sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; @@ -787,7 +787,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) /* pinned uvs */ /* give odd pointsizes odd pin pointsizes */ - glPointSize(pointsize*2 + (((int)pointsize % 2)? (-1): 0)); + glPointSize(pointsize * 2 + (((int)pointsize % 2) ? (-1) : 0)); cpack(0xFF); bglBegin(GL_POINTS); @@ -834,7 +834,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) UI_ThemeColor4(TH_STITCH_PREVIEW_ACTIVE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_tris); - glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_static_tris*3); + glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_static_tris * 3); glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_polys); for (i = 0; i < stitch_preview->num_polys; i++) { @@ -850,12 +850,12 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); #if 0 UI_ThemeColor4(TH_STITCH_PREVIEW_VERT); - glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3); + glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris * 3); #endif glDisable(GL_BLEND); /* draw vert preview */ - glPointSize(pointsize*2.0); + glPointSize(pointsize * 2.0); UI_ThemeColor4(TH_STITCH_PREVIEW_STITCHABLE); glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_stitchable); glDrawArrays(GL_POINTS, 0, stitch_preview->num_stitchable); @@ -877,8 +877,8 @@ void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedi int show_uvedit, show_uvshadow, show_texpaint_uvshadow; show_texpaint_uvshadow = (obact && obact->type == OB_MESH && obact->mode == OB_MODE_TEXTURE_PAINT); - show_uvedit= ED_space_image_show_uvedit(sima, obedit); - show_uvshadow= ED_space_image_show_uvshadow(sima, obedit); + show_uvedit = ED_space_image_show_uvedit(sima, obedit); + show_uvshadow = ED_space_image_show_uvshadow(sima, obedit); if (show_uvedit || show_uvshadow || show_texpaint_uvshadow) { if (show_uvshadow) diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 5609c8e716b..e1ee00be384 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -82,7 +82,7 @@ #include "uvedit_intern.h" -#define EFA_F1_FLAG 2 +#define EFA_F1_FLAG 2 /************************* state testing ************************/ @@ -105,18 +105,18 @@ int ED_uvedit_test(Object *obedit) static int ED_operator_uvedit_can_uv_sculpt(struct bContext *C) { - SpaceImage *sima= CTX_wm_space_image(C); + SpaceImage *sima = CTX_wm_space_image(C); ToolSettings *toolsettings = CTX_data_tool_settings(C); - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); return ED_space_image_show_uvedit(sima, obedit) && !(toolsettings->use_uv_sculpt); } -static int UNUSED_FUNCTION(ED_operator_uvmap_mesh)(bContext *C) +static int UNUSED_FUNCTION(ED_operator_uvmap_mesh) (bContext * C) { - Object *ob= CTX_data_active_object(C); + Object *ob = CTX_data_active_object(C); - if (ob && ob->type==OB_MESH) { + if (ob && ob->type == OB_MESH) { Mesh *me = ob->data; if (CustomData_get_layer(&me->fdata, CD_MTFACE) != NULL) @@ -134,30 +134,30 @@ static int is_image_texture_node(bNode *node) int ED_object_get_active_image(Object *ob, int mat_nr, Image **ima, ImageUser **iuser, bNode **node_r) { - Material *ma= give_current_material(ob, mat_nr); - bNode *node= (ma && ma->use_nodes)? nodeGetActiveTexture(ma->nodetree): NULL; + Material *ma = give_current_material(ob, mat_nr); + bNode *node = (ma && ma->use_nodes) ? nodeGetActiveTexture(ma->nodetree) : NULL; if (node && is_image_texture_node(node)) { - if (ima) *ima= (Image*)node->id; - if (iuser) *iuser= NULL; - if (node_r) *node_r= node; + if (ima) *ima = (Image *)node->id; + if (iuser) *iuser = NULL; + if (node_r) *node_r = node; return TRUE; } - if (ima) *ima= NULL; - if (iuser) *iuser= NULL; - if (node_r) *node_r= node; + if (ima) *ima = NULL; + if (iuser) *iuser = NULL; + if (node_r) *node_r = node; return FALSE; } void ED_object_assign_active_image(Main *bmain, Object *ob, int mat_nr, Image *ima) { - Material *ma= give_current_material(ob, mat_nr); - bNode *node= (ma && ma->use_nodes)? nodeGetActiveTexture(ma->nodetree): NULL; + Material *ma = give_current_material(ob, mat_nr); + bNode *node = (ma && ma->use_nodes) ? nodeGetActiveTexture(ma->nodetree) : NULL; if (node && is_image_texture_node(node)) { - node->id= &ima->id; + node->id = &ima->id; ED_node_generic_update(bmain, ma->nodetree, node); } } @@ -170,10 +170,10 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im BMFace *efa; BMIter iter; MTexPoly *tf; - int update= 0; + int update = 0; /* skip assigning these procedural images... */ - if (ima && (ima->type==IMA_TYPE_R_RESULT || ima->type==IMA_TYPE_COMPOSITE)) + if (ima && (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)) return; /* verify we have a mesh we can work with */ @@ -187,8 +187,8 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im if (scene_use_new_shading_nodes(scene)) { /* new shading system, assign image in material */ - int sloppy= 1; - BMFace *efa= BM_active_face_get(em->bm, sloppy); + int sloppy = 1; + BMFace *efa = BM_active_face_get(em->bm, sloppy); if (efa) ED_object_assign_active_image(bmain, obedit, efa->mat_nr + 1, ima); @@ -200,7 +200,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im if (!CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY)) { BM_data_layer_add(em->bm, &em->bm->pdata, CD_MTEXPOLY); BM_data_layer_add(em->bm, &em->bm->ldata, CD_MLOOPUV); - update= 1; + update = 1; } /* now assign to all visible faces */ @@ -209,13 +209,13 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im if (uvedit_face_visible(scene, previma, efa, tf)) { if (ima) { - tf->tpage= ima; + tf->tpage = ima; - if (ima->id.us==0) id_us_plus(&ima->id); + if (ima->id.us == 0) id_us_plus(&ima->id); else id_lib_extern(&ima->id); } else { - tf->tpage= NULL; + tf->tpage = NULL; } update = 1; @@ -229,8 +229,8 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im } -/* dotile - 1, set the tile flag (from the space image) - * 2, set the tile index for the faces. */ +/* dotile - 1, set the tile flag (from the space image) + * 2, set the tile index for the faces. */ static int uvedit_set_tile(Object *obedit, Image *ima, int curtile) { BMEditMesh *em; @@ -246,7 +246,7 @@ static int uvedit_set_tile(Object *obedit, Image *ima, int curtile) return 0; /* skip assigning these procedural images... */ - if (ima->type==IMA_TYPE_R_RESULT || ima->type==IMA_TYPE_COMPOSITE) + if (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) return 0; em = BMEdit_FromObject(obedit); @@ -255,7 +255,7 @@ static int uvedit_set_tile(Object *obedit, Image *ima, int curtile) tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BM_elem_flag_test(efa, BM_ELEM_SELECT)) - tf->tile= curtile; /* set tile index */ + tf->tile = curtile; /* set tile index */ } DAG_id_tag_update(obedit->data, 0); @@ -273,39 +273,39 @@ static void uvedit_pixel_to_float(SpaceImage *sima, float *dist, float pixeldist ED_space_image_size(sima, &width, &height); } else { - width= 256; - height= 256; + width = 256; + height = 256; } - dist[0]= pixeldist/width; - dist[1]= pixeldist/height; + dist[0] = pixeldist / width; + dist[1] = pixeldist / height; } /*************** visibility and selection utilities **************/ int uvedit_face_visible_nolocal(Scene *scene, BMFace *efa) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) - return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)==0); + return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN) == 0); else - return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)==0 && BM_elem_flag_test(efa, BM_ELEM_SELECT)); + return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN) == 0 && BM_elem_flag_test(efa, BM_ELEM_SELECT)); } int uvedit_face_visible(Scene *scene, Image *ima, BMFace *efa, MTexPoly *tf) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SHOW_SAME_IMAGE) - return (tf->tpage==ima)? uvedit_face_visible_nolocal(scene, efa): 0; + return (tf->tpage == ima) ? uvedit_face_visible_nolocal(scene, efa) : 0; else return uvedit_face_visible_nolocal(scene, efa); } int uvedit_face_selected(Scene *scene, BMEditMesh *em, BMFace *efa) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) return (BM_elem_flag_test(efa, BM_ELEM_SELECT)); @@ -326,7 +326,7 @@ int uvedit_face_selected(Scene *scene, BMEditMesh *em, BMFace *efa) int uvedit_face_select(Scene *scene, BMEditMesh *em, BMFace *efa) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) BM_elem_select_set(em->bm, efa, TRUE); @@ -348,7 +348,7 @@ int uvedit_face_select(Scene *scene, BMEditMesh *em, BMFace *efa) int uvedit_face_deselect(Scene *scene, BMEditMesh *em, BMFace *efa) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { BM_elem_select_set(em->bm, efa, FALSE); @@ -371,7 +371,7 @@ int uvedit_face_deselect(Scene *scene, BMEditMesh *em, BMFace *efa) int uvedit_edge_selected(BMEditMesh *em, Scene *scene, BMLoop *l) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->selectmode & SCE_SELECT_FACE) { @@ -398,7 +398,7 @@ int uvedit_edge_selected(BMEditMesh *em, Scene *scene, BMLoop *l) void uvedit_edge_select(BMEditMesh *em, Scene *scene, BMLoop *l) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->selectmode & SCE_SELECT_FACE) @@ -424,7 +424,7 @@ void uvedit_edge_select(BMEditMesh *em, Scene *scene, BMLoop *l) void uvedit_edge_deselect(BMEditMesh *em, Scene *scene, BMLoop *l) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->selectmode & SCE_SELECT_FACE) @@ -449,7 +449,7 @@ void uvedit_edge_deselect(BMEditMesh *em, Scene *scene, BMLoop *l) int uvedit_uv_selected(BMEditMesh *em, Scene *scene, BMLoop *l) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->selectmode & SCE_SELECT_FACE) @@ -466,7 +466,7 @@ int uvedit_uv_selected(BMEditMesh *em, Scene *scene, BMLoop *l) void uvedit_uv_select(BMEditMesh *em, Scene *scene, BMLoop *l) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->selectmode & SCE_SELECT_FACE) @@ -483,7 +483,7 @@ void uvedit_uv_select(BMEditMesh *em, Scene *scene, BMLoop *l) void uvedit_uv_deselect(BMEditMesh *em, Scene *scene, BMLoop *l) { - ToolSettings *ts= scene->toolsettings; + ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->selectmode & SCE_SELECT_FACE) @@ -563,25 +563,25 @@ float poly_uv_area(float uv[][2], int len) void poly_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float aspy, int len) { int i; - for (i=0; i<len; i++) { - uv[i][0] = uv_orig[i][0]*aspx; - uv[i][1] = uv_orig[i][1]*aspy; + for (i = 0; i < len; i++) { + uv[i][0] = uv_orig[i][0] * aspx; + uv[i][1] = uv_orig[i][1] * aspy; } } void uv_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float aspy) { - uv[0][0] = uv_orig[0][0]*aspx; - uv[0][1] = uv_orig[0][1]*aspy; + uv[0][0] = uv_orig[0][0] * aspx; + uv[0][1] = uv_orig[0][1] * aspy; - uv[1][0] = uv_orig[1][0]*aspx; - uv[1][1] = uv_orig[1][1]*aspy; + uv[1][0] = uv_orig[1][0] * aspx; + uv[1][1] = uv_orig[1][1] * aspy; - uv[2][0] = uv_orig[2][0]*aspx; - uv[2][1] = uv_orig[2][1]*aspy; + uv[2][0] = uv_orig[2][0] * aspx; + uv[2][1] = uv_orig[2][1] * aspy; - uv[3][0] = uv_orig[3][0]*aspx; - uv[3][1] = uv_orig[3][1]*aspy; + uv[3][0] = uv_orig[3][0] * aspx; + uv[3][1] = uv_orig[3][1] * aspy; } int ED_uvedit_minmax(Scene *scene, Image *ima, Object *obedit, float *min, float *max) @@ -596,7 +596,7 @@ int ED_uvedit_minmax(Scene *scene, Image *ima, Object *obedit, float *min, float INIT_MINMAX2(min, max); - sel= 0; + sel = 0; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) @@ -622,11 +622,11 @@ static int ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[2 BMIter iter, liter; MTexPoly *tf; MLoopUV *luv; - unsigned int sel= 0; + unsigned int sel = 0; zero_v2(co); BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; @@ -639,7 +639,7 @@ static int ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[2 } } - mul_v2_fl(co, 1.0f/(float)sel); + mul_v2_fl(co, 1.0f / (float)sel); return (sel != 0); } @@ -676,13 +676,13 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, float co[2], float mindist, dist; int i; - mindist= 1e10f; + mindist = 1e10f; memset(hit, 0, sizeof(*hit)); BM_mesh_elem_index_ensure(em->bm, BM_VERT); BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; @@ -691,11 +691,11 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, float co[2], luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); nextluv = CustomData_bmesh_get(&em->bm->ldata, l->next->head.data, CD_MLOOPUV); - dist= dist_to_line_segment_v2(co, luv->uv, nextluv->uv); + dist = dist_to_line_segment_v2(co, luv->uv, nextluv->uv); if (dist < mindist) { - hit->tf= tf; - hit->efa= efa; + hit->tf = tf; + hit->efa = efa; hit->l = l; hit->nextl = l->next; @@ -722,7 +722,7 @@ static void find_nearest_uv_face(Scene *scene, Image *ima, BMEditMesh *em, float MLoopUV *luv; float mindist, dist, cent[2]; - mindist= 1e10f; + mindist = 1e10f; memset(hit, 0, sizeof(*hit)); /*this will fill in hit.vert1 and hit.vert2*/ @@ -731,11 +731,11 @@ static void find_nearest_uv_face(Scene *scene, Image *ima, BMEditMesh *em, float hit->luv = hit->nextluv = NULL; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; - cent[0]= cent[1]= 0.0f; + cent[0] = cent[1] = 0.0f; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -744,18 +744,18 @@ static void find_nearest_uv_face(Scene *scene, Image *ima, BMEditMesh *em, float cent[0] /= efa->len; cent[1] /= efa->len; - dist= fabs(co[0]- cent[0]) + fabs(co[1]- cent[1]); + dist = fabs(co[0] - cent[0]) + fabs(co[1] - cent[1]); if (dist < mindist) { - hit->tf= tf; - hit->efa= efa; - mindist= dist; + hit->tf = tf; + hit->efa = efa; + mindist = dist; } } } static int nearest_uv_between(BMEditMesh *em, BMFace *efa, int UNUSED(nverts), int id, - float co[2], float uv[2]) + float co[2], float uv[2]) { BMLoop *l; MLoopUV *luv; @@ -763,11 +763,11 @@ static int nearest_uv_between(BMEditMesh *em, BMFace *efa, int UNUSED(nverts), i float m[3], v1[3], v2[3], c1, c2, *uv1, /* *uv2, */ /* UNUSED */ *uv3; int id1, id2, i; - id1= (id+efa->len-1)%efa->len; - id2= (id+efa->len+1)%efa->len; + id1 = (id + efa->len - 1) % efa->len; + id2 = (id + efa->len + 1) % efa->len; - m[0]= co[0]-uv[0]; - m[1]= co[1]-uv[1]; + m[0] = co[0] - uv[0]; + m[1] = co[1] - uv[1]; i = 0; BM_ITER(l, &iter, em->bm, BM_LOOPS_OF_FACE, efa) { @@ -776,7 +776,7 @@ static int nearest_uv_between(BMEditMesh *em, BMFace *efa, int UNUSED(nverts), i if (i == id1) uv1 = luv->uv; else if (i == id) - ; /* uv2 = luv->uv; */ /* UNUSED */ + ; /* uv2 = luv->uv; */ /* UNUSED */ else if (i == id2) uv3 = luv->uv; @@ -787,17 +787,17 @@ static int nearest_uv_between(BMEditMesh *em, BMFace *efa, int UNUSED(nverts), i sub_v3_v3v3(v2, uv3, uv); /* m and v2 on same side of v-v1? */ - c1= v1[0]*m[1] - v1[1]*m[0]; - c2= v1[0]*v2[1] - v1[1]*v2[0]; + c1 = v1[0] * m[1] - v1[1] * m[0]; + c2 = v1[0] * v2[1] - v1[1] * v2[0]; - if (c1*c2 < 0.0f) + if (c1 * c2 < 0.0f) return 0; /* m and v1 on same side of v-v2? */ - c1= v2[0]*m[1] - v2[1]*m[0]; - c2= v2[0]*v1[1] - v2[1]*v1[0]; + c1 = v2[0] * m[1] - v2[1] * m[0]; + c2 = v2[0] * v1[1] - v2[1] * v1[0]; - return (c1*c2 >= 0.0f); + return (c1 * c2 >= 0.0f); } void uv_find_nearest_vert(Scene *scene, Image *ima, BMEditMesh *em, @@ -816,13 +816,13 @@ void uv_find_nearest_vert(Scene *scene, Image *ima, BMEditMesh *em, hit->l = hit->nextl = NULL; hit->luv = hit->nextluv = NULL; - mindist= 1e10f; + mindist = 1e10f; memset(hit, 0, sizeof(*hit)); BM_mesh_elem_index_ensure(em->bm, BM_VERT); BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; @@ -831,25 +831,25 @@ void uv_find_nearest_vert(Scene *scene, Image *ima, BMEditMesh *em, luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); if (penalty && uvedit_uv_selected(em, scene, l)) - dist= fabs(co[0]-luv->uv[0])+penalty[0] + fabs(co[1]-luv->uv[1])+penalty[1]; + dist = fabs(co[0] - luv->uv[0]) + penalty[0] + fabs(co[1] - luv->uv[1]) + penalty[1]; else - dist= fabs(co[0]-luv->uv[0]) + fabs(co[1]-luv->uv[1]); + dist = fabs(co[0] - luv->uv[0]) + fabs(co[1] - luv->uv[1]); - if (dist<=mindist) { - if (dist==mindist) + if (dist <= mindist) { + if (dist == mindist) if (!nearest_uv_between(em, efa, efa->len, i, co, luv->uv)) { i++; continue; } - mindist= dist; + mindist = dist; hit->l = l; hit->nextl = l->next; hit->luv = luv; hit->nextluv = CustomData_bmesh_get(&em->bm->ldata, l->next->head.data, CD_MLOOPUV); - hit->tf= tf; - hit->efa= efa; + hit->tf = tf; + hit->efa = efa; hit->lindex = i; hit->vert1 = BM_elem_index_get(hit->l->v); } @@ -868,27 +868,27 @@ int ED_uvedit_nearest_uv(Scene *scene, Object *obedit, Image *ima, float co[2], MTexPoly *tf; MLoopUV *luv; float mindist, dist; - int found= 0; + int found = 0; - mindist= 1e10f; - uv[0]= co[0]; - uv[1]= co[1]; + mindist = 1e10f; + uv[0] = co[0]; + uv[1] = co[1]; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - dist= fabs(co[0]-luv->uv[0]) + fabs(co[1]-luv->uv[1]); + dist = fabs(co[0] - luv->uv[0]) + fabs(co[1] - luv->uv[1]); - if (dist<=mindist) { - mindist= dist; + if (dist <= mindist) { + mindist = dist; - uv[0]= luv->uv[0]; - uv[1]= luv->uv[1]; - found= 1; + uv[0] = luv->uv[0]; + uv[1] = luv->uv[1]; + found = 1; } } } @@ -901,17 +901,17 @@ int ED_uvedit_nearest_uv(Scene *scene, Object *obedit, Image *ima, float co[2], static void uv_vertex_loop_flag(UvMapVert *first) { UvMapVert *iterv; - int count= 0; + int count = 0; - for (iterv=first; iterv; iterv=iterv->next) { - if (iterv->separate && iterv!=first) + for (iterv = first; iterv; iterv = iterv->next) { + if (iterv->separate && iterv != first) break; count++; } if (count < 5) - first->flag= 1; + first->flag = 1; } static UvMapVert *uv_vertex_map_get(UvVertMap *vmap, BMFace *efa, int a) @@ -920,11 +920,11 @@ static UvMapVert *uv_vertex_map_get(UvVertMap *vmap, BMFace *efa, int a) BMLoop *l; l = BM_iter_at_index(NULL, BM_LOOPS_OF_FACE, efa, a); - first= EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); + first = EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); - for (iterv=first; iterv; iterv=iterv->next) { + for (iterv = first; iterv; iterv = iterv->next) { if (iterv->separate) - first= iterv; + first = iterv; if (iterv->f == BM_elem_index_get(efa)) return first; } @@ -952,17 +952,17 @@ static int uv_edge_tag_faces(BMEditMesh *em, UvMapVert *first1, UvMapVert *first int tot = 0; /* count number of faces this edge has */ - for (iterv1=first1; iterv1; iterv1=iterv1->next) { + for (iterv1 = first1; iterv1; iterv1 = iterv1->next) { if (iterv1->separate && iterv1 != first1) break; - for (iterv2=first2; iterv2; iterv2=iterv2->next) { + for (iterv2 = first2; iterv2; iterv2 = iterv2->next) { if (iterv2->separate && iterv2 != first2) break; if (iterv1->f == iterv2->f) { /* if face already tagged, don't do this edge */ - efa= EDBM_face_at_index(em, iterv1->f); + efa = EDBM_face_at_index(em, iterv1->f); if (BMO_elem_flag_test(em->bm, efa, EFA_F1_FLAG)) return 0; @@ -973,21 +973,21 @@ static int uv_edge_tag_faces(BMEditMesh *em, UvMapVert *first1, UvMapVert *first } if (*totface == 0) /* start edge */ - *totface= tot; + *totface = tot; else if (tot != *totface) /* check for same number of faces as start edge */ return 0; /* tag the faces */ - for (iterv1=first1; iterv1; iterv1=iterv1->next) { + for (iterv1 = first1; iterv1; iterv1 = iterv1->next) { if (iterv1->separate && iterv1 != first1) break; - for (iterv2=first2; iterv2; iterv2=iterv2->next) { + for (iterv2 = first2; iterv2; iterv2 = iterv2->next) { if (iterv2->separate && iterv2 != first2) break; if (iterv1->f == iterv2->f) { - efa= EDBM_face_at_index(em, iterv1->f); + efa = EDBM_face_at_index(em, iterv1->f); BMO_elem_flag_enable(em->bm, efa, EFA_F1_FLAG); break; } @@ -1009,7 +1009,7 @@ static int select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestHit /* setup */ EDBM_index_arrays_init(em, 0, 0, 1); - vmap= EDBM_uv_vert_map_create(em, 0, 0, limit); + vmap = EDBM_uv_vert_map_create(em, 0, 0, limit); BM_mesh_elem_index_ensure(em->bm, BM_VERT); @@ -1028,34 +1028,34 @@ static int select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestHit em->bm->elem_index_dirty &= ~BM_FACE; /* set flags for first face and verts */ - nverts= hit->efa->len; - iterv1= uv_vertex_map_get(vmap, hit->efa, hit->lindex); - iterv2= uv_vertex_map_get(vmap, hit->efa, (hit->lindex+1)%nverts); + nverts = hit->efa->len; + iterv1 = uv_vertex_map_get(vmap, hit->efa, hit->lindex); + iterv2 = uv_vertex_map_get(vmap, hit->efa, (hit->lindex + 1) % nverts); uv_vertex_loop_flag(iterv1); uv_vertex_loop_flag(iterv2); - starttotf= 0; + starttotf = 0; uv_edge_tag_faces(em, iterv1, iterv2, &starttotf); /* sorry, first edge isn't even ok */ - if (iterv1->flag==0 && iterv2->flag==0) looking= 0; - else looking= 1; + if (iterv1->flag == 0 && iterv2->flag == 0) looking = 0; + else looking = 1; /* iterate */ while (looking) { - looking= 0; + looking = 0; /* find correct valence edges which are not tagged yet, but connect to tagged one */ BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!BMO_elem_flag_test(em->bm, efa, EFA_F1_FLAG) && uvedit_face_visible(scene, ima, efa, tf)) { - nverts= efa->len; - for (a=0; a<nverts; a++) { + nverts = efa->len; + for (a = 0; a < nverts; a++) { /* check face not hidden and not tagged */ - iterv1= uv_vertex_map_get(vmap, efa, a); - iterv2= uv_vertex_map_get(vmap, efa, (a+1)%nverts); + iterv1 = uv_vertex_map_get(vmap, efa, a); + iterv2 = uv_vertex_map_get(vmap, efa, (a + 1) % nverts); if (!iterv1 || !iterv2) continue; @@ -1063,7 +1063,7 @@ static int select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestHit /* check if vertex is tagged and has right valence */ if (iterv1->flag || iterv2->flag) { if (uv_edge_tag_faces(em, iterv1, iterv2, &starttotf)) { - looking= 1; + looking = 1; BMO_elem_flag_enable(em->bm, efa, EFA_F1_FLAG); uv_vertex_loop_flag(iterv1); @@ -1077,25 +1077,25 @@ static int select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestHit } /* do the actual select/deselect */ - nverts= hit->efa->len; - iterv1= uv_vertex_map_get(vmap, hit->efa, hit->lindex); - iterv2= uv_vertex_map_get(vmap, hit->efa, (hit->lindex+1)%nverts); - iterv1->flag= 1; - iterv2->flag= 1; + nverts = hit->efa->len; + iterv1 = uv_vertex_map_get(vmap, hit->efa, hit->lindex); + iterv2 = uv_vertex_map_get(vmap, hit->efa, (hit->lindex + 1) % nverts); + iterv1->flag = 1; + iterv2->flag = 1; if (extend) { if (uvedit_uv_selected(em, scene, hit->l)) - select= 0; + select = 0; else - select= 1; + select = 1; } else - select= 1; + select = 1; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { a = 0; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { - iterv1= uv_vertex_map_get(vmap, efa, a); + iterv1 = uv_vertex_map_get(vmap, efa, a); if (iterv1->flag) { if (select) uvedit_uv_select(em, scene, l); @@ -1110,7 +1110,7 @@ static int select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestHit EDBM_uv_vert_map_free(vmap); EDBM_index_arrays_free(em); - return (select)? 1: -1; + return (select) ? 1 : -1; } /*********************** linked select ***********************/ @@ -1124,18 +1124,18 @@ static void select_linked(Scene *scene, Image *ima, BMEditMesh *em, float limit[ MLoopUV *luv; UvVertMap *vmap; UvMapVert *vlist, *iterv, *startv; - int i, stacksize= 0, *stack; + int i, stacksize = 0, *stack; unsigned int a; char *flag; EDBM_index_arrays_init(em, 0, 0, 1); /* we can use this too */ - vmap= EDBM_uv_vert_map_create(em, 1, 1, limit); + vmap = EDBM_uv_vert_map_create(em, 1, 1, limit); if (vmap == NULL) return; - stack= MEM_mallocN(sizeof(*stack)*(em->bm->totface+1), "UvLinkStack"); - flag= MEM_callocN(sizeof(*flag)*em->bm->totface, "UvLinkFlag"); + stack = MEM_mallocN(sizeof(*stack) * (em->bm->totface + 1), "UvLinkStack"); + flag = MEM_callocN(sizeof(*flag) * em->bm->totface, "UvLinkFlag"); if (!hit) { BM_ITER_INDEX(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL, a) { @@ -1146,9 +1146,9 @@ static void select_linked(Scene *scene, Image *ima, BMEditMesh *em, float limit[ luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); if (luv->flag & MLOOPUV_VERTSEL) { - stack[stacksize]= a; + stack[stacksize] = a; stacksize++; - flag[a]= 1; + flag[a] = 1; break; } @@ -1160,9 +1160,9 @@ static void select_linked(Scene *scene, Image *ima, BMEditMesh *em, float limit[ a = 0; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (efa == hit->efa) { - stack[stacksize]= a; + stack[stacksize] = a; stacksize++; - flag[a]= 1; + flag[a] = 1; break; } @@ -1174,11 +1174,11 @@ static void select_linked(Scene *scene, Image *ima, BMEditMesh *em, float limit[ int j; stacksize--; - a= stack[stacksize]; + a = stack[stacksize]; j = 0; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - if (j==a) + if (j == a) break; j++; @@ -1188,23 +1188,23 @@ static void select_linked(Scene *scene, Image *ima, BMEditMesh *em, float limit[ BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { /* make_uv_vert_map_EM sets verts tmp.l to the indices */ - vlist= EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); + vlist = EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); - startv= vlist; + startv = vlist; - for (iterv=vlist; iterv; iterv=iterv->next) { + for (iterv = vlist; iterv; iterv = iterv->next) { if (iterv->separate) - startv= iterv; + startv = iterv; if (iterv->f == a) break; } - for (iterv=startv; iterv; iterv=iterv->next) { + for (iterv = startv; iterv; iterv = iterv->next) { if ((startv != iterv) && (iterv->separate)) break; else if (!flag[iterv->f]) { - flag[iterv->f]= 1; - stack[stacksize]= iterv->f; + flag[iterv->f] = 1; + stack[stacksize] = iterv->f; stacksize++; } } @@ -1352,7 +1352,7 @@ static void weld_align_uv(bContext *C, int tool) } } - tool= (max[0]-min[0] >= max[1]-min[1])? 'y': 'x'; + tool = (max[0] - min[0] >= max[1] - min[1]) ? 'y' : 'x'; } uvedit_center(scene, ima, obedit, cent, 0); @@ -1520,7 +1520,7 @@ static void weld_align_uv(bContext *C, int tool) uvedit_live_unwrap_update(sima, scene, obedit); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); } static int align_exec(bContext *C, wmOperator *op) @@ -1545,11 +1545,11 @@ static void UV_OT_align(wmOperatorType *ot) ot->name = "Align"; ot->description = "Align selected UV vertices to an axis"; ot->idname = "UV_OT_align"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = align_exec; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; /* properties */ RNA_def_enum(ot->srna, "axis", axis_items, 'a', "Axis", "Axis to align UV locations on"); @@ -1570,7 +1570,7 @@ static void UV_OT_weld(wmOperatorType *ot) ot->name = "Weld"; ot->description = "Weld selected UV vertices together"; ot->idname = "UV_OT_weld"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = weld_exec; @@ -1602,19 +1602,19 @@ static void select_all_perform(bContext *C, int action) if (ts->uv_flag & UV_SYNC_SELECTION) { switch (action) { - case SEL_TOGGLE: - EDBM_select_toggle_all(BMEdit_FromObject(obedit)); - break; - case SEL_SELECT: - EDBM_flag_enable_all(em, BM_ELEM_SELECT); - break; - case SEL_DESELECT: - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - break; - case SEL_INVERT: - EDBM_select_swap(em); - EDBM_selectmode_flush(em); - break; + case SEL_TOGGLE: + EDBM_select_toggle_all(BMEdit_FromObject(obedit)); + break; + case SEL_SELECT: + EDBM_flag_enable_all(em, BM_ELEM_SELECT); + break; + case SEL_DESELECT: + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + break; + case SEL_INVERT: + EDBM_select_swap(em); + EDBM_selectmode_flush(em); + break; } } else { @@ -1648,15 +1648,15 @@ static void select_all_perform(bContext *C, int action) luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); switch (action) { - case SEL_SELECT: - luv->flag |= MLOOPUV_VERTSEL; - break; - case SEL_DESELECT: - luv->flag &= ~MLOOPUV_VERTSEL; - break; - case SEL_INVERT: - luv->flag ^= MLOOPUV_VERTSEL; - break; + case SEL_SELECT: + luv->flag |= MLOOPUV_VERTSEL; + break; + case SEL_DESELECT: + luv->flag &= ~MLOOPUV_VERTSEL; + break; + case SEL_INVERT: + luv->flag ^= MLOOPUV_VERTSEL; + break; } } } @@ -1665,12 +1665,12 @@ static void select_all_perform(bContext *C, int action) static int select_all_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - int action= RNA_enum_get(op->ptr, "action"); + Object *obedit = CTX_data_edit_object(C); + int action = RNA_enum_get(op->ptr, "action"); select_all_perform(C, action); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -1681,7 +1681,7 @@ static void UV_OT_select_all(wmOperatorType *ot) ot->name = "(De)select All"; ot->description = "Change selection of all UV vertices"; ot->idname = "UV_OT_select_all"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = select_all_exec; @@ -1701,10 +1701,10 @@ static int sticky_select(float *limit, int hitv[4], int v, float *hituv[4], floa if (sticky == SI_STICKY_DISABLE) return 0; - for (i=0; i<hitlen; i++) { + for (i = 0; i < hitlen; i++) { if (hitv[i] == v) { if (sticky == SI_STICKY_LOC) { - if (fabsf(hituv[i][0]-uv[0]) < limit[0] && fabsf(hituv[i][1]-uv[1]) < limit[1]) + if (fabsf(hituv[i][0] - uv[0]) < limit[0] && fabsf(hituv[i][1] - uv[1]) < limit[1]) return 1; } else if (sticky == SI_STICKY_VERTEX) @@ -1729,9 +1729,9 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) MTexPoly *tf; MLoopUV *luv; NearestHit hit; - int i, select = 1, selectmode, sticky, sync, *hitv=NULL, nvert; + int i, select = 1, selectmode, sticky, sync, *hitv = NULL, nvert; BLI_array_declare(hitv); - int flush = 0, hitlen=0; /* 0 == don't flush, 1 == sel, -1 == desel; only use when selection sync is enabled */ + int flush = 0, hitlen = 0; /* 0 == don't flush, 1 == sel, -1 == desel; only use when selection sync is enabled */ float limit[2], **hituv = NULL; BLI_array_declare(hituv); float penalty[2]; @@ -1747,21 +1747,21 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* retrieve operation mode */ if (ts->uv_flag & UV_SYNC_SELECTION) { - sync= 1; + sync = 1; if (ts->selectmode & SCE_SELECT_FACE) - selectmode= UV_SELECT_FACE; + selectmode = UV_SELECT_FACE; else if (ts->selectmode & SCE_SELECT_EDGE) - selectmode= UV_SELECT_EDGE; + selectmode = UV_SELECT_EDGE; else - selectmode= UV_SELECT_VERTEX; + selectmode = UV_SELECT_VERTEX; - sticky= SI_STICKY_DISABLE; + sticky = SI_STICKY_DISABLE; } else { - sync= 0; - selectmode= ts->uv_selectmode; - sticky= (sima)? sima->sticky: 1; + sync = 0; + selectmode = ts->uv_selectmode; + sticky = (sima) ? sima->sticky : 1; } /* find nearest element */ @@ -1788,12 +1788,12 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* mark 1 vertex as being hit */ BLI_array_growitems(hitv, hit.efa->len); BLI_array_growitems(hituv, hit.efa->len); - for (i=0; i<hit.efa->len; i++) { - hitv[i]= 0xFFFFFFFF; + for (i = 0; i < hit.efa->len; i++) { + hitv[i] = 0xFFFFFFFF; } - hitv[hit.lindex]= hit.vert1; - hituv[hit.lindex]= hit.luv->uv; + hitv[hit.lindex] = hit.vert1; + hituv[hit.lindex] = hit.luv->uv; hitlen = hit.efa->len; } @@ -1809,16 +1809,16 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* mark 2 edge vertices as being hit */ BLI_array_growitems(hitv, hit.efa->len); BLI_array_growitems(hituv, hit.efa->len); - for (i=0; i < hit.efa->len; i++) { - hitv[i]= 0xFFFFFFFF; + for (i = 0; i < hit.efa->len; i++) { + hitv[i] = 0xFFFFFFFF; } - nvert= hit.efa->len; + nvert = hit.efa->len; - hitv[hit.lindex]= hit.vert1; - hitv[(hit.lindex+1)%nvert]= hit.vert2; - hituv[hit.lindex]= hit.luv->uv; - hituv[(hit.lindex+1)%nvert]= hit.nextluv->uv; + hitv[hit.lindex] = hit.vert1; + hitv[(hit.lindex + 1) % nvert] = hit.vert2; + hituv[hit.lindex] = hit.luv->uv; + hituv[(hit.lindex + 1) % nvert] = hit.nextluv->uv; hitlen = hit.efa->len; } @@ -1841,7 +1841,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) i = 0; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, hit.efa) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - hituv[i]= luv->uv; + hituv[i] = luv->uv; hitv[i] = BM_elem_index_get(l->v); i++; } @@ -1851,7 +1851,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) else if (selectmode == UV_SELECT_ISLAND) { uv_find_nearest_vert(scene, ima, em, co, NULL, &hit); - if (hit.efa==NULL) { + if (hit.efa == NULL) { BLI_array_free(hitv); BLI_array_free(hituv); return OPERATOR_CANCELLED; @@ -1868,7 +1868,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* do selection */ if (loop) { - flush= select_edgeloop(scene, ima, em, &hit, limit, extend); + flush = select_edgeloop(scene, ima, em, &hit, limit, extend); } else if (selectmode == UV_SELECT_ISLAND) { select_linked(scene, ima, em, limit, &hit, extend); @@ -1878,11 +1878,11 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* (de)select uv vertex */ if (uvedit_uv_selected(em, scene, hit.l)) { uvedit_uv_deselect(em, scene, hit.l); - select= 0; + select = 0; } else { uvedit_uv_select(em, scene, hit.l); - select= 1; + select = 1; } flush = 1; } @@ -1890,11 +1890,11 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* (de)select edge */ if (uvedit_edge_selected(em, scene, hit.l)) { uvedit_edge_deselect(em, scene, hit.l); - select= 0; + select = 0; } else { uvedit_edge_select(em, scene, hit.l); - select= 1; + select = 1; } flush = 1; } @@ -1902,11 +1902,11 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* (de)select face */ if (uvedit_face_selected(scene, em, hit.efa)) { uvedit_face_deselect(scene, em, hit.efa); - select= 0; + select = 0; } else { uvedit_face_select(scene, em, hit.efa); - select= 1; + select = 1; } flush = -1; } @@ -1917,9 +1917,9 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) BM_mesh_elem_index_ensure(em->bm, BM_VERT); /* deselect */ - if (select==0) { + if (select == 0) { BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; @@ -1934,7 +1934,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* select */ else { BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; @@ -1958,12 +1958,12 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) if (selectmode == UV_SELECT_VERTEX) { /* select vertex */ uvedit_uv_select(em, scene, hit.l); - flush= 1; + flush = 1; } else if (selectmode == UV_SELECT_EDGE) { /* select edge */ uvedit_edge_select(em, scene, hit.l); - flush= 1; + flush = 1; } else if (selectmode == UV_SELECT_FACE) { /* select face */ @@ -1973,7 +1973,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) /* select sticky uvs */ if (sticky != SI_STICKY_DISABLE) { BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; @@ -1984,19 +1984,19 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) if (sticky_select(limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) uvedit_uv_select(em, scene, l); - flush= 1; + flush = 1; } } } } -#if 0 /* BM_elem_select_set API handles all of this? */ +#if 0 /* BM_elem_select_set API handles all of this? */ if (sync) { /* flush for mesh selection */ if (ts->selectmode != SCE_SELECT_FACE) { - if (flush==1) EDBM_select_flush(em); - else if (flush==-1) EDBM_deselect_flush(em); + if (flush == 1) EDBM_select_flush(em); + else if (flush == -1) EDBM_deselect_flush(em); } } #else @@ -2005,12 +2005,12 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop) #endif DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); BLI_array_free(hitv); BLI_array_free(hituv); - return OPERATOR_PASS_THROUGH|OPERATOR_FINISHED; + return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED; } static int select_exec(bContext *C, wmOperator *op) @@ -2019,15 +2019,15 @@ static int select_exec(bContext *C, wmOperator *op) int extend, loop; RNA_float_get_array(op->ptr, "location", co); - extend= RNA_boolean_get(op->ptr, "extend"); - loop= 0; + extend = RNA_boolean_get(op->ptr, "extend"); + loop = 0; return mouse_select(C, co, extend, loop); } static int select_invoke(bContext *C, wmOperator *op, wmEvent *event) { - ARegion *ar= CTX_wm_region(C); + ARegion *ar = CTX_wm_region(C); float co[2]; UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]); @@ -2042,18 +2042,18 @@ static void UV_OT_select(wmOperatorType *ot) ot->name = "Select"; ot->description = "Select UV vertices"; ot->idname = "UV_OT_select"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = select_exec; ot->invoke = select_invoke; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; /* properties */ RNA_def_boolean(ot->srna, "extend", 0, - "Extend", "Extend selection rather than clearing the existing selection"); + "Extend", "Extend selection rather than clearing the existing selection"); RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, - "Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f); + "Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f); } /* ******************** loop select operator **************** */ @@ -2064,15 +2064,15 @@ static int select_loop_exec(bContext *C, wmOperator *op) int extend, loop; RNA_float_get_array(op->ptr, "location", co); - extend= RNA_boolean_get(op->ptr, "extend"); - loop= 1; + extend = RNA_boolean_get(op->ptr, "extend"); + loop = 1; return mouse_select(C, co, extend, loop); } static int select_loop_invoke(bContext *C, wmOperator *op, wmEvent *event) { - ARegion *ar= CTX_wm_region(C); + ARegion *ar = CTX_wm_region(C); float co[2]; UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]); @@ -2087,18 +2087,18 @@ static void UV_OT_select_loop(wmOperatorType *ot) ot->name = "Loop Select"; ot->description = "Select a loop of connected UV vertices"; ot->idname = "UV_OT_select_loop"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = select_loop_exec; ot->invoke = select_loop_invoke; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; /* properties */ RNA_def_boolean(ot->srna, "extend", 0, - "Extend", "Extend selection rather than clearing the existing selection"); + "Extend", "Extend selection rather than clearing the existing selection"); RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, - "Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f); + "Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f); } /* ******************** linked select operator **************** */ @@ -2114,14 +2114,14 @@ static int select_linked_internal(bContext *C, wmOperator *op, wmEvent *event, i float limit[2]; int extend; - NearestHit hit, *hit_p= NULL; + NearestHit hit, *hit_p = NULL; if (ts->uv_flag & UV_SYNC_SELECTION) { BKE_report(op->reports, RPT_ERROR, "Can't select linked when sync selection is enabled"); return OPERATOR_CANCELLED; } - extend= RNA_boolean_get(op->ptr, "extend"); + extend = RNA_boolean_get(op->ptr, "extend"); uvedit_pixel_to_float(sima, limit, 0.05f); if (pick) { @@ -2129,7 +2129,7 @@ static int select_linked_internal(bContext *C, wmOperator *op, wmEvent *event, i if (event) { /* invoke */ - ARegion *ar= CTX_wm_region(C); + ARegion *ar = CTX_wm_region(C); UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]); RNA_float_set_array(op->ptr, "location", co); @@ -2140,13 +2140,13 @@ static int select_linked_internal(bContext *C, wmOperator *op, wmEvent *event, i } uv_find_nearest_vert(scene, ima, em, co, NULL, &hit); - hit_p= &hit; + hit_p = &hit; } select_linked(scene, ima, em, limit, hit_p, extend); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2162,15 +2162,15 @@ static void UV_OT_select_linked(wmOperatorType *ot) ot->name = "Select Linked"; ot->description = "Select all UV vertices linked to the active UV map"; ot->idname = "UV_OT_select_linked"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = select_linked_exec; - ot->poll = ED_operator_image_active; /* requires space image */ + ot->poll = ED_operator_image_active; /* requires space image */ /* properties */ RNA_def_boolean(ot->srna, "extend", 0, - "Extend", "Extend selection rather than clearing the existing selection"); + "Extend", "Extend selection rather than clearing the existing selection"); } static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event) @@ -2189,19 +2189,19 @@ static void UV_OT_select_linked_pick(wmOperatorType *ot) ot->name = "Select Linked Pick"; ot->description = "Select all UV vertices linked under the mouse"; ot->idname = "UV_OT_select_linked_pick"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->invoke = select_linked_pick_invoke; ot->exec = select_linked_pick_exec; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; /* properties */ RNA_def_boolean(ot->srna, "extend", 0, - "Extend", "Extend selection rather than clearing the existing selection"); + "Extend", "Extend selection rather than clearing the existing selection"); RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, - "Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f); + "Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f); } /* ******************** unlink selection operator **************** */ @@ -2249,7 +2249,7 @@ static int unlink_selection_exec(bContext *C, wmOperator *op) } DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2260,7 +2260,7 @@ static void UV_OT_unlink_selected(wmOperatorType *ot) ot->name = "Unlink Selection"; ot->description = "Unlink selected UV vertices from active UV map"; ot->idname = "UV_OT_unlink_selected"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = unlink_selection_exec; @@ -2291,7 +2291,7 @@ static void uv_faces_do_sticky(bContext *C, SpaceImage *sima, Scene *scene, Obje BMIter iter, liter; /* MTexPoly *tf; */ - if ((ts->uv_flag & UV_SYNC_SELECTION)==0 && sima->sticky == SI_STICKY_VERTEX) { + if ((ts->uv_flag & UV_SYNC_SELECTION) == 0 && sima->sticky == SI_STICKY_VERTEX) { /* Tag all verts as untouched, then touch the ones that have a face center * in the loop and select all MLoopUV's that use a touched vert. */ BMVert *eve; @@ -2322,10 +2322,10 @@ static void uv_faces_do_sticky(bContext *C, SpaceImage *sima, Scene *scene, Obje } } } - else if ((ts->uv_flag & UV_SYNC_SELECTION)==0 && sima->sticky == SI_STICKY_LOC) { + else if ((ts->uv_flag & UV_SYNC_SELECTION) == 0 && sima->sticky == SI_STICKY_LOC) { BMFace *efa_vlist; /* MTexPoly *tf_vlist; */ /* UNUSED */ - UvMapVert *start_vlist=NULL, *vlist_iter; + UvMapVert *start_vlist = NULL, *vlist_iter; struct UvVertMap *vmap; float limit[2]; unsigned int efa_index; @@ -2335,12 +2335,12 @@ static void uv_faces_do_sticky(bContext *C, SpaceImage *sima, Scene *scene, Obje uvedit_pixel_to_float(sima, limit, 0.05); EDBM_index_arrays_init(em, 0, 0, 1); - vmap= EDBM_uv_vert_map_create(em, 0, 0, limit); + vmap = EDBM_uv_vert_map_create(em, 0, 0, limit); /* verts are numbered above in make_uv_vert_map_EM, make sure this stays true! */ /* BMESH_TODO - why keep this commented? - campbell */ #if 0 - for (a=0, eve= em->verts.first; eve; a++, eve= eve->next) + for (a = 0, eve = em->verts.first; eve; a++, eve = eve->next) eve->tmp.l = a; #endif if (vmap == NULL) { @@ -2348,7 +2348,7 @@ static void uv_faces_do_sticky(bContext *C, SpaceImage *sima, Scene *scene, Obje } efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); - for (efa_index=0; efa; efa=BM_iter_step(&iter), efa_index++) { + for (efa_index = 0; efa; efa = BM_iter_step(&iter), efa_index++) { if (BM_elem_flag_test(efa, BM_ELEM_TAG)) { /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ @@ -2358,7 +2358,7 @@ static void uv_faces_do_sticky(bContext *C, SpaceImage *sima, Scene *scene, Obje else uvedit_uv_deselect(em, scene, l); - vlist_iter= EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); + vlist_iter = EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); while (vlist_iter) { if (vlist_iter->separate) @@ -2434,30 +2434,30 @@ static int border_select_exec(bContext *C, wmOperator *op) UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); /* figure out what to select/deselect */ - select= (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); - pinned= RNA_boolean_get(op->ptr, "pinned"); - extend= RNA_boolean_get(op->ptr, "extend"); + select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); + pinned = RNA_boolean_get(op->ptr, "pinned"); + extend = RNA_boolean_get(op->ptr, "extend"); if (!extend) select_all_perform(C, SEL_DESELECT); if (ts->uv_flag & UV_SYNC_SELECTION) - faces= (ts->selectmode == SCE_SELECT_FACE); + faces = (ts->selectmode == SCE_SELECT_FACE); else - faces= (ts->uv_selectmode == UV_SELECT_FACE); + faces = (ts->uv_selectmode == UV_SELECT_FACE); /* do actual selection */ if (faces && !pinned) { /* handle face selection mode */ float cent[2]; - change= 0; + change = 0; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { /* assume not touched */ BM_elem_flag_disable(efa, BM_ELEM_TAG); - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (uvedit_face_visible(scene, ima, efa, tf)) { poly_uv_center(em, efa, cent); if (BLI_in_rctf(&rectf, cent[0], cent[1])) { @@ -2473,10 +2473,10 @@ static int border_select_exec(bContext *C, wmOperator *op) } else { /* other selection modes */ - change= 1; + change = 1; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tf)) continue; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { @@ -2486,15 +2486,15 @@ static int border_select_exec(bContext *C, wmOperator *op) /* UV_SYNC_SELECTION - can't do pinned selection */ if (BLI_in_rctf(&rectf, luv->uv[0], luv->uv[1])) { - if (select) uvedit_uv_select(em, scene, l); - else uvedit_uv_deselect(em, scene, l); + if (select) uvedit_uv_select(em, scene, l); + else uvedit_uv_deselect(em, scene, l); } } else if (pinned) { if ((luv->flag & MLOOPUV_PINNED) && BLI_in_rctf(&rectf, luv->uv[0], luv->uv[1])) { - if (select) uvedit_uv_select(em, scene, l); - else uvedit_uv_deselect(em, scene, l); + if (select) uvedit_uv_select(em, scene, l); + else uvedit_uv_deselect(em, scene, l); } } } @@ -2503,16 +2503,16 @@ static int border_select_exec(bContext *C, wmOperator *op) if (change) { /* make sure newly selected vert selection is updated*/ -#if 0 /* BM_elem_select_set API handles all of this? */ +#if 0 /* BM_elem_select_set API handles all of this? */ if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->selectmode != SCE_SELECT_FACE) { - if (select) EDBM_select_flush(em); - else EDBM_deselect_flush(em); + if (select) EDBM_select_flush(em); + else EDBM_deselect_flush(em); } } #endif - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2531,11 +2531,11 @@ static void UV_OT_select_border(wmOperatorType *ot) ot->invoke = WM_border_select_invoke; ot->exec = border_select_exec; ot->modal = WM_border_select_modal; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; ot->cancel = WM_border_select_cancel; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_boolean(ot->srna, "pinned", 0, "Pinned", "Border select pinned UVs only"); @@ -2546,18 +2546,18 @@ static void UV_OT_select_border(wmOperatorType *ot) /* ******************** circle select operator **************** */ static void select_uv_inside_ellipse(BMEditMesh *em, SpaceImage *UNUSED(sima), Scene *scene, int select, - float *offset, float *ell, BMLoop *l, MLoopUV *luv) + float *offset, float *ell, BMLoop *l, MLoopUV *luv) { /* normalized ellipse: ell[0] = scaleX, ell[1] = scaleY */ float x, y, r2, *uv; - uv= luv->uv; + uv = luv->uv; - x= (uv[0] - offset[0])*ell[0]; - y= (uv[1] - offset[1])*ell[1]; + x = (uv[0] - offset[0]) * ell[0]; + y = (uv[1] - offset[1]) * ell[1]; - r2 = x*x + y*y; + r2 = x * x + y * y; if (r2 < 1.0f) { if (select) uvedit_uv_select(em, scene, l); else uvedit_uv_deselect(em, scene, l); @@ -2577,21 +2577,21 @@ static int circle_select_exec(bContext *C, wmOperator *op) MLoopUV *luv; int x, y, radius, width, height, select; float zoomx, zoomy, offset[2], ellipse[2]; - int gesture_mode= RNA_int_get(op->ptr, "gesture_mode"); + int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); /* get operator properties */ - select= (gesture_mode == GESTURE_MODAL_SELECT); - x= RNA_int_get(op->ptr, "x"); - y= RNA_int_get(op->ptr, "y"); - radius= RNA_int_get(op->ptr, "radius"); + select = (gesture_mode == GESTURE_MODAL_SELECT); + x = RNA_int_get(op->ptr, "x"); + y = RNA_int_get(op->ptr, "y"); + radius = RNA_int_get(op->ptr, "radius"); /* compute ellipse size and location, not a circle since we deal * with non square image. ellipse is normalized, r = 1.0. */ ED_space_image_size(sima, &width, &height); ED_space_image_zoom(sima, ar, &zoomx, &zoomy); - ellipse[0]= width*zoomx/radius; - ellipse[1]= height*zoomy/radius; + ellipse[0] = width * zoomx / radius; + ellipse[1] = height * zoomy / radius; UI_view2d_region_to_view(&ar->v2d, x, y, &offset[0], &offset[1]); @@ -2607,7 +2607,7 @@ static int circle_select_exec(bContext *C, wmOperator *op) if (select) EM_select_flush(em); else EM_deselect_flush(em); #endif - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2623,11 +2623,11 @@ static void UV_OT_circle_select(wmOperatorType *ot) ot->invoke = WM_gesture_circle_invoke; ot->modal = WM_gesture_circle_modal; ot->exec = circle_select_exec; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; ot->cancel = WM_gesture_circle_cancel; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX); @@ -2640,13 +2640,13 @@ static void UV_OT_circle_select(wmOperatorType *ot) static void snap_uv_to_pixel(float *uvco, float w, float h) { - uvco[0] = ((float)((int)((uvco[0]*w) + 0.5f)))/w; - uvco[1] = ((float)((int)((uvco[1]*h) + 0.5f)))/h; + uvco[0] = ((float)((int)((uvco[0] * w) + 0.5f))) / w; + uvco[1] = ((float)((int)((uvco[1] * h) + 0.5f))) / h; } static void snap_cursor_to_pixels(SpaceImage *sima) { - int width= 0, height= 0; + int width = 0, height = 0; ED_space_image_size(sima, &width, &height); snap_uv_to_pixel(sima->cursor, width, height); @@ -2659,26 +2659,26 @@ static int snap_cursor_to_selection(Scene *scene, Image *ima, Object *obedit, Sp static int snap_cursor_exec(bContext *C, wmOperator *op) { - SpaceImage *sima= CTX_wm_space_image(C); - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - Image *ima= CTX_data_edit_image(C); - int change= 0; + SpaceImage *sima = CTX_wm_space_image(C); + Scene *scene = CTX_data_scene(C); + Object *obedit = CTX_data_edit_object(C); + Image *ima = CTX_data_edit_image(C); + int change = 0; - switch(RNA_enum_get(op->ptr, "target")) { + switch (RNA_enum_get(op->ptr, "target")) { case 0: snap_cursor_to_pixels(sima); - change= 1; + change = 1; break; case 1: - change= snap_cursor_to_selection(scene, ima, obedit, sima); + change = snap_cursor_to_selection(scene, ima, obedit, sima); break; } if (!change) return OPERATOR_CANCELLED; - WM_event_add_notifier(C, NC_SPACE|ND_SPACE_IMAGE, sima); + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, sima); return OPERATOR_FINISHED; } @@ -2694,11 +2694,11 @@ static void UV_OT_snap_cursor(wmOperatorType *ot) ot->name = "Snap Cursor"; ot->description = "Snap cursor to target type"; ot->idname = "UV_OT_snap_cursor"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = snap_cursor_exec; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; /* properties */ RNA_def_enum(ot->srna, "target", target_items, 0, "Target", "Target to snap the selected UVs to"); @@ -2714,10 +2714,10 @@ static int snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, SpaceIma BMIter iter, liter; MTexPoly *tface; MLoopUV *luv; - short change= 0; + short change = 0; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tface= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tface = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tface)) continue; @@ -2725,7 +2725,7 @@ static int snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, SpaceIma if (uvedit_uv_selected(em, scene, l)) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(luv->uv, sima->cursor); - change= 1; + change = 1; } } } @@ -2808,7 +2808,7 @@ static int snap_uvs_to_pixels(SpaceImage *sima, Scene *scene, Object *obedit) h = (float)height; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tface= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tface = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tface)) continue; @@ -2827,21 +2827,21 @@ static int snap_uvs_to_pixels(SpaceImage *sima, Scene *scene, Object *obedit) static int snap_selection_exec(bContext *C, wmOperator *op) { - SpaceImage *sima= CTX_wm_space_image(C); - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - Image *ima= CTX_data_edit_image(C); - int change= 0; + SpaceImage *sima = CTX_wm_space_image(C); + Scene *scene = CTX_data_scene(C); + Object *obedit = CTX_data_edit_object(C); + Image *ima = CTX_data_edit_image(C); + int change = 0; - switch(RNA_enum_get(op->ptr, "target")) { + switch (RNA_enum_get(op->ptr, "target")) { case 0: - change= snap_uvs_to_pixels(sima, scene, obedit); + change = snap_uvs_to_pixels(sima, scene, obedit); break; case 1: - change= snap_uvs_to_cursor(scene, ima, obedit, sima); + change = snap_uvs_to_cursor(scene, ima, obedit, sima); break; case 2: - change= snap_uvs_to_adjacent_unselected(scene, ima, obedit); + change = snap_uvs_to_adjacent_unselected(scene, ima, obedit); break; } @@ -2850,7 +2850,7 @@ static int snap_selection_exec(bContext *C, wmOperator *op) uvedit_live_unwrap_update(sima, scene, obedit); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -2867,11 +2867,11 @@ static void UV_OT_snap_selected(wmOperatorType *ot) ot->name = "Snap Selection"; ot->description = "Snap selected UV vertices to target type"; ot->idname = "UV_OT_snap_selected"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = snap_selection_exec; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; /* properties */ RNA_def_enum(ot->srna, "target", target_items, 0, "Target", "Target to snap the selected UVs to"); @@ -2893,7 +2893,7 @@ static int pin_exec(bContext *C, wmOperator *op) int clear = RNA_boolean_get(op->ptr, "clear"); BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tface= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tface = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tface)) continue; @@ -2911,7 +2911,7 @@ static int pin_exec(bContext *C, wmOperator *op) } } - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -2922,7 +2922,7 @@ static void UV_OT_pin(wmOperatorType *ot) ot->name = "Pin"; ot->description = "Set/clear selected UV vertices as anchored between multiple unwrap operations"; ot->idname = "UV_OT_pin"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = pin_exec; @@ -2947,7 +2947,7 @@ static int select_pinned_exec(bContext *C, wmOperator *UNUSED(op)) MLoopUV *luv; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - tface= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tface = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); if (!uvedit_face_visible(scene, ima, efa, tface)) continue; @@ -2959,7 +2959,7 @@ static int select_pinned_exec(bContext *C, wmOperator *UNUSED(op)) } } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2970,7 +2970,7 @@ static void UV_OT_select_pinned(wmOperatorType *ot) ot->name = "Selected Pinned"; ot->description = "Select all pinned UV vertices"; ot->idname = "UV_OT_select_pinned"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = select_pinned_exec; @@ -2991,11 +2991,11 @@ static int hide_exec(bContext *C, wmOperator *op) BMIter iter, liter; MLoopUV *luv; int swap = RNA_boolean_get(op->ptr, "unselected"); - int facemode= sima ? sima->flag & SI_SELACTFACE : 0; + int facemode = sima ? sima->flag & SI_SELACTFACE : 0; if (ts->uv_flag & UV_SYNC_SELECTION) { EDBM_mesh_hide(em, swap); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -3053,11 +3053,11 @@ static int hide_exec(bContext *C, wmOperator *op) } /* flush vertex selection changes */ - if(!facemode && em->selectmode != SCE_SELECT_FACE) + if (!facemode && em->selectmode != SCE_SELECT_FACE) EDBM_selectmode_flush(em); EDBM_editselection_validate(em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -3068,7 +3068,7 @@ static void UV_OT_hide(wmOperatorType *ot) ot->name = "Hide Selected"; ot->description = "Hide (un)selected UV vertices"; ot->idname = "UV_OT_hide"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = hide_exec; @@ -3082,17 +3082,17 @@ static void UV_OT_hide(wmOperatorType *ot) static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceImage *sima= CTX_wm_space_image(C); - ToolSettings *ts= CTX_data_tool_settings(C); - Object *obedit= CTX_data_edit_object(C); + SpaceImage *sima = CTX_wm_space_image(C); + ToolSettings *ts = CTX_data_tool_settings(C); + Object *obedit = CTX_data_edit_object(C); /*Scene *scene = CTX_data_scene(C);*/ /*UNUSED*/ BMEditMesh *em = BMEdit_FromObject(obedit); BMFace *efa; BMLoop *l; BMIter iter, liter; MLoopUV *luv; - int facemode= sima ? sima->flag & SI_SELACTFACE : 0; - int stickymode= sima ? (sima->sticky != SI_STICKY_DISABLE) : 1; + int facemode = sima ? sima->flag & SI_SELACTFACE : 0; + int stickymode = sima ? (sima->sticky != SI_STICKY_DISABLE) : 1; /* note on tagging, selecting faces needs to be delayed so it doesn't select the verts and * confuse our checks on selected verts. */ @@ -3100,7 +3100,7 @@ static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) /* call the mesh function if we are in mesh sync sel */ if (ts->uv_flag & UV_SYNC_SELECTION) { EDBM_mesh_reveal(em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -3124,7 +3124,7 @@ static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { BM_elem_flag_disable(efa, BM_ELEM_TAG); if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) { - int totsel=0; + int totsel = 0; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { totsel += BM_elem_flag_test(l->v, BM_ELEM_SELECT); } @@ -3145,7 +3145,7 @@ static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) BM_elem_flag_disable(efa, BM_ELEM_TAG); if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) { BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { - if (BM_elem_flag_test(l->v, BM_ELEM_SELECT)==0) { + if (BM_elem_flag_test(l->v, BM_ELEM_SELECT) == 0) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); luv->flag |= MLOOPUV_VERTSEL; } @@ -3175,7 +3175,7 @@ static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) BM_elem_flag_disable(efa, BM_ELEM_TAG); if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) { BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { - if (BM_elem_flag_test(l->v, BM_ELEM_SELECT)==0) { + if (BM_elem_flag_test(l->v, BM_ELEM_SELECT) == 0) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); luv->flag |= MLOOPUV_VERTSEL; } @@ -3189,7 +3189,7 @@ static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) /* re-select tagged faces */ BM_mesh_elem_hflag_enable_test(em->bm, BM_FACE, BM_ELEM_SELECT, TRUE, BM_ELEM_TAG); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -3200,7 +3200,7 @@ static void UV_OT_reveal(wmOperatorType *ot) ot->name = "Reveal Hidden"; ot->description = "Reveal all hidden UV vertices"; ot->idname = "UV_OT_reveal"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = reveal_exec; @@ -3218,17 +3218,17 @@ static int set_2d_cursor_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; RNA_float_get_array(op->ptr, "location", location); - sima->cursor[0]= location[0]; - sima->cursor[1]= location[1]; + sima->cursor[0] = location[0]; + sima->cursor[1] = location[1]; - WM_event_add_notifier(C, NC_SPACE|ND_SPACE_IMAGE, NULL); + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, NULL); return OPERATOR_FINISHED; } static int set_2d_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) { - ARegion *ar= CTX_wm_region(C); + ARegion *ar = CTX_wm_region(C); float location[2]; UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]); @@ -3247,10 +3247,10 @@ static void UV_OT_cursor_set(wmOperatorType *ot) /* api callbacks */ ot->exec = set_2d_cursor_exec; ot->invoke = set_2d_cursor_invoke; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location", "Cursor location in normalised (0.0-1.0) coordinates", -10.0f, 10.0f); @@ -3260,15 +3260,15 @@ static void UV_OT_cursor_set(wmOperatorType *ot) static int set_tile_exec(bContext *C, wmOperator *op) { - Image *ima= CTX_data_edit_image(C); + Image *ima = CTX_data_edit_image(C); int tile[2]; - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); RNA_int_get_array(op->ptr, "tile", tile); - if (uvedit_set_tile(obedit, ima, tile[0] + ima->xrep*tile[1])) { - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - WM_event_add_notifier(C, NC_SPACE|ND_SPACE_IMAGE, NULL); + if (uvedit_set_tile(obedit, ima, tile[0] + ima->xrep * tile[1])) { + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, NULL); return OPERATOR_FINISHED; } @@ -3278,9 +3278,9 @@ static int set_tile_exec(bContext *C, wmOperator *op) static int set_tile_invoke(bContext *C, wmOperator *op, wmEvent *event) { - SpaceImage *sima= CTX_wm_space_image(C); - Image *ima= CTX_data_edit_image(C); - ARegion *ar= CTX_wm_region(C); + SpaceImage *sima = CTX_wm_space_image(C); + Image *ima = CTX_data_edit_image(C); + ARegion *ar = CTX_wm_region(C); float fx, fy; int tile[2]; @@ -3290,13 +3290,13 @@ static int set_tile_invoke(bContext *C, wmOperator *op, wmEvent *event) UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy); if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { - fx= fx*ima->xrep; - fy= fy*ima->yrep; + fx = fx * ima->xrep; + fy = fy * ima->yrep; - tile[0]= fx; - tile[1]= fy; + tile[0] = fx; + tile[1] = fy; - sima->curtile= tile[1]*ima->xrep + tile[0]; + sima->curtile = tile[1] * ima->xrep + tile[0]; RNA_int_set_array(op->ptr, "tile", tile); } @@ -3313,10 +3313,10 @@ static void UV_OT_tile_set(wmOperatorType *ot) /* api callbacks */ ot->exec = set_tile_exec; ot->invoke = set_tile_invoke; - ot->poll = ED_operator_image_active; /* requires space image */; + ot->poll = ED_operator_image_active; /* requires space image */; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_int_vector(ot->srna, "tile", 2, NULL, 0, INT_MAX, "Tile", "Tile coordinate", 0, 10); @@ -3327,7 +3327,7 @@ static int seams_from_islands_exec(bContext *C, wmOperator *op) { UvVertMap *vmap; Object *ob = CTX_data_edit_object(C); - Mesh *me= (Mesh*)ob->data; + Mesh *me = (Mesh *)ob->data; BMEditMesh *em; BMEdge *editedge; float limit[2] = {STD_UV_CONNECT_LIMIT, STD_UV_CONNECT_LIMIT}; @@ -3428,7 +3428,7 @@ static int seams_from_islands_exec(bContext *C, wmOperator *op) EDBM_index_arrays_free(em); DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return OPERATOR_FINISHED; } @@ -3442,7 +3442,7 @@ static void UV_OT_seams_from_islands(wmOperatorType *ot) ot->idname = "UV_OT_seams_from_islands"; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = seams_from_islands_exec; @@ -3456,8 +3456,8 @@ static int mark_seam_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_edit_object(C); Scene *scene = CTX_data_scene(C); - Mesh *me= (Mesh*)ob->data; - BMEditMesh *em= me->edit_btmesh; + Mesh *me = (Mesh *)ob->data; + BMEditMesh *em = me->edit_btmesh; BMesh *bm = em->bm; BMFace *efa; BMLoop *loop; @@ -3478,7 +3478,7 @@ static int mark_seam_exec(bContext *C, wmOperator *UNUSED(op)) ED_unwrap_lscm(scene, ob, FALSE); DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return OPERATOR_FINISHED; } @@ -3491,7 +3491,7 @@ static void UV_OT_mark_seam(wmOperatorType *ot) ot->idname = "UV_OT_mark_seam"; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = mark_seam_exec; @@ -3561,7 +3561,7 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf) RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select", SELECTMOUSE, KM_PRESS, 0, 0)->ptr, "extend", FALSE); RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", TRUE); RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_loop", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "extend", FALSE); - RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_loop", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "extend", TRUE); + RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_loop", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0)->ptr, "extend", TRUE); /* border/circle selection */ kmi = WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, 0, 0); @@ -3574,7 +3574,7 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf) /* selection manipulation */ RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0)->ptr, "extend", FALSE); RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0)->ptr, "extend", FALSE); - RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "extend", TRUE); + RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0)->ptr, "extend", TRUE); RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", TRUE); WM_keymap_add_item(keymap, "UV_OT_unlink_selected", LKEY, KM_PRESS, KM_ALT, 0); diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 7d388e6206c..d2c711fccf3 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -32,24 +32,23 @@ /* Utils */ #if 0 - #define param_assert(condition); - #define param_warning(message); - #define param_test_equals_ptr(condition); - #define param_test_equals_int(condition); + #define param_assert(condition) + #define param_warning(message) + #define param_test_equals_ptr(condition) + #define param_test_equals_int(condition) #else #define param_assert(condition) \ if (!(condition)) \ - { /*printf("Assertion %s:%d\n", __FILE__, __LINE__); abort();*/ } + { /*printf("Assertion %s:%d\n", __FILE__, __LINE__); abort();*/ } (void)0 #define param_warning(message) \ - { /*printf("Warning %s:%d: %s\n", __FILE__, __LINE__, message);*/ } + { /*printf("Warning %s:%d: %s\n", __FILE__, __LINE__, message);*/ } (void)0 #define param_test_equals_ptr(str, a, b) \ if (a != b) \ - { /*printf("Equals %s => %p != %p\n", str, a, b);*/ }; + { /*printf("Equals %s => %p != %p\n", str, a, b);*/ } (void)0 #define param_test_equals_int(str, a, b) \ if (a != b) \ - { /*printf("Equals %s => %d != %d\n", str, a, b);*/ }; + { /*printf("Equals %s => %d != %d\n", str, a, b);*/ } (void)0 #endif - typedef enum PBool { P_TRUE = 1, P_FALSE = 0 @@ -84,10 +83,10 @@ typedef struct PVert { struct PVert *nextlink; union PVertUnion { - PHashKey key; /* construct */ - int id; /* abf/lscm matrix index */ - float distortion; /* area smoothing */ - HeapNode *heaplink; /* edge collapsing */ + PHashKey key; /* construct */ + int id; /* abf/lscm matrix index */ + float distortion; /* area smoothing */ + HeapNode *heaplink; /* edge collapsing */ } u; struct PEdge *edge; @@ -101,10 +100,10 @@ typedef struct PEdge { struct PEdge *nextlink; union PEdgeUnion { - PHashKey key; /* construct */ - int id; /* abf matrix index */ - HeapNode *heaplink; /* fill holes */ - struct PEdge *nextcollapse; /* simplification */ + PHashKey key; /* construct */ + int id; /* abf matrix index */ + HeapNode *heaplink; /* fill holes */ + struct PEdge *nextcollapse; /* simplification */ } u; struct PVert *vert; @@ -120,10 +119,10 @@ typedef struct PFace { struct PFace *nextlink; union PFaceUnion { - PHashKey key; /* construct */ - int chart; /* construct splitting*/ - float area3d; /* stretch */ - int id; /* abf matrix index */ + PHashKey key; /* construct */ + int chart; /* construct splitting*/ + float area3d; /* stretch */ + int id; /* abf matrix index */ } u; struct PEdge *edge; @@ -230,12 +229,12 @@ static int PHashSizes[] = { 4194319, 8388617, 16777259, 33554467, 67108879, 134217757, 268435459 }; -#define PHASH_hash(ph, item) (((uintptr_t) (item))%((unsigned int) (ph)->cursize)) -#define PHASH_edge(v1, v2) ((v1)^(v2)) +#define PHASH_hash(ph, item) (((uintptr_t) (item)) % ((unsigned int) (ph)->cursize)) +#define PHASH_edge(v1, v2) ((v1) ^ (v2)) static PHash *phash_new(PHashLink **list, int sizehint) { - PHash *ph = (PHash*)MEM_callocN(sizeof(PHash), "PHash"); + PHash *ph = (PHash *)MEM_callocN(sizeof(PHash), "PHash"); ph->size = 0; ph->cursize_id = 0; ph->list = list; @@ -244,7 +243,7 @@ static PHash *phash_new(PHashLink **list, int sizehint) ph->cursize_id++; ph->cursize = PHashSizes[ph->cursize_id]; - ph->buckets = (PHashLink**)MEM_callocN(ph->cursize*sizeof(*ph->buckets), "PHashBuckets"); + ph->buckets = (PHashLink **)MEM_callocN(ph->cursize * sizeof(*ph->buckets), "PHashBuckets"); return ph; } @@ -280,12 +279,12 @@ static void phash_insert(PHash *ph, PHashLink *link) ph->size++; - if (ph->size > (size*3)) { + if (ph->size > (size * 3)) { PHashLink *next = NULL, *first = *(ph->list); ph->cursize = PHashSizes[++ph->cursize_id]; MEM_freeN(ph->buckets); - ph->buckets = (PHashLink**)MEM_callocN(ph->cursize*sizeof(*ph->buckets), "PHashBuckets"); + ph->buckets = (PHashLink **)MEM_callocN(ph->cursize * sizeof(*ph->buckets), "PHashBuckets"); ph->size = 0; *(ph->list) = NULL; @@ -340,7 +339,7 @@ static float p_vec_angle_cos(float *v1, float *v2, float *v3) normalize_v3(d1); normalize_v3(d2); - return d1[0]*d2[0] + d1[1]*d2[1] + d1[2]*d2[2]; + return d1[0] * d2[0] + d1[1] * d2[1] + d1[2] * d2[2]; } static float p_vec_angle(float *v1, float *v2, float *v3) @@ -391,8 +390,8 @@ static float p_face_area(PFace *f) static float p_area_signed(float *v1, float *v2, float *v3) { - return 0.5f*(((v2[0] - v1[0])*(v3[1] - v1[1])) - - ((v3[0] - v1[0])*(v2[1] - v1[1]))); + return 0.5f * (((v2[0] - v1[0]) * (v3[1] - v1[1])) - + ((v3[0] - v1[0]) * (v2[1] - v1[1]))); } static float p_face_uv_area_signed(PFace *f) @@ -400,8 +399,8 @@ static float p_face_uv_area_signed(PFace *f) PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; PVert *v1 = e1->vert, *v2 = e2->vert, *v3 = e3->vert; - return 0.5f*(((v2->uv[0] - v1->uv[0])*(v3->uv[1] - v1->uv[1])) - - ((v3->uv[0] - v1->uv[0])*(v2->uv[1] - v1->uv[1]))); + return 0.5f * (((v2->uv[0] - v1->uv[0]) * (v3->uv[1] - v1->uv[1])) - + ((v3->uv[0] - v1->uv[0]) * (v2->uv[1] - v1->uv[1]))); } static float p_edge_length(PEdge *e) @@ -413,7 +412,7 @@ static float p_edge_length(PEdge *e) d[1] = v2->co[1] - v1->co[1]; d[2] = v2->co[2] - v1->co[2]; - return sqrt(d[0]*d[0] + d[1]*d[1] + d[2]*d[2]); + return sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]); } static float p_edge_uv_length(PEdge *e) @@ -424,7 +423,7 @@ static float p_edge_uv_length(PEdge *e) d[0] = v2->uv[0] - v1->uv[0]; d[1] = v2->uv[1] - v1->uv[1]; - return sqrt(d[0]*d[0] + d[1]*d[1]); + return sqrt(d[0] * d[0] + d[1] * d[1]); } static void p_chart_uv_bbox(PChart *chart, float *minv, float *maxv) @@ -433,7 +432,7 @@ static void p_chart_uv_bbox(PChart *chart, float *minv, float *maxv) INIT_MINMAX2(minv, maxv); - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { DO_MINMAX2(v->uv, minv, maxv); } } @@ -442,7 +441,7 @@ static void p_chart_uv_scale(PChart *chart, float scale) { PVert *v; - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { v->uv[0] *= scale; v->uv[1] *= scale; } @@ -452,7 +451,7 @@ static void p_chart_uv_scale_xy(PChart *chart, float x, float y) { PVert *v; - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { v->uv[0] *= x; v->uv[1] *= y; } @@ -462,7 +461,7 @@ static void p_chart_uv_translate(PChart *chart, float trans[2]) { PVert *v; - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { v->uv[0] += trans[0]; v->uv[1] += trans[1]; } @@ -472,14 +471,14 @@ static PBool p_intersect_line_2d_dir(float *v1, float *dir1, float *v2, float *d { float lmbda, div; - div= dir2[0]*dir1[1] - dir2[1]*dir1[0]; + div = dir2[0] * dir1[1] - dir2[1] * dir1[0]; if (div == 0.0f) return P_FALSE; - lmbda= ((v1[1]-v2[1])*dir1[0]-(v1[0]-v2[0])*dir1[1])/div; - isect[0] = v1[0] + lmbda*dir2[0]; - isect[1] = v1[1] + lmbda*dir2[1]; + lmbda = ((v1[1] - v2[1]) * dir1[0] - (v1[0] - v2[0]) * dir1[1]) / div; + isect[0] = v1[0] + lmbda * dir2[0]; + isect[1] = v1[1] + lmbda * dir2[1]; return P_TRUE; } @@ -498,8 +497,8 @@ static PBool p_intersect_line_2d(float *v1, float *v2, float *v3, float *v4, flo if (!p_intersect_line_2d_dir(v1, dir1, v2, dir2, isect)) { /* parallel - should never happen in theory for polygon kernel, but * let's give a point nearby in case things go wrong */ - isect[0] = (v1[0] + v2[0])*0.5f; - isect[1] = (v1[1] + v2[1])*0.5f; + isect[0] = (v1[0] + v2[0]) * 0.5f; + isect[1] = (v1[1] + v2[1]) * 0.5f; return P_FALSE; } @@ -516,7 +515,7 @@ static PEdge *p_wheel_edge_next(PEdge *e) static PEdge *p_wheel_edge_prev(PEdge *e) { - return (e->pair)? e->pair->next: NULL; + return (e->pair) ? e->pair->next : NULL; } static PEdge *p_boundary_edge_next(PEdge *e) @@ -570,10 +569,10 @@ static void p_chart_topological_sanity_check(PChart *chart) PVert *v; PEdge *e; - for (v=chart->verts; v; v=v->nextlink) + for (v = chart->verts; v; v = v->nextlink) param_test_equals_ptr("v->edge->vert", v, v->edge->vert); - for (e=chart->edges; e; e=e->nextlink) { + for (e = chart->edges; e; e = e->nextlink) { if (e->pair) { param_test_equals_ptr("e->pair->pair", e, e->pair->pair); param_test_equals_ptr("pair->vert", e->vert, e->pair->next->vert); @@ -600,13 +599,13 @@ static void p_vert_load_pin_select_uvs(PHandle *handle, PVert *v) v->flag |= PVERT_SELECT; if (e->flag & PEDGE_PIN) { - pinuv[0] += e->orig_uv[0]*handle->aspx; - pinuv[1] += e->orig_uv[1]*handle->aspy; + pinuv[0] += e->orig_uv[0] * handle->aspx; + pinuv[1] += e->orig_uv[1] * handle->aspy; npins++; } else { - v->uv[0] += e->orig_uv[0]*handle->aspx; - v->uv[1] += e->orig_uv[1]*handle->aspy; + v->uv[0] += e->orig_uv[0] * handle->aspx; + v->uv[1] += e->orig_uv[1] * handle->aspy; } nedges++; @@ -616,8 +615,8 @@ static void p_vert_load_pin_select_uvs(PHandle *handle, PVert *v) } while (e && e != (v->edge)); if (npins > 0) { - v->uv[0] = pinuv[0]/npins; - v->uv[1] = pinuv[1]/npins; + v->uv[0] = pinuv[0] / npins; + v->uv[1] = pinuv[1] / npins; v->flag |= PVERT_PIN; } else if (nedges > 0) { @@ -630,10 +629,10 @@ static void p_flush_uvs(PHandle *handle, PChart *chart) { PEdge *e; - for (e=chart->edges; e; e=e->nextlink) { + for (e = chart->edges; e; e = e->nextlink) { if (e->orig_uv) { - e->orig_uv[0] = e->vert->uv[0]/handle->aspx; - e->orig_uv[1] = e->vert->uv[1]/handle->aspy; + e->orig_uv[0] = e->vert->uv[0] / handle->aspx; + e->orig_uv[1] = e->vert->uv[1] / handle->aspy; } } } @@ -643,10 +642,10 @@ static void p_flush_uvs_blend(PHandle *handle, PChart *chart, float blend) PEdge *e; float invblend = 1.0f - blend; - for (e=chart->edges; e; e=e->nextlink) { + for (e = chart->edges; e; e = e->nextlink) { if (e->orig_uv) { - e->orig_uv[0] = blend*e->old_uv[0] + invblend*e->vert->uv[0]/handle->aspx; - e->orig_uv[1] = blend*e->old_uv[1] + invblend*e->vert->uv[1]/handle->aspy; + e->orig_uv[0] = blend * e->old_uv[0] + invblend * e->vert->uv[0] / handle->aspx; + e->orig_uv[1] = blend * e->old_uv[1] + invblend * e->vert->uv[1] / handle->aspy; } } } @@ -691,20 +690,20 @@ static void p_face_restore_uvs(PFace *f) static PVert *p_vert_add(PHandle *handle, PHashKey key, float *co, PEdge *e) { - PVert *v = (PVert*)BLI_memarena_alloc(handle->arena, sizeof *v); + PVert *v = (PVert *)BLI_memarena_alloc(handle->arena, sizeof *v); copy_v3_v3(v->co, co); v->u.key = key; v->edge = e; v->flag = 0; - phash_insert(handle->hash_verts, (PHashLink*)v); + phash_insert(handle->hash_verts, (PHashLink *)v); return v; } static PVert *p_vert_lookup(PHandle *handle, PHashKey key, float *co, PEdge *e) { - PVert *v = (PVert*)phash_lookup(handle->hash_verts, key); + PVert *v = (PVert *)phash_lookup(handle->hash_verts, key); if (v) return v; @@ -714,7 +713,7 @@ static PVert *p_vert_lookup(PHandle *handle, PHashKey key, float *co, PEdge *e) static PVert *p_vert_copy(PChart *chart, PVert *v) { - PVert *nv = (PVert*)BLI_memarena_alloc(chart->handle->arena, sizeof *nv); + PVert *nv = (PVert *)BLI_memarena_alloc(chart->handle->arena, sizeof *nv); copy_v3_v3(nv->co, v->co); nv->uv[0] = v->uv[0]; @@ -729,7 +728,7 @@ static PVert *p_vert_copy(PChart *chart, PVert *v) static PEdge *p_edge_lookup(PHandle *handle, PHashKey *vkeys) { PHashKey key = PHASH_edge(vkeys[0], vkeys[1]); - PEdge *e = (PEdge*)phash_lookup(handle->hash_edges, key); + PEdge *e = (PEdge *)phash_lookup(handle->hash_edges, key); while (e) { if ((e->vert->u.key == vkeys[0]) && (e->next->vert->u.key == vkeys[1])) @@ -737,7 +736,7 @@ static PEdge *p_edge_lookup(PHandle *handle, PHashKey *vkeys) else if ((e->vert->u.key == vkeys[1]) && (e->next->vert->u.key == vkeys[0])) return e; - e = (PEdge*)phash_next(handle->hash_edges, key, (PHashLink*)e); + e = (PEdge *)phash_next(handle->hash_edges, key, (PHashLink *)e); } return NULL; @@ -745,10 +744,10 @@ static PEdge *p_edge_lookup(PHandle *handle, PHashKey *vkeys) int p_face_exists(ParamHandle *phandle, ParamKey *pvkeys, int i1, int i2, int i3) { - PHandle *handle = (PHandle*)phandle; - PHashKey *vkeys = (PHashKey*)pvkeys; + PHandle *handle = (PHandle *)phandle; + PHashKey *vkeys = (PHashKey *)pvkeys; PHashKey key = PHASH_edge(vkeys[i1], vkeys[i2]); - PEdge *e = (PEdge*)phash_lookup(handle->hash_edges, key); + PEdge *e = (PEdge *)phash_lookup(handle->hash_edges, key); while (e) { if ((e->vert->u.key == vkeys[i1]) && (e->next->vert->u.key == vkeys[i2])) { @@ -760,7 +759,7 @@ int p_face_exists(ParamHandle *phandle, ParamKey *pvkeys, int i1, int i2, int i3 return P_TRUE; } - e = (PEdge*)phash_next(handle->hash_edges, key, (PHashLink*)e); + e = (PEdge *)phash_next(handle->hash_edges, key, (PHashLink *)e); } return P_FALSE; @@ -768,7 +767,7 @@ int p_face_exists(ParamHandle *phandle, ParamKey *pvkeys, int i1, int i2, int i3 static PChart *p_chart_new(PHandle *handle) { - PChart *chart = (PChart*)MEM_callocN(sizeof*chart, "PChart"); + PChart *chart = (PChart *)MEM_callocN(sizeof *chart, "PChart"); chart->handle = handle; return chart; @@ -800,12 +799,12 @@ static PBool p_edge_implicit_seam(PEdge *e, PEdge *ep) uvp2 = ep->orig_uv; } - if ((fabsf(uv1[0]-uvp1[0]) > limit[0]) || (fabsf(uv1[1]-uvp1[1]) > limit[1])) { + if ((fabsf(uv1[0] - uvp1[0]) > limit[0]) || (fabsf(uv1[1] - uvp1[1]) > limit[1])) { e->flag |= PEDGE_SEAM; ep->flag |= PEDGE_SEAM; return P_TRUE; } - if ((fabsf(uv2[0]-uvp2[0]) > limit[0]) || (fabsf(uv2[1]-uvp2[1]) > limit[1])) { + if ((fabsf(uv2[0] - uvp2[0]) > limit[0]) || (fabsf(uv2[1] - uvp2[1]) > limit[1])) { e->flag |= PEDGE_SEAM; ep->flag |= PEDGE_SEAM; return P_TRUE; @@ -826,7 +825,7 @@ static PBool p_edge_has_pair(PHandle *handle, PEdge *e, PEdge **pair, PBool impl return P_FALSE; key = PHASH_edge(key1, key2); - pe = (PEdge*)phash_lookup(handle->hash_edges, key); + pe = (PEdge *)phash_lookup(handle->hash_edges, key); *pair = NULL; while (pe) { @@ -835,11 +834,13 @@ static PBool p_edge_has_pair(PHandle *handle, PEdge *e, PEdge **pair, PBool impl v2 = pe->next->vert; if (((v1->u.key == key1) && (v2->u.key == key2)) || - ((v1->u.key == key2) && (v2->u.key == key1))) { + ((v1->u.key == key2) && (v2->u.key == key1))) + { /* don't connect seams and t-junctions */ if ((pe->flag & PEDGE_SEAM) || *pair || - (impl && p_edge_implicit_seam(e, pe))) { + (impl && p_edge_implicit_seam(e, pe))) + { *pair = NULL; return P_FALSE; } @@ -848,7 +849,7 @@ static PBool p_edge_has_pair(PHandle *handle, PEdge *e, PEdge **pair, PBool impl } } - pe = (PEdge*)phash_next(handle->hash_edges, key, (PHashLink*)pe); + pe = (PEdge *)phash_next(handle->hash_edges, key, (PHashLink *)pe); } if (*pair && (e->vert == (*pair)->vert)) { @@ -884,7 +885,7 @@ static PBool p_edge_connect_pair(PHandle *handle, PEdge *e, PEdge ***stack, PBoo static int p_connect_pairs(PHandle *handle, PBool impl) { - PEdge **stackbase = MEM_mallocN(sizeof*stackbase*phash_size(handle->hash_faces), "Pstackbase"); + PEdge **stackbase = MEM_mallocN(sizeof *stackbase * phash_size(handle->hash_faces), "Pstackbase"); PEdge **stack = stackbase; PFace *f, *first; PEdge *e, *e1, *e2; @@ -892,7 +893,7 @@ static int p_connect_pairs(PHandle *handle, PBool impl) int ncharts = 0; /* connect pairs, count edges, set vertex-edge pointer to a pairless edge */ - for (first=chart->faces; first; first=first->nextlink) { + for (first = chart->faces; first; first = first->nextlink) { if (first->flag & PFACE_CONNECTED) continue; @@ -979,7 +980,7 @@ static void p_split_vert(PChart *chart, PEdge *e) static PChart **p_split_charts(PHandle *handle, PChart *chart, int ncharts) { - PChart **charts = MEM_mallocN(sizeof*charts * ncharts, "PCharts"), *nchart; + PChart **charts = MEM_mallocN(sizeof *charts * ncharts, "PCharts"), *nchart; PFace *f, *nextf; int i; @@ -1021,12 +1022,12 @@ static PFace *p_face_add(PHandle *handle) PEdge *e1, *e2, *e3; /* allocate */ - f = (PFace*)BLI_memarena_alloc(handle->arena, sizeof *f); - f->flag=0; // init ! + f = (PFace *)BLI_memarena_alloc(handle->arena, sizeof *f); + f->flag = 0; // init ! - e1 = (PEdge*)BLI_memarena_alloc(handle->arena, sizeof *e1); - e2 = (PEdge*)BLI_memarena_alloc(handle->arena, sizeof *e2); - e3 = (PEdge*)BLI_memarena_alloc(handle->arena, sizeof *e3); + e1 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof *e1); + e2 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof *e2); + e3 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof *e3); /* set up edges */ f->edge = e1; @@ -1040,16 +1041,16 @@ static PFace *p_face_add(PHandle *handle) e2->pair = NULL; e3->pair = NULL; - e1->flag =0; - e2->flag =0; - e3->flag =0; + e1->flag = 0; + e2->flag = 0; + e3->flag = 0; return f; } static PFace *p_face_add_construct(PHandle *handle, ParamKey key, ParamKey *vkeys, - float *co[3], float *uv[3], int i1, int i2, int i3, - ParamBool *pin, ParamBool *select) + float *co[3], float *uv[3], int i1, int i2, int i3, + ParamBool *pin, ParamBool *select) { PFace *f = p_face_add(handle); PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; @@ -1076,15 +1077,15 @@ static PFace *p_face_add_construct(PHandle *handle, ParamKey key, ParamKey *vkey /* insert into hash */ f->u.key = key; - phash_insert(handle->hash_faces, (PHashLink*)f); + phash_insert(handle->hash_faces, (PHashLink *)f); e1->u.key = PHASH_edge(vkeys[i1], vkeys[i2]); e2->u.key = PHASH_edge(vkeys[i2], vkeys[i3]); e3->u.key = PHASH_edge(vkeys[i3], vkeys[i1]); - phash_insert(handle->hash_edges, (PHashLink*)e1); - phash_insert(handle->hash_edges, (PHashLink*)e2); - phash_insert(handle->hash_edges, (PHashLink*)e3); + phash_insert(handle->hash_edges, (PHashLink *)e1); + phash_insert(handle->hash_edges, (PHashLink *)e2); + phash_insert(handle->hash_edges, (PHashLink *)e3); return f; } @@ -1117,7 +1118,7 @@ static PFace *p_face_add_fill(PChart *chart, PVert *v1, PVert *v2, PVert *v3) static PBool p_quad_split_direction(PHandle *handle, float **co, PHashKey *vkeys) { - float fac= len_v3v3(co[0], co[2]) - len_v3v3(co[1], co[3]); + float fac = len_v3v3(co[0], co[2]) - len_v3v3(co[1], co[3]); PBool dir = (fac <= 0.0f); /* the face exists check is there because of a special case: when @@ -1125,11 +1126,11 @@ static PBool p_quad_split_direction(PHandle *handle, float **co, PHashKey *vkeys * triangles, resulting in two identical triangles. for example in * suzanne's nose. */ if (dir) { - if (p_face_exists(handle,vkeys,0,1,2) || p_face_exists(handle,vkeys,0,2,3)) + if (p_face_exists(handle, vkeys, 0, 1, 2) || p_face_exists(handle, vkeys, 0, 2, 3)) return !dir; } else { - if (p_face_exists(handle,vkeys,0,1,3) || p_face_exists(handle,vkeys,1,2,3)) + if (p_face_exists(handle, vkeys, 0, 1, 3) || p_face_exists(handle, vkeys, 1, 2, 3)) return !dir; } @@ -1148,7 +1149,7 @@ static void p_chart_boundaries(PChart *chart, int *nboundaries, PEdge **outer) if (outer) *outer = NULL; - for (e=chart->edges; e; e=e->nextlink) { + for (e = chart->edges; e; e = e->nextlink) { if (e->pair || (e->flag & PEDGE_DONE)) continue; @@ -1170,7 +1171,7 @@ static void p_chart_boundaries(PChart *chart, int *nboundaries, PEdge **outer) } } - for (e=chart->edges; e; e=e->nextlink) + for (e = chart->edges; e; e = e->nextlink) e->flag &= ~PEDGE_DONE; } @@ -1228,7 +1229,7 @@ static void p_chart_fill_boundary(PChart *chart, PEdge *be, int nedges) while (nedges > 2) { PEdge *ne, *ne1, *ne2; - e = (PEdge*)BLI_heap_popmin(heap); + e = (PEdge *)BLI_heap_popmin(heap); e1 = p_boundary_edge_prev(e); e2 = p_boundary_edge_next(e); @@ -1285,7 +1286,7 @@ static void p_chart_fill_boundaries(PChart *chart, PEdge *outer) PEdge *e, *be; /* *enext - as yet unused */ int nedges; - for (e=chart->edges; e; e=e->nextlink) { + for (e = chart->edges; e; e = e->nextlink) { /* enext = e->nextlink; - as yet unused */ if (e->pair || (e->flag & PEDGE_FILLED)) @@ -1322,7 +1323,7 @@ static void p_polygon_kernel_clip(float (*oldpoints)[2], int noldpoints, float ( float *p2, *p1, isect[2]; int i, p2in, p1in; - p1 = oldpoints[noldpoints-1]; + p1 = oldpoints[noldpoints - 1]; p1in = p_polygon_point_in(cp1, cp2, p1); *nnewpoints = 0; @@ -1364,20 +1365,20 @@ static void p_polygon_kernel_center(float (*points)[2], int npoints, float *cent int i, size, nnewpoints = npoints; float (*oldpoints)[2], (*newpoints)[2], *p1, *p2; - size = npoints*3; - oldpoints = MEM_mallocN(sizeof(float)*2*size, "PPolygonOldPoints"); - newpoints = MEM_mallocN(sizeof(float)*2*size, "PPolygonNewPoints"); + size = npoints * 3; + oldpoints = MEM_mallocN(sizeof(float) * 2 * size, "PPolygonOldPoints"); + newpoints = MEM_mallocN(sizeof(float) * 2 * size, "PPolygonNewPoints"); - memcpy(oldpoints, points, sizeof(float)*2*npoints); + memcpy(oldpoints, points, sizeof(float) * 2 * npoints); for (i = 0; i < npoints; i++) { p1 = points[i]; - p2 = points[(i+1)%npoints]; + p2 = points[(i + 1) % npoints]; p_polygon_kernel_clip(oldpoints, nnewpoints, newpoints, &nnewpoints, p1, p2); if (nnewpoints == 0) { /* degenerate case, use center of original polygon */ - memcpy(oldpoints, points, sizeof(float)*2*npoints); + memcpy(oldpoints, points, sizeof(float) * 2 * npoints); nnewpoints = npoints; break; } @@ -1392,13 +1393,13 @@ static void p_polygon_kernel_center(float (*points)[2], int npoints, float *cent return; } - if (nnewpoints*2 > size) { + if (nnewpoints * 2 > size) { size *= 2; MEM_freeN(oldpoints); - oldpoints = MEM_mallocN(sizeof(float)*2*size, "oldpoints"); - memcpy(oldpoints, newpoints, sizeof(float)*2*nnewpoints); + oldpoints = MEM_mallocN(sizeof(float) * 2 * size, "oldpoints"); + memcpy(oldpoints, newpoints, sizeof(float) * 2 * nnewpoints); MEM_freeN(newpoints); - newpoints = MEM_mallocN(sizeof(float)*2*size, "newpoints"); + newpoints = MEM_mallocN(sizeof(float) * 2 * size, "newpoints"); } else { float (*sw_points)[2] = oldpoints; @@ -1441,7 +1442,7 @@ static float p_vert_cotan(float *v1, float *v2, float *v3) if (clen == 0.0f) return 0.0f; - return dot_v3v3(a, b)/clen; + return dot_v3v3(a, b) / clen; } static PBool p_vert_flipped_wheel_triangle(PVert *v) @@ -1480,10 +1481,10 @@ static PBool p_vert_map_harmonic_weights(PVert *v) v2 = e->pair->next->next->vert; t2 = p_vert_cotan(v2->co, e->pair->vert->co, v1->co); - weight = 0.5f*(t1 + t2); + weight = 0.5f * (t1 + t2); weightsum += weight; - positionsum[0] += weight*e->pair->vert->uv[0]; - positionsum[1] += weight*e->pair->vert->uv[1]; + positionsum[0] += weight * e->pair->vert->uv[0]; + positionsum[1] += weight * e->pair->vert->uv[1]; e = p_wheel_edge_next(e); } while (e && (e != v->edge)); @@ -1502,15 +1503,15 @@ static PBool p_vert_map_harmonic_weights(PVert *v) t2 = p_vert_cotan(v2->co, v->co, v1->co); weightsum += t1 + t2; - positionsum[0] += (v2->uv[1] - v1->uv[1]) + (t1*v2->uv[0] + t2*v1->uv[0]); - positionsum[1] += (v1->uv[0] - v2->uv[0]) + (t1*v2->uv[1] + t2*v1->uv[1]); + positionsum[0] += (v2->uv[1] - v1->uv[1]) + (t1 * v2->uv[0] + t2 * v1->uv[0]); + positionsum[1] += (v1->uv[0] - v2->uv[0]) + (t1 * v2->uv[1] + t2 * v1->uv[1]); e = p_wheel_edge_next(e); } while (e && (e != v->edge)); } if (weightsum != 0.0f) { - weightsum = 1.0f/weightsum; + weightsum = 1.0f / weightsum; positionsum[0] *= weightsum; positionsum[1] *= weightsum; } @@ -1551,7 +1552,7 @@ static void p_vert_harmonic_insert(PVert *v) if (e == NULL) npoints++; - points = MEM_mallocN(sizeof(float)*2*npoints, "PHarmonicPoints"); + points = MEM_mallocN(sizeof(float) * 2 * npoints, "PHarmonicPoints"); e = v->edge; i = 0; @@ -1789,7 +1790,7 @@ static PBool p_collapse_allowed_geometric(PEdge *edge, PEdge *pair) p_collapsing_verts(edge, pair, &oldv, &keepv); - angulardefect = 2*M_PI; + angulardefect = 2 * M_PI; e = oldv->edge; do { @@ -1819,7 +1820,7 @@ static PBool p_collapse_allowed_geometric(PEdge *edge, PEdge *pair) b[2] = M_PI - b[0] - b[1]; /* abf criterion 1: avoid sharp and obtuse angles */ - minangle = 15.0f*M_PI/180.0f; + minangle = 15.0f * M_PI / 180.0f; maxangle = M_PI - minangle; for (i = 0; i < 3; i++) { @@ -1834,7 +1835,7 @@ static PBool p_collapse_allowed_geometric(PEdge *edge, PEdge *pair) if (p_vert_interior(oldv)) { /* hlscm criterion: angular defect smaller than threshold */ - if (fabs(angulardefect) > (M_PI*30.0/180.0)) + if (fabs(angulardefect) > (M_PI * 30.0 / 180.0)) return P_FALSE; } else { @@ -1847,7 +1848,7 @@ static PBool p_collapse_allowed_geometric(PEdge *edge, PEdge *pair) /* don't collapse significant boundary changes */ angle = p_vec_angle(v1->co, oldv->co, v2->co); - if (angle < (M_PI*160.0/180.0)) + if (angle < (M_PI * 160.0 / 180.0)) return P_FALSE; } @@ -1864,7 +1865,7 @@ static PBool p_collapse_allowed(PEdge *edge, PEdge *pair) return P_FALSE; return (p_collapse_allowed_topologic(edge, pair) && - p_collapse_allowed_geometric(edge, pair)); + p_collapse_allowed_geometric(edge, pair)); } static float p_collapse_cost(PEdge *edge, PEdge *pair) @@ -1881,8 +1882,8 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) int nshapeold = 0, nshapenew = 0; p_collapsing_verts(edge, pair, &oldv, &keepv); - oldf1 = (edge)? edge->face: NULL; - oldf2 = (pair)? pair->face: NULL; + oldf1 = (edge) ? edge->face : NULL; + oldf2 = (pair) ? pair->face : NULL; sub_v3_v3v3(edgevec, keepv->co, oldv->co); @@ -1900,7 +1901,7 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) sub_v3_v3v3(tetrav3, co2, oldv->co); cross_v3_v3v3(c, tetrav2, tetrav3); - volumecost += fabs(dot_v3v3(edgevec, c)/6.0f); + volumecost += fabs(dot_v3v3(edgevec, c) / 6.0f); #if 0 shapecost += dot_v3v3(co1, keepv->co); @@ -1909,19 +1910,19 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) #endif p_triangle_angles(oldv->co, co1, co2, &a1, &a2, &a3); - a1 = a1 - M_PI/3.0; - a2 = a2 - M_PI/3.0; - a3 = a3 - M_PI/3.0; - shapeold = (a1*a1 + a2*a2 + a3*a3)/((M_PI/2)*(M_PI/2)); + a1 = a1 - M_PI / 3.0; + a2 = a2 - M_PI / 3.0; + a3 = a3 - M_PI / 3.0; + shapeold = (a1 * a1 + a2 * a2 + a3 * a3) / ((M_PI / 2) * (M_PI / 2)); nshapeold++; } else { p_triangle_angles(keepv->co, co1, co2, &a1, &a2, &a3); - a1 = a1 - M_PI/3.0; - a2 = a2 - M_PI/3.0; - a3 = a3 - M_PI/3.0; - shapenew = (a1*a1 + a2*a2 + a3*a3)/((M_PI/2)*(M_PI/2)); + a1 = a1 - M_PI / 3.0; + a2 = a2 - M_PI / 3.0; + a3 = a3 - M_PI / 3.0; + shapenew = (a1 * a1 + a2 * a2 + a3 * a3) / ((M_PI / 2) * (M_PI / 2)); nshapenew++; } @@ -1938,13 +1939,13 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) elen = len_v3(edgevec); weight = 1.0f; /* 0.2f */ - cost = weight*volumecost*volumecost + elen*elen*areacost*areacost; + cost = weight * volumecost * volumecost + elen * elen * areacost * areacost; #if 0 cost += shapecost; #else shapeold /= nshapeold; shapenew /= nshapenew; - shapecost = (shapeold + 0.00001)/(shapenew + 0.00001); + shapecost = (shapeold + 0.00001) / (shapenew + 0.00001); cost *= shapecost; #endif @@ -2005,7 +2006,7 @@ static void p_chart_post_collapse_flush(PChart *chart, PEdge *collapsed) chart->nverts = chart->nedges = chart->nfaces = 0; - for (v=verts; v; v=nextv) { + for (v = verts; v; v = nextv) { nextv = v->nextlink; if (v->flag & PVERT_COLLAPSE) { @@ -2019,7 +2020,7 @@ static void p_chart_post_collapse_flush(PChart *chart, PEdge *collapsed) } } - for (e=edges; e; e=nexte) { + for (e = edges; e; e = nexte) { nexte = e->nextlink; if (!collapsed || !(e->flag & PEDGE_COLLAPSE_EDGE)) { @@ -2037,7 +2038,7 @@ static void p_chart_post_collapse_flush(PChart *chart, PEdge *collapsed) /* these are added last so they can be popped of in the right order * for splitting */ - for (e=collapsed; e; e=e->nextlink) { + for (e = collapsed; e; e = e->nextlink) { e->nextlink = e->u.nextcollapse; laste = e; } @@ -2046,7 +2047,7 @@ static void p_chart_post_collapse_flush(PChart *chart, PEdge *collapsed) chart->collapsed_edges = collapsed; } - for (f=faces; f; f=nextf) { + for (f = faces; f; f = nextf) { nextf = f->nextlink; if (f->flag & PFACE_COLLAPSE) { @@ -2069,21 +2070,21 @@ static void p_chart_post_split_flush(PChart *chart) PEdge *e, *nexte = NULL; PFace *f, *nextf = NULL; - for (v=chart->collapsed_verts; v; v=nextv) { + for (v = chart->collapsed_verts; v; v = nextv) { nextv = v->nextlink; v->nextlink = chart->verts; chart->verts = v; chart->nverts++; } - for (e=chart->collapsed_edges; e; e=nexte) { + for (e = chart->collapsed_edges; e; e = nexte) { nexte = e->nextlink; e->nextlink = chart->edges; chart->edges = e; chart->nedges++; } - for (f=chart->collapsed_faces; f; f=nextf) { + for (f = chart->collapsed_faces; f; f = nextf) { nextf = f->nextlink; f->nextlink = chart->faces; chart->faces = f; @@ -2107,10 +2108,10 @@ static void p_chart_simplify_compute(PChart *chart) PEdge *collapsededges = NULL, *e; int nwheelverts, i, ncollapsed = 0; - wheelverts = MEM_mallocN(sizeof(PVert*)*chart->nverts, "PChartWheelVerts"); + wheelverts = MEM_mallocN(sizeof(PVert *) * chart->nverts, "PChartWheelVerts"); /* insert all potential collapses into heap */ - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { float cost; PEdge *e = NULL; @@ -2122,7 +2123,7 @@ static void p_chart_simplify_compute(PChart *chart) v->u.heaplink = NULL; } - for (e=chart->edges; e; e=e->nextlink) + for (e = chart->edges; e; e = e->nextlink) e->u.nextcollapse = NULL; /* pop edge collapse out of heap one by one */ @@ -2131,7 +2132,7 @@ static void p_chart_simplify_compute(PChart *chart) break; HeapNode *link = BLI_heap_top(heap); - PEdge *edge = (PEdge*)BLI_heap_popmin(heap), *pair = edge->pair; + PEdge *edge = (PEdge *)BLI_heap_popmin(heap), *pair = edge->pair; PVert *oldv, *keepv; PEdge *wheele, *nexte; @@ -2140,9 +2141,9 @@ static void p_chart_simplify_compute(PChart *chart) collapsededges = edge; if (edge->vert->u.heaplink != link) { - edge->flag |= (PEDGE_COLLAPSE_EDGE|PEDGE_COLLAPSE_PAIR); + edge->flag |= (PEDGE_COLLAPSE_EDGE | PEDGE_COLLAPSE_PAIR); edge->next->vert->u.heaplink = NULL; - SWAP(PEdge*, edge, pair); + SWAP(PEdge *, edge, pair); } else { edge->flag |= PEDGE_COLLAPSE_EDGE; @@ -2200,7 +2201,7 @@ static void p_chart_complexify(PChart *chart) PVert *newv, *keepv; int x = 0; - for (e=chart->collapsed_edges; e; e=e->nextlink) { + for (e = chart->collapsed_edges; e; e = e->nextlink) { if (!(e->flag & PEDGE_COLLAPSE_EDGE)) break; @@ -2208,7 +2209,7 @@ static void p_chart_complexify(PChart *chart) pair = e->pair; if (edge->flag & PEDGE_COLLAPSE_PAIR) { - SWAP(PEdge*, edge, pair); + SWAP(PEdge *, edge, pair); } p_split_vertex(edge, pair); @@ -2252,28 +2253,28 @@ static void p_abf_setup_system(PAbfSystem *sys) { int i; - sys->alpha = (float*)MEM_mallocN(sizeof(float)*sys->nangles, "ABFalpha"); - sys->beta = (float*)MEM_mallocN(sizeof(float)*sys->nangles, "ABFbeta"); - sys->sine = (float*)MEM_mallocN(sizeof(float)*sys->nangles, "ABFsine"); - sys->cosine = (float*)MEM_mallocN(sizeof(float)*sys->nangles, "ABFcosine"); - sys->weight = (float*)MEM_mallocN(sizeof(float)*sys->nangles, "ABFweight"); + sys->alpha = (float *)MEM_mallocN(sizeof(float) * sys->nangles, "ABFalpha"); + sys->beta = (float *)MEM_mallocN(sizeof(float) * sys->nangles, "ABFbeta"); + sys->sine = (float *)MEM_mallocN(sizeof(float) * sys->nangles, "ABFsine"); + sys->cosine = (float *)MEM_mallocN(sizeof(float) * sys->nangles, "ABFcosine"); + sys->weight = (float *)MEM_mallocN(sizeof(float) * sys->nangles, "ABFweight"); - sys->bAlpha = (float*)MEM_mallocN(sizeof(float)*sys->nangles, "ABFbalpha"); - sys->bTriangle = (float*)MEM_mallocN(sizeof(float)*sys->nfaces, "ABFbtriangle"); - sys->bInterior = (float*)MEM_mallocN(sizeof(float)*2*sys->ninterior, "ABFbinterior"); + sys->bAlpha = (float *)MEM_mallocN(sizeof(float) * sys->nangles, "ABFbalpha"); + sys->bTriangle = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFbtriangle"); + sys->bInterior = (float *)MEM_mallocN(sizeof(float) * 2 * sys->ninterior, "ABFbinterior"); - sys->lambdaTriangle = (float*)MEM_callocN(sizeof(float)*sys->nfaces, "ABFlambdatri"); - sys->lambdaPlanar = (float*)MEM_callocN(sizeof(float)*sys->ninterior, "ABFlamdaplane"); - sys->lambdaLength = (float*)MEM_mallocN(sizeof(float)*sys->ninterior, "ABFlambdalen"); + sys->lambdaTriangle = (float *)MEM_callocN(sizeof(float) * sys->nfaces, "ABFlambdatri"); + sys->lambdaPlanar = (float *)MEM_callocN(sizeof(float) * sys->ninterior, "ABFlamdaplane"); + sys->lambdaLength = (float *)MEM_mallocN(sizeof(float) * sys->ninterior, "ABFlambdalen"); - sys->J2dt = MEM_mallocN(sizeof(float)*sys->nangles*3, "ABFj2dt"); - sys->bstar = (float*)MEM_mallocN(sizeof(float)*sys->nfaces, "ABFbstar"); - sys->dstar = (float*)MEM_mallocN(sizeof(float)*sys->nfaces, "ABFdstar"); + sys->J2dt = MEM_mallocN(sizeof(float) * sys->nangles * 3, "ABFj2dt"); + sys->bstar = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFbstar"); + sys->dstar = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFdstar"); for (i = 0; i < sys->ninterior; i++) sys->lambdaLength[i] = 1.0; - sys->minangle = 7.5*M_PI/180.0; + sys->minangle = 7.5 * M_PI / 180.0; sys->maxangle = (float)M_PI - sys->minangle; } @@ -2346,7 +2347,7 @@ static float p_abf_compute_grad_alpha(PAbfSystem *sys, PFace *f, PEdge *e) PVert *v = e->vert, *v1 = e->next->vert, *v2 = e->next->next->vert; float deriv; - deriv = (sys->alpha[e->u.id] - sys->beta[e->u.id])*sys->weight[e->u.id]; + deriv = (sys->alpha[e->u.id] - sys->beta[e->u.id]) * sys->weight[e->u.id]; deriv += sys->lambdaTriangle[f->u.id]; if (v->flag & PVERT_INTERIOR) { @@ -2355,12 +2356,12 @@ static float p_abf_compute_grad_alpha(PAbfSystem *sys, PFace *f, PEdge *e) if (v1->flag & PVERT_INTERIOR) { float product = p_abf_compute_sin_product(sys, v1, e->u.id); - deriv += sys->lambdaLength[v1->u.id]*product; + deriv += sys->lambdaLength[v1->u.id] * product; } if (v2->flag & PVERT_INTERIOR) { float product = p_abf_compute_sin_product(sys, v2, e->u.id); - deriv += sys->lambdaLength[v2->u.id]*product; + deriv += sys->lambdaLength[v2->u.id] * product; } return deriv; @@ -2373,7 +2374,7 @@ static float p_abf_compute_gradient(PAbfSystem *sys, PChart *chart) PVert *v; float norm = 0.0; - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; float gtriangle, galpha1, galpha2, galpha3; @@ -2385,16 +2386,16 @@ static float p_abf_compute_gradient(PAbfSystem *sys, PChart *chart) sys->bAlpha[e2->u.id] = -galpha2; sys->bAlpha[e3->u.id] = -galpha3; - norm += galpha1*galpha1 + galpha2*galpha2 + galpha3*galpha3; + norm += galpha1 * galpha1 + galpha2 * galpha2 + galpha3 * galpha3; gtriangle = sys->alpha[e1->u.id] + sys->alpha[e2->u.id] + sys->alpha[e3->u.id] - (float)M_PI; sys->bTriangle[f->u.id] = -gtriangle; - norm += gtriangle*gtriangle; + norm += gtriangle * gtriangle; } - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { if (v->flag & PVERT_INTERIOR) { - float gplanar = -2*M_PI, glength; + float gplanar = -2 * M_PI, glength; e = v->edge; do { @@ -2403,11 +2404,11 @@ static float p_abf_compute_gradient(PAbfSystem *sys, PChart *chart) } while (e && (e != v->edge)); sys->bInterior[v->u.id] = -gplanar; - norm += gplanar*gplanar; + norm += gplanar * gplanar; glength = p_abf_compute_sin_product(sys, v, -1); sys->bInterior[sys->ninterior + v->u.id] = -glength; - norm += glength*glength; + norm += glength * glength; } } @@ -2418,7 +2419,7 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) { PFace *f; PEdge *e; - int i, j, ninterior = sys->ninterior, nvar = 2*sys->ninterior; + int i, j, ninterior = sys->ninterior, nvar = 2 * sys->ninterior; PBool success; nlNewContext(); @@ -2431,30 +2432,30 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) for (i = 0; i < nvar; i++) nlRightHandSideAdd(0, i, sys->bInterior[i]); - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { float wi1, wi2, wi3, b, si, beta[3], j2[3][3], W[3][3]; float row1[6], row2[6], row3[6]; int vid[6]; PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; PVert *v1 = e1->vert, *v2 = e2->vert, *v3 = e3->vert; - wi1 = 1.0f/sys->weight[e1->u.id]; - wi2 = 1.0f/sys->weight[e2->u.id]; - wi3 = 1.0f/sys->weight[e3->u.id]; + wi1 = 1.0f / sys->weight[e1->u.id]; + wi2 = 1.0f / sys->weight[e2->u.id]; + wi3 = 1.0f / sys->weight[e3->u.id]; /* bstar1 = (J1*dInv*bAlpha - bTriangle) */ - b = sys->bAlpha[e1->u.id]*wi1; - b += sys->bAlpha[e2->u.id]*wi2; - b += sys->bAlpha[e3->u.id]*wi3; + b = sys->bAlpha[e1->u.id] * wi1; + b += sys->bAlpha[e2->u.id] * wi2; + b += sys->bAlpha[e3->u.id] * wi3; b -= sys->bTriangle[f->u.id]; /* si = J1*d*J1t */ - si = 1.0f/(wi1 + wi2 + wi3); + si = 1.0f / (wi1 + wi2 + wi3); /* J1t*si*bstar1 - bAlpha */ - beta[0] = b*si - sys->bAlpha[e1->u.id]; - beta[1] = b*si - sys->bAlpha[e2->u.id]; - beta[2] = b*si - sys->bAlpha[e3->u.id]; + beta[0] = b * si - sys->bAlpha[e1->u.id]; + beta[1] = b * si - sys->bAlpha[e2->u.id]; + beta[2] = b * si - sys->bAlpha[e3->u.id]; /* use this later for computing other lambda's */ sys->bstar[f->u.id] = b; @@ -2472,59 +2473,59 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) vid[3] = ninterior + v1->u.id; sys->J2dt[e1->u.id][0] = j2[0][0] = 1.0f * wi1; - sys->J2dt[e2->u.id][0] = j2[1][0] = p_abf_compute_sin_product(sys, v1, e2->u.id)*wi2; - sys->J2dt[e3->u.id][0] = j2[2][0] = p_abf_compute_sin_product(sys, v1, e3->u.id)*wi3; + sys->J2dt[e2->u.id][0] = j2[1][0] = p_abf_compute_sin_product(sys, v1, e2->u.id) * wi2; + sys->J2dt[e3->u.id][0] = j2[2][0] = p_abf_compute_sin_product(sys, v1, e3->u.id) * wi3; - nlRightHandSideAdd(0, v1->u.id, j2[0][0]*beta[0]); - nlRightHandSideAdd(0, ninterior + v1->u.id, j2[1][0]*beta[1] + j2[2][0]*beta[2]); + nlRightHandSideAdd(0, v1->u.id, j2[0][0] * beta[0]); + nlRightHandSideAdd(0, ninterior + v1->u.id, j2[1][0] * beta[1] + j2[2][0] * beta[2]); - row1[0] = j2[0][0]*W[0][0]; - row2[0] = j2[0][0]*W[1][0]; - row3[0] = j2[0][0]*W[2][0]; + row1[0] = j2[0][0] * W[0][0]; + row2[0] = j2[0][0] * W[1][0]; + row3[0] = j2[0][0] * W[2][0]; - row1[3] = j2[1][0]*W[0][1] + j2[2][0]*W[0][2]; - row2[3] = j2[1][0]*W[1][1] + j2[2][0]*W[1][2]; - row3[3] = j2[1][0]*W[2][1] + j2[2][0]*W[2][2]; + row1[3] = j2[1][0] * W[0][1] + j2[2][0] * W[0][2]; + row2[3] = j2[1][0] * W[1][1] + j2[2][0] * W[1][2]; + row3[3] = j2[1][0] * W[2][1] + j2[2][0] * W[2][2]; } if (v2->flag & PVERT_INTERIOR) { vid[1] = v2->u.id; vid[4] = ninterior + v2->u.id; - sys->J2dt[e1->u.id][1] = j2[0][1] = p_abf_compute_sin_product(sys, v2, e1->u.id)*wi1; - sys->J2dt[e2->u.id][1] = j2[1][1] = 1.0f*wi2; - sys->J2dt[e3->u.id][1] = j2[2][1] = p_abf_compute_sin_product(sys, v2, e3->u.id)*wi3; + sys->J2dt[e1->u.id][1] = j2[0][1] = p_abf_compute_sin_product(sys, v2, e1->u.id) * wi1; + sys->J2dt[e2->u.id][1] = j2[1][1] = 1.0f * wi2; + sys->J2dt[e3->u.id][1] = j2[2][1] = p_abf_compute_sin_product(sys, v2, e3->u.id) * wi3; - nlRightHandSideAdd(0, v2->u.id, j2[1][1]*beta[1]); - nlRightHandSideAdd(0, ninterior + v2->u.id, j2[0][1]*beta[0] + j2[2][1]*beta[2]); + nlRightHandSideAdd(0, v2->u.id, j2[1][1] * beta[1]); + nlRightHandSideAdd(0, ninterior + v2->u.id, j2[0][1] * beta[0] + j2[2][1] * beta[2]); - row1[1] = j2[1][1]*W[0][1]; - row2[1] = j2[1][1]*W[1][1]; - row3[1] = j2[1][1]*W[2][1]; + row1[1] = j2[1][1] * W[0][1]; + row2[1] = j2[1][1] * W[1][1]; + row3[1] = j2[1][1] * W[2][1]; - row1[4] = j2[0][1]*W[0][0] + j2[2][1]*W[0][2]; - row2[4] = j2[0][1]*W[1][0] + j2[2][1]*W[1][2]; - row3[4] = j2[0][1]*W[2][0] + j2[2][1]*W[2][2]; + row1[4] = j2[0][1] * W[0][0] + j2[2][1] * W[0][2]; + row2[4] = j2[0][1] * W[1][0] + j2[2][1] * W[1][2]; + row3[4] = j2[0][1] * W[2][0] + j2[2][1] * W[2][2]; } if (v3->flag & PVERT_INTERIOR) { vid[2] = v3->u.id; vid[5] = ninterior + v3->u.id; - sys->J2dt[e1->u.id][2] = j2[0][2] = p_abf_compute_sin_product(sys, v3, e1->u.id)*wi1; - sys->J2dt[e2->u.id][2] = j2[1][2] = p_abf_compute_sin_product(sys, v3, e2->u.id)*wi2; + sys->J2dt[e1->u.id][2] = j2[0][2] = p_abf_compute_sin_product(sys, v3, e1->u.id) * wi1; + sys->J2dt[e2->u.id][2] = j2[1][2] = p_abf_compute_sin_product(sys, v3, e2->u.id) * wi2; sys->J2dt[e3->u.id][2] = j2[2][2] = 1.0f * wi3; - nlRightHandSideAdd(0, v3->u.id, j2[2][2]*beta[2]); - nlRightHandSideAdd(0, ninterior + v3->u.id, j2[0][2]*beta[0] + j2[1][2]*beta[1]); + nlRightHandSideAdd(0, v3->u.id, j2[2][2] * beta[2]); + nlRightHandSideAdd(0, ninterior + v3->u.id, j2[0][2] * beta[0] + j2[1][2] * beta[1]); - row1[2] = j2[2][2]*W[0][2]; - row2[2] = j2[2][2]*W[1][2]; - row3[2] = j2[2][2]*W[2][2]; + row1[2] = j2[2][2] * W[0][2]; + row2[2] = j2[2][2] * W[1][2]; + row3[2] = j2[2][2] * W[2][2]; - row1[5] = j2[0][2]*W[0][0] + j2[1][2]*W[0][1]; - row2[5] = j2[0][2]*W[1][0] + j2[1][2]*W[1][1]; - row3[5] = j2[0][2]*W[2][0] + j2[1][2]*W[2][1]; + row1[5] = j2[0][2] * W[0][0] + j2[1][2] * W[0][1]; + row2[5] = j2[0][2] * W[1][0] + j2[1][2] * W[1][1]; + row3[5] = j2[0][2] * W[2][0] + j2[1][2] * W[2][1]; } for (i = 0; i < 3; i++) { @@ -2540,20 +2541,20 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) continue; if (i == 0) - nlMatrixAdd(r, c, j2[0][i]*row1[j]); + nlMatrixAdd(r, c, j2[0][i] * row1[j]); else - nlMatrixAdd(r + ninterior, c, j2[0][i]*row1[j]); + nlMatrixAdd(r + ninterior, c, j2[0][i] * row1[j]); if (i == 1) - nlMatrixAdd(r, c, j2[1][i]*row2[j]); + nlMatrixAdd(r, c, j2[1][i] * row2[j]); else - nlMatrixAdd(r + ninterior, c, j2[1][i]*row2[j]); + nlMatrixAdd(r + ninterior, c, j2[1][i] * row2[j]); if (i == 2) - nlMatrixAdd(r, c, j2[2][i]*row3[j]); + nlMatrixAdd(r, c, j2[2][i] * row3[j]); else - nlMatrixAdd(r + ninterior, c, j2[2][i]*row3[j]); + nlMatrixAdd(r + ninterior, c, j2[2][i] * row3[j]); } } } @@ -2565,7 +2566,7 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) success = nlSolve(); if (success) { - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { float dlambda1, pre[3], dalpha; PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; PVert *v1 = e1->vert, *v2 = e2->vert, *v3 = e3->vert; @@ -2575,40 +2576,40 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) if (v1->flag & PVERT_INTERIOR) { float x = nlGetVariable(0, v1->u.id); float x2 = nlGetVariable(0, ninterior + v1->u.id); - pre[0] += sys->J2dt[e1->u.id][0]*x; - pre[1] += sys->J2dt[e2->u.id][0]*x2; - pre[2] += sys->J2dt[e3->u.id][0]*x2; + pre[0] += sys->J2dt[e1->u.id][0] * x; + pre[1] += sys->J2dt[e2->u.id][0] * x2; + pre[2] += sys->J2dt[e3->u.id][0] * x2; } if (v2->flag & PVERT_INTERIOR) { float x = nlGetVariable(0, v2->u.id); float x2 = nlGetVariable(0, ninterior + v2->u.id); - pre[0] += sys->J2dt[e1->u.id][1]*x2; - pre[1] += sys->J2dt[e2->u.id][1]*x; - pre[2] += sys->J2dt[e3->u.id][1]*x2; + pre[0] += sys->J2dt[e1->u.id][1] * x2; + pre[1] += sys->J2dt[e2->u.id][1] * x; + pre[2] += sys->J2dt[e3->u.id][1] * x2; } if (v3->flag & PVERT_INTERIOR) { float x = nlGetVariable(0, v3->u.id); float x2 = nlGetVariable(0, ninterior + v3->u.id); - pre[0] += sys->J2dt[e1->u.id][2]*x2; - pre[1] += sys->J2dt[e2->u.id][2]*x2; - pre[2] += sys->J2dt[e3->u.id][2]*x; + pre[0] += sys->J2dt[e1->u.id][2] * x2; + pre[1] += sys->J2dt[e2->u.id][2] * x2; + pre[2] += sys->J2dt[e3->u.id][2] * x; } dlambda1 = pre[0] + pre[1] + pre[2]; - dlambda1 = sys->dstar[f->u.id]*(sys->bstar[f->u.id] - dlambda1); + dlambda1 = sys->dstar[f->u.id] * (sys->bstar[f->u.id] - dlambda1); sys->lambdaTriangle[f->u.id] += dlambda1; dalpha = (sys->bAlpha[e1->u.id] - dlambda1); - sys->alpha[e1->u.id] += dalpha/sys->weight[e1->u.id] - pre[0]; + sys->alpha[e1->u.id] += dalpha / sys->weight[e1->u.id] - pre[0]; dalpha = (sys->bAlpha[e2->u.id] - dlambda1); - sys->alpha[e2->u.id] += dalpha/sys->weight[e2->u.id] - pre[1]; + sys->alpha[e2->u.id] += dalpha / sys->weight[e2->u.id] - pre[1]; dalpha = (sys->bAlpha[e3->u.id] - dlambda1); - sys->alpha[e3->u.id] += dalpha/sys->weight[e3->u.id] - pre[2]; + sys->alpha[e3->u.id] += dalpha / sys->weight[e3->u.id] - pre[2]; /* clamp */ e = f->edge; @@ -2638,12 +2639,12 @@ static PBool p_chart_abf_solve(PChart *chart) PEdge *e, *e1, *e2, *e3; PAbfSystem sys; int i; - float /* lastnorm, */ /* UNUSED */ limit = (chart->nfaces > 100)? 1.0f: 0.001f; + float /* lastnorm, */ /* UNUSED */ limit = (chart->nfaces > 100) ? 1.0f : 0.001f; /* setup id's */ sys.ninterior = sys.nfaces = sys.nangles = 0; - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { if (p_vert_interior(v)) { v->flag |= PVERT_INTERIOR; v->u.id = sys.ninterior++; @@ -2652,7 +2653,7 @@ static PBool p_chart_abf_solve(PChart *chart) v->flag &= ~PVERT_INTERIOR; } - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { e1 = f->edge; e2 = e1->next; e3 = e2->next; f->u.id = sys.nfaces++; @@ -2665,7 +2666,7 @@ static PBool p_chart_abf_solve(PChart *chart) p_abf_setup_system(&sys); /* compute initial angles */ - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { float a1, a2, a3; e1 = f->edge; e2 = e1->next; e3 = e2->next; @@ -2688,12 +2689,12 @@ static PBool p_chart_abf_solve(PChart *chart) sys.alpha[e2->u.id] = sys.beta[e2->u.id] = a2; sys.alpha[e3->u.id] = sys.beta[e3->u.id] = a3; - sys.weight[e1->u.id] = 2.0f/(a1*a1); - sys.weight[e2->u.id] = 2.0f/(a2*a2); - sys.weight[e3->u.id] = 2.0f/(a3*a3); + sys.weight[e1->u.id] = 2.0f / (a1 * a1); + sys.weight[e2->u.id] = 2.0f / (a2 * a2); + sys.weight[e3->u.id] = 2.0f / (a3 * a3); } - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { if (v->flag & PVERT_INTERIOR) { float anglesum = 0.0, scale; @@ -2703,11 +2704,11 @@ static PBool p_chart_abf_solve(PChart *chart) e = e->next->next->pair; } while (e && (e != v->edge)); - scale = (anglesum == 0.0f)? 0.0f: 2.0f*(float)M_PI/anglesum; + scale = (anglesum == 0.0f) ? 0.0f : 2.0f * (float)M_PI / anglesum; e = v->edge; do { - sys.beta[e->u.id] = sys.alpha[e->u.id] = sys.beta[e->u.id]*scale; + sys.beta[e->u.id] = sys.alpha[e->u.id] = sys.beta[e->u.id] * scale; e = e->next->next->pair; } while (e && (e != v->edge)); } @@ -2775,15 +2776,15 @@ static void p_chart_pin_positions(PChart *chart, PVert **pin1, PVert **pin2) if ((sub[0] > sub[1]) && (sub[0] > sub[2])) { dirx = 0; - diry = (sub[1] > sub[2])? 1: 2; + diry = (sub[1] > sub[2]) ? 1 : 2; } else if ((sub[1] > sub[0]) && (sub[1] > sub[2])) { dirx = 1; - diry = (sub[0] > sub[2])? 0: 2; + diry = (sub[0] > sub[2]) ? 0 : 2; } else { dirx = 2; - diry = (sub[0] > sub[1])? 0: 1; + diry = (sub[0] > sub[1]) ? 0 : 1; } if (dirx == 2) { @@ -2809,8 +2810,8 @@ static PBool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PV float maxlen = 0.0f, curlen = 0.0f, totlen = 0.0f, firstlen = 0.0f; float len1, len2; - /* find longest series of verts split in the chart itself, these are - * marked during construction */ + /* find longest series of verts split in the chart itself, these are + * marked during construction */ be = outer; lastbe = p_boundary_edge_prev(be); do { @@ -2820,7 +2821,8 @@ static PBool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PV nextbe = p_boundary_edge_next(be); if ((be->vert->flag & PVERT_SPLIT) || - (lastbe->vert->flag & nextbe->vert->flag & PVERT_SPLIT)) { + (lastbe->vert->flag & nextbe->vert->flag & PVERT_SPLIT)) + { if (!cure) { if (be == outer) firste1 = be; @@ -2860,7 +2862,7 @@ static PBool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PV } } - if (!maxe1 || !maxe2 || (maxlen < 0.5f*totlen)) + if (!maxe1 || !maxe2 || (maxlen < 0.5f * totlen)) return P_FALSE; /* find pin1 in the split vertices */ @@ -2919,7 +2921,7 @@ static void p_chart_extrema_verts(PChart *chart, PVert **pin1, PVert **pin2) minvert[0] = minvert[1] = minvert[2] = NULL; maxvert[0] = maxvert[1] = maxvert[2] = NULL; - for (v = chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { for (i = 0; i < 3; i++) { if (v->co[i] < minv[i]) { minv[i] = v->co[i]; @@ -2953,9 +2955,9 @@ static void p_chart_lscm_load_solution(PChart *chart) { PVert *v; - for (v=chart->verts; v; v=v->nextlink) { - v->uv[0] = nlGetVariable(0, 2*v->u.id); - v->uv[1] = nlGetVariable(0, 2*v->u.id + 1); + for (v = chart->verts; v; v = v->nextlink) { + v->uv[0] = nlGetVariable(0, 2 * v->u.id); + v->uv[1] = nlGetVariable(0, 2 * v->u.id + 1); } } @@ -2966,7 +2968,7 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf) int npins = 0, id = 0; /* give vertices matrix indices and count pins */ - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { if (v->flag & PVERT_PIN) { npins++; if (v->flag & PVERT_SELECT) @@ -3007,12 +3009,12 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf) chart->flag |= PCHART_NOPACK; } - for (v=chart->verts; v; v=v->nextlink) + for (v = chart->verts; v; v = v->nextlink) v->u.id = id++; nlNewContext(); - nlSolverParameteri(NL_NB_VARIABLES, 2*chart->nverts); - nlSolverParameteri(NL_NB_ROWS, 2*chart->nfaces); + nlSolverParameteri(NL_NB_VARIABLES, 2 * chart->nverts); + nlSolverParameteri(NL_NB_ROWS, 2 * chart->nfaces); nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE); chart->u.lscm.context = nlGetCurrent(); @@ -3034,30 +3036,30 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) /* TODO: make loading pins work for simplify/complexify. */ #endif - for (v=chart->verts; v; v=v->nextlink) + for (v = chart->verts; v; v = v->nextlink) if (v->flag & PVERT_PIN) - p_vert_load_pin_select_uvs(handle, v); /* reload for live */ + p_vert_load_pin_select_uvs(handle, v); /* reload for live */ if (chart->u.lscm.pin1) { - nlLockVariable(2*pin1->u.id); - nlLockVariable(2*pin1->u.id + 1); - nlLockVariable(2*pin2->u.id); - nlLockVariable(2*pin2->u.id + 1); - - nlSetVariable(0, 2*pin1->u.id, pin1->uv[0]); - nlSetVariable(0, 2*pin1->u.id + 1, pin1->uv[1]); - nlSetVariable(0, 2*pin2->u.id, pin2->uv[0]); - nlSetVariable(0, 2*pin2->u.id + 1, pin2->uv[1]); + nlLockVariable(2 * pin1->u.id); + nlLockVariable(2 * pin1->u.id + 1); + nlLockVariable(2 * pin2->u.id); + nlLockVariable(2 * pin2->u.id + 1); + + nlSetVariable(0, 2 * pin1->u.id, pin1->uv[0]); + nlSetVariable(0, 2 * pin1->u.id + 1, pin1->uv[1]); + nlSetVariable(0, 2 * pin2->u.id, pin2->uv[0]); + nlSetVariable(0, 2 * pin2->u.id + 1, pin2->uv[1]); } else { /* set and lock the pins */ - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { if (v->flag & PVERT_PIN) { - nlLockVariable(2*v->u.id); - nlLockVariable(2*v->u.id + 1); + nlLockVariable(2 * v->u.id); + nlLockVariable(2 * v->u.id + 1); - nlSetVariable(0, 2*v->u.id, v->uv[0]); - nlSetVariable(0, 2*v->u.id + 1, v->uv[1]); + nlSetVariable(0, 2 * v->u.id, v->uv[0]); + nlSetVariable(0, 2 * v->u.id + 1, v->uv[1]); } } } @@ -3067,7 +3069,7 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) nlBegin(NL_MATRIX); row = 0; - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; PVert *v1 = e1->vert, *v2 = e2->vert, *v3 = e3->vert; float a1, a2, a3, ratio, cosine, sine; @@ -3090,51 +3092,51 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) /* shift vertices to find most stable order */ if (sina3 != sinmax) { - SHIFT3(PVert*, v1, v2, v3); + SHIFT3(PVert *, v1, v2, v3); SHIFT3(float, a1, a2, a3); SHIFT3(float, sina1, sina2, sina3); if (sina2 == sinmax) { - SHIFT3(PVert*, v1, v2, v3); + SHIFT3(PVert *, v1, v2, v3); SHIFT3(float, a1, a2, a3); SHIFT3(float, sina1, sina2, sina3); } } /* angle based lscm formulation */ - ratio = (sina3 == 0.0f)? 1.0f: sina2/sina3; - cosine = cosf(a1)*ratio; - sine = sina1*ratio; + ratio = (sina3 == 0.0f) ? 1.0f : sina2 / sina3; + cosine = cosf(a1) * ratio; + sine = sina1 * ratio; #if 0 nlBegin(NL_ROW); - nlCoefficient(2*v1->u.id, cosine - 1.0); - nlCoefficient(2*v1->u.id+1, -sine); - nlCoefficient(2*v2->u.id, -cosine); - nlCoefficient(2*v2->u.id+1, sine); - nlCoefficient(2*v3->u.id, 1.0); + nlCoefficient(2 * v1->u.id, cosine - 1.0); + nlCoefficient(2 * v1->u.id + 1, -sine); + nlCoefficient(2 * v2->u.id, -cosine); + nlCoefficient(2 * v2->u.id + 1, sine); + nlCoefficient(2 * v3->u.id, 1.0); nlEnd(NL_ROW); nlBegin(NL_ROW); - nlCoefficient(2*v1->u.id, sine); - nlCoefficient(2*v1->u.id+1, cosine - 1.0); - nlCoefficient(2*v2->u.id, -sine); - nlCoefficient(2*v2->u.id+1, -cosine); - nlCoefficient(2*v3->u.id+1, 1.0); + nlCoefficient(2 * v1->u.id, sine); + nlCoefficient(2 * v1->u.id + 1, cosine - 1.0); + nlCoefficient(2 * v2->u.id, -sine); + nlCoefficient(2 * v2->u.id + 1, -cosine); + nlCoefficient(2 * v3->u.id + 1, 1.0); nlEnd(NL_ROW); #else - nlMatrixAdd(row, 2*v1->u.id, cosine - 1.0f); - nlMatrixAdd(row, 2*v1->u.id+1, -sine); - nlMatrixAdd(row, 2*v2->u.id, -cosine); - nlMatrixAdd(row, 2*v2->u.id+1, sine); - nlMatrixAdd(row, 2*v3->u.id, 1.0); + nlMatrixAdd(row, 2 * v1->u.id, cosine - 1.0f); + nlMatrixAdd(row, 2 * v1->u.id + 1, -sine); + nlMatrixAdd(row, 2 * v2->u.id, -cosine); + nlMatrixAdd(row, 2 * v2->u.id + 1, sine); + nlMatrixAdd(row, 2 * v3->u.id, 1.0); row++; - nlMatrixAdd(row, 2*v1->u.id, sine); - nlMatrixAdd(row, 2*v1->u.id+1, cosine - 1.0f); - nlMatrixAdd(row, 2*v2->u.id, -sine); - nlMatrixAdd(row, 2*v2->u.id+1, -cosine); - nlMatrixAdd(row, 2*v3->u.id+1, 1.0); + nlMatrixAdd(row, 2 * v1->u.id, sine); + nlMatrixAdd(row, 2 * v1->u.id + 1, cosine - 1.0f); + nlMatrixAdd(row, 2 * v2->u.id, -sine); + nlMatrixAdd(row, 2 * v2->u.id + 1, -cosine); + nlMatrixAdd(row, 2 * v3->u.id + 1, 1.0); row++; #endif } @@ -3148,7 +3150,7 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) return P_TRUE; } else { - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { v->uv[0] = 0.0f; v->uv[1] = 0.0f; } @@ -3180,7 +3182,7 @@ static void p_stretch_pin_boundary(PChart *chart) { PVert *v; - for (v=chart->verts; v; v=v->nextlink) + for (v = chart->verts; v; v = v->nextlink) if (v->edge->pair == NULL) v->flag |= PVERT_PIN; else @@ -3200,7 +3202,7 @@ static float p_face_stretch(PFace *f) if (area <= 0.0f) /* flipped face -> infinite stretch */ return 1e10f; - w= 1.0f/(2.0f*area); + w = 1.0f / (2.0f * area); /* compute derivatives */ copy_v3_v3(Ps, v1->co); @@ -3230,10 +3232,10 @@ static float p_face_stretch(PFace *f) mul_v3_fl(Pt, w); /* Sander Tensor */ - a= dot_v3v3(Ps, Ps); - c= dot_v3v3(Pt, Pt); + a = dot_v3v3(Ps, Ps); + c = dot_v3v3(Pt, Pt); - T = sqrt(0.5f*(a + c)); + T = sqrt(0.5f * (a + c)); if (f->flag & PFACE_FILLED) T *= 0.2f; @@ -3261,7 +3263,7 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng) float orig_stretch, low, stretch_low, high, stretch_high, mid, stretch; float orig_uv[2], dir[2], random_angle, trusted_radius; - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { if ((v->flag & PVERT_PIN) || !(v->flag & PVERT_SELECT)) continue; @@ -3298,8 +3300,8 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng) /* binary search for lowest stretch position */ for (j = 0; j < P_STRETCH_ITER; j++) { mid = 0.5f * (low + high); - v->uv[0]= orig_uv[0] + mid*dir[0]; - v->uv[1]= orig_uv[1] + mid*dir[1]; + v->uv[0] = orig_uv[0] + mid * dir[0]; + v->uv[1] = orig_uv[1] + mid * dir[1]; stretch = p_stretch_compute_vertex(v); if (stretch_low < stretch_high) { @@ -3322,8 +3324,8 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng) static int p_compare_geometric_uv(const void *a, const void *b) { - PVert *v1 = *(PVert**)a; - PVert *v2 = *(PVert**)b; + PVert *v1 = *(PVert **)a; + PVert *v2 = *(PVert **)b; if (v1->uv[0] < v2->uv[0]) return -1; @@ -3359,9 +3361,9 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int e = p_boundary_edge_next(e); } while (e != be); - p = points = (PVert**)MEM_mallocN(sizeof(PVert*)*npoints*2, "PCHullpoints"); - U = (PVert**)MEM_mallocN(sizeof(PVert*)*npoints, "PCHullU"); - L = (PVert**)MEM_mallocN(sizeof(PVert*)*npoints, "PCHullL"); + p = points = (PVert **)MEM_mallocN(sizeof(PVert *) * npoints * 2, "PCHullpoints"); + U = (PVert **)MEM_mallocN(sizeof(PVert *) * npoints, "PCHullU"); + L = (PVert **)MEM_mallocN(sizeof(PVert *) * npoints, "PCHullL"); e = be; do { @@ -3370,13 +3372,13 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int e = p_boundary_edge_next(e); } while (e != be); - qsort(points, npoints, sizeof(PVert*), p_compare_geometric_uv); + qsort(points, npoints, sizeof(PVert *), p_compare_geometric_uv); ulen = llen = 0; - for (p=points, i = 0; i < npoints; i++, p++) { - while ((ulen > 1) && (p_area_signed(U[ulen-2]->uv, (*p)->uv, U[ulen-1]->uv) <= 0)) + for (p = points, i = 0; i < npoints; i++, p++) { + while ((ulen > 1) && (p_area_signed(U[ulen - 2]->uv, (*p)->uv, U[ulen - 1]->uv) <= 0)) ulen--; - while ((llen > 1) && (p_area_signed(L[llen-2]->uv, (*p)->uv, L[llen-1]->uv) >= 0)) + while ((llen > 1) && (p_area_signed(L[llen - 2]->uv, (*p)->uv, L[llen - 1]->uv) >= 0)) llen--; U[ulen] = *p; @@ -3386,11 +3388,11 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int } npoints = 0; - for (p=points, i = 0; i < ulen; i++, p++, npoints++) + for (p = points, i = 0; i < ulen; i++, p++, npoints++) *p = U[i]; /* the first and last point in L are left out, since they are also in U */ - for (i = llen-2; i > 0; i--, p++, npoints++) + for (i = llen - 2; i > 0; i--, p++, npoints++) *p = L[i]; *verts = points; @@ -3422,7 +3424,7 @@ static float p_rectangle_area(float *p1, float *dir, float *p2, float *p3, float if (!p_intersect_line_2d_dir(p3, dir, p4, orthodir, corner3)) return 1e10; - return len_v2v2(corner1, corner2)*len_v2v2(corner2, corner3); + return len_v2v2(corner1, corner2) * len_v2v2(corner2, corner3); } static float p_chart_minimum_area_angle(PChart *chart) @@ -3440,16 +3442,16 @@ static float p_chart_minimum_area_angle(PChart *chart) return 0.0; /* find left/top/right/bottom points, and compute angle for each point */ - angles = MEM_mallocN(sizeof(float)*npoints, "PMinAreaAngles"); + angles = MEM_mallocN(sizeof(float) * npoints, "PMinAreaAngles"); mini = maxi = 0; miny = 1e10; maxy = -1e10; for (i = 0; i < npoints; i++) { - p1 = (i == 0)? points[npoints-1]: points[i-1]; + p1 = (i == 0) ? points[npoints - 1] : points[i - 1]; p2 = points[i]; - p3 = (i == npoints-1)? points[0]: points[i+1]; + p3 = (i == npoints - 1) ? points[0] : points[i + 1]; angles[i] = (float)M_PI - p_vec2_angle(p1->uv, p2->uv, p3->uv); @@ -3471,19 +3473,19 @@ static float p_chart_minimum_area_angle(PChart *chart) v[0] = points[idx[0]]->uv[0]; v[1] = points[idx[0]]->uv[1] + 1.0f; - a[0] = p_vec2_angle(points[(idx[0]+1)%npoints]->uv, points[idx[0]]->uv, v); + a[0] = p_vec2_angle(points[(idx[0] + 1) % npoints]->uv, points[idx[0]]->uv, v); v[0] = points[idx[1]]->uv[0] + 1.0f; v[1] = points[idx[1]]->uv[1]; - a[1] = p_vec2_angle(points[(idx[1]+1)%npoints]->uv, points[idx[1]]->uv, v); + a[1] = p_vec2_angle(points[(idx[1] + 1) % npoints]->uv, points[idx[1]]->uv, v); v[0] = points[idx[2]]->uv[0]; v[1] = points[idx[2]]->uv[1] - 1.0f; - a[2] = p_vec2_angle(points[(idx[2]+1)%npoints]->uv, points[idx[2]]->uv, v); + a[2] = p_vec2_angle(points[(idx[2] + 1) % npoints]->uv, points[idx[2]]->uv, v); v[0] = points[idx[3]]->uv[0] - 1.0f; v[1] = points[idx[3]]->uv[1]; - a[3] = p_vec2_angle(points[(idx[3]+1)%npoints]->uv, points[idx[3]]->uv, v); + a[3] = p_vec2_angle(points[(idx[3] + 1) % npoints]->uv, points[idx[3]]->uv, v); /* 4 rotating calipers */ @@ -3491,7 +3493,7 @@ static float p_chart_minimum_area_angle(PChart *chart) minarea = 1e10; minangle = 0.0; - while (rotated <= (float)(M_PI/2.0)) { /* INVESTIGATE: how far to rotate? */ + while (rotated <= (float)(M_PI / 2.0)) { /* INVESTIGATE: how far to rotate? */ /* rotate with the smallest angle */ mini = 0; mina = 1e10; @@ -3503,26 +3505,26 @@ static float p_chart_minimum_area_angle(PChart *chart) } rotated += mina; - nextidx = (idx[mini]+1)%npoints; + nextidx = (idx[mini] + 1) % npoints; a[mini] = angles[nextidx]; - a[(mini+1)%4] = a[(mini+1)%4] - mina; - a[(mini+2)%4] = a[(mini+2)%4] - mina; - a[(mini+3)%4] = a[(mini+3)%4] - mina; + a[(mini + 1) % 4] = a[(mini + 1) % 4] - mina; + a[(mini + 2) % 4] = a[(mini + 2) % 4] - mina; + a[(mini + 3) % 4] = a[(mini + 3) % 4] - mina; /* compute area */ p1 = points[idx[mini]]; p1n = points[nextidx]; - p2 = points[idx[(mini+1)%4]]; - p3 = points[idx[(mini+2)%4]]; - p4 = points[idx[(mini+3)%4]]; + p2 = points[idx[(mini + 1) % 4]]; + p3 = points[idx[(mini + 2) % 4]]; + p4 = points[idx[(mini + 3) % 4]]; len = len_v2v2(p1->uv, p1n->uv); if (len > 0.0f) { - len = 1.0f/len; - v[0] = (p1n->uv[0] - p1->uv[0])*len; - v[1] = (p1n->uv[1] - p1->uv[1])*len; + len = 1.0f / len; + v[0] = (p1n->uv[0] - p1->uv[0]) * len; + v[1] = (p1n->uv[1] - p1->uv[1]) * len; area = p_rectangle_area(p1->uv, v, p2->uv, p3->uv, p4->uv); @@ -3537,8 +3539,8 @@ static float p_chart_minimum_area_angle(PChart *chart) } /* try keeping rotation as small as possible */ - if (minangle > (float)(M_PI/4)) - minangle -= (float)(M_PI/2.0); + if (minangle > (float)(M_PI / 4)) + minangle -= (float)(M_PI / 2.0); MEM_freeN(angles); MEM_freeN(points); @@ -3553,10 +3555,10 @@ static void p_chart_rotate_minimum_area(PChart *chart) float cosine = cos(angle); PVert *v; - for (v = chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { float oldu = v->uv[0], oldv = v->uv[1]; - v->uv[0] = cosine*oldu - sine*oldv; - v->uv[1] = sine*oldu + cosine*oldv; + v->uv[0] = cosine * oldu - sine * oldv; + v->uv[1] = sine * oldu + cosine * oldv; } } @@ -3585,21 +3587,21 @@ static void p_barycentric_2d(float *v1, float *v2, float *v3, float *p, float *b c[0] = v3[0] - v1[0]; c[1] = v3[1] - v1[1]; - div = a[0]*c[1] - a[1]*c[0]; + div = a[0] * c[1] - a[1] * c[0]; if (div == 0.0f) { - b[0] = 1.0f/3.0f; - b[1] = 1.0f/3.0f; - b[2] = 1.0f/3.0f; + b[0] = 1.0f / 3.0f; + b[1] = 1.0f / 3.0f; + b[2] = 1.0f / 3.0f; } else { h[0] = p[0] - v1[0]; h[1] = p[1] - v1[1]; - div = 1.0f/div; + div = 1.0f / div; - b[1] = (h[0]*c[1] - h[1]*c[0])*div; - b[2] = (a[0]*h[1] - a[1]*h[0])*div; + b[1] = (h[0] * c[1] - h[1] * c[0]) * div; + b[2] = (a[0] * h[1] - a[1] * h[0]) * div; b[0] = 1.0f - b[1] - b[2]; } } @@ -3611,8 +3613,8 @@ static PBool p_triangle_inside(SmoothTriangle *t, float *co) p_barycentric_2d(t->co1, t->co2, t->co3, co, b); if ((b[0] >= 0.0f) && (b[1] >= 0.0f) && (b[2] >= 0.0f)) { - co[0] = t->oco1[0]*b[0] + t->oco2[0]*b[1] + t->oco3[0]*b[2]; - co[1] = t->oco1[1]*b[0] + t->oco2[1]*b[1] + t->oco3[1]*b[2]; + co[0] = t->oco1[0] * b[0] + t->oco2[0] * b[1] + t->oco3[0] * b[2]; + co[1] = t->oco1[1] * b[0] + t->oco2[1] * b[1] + t->oco3[1] * b[2]; return P_TRUE; } @@ -3632,11 +3634,11 @@ static SmoothNode *p_node_new(MemArena *arena, SmoothTriangle **tri, int ntri, f if (ntri <= 10 || depth >= 15) return node; - t1 = MEM_mallocN(sizeof(SmoothTriangle)*ntri, "PNodeTri1"); - t2 = MEM_mallocN(sizeof(SmoothTriangle)*ntri, "PNodeTri1"); + t1 = MEM_mallocN(sizeof(SmoothTriangle) * ntri, "PNodeTri1"); + t2 = MEM_mallocN(sizeof(SmoothTriangle) * ntri, "PNodeTri1"); - axis = (bmax[0] - bmin[0] > bmax[1] - bmin[1])? 0: 1; - split = 0.5f*(bmin[axis] + bmax[axis]); + axis = (bmax[0] - bmin[0] > bmax[1] - bmin[1]) ? 0 : 1; + split = 0.5f * (bmin[axis] + bmax[axis]); for (i = 0; i < ntri; i++) { t = tri[i]; @@ -3667,11 +3669,11 @@ static SmoothNode *p_node_new(MemArena *arena, SmoothTriangle **tri, int ntri, f /* mi = bmin[axis]; */ /* UNUSED */ mx = bmax[axis]; bmax[axis] = split; - node->c1 = p_node_new(arena, t1, t1size, bmin, bmax, depth+1); + node->c1 = p_node_new(arena, t1, t1size, bmin, bmax, depth + 1); bmin[axis] = bmax[axis]; bmax[axis] = mx; - node->c2 = p_node_new(arena, t2, t2size, bmin, bmax, depth+1); + node->c2 = p_node_new(arena, t2, t2size, bmin, bmax, depth + 1); return node; } @@ -3710,9 +3712,9 @@ static PBool p_node_intersect(SmoothNode *node, float *co) static int p_compare_float(const void *a, const void *b) { - if (*((float*)a) < *((float*)b)) + if (*((float *)a) < *((float *)b)) return -1; - else if (*((float*)a) == *((float*)b)) + else if (*((float *)a) == *((float *)b)) return 0; else return 1; @@ -3721,17 +3723,17 @@ static int p_compare_float(const void *a, const void *b) static float p_smooth_median_edge_length(PChart *chart) { PEdge *e; - float *lengths = MEM_mallocN(sizeof(chart->edges)*chart->nedges, "PMedianLength"); + float *lengths = MEM_mallocN(sizeof(chart->edges) * chart->nedges, "PMedianLength"); float median; int i; /* ok, so i'm lazy */ - for (i=0, e=chart->edges; e; e=e->nextlink, i++) + for (i = 0, e = chart->edges; e; e = e->nextlink, i++) lengths[i] = p_edge_length(e); qsort(lengths, i, sizeof(float), p_compare_float); - median = lengths[i/2]; + median = lengths[i / 2]; MEM_freeN(lengths); return median; @@ -3739,10 +3741,10 @@ static float p_smooth_median_edge_length(PChart *chart) static float p_smooth_distortion(PEdge *e, float avg2d, float avg3d) { - float len2d = p_edge_uv_length(e)*avg3d; - float len3d = p_edge_length(e)*avg2d; + float len2d = p_edge_uv_length(e) * avg3d; + float len3d = p_edge_length(e) * avg2d; - return (len3d == 0.0f)? 0.0f: len2d/len3d; + return (len3d == 0.0f) ? 0.0f : len2d / len3d; } static void p_smooth(PChart *chart) @@ -3764,17 +3766,17 @@ static void p_smooth(PChart *chart) return; p_chart_uv_bbox(chart, minv, maxv); - median = p_smooth_median_edge_length(chart)*0.10f; + median = p_smooth_median_edge_length(chart) * 0.10f; if (median == 0.0f) return; - invmedian = 1.0f/median; + invmedian = 1.0f / median; /* compute edge distortion */ avglen2d = avglen3d = 0.0; - for (e=chart->edges; e; e=e->nextlink) { + for (e = chart->edges; e; e = e->nextlink) { avglen2d += p_edge_uv_length(e); avglen3d += p_edge_length(e); } @@ -3782,7 +3784,7 @@ static void p_smooth(PChart *chart) avglen2d /= nedges; avglen3d /= nedges; - for (v=chart->verts; v; v=v->nextlink) { + for (v = chart->verts; v; v = v->nextlink) { v->u.distortion = 0.0; nwheel = 0; @@ -3798,43 +3800,43 @@ static void p_smooth(PChart *chart) } /* need to do excessive grid size checking still */ - center[0] = 0.5f*(minv[0] + maxv[0]); - center[1] = 0.5f*(minv[1] + maxv[1]); + center[0] = 0.5f * (minv[0] + maxv[0]); + center[1] = 0.5f * (minv[1] + maxv[1]); - dx = 0.5f*(maxv[0] - minv[0]); - dy = 0.5f*(maxv[1] - minv[1]); + dx = 0.5f * (maxv[0] - minv[0]); + dy = 0.5f * (maxv[1] - minv[1]); padding = 0.15f; - dx += padding*dx + 2.0f*median; - dy += padding*dy + 2.0f*median; + dx += padding * dx + 2.0f * median; + dy += padding * dy + 2.0f * median; - gridx = (int)(dx*invmedian); - gridy = (int)(dy*invmedian); + gridx = (int)(dx * invmedian); + gridy = (int)(dy * invmedian); - minv[0] = center[0] - median*gridx; - minv[1] = center[1] - median*gridy; - maxv[0] = center[0] + median*gridx; - maxv[1] = center[1] + median*gridy; + minv[0] = center[0] - median * gridx; + minv[1] = center[1] - median * gridy; + maxv[0] = center[0] + median * gridx; + maxv[1] = center[1] + median * gridy; /* create grid */ - gridx = gridx*2 + 1; - gridy = gridy*2 + 1; + gridx = gridx * 2 + 1; + gridy = gridy * 2 + 1; if ((gridx <= 2) || (gridy <= 2)) return; - edgesx = gridx-1; - edgesy = gridy-1; - nsize = gridx*gridy; - esize = edgesx*edgesy; - - nodes = MEM_mallocN(sizeof(float)*nsize, "PSmoothNodes"); - nodesx = MEM_mallocN(sizeof(float)*nsize, "PSmoothNodesX"); - nodesy = MEM_mallocN(sizeof(float)*nsize, "PSmoothNodesY"); - oldnodesx = MEM_mallocN(sizeof(float)*nsize, "PSmoothOldNodesX"); - oldnodesy = MEM_mallocN(sizeof(float)*nsize, "PSmoothOldNodesY"); - hedges = MEM_mallocN(sizeof(float)*esize, "PSmoothHEdges"); - vedges = MEM_mallocN(sizeof(float)*esize, "PSmoothVEdges"); + edgesx = gridx - 1; + edgesy = gridy - 1; + nsize = gridx * gridy; + esize = edgesx * edgesy; + + nodes = MEM_mallocN(sizeof(float) * nsize, "PSmoothNodes"); + nodesx = MEM_mallocN(sizeof(float) * nsize, "PSmoothNodesX"); + nodesy = MEM_mallocN(sizeof(float) * nsize, "PSmoothNodesY"); + oldnodesx = MEM_mallocN(sizeof(float) * nsize, "PSmoothOldNodesX"); + oldnodesy = MEM_mallocN(sizeof(float) * nsize, "PSmoothOldNodesY"); + hedges = MEM_mallocN(sizeof(float) * esize, "PSmoothHEdges"); + vedges = MEM_mallocN(sizeof(float) * esize, "PSmoothVEdges"); if (!nodes || !nodesx || !nodesy || !oldnodesx || !oldnodesy || !hedges || !vedges) { if (nodes) MEM_freeN(nodes); @@ -3851,17 +3853,17 @@ static void p_smooth(PChart *chart) for (x = 0; x < gridx; x++) { for (y = 0; y < gridy; y++) { - i = x + y*gridx; + i = x + y * gridx; - nodesx[i] = minv[0] + median*x; - nodesy[i] = minv[1] + median*y; + nodesx[i] = minv[0] + median * x; + nodesy[i] = minv[1] + median * y; nodes[i] = 1.0f; } } /* embed in grid */ - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; float fmin[2], fmax[2]; int bx1, by1, bx2, by2; @@ -3872,16 +3874,16 @@ static void p_smooth(PChart *chart) DO_MINMAX2(e2->vert->uv, fmin, fmax); DO_MINMAX2(e3->vert->uv, fmin, fmax); - bx1 = (int)((fmin[0] - minv[0])*invmedian); - by1 = (int)((fmin[1] - minv[1])*invmedian); - bx2 = (int)((fmax[0] - minv[0])*invmedian + 2); - by2 = (int)((fmax[1] - minv[1])*invmedian + 2); + bx1 = (int)((fmin[0] - minv[0]) * invmedian); + by1 = (int)((fmin[1] - minv[1]) * invmedian); + bx2 = (int)((fmax[0] - minv[0]) * invmedian + 2); + by2 = (int)((fmax[1] - minv[1]) * invmedian + 2); for (x = bx1; x < bx2; x++) { for (y = by1; y < by2; y++) { float p[2], b[3]; - i = x + y*gridx; + i = x + y * gridx; p[0] = nodesx[i]; p[1] = nodesy[i]; @@ -3889,9 +3891,9 @@ static void p_smooth(PChart *chart) p_barycentric_2d(e1->vert->uv, e2->vert->uv, e3->vert->uv, p, b); if ((b[0] > 0.0f) && (b[1] > 0.0f) && (b[2] > 0.0f)) { - nodes[i] = e1->vert->u.distortion*b[0]; - nodes[i] += e2->vert->u.distortion*b[1]; - nodes[i] += e3->vert->u.distortion*b[2]; + nodes[i] = e1->vert->u.distortion * b[0]; + nodes[i] += e2->vert->u.distortion * b[1]; + nodes[i] += e3->vert->u.distortion * b[2]; } } } @@ -3900,22 +3902,22 @@ static void p_smooth(PChart *chart) /* smooth the grid */ maxiter = 10; totiter = 0; - climit = 0.00001f*nsize; + climit = 0.00001f * nsize; for (it = 0; it < maxiter; it++) { moved = 0.0f; for (x = 0; x < edgesx; x++) { for (y = 0; y < edgesy; y++) { - i = x + y*gridx; - j = x + y*edgesx; + i = x + y * gridx; + j = x + y * edgesx; - hedges[j] = (nodes[i] + nodes[i+1])*0.5f; - vedges[j] = (nodes[i] + nodes[i+gridx])*0.5f; + hedges[j] = (nodes[i] + nodes[i + 1]) * 0.5f; + vedges[j] = (nodes[i] + nodes[i + gridx]) * 0.5f; /* we do *inverse* mapping */ - hedges[j] = 1.0f/hedges[j]; - vedges[j] = 1.0f/vedges[j]; + hedges[j] = 1.0f / hedges[j]; + vedges[j] = 1.0f / vedges[j]; } } @@ -3926,37 +3928,37 @@ static void p_smooth(PChart *chart) d = 0.0f; totiter += 1; - memcpy(oldnodesx, nodesx, sizeof(float)*nsize); - memcpy(oldnodesy, nodesy, sizeof(float)*nsize); + memcpy(oldnodesx, nodesx, sizeof(float) * nsize); + memcpy(oldnodesy, nodesy, sizeof(float) * nsize); - for (x=1; x < gridx-1; x++) { - for (y=1; y < gridy-1; y++) { + for (x = 1; x < gridx - 1; x++) { + for (y = 1; y < gridy - 1; y++) { float p[2], oldp[2], sum1, sum2, diff[2], length; - i = x + gridx*y; - j = x + edgesx*y; + i = x + gridx * y; + j = x + edgesx * y; oldp[0] = oldnodesx[i]; oldp[1] = oldnodesy[i]; - sum1 = hedges[j-1]*oldnodesx[i-1]; - sum1 += hedges[j]*oldnodesx[i+1]; - sum1 += vedges[j-edgesx]*oldnodesx[i-gridx]; - sum1 += vedges[j]*oldnodesx[i+gridx]; + sum1 = hedges[j - 1] * oldnodesx[i - 1]; + sum1 += hedges[j] * oldnodesx[i + 1]; + sum1 += vedges[j - edgesx] * oldnodesx[i - gridx]; + sum1 += vedges[j] * oldnodesx[i + gridx]; - sum2 = hedges[j-1]; + sum2 = hedges[j - 1]; sum2 += hedges[j]; - sum2 += vedges[j-edgesx]; + sum2 += vedges[j - edgesx]; sum2 += vedges[j]; - nodesx[i] = sum1/sum2; + nodesx[i] = sum1 / sum2; - sum1 = hedges[j-1]*oldnodesy[i-1]; - sum1 += hedges[j]*oldnodesy[i+1]; - sum1 += vedges[j-edgesx]*oldnodesy[i-gridx]; - sum1 += vedges[j]*oldnodesy[i+gridx]; + sum1 = hedges[j - 1] * oldnodesy[i - 1]; + sum1 += hedges[j] * oldnodesy[i + 1]; + sum1 += vedges[j - edgesx] * oldnodesy[i - gridx]; + sum1 += vedges[j] * oldnodesy[i + gridx]; - nodesy[i] = sum1/sum2; + nodesy[i] = sum1 / sum2; p[0] = nodesx[i]; p[1] = nodesy[i]; @@ -3964,7 +3966,7 @@ static void p_smooth(PChart *chart) diff[0] = p[0] - oldp[0]; diff[1] = p[1] - oldp[1]; - length = sqrt(diff[0]*diff[0] + diff[1]*diff[1]); + length = sqrt(diff[0] * diff[0] + diff[1] * diff[1]); d = MAX2(d, length); moved += length; } @@ -3984,8 +3986,8 @@ static void p_smooth(PChart *chart) MEM_freeN(vedges); /* create bsp */ - t = triangles = MEM_mallocN(sizeof(SmoothTriangle)*esize*2, "PSmoothTris"); - trip = tri = MEM_mallocN(sizeof(SmoothTriangle*)*esize*2, "PSmoothTriP"); + t = triangles = MEM_mallocN(sizeof(SmoothTriangle) * esize * 2, "PSmoothTris"); + trip = tri = MEM_mallocN(sizeof(SmoothTriangle *) * esize * 2, "PSmoothTriP"); if (!triangles || !tri) { MEM_freeN(nodes); @@ -4001,33 +4003,33 @@ static void p_smooth(PChart *chart) for (x = 0; x < edgesx; x++) { for (y = 0; y < edgesy; y++) { - i = x + y*gridx; + i = x + y * gridx; t->co1[0] = nodesx[i]; t->co1[1] = nodesy[i]; - t->co2[0] = nodesx[i+1]; - t->co2[1] = nodesy[i+1]; + t->co2[0] = nodesx[i + 1]; + t->co2[1] = nodesy[i + 1]; - t->co3[0] = nodesx[i+gridx]; - t->co3[1] = nodesy[i+gridx]; + t->co3[0] = nodesx[i + gridx]; + t->co3[1] = nodesy[i + gridx]; - t->oco1[0] = minv[0] + x*median; - t->oco1[1] = minv[1] + y*median; + t->oco1[0] = minv[0] + x * median; + t->oco1[1] = minv[1] + y * median; - t->oco2[0] = minv[0] + (x+1)*median; - t->oco2[1] = minv[1] + y*median; + t->oco2[0] = minv[0] + (x + 1) * median; + t->oco2[1] = minv[1] + y * median; - t->oco3[0] = minv[0] + x*median; - t->oco3[1] = minv[1] + (y+1)*median; + t->oco3[0] = minv[0] + x * median; + t->oco3[1] = minv[1] + (y + 1) * median; - t2 = t+1; + t2 = t + 1; - t2->co1[0] = nodesx[i+gridx+1]; - t2->co1[1] = nodesy[i+gridx+1]; + t2->co1[0] = nodesx[i + gridx + 1]; + t2->co1[1] = nodesy[i + gridx + 1]; - t2->oco1[0] = minv[0] + (x+1)*median; - t2->oco1[1] = minv[1] + (y+1)*median; + t2->oco1[0] = minv[0] + (x + 1) * median; + t2->oco1[1] = minv[1] + (y + 1) * median; t2->co2[0] = t->co2[0]; t2->co2[1] = t->co2[1]; t2->oco2[0] = t->oco2[0]; t2->oco2[1] = t->oco2[1]; @@ -4044,10 +4046,10 @@ static void p_smooth(PChart *chart) MEM_freeN(nodesx); MEM_freeN(nodesy); - arena = BLI_memarena_new(1<<16, "param smooth arena"); - root = p_node_new(arena, tri, esize*2, minv, maxv, 0); + arena = BLI_memarena_new(1 << 16, "param smooth arena"); + root = p_node_new(arena, tri, esize * 2, minv, maxv, 0); - for (v=chart->verts; v; v=v->nextlink) + for (v = chart->verts; v; v = v->nextlink) if (!p_node_intersect(root, v->uv)) param_warning("area smoothing error: couldn't find mapping triangle\n"); @@ -4061,23 +4063,23 @@ static void p_smooth(PChart *chart) ParamHandle *param_construct_begin(void) { - PHandle *handle = MEM_callocN(sizeof*handle, "PHandle"); + PHandle *handle = MEM_callocN(sizeof *handle, "PHandle"); handle->construction_chart = p_chart_new(handle); handle->state = PHANDLE_STATE_ALLOCATED; - handle->arena = BLI_memarena_new((1<<16), "param construct arena"); + handle->arena = BLI_memarena_new((1 << 16), "param construct arena"); handle->aspx = 1.0f; handle->aspy = 1.0f; - handle->hash_verts = phash_new((PHashLink**)&handle->construction_chart->verts, 1); - handle->hash_edges = phash_new((PHashLink**)&handle->construction_chart->edges, 1); - handle->hash_faces = phash_new((PHashLink**)&handle->construction_chart->faces, 1); + handle->hash_verts = phash_new((PHashLink **)&handle->construction_chart->verts, 1); + handle->hash_edges = phash_new((PHashLink **)&handle->construction_chart->edges, 1); + handle->hash_faces = phash_new((PHashLink **)&handle->construction_chart->faces, 1); - return (ParamHandle*)handle; + return (ParamHandle *)handle; } void param_aspect_ratio(ParamHandle *handle, float aspx, float aspy) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; phandle->aspx = aspx; phandle->aspy = aspy; @@ -4085,11 +4087,11 @@ void param_aspect_ratio(ParamHandle *handle, float aspx, float aspy) void param_delete(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; int i; param_assert((phandle->state == PHANDLE_STATE_ALLOCATED) || - (phandle->state == PHANDLE_STATE_CONSTRUCTED)); + (phandle->state == PHANDLE_STATE_CONSTRUCTED)); for (i = 0; i < phandle->ncharts; i++) p_chart_delete(phandle->charts[i]); @@ -4110,10 +4112,10 @@ void param_delete(ParamHandle *handle) } void param_face_add(ParamHandle *handle, ParamKey key, int nverts, - ParamKey *vkeys, float **co, float **uv, - ParamBool *pin, ParamBool *select) + ParamKey *vkeys, float **co, float **uv, + ParamBool *pin, ParamBool *select) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; param_assert(phash_lookup(phandle->hash_faces, key) == NULL); param_assert(phandle->state == PHANDLE_STATE_ALLOCATED); @@ -4135,7 +4137,7 @@ void param_face_add(ParamHandle *handle, ParamKey key, int nverts, void param_edge_set_seam(ParamHandle *handle, ParamKey *vkeys) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PEdge *e; param_assert(phandle->state == PHANDLE_STATE_ALLOCATED); @@ -4147,7 +4149,7 @@ void param_edge_set_seam(ParamHandle *handle, ParamKey *vkeys) void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PChart *chart = phandle->construction_chart; int i, j, nboundaries = 0; PEdge *outer; @@ -4182,7 +4184,7 @@ void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl) if (fill && (nboundaries > 1)) p_chart_fill_boundaries(chart, outer); - for (v=chart->verts; v; v=v->nextlink) + for (v = chart->verts; v; v = v->nextlink) p_vert_load_pin_select_uvs(handle, v); } @@ -4193,7 +4195,7 @@ void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl) void param_lscm_begin(ParamHandle *handle, ParamBool live, ParamBool abf) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PFace *f; int i; @@ -4201,7 +4203,7 @@ void param_lscm_begin(ParamHandle *handle, ParamBool live, ParamBool abf) phandle->state = PHANDLE_STATE_LSCM; for (i = 0; i < phandle->ncharts; i++) { - for (f=phandle->charts[i]->faces; f; f=f->nextlink) + for (f = phandle->charts[i]->faces; f; f = f->nextlink) p_face_backup_uvs(f); p_chart_lscm_begin(phandle->charts[i], (PBool)live, (PBool)abf); } @@ -4209,7 +4211,7 @@ void param_lscm_begin(ParamHandle *handle, ParamBool live, ParamBool abf) void param_lscm_solve(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PChart *chart; int i; PBool result; @@ -4233,7 +4235,7 @@ void param_lscm_solve(ParamHandle *handle) void param_lscm_end(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; int i; param_assert(phandle->state == PHANDLE_STATE_LSCM); @@ -4250,7 +4252,7 @@ void param_lscm_end(ParamHandle *handle) void param_stretch_begin(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PChart *chart; PVert *v; PFace *f; @@ -4265,12 +4267,12 @@ void param_stretch_begin(ParamHandle *handle) for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; - for (v=chart->verts; v; v=v->nextlink) - v->flag &= ~PVERT_PIN; /* don't use user-defined pins */ + for (v = chart->verts; v; v = v->nextlink) + v->flag &= ~PVERT_PIN; /* don't use user-defined pins */ p_stretch_pin_boundary(chart); - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { p_face_backup_uvs(f); f->u.area3d = p_face_area(f); } @@ -4279,7 +4281,7 @@ void param_stretch_begin(ParamHandle *handle) void param_stretch_blend(ParamHandle *handle, float blend) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; param_assert(phandle->state == PHANDLE_STATE_STRETCH); phandle->blend = blend; @@ -4287,7 +4289,7 @@ void param_stretch_blend(ParamHandle *handle, float blend) void param_stretch_iter(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PChart *chart; int i; @@ -4301,7 +4303,7 @@ void param_stretch_iter(ParamHandle *handle) void param_stretch_end(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; param_assert(phandle->state == PHANDLE_STATE_STRETCH); phandle->state = PHANDLE_STATE_CONSTRUCTED; @@ -4312,7 +4314,7 @@ void param_stretch_end(ParamHandle *handle) void param_smooth_area(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; int i; param_assert(phandle->state == PHANDLE_STATE_CONSTRUCTED); @@ -4321,7 +4323,7 @@ void param_smooth_area(ParamHandle *handle) PChart *chart = phandle->charts[i]; PVert *v; - for (v=chart->verts; v; v=v->nextlink) + for (v = chart->verts; v; v = v->nextlink) v->flag &= ~PVERT_PIN; p_smooth(chart); @@ -4335,20 +4337,20 @@ void param_pack(ParamHandle *handle, float margin) float tot_width, tot_height, scale; PChart *chart; - int i, unpacked=0; + int i, unpacked = 0; float trans[2]; - double area= 0.0; + double area = 0.0; - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; if (phandle->ncharts == 0) return; if (phandle->aspx != phandle->aspy) - param_scale(handle, 1.0f/phandle->aspx, 1.0f/phandle->aspy); + param_scale(handle, 1.0f / phandle->aspx, 1.0f / phandle->aspy); /* we may not use all these boxes */ - boxarray = MEM_mallocN( phandle->ncharts*sizeof(boxPack), "boxPack box"); + boxarray = MEM_mallocN(phandle->ncharts * sizeof(boxPack), "boxPack box"); for (i = 0; i < phandle->ncharts; i++) { @@ -4359,7 +4361,7 @@ void param_pack(ParamHandle *handle, float margin) continue; } - box = boxarray+(i-unpacked); + box = boxarray + (i - unpacked); p_chart_uv_bbox(chart, trans, chart->u.pack.size); @@ -4372,16 +4374,16 @@ void param_pack(ParamHandle *handle, float margin) box->h = chart->u.pack.size[1] + trans[1]; box->index = i; /* warning this index skips PCHART_NOPACK boxes */ - if (margin>0.0f) - area += sqrt(box->w*box->h); + if (margin > 0.0f) + area += sqrt(box->w * box->h); } - if (margin>0.0f) { + if (margin > 0.0f) { /* multiply the margin by the area to give predictable results not dependent on UV scale, * ...Without using the area running pack multiple times also gives a bad feedback loop. * multiply by 0.1 so the margin value from the UI can be from 0.0 to 1.0 but not give a massive margin */ - margin = (margin*(float)area) * 0.1f; - unpacked= 0; + margin = (margin * (float)area) * 0.1f; + unpacked = 0; for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; @@ -4390,24 +4392,24 @@ void param_pack(ParamHandle *handle, float margin) continue; } - box = boxarray+(i-unpacked); + box = boxarray + (i - unpacked); trans[0] = margin; trans[1] = margin; p_chart_uv_translate(chart, trans); - box->w += margin*2; - box->h += margin*2; + box->w += margin * 2; + box->h += margin * 2; } } - boxPack2D(boxarray, phandle->ncharts-unpacked, &tot_width, &tot_height); + boxPack2D(boxarray, phandle->ncharts - unpacked, &tot_width, &tot_height); - if (tot_height>tot_width) - scale = 1.0f/tot_height; + if (tot_height > tot_width) + scale = 1.0f / tot_height; else - scale = 1.0f/tot_width; + scale = 1.0f / tot_width; - for (i = 0; i < phandle->ncharts-unpacked; i++) { - box = boxarray+i; + for (i = 0; i < phandle->ncharts - unpacked; i++) { + box = boxarray + i; trans[0] = box->x; trans[1] = box->y; @@ -4428,7 +4430,7 @@ void param_average(ParamHandle *handle) float tot_uvarea = 0.0f, tot_facearea = 0.0f; float tot_fac, fac; float minv[2], maxv[2], trans[2]; - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; if (phandle->ncharts == 0) return; @@ -4440,7 +4442,7 @@ void param_average(ParamHandle *handle) chart->u.pack.area = 0.0f; /* 3d area */ chart->u.pack.rescale = 0.0f; /* UV area, abusing rescale for tmp storage, oh well :/ */ - for (f=chart->faces; f; f=f->nextlink) { + for (f = chart->faces; f; f = f->nextlink) { chart->u.pack.area += p_face_area(f); chart->u.pack.rescale += fabsf(p_face_uv_area_signed(f)); } @@ -4449,12 +4451,12 @@ void param_average(ParamHandle *handle) tot_uvarea += chart->u.pack.rescale; } - if (tot_facearea == tot_uvarea || tot_facearea==0.0f || tot_uvarea==0.0f) { + if (tot_facearea == tot_uvarea || tot_facearea == 0.0f || tot_uvarea == 0.0f) { /* nothing to do */ return; } - tot_fac = tot_facearea/tot_uvarea; + tot_fac = tot_facearea / tot_uvarea; for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; @@ -4463,8 +4465,8 @@ void param_average(ParamHandle *handle) /* Get the island center */ p_chart_uv_bbox(chart, minv, maxv); - trans[0] = (minv[0] + maxv[0]) /-2.0f; - trans[1] = (minv[1] + maxv[1]) /-2.0f; + trans[0] = (minv[0] + maxv[0]) / -2.0f; + trans[1] = (minv[1] + maxv[1]) / -2.0f; /* Move center to 0,0 */ p_chart_uv_translate(chart, trans); @@ -4480,7 +4482,7 @@ void param_average(ParamHandle *handle) void param_scale(ParamHandle *handle, float x, float y) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PChart *chart; int i; @@ -4492,7 +4494,7 @@ void param_scale(ParamHandle *handle, float x, float y) void param_flush(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PChart *chart; int i; @@ -4511,7 +4513,7 @@ void param_flush(ParamHandle *handle) void param_flush_restore(ParamHandle *handle) { - PHandle *phandle = (PHandle*)handle; + PHandle *phandle = (PHandle *)handle; PChart *chart; PFace *f; int i; @@ -4519,7 +4521,7 @@ void param_flush_restore(ParamHandle *handle) for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; - for (f=chart->faces; f; f=f->nextlink) + for (f = chart->faces; f; f = f->nextlink) p_face_restore_uvs(f); } } diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index 384581247a0..33ecf3c97ef 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -73,7 +73,7 @@ struct IslandStitchData; /* This is a straightforward implementation, count the uv's in the island that will move and take the mean displacement/rotation and apply it to all * elements of the island except from the stitchable */ -typedef struct IslandStitchData{ +typedef struct IslandStitchData { /* rotation can be used only for edges, for vertices there is no such notion */ float rotation; float translation[2]; @@ -143,7 +143,7 @@ typedef struct StitchState { unsigned int *tris_per_island; } StitchState; -typedef struct PreviewPosition{ +typedef struct PreviewPosition { int data_position; int polycount_position; }PreviewPosition; @@ -162,7 +162,7 @@ typedef struct PreviewPosition{ static StitchPreviewer *_stitch_preview; /* constructor */ -static StitchPreviewer * stitch_preview_init(void) +static StitchPreviewer *stitch_preview_init(void) { _stitch_preview = MEM_mallocN(sizeof(StitchPreviewer), "stitch_previewer"); _stitch_preview->preview_polys = NULL; @@ -227,14 +227,14 @@ static void stitch_update_header(StitchState *stitch_state, bContext *C) static char str[] = "(S)nap %s, (M)idpoints %s, (L)imit %.2f (Alt Wheel adjust) %s, Switch (I)sland, shift select vertices"; char msg[HEADER_LENGTH]; - ScrArea *sa= CTX_wm_area(C); + ScrArea *sa = CTX_wm_area(C); if (sa) { BLI_snprintf(msg, HEADER_LENGTH, str, - stitch_state->snap_islands? "On" : "Off", - stitch_state->midpoints? "On": "Off", - stitch_state->limit_dist, - stitch_state->use_limit? "On" : "Off"); + stitch_state->snap_islands ? "On" : "Off", + stitch_state->midpoints ? "On" : "Off", + stitch_state->limit_dist, + stitch_state->use_limit ? "On" : "Off"); ED_area_headerprint(sa, msg); } @@ -242,11 +242,11 @@ static void stitch_update_header(StitchState *stitch_state, bContext *C) static int getNumOfIslandUvs(UvElementMap *elementMap, int island) { - if (island == elementMap->totalIslands-1) { + if (island == elementMap->totalIslands - 1) { return elementMap->totalUVs - elementMap->islandIndices[island]; } else { - return elementMap->islandIndices[island+1] - elementMap->islandIndices[island]; + return elementMap->islandIndices[island + 1] - elementMap->islandIndices[island]; } } @@ -257,8 +257,8 @@ static void stitch_uv_rotate(float rotation, float medianPoint[2], float uv[2]) uv[0] -= medianPoint[0]; uv[1] -= medianPoint[1]; - uv_rotation_result[0] = cos(rotation)*uv[0] - sin(rotation)*uv[1]; - uv_rotation_result[1] = sin(rotation)*uv[0] + cos(rotation)*uv[1]; + uv_rotation_result[0] = cos(rotation) * uv[0] - sin(rotation) * uv[1]; + uv_rotation_result[1] = sin(rotation) * uv[0] + cos(rotation) * uv[1]; uv[0] = uv_rotation_result[0] + medianPoint[0]; uv[1] = uv_rotation_result[1] + medianPoint[1]; @@ -286,8 +286,9 @@ static int stitch_check_uvs_stitchable(UvElement *element, UvElement *element_it l_iter = element_iter->l; luv_iter = CustomData_bmesh_get(&state->em->bm->ldata, l_iter->head.data, CD_MLOOPUV); - if (fabs(luv_orig->uv[0] - luv_iter->uv[0]) < limit - && fabs(luv_orig->uv[1] - luv_iter->uv[1]) < limit) { + if (fabs(luv_orig->uv[0] - luv_iter->uv[0]) < limit && + fabs(luv_orig->uv[1] - luv_iter->uv[1]) < limit) + { return 1; } else { @@ -303,8 +304,10 @@ static int stitch_check_uvs_stitchable(UvElement *element, UvElement *element_it static int stitch_check_uvs_state_stitchable(UvElement *element, UvElement *element_iter, StitchState *state) { if ((state->snap_islands && element->island == element_iter->island) || - (!state->midpoints && element->island == element_iter->island)) + (!state->midpoints && element->island == element_iter->island)) + { return 0; + } return stitch_check_uvs_stitchable(element, element_iter, state); } @@ -321,7 +324,7 @@ static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition int numOfIslandUVs = 0, j; /* check to avoid divide by 0 */ - if (island_stitch_data[i].num_rot_elements>0) { + if (island_stitch_data[i].num_rot_elements > 0) { island_stitch_data[i].rotation /= island_stitch_data[i].num_rot_elements; island_stitch_data[i].medianPoint[0] /= island_stitch_data[i].numOfElements; island_stitch_data[i].medianPoint[1] /= island_stitch_data[i].numOfElements; @@ -350,10 +353,10 @@ static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition int face_preview_pos = preview_position[BM_elem_index_get(element->face)].data_position; stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, - preview->preview_polys + face_preview_pos + 2*element->tfindex); + preview->preview_polys + face_preview_pos + 2 * element->tfindex); - add_v2_v2(preview->preview_polys + face_preview_pos + 2*element->tfindex, - island_stitch_data[i].translation); + add_v2_v2(preview->preview_polys + face_preview_pos + 2 * element->tfindex, + island_stitch_data[i].translation); } } /* cleanup */ @@ -397,10 +400,10 @@ static void stitch_island_calculate_edge_rotation(UvEdge *edge, StitchState *sta normalize_v2(uv1); normalize_v2(uv2); - edgecos = uv1[0]*uv2[0] + uv1[1]*uv2[1]; - edgesin = uv1[0]*uv2[1] - uv2[0]*uv1[1]; + edgecos = uv1[0] * uv2[0] + uv1[1] * uv2[1]; + edgesin = uv1[0] * uv2[1] - uv2[0] * uv1[1]; - rotation = (edgesin > 0)? acos(MAX2(-1.0, MIN2(1.0, edgecos))): -acos(MAX2(-1.0, MIN2(1.0, edgecos))); + rotation = (edgesin > 0) ? acos(MAX2(-1.0, MIN2(1.0, edgecos))) : -acos(MAX2(-1.0, MIN2(1.0, edgecos))); island_stitch_data[element1->island].num_rot_elements++; island_stitch_data[element1->island].rotation += rotation; @@ -435,10 +438,10 @@ static void stitch_island_calculate_vert_rotation(UvElement *element, StitchStat index_tmp2 = element - state->element_map->buf; index_tmp2 = state->map[index_tmp2]; - negate_v2_v2(normal, state->normals + index_tmp2*2); - edgecos = dot_v2v2(normal, state->normals + index_tmp1*2); - edgesin = cross_v2v2(normal, state->normals + index_tmp1*2); - rotation += (edgesin > 0)? acos(edgecos): -acos(edgecos); + negate_v2_v2(normal, state->normals + index_tmp2 * 2); + edgecos = dot_v2v2(normal, state->normals + index_tmp1 * 2); + edgesin = cross_v2v2(normal, state->normals + index_tmp1 * 2); + rotation += (edgesin > 0) ? acos(edgecos) : -acos(edgecos); } } @@ -512,7 +515,7 @@ static void stitch_set_face_preview_buffer_position(BMFace *efa, StitchPreviewer int index = BM_elem_index_get(efa); if (preview_position[index].data_position == STITCH_NO_PREVIEW) { - preview_position[index].data_position = preview->preview_uvs*2; + preview_position[index].data_position = preview->preview_uvs * 2; preview_position[index].polycount_position = preview->num_polys++; preview->preview_uvs += efa->len; } @@ -521,7 +524,7 @@ static void stitch_set_face_preview_buffer_position(BMFace *efa, StitchPreviewer /* setup face preview for all coincident uvs and their faces */ static void stitch_setup_face_preview_for_uv_group(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data, - PreviewPosition *preview_position) { + PreviewPosition *preview_position) { StitchPreviewer *preview = uv_get_stitch_previewer(); /* static island does not change so returning immediately */ @@ -540,8 +543,8 @@ static void stitch_setup_face_preview_for_uv_group(UvElement *element, StitchSta /* checks if uvs are indeed stitchable and registers so that they can be shown in preview */ -static void stitch_validate_stichability (UvElement *element, StitchState *state, IslandStitchData *island_stitch_data, - PreviewPosition *preview_position) { +static void stitch_validate_stichability(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data, + PreviewPosition *preview_position) { UvElement *element_iter; StitchPreviewer *preview; int vert_index; @@ -597,13 +600,13 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) if (preview == NULL) return 0; - preview_position = MEM_mallocN(state->em->bm->totface*sizeof(*preview_position), "stitch_face_preview_position"); + preview_position = MEM_mallocN(state->em->bm->totface * sizeof(*preview_position), "stitch_face_preview_position"); /* each face holds its position in the preview buffer in tmp. -1 is uninitialized */ for (i = 0; i < state->em->bm->totface; i++) { preview_position[i].data_position = STITCH_NO_PREVIEW; } - island_stitch_data = MEM_callocN(sizeof(*island_stitch_data)*state->element_map->totalIslands, "stitch_island_data"); + island_stitch_data = MEM_callocN(sizeof(*island_stitch_data) * state->element_map->totalIslands, "stitch_island_data"); if (!island_stitch_data) { return 0; } @@ -669,12 +672,12 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) unsigned int buffer_index = 0; int stitchBufferIndex = 0, unstitchBufferIndex = 0; /* initialize the preview buffers */ - preview->preview_polys = (float *)MEM_mallocN(preview->preview_uvs*sizeof(float)*2, "tri_uv_stitch_prev"); - preview->uvs_per_polygon = MEM_mallocN(preview->num_polys*sizeof(*preview->uvs_per_polygon), "tri_uv_stitch_prev"); - preview->preview_stitchable = (float *)MEM_mallocN(preview->num_stitchable*sizeof(float)*2, "stitch_preview_stichable_data"); - preview->preview_unstitchable = (float *)MEM_mallocN(preview->num_unstitchable*sizeof(float)*2, "stitch_preview_unstichable_data"); + preview->preview_polys = (float *)MEM_mallocN(preview->preview_uvs * sizeof(float) * 2, "tri_uv_stitch_prev"); + preview->uvs_per_polygon = MEM_mallocN(preview->num_polys * sizeof(*preview->uvs_per_polygon), "tri_uv_stitch_prev"); + preview->preview_stitchable = (float *)MEM_mallocN(preview->num_stitchable * sizeof(float) * 2, "stitch_preview_stichable_data"); + preview->preview_unstitchable = (float *)MEM_mallocN(preview->num_unstitchable * sizeof(float) * 2, "stitch_preview_unstichable_data"); - preview->static_tris = (float *)MEM_mallocN(state->tris_per_island[state->static_island]*sizeof(float)*6, "static_island_preview_tris"); + preview->static_tris = (float *)MEM_mallocN(state->tris_per_island[state->static_island] * sizeof(float) * 6, "static_island_preview_tris"); preview->num_static_tris = state->tris_per_island[state->static_island]; /* will cause cancel and freeing of all data structures so OK */ @@ -695,7 +698,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) preview->uvs_per_polygon[preview_position[index].polycount_position] = efa->len; BM_ITER_INDEX(l, &liter, state->em->bm, BM_LOOPS_OF_FACE, efa, i) { luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); - copy_v2_v2(preview->preview_polys + face_preview_pos + i*2, luv->uv); + copy_v2_v2(preview->preview_polys + face_preview_pos + i * 2, luv->uv); } } @@ -710,9 +713,9 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) MLoopUV *luvnext = CustomData_bmesh_get(&state->em->bm->ldata, lnext->next->head.data, CD_MLOOPUV); luv = CustomData_bmesh_get(&state->em->bm->ldata, lnext->head.data, CD_MLOOPUV); - memcpy(preview->static_tris + buffer_index, fuv->uv, 2*sizeof(float)); - memcpy(preview->static_tris + buffer_index + 2, luv->uv, 2*sizeof(float)); - memcpy(preview->static_tris + buffer_index + 4, luvnext->uv, 2*sizeof(float)); + memcpy(preview->static_tris + buffer_index, fuv->uv, 2 * sizeof(float)); + memcpy(preview->static_tris + buffer_index + 2, luv->uv, 2 * sizeof(float)); + memcpy(preview->static_tris + buffer_index + 4, luvnext->uv, 2 * sizeof(float)); buffer_index += 6; } else { @@ -730,7 +733,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) l = element->l; luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); - copy_v2_v2(&preview->preview_stitchable[stitchBufferIndex*2], luv->uv); + copy_v2_v2(&preview->preview_stitchable[stitchBufferIndex * 2], luv->uv); stitchBufferIndex++; } @@ -738,7 +741,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) l = element->l; luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); - copy_v2_v2(&preview->preview_unstitchable[unstitchBufferIndex*2], luv->uv); + copy_v2_v2(&preview->preview_unstitchable[unstitchBufferIndex * 2], luv->uv); unstitchBufferIndex++; } } @@ -748,8 +751,8 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) * Here we calculate the final coordinates of the uvs * ******************************************************/ - final_position = MEM_callocN(state->selection_size*sizeof(*final_position), "stitch_uv_average"); - uvfinal_map = MEM_mallocN(state->element_map->totalUVs*sizeof(*uvfinal_map), "stitch_uv_final_map"); + final_position = MEM_callocN(state->selection_size * sizeof(*final_position), "stitch_uv_average"); + uvfinal_map = MEM_mallocN(state->element_map->totalUVs * sizeof(*uvfinal_map), "stitch_uv_final_map"); /* first pass, calculate final position for stitchable uvs of the static island */ for (i = 0; i < state->selection_size; i++) { @@ -773,7 +776,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) element_iter = state->element_map->vert[BM_elem_index_get(l->v)]; - for (;element_iter; element_iter = element_iter->next) { + for ( ; element_iter; element_iter = element_iter->next) { if (element_iter->separate) { if (stitch_check_uvs_state_stitchable(element, element_iter, state)) { l = element_iter->l; @@ -821,7 +824,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) /* only calculate rotation when an edge has been fully selected */ for (i = 0; i < state->total_boundary_edges; i++) { - UvEdge *edge = state->edges+i; + UvEdge *edge = state->edges + i; if ((state->uvs[edge->uv1]->flag & STITCH_STITCHABLE) && (state->uvs[edge->uv2]->flag & STITCH_STITCHABLE)) { stitch_island_calculate_edge_rotation(edge, state, final_position, uvfinal_map, island_stitch_data); island_stitch_data[state->uvs[edge->uv1]->island].use_edge_rotation = 1; @@ -862,8 +865,8 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) else { int face_preview_pos = preview_position[BM_elem_index_get(element_iter->face)].data_position; if (face_preview_pos != STITCH_NO_PREVIEW) { - copy_v2_v2(preview->preview_polys + face_preview_pos + 2*element_iter->tfindex, - final_position[i].uv); + copy_v2_v2(preview->preview_polys + face_preview_pos + 2 * element_iter->tfindex, + final_position[i].uv); } } @@ -891,12 +894,12 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) } /* Stitch hash initialization functions */ -static unsigned int uv_edge_hash(const void *key) +static unsigned int uv_edge_hash(const void *key) { UvEdge *edge = (UvEdge *)key; return - BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv2)) + - BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv1)); + BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv2)) + + BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv1)); } static int uv_edge_compare(const void *a, const void *b) @@ -979,7 +982,7 @@ static int stitch_init(bContext *C, wmOperator *op) BMLoop *l; BMIter iter, liter; BMEditMesh *em; - GHashIterator* ghi; + GHashIterator *ghi; UvEdge *all_edges; StitchState *state = MEM_mallocN(sizeof(StitchState), "stitch state"); Scene *scene = CTX_data_scene(C); @@ -1023,18 +1026,18 @@ static int stitch_init(bContext *C, wmOperator *op) } /* Allocate the unique uv buffers */ - state->uvs = MEM_mallocN(sizeof(*state->uvs)*counter, "uv_stitch_unique_uvs"); + state->uvs = MEM_mallocN(sizeof(*state->uvs) * counter, "uv_stitch_unique_uvs"); /* internal uvs need no normals but it is hard and slow to keep a map of * normals only for boundary uvs, so allocating for all uvs */ - state->normals = MEM_callocN(sizeof(*state->normals)*counter*2, "uv_stitch_normals"); + state->normals = MEM_callocN(sizeof(*state->normals) * counter * 2, "uv_stitch_normals"); state->total_separate_uvs = counter; /* we can at most have totalUVs edges or uvs selected. Actually they are less, considering we store only * unique uvs for processing but I am accounting for all bizarre cases, especially for edges, this way */ - state->selection_stack = MEM_mallocN(sizeof(*state->selection_stack)*counter, "uv_stitch_selection_stack"); - state->map = map = MEM_mallocN(sizeof(*map)*state->element_map->totalUVs, "uv_stitch_unique_map"); + state->selection_stack = MEM_mallocN(sizeof(*state->selection_stack) * counter, "uv_stitch_selection_stack"); + state->map = map = MEM_mallocN(sizeof(*map) * state->element_map->totalUVs, "uv_stitch_unique_map"); /* Allocate the edge stack */ edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "stitch_edge_hash"); - all_edges = MEM_mallocN(sizeof(*all_edges)*state->element_map->totalUVs, "stitch_all_edges"); + all_edges = MEM_mallocN(sizeof(*all_edges) * state->element_map->totalUVs, "stitch_all_edges"); if (!state->selection_stack || !state->uvs || !map || !edgeHash || !all_edges) { stitch_state_delete(state); @@ -1105,7 +1108,7 @@ static int stitch_init(bContext *C, wmOperator *op) total_edges++; } } - state->edges = edges = MEM_mallocN(sizeof(*edges)*total_edges, "stitch_edges"); + state->edges = edges = MEM_mallocN(sizeof(*edges) * total_edges, "stitch_edges"); if (!ghi || !edges) { MEM_freeN(all_edges); stitch_state_delete(state); @@ -1140,11 +1143,11 @@ static int stitch_init(bContext *C, wmOperator *op) float normal[2]; stitch_calculate_edge_normal(em, edges + i, normal); - add_v2_v2(state->normals + edges[i].uv1*2, normal); - add_v2_v2(state->normals + edges[i].uv2*2, normal); + add_v2_v2(state->normals + edges[i].uv1 * 2, normal); + add_v2_v2(state->normals + edges[i].uv2 * 2, normal); - normalize_v2(state->normals + edges[i].uv1*2); - normalize_v2(state->normals + edges[i].uv2*2); + normalize_v2(state->normals + edges[i].uv1 * 2); + normalize_v2(state->normals + edges[i].uv2 * 2); } @@ -1188,8 +1191,8 @@ static int stitch_init(bContext *C, wmOperator *op) /***** initialize static island preview data *****/ - state->tris_per_island = MEM_mallocN(sizeof(*state->tris_per_island)*state->element_map->totalIslands, - "stitch island tris"); + state->tris_per_island = MEM_mallocN(sizeof(*state->tris_per_island) * state->element_map->totalIslands, + "stitch island tris"); for (i = 0; i < state->element_map->totalIslands; i++) { state->tris_per_island[i] = 0; } @@ -1198,7 +1201,7 @@ static int stitch_init(bContext *C, wmOperator *op) UvElement *element = ED_uv_element_get(state->element_map, efa, BM_FACE_FIRST_LOOP(efa)); if (element) { - state->tris_per_island[element->island] += (efa->len > 2)? efa->len-2 : 0; + state->tris_per_island[element->island] += (efa->len > 2) ? efa->len - 2 : 0; } } @@ -1218,7 +1221,7 @@ static int stitch_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) return OPERATOR_CANCELLED; WM_event_add_modal_handler(C, op); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_RUNNING_MODAL; } @@ -1227,12 +1230,12 @@ static void stitch_exit(bContext *C, wmOperator *op, int finished) StitchState *stitch_state; Scene *scene; SpaceImage *sima; - ScrArea *sa= CTX_wm_area(C); + ScrArea *sa = CTX_wm_area(C); Object *obedit; - scene= CTX_data_scene(C); - obedit= CTX_data_edit_object(C); - sima= CTX_wm_space_image(C); + scene = CTX_data_scene(C); + obedit = CTX_data_edit_object(C); + sima = CTX_wm_space_image(C); stitch_state = (StitchState *)op->customdata; @@ -1265,7 +1268,7 @@ static void stitch_exit(bContext *C, wmOperator *op, int finished) ED_area_headerprint(sa, NULL); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); stitch_state_delete(stitch_state); op->customdata = NULL; @@ -1301,8 +1304,8 @@ static void stitch_select(bContext *C, Scene *scene, wmEvent *event, StitchState /* add uv under mouse to processed uv's */ float co[2]; NearestHit hit; - ARegion *ar= CTX_wm_region(C); - Image *ima= CTX_data_edit_image(C); + ARegion *ar = CTX_wm_region(C); + Image *ima = CTX_data_edit_image(C); UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]); uv_find_nearest_vert(scene, ima, stitch_state->em, co, NULL, &hit); @@ -1326,7 +1329,7 @@ static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event) stitch_state = (StitchState *)op->customdata; - switch(event->type) { + switch (event->type) { case MIDDLEMOUSE: return OPERATOR_PASS_THROUGH; @@ -1419,7 +1422,7 @@ static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event) /* Select geometry*/ case RIGHTMOUSE: if (!event->shift) { - return stitch_cancel(C, op); + return stitch_cancel(C, op); } if (event->val == KM_RELEASE && !(U.flag & USER_LMOUSESELECT)) { stitch_select(C, scene, event, stitch_state); @@ -1440,8 +1443,9 @@ static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event) } break; } - else - return OPERATOR_RUNNING_MODAL; + else { + return OPERATOR_RUNNING_MODAL; + } default: return OPERATOR_RUNNING_MODAL; @@ -1461,7 +1465,7 @@ void UV_OT_stitch(wmOperatorType *ot) ot->name = "Stitch"; ot->description = "Stitch selected UV vertices by proximity"; ot->idname = "UV_OT_stitch"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->invoke = stitch_invoke; @@ -1473,14 +1477,14 @@ void UV_OT_stitch(wmOperatorType *ot) /* properties */ RNA_def_boolean(ot->srna, "use_limit", 0, "Use Limit", "Stitch UVs within a specified limit distance"); RNA_def_boolean(ot->srna, "snap_islands", 1, "Snap Islands", - "Snap islands together (on edge stitch mode, rotates the islands too)"); + "Snap islands together (on edge stitch mode, rotates the islands too)"); RNA_def_float(ot->srna, "limit", 0.01f, 0.0f, FLT_MAX, "Limit", - "Limit distance in normalized coordinates", 0.0, FLT_MAX); + "Limit distance in normalized coordinates", 0.0, FLT_MAX); RNA_def_int(ot->srna, "static_island", 0, 0, INT_MAX, "Static Island", - "Island that stays in place when stitching islands", 0, INT_MAX); + "Island that stays in place when stitching islands", 0, INT_MAX); RNA_def_boolean(ot->srna, "midpoint_snap", 0, "Snap At Midpoint", - "UVs are stitched at midpoint instead of at static island"); + "UVs are stitched at midpoint instead of at static island"); prop = RNA_def_collection_runtime(ot->srna, "selection", &RNA_SelectedUvElement, "Selection", ""); /* Selection should not be editable or viewed in toolbar */ RNA_def_property_flag(prop, PROP_HIDDEN); diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index ac04e25216d..a3cbcc57a9c 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -112,21 +112,21 @@ static int ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit) return 0; } - ima= CTX_data_edit_image(C); + ima = CTX_data_edit_image(C); if (!ima) { /* no image in context in the 3d view, we find first image window .. */ - sc= CTX_wm_screen(C); + sc = CTX_wm_screen(C); - for (sa=sc->areabase.first; sa; sa=sa->next) { - slink= sa->spacedata.first; + for (sa = sc->areabase.first; sa; sa = sa->next) { + slink = sa->spacedata.first; if (slink->spacetype == SPACE_IMAGE) { - sima= (SpaceImage*)slink; + sima = (SpaceImage *)slink; - ima= sima->image; + ima = sima->image; if (ima) { - if (ima->type==IMA_TYPE_R_RESULT || ima->type==IMA_TYPE_COMPOSITE) - ima= NULL; + if (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) + ima = NULL; else break; } @@ -183,8 +183,8 @@ static int uvedit_have_selection(Scene *scene, BMEditMesh *em, short implicit) } static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, - short implicit, short fill, short sel, - short correct_aspect) + short implicit, short fill, short sel, + short correct_aspect) { ParamHandle *handle; BMFace *efa; @@ -200,11 +200,11 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, if (efa) { float aspx, aspy; - tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); ED_image_uv_aspect(tf->tpage, &aspx, &aspy); - if (aspx!=aspy) + if (aspx != aspy) param_aspect_ratio(handle, aspx, aspy); } } @@ -223,7 +223,7 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, float *uv[4]; int lsel; - if ((BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) || (sel && BM_elem_flag_test(efa, BM_ELEM_SELECT)==0)) + if ((BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) || (sel && BM_elem_flag_test(efa, BM_ELEM_SELECT) == 0)) continue; /* tf= (MTexPoly *)CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ @@ -251,8 +251,8 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, v = BLI_addfillvert(l->v->co); /*add small random offset*/ - for (i=0; i<3; i++) { - v->co[i] += (BLI_drand()-0.5f)*FLT_EPSILON*50; + for (i = 0; i < 3; i++) { + v->co[i] += (BLI_drand() - 0.5f) * FLT_EPSILON * 50; } v->tmp.p = l; @@ -270,7 +270,7 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, /*mode 2 enables faster handling of tri/quads*/ BLI_edgefill(2); - for (sefa = fillfacebase.first; sefa; sefa=sefa->next) { + for (sefa = fillfacebase.first; sefa; sefa = sefa->next) { ls[0] = sefa->v1->tmp.p; ls[1] = sefa->v2->tmp.p; ls[2] = sefa->v3->tmp.p; @@ -299,8 +299,8 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, select[1] = uvedit_uv_selected(em, scene, ls[1]) != 0; select[2] = uvedit_uv_selected(em, scene, ls[2]) != 0; - if (!p_face_exists(handle,vkeys,0,1,2)) - param_face_add(handle, key, 3, vkeys, co, uv, pin, select); + if (!p_face_exists(handle, vkeys, 0, 1, 2)) + param_face_add(handle, key, 3, vkeys, co, uv, pin, select); } BLI_end_edgefill(); @@ -340,7 +340,7 @@ static void texface_from_original_index(BMFace *efa, int index, float **uv, Para if (BM_elem_index_get(l->v) == index) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); *uv = luv->uv; - *pin = (luv->flag & MLOOPUV_PINNED)? 1 : 0; + *pin = (luv->flag & MLOOPUV_PINNED) ? 1 : 0; *select = (uvedit_uv_selected(em, scene, l) != 0); } } @@ -383,11 +383,11 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e if (editFace) { MTexPoly *tf; float aspx, aspy; - tf= CustomData_bmesh_get(&em->bm->pdata, editFace->head.data, CD_MTEXPOLY); + tf = CustomData_bmesh_get(&em->bm->pdata, editFace->head.data, CD_MTEXPOLY); ED_image_uv_aspect(tf->tpage, &aspx, &aspy); - if (aspx!=aspy) + if (aspx != aspy) param_aspect_ratio(handle, aspx, aspy); } } @@ -398,7 +398,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e initialDerived = CDDM_from_BMEditMesh(em, NULL, 0, 0); derivedMesh = subsurf_make_derived_from_derived(initialDerived, &smd, - 0, NULL, 0, 0, 1); + 0, NULL, 0, 0, 1); initialDerived->release(initialDerived); @@ -414,7 +414,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e numOfEdges = derivedMesh->getNumEdges(derivedMesh); numOfFaces = derivedMesh->getNumTessFaces(derivedMesh); - faceMap = MEM_mallocN(numOfFaces*sizeof(BMFace *), "unwrap_edit_face_map"); + faceMap = MEM_mallocN(numOfFaces * sizeof(BMFace *), "unwrap_edit_face_map"); BM_mesh_elem_index_ensure(em->bm, BM_VERT); EDBM_index_arrays_init(em, 0, 1, 1); @@ -423,13 +423,13 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e for (i = 0; i < numOfFaces; i++) faceMap[i] = EDBM_face_at_index(em, origFaceIndices[i]); - edgeMap = MEM_mallocN(numOfEdges*sizeof(BMEdge *), "unwrap_edit_edge_map"); + edgeMap = MEM_mallocN(numOfEdges * sizeof(BMEdge *), "unwrap_edit_edge_map"); /* map subsurfed edges to original editEdges */ for (i = 0; i < numOfEdges; i++) { /* not all edges correspond to an old edge */ - edgeMap[i] = (origEdgeIndices[i] != -1)? - EDBM_edge_at_index(em, origEdgeIndices[i]) : NULL; + edgeMap[i] = (origEdgeIndices[i] != -1) ? + EDBM_edge_at_index(em, origEdgeIndices[i]) : NULL; } EDBM_index_arrays_free(em); @@ -442,7 +442,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e float *uv[4]; BMFace *origFace = faceMap[i]; - face = subsurfedFaces+i; + face = subsurfedFaces + i; if (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) { if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN)) @@ -521,29 +521,29 @@ static int minimize_stretch_init(bContext *C, wmOperator *op) return 0; } - ms= MEM_callocN(sizeof(MinStretch), "MinStretch"); - ms->scene= scene; - ms->obedit= obedit; - ms->em= em; - ms->blend= RNA_float_get(op->ptr, "blend"); - ms->iterations= RNA_int_get(op->ptr, "iterations"); - ms->i= 0; - ms->handle= construct_param_handle(scene, em, implicit, fill_holes, 1, 1); - ms->lasttime= PIL_check_seconds_timer(); + ms = MEM_callocN(sizeof(MinStretch), "MinStretch"); + ms->scene = scene; + ms->obedit = obedit; + ms->em = em; + ms->blend = RNA_float_get(op->ptr, "blend"); + ms->iterations = RNA_int_get(op->ptr, "iterations"); + ms->i = 0; + ms->handle = construct_param_handle(scene, em, implicit, fill_holes, 1, 1); + ms->lasttime = PIL_check_seconds_timer(); param_stretch_begin(ms->handle); if (ms->blend != 0.0f) param_stretch_blend(ms->handle, ms->blend); - op->customdata= ms; + op->customdata = ms; return 1; } static void minimize_stretch_iteration(bContext *C, wmOperator *op, int interactive) { - MinStretch *ms= op->customdata; - ScrArea *sa= CTX_wm_area(C); + MinStretch *ms = op->customdata; + ScrArea *sa = CTX_wm_area(C); param_stretch_blend(ms->handle, ms->blend); param_stretch_iter(ms->handle); @@ -564,14 +564,14 @@ static void minimize_stretch_iteration(bContext *C, wmOperator *op, int interact ms->lasttime = PIL_check_seconds_timer(); DAG_id_tag_update(ms->obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ms->obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, ms->obedit->data); } } static void minimize_stretch_exit(bContext *C, wmOperator *op, int cancel) { - MinStretch *ms= op->customdata; - ScrArea *sa= CTX_wm_area(C); + MinStretch *ms = op->customdata; + ScrArea *sa = CTX_wm_area(C); if (sa) ED_area_headerprint(sa, NULL); @@ -587,10 +587,10 @@ static void minimize_stretch_exit(bContext *C, wmOperator *op, int cancel) param_delete(ms->handle); DAG_id_tag_update(ms->obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ms->obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, ms->obedit->data); MEM_freeN(ms); - op->customdata= NULL; + op->customdata = NULL; } static int minimize_stretch_exec(bContext *C, wmOperator *op) @@ -600,8 +600,8 @@ static int minimize_stretch_exec(bContext *C, wmOperator *op) if (!minimize_stretch_init(C, op)) return OPERATOR_CANCELLED; - iterations= RNA_int_get(op->ptr, "iterations"); - for (i=0; i<iterations; i++) + iterations = RNA_int_get(op->ptr, "iterations"); + for (i = 0; i < iterations; i++) minimize_stretch_iteration(C, op, 0); minimize_stretch_exit(C, op, 0); @@ -617,18 +617,18 @@ static int minimize_stretch_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED( minimize_stretch_iteration(C, op, 1); - ms= op->customdata; + ms = op->customdata; WM_event_add_modal_handler(C, op); - ms->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); + ms->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); return OPERATOR_RUNNING_MODAL; } static int minimize_stretch_modal(bContext *C, wmOperator *op, wmEvent *event) { - MinStretch *ms= op->customdata; + MinStretch *ms = op->customdata; - switch(event->type) { + switch (event->type) { case ESCKEY: case RIGHTMOUSE: minimize_stretch_exit(C, op, 1); @@ -642,7 +642,7 @@ static int minimize_stretch_modal(bContext *C, wmOperator *op, wmEvent *event) case WHEELUPMOUSE: if (ms->blend < 0.95f) { ms->blend += 0.1f; - ms->lasttime= 0.0f; + ms->lasttime = 0.0f; RNA_float_set(op->ptr, "blend", ms->blend); minimize_stretch_iteration(C, op, 1); } @@ -651,14 +651,14 @@ static int minimize_stretch_modal(bContext *C, wmOperator *op, wmEvent *event) case WHEELDOWNMOUSE: if (ms->blend > 0.05f) { ms->blend -= 0.1f; - ms->lasttime= 0.0f; + ms->lasttime = 0.0f; RNA_float_set(op->ptr, "blend", ms->blend); minimize_stretch_iteration(C, op, 1); } break; case TIMER: if (ms->timer == event->customdata) { - double start= PIL_check_seconds_timer(); + double start = PIL_check_seconds_timer(); do { minimize_stretch_iteration(C, op, 1); @@ -687,7 +687,7 @@ void UV_OT_minimize_stretch(wmOperatorType *ot) /* identifiers */ ot->name = "Minimize Stretch"; ot->idname = "UV_OT_minimize_stretch"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_GRAB_POINTER|OPTYPE_BLOCKING; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_POINTER | OPTYPE_BLOCKING; ot->description = "Reduce UV stretching by relaxing angles"; /* api callbacks */ @@ -718,7 +718,7 @@ static int pack_islands_exec(bContext *C, wmOperator *op) } if (RNA_struct_property_is_set(op->ptr, "margin")) { - scene->toolsettings->uvcalc_margin= RNA_float_get(op->ptr, "margin"); + scene->toolsettings->uvcalc_margin = RNA_float_get(op->ptr, "margin"); } else { RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin); @@ -730,7 +730,7 @@ static int pack_islands_exec(bContext *C, wmOperator *op) param_delete(handle); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -740,7 +740,7 @@ void UV_OT_pack_islands(wmOperatorType *ot) /* identifiers */ ot->name = "Pack Islands"; ot->idname = "UV_OT_pack_islands"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = pack_islands_exec; @@ -764,13 +764,13 @@ static int average_islands_scale_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; } - handle= construct_param_handle(scene, em, implicit, 0, 1, 1); + handle = construct_param_handle(scene, em, implicit, 0, 1, 1); param_average(handle); param_flush(handle); param_delete(handle); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -780,7 +780,7 @@ void UV_OT_average_islands_scale(wmOperatorType *ot) /* identifiers */ ot->name = "Average Islands Scale"; ot->idname = "UV_OT_average_islands_scale"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = average_islands_scale_exec; @@ -832,27 +832,27 @@ void ED_uvedit_live_unwrap_end(short cancel) /*************** UV Map Common Transforms *****************/ #define VIEW_ON_EQUATOR 0 -#define VIEW_ON_POLES 1 -#define ALIGN_TO_OBJECT 2 +#define VIEW_ON_POLES 1 +#define ALIGN_TO_OBJECT 2 -#define POLAR_ZX 0 -#define POLAR_ZY 1 +#define POLAR_ZX 0 +#define POLAR_ZY 1 static void uv_map_transform_center(Scene *scene, View3D *v3d, float *result, - Object *ob, BMEditMesh *em) + Object *ob, BMEditMesh *em) { BMFace *efa; BMLoop *l; BMIter iter, liter; float min[3], max[3], *cursx; - int around= (v3d)? v3d->around: V3D_CENTER; + int around = (v3d) ? v3d->around : V3D_CENTER; /* only operates on the edit object - this is all that's needed now */ switch (around) { case V3D_CENTER: /* bounding box center */ - min[0]= min[1]= min[2]= 1e20f; - max[0]= max[1]= max[2]= -1e20f; + min[0] = min[1] = min[2] = 1e20f; + max[0] = max[1] = max[2] = -1e20f; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { @@ -865,17 +865,17 @@ static void uv_map_transform_center(Scene *scene, View3D *v3d, float *result, break; case V3D_CURSOR: /*cursor center*/ - cursx= give_cursor(scene, v3d); + cursx = give_cursor(scene, v3d); /* shift to objects world */ - result[0]= cursx[0]-ob->obmat[3][0]; - result[1]= cursx[1]-ob->obmat[3][1]; - result[2]= cursx[2]-ob->obmat[3][2]; + result[0] = cursx[0] - ob->obmat[3][0]; + result[1] = cursx[1] - ob->obmat[3][1]; + result[2] = cursx[2] - ob->obmat[3][2]; break; case V3D_LOCAL: /*object center*/ case V3D_CENTROID: /* multiple objects centers, only one object here*/ default: - result[0]= result[1]= result[2]= 0.0; + result[0] = result[1] = result[2] = 0.0; break; } } @@ -884,7 +884,7 @@ static void uv_map_rotation_matrix(float result[][4], RegionView3D *rv3d, Object float upangledeg, float sideangledeg, float radius) { float rotup[4][4], rotside[4][4], viewmatrix[4][4], rotobj[4][4]; - float sideangle= 0.0f, upangle= 0.0f; + float sideangle = 0.0f, upangle = 0.0f; int k; /* get rotation of the current view matrix */ @@ -894,15 +894,15 @@ static void uv_map_rotation_matrix(float result[][4], RegionView3D *rv3d, Object unit_m4(viewmatrix); /* but shifting */ - for (k=0; k<4; k++) - viewmatrix[3][k] =0.0f; + for (k = 0; k < 4; k++) + viewmatrix[3][k] = 0.0f; /* get rotation of the current object matrix */ - copy_m4_m4(rotobj,ob->obmat); + copy_m4_m4(rotobj, ob->obmat); /* but shifting */ - for (k=0; k<4; k++) - rotobj[3][k] =0.0f; + for (k = 0; k < 4; k++) + rotobj[3][k] = 0.0f; zero_m4(rotup); zero_m4(rotside); @@ -910,19 +910,19 @@ static void uv_map_rotation_matrix(float result[][4], RegionView3D *rv3d, Object /* compensate front/side.. against opengl x,y,z world definition */ /* this is "kanonen gegen spatzen", a few plus minus 1 will do here */ /* i wanted to keep the reason here, so we're rotating*/ - sideangle= (float)M_PI*(sideangledeg + 180.0f)/180.0f; - rotside[0][0]= (float)cos(sideangle); - rotside[0][1]= -(float)sin(sideangle); - rotside[1][0]= (float)sin(sideangle); - rotside[1][1]= (float)cos(sideangle); - rotside[2][2]= 1.0f; - - upangle= (float)M_PI*upangledeg/180.0f; - rotup[1][1]= (float)cos(upangle)/radius; - rotup[1][2]= -(float)sin(upangle)/radius; - rotup[2][1]= (float)sin(upangle)/radius; - rotup[2][2]= (float)cos(upangle)/radius; - rotup[0][0]= (float)1.0f/radius; + sideangle = (float)M_PI * (sideangledeg + 180.0f) / 180.0f; + rotside[0][0] = (float)cos(sideangle); + rotside[0][1] = -(float)sin(sideangle); + rotside[1][0] = (float)sin(sideangle); + rotside[1][1] = (float)cos(sideangle); + rotside[2][2] = 1.0f; + + upangle = (float)M_PI * upangledeg / 180.0f; + rotup[1][1] = (float)cos(upangle) / radius; + rotup[1][2] = -(float)sin(upangle) / radius; + rotup[2][1] = (float)sin(upangle) / radius; + rotup[2][2] = (float)cos(upangle) / radius; + rotup[0][0] = (float)1.0f / radius; /* calculate transforms*/ mul_serie_m4(result, rotup, rotside, viewmatrix, rotobj, NULL, NULL, NULL, NULL); @@ -937,21 +937,21 @@ static void uv_map_transform(bContext *C, wmOperator *op, float center[3], float View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); /* common operator properties */ - int align= RNA_enum_get(op->ptr, "align"); - int direction= RNA_enum_get(op->ptr, "direction"); - float radius= RNA_struct_find_property(op->ptr, "radius")? RNA_float_get(op->ptr, "radius"): 1.0f; + int align = RNA_enum_get(op->ptr, "align"); + int direction = RNA_enum_get(op->ptr, "direction"); + float radius = RNA_struct_find_property(op->ptr, "radius") ? RNA_float_get(op->ptr, "radius") : 1.0f; float upangledeg, sideangledeg; uv_map_transform_center(scene, v3d, center, obedit, em); if (direction == VIEW_ON_EQUATOR) { - upangledeg= 90.0f; - sideangledeg= 0.0f; + upangledeg = 90.0f; + sideangledeg = 0.0f; } else { - upangledeg= 0.0f; - if (align == POLAR_ZY) sideangledeg= 0.0f; - else sideangledeg= 90.0f; + upangledeg = 0.0f; + if (align == POLAR_ZY) sideangledeg = 0.0f; + else sideangledeg = 90.0f; } /* be compatible to the "old" sphere/cylinder mode */ @@ -964,13 +964,13 @@ static void uv_map_transform(bContext *C, wmOperator *op, float center[3], float static void uv_transform_properties(wmOperatorType *ot, int radius) { - static EnumPropertyItem direction_items[]= { + static EnumPropertyItem direction_items[] = { {VIEW_ON_EQUATOR, "VIEW_ON_EQUATOR", 0, "View on Equator", "3D view is on the equator"}, {VIEW_ON_POLES, "VIEW_ON_POLES", 0, "View on Poles", "3D view is on the poles"}, {ALIGN_TO_OBJECT, "ALIGN_TO_OBJECT", 0, "Align to Object", "Align according to object transform"}, {0, NULL, 0, NULL, NULL} }; - static EnumPropertyItem align_items[]= { + static EnumPropertyItem align_items[] = { {POLAR_ZX, "POLAR_ZX", 0, "Polar ZX", "Polar 0 is X"}, {POLAR_ZY, "POLAR_ZY", 0, "Polar ZY", "Polar 0 is Y"}, {0, NULL, 0, NULL, NULL} @@ -987,11 +987,11 @@ static void uv_transform_properties(wmOperatorType *ot, int radius) static void correct_uv_aspect(BMEditMesh *em) { - BMFace *efa= BM_active_face_get(em->bm, TRUE); + BMFace *efa = BM_active_face_get(em->bm, TRUE); BMLoop *l; BMIter iter, liter; MLoopUV *luv; - float scale, aspx= 1.0f, aspy=1.0f; + float scale, aspx = 1.0f, aspy = 1.0f; if (efa) { MTexPoly *tf; @@ -1004,7 +1004,7 @@ static void correct_uv_aspect(BMEditMesh *em) return; if (aspx > aspy) { - scale= aspy/aspx; + scale = aspy / aspx; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (!BM_elem_flag_test(efa, BM_ELEM_SELECT) || BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) @@ -1012,20 +1012,20 @@ static void correct_uv_aspect(BMEditMesh *em) BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - luv->uv[0] = ((luv->uv[0]-0.5)*scale)+0.5; + luv->uv[0] = ((luv->uv[0] - 0.5) * scale) + 0.5; } } } else { - scale= aspx/aspy; + scale = aspx / aspy; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)||BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT) || BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) continue; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - luv->uv[1] = ((luv->uv[1]-0.5)*scale)+0.5; + luv->uv[1] = ((luv->uv[1] - 0.5) * scale) + 0.5; } } } @@ -1050,9 +1050,9 @@ static void uv_map_clip_correct(BMEditMesh *em, wmOperator *op) BMIter iter, liter; MLoopUV *luv; float dx, dy, min[2], max[2]; - int correct_aspect= RNA_boolean_get(op->ptr, "correct_aspect"); - int clip_to_bounds= RNA_boolean_get(op->ptr, "clip_to_bounds"); - int scale_to_bounds= RNA_boolean_get(op->ptr, "scale_to_bounds"); + int correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect"); + int clip_to_bounds = RNA_boolean_get(op->ptr, "clip_to_bounds"); + int scale_to_bounds = RNA_boolean_get(op->ptr, "scale_to_bounds"); /* correct for image aspect ratio */ if (correct_aspect) @@ -1072,13 +1072,13 @@ static void uv_map_clip_correct(BMEditMesh *em, wmOperator *op) } /* rescale UV to be in 1/1 */ - dx= (max[0]-min[0]); - dy= (max[1]-min[1]); + dx = (max[0] - min[0]); + dy = (max[1] - min[1]); if (dx > 0.0f) - dx= 1.0f/dx; + dx = 1.0f / dx; if (dy > 0.0f) - dy= 1.0f/dy; + dy = 1.0f / dy; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) @@ -1087,8 +1087,8 @@ static void uv_map_clip_correct(BMEditMesh *em, wmOperator *op) BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - luv->uv[0] = (luv->uv[0]-min[0])*dx; - luv->uv[1] = (luv->uv[1]-min[1])*dy; + luv->uv[0] = (luv->uv[0] - min[0]) * dx; + luv->uv[1] = (luv->uv[1] - min[1]) * dy; } } } @@ -1115,14 +1115,14 @@ void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel) BMEditMesh *em = BMEdit_FromObject(obedit); ParamHandle *handle; - const short fill_holes= scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES; - const short correct_aspect= !(scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT); + const short fill_holes = scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES; + const short correct_aspect = !(scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT); const short use_subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF; if (use_subsurf) handle = construct_param_handle_subsurfed(scene, em, fill_holes, sel, correct_aspect); else - handle= construct_param_handle(scene, em, 0, fill_holes, sel, correct_aspect); + handle = construct_param_handle(scene, em, 0, fill_holes, sel, correct_aspect); param_lscm_begin(handle, PARAM_FALSE, scene->toolsettings->unwrapper == 0); param_lscm_solve(handle); @@ -1146,7 +1146,7 @@ static int unwrap_exec(bContext *C, wmOperator *op) int use_subsurf = RNA_boolean_get(op->ptr, "use_subsurf_data"); int subsurf_level = RNA_int_get(op->ptr, "uv_subsurf_level"); float obsize[3], unitsize[3] = {1.0f, 1.0f, 1.0f}; - short implicit= 0; + short implicit = 0; if (!uvedit_have_selection(scene, em, implicit)) { return OPERATOR_CANCELLED; @@ -1166,20 +1166,20 @@ static int unwrap_exec(bContext *C, wmOperator *op) scene->toolsettings->uv_subsurf_level = subsurf_level; - if (fill_holes) scene->toolsettings->uvcalc_flag |= UVCALC_FILLHOLES; - else scene->toolsettings->uvcalc_flag &= ~UVCALC_FILLHOLES; + if (fill_holes) scene->toolsettings->uvcalc_flag |= UVCALC_FILLHOLES; + else scene->toolsettings->uvcalc_flag &= ~UVCALC_FILLHOLES; - if (correct_aspect) scene->toolsettings->uvcalc_flag &= ~UVCALC_NO_ASPECT_CORRECT; - else scene->toolsettings->uvcalc_flag |= UVCALC_NO_ASPECT_CORRECT; + if (correct_aspect) scene->toolsettings->uvcalc_flag &= ~UVCALC_NO_ASPECT_CORRECT; + else scene->toolsettings->uvcalc_flag |= UVCALC_NO_ASPECT_CORRECT; - if (use_subsurf) scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF; - else scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF; + if (use_subsurf) scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF; + else scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF; /* execute unwrap */ ED_unwrap_lscm(scene, obedit, TRUE); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -1195,7 +1195,7 @@ void UV_OT_unwrap(wmOperatorType *ot) ot->name = "Unwrap"; ot->description = "Unwrap the mesh of the object being edited"; ot->idname = "UV_OT_unwrap"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = unwrap_exec; @@ -1209,9 +1209,9 @@ void UV_OT_unwrap(wmOperatorType *ot) RNA_def_boolean(ot->srna, "correct_aspect", 1, "Correct Aspect", "Map UVs taking image aspect ratio into account"); RNA_def_boolean(ot->srna, "use_subsurf_data", 0, "Use Subsurf Data", - "Map UVs taking vertex position after subsurf into account"); + "Map UVs taking vertex position after subsurf into account"); RNA_def_int(ot->srna, "uv_subsurf_level", 1, 1, 6, "SubSurf Target", - "Number of times to subdivide before calculating UVs", 1, 6); + "Number of times to subdivide before calculating UVs", 1, 6); } /**************** Project From View operator **************/ @@ -1236,8 +1236,8 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) } /* establish the camera object, so we can default to view mapping if anything is wrong with it */ - if ((rv3d->persp==RV3D_CAMOB) && (v3d->camera) && (v3d->camera->type==OB_CAMERA)) { - camera= v3d->camera->data; + if ((rv3d->persp == RV3D_CAMOB) && (v3d->camera) && (v3d->camera->type == OB_CAMERA)) { + camera = v3d->camera->data; } if (RNA_boolean_get(op->ptr, "orthographic")) { @@ -1254,7 +1254,7 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) } } else if (camera) { - struct UvCameraInfo *uci= project_camera_info(v3d->camera, obedit->obmat, scene->r.xsch, scene->r.ysch); + struct UvCameraInfo *uci = project_camera_info(v3d->camera, obedit->obmat, scene->r.xsch, scene->r.ysch); if (uci) { BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { @@ -1287,14 +1287,14 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) uv_map_clip_correct(em, op); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } static int uv_from_view_poll(bContext *C) { - RegionView3D *rv3d= CTX_wm_region_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); if (!ED_operator_uvmap(C)) return 0; @@ -1307,7 +1307,7 @@ void UV_OT_from_view(wmOperatorType *ot) /* identifiers */ ot->name = "Project From View"; ot->idname = "UV_OT_project_from_view"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = uv_from_view_exec; @@ -1322,9 +1322,9 @@ void UV_OT_from_view(wmOperatorType *ot) static int reset_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - Mesh *me = (Mesh*)obedit->data; + Scene *scene = CTX_data_scene(C); + Object *obedit = CTX_data_edit_object(C); + Mesh *me = (Mesh *)obedit->data; /* add uvs if they don't exist yet */ if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { @@ -1336,7 +1336,7 @@ static int reset_exec(bContext *C, wmOperator *UNUSED(op)) } DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -1346,7 +1346,7 @@ void UV_OT_reset(wmOperatorType *ot) /* identifiers */ ot->name = "Reset"; ot->idname = "UV_OT_reset"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = reset_exec; @@ -1362,7 +1362,7 @@ static void uv_sphere_project(float target[2], float source[3], float center[3], sub_v3_v3v3(pv, source, center); mul_m4_v3(rotmat, pv); - map_to_sphere( &target[0], &target[1],pv[0], pv[1], pv[2]); + map_to_sphere(&target[0], &target[1], pv[0], pv[1], pv[2]); /* split line is always zero */ if (target[0] >= 1.0f) @@ -1387,11 +1387,11 @@ static void uv_map_mirror(BMEditMesh *em, BMFace *efa, MTexPoly *UNUSED(tf)) } mi = 0; - for (i=1; i<efa->len; i++) + for (i = 1; i < efa->len; i++) if (uvs[i][0] > uvs[mi][0]) mi = i; - for (i=0; i<efa->len; i++) { + for (i = 0; i < efa->len; i++) { if (i != mi) { dx = uvs[mi][0] - uvs[i][0]; if (dx > 0.5f) uvs[i][0] += 1.0f; @@ -1437,7 +1437,7 @@ static int sphere_project_exec(bContext *C, wmOperator *op) uv_map_clip_correct(em, op); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -1447,7 +1447,7 @@ void UV_OT_sphere_project(wmOperatorType *ot) /* identifiers */ ot->name = "Sphere Projection"; ot->idname = "UV_OT_sphere_project"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = sphere_project_exec; @@ -1467,7 +1467,7 @@ static void uv_cylinder_project(float target[2], float source[3], float center[3 sub_v3_v3v3(pv, source, center); mul_m4_v3(rotmat, pv); - map_to_tube( &target[0], &target[1],pv[0], pv[1], pv[2]); + map_to_tube(&target[0], &target[1], pv[0], pv[1], pv[2]); /* split line is always zero */ if (target[0] >= 1.0f) @@ -1510,7 +1510,7 @@ static int cylinder_project_exec(bContext *C, wmOperator *op) uv_map_clip_correct(em, op); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -1520,7 +1520,7 @@ void UV_OT_cylinder_project(wmOperatorType *ot) /* identifiers */ ot->name = "Cylinder Projection"; ot->idname = "UV_OT_cylinder_project"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = cylinder_project_exec; @@ -1551,14 +1551,14 @@ static int cube_project_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - loc= obedit->obmat[3]; - cube_size= RNA_float_get(op->ptr, "cube_size"); + loc = obedit->obmat[3]; + cube_size = RNA_float_get(op->ptr, "cube_size"); /* choose x,y,z axis for projection depending on the largest normal - * component, but clusters all together around the center of map. */ + * component, but clusters all together around the center of map. */ BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - int first=1; + int first = 1; /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) @@ -1570,8 +1570,8 @@ static int cube_project_exec(bContext *C, wmOperator *op) BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - luv->uv[0] = 0.5f+0.5f*cube_size*(loc[cox] + l->v->co[cox]); - luv->uv[1] = 0.5f+0.5f*cube_size*(loc[coy] + l->v->co[coy]); + luv->uv[0] = 0.5f + 0.5f * cube_size * (loc[cox] + l->v->co[cox]); + luv->uv[1] = 0.5f + 0.5f * cube_size * (loc[coy] + l->v->co[coy]); if (first) { dx = floor(luv->uv[0]); @@ -1588,7 +1588,7 @@ static int cube_project_exec(bContext *C, wmOperator *op) uv_map_clip_correct(em, op); DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -1598,7 +1598,7 @@ void UV_OT_cube_project(wmOperatorType *ot) /* identifiers */ ot->name = "Cube Projection"; ot->idname = "UV_OT_cube_project"; - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->exec = cube_project_exec; |