Added UV Stretch (area/angle) display options

This commit is contained in:
Campbell Barton
2008-03-09 03:42:59 +00:00
parent ac750cf7a2
commit 6382acbc27
4 changed files with 208 additions and 13 deletions

View File

@@ -267,6 +267,9 @@ float VecAngle2(float *v1, float *v2);
float VecAngle3(float *v1, float *v2, float *v3);
float NormalizedVecAngle2(float *v1, float *v2);
float VecAngle3_2D(float *v1, float *v2, float *v3);
float NormalizedVecAngle2_2D(float *v1, float *v2);
void euler_rot(float *beul, float ang, char axis);

View File

@@ -2868,6 +2868,22 @@ float VecAngle3(float *v1, float *v2, float *v3)
return NormalizedVecAngle2(vec1, vec2) * 180.0/M_PI;
}
float VecAngle3_2D(float *v1, float *v2, float *v3)
{
float vec1[2], vec2[2];
vec1[0] = v2[0]-v1[0];
vec1[1] = v2[1]-v1[1];
vec2[0] = v2[0]-v3[0];
vec2[1] = v2[1]-v3[1];
Normalize2(vec1);
Normalize2(vec2);
return NormalizedVecAngle2_2D(vec1, vec2) * 180.0/M_PI;
}
/* Return the shortest angle in degrees between the 2 vectors */
float VecAngle2(float *v1, float *v2)
{
@@ -2897,6 +2913,21 @@ float NormalizedVecAngle2(float *v1, float *v2)
return 2.0f*saasin(VecLenf(v2, v1)/2.0);
}
float NormalizedVecAngle2_2D(float *v1, float *v2)
{
/* this is the same as acos(Inpf(v1, v2)), but more accurate */
if (Inp2f(v1, v2) < 0.0f) {
float vec[2];
vec[0]= -v2[0];
vec[1]= -v2[1];
return (float)M_PI - 2.0f*saasin(Vec2Lenf(vec, v1)/2.0f);
}
else
return 2.0f*saasin(Vec2Lenf(v2, v1)/2.0);
}
void euler_rot(float *beul, float ang, char axis)
{
float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];

View File

