9 |
|
#include "octree.h" |
10 |
|
#include "object.h" |
11 |
|
#include "mesh.h" |
12 |
+ |
#include "resolu.h" |
13 |
|
|
14 |
|
static char *meshfn; /* input file name */ |
15 |
|
static FILE *meshfp; /* mesh file pointer */ |
74 |
|
register int i; |
75 |
|
|
76 |
|
switch (getc(meshfp)) { |
77 |
< |
case OT_EMPTY: |
78 |
< |
return(EMPTY); |
79 |
< |
case OT_FULL: |
80 |
< |
return(getfullnode()); |
81 |
< |
case OT_TREE: |
82 |
< |
if ((ot = octalloc()) == EMPTY) |
83 |
< |
mesherror(SYSTEM, "out of tree space in readmesh"); |
84 |
< |
for (i = 0; i < 8; i++) |
85 |
< |
octkid(ot, i) = gettree(); |
86 |
< |
return(ot); |
87 |
< |
case EOF: |
88 |
< |
mesherror(USER, "truncated mesh octree"); |
89 |
< |
default: |
90 |
< |
mesherror(USER, "damaged mesh octree"); |
77 |
> |
case OT_EMPTY: |
78 |
> |
return(EMPTY); |
79 |
> |
case OT_FULL: |
80 |
> |
return(getfullnode()); |
81 |
> |
case OT_TREE: |
82 |
> |
if ((ot = octalloc()) == EMPTY) |
83 |
> |
mesherror(SYSTEM, "out of tree space in readmesh"); |
84 |
> |
for (i = 0; i < 8; i++) |
85 |
> |
octkid(ot, i) = gettree(); |
86 |
> |
return(ot); |
87 |
> |
case EOF: |
88 |
> |
mesherror(USER, "truncated mesh octree"); |
89 |
> |
default: |
90 |
> |
mesherror(USER, "damaged mesh octree"); |
91 |
|
} |
92 |
+ |
return NULL; /* pro forma return */ |
93 |
|
} |
94 |
|
|
95 |
|
|
176 |
|
} |
177 |
|
} else |
178 |
|
pp->tri = NULL; |
179 |
+ |
/* local triangle material(s) */ |
180 |
+ |
if (mgetint(2) > 1) { |
181 |
+ |
pp->trimat = (int2 *)malloc(pp->ntris*sizeof(int2)); |
182 |
+ |
if (pp->trimat == NULL) |
183 |
+ |
goto nomem; |
184 |
+ |
for (i = 0; i < pp->ntris; i++) |
185 |
+ |
pp->trimat[i] = mgetint(2); |
186 |
+ |
} else { |
187 |
+ |
pp->solemat = mgetint(2); |
188 |
+ |
pp->trimat = NULL; |
189 |
+ |
} |
190 |
|
/* joiner triangles */ |
191 |
|
pp->nj1tris = mgetint(2); |
192 |
|
if (pp->nj1tris < 0 || pp->nj1tris > 512) |
200 |
|
pp->j1tri[i].v1j = mgetint(4); |
201 |
|
pp->j1tri[i].v2 = mgetint(1); |
202 |
|
pp->j1tri[i].v3 = mgetint(1); |
203 |
+ |
pp->j1tri[i].mat = mgetint(2); |
204 |
|
} |
205 |
|
} else |
206 |
|
pp->j1tri = NULL; |
217 |
|
pp->j2tri[i].v1j = mgetint(4); |
218 |
|
pp->j2tri[i].v2j = mgetint(4); |
219 |
|
pp->j2tri[i].v3 = mgetint(1); |
220 |
+ |
pp->j2tri[i].mat = mgetint(2); |
221 |
|
} |
222 |
|
} else |
223 |
|
pp->j2tri = NULL; |
233 |
|
char *path; |
234 |
|
int flags; |
235 |
|
{ |
236 |
+ |
char *err; |
237 |
|
char sbuf[64]; |
238 |
|
int i; |
239 |
|
/* check what's loaded */ |
246 |
|
sprintf(errmsg, "cannot open mesh file \"%s\"", path); |
247 |
|
error(SYSTEM, errmsg); |
248 |
|
} |
249 |
< |
#ifdef MSDOS |
234 |
< |
setmode(fileno(meshfp), O_BINARY); |
235 |
< |
#endif |
249 |
> |
SET_FILE_BINARY(meshfp); |
250 |
|
/* read header */ |
251 |
|
checkheader(meshfp, MESHFMT, flags&IO_INFO ? stdout : (FILE *)NULL); |
252 |
|
/* read format number */ |
273 |
|
mp->mcube.cutree = gettree(); |
274 |
|
else if (flags & IO_SCENE) |
275 |
|
skiptree(); |
276 |
< |
/* read the patches */ |
276 |
> |
/* read materials and patches */ |
277 |
|
if (flags & IO_SCENE) { |
278 |
+ |
mp->mat0 = nobjects; |
279 |
+ |
readscene(meshfp, objsize); |
280 |
+ |
mp->nmats = nobjects - mp->mat0; |
281 |
|
mp->npatches = mgetint(4); |
282 |
|
mp->patch = (MESHPATCH *)calloc(mp->npatches, |
283 |
|
sizeof(MESHPATCH)); |
289 |
|
/* clean up */ |
290 |
|
fclose(meshfp); |
291 |
|
mp->ldflags |= flags; |
292 |
+ |
/* verify data */ |
293 |
+ |
if ((err = checkmesh(mp)) != NULL) |
294 |
+ |
mesherror(USER, err); |
295 |
|
} |