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); }
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); }