Bugfix: unwrap pinning did not work correct with aspect ratio option.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 8 May 2008 20:38:38 +0000 (20:38 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 8 May 2008 20:38:38 +0000 (20:38 +0000)
source/blender/src/parametrizer.c
source/blender/src/parametrizer.h
source/blender/src/parametrizer_intern.h
source/blender/src/unwrapper.c

index a643f37ec2a32a8dcc298aa11007ac6a857d7296..096629b01ec4fb7ea195b795d9525efff63cf999 100644 (file)
@@ -389,7 +389,7 @@ static void p_chart_topological_sanity_check(PChart *chart)
 
 /* Loading / Flushing */
 
-static void p_vert_load_pin_select_uvs(PVert *v)
+static void p_vert_load_pin_select_uvs(PHandle *handle, PVert *v)
 {
        PEdge *e;
        int nedges = 0, npins = 0;
@@ -404,13 +404,13 @@ static void p_vert_load_pin_select_uvs(PVert *v)
                                v->flag |= PVERT_SELECT;
 
                        if (e->flag & PEDGE_PIN) {
-                               pinuv[0] += e->orig_uv[0];
-                               pinuv[1] += e->orig_uv[1];
+                               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];
-                               v->uv[1] += e->orig_uv[1];
+                               v->uv[0] += e->orig_uv[0]*handle->aspx;
+                               v->uv[1] += e->orig_uv[1]*handle->aspy;
                        }
 
                        nedges++;
@@ -430,27 +430,27 @@ static void p_vert_load_pin_select_uvs(PVert *v)
        }
 }
 
-static void p_flush_uvs(PChart *chart)
+static void p_flush_uvs(PHandle *handle, PChart *chart)
 {
        PEdge *e;
 
        for (e=chart->edges; e; e=e->nextlink) {
                if (e->orig_uv) {
-                       e->orig_uv[0] = e->vert->uv[0];
-                       e->orig_uv[1] = e->vert->uv[1];
+                       e->orig_uv[0] = e->vert->uv[0]/handle->aspx;
+                       e->orig_uv[1] = e->vert->uv[1]/handle->aspy;
                }
        }
 }
 
-static void p_flush_uvs_blend(PChart *chart, float blend)
+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) {
                if (e->orig_uv) {
-                       e->orig_uv[0] = blend*e->old_uv[0] + invblend*e->vert->uv[0];
-                       e->orig_uv[1] = blend*e->old_uv[1] + invblend*e->vert->uv[1];
+                       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;
                }
        }
 }
@@ -2813,7 +2813,7 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf)
        }
 }
 
-static PBool p_chart_lscm_solve(PChart *chart)
+static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart)
 {
        PVert *v, *pin1 = chart->u.lscm.pin1, *pin2 = chart->u.lscm.pin2;
        PFace *f;
@@ -2830,7 +2830,7 @@ static PBool p_chart_lscm_solve(PChart *chart)
 
        for (v=chart->verts; v; v=v->nextlink)
                if (v->flag & PVERT_PIN)
-                       p_vert_load_pin_select_uvs(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);
@@ -3860,6 +3860,8 @@ ParamHandle *param_construct_begin()
        handle->construction_chart = p_chart_new(handle);
        handle->state = PHANDLE_STATE_ALLOCATED;
        handle->arena = BLI_memarena_new((1<<16));
+       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);
@@ -3868,6 +3870,14 @@ ParamHandle *param_construct_begin()
        return (ParamHandle*)handle;
 }
 
+void param_aspect_ratio(ParamHandle *handle, float aspx, float aspy)
+{
+       PHandle *phandle = (PHandle*)handle;
+
+       phandle->aspx = aspx;
+       phandle->aspy = aspy;
+}
+
 void param_delete(ParamHandle *handle)
 {
        PHandle *phandle = (PHandle*)handle;
@@ -3968,7 +3978,7 @@ void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl)
                        p_chart_fill_boundaries(chart, outer);
 
                for (v=chart->verts; v; v=v->nextlink)
