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.
This commit is contained in:
2005-12-01 12:45:17 +00:00
parent 1a59b16b48
commit a09fbc080d
4 changed files with 80 additions and 6 deletions

View File

@@ -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);
if (phandle->blend == 0.0f)
p_flush_uvs(chart);
else
p_flush_uvs_blend(chart, phandle->blend);
}
}

View File

@@ -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);

View File

@@ -180,6 +180,7 @@ typedef struct PHandle {
MemArena *arena;
PBool implicit;
RNG *rng;
float blend;
} PHandle;
#endif /*__PARAMETRIZER_INTERN_H__*/

View File

@@ -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))
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);