Skip to content

Commit

Permalink
Fixed MLIQ parsing in alpha data
Browse files Browse the repository at this point in the history
  • Loading branch information
namreeb committed Sep 18, 2023
1 parent 2ab2ae8 commit bb4a222
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
23 changes: 18 additions & 5 deletions parser/Wmo/GroupFile/Chunks/MLIQ.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
#include "Common.hpp"
#include "Wmo/GroupFile/Chunks/MLIQ.hpp"

namespace parser
{
namespace input
{
MLIQ::MLIQ(size_t position, utility::BinaryStream* groupFileStream)
MLIQ::MLIQ(size_t position, utility::BinaryStream* groupFileStream,
unsigned int version)
: WmoGroupChunk(position, groupFileStream)
{
groupFileStream->rpos(position + 16);

Width = groupFileStream->Read<unsigned int>();
Height = groupFileStream->Read<unsigned int>();
Width = groupFileStream->Read<std::uint32_t>();
Height = groupFileStream->Read<std::uint32_t>();

groupFileStream->ReadBytes(&Base, sizeof(Base));
groupFileStream->ReadBytes(&Corner, sizeof(Corner));

// Adjustment for alpha data
if (version == 14)
{
constexpr float tileSize = MeshSettings::AdtSize / 128.f;
Corner[0] -= tileSize * Height;

auto const w = Width;
Width = Height;
Height = w;
}

groupFileStream->rpos(groupFileStream->rpos() + 2);

Heights = std::make_unique<utility::Array2d<float>>(Height + 1, Width + 1);
for (unsigned int y = 0; y <= Height; ++y)
for (unsigned int x = 0; x <= Width; ++x)
{
groupFileStream->rpos(groupFileStream->rpos() + 4); // unknown
groupFileStream->rpos(groupFileStream->rpos() + 4);
Heights->Set(y, x, groupFileStream->Read<float>());
}
}
Expand Down
5 changes: 3 additions & 2 deletions parser/Wmo/GroupFile/Chunks/MLIQ.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class MLIQ : WmoGroupChunk
unsigned int Width;
unsigned int Height;

float Base[3];
float Corner[3];
std::unique_ptr<utility::Array2d<float>> Heights;

MLIQ(size_t position, utility::BinaryStream* groupFileStream);
MLIQ(size_t position, utility::BinaryStream* groupFileStream,
unsigned int version);
};
} // namespace input
} // namespace parser
2 changes: 1 addition & 1 deletion parser/Wmo/GroupFile/WmoGroupFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void ReadWmoGroupFile(parser::input::WmoGroupFile *groupFile,
size_t mliqLocation;
groupFile->LiquidChunk.reset(
reader->GetChunkLocation("MLIQ", movtLocation, mliqLocation) ?
new parser::input::MLIQ(mliqLocation, reader) :
new parser::input::MLIQ(mliqLocation, reader, version) :
nullptr);

// we jump the reader ahead here. in the case of the alpha data, this will
Expand Down
29 changes: 15 additions & 14 deletions parser/Wmo/Wmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,28 @@ Wmo::Wmo(const std::string& path) : MpqPath(utility::lower(path))
constexpr float tileSize = MeshSettings::AdtSize / 128.f;
auto const liquidChunk = groupFiles[g]->LiquidChunk.get();

const math::Vector3 baseVector3(
liquidChunk->Base[0], liquidChunk->Base[1], liquidChunk->Base[2]);
const math::Vector3 baseVertex(liquidChunk->Corner[0],
liquidChunk->Corner[1],
liquidChunk->Corner[2]);

// process liquid chunk for the current group file
// XXX - for some reason, this works best when you ignore the height map
// and use only the base height
for (unsigned int y = 0; y < liquidChunk->Height; ++y)
for (unsigned int x = 0; x < liquidChunk->Width; ++x)
{
const math::Vector3 v1({(x + 0) * tileSize + baseVector3.X,
(y + 0) * tileSize + baseVector3.Y,
baseVector3.Z});
const math::Vector3 v2({(x + 1) * tileSize + baseVector3.X,
(y + 0) * tileSize + baseVector3.Y,
baseVector3.Z});
const math::Vector3 v3({(x + 0) * tileSize + baseVector3.X,
(y + 1) * tileSize + baseVector3.Y,
baseVector3.Z});
const math::Vector3 v4({(x + 1) * tileSize + baseVector3.X,
(y + 1) * tileSize + baseVector3.Y,
baseVector3.Z});
const math::Vector3 v1({baseVertex.X + tileSize * (x + 0),
baseVertex.Y + tileSize * (y + 0),
baseVertex.Z});
const math::Vector3 v2({baseVertex.X + tileSize * (x + 1),
baseVertex.Y + tileSize * (y + 0),
baseVertex.Z});
const math::Vector3 v3({baseVertex.X + tileSize * (x + 0),
baseVertex.Y + tileSize * (y + 1),
baseVertex.Z});
const math::Vector3 v4({baseVertex.X + tileSize * (x + 1),
baseVertex.Y + tileSize * (y + 1),
baseVertex.Z});

LiquidVertices.push_back(v1);
LiquidVertices.push_back(v2);
Expand Down

0 comments on commit bb4a222

Please sign in to comment.