Because I got a PM of a user and still not able to PM him back (10 Post rule olol)... Here is my answer:
Greetings.
I am also parsing terrain data, and I'm curious..
Did you get MH2O working completely?
I'm having a bit of difficulty determining when to use which render mask. Any thoughts?
Yeah i got it, it's not as hard as I thought... the render mask is a byte array of 64 bitflags (-> 8 bytes). You might know that they determine if to render water in one of the 64 tiles (9x9 vertices with 8x8 tiles between). So all you need to do is to only override the green terrain vertices if the render flag says so. If it is the case, you have to get the corresponding water height of the heightmap (64 floats for each tile iirc) and then override the vertices in the corners of the tile (NW, NE, SW, SE). I got solved that like this:
Code:
for(int row = 0; row < 8; row++)
{
for(int col = 0; col < 8; col++)
{
if((render[row] & 1 << (7-col)) != 0)
{
VertexPositionColor NW = positionList[row * 9 + col]; // Get currentMCNK vertex, there are 9 per row
NW.Color = Color.Blue;
// But there are only 8 floats per row for each tile in between the vertices
NW.Position.Z = heightmap[row * 8 + col]; // Z is up for me, in MPQNav it's Y
positionList[row * 9 + col] = NW;
VertexPositionColor NE = positionList[row * 9 + col + 1];
NE.Color = Color.Blue;
NE.Position.Z = heightmap[row * 8 + col];
positionList[row * 9 + col + 1] = NE;
// continue for SW and SE with (row+1)*8
}
}
}
In my own code, I only iterate from xOffset to xOffset + width in col and from yOffset to yOffset + height in rows from the MH2OInfo chunk. Sometimes it looks a bit awkward, with edged rivers and so on, bur for now... it's enough for me^^ to be continued :P
P.S.: try the SVN on the MPQNav blog, it's an updated version, I'm currently learning form it...
EDIT: As I refactored my own project and compared with the "real" MPQNav, I found out that the bitflags are not always present. There are only MH2OInfo.height bytes in that array, you have to either fill the rest with 0x00 or care for that in my given code. You got wrong data because you maybe read to far and got into the heightmap part ( they follow each after another, test it with breakpoints and test the difference of MH2OInfo.ofsHeightMap and MH2OInfo.ofsMask2). It may confuse you even more to read that... I'm just about to figure it out, so pm me/post here if you want to know it
EDIT2: Ok, in MPQNav the MH2OInfo.ofsMask2 is dereferenced for getting to the bit mask. That's much more work than only use MH2OHeader.Render, which points to an 8-byte array. If it does not, (if(MH2OHeader.Render == 0)), you may render the whole mcnk with water(resulting in an 8 byte array bit 0xFF elements). The same goes for a bit mask with only 0x00 if the MH2OInfo.width or MH2OInfo.height not 0:
Code:
if(RenderMask.All(b => b == 0) && ((MH2OInfo.width != 0) || (MH2OInfo.height != 0))) )
which is interpreted same as a Mask for a missing MH2OHeader.Render offset.
Something similar happens to the HeightMap. There are always only as much values given as needed for the liquid rectangle(MH2OInfo.yOffset, .xOffset, height, width). So you only get an array of HeightMap[height+1][width+1] (for a 4*3 rect you need 5*4 vertices). You need to care for special cases (such as MH2OInfo.ofsHeightMap == 0 and so on, similar to the rendermask) explained in the WoWDev article below.
Hope you understood, but don't think so 
take WoWDev as reference, the explanation helped me a lot:
http://www.madx.dk/wowdev/wiki/index..._Header.Render
One thing for when you got it: It really does not look that much pretty for me... rather it seems that the green "islands" and stripes in the liquids are places, where you are actually in a liquid, but still remain walkable. The result are blue patches spread along an ingame river or a shallow water.