Archived
1
Fork 0

Output model as a real struct from parseMDL instead of into an obj file

This commit is contained in:
Joshua Goins 2022-04-11 21:56:10 -04:00
parent 2610de0f7f
commit f8835854a3
2 changed files with 22 additions and 23 deletions

View file

@ -6,16 +6,19 @@
struct Vertex { struct Vertex {
std::array<float, 4> position; std::array<float, 4> position;
float blendWeights[4]; };
std::vector<uint8_t> blendIndices;
float normal[3]; struct Part {
float uv[4]; std::vector<Vertex> vertices;
float color[4]; std::vector<uint16_t> indices;
float tangent2[4]; };
float tangent1[4];
struct Lod {
std::vector<Part> parts;
}; };
struct Model { struct Model {
std::vector<Lod> lods;
}; };
Model parseMDL(const std::string_view path); Model parseMDL(const std::string_view path);

View file

@ -13,7 +13,7 @@ Model parseMDL(const std::string_view path) {
throw std::runtime_error("Failed to open exh file " + std::string(path)); throw std::runtime_error("Failed to open exh file " + std::string(path));
} }
enum FileType : int32_t { enum class FileType : int32_t {
Empty = 1, Empty = 1,
Standard = 2, Standard = 2,
Model = 3, Model = 3,
@ -297,10 +297,14 @@ Model parseMDL(const std::string_view path) {
fmt::print("Now exporting as test.obj...\n"); fmt::print("Now exporting as test.obj...\n");
Model model;
// TODO: doesn't work for lod above 0 // TODO: doesn't work for lod above 0
for(int i = 0; i < modelHeader.lodCount; i++) { for(int i = 0; i < modelHeader.lodCount; i++) {
::Lod lod;
for(int j = lods[i].meshIndex; j < (lods[i].meshIndex + lods[i].meshCount); j++) { 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]; const VertexDeclaration decl = vertexDecls[j];
@ -370,28 +374,20 @@ Model parseMDL(const std::string_view path) {
break; 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); fseek(file, modelFileHeader.indexOffsets[i] + (meshes[j].startIndex * 2), SEEK_SET);
std::vector<uint16_t> indices(meshes[j].indexCount); std::vector<uint16_t> indices(meshes[j].indexCount);
fread(indices.data(), meshes[j].indexCount * sizeof(uint16_t), 1, file); fread(indices.data(), meshes[j].indexCount * sizeof(uint16_t), 1, file);
for(int k = 0; k < indices.size(); k += 3) { part.indices = indices;
unsigned short x = indices[k + 0] + 1; part.vertices = vertices;
unsigned short y = indices[k + 1] + 1;
unsigned short z = indices[k + 2] + 1;
out << "f "; lod.parts.push_back(part);
out << x << "/" << x << "/" << x << " ";
out << y << "/" << y << "/" << y << " ";
out << z << "/" << z << "/" << z << std::endl;
} }
out.close(); model.lods.push_back(lod);
}
} }
return {}; return model;
} }