~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/uvedit/uvedit_draw.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: uvedit_draw.c 28202 2010-04-15 10:28:32Z blendix $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
25
23
 * ***** END GPL LICENSE BLOCK *****
26
24
 */
27
25
 
 
26
/** \file blender/editors/uvedit/uvedit_draw.c
 
27
 *  \ingroup eduv
 
28
 */
 
29
 
 
30
 
28
31
#include <float.h>
29
32
#include <math.h>
30
33
#include <stdlib.h>
31
 
 
 
34
#include <string.h>
 
35
 
 
36
#include "MEM_guardedalloc.h"
 
37
 
 
38
#include "DNA_mesh_types.h"
32
39
#include "DNA_meshdata_types.h"
33
40
#include "DNA_object_types.h"
34
41
#include "DNA_scene_types.h"
35
42
#include "DNA_screen_types.h"
36
43
#include "DNA_space_types.h"
37
44
 
38
 
#include "BKE_customdata.h"
 
45
#include "BLI_math.h"
 
46
#include "BLI_utildefines.h"
 
47
 
39
48
#include "BKE_DerivedMesh.h"
40
49
#include "BKE_mesh.h"
41
 
#include "BKE_object.h"
42
 
#include "BKE_utildefines.h"
 
50
#include "BKE_tessmesh.h"
43
51
 
44
 
#include "BLI_math.h"
45
 
#include "BLI_editVert.h"
 
52
#include "BLI_array.h"
46
53
 
47
54
#include "BIF_gl.h"
48
55
#include "BIF_glutil.h"
49
56
 
 
57
#include "ED_util.h"
50
58
#include "ED_image.h"
51
59
#include "ED_mesh.h"
 
60
#include "ED_uvedit.h"
52
61
 
53
62
#include "UI_resources.h"
54
63
 
62
71
        ED_space_image_size(sima, &width, &height);
63
72
        ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
64
73
 
65
 
        w= zoomx*width/256.0f;
66
 
        h= zoomy*height/256.0f;
 
74
        w = zoomx * width / 256.0f;
 
75
        h = zoomy * height / 256.0f;
67
76
        
68
77
        cpack(0xFFFFFF);
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);
74
 
        
 
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);
 
83
 
75
84
        setlinestyle(4);
76
85
        cpack(0xFF);
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);
81
 
        
82
 
        
83
 
        setlinestyle(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);
 
90
 
 
91
 
 
92
        setlinestyle(0.0f);
84
93
        cpack(0x0);
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);
89
 
        
 
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);
 
98
 
90
99
        setlinestyle(1);
91
100
        cpack(0xFFFFFF);
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);
96
 
        
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);
 
105
 
 
106
        glTranslatef(-sima->cursor[0], -sima->cursor[1], 0.0);
98
107
        setlinestyle(0);
99
108
}
100
109
 
101
110
static int draw_uvs_face_check(Scene *scene)
102
111
{
103
 
        ToolSettings *ts= scene->toolsettings;
 
112
        ToolSettings *ts = scene->toolsettings;
104
113
 
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)
108
117
                        return 2;
109
 
                else if(ts->selectmode & SCE_SELECT_FACE)
 
118
                else if (ts->selectmode & SCE_SELECT_FACE)
110
119
                        return 1;
111
120
                else
112
121
                        return 0;
115
124
                return (ts->uv_selectmode == UV_SELECT_FACE);
116
125
}
117
126
 
118
 
static void draw_uvs_shadow(SpaceImage *sima, Object *obedit)
 
127
static void draw_uvs_shadow(Object *obedit)
119
128
{
120
 
        EditMesh *em;
121
 
        EditFace *efa;
122
 
        MTFace *tf;
123
 
        
124
 
        em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
 
129
        BMEditMesh *em = BMEdit_FromObject(obedit);
 
130
        BMesh *bm = em->bm;
 
131
        BMFace *efa;
 
132
        BMLoop *l;
 
133
        BMIter iter, liter;
 
134
        MLoopUV *luv;
125
135
 
126
136
        /* draws the grey mesh when painting */
127
137
        glColor3ub(112, 112, 112);
128
138
 
129
 
        for(efa= em->faces.first; efa; efa= efa->next) {
130
 
                tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
131
 
 
 
139
        BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
132
140
                glBegin(GL_LINE_LOOP);
133
 
                        glVertex2fv(tf->uv[0]);
134
 
                        glVertex2fv(tf->uv[1]);
135
 
                        glVertex2fv(tf->uv[2]);
136
 
                        if(efa->v4) glVertex2fv(tf->uv[3]);
 
141
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 
142
                        luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
 
143
 
 
144
                        glVertex2fv(luv->uv);
 
145
                }
137
146
                glEnd();
138
147
        }
