| 307 |
|
if ((mat = material()) == NULL) /* get material */ |
| 308 |
|
return(MG_EBADMAT); |
| 309 |
|
if (ac <= 5) { /* check for smoothing */ |
| 310 |
+ |
C_VERTEX *cva[5]; |
| 311 |
|
for (i = 1; i < ac; i++) { |
| 312 |
< |
if ((cv = c_getvert(av[i])) == NULL) |
| 312 |
> |
if ((cva[i-1] = c_getvert(av[i])) == NULL) |
| 313 |
|
return(MG_EUNDEF); |
| 314 |
< |
if (is0vect(cv->n)) |
| 314 |
> |
if (is0vect(cva[i-1]->n)) |
| 315 |
|
break; |
| 316 |
|
} |
| 317 |
< |
if (i == ac) { /* break into triangles */ |
| 318 |
< |
do_tri(mat, av[1], av[2], av[3]); |
| 317 |
> |
if (i == ac) { |
| 318 |
> |
i = flat_tri(cva[0]->p, cva[1]->p, cva[2]->p, |
| 319 |
> |
cva[0]->n, cva[1]->n, cva[2]->n); |
| 320 |
> |
if (i < 0) |
| 321 |
> |
return(MG_OK); /* degenerate (error?) */ |
| 322 |
> |
} |
| 323 |
> |
if (!i) { /* smoothed triangles */ |
| 324 |
> |
do_tri(mat, cva[0], cva[1], cva[2]); |
| 325 |
|
if (ac == 5) |
| 326 |
< |
do_tri(mat, av[3], av[4], av[1]); |
| 326 |
> |
do_tri(mat, cva[2], cva[3], cva[0]); |
| 327 |
|
return(MG_OK); |
| 328 |
|
} |
| 329 |
|
} |
| 355 |
|
if (ac < 2) |
| 356 |
|
return(MG_EARGC); |
| 357 |
|
/* construct output file name */ |
| 358 |
< |
if ((op = strrchr(av[1], '/')) == NULL) |
| 358 |
> |
if ((op = strrchr(av[1], '/')) != NULL) |
| 359 |
> |
op++; |
| 360 |
> |
else |
| 361 |
|
op = av[1]; |
| 362 |
|
(void)strcpy(fname, op); |
| 363 |
|
if ((op = strrchr(fname, '.')) == NULL) |
| 405 |
|
} |
| 406 |
|
|
| 407 |
|
|
| 408 |
< |
do_tri(mat, vn1, vn2, vn3) /* put out smoothed triangle */ |
| 409 |
< |
char *mat, *vn1, *vn2, *vn3; |
| 408 |
> |
do_tri(mat, cv1, cv2, cv3) /* put out smoothed triangle */ |
| 409 |
> |
char *mat; |
| 410 |
> |
C_VERTEX *cv1, *cv2, *cv3; |
| 411 |
|
{ |
| 412 |
|
static int ntris; |
| 413 |
|
BARYCCM bvecs; |
| 414 |
|
FLOAT bcoor[3][3]; |
| 415 |
< |
C_VERTEX *cv1, *cv2, *cv3; |
| 415 |
> |
C_VERTEX *cvt; |
| 416 |
|
FVECT v1, v2, v3; |
| 417 |
|
FVECT n1, n2, n3; |
| 418 |
|
register int i; |
| 419 |
< |
/* the following is repeat code, so assume it's OK */ |
| 420 |
< |
cv2 = c_getvert(vn2); |
| 421 |
< |
if (invert) { |
| 422 |
< |
cv3 = c_getvert(vn1); |
| 423 |
< |
cv1 = c_getvert(vn3); |
| 414 |
< |
} else { |
| 415 |
< |
cv1 = c_getvert(vn1); |
| 416 |
< |
cv3 = c_getvert(vn3); |
| 419 |
> |
|
| 420 |
> |
if (invert) { /* swap vertex order if inverted */ |
| 421 |
> |
cvt = cv1; |
| 422 |
> |
cv1 = cv3; |
| 423 |
> |
cv3 = cvt; |
| 424 |
|
} |
| 425 |
|
xf_xfmpoint(v1, cv1->p); |
| 426 |
|
xf_xfmpoint(v2, cv2->p); |