| 420 | } |
| 421 | |
| 422 | std::vector<TrackBlock> NFS3::ParseTRKModels(const std::shared_ptr<TRACK> &track) { |
| 423 | LOG(INFO) << "Parsing TRK file into ONFS GL structures"; |
| 424 | |
| 425 | std::vector<TrackBlock> track_blocks = std::vector<TrackBlock>(); |
| 426 | glm::quat rotationMatrix = glm::normalize(glm::quat(glm::vec3(-SIMD_PI/2,0,0))); // All Vertices are stored so that the model is rotated 90 degs on X. Remove this at Vert load time. |
| 427 | |
| 428 | /* TRKBLOCKS - BASE TRACK GEOMETRY */ |
| 429 | for (uint32_t i = 0; i < track->nBlocks; i++) { |
| 430 | // Get Verts from Trk block, indices from associated polygon block |
| 431 | TRKBLOCK trk_block = track->trk[i]; |
| 432 | POLYGONBLOCK polygon_block = track->poly[i]; |
| 433 | TrackBlock current_track_block(i, rotationMatrix * glm::vec3(trk_block.ptCentre.x/ 10, trk_block.ptCentre.y/ 10, trk_block.ptCentre.z/ 10)); |
| 434 | glm::vec3 trk_block_center = rotationMatrix * glm::vec3(0, 0, 0); |
| 435 | |
| 436 | // Light sources |
| 437 | for (uint32_t j = 0; j < trk_block.nLightsrc; j++) { |
| 438 | glm::vec3 light_center = rotationMatrix * glm::vec3((trk_block.lightsrc[j].refpoint.x / 65536.0) / 10, |
| 439 | (trk_block.lightsrc[j].refpoint.y / 65536.0) / 10, |
| 440 | (trk_block.lightsrc[j].refpoint.z / 65536.0) / 10); |
| 441 | current_track_block.lights.emplace_back(Entity(i, j, NFS_3, LIGHT, MakeLight(light_center, trk_block.lightsrc[j].type))); |
| 442 | } |
| 443 | |
| 444 | for (uint32_t s = 0; s < trk_block.nSoundsrc; s++) { |
| 445 | glm::vec3 sound_center = rotationMatrix * glm::vec3((trk_block.soundsrc[s].refpoint.x / 65536.0) / 10, |
| 446 | (trk_block.soundsrc[s].refpoint.y / 65536.0) / 10, |
| 447 | (trk_block.soundsrc[s].refpoint.z / 65536.0) / 10); |
| 448 | current_track_block.sounds.emplace_back(Entity(i, s, NFS_3, SOUND, Sound(sound_center, trk_block.soundsrc[s].type))); |
| 449 | } |
| 450 | |
| 451 | // Get Object vertices |
| 452 | std::vector<glm::vec3> obj_verts; |
| 453 | std::vector<glm::vec4> obj_shading_verts; |
| 454 | for (uint32_t v = 0; v < trk_block.nObjectVert; v++) { |
| 455 | obj_verts.emplace_back(rotationMatrix * glm::vec3(trk_block.vert[v].x / 10, trk_block.vert[v].y / 10, trk_block.vert[v].z / 10)); |
| 456 | uint32_t shading_data = trk_block.unknVertices[v]; |
| 457 | obj_shading_verts.emplace_back(glm::vec4(((shading_data >> 16) & 0xFF) / 255.0f, ((shading_data >> 8) & 0xFF) / 255.0f, (shading_data & 0xFF) / 255.0f, ((shading_data >> 24) & 0xFF) / 255.0f)); |
| 458 | } |
| 459 | // 4 OBJ Poly blocks |
| 460 | for (uint32_t j = 0; j < 4; j++) { |
| 461 | OBJPOLYBLOCK obj_polygon_block = polygon_block.obj[j]; |
| 462 | if (obj_polygon_block.n1 > 0) { |
| 463 | // Iterate through objects in objpoly block up to num objects |
| 464 | for (uint32_t k = 0; k < obj_polygon_block.nobj; k++) { |
| 465 | //TODO: Animated objects here, obj_polygon_block.types |
| 466 | // Mesh Data |
| 467 | std::vector<unsigned int> vertex_indices; |
| 468 | std::vector<glm::vec2> uvs; |
| 469 | std::vector<unsigned int> texture_indices; |
| 470 | std::vector<glm::vec3> norms; |
| 471 | FLOATPT norm_floatpt = {0.f, 0.f, 0.f}; |
| 472 | // Get Polygons in object |
| 473 | LPPOLYGONDATA object_polys = obj_polygon_block.poly[k]; |
| 474 | for (uint32_t p = 0; p < obj_polygon_block.numpoly[k]; p++) { |
| 475 | TEXTUREBLOCK texture_for_block = track->texture[object_polys[p].texture]; |
| 476 | Texture gl_texture = track->textures[texture_for_block.texture]; |
| 477 | |
| 478 | glm::vec3 normal = rotationMatrix * calculateQuadNormal( pointToVec(trk_block.vert[object_polys[p].vertex[0]]), pointToVec(trk_block.vert[object_polys[p].vertex[1]]), pointToVec(trk_block.vert[object_polys[p].vertex[2]]), pointToVec(trk_block.vert[object_polys[p].vertex[3]])); |
| 479 | norms.emplace_back(normal); |
nothing calls this directly
no test coverage detected