Пример #1
0
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;
    }
  }
}
Пример #2
0
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;
}
Пример #4
0
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);
}
Пример #5
0
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();
}
Пример #6
0
	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);
	}