home *** CD-ROM | disk | FTP | other *** search
/ Avalon - 3D Objects & Resources / Avalon.iso / frmtspcs / byuformt < prev    next >
Text File  |  1995-01-01  |  3KB  |  114 lines

  1. Ok this is the BYU format (well at least this is what I think is the
  2.     BYU format.)
  3.  
  4. Line 1 has the number of parts, number of vertices, number of polygons and
  5.     number of elements in the connectivity array.
  6.  
  7. Line 2 has the start polygon number and end polygon number for part 1
  8. Line 3 has the start polygon number and end polygon number for part 2
  9. .
  10. .
  11. .
  12.  
  13. Line 18 has the x y z coordinates for vertex 1 and vertex 2
  14. Line 19 has the x y z coordinates for vertex 3 and vertex 4
  15. .
  16. .
  17. .
  18. Line 12715 has the connectivity array for the first polygon
  19.     example:
  20.         1 2 3 -4
  21.     vertex 1 to vertex 2 to vertex 3 to vertex 4 and back to vertex 1
  22.  
  23.     a negative number show the last vertex of a polygon
  24.  
  25. -------------------------------------------------------------------------
  26. /* source to read in BYU format
  27.     written by Kalvin Quinkert kalvin@uswest.com
  28.     sometime between January 1992 and May 1992
  29. */
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32.  
  33. int     np,nj,npt,ncon; /* number of parts,vertices,polygons,connectivity*/
  34. int     npl[3][MAX_PARTS];/* start and end polygons for each part*/
  35. float   xpp[MAX_VERTICES];
  36. float   ypp[MAX_VERTICES];
  37. float   zpp[MAX_VERTICES];
  38. int     ivq[MAX_VERTICES];/*connectivity array*/
  39.  
  40.  
  41. rwmovi(filename)
  42.     char *filename;
  43. {
  44.     readasc(filename);
  45. }
  46.  
  47. readasc(filename)
  48.     char *filename;
  49. {
  50.     FILE *fp;
  51.     int  i;
  52.  
  53.     if(np>0)return 1;
  54.     printf("opening %s\n",filename);
  55.     if(!(fp=fopen(filename,"r")))
  56.     {
  57.         fprintf(stderr,"cannot open %s\n",filename);
  58.         exit(1);
  59.     }
  60.  
  61.     fscanf(fp,"%d%d%d%d\n",&np,&nj,&npt,&ncon);
  62.     for(i=0;i<np;i++)
  63.     {
  64.         fscanf(fp,"%d %d\n",&npl[1][i],&npl[2][i]);
  65.     }
  66.     for(i=0;i<nj;i+=2)
  67.     {
  68.     printf("vertex %d\n",i);
  69.         if(i+1<nj)
  70.         {
  71.             fscanf(fp,"%f %f %f %f %f %f\n",&xpp[i],&ypp[i],&zpp[i],
  72.                                         &xpp[i+1],&ypp[i+1],&zpp[i+1]);
  73.         }
  74.         else
  75.         {
  76.             fscanf(fp,"%f %f %f\n",&xpp[i],&ypp[i],&zpp[i]);
  77.         }
  78.     }
  79.     for(i=0;i<ncon;i++)
  80.     {
  81.         printf("connectivity %d\n",i);
  82.         ivq[i] = readint(fp);
  83.     }
  84. }
  85.  
  86. int readint(fp)
  87.     FILE *fp;
  88. {
  89.     int value=0;
  90.     int sign=1;
  91.     char ch;
  92.  
  93.     while(!feof(fp))
  94.     {
  95.         while(1)
  96.         {   ch=fgetc(fp);
  97.             if((ch=='+')||(ch=='-')||(ch>='0'&&ch<='9')) break;
  98.         }
  99.         while(1)
  100.         {
  101.             if(ch=='+')
  102.                 sign=1;
  103.             else if(ch=='-')
  104.                 sign=-1;
  105.             else if(ch>='0'&&ch<='9')
  106.                 value = (value*10)+(ch-'0');
  107.                 return(value);
  108.             }
  109.             ch=fgetc(fp);
  110.         }
  111.     }
  112. }
  113.  
  114.