// Helper function for reading PLY mesh file bool Mesh::readNumPlyTris(FILE *&inFile, int& nTris) { bool bElementFound = false; /* Get number of faces in mesh*/ for(;;) { char tempStr[1024]; fscanf(inFile, "%s", tempStr); if (feof(inFile)) { //MessageBox(NULL, "Reached End of File and string \"element face\" not found!\n",NULL, MB_ICONEXCLAMATION); return false; } /* change tempStr to lower case */ ChangeStrToLower(tempStr); if (bElementFound && !strncmp(tempStr, "face", 4)) break; if (!strncmp(tempStr, "element", 7)) { bElementFound = true; continue; } } fscanf(inFile, "%d", &nTris); if (feof(inFile)) { //MessageBox(NULL, "Reached End of File before list of vertices found!\n",NULL, MB_ICONEXCLAMATION); return false; } return true; }
// Helper function for reading PLY mesh file,读入字符ply bool Mesh::readPlyHeader(FILE *&inFile) { char tempStr[1024]; // Read "ply" string do { fscanf(inFile, "%s", tempStr); if (feof(inFile)) { MessageBox(NULL, "Reached End of File and the string \"ply\" NOT FOUND!!\n", NULL, MB_ICONEXCLAMATION); return false; } ChangeStrToLower(tempStr); // change tempStr to lower case } while (strncmp(tempStr, "ply", 3)); // Read # of verts if (!readNumPlyVerts(inFile, _numVerts)) { return false; } // Read # of triangles if (!readNumPlyTris(inFile, _numTriangles)) { return false; } // get end_header,读取文件结束标志 do { fscanf(inFile, "%s", tempStr); if (feof(inFile)) { MessageBox(NULL, TEXT("Reached End of File and string \"end_header\" not found!\n"), NULL, MB_ICONEXCLAMATION); return false; } /* change tempStr to lower case */ ChangeStrToLower(tempStr); } while (strncmp(tempStr, "end_header", 10)); ////////// end of header return true; }