16 |
|
#include <ctype.h> |
17 |
|
#include "objutil.h" |
18 |
|
|
19 |
– |
typedef int VNDX[3]; /* vertex index (point,map,normal) */ |
20 |
– |
|
19 |
|
#define MAXARG 512 /* maximum # arguments in a statement */ |
20 |
|
|
21 |
|
static int lineno; /* current line number */ |
141 |
|
return(nambuf); |
142 |
|
} |
143 |
|
|
144 |
< |
/* Add a new face to scene */ |
144 |
> |
/* add a new face to scene */ |
145 |
|
static int |
146 |
|
add_face(Scene *sc, const VNDX ondx, int ac, char *av[]) |
147 |
|
{ |
148 |
< |
Face *f; |
148 |
> |
VNDX vdef[4]; |
149 |
> |
VNDX *varr = vdef; |
150 |
> |
Face *f = NULL; |
151 |
|
int i; |
152 |
|
|
153 |
< |
if (ac < 3) |
153 |
> |
if (ac < 3) /* legal polygon? */ |
154 |
|
return(0); |
155 |
< |
f = (Face *)emalloc(sizeof(Face)+sizeof(VertEnt)*(ac-3)); |
156 |
< |
f->flags = 0; |
157 |
< |
f->nv = ac; |
158 |
< |
f->grp = sc->lastgrp; |
159 |
< |
f->mat = sc->lastmat; |
160 |
< |
for (i = 0; i < ac; i++) { /* add each vertex */ |
161 |
< |
VNDX vin; |
162 |
< |
int j; |
163 |
< |
if (!cvtndx(vin, sc, ondx, av[i])) { |
164 |
< |
efree((char *)f); |
165 |
< |
return(0); |
166 |
< |
} |
167 |
< |
f->v[i].vid = vin[0]; |
168 |
< |
f->v[i].tid = vin[1]; |
169 |
< |
f->v[i].nid = vin[2]; |
170 |
< |
f->v[i].fnext = NULL; |
171 |
< |
for (j = i; j-- > 0; ) |
172 |
< |
if (f->v[j].vid == vin[0]) |
173 |
< |
break; |
174 |
< |
if (j < 0) { /* first occurrence? */ |
175 |
< |
f->v[i].fnext = sc->vert[vin[0]].vflist; |
176 |
< |
sc->vert[vin[0]].vflist = f; |
177 |
< |
} else if (ac == 3) /* degenerate triangle? */ |
178 |
< |
f->flags |= FACE_DEGENERATE; |
179 |
< |
} |
180 |
< |
f->next = sc->flist; /* push onto face list */ |
181 |
< |
sc->flist = f; |
182 |
< |
sc->nfaces++; |
183 |
< |
/* check face area */ |
184 |
< |
if (!(f->flags & FACE_DEGENERATE) && faceArea(sc, f, NULL) <= FTINY) |
185 |
< |
f->flags |= FACE_DEGENERATE; |
186 |
< |
return(1); |
155 |
> |
if (ac > 4) /* need to allocate array? */ |
156 |
> |
varr = (VNDX *)emalloc(ac*sizeof(VNDX)); |
157 |
> |
for (i = ac; i--; ) /* index each vertex */ |
158 |
> |
if (!cvtndx(varr[i], sc, ondx, av[i])) |
159 |
> |
break; |
160 |
> |
if (i < 0) /* create face if indices OK */ |
161 |
> |
f = addFace(sc, varr, ac); |
162 |
> |
if (varr != vdef) |
163 |
> |
efree((char *)varr); |
164 |
> |
return(f != NULL); |
165 |
|
} |
166 |
|
|
167 |
|
/* Load a .OBJ file */ |
276 |
|
fprintf(stderr, " %8d statements\r", nstats); |
277 |
|
} |
278 |
|
#if POPEN_SUPPORT |
279 |
< |
if (fspec[0] == '!') |
280 |
< |
pclose(fp); |
281 |
< |
else |
279 |
> |
if (fspec[0] == '!') { |
280 |
> |
if (pclose(fp) != 0) { |
281 |
> |
sprintf(errmsg, "Bad return status from: %s", fspec+1); |
282 |
> |
error(USER, errmsg); |
283 |
> |
freeScene(sc); |
284 |
> |
return(NULL); |
285 |
> |
} |
286 |
> |
} else |
287 |
|
#endif |
288 |
|
if (fp != stdin) |
289 |
|
fclose(fp); |