ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/mesh.c
(Generate patch)

Comparing ray/src/common/mesh.c (file contents):
Revision 2.34 by greg, Tue Jul 14 23:13:50 2020 UTC vs.
Revision 2.35 by greg, Thu Jun 10 00:27:25 2021 UTC

# Line 550 | Line 550 | checkmesh(MESH *mp)                    /* validate mesh data */
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");
# Line 572 | Line 572 | checkmesh(MESH *mp)                    /* validate mesh data */
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)
# Line 601 | Line 602 | checkmesh(MESH *mp)                    /* validate mesh data */
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines