@loaders.gl/3d-tiles 4.2.0-alpha.3 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +66 -41
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +26 -16
- package/dist/3d-tiles-archive-loader.js +26 -15
- package/dist/cesium-ion-loader.js +34 -30
- package/dist/dist.dev.js +1963 -1037
- package/dist/dist.min.js +32 -0
- package/dist/index.cjs +122 -337
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
- package/dist/lib/classes/tile-3d-batch-table.js +232 -217
- package/dist/lib/classes/tile-3d-feature-table.js +62 -59
- package/dist/lib/constants.js +19 -15
- package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
- package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
- package/dist/lib/encoders/encode-3d-tile.js +23 -19
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
- package/dist/lib/ion/ion.js +55 -54
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
- package/dist/lib/parsers/helpers/parse-utils.js +19 -14
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
- package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
- package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile.js +24 -24
- package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
- package/dist/lib/utils/s2/index.d.ts +7 -7
- package/dist/lib/utils/s2/index.d.ts.map +1 -1
- package/dist/lib/utils/s2/index.js +3 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
- package/dist/lib/utils/s2/s2-token-functions.js +51 -22
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
- package/dist/lib/utils/version.js +4 -2
- package/dist/tile-3d-subtree-loader.d.ts +1 -1
- package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
- package/dist/tile-3d-subtree-loader.js +15 -10
- package/dist/tile-3d-writer.js +19 -14
- package/dist/tiles-3d-loader.js +65 -55
- package/dist/types.js +3 -1
- package/package.json +11 -10
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
- package/dist/3d-tiles-archive-loader.js.map +0 -1
- package/dist/cesium-ion-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
- package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
- package/dist/lib/ion/ion.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
- package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
- package/dist/lib/utils/s2/index.js.map +0 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/tile-3d-subtree-loader.js.map +0 -1
- package/dist/tile-3d-writer.js.map +0 -1
- package/dist/tiles-3d-loader.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,40 +1,45 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
6
|
import { padToNBytes, copyBinaryToDataView, copyPaddedStringToDataView } from '@loaders.gl/loader-utils';
|
|
2
7
|
import { MAGIC_ARRAY } from "../constants.js";
|
|
3
8
|
import { encode3DTileHeader, encode3DTileByteLength } from "./helpers/encode-3d-tile-header.js";
|
|
9
|
+
// Procedurally encode the tile array dataView for testing purposes
|
|
4
10
|
export function encodeBatchedModel3DTile(tile, dataView, byteOffset, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
const { featuresLength = 0, batchTable } = tile;
|
|
12
|
+
const featureTableJson = {
|
|
13
|
+
BATCH_LENGTH: featuresLength
|
|
14
|
+
};
|
|
15
|
+
const featureTableJsonString = JSON.stringify(featureTableJson);
|
|
16
|
+
const batchTableJsonString = batchTable ? JSON.stringify(batchTable) : '';
|
|
17
|
+
const featureTableJsonByteLength = padToNBytes(featureTableJsonString.length, 8);
|
|
18
|
+
const batchTableJsonByteLength = batchTableJsonString
|
|
19
|
+
? padToNBytes(batchTableJsonString.length, 8)
|
|
20
|
+
: 0;
|
|
21
|
+
// Add default magic for this tile type
|
|
22
|
+
tile = { magic: MAGIC_ARRAY.BATCHED_MODEL, ...tile };
|
|
23
|
+
const byteOffsetStart = byteOffset;
|
|
24
|
+
byteOffset = encode3DTileHeader(tile, dataView, byteOffset);
|
|
25
|
+
if (dataView) {
|
|
26
|
+
dataView.setUint32(12, featureTableJsonByteLength, true); // featureTableJsonByteLength
|
|
27
|
+
dataView.setUint32(16, 0, true); // featureTableBinaryByteLength
|
|
28
|
+
dataView.setUint32(20, batchTableJsonByteLength, true); // batchTableJsonByteLength
|
|
29
|
+
dataView.setUint32(24, 0, true); // batchTableBinaryByteLength
|
|
30
|
+
}
|
|
31
|
+
byteOffset += 16;
|
|
32
|
+
// TODO feature table binary
|
|
33
|
+
byteOffset = copyPaddedStringToDataView(dataView, byteOffset, featureTableJsonString, 8);
|
|
34
|
+
if (batchTable) {
|
|
35
|
+
byteOffset = copyPaddedStringToDataView(dataView, byteOffset, batchTableJsonString, 8);
|
|
36
|
+
}
|
|
37
|
+
// Add encoded GLTF to the end of data
|
|
38
|
+
const gltfEncoded = tile.gltfEncoded;
|
|
39
|
+
if (gltfEncoded) {
|
|
40
|
+
byteOffset = copyBinaryToDataView(dataView, byteOffset, gltfEncoded, gltfEncoded.byteLength);
|
|
41
|
+
}
|
|
42
|
+
// Go "back" and rewrite the tile's `byteLength` now that we know the value
|
|
43
|
+
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
44
|
+
return byteOffset;
|
|
39
45
|
}
|
|
40
|
-
//# sourceMappingURL=encode-3d-tile-batched-model.js.map
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
6
|
import { MAGIC_ARRAY } from "../constants.js";
|
|
2
7
|
import { encode3DTileHeader, encode3DTileByteLength } from "./helpers/encode-3d-tile-header.js";
|
|
3
8
|
export function encodeComposite3DTile(tile, dataView, byteOffset, options, encode3DTile) {
|
|
4
|
-
|
|
5
|
-
magic: MAGIC_ARRAY.COMPOSITE,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
19
|
-
return byteOffset;
|
|
9
|
+
// Add default magic for this tile type
|
|
10
|
+
tile = { magic: MAGIC_ARRAY.COMPOSITE, tiles: [], ...tile };
|
|
11
|
+
const byteOffsetStart = byteOffset;
|
|
12
|
+
byteOffset += encode3DTileHeader(tile, dataView, byteOffset);
|
|
13
|
+
if (dataView) {
|
|
14
|
+
dataView.setUint32(byteOffset, tile.tiles.length, true); // tilesLength
|
|
15
|
+
}
|
|
16
|
+
byteOffset += 4;
|
|
17
|
+
for (let i = 0; i < tile.tiles.length; ++i) {
|
|
18
|
+
byteOffset += encode3DTile(tile.tiles[i], dataView, byteOffset, options);
|
|
19
|
+
}
|
|
20
|
+
// Go "back" and rewrite the tile's `byteLength` now that we know the value
|
|
21
|
+
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
22
|
+
return byteOffset;
|
|
20
23
|
}
|
|
21
|
-
//# sourceMappingURL=encode-3d-tile-composite.js.map
|
|
@@ -1,36 +1,37 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
6
|
import { copyStringToDataView } from '@loaders.gl/loader-utils';
|
|
2
7
|
import { MAGIC_ARRAY } from "../constants.js";
|
|
3
8
|
import { encode3DTileHeader, encode3DTileByteLength } from "./helpers/encode-3d-tile-header.js";
|
|
9
|
+
// Procedurally encode the tile array buffer for testing purposes
|
|
10
|
+
// eslint-disable-next-line max-statements
|
|
4
11
|
export function encodeInstancedModel3DTile(tile, dataView, byteOffset, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
dataView
|
|
26
|
-
dataView
|
|
27
|
-
|
|
28
|
-
dataView
|
|
29
|
-
|
|
30
|
-
byteOffset += 20;
|
|
31
|
-
byteOffset += copyStringToDataView(dataView, byteOffset, featureTableJsonString, featureTableJsonByteLength);
|
|
32
|
-
byteOffset += copyStringToDataView(dataView, byteOffset, gltfUri, gltfUriByteLength);
|
|
33
|
-
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
34
|
-
return byteOffset;
|
|
12
|
+
const { featuresLength = 1, gltfFormat = 1, gltfUri = '' } = tile;
|
|
13
|
+
const gltfUriByteLength = gltfUri.length;
|
|
14
|
+
const featureTableJson = {
|
|
15
|
+
INSTANCES_LENGTH: featuresLength,
|
|
16
|
+
POSITION: new Array(featuresLength * 3).fill(0)
|
|
17
|
+
};
|
|
18
|
+
const featureTableJsonString = JSON.stringify(featureTableJson);
|
|
19
|
+
const featureTableJsonByteLength = featureTableJsonString.length;
|
|
20
|
+
// Add default magic for this tile type
|
|
21
|
+
tile = { magic: MAGIC_ARRAY.INSTANCED_MODEL, ...tile };
|
|
22
|
+
const byteOffsetStart = byteOffset;
|
|
23
|
+
byteOffset = encode3DTileHeader(tile, dataView, 0);
|
|
24
|
+
if (dataView) {
|
|
25
|
+
dataView.setUint32(12, featureTableJsonByteLength, true); // featureTableJsonByteLength
|
|
26
|
+
dataView.setUint32(16, 0, true); // featureTableBinaryByteLength
|
|
27
|
+
dataView.setUint32(20, 0, true); // batchTableJsonByteLength
|
|
28
|
+
dataView.setUint32(24, 0, true); // batchTableBinaryByteLength
|
|
29
|
+
dataView.setUint32(28, gltfFormat, true); // gltfFormat
|
|
30
|
+
}
|
|
31
|
+
byteOffset += 20;
|
|
32
|
+
byteOffset += copyStringToDataView(dataView, byteOffset, featureTableJsonString, featureTableJsonByteLength);
|
|
33
|
+
byteOffset += copyStringToDataView(dataView, byteOffset, gltfUri, gltfUriByteLength);
|
|
34
|
+
// Go "back" and rewrite the tile's `byteLength` now that we know the value
|
|
35
|
+
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
36
|
+
return byteOffset;
|
|
35
37
|
}
|
|
36
|
-
//# sourceMappingURL=encode-3d-tile-instanced-model.js.map
|
|
@@ -1,39 +1,38 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
6
|
import { MAGIC_ARRAY } from "../constants.js";
|
|
2
7
|
import { encode3DTileHeader, encode3DTileByteLength } from "./helpers/encode-3d-tile-header.js";
|
|
3
8
|
import { padStringToByteAlignment, copyStringToDataView, copyBinaryToDataView } from '@loaders.gl/loader-utils';
|
|
4
9
|
const DEFAULT_FEATURE_TABLE_JSON = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
POINTS_LENGTH: 1,
|
|
11
|
+
POSITIONS: {
|
|
12
|
+
byteOffset: 0
|
|
13
|
+
}
|
|
9
14
|
};
|
|
10
15
|
export function encodePointCloud3DTile(tile, dataView, byteOffset, options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
dataView
|
|
32
|
-
|
|
33
|
-
byteOffset += 16;
|
|
34
|
-
byteOffset += copyStringToDataView(dataView, byteOffset, featureTableJsonString, featureTableJsonByteLength);
|
|
35
|
-
byteOffset += copyBinaryToDataView(dataView, byteOffset, featureTableBinary, featureTableBinaryByteLength);
|
|
36
|
-
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
37
|
-
return byteOffset;
|
|
16
|
+
const { featureTableJson = DEFAULT_FEATURE_TABLE_JSON } = tile;
|
|
17
|
+
let featureTableJsonString = JSON.stringify(featureTableJson);
|
|
18
|
+
featureTableJsonString = padStringToByteAlignment(featureTableJsonString, 4);
|
|
19
|
+
const { featureTableJsonByteLength = featureTableJsonString.length } = tile;
|
|
20
|
+
const featureTableBinary = new ArrayBuffer(12); // Enough space to hold 3 floats
|
|
21
|
+
const featureTableBinaryByteLength = featureTableBinary.byteLength;
|
|
22
|
+
// Add default magic for this tile type
|
|
23
|
+
tile = { magic: MAGIC_ARRAY.POINT_CLOUD, ...tile };
|
|
24
|
+
const byteOffsetStart = byteOffset;
|
|
25
|
+
byteOffset += encode3DTileHeader(tile, dataView, 0);
|
|
26
|
+
if (dataView) {
|
|
27
|
+
dataView.setUint32(byteOffset + 0, featureTableJsonByteLength, true); // featureTableJsonByteLength
|
|
28
|
+
dataView.setUint32(byteOffset + 4, featureTableBinaryByteLength, true); // featureTableBinaryByteLength
|
|
29
|
+
dataView.setUint32(byteOffset + 8, 0, true); // batchTableJsonByteLength
|
|
30
|
+
dataView.setUint32(byteOffset + 12, 0, true); // batchTableBinaryByteLength
|
|
31
|
+
}
|
|
32
|
+
byteOffset += 16;
|
|
33
|
+
byteOffset += copyStringToDataView(dataView, byteOffset, featureTableJsonString, featureTableJsonByteLength);
|
|
34
|
+
byteOffset += copyBinaryToDataView(dataView, byteOffset, featureTableBinary, featureTableBinaryByteLength);
|
|
35
|
+
// Go "back" and rewrite the tile's `byteLength` now that we know the value
|
|
36
|
+
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
37
|
+
return byteOffset;
|
|
38
38
|
}
|
|
39
|
-
//# sourceMappingURL=encode-3d-tile-point-cloud.js.map
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
6
|
import { TILE3D_TYPE } from "../constants.js";
|
|
2
7
|
import { assert } from '@loaders.gl/loader-utils';
|
|
3
8
|
import { encodeComposite3DTile } from "./encode-3d-tile-composite.js";
|
|
@@ -5,25 +10,24 @@ import { encodeBatchedModel3DTile } from "./encode-3d-tile-batched-model.js";
|
|
|
5
10
|
import { encodeInstancedModel3DTile } from "./encode-3d-tile-instanced-model.js";
|
|
6
11
|
import { encodePointCloud3DTile } from "./encode-3d-tile-point-cloud.js";
|
|
7
12
|
export default function encode3DTile(tile, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const byteLength = encode3DTileToDataView(tile, null, 0, options);
|
|
14
|
+
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
15
|
+
const dataView = new DataView(arrayBuffer);
|
|
16
|
+
encode3DTileToDataView(tile, dataView, 0, options);
|
|
17
|
+
return arrayBuffer;
|
|
13
18
|
}
|
|
14
19
|
function encode3DTileToDataView(tile, dataView, byteOffset, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
assert(typeof tile.type === 'string');
|
|
21
|
+
switch (tile.type) {
|
|
22
|
+
case TILE3D_TYPE.COMPOSITE:
|
|
23
|
+
return encodeComposite3DTile(tile, dataView, byteOffset, options, encode3DTileToDataView);
|
|
24
|
+
case TILE3D_TYPE.POINT_CLOUD:
|
|
25
|
+
return encodePointCloud3DTile(tile, dataView, byteOffset, options);
|
|
26
|
+
case TILE3D_TYPE.BATCHED_3D_MODEL:
|
|
27
|
+
return encodeBatchedModel3DTile(tile, dataView, byteOffset, options);
|
|
28
|
+
case TILE3D_TYPE.INSTANCED_3D_MODEL:
|
|
29
|
+
return encodeInstancedModel3DTile(tile, dataView, byteOffset, options);
|
|
30
|
+
default:
|
|
31
|
+
throw new Error('3D Tiles: unknown tile type');
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
|
-
//# sourceMappingURL=encode-3d-tile.js.map
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// HELPER ENCODERS
|
|
1
5
|
import { assert } from '@loaders.gl/loader-utils';
|
|
2
6
|
export function encode3DTileHeader(tile, dataView, byteOffset) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
magic
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
dataView.setUint32(byteOffset + 4, version, true);
|
|
18
|
-
dataView.setUint32(byteOffset + 8, byteLength, true);
|
|
19
|
-
byteOffset += HEADER_SIZE;
|
|
20
|
-
return byteOffset;
|
|
7
|
+
const HEADER_SIZE = 12;
|
|
8
|
+
if (!dataView) {
|
|
9
|
+
return byteOffset + HEADER_SIZE;
|
|
10
|
+
}
|
|
11
|
+
const { magic, version = 1, byteLength = 12 } = tile;
|
|
12
|
+
assert(Array.isArray(magic) && Number.isFinite(version) && Number.isFinite(byteLength));
|
|
13
|
+
dataView.setUint8(byteOffset + 0, magic[0]);
|
|
14
|
+
dataView.setUint8(byteOffset + 1, magic[1]);
|
|
15
|
+
dataView.setUint8(byteOffset + 2, magic[2]);
|
|
16
|
+
dataView.setUint8(byteOffset + 3, magic[3]);
|
|
17
|
+
dataView.setUint32(byteOffset + 4, version, true); // version
|
|
18
|
+
dataView.setUint32(byteOffset + 8, byteLength, true); // byteLength
|
|
19
|
+
byteOffset += HEADER_SIZE;
|
|
20
|
+
return byteOffset;
|
|
21
21
|
}
|
|
22
|
+
// Bytelength is sometimes only known at the end of writing a tile
|
|
22
23
|
export function encode3DTileByteLength(dataView, byteOffsetTileStart, byteLength) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
if (!dataView) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
dataView.setUint32(byteOffsetTileStart + 8, byteLength, true); // byteLength
|
|
27
28
|
}
|
|
28
|
-
//# sourceMappingURL=encode-3d-tile-header.js.map
|
package/dist/lib/ion/ion.js
CHANGED
|
@@ -1,64 +1,65 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// Minimal support to load tilsets from the Cesium ION services
|
|
1
5
|
import { fetchFile } from '@loaders.gl/core';
|
|
2
6
|
import { assert } from '@loaders.gl/loader-utils';
|
|
3
7
|
const CESIUM_ION_URL = 'https://api.cesium.com/v1/assets';
|
|
8
|
+
// Returns `{url, headers, type, attributions}` for an ion tileset
|
|
4
9
|
export async function getIonTilesetMetadata(accessToken, assetId) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
// Step 1, if no asset id, look for first 3DTILES asset associated with this token.
|
|
11
|
+
if (!assetId) {
|
|
12
|
+
const assets = await getIonAssets(accessToken);
|
|
13
|
+
for (const item of assets.items) {
|
|
14
|
+
if (item.type === '3DTILES') {
|
|
15
|
+
assetId = item.id;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
11
18
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
return ionAssetMetadata;
|
|
19
|
+
// Step 2: Query metdatadata for this asset.
|
|
20
|
+
const ionAssetMetadata = await getIonAssetMetadata(accessToken, assetId);
|
|
21
|
+
const { type, url } = ionAssetMetadata;
|
|
22
|
+
assert(type === '3DTILES' && url);
|
|
23
|
+
// Prepare a headers object for fetch
|
|
24
|
+
ionAssetMetadata.headers = {
|
|
25
|
+
Authorization: `Bearer ${ionAssetMetadata.accessToken}`
|
|
26
|
+
};
|
|
27
|
+
return ionAssetMetadata;
|
|
23
28
|
}
|
|
29
|
+
// Return a list of all assets associated with accessToken
|
|
24
30
|
export async function getIonAssets(accessToken) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!response.ok) {
|
|
34
|
-
throw new Error(response.statusText);
|
|
35
|
-
}
|
|
36
|
-
return await response.json();
|
|
31
|
+
assert(accessToken);
|
|
32
|
+
const url = CESIUM_ION_URL;
|
|
33
|
+
const headers = { Authorization: `Bearer ${accessToken}` };
|
|
34
|
+
const response = await fetchFile(url, { headers });
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error(response.statusText);
|
|
37
|
+
}
|
|
38
|
+
return await response.json();
|
|
37
39
|
}
|
|
40
|
+
// Return metadata for a specific asset associated with token
|
|
38
41
|
export async function getIonAssetMetadata(accessToken, assetId) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return metadata;
|
|
42
|
+
assert(accessToken, assetId);
|
|
43
|
+
const headers = { Authorization: `Bearer ${accessToken}` };
|
|
44
|
+
const url = `${CESIUM_ION_URL}/${assetId}`;
|
|
45
|
+
// https://cesium.com/docs/rest-api/#operation/getAsset
|
|
46
|
+
// Retrieves metadata information about a specific asset.
|
|
47
|
+
let response = await fetchFile(`${url}`, { headers });
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new Error(response.statusText);
|
|
50
|
+
}
|
|
51
|
+
let metadata = await response.json();
|
|
52
|
+
// https://cesium.com/docs/rest-api/#operation/getAssetEndpoint
|
|
53
|
+
// Retrieves information and credentials that allow you to access the tiled asset data for visualization and analysis.
|
|
54
|
+
response = await fetchFile(`${url}/endpoint`, { headers });
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
throw new Error(response.statusText);
|
|
57
|
+
}
|
|
58
|
+
const tilesetInfo = await response.json();
|
|
59
|
+
// extract dataset description
|
|
60
|
+
metadata = {
|
|
61
|
+
...metadata,
|
|
62
|
+
...tilesetInfo
|
|
63
|
+
};
|
|
64
|
+
return metadata;
|
|
63
65
|
}
|
|
64
|
-
//# sourceMappingURL=ion.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tile3DBatchTable } from '@loaders.gl/3d-tiles';
|
|
2
|
-
import { Tiles3DTileContent } from
|
|
2
|
+
import { Tiles3DTileContent } from "../../../types.js";
|
|
3
3
|
export declare function normalize3DTileColorAttribute(tile: Tiles3DTileContent, colors: Uint8ClampedArray | null, batchTable?: Tile3DBatchTable): {
|
|
4
4
|
type: number;
|
|
5
5
|
value: Uint8ClampedArray;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-3d-tile-colors.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/normalize-3d-tile-colors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAC,kBAAkB,EAAC,
|
|
1
|
+
{"version":3,"file":"normalize-3d-tile-colors.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/normalize-3d-tile-colors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAC,kBAAkB,EAAC,0BAAuB;AAGlD,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,iBAAiB,GAAG,IAAI,EAChC,UAAU,CAAC,EAAE,gBAAgB,GAC5B;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAC,GAAG,IAAI,CA6DpF"}
|
|
@@ -1,58 +1,64 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
1
4
|
import { decodeRGB565, GL } from '@loaders.gl/math';
|
|
5
|
+
/* eslint-disable complexity*/
|
|
2
6
|
export function normalize3DTileColorAttribute(tile, colors, batchTable) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
batchIds,
|
|
8
|
-
isRGB565,
|
|
9
|
-
pointCount = 0
|
|
10
|
-
} = tile;
|
|
11
|
-
if (batchIds && batchTable) {
|
|
12
|
-
const colorArray = new Uint8ClampedArray(pointCount * 3);
|
|
13
|
-
for (let i = 0; i < pointCount; i++) {
|
|
14
|
-
const batchId = batchIds[i];
|
|
15
|
-
const dimensions = batchTable.getProperty(batchId, 'dimensions');
|
|
16
|
-
const color = dimensions.map(d => d * 255);
|
|
17
|
-
colorArray[i * 3] = color[0];
|
|
18
|
-
colorArray[i * 3 + 1] = color[1];
|
|
19
|
-
colorArray[i * 3 + 2] = color[2];
|
|
7
|
+
// no colors defined
|
|
8
|
+
if (!colors && (!tile || !tile.batchIds || !batchTable)) {
|
|
9
|
+
return null;
|
|
20
10
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
const { batchIds, isRGB565, pointCount = 0 } = tile;
|
|
12
|
+
// Batch table, look up colors in table
|
|
13
|
+
if (batchIds && batchTable) {
|
|
14
|
+
const colorArray = new Uint8ClampedArray(pointCount * 3);
|
|
15
|
+
for (let i = 0; i < pointCount; i++) {
|
|
16
|
+
const batchId = batchIds[i];
|
|
17
|
+
// TODO figure out what is `dimensions` used for
|
|
18
|
+
const dimensions = batchTable.getProperty(batchId, 'dimensions');
|
|
19
|
+
const color = dimensions.map((d) => d * 255);
|
|
20
|
+
colorArray[i * 3] = color[0];
|
|
21
|
+
colorArray[i * 3 + 1] = color[1];
|
|
22
|
+
colorArray[i * 3 + 2] = color[2];
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
type: GL.UNSIGNED_BYTE,
|
|
26
|
+
value: colorArray,
|
|
27
|
+
size: 3,
|
|
28
|
+
normalized: true
|
|
29
|
+
};
|
|
35
30
|
}
|
|
31
|
+
// RGB565 case, convert to RGB
|
|
32
|
+
if (colors && isRGB565) {
|
|
33
|
+
const colorArray = new Uint8ClampedArray(pointCount * 3);
|
|
34
|
+
for (let i = 0; i < pointCount; i++) {
|
|
35
|
+
const color = decodeRGB565(colors[i]);
|
|
36
|
+
colorArray[i * 3] = color[0];
|
|
37
|
+
colorArray[i * 3 + 1] = color[1];
|
|
38
|
+
colorArray[i * 3 + 2] = color[2];
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
type: GL.UNSIGNED_BYTE,
|
|
42
|
+
value: colorArray,
|
|
43
|
+
size: 3,
|
|
44
|
+
normalized: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// RGB case (tile.isTranslucent)
|
|
48
|
+
if (colors && colors.length === pointCount * 3) {
|
|
49
|
+
return {
|
|
50
|
+
type: GL.UNSIGNED_BYTE,
|
|
51
|
+
value: colors,
|
|
52
|
+
size: 3,
|
|
53
|
+
normalized: true
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// DEFAULT: RGBA case
|
|
36
57
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (colors && colors.length === pointCount * 3) {
|
|
44
|
-
return {
|
|
45
|
-
type: GL.UNSIGNED_BYTE,
|
|
46
|
-
value: colors,
|
|
47
|
-
size: 3,
|
|
48
|
-
normalized: true
|
|
58
|
+
type: GL.UNSIGNED_BYTE,
|
|
59
|
+
value: colors || new Uint8ClampedArray(),
|
|
60
|
+
size: 4,
|
|
61
|
+
normalized: true
|
|
49
62
|
};
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
type: GL.UNSIGNED_BYTE,
|
|
53
|
-
value: colors || new Uint8ClampedArray(),
|
|
54
|
-
size: 4,
|
|
55
|
-
normalized: true
|
|
56
|
-
};
|
|
57
63
|
}
|
|
58
|
-
|
|
64
|
+
/* eslint-enable complexity*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-3d-tile-normals.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/normalize-3d-tile-normals.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,kBAAkB,EAAC,
|
|
1
|
+
{"version":3,"file":"normalize-3d-tile-normals.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/normalize-3d-tile-normals.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,kBAAkB,EAAC,0BAAuB;AAIlD,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,YAAY,GAAG,IAAI,GAC3B;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAC,GAAG,IAAI,CAyB1D"}
|