天天看點

3dTile技術研究-概念詳述(9)Batch Table1. 内容(Contents)2. 概述3. 布局(Layout)4. 填充(Padding)5. JSON header6. 二進制體(Binary body)7. 擴充(Extensions)8. 樣例實作(Implementation example)9. 總結

上篇:3dTile技術研究-概念詳述(8)Feature Table

1. 内容(Contents)

  • 概述(Overview)
  • 布局(Layout)
    • Padding
    • JSON header
    • Binary body
  • 擴充(Extensions)
  • 樣例實作(Implementation example)
  • 屬性引用(Property reference)

2. 概述

注意Batch Table是定義程式相關的屬性,它是可選的。

Batch Table是一個tile的二進制内容體的一個元件(組成部分),并且它包含了tile中的每一個對象(per-feature)特定于程式的屬性。這些屬性在運作時被查詢,為了聲明式樣式和任何特定于程式的場景,比如填充UI或是發起REST API請求。一些示例的Batch Table屬性是建築高度,地理坐标和資料庫主鍵。

Batch Table被下面的tile格式使用:

  • Batched 3D Model (b3dm)
  • Instanced 3D Model (i3dm)
  • Point Cloud (pnts)

3. 布局(Layout)

一個Batch Table由兩部分組成:一個JSON标頭和一個可選小端方式(little endian)存儲的二進制體。這個JSON描述了這些屬性,其中屬性值既可以在JSON中直接以數組定義,也可以引用二進制體的内容部分。在二進制體中存儲長數值型數組是很高效的。下面的圖形顯示了Batch Table的布局。

3dTile技術研究-概念詳述(9)Batch Table1. 内容(Contents)2. 概述3. 布局(Layout)4. 填充(Padding)5. JSON header6. 二進制體(Binary body)7. 擴充(Extensions)8. 樣例實作(Implementation example)9. 總結

當tile格式(比如i3dm、b3dm、pnts)包含了Batch Table,Batch Table要緊跟在tile的Feature Table後面。标頭部分也會包含

batchTableJSONByteLength

batchTableBinaryByteLength

uint32

和的字段,它們可以被用來解析Batch Table的各部分。

4. 填充(Padding)

JSON标頭必須在包含的tile二進制檔案内的8位元組邊界處結束。JSON标頭必須用尾随空格字元(

0x20

)填充才能滿足此要求。

二進制體必須在包含的tile二進制檔案内的8位元組邊界處開始和結束。為了滿足此要求,必須用任意值的附加位元組來填充二進制主體。

二進制屬性必須以一個位元組偏移量開始,該位元組偏移量是

componentType

類型屬性的位元組大小的倍數。例如,

FLOAT

元件類型的屬性每個元素有4個位元組,是以開始位置的偏移量必須是4的倍數。為了滿足此要求,必須在前面的二進制屬性中填充其他任意值的位元組。

5. JSON header

Batch Table的值可以以兩種不同的方式出現在JSON表頭中:

  • 值的數組, 比如, 

    "name" : ['name1', 'name2', 'name3']

     or 

    "height" : [10.0, 20.0, 15.0]

    .
    • 數組元素可以是任意有效的JSON資料類型,包括對象和數組。元素可以是null。
    • 每個數組的長度和

      batchLength

      相等,

      batchLength

      在每個tile格式中都有指定。這是tile中包含的對象(features)的數量。比如,

      batchLength

      可以是一個b3dm的tile中的模型(構件)數量,也可以是一個i3dm的tile中的執行個體數量,也可以是一個pnts的tile中的點數量(或者對象數量)。
tile格式指i3dm、b3dm、pnts,比如下面的b3dm示例中指定了

batchLength

3dTile技術研究-概念詳述(9)Batch Table1. 内容(Contents)2. 概述3. 布局(Layout)4. 填充(Padding)5. JSON header6. 二進制體(Binary body)7. 擴充(Extensions)8. 樣例實作(Implementation example)9. 總結
  • 引用二進制體中的資料,用一個包含

    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對象。

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.

6. 二進制體(Binary body)

當JSON表頭包含了指向二進制體部分的引用時,提供的 

byteOffset

被用來索引資料,像下面圖檔中展示的那樣:

3dTile技術研究-概念詳述(9)Batch Table1. 内容(Contents)2. 概述3. 布局(Layout)4. 填充(Padding)5. JSON header6. 二進制體(Binary body)7. 擴充(Extensions)8. 樣例實作(Implementation example)9. 總結

可以使用

batchLength

(辨別了對象的數量),

batchId

(期望的batch的id)和JSON标頭中定義的 

componentType

type

來擷取資料值。

下面的表可以用來計算屬性的位元組大小。

3dTile技術研究-概念詳述(9)Batch Table1. 内容(Contents)2. 概述3. 布局(Layout)4. 填充(Padding)5. JSON header6. 二進制體(Binary body)7. 擴充(Extensions)8. 樣例實作(Implementation example)9. 總結

7. 擴充(Extensions)

下面的擴充可以應用于Batch Table。

  • 3DTILES_batch_table_hierarchy

8. 樣例實作(Implementation example)

本章節是非規範性的

下面的示例分别擷取了下面的

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的代碼。

9. 總結

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