一个地形瓦片在quantied-mesh-1.0格式是简单的根据瓦片地图服务器(Tile Map Service (TMS))和全球大数据的多分辨率四叉树。所有的瓦片都有延伸地形,所以,瓦片的URL是:
http://assets.agi.com/stk-terrain/world/tiles
然后在这些URL种找到金智塔的两个根文件:
(-180 deg, -90 deg) - (0 deg, 90 deg) - http://assets.agi.com/stk-terrain/world/tiles/0/0/0.terrain
(0 deg, -90 deg) - (180 deg, 90 deg) - http://assets.agi.com/stk-terrain/world/tiles/0/1/0.terrain
下一层的八块瓦片在这些URL中:
(-180 deg, -90 deg) - (-90 deg, 0 deg) - http://assets.agi.com/stk-terrain/world/tiles/1/0/0.terrain
(-90 deg, -90 deg) - (0 deg, 0 deg) - http://assets.agi.com/stk-terrain/world/tiles/1/1/0.terrain
(0 deg, -90 deg) - (90 deg, 0 deg) - http://assets.agi.com/stk-terrain/world/tiles/1/2/0.terrain
(90 deg, -90 deg) - (180 deg, 0 deg) - http://assets.agi.com/stk-terrain/world/tiles/1/3/0.terrain
(-180 deg, 0 deg) - (-90 deg, 90 deg) - http://assets.agi.com/stk-terrain/world/tiles/1/0/1.terrain
(-90 deg, 0 deg) - (0 deg, 90 deg) - http://assets.agi.com/stk-terrain/world/tiles/1/1/1.terrain
(0 deg, 0 deg) - (90 deg, 90 deg) - http://assets.agi.com/stk-terrain/world/tiles/1/2/1.terrain
(90 deg, 0 deg) - (180 deg, 90 deg) - http://assets.agi.com/stk-terrain/world/tiles/1/3/1.terrain
在请求瓦片时,轻确保在亲贵中包含以下HTTP头:
Accept: application/vnd.quantized-mesh,application/octet-stream;q=0.9
否则,一些服务器可能返回一个不同的瓦片表示,而不少这里描述的。
每个瓦片的网片边缘重叠的顶点是特别编码三角网格的。换句话说,实际上,在西边瓦片中最东边的顶点和东边瓦片最西边的顶点在同一个经度上。
地形瓦片是压缩保存的。一旦提取,瓦片是 little-endian,二进制数据。文件的第一部分后具有一些格式的标题。Doubles的是IEEE 754,64为浮点数,和Floats是IEEE 754 32位浮点数。
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;
};
在头文件后面是定点数据。Unsigned interesting是32位无符号整数和unsgned short是一个16位无符号整型。
struct VertexData
{
unsigned int vertexCount;
unsigned short u[vertexCount];
unsigned short v[vertexCount];
unsigned short height[vertexCount];
};
这个vertexCount在这个三个数组中使用。这三个数组包含先前得到的delta,然后用zig-zag编码来生成小整数,不管它们的符号是什么都是使用少量的bit。
解码这个值也是很简单的:
var u = 0;var v = 0;var height = 0;
function zigZagDecode(value) {
return (value >> 1) ^ (-(value & 1));
}
for (i = 0; i < vertexCount; ++i) {
u += zigZagDecode(uBuffer[i]);
v += zigZagDecode(vBuffer[i]);
height += zigZagDecode(heightBuffer[i]);
uBuffer[i] = u;
vBuffer[i] = v;
heightBuffer[i] = height;
}
一旦解码,每个阵列的值的含义如下:
名称 | 意义 |
|
u | 在瓦片中顶点的水平坐标。当u值是0,顶点是瓦片的西边缘。当值是32767,顶点是在瓦片东边。是其他的值时,顶点的经度是瓦片东边和西边经度的线性插值。 |
|
v | 这个是顶点的垂直坐标。当这个v值是0时,顶点在瓦片的南边,当这个值是32767,顶点在瓦片的北边。其他值时,顶点的纬度是瓦片你南边和北边纬度的线性插值。 |
|
height | 在瓦片顶点的高度值。当高度值是0,顶点高度相当于瓦片的最小高度,正如在瓦片标题中指定的。当值是32767,顶点高度相当于瓦片最大高度值。如果是其他值,顶点的高度值是最大和最小的高度值的线性插值。 |
|
紧跟着顶点数据是索引数据。索引指定顶点如何连接成三角形。当瓦片有多余65536个顶点,瓦片使用IndexData32结构来编码索引。否则,使用IndexData16结构。
执行适当的字节对齐,在IndexData之前添加填充物,以确保IndexData16的2个字节和IndexData32的4个字节对齐。
struct IndexData16
{
unsigned int triangleCount;
unsigned short indices[triangleCount * 3];
}
struct IndexData32
{
unsigned int triangleCount;
unsigned int indices[triangleCount * 3];
}
索引使用来自webgl-loader的高水平标记编码,索引北解码如下:
var highest = 0;for (var i = 0; i < indices.length; ++i) {
var code = indices[i];
indices[i] = highest - code;
if (code === 0) {
++highest;
}
}
每一个索引值构成一个三角形,使用逆时针绕序。下面的三角形索引是四个指标列表:
struct EdgeIndices16
{
unsigned int westVertexCount;
unsigned short westIndices[westVertexCount];
unsigned int southVertexCount;
unsigned short southIndices[southVertexCount];
unsigned int eastVertexCount;
unsigned short eastIndices[eastVertexCount];
unsigned int northVertexCount;
unsigned short northIndices[northVertexCount];
}
struct EdgeIndices32
{
unsigned int westVertexCount;
unsigned int westIndices[westVertexCount];
unsigned int southVertexCount;
unsigned int southIndices[southVertexCount];
unsigned int eastVertexCount;
unsigned int eastIndices[eastVertexCount];
unsigned int northVertexCount;
unsigned int northIndices[northVertexCount];
}
这些索引列表列举了瓦片边缘的顶点。指定哪些顶点在边缘很有帮助的,这样就可以在相邻的细节层之间添加裙子来隐藏裂缝。