62
71
ED_space_image_size(sima, &width, &height);
63
72
ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
65
w= zoomx*width/256.0f;
66
h= zoomy*height/256.0f;
74
w = zoomx * width / 256.0f;
75
h = zoomy * height / 256.0f;
69
glTranslatef(sima->cursor[0], sima->cursor[1], 0.0f);
70
fdrawline(-0.05/w, 0, 0, 0.05/h);
71
fdrawline(0, 0.05/h, 0.05/w, 0);
72
fdrawline(0.05/w, 0, 0, -0.05/h);
73
fdrawline(0, -0.05/h, -0.05/w, 0);
78
glTranslatef(sima->cursor[0], sima->cursor[1], 0.0);
79
fdrawline(-0.05f / w, 0, 0, 0.05f / h);
80
fdrawline(0, 0.05f / h, 0.05f / w, 0.0f);
81
fdrawline(0.05f / w, 0.0f, 0.0f, -0.05f / h);
82
fdrawline(0.0f, -0.05f / h, -0.05f / w, 0.0f);
77
fdrawline(-0.05/w, 0, 0, 0.05/h);
78
fdrawline(0, 0.05/h, 0.05/w, 0);
79
fdrawline(0.05/w, 0, 0, -0.05/h);
80
fdrawline(0, -0.05/h, -0.05/w, 0);
86
fdrawline(-0.05f / w, 0.0f, 0.0f, 0.05f / h);
87
fdrawline(0.0f, 0.05f / h, 0.05f / w, 0.0f);
88
fdrawline(0.05f / w, 0.0f, 0.0f, -0.05f / h);
89
fdrawline(0.0f, -0.05f / h, -0.05f / w, 0.0f);
85
fdrawline(-0.020/w, 0, -0.1/w, 0);
86
fdrawline(0.1/w, 0, .020/w, 0);
87
fdrawline(0, -0.020/h, 0, -0.1/h);
88
fdrawline(0, 0.1/h, 0, 0.020/h);
94
fdrawline(-0.020f / w, 0.0f, -0.1f / w, 0.0f);
95
fdrawline(0.1f / w, 0.0f, 0.020f / w, 0.0f);
96
fdrawline(0.0f, -0.020f / h, 0.0f, -0.1f / h);
97
fdrawline(0.0f, 0.1f / h, 0.0f, 0.020f / h);
92
fdrawline(-0.020/w, 0, -0.1/w, 0);
93
fdrawline(0.1/w, 0, .020/w, 0);
94
fdrawline(0, -0.020/h, 0, -0.1/h);
95
fdrawline(0, 0.1/h, 0, 0.020/h);
97
glTranslatef(-sima->cursor[0], -sima->cursor[1], 0.0f);
101
fdrawline(-0.020f / w, 0.0f, -0.1f / w, 0.0f);
102
fdrawline(0.1f / w, 0.0f, 0.020f / w, 0.0f);
103
fdrawline(0.0f, -0.020f / h, 0.0f, -0.1f / h);
104
fdrawline(0.0f, 0.1f / h, 0.0f, 0.020f / h);
106
glTranslatef(-sima->cursor[0], -sima->cursor[1], 0.0);
101
110
static int draw_uvs_face_check(Scene *scene)
103
ToolSettings *ts= scene->toolsettings;
112
ToolSettings *ts = scene->toolsettings;
105
114
/* checks if we are selecting only faces */
106
if(ts->uv_flag & UV_SYNC_SELECTION) {
107
if(ts->selectmode == SCE_SELECT_FACE)
115
if (ts->uv_flag & UV_SYNC_SELECTION) {
116
if (ts->selectmode == SCE_SELECT_FACE)
109
else if(ts->selectmode & SCE_SELECT_FACE)
118
else if (ts->selectmode & SCE_SELECT_FACE)
156
static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, EditMesh *em, MTFace *activetf)
163
static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTexPoly *activetf)
160
Image *ima= sima->image;
161
float aspx, aspy, col[4], tf_uv[4][2];
171
Image *ima = sima->image;
172
BLI_array_declare(tf_uv);
173
BLI_array_declare(tf_uvorig);
174
float aspx, aspy, col[4], (*tf_uv)[2] = NULL, (*tf_uvorig)[2] = NULL;
163
177
ED_space_image_uv_aspect(sima, &aspx, &aspy);
165
switch(sima->dt_uvstretch) {
179
switch (sima->dt_uvstretch) {
166
180
case SI_UVDT_STRETCH_AREA:
168
float totarea=0.0f, totuvarea=0.0f, areadiff, uvarea, area;
182
float totarea = 0.0f, totuvarea = 0.0f, areadiff, uvarea, area;
170
for(efa= em->faces.first; efa; efa= efa->next) {
171
tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
172
uv_copy_aspect(tf->uv, tf_uv, aspx, aspy);
174
totarea += EM_face_area(efa);
184
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
185
tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
187
BLI_array_empty(tf_uv);
188
BLI_array_empty(tf_uvorig);
189
BLI_array_growitems(tf_uv, efa->len);
190
BLI_array_growitems(tf_uvorig, efa->len);
193
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
194
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
196
copy_v2_v2(tf_uvorig[i], luv->uv);
201
poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa->len);
203
totarea += BM_face_calc_area(efa);
175
204
//totuvarea += tf_area(tf, efa->v4!=0);
176
totuvarea += uv_area(tf_uv, efa->v4!=0);
205
totuvarea += poly_uv_area(tf_uv, efa->len);
178
if(uvedit_face_visible(scene, ima, efa, tf)) {
207
if (uvedit_face_visible_test(scene, ima, efa, tf)) {
208
BM_elem_flag_enable(efa, BM_ELEM_TAG);
213
BM_elem_flag_disable(efa, BM_ELEM_TAG);
188
if(totarea < FLT_EPSILON || totuvarea < FLT_EPSILON) {
217
if (totarea < FLT_EPSILON || totuvarea < FLT_EPSILON) {
190
219
col[1] = col[2] = 0.0;
192
for(efa= em->faces.first; efa; efa= efa->next) {
193
if((tf=(MTFace *)efa->tmp.p)) {
194
glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
195
glVertex2fv(tf->uv[0]);
196
glVertex2fv(tf->uv[1]);
197
glVertex2fv(tf->uv[2]);
198
if(efa->v4) glVertex2fv(tf->uv[3]);
221
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
222
if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
224
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
225
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
226
glVertex2fv(luv->uv);
204
for(efa= em->faces.first; efa; efa= efa->next) {
205
if((tf=(MTFace *)efa->tmp.p)) {
206
area = EM_face_area(efa) / totarea;
207
uv_copy_aspect(tf->uv, tf_uv, aspx, aspy);
233
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
234
if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
235
area = BM_face_calc_area(efa) / totarea;
237
BLI_array_empty(tf_uv);
238
BLI_array_empty(tf_uvorig);
239
BLI_array_growitems(tf_uv, efa->len);
240
BLI_array_growitems(tf_uvorig, efa->len);
243
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
244
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
246
copy_v2_v2(tf_uvorig[i], luv->uv);
251
poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa->len);
208
253
//uvarea = tf_area(tf, efa->v4!=0) / totuvarea;
209
uvarea = uv_area(tf_uv, efa->v4!=0) / totuvarea;
254
uvarea = poly_uv_area(tf_uv, efa->len) / totuvarea;
211
if(area < FLT_EPSILON || uvarea < FLT_EPSILON)
214
areadiff = 1.0-(uvarea/area);
256
if (area < FLT_EPSILON || uvarea < FLT_EPSILON)
258
else if (area > uvarea)
259
areadiff = 1.0f - (uvarea / area);
216
areadiff = 1.0-(area/uvarea);
261
areadiff = 1.0f - (area / uvarea);
218
weight_to_rgb(areadiff, col, col+1, col+2);
263
weight_to_rgb(col, areadiff);
221
glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
222
glVertex2fv(tf->uv[0]);
223
glVertex2fv(tf->uv[1]);
224
glVertex2fv(tf->uv[2]);
225
if(efa->v4) glVertex2fv(tf->uv[3]);
267
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
268
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
269
glVertex2fv(luv->uv);
232
277
case SI_UVDT_STRETCH_ANGLE:
234
float uvang1,uvang2,uvang3,uvang4;
235
float ang1,ang2,ang3,ang4;
236
float av1[3], av2[3], av3[3], av4[3]; /* use for 2d and 3d angle vectors */
281
float (*av)[3] = NULL; /* use for 2d and 3d angle vectors */
282
float (*auv)[2] = NULL;
285
BLI_array_declare(uvang);
286
BLI_array_declare(ang);
287
BLI_array_declare(av);
288
BLI_array_declare(auv);
239
290
col[3] = 0.5; /* hard coded alpha, not that nice */
241
292
glShadeModel(GL_SMOOTH);
243
for(efa= em->faces.first; efa; efa= efa->next) {
244
tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
294
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
295
tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
246
if(uvedit_face_visible(scene, ima, efa, tf)) {
248
uv_copy_aspect(tf->uv, tf_uv, aspx, aspy);
251
#if 0 /* Simple but slow, better reuse normalized vectors */
297
if (uvedit_face_visible_test(scene, ima, efa, tf)) {
299
BM_elem_flag_enable(efa, BM_ELEM_TAG);
300
BLI_array_empty(tf_uv);
301
BLI_array_empty(tf_uvorig);
302
BLI_array_empty(uvang);
303
BLI_array_empty(ang);
305
BLI_array_empty(auv);
306
BLI_array_growitems(tf_uv, nverts);
307
BLI_array_growitems(tf_uvorig, nverts);
308
BLI_array_growitems(uvang, nverts);
309
BLI_array_growitems(ang, nverts);
310
BLI_array_growitems(av, nverts);
311
BLI_array_growitems(auv, nverts);
313
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
314
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
315
copy_v2_v2(tf_uvorig[i], luv->uv);
318
poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, nverts);
321
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
322
sub_v2_v2v2(auv[i], tf_uv[j], tf_uv[i]); normalize_v2(auv[i]);
323
sub_v3_v3v3(av[i], l->prev->v->co, l->v->co); normalize_v3(av[i]);
327
for (i = 0; i < nverts; i++) {
329
/* Simple but slow, better reuse normalized vectors
330
* (Not ported to bmesh, copied for reference) */
252
331
uvang1 = RAD2DEG(angle_v2v2v2(tf_uv[3], tf_uv[0], tf_uv[1]));
253
332
ang1 = RAD2DEG(angle_v3v3v3(efa->v4->co, efa->v1->co, efa->v2->co));
255
uvang2 = RAD2DEG(angle_v2v2v2(tf_uv[0], tf_uv[1], tf_uv[2]));
256
ang2 = RAD2DEG(angle_v3v3v3(efa->v1->co, efa->v2->co, efa->v3->co));
258
uvang3 = RAD2DEG(angle_v2v2v2(tf_uv[1], tf_uv[2], tf_uv[3]));
259
ang3 = RAD2DEG(angle_v3v3v3(efa->v2->co, efa->v3->co, efa->v4->co));
261
uvang4 = RAD2DEG(angle_v2v2v2(tf_uv[2], tf_uv[3], tf_uv[0]));
262
ang4 = RAD2DEG(angle_v3v3v3(efa->v3->co, efa->v4->co, efa->v1->co));
266
VECSUB2D(av1, tf_uv[3], tf_uv[0]); normalize_v2(av1);
267
VECSUB2D(av2, tf_uv[0], tf_uv[1]); normalize_v2(av2);
268
VECSUB2D(av3, tf_uv[1], tf_uv[2]); normalize_v2(av3);
269
VECSUB2D(av4, tf_uv[2], tf_uv[3]); normalize_v2(av4);
271
/* This is the correct angle however we are only comparing angles
272
* uvang1 = 90-((angle_normalized_v2v2(av1, av2) * 180.0/M_PI)-90);*/
273
uvang1 = angle_normalized_v2v2(av1, av2)*180.0/M_PI;
274
uvang2 = angle_normalized_v2v2(av2, av3)*180.0/M_PI;
275
uvang3 = angle_normalized_v2v2(av3, av4)*180.0/M_PI;
276
uvang4 = angle_normalized_v2v2(av4, av1)*180.0/M_PI;
279
VECSUB(av1, efa->v4->co, efa->v1->co); normalize_v3(av1);
280
VECSUB(av2, efa->v1->co, efa->v2->co); normalize_v3(av2);
281
VECSUB(av3, efa->v2->co, efa->v3->co); normalize_v3(av3);
282
VECSUB(av4, efa->v3->co, efa->v4->co); normalize_v3(av4);
284
/* This is the correct angle however we are only comparing angles
285
* ang1 = 90-((angle_normalized_v3v3(av1, av2) * 180.0/M_PI)-90);*/
286
ang1 = angle_normalized_v3v3(av1, av2)*180.0/M_PI;
287
ang2 = angle_normalized_v3v3(av2, av3)*180.0/M_PI;
288
ang3 = angle_normalized_v3v3(av3, av4)*180.0/M_PI;
289
ang4 = angle_normalized_v3v3(av4, av1)*180.0/M_PI;
293
/* This simple makes the angles display worse then they really are ;)
294
* 1.0-pow((1.0-a), 2) */
296
a = fabs(uvang1-ang1)/180.0;
297
weight_to_rgb(1.0-pow((1.0-a), 2), col, col+1, col+2);
299
glVertex2fv(tf->uv[0]);
300
a = fabs(uvang2-ang2)/180.0;
301
weight_to_rgb(1.0-pow((1.0-a), 2), col, col+1, col+2);
303
glVertex2fv(tf->uv[1]);
304
a = fabs(uvang3-ang3)/180.0;
305
weight_to_rgb(1.0-pow((1.0-a), 2), col, col+1, col+2);
307
glVertex2fv(tf->uv[2]);
308
a = fabs(uvang4-ang4)/180.0;
309
weight_to_rgb(1.0-pow((1.0-a), 2), col, col+1, col+2);
311
glVertex2fv(tf->uv[3]);
334
uvang[i] = angle_normalized_v2v2(auv[i], auv[(i + 1) % nverts]);
335
ang[i] = angle_normalized_v3v3(av[i], av[(i + 1) % nverts]);
315
#if 0 /* Simple but slow, better reuse normalized vectors */
316
uvang1 = RAD2DEG(angle_v2v2v2(tf_uv[2], tf_uv[0], tf_uv[1]));
317
ang1 = RAD2DEG(angle_v3v3v3(efa->v3->co, efa->v1->co, efa->v2->co));
319
uvang2 = RAD2DEG(angle_v2v2v2(tf_uv[0], tf_uv[1], tf_uv[2]));
320
ang2 = RAD2DEG(angle_v3v3v3(efa->v1->co, efa->v2->co, efa->v3->co));
322
uvang3 = M_PI-(uvang1+uvang2);
323
ang3 = M_PI-(ang1+ang2);
327
VECSUB2D(av1, tf_uv[2], tf_uv[0]); normalize_v2(av1);
328
VECSUB2D(av2, tf_uv[0], tf_uv[1]); normalize_v2(av2);
329
VECSUB2D(av3, tf_uv[1], tf_uv[2]); normalize_v2(av3);
331
/* This is the correct angle however we are only comparing angles
332
* uvang1 = 90-((angle_normalized_v2v2(av1, av2) * 180.0/M_PI)-90); */
333
uvang1 = angle_normalized_v2v2(av1, av2)*180.0/M_PI;
334
uvang2 = angle_normalized_v2v2(av2, av3)*180.0/M_PI;
335
uvang3 = angle_normalized_v2v2(av3, av1)*180.0/M_PI;
338
VECSUB(av1, efa->v3->co, efa->v1->co); normalize_v3(av1);
339
VECSUB(av2, efa->v1->co, efa->v2->co); normalize_v3(av2);
340
VECSUB(av3, efa->v2->co, efa->v3->co); normalize_v3(av3);
341
/* This is the correct angle however we are only comparing angles
342
* ang1 = 90-((angle_normalized_v3v3(av1, av2) * 180.0/M_PI)-90); */
343
ang1 = angle_normalized_v3v3(av1, av2)*180.0/M_PI;
344
ang2 = angle_normalized_v3v3(av2, av3)*180.0/M_PI;
345
ang3 = angle_normalized_v3v3(av3, av1)*180.0/M_PI;
347
/* This simple makes the angles display worse then they really are ;)
348
* 1.0-pow((1.0-a), 2) */
350
glBegin(GL_TRIANGLES);
351
a = fabs(uvang1-ang1)/180.0;
352
weight_to_rgb(1.0-pow((1.0-a), 2), col, col+1, col+2);
354
glVertex2fv(tf->uv[0]);
355
a = fabs(uvang2-ang2)/180.0;
356
weight_to_rgb(1.0-pow((1.0-a), 2), col, col+1, col+2);
358
glVertex2fv(tf->uv[1]);
359
a = fabs(uvang3-ang3)/180.0;
360
weight_to_rgb(1.0-pow((1.0-a), 2), col, col+1, col+2);
362
glVertex2fv(tf->uv[2]);
339
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
340
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
341
a = fabsf(uvang[i] - ang[i]) / (float)M_PI;
342
weight_to_rgb(col, 1.0f - powf((1.0f - a), 2.0f));
344
glVertex2fv(luv->uv);
351
BM_elem_flag_disable(efa, BM_ELEM_TAG);
373
355
glShadeModel(GL_FLAT);
357
BLI_array_free(uvang);
366
BLI_array_free(tf_uv);
367
BLI_array_free(tf_uvorig);
379
static void draw_uvs_other(SpaceImage *sima, Scene *scene, Object *obedit, MTFace *activetf)
370
static void draw_uvs_other(Scene *scene, Object *obedit, Image *curimage)
384
curimage= (activetf)? activetf->tpage: NULL;
386
374
glColor3ub(96, 96, 96);
388
for(base=scene->base.first; base; base=base->next) {
389
Object *ob= base->object;
391
if(!(base->flag & SELECT)) continue;
392
if(!(base->lay & scene->lay)) continue;
393
if(ob->restrictflag & OB_RESTRICT_VIEW) continue;
395
if((ob->type==OB_MESH) && (ob!=obedit)) {
399
MFace *mface= me->mface;
400
MTFace *tface= me->mtface;
403
for(a=me->totface; a>0; a--, tface++, mface++) {
404
if(tface->tpage == curimage) {
376
for (base = scene->base.first; base; base = base->next) {
377
Object *ob = base->object;
379
if (!(base->flag & SELECT)) continue;
380
if (!(base->lay & scene->lay)) continue;
381
if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
383
if ((ob->type == OB_MESH) && (ob != obedit)) {
387
MPoly *mpoly = me->mpoly;
388
MTexPoly *mtpoly = me->mtpoly;
392
for (a = me->totpoly; a > 0; a--, mtpoly++, mpoly++) {
393
if (mtpoly->tpage == curimage) {
405
394
glBegin(GL_LINE_LOOP);
406
glVertex2fv(tface->uv[0]);
407
glVertex2fv(tface->uv[1]);
408
glVertex2fv(tface->uv[2]);
409
if(mface->v4) glVertex2fv(tface->uv[3]);
396
mloopuv = me->mloopuv + mpoly->loopstart;
397
for (b = 0; b < mpoly->totloop; b++, mloopuv++) {
398
glVertex2fv(mloopuv->uv);
408
static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob)
411
Image *curimage = ED_space_image(sima);
413
if (sima->flag & SI_DRAW_OTHER)
414
draw_uvs_other(scene, ob, curimage);
416
glColor3ub(112, 112, 112);
419
MPoly *mpoly = me->mpoly;
420
MTexPoly *tface = me->mtpoly;
424
for (a = me->totpoly; a > 0; a--, tface++, mpoly++) {
425
if (tface->tpage == curimage) {
426
glBegin(GL_LINE_LOOP);
428
mloopuv = me->mloopuv + mpoly->loopstart;
429
for (b = 0; b < mpoly->totloop; b++, mloopuv++) {
430
glVertex2fv(mloopuv->uv);
418
438
/* draws uv's in the image space */
419
439
static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
421
441
ToolSettings *ts;
422
Mesh *me= obedit->data;
424
EditFace *efa, *efa_act;
425
MTFace *tf, *activetf = NULL;
442
Mesh *me = obedit->data;
443
BMEditMesh *em = me->edit_btmesh;
445
BMFace *efa, *efa_act, *activef;
448
MTexPoly *tf, *activetf = NULL;
426
450
DerivedMesh *finaldm, *cagedm;
427
char col1[4], col2[4];
451
unsigned char col1[4], col2[4];
429
int drawfaces, interpedges, lastsel, sel;
430
Image *ima= sima->image;
432
em= BKE_mesh_get_editmesh(me);
433
activetf= EM_get_active_mtface(em, &efa_act, NULL, 0); /* will be set to NULL if hidden */
435
ts= scene->toolsettings;
437
drawfaces= draw_uvs_face_check(scene);
438
if(ts->uv_flag & UV_SYNC_SELECTION)
439
interpedges= (ts->selectmode & SCE_SELECT_VERTEX);
453
int drawfaces, interpedges;
454
Image *ima = sima->image;
456
StitchPreviewer *stitch_preview = uv_get_stitch_previewer();
458
activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE); /* will be set to NULL if hidden */
459
activef = BM_active_face_get(bm, FALSE);
460
ts = scene->toolsettings;
462
drawfaces = draw_uvs_face_check(scene);
463
if (ts->uv_flag & UV_SYNC_SELECTION)
464
interpedges = (ts->selectmode & SCE_SELECT_VERTEX);
441
interpedges= (ts->uv_selectmode == UV_SELECT_VERTEX);
466
interpedges = (ts->uv_selectmode == UV_SELECT_VERTEX);
443
468
/* draw other uvs */
444
if(sima->flag & SI_DRAW_OTHER)
445
draw_uvs_other(sima, scene, obedit, activetf);
469
if (sima->flag & SI_DRAW_OTHER) {
470
Image *curimage = (activetf) ? activetf->tpage : NULL;
472
draw_uvs_other(scene, obedit, curimage);
447
475
/* 1. draw shadow mesh */
449
if(sima->flag & SI_DRAWSHADOW) {
477
if (sima->flag & SI_DRAWSHADOW) {
450
478
/* first try existing derivedmesh */
451
if(!draw_uvs_dm_shadow(em->derivedFinal)) {
479
if (!draw_uvs_dm_shadow(em->derivedFinal)) {
452
480
/* create one if it does not exist */
453
cagedm = editmesh_get_derived_cage_and_final(scene, obedit, em, &finaldm, CD_MASK_BAREMESH|CD_MASK_MTFACE);
481
cagedm = editbmesh_get_derived_cage_and_final(scene, obedit, me->edit_btmesh, &finaldm, CD_MASK_BAREMESH | CD_MASK_MTFACE);
455
483
/* when sync selection is enabled, all faces are drawn (except for hidden)
456
484
* so if cage is the same as the final, theres no point in drawing this */
457
if(!((ts->uv_flag & UV_SYNC_SELECTION) && (cagedm == finaldm)))
485
if (!((ts->uv_flag & UV_SYNC_SELECTION) && (cagedm == finaldm)))
458
486
draw_uvs_dm_shadow(finaldm);
460
488
/* release derivedmesh again */
461
if(cagedm != finaldm) cagedm->release(cagedm);
489
if (cagedm != finaldm) cagedm->release(cagedm);
462
490
finaldm->release(finaldm);
466
494
/* 2. draw colored faces */
468
if(sima->flag & SI_DRAW_STRETCH) {
496
if (sima->flag & SI_DRAW_STRETCH) {
469
497
draw_uvs_stretch(sima, scene, em, activetf);
471
else if(me->drawflag & ME_DRAWFACES) {
499
else if (!(sima->flag & SI_NO_DRAWFACES)) {
472
500
/* draw transparent faces */
473
501
UI_GetThemeColor4ubv(TH_FACE, col1);
474
502
UI_GetThemeColor4ubv(TH_FACE_SELECT, col2);
475
503
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
476
504
glEnable(GL_BLEND);
478
for(efa= em->faces.first; efa; efa= efa->next) {
479
tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
506
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
507
tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
481
if(uvedit_face_visible(scene, ima, efa, tf)) {
483
if(tf==activetf) continue; /* important the temp pointer is set above */
509
if (uvedit_face_visible_test(scene, ima, efa, tf)) {
510
BM_elem_flag_enable(efa, BM_ELEM_TAG);
511
if (tf == activetf) continue; /* important the temp boolean is set above */
485
if(uvedit_face_selected(scene, efa, tf))
513
if (uvedit_face_select_test(scene, em, efa))
486
514
glColor4ubv((GLubyte *)col2);
488
516
glColor4ubv((GLubyte *)col1);
490
glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
491
glVertex2fv(tf->uv[0]);
492
glVertex2fv(tf->uv[1]);
493
glVertex2fv(tf->uv[2]);
494
if(efa->v4) glVertex2fv(tf->uv[3]);
519
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
520
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
521
glVertex2fv(luv->uv);
528
BM_elem_flag_disable(efa, BM_ELEM_TAG);
503
531
glDisable(GL_BLEND);
506
534
/* would be nice to do this within a draw loop but most below are optional, so it would involve too many checks */
507
for(efa= em->faces.first; efa; efa= efa->next) {
508
tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
536
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
537
tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
510
if(uvedit_face_visible(scene, ima, efa, tf)) {
539
if (uvedit_face_visible_test(scene, ima, efa, tf)) {
540
BM_elem_flag_enable(efa, BM_ELEM_TAG);
545
BM_elem_flag_disable(efa, BM_ELEM_TAG);
522
551
/* 3. draw active face stippled */
526
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
527
UI_ThemeColor4(TH_EDITMESH_ACTIVE);
529
glEnable(GL_POLYGON_STIPPLE);
530
glPolygonStipple(stipple_quarttone);
532
glBegin(efa_act->v4? GL_QUADS: GL_TRIANGLES);
533
glVertex2fv(activetf->uv[0]);
534
glVertex2fv(activetf->uv[1]);
535
glVertex2fv(activetf->uv[2]);
536
if(efa_act->v4) glVertex2fv(activetf->uv[3]);
539
glDisable(GL_POLYGON_STIPPLE);
554
tf = CustomData_bmesh_get(&bm->pdata, activef->head.data, CD_MTEXPOLY);
555
if (uvedit_face_visible_test(scene, ima, activef, tf)) {
557
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
558
UI_ThemeColor4(TH_EDITMESH_ACTIVE);
560
glEnable(GL_POLYGON_STIPPLE);
561
glPolygonStipple(stipple_quarttone);
564
BM_ITER_ELEM (l, &liter, activef, BM_LOOPS_OF_FACE) {
565
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
566
glVertex2fv(luv->uv);
570
glDisable(GL_POLYGON_STIPPLE);
543
575
/* 4. draw edges */
545
if(sima->flag & SI_SMOOTH_UV) {
577
if (sima->flag & SI_SMOOTH_UV) {
546
578
glEnable(GL_LINE_SMOOTH);
547
579
glEnable(GL_BLEND);
548
580
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
551
switch(sima->dt_uv) {
583
switch (sima->dt_uv) {
552
584
case SI_UVDT_DASH:
553
for(efa= em->faces.first; efa; efa= efa->next) {
554
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
585
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
586
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
588
tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
559
593
glBegin(GL_LINE_LOOP);
560
glVertex2fv(tf->uv[0]);
561
glVertex2fv(tf->uv[1]);
562
glVertex2fv(tf->uv[2]);
563
if(efa->v4) glVertex2fv(tf->uv[3]);
594
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
595
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
596
glVertex2fv(luv->uv);
569
glBegin(GL_LINE_STRIP);
570
glVertex2fv(tf->uv[0]);
571
glVertex2fv(tf->uv[1]);
574
glBegin(GL_LINE_STRIP);
575
glVertex2fv(tf->uv[0]);
576
if(efa->v4) glVertex2fv(tf->uv[3]);
577
else glVertex2fv(tf->uv[2]);
580
glBegin(GL_LINE_STRIP);
581
glVertex2fv(tf->uv[1]);
582
glVertex2fv(tf->uv[2]);
583
if(efa->v4) glVertex2fv(tf->uv[3]);
603
glBegin(GL_LINE_LOOP);
604
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
605
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
606
glVertex2fv(luv->uv);
611
glBegin(GL_LINE_STRIP);
612
luv = CustomData_bmesh_get(&bm->ldata, efa->lbase->head.data, CD_MLOOPUV);
613
glVertex2fv(luv->uv);
614
luv = CustomData_bmesh_get(&bm->ldata, efa->lbase->next->head.data, CD_MLOOPUV);
615
glVertex2fv(luv->uv);
590
623
case SI_UVDT_BLACK: /* black/white */
591
624
case SI_UVDT_WHITE:
592
if(sima->dt_uv==SI_UVDT_WHITE) glColor3f(1.0f, 1.0f, 1.0f);
625
if (sima->dt_uv == SI_UVDT_WHITE) glColor3f(1.0f, 1.0f, 1.0f);
593
626
else glColor3f(0.0f, 0.0f, 0.0f);
595
for(efa= em->faces.first; efa; efa= efa->next) {
596
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
628
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
629
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
599
glBegin(GL_LINE_LOOP);
600
glVertex2fv(tf->uv[0]);
601
glVertex2fv(tf->uv[1]);
602
glVertex2fv(tf->uv[2]);
603
if(efa->v4) glVertex2fv(tf->uv[3]);
632
glBegin(GL_LINE_LOOP);
633
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
634
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
635
glVertex2fv(luv->uv);
608
640
case SI_UVDT_OUTLINE:
612
for(efa= em->faces.first; efa; efa= efa->next) {
613
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
644
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
645
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
616
glBegin(GL_LINE_LOOP);
617
glVertex2fv(tf->uv[0]);
618
glVertex2fv(tf->uv[1]);
619
glVertex2fv(tf->uv[2]);
620
if(efa->v4) glVertex2fv(tf->uv[3]);
648
glBegin(GL_LINE_LOOP);
649
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
650
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
651
glVertex2fv(luv->uv);
626
657
col2[0] = col2[1] = col2[2] = 192; col2[3] = 255;
627
658
glColor4ubv((unsigned char *)col2);
629
if(me->drawflag & ME_DRAWEDGES) {
660
if (me->drawflag & ME_DRAWEDGES) {
661
int sel, lastsel = -1;
630
662
UI_GetThemeColor4ubv(TH_VERTEX_SELECT, col1);
634
665
glShadeModel(GL_SMOOTH);
636
for(efa= em->faces.first; efa; efa= efa->next) {
637
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
640
glBegin(GL_LINE_LOOP);
641
sel = (uvedit_uv_selected(scene, efa, tf, 0)? 1 : 0);
642
if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; }
643
glVertex2fv(tf->uv[0]);
645
sel = uvedit_uv_selected(scene, efa, tf, 1)? 1 : 0;
646
if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; }
647
glVertex2fv(tf->uv[1]);
649
sel = uvedit_uv_selected(scene, efa, tf, 2)? 1 : 0;
650
if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; }
651
glVertex2fv(tf->uv[2]);
654
sel = uvedit_uv_selected(scene, efa, tf, 3)? 1 : 0;
655
if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; }
656
glVertex2fv(tf->uv[3]);
667
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
668
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
671
glBegin(GL_LINE_LOOP);
672
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
673
sel = (uvedit_uv_select_test(em, scene, l) ? 1 : 0);
674
glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2);
676
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
677
glVertex2fv(luv->uv);
663
682
glShadeModel(GL_FLAT);
666
for(efa= em->faces.first; efa; efa= efa->next) {
667
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
671
sel = (uvedit_edge_selected(scene, efa, tf, 0)? 1 : 0);
672
if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; }
673
glVertex2fv(tf->uv[0]);
674
glVertex2fv(tf->uv[1]);
676
sel = uvedit_edge_selected(scene, efa, tf, 1)? 1 : 0;
677
if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; }
678
glVertex2fv(tf->uv[1]);
679
glVertex2fv(tf->uv[2]);
681
sel = uvedit_edge_selected(scene, efa, tf, 2)? 1 : 0;
682
if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; }
683
glVertex2fv(tf->uv[2]);
686
glVertex2fv(tf->uv[3]);
688
sel = uvedit_edge_selected(scene, efa, tf, 3)? 1 : 0;
689
if(sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; }
690
glVertex2fv(tf->uv[3]);
685
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
686
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
690
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
691
sel = (uvedit_edge_select_test(em, scene, l) ? 1 : 0);
692
if (sel != lastsel) {
693
glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2);
693
glVertex2fv(tf->uv[0]);
696
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
697
glVertex2fv(luv->uv);
698
luv = CustomData_bmesh_get(&bm->ldata, l->next->head.data, CD_MLOOPUV);
699
glVertex2fv(luv->uv);
701
706
/* no nice edges */
702
for(efa= em->faces.first; efa; efa= efa->next) {
703
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
706
glBegin(GL_LINE_LOOP);
707
glVertex2fv(tf->uv[0]);
708
glVertex2fv(tf->uv[1]);
709
glVertex2fv(tf->uv[2]);
710
if(efa->v4) glVertex2fv(tf->uv[3]);
707
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
708
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
711
glBegin(GL_LINE_LOOP);
712
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
713
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
714
glVertex2fv(luv->uv);
719
if(sima->flag & SI_SMOOTH_UV) {
723
if (sima->flag & SI_SMOOTH_UV) {
720
724
glDisable(GL_LINE_SMOOTH);
721
725
glDisable(GL_BLEND);
724
728
/* 5. draw face centers */
729
733
pointsize = UI_GetThemeValuef(TH_FACEDOT_SIZE);
761
767
/* 6. draw uv vertices */
763
if(drawfaces != 2) { /* 2 means Mesh Face Mode */
769
if (drawfaces != 2) { /* 2 means Mesh Face Mode */
764
770
/* unselected uvs */
765
771
UI_ThemeColor(TH_VERTEX);
766
772
pointsize = UI_GetThemeValuef(TH_VERTEX_SIZE);
767
773
glPointSize(pointsize);
769
775
bglBegin(GL_POINTS);
770
for(efa= em->faces.first; efa; efa= efa->next) {
771
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
776
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
777
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
774
if(!uvedit_uv_selected(scene, efa, tf, 0))
775
bglVertex2fv(tf->uv[0]);
776
if(!uvedit_uv_selected(scene, efa, tf, 1))
777
bglVertex2fv(tf->uv[1]);
778
if(!uvedit_uv_selected(scene, efa, tf, 2))
779
bglVertex2fv(tf->uv[2]);
780
if(efa->v4 && !uvedit_uv_selected(scene, efa, tf, 3))
781
bglVertex2fv(tf->uv[3]);
780
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
781
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
782
if (!uvedit_uv_select_test(em, scene, l))
783
bglVertex2fv(luv->uv);
787
789
/* give odd pointsizes odd pin pointsizes */
788
glPointSize(pointsize*2 + (((int)pointsize % 2)? (-1): 0));
790
glPointSize(pointsize * 2 + (((int)pointsize % 2) ? (-1) : 0));
791
793
bglBegin(GL_POINTS);
792
for(efa= em->faces.first; efa; efa= efa->next) {
793
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
796
if(tf->unwrap & TF_PIN1)
797
bglVertex2fv(tf->uv[0]);
798
if(tf->unwrap & TF_PIN2)
799
bglVertex2fv(tf->uv[1]);
800
if(tf->unwrap & TF_PIN3)
801
bglVertex2fv(tf->uv[2]);
802
if(efa->v4 && (tf->unwrap & TF_PIN4))
803
bglVertex2fv(tf->uv[3]);
794
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
795
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
798
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
799
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
801
if (luv->flag & MLOOPUV_PINNED)
802
bglVertex2fv(luv->uv);
810
809
glPointSize(pointsize);
812
811
bglBegin(GL_POINTS);
813
for(efa= em->faces.first; efa; efa= efa->next) {
814
tf= (MTFace *)efa->tmp.p; /* visible faces cached */
817
if(uvedit_uv_selected(scene, efa, tf, 0))
818
bglVertex2fv(tf->uv[0]);
819
if(uvedit_uv_selected(scene, efa, tf, 1))
820
bglVertex2fv(tf->uv[1]);
821
if(uvedit_uv_selected(scene, efa, tf, 2))
822
bglVertex2fv(tf->uv[2]);
823
if(efa->v4 && uvedit_uv_selected(scene, efa, tf, 3))
824
bglVertex2fv(tf->uv[3]);
812
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
813
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
816
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
817
luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
819
if (uvedit_uv_select_test(em, scene, l))
820
bglVertex2fv(luv->uv);
826
/* finally draw stitch preview */
827
if (stitch_preview) {
829
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
830
glEnableClientState(GL_VERTEX_ARRAY);
834
UI_ThemeColor4(TH_STITCH_PREVIEW_ACTIVE);
835
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
836
glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_tris);
837
glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_static_tris * 3);
839
glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_polys);
840
for (i = 0; i < stitch_preview->num_polys; i++) {
841
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
842
UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
843
glDrawArrays(GL_POLYGON, index, stitch_preview->uvs_per_polygon[i]);
844
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
845
UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
846
glDrawArrays(GL_POLYGON, index, stitch_preview->uvs_per_polygon[i]);
848
index += stitch_preview->uvs_per_polygon[i];
850
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
852
UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
853
glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris * 3);
857
/* draw vert preview */
858
glPointSize(pointsize * 2.0);
859
UI_ThemeColor4(TH_STITCH_PREVIEW_STITCHABLE);
860
glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_stitchable);
861
glDrawArrays(GL_POINTS, 0, stitch_preview->num_stitchable);
863
UI_ThemeColor4(TH_STITCH_PREVIEW_UNSTITCHABLE);
864
glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_unstitchable);
865
glDrawArrays(GL_POINTS, 0, stitch_preview->num_unstitchable);
868
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
830
871
glPointSize(1.0);
831
BKE_mesh_end_editmesh(obedit->data, em);
834
void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedit)
874
void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedit, Object *obact)
836
int show_uvedit, show_uvshadow;
838
show_uvedit= ED_space_image_show_uvedit(sima, obedit);
839
show_uvshadow= ED_space_image_show_uvshadow(sima, obedit);
841
if(show_uvedit || show_uvshadow) {
843
draw_uvs_shadow(sima, obedit);
876
ToolSettings *toolsettings = scene->toolsettings;
877
int show_uvedit, show_uvshadow, show_texpaint_uvshadow;
879
show_texpaint_uvshadow = (obact && obact->type == OB_MESH && obact->mode == OB_MODE_TEXTURE_PAINT);
880
show_uvedit = ED_space_image_show_uvedit(sima, obedit);
881
show_uvshadow = ED_space_image_show_uvshadow(sima, obedit);
883
if (show_uvedit || show_uvshadow || show_texpaint_uvshadow) {
885
draw_uvs_shadow(obedit);
886
else if (show_uvedit)
845
887
draw_uvs(sima, scene, obedit);
889
draw_uvs_texpaint(sima, scene, obact);
891
if (show_uvedit && !(toolsettings->use_uv_sculpt))
848
892
drawcursor_sima(sima, ar);