139
 
 
140
 
        BKE_mesh_end_editmesh(obedit->data, em);
141
148
}
142
149
 
143
150
static int draw_uvs_dm_shadow(DerivedMesh *dm)
144
151
{
145
152
        /* draw shadow mesh - this is the mesh with the modifier applied */
146
153
 
147
 
        if(dm && dm->drawUVEdges && CustomData_has_layer(&dm->faceData, CD_MTFACE)) {
 
154
        if (dm && dm->drawUVEdges && CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) {
148
155
                glColor3ub(112, 112, 112);
149
156
                dm->drawUVEdges(dm);
150
157
                return 1;
153
160
        return 0;
154
161
}
155
162
 
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)
157
164
{
158
 
        EditFace *efa;
159
 
        MTFace *tf;
160
 
        Image *ima= sima->image;
161
 
        float aspx, aspy, col[4], tf_uv[4][2];
162
 
        
 
165
        BMesh *bm = em->bm;
 
166
        BMFace *efa;
 
167
        BMLoop *l;
 
168
        BMIter iter, liter;
 
169
        MTexPoly *tf;
 
170
        MLoopUV *luv;
 
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;
 
175
        int i, j, nverts;
 
176
 
163
177
        ED_space_image_uv_aspect(sima, &aspx, &aspy);
164
178
        
165
 
        switch(sima->dt_uvstretch) {
 
179
        switch (sima->dt_uvstretch) {
166
180
                case SI_UVDT_STRETCH_AREA:
167
181
                {
168
 
                        float totarea=0.0f, totuvarea=0.0f, areadiff, uvarea, area;
 
182
                        float totarea = 0.0f, totuvarea = 0.0f, areadiff, uvarea, area;
169
183
                        
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);
173
 
 
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);
 
186
                                
 
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);
 
191
 
 
192
                                i = 0;
 
193
                                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 
194
                                        luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
 
195
 
 
196
                                        copy_v2_v2(tf_uvorig[i], luv->uv);
 
197
 
 
198
                                        i++;
 
199
                                }
 
200
 
 
201
                                poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa->len);
 
202
 
 
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);
177
206
                                
178
 
                                if(uvedit_face_visible(scene, ima, efa, tf)) {
179
 
                                        efa->tmp.p = tf;
 
207
                                if (uvedit_face_visible_test(scene, ima, efa, tf)) {
 
208
                                        BM_elem_flag_enable(efa, BM_ELEM_TAG);
180
209
                                }
181
210
                                else {
182
 
                                        if(tf == activetf)
183
 
                                                activetf= NULL;
184
 
                                        efa->tmp.p = NULL;
 
211
                                        if (tf == activetf)
 
212
                                                activetf = NULL;
 
213
                                        BM_elem_flag_disable(efa, BM_ELEM_TAG);
185
214
                                }
186
215
                        }
187
216
                        
188
 
                        if(totarea < FLT_EPSILON || totuvarea < FLT_EPSILON) {
 
217
                        if (totarea < FLT_EPSILON || totuvarea < FLT_EPSILON) {
189
218
                                col[0] = 1.0;
190
219
                                col[1] = col[2] = 0.0;
191
220
                                glColor3fv(col);
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)) {
 
223
                                                glBegin(GL_POLYGON);
 
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);
 
227
                                                }
199
228
                                                glEnd();
200
229
                                        }
201
230
                                }
202
231
                        }
203
232
                        else {
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;
 
236
 
 
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);
 
241
 
 
242
                                                i = 0;
 
243
                                                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 
244
                                                        luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
 
245
 
 
246
                                                        copy_v2_v2(tf_uvorig[i], luv->uv);
 
247
 
 
248
                                                        i++;
 
249
                                                }
 
250
 
 
251
                                                poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa->len);
 
252
 
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;
210
255
                                                
