--Saving an OFF file-- The following partial implementation of the Serialize method is one way to handle saving an OFF file, with the amount of detail we need. It writes a basic OFF file. This assumes that your data is stored in the following way: int numVertices // The number of vertices in the mesh int numFaces // The number of faces in the mesh int numEdges // The number of edges in the mesh (If known. Otherwise, 0 works) double** vertices // A dynamically allocated 2D array of doubles, with numVertices rows // and 3 columns (x, y, z). int* faceSizes // A dynamically allocated array of ints, where each entry is the size // of the corresponding face (# of edges/vertices in it) int** faces // A dynamically allocated 2D array of ints, with numFaces rows // and as many columns per row as the corresponding faceSizes entry. Use the information above to translate this code to work on your own data structures. void Doc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // If the user hit Save or Save As, this block is executed // instead of the one below. // Write out the first line of the file header ar.WriteString("OFF\n"); // Create a CString to format strings into CString writeLine; // Write the header information into the string, using the printf-like // Format method. writeLine.Format("%d %d %d\n", numVertices, numFaces, numEdges); // Write out the second line of the file header. ar.WriteString(writeLine); // Write out all the vertices in order. for (int i = 0;i < numVertices;i++) { writeLine.Format("%f %f %f", vertices[i][0], vertices[i][1], vertices[i][2]); ar.WriteString(writeLine); ar.WriteString("\n"); } int currentFaceSize = 0; for (i = 0;i < numFaces;i++) { currentFaceSize = faceSizes[i]; writeLine.Format("%d", currentFaceSize); ar.WriteString(writeLine); for (int j = 0;j < currentFaceSize; j++) { writeLine.Format(" %d", faces[i][j]); ar.WriteString(writeLine); } ar.WriteString("\n"); } } else { // This is where the loading code is. } } Ryan Holmes 4/5/02