上篇:3dTile技术研究-概念详述(8)Feature Table
注意Batch Table是定义程序相关的属性,它是可选的。
Batch Table是一个tile的二进制内容体的一个组件(组成部分),并且它包含了tile中的每一个对象(per-feature)特定于程序的属性。这些属性在运行时被查询,为了声明式样式和任何特定于程序的场景,比如填充UI或是发起REST API请求。一些示例的Batch Table属性是建筑高度,地理坐标和数据库主键。
Batch Table被下面的tile格式使用:
一个Batch Table由两部分组成:一个JSON标头和一个可选小端方式(little endian)存储的二进制体。这个JSON描述了这些属性,其中属性值既可以在JSON中直接以数组定义,也可以引用二进制体的内容部分。在二进制体中存储长数值型数组是很高效的。下面的图形显示了Batch Table的布局。
当tile格式(比如i3dm、b3dm、pnts)包含了Batch Table,Batch Table要紧跟在tile的Feature Table后面。标头部分也会包含batchTableJSONByteLength
和batchTableBinaryByteLength
uint32
和的字段,它们可以被用来解析Batch Table的各部分。
JSON标头必须在包含的tile二进制文件内的8字节边界处结束。JSON标头必须用尾随空格字符(0x20
)填充才能满足此要求。
二进制体必须在包含的tile二进制文件内的8字节边界处开始和结束。为了满足此要求,必须用任意值的附加字节来填充二进制主体。
二进制属性必须以一个字节偏移量开始,该字节偏移量是componentType
类型属性的字节大小的倍数。例如,FLOAT
组件类型的属性每个元素有4个字节,因此开始位置的偏移量必须是4的倍数。为了满足此要求,必须在前面的二进制属性中填充其他任意值的字节。
Batch Table的值可以以两种不同的方式出现在JSON表头中:
"name" : ['name1', 'name2', 'name3']
or "height" : [10.0, 20.0, 15.0]
.
batchLength
相等,batchLength
在每个tile格式中都有指定。这是tile中包含的对象(features)的数量。比如,batchLength
可以是一个b3dm的tile中的模型(构件)数量,也可以是一个i3dm的tile中的实例数量,也可以是一个pnts的tile中的点数量(或者对象数量)。tile格式指i3dm、b3dm、pnts,比如下面的b3dm示例中指定了
batchLength
,
byteOffset
、componentType
和type
属性的对象表示,比如"height" : { "byteOffset" : 24, "componentType" : "FLOAT", "type" : "SCALAR"}。
byteOffset
指定了一个从0开始的相对于二进制体开始位置的偏移。byteOffset
的值必须是componentType
类型的属性的字节大小的倍数,比如,一个 FLOAT
类型的属性的byteOffset
值必须是4的倍数。componentType
是属性中元素的数据类型。允许的值是 "BYTE"
, "UNSIGNED_BYTE"
, "SHORT"
, "UNSIGNED_SHORT"
, "INT"
, "UNSIGNED_INT"
, "FLOAT"
, 和 "DOUBLE"。
type
指定了属性是标量还是列表。允许的值是"SCALAR"
, "VEC2"
, "VEC3"
, and "VEC4"。
Batch Table JSON是包含UTF-8
字符串的JSON。
实现注意项:在JavaScript中,Batch Table JSON的
ArrayBuffer
可以使用TextDecoder
JavaScript API 来解析,可以使用JSON.parse
转换为JavaScript对象。
A batchId
is used to access elements in each array and extract the corresponding properties. For example, the following Batch Table has properties for a batch of two features:
batchId
可以被用来访问每个数组中的元素,然后解析对应的属性。比如,下面的Batch Table包含一个有两个对象(features)的batch的属性:
{
"id" : ["unique id", "another unique id"],
"displayName" : ["Building name", "Another building name"],
"yearBuilt" : [1999, 2015],
"address" : [{"street" : "Main Street", "houseNumber" : "1"}, {"street" : "Main Street", "houseNumber" : "2"}]
}
batchId = 0
对应的对象( feature)的属性是:
id[0] = 'unique id';
displayName[0] = 'Building name';
yearBuilt[0] = 1999;
address[0] = {street : 'Main Street', houseNumber : '1'};
batchId = 1
对应的对象的属性是:
id[1] = 'another unique id';
displayName[1] = 'Another building name';
yearBuilt[1] = 2015;
address[1] = {street : 'Main Street', houseNumber : '2'};
See Property reference for the full JSON header schema reference. The full JSON schema can be found in batchTable.schema.json.
当JSON表头包含了指向二进制体部分的引用时,提供的 byteOffset
被用来索引数据,像下面图片中展示的那样:
可以使用batchLength
(标识了对象的数量),batchId
(期望的batch的id)和JSON标头中定义的 componentType
和type
来获取数据值。
下面的表可以用来计算属性的字节大小。
下面的扩展可以应用于Batch Table。
本章节是非规范性的
下面的示例分别获取了下面的batchLength
为10的Batch Table JSON的"height"
和"geographic"
值:
{
"height" : {
"byteOffset" : 0,
"componentType" : "FLOAT",
"type" : "SCALAR"
},
"geographic" : {
"byteOffset" : 40,
"componentType" : "DOUBLE",
"type" : "VEC3"
}
}
为了获取"height"值:
var height = batchTableJSON.height;
var byteOffset = height.byteOffset;
var componentType = height.componentType;
var type = height.type;
var heightArrayByteLength = batchLength * sizeInBytes(componentType) * numberOfComponents(type); // 10 * 4 * 1
var heightArray = new Float32Array(batchTableBinary.buffer, byteOffset, heightArrayByteLength);
var heightOfFeature = heightArray[batchId];
为了获取"geographic"值:
var geographic = batchTableJSON.geographic;
var byteOffset = geographic.byteOffset;
var componentType = geographic.componentType;
var type = geographic.type;
var componentSizeInBytes = sizeInBytes(componentType)
var numberOfComponents = numberOfComponents(type);
var geographicArrayByteLength = batchLength * componentSizeInBytes * numberOfComponents // 10 * 8 * 3
var geographicArray = new Float64Array(batchTableBinary.buffer, byteOffset, geographicArrayByteLength);
var geographicOfFeature = positionArray.subarray(batchId * numberOfComponents, batchId * numberOfComponents + numberOfComponents); // Using subarray creates a view into the array, and not a new array.
在CesiumJS实现的3D Tiles中的Cesium3DTileBatchTable.js
中可以找到读取Batch Table的代码。
Batch Table是定义程序相关的属性,如业务上的功能:需要选择构件,由于3D Tiles中没有构件,那么就需要在Batch Table中定义属性来使得在运行时可以获取到构件相关的数据来达到构件选择的目的。
传送:
3dTile技术研究-开篇
3dTile技术研究-概述
3dTile技术研究-概念详述(1)
3dTile技术研究-概念详述(2)
3dTile技术研究-概念详述(3)
3dTile技术研究-概念详述(4)
3dTile技术研究-概念详述(5)
3dTile技术研究-概念详述(6)
3dTile技术研究-概念详述(7)Batched 3D Model
3dTile技术研究-概念详述(8)Feature Table