174 |
|
} |
175 |
|
} else |
176 |
|
pp->tri = NULL; |
177 |
+ |
/* local triangle material(s) */ |
178 |
+ |
if (mgetint(2) > 1) { |
179 |
+ |
pp->trimat = (int2 *)malloc(pp->ntris*sizeof(int2)); |
180 |
+ |
if (pp->trimat == NULL) |
181 |
+ |
goto nomem; |
182 |
+ |
for (i = 0; i < pp->ntris; i++) |
183 |
+ |
pp->trimat[i] = mgetint(2); |
184 |
+ |
} else { |
185 |
+ |
pp->solemat = mgetint(2); |
186 |
+ |
pp->trimat = NULL; |
187 |
+ |
} |
188 |
|
/* joiner triangles */ |
189 |
|
pp->nj1tris = mgetint(2); |
190 |
|
if (pp->nj1tris < 0 || pp->nj1tris > 512) |
198 |
|
pp->j1tri[i].v1j = mgetint(4); |
199 |
|
pp->j1tri[i].v2 = mgetint(1); |
200 |
|
pp->j1tri[i].v3 = mgetint(1); |
201 |
+ |
pp->j1tri[i].mat = mgetint(2); |
202 |
|
} |
203 |
|
} else |
204 |
|
pp->j1tri = NULL; |
215 |
|
pp->j2tri[i].v1j = mgetint(4); |
216 |
|
pp->j2tri[i].v2j = mgetint(4); |
217 |
|
pp->j2tri[i].v3 = mgetint(1); |
218 |
+ |
pp->j2tri[i].mat = mgetint(2); |
219 |
|
} |
220 |
|
} else |
221 |
|
pp->j2tri = NULL; |
231 |
|
char *path; |
232 |
|
int flags; |
233 |
|
{ |
234 |
+ |
char *err; |
235 |
|
char sbuf[64]; |
236 |
|
int i; |
237 |
|
/* check what's loaded */ |
244 |
|
sprintf(errmsg, "cannot open mesh file \"%s\"", path); |
245 |
|
error(SYSTEM, errmsg); |
246 |
|
} |
247 |
< |
#ifdef MSDOS |
234 |
< |
setmode(fileno(meshfp), O_BINARY); |
235 |
< |
#endif |
247 |
> |
SET_FILE_BINARY(meshfp); |
248 |
|
/* read header */ |
249 |
|
checkheader(meshfp, MESHFMT, flags&IO_INFO ? stdout : (FILE *)NULL); |
250 |
|
/* read format number */ |
271 |
|
mp->mcube.cutree = gettree(); |
272 |
|
else if (flags & IO_SCENE) |
273 |
|
skiptree(); |
274 |
< |
/* read the patches */ |
274 |
> |
/* read materials and patches */ |
275 |
|
if (flags & IO_SCENE) { |
276 |
+ |
mp->mat0 = nobjects; |
277 |
+ |
readscene(meshfp, objsize); |
278 |
+ |
mp->nmats = nobjects - mp->mat0; |
279 |
|
mp->npatches = mgetint(4); |
280 |
|
mp->patch = (MESHPATCH *)calloc(mp->npatches, |
281 |
|
sizeof(MESHPATCH)); |
287 |
|
/* clean up */ |
288 |
|
fclose(meshfp); |
289 |
|
mp->ldflags |= flags; |
290 |
+ |
/* verify data */ |
291 |
+ |
if ((err = checkmesh(mp)) != NULL) |
292 |
+ |
mesherror(USER, err); |
293 |
|
} |