211
 
                                                if(area < FLT_EPSILON || uvarea < FLT_EPSILON)
212
 
                                                        areadiff = 1.0;
213
 
                                                else if(area>uvarea)
214
 
                                                        areadiff = 1.0-(uvarea/area);
 
256
                                                if (area < FLT_EPSILON || uvarea < FLT_EPSILON)
 
257
                                                        areadiff = 1.0f;
 
258
                                                else if (area > uvarea)
 
259
                                                        areadiff = 1.0f - (uvarea / area);
215
260
                                                else
216
 
                                                        areadiff = 1.0-(area/uvarea);
 
261
                                                        areadiff = 1.0f - (area / uvarea);
217
262
                                                
218
 
                                                weight_to_rgb(areadiff, col, col+1, col+2);
 
263
                                                weight_to_rgb(col, areadiff);
219
264
                                                glColor3fv(col);
220
265
                                                
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]);
 
266
                                                glBegin(GL_POLYGON);
 
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);
 
270
                                                }
226
271
                                                glEnd();
227
272
                                        }
228
273
                                }
231
276
                }
232
277
                case SI_UVDT_STRETCH_ANGLE:
233
278
                {
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 */
 
279
                        float *uvang = NULL;
 
280
                        float *ang = NULL;
 
281
                        float (*av)[3] = NULL;  /* use for 2d and 3d  angle vectors */
 
282
                        float (*auv)[2] = NULL;
237
283
                        float a;
238
 
                        
 
284
 
 
285
                        BLI_array_declare(uvang);
 
286
                        BLI_array_declare(ang);
 
287
                        BLI_array_declare(av);
 
288
                        BLI_array_declare(auv);
 
289
 
239
290
                        col[3] = 0.5; /* hard coded alpha, not that nice */
240
291
                        
241
292
                        glShadeModel(GL_SMOOTH);
242
293
                        
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);
245
296
                                
246
 
                                if(uvedit_face_visible(scene, ima, efa, tf)) {
247
 
                                        efa->tmp.p = tf;
248
 
                                        uv_copy_aspect(tf->uv, tf_uv, aspx, aspy);
249
 
                                        if(efa->v4) {
250
 
                                                
251
 
#if 0                                           /* Simple but slow, better reuse normalized vectors */
 
297
                                if (uvedit_face_visible_test(scene, ima, efa, tf)) {
 
298
                                        nverts = efa->len;
 
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);
 
304
                                        BLI_array_empty(av);
 
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);
 
312
 
 
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);
 
316
                                        }
 
317
 
 
318
                                        poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, nverts);
 
319
 
 
320
                                        j = nverts - 1;
 
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]);
 
324
                                                j = i;
 
325
                                        }
 
326
 
 
327
                                        for (i = 0; i < nverts; i++) {
 
328
#if 0
 
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));
254
 
                                                
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));
257
 
                                                
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));
260
 
                                                
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));
263
333
#endif
264
 
                                                
265
 
                                                /* uv angles */
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);
270
 
                                                
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;
277
 
                                                
278
 
                                                /* 3d angles */
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);
283
 
                                                
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;
290
 
                                                
291
 
                                                glBegin(GL_QUADS);
292
 
                                                
293
 
                                                /* This simple makes the angles display worse then they really are ;)
294
 
                                                 * 1.0-pow((1.0-a), 2) */
295
 
                                                
296
 
                                                a = fabs(uvang1-ang1)/180.0;
297
 
                                                weight_to_rgb(1.0-pow((1.0-a), 2), col, col+1, col+2);
298
 
                                                glColor3fv(col);
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);
302
 
                                                glColor3fv(col);
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);
306
 
                                                glColor3fv(col);
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);
310
 
                                                glColor3fv(col);
311
 
                                                glVertex2fv(tf->uv[3]);
312
 
                                                
 
334
                                                uvang[i] = angle_normalized_v2v2(auv[i], auv[(i + 1) % nverts]);
 
335
                                                ang[i] = angle_normalized_v3v3(av[i], av[(i + 1) % nverts]);
313
336
                                        }
314
 
                                        else {
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));
318
 
                                                
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));
321
 
                                                
322
 
                                                uvang3 = M_PI-(uvang1+uvang2);
323
 
                                                ang3 = M_PI-(ang1+ang2);
324
 
