Пример #1
0
bool ObjIO::ReadData(std::istream & is){
  std::string lineBuf;
  int c;
  int i=0;
  while(!is.eof()){
    c = is.peek();
    switch (c) {
    case 'V':
    case 'v':{
      std::string startBuf;
      is >> startBuf; // get the start of the line
      getline(is, lineBuf); // get the rest of the line
      if(startBuf == "v"){
        loadData.verts.push_back(Vector3<float>(lineBuf));
      }
    }
      break;
    case 'F':
    case 'f':
      {
        std::stringstream buf;
        is.get(*buf.rdbuf(), '\n'); // read a line into buf
        is.get(); // read the not extracted \n
        buf << "\n"; // and add it to the string stream

        std::string tmp;
        buf >> tmp; // get the first f or F (+ whitespace)

        // count the number of faces, delimited by whitespace
        int count = 0;
        while (buf >> tmp){
          count++;
        }
        // reset stream
        buf.clear();
        buf.seekg(0, std::ios::beg);

        // Determine wheter we have a triangle or a quad
        if (count == 3){
          loadData.tris.push_back(ReadTri(buf));
        }
        else {
          std::cerr << "Encountered polygon with " << count << " faces. Bailing out.\n";
          return false;
        }
      }
      break;
    default:
      // otherwise just skip the row
      getline(is, lineBuf);
      // output it so we see what we miss :)
      // std::cerr << "\"" << lineBuf << "\"\n";
      break;
    }
    i++;
  }
  return true;
}
Пример #2
0
int main(int argc, char* argv[])
{
	if(argc <2)
	{
		printf("need: exe,inputfile\n");	
	}
	ReadTri(argv[1]);
	return 0;
}