| 11 |  | #include "cvmesh.h" | 
| 12 |  | #include <ctype.h> | 
| 13 |  |  | 
| 14 | – | FVECT   *vlist;                 /* our vertex list */ | 
| 15 | – | int     nvs;                    /* number of vertices in our list */ | 
| 16 | – | FVECT   *vnlist;                /* vertex normal list */ | 
| 17 | – | int     nvns; | 
| 18 | – | FLOAT   (*vtlist)[2];           /* map vertex list */ | 
| 19 | – | int     nvts; | 
| 20 | – |  | 
| 14 |  | typedef int     VNDX[3];        /* vertex index (point,map,normal) */ | 
| 15 |  |  | 
| 16 |  | #define CHUNKSIZ        1024    /* vertex allocation chunk size */ | 
| 17 |  |  | 
| 18 |  | #define MAXARG          64      /* maximum # arguments in a statement */ | 
| 19 |  |  | 
| 20 | < | char    *inpfile;               /* input file name */ | 
| 21 | < | int     lineno;                 /* current line number */ | 
| 22 | < | int     faceno;                 /* current face number */ | 
| 20 | > | static FVECT    *vlist;         /* our vertex list */ | 
| 21 | > | static int      nvs;            /* number of vertices in our list */ | 
| 22 | > | static FVECT    *vnlist;        /* vertex normal list */ | 
| 23 | > | static int      nvns; | 
| 24 | > | static FLOAT    (*vtlist)[2];   /* map vertex list */ | 
| 25 | > | static int      nvts; | 
| 26 |  |  | 
| 27 | + | static char     *inpfile;       /* input file name */ | 
| 28 | + | static int      havemats;       /* materials available? */ | 
| 29 | + | static char     material[64];   /* current material name */ | 
| 30 | + | static char     group[64];      /* current group name */ | 
| 31 | + | static int      lineno;         /* current line number */ | 
| 32 | + | static int      faceno;         /* current face number */ | 
| 33 |  |  | 
| 34 | + | static int      getstmt(); | 
| 35 | + | static int      cvtndx(); | 
| 36 | + | static OBJECT   getmod(); | 
| 37 | + | static int      putface(); | 
| 38 | + | static int      puttri(); | 
| 39 | + | static void     freeverts(); | 
| 40 | + | static int      newv(); | 
| 41 | + | static int      newvn(); | 
| 42 | + | static int      newvt(); | 
| 43 | + | static void     syntax(); | 
| 44 | + |  | 
| 45 | + |  | 
| 46 | + | void | 
| 47 |  | wfreadobj(objfn)                /* read in .OBJ file and convert */ | 
| 48 |  | char    *objfn; | 
| 49 |  | { | 
| 60 |  | sprintf(errmsg, "cannot open \"%s\"", inpfile); | 
| 61 |  | error(USER, errmsg); | 
| 62 |  | } | 
| 63 | + | havemats = (nobjects > 0); | 
| 64 |  | nstats = nunknown = 0; | 
| 65 | + | material[0] = '\0'; | 
| 66 | + | group[0] = '\0'; | 
| 67 |  | lineno = 0; faceno = 0; | 
| 68 |  | /* scan until EOF */ | 
| 69 |  | while (argc = getstmt(argv, fp)) { | 
| 114 |  | break; | 
| 115 |  | } | 
| 116 |  | break; | 
| 117 | < | case 'u': | 
| 118 | < | if (strcmp(argv[0], "usemtl") && | 
| 119 | < | strcmp(argv[0], "usemap")) | 
| 117 | > | case 'u':                               /* usemtl/usemap */ | 
| 118 | > | if (!strcmp(argv[0], "usemap")) | 
| 119 | > | break; | 
| 120 | > | if (strcmp(argv[0], "usemtl")) | 
| 121 |  | goto unknown; | 
| 122 | + | if (argc > 1) | 
| 123 | + | strcpy(material, argv[1]); | 
| 124 | + | else | 
| 125 | + | material[0] = '\0'; | 
| 126 |  | break; | 
| 127 |  | case 'o':               /* object name */ | 
| 128 |  | if (argv[0][1]) | 
| 129 |  | goto unknown; | 
| 130 |  | break; | 
| 131 | < | case 'g':               /* group name(s) */ | 
| 131 | > | case 'g':               /* group name */ | 
| 132 |  | if (argv[0][1]) | 
| 133 |  | goto unknown; | 
| 134 | + | if (argc > 1) | 
| 135 | + | strcpy(group, argv[1]); | 
| 136 | + | else | 
| 137 | + | group[0] = '\0'; | 
| 138 |  | break; | 
| 139 |  | case '#':               /* comment */ | 
| 140 |  | break; | 
| 156 |  | } | 
| 157 |  |  | 
| 158 |  |  | 
| 159 | < | int | 
| 159 | > | static int | 
| 160 |  | getstmt(av, fp)                         /* read the next statement from fp */ | 
| 161 |  | register char   *av[MAXARG]; | 
| 162 |  | FILE    *fp; | 
| 163 |  | { | 
| 164 | < | static char     sbuf[MAXARG*10]; | 
| 164 | > | static char     sbuf[MAXARG*16]; | 
| 165 |  | register char   *cp; | 
| 166 |  | register int    i; | 
| 167 |  |  | 
| 189 |  | } | 
| 190 |  |  | 
| 191 |  |  | 
| 192 | + | static int | 
| 193 |  | cvtndx(vi, vs)                          /* convert vertex string to index */ | 
| 194 |  | register VNDX   vi; | 
| 195 |  | register char   *vs; | 
| 237 |  | } | 
| 238 |  |  | 
| 239 |  |  | 
| 240 | + | static int | 
| 241 |  | putface(ac, av)                         /* put out an N-sided polygon */ | 
| 242 |  | int     ac; | 
| 243 |  | register char   **av; | 
| 258 |  | } | 
| 259 |  |  | 
| 260 |  |  | 
| 261 | + | static OBJECT | 
| 262 | + | getmod()                                /* get current modifier ID */ | 
| 263 | + | { | 
| 264 | + | char    *mnam; | 
| 265 | + | OBJECT  mod; | 
| 266 | + |  | 
| 267 | + | if (!havemats) | 
| 268 | + | return(OVOID); | 
| 269 | + | if (!strcmp(material, VOIDID)) | 
| 270 | + | return(OVOID); | 
| 271 | + | if (material[0])                /* prefer usemtl statements */ | 
| 272 | + | mnam = material; | 
| 273 | + | else if (group[0])              /* else use group name */ | 
| 274 | + | mnam = group; | 
| 275 | + | else | 
| 276 | + | return(OVOID); | 
| 277 | + | mod = modifier(mnam); | 
| 278 | + | if (mod == OVOID) { | 
| 279 | + | sprintf(errmsg, "%s: undefined modifier \"%s\"", | 
| 280 | + | inpfile, mnam); | 
| 281 | + | error(USER, errmsg); | 
| 282 | + | } | 
| 283 | + | return(mod); | 
| 284 | + | } | 
| 285 | + |  | 
| 286 | + |  | 
| 287 | + | static int | 
| 288 |  | puttri(v1, v2, v3)                      /* convert a triangle */ | 
| 289 |  | char    *v1, *v2, *v3; | 
| 290 |  | { | 
| 309 |  | } else | 
| 310 |  | v1n = v2n = v3n = NULL; | 
| 311 |  |  | 
| 312 | < | return(cvtri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]], | 
| 312 | > | return(cvtri(getmod(), vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]], | 
| 313 |  | v1n, v2n, v3n, v1c, v2c, v3c) >= 0); | 
| 314 |  | } | 
| 315 |  |  | 
| 316 |  |  | 
| 317 | + | static void | 
| 318 |  | freeverts()                     /* free all vertices */ | 
| 319 |  | { | 
| 320 |  | if (nvs) { | 
| 332 |  | } | 
| 333 |  |  | 
| 334 |  |  | 
| 335 | < | int | 
| 335 | > | static int | 
| 336 |  | newv(x, y, z)                   /* create a new vertex */ | 
| 337 |  | double  x, y, z; | 
| 338 |  | { | 
| 353 |  | } | 
| 354 |  |  | 
| 355 |  |  | 
| 356 | < | int | 
| 356 | > | static int | 
| 357 |  | newvn(x, y, z)                  /* create a new vertex normal */ | 
| 358 |  | double  x, y, z; | 
| 359 |  | { | 
| 376 |  | } | 
| 377 |  |  | 
| 378 |  |  | 
| 379 | < | int | 
| 379 | > | static int | 
| 380 |  | newvt(x, y)                     /* create a new texture map vertex */ | 
| 381 |  | double  x, y; | 
| 382 |  | { | 
| 396 |  | } | 
| 397 |  |  | 
| 398 |  |  | 
| 399 | + | static void | 
| 400 |  | syntax(er)                      /* report syntax error and exit */ | 
| 401 |  | char    *er; | 
| 402 |  | { |