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.4 by greg, Wed Apr 13 15:16:49 1994 UTC vs.
Revision 2.5 by greg, Wed Apr 13 17:24:24 1994 UTC

# Line 7 | Line 7 | static char SCCSid[] = "$SunId$ LBL";
7   /*
8   * Convert a Wavefront .obj file to Radiance format.
9   *
10 < * Currently, we support only polygonal geometry, and faces
11 < * must be either quads or triangles for smoothing to work.
10 > * Currently, we support only polygonal geometry.  Non-planar
11 > * faces are broken rather haphazardly into triangles.
12   * Also, texture map indices only work for triangles, though
13   * I'm not sure they work correctly.
14   */
# Line 465 | Line 465 | register char  *vs;
465   }
466  
467  
468 < putface(ac, av)                         /* put out an N-sided polygon */
468 > nonplanar(ac, av)                       /* are vertices are non-planar? */
469   register int    ac;
470   register char   **av;
471   {
472          VNDX    vi;
473 +        FLOAT   *p0, *p1;
474 +        FVECT   v1, v2, nsum, newn;
475 +        double  d;
476 +        register int    i;
477 +
478 +        if (!cvtndx(vi, av[0]))
479 +                return(0);
480 +        if (vi[2] >= 0)
481 +                return(1);              /* has interpolated normals */
482 +        if (ac < 4)
483 +                return(0);              /* it's a triangle! */
484 +                                        /* set up */
485 +        p0 = vlist[vi[0]];
486 +        if (!cvtndx(vi, av[1]))
487 +                return(0);              /* error gets caught later */
488 +        nsum[0] = nsum[1] = nsum[2] = 0.;
489 +        p1 = vlist[vi[0]];
490 +        fvsum(v2, p1, p0, -1.0);
491 +        for (i = 2; i < ac; i++) {
492 +                VCOPY(v1, v2);
493 +                if (!cvtndx(vi, av[i]))
494 +                        return(0);
495 +                p1 = vlist[vi[0]];
496 +                fvsum(v2, p1, p0, -1.0);
497 +                fcross(newn, v1, v2);
498 +                if (normalize(newn) == 0.0) {
499 +                        if (i < 3)
500 +                                return(1);      /* can't deal with this */
501 +                        fvsum(nsum, nsum, nsum, 1./(i-2));
502 +                        continue;
503 +                }
504 +                d = fdot(newn,nsum);
505 +                if (d >= 0) {
506 +                        if (d < (1.0-FTINY)*(i-2))
507 +                                return(1);
508 +                        fvsum(nsum, nsum, newn, 1.0);
509 +                } else {
510 +                        if (d > -(1.0-FTINY)*(i-2))
511 +                                return(1);
512 +                        fvsum(nsum, nsum, newn, -1.0);
513 +                }
514 +        }
515 +        return(0);
516 + }
517 +
518 +
519 + putface(ac, av)                         /* put out an N-sided polygon */
520 + int     ac;
521 + register char   **av;
522 + {
523 +        VNDX    vi;
524          char    *mod;
525 +        register int    i;
526  
527 +        if (nonplanar(ac, av)) {        /* break into quads and triangles */
528 +                while (ac > 3) {
529 +                        if (!putquad(av[0], av[1], av[2], av[3]))
530 +                                return(0);
531 +                        ac -= 2;                /* remove two vertices */
532 +                        for (i = 1; i < ac; i++)
533 +                                av[i] = av[i+2];
534 +                }
535 +                if (ac == 3 && !puttri(av[0], av[1], av[2]))
536 +                        return(0);
537 +                return(1);
538 +        }
539          if ((mod = getmtl()) == NULL)
540                  return(-1);
541          printf("\n%s polygon %s.%d\n", mod, getonm(), faceno);
542          printf("0\n0\n%d\n", 3*ac);
543 <        while (ac--) {
544 <                if (!cvtndx(vi, *av++))
543 >        for (i = 0; i < ac; i++) {
544 >                if (!cvtndx(vi, av[i]))
545                          return(0);
546                  pvect(vlist[vi[0]]);
547          }
# Line 627 | Line 691 | char  *p0, *p1, *p3, *p2;              /* names correspond to bina
691          axis = norminterp(norm, p0i, p1i, p2i, p3i);
692  
693                                          /* put out quadrilateral? */
694 <        if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) {
694 >        if (ok1 & ok2 && fabs(fdot(vc1,vc2)) >= 1.0-FTINY) {
695                  printf("\n%s ", mod);
696                  if (axis != -1) {
697                          printf("texfunc %s\n", TEXNAME);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines