Exemplo n.º 1
0
 public bool writeMD3Frame(ByteFileWriter w)
 {
     w.writeVec3(mins);
     w.writeVec3(maxs);
     w.writeVec3(localOrigin);
     w.writeFloat((float)radius);
     w.writeFixedString(name, 16);
     return(false);
 }
Exemplo n.º 2
0
 public bool writeMD3Tag(ByteFileWriter w)
 {
     w.writeFixedString(tagName, 64);
     w.writeVec3(origin);
     w.writeVec3(f);
     w.writeVec3(r);
     w.writeVec3(u);
     return(false);
 }
Exemplo n.º 3
0
        public void writeMD3Vertex(ByteFileWriter w)
        {
            short x = (short)(xyz.getX() / 0.015625);
            short y = (short)(xyz.getY() / 0.015625);
            short z = (short)(xyz.getZ() / 0.015625);

            w.writeShort(x);
            w.writeShort(y);
            w.writeShort(z);
        }
Exemplo n.º 4
0
        public bool writeMD3Surface(ByteFileWriter w)
        {
            long surfaceDataStart = w.getPos();

            int ident = 0;

            w.writeInt(ident);
            w.writeFixedString(surfName, 64);
            w.writeInt(flags);
            w.writeInt(frameVerts.Count);
            w.writeInt(materials.Count);
            w.writeInt(texCoords.Count);
            w.writeInt(indices.Count / 3);
            long offsetsAt = w.getPos();

            // write offsets
            w.writeInt(0); // ofsTris
            w.writeInt(0); // ofsMaterials
            w.writeInt(0); // ofsTexCoords
            w.writeInt(0); // ofsXYZNormals
            w.writeInt(0); // ofsEnd
            long ofsMaterials = w.getPos();

            // write material names
            foreach (string s in materials)
            {
                w.writeFixedString(s, 64);
                w.writeInt(0);
            }
            long ofsTris = w.getPos();

            foreach (int i in indices)
            {
                w.writeInt(i);
            }
            long ofsXYZNormals = w.getPos();

            foreach (MD3SurfVertsFrame f in frameVerts)
            {
                foreach (MD3Vertex v in f.getVerts())
                {
                    v.writeMD3Vertex(w);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        public bool writeMD3Model(string outFileName)
        {
            ByteFileWriter w = new ByteFileWriter();

            if (w.beginWriting(outFileName))
            {
                return(true);
            }
            w.writeFixedString("IDP3", 4);
            w.writeInt(10);
            w.writeFixedString(internalName, 64);
            w.writeInt(flags);
            w.writeInt(frames.Count);
            w.writeInt(tags.Count);
            w.writeInt(surfaces.Count);
            // skins count
            w.writeInt(0);
            int ofsFrames   = 108;
            int ofsTags     = ofsFrames + frames.Count * 56;
            int ofsSurfaces = ofsTags + tags.Count * 110;

            // sanity check
            //if (ofsTags != w.getPos())
            //{
            //    MessageBox.Show("OfsTags mismatch.",
            //    "MD3 write error",
            //    MessageBoxButtons.OK,
            //    MessageBoxIcon.Exclamation,
            //    MessageBoxDefaultButton.Button1);
            //    return true;
            //}
            // offset to first frame
            w.writeInt(ofsFrames);
            // offset to first tag
            w.writeInt(ofsTags);
            // write offset to surface
            w.writeInt(ofsSurfaces);
            // ofs ends - will be set after writing the surfaces
            w.writeInt(0);

            // sanity check
            if (ofsFrames != w.getPos())
            {
                MessageBox.Show("Ofsframes mismatch.",
                                "MD3 write error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return(true);
            }
            foreach (MD3Frame f in frames)
            {
                f.writeMD3Frame(w);
            }
            // sanity check
            if (ofsTags != w.getPos())
            {
                MessageBox.Show("OfsTags mismatch (" + ofsTags + " vs pos " + w.getPos() + ".",
                                "MD3 write error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return(true);
            }
            foreach (MD3Tag t in tags)
            {
                t.writeMD3Tag(w);
            }
            // sanity check
            if (ofsSurfaces != w.getPos())
            {
                MessageBox.Show("OfsSurfaces mismatch.",
                                "MD3 write error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return(true);
            }
            foreach (MD3Surface sf in surfaces)
            {
                sf.writeMD3Surface(w);
            }



            return(false);
        }