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

Comparing ray/src/cv/obj2rad.c (file contents):
Revision 2.13 by greg, Wed Jun 15 15:07:08 1994 UTC vs.
Revision 2.17 by greg, Sat Feb 22 02:07:23 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Convert a Wavefront .obj file to Radiance format.
6   *
# Line 17 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include "trans.h"
16  
17 + #include "tmesh.h"
18 +
19   #include <ctype.h>
20  
22 #define TCALNAME        "tmesh.cal"     /* triangle interp. file */
21   #define PATNAME         "M-pat"         /* mesh pattern name (reused) */
22   #define TEXNAME         "M-nor"         /* mesh texture name (reused) */
23   #define DEFOBJ          "unnamed"       /* default object name */
24   #define DEFMAT          "white"         /* default material name */
25  
28 #define  ABS(x)         ((x)>=0 ? (x) : -(x))
29
26   #define pvect(v)        printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2])
27  
28   FVECT   *vlist;                 /* our vertex list */
# Line 36 | Line 32 | int    nvns;
32   FLOAT   (*vtlist)[2];           /* map vertex list */
33   int     nvts;
34  
39 typedef struct {
40        int     ax;             /* major axis */
41        FLOAT   tm[2][3];       /* transformation */
42 } BARYCCM;
43
35   typedef int     VNDX[3];        /* vertex index (point,map,normal) */
36  
37   #define CHUNKSIZ        256     /* vertex allocation chunk size */
# Line 564 | Line 555 | char   *v1, *v2, *v3;
555          char    *mod;
556          VNDX    v1i, v2i, v3i;
557          BARYCCM bvecs;
558 <        FVECT   bcoor[3];
558 >        FLOAT   bcoor[3][3];
559          int     texOK, patOK;
560          register int    i;
561  
# Line 574 | Line 565 | char   *v1, *v2, *v3;
565          if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3))
566                  return(0);
567                                          /* compute barycentric coordinates */
568 <        texOK = !flatten && (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0);
568 >        if (!flatten && v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0)
569 >                switch (flat_tri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]],
570 >                        vnlist[v1i[2]], vnlist[v2i[2]], vnlist[v3i[2]])) {
571 >                case DEGEN:             /* zero area */
572 >                        return(-1);
573 >                case RVFLAT:            /* reversed normals, but flat */
574 >                case ISFLAT:            /* smoothing unnecessary */
575 >                        texOK = 0;
576 >                        break;
577 >                case RVBENT:            /* reversed normals with smoothing */
578 >                case ISBENT:            /* proper smoothing */
579 >                        texOK = 1;
580 >                        break;
581 >                }
582 >        else
583 >                texOK = 0;
584   #ifdef TEXMAPS
585          patOK = mapname[0] && (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0);
586   #else
# Line 623 | Line 629 | char   *v1, *v2, *v3;
629   }
630  
631  
626 int
627 comp_baryc(bcm, v1, v2, v3)             /* compute barycentric vectors */
628 register BARYCCM        *bcm;
629 FLOAT   *v1, *v2, *v3;
630 {
631        FLOAT   *vt;
632        FVECT   va, vab, vcb;
633        double  d;
634        int     ax0, ax1;
635        register int    i, j;
636                                        /* compute major axis */
637        for (i = 0; i < 3; i++) {
638                vab[i] = v1[i] - v2[i];
639                vcb[i] = v3[i] - v2[i];
640        }
641        fcross(va, vab, vcb);
642        bcm->ax = ABS(va[0]) > ABS(va[1]) ? 0 : 1;
643        bcm->ax = ABS(va[bcm->ax]) > ABS(va[2]) ? bcm->ax : 2;
644        ax0 = (bcm->ax + 1) % 3;
645        ax1 = (bcm->ax + 2) % 3;
646        for (j = 0; j < 2; j++) {
647                vab[0] = v1[ax0] - v2[ax0];
648                vcb[0] = v3[ax0] - v2[ax0];
649                vab[1] = v1[ax1] - v2[ax1];
650                vcb[1] = v3[ax1] - v2[ax1];
651                d = vcb[0]*vcb[0] + vcb[1]*vcb[1];
652                if (d <= FTINY)
653                        return(-1);
654                d = (vcb[0]*vab[0]+vcb[1]*vab[1])/d;
655                va[0] = vab[0] - vcb[0]*d;
656                va[1] = vab[1] - vcb[1]*d;
657                d = va[0]*va[0] + va[1]*va[1];
658                if (d <= FTINY)
659                        return(-1);
660                bcm->tm[j][0] = va[0] /= d;
661                bcm->tm[j][1] = va[1] /= d;
662                bcm->tm[j][2] = -(v2[ax0]*va[0]+v2[ax1]*va[1]);
663                                        /* rotate vertices */
664                vt = v1;
665                v1 = v2;
666                v2 = v3;
667                v3 = vt;
668        }
669        return(0);
670 }
671
672
673 put_baryc(bcm, com, n)                  /* put barycentric coord. vectors */
674 register BARYCCM        *bcm;
675 register FVECT  com[];
676 int     n;
677 {
678        double  a, b;
679        register int    i, j;
680
681        printf("%d\t%d\n", 1+3*n, bcm->ax);
682        for (i = 0; i < n; i++) {
683                a = com[i][0] - com[i][2];
684                b = com[i][1] - com[i][2];
685                printf("%14.8f %14.8f %14.8f\n",
686                        bcm->tm[0][0]*a + bcm->tm[1][0]*b,
687                        bcm->tm[0][1]*a + bcm->tm[1][1]*b,
688                        bcm->tm[0][2]*a + bcm->tm[1][2]*b + com[i][2]);
689        }
690 }
691
692
632   freeverts()                     /* free all vertices */
633   {
634          if (nvs) {
635 <                free((char *)vlist);
635 >                free((void *)vlist);
636                  nvs = 0;
637          }
638          if (nvts) {
639 <                free((char *)vtlist);
639 >                free((void *)vtlist);
640                  nvts = 0;
641          }
642          if (nvns) {
643 <                free((char *)vnlist);
643 >                free((void *)vnlist);
644                  nvns = 0;
645          }
646   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines