| 10 |
|
* Currently, we support only polygonal geometry. Non-planar |
| 11 |
|
* faces are broken rather haphazardly into triangles. |
| 12 |
|
* Also, texture map indices only work for triangles, though |
| 13 |
< |
* I'm not sure they work correctly. |
| 13 |
> |
* I'm not sure they work correctly. (Taken out -- see TEXMAPS defines.) |
| 14 |
|
*/ |
| 15 |
|
|
| 16 |
|
#include "standard.h" |
| 70 |
|
char *defmat = DEFMAT; /* default (starting) material name */ |
| 71 |
|
char *defobj = DEFOBJ; /* default (starting) object name */ |
| 72 |
|
|
| 73 |
+ |
int flatten = 0; /* discard surface normal information */ |
| 74 |
+ |
|
| 75 |
|
char *getmtl(), *getonm(); |
| 76 |
|
|
| 77 |
|
char mapname[128]; /* current picture file */ |
| 101 |
|
case 'm': /* use custom mapfile */ |
| 102 |
|
ourmapping = getmapping(argv[++i], &qlist); |
| 103 |
|
break; |
| 104 |
+ |
case 'f': /* flatten surfaces */ |
| 105 |
+ |
flatten++; |
| 106 |
+ |
break; |
| 107 |
|
default: |
| 108 |
|
goto userr; |
| 109 |
|
} |
| 130 |
|
} |
| 131 |
|
exit(0); |
| 132 |
|
userr: |
| 133 |
< |
fprintf(stderr, "Usage: %s [-o obj][-m mapping][-n] [file.obj]\n", |
| 133 |
> |
fprintf(stderr, "Usage: %s [-o obj][-m mapping][-n][-f] [file.obj]\n", |
| 134 |
|
argv[0]); |
| 135 |
|
exit(1); |
| 136 |
|
} |
| 259 |
|
if (!strcmp(argv[1], "off")) |
| 260 |
|
mapname[0] = '\0'; |
| 261 |
|
else |
| 262 |
< |
strcpy(mapname, argv[1]); |
| 262 |
> |
sprintf(mapname, "%s.pic", argv[1]); |
| 263 |
|
} else |
| 264 |
|
goto unknown; |
| 265 |
|
break; |
| 278 |
|
group[i-1][0] = '\0'; |
| 279 |
|
break; |
| 280 |
|
case '#': /* comment */ |
| 281 |
+ |
printargs(argc, argv, stdout); |
| 282 |
|
break; |
| 283 |
|
default:; /* something we don't deal with */ |
| 284 |
|
unknown: |
| 440 |
|
if (vi[0]-- > nvs) |
| 441 |
|
return(0); |
| 442 |
|
} else if (vi[0] < 0) { |
| 443 |
< |
vi[0] = nvs + vi[0]; |
| 443 |
> |
vi[0] += nvs; |
| 444 |
|
if (vi[0] < 0) |
| 445 |
|
return(0); |
| 446 |
|
} else |
| 454 |
|
if (vi[1]-- > nvts) |
| 455 |
|
return(0); |
| 456 |
|
} else if (vi[1] < 0) { |
| 457 |
< |
vi[1] = nvts + vi[1]; |
| 457 |
> |
vi[1] += nvts; |
| 458 |
|
if (vi[1] < 0) |
| 459 |
|
return(0); |
| 460 |
|
} else |
| 468 |
|
if (vi[2]-- > nvns) |
| 469 |
|
return(0); |
| 470 |
|
} else if (vi[2] < 0) { |
| 471 |
< |
vi[2] = nvns + vi[2]; |
| 471 |
> |
vi[2] += nvns; |
| 472 |
|
if (vi[2] < 0) |
| 473 |
|
return(0); |
| 474 |
|
} else |
| 477 |
|
} |
| 478 |
|
|
| 479 |
|
|
| 480 |
< |
nonplanar(ac, av) /* are vertices are non-planar? */ |
| 480 |
> |
nonplanar(ac, av) /* are vertices non-planar? */ |
| 481 |
|
register int ac; |
| 482 |
|
register char **av; |
| 483 |
|
{ |
| 533 |
|
register char **av; |
| 534 |
|
{ |
| 535 |
|
VNDX vi; |
| 536 |
< |
char *mod; |
| 536 |
> |
char *cp; |
| 537 |
|
register int i; |
| 538 |
|
|
| 539 |
|
if (nonplanar(ac, av)) { /* break into quads and triangles */ |
| 540 |
|
while (ac > 3) { |
| 541 |
|
if (!putquad(av[0], av[1], av[2], av[3])) |
| 542 |
|
return(0); |
| 543 |
< |
/* remove two vertices & rotate */ |
| 544 |
< |
av[ac -= 2] = av[0]; |
| 545 |
< |
for (i = 0; i <= ac; i++) |
| 546 |
< |
av[i] = av[i+2]; |
| 543 |
> |
ac -= 2; /* remove two vertices & rotate */ |
| 544 |
> |
cp = av[0]; |
| 545 |
> |
for (i = 0; i < ac-1; i++) |
| 546 |
> |
av[i] = av[i+3]; |
| 547 |
> |
av[i] = cp; |
| 548 |
|
} |
| 549 |
|
if (ac == 3 && !puttri(av[0], av[1], av[2])) |
| 550 |
|
return(0); |
| 551 |
|
return(1); |
| 552 |
|
} |
| 553 |
< |
if ((mod = getmtl()) == NULL) |
| 553 |
> |
if ((cp = getmtl()) == NULL) |
| 554 |
|
return(-1); |
| 555 |
< |
printf("\n%s polygon %s.%d\n", mod, getonm(), faceno); |
| 555 |
> |
printf("\n%s polygon %s.%d\n", cp, getonm(), faceno); |
| 556 |
|
printf("0\n0\n%d\n", 3*ac); |
| 557 |
|
for (i = 0; i < ac; i++) { |
| 558 |
|
if (!cvtndx(vi, av[i])) |
| 577 |
|
if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3)) |
| 578 |
|
return(0); |
| 579 |
|
/* compute barycentric coordinates */ |
| 580 |
< |
texOK = (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0); |
| 580 |
> |
texOK = !flatten && (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0); |
| 581 |
> |
#ifdef TEXMAPS |
| 582 |
|
patOK = mapname[0] && (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0); |
| 583 |
+ |
#else |
| 584 |
+ |
patOK = 0; |
| 585 |
+ |
#endif |
| 586 |
|
if (texOK | patOK) |
| 587 |
|
if (comp_baryc(bvecs, vlist[v1i[0]], vlist[v2i[0]], |
| 588 |
|
vlist[v3i[0]]) < 0) |
| 604 |
|
vnlist[v1i[2]][2], vnlist[v2i[2]][2], |
| 605 |
|
vnlist[v3i[2]][2]); |
| 606 |
|
} |
| 607 |
+ |
#ifdef TEXMAPS |
| 608 |
|
/* put out pattern (if any) */ |
| 609 |
|
if (patOK) { |
| 610 |
|
printf("\n%s colorpict %s\n", mod, PATNAME); |
| 617 |
|
printf("\t%f %f %f\n", vtlist[v1i[1]][1], |
| 618 |
|
vtlist[v2i[1]][1], vtlist[v3i[1]][1]); |
| 619 |
|
} |
| 620 |
+ |
#endif |
| 621 |
|
/* put out triangle */ |
| 622 |
|
printf("\n%s polygon %s.%d\n", mod, getonm(), faceno); |
| 623 |
|
printf("0\n0\n9\n"); |
| 689 |
|
FVECT v1, v2, vc1, vc2; |
| 690 |
|
int ok1, ok2; |
| 691 |
|
|
| 692 |
+ |
#ifdef TEXMAPS |
| 693 |
+ |
/* also should output texture index coordinates, |
| 694 |
+ |
* which will require new .cal file |
| 695 |
+ |
*/ |
| 696 |
+ |
#endif |
| 697 |
|
if ((mod = getmtl()) == NULL) |
| 698 |
|
return(-1); |
| 699 |
|
name = getonm(); |
| 794 |
|
FVECT v1; |
| 795 |
|
register int i, j; |
| 796 |
|
|
| 797 |
< |
if (!(p0i[2]>=0 && p1i[2]>=0 && p2i[2]>=0 && p3i[2]>=0)) |
| 797 |
> |
#ifdef TEXMAPS |
| 798 |
> |
/* also check for texture indices */ |
| 799 |
> |
#endif |
| 800 |
> |
if (flatten || !(p0i[2]>=0 && p1i[2]>=0 && p2i[2]>=0 && p3i[2]>=0)) |
| 801 |
|
return(-1); |
| 802 |
|
/* find dominant axis */ |
| 803 |
|
VCOPY(v1, vnlist[p0i[2]]); |
| 833 |
|
eqnmat[j][1]*vnlist[p1i[2]][i] + |
| 834 |
|
eqnmat[j][2]*vnlist[p2i[2]][i] + |
| 835 |
|
eqnmat[j][3]*vnlist[p3i[2]][i]; |
| 836 |
+ |
#ifdef TEXMAPS |
| 837 |
+ |
/* compute result matrix for texture indices */ |
| 838 |
+ |
#endif |
| 839 |
|
return(ax); |
| 840 |
|
|
| 841 |
|
#undef u |