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" |
16 |
– |
|
21 |
|
#include "tmesh.h" |
22 |
|
|
19 |
– |
#include <ctype.h> |
23 |
|
|
24 |
|
#define PATNAME "M-pat" /* mesh pattern name (reused) */ |
25 |
|
#define TEXNAME "M-nor" /* mesh texture name (reused) */ |
37 |
|
|
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 |
|
|
68 |
– |
char *getmtl(), *getonm(); |
69 |
– |
|
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]) { |
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(); |
290 |
< |
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 |
|
RREAL *p0, *p1; |
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; |
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 |
|
RREAL bcoor[3][3]; |
600 |
< |
int texOK, patOK; |
600 |
> |
int texOK = 0, patOK; |
601 |
|
int flatness; |
602 |
|
register int i; |
603 |
|
|
680 |
|
} |
681 |
|
|
682 |
|
|
683 |
< |
freeverts() /* free all vertices */ |
683 |
> |
void |
684 |
> |
freeverts(void) /* free all vertices */ |
685 |
|
{ |
686 |
|
if (nvs) { |
687 |
|
free((void *)vlist); |
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) |
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) |
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) |
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); |