Mesh* MeshBuilder::GenerateOBJ(const std::string &meshName, const std::string &file_path) { //Read vertices, texcoords & normals from OBJ std::vector<Position> vertices; std::vector<TexCoord> uvs; std::vector<Vector3> normals; bool success = LoadOBJ(file_path.c_str(), vertices, uvs, normals); if (!success) return NULL; //Index the vertices, texcoords & normals properly std::vector<Vertex> vertex_buffer_data; std::vector<GLuint> index_buffer_data; IndexVBO(vertices, uvs, normals, index_buffer_data, vertex_buffer_data); //Create the mesh and call glBindBuffer, glBufferData //Use triangle list and remember to set index size Mesh *mesh = new Mesh(meshName); glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer); glBufferData(GL_ARRAY_BUFFER, vertex_buffer_data.size()*sizeof(Vertex), &vertex_buffer_data[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, mesh->indexBuffer); glBufferData(GL_ARRAY_BUFFER, index_buffer_data.size()*sizeof(GLuint), &index_buffer_data[0], GL_STATIC_DRAW); mesh->indexSize = index_buffer_data.size(); mesh->mode = Mesh::DRAW_TRIANGLES; return mesh; }
Mesh* MeshBuilder::GenerateOBJ(const std::string &meshName, const std::string &file_path) { std::vector<Position> vertices; std::vector<TexCoord> uvs; std::vector<Vector3> normals; bool success = LoadOBJ(file_path.c_str(), vertices, uvs, normals); if (!success) return NULL; std::vector<Vertex> vertex_buffer_data; std::vector<GLuint> index_buffer_data; IndexVBO(vertices, uvs, normals, index_buffer_data, vertex_buffer_data); Mesh *mesh = new Mesh(meshName); mesh->mode = Mesh::DRAW_TRIANGLES; glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer); glBufferData(GL_ARRAY_BUFFER, vertex_buffer_data.size() * sizeof(Vertex), &vertex_buffer_data[0], GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_buffer_data.size() * sizeof(GLuint), &index_buffer_data[0], GL_STATIC_DRAW); mesh->indexSize = index_buffer_data.size(); return mesh; }
Mesh* MeshBuilder::GenerateOBJ(const std::string &meshName, const std::string &file_path) { //Read vertices, texcoords & normals from OBJ std::vector<Position> vertices; std::vector<TexCoord> uvs; std::vector<Vector3> normals; bool success = LoadOBJ(file_path.c_str(), vertices, uvs, normals); if (!success) return NULL; //Index the vertices, texcoords & normals properly std::vector<Vertex> vertex_buffer_data; std::vector<GLuint> index_buffer_data; for (size_t i = 0; i < vertex_buffer_data.size(); ++i) { index_buffer_data.push_back(i); } ////verticeNum = &vertices; Position maxPos = Position(0, 0, 0); // Vector for max pos Position minPos = Position(0, 0, 0); // Vector for min pos Position * posPtr1 = 0; for (size_t i = 0; i < vertices.size(); ++i) { posPtr1 = &vertices[i]; if (posPtr1->x > maxPos.x) { maxPos.x = posPtr1->x; } if (posPtr1->x < minPos.x) { minPos.x = posPtr1->x; } if (posPtr1->y > maxPos.y) { maxPos.y = posPtr1->y; } if (posPtr1->y < minPos.y) { minPos.y = posPtr1->y; } if (posPtr1->z > maxPos.z) { maxPos.z = posPtr1->z; } if (posPtr1->z < minPos.z) { minPos.z = posPtr1->z; } } maxPos.x += 0.1f; maxPos.y += 0.1f; maxPos.z += 0.1f; minPos.x -= 0.1f; minPos.y -= 0.1f; minPos.z -= 0.1f; IndexVBO(vertices, uvs, normals, index_buffer_data, vertex_buffer_data); //Create the mesh and call glBindBuffer, glBufferData //Use triangle list and remember to set index size Mesh *mesh = new Mesh(meshName); glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer); glBufferData(GL_ARRAY_BUFFER, vertex_buffer_data.size() * sizeof(Vertex), &vertex_buffer_data[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, mesh->indexBuffer); glBufferData(GL_ARRAY_BUFFER, index_buffer_data.size() * sizeof(GLuint), &index_buffer_data[0], GL_STATIC_DRAW); mesh->indexSize = index_buffer_data.size(); mesh->mode = Mesh::DRAW_TRIANGLES; mesh->maxPos = maxPos; mesh->minPos = minPos; return mesh; }