#endif                                          
325
 
                                                
326
 
                                                /* uv angles */
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);
330
 
                                                
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;
336
 
                                                
337
 
                                                /* 3d angles */
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;
346
 
                                                
347
 
                                                /* This simple makes the angles display worse then they really are ;)
348
 
                                                 * 1.0-pow((1.0-a), 2) */
349
 
                                                
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);
353
 
                                                glColor3fv(col);
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);
357
 
                                                glColor3fv(col);
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);
361
 
                                                glColor3fv(col);
362
 
                                                glVertex2fv(tf->uv[2]);
 
337
 
 
338
                                        glBegin(GL_POLYGON);
 
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));
 
343
                                                glColor3fv(col);
 
344
                                                glVertex2fv(luv->uv);
363
345
                                        }
364
346
                                        glEnd();
365
347
                                }
366
348
                                else {
367
 
                                        if(tf == activetf)
368
 
                                                activetf= NULL;
369
 
                                        efa->tmp.p = NULL;
 
349
                                        if (tf == activetf)
 
350
                                                activetf = NULL;
 
351
                                        BM_elem_flag_disable(efa, BM_ELEM_TAG);
370
352
                                }
371
353
                        }
372
354
 
373
355
                        glShadeModel(GL_FLAT);
 
356
 
 
357
                        BLI_array_free(uvang);
 
358
                        BLI_array_free(ang);
 
359
                        BLI_array_free(av);
 
360
                        BLI_array_free(auv);
 
361
 
374
362
                        break;
375
363
                }
376
364
        }
 
365
 
 
366
        BLI_array_free(tf_uv);
 
367
        BLI_array_free(tf_uvorig);
377
368
}
378
369
 
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)
380
371
{
381
372
        Base *base;
382
 
        Image *curimage;
383
 
 
384
 
        curimage= (activetf)? activetf->tpage: NULL;
385
373
 
386
374
        glColor3ub(96, 96, 96);
387
375
 
388
 
        for(base=scene->base.first; base; base=base->next) {
389
 
                Object *ob= base->object;
390
 
 
391
 
                if(!(base->flag & SELECT)) continue;
392
 
                if(!(base->lay & scene->lay)) continue;
393
 
                if(ob->restrictflag & OB_RESTRICT_VIEW) continue;
394
 
 
395
 
                if((ob->type==OB_MESH) && (ob!=obedit)) {
396
 
                        Mesh *me= ob->data;
397
 
 
398
 
                        if(me->mtface) {
399
 
                                MFace *mface= me->mface;
400
 
                                MTFace *tface= me->mtface;
401
 
                                int a;
402
 
 
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;
 
378
 
 
379
                if (!(base->flag & SELECT)) continue;
 
380
                if (!(base->lay & scene->lay)) continue;
 
381
                if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
 
382
 
 
383
                if ((ob->type == OB_MESH) && (ob != obedit)) {
 
384
                        Mesh *me = ob->data;
 
385
 
 
386
                        if (me->mtpoly) {
 
387
                                MPoly *mpoly = me->mpoly;
 
388
                                MTexPoly *mtpoly = me->mtpoly;
 
389
                                MLoopUV *mloopuv;
 
390
                                int a, b;
 
391
 
 
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]);
 
395
 
 
396
                                                mloopuv = me->mloopuv + mpoly->loopstart;
 
397
                                                for (b = 0; b < mpoly->totloop; b++, mloopuv++) {
 
398
                                                        glVertex2fv(mloopuv->uv);
 
399
                                                }
410
400
                                                glEnd();
411
401
                                        }
412
402
                                }
415
405
        }
416
406
}
417
407
 
 
408
static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob)
 
409
{
 
410
        Mesh *me = ob->data;
 
411
        Image *curimage = ED_space_image(sima);
 
412
 
 
413
        if (sima->flag & SI_DRAW_OTHER)
 
414
                draw_uvs_other(scene, ob, curimage);
 
415
 
 
416
        glColor3ub(112, 112, 112);
 
417
 
 
418
        if (me->mtface) {
 
419
                MPoly *mpoly = me->mpoly;
 
420
                MTexPoly *tface = me->mtpoly;
 
421
                MLoopUV *mloopuv;
 
422
                int a, b;
 
423
 
 
424
                for (a = me->totpoly; a > 0; a--, tface++, mpoly++) {
 
425
                        if (tface->tpage == curimage) {
 
426
                                glBegin(GL_LINE_LOOP);
 
427
 
 
428
                                mloopuv = me->mloopuv + mpoly->loopstart;
 
429
                                for (b = 0; b < mpoly->totloop; b++, mloopuv++) {
 
430
                                        glVertex2fv(mloopuv->uv);
 
431
                                }
 
432
                                glEnd();
 
433
                        }
 
434
                }
 
435
        }
 
436
}
 