-                       p_vert_load_pin_select_uvs(v);
+                       p_vert_load_pin_select_uvs(handle, v);
        }
 
        phandle->ncharts = j;
@@ -4005,7 +4015,7 @@ void param_lscm_solve(ParamHandle *handle)
                chart = phandle->charts[i];
 
                if (chart->u.lscm.context) {
-                       result = p_chart_lscm_solve(chart);
+                       result = p_chart_lscm_solve(phandle, chart);
 
                        if (result && !(chart->flag & PCHART_NOPACK))
                                p_chart_rotate_minimum_area(chart);
@@ -4128,6 +4138,9 @@ void param_pack(ParamHandle *handle)
        if (phandle->ncharts == 0)
                return;
        
+       if(phandle->aspx != 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");
        
@@ -4170,8 +4183,10 @@ void param_pack(ParamHandle *handle)
                p_chart_uv_scale(chart, scale);
        }
        MEM_freeN(boxarray);
-}
 
+       if(phandle->aspx != phandle->aspy)
+               param_scale(handle, phandle->aspx, phandle->aspy);
+}
 
 void param_average(ParamHandle *handle)
 {
@@ -4255,9 +4270,9 @@ void param_flush(ParamHandle *handle)
                        continue;
 
                if (phandle->blend == 0.0f)
-                       p_flush_uvs(chart);
+                       p_flush_uvs(phandle, chart);
                else
-                       p_flush_uvs_blend(chart, phandle->blend);
+                       p_flush_uvs_blend(phandle, chart, phandle->blend);
        }
 }
 
index 766d461416dee06c3e9f541c6b38a498a6f5eb33..80fab110d5fd1747270949deffc5a9cc02e8f789 100644 (file)
@@ -26,6 +26,8 @@ typedef enum ParamBool {
 
 ParamHandle *param_construct_begin();
 
+void param_aspect_ratio(ParamHandle *handle, float aspx, float aspy);
+
 void param_face_add(ParamHandle *handle,
                     ParamKey key,
                     int nverts,        
index 6114ecc8696b360fe4bdbe71ab15c769fd2619fc..f7a32816b332125fec84471aad34399441eab20f 100644 (file)
@@ -184,6 +184,8 @@ typedef struct PHandle {
        PChart **charts;
        int ncharts;
 
+       float aspx, aspy;
+
        RNG *rng;
        float blend;
 } PHandle;
index fafae7458f17d9d8b004f042c1ca83c9678a1ce2..ee5ce0c914e49c20f327be12538b951fc15377d9 100644 (file)
@@ -200,6 +200,19 @@ ParamHandle *construct_param_handle(EditMesh *em, short implicit, short fill, sh
        ParamHandle *handle;
        
        handle = param_construct_begin();
+
+       if ((G.scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT)==0) {
+               EditMesh *em = G.editMesh;
+               EditFace *efa = EM_get_actFace(1);
+               if (efa) {
+                       float aspx, aspy;
+                       MTFace *tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+                       image_final_aspect(tface->tpage, &aspx, &aspy);
+               
+                       if (aspx!=aspy)
+                               param_aspect_ratio(handle, aspx, aspy);
+               }
+       }
        
        /* we need the vert indicies */
        for (ev= em->verts.first, a=0; ev; ev= ev->next, a++)
@@ -314,21 +327,6 @@ void unwrap_lscm(short seamcut)
        param_lscm_begin(handle, PARAM_FALSE, abf);
        param_lscm_solve(handle);
        param_lscm_end(handle);
-
-       
-       /* scale before packing */
-       if ((G.scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT)==0) {
-               EditFace *efa = EM_get_actFace(1);
-               if (efa) {
-                       float aspx, aspy;
-                       MTFace *tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-                       image_final_aspect(tface->tpage, &aspx, &aspy);
-               
-                       if (aspx!=aspy) {
-                               param_scale(handle, 1.0, aspx/aspy);
-                       }
-               }
-       }
        
        param_pack(handle);