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

Comparing ray/src/common/objutil.c (file contents):
Revision 2.4 by greg, Fri May 1 18:55:34 2020 UTC vs.
Revision 2.10 by greg, Fri Dec 18 00:15:47 2020 UTC

# Line 19 | Line 19 | static const char RCSid[] = "$Id$";
19   int
20   findName(const char *nm, const char **nmlist, int n)
21   {
22 <        register int    i;
22 >        int    i;
23          
24          for (i = n; i-- > 0; )
25                  if (!strcmp(nmlist[i], nm))
# Line 322 | Line 322 | replace_vertex(Scene *sc, int prev, int repl, double e
322                          goto linkerr;
323                  /* XXX doesn't allow for multiple references to prev in face */
324                  f->v[j].vid = repl;     /* replace vertex itself */
325 <                if (faceArea(sc, f, NULL) <= FTINY)
325 >                if (faceArea(sc, f, NULL) <= FTINY*FTINY)
326                          f->flags |= FACE_DEGENERATE;
327                  if (f->v[j].tid >= 0)   /* replace texture if appropriate */
328                          for (i = 0; repl_tex[i] >= 0; i++) {
# Line 460 | Line 460 | findDuplicateFaces(Scene *sc)
460                          ++nfound;
461                  }
462          }
463 +        if (verbose)
464 +                fprintf(stderr, "Found %d duplicate faces\n", nfound);
465          return(nfound);
466   }
467  
# Line 547 | Line 549 | addComment(Scene *sc, const char *comment)
549          sc->descr[sc->ndescr++] = savqstr((char *)comment);
550   }
551  
552 + /* Find index for comment containing the given string (starting from n) */
553 + int
554 + findComment(Scene *sc, const char *match, int n)
555 + {
556 +        if (n >= sc->ndescr)
557 +                return(-1);
558 +        n *= (n > 0);
559 +        while (n < sc->ndescr)
560 +                if (strstr(sc->descr[n], match) != NULL)
561 +                        return(n);
562 +        return(-1);
563 + }
564 +
565   /* Clear comments */
566   void
567   clearComments(Scene *sc)
# Line 599 | Line 614 | newScene(void)
614          return(sc);
615   }
616  
617 < /* Add a vertex to our scene */
617 > /* Add a vertex to a scene */
618   int
619   addVertex(Scene *sc, double x, double y, double z)
620   {
# Line 611 | Line 626 | addVertex(Scene *sc, double x, double y, double z)
626          return(sc->nverts++);
627   }
628  
629 < /* Add a texture coordinate to our scene */
629 > /* Add a texture coordinate to a scene */
630   int
631   addTexture(Scene *sc, double u, double v)
632   {
# Line 621 | Line 636 | addTexture(Scene *sc, double u, double v)
636          return(sc->ntex++);
637   }
638  
639 < /* Add a surface normal to our scene */
639 > /* Add a surface normal to a scene */
640   int
641   addNormal(Scene *sc, double xn, double yn, double zn)
642   {
# Line 657 | Line 672 | setMaterial(Scene *sc, const char *nm)
672          sc->matname[sc->lastmat=sc->nmats++] = savqstr((char *)nm);
673   }
674  
675 + /* Add new face to a scene */
676 + Face *
677 + addFace(Scene *sc, VNDX vid[], int nv)
678 + {
679 +        Face    *f;
680 +        int     i;
681 +        
682 +        if (nv < 3)
683 +                return(NULL);
684 +        f = (Face *)emalloc(sizeof(Face)+sizeof(VertEnt)*(nv-3));
685 +        f->flags = 0;
686 +        f->nv = nv;
687 +        f->grp = sc->lastgrp;
688 +        f->mat = sc->lastmat;
689 +        for (i = 0; i < nv; i++) {              /* add each vertex */
690 +                int     j;
691 +                f->v[i].vid = vid[i][0];
692 +                f->v[i].tid = vid[i][1];
693 +                f->v[i].nid = vid[i][2];
694 +                f->v[i].fnext = NULL;
695 +                for (j = i; j-- > 0; )
696 +                        if (f->v[j].vid == vid[i][0])
697 +                                break;
698 +                if (j < 0) {                    /* first occurrence? */
699 +                        f->v[i].fnext = sc->vert[vid[i][0]].vflist;
700 +                        sc->vert[vid[i][0]].vflist = f;
701 +                } else if (nv == 3)             /* degenerate triangle? */
702 +                        f->flags |= FACE_DEGENERATE;
703 +        }
704 +        f->next = sc->flist;                    /* push onto face list */
705 +        sc->flist = f;
706 +        sc->nfaces++;
707 +                                                /* check face area */
708 +        if (!(f->flags & FACE_DEGENERATE) && faceArea(sc, f, NULL) <= FTINY*FTINY)
709 +                f->flags |= FACE_DEGENERATE;
710 +        return(f);
711 + }
712 +
713   /* Duplicate a scene */
714   Scene *
715   dupScene(const Scene *osc)
# Line 722 | Line 775 | dupScene(const Scene *osc)
775          return(sc);
776   }
777  
778 + #define MAXAC   100
779 +
780   /* Transform entire scene */
781   int
782   xfScene(Scene *sc, int xac, char *xav[])
783   {
784 +        char    comm[24+MAXAC*8];
785 +        char    *cp;
786          XF      myxf;
787          FVECT   vec;
788          int     i;
# Line 748 | Line 805 | xfScene(Scene *sc, int xac, char *xav[])
805                  vec[0] /= myxf.sca; vec[1] /= myxf.sca; vec[2] /= myxf.sca;
806                  VCOPY(sc->norm[i], vec);
807          }
808 +                                        /* add comment */
809 +        cp = strcpy(comm, "Transformed by:");
810 +        for (i = 0; i < xac; i++) {
811 +                while (*cp) cp++;
812 +                *cp++ = ' ';
813 +                strcpy(cp, xav[i]);
814 +        }
815 +        addComment(sc, comm);
816          return(xac);                    /* all done */
817   }
818  
819   /* Ditto, using transform string rather than pre-parsed words */
755 #define MAXAC   100
820   int
821   xfmScene(Scene *sc, const char *xfm)
822   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines