1345
static int VecEqual(float *a, float *b)
1357
static void set_uv_vcol(EditFace *efa, float *co, float *uv, char *col)
1359
EditVert *v1,*v2,*v3,*v4;
1361
float t00, t01, t10, t11;
1362
float detsh, u, v, l;
1365
char *cp0, *cp1, *cp2;
1368
//First Check for exact match between co and efa verts
1369
if(VecEqual(co,efa->v1->co)) {
1370
uv[0] = efa->tf.uv[0][0];
1371
uv[1] = efa->tf.uv[0][1];
1373
hold = (char*)&efa->tf.col[0];
1379
} else if(VecEqual(co,efa->v2->co)) {
1380
uv[0] = efa->tf.uv[1][0];
1381
uv[1] = efa->tf.uv[1][1];
1383
hold = (char*)&efa->tf.col[1];
1389
} else if(VecEqual(co,efa->v3->co)) {
1390
uv[0] = efa->tf.uv[2][0];
1391
uv[1] = efa->tf.uv[2][1];
1393
hold = (char*)&efa->tf.col[2];
1399
} else if(efa->v4 && VecEqual(co,efa->v4->co)) {
1400
uv[0] = efa->tf.uv[3][0];
1401
uv[1] = efa->tf.uv[3][1];
1403
hold = (char*)&efa->tf.col[3];
1411
/* define best projection of face XY, XZ or YZ */
1412
xn= fabs(efa->n[0]);
1413
yn= fabs(efa->n[1]);
1414
zn= fabs(efa->n[2]);
1415
if(zn>=xn && zn>=yn) {i= 0; j= 1;}
1416
else if(yn>=xn && yn>=zn) {i= 0; j= 2;}
1419
/* calculate u and v */
1424
t00= v3->co[i]-v1->co[i]; t01= v3->co[j]-v1->co[j];
1425
t10= v3->co[i]-v2->co[i]; t11= v3->co[j]-v2->co[j];
1427
detsh= 1.0/(t00*t11-t10*t01); /* potential danger */
1428
t00*= detsh; t01*=detsh;
1429
t10*=detsh; t11*=detsh;
1431
u= (co[i]-v3->co[i])*t11-(co[j]-v3->co[j])*t10;
1432
v= (co[j]-v3->co[j])*t00-(co[i]-v3->co[i])*t01;
1434
/* btw; u and v range from -1 to 0 */
1438
/* outside triangle? */
1439
/* printf("l: %f u %f v %f\n",l,u,v); */
1441
if(efa->v4 && (v>0.001f)) { /* only check for positive v is OK, that's the diagonal */
1442
/* printf("outside\n"); */
1443
/* do it all over, but now with vertex 2 replaced with 4 */
1445
/* calculate u and v */
1450
t00= v3->co[i]-v1->co[i]; t01= v3->co[j]-v1->co[j];
1451
t10= v3->co[i]-v4->co[i]; t11= v3->co[j]-v4->co[j];
1453
detsh= 1.0/(t00*t11-t10*t01); /* potential danger */
1454
t00*= detsh; t01*=detsh;
1455
t10*=detsh; t11*=detsh;
1457
u= (co[i]-v3->co[i])*t11-(co[j]-v3->co[j])*t10;
1458
v= (co[j]-v3->co[j])*t00-(co[i]-v3->co[i])*t01;
1460
/* btw; u and v range from -1 to 0 */
1464
uv[0] = (l*efa->tf.uv[2][0] - u*efa->tf.uv[0][0] - v*efa->tf.uv[3][0]);
1465
uv[1] = (l*efa->tf.uv[2][1] - u*efa->tf.uv[0][1] - v*efa->tf.uv[3][1]);
1467
cp0= (char*)&(efa->tf.col[0]);
1468
cp1= (char*)&(efa->tf.col[3]);
1469
cp2= (char*)&(efa->tf.col[2]);
1471
for(i=0; i<4; i++) {
1472
fac= (int)(l*cp2[i] - u*cp0[i] - v*cp1[i]);
1473
col[i]= CLAMPIS(fac, 0, 255);
1476
// printf("inside\n");
1477
//new = l*vertex3_val - u*vertex1_val - v*vertex2_val;
1478
uv[0] = (l*efa->tf.uv[2][0] - u*efa->tf.uv[0][0] - v*efa->tf.uv[1][0]);
1479
uv[1] = (l*efa->tf.uv[2][1] - u*efa->tf.uv[0][1] - v*efa->tf.uv[1][1]);
1481
cp0= (char*)&(efa->tf.col[0]);
1482
cp1= (char*)&(efa->tf.col[1]);
1483
cp2= (char*)&(efa->tf.col[2]);
1485
for(i=0; i<4; i++) {
1486
fac= (int)(l*cp2[i] - u*cp0[i] - v*cp1[i]);
1487
col[i]= CLAMPIS(fac, 0, 255);
1492
static void facecopy(EditFace *source,EditFace *target)
1495
set_uv_vcol(source,target->v1->co,target->tf.uv[0],(char*)&target->tf.col[0]);
1496
set_uv_vcol(source,target->v2->co,target->tf.uv[1],(char*)&target->tf.col[1]);
1497
set_uv_vcol(source,target->v3->co,target->tf.uv[2],(char*)&target->tf.col[2]);
1499
set_uv_vcol(source,target->v4->co,target->tf.uv[3],(char*)&target->tf.col[3]);
1501
target->mat_nr = source->mat_nr;
1502
target->tf.flag = source->tf.flag&~TF_ACTIVE;
1503
target->tf.transp = source->tf.transp;
1504
target->tf.mode = source->tf.mode;
1505
target->tf.tile = source->tf.tile;
1506
target->tf.unwrap = source->tf.unwrap;
1507
target->tf.tpage = source->tf.tpage;
1508
target->flag = source->flag;
1330
static void facecopy(EditFace *source, EditFace *target)
1332
EditMesh *em= G.editMesh;
1333
float *v1 = source->v1->co, *v2 = source->v2->co, *v3 = source->v3->co;
1334
float *v4 = source->v4? source->v4->co: NULL;
1337
CustomData_em_copy_data(&em->fdata, &em->fdata, source->data, &target->data);
1339
target->mat_nr = source->mat_nr;
1340
target->flag = source->flag;
1341
target->h = source->h;
1343
InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v1->co, w[0]);
1344
InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v2->co, w[1]);
1345
InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v3->co, w[2]);
1347
InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v4->co, w[3]);
1349
CustomData_em_interp(&em->fdata, &source->data, NULL, (float*)w, 1, target->data);
1511
1352
static void fill_quad_single(EditFace *efa, struct GHash *gh, int numcuts, int seltype)
2414
2257
MEM_freeN(innerverts);
2260
//Next two fill types are for knife exact only and are provided to allow for knifing through vertices
2261
//This means there is no multicut!
2262
static void fill_quad_doublevert(EditFace *efa, int v1, int v2){
2265
Depending on which two vertices have been knifed through (v1 and v2), we
2266
triangulate like the patterns below.
2274
if(v1 == 1 && v2 == 3){
2275
hold= addfacelist(efa->v1, efa->v2, efa->v3, 0, efa, NULL);
2276
hold->e1->f2 |= EDGENEW;
2277
hold->e2->f2 |= EDGENEW;
2278
hold->e3->f2 |= EDGENEW;
2279
hold->e3->f2 |= EDGEINNER;
2280
facecopy(efa, hold);
2282
hold= addfacelist(efa->v1, efa->v3, efa->v4, 0, efa, NULL);
2283
hold->e1->f2 |= EDGENEW;
2284
hold->e2->f2 |= EDGENEW;
2285
hold->e3->f2 |= EDGENEW;
2286
hold->e1->f2 |= EDGEINNER;
2287
facecopy(efa, hold);
2290
hold= addfacelist(efa->v1, efa->v2, efa->v4, 0, efa, NULL);
2291
hold->e1->f2 |= EDGENEW;
2292
hold->e2->f2 |= EDGENEW;
2293
hold->e3->f2 |= EDGENEW;
2294
hold->e2->f2 |= EDGEINNER;
2295
facecopy(efa, hold);
2297
hold= addfacelist(efa->v2, efa->v3, efa->v4, 0, efa, NULL);
2298
hold->e1->f2 |= EDGENEW;
2299
hold->e2->f2 |= EDGENEW;
2300
hold->e3->f2 |= EDGENEW;
2301
hold->e3->f2 |= EDGEINNER;
2302
facecopy(efa, hold);
2306
static void fill_quad_singlevert(EditFace *efa, struct GHash *gh)
2308
EditEdge *cedge=NULL;
2309
EditVert *v[4], **verts;
2311
short start=0, end, left, right, vertsize;
2318
if(efa->e1->f & SELECT) { cedge = efa->e1; start = 0;}
2319
else if(efa->e2->f & SELECT) { cedge = efa->e2; start = 1;}
2320
else if(efa->e3->f & SELECT) { cedge = efa->e3; start = 2;}
2321
else if(efa->e4->f & SELECT) { cedge = efa->e4; start = 3;}
2323
// Point verts to the array of new verts for cedge
2324
verts = BLI_ghash_lookup(gh, cedge);
2325
//This is the index size of the verts array
2328
// Is the original v1 the same as the first vert on the selected edge?
2329
// if not, the edge is running the opposite direction in this face so flip
2330
// the array to the correct direction
2332
if(verts[0] != v[start]) {flipvertarray(verts,3);}
2335
right = (start+3)%4;
2338
We should have something like this now
2349
where start,end,left, right are indexes of EditFace->v1, etc (stored in v)
2350
and 0,1,2 are the indexes of the new verts stored in verts. We fill like
2351
this, depending on whether its vertex 'left' or vertex 'right' thats
2352
been knifed through...
2362
//triangle is composed of cutvert, end and left
2363
hold = addfacelist(verts[1],v[end],v[left],NULL, NULL,NULL);
2364
hold->e1->f2 |= EDGENEW;
2365
hold->e2->f2 |= EDGENEW;
2366
hold->e3->f2 |= EDGENEW;
2367
hold->e3->f2 |= EDGEINNER;
2368
facecopy(efa, hold);
2370
//quad is composed of cutvert, left, right and start
2371
hold = addfacelist(verts[1],v[left],v[right],v[start], NULL, NULL);
2372
hold->e1->f2 |= EDGENEW;
2373
hold->e2->f2 |= EDGENEW;
2374
hold->e3->f2 |= EDGENEW;
2375
hold->e4->f2 |= EDGENEW;
2376
hold->e1->f2 |= EDGEINNER;
2377
facecopy(efa, hold);
2379
else if(v[right]->f1){
2380
//triangle is composed of cutvert, right and start
2381
hold = addfacelist(verts[1],v[right],v[start], NULL, NULL, NULL);
2382
hold->e1->f2 |= EDGENEW;
2383
hold->e2->f2 |= EDGENEW;
2384
hold->e3->f2 |= EDGENEW;
2385
hold->e1->f2 |= EDGEINNER;
2386
facecopy(efa, hold);
2387
//quad is composed of cutvert, end, left, right
2388
hold = addfacelist(verts[1],v[end], v[left], v[right], NULL, NULL);
2389
hold->e1->f2 |= EDGENEW;
2390
hold->e2->f2 |= EDGENEW;
2391
hold->e3->f2 |= EDGENEW;
2392
hold->e4->f2 |= EDGENEW;
2393
hold->e4->f2 |= EDGEINNER;
2394
facecopy(efa, hold);
2417
2399
// This function takes an example edge, the current point to create and
2418
2400
// the total # of points to create, then creates the point and return the
2419
2401
// editvert pointer to it.
3119
3133
allqueue(REDRAWVIEW3D, 0);
3120
3134
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
3136
if(G.editMesh->vnode)
3137
sync_all_versefaces_with_editfaces((VNode*)G.editMesh->vnode);
3121
3139
BIF_undo_push("Beauty Fill");
3125
/* ******************** FLIP EDGE ************************************* */
3128
#define FACE_MARKCLEAR(f) (f->f1 = 1)
3143
/* ******************** BEGIN TRIANGLE TO QUAD ************************************* */
3144
static float measure_facepair(EditVert *v1, EditVert *v2, EditVert *v3, EditVert *v4, float limit){
3146
/*gives a 'weight' to a pair of triangles that join an edge to decide how good a join they would make*/
3147
/*Note: this is more complicated than it needs to be and should be cleaned up...*/
3148
float measure = 0.0, noA1[3], noA2[3], noB1[3], noB2[3], normalADiff, normalBDiff,
3149
edgeVec1[3], edgeVec2[3], edgeVec3[3], edgeVec4[3], diff,
3150
minarea, maxarea, areaA, areaB;
3152
/*First Test: Normal difference*/
3153
CalcNormFloat(v1->co, v2->co, v3->co, noA1);
3154
CalcNormFloat(v1->co, v3->co, v4->co, noA2);
3156
if(noA1[0] == noA2[0] && noA1[1] == noA2[1] && noA1[2] == noA2[2]) normalADiff = 0.0;
3157
else normalADiff = VecAngle2(noA1, noA2);
3158
//if(!normalADiff) normalADiff = 179;
3159
CalcNormFloat(v2->co, v3->co, v4->co, noB1);
3160
CalcNormFloat(v4->co, v1->co, v2->co, noB2);
3162
if(noB1[0] == noB2[0] && noB1[1] == noB2[1] && noB1[2] == noB2[2]) normalBDiff = 0.0;
3163
else normalBDiff = VecAngle2(noB1, noB2);
3164
//if(!normalBDiff) normalBDiff = 179;
3166
measure += (normalADiff/360) + (normalBDiff/360);
3167
if(measure > limit) return measure;
3169
/*Second test: Colinearity*/
3170
VecSubf(edgeVec1, v1->co, v2->co);
3171
VecSubf(edgeVec2, v2->co, v3->co);
3172
VecSubf(edgeVec3, v3->co, v4->co);
3173
VecSubf(edgeVec4, v4->co, v1->co);
3178
fabs(VecAngle2(edgeVec1, edgeVec2) - 90) +
3179
fabs(VecAngle2(edgeVec2, edgeVec3) - 90) +
3180
fabs(VecAngle2(edgeVec3, edgeVec4) - 90) +
3181
fabs(VecAngle2(edgeVec4, edgeVec1) - 90)) / 360;
3182
if(!diff) return 0.0;
3185
if(measure > limit) return measure;
3187
/*Third test: Concavity*/
3188
areaA = AreaT3Dfl(v1->co, v2->co, v3->co) + AreaT3Dfl(v1->co, v3->co, v4->co);
3189
areaB = AreaT3Dfl(v2->co, v3->co, v4->co) + AreaT3Dfl(v4->co, v1->co, v2->co);
3191
if(areaA <= areaB) minarea = areaA;
3192
else minarea = areaB;
3194
if(areaA >= areaB) maxarea = areaA;
3195
else maxarea = areaB;
3197
if(!maxarea) measure += 1;
3198
else measure += (1 - (minarea / maxarea));
3203
#define T2QUV_LIMIT 0.005
3204
#define T2QCOL_LIMIT 3
3205
static int compareFaceAttribs(EditFace *f1, EditFace *f2, EditEdge *eed)
3207
/*Test to see if the per-face attributes for the joining edge match within limit*/
3209
unsigned int *col1, *col2;
3210
short i,attrok=0, flag = G.scene->toolsettings->editbutflag, fe1[2], fe2[2];
3212
tf1 = CustomData_em_get(&G.editMesh->fdata, f1->data, CD_MTFACE);
3213
tf2 = CustomData_em_get(&G.editMesh->fdata, f2->data, CD_MTFACE);
3215
col1 = CustomData_em_get(&G.editMesh->fdata, f1->data, CD_MCOL);
3216
col2 = CustomData_em_get(&G.editMesh->fdata, f2->data, CD_MCOL);
3218
/*store indices for faceedges*/
3223
fe1[0] = eed->v1->f1;
3224
fe1[1] = eed->v2->f1;
3230
fe2[0] = eed->v1->f1;
3231
fe2[1] = eed->v2->f1;
3233
/*compare faceedges for each face attribute. Additional per face attributes can be added later*/
3235
if(flag & B_JOINTRIA_UV){
3237
if(tf1 == NULL || tf2 == NULL) attrok |= B_JOINTRIA_UV;
3238
else if(tf1->tpage != tf2->tpage); /*do nothing*/
3240
for(i = 0; i < 2; i++){
3241
if(tf1->uv[fe1[i]][0] + T2QUV_LIMIT > tf2->uv[fe2[i]][0] && tf1->uv[fe1[i]][0] - T2QUV_LIMIT < tf2->uv[fe2[i]][0] &&
3242
tf1->uv[fe1[i]][1] + T2QUV_LIMIT > tf2->uv[fe2[i]][1] && tf1->uv[fe1[i]][1] - T2QUV_LIMIT < tf2->uv[fe2[i]][1]) attrok |= B_JOINTRIA_UV;
3248
if(flag & B_JOINTRIA_VCOL){
3249
if(!col1 || !col2) attrok |= B_JOINTRIA_VCOL;
3251
char *f1vcol, *f2vcol;
3252
for(i = 0; i < 2; i++){
3253
f1vcol = (char *)&(col1[fe1[i]]);
3254
f2vcol = (char *)&(col2[fe2[i]]);
3256
/*compare f1vcol with f2vcol*/
3257
if( f1vcol[1] + T2QCOL_LIMIT > f2vcol[1] && f1vcol[1] - T2QCOL_LIMIT < f2vcol[1] &&
3258
f1vcol[2] + T2QCOL_LIMIT > f2vcol[2] && f1vcol[2] - T2QCOL_LIMIT < f2vcol[2] &&
3259
f1vcol[3] + T2QCOL_LIMIT > f2vcol[3] && f1vcol[3] - T2QCOL_LIMIT < f2vcol[3]) attrok |= B_JOINTRIA_VCOL;
3264
if( ((attrok & B_JOINTRIA_UV) == (flag & B_JOINTRIA_UV)) && ((attrok & B_JOINTRIA_VCOL) == (flag & B_JOINTRIA_VCOL)) ) return 1;
3268
static int fplcmp(const void *v1, const void *v2)
3270
const EditEdge *e1= *((EditEdge**)v1), *e2=*((EditEdge**)v2);
3272
if( e1->crease > e2->crease) return 1;
3273
else if( e1->crease < e2->crease) return -1;
3278
/*Bitflags for edges.*/
3280
#define T2QCOMPLEX 2
3130
3282
void join_triangles(void)
3132
EditMesh *em = G.editMesh;
3133
EditVert *v1, *v2, *v3, *v4;
3137
EditEdge *eed, *nexted;
3140
unsigned int col[4];
3142
EM_selectmode_flush(); // makes sure in selectmode 'face' the edges of selected faces are selected too
3144
totedge = count_selected_edges(em->edges.first);
3145
if(totedge==0) return;
3147
efaar= (EVPTuple *) MEM_callocN(totedge * sizeof(EVPTuple), "jointris");
3284
EditMesh *em=G.editMesh;
3285
EditVert *v1, *v2, *v3, *v4, *eve;
3286
EditEdge *eed, **edsortblock = NULL, **edb = NULL;
3288
EVPTuple *efaar = NULL;
3290
float *creases = NULL;
3291
float measure; /*Used to set tolerance*/
3292
float limit = G.scene->toolsettings->jointrilimit;
3293
int i, ok, totedge=0, totseledge=0, complexedges, vindex[4];
3295
/*test for multi-resolution data*/
3296
if(multires_test()) return;
3298
/*if we take a long time on very dense meshes we want waitcursor to display*/
3301
totseledge = count_selected_edges(em->edges.first);
3302
if(totseledge==0) return;
3304
/*abusing crease value to store weights for edge pairs. Nasty*/
3305
for(eed=em->edges.first; eed; eed=eed->next) totedge++;
3306
if(totedge) creases = MEM_callocN(sizeof(float) * totedge, "Join Triangles Crease Array");
3307
for(eed=em->edges.first, i = 0; eed; eed=eed->next, i++){
3308
creases[i] = eed->crease;
3312
/*clear temp flags*/
3313
for(eve=em->verts.first; eve; eve=eve->next) eve->f1 = eve->f2 = 0;
3314
for(eed=em->edges.first; eed; eed=eed->next) eed->f2 = eed->f1 = 0;
3315
for(efa=em->faces.first; efa; efa=efa->next) efa->f1 = efa->tmp.l = 0;
3317
/*For every selected 2 manifold edge, create pointers to its two faces.*/
3318
efaar= (EVPTuple *) MEM_callocN(totseledge * sizeof(EVPTuple), "Tri2Quad");
3149
3319
ok = collect_quadedges(efaar, em->edges.first, em->faces.first);
3150
if (G.f & G_DEBUG) {
3151
printf("Edges selected: %d\n", ok);
3154
eed= em->edges.first;
3158
if(eed->f2==2) { /* points to 2 faces */
3160
efaa= (EVPtr *) eed->tmp.p;
3162
/* don't do it if flagged */
3166
if(efa->e1->f1 || efa->e2->f1 || efa->e3->f1) ok= 0;
3168
if(efa->e1->f1 || efa->e2->f1 || efa->e3->f1) ok= 0;
3172
givequadverts(efaa[0], efaa[1], &v1, &v2, &v3, &v4, uv, col);
3183
/* make new faces */
3184
if(v1 && v2 && v3 && v4) {
3185
if( convex(v1->co, v2->co, v3->co, v4->co) ) {
3186
if(exist_face(v1, v2, v3, v4)==0) {
3187
w = addfacelist(v1, v2, v3, v4, efaa[0], NULL); /* seam edge may get broken */
3188
w->f= efaa[0]->f; /* copy selection flag */
3191
UVCOPY(w->tf.uv[0], uv[0]);
3192
UVCOPY(w->tf.uv[1], uv[1]);
3193
UVCOPY(w->tf.uv[2], uv[2]);
3194
UVCOPY(w->tf.uv[3], uv[3]);
3196
memcpy(w->tf.col, col, sizeof(w->tf.col));
3198
/* tag as to-be-removed */
3199
FACE_MARKCLEAR(efaa[0]);
3200
FACE_MARKCLEAR(efaa[1]);
3202
} /* endif test convex */
3208
free_tagged_edgelist(em->edges.first);
3209
free_tagged_facelist(em->faces.first);
3325
/*clear tmp.l flag and store number of faces that are selected and coincident to current face here.*/
3326
for(eed=em->edges.first; eed; eed=eed->next){
3327
/* eed->f2 is 2 only if this edge is part of exactly two
3328
triangles, and both are selected, and it has EVPTuple assigned */
3330
efaa= (EVPtr *) eed->tmp.p;
3336
for(eed=em->edges.first; eed; eed=eed->next){
3338
efaa= (EVPtr *) eed->tmp.p;
3339
v1 = v2 = v3 = v4 = NULL;
3340
givequadverts(efaa[0], efaa[1], &v1, &v2, &v3, &v4, vindex);
3341
if(v1 && v2 && v3 && v4){
3342
/*test if simple island first. This mimics 2.42 behaviour and the tests are less restrictive.*/
3343
if(efaa[0]->tmp.l == 1 && efaa[1]->tmp.l == 1){
3344
if( convex(v1->co, v2->co, v3->co, v4->co) ){
3346
efaa[0]->f1 = 1; //mark for join
3347
efaa[1]->f1 = 1; //mark for join
3352
/* The face pair is part of a 'complex' island, so the rules for dealing with it are more involved.
3353
Depending on what options the user has chosen, this face pair can be 'thrown out' based upon the following criteria:
3355
1: the two faces do not share the same material
3356
2: the edge joining the two faces is marked as sharp.
3357
3: the two faces UV's do not make a good match
3358
4: the two faces Vertex colors do not make a good match
3360
If the face pair passes all the applicable tests, it is then given a 'weight' with the measure_facepair() function.
3361
This measures things like concavity, colinearity ect. If this weight is below the threshold set by the user
3362
the edge joining them is marked as being 'complex' and will be compared against other possible pairs which contain one of the
3363
same faces in the current pair later.
3365
This technique is based upon an algorithm that Campbell Barton developed for his Tri2Quad script that was previously part of
3366
the python scripts bundled with Blender releases.
3369
if(G.scene->toolsettings->editbutflag & B_JOINTRIA_SHARP && eed->sharp); /*do nothing*/
3370
else if(G.scene->toolsettings->editbutflag & B_JOINTRIA_MAT && efaa[0]->mat_nr != efaa[1]->mat_nr); /*do nothing*/
3371
else if(((G.scene->toolsettings->editbutflag & B_JOINTRIA_UV) || (G.scene->toolsettings->editbutflag & B_JOINTRIA_VCOL)) &&
3372
compareFaceAttribs(efaa[0], efaa[1], eed) == 0); /*do nothing*/
3374
measure = measure_facepair(v1, v2, v3, v4, limit);
3375
if(measure < limit){
3377
eed->f1 |= T2QCOMPLEX;
3378
eed->crease = measure; /*we dont mark edges for join yet*/
3386
/*Quicksort the complex edges according to their weighting*/
3388
edsortblock = edb = MEM_callocN(sizeof(EditEdge*) * complexedges, "Face Pairs quicksort Array");
3389
for(eed = em->edges.first; eed; eed=eed->next){
3390
if(eed->f1 & T2QCOMPLEX){
3395
qsort(edsortblock, complexedges, sizeof(EditEdge*), fplcmp);
3396
/*now go through and mark the edges who get the highest weighting*/
3397
for(edb=edsortblock, i=0; i < complexedges; edb++, i++){
3398
efaa = (EVPtr *)((*edb)->tmp.p); /*suspect!*/
3399
if( !efaa[0]->f1 && !efaa[1]->f1){
3400
efaa[0]->f1 = 1; //mark for join
3401
efaa[1]->f1 = 1; //mark for join
3402
(*edb)->f1 |= T2QJOIN;
3407
/*finally go through all edges marked for join (simple and complex) and create new faces*/
3408
for(eed=em->edges.first; eed; eed=eed->next){
3409
if(eed->f1 & T2QJOIN){
3410
efaa= (EVPtr *)eed->tmp.p;
3411
v1 = v2 = v3 = v4 = NULL;
3412
givequadverts(efaa[0], efaa[1], &v1, &v2, &v3, &v4, vindex);
3413
if((v1 && v2 && v3 && v4) && (exist_face(v1, v2, v3, v4)==0)){ /*exist_face is very slow! Needs to be adressed.*/
3415
eed->f1 |= T2QDELETE;
3416
/*create new quad and select*/
3417
efa = EM_face_from_faces(efaa[0], efaa[1], vindex[0], vindex[1], 4+vindex[2], 4+vindex[3]);
3418
EM_select_face(efa,1);
3428
/*free data and cleanup*/
3430
for(eed=em->edges.first, i = 0; eed; eed=eed->next, i++) eed->crease = creases[i];
3433
for(eed=em->edges.first; eed; eed=eed->next){
3434
if(eed->f1 & T2QDELETE) eed->f1 = 1;
3437
free_tagged_edges_faces(em->edges.first, em->faces.first);
3438
if(efaar) MEM_freeN(efaar);
3439
if(edsortblock) MEM_freeN(edsortblock);
3441
EM_selectmode_flush();
3213
3443
allqueue(REDRAWVIEW3D, 0);
3214
3444
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
3446
if(G.editMesh->vnode)
3447
sync_all_versefaces_with_editfaces((VNode*)G.editMesh->vnode);
3215
3450
BIF_undo_push("Convert Triangles to Quads");
3452
/* ******************** END TRIANGLE TO QUAD ************************************* */
3454
#define FACE_MARKCLEAR(f) (f->f1 = 1)
3218
3456
/* quick hack, basically a copy of beauty_fill */
3219
3457
void edge_flip(void)
3330
3557
static void edge_rotate(EditEdge *eed,int dir)
3332
3559
EditMesh *em = G.editMesh;
3560
EditVert **verts[2];
3333
3561
EditFace *face[2], *efa, *newFace[2];
3334
EditVert *faces[2][4],*v1,*v2,*v3,*v4,*vtemp;
3335
EditEdge *srchedge = NULL;
3336
short facecount=0, p1=0,p2=0,p3=0,p4=0,fac1=4,fac2=4,i,j,numhidden;
3337
EditEdge **hiddenedges;
3562
EditEdge **edges[2], **hiddenedges, *srchedge;
3563
int facecount, p1, p2, p3, p4, fac1, fac2, i, j;
3564
int numhidden, numshared, p[2][4];
3339
3566
/* check to make sure that the edge is only part of 2 faces */
3340
3568
for(efa = em->faces.first;efa;efa = efa->next) {
3341
3569
if((efa->e1 == eed || efa->e2 == eed) || (efa->e3 == eed || efa->e4 == eed)) {
3342
if(facecount == 2) {
3570
if(facecount >= 2) {
3571
/* more than two faces with this edge */
3346
3575
face[facecount] = efa;
3355
3584
/* how many edges does each face have */
3356
if(face[0]->e4 == NULL)
3360
if(face[1]->e4 == NULL)
3365
/*store the face info in a handy array */
3366
faces[0][0] = face[0]->v1;
3367
faces[0][1] = face[0]->v2;
3368
faces[0][2] = face[0]->v3;
3369
if(face[0]->e4 != NULL)
3370
faces[0][3] = face[0]->v4;
3374
faces[1][0] = face[1]->v1;
3375
faces[1][1] = face[1]->v2;
3376
faces[1][2] = face[1]->v3;
3377
if(face[1]->e4 != NULL)
3378
faces[1][3] = face[1]->v4;
3585
if(face[0]->e4) fac1= 4;
3588
if(face[1]->e4) fac2= 4;
3591
/* make a handy array for verts and edges */
3592
verts[0]= &face[0]->v1;
3593
edges[0]= &face[0]->e1;
3594
verts[1]= &face[1]->v1;
3595
edges[1]= &face[1]->e1;
3383
3597
/* we don't want to rotate edges between faces that share more than one edge */
3386
if(face[0]->e1 == face[1]->e1 ||
3387
face[0]->e1 == face[1]->e2 ||
3388
face[0]->e1 == face[1]->e3 ||
3389
((face[1]->e4) && face[0]->e1 == face[1]->e4) )
3392
if(face[0]->e2 == face[1]->e1 ||
3393
face[0]->e2 == face[1]->e2 ||
3394
face[0]->e2 == face[1]->e3 ||
3395
((face[1]->e4) && face[0]->e2 == face[1]->e4) )
3398
if(face[0]->e3 == face[1]->e1 ||
3399
face[0]->e3 == face[1]->e2 ||
3400
face[0]->e3 == face[1]->e3 ||
3401
((face[1]->e4) && face[0]->e3 == face[1]->e4) )
3405
if(face[0]->e4 == face[1]->e1 ||
3406
face[0]->e4 == face[1]->e2 ||
3407
face[0]->e4 == face[1]->e3 ||
3408
((face[1]->e4) && face[0]->e4 == face[1]->e4) )
3415
/* Coplaner Faces Only Please */
3416
if(Inpf(face[0]->n,face[1]->n) <= 0.000001) {
3420
/*get the edges verts */
3426
/*figure out where the edges verts lie one the 2 faces */
3428
if(v1 == faces[0][i])
3430
if(v2 == faces[0][i])
3432
if(v1 == faces[1][i])
3434
if(v2 == faces[1][i])
3438
/*make sure the verts are in the correct order */
3439
if((p1+1)%fac1 == p2) {
3448
if((p3+1)%fac2 == p4) {
3459
/* Create an Array of the Edges who have h set prior to rotate */
3599
for(i=0; i<fac1; i++)
3600
for(j=0; j<fac2; j++)
3601
if (edges[0][i] == edges[1][j])
3607
/* coplaner faces only please */
3608
if(Inpf(face[0]->n,face[1]->n) <= 0.000001)
3611
/* we want to construct an array of vertex indicis in both faces, starting at
3612
the last vertex of the edge being rotated.
3613
- first we find the two vertices that lie on the rotating edge
3614
- then we make sure they are ordered according to the face vertex order
3615
- and then we construct the array */
3618
for(i=0; i<4; i++) {
3619
if(eed->v1 == verts[0][i]) p1 = i;
3620
if(eed->v2 == verts[0][i]) p2 = i;
3621
if(eed->v1 == verts[1][i]) p3 = i;
3622
if(eed->v2 == verts[1][i]) p4 = i;
3625
if((p1+1)%fac1 == p2)
3627
if((p3+1)%fac2 == p4)
3630
for (i = 0; i < 4; i++) {
3631
p[0][i]= (p1 + i)%fac1;
3632
p[1][i]= (p3 + i)%fac2;
3635
/* create an Array of the Edges who have h set prior to rotate */
3461
for(srchedge = em->edges.first;srchedge;srchedge = srchedge->next) {
3462
if(srchedge->h && (srchedge->v1->f & SELECT || srchedge->v2->f & SELECT)) {
3637
for(srchedge = em->edges.first;srchedge;srchedge = srchedge->next)
3638
if(srchedge->h && ((srchedge->v1->f & SELECT) || (srchedge->v2->f & SELECT)))
3466
hiddenedges = MEM_mallocN(sizeof(EditVert*)*numhidden+1,"Hidden Vert Scratch Array for Rotate Edges");
3641
hiddenedges = MEM_mallocN(sizeof(EditVert*)*numhidden+1, "RotateEdgeHiddenVerts");
3467
3642
if(!hiddenedges) {
3468
3643
error("Malloc Was not happy!");
3472
for(srchedge = em->edges.first;srchedge;srchedge = srchedge->next) {
3473
if(srchedge->h && (srchedge->v1->f & SELECT || srchedge->v2->f & SELECT)) {
3474
hiddenedges[numhidden] = srchedge;
3479
/* create the 2 new faces */
3648
for(srchedge=em->edges.first; srchedge; srchedge=srchedge->next)
3649
if(srchedge->h && (srchedge->v1->f & SELECT || srchedge->v2->f & SELECT))
3650
hiddenedges[numhidden++] = srchedge;
3652
/* create the 2 new faces */
3480
3653
if(fac1 == 3 && fac2 == 3) {
3481
/*No need of reverse setup*/
3482
newFace[0] = addfacelist(faces[0][(p1+1 )%3],faces[0][(p1+2 )%3],faces[1][(p3+1 )%3],NULL,NULL,NULL);
3483
newFace[1] = addfacelist(faces[1][(p3+1 )%3],faces[1][(p3+2 )%3],faces[0][(p1+1 )%3],NULL,NULL,NULL);
3485
newFace[0]->tf.col[0] = face[0]->tf.col[(p1+1 )%3];
3486
newFace[0]->tf.col[1] = face[0]->tf.col[(p1+2 )%3];
3487
newFace[0]->tf.col[2] = face[1]->tf.col[(p3+1 )%3];
3488
newFace[1]->tf.col[0] = face[1]->tf.col[(p3+1 )%3];
3489
newFace[1]->tf.col[1] = face[1]->tf.col[(p3+2 )%3];
3490
newFace[1]->tf.col[2] = face[0]->tf.col[(p1+1 )%3];
3492
UVCOPY(newFace[0]->tf.uv[0],face[0]->tf.uv[(p1+1 )%3]);
3493
UVCOPY(newFace[0]->tf.uv[1],face[0]->tf.uv[(p1+2 )%3]);
3494
UVCOPY(newFace[0]->tf.uv[2],face[1]->tf.uv[(p3+1 )%3]);
3495
UVCOPY(newFace[1]->tf.uv[0],face[1]->tf.uv[(p3+1 )%3]);
3496
UVCOPY(newFace[1]->tf.uv[1],face[1]->tf.uv[(p3+2 )%3]);
3497
UVCOPY(newFace[1]->tf.uv[2],face[0]->tf.uv[(p1+1 )%3]);
3654
/* no need of reverse setup */
3656
newFace[0]= EM_face_from_faces(face[0], face[1], p[0][1], p[0][2], 4+p[1][1], -1);
3657
newFace[1]= EM_face_from_faces(face[1], face[0], p[1][1], p[1][2], 4+p[0][1], -1);
3499
3659
else if(fac1 == 4 && fac2 == 3) {
3501
newFace[0] = addfacelist(faces[0][(p1+1 )%4],faces[0][(p1+2 )%4],faces[0][(p1+3 )%4],faces[1][(p3+1 )%3],NULL,NULL);
3502
newFace[1] = addfacelist(faces[1][(p3+1 )%3],faces[1][(p3+2 )%3],faces[0][(p1+1 )%4],NULL,NULL,NULL);
3504
newFace[0]->tf.col[0] = face[0]->tf.col[(p1+1 )%4];
3505
newFace[0]->tf.col[1] = face[0]->tf.col[(p1+2 )%4];
3506
newFace[0]->tf.col[2] = face[0]->tf.col[(p1+3 )%4];
3507
newFace[0]->tf.col[3] = face[1]->tf.col[(p3+1 )%3];
3508
newFace[1]->tf.col[0] = face[1]->tf.col[(p3+1 )%3];
3509
newFace[1]->tf.col[1] = face[1]->tf.col[(p3+2 )%3];
3510
newFace[1]->tf.col[2] = face[0]->tf.col[(p1+1 )%4];
3512
UVCOPY(newFace[0]->tf.uv[0],face[0]->tf.uv[(p1+1 )%4]);
3513
UVCOPY(newFace[0]->tf.uv[1],face[0]->tf.uv[(p1+2 )%4]);
3514
UVCOPY(newFace[0]->tf.uv[2],face[0]->tf.uv[(p1+3 )%4]);
3515
UVCOPY(newFace[0]->tf.uv[3],face[1]->tf.uv[(p3+1 )%3]);
3516
UVCOPY(newFace[1]->tf.uv[0],face[1]->tf.uv[(p3+1 )%3]);
3517
UVCOPY(newFace[1]->tf.uv[1],face[1]->tf.uv[(p3+2 )%3]);
3518
UVCOPY(newFace[1]->tf.uv[2],face[0]->tf.uv[(p1+1 )%4]);
3661
newFace[0]= EM_face_from_faces(face[0], face[1], p[0][1], p[0][2], p[0][3], 4+p[1][1]);
3662
newFace[1]= EM_face_from_faces(face[1], face[0], p[1][1], p[1][2], 4+p[0][1], -1);
3519
3663
} else if (dir == 2) {
3520
newFace[0] = addfacelist(faces[0][(p1+2 )%4],faces[1][(p3+1)%3],faces[0][(p1)%4],faces[0][(p1+1 )%4],NULL,NULL);
3521
newFace[1] = addfacelist(faces[0][(p1+2 )%4],faces[1][(p3)%3],faces[1][(p3+1 )%3],NULL,NULL,NULL);
3523
newFace[0]->tf.col[0] = face[0]->tf.col[(p1+2)%4];
3524
newFace[0]->tf.col[1] = face[1]->tf.col[(p3+1)%3];
3525
newFace[0]->tf.col[2] = face[0]->tf.col[(p1 )%4];
3526
newFace[0]->tf.col[3] = face[0]->tf.col[(p1+1)%4];
3527
newFace[1]->tf.col[0] = face[0]->tf.col[(p1+2)%4];
3528
newFace[1]->tf.col[1] = face[1]->tf.col[(p3 )%3];
3529
newFace[1]->tf.col[2] = face[1]->tf.col[(p3+1)%3];
3531
UVCOPY(newFace[0]->tf.uv[0],face[0]->tf.uv[(p1+2)%4]);
3532
UVCOPY(newFace[0]->tf.uv[1],face[1]->tf.uv[(p3+1)%3]);
3533
UVCOPY(newFace[0]->tf.uv[2],face[0]->tf.uv[(p1 )%4]);
3534
UVCOPY(newFace[0]->tf.uv[3],face[0]->tf.uv[(p1+1)%4]);
3535
UVCOPY(newFace[1]->tf.uv[0],face[0]->tf.uv[(p1+2)%4]);
3536
UVCOPY(newFace[1]->tf.uv[1],face[1]->tf.uv[(p3 )%3]);
3537
UVCOPY(newFace[1]->tf.uv[2],face[1]->tf.uv[(p3+1)%3]);
3664
newFace[0]= EM_face_from_faces(face[0], face[1], p[0][2], 4+p[1][1], p[0][0], p[0][1]);
3665
newFace[1]= EM_face_from_faces(face[1], face[0], 4+p[0][2], p[1][0], p[1][1], -1);
3539
faces[0][(p1+2)%fac1]->f |= SELECT;
3540
faces[1][(p3+1)%fac2]->f |= SELECT;
3667
verts[0][p[0][2]]->f |= SELECT;
3668
verts[1][p[1][1]]->f |= SELECT;
3544
3671
else if(fac1 == 3 && fac2 == 4) {
3546
newFace[0] = addfacelist(faces[0][(p1+1 )%3],faces[0][(p1+2 )%3],faces[1][(p3+1 )%4],NULL,NULL,NULL);
3547
newFace[1] = addfacelist(faces[1][(p3+1 )%4],faces[1][(p3+2 )%4],faces[1][(p3+3 )%4],faces[0][(p1+1 )%3],NULL,NULL);
3549
newFace[0]->tf.col[0] = face[0]->tf.col[(p1+1 )%3];
3550
newFace[0]->tf.col[1] = face[0]->tf.col[(p1+2 )%3];
3551
newFace[0]->tf.col[2] = face[1]->tf.col[(p3+1 )%4];
3552
newFace[1]->tf.col[0] = face[1]->tf.col[(p3+1 )%4];
3553
newFace[1]->tf.col[1] = face[1]->tf.col[(p3+2 )%4];
3554
newFace[1]->tf.col[2] = face[1]->tf.col[(p3+3 )%4];
3555
newFace[1]->tf.col[3] = face[0]->tf.col[(p1+1 )%3];
3557
UVCOPY(newFace[0]->tf.uv[0],face[0]->tf.uv[(p1+1 )%3]);
3558
UVCOPY(newFace[0]->tf.uv[1],face[0]->tf.uv[(p1+2 )%3]);
3559
UVCOPY(newFace[0]->tf.uv[2],face[1]->tf.uv[(p3+1 )%4]);
3560
UVCOPY(newFace[1]->tf.uv[0],face[1]->tf.uv[(p3+1 )%4]);
3561
UVCOPY(newFace[1]->tf.uv[1],face[1]->tf.uv[(p3+2 )%4]);
3562
UVCOPY(newFace[1]->tf.uv[2],face[1]->tf.uv[(p3+3 )%4]);
3563
UVCOPY(newFace[1]->tf.uv[3],face[0]->tf.uv[(p1+1 )%3]);
3673
newFace[0]= EM_face_from_faces(face[0], face[1], p[0][1], p[0][2], 4+p[1][1], -1);
3674
newFace[1]= EM_face_from_faces(face[1], face[0], p[1][1], p[1][2], p[1][3], 4+p[0][1]);
3564
3675
} else if (dir == 2) {
3565
newFace[0] = addfacelist(faces[0][(p1)%3],faces[0][(p1+1 )%3],faces[1][(p3+2 )%4],NULL,NULL,NULL);
3566
newFace[1] = addfacelist(faces[1][(p3+1 )%4],faces[1][(p3+2 )%4],faces[0][(p1+1 )%3],faces[0][(p1+2 )%3],NULL,NULL);
3568
newFace[0]->tf.col[0] = face[0]->tf.col[(p1 )%3];
3569
newFace[0]->tf.col[1] = face[0]->tf.col[(p1+1 )%3];
3570
newFace[0]->tf.col[2] = face[1]->tf.col[(p3+2 )%4];
3571
newFace[1]->tf.col[0] = face[1]->tf.col[(p3+1 )%4];
3572
newFace[1]->tf.col[1] = face[1]->tf.col[(p3+2 )%4];
3573
newFace[1]->tf.col[2] = face[0]->tf.col[(p1+1 )%3];
3574
newFace[1]->tf.col[3] = face[0]->tf.col[(p1+2 )%3];
3576
UVCOPY(newFace[0]->tf.uv[0],face[0]->tf.uv[(p1 )%3]);
3577
UVCOPY(newFace[0]->tf.uv[1],face[0]->tf.uv[(p1+1 )%3]);
3578
UVCOPY(newFace[0]->tf.uv[2],face[1]->tf.uv[(p3+2 )%4]);
3579
UVCOPY(newFace[1]->tf.uv[0],face[1]->tf.uv[(p3+1 )%4]);
3580
UVCOPY(newFace[1]->tf.uv[1],face[1]->tf.uv[(p3+2 )%4]);
3581
UVCOPY(newFace[1]->tf.uv[2],face[0]->tf.uv[(p1+1 )%3]);
3582
UVCOPY(newFace[1]->tf.uv[3],face[0]->tf.uv[(p1+2 )%3]);
3676
newFace[0]= EM_face_from_faces(face[0], face[1], p[0][0], p[0][1], 4+p[1][2], -1);
3677
newFace[1]= EM_face_from_faces(face[1], face[0], p[1][1], p[1][2], 4+p[0][1], 4+p[0][2]);
3584
faces[0][(p1+1)%fac1]->f |= SELECT;
3585
faces[1][(p3+2)%fac2]->f |= SELECT;
3679
verts[0][p[0][1]]->f |= SELECT;
3680
verts[1][p[1][2]]->f |= SELECT;
3590
3684
else if(fac1 == 4 && fac2 == 4) {
3592
newFace[0] = addfacelist(faces[0][(p1+1 )%4],faces[0][(p1+2 )%4],faces[0][(p1+3 )%4],faces[1][(p3+1 )%4],NULL,NULL);
3593
newFace[1] = addfacelist(faces[1][(p3+1 )%4],faces[1][(p3+2 )%4],faces[1][(p3+3 )%4],faces[0][(p1+1 )%4],NULL,NULL);
3595
newFace[0]->tf.col[0] = face[0]->tf.col[(p1+1 )%4];
3596
newFace[0]->tf.col[1] = face[0]->tf.col[(p1+2 )%4];
3597
newFace[0]->tf.col[2] = face[0]->tf.col[(p1+3 )%4];
3598
newFace[0]->tf.col[3] = face[1]->tf.col[(p3+1 )%4];
3599
newFace[1]->tf.col[0] = face[1]->tf.col[(p3+1 )%4];
3600
newFace[1]->tf.col[1] = face[1]->tf.col[(p3+2 )%4];
3601
newFace[1]->tf.col[2] = face[1]->tf.col[(p3+3 )%4];
3602
newFace[1]->tf.col[3] = face[0]->tf.col[(p1+1 )%4];
3604
UVCOPY(newFace[0]->tf.uv[0],face[0]->tf.uv[(p1+1 )%4]);
3605
UVCOPY(newFace[0]->tf.uv[1],face[0]->tf.uv[(p1+2 )%4]);
3606
UVCOPY(newFace[0]->tf.uv[2],face[0]->tf.uv[(p1+3 )%4]);
3607
UVCOPY(newFace[0]->tf.uv[3],face[1]->tf.uv[(p3+1 )%4]);
3608
UVCOPY(newFace[1]->tf.uv[0],face[1]->tf.uv[(p3+1 )%4]);
3609
UVCOPY(newFace[1]->tf.uv[1],face[1]->tf.uv[(p3+2 )%4]);
3610
UVCOPY(newFace[1]->tf.uv[2],face[1]->tf.uv[(p3+3 )%4]);
3611
UVCOPY(newFace[1]->tf.uv[3],face[0]->tf.uv[(p1+1 )%4]);
3686
newFace[0]= EM_face_from_faces(face[0], face[1], p[0][1], p[0][2], p[0][3], 4+p[1][1]);
3687
newFace[1]= EM_face_from_faces(face[1], face[0], p[1][1], p[1][2], p[1][3], 4+p[0][1]);
3612
3688
} else if (dir == 2) {
3613
newFace[0] = addfacelist(faces[0][(p1+2 )%4],faces[0][(p1+3 )%4],faces[1][(p3+1 )%4],faces[1][(p3+2 )%4],NULL,NULL);
3614
newFace[1] = addfacelist(faces[1][(p3+2 )%4],faces[1][(p3+3 )%4],faces[0][(p1+1 )%4],faces[0][(p1+2 )%4],NULL,NULL);
3616
newFace[0]->tf.col[0] = face[0]->tf.col[(p1+2 )%4];
3617
newFace[0]->tf.col[1] = face[0]->tf.col[(p1+3 )%4];
3618
newFace[0]->tf.col[2] = face[1]->tf.col[(p3+1 )%4];
3619
newFace[0]->tf.col[3] = face[1]->tf.col[(p3+2 )%4];
3620
newFace[1]->tf.col[0] = face[1]->tf.col[(p3+2 )%4];
3621
newFace[1]->tf.col[1] = face[1]->tf.col[(p3+3 )%4];
3622
newFace[1]->tf.col[2] = face[0]->tf.col[(p1+1 )%4];
3623
newFace[1]->tf.col[3] = face[0]->tf.col[(p1+2 )%4];
3625
UVCOPY(newFace[0]->tf.uv[0],face[0]->tf.uv[(p1+2 )%4]);
3626
UVCOPY(newFace[0]->tf.uv[1],face[0]->tf.uv[(p1+3 )%4]);
3627
UVCOPY(newFace[0]->tf.uv[2],face[1]->tf.uv[(p3+1 )%4]);
3628
UVCOPY(newFace[0]->tf.uv[3],face[1]->tf.uv[(p3+2 )%4]);
3629
UVCOPY(newFace[1]->tf.uv[0],face[1]->tf.uv[(p3+2 )%4]);
3630
UVCOPY(newFace[1]->tf.uv[1],face[1]->tf.uv[(p3+3 )%4]);
3631
UVCOPY(newFace[1]->tf.uv[2],face[0]->tf.uv[(p1+1 )%4]);
3632
UVCOPY(newFace[1]->tf.uv[3],face[0]->tf.uv[(p1+2 )%4]);
3689
newFace[0]= EM_face_from_faces(face[0], face[1], p[0][2], p[0][3], 4+p[1][1], 4+p[1][2]);
3690
newFace[1]= EM_face_from_faces(face[1], face[0], p[1][2], p[1][3], 4+p[0][1], 4+p[0][2]);
3634
faces[0][(p1+2)%fac1]->f |= SELECT;
3635
faces[1][(p3+2)%fac2]->f |= SELECT;
3692
verts[0][p[0][2]]->f |= SELECT;
3693
verts[1][p[1][2]]->f |= SELECT;
3641
/*This should never happen*/
3697
return; /* This should never happen */
3646
faces[0][(p1+1)%fac1]->f |= SELECT;
3647
faces[1][(p3+1)%fac2]->f |= SELECT;
3699
if(dir == 1 || (fac1 == 3 && fac2 == 3)) {
3700
verts[0][p[0][1]]->f |= SELECT;
3701
verts[1][p[1][1]]->f |= SELECT;
3650
/*Copy old edge's flags to new center edge*/
3704
/* copy old edge's flags to new center edge*/
3651
3705
for(srchedge=em->edges.first;srchedge;srchedge=srchedge->next) {
3652
if(srchedge->v1->f & SELECT &&srchedge->v2->f & SELECT ) {
3706
if((srchedge->v1->f & SELECT) && (srchedge->v2->f & SELECT)) {
3653
3707
srchedge->f = eed->f;
3654
3708
srchedge->h = eed->h;
3655
3709
srchedge->dir = eed->dir;
3656
3710
srchedge->seam = eed->seam;
3657
3711
srchedge->crease = eed->crease;
3712
srchedge->bweight = eed->bweight;
3662
/* copy flags and material */
3664
newFace[0]->mat_nr = face[0]->mat_nr;
3665
newFace[0]->tf.flag = face[0]->tf.flag;
3666
newFace[0]->tf.transp = face[0]->tf.transp;
3667
newFace[0]->tf.mode = face[0]->tf.mode;
3668
newFace[0]->tf.tile = face[0]->tf.tile;
3669
newFace[0]->tf.unwrap = face[0]->tf.unwrap;
3670
newFace[0]->tf.tpage = face[0]->tf.tpage;
3671
newFace[0]->flag = face[0]->flag;
3673
newFace[1]->mat_nr = face[1]->mat_nr;
3674
newFace[1]->tf.flag = face[1]->tf.flag;
3675
newFace[1]->tf.transp = face[1]->tf.transp;
3676
newFace[1]->tf.mode = face[1]->tf.mode;
3677
newFace[1]->tf.tile = face[1]->tf.tile;
3678
newFace[1]->tf.unwrap = face[1]->tf.unwrap;
3679
newFace[1]->tf.tpage = face[1]->tf.tpage;
3680
newFace[1]->flag = face[1]->flag;
3682
/* Resetting Hidden Flag */
3683
for(numhidden--;numhidden>=0;numhidden--) {
3684
hiddenedges[numhidden]->h = 1;
3716
/* resetting hidden flag */
3717
for(numhidden--; numhidden>=0; numhidden--)
3718
hiddenedges[numhidden]->h= 1;
3688
3720
/* check for orhphan edges */
3689
for(srchedge=em->edges.first;srchedge;srchedge = srchedge->next) {
3721
for(srchedge=em->edges.first; srchedge; srchedge=srchedge->next)
3693
/*for(efa = em->faces.first;efa;efa = efa->next) {
3703
if(efa->e1->f1 == -1) {
3706
if(efa->e2->f1 == -1) {
3709
if(efa->e1->f1 == -1) {
3718
3725
MEM_freeN(hiddenedges);
3720
3727
/* get rid of the old edge and faces*/
6552
6678
freecollections(&allcollections);
6553
6679
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
6554
6680
allqueue(REDRAWVIEW3D, 0);
6681
if (EM_texFaceCheck())
6682
allqueue(REDRAWIMAGE, 0);
6555
6683
BIF_undo_push("Edge Loop to Face Region");
6687
/* texface and vertex color editmode tools for the face menu */
6689
void mesh_rotate_uvs(void)
6691
EditMesh *em = G.editMesh;
6693
short change = 0, ccw;
6697
if (!EM_texFaceCheck()) {
6698
error("mesh has no uv/image layers");
6702
ccw = (G.qual == LR_SHIFTKEY);
6704
for(efa=em->faces.first; efa; efa=efa->next) {
6705
if (efa->f & SELECT) {
6706
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
6712
tf->uv[0][0]= tf->uv[3][0];
6713
tf->uv[0][1]= tf->uv[3][1];
6715
tf->uv[3][0]= tf->uv[2][0];
6716
tf->uv[3][1]= tf->uv[2][1];
6718
tf->uv[0][0]= tf->uv[2][0];
6719
tf->uv[0][1]= tf->uv[2][1];
6722
tf->uv[2][0]= tf->uv[1][0];
6723
tf->uv[2][1]= tf->uv[1][1];
6728
tf->uv[0][0]= tf->uv[1][0];
6729
tf->uv[0][1]= tf->uv[1][1];
6731
tf->uv[1][0]= tf->uv[2][0];
6732
tf->uv[1][1]= tf->uv[2][1];
6735
tf->uv[2][0]= tf->uv[3][0];
6736
tf->uv[2][1]= tf->uv[3][1];
6751
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
6752
allqueue(REDRAWVIEW3D, 0);
6753
BIF_undo_push("Rotate UV face");
6757
void mesh_mirror_uvs(void)
6759
EditMesh *em = G.editMesh;
6761
short change = 0, altaxis;
6765
if (!EM_texFaceCheck()) {
6766
error("mesh has no uv/image layers");
6770
altaxis = (G.qual == LR_SHIFTKEY);
6772
for(efa=em->faces.first; efa; efa=efa->next) {
6773
if (efa->f & SELECT) {
6774
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
6780
tf->uv[1][0]= tf->uv[2][0];
6781
tf->uv[1][1]= tf->uv[2][1];
6789
tf->uv[3][0]= tf->uv[0][0];
6790
tf->uv[3][1]= tf->uv[0][1];
6796
tf->uv[1][0]= tf->uv[2][0];
6797
tf->uv[1][1]= tf->uv[2][1];
6807
tf->uv[0][0]= tf->uv[1][0];
6808
tf->uv[0][1]= tf->uv[1][1];
6816
tf->uv[3][0]= tf->uv[2][0];
6817
tf->uv[3][1]= tf->uv[2][1];
6823
tf->uv[0][0]= tf->uv[1][0];
6824
tf->uv[0][1]= tf->uv[1][1];
6834
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
6835
allqueue(REDRAWVIEW3D, 0);
6836
BIF_undo_push("Mirror UV face");
6840
void mesh_rotate_colors(void)
6842
EditMesh *em = G.editMesh;
6844
short change = 0, ccw;
6846
if (!EM_vertColorCheck()) {
6847
error("mesh has no color layers");
6851
ccw = (G.qual == LR_SHIFTKEY);
6853
for(efa=em->faces.first; efa; efa=efa->next) {
6854
if (efa->f & SELECT) {
6855
mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
6883
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
6884
allqueue(REDRAWVIEW3D, 0);
6885
BIF_undo_push("Rotate Color face");
6889
void mesh_mirror_colors(void)
6891
EditMesh *em = G.editMesh;
6893
short change = 0, altaxis;
6895
if (!EM_vertColorCheck()) {
6896
error("mesh has no color layers");
6900
altaxis = (G.qual == LR_SHIFTKEY);
6902
for(efa=em->faces.first; efa; efa=efa->next) {
6903
if (efa->f & SELECT) {
6904
mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
6931
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
6932
allqueue(REDRAWVIEW3D, 0);
6933
BIF_undo_push("Mirror Color face");