| 6 | |
| 7 | |
| 8 | SkyRenderer::SkyRenderer(const shared_ptr<ONFSTrack> &activeTrack) { |
| 9 | // Load track HRZ parameters into shader |
| 10 | loadTextures(); |
| 11 | |
| 12 | // Load OBJ Model |
| 13 | tinyobj::attrib_t attrib; |
| 14 | std::vector<tinyobj::shape_t> shapes; |
| 15 | std::vector<tinyobj::material_t> materials; |
| 16 | std::string err; |
| 17 | std::string warn; |
| 18 | ASSERT(tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, "../resources/misc/skydome/sphere.obj", nullptr, true, true), err); |
| 19 | |
| 20 | // TODO: Generify the Utils loader to detect norms and uvs, else backfill with vecs of 0's |
| 21 | for (size_t s = 0; s < shapes.size(); s++) { |
| 22 | std::vector<glm::vec3> verts = std::vector<glm::vec3>(); |
| 23 | std::vector<glm::vec3> norms = std::vector<glm::vec3>(); |
| 24 | std::vector<glm::vec2> uvs = std::vector<glm::vec2>(); |
| 25 | std::vector<unsigned int> indices = std::vector<unsigned int>(); |
| 26 | // Loop over faces(polygon) |
| 27 | size_t index_offset = 0; |
| 28 | for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++) { |
| 29 | int fv = shapes[s].mesh.num_face_vertices[f]; |
| 30 | // Loop over vertices in the face. |
| 31 | for (size_t v = 0; v < fv; v++) { |
| 32 | // access to vertex |
| 33 | tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v]; |
| 34 | indices.emplace_back((const unsigned int &) idx.vertex_index); |
| 35 | verts.emplace_back(glm::vec3(attrib.vertices[3 * idx.vertex_index + 0] * 400, attrib.vertices[3 * idx.vertex_index + 1] * 400, attrib.vertices[3 * idx.vertex_index + 2] * 400)); |
| 36 | norms.emplace_back(glm::vec3(0.f, 0.f, 0.f)); // Fill the sphere attribs with empty data as missing |
| 37 | uvs.emplace_back(glm::vec2(0.0f, 0.0f)); |
| 38 | } |
| 39 | index_offset += fv; |
| 40 | // per-face material |
| 41 | shapes[s].mesh.material_ids[f]; |
| 42 | } |
| 43 | skydome = CarModel(shapes[s].name + "_obj", verts, uvs, norms, indices, glm::vec3(0, 0, 0), 0.01f, 0.0f, 0.5f); |
| 44 | break; |
| 45 | } |
| 46 | skydome.enable(); |
| 47 | skydome.update(); |
| 48 | } |
| 49 | |
| 50 | void SkyRenderer::loadTextures() { |
| 51 | std::string clouds1_texture_path("../resources/misc/skydome/clouds1.tga"); |