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.3 by greg, Thu Apr 2 22:14:01 2020 UTC vs.
Revision 2.8 by greg, Tue Jun 23 19:29:40 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 547 | Line 547 | addComment(Scene *sc, const char *comment)
547          sc->descr[sc->ndescr++] = savqstr((char *)comment);
548   }
549  
550 + /* Find index for comment containing the given string (starting from n) */
551 + int
552 + findComment(Scene *sc, const char *match, int n)
553 + {
554 +        if (n >= sc->ndescr)
555 +                return(-1);
556 +        n *= (n > 0);
557 +        while (n < sc->ndescr)
558 +                if (strcasestr(sc->descr[n], match) != NULL)
559 +                        return(n);
560 +        return(-1);
561 + }
562 +
563   /* Clear comments */
564   void
565   clearComments(Scene *sc)
# Line 599 | Line 612 | newScene(void)
612          return(sc);
613   }
614  
615 + /* Add a vertex to a scene */
616 + int
617 + addVertex(Scene *sc, double x, double y, double z)
618 + {
619 +        sc->vert = chunk_alloc(Vertex, sc->vert, sc->nverts);
620 +        sc->vert[sc->nverts].p[0] = x;
621 +        sc->vert[sc->nverts].p[1] = y;
622 +        sc->vert[sc->nverts].p[2] = z;
623 +        sc->vert[sc->nverts].vflist = NULL;
624 +        return(sc->nverts++);
625 + }
626 +
627 + /* Add a texture coordinate to a scene */
628 + int
629 + addTexture(Scene *sc, double u, double v)
630 + {
631 +        sc->tex = chunk_alloc(TexCoord, sc->tex, sc->ntex);
632 +        sc->tex[sc->ntex].u = u;
633 +        sc->tex[sc->ntex].v = v;
634 +        return(sc->ntex++);
635 + }
636 +
637 + /* Add a surface normal to a scene */
638 + int
639 + addNormal(Scene *sc, double xn, double yn, double zn)
640 + {
641 +        FVECT   nrm;
642 +
643 +        nrm[0] = xn; nrm[1] = yn; nrm[2] = zn;
644 +        if (normalize(nrm) == .0)
645 +                return(-1);
646 +        sc->norm = chunk_alloc(Normal, sc->norm, sc->nnorms);
647 +        VCOPY(sc->norm[sc->nnorms], nrm);
648 +        return(sc->nnorms++);
649 + }
650 +
651 + /* Set current (last) group */
652 + void
653 + setGroup(Scene *sc, const char *nm)
654 + {
655 +        sc->lastgrp = findName(nm, (const char **)sc->grpname, sc->ngrps);
656 +        if (sc->lastgrp >= 0)
657 +                return;
658 +        sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps);
659 +        sc->grpname[sc->lastgrp=sc->ngrps++] = savqstr((char *)nm);
660 + }
661 +
662 + /* Set current (last) material */
663 + void
664 + setMaterial(Scene *sc, const char *nm)
665 + {
666 +        sc->lastmat = findName(nm, (const char **)sc->matname, sc->nmats);
667 +        if (sc->lastmat >= 0)
668 +                return;
669 +        sc->matname = chunk_alloc(char *, sc->matname, sc->nmats);
670 +        sc->matname[sc->lastmat=sc->nmats++] = savqstr((char *)nm);
671 + }
672 +
673 + /* Add new face to a scene */
674 + Face *
675 + addFace(Scene *sc, VNDX vid[], int nv)
676 + {
677 +        Face    *f;
678 +        int     i;
679 +        
680 +        if (nv < 3)
681 +                return(NULL);
682 +        f = (Face *)emalloc(sizeof(Face)+sizeof(VertEnt)*(nv-3));
683 +        f->flags = 0;
684 +        f->nv = nv;
685 +        f->grp = sc->lastgrp;
686 +        f->mat = sc->lastmat;
687 +        for (i = 0; i < nv; i++) {              /* add each vertex */
688 +                int     j;
689 +                f->v[i].vid = vid[i][0];
690 +                f->v[i].tid = vid[i][1];
691 +                f->v[i].nid = vid[i][2];
692 +                f->v[i].fnext = NULL;
693 +                for (j = i; j-- > 0; )
694 +                        if (f->v[j].vid == vid[i][0])
695 +                                break;
696 +                if (j < 0) {                    /* first occurrence? */
697 +                        f->v[i].fnext = sc->vert[vid[i][0]].vflist;
698 +                        sc->vert[vid[i][0]].vflist = f;
699 +                } else if (nv == 3)             /* degenerate triangle? */
700 +                        f->flags |= FACE_DEGENERATE;
701 +        }
702 +        f->next = sc->flist;                    /* push onto face list */
703 +        sc->flist = f;
704 +        sc->nfaces++;
705 +                                                /* check face area */
706 +        if (!(f->flags & FACE_DEGENERATE) && faceArea(sc, f, NULL) <= FTINY*FTINY)
707 +                f->flags |= FACE_DEGENERATE;
708 +        return(f);
709 + }
710 +
711   /* Duplicate a scene */
712   Scene *
713   dupScene(const Scene *osc)
# Line 664 | Line 773 | dupScene(const Scene *osc)
773          return(sc);
774   }
775  
776 + #define MAXAC   100
777 +
778   /* Transform entire scene */
779   int
780   xfScene(Scene *sc, int xac, char *xav[])
781   {
782 +        char    comm[24+MAXAC*8];
783 +        char    *cp;
784          XF      myxf;
785          FVECT   vec;
786          int     i;
# Line 690 | Line 803 | xfScene(Scene *sc, int xac, char *xav[])
803                  vec[0] /= myxf.sca; vec[1] /= myxf.sca; vec[2] /= myxf.sca;
804                  VCOPY(sc->norm[i], vec);
805          }
806 +                                        /* add comment */
807 +        cp = strcpy(comm, "Transformed by:");
808 +        for (i = 0; i < xac; i++) {
809 +                while (*cp) cp++;
810 +                *cp++ = ' ';
811 +                strcpy(cp, xav[i]);
812 +        }
813 +        addComment(sc, comm);
814          return(xac);                    /* all done */
815   }
816  
817   /* Ditto, using transform string rather than pre-parsed words */
697 #define MAXAC   100
818   int
819   xfmScene(Scene *sc, const char *xfm)
820   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines