5 |
|
* Mesh support routines |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include <string.h> |
9 |
+ |
|
10 |
|
#include "standard.h" |
11 |
|
#include "octree.h" |
12 |
|
#include "object.h" |
16 |
|
/* An encoded mesh vertex */ |
17 |
|
typedef struct { |
18 |
|
int fl; |
19 |
< |
uint4 xyz[3]; |
20 |
< |
int4 norm; |
21 |
< |
uint4 uv[2]; |
19 |
> |
uint32 xyz[3]; |
20 |
> |
int32 norm; |
21 |
> |
uint32 uv[2]; |
22 |
|
} MCVERT; |
23 |
|
|
24 |
|
#define MPATCHBLKSIZ 128 /* patch allocation block size */ |
70 |
|
|
71 |
|
|
72 |
|
MESH * |
73 |
< |
getmesh(mname, flags) /* get mesh data */ |
73 |
> |
getmesh(mname, flags) /* get new mesh data reference */ |
74 |
|
char *mname; |
75 |
|
int flags; |
76 |
|
{ |
80 |
|
flags &= IO_LEGAL; |
81 |
|
for (ms = mlist; ms != NULL; ms = ms->next) |
82 |
|
if (!strcmp(mname, ms->name)) { |
83 |
< |
if ((ms->ldflags & flags) == flags) { |
84 |
< |
ms->nref++; |
83 |
< |
return(ms); /* loaded */ |
84 |
< |
} |
85 |
< |
break; /* load the rest */ |
83 |
> |
ms->nref++; /* increase reference count */ |
84 |
> |
break; |
85 |
|
} |
86 |
< |
if (ms == NULL) { |
86 |
> |
if (ms == NULL) { /* load first time */ |
87 |
|
ms = (MESH *)calloc(1, sizeof(MESH)); |
88 |
|
if (ms == NULL) |
89 |
|
error(SYSTEM, "out of memory in getmesh"); |
93 |
|
ms->next = mlist; |
94 |
|
mlist = ms; |
95 |
|
} |
96 |
< |
if ((pathname = getpath(mname, getlibpath(), R_OK)) == NULL) { |
96 |
> |
if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) { |
97 |
|
sprintf(errmsg, "cannot find mesh file \"%s\"", mname); |
98 |
|
error(USER, errmsg); |
99 |
|
} |
127 |
|
ins->msh = NULL; |
128 |
|
o->os = (char *)ins; |
129 |
|
} |
130 |
< |
if (ins->msh == NULL || (ins->msh->ldflags & flags) != flags) |
130 |
> |
if (ins->msh == NULL) |
131 |
|
ins->msh = getmesh(o->oargs.sarg[0], flags); |
132 |
+ |
else if ((flags &= ~ins->msh->ldflags)) |
133 |
+ |
readmesh(ins->msh, |
134 |
+ |
getpath(o->oargs.sarg[0], getrlibpath(), R_OK), |
135 |
+ |
flags); |
136 |
|
return(ins); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
int |
141 |
|
getmeshtrivid(tvid, mo, mp, ti) /* get triangle vertex ID's */ |
142 |
< |
int4 tvid[3]; |
142 |
> |
int32 tvid[3]; |
143 |
|
OBJECT *mo; |
144 |
|
MESH *mp; |
145 |
|
OBJECT ti; |
202 |
|
getmeshvert(vp, mp, vid, what) /* get triangle vertex from ID */ |
203 |
|
MESHVERT *vp; |
204 |
|
MESH *mp; |
205 |
< |
int4 vid; |
205 |
> |
int32 vid; |
206 |
|
int what; |
207 |
|
{ |
208 |
|
int pn = vid >> 8; |
272 |
|
OBJECT ti; |
273 |
|
int wha; |
274 |
|
{ |
275 |
< |
int4 tvid[3]; |
275 |
> |
int32 tvid[3]; |
276 |
|
|
277 |
|
if (!getmeshtrivid(tvid, mo, mp, ti)) |
278 |
|
return(0); |
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
< |
int4 |
288 |
> |
int32 |
289 |
|
addmeshvert(mp, vp) /* find/add a mesh vertex */ |
290 |
|
register MESH *mp; |
291 |
|
MESHVERT *vp; |
302 |
|
return(-1); |
303 |
|
if (vp->v[i] >= mp->mcube.cuorg[i] + mp->mcube.cusize) |
304 |
|
return(-1); |
305 |
< |
cv.xyz[i] = (uint4)(4294967296. * |
305 |
> |
cv.xyz[i] = (uint32)(4294967296. * |
306 |
|
(vp->v[i] - mp->mcube.cuorg[i]) / |
307 |
|
mp->mcube.cusize); |
308 |
|
} |
314 |
|
return(-1); |
315 |
|
if (vp->uv[i] >= mp->uvlim[1][i]) |
316 |
|
return(-1); |
317 |
< |
cv.uv[i] = (uint4)(4294967296. * |
317 |
> |
cv.uv[i] = (uint32)(4294967296. * |
318 |
|
(vp->uv[i] - mp->uvlim[0][i]) / |
319 |
|
(mp->uvlim[1][i] - mp->uvlim[0][i])); |
320 |
|
} |
331 |
|
if (lvp == NULL) |
332 |
|
goto nomem; |
333 |
|
if (lvp->key == NULL) { |
334 |
< |
lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int4)); |
335 |
< |
bcopy((void *)&cv, (void *)lvp->key, sizeof(MCVERT)); |
334 |
> |
lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int32)); |
335 |
> |
memcpy((void *)lvp->key, (void *)&cv, sizeof(MCVERT)); |
336 |
|
} |
337 |
|
if (lvp->data == NULL) { /* new vertex */ |
338 |
|
register MESHPATCH *pp; |
348 |
|
(void *)mp->patch, |
349 |
|
(mp->npatches + MPATCHBLKSIZ)* |
350 |
|
sizeof(MESHPATCH)); |
351 |
< |
bzero((void *)(mp->patch + mp->npatches), |
351 |
> |
memset((void *)(mp->patch + mp->npatches), '\0', |
352 |
|
MPATCHBLKSIZ*sizeof(MESHPATCH)); |
353 |
|
} |
354 |
|
if (mp->npatches++ >= 1L<<22) |
356 |
|
} |
357 |
|
pp = &mp->patch[mp->npatches-1]; |
358 |
|
if (pp->xyz == NULL) { |
359 |
< |
pp->xyz = (uint4 (*)[3])calloc(256, 3*sizeof(int4)); |
359 |
> |
pp->xyz = (uint32 (*)[3])calloc(256, 3*sizeof(int32)); |
360 |
|
if (pp->xyz == NULL) |
361 |
|
goto nomem; |
362 |
|
} |
364 |
|
pp->xyz[pp->nverts][i] = cv.xyz[i]; |
365 |
|
if (cv.fl & MT_N) { |
366 |
|
if (pp->norm == NULL) { |
367 |
< |
pp->norm = (int4 *)calloc(256, sizeof(int4)); |
367 |
> |
pp->norm = (int32 *)calloc(256, sizeof(int32)); |
368 |
|
if (pp->norm == NULL) |
369 |
|
goto nomem; |
370 |
|
} |
372 |
|
} |
373 |
|
if (cv.fl & MT_UV) { |
374 |
|
if (pp->uv == NULL) { |
375 |
< |
pp->uv = (uint4 (*)[2])calloc(256, |
376 |
< |
2*sizeof(uint4)); |
375 |
> |
pp->uv = (uint32 (*)[2])calloc(256, |
376 |
> |
2*sizeof(uint32)); |
377 |
|
if (pp->uv == NULL) |
378 |
|
goto nomem; |
379 |
|
} |
382 |
|
} |
383 |
|
pp->nverts++; |
384 |
|
lvp->data = lvp->key + sizeof(MCVERT); |
385 |
< |
*(int4 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1); |
385 |
> |
*(int32 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1); |
386 |
|
} |
387 |
< |
return(*(int4 *)lvp->data); |
387 |
> |
return(*(int32 *)lvp->data); |
388 |
|
nomem: |
389 |
|
error(SYSTEM, "out of memory in addmeshvert"); |
390 |
|
return(-1); |
397 |
|
MESHVERT tv[3]; |
398 |
|
OBJECT mo; |
399 |
|
{ |
400 |
< |
int4 vid[3], t; |
400 |
> |
int32 vid[3], t; |
401 |
|
int pn[3], i; |
402 |
|
register MESHPATCH *pp; |
403 |
|
|
431 |
|
if (pp->ntris == 0) |
432 |
|
pp->solemat = mo; |
433 |
|
else if (pp->trimat == NULL && mo != pp->solemat) { |
434 |
< |
pp->trimat = (int2 *)malloc( |
435 |
< |
512*sizeof(int2)); |
434 |
> |
pp->trimat = (int16 *)malloc( |
435 |
> |
512*sizeof(int16)); |
436 |
|
if (pp->trimat == NULL) |
437 |
|
goto nomem; |
438 |
|
for (i = pp->ntris; i--; ) |
614 |
|
fprintf(fp, "\t%d materials\n", ms->nmats); |
615 |
|
fprintf(fp, "\t%d patches (%.2f MBytes)\n", ms->npatches, |
616 |
|
(ms->npatches*sizeof(MESHPATCH) + |
617 |
< |
vcnt*3*sizeof(uint4) + |
618 |
< |
nscnt*sizeof(int4) + |
619 |
< |
uvscnt*2*sizeof(uint4) + |
617 |
> |
vcnt*3*sizeof(uint32) + |
618 |
> |
nscnt*sizeof(int32) + |
619 |
> |
uvscnt*2*sizeof(uint32) + |
620 |
|
tcnt*sizeof(struct PTri) + |
621 |
|
t1cnt*sizeof(struct PJoin1) + |
622 |
|
t2cnt*sizeof(struct PJoin2))/(1024.*1024.)); |