@@ -239,8 +239,9 @@ typedef struct SpaceImage {
short pin, pad2;
float zoom;
char dt_uv; /* UV draw type */
char sticky; /* sticky selection type */
char pad[6];
char sticky; /* sticky selection type */
char dt_uvstretch;
char pad[5];
float xof, yof; /* user defined offset, image is centered */
float centx, centy; /* storage for offset while render drawing */
@@ -487,6 +488,10 @@ typedef struct SpaceImaSel {
#define SI_UVDT_WHITE 2
#define SI_UVDT_OUTLINE 3
/* SpaceImage->dt_uvstretch */
#define SI_UVDT_STRETCH_ANGLE 0
#define SI_UVDT_STRETCH_AREA 1
/* SpaceImage->sticky
* Note DISABLE should be 0, however would also need to re-arrange icon order,
* also, sticky loc is the default mode so this means we dont need to 'do_versons' */
@@ -518,7 +523,8 @@ typedef struct SpaceImaSel {
/* this means that the image is drawn until it reaches the view edge,
* in the image view, its unrelated to the 'tile' mode for texface */
#define SI_DRAW_TILE 1<<19
#define SI_SMOOTH_UV 1<<20
#define SI_SMOOTH_UV 1<<20
#define SI_DRAW_STRETCH 1<<21
/* SpaceText flags (moved from DNA_text_types.h) */

View File

@@ -502,6 +502,14 @@ void tface_center(MTFace *tf, float cent[2], void * isquad)
}
}
float tface_area(MTFace *tf, int quad)
{
if (quad) {
return AreaF2Dfl(tf->uv[0], tf->uv[1], tf->uv[2]) + AreaF2Dfl(tf->uv[0], tf->uv[2], tf->uv[3]);
} else {
return AreaF2Dfl(tf->uv[0], tf->uv[1], tf->uv[2]);
}
}
/* draws uv's in the image space */
void draw_uvs_sima(void)
{
@@ -570,8 +578,146 @@ void draw_uvs_sima(void)
activetface = get_active_mtface(&efa_act, NULL, 0); /* will be set to NULL if hidden */
/* draw transparent faces */
if(G.f & G_DRAWFACES) {
if (G.sima->flag & SI_DRAW_STRETCH) {
switch (G.sima->dt_uvstretch) {
case SI_UVDT_STRETCH_AREA:
{
float totarea, totuvarea, areadiff, uvarea, area, col[3];
int uvarea_error = 0;
for (efa= em->faces.first; efa; efa= efa->next) {
tface= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
totarea += EM_face_area(efa);
totuvarea += tface_area(tface, efa->v4!=0);
if (simaFaceDraw_Check(efa, tface)) {
efa->tmp.p = tface;
} else {
if (tface == activetface)
activetface= NULL;
efa->tmp.p = NULL;
}
}
if (totarea==0.0 || totarea==0.0) {
col[0] - 1.0;
col[1] = col[2] = 0.0;
glColor3fv(col);
for (efa= em->faces.first; efa; efa= efa->next) {
glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
glVertex2fv(tface->uv[0]);
glVertex2fv(tface->uv[1]);
glVertex2fv(tface->uv[2]);
if(efa->v4) glVertex2fv(tface->uv[3]);
glEnd();
}
}
for (efa= em->faces.first; efa; efa= efa->next) {
if ((tface=(MTFace *)efa->tmp.p)) {
area = EM_face_area(efa) / totarea;
uvarea = tface_area(tface, efa->v4!=0) / totuvarea;
if (area==0.0 || uvarea==0.0) {
areadiff = 1.0;
} else if (area>uvarea) {
areadiff = 1.0-(uvarea/area);
} else {
areadiff = 1.0-(area/uvarea);
}
weight_to_rgb(areadiff, col, col+1, col+2);
glColor3fv(col);
glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
glVertex2fv(tface->uv[0]);
glVertex2fv(tface->uv[1]);
glVertex2fv(tface->uv[2]);
if(efa->v4) glVertex2fv(tface->uv[3]);
glEnd();
}
}
break;
}
case SI_UVDT_STRETCH_ANGLE:
{
float uvang1,uvang2,uvang3,uvang4;
float ang1,ang2,ang3,ang4;
float col[3];
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
for (efa= em->faces.first; efa; efa= efa->next) {
tface= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (simaFaceDraw_Check(efa, tface)) {
efa->tmp.p = tface;
if (efa->v4) {
uvang1 = VecAngle3_2D(tface->uv[3], tface->uv[0], tface->uv[1]);
ang1 = VecAngle3(efa->v4->co, efa->v1->co, efa->v2->co);
uvang2 = VecAngle3_2D(tface->uv[0], tface->uv[1], tface->uv[2]);
ang2 = VecAngle3(efa->v1->co, efa->v2->co, efa->v3->co);
uvang3 = VecAngle3_2D(tface->uv[1], tface->uv[2], tface->uv[3]);
ang3 = VecAngle3(efa->v2->co, efa->v3->co, efa->v4->co);
uvang4 = VecAngle3_2D(tface->uv[2], tface->uv[3], tface->uv[0]);
ang4 = VecAngle3(efa->v3->co, efa->v4->co, efa->v1->co);
glBegin(GL_QUADS);
weight_to_rgb(fabs(uvang1-ang1)/180.0, col, col+1, col+2);
glColor3fv(col);
glVertex2fv(tface->uv[0]);
weight_to_rgb(fabs(uvang2-ang2)/180.0, col, col+1, col+2);
glColor3fv(col);
glVertex2fv(tface->uv[1]);
weight_to_rgb(fabs(uvang3-ang3)/180.0, col, col+1, col+2);
glColor3fv(col);
glVertex2fv(tface->uv[2]);
weight_to_rgb(fabs(uvang4-ang4)/180.0, col, col+1, col+2);
glColor3fv(col);
glVertex2fv(tface->uv[3]);
} else {
uvang1 = VecAngle3_2D(tface->uv[2], tface->uv[0], tface->uv[1]);
ang1 = VecAngle3(efa->v3->co, efa->v1->co, efa->v2->co);
uvang2 = VecAngle3_2D(tface->uv[0], tface->uv[1], tface->uv[2]);
ang2 = VecAngle3(efa->v1->co, efa->v2->co, efa->v3->co);
uvang3 = 180-(uvang1+uvang2);
ang3 = 180-(ang1+ang2);
glBegin(GL_TRIANGLES);
weight_to_rgb(fabs(uvang1-ang1)/180.0, col, col+1, col+2);
glColor3fv(col);
glVertex2fv(tface->uv[0]);
weight_to_rgb(fabs(uvang2-ang2)/180.0, col, col+1, col+2);
glColor3fv(col);
glVertex2fv(tface->uv[1]);
weight_to_rgb(fabs(uvang3-ang3)/180.0, col, col+1, col+2);
glColor3fv(col);
glVertex2fv(tface->uv[2]);
}
glEnd();
} else {
if (tface == activetface)
activetface= NULL;
efa->tmp.p = NULL;
}
}
glDisable(GL_SMOOTH);
glDisable(GL_BLEND);
break;
}
}
} else if(G.f & G_DRAWFACES) {
/* draw transparent faces */
BIF_GetThemeColor4ubv(TH_FACE, col1);
BIF_GetThemeColor4ubv(TH_FACE_SELECT, col2);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -583,10 +729,11 @@ void draw_uvs_sima(void)
if (simaFaceDraw_Check(efa, tface)) {
efa->tmp.p = tface;
if (tface==activetface) continue; /* important the temp pointer is set above */
if( simaFaceSel_Check(efa, tface) )
if( simaFaceSel_Check(efa, tface)) {
glColor4ubv((GLubyte *)col2);
else
} else {
glColor4ubv((GLubyte *)col1);
}
glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
glVertex2fv(tface->uv[0]);
@@ -1266,14 +1413,22 @@ static void image_panel_view_properties(short cntrl) // IMAGE_HANDLER_VIEW_PROPE
if (EM_texFaceCheck()) {
uiDefBut(block, LABEL, B_NOP, "Draw Type:", 10, 20,120,19, 0, 0, 0, 0, 0, "");
uiDefBut(block, LABEL, B_NOP, "Draw Type:", 10, 60,120,19, 0, 0, 0, 0, 0, "");
uiBlockBeginAlign(block);
uiDefButC(block, ROW, B_REDR, "Dash", 10, 0,58,19, &G.sima->dt_uv, 0.0, SI_UVDT_DASH, 0, 0, "Dashed Wire UV drawtype");
uiDefButC(block, ROW, B_REDR, "Black", 68, 0,58,19, &G.sima->dt_uv, 0.0, SI_UVDT_BLACK, 0, 0, "Black Wire UV drawtype");
uiDefButC(block, ROW, B_REDR, "White", 126,0,58,19, &G.sima->dt_uv, 0.0, SI_UVDT_WHITE, 0, 0, "White Wire UV drawtype");
uiDefButC(block, ROW, B_REDR, "Outline", 184,0,58,19, &G.sima->dt_uv, 0.0, SI_UVDT_OUTLINE, 0, 0, "Outline Wire UV drawtype");
uiDefButC(block, ROW, B_REDR, "Dash", 10, 40,58,19, &G.sima->dt_uv, 0.0, SI_UVDT_DASH, 0, 0, "Dashed Wire UV drawtype");
uiDefButC(block, ROW, B_REDR, "Black", 68, 40,58,19, &G.sima->dt_uv, 0.0, SI_UVDT_BLACK, 0, 0, "Black Wire UV drawtype");
uiDefButC(block, ROW, B_REDR, "White", 126,40,58,19, &G.sima->dt_uv, 0.0, SI_UVDT_WHITE, 0, 0, "White Wire UV drawtype");
uiDefButC(block, ROW, B_REDR, "Outline", 184,40,58,19, &G.sima->dt_uv, 0.0, SI_UVDT_OUTLINE, 0, 0, "Outline Wire UV drawtype");
uiBlockEndAlign(block);
uiDefButBitI(block, TOG, SI_SMOOTH_UV, B_REDR, "Smooth", 250,40,60,19, &G.sima->flag, 0, 0, 0, 0, "Display smooth lines in the UV view");
uiDefButBitI(block, TOG, SI_DRAW_STRETCH, B_REDR, "UV Stretch", 10,0,100,19, &G.sima->flag, 0, 0, 0, 0, "Display distortion between the UV's and the 3D coords");
uiBlockBeginAlign(block);
uiDefButBitI(block, TOG, SI_SMOOTH_UV, B_REDR, "Smooth", 250,0,60,19, &G.sima->flag, 0, 0, 0, 0, "Display smooth lines in the UV view");
uiDefButC(block, ROW, B_REDR, "Area", 126,0,58,19, &G.sima->dt_uvstretch, 0.0, SI_UVDT_STRETCH_AREA, 0, 0, "Draw the area distortion");
uiDefButC(block, ROW, B_REDR, "Angle", 184,0,58,19, &G.sima->dt_uvstretch, 0.0, SI_UVDT_STRETCH_ANGLE, 0, 0, "Draw the angle distortion");
uiBlockEndAlign(block);
}
image_editcursor_buts(block);
}