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 |
|
* |
10 |
|
* I'm not sure they work correctly. (Taken out -- see TEXMAPS defines.) |
11 |
|
*/ |
12 |
|
|
13 |
< |
#include "standard.h" |
13 |
> |
#include <stdlib.h> |
14 |
> |
#include <stdio.h> |
15 |
> |
#include <ctype.h> |
16 |
|
|
17 |
+ |
#include "rtmath.h" |
18 |
+ |
#include "rtio.h" |
19 |
+ |
#include "resolu.h" |
20 |
|
#include "trans.h" |
21 |
+ |
#include "tmesh.h" |
22 |
|
|
20 |
– |
#include <ctype.h> |
23 |
|
|
22 |
– |
#define TCALNAME "tmesh.cal" /* triangle interp. file */ |
23 |
– |
#define QCALNAME "surf.cal" /* quad interp. file */ |
24 |
|
#define PATNAME "M-pat" /* mesh pattern name (reused) */ |
25 |
|
#define TEXNAME "M-nor" /* mesh texture name (reused) */ |
26 |
|
#define DEFOBJ "unnamed" /* default object name */ |
27 |
|
#define DEFMAT "white" /* default material name */ |
28 |
|
|
29 |
– |
#define ABS(x) ((x)>=0 ? (x) : -(x)) |
30 |
– |
|
29 |
|
#define pvect(v) printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2]) |
30 |
|
|
31 |
|
FVECT *vlist; /* our vertex list */ |
32 |
|
int nvs; /* number of vertices in our list */ |
33 |
|
FVECT *vnlist; /* vertex normal list */ |
34 |
|
int nvns; |
35 |
< |
FLOAT (*vtlist)[2]; /* map vertex list */ |
35 |
> |
RREAL (*vtlist)[2]; /* map vertex list */ |
36 |
|
int nvts; |
37 |
|
|
40 |
– |
typedef struct { |
41 |
– |
int ax; /* major axis */ |
42 |
– |
FLOAT tm[2][3]; /* transformation */ |
43 |
– |
} BARYCCM; |
44 |
– |
|
38 |
|
typedef int VNDX[3]; /* vertex index (point,map,normal) */ |
39 |
|
|
40 |
< |
#define CHUNKSIZ 256 /* vertex allocation chunk size */ |
40 |
> |
#define CHUNKSIZ 1024 /* vertex allocation chunk size */ |
41 |
|
|
42 |
< |
#define MAXARG 64 /* maximum # arguments in a statement */ |
42 |
> |
#define MAXARG 512 /* maximum # arguments in a statement */ |
43 |
|
|
44 |
|
/* qualifiers */ |
45 |
|
#define Q_MTL 0 |
68 |
|
|
69 |
|
int flatten = 0; /* discard surface normal information */ |
70 |
|
|
78 |
– |
char *getmtl(), *getonm(); |
79 |
– |
|
71 |
|
char mapname[128]; /* current picture file */ |
72 |
|
char matname[64]; /* current material name */ |
73 |
|
char group[16][32]; /* current group names */ |
76 |
|
int lineno; /* current line number */ |
77 |
|
int faceno; /* current face number */ |
78 |
|
|
79 |
+ |
static void getnames(FILE *fp); |
80 |
+ |
static void convert(FILE *fp); |
81 |
+ |
static int getstmt(char *av[MAXARG], FILE *fp); |
82 |
+ |
static char * getmtl(void); |
83 |
+ |
static char * getonm(void); |
84 |
+ |
static int matchrule(RULEHD *rp); |
85 |
+ |
static int cvtndx(VNDX vi, char *vs); |
86 |
+ |
static int nonplanar(int ac, char **av); |
87 |
+ |
static int putface(int ac, char **av); |
88 |
+ |
static int puttri(char *v1, char *v2, char *v3); |
89 |
+ |
static void freeverts(void); |
90 |
+ |
static int newv(double x, double y, double z); |
91 |
+ |
static int newvn(double x, double y, double z); |
92 |
+ |
static int newvt(double x, double y); |
93 |
+ |
static void syntax(char *er); |
94 |
|
|
95 |
< |
main(argc, argv) /* read in .obj file and convert */ |
96 |
< |
int argc; |
97 |
< |
char *argv[]; |
95 |
> |
|
96 |
> |
int |
97 |
> |
main( /* read in .obj file and convert */ |
98 |
> |
int argc, |
99 |
> |
char *argv[] |
100 |
> |
) |
101 |
|
{ |
102 |
|
int donames = 0; |
103 |
|
int i; |
119 |
|
default: |
120 |
|
goto userr; |
121 |
|
} |
122 |
< |
if (i > argc | i < argc-1) |
122 |
> |
if ((i > argc) | (i < argc-1)) |
123 |
|
goto userr; |
124 |
|
if (i == argc) |
125 |
|
inpfile = "<stdin>"; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
< |
getnames(fp) /* get valid qualifier names */ |
152 |
< |
FILE *fp; |
151 |
> |
void |
152 |
> |
getnames( /* get valid qualifier names */ |
153 |
> |
FILE *fp |
154 |
> |
) |
155 |
|
{ |
156 |
|
char *argv[MAXARG]; |
157 |
|
int argc; |
158 |
|
ID tmpid; |
159 |
|
register int i; |
160 |
|
|
161 |
< |
while (argc = getstmt(argv, fp)) |
161 |
> |
while ( (argc = getstmt(argv, fp)) ) |
162 |
|
switch (argv[0][0]) { |
163 |
|
case 'f': /* face */ |
164 |
|
if (!argv[0][1]) |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
< |
convert(fp) /* convert a T-mesh */ |
203 |
< |
FILE *fp; |
202 |
> |
void |
203 |
> |
convert( /* convert a T-mesh */ |
204 |
> |
FILE *fp |
205 |
> |
) |
206 |
|
{ |
207 |
|
char *argv[MAXARG]; |
208 |
|
int argc; |
211 |
|
|
212 |
|
nstats = nunknown = 0; |
213 |
|
/* scan until EOF */ |
214 |
< |
while (argc = getstmt(argv, fp)) { |
214 |
> |
while ( (argc = getstmt(argv, fp)) ) { |
215 |
|
switch (argv[0][0]) { |
216 |
|
case 'v': /* vertex */ |
217 |
|
switch (argv[0][1]) { |
253 |
|
if (!puttri(argv[1], argv[2], argv[3])) |
254 |
|
syntax("Bad triangle"); |
255 |
|
break; |
243 |
– |
case 4: |
244 |
– |
if (!putquad(argv[1], argv[2], |
245 |
– |
argv[3], argv[4])) |
246 |
– |
syntax("Bad quad"); |
247 |
– |
break; |
256 |
|
default: |
257 |
|
if (!putface(argc-1, argv+1)) |
258 |
|
syntax("Bad face"); |
305 |
|
|
306 |
|
|
307 |
|
int |
308 |
< |
getstmt(av, fp) /* read the next statement from fp */ |
309 |
< |
register char *av[MAXARG]; |
310 |
< |
FILE *fp; |
308 |
> |
getstmt( /* read the next statement from fp */ |
309 |
> |
register char *av[MAXARG], |
310 |
> |
FILE *fp |
311 |
> |
) |
312 |
|
{ |
313 |
< |
extern char *fgetline(); |
305 |
< |
static char sbuf[MAXARG*10]; |
313 |
> |
static char sbuf[MAXARG*16]; |
314 |
|
register char *cp; |
315 |
|
register int i; |
316 |
|
|
324 |
|
lineno++; |
325 |
|
*cp++ = '\0'; |
326 |
|
} |
327 |
< |
if (!*cp || i >= MAXARG-1) |
327 |
> |
if (!*cp) |
328 |
|
break; |
329 |
+ |
if (i >= MAXARG-1) { |
330 |
+ |
fprintf(stderr, |
331 |
+ |
"warning: line %d: too many arguments (limit %d)\n", |
332 |
+ |
lineno+1, MAXARG-1); |
333 |
+ |
break; |
334 |
+ |
} |
335 |
|
av[i++] = cp; |
336 |
|
while (*++cp && !isspace(*cp)) |
337 |
|
; |
345 |
|
|
346 |
|
|
347 |
|
char * |
348 |
< |
getmtl() /* figure material for this face */ |
348 |
> |
getmtl(void) /* figure material for this face */ |
349 |
|
{ |
350 |
|
register RULEHD *rp = ourmapping; |
351 |
|
|
371 |
|
|
372 |
|
|
373 |
|
char * |
374 |
< |
getonm() /* invent a good name for object */ |
374 |
> |
getonm(void) /* invent a good name for object */ |
375 |
|
{ |
376 |
|
static char name[64]; |
377 |
|
register char *cp1, *cp2; |
386 |
|
cp2 = group[i]; |
387 |
|
if (cp1 > name) |
388 |
|
*cp1++ = '.'; |
389 |
< |
while (*cp1 = *cp2++) |
389 |
> |
while ( (*cp1 = *cp2++) ) |
390 |
|
if (++cp1 >= name+sizeof(name)-2) { |
391 |
|
*cp1 = '\0'; |
392 |
|
return(name); |
396 |
|
} |
397 |
|
|
398 |
|
|
399 |
< |
matchrule(rp) /* check for a match on this rule */ |
400 |
< |
register RULEHD *rp; |
399 |
> |
int |
400 |
> |
matchrule( /* check for a match on this rule */ |
401 |
> |
register RULEHD *rp |
402 |
> |
) |
403 |
|
{ |
404 |
|
ID tmpid; |
405 |
|
int gotmatch; |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
< |
cvtndx(vi, vs) /* convert vertex string to index */ |
453 |
< |
register VNDX vi; |
454 |
< |
register char *vs; |
452 |
> |
int |
453 |
> |
cvtndx( /* convert vertex string to index */ |
454 |
> |
register VNDX vi, |
455 |
> |
register char *vs |
456 |
> |
) |
457 |
|
{ |
458 |
|
/* get point */ |
459 |
|
vi[0] = atoi(vs); |
498 |
|
} |
499 |
|
|
500 |
|
|
501 |
< |
nonplanar(ac, av) /* are vertices non-planar? */ |
502 |
< |
register int ac; |
503 |
< |
register char **av; |
501 |
> |
int |
502 |
> |
nonplanar( /* are vertices non-planar? */ |
503 |
> |
register int ac, |
504 |
> |
register char **av |
505 |
> |
) |
506 |
|
{ |
507 |
|
VNDX vi; |
508 |
< |
FLOAT *p0, *p1; |
508 |
> |
RREAL *p0, *p1; |
509 |
|
FVECT v1, v2, nsum, newn; |
510 |
|
double d; |
511 |
|
register int i; |
512 |
|
|
513 |
|
if (!cvtndx(vi, av[0])) |
514 |
|
return(0); |
515 |
< |
if (vi[2] >= 0) |
515 |
> |
if (!flatten && vi[2] >= 0) |
516 |
|
return(1); /* has interpolated normals */ |
517 |
|
if (ac < 4) |
518 |
|
return(0); /* it's a triangle! */ |
551 |
|
} |
552 |
|
|
553 |
|
|
554 |
< |
putface(ac, av) /* put out an N-sided polygon */ |
555 |
< |
int ac; |
556 |
< |
register char **av; |
554 |
> |
int |
555 |
> |
putface( /* put out an N-sided polygon */ |
556 |
> |
int ac, |
557 |
> |
register char **av |
558 |
> |
) |
559 |
|
{ |
560 |
|
VNDX vi; |
561 |
|
char *cp; |
562 |
|
register int i; |
563 |
|
|
564 |
< |
if (nonplanar(ac, av)) { /* break into quads and triangles */ |
565 |
< |
while (ac > 3) { |
566 |
< |
if (!putquad(av[0], av[1], av[2], av[3])) |
564 |
> |
if (nonplanar(ac, av)) { /* break into triangles */ |
565 |
> |
while (ac > 2) { |
566 |
> |
if (!puttri(av[0], av[1], av[2])) |
567 |
|
return(0); |
568 |
< |
ac -= 2; /* remove two vertices & rotate */ |
568 |
> |
ac--; /* remove vertex & rotate */ |
569 |
|
cp = av[0]; |
570 |
|
for (i = 0; i < ac-1; i++) |
571 |
< |
av[i] = av[i+3]; |
571 |
> |
av[i] = av[i+2]; |
572 |
|
av[i] = cp; |
573 |
|
} |
552 |
– |
if (ac == 3 && !puttri(av[0], av[1], av[2])) |
553 |
– |
return(0); |
574 |
|
return(1); |
575 |
|
} |
576 |
|
if ((cp = getmtl()) == NULL) |
586 |
|
} |
587 |
|
|
588 |
|
|
589 |
< |
puttri(v1, v2, v3) /* put out a triangle */ |
590 |
< |
char *v1, *v2, *v3; |
589 |
> |
int |
590 |
> |
puttri( /* put out a triangle */ |
591 |
> |
char *v1, |
592 |
> |
char *v2, |
593 |
> |
char *v3 |
594 |
> |
) |
595 |
|
{ |
596 |
|
char *mod; |
597 |
|
VNDX v1i, v2i, v3i; |
598 |
|
BARYCCM bvecs; |
599 |
< |
int texOK, patOK; |
599 |
> |
RREAL bcoor[3][3]; |
600 |
> |
int texOK = 0, patOK; |
601 |
> |
int flatness; |
602 |
> |
register int i; |
603 |
|
|
604 |
|
if ((mod = getmtl()) == NULL) |
605 |
|
return(-1); |
607 |
|
if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3)) |
608 |
|
return(0); |
609 |
|
/* compute barycentric coordinates */ |
610 |
< |
texOK = !flatten && (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0); |
610 |
> |
if (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0) |
611 |
> |
flatness = flat_tri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]], |
612 |
> |
vnlist[v1i[2]], vnlist[v2i[2]], vnlist[v3i[2]]); |
613 |
> |
else |
614 |
> |
flatness = ISFLAT; |
615 |
> |
|
616 |
> |
switch (flatness) { |
617 |
> |
case DEGEN: /* zero area */ |
618 |
> |
return(-1); |
619 |
> |
case RVFLAT: /* reversed normals, but flat */ |
620 |
> |
case ISFLAT: /* smoothing unnecessary */ |
621 |
> |
texOK = 0; |
622 |
> |
break; |
623 |
> |
case RVBENT: /* reversed normals with smoothing */ |
624 |
> |
case ISBENT: /* proper smoothing */ |
625 |
> |
texOK = 1; |
626 |
> |
break; |
627 |
> |
} |
628 |
> |
if (flatten) |
629 |
> |
texOK = 0; |
630 |
|
#ifdef TEXMAPS |
631 |
|
patOK = mapname[0] && (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0); |
632 |
|
#else |
641 |
|
printf("\n%s texfunc %s\n", mod, TEXNAME); |
642 |
|
mod = TEXNAME; |
643 |
|
printf("4 dx dy dz %s\n", TCALNAME); |
644 |
< |
printf("0\n16 "); |
645 |
< |
put_baryc(&bvecs); |
646 |
< |
printf("\t%14.12g %14.12g %14.12g\n", |
647 |
< |
vnlist[v1i[2]][0], vnlist[v2i[2]][0], |
648 |
< |
vnlist[v3i[2]][0]); |
649 |
< |
printf("\t%14.12g %14.12g %14.12g\n", |
650 |
< |
vnlist[v1i[2]][1], vnlist[v2i[2]][1], |
605 |
< |
vnlist[v3i[2]][1]); |
606 |
< |
printf("\t%14.12g %14.12g %14.12g\n", |
607 |
< |
vnlist[v1i[2]][2], vnlist[v2i[2]][2], |
608 |
< |
vnlist[v3i[2]][2]); |
644 |
> |
printf("0\n"); |
645 |
> |
for (i = 0; i < 3; i++) { |
646 |
> |
bcoor[i][0] = vnlist[v1i[2]][i]; |
647 |
> |
bcoor[i][1] = vnlist[v2i[2]][i]; |
648 |
> |
bcoor[i][2] = vnlist[v3i[2]][i]; |
649 |
> |
} |
650 |
> |
put_baryc(&bvecs, bcoor, 3); |
651 |
|
} |
652 |
|
#ifdef TEXMAPS |
653 |
|
/* put out pattern (if any) */ |
655 |
|
printf("\n%s colorpict %s\n", mod, PATNAME); |
656 |
|
mod = PATNAME; |
657 |
|
printf("7 noneg noneg noneg %s %s u v\n", mapname, TCALNAME); |
658 |
< |
printf("0\n13 "); |
659 |
< |
put_baryc(&bvecs); |
660 |
< |
printf("\t%f %f %f\n", vtlist[v1i[1]][0], |
661 |
< |
vtlist[v2i[1]][0], vtlist[v3i[1]][0]); |
662 |
< |
printf("\t%f %f %f\n", vtlist[v1i[1]][1], |
663 |
< |
vtlist[v2i[1]][1], vtlist[v3i[1]][1]); |
658 |
> |
printf("0\n"); |
659 |
> |
for (i = 0; i < 2; i++) { |
660 |
> |
bcoor[i][0] = vtlist[v1i[1]][i]; |
661 |
> |
bcoor[i][1] = vtlist[v2i[1]][i]; |
662 |
> |
bcoor[i][2] = vtlist[v3i[1]][i]; |
663 |
> |
} |
664 |
> |
put_baryc(&bvecs, bcoor, 2); |
665 |
|
} |
666 |
|
#endif |
667 |
< |
/* put out triangle */ |
667 |
> |
/* put out (reversed) triangle */ |
668 |
|
printf("\n%s polygon %s.%d\n", mod, getonm(), faceno); |
669 |
|
printf("0\n0\n9\n"); |
670 |
< |
pvect(vlist[v1i[0]]); |
671 |
< |
pvect(vlist[v2i[0]]); |
672 |
< |
pvect(vlist[v3i[0]]); |
673 |
< |
|
674 |
< |
return(1); |
675 |
< |
} |
676 |
< |
|
677 |
< |
|
635 |
< |
int |
636 |
< |
comp_baryc(bcm, v1, v2, v3) /* compute barycentric vectors */ |
637 |
< |
register BARYCCM *bcm; |
638 |
< |
FLOAT *v1, *v2, *v3; |
639 |
< |
{ |
640 |
< |
FLOAT *vt; |
641 |
< |
FVECT va, vab, vcb; |
642 |
< |
double d; |
643 |
< |
int ax0, ax1; |
644 |
< |
register int i, j; |
645 |
< |
/* compute major axis */ |
646 |
< |
for (i = 0; i < 3; i++) { |
647 |
< |
vab[i] = v1[i] - v2[i]; |
648 |
< |
vcb[i] = v3[i] - v2[i]; |
670 |
> |
if (flatness == RVFLAT || flatness == RVBENT) { |
671 |
> |
pvect(vlist[v3i[0]]); |
672 |
> |
pvect(vlist[v2i[0]]); |
673 |
> |
pvect(vlist[v1i[0]]); |
674 |
> |
} else { |
675 |
> |
pvect(vlist[v1i[0]]); |
676 |
> |
pvect(vlist[v2i[0]]); |
677 |
> |
pvect(vlist[v3i[0]]); |
678 |
|
} |
650 |
– |
fcross(va, vab, vcb); |
651 |
– |
bcm->ax = ABS(va[0]) > ABS(va[1]) ? 0 : 1; |
652 |
– |
bcm->ax = ABS(va[bcm->ax]) > ABS(va[2]) ? bcm->ax : 2; |
653 |
– |
ax0 = (bcm->ax + 1) % 3; |
654 |
– |
ax1 = (bcm->ax + 2) % 3; |
655 |
– |
for (j = 0; j < 2; j++) { |
656 |
– |
vab[0] = v1[ax0] - v2[ax0]; |
657 |
– |
vcb[0] = v3[ax0] - v2[ax0]; |
658 |
– |
vab[1] = v1[ax1] - v2[ax1]; |
659 |
– |
vcb[1] = v3[ax1] - v2[ax1]; |
660 |
– |
d = vcb[0]*vcb[0] + vcb[1]*vcb[1]; |
661 |
– |
if (d <= FTINY) |
662 |
– |
return(-1); |
663 |
– |
d = (vcb[0]*vab[0]+vcb[1]*vab[1])/d; |
664 |
– |
va[0] = vab[0] - vcb[0]*d; |
665 |
– |
va[1] = vab[1] - vcb[1]*d; |
666 |
– |
d = va[0]*va[0] + va[1]*va[1]; |
667 |
– |
if (d <= FTINY) |
668 |
– |
return(-1); |
669 |
– |
bcm->tm[j][0] = va[0] /= d; |
670 |
– |
bcm->tm[j][1] = va[1] /= d; |
671 |
– |
bcm->tm[j][2] = -(v2[ax0]*va[0]+v2[ax1]*va[1]); |
672 |
– |
/* rotate vertices */ |
673 |
– |
vt = v1; |
674 |
– |
v1 = v2; |
675 |
– |
v2 = v3; |
676 |
– |
v3 = vt; |
677 |
– |
} |
678 |
– |
return(0); |
679 |
– |
} |
680 |
– |
|
681 |
– |
|
682 |
– |
put_baryc(bcm) /* put barycentric coord. vectors */ |
683 |
– |
register BARYCCM *bcm; |
684 |
– |
{ |
685 |
– |
printf("\t%d\n", bcm->ax); |
686 |
– |
printf("%14.8f %14.8f %14.8f\n", |
687 |
– |
bcm->tm[0][0], bcm->tm[0][1], bcm->tm[0][2]); |
688 |
– |
printf("%14.8f %14.8f %14.8f\n", |
689 |
– |
bcm->tm[1][0], bcm->tm[1][1], bcm->tm[1][2]); |
690 |
– |
} |
691 |
– |
|
692 |
– |
|
693 |
– |
putquad(p0, p1, p3, p2) /* put out a quadrilateral */ |
694 |
– |
char *p0, *p1, *p3, *p2; /* names correspond to binary pos. */ |
695 |
– |
{ |
696 |
– |
VNDX p0i, p1i, p2i, p3i; |
697 |
– |
FVECT norm[4]; |
698 |
– |
char *mod, *name; |
699 |
– |
int axis; |
700 |
– |
FVECT v1, v2, vc1, vc2; |
701 |
– |
int ok1, ok2; |
702 |
– |
|
703 |
– |
#ifdef TEXMAPS |
704 |
– |
/* also should output texture index coordinates, |
705 |
– |
* which will require new .cal file |
706 |
– |
*/ |
707 |
– |
#endif |
708 |
– |
if ((mod = getmtl()) == NULL) |
709 |
– |
return(-1); |
710 |
– |
name = getonm(); |
711 |
– |
/* get actual indices */ |
712 |
– |
if (!cvtndx(p0i,p0) || !cvtndx(p1i,p1) || |
713 |
– |
!cvtndx(p2i,p2) || !cvtndx(p3i,p3)) |
714 |
– |
return(0); |
715 |
– |
/* compute exact normals */ |
716 |
– |
fvsum(v1, vlist[p1i[0]], vlist[p0i[0]], -1.0); |
717 |
– |
fvsum(v2, vlist[p2i[0]], vlist[p0i[0]], -1.0); |
718 |
– |
fcross(vc1, v1, v2); |
719 |
– |
ok1 = normalize(vc1) != 0.0; |
720 |
– |
fvsum(v1, vlist[p2i[0]], vlist[p3i[0]], -1.0); |
721 |
– |
fvsum(v2, vlist[p1i[0]], vlist[p3i[0]], -1.0); |
722 |
– |
fcross(vc2, v1, v2); |
723 |
– |
ok2 = normalize(vc2) != 0.0; |
724 |
– |
if (!(ok1 | ok2)) |
725 |
– |
return(-1); |
726 |
– |
/* compute normal interpolation */ |
727 |
– |
axis = norminterp(norm, p0i, p1i, p2i, p3i); |
728 |
– |
|
729 |
– |
/* put out quadrilateral? */ |
730 |
– |
if (ok1 & ok2 && fabs(fdot(vc1,vc2)) >= 1.0-FTINY) { |
731 |
– |
printf("\n%s ", mod); |
732 |
– |
if (axis != -1) { |
733 |
– |
printf("texfunc %s\n", TEXNAME); |
734 |
– |
printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME); |
735 |
– |
printf("0\n13\t%d\n", axis); |
736 |
– |
pvect(norm[0]); |
737 |
– |
pvect(norm[1]); |
738 |
– |
pvect(norm[2]); |
739 |
– |
fvsum(v1, norm[3], vc1, -0.5); |
740 |
– |
fvsum(v1, v1, vc2, -0.5); |
741 |
– |
pvect(v1); |
742 |
– |
printf("\n%s ", TEXNAME); |
743 |
– |
} |
744 |
– |
printf("polygon %s.%d\n", name, faceno); |
745 |
– |
printf("0\n0\n12\n"); |
746 |
– |
pvect(vlist[p0i[0]]); |
747 |
– |
pvect(vlist[p1i[0]]); |
748 |
– |
pvect(vlist[p3i[0]]); |
749 |
– |
pvect(vlist[p2i[0]]); |
750 |
– |
return(1); |
751 |
– |
} |
752 |
– |
/* put out triangles? */ |
753 |
– |
if (ok1) { |
754 |
– |
printf("\n%s ", mod); |
755 |
– |
if (axis != -1) { |
756 |
– |
printf("texfunc %s\n", TEXNAME); |
757 |
– |
printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME); |
758 |
– |
printf("0\n13\t%d\n", axis); |
759 |
– |
pvect(norm[0]); |
760 |
– |
pvect(norm[1]); |
761 |
– |
pvect(norm[2]); |
762 |
– |
fvsum(v1, norm[3], vc1, -1.0); |
763 |
– |
pvect(v1); |
764 |
– |
printf("\n%s ", TEXNAME); |
765 |
– |
} |
766 |
– |
printf("polygon %s.%da\n", name, faceno); |
767 |
– |
printf("0\n0\n9\n"); |
768 |
– |
pvect(vlist[p0i[0]]); |
769 |
– |
pvect(vlist[p1i[0]]); |
770 |
– |
pvect(vlist[p2i[0]]); |
771 |
– |
} |
772 |
– |
if (ok2) { |
773 |
– |
printf("\n%s ", mod); |
774 |
– |
if (axis != -1) { |
775 |
– |
printf("texfunc %s\n", TEXNAME); |
776 |
– |
printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME); |
777 |
– |
printf("0\n13\t%d\n", axis); |
778 |
– |
pvect(norm[0]); |
779 |
– |
pvect(norm[1]); |
780 |
– |
pvect(norm[2]); |
781 |
– |
fvsum(v2, norm[3], vc2, -1.0); |
782 |
– |
pvect(v2); |
783 |
– |
printf("\n%s ", TEXNAME); |
784 |
– |
} |
785 |
– |
printf("polygon %s.%db\n", name, faceno); |
786 |
– |
printf("0\n0\n9\n"); |
787 |
– |
pvect(vlist[p2i[0]]); |
788 |
– |
pvect(vlist[p1i[0]]); |
789 |
– |
pvect(vlist[p3i[0]]); |
790 |
– |
} |
679 |
|
return(1); |
680 |
|
} |
681 |
|
|
682 |
|
|
683 |
< |
int |
684 |
< |
norminterp(resmat, p0i, p1i, p2i, p3i) /* compute normal interpolation */ |
797 |
< |
register FVECT resmat[4]; |
798 |
< |
register VNDX p0i, p1i, p2i, p3i; |
683 |
> |
void |
684 |
> |
freeverts(void) /* free all vertices */ |
685 |
|
{ |
800 |
– |
#define u ((ax+1)%3) |
801 |
– |
#define v ((ax+2)%3) |
802 |
– |
|
803 |
– |
register int ax; |
804 |
– |
MAT4 eqnmat; |
805 |
– |
FVECT v1; |
806 |
– |
register int i, j; |
807 |
– |
|
808 |
– |
#ifdef TEXMAPS |
809 |
– |
/* also check for texture indices */ |
810 |
– |
#endif |
811 |
– |
if (flatten || !(p0i[2]>=0 && p1i[2]>=0 && p2i[2]>=0 && p3i[2]>=0)) |
812 |
– |
return(-1); |
813 |
– |
/* find dominant axis */ |
814 |
– |
VCOPY(v1, vnlist[p0i[2]]); |
815 |
– |
fvsum(v1, v1, vnlist[p1i[2]], 1.0); |
816 |
– |
fvsum(v1, v1, vnlist[p2i[2]], 1.0); |
817 |
– |
fvsum(v1, v1, vnlist[p3i[2]], 1.0); |
818 |
– |
ax = ABS(v1[0]) > ABS(v1[1]) ? 0 : 1; |
819 |
– |
ax = ABS(v1[ax]) > ABS(v1[2]) ? ax : 2; |
820 |
– |
/* assign equation matrix */ |
821 |
– |
eqnmat[0][0] = vlist[p0i[0]][u]*vlist[p0i[0]][v]; |
822 |
– |
eqnmat[0][1] = vlist[p0i[0]][u]; |
823 |
– |
eqnmat[0][2] = vlist[p0i[0]][v]; |
824 |
– |
eqnmat[0][3] = 1.0; |
825 |
– |
eqnmat[1][0] = vlist[p1i[0]][u]*vlist[p1i[0]][v]; |
826 |
– |
eqnmat[1][1] = vlist[p1i[0]][u]; |
827 |
– |
eqnmat[1][2] = vlist[p1i[0]][v]; |
828 |
– |
eqnmat[1][3] = 1.0; |
829 |
– |
eqnmat[2][0] = vlist[p2i[0]][u]*vlist[p2i[0]][v]; |
830 |
– |
eqnmat[2][1] = vlist[p2i[0]][u]; |
831 |
– |
eqnmat[2][2] = vlist[p2i[0]][v]; |
832 |
– |
eqnmat[2][3] = 1.0; |
833 |
– |
eqnmat[3][0] = vlist[p3i[0]][u]*vlist[p3i[0]][v]; |
834 |
– |
eqnmat[3][1] = vlist[p3i[0]][u]; |
835 |
– |
eqnmat[3][2] = vlist[p3i[0]][v]; |
836 |
– |
eqnmat[3][3] = 1.0; |
837 |
– |
/* invert matrix (solve system) */ |
838 |
– |
if (!invmat4(eqnmat, eqnmat)) |
839 |
– |
return(-1); /* no solution */ |
840 |
– |
/* compute result matrix */ |
841 |
– |
for (j = 0; j < 4; j++) |
842 |
– |
for (i = 0; i < 3; i++) |
843 |
– |
resmat[j][i] = eqnmat[j][0]*vnlist[p0i[2]][i] + |
844 |
– |
eqnmat[j][1]*vnlist[p1i[2]][i] + |
845 |
– |
eqnmat[j][2]*vnlist[p2i[2]][i] + |
846 |
– |
eqnmat[j][3]*vnlist[p3i[2]][i]; |
847 |
– |
#ifdef TEXMAPS |
848 |
– |
/* compute result matrix for texture indices */ |
849 |
– |
#endif |
850 |
– |
return(ax); |
851 |
– |
|
852 |
– |
#undef u |
853 |
– |
#undef v |
854 |
– |
} |
855 |
– |
|
856 |
– |
|
857 |
– |
freeverts() /* free all vertices */ |
858 |
– |
{ |
686 |
|
if (nvs) { |
687 |
< |
free((char *)vlist); |
687 |
> |
free((void *)vlist); |
688 |
|
nvs = 0; |
689 |
|
} |
690 |
|
if (nvts) { |
691 |
< |
free((char *)vtlist); |
691 |
> |
free((void *)vtlist); |
692 |
|
nvts = 0; |
693 |
|
} |
694 |
|
if (nvns) { |
695 |
< |
free((char *)vnlist); |
695 |
> |
free((void *)vnlist); |
696 |
|
nvns = 0; |
697 |
|
} |
698 |
|
} |
699 |
|
|
700 |
|
|
701 |
|
int |
702 |
< |
newv(x, y, z) /* create a new vertex */ |
703 |
< |
double x, y, z; |
702 |
> |
newv( /* create a new vertex */ |
703 |
> |
double x, |
704 |
> |
double y, |
705 |
> |
double z |
706 |
> |
) |
707 |
|
{ |
708 |
|
if (!(nvs%CHUNKSIZ)) { /* allocate next block */ |
709 |
|
if (nvs == 0) |
710 |
|
vlist = (FVECT *)malloc(CHUNKSIZ*sizeof(FVECT)); |
711 |
|
else |
712 |
< |
vlist = (FVECT *)realloc((char *)vlist, |
712 |
> |
vlist = (FVECT *)realloc((void *)vlist, |
713 |
|
(nvs+CHUNKSIZ)*sizeof(FVECT)); |
714 |
|
if (vlist == NULL) { |
715 |
|
fprintf(stderr, |
726 |
|
|
727 |
|
|
728 |
|
int |
729 |
< |
newvn(x, y, z) /* create a new vertex normal */ |
730 |
< |
double x, y, z; |
729 |
> |
newvn( /* create a new vertex normal */ |
730 |
> |
double x, |
731 |
> |
double y, |
732 |
> |
double z |
733 |
> |
) |
734 |
|
{ |
735 |
|
if (!(nvns%CHUNKSIZ)) { /* allocate next block */ |
736 |
|
if (nvns == 0) |
737 |
|
vnlist = (FVECT *)malloc(CHUNKSIZ*sizeof(FVECT)); |
738 |
|
else |
739 |
< |
vnlist = (FVECT *)realloc((char *)vnlist, |
739 |
> |
vnlist = (FVECT *)realloc((void *)vnlist, |
740 |
|
(nvns+CHUNKSIZ)*sizeof(FVECT)); |
741 |
|
if (vnlist == NULL) { |
742 |
|
fprintf(stderr, |
755 |
|
|
756 |
|
|
757 |
|
int |
758 |
< |
newvt(x, y) /* create a new texture map vertex */ |
759 |
< |
double x, y; |
758 |
> |
newvt( /* create a new texture map vertex */ |
759 |
> |
double x, |
760 |
> |
double y |
761 |
> |
) |
762 |
|
{ |
763 |
|
if (!(nvts%CHUNKSIZ)) { /* allocate next block */ |
764 |
|
if (nvts == 0) |
765 |
< |
vtlist = (FLOAT (*)[2])malloc(CHUNKSIZ*2*sizeof(FLOAT)); |
765 |
> |
vtlist = (RREAL (*)[2])malloc(CHUNKSIZ*2*sizeof(RREAL)); |
766 |
|
else |
767 |
< |
vtlist = (FLOAT (*)[2])realloc((char *)vtlist, |
768 |
< |
(nvts+CHUNKSIZ)*2*sizeof(FLOAT)); |
767 |
> |
vtlist = (RREAL (*)[2])realloc((void *)vtlist, |
768 |
> |
(nvts+CHUNKSIZ)*2*sizeof(RREAL)); |
769 |
|
if (vtlist == NULL) { |
770 |
|
fprintf(stderr, |
771 |
|
"Out of memory while allocating texture vertex %d\n", |
780 |
|
} |
781 |
|
|
782 |
|
|
783 |
< |
syntax(er) /* report syntax error and exit */ |
784 |
< |
char *er; |
783 |
> |
void |
784 |
> |
syntax( /* report syntax error and exit */ |
785 |
> |
char *er |
786 |
> |
) |
787 |
|
{ |
788 |
|
fprintf(stderr, "%s: Wavefront syntax error near line %d: %s\n", |
789 |
|
inpfile, lineno, er); |