diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-02-13 14:38:05 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-02-13 14:38:05 +0400 |
commit | 35629a623ba1fb13db96209a206cc4aedbc9cf9e (patch) | |
tree | 06cb32529c54f592d274a63d0961ba88785aa7bb /source/blender/editors/uvedit/uvedit_parametrizer.c | |
parent | 3502fdea4a943ef63686ff440e9ccd7dc6132236 (diff) |
Fix #34216: uv unwrap with some faces pinned to point the normals down will now
automatically flip the unpinned faces to point down too, instead of trying to
unwrap them in the other direction and giving bad results.
If there's a mix of faces pinned up and down it will pick the direction with the
biggest area.
Diffstat (limited to 'source/blender/editors/uvedit/uvedit_parametrizer.c')
-rw-r--r-- | source/blender/editors/uvedit/uvedit_parametrizer.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 7e3302e233e..8911e227373 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -60,6 +60,7 @@ { /*printf("Assertion %s:%d\n", __FILE__, __LINE__); abort();*/ } (void)0 #define param_warning(message) \ { /*printf("Warning %s:%d: %s\n", __FILE__, __LINE__, message);*/ } (void)0 +#if 0 #define param_test_equals_ptr(str, a, b) \ if (a != b) \ { /*printf("Equals %s => %p != %p\n", str, a, b);*/ } (void)0 @@ -67,6 +68,7 @@ if (a != b) \ { /*printf("Equals %s => %d != %d\n", str, a, b);*/ } (void)0 #endif +#endif typedef enum PBool { P_TRUE = 1, P_FALSE = 0 @@ -3047,6 +3049,8 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) PVert *v, *pin1 = chart->u.lscm.pin1, *pin2 = chart->u.lscm.pin2; PFace *f; float *alpha = chart->u.lscm.abf_alpha; + float area_pinned_up, area_pinned_down; + bool flip_faces; int row; nlMakeCurrent(chart->u.lscm.context); @@ -3085,6 +3089,26 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) } } + /* detect up direction based on pinned vertices */ + area_pinned_up = 0.0f; + area_pinned_down = 0.0f; + + 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; + + if ((v1->flag & PVERT_PIN) && (v2->flag & PVERT_PIN) && (v3->flag & PVERT_PIN)) { + float area = p_face_uv_area_signed(f); + + if(area > 0.0f) + area_pinned_up += area; + else + area_pinned_down -= area; + } + } + + flip_faces = (area_pinned_down > area_pinned_up); + /* construct matrix */ nlBegin(NL_MATRIX); @@ -3105,6 +3129,12 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) else p_face_angles(f, &a1, &a2, &a3); + if (flip_faces) { + SWAP(float, a2, a3); + SWAP(PEdge*, e2, e3); + SWAP(PVert*, v2, v3); + } + sina1 = sin(a1); sina2 = sin(a2); sina3 = sin(a3); |