Skip to content

Instantly share code, notes, and snippets.

@donno
Created January 18, 2021 12:05
Show Gist options
  • Save donno/dddd1fade127247800b3d0bfc3e7f572 to your computer and use it in GitHub Desktop.
Save donno/dddd1fade127247800b3d0bfc3e7f572 to your computer and use it in GitHub Desktop.
ImHex pattern file for quantized-mesh
#pragma MIME application/vnd.quantized-mesh
// This a hex pattern match for ImHex: https://github.com/WerWolv/ImHex
// Format: https://github.com/CesiumGS/quantized-mesh
struct QuantizedMeshHeader
{
// The center of the tile in Earth-centered Fixed coordinates.
double CenterX;
double CenterY;
double CenterZ;
// The minimum and maximum heights in the area covered by this tile.
// The minimum may be lower and the maximum may be higher than
// the height of any vertex in this tile in the case that the min/max vertex
// was removed during mesh simplification, but these are the appropriate
// values to use for analysis or visualization.
float MinimumHeight;
float MaximumHeight;
// The tile’s bounding sphere. The X,Y,Z coordinates are again expressed
// in Earth-centered Fixed coordinates, and the radius is in meters.
double BoundingSphereCenterX;
double BoundingSphereCenterY;
double BoundingSphereCenterZ;
double BoundingSphereRadius;
// The horizon occlusion point, expressed in the ellipsoid-scaled Earth-centered Fixed frame.
// If this point is below the horizon, the entire tile is below the horizon.
// See http://cesiumjs.org/2013/04/25/Horizon-culling/ for more information.
double HorizonOcclusionPointX;
double HorizonOcclusionPointY;
double HorizonOcclusionPointZ;
};
struct VertexData
{
u32 vertexCount;
u16 u[vertexCount];
u16 v[vertexCount];
u16 height[vertexCount];
};
struct IndexData16
{
u32 triangleCount;
u16 indices[triangleCount * 3];
};
struct IndexData32
{
u32 triangleCount;
u32 indices[triangleCount * 3];
};
struct EdgeIndices16
{
u32 westVertexCount;
u16 westIndices[westVertexCount];
u32 southVertexCount;
u16 southIndices[southVertexCount];
u32 eastVertexCount;
u16 eastIndices[eastVertexCount];
u32 northVertexCount;
u16 northIndices[northVertexCount];
};
struct EdgeIndices32
{
u32 westVertexCount;
u32 westIndices[westVertexCount];
u32 southVertexCount;
u32 southIndices[southVertexCount];
u32 eastVertexCount;
u32 eastIndices[eastVertexCount];
u32 northVertexCount;
u32 northIndices[northVertexCount];
};
// Extension data may follow to supplement the quantized-mesh with additional
// information. Each extension begins with an ExtensionHeader, consisting of a
// unique identifier and the size of the extension data in bytes.
struct ExtensionHeader
{
u8 extensionId;
u32 extensionLength;
};
// Extension: Oct-Encoded Per-Vertex Normals (id = 1)
struct OctEncodedVertexNormals
{
u8 xy[vertexCount * 2];
};
// Extension: Water Mask (id = 2)
struct WaterMaskSingle
{
u8 mask;
};
struct WaterMask
{
u8 mask[256 * 256];
};
// Extension: Metadata (id = 4)
struct Metadata
{
u32 jsonLength;
char json[jsonLength];
};
struct QuantizedMesh
{
QuantizedMeshHeader header;
VertexData vertices;
if (vertices.vertexCount > 65536)
{
// Padding may be present to ensure 4 byte alignment for IndexData32.
// Handle padding [TODO]
IndexData32 indices;
EdgeIndices32 edges;
}
else
{
// Padding may be present to ensure 2 byte alignment for IndexData16.
// Handle padding [TODO]
IndexData16 indices;
EdgeIndices16 edges;
}
// This part repeats until end of file.
ExtensionHeader extension;
if (extension.extensionId == 1)
{
// Should be the following but not sure how to make the
// vertices.vertexCount accessible from there.
// OctEncodedVertexNormals normals;
u8 xy[vertices.vertexCount * 2];
}
else if (extension.extensionId == 2)
{
if (extension.extensionLength == 1)
{
WaterMaskSingle waterMask;
}
else
{
WaterMask waterMask;
}
}
else if (extension.extensionId == 4)
{
Metadata metadata;
}
else
{
// Skip over the extention we don't understand by going forward
// extension.extensionLength bytes. [TODO]
}
};
QuantizedMesh mesh @ 0x00;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment