looks like an .obj file? well either way... If you're not aiming for speed this should be kinda clare. I use a dummy string to extract dummy text. =)
std::ifstream file("filenamehere");if( !file.is_open() ) ;// Scream for mercy, and then change "filenamehere"std::string dummy, objName;file >> dummy; // "Named"file >> dummy; // "object:"file >> objName; // "Box01"int vertices=0, faces=0;file >> dummy >> dummy >> vertices >> dummy >> faces; // "Tri-mesh,", "Vertices:", vertices=8, "Faces:", faces=12file >> dummy >> dummy; // "Vertex", "List:"for( int vertex=0; vertex < vertices; vertex++ ){ float x=0, y=0, z=0; file >> dummy >> dummy; // "Vertex", index file >> dummy >> x; // "X:" file >> dummy >> y; // "Y:" file >> dummy >> z; // "Z:" // do something with your x,y,z =)}file >> dummy >> dummy; // "Face", "list:"for( int face=0; face < faces; face++ ){ int a=0, b=0, c=0, ab=0, bc=0, ca=0, smoothing; file >> dummy >> dummy: // "Face", index file >> dummy >> a; // "A:" file >> dummy >> b; // "B:" file >> dummy >> c; // "C:" file >> dummy >> ab; // "AB:" file >> dummy >> bc; // "BC:" file >> dummy >> ca; // "CA:" file >> dummy >> smoothing; // "Smoothing:" // do something with your face info =)}
That's a C++ way to do it, not saying it's THE way to do it... If you use C you'll get some better performance, and maybe more readable code? =P But I'm to tired to write an example, somebody else might want to give it a try? =)
[edited by - seriema on May 17, 2004 8:36:29 PM]