mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 23:17:28 +00:00
fix raw reading
This commit is contained in:
parent
cefdfc696a
commit
fe6be21008
@ -32,13 +32,15 @@ RawFile::RawFile(std::string fileName) {
|
|||||||
m_Chunks.push_back(chunk);
|
m_Chunks.push_back(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_FinalMesh = new RawMesh();
|
||||||
|
|
||||||
this->GenerateFinalMeshFromChunks();
|
this->GenerateFinalMeshFromChunks();
|
||||||
}
|
}
|
||||||
|
|
||||||
RawFile::~RawFile() {
|
RawFile::~RawFile() {
|
||||||
delete m_FinalMesh;
|
if (m_FinalMesh) delete m_FinalMesh;
|
||||||
for (const auto* item : m_Chunks) {
|
for (const auto* item : m_Chunks) {
|
||||||
delete item;
|
if (item) delete item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,10 +51,14 @@ void RawFile::GenerateFinalMeshFromChunks() {
|
|||||||
for (const auto& vert : chunk->m_Mesh->m_Vertices) {
|
for (const auto& vert : chunk->m_Mesh->m_Vertices) {
|
||||||
auto tempVert = vert;
|
auto tempVert = vert;
|
||||||
|
|
||||||
tempVert.SetX(tempVert.GetX() + (chunk->m_X / 4));
|
// Scale X and Z by the chunk's position in the world
|
||||||
tempVert.SetZ(tempVert.GetZ() + (chunk->m_Z / 4));
|
// Scale Y by the chunk's heightmap scale factor
|
||||||
|
tempVert.SetX(tempVert.GetX() + (chunk->m_X / chunk->m_HeightMap->m_ScaleFactor));
|
||||||
|
tempVert.SetY(tempVert.GetY() / chunk->m_HeightMap->m_ScaleFactor);
|
||||||
|
tempVert.SetZ(tempVert.GetZ() + (chunk->m_Z / chunk->m_HeightMap->m_ScaleFactor));
|
||||||
|
|
||||||
tempVert* chunk->m_HeightMap->m_ScaleFactor;
|
// Then scale it again for some reason
|
||||||
|
tempVert *= chunk->m_HeightMap->m_ScaleFactor;
|
||||||
|
|
||||||
m_FinalMesh->m_Vertices.push_back(tempVert);
|
m_FinalMesh->m_Vertices.push_back(tempVert);
|
||||||
}
|
}
|
||||||
@ -67,16 +73,12 @@ void RawFile::GenerateFinalMeshFromChunks() {
|
|||||||
|
|
||||||
void RawFile::WriteFinalMeshToOBJ(std::string path) {
|
void RawFile::WriteFinalMeshToOBJ(std::string path) {
|
||||||
std::ofstream file(path);
|
std::ofstream file(path);
|
||||||
std::string vertData;
|
|
||||||
|
|
||||||
for (const auto& v : m_FinalMesh->m_Vertices) {
|
for (const auto& v : m_FinalMesh->m_Vertices) {
|
||||||
vertData += "v " + std::to_string(v.x) + " " + std::to_string(v.y) + " " + std::to_string(v.z) + "\n";
|
file << "v " << v.x << ' ' << v.y << ' ' << v.z << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < m_FinalMesh->m_Triangles.size(); i += 3) {
|
for (int i = 0; i < m_FinalMesh->m_Triangles.size(); i += 3) {
|
||||||
vertData += "f " + std::to_string(*std::next(m_FinalMesh->m_Triangles.begin(), i) + 1) + " " + std::to_string(*std::next(m_FinalMesh->m_Triangles.begin(), i + 1) + 1) + " " + std::to_string(*std::next(m_FinalMesh->m_Triangles.begin(), i + 2) + 1) + "\n";
|
file << "f " << *std::next(m_FinalMesh->m_Triangles.begin(), i) + 1 << ' ' << *std::next(m_FinalMesh->m_Triangles.begin(), i + 1) + 1 << ' ' << *std::next(m_FinalMesh->m_Triangles.begin(), i + 2) + 1 << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
file.write(vertData.c_str(), vertData.size());
|
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
|
@ -24,5 +24,5 @@ private:
|
|||||||
uint32_t m_Height;
|
uint32_t m_Height;
|
||||||
|
|
||||||
std::vector<RawChunk*> m_Chunks;
|
std::vector<RawChunk*> m_Chunks;
|
||||||
RawMesh* m_FinalMesh;
|
RawMesh* m_FinalMesh = nullptr;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user