diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2005-12-01 15:45:17 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2005-12-01 15:45:17 +0300 |
commit | a09fbc080dea64078a6cfb307a720194ee30e6db (patch) | |
tree | d1b3d61b00d95522d4496b3b029f6a2da9cc7743 | |
parent | 1a59b16b4831987a12906a1821755c4b249287bb (diff) |
Small addition to stretch minimize: with pad +/- or the wheel mouse
you can now blend between the original and minimized.
Stretch minimizing trades conformality (= perfect squares in checkerboard
texture) for a better sampling of the texture (= often not so well shaped
checkerboard), so it is useful to let the user find a balance between the
two.
-rw-r--r-- | source/blender/src/parametrizer.c | 42 | ||||
-rw-r--r-- | source/blender/src/parametrizer.h | 1 | ||||
-rw-r--r-- | source/blender/src/parametrizer_intern.h | 1 | ||||
-rw-r--r-- | source/blender/src/unwrapper.c | 42 |
4 files changed, 80 insertions, 6 deletions
diff --git a/source/blender/src/parametrizer.c b/source/blender/src/parametrizer.c index ff5d92e4604..32e8f6ac187 100644 --- a/source/blender/src/parametrizer.c +++ b/source/blender/src/parametrizer.c @@ -1135,6 +1135,19 @@ static void p_flush_uvs(PChart *chart) } } +static void p_flush_uvs_blend(PChart *chart, float blend) +{ + PEdge *e; + float invblend = 1.0f - blend; + + for (e=(PEdge*)chart->edges->first; e; e=e->link.next) { + 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]; + } + } +} + /* Exported */ ParamHandle *param_construct_begin() @@ -1620,6 +1633,7 @@ void param_stretch_begin(ParamHandle *handle) phandle->state = PHANDLE_STATE_STRETCH; phandle->rng = rng_new(31415926); + phandle->blend = 0.0f; for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; @@ -1636,6 +1650,28 @@ void param_stretch_begin(ParamHandle *handle) } } +void param_stretch_blend(ParamHandle *handle, float blend) +{ + PHandle *phandle = (PHandle*)handle; + PChart *chart; + int i; + + param_assert(phandle->state == PHANDLE_STATE_STRETCH); + + if (phandle->blend != blend) { + phandle->blend = blend; + + for (i = 0; i < phandle->ncharts; i++) { + chart = phandle->charts[i]; + + if (blend == 0.0f) + p_flush_uvs(chart); + else + p_flush_uvs_blend(chart, blend); + } + } +} + void param_stretch_iter(ParamHandle *handle) { PHandle *phandle = (PHandle*)handle; @@ -1648,7 +1684,11 @@ void param_stretch_iter(ParamHandle *handle) chart = phandle->charts[i]; p_chart_stretch_minimize(chart, phandle->rng); - p_flush_uvs(chart); + + if (phandle->blend == 0.0f) + p_flush_uvs(chart); + else + p_flush_uvs_blend(chart, phandle->blend); } } diff --git a/source/blender/src/parametrizer.h b/source/blender/src/parametrizer.h index a3904af83b9..614eef2fbf7 100644 --- a/source/blender/src/parametrizer.h +++ b/source/blender/src/parametrizer.h @@ -59,6 +59,7 @@ void param_lscm_end(ParamHandle *handle); /* Stretch */ void param_stretch_begin(ParamHandle *handle); +void param_stretch_blend(ParamHandle *handle, float blend); void param_stretch_iter(ParamHandle *handle); void param_stretch_end(ParamHandle *handle, ParamBool restore); diff --git a/source/blender/src/parametrizer_intern.h b/source/blender/src/parametrizer_intern.h index 4086372e2d5..d873c1dab47 100644 --- a/source/blender/src/parametrizer_intern.h +++ b/source/blender/src/parametrizer_intern.h @@ -180,6 +180,7 @@ typedef struct PHandle { MemArena *arena; PBool implicit; RNG *rng; + float blend; } PHandle; #endif /*__PARAMETRIZER_INTERN_H__*/ diff --git a/source/blender/src/unwrapper.c b/source/blender/src/unwrapper.c index 7b61e8f51f0..b74181cb385 100644 --- a/source/blender/src/unwrapper.c +++ b/source/blender/src/unwrapper.c @@ -1457,7 +1457,7 @@ void minimize_stretch_tface_uv(void) Mesh *me; ParamHandle *handle; double lasttime; - short doit = 1, val; + short doit = 1, escape = 0, val, blend = 0; unsigned short event = 0; me = get_mesh(OBACT); @@ -1474,15 +1474,47 @@ void minimize_stretch_tface_uv(void) while (qtest()) { event= extern_qread(&val); - if (val && (event==ESCKEY || event==RETKEY || event==PADENTER)) - doit = 0; + + if (val) { + switch (event) { + case ESCKEY: + escape = 1; + case RETKEY: + case PADENTER: + doit = 0; + break; + case PADPLUSKEY: + case WHEELUPMOUSE: + if (blend < 10) { + blend++; + param_stretch_blend(handle, blend*0.1f); + lasttime = 0.0f; + } + break; + case PADMINUS: + case WHEELDOWNMOUSE: + if (blend > 0) { + blend--; + param_stretch_blend(handle, blend*0.1f); + lasttime = 0.0f; + } + break; + } + } + else if ((event == LEFTMOUSE) || (event == RIGHTMOUSE)) { + escape = (event == RIGHTMOUSE); + doit = 0; + } } if (!doit) break; if (PIL_check_seconds_timer() - lasttime > 0.5) { - headerprint("Enter to finish. Escape to cancel."); + char str[100]; + + sprintf(str, "Stretch minimize. Blend %.2f.", blend*0.1f); + headerprint(str); lasttime = PIL_check_seconds_timer(); if(G.sima->lock) force_draw_plus(SPACE_VIEW3D, 0); @@ -1490,7 +1522,7 @@ void minimize_stretch_tface_uv(void) } } - param_stretch_end(handle, event==ESCKEY); + param_stretch_end(handle, escape); param_delete(handle); |