| 33 | } |
| 34 | |
| 35 | bool skd::asset::SMeshCooker::Cook(SCookContext* ctx) |
| 36 | { |
| 37 | const auto outputPath = ctx->GetOutputPath(); |
| 38 | const auto assetRecord = ctx->GetAssetRecord(); |
| 39 | auto cfg = LoadConfig<SMeshCookConfig>(ctx); |
| 40 | if(cfg.vertexType == skr_guid_t{}) |
| 41 | { |
| 42 | SKR_LOG_ERROR(u8"MeshCooker: VertexType is not specified for asset %s!", ctx->GetAssetPath().c_str()); |
| 43 | return false; |
| 44 | } |
| 45 | auto gltf_data = ctx->Import<cgltf_data>(); |
| 46 | if(!gltf_data) |
| 47 | { |
| 48 | return false; |
| 49 | } |
| 50 | SKR_DEFER({ ctx->Destroy(gltf_data); }); |
| 51 | skr_mesh_resource_t mesh; |
| 52 | skr::Vector<skr::Vector<uint8_t>> blobs; |
| 53 | auto importer = static_cast<SGltfMeshImporter*>(ctx->GetImporter()); |
| 54 | mesh.install_to_ram = importer->install_to_ram; |
| 55 | mesh.install_to_vram = importer->install_to_vram; |
| 56 | if (importer->invariant_vertices) |
| 57 | { |
| 58 | CookGLTFMeshData(gltf_data, &cfg, mesh, blobs); |
| 59 | // TODO: support ram-only mode install |
| 60 | mesh.install_to_vram = true; |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | CookGLTFMeshData_SplitSkin(gltf_data, &cfg, mesh, blobs); |
| 65 | // TODO: install only pos/norm/tangent vertices |
| 66 | mesh.install_to_ram = true; |
| 67 | // TODO: support ram-only mode install |
| 68 | mesh.install_to_vram = true; |
| 69 | } |
| 70 | |
| 71 | //----- optimize mesh |
| 72 | { |
| 73 | SkrZoneScopedN("WaitOptimizeMesh"); |
| 74 | |
| 75 | // allow up to 1% worse ACMR to get more reordering opportunities for overdraw |
| 76 | const float kOverDrawThreshold = 1.01f; |
| 77 | // for (auto& prim : mesh.primitives) |
| 78 | skr::parallel_for(mesh.primitives.begin(), mesh.primitives.end(), 1, |
| 79 | [&](auto begin, auto end) |
| 80 | { |
| 81 | SkrZoneScopedN("OptimizeMesh"); |
| 82 | |
| 83 | const auto& prim = *begin; |
| 84 | auto& indices_blob = blobs[prim.index_buffer.buffer_index]; |
| 85 | const auto first_index = prim.index_buffer.first_index; |
| 86 | const auto index_stride = prim.index_buffer.stride; |
| 87 | const auto index_offset = prim.index_buffer.index_offset; |
| 88 | const auto index_count = prim.index_buffer.index_count; |
| 89 | const auto vertex_count = prim.vertex_count; |
| 90 | skr::stl_vector<uint64_t> optimized_indices; |
| 91 | optimized_indices.resize(index_count); |
| 92 | uint64_t* indices_ptr = optimized_indices.data(); |
nothing calls this directly
no test coverage detected