437
 
418
438
/* draws uv's in the image space */
419
439
static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
420
440
{
421
441
        ToolSettings *ts;
422
 
        Mesh *me= obedit->data;
423
 
        EditMesh *em;
424
 
        EditFace *efa, *efa_act;
425
 
        MTFace *tf, *activetf = NULL;
 
442
        Mesh *me = obedit->data;
 
443
        BMEditMesh *em = me->edit_btmesh;
 
444
        BMesh *bm = em->bm;
 
445
        BMFace *efa, *efa_act, *activef;
 
446
        BMLoop *l;
 
447
        BMIter iter, liter;
 
448
        MTexPoly *tf, *activetf = NULL;
 
449
        MLoopUV *luv;
426
450
        DerivedMesh *finaldm, *cagedm;
427
 
        char col1[4], col2[4];
 
451
        unsigned char col1[4], col2[4];
428
452
        float pointsize;
429
 
        int drawfaces, interpedges, lastsel, sel;
430
 
        Image *ima= sima->image;
431
 
        
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 */
434
 
 
435
 
        ts= scene->toolsettings;
436
 
 
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;
 
455
 
 
456
        StitchPreviewer *stitch_preview = uv_get_stitch_previewer();
 
457
 
 
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;
 
461
 
 
462
        drawfaces = draw_uvs_face_check(scene);
 
463
        if (ts->uv_flag & UV_SYNC_SELECTION)
 
464
                interpedges = (ts->selectmode & SCE_SELECT_VERTEX);
440
465
        else
441
 
                interpedges= (ts->uv_selectmode == UV_SELECT_VERTEX);
 
466
                interpedges = (ts->uv_selectmode == UV_SELECT_VERTEX);
442
467
        
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;
 
471
 
 
472
                draw_uvs_other(scene, obedit, curimage);
 
473
        }
446
474
 
447
475
        /* 1. draw shadow mesh */
448
476
        
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);
454
482
 
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);
459
487
                        
460
488
                        /* release derivedmesh again */
461
 
                        if(cagedm != finaldm) cagedm->release(cagedm);
 
489
                        if (cagedm != finaldm) cagedm->release(cagedm);
462
490
                        finaldm->release(finaldm);
463
491
                }
464
492
        }
465
493
        
466
494
        /* 2. draw colored faces */
467
495
        
468
 
        if(sima->flag & SI_DRAW_STRETCH) {
 
496
        if (sima->flag & SI_DRAW_STRETCH) {
469
497
                draw_uvs_stretch(sima, scene, em, activetf);
470
498
        }
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);
477
505
                
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);
480
508
                        
481
 
                        if(uvedit_face_visible(scene, ima, efa, tf)) {
482
 
                                efa->tmp.p = 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 */
484
512
 
485
 
                                if(uvedit_face_selected(scene, efa, tf))
 
513
                                if (uvedit_face_select_test(scene, em, efa))
486
514
                                        glColor4ubv((GLubyte *)col2);
487
515
                                else
488
516
                                        glColor4ubv((GLubyte *)col1);
489
 
                                        
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]);
 
517
                                
 
518
                                glBegin(GL_POLYGON);
 
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);
 
522
                                }
495
523
                                glEnd();
496
524
                        }
497
525
                        else {
498
 
                                if(tf == activetf)
499
 
                                        activetf= NULL;
500
 
                                efa->tmp.p = NULL;
 
526
                                if (tf == activetf)
 
527
                                        activetf = NULL;
 
528
                                BM_elem_flag_disable(efa, BM_ELEM_TAG);
501
529
                        }
502
530
                }
503
531
                glDisable(GL_BLEND);
504
532
        }
505
533
        else {
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);
 
535
                
 
536
                BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 
537
                        tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
509
538
 
