I have been tasked to generate quantized mesh using oss. while I have achived partial sucess in that I am not able to generate tiles with watermask extention. I have read the qmesh spec that says " water mask is either 1 byte, in the case that the tile is all land or all water, or it is 256 * 256 * 1 = 65536
bytes if the tile has a mix of land and water. Each mask value is 0 for land and 255 for water." what does internal byte structure of terrain tile look like of tile with water mask extetion. If any one from community has been able to generate it on their own kindly share your experience and approch.
@Aankit_K The water mask extension comes at the end of a normal Quantized Mesh tile. To reference the structures defined in the Quantized Mesh specification, a normal Quantized Mesh tile looks like this:
struct QuantizedMeshTile {
QuantizedMeshHeader header;
VertexData vertexData;
IndexData16 indexData; // or IndexData32 if more than 65536 vertices
EdgeIndices16 edgeData; // or EdgeIndices32 if more than 65536 vertices
}
The water mask is an extension. Extensions start with the extension header, placed in the file directly after the end of the above structure:
struct ExtensionHeader
{
unsigned char extensionId;
unsigned int extensionLength;
}
Here, extensionId
is a one-byte identifier for what the extension is. The ID of the water mask extension is 2
. extensionLength
is the length of the extension data in bytes. This would be 65536
for the case where the tile is a mix of land or water, or it would be 1
for the case that the tile is all land or all water.
Then, following this extension header, you would write your data - that one byte or 65536 bytes.
So, to put it in psuedocode:
// Handle writing the quantized mesh tile as normal
writeQuantizedMeshTile();
// Write the extension ID
writeByte(2);
// Handle both types of water mask
if(isAllLand || isAllWater) {
// Write extension length
writeUint32(1);
// Write mask data
writeByte(isAllLand ? 0 : 255);
} else {
// Write extension length
writeUint32(65536);
// Write mask data
writeBytes(&mask, 65536);
}
Iād recommend taking a look at the cesium-native CesiumQuantizedMeshTerrain
library, which handles loading Quantized Mesh. This will give you an idea of how to create a Quantized Mesh tile that will be compatible with existing libraries that work with Quantized Mesh. In particular, the parseQuantizedMesh
method handles parsing the raw bytes of a tile, including the water mask extension.