From f8835854a3656f6212d647e7c7ce7c0c50c698b7 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 11 Apr 2022 21:56:10 -0400 Subject: [PATCH] Output model as a real struct from parseMDL instead of into an obj file --- include/mdlparser.h | 17 ++++++++++------- src/mdlparser.cpp | 28 ++++++++++++---------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/mdlparser.h b/include/mdlparser.h index 67891f2..71410bc 100644 --- a/include/mdlparser.h +++ b/include/mdlparser.h @@ -6,16 +6,19 @@ struct Vertex { std::array position; - float blendWeights[4]; - std::vector blendIndices; - float normal[3]; - float uv[4]; - float color[4]; - float tangent2[4]; - float tangent1[4]; +}; + +struct Part { + std::vector vertices; + std::vector indices; +}; + +struct Lod { + std::vector parts; }; struct Model { + std::vector lods; }; Model parseMDL(const std::string_view path); \ No newline at end of file diff --git a/src/mdlparser.cpp b/src/mdlparser.cpp index 78b4383..dc96a4b 100644 --- a/src/mdlparser.cpp +++ b/src/mdlparser.cpp @@ -13,7 +13,7 @@ Model parseMDL(const std::string_view path) { throw std::runtime_error("Failed to open exh file " + std::string(path)); } - enum FileType : int32_t { + enum class FileType : int32_t { Empty = 1, Standard = 2, Model = 3, @@ -297,10 +297,14 @@ Model parseMDL(const std::string_view path) { fmt::print("Now exporting as test.obj...\n"); + Model model; + // TODO: doesn't work for lod above 0 for(int i = 0; i < modelHeader.lodCount; i++) { + ::Lod lod; + for(int j = lods[i].meshIndex; j < (lods[i].meshIndex + lods[i].meshCount); j++) { - std::ofstream out(fmt::format("lod{}_part{}.obj", i, j)); + Part part; const VertexDeclaration decl = vertexDecls[j]; @@ -370,28 +374,20 @@ Model parseMDL(const std::string_view path) { break; } } - - out << "v " << vertices[k].position[0] << " " << vertices[k].position[1] << " " << vertices[k].position[2] << std::endl; } fseek(file, modelFileHeader.indexOffsets[i] + (meshes[j].startIndex * 2), SEEK_SET); std::vector indices(meshes[j].indexCount); fread(indices.data(), meshes[j].indexCount * sizeof(uint16_t), 1, file); - for(int k = 0; k < indices.size(); k += 3) { - unsigned short x = indices[k + 0] + 1; - unsigned short y = indices[k + 1] + 1; - unsigned short z = indices[k + 2] + 1; + part.indices = indices; + part.vertices = vertices; - out << "f "; - out << x << "/" << x << "/" << x << " "; - out << y << "/" << y << "/" << y << " "; - out << z << "/" << z << "/" << z << std::endl; - } - - out.close(); + lod.parts.push_back(part); } + + model.lods.push_back(lod); } - return {}; + return model; } \ No newline at end of file