| 655 | } |
| 656 | |
| 657 | std::vector<TrackBlock> NFS4::ParseTRKModels(const std::shared_ptr<TRACK> &track) { |
| 658 | std::vector<TrackBlock> track_blocks = std::vector<TrackBlock>(); |
| 659 | 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. |
| 660 | |
| 661 | /* TRKBLOCKS - BASE TRACK GEOMETRY */ |
| 662 | for (uint32_t i = 0; i < track->nBlocks; i++) { |
| 663 | // Get Verts from Trk block, indices from associated polygon block |
| 664 | TRKBLOCK trk_block = track->trk[i]; |
| 665 | POLYGONBLOCK polygon_block = track->poly[i]; |
| 666 | TrackBlock current_track_block(i, rotationMatrix * glm::vec3(trk_block.ptCentre.x / 10, trk_block.ptCentre.y / 10, trk_block.ptCentre.z / 10)); |
| 667 | glm::vec3 trk_block_center = rotationMatrix * glm::vec3(0, 0, 0); |
| 668 | |
| 669 | // Light sources |
| 670 | for (uint32_t j = 0; j < trk_block.nLightsrc; j++) { |
| 671 | glm::vec3 light_center = rotationMatrix * glm::vec3((trk_block.lightsrc[j].refpoint.x / 65536.0) / 10, |
| 672 | (trk_block.lightsrc[j].refpoint.y / 65536.0) / 10, |
| 673 | (trk_block.lightsrc[j].refpoint.z / 65536.0) / 10); |
| 674 | current_track_block.lights.emplace_back(Entity(i, j, NFS_4, LIGHT, MakeLight(light_center, trk_block.lightsrc[j].type))); |
| 675 | } |
| 676 | |
| 677 | for (uint32_t s = 0; s < trk_block.nSoundsrc; s++) { |
| 678 | glm::vec3 sound_center = rotationMatrix * glm::vec3((trk_block.soundsrc[s].refpoint.x / 65536.0) / 10, |
| 679 | (trk_block.soundsrc[s].refpoint.y / 65536.0) / 10, |
| 680 | (trk_block.soundsrc[s].refpoint.z / 65536.0) / 10); |
| 681 | current_track_block.sounds.emplace_back(Entity(i, s, NFS_4, SOUND, Sound(sound_center, trk_block.soundsrc[s].type))); |
| 682 | } |
| 683 | |
| 684 | // Get Object vertices |
| 685 | std::vector<glm::vec3> obj_verts; |
| 686 | std::vector<glm::vec4> obj_shading_verts; |
| 687 | for (uint32_t v = 0; v < trk_block.nObjectVert; v++) { |
| 688 | 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)); |
| 689 | uint32_t shading_data = trk_block.unknVertices[v]; |
| 690 | 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)); |
| 691 | } |
| 692 | // 4 OBJ Poly blocks |
| 693 | for (uint32_t j = 0; j < 4; j++) { |
| 694 | OBJPOLYBLOCK obj_polygon_block = polygon_block.obj[j]; |
| 695 | if (obj_polygon_block.n1 > 0) { |
| 696 | // Iterate through objects in objpoly block up to num objects |
| 697 | for (uint32_t k = 0; k < obj_polygon_block.nobj; k++) { |
| 698 | //TODO: Animated objects here, obj_polygon_block.types |
| 699 | // Mesh Data |
| 700 | std::vector<unsigned int> vertex_indices; |
| 701 | std::vector<glm::vec2> uvs; |
| 702 | std::vector<unsigned int> texture_indices; |
| 703 | std::vector<glm::vec3> norms; |
| 704 | FLOATPT norm_floatpt = {0.f, 0.f, 0.f}; |
| 705 | // Get Polygons in object |
| 706 | LPPOLYGONDATA object_polys = obj_polygon_block.poly[k]; |
| 707 | for (uint32_t p = 0; p < obj_polygon_block.numpoly[k]; p++) { |
| 708 | TEXTUREBLOCK texture_for_block = track->texture[object_polys[p].texture]; |
| 709 | Texture gl_texture = track->textures[texture_for_block.texture]; |
| 710 | |
| 711 | 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]])); |
| 712 | norms.emplace_back(normal); |
| 713 | norms.emplace_back(normal); |
| 714 | norms.emplace_back(normal); |
nothing calls this directly
no test coverage detected