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