| 5 |  | * Mesh support routines | 
| 6 |  | */ | 
| 7 |  |  | 
| 8 | < | #include <string.h> | 
| 9 | < |  | 
| 10 | < | #include "standard.h" | 
| 8 | > | #include "rtio.h" | 
| 9 | > | #include "rtmath.h" | 
| 10 | > | #include "rterror.h" | 
| 11 | > | #include "paths.h" | 
| 12 |  | #include "octree.h" | 
| 13 |  | #include "object.h" | 
| 14 |  | #include "otypes.h" | 
| 19 |  | int             fl; | 
| 20 |  | uint32          xyz[3]; | 
| 21 |  | int32           norm; | 
| 22 | < | uint16          uv[2]; | 
| 22 | > | uint32          uv[2]; | 
| 23 |  | } MCVERT; | 
| 24 |  |  | 
| 25 |  | #define  MPATCHBLKSIZ   128             /* patch allocation block size */ | 
| 30 |  |  | 
| 31 |  |  | 
| 32 |  | static unsigned long | 
| 33 | < | cvhash(cvp)                             /* hash an encoded vertex */ | 
| 33 | < | MCVERT  *cvp; | 
| 33 | > | cvhash(const char *p)                   /* hash an encoded vertex */ | 
| 34 |  | { | 
| 35 | + | const MCVERT    *cvp = (const MCVERT *)p; | 
| 36 |  | unsigned long   hval; | 
| 37 |  |  | 
| 38 |  | if (!(cvp->fl & MT_V)) | 
| 47 |  |  | 
| 48 |  |  | 
| 49 |  | static int | 
| 50 | < | cvcmp(v1, v2)                           /* compare encoded vertices */ | 
| 50 | < | register MCVERT *v1, *v2; | 
| 50 | > | cvcmp(const char *vv1, const char *vv2)         /* compare encoded vertices */ | 
| 51 |  | { | 
| 52 | + | const MCVERT    *v1 = (const MCVERT *)vv1, *v2 = (const MCVERT *)vv2; | 
| 53 | + |  | 
| 54 |  | if (v1->fl != v2->fl) | 
| 55 |  | return(1); | 
| 56 |  | if (v1->xyz[0] != v2->xyz[0]) | 
| 72 |  |  | 
| 73 |  |  | 
| 74 |  | MESH * | 
| 75 | < | getmesh(mname, flags)                   /* get new mesh data reference */ | 
| 76 | < | char    *mname; | 
| 77 | < | int     flags; | 
| 75 | > | getmesh(                                /* get new mesh data reference */ | 
| 76 | > | char    *mname, | 
| 77 | > | int     flags | 
| 78 | > | ) | 
| 79 |  | { | 
| 80 |  | char  *pathname; | 
| 81 | < | register MESH  *ms; | 
| 81 | > | MESH  *ms; | 
| 82 |  |  | 
| 83 |  | flags &= IO_LEGAL; | 
| 84 |  | for (ms = mlist; ms != NULL; ms = ms->next) | 
| 98 |  | } | 
| 99 |  | if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) { | 
| 100 |  | sprintf(errmsg, "cannot find mesh file \"%s\"", mname); | 
| 101 | < | error(USER, errmsg); | 
| 101 | > | error(SYSTEM, errmsg); | 
| 102 |  | } | 
| 103 |  | flags &= ~ms->ldflags; | 
| 104 |  | if (flags) | 
| 108 |  |  | 
| 109 |  |  | 
| 110 |  | MESHINST * | 
| 111 | < | getmeshinst(o, flags)                   /* create mesh instance */ | 
| 112 | < | OBJREC  *o; | 
| 113 | < | int     flags; | 
| 111 | > | getmeshinst(                            /* create mesh instance */ | 
| 112 | > | OBJREC  *o, | 
| 113 | > | int     flags | 
| 114 | > | ) | 
| 115 |  | { | 
| 116 | < | register MESHINST  *ins; | 
| 116 | > | MESHINST  *ins; | 
| 117 |  |  | 
| 118 |  | flags &= IO_LEGAL; | 
| 119 |  | if ((ins = (MESHINST *)o->os) == NULL) { | 
| 142 |  |  | 
| 143 |  |  | 
| 144 |  | int | 
| 145 | < | getmeshtrivid(tvid, mo, mp, ti)         /* get triangle vertex ID's */ | 
| 146 | < | int32   tvid[3]; | 
| 147 | < | OBJECT  *mo; | 
| 148 | < | MESH    *mp; | 
| 145 | < | OBJECT  ti; | 
| 145 | > | nextmeshtri(                            /* get next triangle ID */ | 
| 146 | > | OBJECT *tip, | 
| 147 | > | MESH *mp | 
| 148 | > | ) | 
| 149 |  | { | 
| 150 | + | int             pn; | 
| 151 | + | MESHPATCH       *pp; | 
| 152 | + |  | 
| 153 | + | pn = ++(*tip) >> 10;                    /* next triangle (OVOID init) */ | 
| 154 | + | while (pn < mp->npatches) { | 
| 155 | + | pp = &mp->patch[pn]; | 
| 156 | + | if (!(*tip & 0x200)) {          /* local triangle? */ | 
| 157 | + | if ((*tip & 0x1ff) < pp->ntris) | 
| 158 | + | return(1); | 
| 159 | + | *tip &= ~0x1ff;         /* move on to single-joiners */ | 
| 160 | + | *tip |= 0x200; | 
| 161 | + | } | 
| 162 | + | if (!(*tip & 0x100)) {          /* single joiner? */ | 
| 163 | + | if ((*tip & 0xff) < pp->nj1tris) | 
| 164 | + | return(1); | 
| 165 | + | *tip &= ~0xff;          /* move on to double-joiners */ | 
| 166 | + | *tip |= 0x100; | 
| 167 | + | } | 
| 168 | + | if ((*tip & 0xff) < pp->nj2tris) | 
| 169 | + | return(1); | 
| 170 | + | *tip = ++pn << 10;              /* first in next patch */ | 
| 171 | + | } | 
| 172 | + | return(0);                              /* out of patches */ | 
| 173 | + | } | 
| 174 | + |  | 
| 175 | + | int | 
| 176 | + | getmeshtrivid(                          /* get triangle vertex ID's */ | 
| 177 | + | int32   tvid[3], | 
| 178 | + | OBJECT  *mo, | 
| 179 | + | MESH    *mp, | 
| 180 | + | OBJECT  ti | 
| 181 | + | ) | 
| 182 | + | { | 
| 183 |  | int             pn = ti >> 10; | 
| 184 |  | MESHPATCH       *pp; | 
| 185 |  |  | 
| 235 |  |  | 
| 236 |  |  | 
| 237 |  | int | 
| 238 | < | getmeshvert(vp, mp, vid, what)  /* get triangle vertex from ID */ | 
| 239 | < | MESHVERT        *vp; | 
| 240 | < | MESH            *mp; | 
| 241 | < | int32           vid; | 
| 242 | < | int             what; | 
| 238 | > | getmeshvert(                            /* get triangle vertex from ID */ | 
| 239 | > | MESHVERT        *vp, | 
| 240 | > | MESH            *mp, | 
| 241 | > | int32           vid, | 
| 242 | > | int             what | 
| 243 | > | ) | 
| 244 |  | { | 
| 245 |  | int             pn = vid >> 8; | 
| 246 |  | MESHPATCH       *pp; | 
| 247 |  | double          vres; | 
| 248 | < | register int    i; | 
| 248 | > | int     i; | 
| 249 |  |  | 
| 250 |  | vp->fl = 0; | 
| 251 |  | if (pn >= mp->npatches) | 
| 272 |  | for (i = 0; i < 2; i++) | 
| 273 |  | vp->uv[i] = mp->uvlim[0][i] + | 
| 274 |  | (mp->uvlim[1][i] - mp->uvlim[0][i])* | 
| 275 | < | (pp->uv[vid][i] + .5)*(1./65536.); | 
| 275 | > | (pp->uv[vid][i] + .5)*(1./4294967296.); | 
| 276 |  | vp->fl |= MT_UV; | 
| 277 |  | } | 
| 278 |  | return(vp->fl); | 
| 280 |  |  | 
| 281 |  |  | 
| 282 |  | OBJREC * | 
| 283 | < | getmeshpseudo(mp, mo)           /* get mesh pseudo object for material */ | 
| 284 | < | MESH    *mp; | 
| 285 | < | OBJECT  mo; | 
| 283 | > | getmeshpseudo(                  /* get mesh pseudo object for material */ | 
| 284 | > | MESH    *mp, | 
| 285 | > | OBJECT  mo | 
| 286 | > | ) | 
| 287 |  | { | 
| 288 | < | if (mo < mp->mat0 || mo >= mp->mat0 + mp->nmats) | 
| 288 | > | if ((mo < mp->mat0) | (mo >= mp->mat0 + mp->nmats)) | 
| 289 |  | error(INTERNAL, "modifier out of range in getmeshpseudo"); | 
| 290 |  | if (mp->pseudo == NULL) { | 
| 291 | < | register int    i; | 
| 291 | > | int     i; | 
| 292 |  | mp->pseudo = (OBJREC *)calloc(mp->nmats, sizeof(OBJREC)); | 
| 293 |  | if (mp->pseudo == NULL) | 
| 294 |  | error(SYSTEM, "out of memory in getmeshpseudo"); | 
| 303 |  |  | 
| 304 |  |  | 
| 305 |  | int | 
| 306 | < | getmeshtri(tv, mo, mp, ti, wha) /* get triangle vertices */ | 
| 307 | < | MESHVERT        tv[3]; | 
| 308 | < | OBJECT          *mo; | 
| 309 | < | MESH            *mp; | 
| 310 | < | OBJECT          ti; | 
| 311 | < | int             wha; | 
| 306 | > | getmeshtri(                     /* get triangle vertices */ | 
| 307 | > | MESHVERT        tv[3], | 
| 308 | > | OBJECT          *mo, | 
| 309 | > | MESH            *mp, | 
| 310 | > | OBJECT          ti, | 
| 311 | > | int             wha | 
| 312 | > | ) | 
| 313 |  | { | 
| 314 |  | int32   tvid[3]; | 
| 315 |  |  | 
| 325 |  |  | 
| 326 |  |  | 
| 327 |  | int32 | 
| 328 | < | addmeshvert(mp, vp)             /* find/add a mesh vertex */ | 
| 329 | < | register MESH   *mp; | 
| 330 | < | MESHVERT        *vp; | 
| 328 | > | addmeshvert(                    /* find/add a mesh vertex */ | 
| 329 | > | MESH            *mp, | 
| 330 | > | MESHVERT        *vp | 
| 331 | > | ) | 
| 332 |  | { | 
| 333 | < | LUENT           *lvp; | 
| 334 | < | MCVERT          cv; | 
| 335 | < | register int    i; | 
| 333 | > | LUENT   *lvp; | 
| 334 | > | MCVERT  cv; | 
| 335 | > | int     i; | 
| 336 |  |  | 
| 337 |  | if (!(vp->fl & MT_V)) | 
| 338 |  | return(-1); | 
| 346 |  | (vp->v[i] - mp->mcube.cuorg[i]) / | 
| 347 |  | mp->mcube.cusize); | 
| 348 |  | } | 
| 349 | < | if (vp->fl & MT_N) | 
| 349 | > | if (vp->fl & MT_N)              /* assumes normalized! */ | 
| 350 |  | cv.norm = encodedir(vp->n); | 
| 351 |  | if (vp->fl & MT_UV) | 
| 352 |  | for (i = 0; i < 2; i++) { | 
| 354 |  | return(-1); | 
| 355 |  | if (vp->uv[i] >= mp->uvlim[1][i]) | 
| 356 |  | return(-1); | 
| 357 | < | cv.uv[i] = (uint32)(65536. * | 
| 357 | > | cv.uv[i] = (uint32)(4294967296. * | 
| 358 |  | (vp->uv[i] - mp->uvlim[0][i]) / | 
| 359 |  | (mp->uvlim[1][i] - mp->uvlim[0][i])); | 
| 360 |  | } | 
| 372 |  | goto nomem; | 
| 373 |  | if (lvp->key == NULL) { | 
| 374 |  | lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int32)); | 
| 375 | < | memcpy((void *)lvp->key, (void *)&cv, sizeof(MCVERT)); | 
| 375 | > | memcpy(lvp->key, &cv, sizeof(MCVERT)); | 
| 376 |  | } | 
| 377 |  | if (lvp->data == NULL) {        /* new vertex */ | 
| 378 | < | register MESHPATCH      *pp; | 
| 378 | > | MESHPATCH       *pp; | 
| 379 |  | if (mp->npatches <= 0) { | 
| 380 |  | mp->patch = (MESHPATCH *)calloc(MPATCHBLKSIZ, | 
| 381 |  | sizeof(MESHPATCH)); | 
| 383 |  | goto nomem; | 
| 384 |  | mp->npatches = 1; | 
| 385 |  | } else if (mp->patch[mp->npatches-1].nverts >= 256) { | 
| 386 | + | if (mp->npatches >= 1L<<22) | 
| 387 | + | error(INTERNAL, "too many mesh patches"); | 
| 388 |  | if (mp->npatches % MPATCHBLKSIZ == 0) { | 
| 389 | < | mp->patch = (MESHPATCH *)realloc( | 
| 390 | < | (void *)mp->patch, | 
| 391 | < | (mp->npatches + MPATCHBLKSIZ)* | 
| 392 | < | sizeof(MESHPATCH)); | 
| 351 | < | memset((void *)(mp->patch + mp->npatches), '\0', | 
| 389 | > | mp->patch = (MESHPATCH *)realloc(mp->patch, | 
| 390 | > | (mp->npatches + MPATCHBLKSIZ)* | 
| 391 | > | sizeof(MESHPATCH)); | 
| 392 | > | memset((mp->patch + mp->npatches), '\0', | 
| 393 |  | MPATCHBLKSIZ*sizeof(MESHPATCH)); | 
| 394 |  | } | 
| 395 | < | if (mp->npatches++ >= 1L<<22) | 
| 355 | < | error(INTERNAL, "too many mesh patches"); | 
| 395 | > | mp->npatches++; | 
| 396 |  | } | 
| 397 |  | pp = &mp->patch[mp->npatches-1]; | 
| 398 |  | if (pp->xyz == NULL) { | 
| 412 |  | } | 
| 413 |  | if (cv.fl & MT_UV) { | 
| 414 |  | if (pp->uv == NULL) { | 
| 415 | < | pp->uv = (uint16 (*)[2])calloc(256, | 
| 416 | < | 2*sizeof(uint16)); | 
| 415 | > | pp->uv = (uint32 (*)[2])calloc(256, | 
| 416 | > | 2*sizeof(uint32)); | 
| 417 |  | if (pp->uv == NULL) | 
| 418 |  | goto nomem; | 
| 419 |  | } | 
| 432 |  |  | 
| 433 |  |  | 
| 434 |  | OBJECT | 
| 435 | < | addmeshtri(mp, tv, mo)          /* add a new mesh triangle */ | 
| 436 | < | MESH            *mp; | 
| 437 | < | MESHVERT        tv[3]; | 
| 438 | < | OBJECT          mo; | 
| 435 | > | addmeshtri(                     /* add a new mesh triangle */ | 
| 436 | > | MESH            *mp, | 
| 437 | > | MESHVERT        tv[3], | 
| 438 | > | OBJECT          mo | 
| 439 | > | ) | 
| 440 |  | { | 
| 441 | < | int32                   vid[3], t; | 
| 442 | < | int                     pn[3], i; | 
| 443 | < | register MESHPATCH      *pp; | 
| 441 | > | int32           vid[3], t; | 
| 442 | > | int             pn[3], i; | 
| 443 | > | MESHPATCH       *pp; | 
| 444 |  |  | 
| 445 |  | if (!(tv[0].fl & tv[1].fl & tv[2].fl & MT_V)) | 
| 446 |  | return(OVOID); | 
| 458 |  | error(INTERNAL, "modifier range error in addmeshtri"); | 
| 459 |  | } | 
| 460 |  | /* assign triangle */ | 
| 461 | < | if (pn[0] == pn[1] && pn[1] == pn[2]) { /* local case */ | 
| 461 | > | if ((pn[0] == pn[1]) & (pn[1] == pn[2])) {      /* local case */ | 
| 462 |  | pp = &mp->patch[pn[0]]; | 
| 463 |  | if (pp->tri == NULL) { | 
| 464 |  | pp->tri = (struct PTri *)malloc( | 
| 484 |  | pp->trimat[pp->ntris] = mo; | 
| 485 |  | return(pn[0] << 10 | pp->ntris++); | 
| 486 |  | } | 
| 487 | < | } | 
| 447 | < | if (pn[0] == pn[1]) { | 
| 487 | > | } else if (pn[0] == pn[1]) { | 
| 488 |  | t = vid[2]; vid[2] = vid[1]; vid[1] = vid[0]; vid[0] = t; | 
| 489 |  | i = pn[2]; pn[2] = pn[1]; pn[1] = pn[0]; pn[0] = i; | 
| 490 |  | } else if (pn[0] == pn[2]) { | 
| 508 |  | } | 
| 509 |  | } | 
| 510 |  | /* double link */ | 
| 511 | < | pp = &mp->patch[pn[2]]; | 
| 511 | > | pp = &mp->patch[pn[i=0]]; | 
| 512 | > | if (mp->patch[pn[1]].nj2tris < pp->nj2tris) | 
| 513 | > | pp = &mp->patch[pn[i=1]]; | 
| 514 | > | if (mp->patch[pn[2]].nj2tris < pp->nj2tris) | 
| 515 | > | pp = &mp->patch[pn[i=2]]; | 
| 516 | > | if (pp->nj2tris >= 256) | 
| 517 | > | error(INTERNAL, "too many patch triangles in addmeshtri"); | 
| 518 |  | if (pp->j2tri == NULL) { | 
| 519 |  | pp->j2tri = (struct PJoin2 *)malloc( | 
| 520 |  | 256*sizeof(struct PJoin2)); | 
| 521 |  | if (pp->j2tri == NULL) | 
| 522 |  | goto nomem; | 
| 523 |  | } | 
| 478 | – | if (pp->nj2tris >= 256) | 
| 479 | – | error(INTERNAL, "too many patch triangles in addmeshtri"); | 
| 480 | – | pp->j2tri[pp->nj2tris].v1j = vid[0]; | 
| 481 | – | pp->j2tri[pp->nj2tris].v2j = vid[1]; | 
| 482 | – | pp->j2tri[pp->nj2tris].v3 = vid[2] & 0xff; | 
| 524 |  | pp->j2tri[pp->nj2tris].mat = mo; | 
| 525 | < | return(pn[2] << 10 | 0x300 | pp->nj2tris++); | 
| 525 | > | switch (i) { | 
| 526 | > | case 0: | 
| 527 | > | pp->j2tri[pp->nj2tris].v3 = vid[0] & 0xff; | 
| 528 | > | pp->j2tri[pp->nj2tris].v1j = vid[1]; | 
| 529 | > | pp->j2tri[pp->nj2tris].v2j = vid[2]; | 
| 530 | > | return(pn[0] << 10 | 0x300 | pp->nj2tris++); | 
| 531 | > | case 1: | 
| 532 | > | pp->j2tri[pp->nj2tris].v2j = vid[0]; | 
| 533 | > | pp->j2tri[pp->nj2tris].v3 = vid[1] & 0xff; | 
| 534 | > | pp->j2tri[pp->nj2tris].v1j = vid[2]; | 
| 535 | > | return(pn[1] << 10 | 0x300 | pp->nj2tris++); | 
| 536 | > | case 2: | 
| 537 | > | pp->j2tri[pp->nj2tris].v1j = vid[0]; | 
| 538 | > | pp->j2tri[pp->nj2tris].v2j = vid[1]; | 
| 539 | > | pp->j2tri[pp->nj2tris].v3 = vid[2] & 0xff; | 
| 540 | > | return(pn[2] << 10 | 0x300 | pp->nj2tris++); | 
| 541 | > | } | 
| 542 |  | nomem: | 
| 543 |  | error(SYSTEM, "out of memory in addmeshtri"); | 
| 544 |  | return(OVOID); | 
| 546 |  |  | 
| 547 |  |  | 
| 548 |  | char * | 
| 549 | < | checkmesh(mp)                           /* validate mesh data */ | 
| 493 | < | register MESH   *mp; | 
| 549 | > | checkmesh(MESH *mp)                     /* validate mesh data */ | 
| 550 |  | { | 
| 551 |  | static char     embuf[128]; | 
| 552 |  | int             nouvbounds = 1; | 
| 553 | < | register int    i; | 
| 553 | > | int             i, j; | 
| 554 |  | /* basic checks */ | 
| 555 |  | if (mp == NULL) | 
| 556 |  | return("NULL mesh pointer"); | 
| 572 |  | if (isempty(mp->mcube.cutree)) | 
| 573 |  | error(WARNING, "empty mesh octree"); | 
| 574 |  | } | 
| 575 | < | /* check scene data */ | 
| 575 | > | /* check patch data */ | 
| 576 |  | if (mp->ldflags & IO_SCENE) { | 
| 577 | + | MESHVERT        mv; | 
| 578 |  | if (!(mp->ldflags & IO_BOUNDS)) | 
| 579 |  | return("unbounded scene in mesh"); | 
| 580 |  | if (mp->mat0 < 0 || mp->mat0+mp->nmats > nobjects) | 
| 581 |  | return("bad mesh modifier range"); | 
| 582 | + | if (mp->nmats > 0)      /* allocate during preload_objs()! */ | 
| 583 | + | getmeshpseudo(mp, mp->mat0); | 
| 584 |  | for (i = mp->mat0+mp->nmats; i-- > mp->mat0; ) { | 
| 585 |  | int     otyp = objptr(i)->otype; | 
| 586 |  | if (!ismodifier(otyp)) { | 
| 593 |  | if (mp->npatches <= 0) | 
| 594 |  | error(WARNING, "no patches in mesh"); | 
| 595 |  | for (i = 0; i < mp->npatches; i++) { | 
| 596 | < | register MESHPATCH      *pp = &mp->patch[i]; | 
| 596 | > | MESHPATCH       *pp = &mp->patch[i]; | 
| 597 |  | if (pp->nverts <= 0) | 
| 598 |  | error(WARNING, "no vertices in patch"); | 
| 599 |  | else { | 
| 602 |  | if (nouvbounds && pp->uv != NULL) | 
| 603 |  | return("unreferenced uv coordinates"); | 
| 604 |  | } | 
| 605 | < | if (pp->ntris + pp->nj1tris + pp->nj2tris <= 0) | 
| 606 | < | error(WARNING, "no triangles in patch"); | 
| 607 | < | if (pp->ntris > 0 && pp->tri == NULL) | 
| 608 | < | return("missing patch triangle list"); | 
| 609 | < | if (pp->nj1tris > 0 && pp->j1tri == NULL) | 
| 610 | < | return("missing patch joiner triangle list"); | 
| 611 | < | if (pp->nj2tris > 0 && pp->j2tri == NULL) | 
| 612 | < | return("missing patch double-joiner list"); | 
| 605 | > | if (pp->ntris > 0) { | 
| 606 | > | struct PTri     *tp = pp->tri; | 
| 607 | > | if (tp == NULL) | 
| 608 | > | return("missing patch triangle list"); | 
| 609 | > | if (mp->nmats <= 0) | 
| 610 | > | j = -1; | 
| 611 | > | else if (pp->trimat == NULL) | 
| 612 | > | j = ((pp->solemat < 0) | (pp->solemat >= mp->nmats)) - 1; | 
| 613 | > | else | 
| 614 | > | for (j = pp->ntris; j--; ) | 
| 615 | > | if ((pp->trimat[j] < 0) | | 
| 616 | > | (pp->trimat[j] >= mp->nmats)) | 
| 617 | > | break; | 
| 618 | > | if (j >= 0) | 
| 619 | > | return("bad local triangle material"); | 
| 620 | > | for (j = pp->ntris; j--; tp++) | 
| 621 | > | if ((tp->v1 >= pp->nverts) | (tp->v2 >= pp->nverts) | | 
| 622 | > | (tp->v3 >= pp->nverts)) | 
| 623 | > | return("bad local triangle index"); | 
| 624 | > | } | 
| 625 | > | if (pp->nj1tris > 0) { | 
| 626 | > | struct PJoin1   *j1p = pp->j1tri; | 
| 627 | > | if (j1p == NULL) | 
| 628 | > | return("missing patch joiner triangle list"); | 
| 629 | > | for (j = pp->nj1tris; j--; j1p++) { | 
| 630 | > | if (mp->nmats > 0 && | 
| 631 | > | (j1p->mat < 0) | (j1p->mat >= mp->nmats)) | 
| 632 | > | return("bad j1 triangle material"); | 
| 633 | > | if (!getmeshvert(&mv, mp, j1p->v1j, MT_V)) | 
| 634 | > | return("bad j1 triangle joiner"); | 
| 635 | > | if ((j1p->v2 >= pp->nverts) | (j1p->v3 >= pp->nverts)) | 
| 636 | > | return("bad j1 triangle local index"); | 
| 637 | > | } | 
| 638 | > | } | 
| 639 | > | if (pp->nj2tris > 0) { | 
| 640 | > | struct PJoin2   *j2p = pp->j2tri; | 
| 641 | > | if (j2p == NULL) | 
| 642 | > | return("missing patch double-joiner list"); | 
| 643 | > | for (j = pp->nj2tris; j--; j2p++) { | 
| 644 | > | if (mp->nmats > 0 && | 
| 645 | > | (j2p->mat < 0) | (j2p->mat >= mp->nmats)) | 
| 646 | > | return("bad j2 triangle material"); | 
| 647 | > | if (!getmeshvert(&mv, mp, j2p->v1j, MT_V) | | 
| 648 | > | !getmeshvert(&mv, mp, j2p->v2j, MT_V)) | 
| 649 | > | return("bad j2 triangle joiner"); | 
| 650 | > | if (j2p->v3 >= pp->nverts) | 
| 651 | > | return("bad j2 triangle local index"); | 
| 652 | > | } | 
| 653 | > | } | 
| 654 |  | } | 
| 655 |  | } | 
| 656 | < | return(NULL);                   /* seems OK */ | 
| 656 | > | return(NULL);                   /* seems to be self-consistent */ | 
| 657 |  | } | 
| 658 |  |  | 
| 659 |  |  | 
| 660 |  | static void | 
| 661 | < | tallyoctree(ot, ecp, lcp, ocp)  /* tally octree size */ | 
| 662 | < | OCTREE  ot; | 
| 663 | < | int     *ecp, *lcp, *ocp; | 
| 661 | > | tallyoctree(                    /* tally octree size */ | 
| 662 | > | OCTREE  ot, | 
| 663 | > | int     *ecp, | 
| 664 | > | int     *lcp, | 
| 665 | > | int     *ocp | 
| 666 | > | ) | 
| 667 |  | { | 
| 668 |  | int     i; | 
| 669 |  |  | 
| 684 |  |  | 
| 685 |  |  | 
| 686 |  | void | 
| 687 | < | printmeshstats(ms, fp)          /* print out mesh statistics */ | 
| 688 | < | MESH    *ms; | 
| 689 | < | FILE    *fp; | 
| 687 | > | printmeshstats(                 /* print out mesh statistics */ | 
| 688 | > | MESH    *ms, | 
| 689 | > | FILE    *fp | 
| 690 | > | ) | 
| 691 |  | { | 
| 692 |  | int     lfcnt=0, lecnt=0, locnt=0; | 
| 693 |  | int     vcnt=0, ncnt=0, uvcnt=0; | 
| 697 |  |  | 
| 698 |  | tallyoctree(ms->mcube.cutree, &lecnt, &lfcnt, &locnt); | 
| 699 |  | for (i = 0; i < ms->npatches; i++) { | 
| 700 | < | register MESHPATCH      *pp = &ms->patch[i]; | 
| 700 | > | MESHPATCH       *pp = &ms->patch[i]; | 
| 701 |  | vcnt += pp->nverts; | 
| 702 |  | if (pp->norm != NULL) { | 
| 703 |  | for (j = pp->nverts; j--; ) | 
| 716 |  | t2cnt += pp->nj2tris; | 
| 717 |  | } | 
| 718 |  | fprintf(fp, "Mesh statistics:\n"); | 
| 719 | < | fprintf(fp, "\t%ld materials\n", ms->nmats); | 
| 719 | > | fprintf(fp, "\t%ld materials\n", (long)ms->nmats); | 
| 720 |  | fprintf(fp, "\t%d patches (%.2f MBytes)\n", ms->npatches, | 
| 721 |  | (ms->npatches*sizeof(MESHPATCH) + | 
| 722 |  | vcnt*3*sizeof(uint32) + | 
| 723 |  | nscnt*sizeof(int32) + | 
| 724 | < | uvscnt*2*sizeof(uint16) + | 
| 724 | > | uvscnt*2*sizeof(uint32) + | 
| 725 |  | tcnt*sizeof(struct PTri) + | 
| 726 |  | t1cnt*sizeof(struct PJoin1) + | 
| 727 |  | t2cnt*sizeof(struct PJoin2))/(1024.*1024.)); | 
| 739 |  |  | 
| 740 |  |  | 
| 741 |  | void | 
| 742 | < | freemesh(ms)                    /* free mesh data */ | 
| 639 | < | register MESH   *ms; | 
| 742 | > | freemesh(MESH *ms)              /* free mesh data */ | 
| 743 |  | { | 
| 744 |  | MESH    mhead; | 
| 745 |  | MESH    *msp; | 
| 767 |  | octfree(ms->mcube.cutree); | 
| 768 |  | lu_done(&ms->lut); | 
| 769 |  | if (ms->npatches > 0) { | 
| 770 | < | register MESHPATCH      *pp = ms->patch + ms->npatches; | 
| 770 | > | MESHPATCH       *pp = ms->patch + ms->npatches; | 
| 771 |  | while (pp-- > ms->patch) { | 
| 772 |  | if (pp->j2tri != NULL) | 
| 773 | < | free((void *)pp->j2tri); | 
| 773 | > | free(pp->j2tri); | 
| 774 |  | if (pp->j1tri != NULL) | 
| 775 | < | free((void *)pp->j1tri); | 
| 775 | > | free(pp->j1tri); | 
| 776 |  | if (pp->tri != NULL) | 
| 777 | < | free((void *)pp->tri); | 
| 777 | > | free(pp->tri); | 
| 778 |  | if (pp->uv != NULL) | 
| 779 | < | free((void *)pp->uv); | 
| 779 | > | free(pp->uv); | 
| 780 |  | if (pp->norm != NULL) | 
| 781 | < | free((void *)pp->norm); | 
| 781 | > | free(pp->norm); | 
| 782 |  | if (pp->xyz != NULL) | 
| 783 | < | free((void *)pp->xyz); | 
| 783 | > | free(pp->xyz); | 
| 784 | > | if (pp->trimat != NULL) | 
| 785 | > | free(pp->trimat); | 
| 786 |  | } | 
| 787 | < | free((void *)ms->patch); | 
| 787 | > | free(ms->patch); | 
| 788 |  | } | 
| 789 |  | if (ms->pseudo != NULL) | 
| 790 | < | free((void *)ms->pseudo); | 
| 791 | < | free((void *)ms); | 
| 790 | > | free(ms->pseudo); | 
| 791 | > | free(ms); | 
| 792 |  | } | 
| 793 |  |  | 
| 794 |  |  | 
| 795 |  | void | 
| 796 | < | freemeshinst(o)                 /* free mesh instance */ | 
| 692 | < | OBJREC  *o; | 
| 796 | > | freemeshinst(OBJREC *o)         /* free mesh instance */ | 
| 797 |  | { | 
| 798 |  | if (o->os == NULL) | 
| 799 |  | return; | 
| 800 |  | freemesh((*(MESHINST *)o->os).msh); | 
| 801 | < | free((void *)o->os); | 
| 801 | > | free(o->os); | 
| 802 |  | o->os = NULL; | 
| 803 |  | } |