| 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 */ | 
| 96 |  | ms->next = mlist; | 
| 97 |  | mlist = ms; | 
| 98 |  | } | 
| 99 | < | if ((pathname = getpath(mname, getlibpath(), R_OK)) == NULL) { | 
| 99 | > | if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) { | 
| 100 |  | sprintf(errmsg, "cannot find mesh file \"%s\"", mname); | 
| 101 |  | error(USER, errmsg); | 
| 102 |  | } | 
| 138 |  |  | 
| 139 |  | int | 
| 140 |  | getmeshtrivid(tvid, mo, mp, ti)         /* get triangle vertex ID's */ | 
| 141 | < | int4    tvid[3]; | 
| 141 | > | int32   tvid[3]; | 
| 142 |  | OBJECT  *mo; | 
| 143 |  | MESH    *mp; | 
| 144 |  | OBJECT  ti; | 
| 201 |  | getmeshvert(vp, mp, vid, what)  /* get triangle vertex from ID */ | 
| 202 |  | MESHVERT        *vp; | 
| 203 |  | MESH            *mp; | 
| 204 | < | int4            vid; | 
| 204 | > | int32           vid; | 
| 205 |  | int             what; | 
| 206 |  | { | 
| 207 |  | int             pn = vid >> 8; | 
| 271 |  | OBJECT          ti; | 
| 272 |  | int             wha; | 
| 273 |  | { | 
| 274 | < | int4    tvid[3]; | 
| 274 | > | int32   tvid[3]; | 
| 275 |  |  | 
| 276 |  | if (!getmeshtrivid(tvid, mo, mp, ti)) | 
| 277 |  | return(0); | 
| 284 |  | } | 
| 285 |  |  | 
| 286 |  |  | 
| 287 | < | int4 | 
| 287 | > | int32 | 
| 288 |  | addmeshvert(mp, vp)             /* find/add a mesh vertex */ | 
| 289 |  | register MESH   *mp; | 
| 290 |  | MESHVERT        *vp; | 
| 301 |  | return(-1); | 
| 302 |  | if (vp->v[i] >= mp->mcube.cuorg[i] + mp->mcube.cusize) | 
| 303 |  | return(-1); | 
| 304 | < | cv.xyz[i] = (uint4)(4294967296. * | 
| 304 | > | cv.xyz[i] = (uint32)(4294967296. * | 
| 305 |  | (vp->v[i] - mp->mcube.cuorg[i]) / | 
| 306 |  | mp->mcube.cusize); | 
| 307 |  | } | 
| 313 |  | return(-1); | 
| 314 |  | if (vp->uv[i] >= mp->uvlim[1][i]) | 
| 315 |  | return(-1); | 
| 316 | < | cv.uv[i] = (uint4)(4294967296. * | 
| 316 | > | cv.uv[i] = (uint32)(4294967296. * | 
| 317 |  | (vp->uv[i] - mp->uvlim[0][i]) / | 
| 318 |  | (mp->uvlim[1][i] - mp->uvlim[0][i])); | 
| 319 |  | } | 
| 330 |  | if (lvp == NULL) | 
| 331 |  | goto nomem; | 
| 332 |  | if (lvp->key == NULL) { | 
| 333 | < | lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int4)); | 
| 334 | < | bcopy((void *)&cv, (void *)lvp->key, sizeof(MCVERT)); | 
| 333 | > | lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int32)); | 
| 334 | > | memcpy((void *)lvp->key, (void *)&cv, sizeof(MCVERT)); | 
| 335 |  | } | 
| 336 |  | if (lvp->data == NULL) {        /* new vertex */ | 
| 337 |  | register MESHPATCH      *pp; | 
| 347 |  | (void *)mp->patch, | 
| 348 |  | (mp->npatches + MPATCHBLKSIZ)* | 
| 349 |  | sizeof(MESHPATCH)); | 
| 350 | < | bzero((void *)(mp->patch + mp->npatches), | 
| 350 | > | memset((void *)(mp->patch + mp->npatches), '\0', | 
| 351 |  | MPATCHBLKSIZ*sizeof(MESHPATCH)); | 
| 352 |  | } | 
| 353 |  | if (mp->npatches++ >= 1L<<22) | 
| 355 |  | } | 
| 356 |  | pp = &mp->patch[mp->npatches-1]; | 
| 357 |  | if (pp->xyz == NULL) { | 
| 358 | < | pp->xyz = (uint4 (*)[3])calloc(256, 3*sizeof(int4)); | 
| 358 | > | pp->xyz = (uint32 (*)[3])calloc(256, 3*sizeof(int32)); | 
| 359 |  | if (pp->xyz == NULL) | 
| 360 |  | goto nomem; | 
| 361 |  | } | 
| 363 |  | pp->xyz[pp->nverts][i] = cv.xyz[i]; | 
| 364 |  | if (cv.fl & MT_N) { | 
| 365 |  | if (pp->norm == NULL) { | 
| 366 | < | pp->norm = (int4 *)calloc(256, sizeof(int4)); | 
| 366 | > | pp->norm = (int32 *)calloc(256, sizeof(int32)); | 
| 367 |  | if (pp->norm == NULL) | 
| 368 |  | goto nomem; | 
| 369 |  | } | 
| 371 |  | } | 
| 372 |  | if (cv.fl & MT_UV) { | 
| 373 |  | if (pp->uv == NULL) { | 
| 374 | < | pp->uv = (uint4 (*)[2])calloc(256, | 
| 375 | < | 2*sizeof(uint4)); | 
| 374 | > | pp->uv = (uint32 (*)[2])calloc(256, | 
| 375 | > | 2*sizeof(uint32)); | 
| 376 |  | if (pp->uv == NULL) | 
| 377 |  | goto nomem; | 
| 378 |  | } | 
| 381 |  | } | 
| 382 |  | pp->nverts++; | 
| 383 |  | lvp->data = lvp->key + sizeof(MCVERT); | 
| 384 | < | *(int4 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1); | 
| 384 | > | *(int32 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1); | 
| 385 |  | } | 
| 386 | < | return(*(int4 *)lvp->data); | 
| 386 | > | return(*(int32 *)lvp->data); | 
| 387 |  | nomem: | 
| 388 |  | error(SYSTEM, "out of memory in addmeshvert"); | 
| 389 |  | return(-1); | 
| 396 |  | MESHVERT        tv[3]; | 
| 397 |  | OBJECT          mo; | 
| 398 |  | { | 
| 399 | < | int4                    vid[3], t; | 
| 399 | > | int32                   vid[3], t; | 
| 400 |  | int                     pn[3], i; | 
| 401 |  | register MESHPATCH      *pp; | 
| 402 |  |  | 
| 430 |  | if (pp->ntris == 0) | 
| 431 |  | pp->solemat = mo; | 
| 432 |  | else if (pp->trimat == NULL && mo != pp->solemat) { | 
| 433 | < | pp->trimat = (int2 *)malloc( | 
| 434 | < | 512*sizeof(int2)); | 
| 433 | > | pp->trimat = (int16 *)malloc( | 
| 434 | > | 512*sizeof(int16)); | 
| 435 |  | if (pp->trimat == NULL) | 
| 436 |  | goto nomem; | 
| 437 |  | for (i = pp->ntris; i--; ) | 
| 613 |  | fprintf(fp, "\t%d materials\n", ms->nmats); | 
| 614 |  | fprintf(fp, "\t%d patches (%.2f MBytes)\n", ms->npatches, | 
| 615 |  | (ms->npatches*sizeof(MESHPATCH) + | 
| 616 | < | vcnt*3*sizeof(uint4) + | 
| 617 | < | nscnt*sizeof(int4) + | 
| 618 | < | uvscnt*2*sizeof(uint4) + | 
| 616 | > | vcnt*3*sizeof(uint32) + | 
| 617 | > | nscnt*sizeof(int32) + | 
| 618 | > | uvscnt*2*sizeof(uint32) + | 
| 619 |  | tcnt*sizeof(struct PTri) + | 
| 620 |  | t1cnt*sizeof(struct PJoin1) + | 
| 621 |  | t2cnt*sizeof(struct PJoin2))/(1024.*1024.)); |