509 |
|
} |
510 |
|
/* double link */ |
511 |
|
pp = &mp->patch[pn[i=0]]; |
512 |
< |
if (pp->nj2tris >= 256) |
512 |
> |
if (mp->patch[pn[1]].nj2tris < pp->nj2tris) |
513 |
|
pp = &mp->patch[pn[i=1]]; |
514 |
< |
if (pp->nj2tris >= 256) |
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"); |
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) |
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)) { |
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 |
|
|