Movie BYU Format

Original by Ken Chin-Purcell
Editied by Paul Bourke
June 1987


File Format

The Movie BYU format is an ascii file format for unstructured collections of polygons. Integers are written using a FORTRAN I/O format of 10I8. Floating point numbers are written using a FORTRAN I/O format of 6E12.5.

BYU geometry is described using verticies, connectivity, and parts. A vertex is a point location, and is specified by x, y and z coordinates. The order that the verticies appear in the file determines vertex indecies, with the first vertex being number one, the next vertex number two, and so forth. A polygon is specified as a list of verticies. In the file format the last vertex index for each polygon is negated. A part is composed of a consecutive set of polygons, such as polygons 121 thru 233.

The geometry file has four sections. The first section is one line long, and specifies array dimensions. The second section describes the part boundaries. The third section contains x-y-z coordinates for all of the verticies. The fourth section is the connectivity array, a list of vertex indicies that describe the polygons.

The first section contains four integers in the following order: the number of parts, the number vertecies, the number of polygons, and the number of entries in the connectivity array.

The next section contains two integers for every part: the starting polygon number and the ending polygon number.

The third section lists three floating point numbers for every vertex: the x, y and z coordinates.

The last section is a list of integers describing connectivity. For each polygon the vertex numbers are listed, with the last vertex negated.

The scalar file is simply a list of floating points numbers, one per vertex.


Example

Geometry file for a unit cube:

1       8       6      24
1       6
0.00000e+00 0.00000e+00 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
1.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00 1.00000e+00 0.00000e+00
0.00000e+00 0.00000e+00 1.00000e+00 1.00000e+00 0.00000e+00 1.00000e+00
1.00000e+00 1.00000e+00 1.00000e+00 0.00000e+00 1.00000e+00 1.00000e+00
1       4       3      -2       5       6       7      -8       1       2
6      -5       2       3       7      -6       3       4       8      -7
4       1       5      -8

A sample scalar file for this cube:

0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00
6.00000e+00 7.00000e+00

Source to parse BYU files

/* 
   source to read in BYU format
   written by Kalvin Quinkert kalvin@uswest.com
   sometime between January 1992 and May 1992
*/

int   np,nj,npt,ncon;    /* number of parts,vertices,polygons,connectivity */
int   npl[3][MAX_PARTS]; /* start and end polygons for each part */
float xpp[MAX_VERTICES];
float ypp[MAX_VERTICES];
float zpp[MAX_VERTICES];
int   ivq[MAX_VERTICES]; /* connectivity array */

readasc(char *filename)
{
   FILE *fp;
   int  i;

   if (np > 0)
	   return 1;
   printf("opening %s\n",filename);
   if (!(fp = fopen(filename,"r"))) {
      fprintf(stderr,"cannot open %s\n",filename);
      exit(1);
   }

   fscanf(fp,"%d%d%d%d\n",&np,&nj,&npt,&ncon);
   for (i=0;i<np;i++) 
      fscanf(fp,"%d %d\n",&npl[1][i],&npl[2][i]);
   for (i=0;i<nj;i+=2) {
      printf("vertex %d\n",i);
      if (i + 1 < nj)
         fscanf(fp,"%f %f %f %f %f %f\n",&xpp[i],&ypp[i],&zpp[i],
                                        &xpp[i+1],&ypp[i+1],&zpp[i+1]);
      else
         fscanf(fp,"%f %f %f\n",&xpp[i],&ypp[i],&zpp[i]);
   }
   for (i=0;i<ncon;i++) {
      printf("connectivity %d\n",i);
      ivq[i] = readint(fp);
   }
}

int readint(FILE *fp)
{
   int value=0;
   int sign=1;
   char ch;

   while(!feof(fp)) {
      while(1) {
         ch=fgetc(fp);
         if((ch=='+')||(ch=='-')||(ch>='0'&&ch<='9')) break;
      }
      while(1) {
         if (ch=='+')
            sign=1;
         else if(ch=='-')
            sign=-1;
         else if(ch>='0'&&ch<='9')
            value = (value*10)+(ch-'0');
            return(value);
         }
         ch=fgetc(fp);
      }
   }
}