home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch13 / quake / MDLFile.java < prev    next >
Text File  |  1996-11-17  |  4KB  |  84 lines

  1. // A class representing an MDL file from Quake
  2.  
  3. // Written by Bernie Roehl, November 1996
  4.  
  5. package quake;
  6.  
  7. import java.io.*;
  8.  
  9. public class MDLFile {
  10.         protected int version;     // version number
  11.         protected Vec3 scale;      // scaling factors
  12.         protected Vec3 origin;     // origin of the model
  13.         protected float radius;    // radius of bounding sphere
  14.         protected Vec3 offsets;    // eye position
  15.         protected int numskins;    // number of skins
  16.         protected int skinwidth;   // must be multiple of 8
  17.         protected int skinheight;  // must be multiple of 8
  18.         protected int numverts, numtris, numframes;
  19.         protected int synctype;    // 0=synchron, 1=random
  20.         protected int flags;
  21.         protected float size;      // average size of triangles
  22.  
  23.         protected Skin[] skins;              // array of skins
  24.         protected TextureVertex[] textureVertices;  // array of texture verts
  25.         protected Triangle[] triangles;      // array of triangles
  26.         protected FrameGroup[] framegroups;  // array of frame groups
  27.  
  28.         public int getVersion() { return version; }
  29.         public Vec3 getScale() { return scale; }
  30.         public Vec3 getOrigin() { return origin; }
  31.         public float getRadius() { return radius; }
  32.         public Vec3 getOffsets() { return offsets; }
  33.         public int getNumberOfSkins() { return numskins; }
  34.         public int getSkinWidth() { return skinwidth; }
  35.         public int getSkinHeight() { return skinheight; }
  36.         public int getNumberOfVertices() { return numverts; }
  37.         public int getNumberOfTriangles() { return numtris; }
  38.         public int getNumberOfFrameGroups() { return numframes; }
  39.         public int getSyncType() { return synctype; }
  40.         public int getFlags() { return flags; }
  41.         public float getSize() { return size; }
  42.         public Skin getSkin(int n) { return skins[n]; }
  43.         public TextureVertex getTextureVertex(int n) { return textureVertices[n]; }
  44.         public Triangle getTriangle(int n) { return triangles[n]; }
  45.         public FrameGroup getFrameGroup(int n) { return framegroups[n]; }
  46.  
  47.         public MDLFile(DataInputStream in)
  48.                 throws MDLFormatException, IOException {
  49.                 ByteFlipInputStream input = new ByteFlipInputStream(in);
  50.                 // read header
  51.                 if (input.readFlippedInt() != 0x4F504449)
  52.                         throw new MDLFormatException("bad signature");
  53.                 if ((version = input.readFlippedInt()) != 6)
  54.                         throw new MDLFormatException("only version 6 supported; file is version " + version);
  55.                 scale = new Vec3(input);
  56.                 origin = new Vec3(input);
  57.                 radius = input.readFlippedFloat();
  58.                 offsets = new Vec3(input);
  59.                 numskins = input.readFlippedInt();
  60.                 skinwidth = input.readFlippedInt();
  61.                 skinheight = input.readFlippedInt();
  62.                 numverts = input.readFlippedInt();
  63.                 numtris = input.readFlippedInt();
  64.                 numframes = input.readFlippedInt();
  65.                 synctype = input.readFlippedInt();
  66.                 flags = input.readFlippedInt();
  67.                 size = input.readFlippedFloat();
  68.                 // read skins
  69.                 skins = new Skin[numskins];
  70.                 for (int i = 0; i < numskins; ++i)
  71.                         skins[i] = new Skin(input, skinwidth, skinheight);
  72.                 textureVertices = new TextureVertex[numverts];
  73.                 for (int i = 0; i < numverts; ++i)
  74.                         textureVertices[i] = new TextureVertex(input);
  75.                 triangles = new Triangle[numtris];
  76.                 for (int i = 0; i < numtris; ++i)
  77.                         triangles[i] = new Triangle(input);
  78.                 framegroups = new FrameGroup[numframes];
  79.                 for (int i = 0; i < numframes; ++i)
  80.                         framegroups[i] = new FrameGroup(input, numverts);
  81.         }
  82. }
  83.  
  84.