510
 
                        if(uvedit_face_visible(scene, ima, efa, tf)) {          
511
 
                                efa->tmp.p = tf;
 
539
                        if (uvedit_face_visible_test(scene, ima, efa, tf)) {            
 
540
                                BM_elem_flag_enable(efa, BM_ELEM_TAG);
512
541
                        }
513
542
                        else {
514
 
                                if(tf == activetf)
515
 
                                        activetf= NULL;
516
 
                                efa->tmp.p = NULL;
 
543
                                if (tf == activetf)
 
544
                                        activetf = NULL;
 
545
                                BM_elem_flag_disable(efa, BM_ELEM_TAG);
517
546
                        }
518
547
                }
519
548
                
520
549
        }
521
 
        
 
550
 
522
551
        /* 3. draw active face stippled */
523
552
 
524
 
        if(activetf) {
525
 
                glEnable(GL_BLEND);
526
 
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
527
 
                UI_ThemeColor4(TH_EDITMESH_ACTIVE);
528
 
 
529
 
                glEnable(GL_POLYGON_STIPPLE);
530
 
                glPolygonStipple(stipple_quarttone);
531
 
 
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]);
537
 
                glEnd();
538
 
 
539
 
                glDisable(GL_POLYGON_STIPPLE);
540
 
                glDisable(GL_BLEND);
 
553
        if (activef) {
 
554
                tf = CustomData_bmesh_get(&bm->pdata, activef->head.data, CD_MTEXPOLY);
 
555
                if (uvedit_face_visible_test(scene, ima, activef, tf)) {
 
556
                        glEnable(GL_BLEND);
 
557
                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
558
                        UI_ThemeColor4(TH_EDITMESH_ACTIVE);
 
559
 
 
560
                        glEnable(GL_POLYGON_STIPPLE);
 
561
                        glPolygonStipple(stipple_quarttone);
 
562
 
 
563
                        glBegin(GL_POLYGON);
 
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);
 
567
                        }
 
568
                        glEnd();
 
569
 
 
570
                        glDisable(GL_POLYGON_STIPPLE);
 
571
                        glDisable(GL_BLEND);
 
572
                }
541
573
        }
542
574
        
543
575
        /* 4. draw edges */
544
576
 
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);
549
581
        }
550
582
        
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))
 
587
                                        continue;
 
588
                                tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
555
589
 
556
 
                                if(tf) {
 
590
                                if (tf) {
557
591
                                        cpack(0x111111);
558
592
 
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);
 
597
                                        }
564
598
                                        glEnd();
565
 
                                
 
599
 
566
600
                                        setlinestyle(2);
567
601
                                        cpack(0x909090);
568
602
 
569
 
                                        glBegin(GL_LINE_STRIP);
570
 
                                                glVertex2fv(tf->uv[0]);
571
 
                                                glVertex2fv(tf->uv[1]);
572
 
                                        glEnd();
573
 
                
574
 
                                        glBegin(GL_LINE_STRIP);
575
 
                                                glVertex2fv(tf->uv[0]);
576
 
                                                if(efa->v4) glVertex2fv(tf->uv[3]);
577
 
                                                else glVertex2fv(tf->uv[2]);
578
 
                                        glEnd();
579
 
                
580
 
                                        glBegin(GL_LINE_STRIP);
581
 
                                                glVertex2fv(tf->uv[1]);
582
 
                                                glVertex2fv(tf->uv[2]);
583
 
                                                if(efa->v4) glVertex2fv(tf->uv[3]);
584
 
                                        glEnd();
 
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);
 
607
                                        }
 
608
                                        glEnd();
 
609
 
 
610
#if 0
 
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);
 
616
                                        glEnd();
 
617
#endif
585
618
 
586
619
                                        setlinestyle(0);
587
620
                                }
589
622
                        break;
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);
594
627
 
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))
 
630
                                        continue;
597
631
 
598
 
                                if(tf) {
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]);
604
 
                                        glEnd();
 
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);
605
636
                                }
 
637
                                glEnd();
606
638
                        }
607
639
                        break;
608
640
                case SI_UVDT_OUTLINE:
609
641
                        glLineWidth(3);
610
642
                        cpack(0x0);
611
643
                        
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))
 
646
                                        continue;
614
647
 
