@loaders.gl/3d-tiles 4.2.0-alpha.4 → 4.2.0-alpha.6
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 +68 -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 +8824 -6420
- package/dist/dist.min.js +32 -0
- package/dist/index.cjs +138 -340
- 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.d.ts +1 -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.d.ts +1 -1
- package/dist/lib/classes/tile-3d-batch-table.js +241 -217
- package/dist/lib/classes/tile-3d-feature-table.js +64 -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 +17 -12
- package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +1 -1
- 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,66 +1,94 @@
|
|
|
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
|
|
6
|
+
// TODO - should we automatically parse the embedded glTF or leave it to the app?
|
|
7
|
+
// - I.e. some apps might work directly on a GLB, in that case no need for us to decode...
|
|
8
|
+
// - And if we decode, do we still keep the GLB in case it is needed?
|
|
9
|
+
// - Do we add an option to control this?
|
|
10
|
+
// - Also, should we have hard dependency on gltf module or use injection or auto-discovery for gltf parser?
|
|
1
11
|
import { GLTFLoader, postProcessGLTF, _getMemoryUsageGLTF } from '@loaders.gl/gltf';
|
|
2
12
|
import { sliceArrayBuffer, parseFromContext } from '@loaders.gl/loader-utils';
|
|
3
13
|
export const GLTF_FORMAT = {
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
URI: 0,
|
|
15
|
+
EMBEDDED: 1
|
|
6
16
|
};
|
|
7
17
|
export function parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
// Set flags
|
|
19
|
+
// glTF models need to be rotated from Y to Z up
|
|
20
|
+
// https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
|
|
21
|
+
tile.rotateYtoZ = true;
|
|
22
|
+
// Assume glTF consumes rest of tile
|
|
23
|
+
const gltfByteLength = (tile.byteOffset || 0) + (tile.byteLength || 0) - byteOffset;
|
|
24
|
+
if (gltfByteLength === 0) {
|
|
25
|
+
throw new Error('glTF byte length must be greater than 0.');
|
|
26
|
+
}
|
|
27
|
+
// Save gltf up axis
|
|
28
|
+
tile.gltfUpAxis =
|
|
29
|
+
options?.['3d-tiles'] && options['3d-tiles'].assetGltfUpAxis
|
|
30
|
+
? options['3d-tiles'].assetGltfUpAxis
|
|
31
|
+
: 'Y';
|
|
32
|
+
// TODO - We can avoid copy if already 4-byte aligned...
|
|
33
|
+
// However the rest of the code may not be able to accept byteOffsets, so copy anyway
|
|
34
|
+
tile.gltfArrayBuffer = sliceArrayBuffer(arrayBuffer, byteOffset, gltfByteLength);
|
|
35
|
+
tile.gltfByteOffset = 0;
|
|
36
|
+
tile.gltfByteLength = gltfByteLength;
|
|
37
|
+
if (byteOffset % 4 === 0) {
|
|
38
|
+
// tile.gltfArrayBuffer = arrayBuffer;
|
|
39
|
+
// tile.gltfByteOffset = byteOffset;
|
|
40
|
+
// tile.gltfByteLength = gltfByteLength;
|
|
28
41
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const response = await fetch(tile.gltfUrl, options);
|
|
34
|
-
tile.gltfArrayBuffer = await response.arrayBuffer();
|
|
35
|
-
tile.gltfByteOffset = 0;
|
|
42
|
+
else {
|
|
43
|
+
// Create a copy of the glb so that it is 4-byte aligned
|
|
44
|
+
// eslint-disable-next-line
|
|
45
|
+
console.warn(`${tile.type}: embedded glb is not aligned to a 4-byte boundary.`);
|
|
36
46
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
// Entire tile is consumed
|
|
48
|
+
return (tile.byteOffset || 0) + (tile.byteLength || 0);
|
|
49
|
+
}
|
|
50
|
+
export async function extractGLTF(tile, gltfFormat, options, context) {
|
|
51
|
+
const tile3DOptions = options?.['3d-tiles'] || {};
|
|
52
|
+
extractGLTFBufferOrURL(tile, gltfFormat, options);
|
|
53
|
+
if (tile3DOptions.loadGLTF) {
|
|
54
|
+
if (!context) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (tile.gltfUrl) {
|
|
58
|
+
const { fetch } = context;
|
|
59
|
+
const response = await fetch(tile.gltfUrl, options);
|
|
60
|
+
tile.gltfArrayBuffer = await response.arrayBuffer();
|
|
61
|
+
tile.gltfByteOffset = 0;
|
|
62
|
+
}
|
|
63
|
+
if (tile.gltfArrayBuffer) {
|
|
64
|
+
// TODO - Should handle byteOffset... However, not used now...
|
|
65
|
+
const gltfWithBuffers = await parseFromContext(tile.gltfArrayBuffer, GLTFLoader, options, context);
|
|
66
|
+
tile.gltf = postProcessGLTF(gltfWithBuffers);
|
|
67
|
+
tile.gpuMemoryUsageInBytes = _getMemoryUsageGLTF(tile.gltf);
|
|
68
|
+
delete tile.gltfArrayBuffer;
|
|
69
|
+
delete tile.gltfByteOffset;
|
|
70
|
+
delete tile.gltfByteLength;
|
|
71
|
+
}
|
|
44
72
|
}
|
|
45
|
-
}
|
|
46
73
|
}
|
|
47
74
|
function extractGLTFBufferOrURL(tile, gltfFormat, options) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
switch (gltfFormat) {
|
|
76
|
+
case GLTF_FORMAT.URI:
|
|
77
|
+
// We need to remove padding from the end of the model URL in case this tile was part of a composite tile.
|
|
78
|
+
// This removes all white space and null characters from the end of the string.
|
|
79
|
+
if (tile.gltfArrayBuffer) {
|
|
80
|
+
const gltfUrlBytes = new Uint8Array(tile.gltfArrayBuffer, tile.gltfByteOffset);
|
|
81
|
+
const textDecoder = new TextDecoder();
|
|
82
|
+
const gltfUrl = textDecoder.decode(gltfUrlBytes);
|
|
83
|
+
tile.gltfUrl = gltfUrl.replace(/[\s\0]+$/, '');
|
|
84
|
+
}
|
|
85
|
+
delete tile.gltfArrayBuffer;
|
|
86
|
+
delete tile.gltfByteOffset;
|
|
87
|
+
delete tile.gltfByteLength;
|
|
88
|
+
break;
|
|
89
|
+
case GLTF_FORMAT.EMBEDDED:
|
|
90
|
+
break;
|
|
91
|
+
default:
|
|
92
|
+
throw new Error('b3dm: Illegal glTF format field');
|
|
93
|
+
}
|
|
65
94
|
}
|
|
66
|
-
//# sourceMappingURL=parse-3d-tile-gltf-view.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Tiles3DTileContent } from
|
|
1
|
+
import { Tiles3DTileContent } from "../../../types.js";
|
|
2
2
|
export declare function parse3DTileHeaderSync(tile: Tiles3DTileContent, arrayBuffer: ArrayBuffer, byteOffset?: number): number;
|
|
3
3
|
//# sourceMappingURL=parse-3d-tile-header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-3d-tile-header.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/parse-3d-tile-header.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,kBAAkB,EAAC,
|
|
1
|
+
{"version":3,"file":"parse-3d-tile-header.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/parse-3d-tile-header.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,kBAAkB,EAAC,0BAAuB;AAWlD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,GAAE,MAAU,UAmBvB"}
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
1
4
|
const SIZEOF_UINT32 = 4;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
/* PARSE FIXED HEADER:
|
|
6
|
+
Populates
|
|
7
|
+
magic, // identifies type of tile
|
|
8
|
+
type, // String version of magic
|
|
9
|
+
version,
|
|
10
|
+
byteLength
|
|
11
|
+
*/
|
|
12
|
+
export function parse3DTileHeaderSync(tile, arrayBuffer, byteOffset = 0) {
|
|
13
|
+
const view = new DataView(arrayBuffer);
|
|
14
|
+
tile.magic = view.getUint32(byteOffset, true);
|
|
15
|
+
byteOffset += SIZEOF_UINT32;
|
|
16
|
+
tile.version = view.getUint32(byteOffset, true);
|
|
17
|
+
byteOffset += SIZEOF_UINT32;
|
|
18
|
+
tile.byteLength = view.getUint32(byteOffset, true);
|
|
19
|
+
byteOffset += SIZEOF_UINT32;
|
|
20
|
+
// TODO - move version check into each tile parser?
|
|
21
|
+
if (tile.version !== 1) {
|
|
22
|
+
throw new Error(`3D Tile Version ${tile.version} not supported`);
|
|
23
|
+
}
|
|
24
|
+
return byteOffset; // Indicates where the parsing ended
|
|
15
25
|
}
|
|
16
|
-
//# sourceMappingURL=parse-3d-tile-header.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-3d-tile-subtree.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/parse-3d-tile-subtree.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,OAAO,EAAE,YAAY,EAAC,
|
|
1
|
+
{"version":3,"file":"parse-3d-tile-subtree.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/parse-3d-tile-subtree.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,OAAO,EAAE,YAAY,EAAC,0BAAuB;AAC1D,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAK3E;;;;;GAKG;AAEH,wBAA8B,mBAAmB,CAC/C,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,OAAO,EAAE,aAAa,GAAG,SAAS,GACjC,OAAO,CAAC,OAAO,CAAC,CAgDlB;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,OAAO,EAChB,kBAAkB,EAAE,YAAY,EAChC,oBAAoB,EAAE,WAAW,EACjC,OAAO,EAAE,aAAa,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC,CA0Cf"}
|
|
@@ -1,62 +1,90 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
1
4
|
const SUBTREE_FILE_MAGIC = 0x74627573;
|
|
2
5
|
const SUBTREE_FILE_VERSION = 1;
|
|
6
|
+
/**
|
|
7
|
+
* Parse subtree file
|
|
8
|
+
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling#subtree-file-format
|
|
9
|
+
* @param data
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line max-statements
|
|
3
13
|
export default async function parse3DTilesSubtree(data, options, context) {
|
|
4
|
-
|
|
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
|
-
|
|
14
|
+
const magic = new Uint32Array(data.slice(0, 4));
|
|
15
|
+
if (magic[0] !== SUBTREE_FILE_MAGIC) {
|
|
16
|
+
throw new Error('Wrong subtree file magic number');
|
|
17
|
+
}
|
|
18
|
+
const version = new Uint32Array(data.slice(4, 8));
|
|
19
|
+
if (version[0] !== SUBTREE_FILE_VERSION) {
|
|
20
|
+
throw new Error('Wrong subtree file verson, must be 1');
|
|
21
|
+
}
|
|
22
|
+
const jsonByteLength = parseUint64Value(data.slice(8, 16));
|
|
23
|
+
const stringAttribute = new Uint8Array(data, 24, jsonByteLength);
|
|
24
|
+
const textDecoder = new TextDecoder('utf8');
|
|
25
|
+
const string = textDecoder.decode(stringAttribute);
|
|
26
|
+
const subtree = JSON.parse(string);
|
|
27
|
+
const binaryByteLength = parseUint64Value(data.slice(16, 24));
|
|
28
|
+
let internalBinaryBuffer = new ArrayBuffer(0);
|
|
29
|
+
if (binaryByteLength) {
|
|
30
|
+
internalBinaryBuffer = data.slice(24 + jsonByteLength);
|
|
31
|
+
}
|
|
32
|
+
await loadExplicitBitstream(subtree, subtree.tileAvailability, internalBinaryBuffer, context);
|
|
33
|
+
if (Array.isArray(subtree.contentAvailability)) {
|
|
34
|
+
for (const contentAvailability of subtree.contentAvailability) {
|
|
35
|
+
await loadExplicitBitstream(subtree, contentAvailability, internalBinaryBuffer, context);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
await loadExplicitBitstream(subtree, subtree.contentAvailability, internalBinaryBuffer, context);
|
|
40
|
+
}
|
|
41
|
+
await loadExplicitBitstream(subtree, subtree.childSubtreeAvailability, internalBinaryBuffer, context);
|
|
42
|
+
return subtree;
|
|
32
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Load explicit bitstream for subtree availability data.
|
|
46
|
+
* @param subtree - subtree data
|
|
47
|
+
* @param availabilityObject - tileAvailability / contentAvailability / childSubtreeAvailability object
|
|
48
|
+
* @param internalBinaryBuffer - subtree binary buffer
|
|
49
|
+
* @param context - loaders.gl context
|
|
50
|
+
*/
|
|
33
51
|
export async function loadExplicitBitstream(subtree, availabilityObject, internalBinaryBuffer, context) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const bufferViewIndex = Number.isFinite(availabilityObject.bitstream)
|
|
53
|
+
? availabilityObject.bitstream
|
|
54
|
+
: availabilityObject.bufferView;
|
|
55
|
+
if (typeof bufferViewIndex !== 'number') {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const bufferView = subtree.bufferViews[bufferViewIndex];
|
|
59
|
+
const buffer = subtree.buffers[bufferView.buffer];
|
|
60
|
+
if (!context?.baseUrl) {
|
|
61
|
+
throw new Error('Url is not provided');
|
|
62
|
+
}
|
|
63
|
+
if (!context.fetch) {
|
|
64
|
+
throw new Error('fetch is not provided');
|
|
65
|
+
}
|
|
66
|
+
// External bitstream loading
|
|
67
|
+
if (buffer.uri) {
|
|
68
|
+
const bufferUri = `${context?.baseUrl || ''}/${buffer.uri}`;
|
|
69
|
+
const response = await context.fetch(bufferUri);
|
|
70
|
+
const data = await response.arrayBuffer();
|
|
71
|
+
availabilityObject.explicitBitstream = new Uint8Array(data, bufferView.byteOffset, bufferView.byteLength);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const bufferStart = subtree.buffers
|
|
75
|
+
.slice(0, bufferView.buffer)
|
|
76
|
+
.reduce((offset, buf) => offset + buf.byteLength, 0);
|
|
77
|
+
availabilityObject.explicitBitstream = new Uint8Array(internalBinaryBuffer.slice(bufferStart, bufferStart + buffer.byteLength), bufferView.byteOffset, bufferView.byteLength);
|
|
55
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Parse buffer to return uint64 value
|
|
81
|
+
* @param buffer
|
|
82
|
+
* @returns 64-bit value until precision is lost after Number.MAX_SAFE_INTEGER
|
|
83
|
+
*/
|
|
56
84
|
function parseUint64Value(buffer) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
85
|
+
const dataView = new DataView(buffer);
|
|
86
|
+
const left = dataView.getUint32(0, true);
|
|
87
|
+
const right = dataView.getUint32(4, true);
|
|
88
|
+
// combine the two 32-bit values
|
|
89
|
+
return left + 2 ** 32 * right;
|
|
61
90
|
}
|
|
62
|
-
//# sourceMappingURL=parse-3d-tile-subtree.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Tiles3DLoaderOptions } from
|
|
2
|
-
import { Tiles3DTileContent } from
|
|
1
|
+
import { Tiles3DLoaderOptions } from "../../../tiles-3d-loader.js";
|
|
2
|
+
import { Tiles3DTileContent } from "../../../types.js";
|
|
3
3
|
export declare function parse3DTileTablesHeaderSync(tile: Tiles3DTileContent, arrayBuffer: ArrayBuffer, byteOffset: number): number;
|
|
4
4
|
export declare function parse3DTileTablesSync(tile: Tiles3DTileContent, arrayBuffer: ArrayBuffer, byteOffset: number, options?: Tiles3DLoaderOptions): number;
|
|
5
5
|
//# sourceMappingURL=parse-3d-tile-tables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-3d-tile-tables.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/parse-3d-tile-tables.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,oBAAoB,EAAC,
|
|
1
|
+
{"version":3,"file":"parse-3d-tile-tables.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/helpers/parse-3d-tile-tables.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,oBAAoB,EAAC,oCAAiC;AAC9D,OAAO,EAAC,kBAAkB,EAAC,0BAAuB;AAMlD,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,UAkDnB;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,oBAAoB,UAK/B"}
|
|
@@ -1,80 +1,91 @@
|
|
|
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 { getStringFromArrayBuffer } from "./parse-utils.js";
|
|
2
7
|
const SIZEOF_UINT32 = 4;
|
|
3
8
|
const DEPRECATION_WARNING = 'b3dm tile in legacy format.';
|
|
9
|
+
// eslint-disable-next-line max-statements
|
|
4
10
|
export function parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset) {
|
|
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 view = new DataView(arrayBuffer);
|
|
12
|
+
let batchLength;
|
|
13
|
+
tile.header = tile.header || {};
|
|
14
|
+
let featureTableJsonByteLength = view.getUint32(byteOffset, true);
|
|
15
|
+
byteOffset += SIZEOF_UINT32;
|
|
16
|
+
let featureTableBinaryByteLength = view.getUint32(byteOffset, true);
|
|
17
|
+
byteOffset += SIZEOF_UINT32;
|
|
18
|
+
let batchTableJsonByteLength = view.getUint32(byteOffset, true);
|
|
19
|
+
byteOffset += SIZEOF_UINT32;
|
|
20
|
+
let batchTableBinaryByteLength = view.getUint32(byteOffset, true);
|
|
21
|
+
byteOffset += SIZEOF_UINT32;
|
|
22
|
+
// First legacy header format - [batchLength] [batchTableByteLength] ('batchTableJsonByteLength': JSON starts with a quotation mark or the glTF magic)
|
|
23
|
+
// Second legacy format - [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength] (Second legacy format is similar as first but here we check 'batchTableBinaryByteLength' instead)
|
|
24
|
+
// Current header format - [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength]
|
|
25
|
+
// First byte will be 0x22 or 0x67. The minimum uint32 expected is 0x22000000 = 570425344 = 570MB.
|
|
26
|
+
if (batchTableJsonByteLength >= 570425344) {
|
|
27
|
+
byteOffset -= SIZEOF_UINT32 * 2;
|
|
28
|
+
batchLength = featureTableJsonByteLength;
|
|
29
|
+
batchTableJsonByteLength = featureTableBinaryByteLength;
|
|
30
|
+
batchTableBinaryByteLength = 0;
|
|
31
|
+
featureTableJsonByteLength = 0;
|
|
32
|
+
featureTableBinaryByteLength = 0;
|
|
33
|
+
console.warn(DEPRECATION_WARNING); // eslint-disable-line
|
|
34
|
+
}
|
|
35
|
+
else if (batchTableBinaryByteLength >= 570425344) {
|
|
36
|
+
byteOffset -= SIZEOF_UINT32;
|
|
37
|
+
batchLength = batchTableJsonByteLength;
|
|
38
|
+
batchTableJsonByteLength = featureTableJsonByteLength;
|
|
39
|
+
batchTableBinaryByteLength = featureTableBinaryByteLength;
|
|
40
|
+
featureTableJsonByteLength = 0;
|
|
41
|
+
featureTableBinaryByteLength = 0;
|
|
42
|
+
console.warn(DEPRECATION_WARNING); // eslint-disable-line
|
|
43
|
+
}
|
|
44
|
+
tile.header.featureTableJsonByteLength = featureTableJsonByteLength;
|
|
45
|
+
tile.header.featureTableBinaryByteLength = featureTableBinaryByteLength;
|
|
46
|
+
tile.header.batchTableJsonByteLength = batchTableJsonByteLength;
|
|
47
|
+
tile.header.batchTableBinaryByteLength = batchTableBinaryByteLength;
|
|
48
|
+
tile.header.batchLength = batchLength;
|
|
49
|
+
return byteOffset;
|
|
39
50
|
}
|
|
40
51
|
export function parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
byteOffset = parse3DTileFeatureTable(tile, arrayBuffer, byteOffset, options);
|
|
53
|
+
byteOffset = parse3DTileBatchTable(tile, arrayBuffer, byteOffset, options);
|
|
54
|
+
return byteOffset;
|
|
44
55
|
}
|
|
45
56
|
function parse3DTileFeatureTable(tile, arrayBuffer, byteOffset, options) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const { featureTableJsonByteLength, featureTableBinaryByteLength, batchLength } = tile.header || {};
|
|
58
|
+
tile.featureTableJson = {
|
|
59
|
+
BATCH_LENGTH: batchLength || 0
|
|
60
|
+
};
|
|
61
|
+
if (featureTableJsonByteLength && featureTableJsonByteLength > 0) {
|
|
62
|
+
const featureTableString = getStringFromArrayBuffer(arrayBuffer, byteOffset, featureTableJsonByteLength);
|
|
63
|
+
tile.featureTableJson = JSON.parse(featureTableString);
|
|
64
|
+
}
|
|
65
|
+
byteOffset += featureTableJsonByteLength || 0;
|
|
66
|
+
tile.featureTableBinary = new Uint8Array(arrayBuffer, byteOffset, featureTableBinaryByteLength);
|
|
67
|
+
byteOffset += featureTableBinaryByteLength || 0;
|
|
68
|
+
/*
|
|
69
|
+
const featureTable = parseFeatureTable(featureTableJson, featureTableBinary);
|
|
70
|
+
|
|
71
|
+
const batchLength = featureTable.getGlobalProperty('BATCH_LENGTH');
|
|
72
|
+
featureTable.featuresLength = batchLength;
|
|
73
|
+
*/
|
|
74
|
+
return byteOffset;
|
|
62
75
|
}
|
|
63
76
|
function parse3DTileBatchTable(tile, arrayBuffer, byteOffset, options) {
|
|
64
|
-
|
|
65
|
-
batchTableJsonByteLength
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
const { batchTableJsonByteLength, batchTableBinaryByteLength } = tile.header || {};
|
|
78
|
+
if (batchTableJsonByteLength && batchTableJsonByteLength > 0) {
|
|
79
|
+
const batchTableString = getStringFromArrayBuffer(arrayBuffer, byteOffset, batchTableJsonByteLength);
|
|
80
|
+
tile.batchTableJson = JSON.parse(batchTableString);
|
|
81
|
+
byteOffset += batchTableJsonByteLength;
|
|
82
|
+
if (batchTableBinaryByteLength && batchTableBinaryByteLength > 0) {
|
|
83
|
+
// Has a batch table binary
|
|
84
|
+
tile.batchTableBinary = new Uint8Array(arrayBuffer, byteOffset, batchTableBinaryByteLength);
|
|
85
|
+
// Copy the batchTableBinary section and let the underlying ArrayBuffer be freed
|
|
86
|
+
tile.batchTableBinary = new Uint8Array(tile.batchTableBinary);
|
|
87
|
+
byteOffset += batchTableBinaryByteLength;
|
|
88
|
+
}
|
|
76
89
|
}
|
|
77
|
-
|
|
78
|
-
return byteOffset;
|
|
90
|
+
return byteOffset;
|
|
79
91
|
}
|
|
80
|
-
//# sourceMappingURL=parse-3d-tile-tables.js.map
|
|
@@ -1,24 +1,29 @@
|
|
|
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 { assert } from '@loaders.gl/loader-utils';
|
|
7
|
+
// Decode the JSON binary array into clear text
|
|
2
8
|
export function getStringFromArrayBuffer(arrayBuffer, byteOffset, byteLength) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
assert(arrayBuffer instanceof ArrayBuffer);
|
|
10
|
+
const textDecoder = new TextDecoder('utf8');
|
|
11
|
+
const typedArray = new Uint8Array(arrayBuffer, byteOffset, byteLength);
|
|
12
|
+
const string = textDecoder.decode(typedArray);
|
|
13
|
+
return string;
|
|
8
14
|
}
|
|
15
|
+
// Decode the JSON binary array into clear text
|
|
9
16
|
export function getStringFromTypedArray(typedArray) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
assert(ArrayBuffer.isView(typedArray));
|
|
18
|
+
const textDecoder = new TextDecoder('utf8');
|
|
19
|
+
const string = textDecoder.decode(typedArray);
|
|
20
|
+
return string;
|
|
14
21
|
}
|
|
15
|
-
export function getMagicString(arrayBuffer) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return `\
|
|
22
|
+
export function getMagicString(arrayBuffer, byteOffset = 0) {
|
|
23
|
+
const dataView = new DataView(arrayBuffer);
|
|
24
|
+
return `\
|
|
19
25
|
${String.fromCharCode(dataView.getUint8(byteOffset + 0))}\
|
|
20
26
|
${String.fromCharCode(dataView.getUint8(byteOffset + 1))}\
|
|
21
27
|
${String.fromCharCode(dataView.getUint8(byteOffset + 2))}\
|
|
22
28
|
${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
|
|
23
29
|
}
|
|
24
|
-
//# sourceMappingURL=parse-utils.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Tiles3DTileContent } from
|
|
2
|
-
import { Tiles3DLoaderOptions } from
|
|
1
|
+
import { Tiles3DTileContent } from "../../types.js";
|
|
2
|
+
import { Tiles3DLoaderOptions } from "../../tiles-3d-loader.js";
|
|
3
3
|
import { LoaderContext } from '@loaders.gl/loader-utils';
|
|
4
4
|
export declare function parseBatchedModel3DTile(tile: Tiles3DTileContent, arrayBuffer: ArrayBuffer, byteOffset: number, options?: Tiles3DLoaderOptions, context?: LoaderContext): Promise<number>;
|
|
5
5
|
//# sourceMappingURL=parse-3d-tile-batched-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-3d-tile-batched-model.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-batched-model.ts"],"names":[],"mappings":"AAcA,OAAO,EAAC,kBAAkB,EAAC,
|
|
1
|
+
{"version":3,"file":"parse-3d-tile-batched-model.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-batched-model.ts"],"names":[],"mappings":"AAcA,OAAO,EAAC,kBAAkB,EAAC,uBAAoB;AAC/C,OAAO,EAAC,oBAAoB,EAAC,iCAA8B;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEvD,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,mBAWxB"}
|