[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14019] trunk/blender/source/blender: Added UV Stretch (area/angle) display options
Campbell Barton
ideasman42 at gmail.com
Sun Mar 9 04:42:59 CET 2008
Revision: 14019
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14019
Author: campbellbarton
Date: 2008-03-09 04:42:59 +0100 (Sun, 09 Mar 2008)
Log Message:
-----------
Added UV Stretch (area/angle) display options
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_arithb.h
trunk/blender/source/blender/blenlib/intern/arithb.c
trunk/blender/source/blender/makesdna/DNA_space_types.h
trunk/blender/source/blender/src/drawimage.c
Modified: trunk/blender/source/blender/blenlib/BLI_arithb.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_arithb.h 2008-03-09 03:41:13 UTC (rev 14018)
+++ trunk/blender/source/blender/blenlib/BLI_arithb.h 2008-03-09 03:42:59 UTC (rev 14019)
@@ -267,6 +267,9 @@
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);
Modified: trunk/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/arithb.c 2008-03-09 03:41:13 UTC (rev 14018)
+++ trunk/blender/source/blender/blenlib/intern/arithb.c 2008-03-09 03:42:59 UTC (rev 14019)
@@ -2868,6 +2868,22 @@
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 @@
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];
Modified: trunk/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_space_types.h 2008-03-09 03:41:13 UTC (rev 14018)
+++ trunk/blender/source/blender/makesdna/DNA_space_types.h 2008-03-09 03:42:59 UTC (rev 14019)
@@ -239,8 +239,9 @@
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 @@
#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 @@
/* 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) */
Modified: trunk/blender/source/blender/src/drawimage.c
===================================================================
--- trunk/blender/source/blender/src/drawimage.c 2008-03-09 03:41:13 UTC (rev 14018)
+++ trunk/blender/source/blender/src/drawimage.c 2008-03-09 03:42:59 UTC (rev 14019)
@@ -502,6 +502,14 @@
}
}
+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,23 +578,151 @@
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];
+
+ 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;
+ }
+ }
+
+ 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>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;
+ }
+ }
+
+
+ /* draw stretch angles */
+
+
+ } 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);
glEnable(GL_BLEND);
for (efa= em->faces.first; efa; efa= efa->next) {
+ int lastsel=-1;
tface= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
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 +1402,22 @@
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);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list