Пример #1
0
void objLoader::readObjFile(t3DModel *pModel) {
    char strLine[255] = {0};
    char ch = 0;

    while(!feof(m_FilePointer)) {
        float x = 0.0f, y = 0.0f, z = 0.0f;

        ch = fgetc(m_FilePointer);

        switch(ch) {
            case 'v':
                if(m_bJustReadAFace) {
                    fillInObjectInfo(pModel);
                }
                readVertexInfo();
                break;
            case 'f':
                readFaceInfo();
                break;
            case '\n':
                break;
            default:
                fgets(strLine, 100, m_FilePointer);
                break;
        }
    }

    fillInObjectInfo(pModel);
}
Пример #2
0
/** main loop for reading in the .obj file */
void Obj::readFile(tOBJModel *pmodel)
{
  char line[256];

  while (! feof(fp)) {
    switch (fgetc(fp)) { // get the beginning character of the current line
    case 'v':	// check if we just read in a 'v' (vertice/normal/textureCoord)
      if (bJustReadAFace) fillInObjectInfo(pmodel); // save the last object's info
      readVertexInfo(); // see if it's a vertex "v", normal "vn", or UV coordinate "vt"
      break;
    case 'f':	// check if we just read in a face header ('f')
      readFaceInfo();
      bJustReadAFace = true;
      break;
    default:
      fgets(line, sizeof(line), fp);
      break;
    }
  }
  fillInObjectInfo(pmodel); // we are done reading in the file
}