615
 
                                if(tf) {
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]);
621
 
                                        glEnd();
 
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);
622
652
                                }
 
653
                                glEnd();
623
654
                        }
624
655
                        
625
656
                        glLineWidth(1);
626
657
                        col2[0] = col2[1] = col2[2] = 192; col2[3] = 255;
627
658
                        glColor4ubv((unsigned char *)col2); 
628
659
                        
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);
631
 
                                lastsel = sel = 0;
632
663
 
633
 
                                if(interpedges) {
 
664
                                if (interpedges) {
634
665
                                        glShadeModel(GL_SMOOTH);
635
666
 
636
 
                                        for(efa= em->faces.first; efa; efa= efa->next) {
637
 
                                                tf= (MTFace *)efa->tmp.p; /* visible faces cached */
638
 
 
639
 
                                                if(tf) {
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]);
644
 
                                                        
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]);
648
 
                                                        
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]);
652
 
                                                        
653
 
                                                        if(efa->v4) {
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]);
657
 
                                                        }
658
 
                                                        
659
 
                                                        glEnd();
 
667
                                        BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 
668
                                                if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
 
669
                                                        continue;
 
670
 
 
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);
 
675
 
 
676
                                                        luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
 
677
                                                        glVertex2fv(luv->uv);
660
678
                                                }
 
679
                                                glEnd();
661
680
                                        }
662
681
 
663
682
                                        glShadeModel(GL_FLAT);
664
683
                                }
665
684
                                else {
666
 
                                        for(efa= em->faces.first; efa; efa= efa->next) {
667
 
                                                tf= (MTFace *)efa->tmp.p; /* visible faces cached */
668
 
 
669
 
                                                if(tf) {
670
 
                                                        glBegin(GL_LINES);
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]);
675
 
                                                        
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]);
680
 
                                                        
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]);
684
 
                                                        
685
 
                                                        if(efa->v4) {
686
 
                                                                glVertex2fv(tf->uv[3]);
687
 
 
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))
 
687
                                                        continue;
 
688
 
 
689
                                                glBegin(GL_LINES);
 
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);
 
694
                                                                lastsel = sel;
691
695
                                                        }
692
 
 
693
 
                                                        glVertex2fv(tf->uv[0]);
694
 
                                                        
695
 
                                                        glEnd();
 
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);
696
700
                                                }
 
701
                                                glEnd();
697
702
                                        }
698
703
                                }
699
704
                        }
700
705
                        else {
701
706
                                /* no nice edges */
702
 
                                for(efa= em->faces.first; efa; efa= efa->next) {
703
 
                                        tf= (MTFace *)efa->tmp.p; /* visible faces cached */
704
 
 
705
 
                                        if(tf) {
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]);
711
 
                                                glEnd();
 
707
                                BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 
708
                                        if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
 
709
                                                continue;
 
710
                                
 
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);
712
715
                                        }
 
716
                                        glEnd();
713
717
                                }
714
718
                        }
715
719
                        
716
720
                        break;
717
721
        }
718
722
 
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);
722
726
        }
723
727
 
724
728
        /* 5. draw face centers */
725
729
 
726
 
        if(drawfaces) {
 
730
        if (drawfaces) {
727
731
                float cent[2];
728
732
                
729
733
                pointsize = UI_GetThemeValuef(TH_FACEDOT_SIZE);
733
737
                UI_ThemeColor(TH_WIRE);
734
738
 
735
739
                bglBegin(GL_POINTS);
736
 
                for(efa= em->faces.first; efa; efa= efa->next) {
737
 
                        tf= (MTFace *)efa->tmp.p; /* visible faces cached */
 
740
                BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 
741
                        if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
 
742
                                continue;
738
743
 
739
 
                        if(tf && !uvedit_face_selected(scene, efa, tf)) {
740
 
                                uv_center(tf->uv, cent, efa->v4 != NULL);
 
744
                        if (!uvedit_face_select_test(scene, em, efa)) {
 
745
                                poly_uv_center(em, efa, cent);
741
746
                                bglVertex2fv(cent);
742
747
                        }
743
748
                }
747
752
                UI_ThemeColor(TH_FACE_DOT);
748
753
 
749
754
                bglBegin(GL_POINTS);
750
 
                for(efa= em->faces.first; efa; efa= efa->next) {
751
 
                        tf= (MTFace *)efa->tmp.p; /* visible faces cached */
 
755
                BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 
756
                        if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
 
757
                                continue;
752
758
 
753
 
                        if(tf && uvedit_face_selected(scene, efa, tf)) {
754
 
                                uv_center(tf->uv, cent, efa->v4 != NULL);
 
759
                        if (uvedit_face_select_test(scene, em, efa)) {
 
760
                                poly_uv_center(em, efa, cent);
755
761
                                bglVertex2fv(cent);
756
762
                        }
757
763
                }
760
766
 
761
767
        /* 6. draw uv vertices */
762
768
        
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);
768
774
        
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))
 
778
                                continue;
772
779
 
773
 
                        if(tf) {
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);
782
784
                        }
