1 |
– |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Convert a Wavefront .obj file to Radiance format. |
6 |
|
* |
557 |
|
BARYCCM bvecs; |
558 |
|
FLOAT bcoor[3][3]; |
559 |
|
int texOK, patOK; |
560 |
+ |
int flatness; |
561 |
|
register int i; |
562 |
|
|
563 |
|
if ((mod = getmtl()) == NULL) |
566 |
|
if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3)) |
567 |
|
return(0); |
568 |
|
/* compute barycentric coordinates */ |
569 |
< |
if (!flatten && v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0) |
570 |
< |
switch (flat_tri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]], |
571 |
< |
vnlist[v1i[2]], vnlist[v2i[2]], vnlist[v3i[2]])) { |
574 |
< |
case DEGEN: /* zero area */ |
575 |
< |
return(-1); |
576 |
< |
case RVFLAT: /* reversed normals, but flat */ |
577 |
< |
case ISFLAT: /* smoothing unnecessary */ |
578 |
< |
texOK = 0; |
579 |
< |
break; |
580 |
< |
case RVBENT: /* reversed normals with smoothing */ |
581 |
< |
case ISBENT: /* proper smoothing */ |
582 |
< |
texOK = 1; |
583 |
< |
break; |
584 |
< |
} |
569 |
> |
if (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0) |
570 |
> |
flatness = flat_tri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]], |
571 |
> |
vnlist[v1i[2]], vnlist[v2i[2]], vnlist[v3i[2]]); |
572 |
|
else |
573 |
+ |
flatness = ISFLAT; |
574 |
+ |
|
575 |
+ |
switch (flatness) { |
576 |
+ |
case DEGEN: /* zero area */ |
577 |
+ |
return(-1); |
578 |
+ |
case RVFLAT: /* reversed normals, but flat */ |
579 |
+ |
case ISFLAT: /* smoothing unnecessary */ |
580 |
|
texOK = 0; |
581 |
+ |
break; |
582 |
+ |
case RVBENT: /* reversed normals with smoothing */ |
583 |
+ |
case ISBENT: /* proper smoothing */ |
584 |
+ |
texOK = 1; |
585 |
+ |
break; |
586 |
+ |
} |
587 |
+ |
if (flatten) |
588 |
+ |
texOK = 0; |
589 |
|
#ifdef TEXMAPS |
590 |
|
patOK = mapname[0] && (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0); |
591 |
|
#else |
623 |
|
put_baryc(&bvecs, bcoor, 2); |
624 |
|
} |
625 |
|
#endif |
626 |
< |
/* put out triangle */ |
626 |
> |
/* put out (reversed) triangle */ |
627 |
|
printf("\n%s polygon %s.%d\n", mod, getonm(), faceno); |
628 |
|
printf("0\n0\n9\n"); |
629 |
< |
pvect(vlist[v1i[0]]); |
630 |
< |
pvect(vlist[v2i[0]]); |
631 |
< |
pvect(vlist[v3i[0]]); |
632 |
< |
|
629 |
> |
if (flatness == RVFLAT || flatness == RVBENT) { |
630 |
> |
pvect(vlist[v3i[0]]); |
631 |
> |
pvect(vlist[v2i[0]]); |
632 |
> |
pvect(vlist[v1i[0]]); |
633 |
> |
} else { |
634 |
> |
pvect(vlist[v1i[0]]); |
635 |
> |
pvect(vlist[v2i[0]]); |
636 |
> |
pvect(vlist[v3i[0]]); |
637 |
> |
} |
638 |
|
return(1); |
639 |
|
} |
640 |
|
|
642 |
|
freeverts() /* free all vertices */ |
643 |
|
{ |
644 |
|
if (nvs) { |
645 |
< |
free((char *)vlist); |
645 |
> |
free((void *)vlist); |
646 |
|
nvs = 0; |
647 |
|
} |
648 |
|
if (nvts) { |
649 |
< |
free((char *)vtlist); |
649 |
> |
free((void *)vtlist); |
650 |
|
nvts = 0; |
651 |
|
} |
652 |
|
if (nvns) { |
653 |
< |
free((char *)vnlist); |
653 |
> |
free((void *)vnlist); |
654 |
|
nvns = 0; |
655 |
|
} |
656 |
|
} |