| 86 |
|
ms->nref++; /* increase reference count */ |
| 87 |
|
break; |
| 88 |
|
} |
| 89 |
< |
if (ms == NULL) { /* load first time */ |
| 89 |
> |
if (ms == NULL) { /* new mesh entry? */ |
| 90 |
|
ms = (MESH *)calloc(1, sizeof(MESH)); |
| 91 |
|
if (ms == NULL) |
| 92 |
|
error(SYSTEM, "out of memory in getmesh"); |
| 96 |
|
ms->next = mlist; |
| 97 |
|
mlist = ms; |
| 98 |
|
} |
| 99 |
+ |
if (!(flags &= ~ms->ldflags)) /* nothing to load? */ |
| 100 |
+ |
return(ms); |
| 101 |
|
if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) { |
| 102 |
|
sprintf(errmsg, "cannot find mesh file \"%s\"", mname); |
| 103 |
|
error(SYSTEM, errmsg); |
| 104 |
|
} |
| 105 |
< |
flags &= ~ms->ldflags; |
| 104 |
< |
if (flags) |
| 105 |
< |
readmesh(ms, pathname, flags); |
| 105 |
> |
readmesh(ms, pathname, flags); |
| 106 |
|
return(ms); |
| 107 |
|
} |
| 108 |
|
|
| 550 |
|
{ |
| 551 |
|
static char embuf[128]; |
| 552 |
|
int nouvbounds = 1; |
| 553 |
< |
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) |
| 602 |
|
if (nouvbounds && pp->uv != NULL) |
| 603 |
|
return("unreferenced uv coordinates"); |
| 604 |
|
} |
| 605 |
< |
if (pp->ntris > 0 && pp->tri == NULL) |
| 606 |
< |
return("missing patch triangle list"); |
| 607 |
< |
if (pp->nj1tris > 0 && pp->j1tri == NULL) |
| 608 |
< |
return("missing patch joiner triangle list"); |
| 609 |
< |
if (pp->nj2tris > 0 && pp->j2tri == NULL) |
| 610 |
< |
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 |
|
|