static bool ReadBisomething(MZFile& file) { u32 bcount; V(file.Read(bcount)); for (u32 i = 0; i < bcount; ++i) { u32 bi; V(file.Read(bi)); V(file.Seek(8 * bi)); } V(file.Seek(4)); return true; }
static bool SkipVector(MZFile& file) { u32 size; V(file.Read(size)); V(file.Seek(size * sizeof(T))); return true; }
static bool LoadSubmeshData(MZFile& file, EluMesh& mesh) { u32 nsubmesh; V(file.Read(nsubmesh)); mesh.DrawProps.resize(nsubmesh); for (u32 i = 0; i < nsubmesh; ++i) { auto& dp = mesh.DrawProps[i]; u32 mat; V(file.Read(mat)); dp.material = mat; u16 idx; V(file.Read(idx)); dp.indexBase = idx; u16 cnt; V(file.Read(cnt)); dp.count = cnt; dp.vertexBase = 0; V(file.Seek(4)); if (dp.material < 0) { if (mesh.DrawProps.size() == 1) { mesh.DrawProps.clear(); return true; } mesh.DrawProps.erase(mesh.DrawProps.begin() + i); mesh.DrawProps.resize(mesh.DrawProps.size() - 1); --i; } } return true; }
static bool ReadSubindices(MZFile& file, std::vector<std::array<u16, 6>>& subindices) { V(ReadVector(file, subindices)); u32 size; V(file.Read(size)); V(file.Seek((64 + 2) * size)); return true; }
static bool ReadIndices(MZFile& file) { u32 ntris; V(file.Read(ntris)); if (ntris > 0) { V(file.Seek(4)); V(file.Read(ntris)); for (u32 i = 0; i < ntris; ++i) { u32 nverts; V(file.Read(nverts)); V(file.Seek(12 * nverts + 2)); } } V(SkipVector<v3>(file)); V(file.Seek(4)); return true; }
static bool LoadMesh5013(MZFile& file, EluMesh &mesh) { V(ReadName(file, mesh)); V(file.Seek(4)); V(SkipVector<char>(file)); V(ReadWorld(file, mesh)); V(file.Seek(16)); VertexData vertexData; V(ReadVertexData(file, mesh, vertexData, { Pos, Tex, SkipVecV3, Nor, Tan, SkipVecV3 })); V(ReadIndices(file)); V(ReadBisomething(file)); std::vector<std::array<u16, 6>> subindices; V(ReadSubindices(file, subindices)); V(LoadSubmeshData(file, mesh)); V(ReadMeshData(file, mesh, subindices, vertexData)); V(file.Seek(2 * sizeof(v3))); return true; }
static bool ReadVertexData(MZFile& file, EluMesh& mesh, VertexData& data, const VertexAttributeOrder (&Order)[6]) { for (auto& Attribute : Order) { switch (Attribute) { case Pos: V(ReadVector(file, data.Positions)); break; case Nor: V(ReadVector(file, data.Normals)); break; case Tan: V(ReadVector(file, data.Tangents)); break; case Tex: V(ReadVector(file, data.TexCoords)); break; case Skip4: V(file.Seek(4)); break; case SkipVecV3: V(SkipVector<v3>(file)); break; } } return true; }