|
Blender
V2.59
|
00001 /* 00002 * $Id: uvedit_draw.c 37891 2011-06-28 09:42:17Z campbellbarton $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * Contributor(s): Blender Foundation, 2002-2009 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include <float.h> 00034 #include <math.h> 00035 #include <stdlib.h> 00036 00037 #include "DNA_meshdata_types.h" 00038 #include "DNA_object_types.h" 00039 #include "DNA_scene_types.h" 00040 #include "DNA_screen_types.h" 00041 #include "DNA_space_types.h" 00042 00043 #include "BLI_math.h" 00044 #include "BLI_editVert.h" 00045 #include "BLI_utildefines.h" 00046 00047 #include "BKE_DerivedMesh.h" 00048 #include "BKE_mesh.h" 00049 00050 00051 #include "BIF_gl.h" 00052 #include "BIF_glutil.h" 00053 00054 #include "ED_util.h" 00055 #include "ED_image.h" 00056 #include "ED_mesh.h" 00057 #include "ED_uvedit.h" 00058 00059 #include "UI_resources.h" 00060 00061 #include "uvedit_intern.h" 00062 00063 static void drawcursor_sima(SpaceImage *sima, ARegion *ar) 00064 { 00065 float zoomx, zoomy, w, h; 00066 int width, height; 00067 00068 ED_space_image_size(sima, &width, &height); 00069 ED_space_image_zoom(sima, ar, &zoomx, &zoomy); 00070 00071 w= zoomx*width/256.0f; 00072 h= zoomy*height/256.0f; 00073 00074 cpack(0xFFFFFF); 00075 glTranslatef(sima->cursor[0], sima->cursor[1], 0.0); 00076 fdrawline(-0.05f/w, 0, 0, 0.05f/h); 00077 fdrawline(0, 0.05f/h, 0.05f/w, 0.0f); 00078 fdrawline(0.05f/w, 0.0f, 0.0f, -0.05f/h); 00079 fdrawline(0.0f, -0.05f/h, -0.05f/w, 0.0f); 00080 00081 setlinestyle(4); 00082 cpack(0xFF); 00083 fdrawline(-0.05f/w, 0.0f, 0.0f, 0.05f/h); 00084 fdrawline(0.0f, 0.05f/h, 0.05f/w, 0.0f); 00085 fdrawline(0.05f/w, 0.0f, 0.0f, -0.05f/h); 00086 fdrawline(0.0f, -0.05f/h, -0.05f/w, 0.0f); 00087 00088 00089 setlinestyle(0.0f); 00090 cpack(0x0); 00091 fdrawline(-0.020f/w, 0.0f, -0.1f/w, 0.0f); 00092 fdrawline(0.1f/w, 0.0f, 0.020f/w, 0.0f); 00093 fdrawline(0.0f, -0.020f/h, 0.0f, -0.1f/h); 00094 fdrawline(0.0f, 0.1f/h, 0.0f, 0.020f/h); 00095 00096 setlinestyle(1); 00097 cpack(0xFFFFFF); 00098 fdrawline(-0.020f/w, 0.0f, -0.1f/w, 0.0f); 00099 fdrawline(0.1f/w, 0.0f, 0.020f/w, 0.0f); 00100 fdrawline(0.0f, -0.020f/h, 0.0f, -0.1f/h); 00101 fdrawline(0.0f, 0.1f/h, 0.0f, 0.020f/h); 00102 00103 glTranslatef(-sima->cursor[0], -sima->cursor[1], 0.0); 00104 setlinestyle(0); 00105 } 00106 00107 static int draw_uvs_face_check(Scene *scene) 00108 { 00109 ToolSettings *ts= scene->toolsettings; 00110 00111 /* checks if we are selecting only faces */ 00112 if(ts->uv_flag & UV_SYNC_SELECTION) { 00113 if(ts->selectmode == SCE_SELECT_FACE) 00114 return 2; 00115 else if(ts->selectmode & SCE_SELECT_FACE) 00116 return 1; 00117 else 00118 return 0; 00119 } 00120 else 00121 return (ts->uv_selectmode == UV_SELECT_FACE); 00122 } 00123 00124 static void draw_uvs_shadow(Object *obedit) 00125 { 00126 EditMesh *em; 00127 EditFace *efa; 00128 MTFace *tf; 00129 00130 em= BKE_mesh_get_editmesh((Mesh*)obedit->data); 00131 00132 /* draws the grey mesh when painting */ 00133 glColor3ub(112, 112, 112); 00134 00135 for(efa= em->faces.first; efa; efa= efa->next) { 00136 tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); 00137 00138 glBegin(GL_LINE_LOOP); 00139 glVertex2fv(tf->uv[0]); 00140 glVertex2fv(tf->uv[1]); 00141 glVertex2fv(tf->uv[2]); 00142 if(efa->v4) glVertex2fv(tf->uv[3]); 00143 glEnd(); 00144 } 00145 00146 BKE_mesh_end_editmesh(obedit->data, em); 00147 } 00148 00149 static int draw_uvs_dm_shadow(DerivedMesh *dm) 00150 { 00151 /* draw shadow mesh - this is the mesh with the modifier applied */ 00152 00153 if(dm && dm->drawUVEdges && CustomData_has_layer(&dm->faceData, CD_MTFACE)) { 00154 glColor3ub(112, 112, 112); 00155 dm->drawUVEdges(dm); 00156 return 1; 00157 } 00158 00159 return 0; 00160 } 00161 00162 static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, EditMesh *em, MTFace *activetf) 00163 { 00164 EditFace *efa; 00165 MTFace *tf; 00166 Image *ima= sima->image; 00167 float aspx, aspy, col[4], tf_uv[4][2]; 00168 00169 ED_space_image_uv_aspect(sima, &aspx, &aspy); 00170 00171 switch(sima->dt_uvstretch) { 00172 case SI_UVDT_STRETCH_AREA: 00173 { 00174 float totarea=0.0f, totuvarea=0.0f, areadiff, uvarea, area; 00175 00176 for(efa= em->faces.first; efa; efa= efa->next) { 00177 tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); 00178 uv_copy_aspect(tf->uv, tf_uv, aspx, aspy); 00179 00180 totarea += EM_face_area(efa); 00181 //totuvarea += tf_area(tf, efa->v4!=0); 00182 totuvarea += uv_area(tf_uv, efa->v4 != NULL); 00183 00184 if(uvedit_face_visible(scene, ima, efa, tf)) { 00185 efa->tmp.p = tf; 00186 } 00187 else { 00188 if(tf == activetf) 00189 activetf= NULL; 00190 efa->tmp.p = NULL; 00191 } 00192 } 00193 00194 if(totarea < FLT_EPSILON || totuvarea < FLT_EPSILON) { 00195 col[0] = 1.0; 00196 col[1] = col[2] = 0.0; 00197 glColor3fv(col); 00198 for(efa= em->faces.first; efa; efa= efa->next) { 00199 if((tf=(MTFace *)efa->tmp.p)) { 00200 glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); 00201 glVertex2fv(tf->uv[0]); 00202 glVertex2fv(tf->uv[1]); 00203 glVertex2fv(tf->uv[2]); 00204 if(efa->v4) glVertex2fv(tf->uv[3]); 00205 glEnd(); 00206 } 00207 } 00208 } 00209 else { 00210 for(efa= em->faces.first; efa; efa= efa->next) { 00211 if((tf=(MTFace *)efa->tmp.p)) { 00212 area = EM_face_area(efa) / totarea; 00213 uv_copy_aspect(tf->uv, tf_uv, aspx, aspy); 00214 //uvarea = tf_area(tf, efa->v4!=0) / totuvarea; 00215 uvarea = uv_area(tf_uv, efa->v4 != NULL) / totuvarea; 00216 00217 if(area < FLT_EPSILON || uvarea < FLT_EPSILON) 00218 areadiff = 1.0f; 00219 else if(area>uvarea) 00220 areadiff = 1.0f-(uvarea/area); 00221 else 00222 areadiff = 1.0f-(area/uvarea); 00223 00224 weight_to_rgb(areadiff, col, col+1, col+2); 00225 glColor3fv(col); 00226 00227 glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); 00228 glVertex2fv(tf->uv[0]); 00229 glVertex2fv(tf->uv[1]); 00230 glVertex2fv(tf->uv[2]); 00231 if(efa->v4) glVertex2fv(tf->uv[3]); 00232 glEnd(); 00233 } 00234 } 00235 } 00236 break; 00237 } 00238 case SI_UVDT_STRETCH_ANGLE: 00239 { 00240 float uvang1,uvang2,uvang3,uvang4; 00241 float ang1,ang2,ang3,ang4; 00242 float av1[3], av2[3], av3[3], av4[3]; /* use for 2d and 3d angle vectors */ 00243 float a; 00244 00245 col[3] = 0.5; /* hard coded alpha, not that nice */ 00246 00247 glShadeModel(GL_SMOOTH); 00248 00249 for(efa= em->faces.first; efa; efa= efa->next) { 00250 tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); 00251 00252 if(uvedit_face_visible(scene, ima, efa, tf)) { 00253 efa->tmp.p = tf; 00254 uv_copy_aspect(tf->uv, tf_uv, aspx, aspy); 00255 if(efa->v4) { 00256 00257 #if 0 /* Simple but slow, better reuse normalized vectors */ 00258 uvang1 = RAD2DEG(angle_v2v2v2(tf_uv[3], tf_uv[0], tf_uv[1])); 00259 ang1 = RAD2DEG(angle_v3v3v3(efa->v4->co, efa->v1->co, efa->v2->co)); 00260 00261 uvang2 = RAD2DEG(angle_v2v2v2(tf_uv[0], tf_uv[1], tf_uv[2])); 00262 ang2 = RAD2DEG(angle_v3v3v3(efa->v1->co, efa->v2->co, efa->v3->co)); 00263 00264 uvang3 = RAD2DEG(angle_v2v2v2(tf_uv[1], tf_uv[2], tf_uv[3])); 00265 ang3 = RAD2DEG(angle_v3v3v3(efa->v2->co, efa->v3->co, efa->v4->co)); 00266 00267 uvang4 = RAD2DEG(angle_v2v2v2(tf_uv[2], tf_uv[3], tf_uv[0])); 00268 ang4 = RAD2DEG(angle_v3v3v3(efa->v3->co, efa->v4->co, efa->v1->co)); 00269 #endif 00270 00271 /* uv angles */ 00272 VECSUB2D(av1, tf_uv[3], tf_uv[0]); normalize_v2(av1); 00273 VECSUB2D(av2, tf_uv[0], tf_uv[1]); normalize_v2(av2); 00274 VECSUB2D(av3, tf_uv[1], tf_uv[2]); normalize_v2(av3); 00275 VECSUB2D(av4, tf_uv[2], tf_uv[3]); normalize_v2(av4); 00276 00277 /* This is the correct angle however we are only comparing angles 00278 * uvang1 = 90-((angle_normalized_v2v2(av1, av2) * 180.0/M_PI)-90);*/ 00279 uvang1 = angle_normalized_v2v2(av1, av2); 00280 uvang2 = angle_normalized_v2v2(av2, av3); 00281 uvang3 = angle_normalized_v2v2(av3, av4); 00282 uvang4 = angle_normalized_v2v2(av4, av1); 00283 00284 /* 3d angles */ 00285 VECSUB(av1, efa->v4->co, efa->v1->co); normalize_v3(av1); 00286 VECSUB(av2, efa->v1->co, efa->v2->co); normalize_v3(av2); 00287 VECSUB(av3, efa->v2->co, efa->v3->co); normalize_v3(av3); 00288 VECSUB(av4, efa->v3->co, efa->v4->co); normalize_v3(av4); 00289 00290 /* This is the correct angle however we are only comparing angles 00291 * ang1 = 90-((angle_normalized_v3v3(av1, av2) * 180.0/M_PI)-90);*/ 00292 ang1 = angle_normalized_v3v3(av1, av2); 00293 ang2 = angle_normalized_v3v3(av2, av3); 00294 ang3 = angle_normalized_v3v3(av3, av4); 00295 ang4 = angle_normalized_v3v3(av4, av1); 00296 00297 glBegin(GL_QUADS); 00298 00299 /* This simple makes the angles display worse then they really are ;) 00300 * 1.0-powf((1.0-a), 2) */ 00301 00302 a = fabsf(uvang1-ang1)/(float)M_PI; 00303 weight_to_rgb(1.0f-powf((1.0f-a), 2.0f), col, col+1, col+2); 00304 glColor3fv(col); 00305 glVertex2fv(tf->uv[0]); 00306 a = fabsf(uvang2-ang2)/(float)M_PI; 00307 weight_to_rgb(1.0f-powf((1.0f-a), 2.0f), col, col+1, col+2); 00308 glColor3fv(col); 00309 glVertex2fv(tf->uv[1]); 00310 a = fabsf(uvang3-ang3)/(float)M_PI; 00311 weight_to_rgb(1.0f-powf((1.0f-a), 2.0f), col, col+1, col+2); 00312 glColor3fv(col); 00313 glVertex2fv(tf->uv[2]); 00314 a = fabsf(uvang4-ang4)/(float)M_PI; 00315 weight_to_rgb(1.0f-powf((1.0f-a), 2.0f), col, col+1, col+2); 00316 glColor3fv(col); 00317 glVertex2fv(tf->uv[3]); 00318 00319 } 00320 else { 00321 #if 0 /* Simple but slow, better reuse normalized vectors */ 00322 uvang1 = RAD2DEG(angle_v2v2v2(tf_uv[2], tf_uv[0], tf_uv[1])); 00323 ang1 = RAD2DEG(angle_v3v3v3(efa->v3->co, efa->v1->co, efa->v2->co)); 00324 00325 uvang2 = RAD2DEG(angle_v2v2v2(tf_uv[0], tf_uv[1], tf_uv[2])); 00326 ang2 = RAD2DEG(angle_v3v3v3(efa->v1->co, efa->v2->co, efa->v3->co)); 00327 00328 uvang3 = M_PI-(uvang1+uvang2); 00329 ang3 = M_PI-(ang1+ang2); 00330 #endif 00331 00332 /* uv angles */ 00333 VECSUB2D(av1, tf_uv[2], tf_uv[0]); normalize_v2(av1); 00334 VECSUB2D(av2, tf_uv[0], tf_uv[1]); normalize_v2(av2); 00335 VECSUB2D(av3, tf_uv[1], tf_uv[2]); normalize_v2(av3); 00336 00337 /* This is the correct angle however we are only comparing angles 00338 * uvang1 = 90-((angle_normalized_v2v2(av1, av2) * 180.0/M_PI)-90); */ 00339 uvang1 = angle_normalized_v2v2(av1, av2); 00340 uvang2 = angle_normalized_v2v2(av2, av3); 00341 uvang3 = angle_normalized_v2v2(av3, av1); 00342 00343 /* 3d angles */ 00344 VECSUB(av1, efa->v3->co, efa->v1->co); normalize_v3(av1); 00345 VECSUB(av2, efa->v1->co, efa->v2->co); normalize_v3(av2); 00346 VECSUB(av3, efa->v2->co, efa->v3->co); normalize_v3(av3); 00347 /* This is the correct angle however we are only comparing angles 00348 * ang1 = 90-((angle_normalized_v3v3(av1, av2) * 180.0/M_PI)-90); */ 00349 ang1 = angle_normalized_v3v3(av1, av2); 00350 ang2 = angle_normalized_v3v3(av2, av3); 00351 ang3 = angle_normalized_v3v3(av3, av1); 00352 00353 /* This simple makes the angles display worse then they really are ;) 00354 * 1.0f-powf((1.0-a), 2) */ 00355 00356 glBegin(GL_TRIANGLES); 00357 a = fabsf(uvang1-ang1)/(float)M_PI; 00358 weight_to_rgb(1.0f-powf((1.0f-a), 2.0f), col, col+1, col+2); 00359 glColor3fv(col); 00360 glVertex2fv(tf->uv[0]); 00361 a = fabsf(uvang2-ang2)/(float)M_PI; 00362 weight_to_rgb(1.0f-powf((1.0f-a), 2.0f), col, col+1, col+2); 00363 glColor3fv(col); 00364 glVertex2fv(tf->uv[1]); 00365 a = fabsf(uvang3-ang3)/(float)M_PI; 00366 weight_to_rgb(1.0f-powf((1.0f-a), 2.0f), col, col+1, col+2); 00367 glColor3fv(col); 00368 glVertex2fv(tf->uv[2]); 00369 } 00370 glEnd(); 00371 } 00372 else { 00373 if(tf == activetf) 00374 activetf= NULL; 00375 efa->tmp.p = NULL; 00376 } 00377 } 00378 00379 glShadeModel(GL_FLAT); 00380 break; 00381 } 00382 } 00383 } 00384 00385 static void draw_uvs_other(Scene *scene, Object *obedit, MTFace *activetf) 00386 { 00387 Base *base; 00388 Image *curimage; 00389 00390 curimage= (activetf)? activetf->tpage: NULL; 00391 00392 glColor3ub(96, 96, 96); 00393 00394 for(base=scene->base.first; base; base=base->next) { 00395 Object *ob= base->object; 00396 00397 if(!(base->flag & SELECT)) continue; 00398 if(!(base->lay & scene->lay)) continue; 00399 if(ob->restrictflag & OB_RESTRICT_VIEW) continue; 00400 00401 if((ob->type==OB_MESH) && (ob!=obedit)) { 00402 Mesh *me= ob->data; 00403 00404 if(me->mtface) { 00405 MFace *mface= me->mface; 00406 MTFace *tface= me->mtface; 00407 int a; 00408 00409 for(a=me->totface; a>0; a--, tface++, mface++) { 00410 if(tface->tpage == curimage) { 00411 glBegin(GL_LINE_LOOP); 00412 glVertex2fv(tface->uv[0]); 00413 glVertex2fv(tface->uv[1]); 00414 glVertex2fv(tface->uv[2]); 00415 if(mface->v4) glVertex2fv(tface->uv[3]); 00416 glEnd(); 00417 } 00418 } 00419 } 00420 } 00421 } 00422 } 00423 00424 /* draws uv's in the image space */ 00425 static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) 00426 { 00427 ToolSettings *ts; 00428 Mesh *me= obedit->data; 00429 EditMesh *em; 00430 EditFace *efa, *efa_act; 00431 MTFace *tf, *activetf = NULL; 00432 DerivedMesh *finaldm, *cagedm; 00433 unsigned char col1[4], col2[4]; 00434 float pointsize; 00435 int drawfaces, interpedges; 00436 Image *ima= sima->image; 00437 00438 em= BKE_mesh_get_editmesh(me); 00439 activetf= EM_get_active_mtface(em, &efa_act, NULL, 0); /* will be set to NULL if hidden */ 00440 00441 ts= scene->toolsettings; 00442 00443 drawfaces= draw_uvs_face_check(scene); 00444 if(ts->uv_flag & UV_SYNC_SELECTION) 00445 interpedges= (ts->selectmode & SCE_SELECT_VERTEX); 00446 else 00447 interpedges= (ts->uv_selectmode == UV_SELECT_VERTEX); 00448 00449 /* draw other uvs */ 00450 if(sima->flag & SI_DRAW_OTHER) 00451 draw_uvs_other(scene, obedit, activetf); 00452 00453 /* 1. draw shadow mesh */ 00454 00455 if(sima->flag & SI_DRAWSHADOW) { 00456 /* first try existing derivedmesh */ 00457 if(!draw_uvs_dm_shadow(em->derivedFinal)) { 00458 /* create one if it does not exist */ 00459 cagedm = editmesh_get_derived_cage_and_final(scene, obedit, em, &finaldm, CD_MASK_BAREMESH|CD_MASK_MTFACE); 00460 00461 /* when sync selection is enabled, all faces are drawn (except for hidden) 00462 * so if cage is the same as the final, theres no point in drawing this */ 00463 if(!((ts->uv_flag & UV_SYNC_SELECTION) && (cagedm == finaldm))) 00464 draw_uvs_dm_shadow(finaldm); 00465 00466 /* release derivedmesh again */ 00467 if(cagedm != finaldm) cagedm->release(cagedm); 00468 finaldm->release(finaldm); 00469 } 00470 } 00471 00472 /* 2. draw colored faces */ 00473 00474 if(sima->flag & SI_DRAW_STRETCH) { 00475 draw_uvs_stretch(sima, scene, em, activetf); 00476 } 00477 else if(!(sima->flag & SI_NO_DRAWFACES)) { 00478 /* draw transparent faces */ 00479 UI_GetThemeColor4ubv(TH_FACE, col1); 00480 UI_GetThemeColor4ubv(TH_FACE_SELECT, col2); 00481 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00482 glEnable(GL_BLEND); 00483 00484 for(efa= em->faces.first; efa; efa= efa->next) { 00485 tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); 00486 00487 if(uvedit_face_visible(scene, ima, efa, tf)) { 00488 efa->tmp.p = tf; 00489 if(tf==activetf) continue; /* important the temp pointer is set above */ 00490 00491 if(uvedit_face_selected(scene, efa, tf)) 00492 glColor4ubv((GLubyte *)col2); 00493 else 00494 glColor4ubv((GLubyte *)col1); 00495 00496 glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); 00497 glVertex2fv(tf->uv[0]); 00498 glVertex2fv(tf->uv[1]); 00499 glVertex2fv(tf->uv[2]); 00500 if(efa->v4) glVertex2fv(tf->uv[3]); 00501 glEnd(); 00502 } 00503 else { 00504 if(tf == activetf) 00505 activetf= NULL; 00506 efa->tmp.p = NULL; 00507 } 00508 } 00509 glDisable(GL_BLEND); 00510 } 00511 else { 00512 /* would be nice to do this within a draw loop but most below are optional, so it would involve too many checks */ 00513 for(efa= em->faces.first; efa; efa= efa->next) { 00514 tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); 00515 00516 if(uvedit_face_visible(scene, ima, efa, tf)) { 00517 efa->tmp.p = tf; 00518 } 00519 else { 00520 if(tf == activetf) 00521 activetf= NULL; 00522 efa->tmp.p = NULL; 00523 } 00524 } 00525 00526 } 00527 00528 /* 3. draw active face stippled */ 00529 00530 if(activetf) { 00531 glEnable(GL_BLEND); 00532 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00533 UI_ThemeColor4(TH_EDITMESH_ACTIVE); 00534 00535 glEnable(GL_POLYGON_STIPPLE); 00536 glPolygonStipple(stipple_quarttone); 00537 00538 glBegin(efa_act->v4? GL_QUADS: GL_TRIANGLES); 00539 glVertex2fv(activetf->uv[0]); 00540 glVertex2fv(activetf->uv[1]); 00541 glVertex2fv(activetf->uv[2]); 00542 if(efa_act->v4) glVertex2fv(activetf->uv[3]); 00543 glEnd(); 00544 00545 glDisable(GL_POLYGON_STIPPLE); 00546 glDisable(GL_BLEND); 00547 } 00548 00549 /* 4. draw edges */ 00550 00551 if(sima->flag & SI_SMOOTH_UV) { 00552 glEnable(GL_LINE_SMOOTH); 00553 glEnable(GL_BLEND); 00554 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00555 } 00556 00557 switch(sima->dt_uv) { 00558 case SI_UVDT_DASH: 00559 for(efa= em->faces.first; efa; efa= efa->next) { 00560 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00561 00562 if(tf) { 00563 cpack(0x111111); 00564 00565 glBegin(GL_LINE_LOOP); 00566 glVertex2fv(tf->uv[0]); 00567 glVertex2fv(tf->uv[1]); 00568 glVertex2fv(tf->uv[2]); 00569 if(efa->v4) glVertex2fv(tf->uv[3]); 00570 glEnd(); 00571 00572 setlinestyle(2); 00573 cpack(0x909090); 00574 00575 glBegin(GL_LINE_STRIP); 00576 glVertex2fv(tf->uv[0]); 00577 glVertex2fv(tf->uv[1]); 00578 glEnd(); 00579 00580 glBegin(GL_LINE_STRIP); 00581 glVertex2fv(tf->uv[0]); 00582 if(efa->v4) glVertex2fv(tf->uv[3]); 00583 else glVertex2fv(tf->uv[2]); 00584 glEnd(); 00585 00586 glBegin(GL_LINE_STRIP); 00587 glVertex2fv(tf->uv[1]); 00588 glVertex2fv(tf->uv[2]); 00589 if(efa->v4) glVertex2fv(tf->uv[3]); 00590 glEnd(); 00591 00592 setlinestyle(0); 00593 } 00594 } 00595 break; 00596 case SI_UVDT_BLACK: /* black/white */ 00597 case SI_UVDT_WHITE: 00598 if(sima->dt_uv==SI_UVDT_WHITE) glColor3f(1.0f, 1.0f, 1.0f); 00599 else glColor3f(0.0f, 0.0f, 0.0f); 00600 00601 for(efa= em->faces.first; efa; efa= efa->next) { 00602 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00603 00604 if(tf) { 00605 glBegin(GL_LINE_LOOP); 00606 glVertex2fv(tf->uv[0]); 00607 glVertex2fv(tf->uv[1]); 00608 glVertex2fv(tf->uv[2]); 00609 if(efa->v4) glVertex2fv(tf->uv[3]); 00610 glEnd(); 00611 } 00612 } 00613 break; 00614 case SI_UVDT_OUTLINE: 00615 glLineWidth(3); 00616 cpack(0x0); 00617 00618 for(efa= em->faces.first; efa; efa= efa->next) { 00619 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00620 00621 if(tf) { 00622 glBegin(GL_LINE_LOOP); 00623 glVertex2fv(tf->uv[0]); 00624 glVertex2fv(tf->uv[1]); 00625 glVertex2fv(tf->uv[2]); 00626 if(efa->v4) glVertex2fv(tf->uv[3]); 00627 glEnd(); 00628 } 00629 } 00630 00631 glLineWidth(1); 00632 col2[0] = col2[1] = col2[2] = 192; col2[3] = 255; 00633 glColor4ubv((unsigned char *)col2); 00634 00635 if(me->drawflag & ME_DRAWEDGES) { 00636 int lastsel= 0, sel; 00637 UI_GetThemeColor4ubv(TH_VERTEX_SELECT, col1); 00638 00639 if(interpedges) { 00640 glShadeModel(GL_SMOOTH); 00641 00642 for(efa= em->faces.first; efa; efa= efa->next) { 00643 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00644 00645 if(tf) { 00646 glBegin(GL_LINE_LOOP); 00647 sel = (uvedit_uv_selected(scene, efa, tf, 0)? 1 : 0); 00648 if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; } 00649 glVertex2fv(tf->uv[0]); 00650 00651 sel = uvedit_uv_selected(scene, efa, tf, 1)? 1 : 0; 00652 if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; } 00653 glVertex2fv(tf->uv[1]); 00654 00655 sel = uvedit_uv_selected(scene, efa, tf, 2)? 1 : 0; 00656 if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; } 00657 glVertex2fv(tf->uv[2]); 00658 00659 if(efa->v4) { 00660 sel = uvedit_uv_selected(scene, efa, tf, 3)? 1 : 0; 00661 if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; } 00662 glVertex2fv(tf->uv[3]); 00663 } 00664 00665 glEnd(); 00666 } 00667 } 00668 00669 glShadeModel(GL_FLAT); 00670 } 00671 else { 00672 for(efa= em->faces.first; efa; efa= efa->next) { 00673 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00674 00675 if(tf) { 00676 glBegin(GL_LINES); 00677 sel = (uvedit_edge_selected(scene, efa, tf, 0)? 1 : 0); 00678 if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; } 00679 glVertex2fv(tf->uv[0]); 00680 glVertex2fv(tf->uv[1]); 00681 00682 sel = uvedit_edge_selected(scene, efa, tf, 1)? 1 : 0; 00683 if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; } 00684 glVertex2fv(tf->uv[1]); 00685 glVertex2fv(tf->uv[2]); 00686 00687 sel = uvedit_edge_selected(scene, efa, tf, 2)? 1 : 0; 00688 if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; } 00689 glVertex2fv(tf->uv[2]); 00690 00691 if(efa->v4) { 00692 glVertex2fv(tf->uv[3]); 00693 00694 sel = uvedit_edge_selected(scene, efa, tf, 3)? 1 : 0; 00695 if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; } 00696 glVertex2fv(tf->uv[3]); 00697 } 00698 00699 glVertex2fv(tf->uv[0]); 00700 00701 glEnd(); 00702 } 00703 } 00704 } 00705 } 00706 else { 00707 /* no nice edges */ 00708 for(efa= em->faces.first; efa; efa= efa->next) { 00709 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00710 00711 if(tf) { 00712 glBegin(GL_LINE_LOOP); 00713 glVertex2fv(tf->uv[0]); 00714 glVertex2fv(tf->uv[1]); 00715 glVertex2fv(tf->uv[2]); 00716 if(efa->v4) glVertex2fv(tf->uv[3]); 00717 glEnd(); 00718 } 00719 } 00720 } 00721 00722 break; 00723 } 00724 00725 if(sima->flag & SI_SMOOTH_UV) { 00726 glDisable(GL_LINE_SMOOTH); 00727 glDisable(GL_BLEND); 00728 } 00729 00730 /* 5. draw face centers */ 00731 00732 if(drawfaces) { 00733 float cent[2]; 00734 00735 pointsize = UI_GetThemeValuef(TH_FACEDOT_SIZE); 00736 glPointSize(pointsize); // TODO - drawobject.c changes this value after - Investigate! 00737 00738 /* unselected faces */ 00739 UI_ThemeColor(TH_WIRE); 00740 00741 bglBegin(GL_POINTS); 00742 for(efa= em->faces.first; efa; efa= efa->next) { 00743 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00744 00745 if(tf && !uvedit_face_selected(scene, efa, tf)) { 00746 uv_center(tf->uv, cent, efa->v4 != NULL); 00747 bglVertex2fv(cent); 00748 } 00749 } 00750 bglEnd(); 00751 00752 /* selected faces */ 00753 UI_ThemeColor(TH_FACE_DOT); 00754 00755 bglBegin(GL_POINTS); 00756 for(efa= em->faces.first; efa; efa= efa->next) { 00757 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00758 00759 if(tf && uvedit_face_selected(scene, efa, tf)) { 00760 uv_center(tf->uv, cent, efa->v4 != NULL); 00761 bglVertex2fv(cent); 00762 } 00763 } 00764 bglEnd(); 00765 } 00766 00767 /* 6. draw uv vertices */ 00768 00769 if(drawfaces != 2) { /* 2 means Mesh Face Mode */ 00770 /* unselected uvs */ 00771 UI_ThemeColor(TH_VERTEX); 00772 pointsize = UI_GetThemeValuef(TH_VERTEX_SIZE); 00773 glPointSize(pointsize); 00774 00775 bglBegin(GL_POINTS); 00776 for(efa= em->faces.first; efa; efa= efa->next) { 00777 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00778 00779 if(tf) { 00780 if(!uvedit_uv_selected(scene, efa, tf, 0)) 00781 bglVertex2fv(tf->uv[0]); 00782 if(!uvedit_uv_selected(scene, efa, tf, 1)) 00783 bglVertex2fv(tf->uv[1]); 00784 if(!uvedit_uv_selected(scene, efa, tf, 2)) 00785 bglVertex2fv(tf->uv[2]); 00786 if(efa->v4 && !uvedit_uv_selected(scene, efa, tf, 3)) 00787 bglVertex2fv(tf->uv[3]); 00788 } 00789 } 00790 bglEnd(); 00791 00792 /* pinned uvs */ 00793 /* give odd pointsizes odd pin pointsizes */ 00794 glPointSize(pointsize*2 + (((int)pointsize % 2)? (-1): 0)); 00795 cpack(0xFF); 00796 00797 bglBegin(GL_POINTS); 00798 for(efa= em->faces.first; efa; efa= efa->next) { 00799 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00800 00801 if(tf) { 00802 if(tf->unwrap & TF_PIN1) 00803 bglVertex2fv(tf->uv[0]); 00804 if(tf->unwrap & TF_PIN2) 00805 bglVertex2fv(tf->uv[1]); 00806 if(tf->unwrap & TF_PIN3) 00807 bglVertex2fv(tf->uv[2]); 00808 if(efa->v4 && (tf->unwrap & TF_PIN4)) 00809 bglVertex2fv(tf->uv[3]); 00810 } 00811 } 00812 bglEnd(); 00813 00814 /* selected uvs */ 00815 UI_ThemeColor(TH_VERTEX_SELECT); 00816 glPointSize(pointsize); 00817 00818 bglBegin(GL_POINTS); 00819 for(efa= em->faces.first; efa; efa= efa->next) { 00820 tf= (MTFace *)efa->tmp.p; /* visible faces cached */ 00821 00822 if(tf) { 00823 if(uvedit_uv_selected(scene, efa, tf, 0)) 00824 bglVertex2fv(tf->uv[0]); 00825 if(uvedit_uv_selected(scene, efa, tf, 1)) 00826 bglVertex2fv(tf->uv[1]); 00827 if(uvedit_uv_selected(scene, efa, tf, 2)) 00828 bglVertex2fv(tf->uv[2]); 00829 if(efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) 00830 bglVertex2fv(tf->uv[3]); 00831 } 00832 } 00833 bglEnd(); 00834 } 00835 00836 glPointSize(1.0); 00837 BKE_mesh_end_editmesh(obedit->data, em); 00838 } 00839 00840 void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedit) 00841 { 00842 int show_uvedit, show_uvshadow; 00843 00844 show_uvedit= ED_space_image_show_uvedit(sima, obedit); 00845 show_uvshadow= ED_space_image_show_uvshadow(sima, obedit); 00846 00847 if(show_uvedit || show_uvshadow) { 00848 if(show_uvshadow) 00849 draw_uvs_shadow(obedit); 00850 else 00851 draw_uvs(sima, scene, obedit); 00852 00853 if(show_uvedit) 00854 drawcursor_sima(sima, ar); 00855 } 00856 } 00857