Hi everyone,
I’m currently running into memory issues when loading pointclouds into a ofVboMesh… So I thought it may be a great idea to reduce the precision of my vertices and normals.
I don’t really need them super precise anyways, I just need lots of them!
Somehow I can’t figure it out and always end up with 0 vertices/normals…
Here is my code to parse a wavefront obj file into a ofVboMesh.
#define SCALING = 10.0f
void loadMeshLevel(ofVboMesh& mesh, string path) {
ofVboMesh mesh;
// i only render points, so..
mesh.setMode(OF_PRIMITIVE_POINTS);
mesh.enableColors();
mesh.enableNormals();
mesh.disableIndices();
mesh.disableTextures();
auto meshLines = ofSplitString(ofBufferFromFile(path).getText(), "\n");
// i don't know beforehand how many normals/vertices i have, so i use vectors instead of arrays
vector<glm::lowp_float> vNormals;
vector<glm::mediump_float> vVertices;
for (string& line : meshLines) {
if (line.empty()) {
continue;
}
if (line[0] == 'v' && line[1] == 'n') {
std::vector<string> vec = ofSplitString(line, " ");
vNormals.push_back(glm::lowp_float(ofToFloat(vec[1])));
vNormals.push_back(glm::lowp_float(ofToFloat(vec[2])));
vNormals.push_back(glm::lowp_float(ofToFloat(vec[3])));
// the following line worked
//mesh.addNormal(glm::vec3(ofToFloat(vec[1]),ofToFloat(vec[2]),ofToFloat(vec[3])));
} else if (line[0] == 'v' && line[1] == ' ') {
std::vector<string> vec = ofSplitString(line, " ");
vVertices.push_back(glm::mediump_float(ofToFloat(vec[1]) * SCALING));
vVertices.push_back(glm::mediump_float(ofToFloat(vec[2]) * SCALING));
vVertices.push_back(glm::mediump_float(ofToFloat(vec[3]) * SCALING));
// again, the following line worked perfectly
//mesh.addVertex(glm::vec3(ofToFloat(vec[1]) * SCALING,ofToFloat(vec[2]) * SCALING,ofToFloat(vec[3]) * SCALING));
// i store the colors normally for now, babysteps..
mesh.addColor( ofColor(ofToFloat(vec[4]) * 255,ofToFloat(vec[5]) * 255, ofToFloat(vec[6]) * 255));
}
}
// here I try to set the data in the vbo... somehow it doesn't want to be there though
mesh.getVbo().setNormalData(&vNormals[0], vNormals.size(), GL_STATIC_DRAW, sizeof(glm::lowp_float)*3);
mesh.getVbo().setVertexData(&vVertices[0], vVertices.size(), GL_STATIC_DRAW, sizeof(glm::mediump_float)*3);
}
am I overcomplicating this?
Is there an easier way?