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);
}
Beispiel #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
}
Beispiel #3
0
bool PtexReader::open(const char* path, Ptex::String& error)
{
    if (!LittleEndian()) {
        error = "Ptex library doesn't currently support big-endian cpu's";
        return 0;
    }
    _path = path;
    _fp = _io->open(path);
    if (!_fp) {
        std::string errstr = "Can't open ptex file: ";
        errstr += path;
        errstr += "\n";
        errstr += _io->lastError();
        error = errstr.c_str();
        return 0;
    }
    readBlock(&_header, HeaderSize);
    if (_header.magic != Magic) {
        std::string errstr = "Not a ptex file: ";
        errstr += path;
        error = errstr.c_str();
        return 0;
    }
    if (_header.version != 1) {
        char ver[21];
        snprintf(ver, 20, "%d", _header.version);
        std::string errstr = "Unsupported ptex file version (";
        errstr += ver;
        errstr += "): ";
        errstr += path;
        error = errstr.c_str();
        return 0;
    }
    _pixelsize = _header.pixelSize();

    // read extended header
    memset(&_extheader, 0, sizeof(_extheader));
    readBlock(&_extheader, PtexUtils::min(uint32_t(ExtHeaderSize), _header.extheadersize));

    // compute offsets of various blocks
    FilePos pos = tell();
    _faceinfopos = pos;
    pos += _header.faceinfosize;
    _constdatapos = pos;
    pos += _header.constdatasize;
    _levelinfopos = pos;
    pos += _header.levelinfosize;
    _leveldatapos = pos;
    pos += _header.leveldatasize;
    _metadatapos = pos;
    pos += _header.metadatazipsize;
    pos += sizeof(uint64_t); // compatibility barrier
    _lmdheaderpos = pos;
    pos += _extheader.lmdheaderzipsize;
    _lmddatapos = pos;
    pos += _extheader.lmddatasize;

    // edit data may not start immediately if additional sections have been added
    // use value from extheader if present (and > pos)
    _editdatapos = PtexUtils::max(FilePos(_extheader.editdatapos), pos);

    // read basic file info
    readFaceInfo();
    readConstData();
    readLevelInfo();
    readEditData();

    // an error occurred while reading the file
    if (!_ok) {
        error = _error.c_str();
        return 0;
    }

    return 1;
}