I've been making a program that displays 3D meshes using OpenGl. I tried loading a mesh with ~70,000 verticies and it took fairly long. I've simply been exporting my model from blender as an .obj and parsing it that way, but I was wondering if there was a better way since what I'm doing currently is pretty slow. For now, I'm not interested in anything but vertex positions and indices.
Is there a better file format for this? Or is it possible to optimize the code below? What is the industry standard for doing things like this? Should I just accept that it'll be slow no matter what?
Here is what I do to load the verticies and indicies. Currently, with a fairly large mesh with ~70,000 verticies, it takes ~1950ms (with \O2).
struct MeshData { std::vector<float> vertexPositions; std::vector<uint32_t> indicies;};MeshData VertexTest::parseObj(const char* path){ Timer t("Loading"); MeshData data; std::ifstream stream(path); std::string line; srand(time(NULL)); while (std::getline(stream, line)) { if (line[0] == 'v'&& line[1] == '') { line = line.substr(2); std::stringstream ss(line); float num; while (ss >> num) { data.vertexPositions.push_back(num); } data.vertexPositions.push_back((float)rand() / (float)RAND_MAX); data.vertexPositions.push_back((float)rand() / (float)RAND_MAX); data.vertexPositions.push_back((float)rand() / (float)RAND_MAX); data.vertexPositions.push_back(1.0f); } if (line[0] == 'f'&& line[1] == '') { line = line.substr(2); std::stringstream parse(line); std::string section; std::vector<int> temp; while (std::getline(parse, section, '')) { temp.push_back(std::stoi(section.substr(0, section.find('/'))) - 1); } if (temp.size() == 4) { data.indicies.push_back(temp[0]); data.indicies.push_back(temp[1]); data.indicies.push_back(temp[2]); data.indicies.push_back(temp[0]); data.indicies.push_back(temp[2]); data.indicies.push_back(temp[3]); } else if (temp.size() == 3) { data.indicies.push_back(temp[0]); data.indicies.push_back(temp[1]); data.indicies.push_back(temp[2]); } else { std::cout << "Unkown case: " << temp.size() << std::endl; ASSERT(false); } } } return data;}