wxPdfObject* wxPdfParser::ParseObjectStream(wxPdfStream* objStm, int idx) { wxPdfObject* obj = NULL; wxPdfNumber* firstNumber = (wxPdfNumber*) ResolveObject(objStm->Get(_T("/First"))); int first = firstNumber->GetInt(); if (objStm->GetBuffer() == NULL) { bool saveUseRawStream = m_useRawStream; m_useRawStream = false; GetStreamBytes(objStm); m_useRawStream = saveUseRawStream; } bool saveEncrypted = m_encrypted; m_encrypted = false; wxPdfTokenizer* saveTokens = m_tokens; wxMemoryInputStream objStream(*(objStm->GetBuffer())); m_tokens = new wxPdfTokenizer(&objStream); int address = 0; bool ok = true; if (!objStm->HasObjOffsets()) { // Read object offsets wxArrayInt* objOffsets = objStm->GetObjOffsets(); int objCount = idx + 1; if (m_cacheObjects) { wxPdfNumber* objCountNumber = (wxPdfNumber*) ResolveObject(objStm->Get(_T("/N"))); objCount = objCountNumber->GetInt(); } int offset; int k; for (k = 0; k < objCount; ++k) { ok = m_tokens->NextToken(); if (!ok) break; if (m_tokens->GetTokenType() != TOKEN_NUMBER) { ok = false; break; } ok = m_tokens->NextToken(); if (!ok) break; if (m_tokens->GetTokenType() != TOKEN_NUMBER) { ok = false; break; } offset = m_tokens->GetIntValue() + first; if (m_cacheObjects) { objOffsets->Add(offset); } if (k == idx) { address = offset; } } if (ok) { objStm->SetHasObjOffsets(m_cacheObjects); } } else { address = objStm->GetObjOffset(idx); ok = (address > 0); } if (ok) { m_tokens->Seek(address); obj = ParseObject(); } else { wxLogError(_T("wxPdfParser::ParseOneObjStm: Error reading ObjStm.")); } delete m_tokens; m_tokens = saveTokens; m_encrypted = saveEncrypted; return obj; }
void Mesh_Obj::RawAttach() { if (this->is_Attached) return; else this->is_Attached = true; fstream fin(this->Dir, ios::in); if (!fin.is_open()) { fin.close(); cout << this->Dir << " :Obj Not Found!" << endl; exit(1); } else { cout << this->Dir << " :Obj Loading Now!" << endl; } fin.seekg(0, ios::end); size_t fileSize = fin.tellg(); fin.seekg(0); string source; source.assign(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>()); fin.close(); vector<vec3> VertexAttribTemp[texCoord + 1]; vector<GLuint> ElementArrayTemp; set<Vertex> VertexBuffer; set<Edge> EdgeTemp; glGenVertexArrays(1, VAO); glGenBuffers(4, VBO); glBindVertexArray(VAO[0]); stringstream objStream(source); while (!objStream.eof()) { string line; getline(objStream, line); stringstream lineStream(line); char numb; if (line.empty()) continue; switch (line.at(0)) { case 'v': switch (line.at(1)) { case ' ': float CoordData[3]; lineStream >> numb >> CoordData[0] >> CoordData[1] >> CoordData[2]; VertexAttribTemp[Coord].push_back(vec3(CoordData[0], CoordData[1], CoordData[2])); break; case 'n': float normalData[3]; lineStream >> numb >> numb >> normalData[0] >> normalData[1] >> normalData[2]; VertexAttribTemp[normalDir].push_back(vec3(normalData[0], normalData[1], normalData[2])); break; case 't': float texCoordData[3]; char numb; lineStream >> numb >> numb >> texCoordData[0] >> texCoordData[1] >> texCoordData[2]; VertexAttribTemp[texCoord].push_back(vec3(texCoordData[0], texCoordData[1], texCoordData[2])); break; default: break; } break; case 'f': lineStream >> numb; if (line.find("//") != line.npos) { for (int i = 0; i != 3; ++i) { unsigned PosTexNor[3]; lineStream >> PosTexNor[Coord] >> numb >> numb >> PosTexNor[normalDir]; for (int i = 0; i != 3; ++i) { PosTexNor[i]--; } ElementArrayTemp.push_back(PosTexNor[0]); VertexBuffer.insert(Vertex(VertexAttribTemp[Coord].at(PosTexNor[Coord]), VertexAttribTemp[normalDir].at(PosTexNor[normalDir]), vec3(0, 0, 0), PosTexNor[0])); } } else { for (int i = 0; i != 3; ++i) { unsigned PosTexNor[3]; lineStream >> PosTexNor[Coord] >> numb >> PosTexNor[texCoord] >> numb >> PosTexNor[normalDir]; for (int i = 0; i != 3; ++i) { PosTexNor[i]--; } ElementArrayTemp.push_back(PosTexNor[0]); VertexBuffer.insert(Vertex(VertexAttribTemp[Coord].at(PosTexNor[Coord]), VertexAttribTemp[normalDir].at(PosTexNor[normalDir]), VertexAttribTemp[texCoord].at(PosTexNor[texCoord]), PosTexNor[0])); } } break; default: break; } }