bool KAbstractObjParserPrivate::parse() { for (;;) { switch (nextToken()) { case PT_ERROR: qFatal("Encountered an error! Aborting"); return false; case PT_EOF: return true; case PT_VERTEX: parseVertex(); break; case PT_TEXTURE: parseTexture(); break; case PT_NORMAL: parseNormal(); break; case PT_PARAMETER: parseParameter(); break; case PT_FACE: parseFace(); case PT_ENDSTATEMENT: break; } } }
void parse(std::ifstream& file, ObjStore& obj) { std::string line; std::stringstream lineStream; char firstChar; std::cout << "Parsing Obj!" << std::endl; while ( std::getline( file, line ) ) { // reject empty lines if ( line.empty() ) { continue; } // make stream from line lineStream.clear(); lineStream.str(line); // check first char to determine type lineStream.get(firstChar); if (firstChar == 'v') { parseVertex(lineStream, obj); } else if (firstChar == 'f') { parseFace(lineStream, obj); } } }
void Obj2::load(std::string const& path) { ifstream file; string work; file.open(path.c_str(), ios::in); //check ouverture if (!file.good()) { throw FileError(0,"Error in OBJ load : \n\timpossible to open " + path + "."); } objects.clear(); vertices.clear(); //boucle de parcours pour tout le fichier int cptr = 0; Object *currentObject = nullptr; while (!file.eof()) { cptr++; file >> work;//premier mot de la ligne //cas face if (work == "f") {//on ne désespère pas. un jour on pourra switcher sur des strings. ptt. if (currentObject == nullptr) throw FileError(1,"Error in OBJ load : \n\tface before first object at line " + to_string(cptr)); getline(file, work); currentObject->addFace(parseFace(work)); }//cas vertice else if (work == "v") { getline(file, work); addVertex(parseVertex(work)); }//cas objet else if (work == "o") { file >> work; if (currentObject != nullptr) { currentObject->setDimension((currentObject->nbrFaces() == 6) ? 0 : 1); addObject(*currentObject); }currentObject = new Object(work, 1); }//cas commentaire else if (work == "#") {
void ModelLoader::parseLine(char *line) { //check for an empty string if(!strlen(line)) { return; } char *linetype; linetype = strtok(strdup(line), " "); if(!strcmp(linetype, "v")) { parseVertex(line); //line is a vertex } else if(!strcmp(linetype, "vn")) { parseNormal(line); //line is a normal } else if(!strcmp(linetype, "vt")) { parseTexel(line); //line is a texel } else if(!strcmp(linetype, "f")) { parseFace(line); //line is a face } return; }
void WFObject::parseLine(char *line) { if(!strlen(line)) { return; } char *lineType; lineType = strtok(_strdup(line), " "); // Decide what to do if(!strcmp(lineType, "v")) // Vertex { parseVertex(line); } else if (!strcmp(lineType, "vt")) { parseTexture(line); } else if(!strcmp(lineType, "vn")) // Normal { parseNormal(line); } else if(!strcmp(lineType, "f")) // Face { parseFace(line); } return; }
void Mesh::parseLine(std::stringstream&& sin) { std::string s; sin >> s; if (s.compare("v") == 0) parseVertex(sin); else if (s.compare("vt") == 0) parseTexcoord(sin); else if (s.compare("vn") == 0) parseNormal(sin); else if (s.compare("f") == 0) parseFace(sin); }
void Geometry::parseObjFile(const std::string filePath, std::vector<GLfloat>& vboData, std::vector<GLushort>& iboData) { //temporary save values in arrays std::vector<glm::vec3> vertices; std::vector<glm::vec3> normals; //save which data vbo already contains std::list<IndexCombination> combinations; //save next vbo index to use GLushort nextVboIndex = 0; //open file std::ifstream objFile; objFile.exceptions(std::ifstream::badbit | std::ifstream::failbit); objFile.open(filePath); std::string line; while (!objFile.eof()) { try { std::getline(objFile, line); } catch (const std::exception &ex) { if (!objFile.eof()) { throw ex; } else { continue; } } std::istringstream lstream(line); std::string type; lstream >> type; if (type.compare("v") == 0) { parseVertex(lstream, vertices); } else if (type.compare("vn") == 0) { parseNormal(lstream, normals); } else if (type.compare("f") == 0) { parseFace(lstream, vboData, iboData, vertices, normals, &nextVboIndex, combinations); } else if (type.compare("s") == 0) { //ignore line } else if (type.compare("o") == 0) { //ignore line } else if (type.compare("#") == 0) { //ignore line } else { throw std::logic_error("Unknown start of line"); } } objFile.close(); }
void parsePolyline() { GROUP_BEGIN(); switch(group.code) { case(0): if("VERTEX" == group.type){ parseVertex(); }else if("SEQEND" == group.type){ finished = true; } break; } GROUP_END(); }
void parseOBJLine(const std::string& line, std::vector<Vertex> &vertexList, std::vector<int> &indexList) { std::istringstream iss(line); std::string key; iss >> key; if (key == "v") { // parse vertex // Vertex v = parseVertex(iss); vertexList.push_back(v); } else if (key == "f") { // parse face // unsigned int index; iss >> index; indexList.push_back(index); iss >> index; indexList.push_back(index); iss >> index; indexList.push_back(index); }
static void emitreducecode(void) { int i, j, v1, v2; set ind1, ind2; for(i=0; i<vcs.sizet; i++) parsedverts[i]=parseVertex(i,1); fermprgemit(); formblocks(&n_vrt); makeprgcode(); for(i=0; i<vcs.sizet; i++) free(parsedverts[i]); for (i = n_vrt - 1; i >= 1; i--) { v1 = prgcode[i-1][0]; v2 = prgcode[i-1][1]; ind1=vertinfo[v1-1].ind; ind2=vertinfo[v2-1].ind; r_mult(v1,v2,set_and(ind1,ind2)); vertinfo[MIN(v1,v2)-1].g5 = vertinfo[v1-1].g5 + vertinfo[v2-1].g5; vertinfo[MIN(v1,v2)-1].ind= set_aun(set_or(ind1,ind2),set_and(ind1,ind2)); } for (i = 0; i < vcs.sizet; i++) for (j = 0; j <vcs.valence[i]; j++) { int mom,np; mom=vcs.vertlist[i][j].moment; np =vcs.vertlist[i][j].partcl; if (mom>0 && prtclbase1[np].hlp == 't') { writeF("Vrt_1:=Vrt_1*(%s**2",prtclbase1[np].massidnt); if(prtclbase1[ghostmother(np)].hlp=='*') writeF(")$\n"); else writeF("-p%d.p%d)$\n",mom,mom); } } writeF("%%\n"); }
void ObjFile::read(std::istream& from) { std::vector<Eigen::Vector4f> points; std::vector<Eigen::Vector4f> normals; std::vector<int> indices; std::vector<int> uvIndices; std::vector<int> vnIndices; std::vector<Eigen::Vector3f> uvs; std::string curLine; while (!from.eof()) { std::getline(from, curLine); utils::trim(&curLine); if (curLine.compare(0, 2, "v ") == 0) { points.push_back(parseVertex(curLine)); } else if (curLine.compare(0, 2, "f ") == 0) { auto tuple = parseIndex(curLine); indices.insert(indices.end(), std::get<0>(tuple).begin(), std::get<0>(tuple).end()); uvIndices.insert(uvIndices.end(), std::get<1>(tuple).begin(), std::get<1>(tuple).end()); vnIndices.insert(vnIndices.end(), std::get<2>(tuple).begin(), std::get<2>(tuple).end()); } else if (curLine.compare(0, 3, "vt ") == 0) { uvs.push_back(parseUV(curLine)); } else if (curLine.compare(0, 3, "vn ") == 0) { normals.push_back(parseNormal(curLine)); } } //std::reverse(indices.begin(), indices.end()); //std::reverse(vnIndices.begin(), vnIndices.end()); //std::reverse(uvIndices.begin(), uvIndices.end()); _points = std::move(points); _indices = std::move(indices); _normals = std::move(normals); _uvIndices = std::move(uvIndices); _vnIndices = std::move(vnIndices); _uvs = std::move(uvs); }
void Model::parseMesh(std::string fileName) { std::string line; std::ifstream myFile(fileName.c_str()); if (myFile.is_open()) { while (getline(myFile, line)) { if (line.at(0) == 'o') { meshName = parseName(line); } else if (line.at(0) == 'v' && line.at(1) == ' ') { vertexArray.push_back(parseVertex(line)); } else if (line.at(0) == 'f') { std::vector<std::string> elements = split(line, ' '); if ((elements.size() - 1) == 4) { quadArray.push_back(parseFace(elements)); } else if ((elements.size() - 1) == 3) { triArray.push_back(parseFace(elements)); } elements.clear(); } else { // N-Gons } } } myFile.close(); }
bool ofxOBJModel::load(string path) { filePath = path; path = ofToDataPath(path, true); string line; for(int i = 0; i < meshes.size(); i++) { delete meshes[i]; } meshes.clear(); ObjMesh *currMesh = NULL; // this is a list of all points // that we can drop after parsing vector<ofPoint> points; // obj file format vertexes are 1-indexed points.push_back(ofPoint()); ifstream myfile (path.c_str()); if (myfile.is_open()) { while (! myfile.eof()) { getline (myfile,line); // parse the obj format here. // // the only things we're interested in is // lines beginning with 'g' - this says start of new object // lines beginning with 'v ' - coordinate of a vertex // lines beginning with 'f ' - specifies a face of a shape // we take each number before the slash as the index // of the vertex to join up to create a face. if(line.find("g ")==0) { // new object definition currMesh = new ObjMesh(line.substr(2)); meshes.push_back(currMesh); } else if(line.find("v ")==0) { // new vertex points.push_back(parseVertex(line)); } else if(line.find("f ")==0) { // face definition if(currMesh!=NULL) { line = line.substr(2); // lop off "f " vector<string> indices = split(line, ' '); // remove any texcoords (/xxx's) for(int i = 0; i < indices.size(); i++) { int slashPos = indices[i].find("/"); if(slashPos!=-1) { indices[i] = indices[i].substr(0, slashPos); } } ObjFace *face = new ObjFace(); for(int i = 0; i < indices.size(); i++) { face->points.push_back(points[atoi(indices[i].c_str())]); } currMesh->addFace(face); } } } myfile.close(); printf("Successfully loaded %s\n-----\nVertices: %d\nMeshes: %d\n", path.c_str(), points.size(), meshes.size()); return true; } else { printf("Couldn't find the OBJ file %s\n", path.c_str()); return false; } }