home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-11-17 | 4.0 KB | 84 lines |
- // A class representing an MDL file from Quake
-
- // Written by Bernie Roehl, November 1996
-
- package quake;
-
- import java.io.*;
-
- public class MDLFile {
- protected int version; // version number
- protected Vec3 scale; // scaling factors
- protected Vec3 origin; // origin of the model
- protected float radius; // radius of bounding sphere
- protected Vec3 offsets; // eye position
- protected int numskins; // number of skins
- protected int skinwidth; // must be multiple of 8
- protected int skinheight; // must be multiple of 8
- protected int numverts, numtris, numframes;
- protected int synctype; // 0=synchron, 1=random
- protected int flags;
- protected float size; // average size of triangles
-
- protected Skin[] skins; // array of skins
- protected TextureVertex[] textureVertices; // array of texture verts
- protected Triangle[] triangles; // array of triangles
- protected FrameGroup[] framegroups; // array of frame groups
-
- public int getVersion() { return version; }
- public Vec3 getScale() { return scale; }
- public Vec3 getOrigin() { return origin; }
- public float getRadius() { return radius; }
- public Vec3 getOffsets() { return offsets; }
- public int getNumberOfSkins() { return numskins; }
- public int getSkinWidth() { return skinwidth; }
- public int getSkinHeight() { return skinheight; }
- public int getNumberOfVertices() { return numverts; }
- public int getNumberOfTriangles() { return numtris; }
- public int getNumberOfFrameGroups() { return numframes; }
- public int getSyncType() { return synctype; }
- public int getFlags() { return flags; }
- public float getSize() { return size; }
- public Skin getSkin(int n) { return skins[n]; }
- public TextureVertex getTextureVertex(int n) { return textureVertices[n]; }
- public Triangle getTriangle(int n) { return triangles[n]; }
- public FrameGroup getFrameGroup(int n) { return framegroups[n]; }
-
- public MDLFile(DataInputStream in)
- throws MDLFormatException, IOException {
- ByteFlipInputStream input = new ByteFlipInputStream(in);
- // read header
- if (input.readFlippedInt() != 0x4F504449)
- throw new MDLFormatException("bad signature");
- if ((version = input.readFlippedInt()) != 6)
- throw new MDLFormatException("only version 6 supported; file is version " + version);
- scale = new Vec3(input);
- origin = new Vec3(input);
- radius = input.readFlippedFloat();
- offsets = new Vec3(input);
- numskins = input.readFlippedInt();
- skinwidth = input.readFlippedInt();
- skinheight = input.readFlippedInt();
- numverts = input.readFlippedInt();
- numtris = input.readFlippedInt();
- numframes = input.readFlippedInt();
- synctype = input.readFlippedInt();
- flags = input.readFlippedInt();
- size = input.readFlippedFloat();
- // read skins
- skins = new Skin[numskins];
- for (int i = 0; i < numskins; ++i)
- skins[i] = new Skin(input, skinwidth, skinheight);
- textureVertices = new TextureVertex[numverts];
- for (int i = 0; i < numverts; ++i)
- textureVertices[i] = new TextureVertex(input);
- triangles = new Triangle[numtris];
- for (int i = 0; i < numtris; ++i)
- triangles[i] = new Triangle(input);
- framegroups = new FrameGroup[numframes];
- for (int i = 0; i < numframes; ++i)
- framegroups[i] = new FrameGroup(input, numverts);
- }
- }
-
-