783
785
                }
784
786
                bglEnd();
785
787
        
786
788
                /* pinned uvs */
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));
789
791
                cpack(0xFF);
790
792
        
791
793
                bglBegin(GL_POINTS);
792
 
                for(efa= em->faces.first; efa; efa= efa->next) {
793
 
                        tf= (MTFace *)efa->tmp.p; /* visible faces cached */
794
 
 
795
 
                        if(tf) {
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))
 
796
                                continue;
 
797
 
 
798
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 
799
                                luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
 
800
 
 
801
                                if (luv->flag & MLOOPUV_PINNED)
 
802
                                        bglVertex2fv(luv->uv);
804
803
                        }
805
804
                }
806
805
                bglEnd();
810
809
                glPointSize(pointsize);
811
810
        
812
811
                bglBegin(GL_POINTS);
813
 
                for(efa= em->faces.first; efa; efa= efa->next) {
814
 
                        tf= (MTFace *)efa->tmp.p; /* visible faces cached */
815
 
 
816
 
                        if(tf) {
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))
 
814
                                continue;
 
815
 
 
816
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 
817
                                luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
 
818
 
 
819
                                if (uvedit_uv_select_test(em, scene, l))
 
820
                                        bglVertex2fv(luv->uv);
825
821
                        }
826
822
                }
827
823
                bglEnd();       
828
824
        }
829
825
 
 
826
        /* finally draw stitch preview */
 
827
        if (stitch_preview) {
 
828
                int i, index = 0;
 
829
                glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
 
830
                glEnableClientState(GL_VERTEX_ARRAY);
 
831
 
 
832
                glEnable(GL_BLEND);
 
833
 
 
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);
 
838
 
 
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]);
 
847
 
 
848
                        index += stitch_preview->uvs_per_polygon[i];
 
849
                }
 
850
                glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
 
851
#if 0
 
852
                UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
 
853
                glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris * 3);
 
854
#endif
 
855
                glDisable(GL_BLEND);
 
856
 
 
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);
 
862
 
 
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);
 
866
 
 
867
                glPopClientAttrib();
 
868
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
869
        }
 
870
 
830
871
        glPointSize(1.0);
831
 
        BKE_mesh_end_editmesh(obedit->data, em);
832
872
}
833
873
 
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)
835
875
{
836
 
        int show_uvedit, show_uvshadow;
837
 
 
838
 
        show_uvedit= ED_space_image_show_uvedit(sima, obedit);
839
 
        show_uvshadow= ED_space_image_show_uvshadow(sima, obedit);
840
 
 
841
 
        if(show_uvedit || show_uvshadow) {
842
 
                if(show_uvshadow)
843
 
                        draw_uvs_shadow(sima, obedit);
844
 
                else
 
876
        ToolSettings *toolsettings = scene->toolsettings;
 
877
        int show_uvedit, show_uvshadow, show_texpaint_uvshadow;
 
878
 
 
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);
 
882
 
 
883
        if (show_uvedit || show_uvshadow || show_texpaint_uvshadow) {
 
884
                if (show_uvshadow)
 
885
                        draw_uvs_shadow(obedit);
 
886
                else if (show_uvedit)
845
887
                        draw_uvs(sima, scene, obedit);
 
888
                else
 
889
                        draw_uvs_texpaint(sima, scene, obact);
846
890
 
847
 
                if(show_uvedit)
 
891
                if (show_uvedit && !(toolsettings->use_uv_sculpt))
848
892
                        drawcursor_sima(sima, ar);
849
893
        }
850
894
}