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.37 by greg, Thu Dec 12 23:04:31 2024 UTC

# Line 72 | Line 72 | cvcmp(const char *vv1, const char *vv2)                /* compare en
72  
73  
74   MESH *
75 < getmesh(                                /* get new mesh data reference */
75 > getmesh(                                /* get mesh data reference */
76          char    *mname,
77          int     flags
78   )
# Line 82 | Line 82 | getmesh(                               /* get new mesh data reference */
82  
83          flags &= IO_LEGAL;
84          for (ms = mlist; ms != NULL; ms = ms->next)
85 <                if (!strcmp(mname, ms->name)) {
86 <                        ms->nref++;     /* increase reference count */
85 >                if (!strcmp(mname, ms->name))
86                          break;
87 <                }
89 <        if (ms == NULL) {               /* load first time */
87 >        if (ms == NULL) {               /* new mesh entry? */
88                  ms = (MESH *)calloc(1, sizeof(MESH));
89                  if (ms == NULL)
90                          error(SYSTEM, "out of memory in getmesh");
91                  ms->name = savestr(mname);
94                ms->nref = 1;
92                  ms->mcube.cutree = EMPTY;
93                  ms->next = mlist;
94                  mlist = ms;
95          }
96 +        ms->nref++;                     /* bump reference count */
97 +        if (!(flags &= ~ms->ldflags))   /* nothing to load? */
98 +                return(ms);
99          if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) {
100                  sprintf(errmsg, "cannot find mesh file \"%s\"", mname);
101                  error(SYSTEM, errmsg);
102          }
103 <        flags &= ~ms->ldflags;
104 <        if (flags)
105 <                readmesh(ms, pathname, flags);
103 >        readmesh(ms, pathname, flags);
104          return(ms);
105   }
106  
# Line 550 | Line 548 | checkmesh(MESH *mp)                    /* validate mesh data */
548   {
549          static char     embuf[128];
550          int             nouvbounds = 1;
551 <        int             i;
551 >        int             i, j;
552                                          /* basic checks */
553          if (mp == NULL)
554                  return("NULL mesh pointer");
# Line 572 | Line 570 | checkmesh(MESH *mp)                    /* validate mesh data */
570                  if (isempty(mp->mcube.cutree))
571                          error(WARNING, "empty mesh octree");
572          }
573 <                                        /* check scene data */
573 >                                        /* check patch data */
574          if (mp->ldflags & IO_SCENE) {
575 +                MESHVERT        mv;
576                  if (!(mp->ldflags & IO_BOUNDS))
577                          return("unbounded scene in mesh");
578                  if (mp->mat0 < 0 || mp->mat0+mp->nmats > nobjects)
# Line 601 | Line 600 | checkmesh(MESH *mp)                    /* validate mesh data */
600                                  if (nouvbounds && pp->uv != NULL)
601                                          return("unreferenced uv coordinates");
602                          }
603 <                        if (pp->ntris > 0 && pp->tri == NULL)
604 <                                return("missing patch triangle list");
605 <                        if (pp->nj1tris > 0 && pp->j1tri == NULL)
606 <                                return("missing patch joiner triangle list");
607 <                        if (pp->nj2tris > 0 && pp->j2tri == NULL)
608 <                                return("missing patch double-joiner list");
603 >                        if (pp->ntris > 0) {
604 >                                struct PTri     *tp = pp->tri;
605 >                                if (tp == NULL)
606 >                                        return("missing patch triangle list");
607 >                                if (mp->nmats <= 0)
608 >                                        j = -1;
609 >                                else if (pp->trimat == NULL)
610 >                                        j = ((pp->solemat < 0) | (pp->solemat >= mp->nmats)) - 1;
611 >                                else
612 >                                        for (j = pp->ntris; j--; )
613 >                                                if ((pp->trimat[j] < 0) |
614 >                                                                (pp->trimat[j] >= mp->nmats))
615 >                                                        break;
616 >                                if (j >= 0)
617 >                                        return("bad local triangle material");
618 >                                for (j = pp->ntris; j--; tp++)
619 >                                        if ((tp->v1 >= pp->nverts) | (tp->v2 >= pp->nverts) |
620 >                                                        (tp->v3 >= pp->nverts))
621 >                                                return("bad local triangle index");
622 >                        }
623 >                        if (pp->nj1tris > 0) {
624 >                                struct PJoin1   *j1p = pp->j1tri;
625 >                                if (j1p == NULL)
626 >                                        return("missing patch joiner triangle list");
627 >                                for (j = pp->nj1tris; j--; j1p++) {
628 >                                        if (mp->nmats > 0 &&
629 >                                                        (j1p->mat < 0) | (j1p->mat >= mp->nmats))
630 >                                                return("bad j1 triangle material");
631 >                                        if (!getmeshvert(&mv, mp, j1p->v1j, MT_V))
632 >                                                return("bad j1 triangle joiner");
633 >                                        if ((j1p->v2 >= pp->nverts) | (j1p->v3 >= pp->nverts))
634 >                                                return("bad j1 triangle local index");
635 >                                }
636 >                        }
637 >                        if (pp->nj2tris > 0) {
638 >                                struct PJoin2   *j2p = pp->j2tri;
639 >                                if (j2p == NULL)
640 >                                        return("missing patch double-joiner list");
641 >                                for (j = pp->nj2tris; j--; j2p++) {
642 >                                        if (mp->nmats > 0 &&
643 >                                                        (j2p->mat < 0) | (j2p->mat >= mp->nmats))
644 >                                                return("bad j2 triangle material");
645 >                                        if (!getmeshvert(&mv, mp, j2p->v1j, MT_V) |
646 >                                                        !getmeshvert(&mv, mp, j2p->v2j, MT_V))
647 >                                                return("bad j2 triangle joiner");
648 >                                        if (j2p->v3 >= pp->nverts)
649 >                                                return("bad j2 triangle local index");
650 >                                }
651 >                        }
652                  }
653          }
654 <        return(NULL);                   /* seems OK */
654 >        return(NULL);                   /* seems to be self-consistent */
655   }
656  
657  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines