@loaders.gl/3d-tiles 4.0.0-beta.1 → 4.0.0-beta.3
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.d.ts +3 -4
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts.map +1 -1
- package/dist/{esm/3d-tiles-archive → 3d-tiles-archive}/3d-tiles-archive-archive.js +12 -12
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -0
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
- package/dist/{esm/3d-tiles-archive → 3d-tiles-archive}/3d-tiles-archive-parser.js +8 -10
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -0
- package/dist/{esm/3d-tiles-archive-loader.js → 3d-tiles-archive-loader.js} +2 -2
- package/dist/3d-tiles-archive-loader.js.map +1 -0
- package/dist/{esm/cesium-ion-loader.js → cesium-ion-loader.js} +2 -2
- package/dist/cesium-ion-loader.js.map +1 -0
- package/dist/{dist.min.js → dist.dev.js} +17589 -18674
- package/dist/index.cjs +2837 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +1 -0
- package/dist/{esm/lib → lib}/classes/tile-3d-batch-table-hierarchy.js +1 -1
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +1 -0
- package/dist/{esm/lib → lib}/classes/tile-3d-batch-table.js +12 -13
- package/dist/lib/classes/tile-3d-batch-table.js.map +1 -0
- package/dist/{esm/lib → lib}/classes/tile-3d-feature-table.js +4 -5
- package/dist/lib/classes/tile-3d-feature-table.js.map +1 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/{esm/lib → lib}/encoders/encode-3d-tile-batched-model.js +2 -2
- package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +1 -0
- package/dist/{esm/lib → lib}/encoders/encode-3d-tile-composite.js +2 -2
- package/dist/lib/encoders/encode-3d-tile-composite.js.map +1 -0
- package/dist/{esm/lib → lib}/encoders/encode-3d-tile-instanced-model.js +2 -2
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +1 -0
- package/dist/{esm/lib → lib}/encoders/encode-3d-tile-point-cloud.js +2 -2
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +1 -0
- package/dist/{esm/lib → lib}/encoders/encode-3d-tile.js +5 -5
- package/dist/lib/encoders/encode-3d-tile.js.map +1 -0
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +1 -0
- package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts +3 -3
- package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/filesystems/tiles-3d-archive-file-system.js +13 -14
- package/dist/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -0
- package/dist/{esm/lib → lib}/ion/ion.js +6 -6
- package/dist/lib/ion/ion.js.map +1 -0
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -0
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -0
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/helpers/parse-3d-implicit-tiles.js +8 -8
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/helpers/parse-3d-tile-gltf-view.js +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/helpers/parse-3d-tile-header.js +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/helpers/parse-3d-tile-subtree.js +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/helpers/parse-3d-tile-tables.js +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/helpers/parse-utils.js +5 -1
- package/dist/lib/parsers/helpers/parse-utils.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/parse-3d-tile-batched-model.js +4 -4
- package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/parse-3d-tile-composite.js +1 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js.map +1 -0
- package/dist/lib/parsers/parse-3d-tile-gltf.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/parse-3d-tile-header.js +5 -5
- package/dist/lib/parsers/parse-3d-tile-header.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/parse-3d-tile-instanced-model.js +6 -6
- package/dist/{es5/lib → lib}/parsers/parse-3d-tile-instanced-model.js.map +1 -1
- package/dist/{esm/lib → lib}/parsers/parse-3d-tile-point-cloud.js +7 -7
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/parse-3d-tile.js +8 -8
- package/dist/lib/parsers/parse-3d-tile.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/obb/s2-corners-to-obb.js +2 -2
- package/dist/lib/utils/obb/s2-corners-to-obb.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/s2/converters/s2-to-boundary.js +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/s2/converters/s2-to-obb-points.js +2 -2
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/s2/converters/s2-to-region.js +3 -3
- package/dist/lib/utils/s2/converters/s2-to-region.js.map +1 -0
- package/dist/lib/utils/s2/index.js +7 -0
- package/dist/lib/utils/s2/index.js.map +1 -0
- package/dist/lib/utils/s2/s2-geometry-functions.js +12 -0
- package/dist/lib/utils/s2/s2-geometry-functions.js.map +1 -0
- package/dist/lib/utils/s2/s2-token-functions.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/s2/s2geometry/s2-cell-utils.js +2 -2
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/s2/s2geometry/s2-geometry.js +5 -5
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +1 -0
- package/dist/lib/utils/version.js +2 -0
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/{esm/tile-3d-subtree-loader.js → tile-3d-subtree-loader.js} +2 -2
- package/dist/tile-3d-subtree-loader.js.map +1 -0
- package/dist/{esm/tile-3d-writer.js → tile-3d-writer.js} +2 -2
- package/dist/tile-3d-writer.js.map +1 -0
- package/dist/{esm/tiles-3d-loader.js → tiles-3d-loader.js} +3 -3
- package/dist/tiles-3d-loader.js.map +1 -0
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -0
- package/package.json +22 -14
- package/src/3d-tiles-archive/3d-tiles-archive-archive.ts +12 -11
- package/src/3d-tiles-archive/3d-tiles-archive-parser.ts +11 -11
- package/src/lib/filesystems/tiles-3d-archive-file-system.ts +11 -12
- package/src/types.ts +4 -4
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js +0 -126
- package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
- package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js +0 -69
- package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
- package/dist/es5/3d-tiles-archive-loader.js +0 -50
- package/dist/es5/3d-tiles-archive-loader.js.map +0 -1
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/cesium-ion-loader.js +0 -77
- package/dist/es5/cesium-ion-loader.js.map +0 -1
- package/dist/es5/index.js +0 -77
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/classes/helpers/tile-3d-accessor-utils.js +0 -114
- package/dist/es5/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
- package/dist/es5/lib/classes/tile-3d-batch-table-hierarchy.js +0 -180
- package/dist/es5/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
- package/dist/es5/lib/classes/tile-3d-batch-table.js +0 -285
- package/dist/es5/lib/classes/tile-3d-batch-table.js.map +0 -1
- package/dist/es5/lib/classes/tile-3d-feature-table.js +0 -97
- package/dist/es5/lib/classes/tile-3d-feature-table.js.map +0 -1
- package/dist/es5/lib/constants.js +0 -32
- package/dist/es5/lib/constants.js.map +0 -1
- package/dist/es5/lib/encoders/encode-3d-tile-batched-model.js +0 -49
- package/dist/es5/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
- package/dist/es5/lib/encoders/encode-3d-tile-composite.js +0 -30
- package/dist/es5/lib/encoders/encode-3d-tile-composite.js.map +0 -1
- package/dist/es5/lib/encoders/encode-3d-tile-instanced-model.js +0 -47
- package/dist/es5/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
- package/dist/es5/lib/encoders/encode-3d-tile-point-cloud.js +0 -48
- package/dist/es5/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
- package/dist/es5/lib/encoders/encode-3d-tile.js +0 -35
- package/dist/es5/lib/encoders/encode-3d-tile.js.map +0 -1
- package/dist/es5/lib/encoders/helpers/encode-3d-tile-header.js +0 -35
- package/dist/es5/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
- package/dist/es5/lib/filesystems/tiles-3d-archive-file-system.js +0 -151
- package/dist/es5/lib/filesystems/tiles-3d-archive-file-system.js.map +0 -1
- package/dist/es5/lib/ion/ion.js +0 -164
- package/dist/es5/lib/ion/ion.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -32
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -32
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -305
- package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -110
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js +0 -22
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -160
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js +0 -85
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
- package/dist/es5/lib/parsers/helpers/parse-utils.js +0 -28
- package/dist/es5/lib/parsers/helpers/parse-utils.js.map +0 -1
- package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js +0 -51
- package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
- package/dist/es5/lib/parsers/parse-3d-tile-composite.js +0 -50
- package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +0 -1
- package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +0 -54
- package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
- package/dist/es5/lib/parsers/parse-3d-tile-header.js +0 -291
- package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +0 -1
- package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js +0 -163
- package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js +0 -295
- package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
- package/dist/es5/lib/parsers/parse-3d-tile.js +0 -76
- package/dist/es5/lib/parsers/parse-3d-tile.js.map +0 -1
- package/dist/es5/lib/utils/obb/s2-corners-to-obb.js +0 -30
- package/dist/es5/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
- package/dist/es5/lib/utils/s2/converters/s2-to-boundary.js +0 -44
- package/dist/es5/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
- package/dist/es5/lib/utils/s2/converters/s2-to-obb-points.js +0 -30
- package/dist/es5/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
- package/dist/es5/lib/utils/s2/converters/s2-to-region.js +0 -52
- package/dist/es5/lib/utils/s2/converters/s2-to-region.js.map +0 -1
- package/dist/es5/lib/utils/s2/index.js +0 -90
- package/dist/es5/lib/utils/s2/index.js.map +0 -1
- package/dist/es5/lib/utils/s2/s2-geometry-functions.js +0 -19
- package/dist/es5/lib/utils/s2/s2-geometry-functions.js.map +0 -1
- package/dist/es5/lib/utils/s2/s2-token-functions.js +0 -41
- package/dist/es5/lib/utils/s2/s2-token-functions.js.map +0 -1
- package/dist/es5/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -22
- package/dist/es5/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
- package/dist/es5/lib/utils/s2/s2geometry/s2-geometry.js +0 -207
- package/dist/es5/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
- package/dist/es5/lib/utils/version.js +0 -9
- package/dist/es5/lib/utils/version.js.map +0 -1
- package/dist/es5/tile-3d-subtree-loader.js +0 -22
- package/dist/es5/tile-3d-subtree-loader.js.map +0 -1
- package/dist/es5/tile-3d-writer.js +0 -26
- package/dist/es5/tile-3d-writer.js.map +0 -1
- package/dist/es5/tiles-3d-loader.js +0 -135
- package/dist/es5/tiles-3d-loader.js.map +0 -1
- package/dist/es5/types.js +0 -2
- package/dist/es5/types.js.map +0 -1
- package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
- package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
- package/dist/esm/3d-tiles-archive-loader.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/cesium-ion-loader.js.map +0 -1
- package/dist/esm/index.js +0 -11
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
- package/dist/esm/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
- package/dist/esm/lib/classes/tile-3d-batch-table.js.map +0 -1
- package/dist/esm/lib/classes/tile-3d-feature-table.js.map +0 -1
- package/dist/esm/lib/constants.js.map +0 -1
- package/dist/esm/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
- package/dist/esm/lib/encoders/encode-3d-tile-composite.js.map +0 -1
- package/dist/esm/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
- package/dist/esm/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
- package/dist/esm/lib/encoders/encode-3d-tile.js.map +0 -1
- package/dist/esm/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
- package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js.map +0 -1
- package/dist/esm/lib/ion/ion.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
- package/dist/esm/lib/parsers/helpers/parse-utils.js.map +0 -1
- package/dist/esm/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
- package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +0 -1
- package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
- package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +0 -1
- package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
- package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
- package/dist/esm/lib/parsers/parse-3d-tile.js.map +0 -1
- package/dist/esm/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
- package/dist/esm/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
- package/dist/esm/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
- package/dist/esm/lib/utils/s2/converters/s2-to-region.js.map +0 -1
- package/dist/esm/lib/utils/s2/index.js +0 -7
- package/dist/esm/lib/utils/s2/index.js.map +0 -1
- package/dist/esm/lib/utils/s2/s2-geometry-functions.js +0 -12
- package/dist/esm/lib/utils/s2/s2-geometry-functions.js.map +0 -1
- package/dist/esm/lib/utils/s2/s2-token-functions.js.map +0 -1
- package/dist/esm/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
- package/dist/esm/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
- package/dist/esm/lib/utils/version.js +0 -2
- package/dist/esm/lib/utils/version.js.map +0 -1
- package/dist/esm/tile-3d-subtree-loader.js.map +0 -1
- package/dist/esm/tile-3d-writer.js.map +0 -1
- package/dist/esm/tiles-3d-loader.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
- package/src/bundle.ts +0 -4
- /package/dist/{esm/lib → lib}/classes/helpers/tile-3d-accessor-utils.js +0 -0
- /package/dist/{esm/lib → lib}/constants.js +0 -0
- /package/dist/{esm/lib → lib}/encoders/helpers/encode-3d-tile-header.js +0 -0
- /package/dist/{esm/lib → lib}/parsers/helpers/normalize-3d-tile-colors.js +0 -0
- /package/dist/{esm/lib → lib}/parsers/helpers/normalize-3d-tile-normals.js +0 -0
- /package/dist/{esm/lib → lib}/parsers/helpers/normalize-3d-tile-positions.js +0 -0
- /package/dist/{esm/lib → lib}/parsers/parse-3d-tile-gltf.js +0 -0
- /package/dist/{esm/lib → lib}/utils/s2/s2-token-functions.js +0 -0
- /package/dist/{esm/types.js → types.js} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2837 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
CesiumIonLoader: () => CesiumIonLoader,
|
|
34
|
+
TILE3D_TYPE: () => TILE3D_TYPE,
|
|
35
|
+
Tile3DBatchTable: () => Tile3DBatchTableParser,
|
|
36
|
+
Tile3DFeatureTable: () => Tile3DFeatureTable,
|
|
37
|
+
Tile3DSubtreeLoader: () => Tile3DSubtreeLoader,
|
|
38
|
+
Tile3DWriter: () => Tile3DWriter,
|
|
39
|
+
Tiles3DArchiveFileLoader: () => Tiles3DArchiveFileLoader,
|
|
40
|
+
Tiles3DArchiveFileSystem: () => Tiles3DArchiveFileSystem,
|
|
41
|
+
Tiles3DLoader: () => Tiles3DLoader,
|
|
42
|
+
_getIonTilesetMetadata: () => getIonTilesetMetadata
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(src_exports);
|
|
45
|
+
|
|
46
|
+
// src/tiles-3d-loader.ts
|
|
47
|
+
var import_loader_utils8 = require("@loaders.gl/loader-utils");
|
|
48
|
+
var import_tiles2 = require("@loaders.gl/tiles");
|
|
49
|
+
|
|
50
|
+
// src/lib/utils/version.ts
|
|
51
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
52
|
+
|
|
53
|
+
// src/lib/constants.ts
|
|
54
|
+
var TILE3D_TYPE = {
|
|
55
|
+
COMPOSITE: "cmpt",
|
|
56
|
+
POINT_CLOUD: "pnts",
|
|
57
|
+
BATCHED_3D_MODEL: "b3dm",
|
|
58
|
+
INSTANCED_3D_MODEL: "i3dm",
|
|
59
|
+
GEOMETRY: "geom",
|
|
60
|
+
VECTOR: "vect",
|
|
61
|
+
GLTF: "glTF"
|
|
62
|
+
};
|
|
63
|
+
var TILE3D_TYPES = Object.keys(TILE3D_TYPE);
|
|
64
|
+
var MAGIC_ARRAY = {
|
|
65
|
+
BATCHED_MODEL: [98, 51, 100, 109],
|
|
66
|
+
INSTANCED_MODEL: [105, 51, 100, 109],
|
|
67
|
+
POINT_CLOUD: [112, 110, 116, 115],
|
|
68
|
+
COMPOSITE: [99, 109, 112, 116]
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/lib/parsers/helpers/parse-utils.ts
|
|
72
|
+
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
73
|
+
function getStringFromArrayBuffer(arrayBuffer, byteOffset, byteLength) {
|
|
74
|
+
(0, import_loader_utils.assert)(arrayBuffer instanceof ArrayBuffer);
|
|
75
|
+
const textDecoder = new TextDecoder("utf8");
|
|
76
|
+
const typedArray = new Uint8Array(arrayBuffer, byteOffset, byteLength);
|
|
77
|
+
const string = textDecoder.decode(typedArray);
|
|
78
|
+
return string;
|
|
79
|
+
}
|
|
80
|
+
function getMagicString(arrayBuffer, byteOffset = 0) {
|
|
81
|
+
const dataView = new DataView(arrayBuffer);
|
|
82
|
+
return `${String.fromCharCode(dataView.getUint8(byteOffset + 0))}${String.fromCharCode(dataView.getUint8(byteOffset + 1))}${String.fromCharCode(dataView.getUint8(byteOffset + 2))}${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/lib/parsers/parse-3d-tile-point-cloud.ts
|
|
86
|
+
var import_draco = require("@loaders.gl/draco");
|
|
87
|
+
var import_loader_utils4 = require("@loaders.gl/loader-utils");
|
|
88
|
+
var import_math6 = require("@loaders.gl/math");
|
|
89
|
+
var import_core3 = require("@math.gl/core");
|
|
90
|
+
|
|
91
|
+
// src/lib/classes/tile-3d-feature-table.ts
|
|
92
|
+
var import_math = require("@loaders.gl/math");
|
|
93
|
+
var Tile3DFeatureTable = class {
|
|
94
|
+
constructor(featureTableJson, featureTableBinary) {
|
|
95
|
+
this.featuresLength = 0;
|
|
96
|
+
this._cachedTypedArrays = {};
|
|
97
|
+
this.json = featureTableJson;
|
|
98
|
+
this.buffer = featureTableBinary;
|
|
99
|
+
}
|
|
100
|
+
getExtension(extensionName) {
|
|
101
|
+
return this.json.extensions && this.json.extensions[extensionName];
|
|
102
|
+
}
|
|
103
|
+
hasProperty(propertyName) {
|
|
104
|
+
return Boolean(this.json[propertyName]);
|
|
105
|
+
}
|
|
106
|
+
getGlobalProperty(propertyName, componentType = import_math.GL.UNSIGNED_INT, componentLength = 1) {
|
|
107
|
+
const jsonValue = this.json[propertyName];
|
|
108
|
+
if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
|
|
109
|
+
return this._getTypedArrayFromBinary(
|
|
110
|
+
propertyName,
|
|
111
|
+
componentType,
|
|
112
|
+
componentLength,
|
|
113
|
+
1,
|
|
114
|
+
jsonValue.byteOffset
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return jsonValue;
|
|
118
|
+
}
|
|
119
|
+
getPropertyArray(propertyName, componentType, componentLength) {
|
|
120
|
+
const jsonValue = this.json[propertyName];
|
|
121
|
+
if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
|
|
122
|
+
if ("componentType" in jsonValue) {
|
|
123
|
+
componentType = import_math.GLType.fromName(jsonValue.componentType);
|
|
124
|
+
}
|
|
125
|
+
return this._getTypedArrayFromBinary(
|
|
126
|
+
propertyName,
|
|
127
|
+
componentType,
|
|
128
|
+
componentLength,
|
|
129
|
+
this.featuresLength,
|
|
130
|
+
jsonValue.byteOffset
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return this._getTypedArrayFromArray(propertyName, componentType, jsonValue);
|
|
134
|
+
}
|
|
135
|
+
getProperty(propertyName, componentType, componentLength, featureId, result) {
|
|
136
|
+
const jsonValue = this.json[propertyName];
|
|
137
|
+
if (!jsonValue) {
|
|
138
|
+
return jsonValue;
|
|
139
|
+
}
|
|
140
|
+
const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
|
|
141
|
+
if (componentLength === 1) {
|
|
142
|
+
return typedArray[featureId];
|
|
143
|
+
}
|
|
144
|
+
for (let i = 0; i < componentLength; ++i) {
|
|
145
|
+
result[i] = typedArray[componentLength * featureId + i];
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
// HELPERS
|
|
150
|
+
_getTypedArrayFromBinary(propertyName, componentType, componentLength, count, byteOffset) {
|
|
151
|
+
const cachedTypedArrays = this._cachedTypedArrays;
|
|
152
|
+
let typedArray = cachedTypedArrays[propertyName];
|
|
153
|
+
if (!typedArray) {
|
|
154
|
+
typedArray = import_math.GLType.createTypedArray(
|
|
155
|
+
componentType,
|
|
156
|
+
this.buffer.buffer,
|
|
157
|
+
this.buffer.byteOffset + byteOffset,
|
|
158
|
+
count * componentLength
|
|
159
|
+
);
|
|
160
|
+
cachedTypedArrays[propertyName] = typedArray;
|
|
161
|
+
}
|
|
162
|
+
return typedArray;
|
|
163
|
+
}
|
|
164
|
+
_getTypedArrayFromArray(propertyName, componentType, array) {
|
|
165
|
+
const cachedTypedArrays = this._cachedTypedArrays;
|
|
166
|
+
let typedArray = cachedTypedArrays[propertyName];
|
|
167
|
+
if (!typedArray) {
|
|
168
|
+
typedArray = import_math.GLType.createTypedArray(componentType, array);
|
|
169
|
+
cachedTypedArrays[propertyName] = typedArray;
|
|
170
|
+
}
|
|
171
|
+
return typedArray;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// src/lib/classes/tile-3d-batch-table.ts
|
|
176
|
+
var import_loader_utils3 = require("@loaders.gl/loader-utils");
|
|
177
|
+
|
|
178
|
+
// src/lib/classes/helpers/tile-3d-accessor-utils.ts
|
|
179
|
+
var import_math2 = require("@loaders.gl/math");
|
|
180
|
+
var import_loader_utils2 = require("@loaders.gl/loader-utils");
|
|
181
|
+
var COMPONENTS_PER_ATTRIBUTE = {
|
|
182
|
+
SCALAR: 1,
|
|
183
|
+
VEC2: 2,
|
|
184
|
+
VEC3: 3,
|
|
185
|
+
VEC4: 4,
|
|
186
|
+
MAT2: 4,
|
|
187
|
+
MAT3: 9,
|
|
188
|
+
MAT4: 16
|
|
189
|
+
};
|
|
190
|
+
var UNPACKER = {
|
|
191
|
+
SCALAR: (values, i) => values[i],
|
|
192
|
+
VEC2: (values, i) => [values[2 * i + 0], values[2 * i + 1]],
|
|
193
|
+
VEC3: (values, i) => [values[3 * i + 0], values[3 * i + 1], values[3 * i + 2]],
|
|
194
|
+
VEC4: (values, i) => [values[4 * i + 0], values[4 * i + 1], values[4 * i + 2], values[4 * i + 3]],
|
|
195
|
+
// TODO: check column major
|
|
196
|
+
MAT2: (values, i) => [
|
|
197
|
+
values[4 * i + 0],
|
|
198
|
+
values[4 * i + 1],
|
|
199
|
+
values[4 * i + 2],
|
|
200
|
+
values[4 * i + 3]
|
|
201
|
+
],
|
|
202
|
+
MAT3: (values, i) => [
|
|
203
|
+
values[9 * i + 0],
|
|
204
|
+
values[9 * i + 1],
|
|
205
|
+
values[9 * i + 2],
|
|
206
|
+
values[9 * i + 3],
|
|
207
|
+
values[9 * i + 4],
|
|
208
|
+
values[9 * i + 5],
|
|
209
|
+
values[9 * i + 6],
|
|
210
|
+
values[9 * i + 7],
|
|
211
|
+
values[9 * i + 8]
|
|
212
|
+
],
|
|
213
|
+
MAT4: (values, i) => [
|
|
214
|
+
values[16 * i + 0],
|
|
215
|
+
values[16 * i + 1],
|
|
216
|
+
values[16 * i + 2],
|
|
217
|
+
values[16 * i + 3],
|
|
218
|
+
values[16 * i + 4],
|
|
219
|
+
values[16 * i + 5],
|
|
220
|
+
values[16 * i + 6],
|
|
221
|
+
values[16 * i + 7],
|
|
222
|
+
values[16 * i + 8],
|
|
223
|
+
values[16 * i + 9],
|
|
224
|
+
values[16 * i + 10],
|
|
225
|
+
values[16 * i + 11],
|
|
226
|
+
values[16 * i + 12],
|
|
227
|
+
values[16 * i + 13],
|
|
228
|
+
values[16 * i + 14],
|
|
229
|
+
values[16 * i + 15]
|
|
230
|
+
]
|
|
231
|
+
};
|
|
232
|
+
var PACKER = {
|
|
233
|
+
SCALAR: (x, values, i) => {
|
|
234
|
+
values[i] = x;
|
|
235
|
+
},
|
|
236
|
+
VEC2: (x, values, i) => {
|
|
237
|
+
values[2 * i + 0] = x[0];
|
|
238
|
+
values[2 * i + 1] = x[1];
|
|
239
|
+
},
|
|
240
|
+
VEC3: (x, values, i) => {
|
|
241
|
+
values[3 * i + 0] = x[0];
|
|
242
|
+
values[3 * i + 1] = x[1];
|
|
243
|
+
values[3 * i + 2] = x[2];
|
|
244
|
+
},
|
|
245
|
+
VEC4: (x, values, i) => {
|
|
246
|
+
values[4 * i + 0] = x[0];
|
|
247
|
+
values[4 * i + 1] = x[1];
|
|
248
|
+
values[4 * i + 2] = x[2];
|
|
249
|
+
values[4 * i + 3] = x[3];
|
|
250
|
+
},
|
|
251
|
+
// TODO: check column major correctness
|
|
252
|
+
MAT2: (x, values, i) => {
|
|
253
|
+
values[4 * i + 0] = x[0];
|
|
254
|
+
values[4 * i + 1] = x[1];
|
|
255
|
+
values[4 * i + 2] = x[2];
|
|
256
|
+
values[4 * i + 3] = x[3];
|
|
257
|
+
},
|
|
258
|
+
MAT3: (x, values, i) => {
|
|
259
|
+
values[9 * i + 0] = x[0];
|
|
260
|
+
values[9 * i + 1] = x[1];
|
|
261
|
+
values[9 * i + 2] = x[2];
|
|
262
|
+
values[9 * i + 3] = x[3];
|
|
263
|
+
values[9 * i + 4] = x[4];
|
|
264
|
+
values[9 * i + 5] = x[5];
|
|
265
|
+
values[9 * i + 6] = x[6];
|
|
266
|
+
values[9 * i + 7] = x[7];
|
|
267
|
+
values[9 * i + 8] = x[8];
|
|
268
|
+
values[9 * i + 9] = x[9];
|
|
269
|
+
},
|
|
270
|
+
MAT4: (x, values, i) => {
|
|
271
|
+
values[16 * i + 0] = x[0];
|
|
272
|
+
values[16 * i + 1] = x[1];
|
|
273
|
+
values[16 * i + 2] = x[2];
|
|
274
|
+
values[16 * i + 3] = x[3];
|
|
275
|
+
values[16 * i + 4] = x[4];
|
|
276
|
+
values[16 * i + 5] = x[5];
|
|
277
|
+
values[16 * i + 6] = x[6];
|
|
278
|
+
values[16 * i + 7] = x[7];
|
|
279
|
+
values[16 * i + 8] = x[8];
|
|
280
|
+
values[16 * i + 9] = x[9];
|
|
281
|
+
values[16 * i + 10] = x[10];
|
|
282
|
+
values[16 * i + 11] = x[11];
|
|
283
|
+
values[16 * i + 12] = x[12];
|
|
284
|
+
values[16 * i + 13] = x[13];
|
|
285
|
+
values[16 * i + 14] = x[14];
|
|
286
|
+
values[16 * i + 15] = x[15];
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
function createTypedArrayFromAccessor(tile3DAccessor, buffer, byteOffset, length) {
|
|
290
|
+
const { componentType } = tile3DAccessor;
|
|
291
|
+
(0, import_loader_utils2.assert)(tile3DAccessor.componentType);
|
|
292
|
+
const type = typeof componentType === "string" ? import_math2.GLType.fromName(componentType) : componentType;
|
|
293
|
+
const size = COMPONENTS_PER_ATTRIBUTE[tile3DAccessor.type];
|
|
294
|
+
const unpacker = UNPACKER[tile3DAccessor.type];
|
|
295
|
+
const packer = PACKER[tile3DAccessor.type];
|
|
296
|
+
byteOffset += tile3DAccessor.byteOffset;
|
|
297
|
+
const values = import_math2.GLType.createTypedArray(type, buffer, byteOffset, size * length);
|
|
298
|
+
return {
|
|
299
|
+
values,
|
|
300
|
+
type,
|
|
301
|
+
size,
|
|
302
|
+
unpacker,
|
|
303
|
+
packer
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// src/lib/classes/tile-3d-batch-table-hierarchy.ts
|
|
308
|
+
var defined = (x) => x !== void 0;
|
|
309
|
+
function initializeHierarchy(batchTable, jsonHeader, binaryBody) {
|
|
310
|
+
if (!jsonHeader) {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
let hierarchy = batchTable.getExtension("3DTILES_batch_table_hierarchy");
|
|
314
|
+
const legacyHierarchy = jsonHeader.HIERARCHY;
|
|
315
|
+
if (legacyHierarchy) {
|
|
316
|
+
console.warn("3D Tile Parser: HIERARCHY is deprecated. Use 3DTILES_batch_table_hierarchy.");
|
|
317
|
+
jsonHeader.extensions = jsonHeader.extensions || {};
|
|
318
|
+
jsonHeader.extensions["3DTILES_batch_table_hierarchy"] = legacyHierarchy;
|
|
319
|
+
hierarchy = legacyHierarchy;
|
|
320
|
+
}
|
|
321
|
+
if (!hierarchy) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
return initializeHierarchyValues(hierarchy, binaryBody);
|
|
325
|
+
}
|
|
326
|
+
function initializeHierarchyValues(hierarchyJson, binaryBody) {
|
|
327
|
+
let i;
|
|
328
|
+
let classId;
|
|
329
|
+
let binaryAccessor;
|
|
330
|
+
const instancesLength = hierarchyJson.instancesLength;
|
|
331
|
+
const classes = hierarchyJson.classes;
|
|
332
|
+
let classIds = hierarchyJson.classIds;
|
|
333
|
+
let parentCounts = hierarchyJson.parentCounts;
|
|
334
|
+
let parentIds = hierarchyJson.parentIds;
|
|
335
|
+
let parentIdsLength = instancesLength;
|
|
336
|
+
if (defined(classIds.byteOffset)) {
|
|
337
|
+
classIds.componentType = defaultValue(classIds.componentType, GL.UNSIGNED_SHORT);
|
|
338
|
+
classIds.type = AttributeType.SCALAR;
|
|
339
|
+
binaryAccessor = getBinaryAccessor(classIds);
|
|
340
|
+
classIds = binaryAccessor.createArrayBufferView(
|
|
341
|
+
binaryBody.buffer,
|
|
342
|
+
binaryBody.byteOffset + classIds.byteOffset,
|
|
343
|
+
instancesLength
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
let parentIndexes;
|
|
347
|
+
if (defined(parentCounts)) {
|
|
348
|
+
if (defined(parentCounts.byteOffset)) {
|
|
349
|
+
parentCounts.componentType = defaultValue(parentCounts.componentType, GL.UNSIGNED_SHORT);
|
|
350
|
+
parentCounts.type = AttributeType.SCALAR;
|
|
351
|
+
binaryAccessor = getBinaryAccessor(parentCounts);
|
|
352
|
+
parentCounts = binaryAccessor.createArrayBufferView(
|
|
353
|
+
binaryBody.buffer,
|
|
354
|
+
binaryBody.byteOffset + parentCounts.byteOffset,
|
|
355
|
+
instancesLength
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
parentIndexes = new Uint16Array(instancesLength);
|
|
359
|
+
parentIdsLength = 0;
|
|
360
|
+
for (i = 0; i < instancesLength; ++i) {
|
|
361
|
+
parentIndexes[i] = parentIdsLength;
|
|
362
|
+
parentIdsLength += parentCounts[i];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (defined(parentIds) && defined(parentIds.byteOffset)) {
|
|
366
|
+
parentIds.componentType = defaultValue(parentIds.componentType, GL.UNSIGNED_SHORT);
|
|
367
|
+
parentIds.type = AttributeType.SCALAR;
|
|
368
|
+
binaryAccessor = getBinaryAccessor(parentIds);
|
|
369
|
+
parentIds = binaryAccessor.createArrayBufferView(
|
|
370
|
+
binaryBody.buffer,
|
|
371
|
+
binaryBody.byteOffset + parentIds.byteOffset,
|
|
372
|
+
parentIdsLength
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
const classesLength = classes.length;
|
|
376
|
+
for (i = 0; i < classesLength; ++i) {
|
|
377
|
+
const classInstancesLength = classes[i].length;
|
|
378
|
+
const properties = classes[i].instances;
|
|
379
|
+
const binaryProperties = getBinaryProperties(classInstancesLength, properties, binaryBody);
|
|
380
|
+
classes[i].instances = combine(binaryProperties, properties);
|
|
381
|
+
}
|
|
382
|
+
const classCounts = new Array(classesLength).fill(0);
|
|
383
|
+
const classIndexes = new Uint16Array(instancesLength);
|
|
384
|
+
for (i = 0; i < instancesLength; ++i) {
|
|
385
|
+
classId = classIds[i];
|
|
386
|
+
classIndexes[i] = classCounts[classId];
|
|
387
|
+
++classCounts[classId];
|
|
388
|
+
}
|
|
389
|
+
const hierarchy = {
|
|
390
|
+
classes,
|
|
391
|
+
classIds,
|
|
392
|
+
classIndexes,
|
|
393
|
+
parentCounts,
|
|
394
|
+
parentIndexes,
|
|
395
|
+
parentIds
|
|
396
|
+
};
|
|
397
|
+
validateHierarchy(hierarchy);
|
|
398
|
+
return hierarchy;
|
|
399
|
+
}
|
|
400
|
+
function traverseHierarchy(hierarchy, instanceIndex, endConditionCallback) {
|
|
401
|
+
if (!hierarchy) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const parentCounts = hierarchy.parentCounts;
|
|
405
|
+
const parentIds = hierarchy.parentIds;
|
|
406
|
+
if (parentIds) {
|
|
407
|
+
return endConditionCallback(hierarchy, instanceIndex);
|
|
408
|
+
}
|
|
409
|
+
if (parentCounts > 0) {
|
|
410
|
+
return traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback);
|
|
411
|
+
}
|
|
412
|
+
return traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback);
|
|
413
|
+
}
|
|
414
|
+
function traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback) {
|
|
415
|
+
const classIds = hierarchy.classIds;
|
|
416
|
+
const parentCounts = hierarchy.parentCounts;
|
|
417
|
+
const parentIds = hierarchy.parentIds;
|
|
418
|
+
const parentIndexes = hierarchy.parentIndexes;
|
|
419
|
+
const instancesLength = classIds.length;
|
|
420
|
+
const visited = scratchVisited;
|
|
421
|
+
visited.length = Math.max(visited.length, instancesLength);
|
|
422
|
+
const visitedMarker = ++marker;
|
|
423
|
+
const stack2 = scratchStack;
|
|
424
|
+
stack2.length = 0;
|
|
425
|
+
stack2.push(instanceIndex);
|
|
426
|
+
while (stack2.length > 0) {
|
|
427
|
+
instanceIndex = stack2.pop();
|
|
428
|
+
if (visited[instanceIndex] === visitedMarker) {
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
visited[instanceIndex] = visitedMarker;
|
|
432
|
+
const result = endConditionCallback(hierarchy, instanceIndex);
|
|
433
|
+
if (defined(result)) {
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
const parentCount = parentCounts[instanceIndex];
|
|
437
|
+
const parentIndex = parentIndexes[instanceIndex];
|
|
438
|
+
for (let i = 0; i < parentCount; ++i) {
|
|
439
|
+
const parentId = parentIds[parentIndex + i];
|
|
440
|
+
if (parentId !== instanceIndex) {
|
|
441
|
+
stack2.push(parentId);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
function traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback) {
|
|
448
|
+
let hasParent = true;
|
|
449
|
+
while (hasParent) {
|
|
450
|
+
const result = endConditionCallback(hierarchy, instanceIndex);
|
|
451
|
+
if (defined(result)) {
|
|
452
|
+
return result;
|
|
453
|
+
}
|
|
454
|
+
const parentId = hierarchy.parentIds[instanceIndex];
|
|
455
|
+
hasParent = parentId !== instanceIndex;
|
|
456
|
+
instanceIndex = parentId;
|
|
457
|
+
}
|
|
458
|
+
throw new Error("traverseHierarchySingleParent");
|
|
459
|
+
}
|
|
460
|
+
function validateHierarchy(hierarchy) {
|
|
461
|
+
const scratchValidateStack = [];
|
|
462
|
+
const classIds = hierarchy.classIds;
|
|
463
|
+
const instancesLength = classIds.length;
|
|
464
|
+
for (let i = 0; i < instancesLength; ++i) {
|
|
465
|
+
validateInstance(hierarchy, i, stack);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function validateInstance(hierarchy, instanceIndex, stack2) {
|
|
469
|
+
const parentCounts = hierarchy.parentCounts;
|
|
470
|
+
const parentIds = hierarchy.parentIds;
|
|
471
|
+
const parentIndexes = hierarchy.parentIndexes;
|
|
472
|
+
const classIds = hierarchy.classIds;
|
|
473
|
+
const instancesLength = classIds.length;
|
|
474
|
+
if (!defined(parentIds)) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
assert(
|
|
478
|
+
instanceIndex < instancesLength,
|
|
479
|
+
`Parent index ${instanceIndex} exceeds the total number of instances: ${instancesLength}`
|
|
480
|
+
);
|
|
481
|
+
assert(
|
|
482
|
+
stack2.indexOf(instanceIndex) === -1,
|
|
483
|
+
"Circular dependency detected in the batch table hierarchy."
|
|
484
|
+
);
|
|
485
|
+
stack2.push(instanceIndex);
|
|
486
|
+
const parentCount = defined(parentCounts) ? parentCounts[instanceIndex] : 1;
|
|
487
|
+
const parentIndex = defined(parentCounts) ? parentIndexes[instanceIndex] : instanceIndex;
|
|
488
|
+
for (let i = 0; i < parentCount; ++i) {
|
|
489
|
+
const parentId = parentIds[parentIndex + i];
|
|
490
|
+
if (parentId !== instanceIndex) {
|
|
491
|
+
validateInstance(hierarchy, parentId, stack2);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
stack2.pop(instanceIndex);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/lib/classes/tile-3d-batch-table.ts
|
|
498
|
+
function defined2(x) {
|
|
499
|
+
return x !== void 0 && x !== null;
|
|
500
|
+
}
|
|
501
|
+
var clone = (x, y) => x;
|
|
502
|
+
var IGNORED_PROPERTY_FIELDS = {
|
|
503
|
+
HIERARCHY: true,
|
|
504
|
+
// Deprecated HIERARCHY property
|
|
505
|
+
extensions: true,
|
|
506
|
+
extras: true
|
|
507
|
+
};
|
|
508
|
+
var Tile3DBatchTableParser = class {
|
|
509
|
+
constructor(json, binary, featureCount, options = {}) {
|
|
510
|
+
var _a;
|
|
511
|
+
(0, import_loader_utils3.assert)(featureCount >= 0);
|
|
512
|
+
this.json = json || {};
|
|
513
|
+
this.binary = binary;
|
|
514
|
+
this.featureCount = featureCount;
|
|
515
|
+
this._extensions = ((_a = this.json) == null ? void 0 : _a.extensions) || {};
|
|
516
|
+
this._properties = {};
|
|
517
|
+
for (const propertyName in this.json) {
|
|
518
|
+
if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
|
|
519
|
+
this._properties[propertyName] = this.json[propertyName];
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
this._binaryProperties = this._initializeBinaryProperties();
|
|
523
|
+
if (options["3DTILES_batch_table_hierarchy"]) {
|
|
524
|
+
this._hierarchy = initializeHierarchy(this, this.json, this.binary);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
getExtension(extensionName) {
|
|
528
|
+
return this.json && this.json.extensions && this.json.extensions[extensionName];
|
|
529
|
+
}
|
|
530
|
+
memorySizeInBytes() {
|
|
531
|
+
return 0;
|
|
532
|
+
}
|
|
533
|
+
isClass(batchId, className) {
|
|
534
|
+
this._checkBatchId(batchId);
|
|
535
|
+
(0, import_loader_utils3.assert)(typeof className === "string", className);
|
|
536
|
+
if (this._hierarchy) {
|
|
537
|
+
const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
538
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
539
|
+
const instanceClass = hierarchy.classes[classId];
|
|
540
|
+
return instanceClass.name === className;
|
|
541
|
+
});
|
|
542
|
+
return defined2(result);
|
|
543
|
+
}
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
isExactClass(batchId, className) {
|
|
547
|
+
(0, import_loader_utils3.assert)(typeof className === "string", className);
|
|
548
|
+
return this.getExactClassName(batchId) === className;
|
|
549
|
+
}
|
|
550
|
+
getExactClassName(batchId) {
|
|
551
|
+
this._checkBatchId(batchId);
|
|
552
|
+
if (this._hierarchy) {
|
|
553
|
+
const classId = this._hierarchy.classIds[batchId];
|
|
554
|
+
const instanceClass = this._hierarchy.classes[classId];
|
|
555
|
+
return instanceClass.name;
|
|
556
|
+
}
|
|
557
|
+
return void 0;
|
|
558
|
+
}
|
|
559
|
+
hasProperty(batchId, name) {
|
|
560
|
+
this._checkBatchId(batchId);
|
|
561
|
+
(0, import_loader_utils3.assert)(typeof name === "string", name);
|
|
562
|
+
return defined2(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
|
|
563
|
+
}
|
|
564
|
+
getPropertyNames(batchId, results) {
|
|
565
|
+
this._checkBatchId(batchId);
|
|
566
|
+
results = defined2(results) ? results : [];
|
|
567
|
+
results.length = 0;
|
|
568
|
+
const propertyNames = Object.keys(this._properties);
|
|
569
|
+
results.push(...propertyNames);
|
|
570
|
+
if (this._hierarchy) {
|
|
571
|
+
this._getPropertyNamesInHierarchy(batchId, results);
|
|
572
|
+
}
|
|
573
|
+
return results;
|
|
574
|
+
}
|
|
575
|
+
getProperty(batchId, name) {
|
|
576
|
+
this._checkBatchId(batchId);
|
|
577
|
+
(0, import_loader_utils3.assert)(typeof name === "string", name);
|
|
578
|
+
if (this._binaryProperties) {
|
|
579
|
+
const binaryProperty = this._binaryProperties[name];
|
|
580
|
+
if (defined2(binaryProperty)) {
|
|
581
|
+
return this._getBinaryProperty(binaryProperty, batchId);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const propertyValues = this._properties[name];
|
|
585
|
+
if (defined2(propertyValues)) {
|
|
586
|
+
return clone(propertyValues[batchId], true);
|
|
587
|
+
}
|
|
588
|
+
if (this._hierarchy) {
|
|
589
|
+
const hierarchyProperty = this._getHierarchyProperty(batchId, name);
|
|
590
|
+
if (defined2(hierarchyProperty)) {
|
|
591
|
+
return hierarchyProperty;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return void 0;
|
|
595
|
+
}
|
|
596
|
+
setProperty(batchId, name, value) {
|
|
597
|
+
const featureCount = this.featureCount;
|
|
598
|
+
this._checkBatchId(batchId);
|
|
599
|
+
(0, import_loader_utils3.assert)(typeof name === "string", name);
|
|
600
|
+
if (this._binaryProperties) {
|
|
601
|
+
const binaryProperty = this._binaryProperties[name];
|
|
602
|
+
if (binaryProperty) {
|
|
603
|
+
this._setBinaryProperty(binaryProperty, batchId, value);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (this._hierarchy) {
|
|
608
|
+
if (this._setHierarchyProperty(this, batchId, name, value)) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
let propertyValues = this._properties[name];
|
|
613
|
+
if (!defined2(propertyValues)) {
|
|
614
|
+
this._properties[name] = new Array(featureCount);
|
|
615
|
+
propertyValues = this._properties[name];
|
|
616
|
+
}
|
|
617
|
+
propertyValues[batchId] = clone(value, true);
|
|
618
|
+
}
|
|
619
|
+
// PRIVATE METHODS
|
|
620
|
+
_checkBatchId(batchId) {
|
|
621
|
+
const valid = batchId >= 0 && batchId < this.featureCount;
|
|
622
|
+
if (!valid) {
|
|
623
|
+
throw new Error("batchId not in range [0, featureCount - 1].");
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
_getBinaryProperty(binaryProperty, index) {
|
|
627
|
+
return binaryProperty.unpack(binaryProperty.typedArray, index);
|
|
628
|
+
}
|
|
629
|
+
_setBinaryProperty(binaryProperty, index, value) {
|
|
630
|
+
binaryProperty.pack(value, binaryProperty.typedArray, index);
|
|
631
|
+
}
|
|
632
|
+
_initializeBinaryProperties() {
|
|
633
|
+
let binaryProperties = null;
|
|
634
|
+
for (const name in this._properties) {
|
|
635
|
+
const property = this._properties[name];
|
|
636
|
+
const binaryProperty = this._initializeBinaryProperty(name, property);
|
|
637
|
+
if (binaryProperty) {
|
|
638
|
+
binaryProperties = binaryProperties || {};
|
|
639
|
+
binaryProperties[name] = binaryProperty;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return binaryProperties;
|
|
643
|
+
}
|
|
644
|
+
_initializeBinaryProperty(name, property) {
|
|
645
|
+
if ("byteOffset" in property) {
|
|
646
|
+
const tile3DAccessor = property;
|
|
647
|
+
(0, import_loader_utils3.assert)(this.binary, `Property ${name} requires a batch table binary.`);
|
|
648
|
+
(0, import_loader_utils3.assert)(tile3DAccessor.type, `Property ${name} requires a type.`);
|
|
649
|
+
const accessor = createTypedArrayFromAccessor(
|
|
650
|
+
tile3DAccessor,
|
|
651
|
+
this.binary.buffer,
|
|
652
|
+
this.binary.byteOffset | 0,
|
|
653
|
+
this.featureCount
|
|
654
|
+
);
|
|
655
|
+
return {
|
|
656
|
+
typedArray: accessor.values,
|
|
657
|
+
componentCount: accessor.size,
|
|
658
|
+
unpack: accessor.unpacker,
|
|
659
|
+
pack: accessor.packer
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
return null;
|
|
663
|
+
}
|
|
664
|
+
// EXTENSION SUPPORT: 3DTILES_batch_table_hierarchy
|
|
665
|
+
_hasPropertyInHierarchy(batchId, name) {
|
|
666
|
+
if (!this._hierarchy) {
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
670
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
671
|
+
const instances = hierarchy.classes[classId].instances;
|
|
672
|
+
return defined2(instances[name]);
|
|
673
|
+
});
|
|
674
|
+
return defined2(result);
|
|
675
|
+
}
|
|
676
|
+
_getPropertyNamesInHierarchy(batchId, results) {
|
|
677
|
+
traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
678
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
679
|
+
const instances = hierarchy.classes[classId].instances;
|
|
680
|
+
for (const name in instances) {
|
|
681
|
+
if (instances.hasOwnProperty(name)) {
|
|
682
|
+
if (results.indexOf(name) === -1) {
|
|
683
|
+
results.push(name);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
_getHierarchyProperty(batchId, name) {
|
|
690
|
+
return traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
691
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
692
|
+
const instanceClass = hierarchy.classes[classId];
|
|
693
|
+
const indexInClass = hierarchy.classIndexes[instanceIndex];
|
|
694
|
+
const propertyValues = instanceClass.instances[name];
|
|
695
|
+
if (defined2(propertyValues)) {
|
|
696
|
+
if (defined2(propertyValues.typedArray)) {
|
|
697
|
+
return this._getBinaryProperty(propertyValues, indexInClass);
|
|
698
|
+
}
|
|
699
|
+
return clone(propertyValues[indexInClass], true);
|
|
700
|
+
}
|
|
701
|
+
return null;
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
_setHierarchyProperty(batchTable, batchId, name, value) {
|
|
705
|
+
const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
706
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
707
|
+
const instanceClass = hierarchy.classes[classId];
|
|
708
|
+
const indexInClass = hierarchy.classIndexes[instanceIndex];
|
|
709
|
+
const propertyValues = instanceClass.instances[name];
|
|
710
|
+
if (defined2(propertyValues)) {
|
|
711
|
+
(0, import_loader_utils3.assert)(instanceIndex === batchId, `Inherited property "${name}" is read-only.`);
|
|
712
|
+
if (defined2(propertyValues.typedArray)) {
|
|
713
|
+
this._setBinaryProperty(propertyValues, indexInClass, value);
|
|
714
|
+
} else {
|
|
715
|
+
propertyValues[indexInClass] = clone(value, true);
|
|
716
|
+
}
|
|
717
|
+
return true;
|
|
718
|
+
}
|
|
719
|
+
return false;
|
|
720
|
+
});
|
|
721
|
+
return defined2(result);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
// src/lib/parsers/helpers/parse-3d-tile-header.ts
|
|
726
|
+
var SIZEOF_UINT32 = 4;
|
|
727
|
+
function parse3DTileHeaderSync(tile, arrayBuffer, byteOffset = 0) {
|
|
728
|
+
const view = new DataView(arrayBuffer);
|
|
729
|
+
tile.magic = view.getUint32(byteOffset, true);
|
|
730
|
+
byteOffset += SIZEOF_UINT32;
|
|
731
|
+
tile.version = view.getUint32(byteOffset, true);
|
|
732
|
+
byteOffset += SIZEOF_UINT32;
|
|
733
|
+
tile.byteLength = view.getUint32(byteOffset, true);
|
|
734
|
+
byteOffset += SIZEOF_UINT32;
|
|
735
|
+
if (tile.version !== 1) {
|
|
736
|
+
throw new Error(`3D Tile Version ${tile.version} not supported`);
|
|
737
|
+
}
|
|
738
|
+
return byteOffset;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// src/lib/parsers/helpers/parse-3d-tile-tables.ts
|
|
742
|
+
var SIZEOF_UINT322 = 4;
|
|
743
|
+
var DEPRECATION_WARNING = "b3dm tile in legacy format.";
|
|
744
|
+
function parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset) {
|
|
745
|
+
const view = new DataView(arrayBuffer);
|
|
746
|
+
let batchLength;
|
|
747
|
+
tile.header = tile.header || {};
|
|
748
|
+
let featureTableJsonByteLength = view.getUint32(byteOffset, true);
|
|
749
|
+
byteOffset += SIZEOF_UINT322;
|
|
750
|
+
let featureTableBinaryByteLength = view.getUint32(byteOffset, true);
|
|
751
|
+
byteOffset += SIZEOF_UINT322;
|
|
752
|
+
let batchTableJsonByteLength = view.getUint32(byteOffset, true);
|
|
753
|
+
byteOffset += SIZEOF_UINT322;
|
|
754
|
+
let batchTableBinaryByteLength = view.getUint32(byteOffset, true);
|
|
755
|
+
byteOffset += SIZEOF_UINT322;
|
|
756
|
+
if (batchTableJsonByteLength >= 570425344) {
|
|
757
|
+
byteOffset -= SIZEOF_UINT322 * 2;
|
|
758
|
+
batchLength = featureTableJsonByteLength;
|
|
759
|
+
batchTableJsonByteLength = featureTableBinaryByteLength;
|
|
760
|
+
batchTableBinaryByteLength = 0;
|
|
761
|
+
featureTableJsonByteLength = 0;
|
|
762
|
+
featureTableBinaryByteLength = 0;
|
|
763
|
+
console.warn(DEPRECATION_WARNING);
|
|
764
|
+
} else if (batchTableBinaryByteLength >= 570425344) {
|
|
765
|
+
byteOffset -= SIZEOF_UINT322;
|
|
766
|
+
batchLength = batchTableJsonByteLength;
|
|
767
|
+
batchTableJsonByteLength = featureTableJsonByteLength;
|
|
768
|
+
batchTableBinaryByteLength = featureTableBinaryByteLength;
|
|
769
|
+
featureTableJsonByteLength = 0;
|
|
770
|
+
featureTableBinaryByteLength = 0;
|
|
771
|
+
console.warn(DEPRECATION_WARNING);
|
|
772
|
+
}
|
|
773
|
+
tile.header.featureTableJsonByteLength = featureTableJsonByteLength;
|
|
774
|
+
tile.header.featureTableBinaryByteLength = featureTableBinaryByteLength;
|
|
775
|
+
tile.header.batchTableJsonByteLength = batchTableJsonByteLength;
|
|
776
|
+
tile.header.batchTableBinaryByteLength = batchTableBinaryByteLength;
|
|
777
|
+
tile.header.batchLength = batchLength;
|
|
778
|
+
return byteOffset;
|
|
779
|
+
}
|
|
780
|
+
function parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options) {
|
|
781
|
+
byteOffset = parse3DTileFeatureTable(tile, arrayBuffer, byteOffset, options);
|
|
782
|
+
byteOffset = parse3DTileBatchTable(tile, arrayBuffer, byteOffset, options);
|
|
783
|
+
return byteOffset;
|
|
784
|
+
}
|
|
785
|
+
function parse3DTileFeatureTable(tile, arrayBuffer, byteOffset, options) {
|
|
786
|
+
const { featureTableJsonByteLength, featureTableBinaryByteLength, batchLength } = tile.header || {};
|
|
787
|
+
tile.featureTableJson = {
|
|
788
|
+
BATCH_LENGTH: batchLength || 0
|
|
789
|
+
};
|
|
790
|
+
if (featureTableJsonByteLength && featureTableJsonByteLength > 0) {
|
|
791
|
+
const featureTableString = getStringFromArrayBuffer(
|
|
792
|
+
arrayBuffer,
|
|
793
|
+
byteOffset,
|
|
794
|
+
featureTableJsonByteLength
|
|
795
|
+
);
|
|
796
|
+
tile.featureTableJson = JSON.parse(featureTableString);
|
|
797
|
+
}
|
|
798
|
+
byteOffset += featureTableJsonByteLength || 0;
|
|
799
|
+
tile.featureTableBinary = new Uint8Array(arrayBuffer, byteOffset, featureTableBinaryByteLength);
|
|
800
|
+
byteOffset += featureTableBinaryByteLength || 0;
|
|
801
|
+
return byteOffset;
|
|
802
|
+
}
|
|
803
|
+
function parse3DTileBatchTable(tile, arrayBuffer, byteOffset, options) {
|
|
804
|
+
const { batchTableJsonByteLength, batchTableBinaryByteLength } = tile.header || {};
|
|
805
|
+
if (batchTableJsonByteLength && batchTableJsonByteLength > 0) {
|
|
806
|
+
const batchTableString = getStringFromArrayBuffer(
|
|
807
|
+
arrayBuffer,
|
|
808
|
+
byteOffset,
|
|
809
|
+
batchTableJsonByteLength
|
|
810
|
+
);
|
|
811
|
+
tile.batchTableJson = JSON.parse(batchTableString);
|
|
812
|
+
byteOffset += batchTableJsonByteLength;
|
|
813
|
+
if (batchTableBinaryByteLength && batchTableBinaryByteLength > 0) {
|
|
814
|
+
tile.batchTableBinary = new Uint8Array(arrayBuffer, byteOffset, batchTableBinaryByteLength);
|
|
815
|
+
tile.batchTableBinary = new Uint8Array(tile.batchTableBinary);
|
|
816
|
+
byteOffset += batchTableBinaryByteLength;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return byteOffset;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// src/lib/parsers/helpers/normalize-3d-tile-colors.ts
|
|
823
|
+
var import_math3 = require("@loaders.gl/math");
|
|
824
|
+
function normalize3DTileColorAttribute(tile, colors, batchTable) {
|
|
825
|
+
if (!colors && (!tile || !tile.batchIds || !batchTable)) {
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
const { batchIds, isRGB565, pointCount = 0 } = tile;
|
|
829
|
+
if (batchIds && batchTable) {
|
|
830
|
+
const colorArray = new Uint8ClampedArray(pointCount * 3);
|
|
831
|
+
for (let i = 0; i < pointCount; i++) {
|
|
832
|
+
const batchId = batchIds[i];
|
|
833
|
+
const dimensions = batchTable.getProperty(batchId, "dimensions");
|
|
834
|
+
const color = dimensions.map((d) => d * 255);
|
|
835
|
+
colorArray[i * 3] = color[0];
|
|
836
|
+
colorArray[i * 3 + 1] = color[1];
|
|
837
|
+
colorArray[i * 3 + 2] = color[2];
|
|
838
|
+
}
|
|
839
|
+
return {
|
|
840
|
+
type: import_math3.GL.UNSIGNED_BYTE,
|
|
841
|
+
value: colorArray,
|
|
842
|
+
size: 3,
|
|
843
|
+
normalized: true
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
if (colors && isRGB565) {
|
|
847
|
+
const colorArray = new Uint8ClampedArray(pointCount * 3);
|
|
848
|
+
for (let i = 0; i < pointCount; i++) {
|
|
849
|
+
const color = (0, import_math3.decodeRGB565)(colors[i]);
|
|
850
|
+
colorArray[i * 3] = color[0];
|
|
851
|
+
colorArray[i * 3 + 1] = color[1];
|
|
852
|
+
colorArray[i * 3 + 2] = color[2];
|
|
853
|
+
}
|
|
854
|
+
return {
|
|
855
|
+
type: import_math3.GL.UNSIGNED_BYTE,
|
|
856
|
+
value: colorArray,
|
|
857
|
+
size: 3,
|
|
858
|
+
normalized: true
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
if (colors && colors.length === pointCount * 3) {
|
|
862
|
+
return {
|
|
863
|
+
type: import_math3.GL.UNSIGNED_BYTE,
|
|
864
|
+
value: colors,
|
|
865
|
+
size: 3,
|
|
866
|
+
normalized: true
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
type: import_math3.GL.UNSIGNED_BYTE,
|
|
871
|
+
value: colors || new Uint8ClampedArray(),
|
|
872
|
+
size: 4,
|
|
873
|
+
normalized: true
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/lib/parsers/helpers/normalize-3d-tile-normals.ts
|
|
878
|
+
var import_core = require("@math.gl/core");
|
|
879
|
+
var import_math4 = require("@loaders.gl/math");
|
|
880
|
+
var scratchNormal = new import_core.Vector3();
|
|
881
|
+
function normalize3DTileNormalAttribute(tile, normals) {
|
|
882
|
+
if (!normals) {
|
|
883
|
+
return null;
|
|
884
|
+
}
|
|
885
|
+
if (tile.isOctEncoded16P) {
|
|
886
|
+
const decodedArray = new Float32Array((tile.pointsLength || 0) * 3);
|
|
887
|
+
for (let i = 0; i < (tile.pointsLength || 0); i++) {
|
|
888
|
+
(0, import_math4.octDecode)(normals[i * 2], normals[i * 2 + 1], scratchNormal);
|
|
889
|
+
scratchNormal.toArray(decodedArray, i * 3);
|
|
890
|
+
}
|
|
891
|
+
return {
|
|
892
|
+
type: import_math4.GL.FLOAT,
|
|
893
|
+
size: 2,
|
|
894
|
+
value: decodedArray
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
return {
|
|
898
|
+
type: import_math4.GL.FLOAT,
|
|
899
|
+
size: 2,
|
|
900
|
+
value: normals
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// src/lib/parsers/helpers/normalize-3d-tile-positions.ts
|
|
905
|
+
var import_core2 = require("@math.gl/core");
|
|
906
|
+
var import_math5 = require("@loaders.gl/math");
|
|
907
|
+
function normalize3DTilePositionAttribute(tile, positions, options) {
|
|
908
|
+
if (!tile.isQuantized) {
|
|
909
|
+
return positions;
|
|
910
|
+
}
|
|
911
|
+
if (options["3d-tiles"] && options["3d-tiles"].decodeQuantizedPositions) {
|
|
912
|
+
tile.isQuantized = false;
|
|
913
|
+
return decodeQuantizedPositions(tile, positions);
|
|
914
|
+
}
|
|
915
|
+
return {
|
|
916
|
+
type: import_math5.GL.UNSIGNED_SHORT,
|
|
917
|
+
value: positions,
|
|
918
|
+
size: 3,
|
|
919
|
+
normalized: true
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
function decodeQuantizedPositions(tile, positions) {
|
|
923
|
+
const scratchPosition = new import_core2.Vector3();
|
|
924
|
+
const decodedArray = new Float32Array(tile.pointCount * 3);
|
|
925
|
+
for (let i = 0; i < tile.pointCount; i++) {
|
|
926
|
+
scratchPosition.set(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]).scale(1 / tile.quantizedRange).multiply(tile.quantizedVolumeScale).add(tile.quantizedVolumeOffset).toArray(decodedArray, i * 3);
|
|
927
|
+
}
|
|
928
|
+
return decodedArray;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// src/lib/parsers/parse-3d-tile-point-cloud.ts
|
|
932
|
+
async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context) {
|
|
933
|
+
byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
|
|
934
|
+
byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
|
|
935
|
+
byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
|
|
936
|
+
initializeTile(tile);
|
|
937
|
+
const { featureTable, batchTable } = parsePointCloudTables(tile);
|
|
938
|
+
await parseDraco(tile, featureTable, batchTable, options, context);
|
|
939
|
+
parsePositions(tile, featureTable, options);
|
|
940
|
+
parseColors(tile, featureTable, batchTable);
|
|
941
|
+
parseNormals(tile, featureTable);
|
|
942
|
+
return byteOffset;
|
|
943
|
+
}
|
|
944
|
+
function initializeTile(tile) {
|
|
945
|
+
tile.attributes = {
|
|
946
|
+
positions: null,
|
|
947
|
+
colors: null,
|
|
948
|
+
normals: null,
|
|
949
|
+
batchIds: null
|
|
950
|
+
};
|
|
951
|
+
tile.isQuantized = false;
|
|
952
|
+
tile.isTranslucent = false;
|
|
953
|
+
tile.isRGB565 = false;
|
|
954
|
+
tile.isOctEncoded16P = false;
|
|
955
|
+
}
|
|
956
|
+
function parsePointCloudTables(tile) {
|
|
957
|
+
const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
|
|
958
|
+
const pointsLength = featureTable.getGlobalProperty("POINTS_LENGTH");
|
|
959
|
+
if (!Number.isFinite(pointsLength)) {
|
|
960
|
+
throw new Error("POINTS_LENGTH must be defined");
|
|
961
|
+
}
|
|
962
|
+
featureTable.featuresLength = pointsLength;
|
|
963
|
+
tile.featuresLength = pointsLength;
|
|
964
|
+
tile.pointsLength = pointsLength;
|
|
965
|
+
tile.pointCount = pointsLength;
|
|
966
|
+
tile.rtcCenter = featureTable.getGlobalProperty("RTC_CENTER", import_math6.GL.FLOAT, 3);
|
|
967
|
+
const batchTable = parseBatchIds(tile, featureTable);
|
|
968
|
+
return { featureTable, batchTable };
|
|
969
|
+
}
|
|
970
|
+
function parsePositions(tile, featureTable, options) {
|
|
971
|
+
tile.attributes = tile.attributes || {
|
|
972
|
+
positions: null,
|
|
973
|
+
colors: null,
|
|
974
|
+
normals: null,
|
|
975
|
+
batchIds: null
|
|
976
|
+
};
|
|
977
|
+
if (!tile.attributes.positions) {
|
|
978
|
+
if (featureTable.hasProperty("POSITION")) {
|
|
979
|
+
tile.attributes.positions = featureTable.getPropertyArray("POSITION", import_math6.GL.FLOAT, 3);
|
|
980
|
+
} else if (featureTable.hasProperty("POSITION_QUANTIZED")) {
|
|
981
|
+
const positions = featureTable.getPropertyArray("POSITION_QUANTIZED", import_math6.GL.UNSIGNED_SHORT, 3);
|
|
982
|
+
tile.isQuantized = true;
|
|
983
|
+
tile.quantizedRange = (1 << 16) - 1;
|
|
984
|
+
tile.quantizedVolumeScale = featureTable.getGlobalProperty(
|
|
985
|
+
"QUANTIZED_VOLUME_SCALE",
|
|
986
|
+
import_math6.GL.FLOAT,
|
|
987
|
+
3
|
|
988
|
+
);
|
|
989
|
+
if (!tile.quantizedVolumeScale) {
|
|
990
|
+
throw new Error("QUANTIZED_VOLUME_SCALE must be defined for quantized positions.");
|
|
991
|
+
}
|
|
992
|
+
tile.quantizedVolumeOffset = featureTable.getGlobalProperty(
|
|
993
|
+
"QUANTIZED_VOLUME_OFFSET",
|
|
994
|
+
import_math6.GL.FLOAT,
|
|
995
|
+
3
|
|
996
|
+
);
|
|
997
|
+
if (!tile.quantizedVolumeOffset) {
|
|
998
|
+
throw new Error("QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.");
|
|
999
|
+
}
|
|
1000
|
+
tile.attributes.positions = normalize3DTilePositionAttribute(tile, positions, options);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (!tile.attributes.positions) {
|
|
1004
|
+
throw new Error("Either POSITION or POSITION_QUANTIZED must be defined.");
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
function parseColors(tile, featureTable, batchTable) {
|
|
1008
|
+
tile.attributes = tile.attributes || {
|
|
1009
|
+
positions: null,
|
|
1010
|
+
colors: null,
|
|
1011
|
+
normals: null,
|
|
1012
|
+
batchIds: null
|
|
1013
|
+
};
|
|
1014
|
+
if (!tile.attributes.colors) {
|
|
1015
|
+
let colors = null;
|
|
1016
|
+
if (featureTable.hasProperty("RGBA")) {
|
|
1017
|
+
colors = featureTable.getPropertyArray("RGBA", import_math6.GL.UNSIGNED_BYTE, 4);
|
|
1018
|
+
tile.isTranslucent = true;
|
|
1019
|
+
} else if (featureTable.hasProperty("RGB")) {
|
|
1020
|
+
colors = featureTable.getPropertyArray("RGB", import_math6.GL.UNSIGNED_BYTE, 3);
|
|
1021
|
+
} else if (featureTable.hasProperty("RGB565")) {
|
|
1022
|
+
colors = featureTable.getPropertyArray("RGB565", import_math6.GL.UNSIGNED_SHORT, 1);
|
|
1023
|
+
tile.isRGB565 = true;
|
|
1024
|
+
}
|
|
1025
|
+
tile.attributes.colors = normalize3DTileColorAttribute(tile, colors, batchTable);
|
|
1026
|
+
}
|
|
1027
|
+
if (featureTable.hasProperty("CONSTANT_RGBA")) {
|
|
1028
|
+
tile.constantRGBA = featureTable.getGlobalProperty("CONSTANT_RGBA", import_math6.GL.UNSIGNED_BYTE, 4);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
function parseNormals(tile, featureTable) {
|
|
1032
|
+
tile.attributes = tile.attributes || {
|
|
1033
|
+
positions: null,
|
|
1034
|
+
colors: null,
|
|
1035
|
+
normals: null,
|
|
1036
|
+
batchIds: null
|
|
1037
|
+
};
|
|
1038
|
+
if (!tile.attributes.normals) {
|
|
1039
|
+
let normals = null;
|
|
1040
|
+
if (featureTable.hasProperty("NORMAL")) {
|
|
1041
|
+
normals = featureTable.getPropertyArray("NORMAL", import_math6.GL.FLOAT, 3);
|
|
1042
|
+
} else if (featureTable.hasProperty("NORMAL_OCT16P")) {
|
|
1043
|
+
normals = featureTable.getPropertyArray("NORMAL_OCT16P", import_math6.GL.UNSIGNED_BYTE, 2);
|
|
1044
|
+
tile.isOctEncoded16P = true;
|
|
1045
|
+
}
|
|
1046
|
+
tile.attributes.normals = normalize3DTileNormalAttribute(tile, normals);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
function parseBatchIds(tile, featureTable) {
|
|
1050
|
+
let batchTable = null;
|
|
1051
|
+
if (!tile.batchIds && featureTable.hasProperty("BATCH_ID")) {
|
|
1052
|
+
tile.batchIds = featureTable.getPropertyArray("BATCH_ID", import_math6.GL.UNSIGNED_SHORT, 1);
|
|
1053
|
+
if (tile.batchIds) {
|
|
1054
|
+
const batchFeatureLength = featureTable.getGlobalProperty("BATCH_LENGTH");
|
|
1055
|
+
if (!batchFeatureLength) {
|
|
1056
|
+
throw new Error("Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.");
|
|
1057
|
+
}
|
|
1058
|
+
const { batchTableJson, batchTableBinary } = tile;
|
|
1059
|
+
batchTable = new Tile3DBatchTableParser(batchTableJson, batchTableBinary, batchFeatureLength);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
return batchTable;
|
|
1063
|
+
}
|
|
1064
|
+
async function parseDraco(tile, featureTable, batchTable, options, context) {
|
|
1065
|
+
let dracoBuffer;
|
|
1066
|
+
let dracoFeatureTableProperties;
|
|
1067
|
+
let dracoBatchTableProperties;
|
|
1068
|
+
const batchTableDraco = tile.batchTableJson && tile.batchTableJson.extensions && tile.batchTableJson.extensions["3DTILES_draco_point_compression"];
|
|
1069
|
+
if (batchTableDraco) {
|
|
1070
|
+
dracoBatchTableProperties = batchTableDraco.properties;
|
|
1071
|
+
}
|
|
1072
|
+
const featureTableDraco = featureTable.getExtension("3DTILES_draco_point_compression");
|
|
1073
|
+
if (featureTableDraco) {
|
|
1074
|
+
dracoFeatureTableProperties = featureTableDraco.properties;
|
|
1075
|
+
const dracoByteOffset = featureTableDraco.byteOffset;
|
|
1076
|
+
const dracoByteLength = featureTableDraco.byteLength;
|
|
1077
|
+
if (!dracoFeatureTableProperties || !Number.isFinite(dracoByteOffset) || !dracoByteLength) {
|
|
1078
|
+
throw new Error("Draco properties, byteOffset, and byteLength must be defined");
|
|
1079
|
+
}
|
|
1080
|
+
dracoBuffer = (tile.featureTableBinary || []).slice(
|
|
1081
|
+
dracoByteOffset,
|
|
1082
|
+
dracoByteOffset + dracoByteLength
|
|
1083
|
+
);
|
|
1084
|
+
tile.hasPositions = Number.isFinite(dracoFeatureTableProperties.POSITION);
|
|
1085
|
+
tile.hasColors = Number.isFinite(dracoFeatureTableProperties.RGB) || Number.isFinite(dracoFeatureTableProperties.RGBA);
|
|
1086
|
+
tile.hasNormals = Number.isFinite(dracoFeatureTableProperties.NORMAL);
|
|
1087
|
+
tile.hasBatchIds = Number.isFinite(dracoFeatureTableProperties.BATCH_ID);
|
|
1088
|
+
tile.isTranslucent = Number.isFinite(dracoFeatureTableProperties.RGBA);
|
|
1089
|
+
}
|
|
1090
|
+
if (!dracoBuffer) {
|
|
1091
|
+
return true;
|
|
1092
|
+
}
|
|
1093
|
+
const dracoData = {
|
|
1094
|
+
buffer: dracoBuffer,
|
|
1095
|
+
properties: { ...dracoFeatureTableProperties, ...dracoBatchTableProperties },
|
|
1096
|
+
featureTableProperties: dracoFeatureTableProperties,
|
|
1097
|
+
batchTableProperties: dracoBatchTableProperties,
|
|
1098
|
+
dequantizeInShader: false
|
|
1099
|
+
};
|
|
1100
|
+
return await loadDraco(tile, dracoData, options, context);
|
|
1101
|
+
}
|
|
1102
|
+
async function loadDraco(tile, dracoData, options, context) {
|
|
1103
|
+
if (!context) {
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
const dracoOptions = {
|
|
1107
|
+
...options,
|
|
1108
|
+
draco: {
|
|
1109
|
+
...options == null ? void 0 : options.draco,
|
|
1110
|
+
extraAttributes: dracoData.batchTableProperties || {}
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
delete dracoOptions["3d-tiles"];
|
|
1114
|
+
const data = await (0, import_loader_utils4.parseFromContext)(dracoData.buffer, import_draco.DracoLoader, dracoOptions, context);
|
|
1115
|
+
const decodedPositions = data.attributes.POSITION && data.attributes.POSITION.value;
|
|
1116
|
+
const decodedColors = data.attributes.COLOR_0 && data.attributes.COLOR_0.value;
|
|
1117
|
+
const decodedNormals = data.attributes.NORMAL && data.attributes.NORMAL.value;
|
|
1118
|
+
const decodedBatchIds = data.attributes.BATCH_ID && data.attributes.BATCH_ID.value;
|
|
1119
|
+
const isQuantizedDraco = decodedPositions && data.attributes.POSITION.value.quantization;
|
|
1120
|
+
const isOctEncodedDraco = decodedNormals && data.attributes.NORMAL.value.quantization;
|
|
1121
|
+
if (isQuantizedDraco) {
|
|
1122
|
+
const quantization = data.POSITION.data.quantization;
|
|
1123
|
+
const range = quantization.range;
|
|
1124
|
+
tile.quantizedVolumeScale = new import_core3.Vector3(range, range, range);
|
|
1125
|
+
tile.quantizedVolumeOffset = new import_core3.Vector3(quantization.minValues);
|
|
1126
|
+
tile.quantizedRange = (1 << quantization.quantizationBits) - 1;
|
|
1127
|
+
tile.isQuantizedDraco = true;
|
|
1128
|
+
}
|
|
1129
|
+
if (isOctEncodedDraco) {
|
|
1130
|
+
tile.octEncodedRange = (1 << data.NORMAL.data.quantization.quantizationBits) - 1;
|
|
1131
|
+
tile.isOctEncodedDraco = true;
|
|
1132
|
+
}
|
|
1133
|
+
const batchTableAttributes = {};
|
|
1134
|
+
if (dracoData.batchTableProperties) {
|
|
1135
|
+
for (const attributeName of Object.keys(dracoData.batchTableProperties)) {
|
|
1136
|
+
if (data.attributes[attributeName] && data.attributes[attributeName].value) {
|
|
1137
|
+
batchTableAttributes[attributeName.toLowerCase()] = data.attributes[attributeName].value;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
tile.attributes = {
|
|
1142
|
+
// @ts-expect-error
|
|
1143
|
+
positions: decodedPositions,
|
|
1144
|
+
// @ts-expect-error
|
|
1145
|
+
colors: normalize3DTileColorAttribute(tile, decodedColors, void 0),
|
|
1146
|
+
// @ts-expect-error
|
|
1147
|
+
normals: decodedNormals,
|
|
1148
|
+
// @ts-expect-error
|
|
1149
|
+
batchIds: decodedBatchIds,
|
|
1150
|
+
...batchTableAttributes
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// src/lib/parsers/parse-3d-tile-batched-model.ts
|
|
1155
|
+
var import_math7 = require("@loaders.gl/math");
|
|
1156
|
+
|
|
1157
|
+
// src/lib/parsers/helpers/parse-3d-tile-gltf-view.ts
|
|
1158
|
+
var import_gltf = require("@loaders.gl/gltf");
|
|
1159
|
+
var import_loader_utils5 = require("@loaders.gl/loader-utils");
|
|
1160
|
+
var GLTF_FORMAT = {
|
|
1161
|
+
URI: 0,
|
|
1162
|
+
EMBEDDED: 1
|
|
1163
|
+
};
|
|
1164
|
+
function parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options) {
|
|
1165
|
+
tile.rotateYtoZ = true;
|
|
1166
|
+
const gltfByteLength = (tile.byteOffset || 0) + (tile.byteLength || 0) - byteOffset;
|
|
1167
|
+
if (gltfByteLength === 0) {
|
|
1168
|
+
throw new Error("glTF byte length must be greater than 0.");
|
|
1169
|
+
}
|
|
1170
|
+
tile.gltfUpAxis = (options == null ? void 0 : options["3d-tiles"]) && options["3d-tiles"].assetGltfUpAxis ? options["3d-tiles"].assetGltfUpAxis : "Y";
|
|
1171
|
+
tile.gltfArrayBuffer = (0, import_loader_utils5.sliceArrayBuffer)(arrayBuffer, byteOffset, gltfByteLength);
|
|
1172
|
+
tile.gltfByteOffset = 0;
|
|
1173
|
+
tile.gltfByteLength = gltfByteLength;
|
|
1174
|
+
if (byteOffset % 4 === 0) {
|
|
1175
|
+
} else {
|
|
1176
|
+
console.warn(`${tile.type}: embedded glb is not aligned to a 4-byte boundary.`);
|
|
1177
|
+
}
|
|
1178
|
+
return (tile.byteOffset || 0) + (tile.byteLength || 0);
|
|
1179
|
+
}
|
|
1180
|
+
async function extractGLTF(tile, gltfFormat, options, context) {
|
|
1181
|
+
const tile3DOptions = (options == null ? void 0 : options["3d-tiles"]) || {};
|
|
1182
|
+
extractGLTFBufferOrURL(tile, gltfFormat, options);
|
|
1183
|
+
if (tile3DOptions.loadGLTF) {
|
|
1184
|
+
if (!context) {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
if (tile.gltfUrl) {
|
|
1188
|
+
const { fetch } = context;
|
|
1189
|
+
const response = await fetch(tile.gltfUrl, options);
|
|
1190
|
+
tile.gltfArrayBuffer = await response.arrayBuffer();
|
|
1191
|
+
tile.gltfByteOffset = 0;
|
|
1192
|
+
}
|
|
1193
|
+
if (tile.gltfArrayBuffer) {
|
|
1194
|
+
const gltfWithBuffers = await (0, import_loader_utils5.parseFromContext)(
|
|
1195
|
+
tile.gltfArrayBuffer,
|
|
1196
|
+
import_gltf.GLTFLoader,
|
|
1197
|
+
options,
|
|
1198
|
+
context
|
|
1199
|
+
);
|
|
1200
|
+
tile.gltf = (0, import_gltf.postProcessGLTF)(gltfWithBuffers);
|
|
1201
|
+
tile.gpuMemoryUsageInBytes = (0, import_gltf._getMemoryUsageGLTF)(tile.gltf);
|
|
1202
|
+
delete tile.gltfArrayBuffer;
|
|
1203
|
+
delete tile.gltfByteOffset;
|
|
1204
|
+
delete tile.gltfByteLength;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
function extractGLTFBufferOrURL(tile, gltfFormat, options) {
|
|
1209
|
+
switch (gltfFormat) {
|
|
1210
|
+
case GLTF_FORMAT.URI:
|
|
1211
|
+
if (tile.gltfArrayBuffer) {
|
|
1212
|
+
const gltfUrlBytes = new Uint8Array(tile.gltfArrayBuffer, tile.gltfByteOffset);
|
|
1213
|
+
const textDecoder = new TextDecoder();
|
|
1214
|
+
const gltfUrl = textDecoder.decode(gltfUrlBytes);
|
|
1215
|
+
tile.gltfUrl = gltfUrl.replace(/[\s\0]+$/, "");
|
|
1216
|
+
}
|
|
1217
|
+
delete tile.gltfArrayBuffer;
|
|
1218
|
+
delete tile.gltfByteOffset;
|
|
1219
|
+
delete tile.gltfByteLength;
|
|
1220
|
+
break;
|
|
1221
|
+
case GLTF_FORMAT.EMBEDDED:
|
|
1222
|
+
break;
|
|
1223
|
+
default:
|
|
1224
|
+
throw new Error("b3dm: Illegal glTF format field");
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
// src/lib/parsers/parse-3d-tile-batched-model.ts
|
|
1229
|
+
async function parseBatchedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
|
|
1230
|
+
var _a;
|
|
1231
|
+
byteOffset = parseBatchedModel(tile, arrayBuffer, byteOffset, options, context);
|
|
1232
|
+
await extractGLTF(tile, GLTF_FORMAT.EMBEDDED, options, context);
|
|
1233
|
+
const extensions = (_a = tile == null ? void 0 : tile.gltf) == null ? void 0 : _a.extensions;
|
|
1234
|
+
if (extensions && extensions.CESIUM_RTC) {
|
|
1235
|
+
tile.rtcCenter = extensions.CESIUM_RTC.center;
|
|
1236
|
+
}
|
|
1237
|
+
return byteOffset;
|
|
1238
|
+
}
|
|
1239
|
+
function parseBatchedModel(tile, arrayBuffer, byteOffset, options, context) {
|
|
1240
|
+
byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
|
|
1241
|
+
byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
|
|
1242
|
+
byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
|
|
1243
|
+
byteOffset = parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options);
|
|
1244
|
+
const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
|
|
1245
|
+
tile.rtcCenter = featureTable.getGlobalProperty("RTC_CENTER", import_math7.GL.FLOAT, 3);
|
|
1246
|
+
return byteOffset;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// src/lib/parsers/parse-3d-tile-instanced-model.ts
|
|
1250
|
+
var import_core4 = require("@math.gl/core");
|
|
1251
|
+
var import_geospatial = require("@math.gl/geospatial");
|
|
1252
|
+
var import_math8 = require("@loaders.gl/math");
|
|
1253
|
+
async function parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
|
|
1254
|
+
byteOffset = parseInstancedModel(tile, arrayBuffer, byteOffset, options, context);
|
|
1255
|
+
await extractGLTF(tile, tile.gltfFormat || 0, options, context);
|
|
1256
|
+
return byteOffset;
|
|
1257
|
+
}
|
|
1258
|
+
function parseInstancedModel(tile, arrayBuffer, byteOffset, options, context) {
|
|
1259
|
+
var _a;
|
|
1260
|
+
byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
|
|
1261
|
+
if (tile.version !== 1) {
|
|
1262
|
+
throw new Error(`Instanced 3D Model version ${tile.version} is not supported`);
|
|
1263
|
+
}
|
|
1264
|
+
byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
|
|
1265
|
+
const view = new DataView(arrayBuffer);
|
|
1266
|
+
tile.gltfFormat = view.getUint32(byteOffset, true);
|
|
1267
|
+
byteOffset += 4;
|
|
1268
|
+
byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
|
|
1269
|
+
byteOffset = parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options);
|
|
1270
|
+
if (!((_a = tile == null ? void 0 : tile.header) == null ? void 0 : _a.featureTableJsonByteLength) || tile.header.featureTableJsonByteLength === 0) {
|
|
1271
|
+
throw new Error("i3dm parser: featureTableJsonByteLength is zero.");
|
|
1272
|
+
}
|
|
1273
|
+
const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
|
|
1274
|
+
const instancesLength = featureTable.getGlobalProperty("INSTANCES_LENGTH");
|
|
1275
|
+
featureTable.featuresLength = instancesLength;
|
|
1276
|
+
if (!Number.isFinite(instancesLength)) {
|
|
1277
|
+
throw new Error("i3dm parser: INSTANCES_LENGTH must be defined");
|
|
1278
|
+
}
|
|
1279
|
+
tile.eastNorthUp = featureTable.getGlobalProperty("EAST_NORTH_UP");
|
|
1280
|
+
tile.rtcCenter = featureTable.getGlobalProperty("RTC_CENTER", import_math8.GL.FLOAT, 3);
|
|
1281
|
+
const batchTable = new Tile3DBatchTableParser(
|
|
1282
|
+
tile.batchTableJson,
|
|
1283
|
+
tile.batchTableBinary,
|
|
1284
|
+
instancesLength
|
|
1285
|
+
);
|
|
1286
|
+
extractInstancedAttributes(tile, featureTable, batchTable, instancesLength);
|
|
1287
|
+
return byteOffset;
|
|
1288
|
+
}
|
|
1289
|
+
function extractInstancedAttributes(tile, featureTable, batchTable, instancesLength) {
|
|
1290
|
+
const instances = new Array(instancesLength);
|
|
1291
|
+
const instancePosition = new import_core4.Vector3();
|
|
1292
|
+
const instanceNormalRight = new import_core4.Vector3();
|
|
1293
|
+
const instanceNormalUp = new import_core4.Vector3();
|
|
1294
|
+
const instanceNormalForward = new import_core4.Vector3();
|
|
1295
|
+
const instanceRotation = new import_core4.Matrix3();
|
|
1296
|
+
const instanceQuaternion = new import_core4.Quaternion();
|
|
1297
|
+
const instanceScale = new import_core4.Vector3();
|
|
1298
|
+
const instanceTranslationRotationScale = {};
|
|
1299
|
+
const instanceTransform = new import_core4.Matrix4();
|
|
1300
|
+
const scratch1 = [];
|
|
1301
|
+
const scratch2 = [];
|
|
1302
|
+
const scratch3 = [];
|
|
1303
|
+
const scratch4 = [];
|
|
1304
|
+
for (let i = 0; i < instancesLength; i++) {
|
|
1305
|
+
let position;
|
|
1306
|
+
if (featureTable.hasProperty("POSITION")) {
|
|
1307
|
+
position = featureTable.getProperty("POSITION", import_math8.GL.FLOAT, 3, i, instancePosition);
|
|
1308
|
+
} else if (featureTable.hasProperty("POSITION_QUANTIZED")) {
|
|
1309
|
+
position = featureTable.getProperty(
|
|
1310
|
+
"POSITION_QUANTIZED",
|
|
1311
|
+
import_math8.GL.UNSIGNED_SHORT,
|
|
1312
|
+
3,
|
|
1313
|
+
i,
|
|
1314
|
+
instancePosition
|
|
1315
|
+
);
|
|
1316
|
+
const quantizedVolumeOffset = featureTable.getGlobalProperty(
|
|
1317
|
+
"QUANTIZED_VOLUME_OFFSET",
|
|
1318
|
+
import_math8.GL.FLOAT,
|
|
1319
|
+
3
|
|
1320
|
+
);
|
|
1321
|
+
if (!quantizedVolumeOffset) {
|
|
1322
|
+
throw new Error(
|
|
1323
|
+
"i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions."
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
const quantizedVolumeScale = featureTable.getGlobalProperty(
|
|
1327
|
+
"QUANTIZED_VOLUME_SCALE",
|
|
1328
|
+
import_math8.GL.FLOAT,
|
|
1329
|
+
3
|
|
1330
|
+
);
|
|
1331
|
+
if (!quantizedVolumeScale) {
|
|
1332
|
+
throw new Error(
|
|
1333
|
+
"i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions."
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
const MAX_UNSIGNED_SHORT = 65535;
|
|
1337
|
+
for (let j = 0; j < 3; j++) {
|
|
1338
|
+
position[j] = position[j] / MAX_UNSIGNED_SHORT * quantizedVolumeScale[j] + quantizedVolumeOffset[j];
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
if (!position) {
|
|
1342
|
+
throw new Error("i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.");
|
|
1343
|
+
}
|
|
1344
|
+
instancePosition.copy(position);
|
|
1345
|
+
instanceTranslationRotationScale.translation = instancePosition;
|
|
1346
|
+
tile.normalUp = featureTable.getProperty("NORMAL_UP", import_math8.GL.FLOAT, 3, i, scratch1);
|
|
1347
|
+
tile.normalRight = featureTable.getProperty("NORMAL_RIGHT", import_math8.GL.FLOAT, 3, i, scratch2);
|
|
1348
|
+
const hasCustomOrientation = false;
|
|
1349
|
+
if (tile.normalUp) {
|
|
1350
|
+
if (!tile.normalRight) {
|
|
1351
|
+
throw new Error("i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.");
|
|
1352
|
+
}
|
|
1353
|
+
tile.hasCustomOrientation = true;
|
|
1354
|
+
} else {
|
|
1355
|
+
tile.octNormalUp = featureTable.getProperty(
|
|
1356
|
+
"NORMAL_UP_OCT32P",
|
|
1357
|
+
import_math8.GL.UNSIGNED_SHORT,
|
|
1358
|
+
2,
|
|
1359
|
+
i,
|
|
1360
|
+
scratch1
|
|
1361
|
+
);
|
|
1362
|
+
tile.octNormalRight = featureTable.getProperty(
|
|
1363
|
+
"NORMAL_RIGHT_OCT32P",
|
|
1364
|
+
import_math8.GL.UNSIGNED_SHORT,
|
|
1365
|
+
2,
|
|
1366
|
+
i,
|
|
1367
|
+
scratch2
|
|
1368
|
+
);
|
|
1369
|
+
if (tile.octNormalUp) {
|
|
1370
|
+
if (!tile.octNormalRight) {
|
|
1371
|
+
throw new Error(
|
|
1372
|
+
"i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P"
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
throw new Error("i3dm: oct-encoded orientation not implemented");
|
|
1376
|
+
} else if (tile.eastNorthUp) {
|
|
1377
|
+
import_geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(instancePosition, instanceTransform);
|
|
1378
|
+
instanceTransform.getRotationMatrix3(instanceRotation);
|
|
1379
|
+
} else {
|
|
1380
|
+
instanceRotation.identity();
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
if (hasCustomOrientation) {
|
|
1384
|
+
instanceNormalForward.copy(instanceNormalRight).cross(instanceNormalUp).normalize();
|
|
1385
|
+
instanceRotation.setColumn(0, instanceNormalRight);
|
|
1386
|
+
instanceRotation.setColumn(1, instanceNormalUp);
|
|
1387
|
+
instanceRotation.setColumn(2, instanceNormalForward);
|
|
1388
|
+
}
|
|
1389
|
+
instanceQuaternion.fromMatrix3(instanceRotation);
|
|
1390
|
+
instanceTranslationRotationScale.rotation = instanceQuaternion;
|
|
1391
|
+
instanceScale.set(1, 1, 1);
|
|
1392
|
+
const scale = featureTable.getProperty("SCALE", import_math8.GL.FLOAT, 1, i, scratch3);
|
|
1393
|
+
if (Number.isFinite(scale)) {
|
|
1394
|
+
instanceScale.multiplyByScalar(scale);
|
|
1395
|
+
}
|
|
1396
|
+
const nonUniformScale = featureTable.getProperty("SCALE_NON_UNIFORM", import_math8.GL.FLOAT, 3, i, scratch1);
|
|
1397
|
+
if (nonUniformScale) {
|
|
1398
|
+
instanceScale.scale(nonUniformScale);
|
|
1399
|
+
}
|
|
1400
|
+
instanceTranslationRotationScale.scale = instanceScale;
|
|
1401
|
+
let batchId = featureTable.getProperty("BATCH_ID", import_math8.GL.UNSIGNED_SHORT, 1, i, scratch4);
|
|
1402
|
+
if (batchId === void 0) {
|
|
1403
|
+
batchId = i;
|
|
1404
|
+
}
|
|
1405
|
+
const rotationMatrix = new import_core4.Matrix4().fromQuaternion(instanceTranslationRotationScale.rotation);
|
|
1406
|
+
instanceTransform.identity();
|
|
1407
|
+
instanceTransform.translate(instanceTranslationRotationScale.translation);
|
|
1408
|
+
instanceTransform.multiplyRight(rotationMatrix);
|
|
1409
|
+
instanceTransform.scale(instanceTranslationRotationScale.scale);
|
|
1410
|
+
const modelMatrix = instanceTransform.clone();
|
|
1411
|
+
instances[i] = {
|
|
1412
|
+
modelMatrix,
|
|
1413
|
+
batchId
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
tile.instances = instances;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
// src/lib/parsers/parse-3d-tile-composite.ts
|
|
1420
|
+
async function parseComposite3DTile(tile, arrayBuffer, byteOffset, options, context, parse3DTile2) {
|
|
1421
|
+
byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
|
|
1422
|
+
const view = new DataView(arrayBuffer);
|
|
1423
|
+
tile.tilesLength = view.getUint32(byteOffset, true);
|
|
1424
|
+
byteOffset += 4;
|
|
1425
|
+
tile.tiles = [];
|
|
1426
|
+
while (tile.tiles.length < tile.tilesLength && (tile.byteLength || 0) - byteOffset > 12) {
|
|
1427
|
+
const subtile = { shape: "tile3d" };
|
|
1428
|
+
tile.tiles.push(subtile);
|
|
1429
|
+
byteOffset = await parse3DTile2(arrayBuffer, byteOffset, options, context, subtile);
|
|
1430
|
+
}
|
|
1431
|
+
return byteOffset;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// src/lib/parsers/parse-3d-tile-gltf.ts
|
|
1435
|
+
var import_loader_utils6 = require("@loaders.gl/loader-utils");
|
|
1436
|
+
var import_gltf2 = require("@loaders.gl/gltf");
|
|
1437
|
+
async function parseGltf3DTile(tile, arrayBuffer, options, context) {
|
|
1438
|
+
var _a, _b;
|
|
1439
|
+
tile.rotateYtoZ = true;
|
|
1440
|
+
tile.gltfUpAxis = ((_a = options == null ? void 0 : options["3d-tiles"]) == null ? void 0 : _a.assetGltfUpAxis) ? options["3d-tiles"].assetGltfUpAxis : "Y";
|
|
1441
|
+
if ((_b = options == null ? void 0 : options["3d-tiles"]) == null ? void 0 : _b.loadGLTF) {
|
|
1442
|
+
if (!context) {
|
|
1443
|
+
return arrayBuffer.byteLength;
|
|
1444
|
+
}
|
|
1445
|
+
const gltfWithBuffers = await (0, import_loader_utils6.parseFromContext)(arrayBuffer, import_gltf2.GLTFLoader, options, context);
|
|
1446
|
+
tile.gltf = (0, import_gltf2.postProcessGLTF)(gltfWithBuffers);
|
|
1447
|
+
tile.gpuMemoryUsageInBytes = (0, import_gltf2._getMemoryUsageGLTF)(tile.gltf);
|
|
1448
|
+
} else {
|
|
1449
|
+
tile.gltfArrayBuffer = arrayBuffer;
|
|
1450
|
+
}
|
|
1451
|
+
return arrayBuffer.byteLength;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// src/lib/parsers/parse-3d-tile.ts
|
|
1455
|
+
async function parse3DTile(arrayBuffer, byteOffset = 0, options, context, tile = { shape: "tile3d" }) {
|
|
1456
|
+
tile.byteOffset = byteOffset;
|
|
1457
|
+
tile.type = getMagicString(arrayBuffer, byteOffset);
|
|
1458
|
+
switch (tile.type) {
|
|
1459
|
+
case TILE3D_TYPE.COMPOSITE:
|
|
1460
|
+
return await parseComposite3DTile(
|
|
1461
|
+
tile,
|
|
1462
|
+
arrayBuffer,
|
|
1463
|
+
byteOffset,
|
|
1464
|
+
options,
|
|
1465
|
+
context,
|
|
1466
|
+
parse3DTile
|
|
1467
|
+
);
|
|
1468
|
+
case TILE3D_TYPE.BATCHED_3D_MODEL:
|
|
1469
|
+
return await parseBatchedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
|
|
1470
|
+
case TILE3D_TYPE.GLTF:
|
|
1471
|
+
return await parseGltf3DTile(tile, arrayBuffer, options, context);
|
|
1472
|
+
case TILE3D_TYPE.INSTANCED_3D_MODEL:
|
|
1473
|
+
return await parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
|
|
1474
|
+
case TILE3D_TYPE.POINT_CLOUD:
|
|
1475
|
+
return await parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context);
|
|
1476
|
+
default:
|
|
1477
|
+
throw new Error(`3DTileLoader: unknown type ${tile.type}`);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
// src/lib/parsers/parse-3d-tile-header.ts
|
|
1482
|
+
var import_loader_utils7 = require("@loaders.gl/loader-utils");
|
|
1483
|
+
|
|
1484
|
+
// src/lib/parsers/helpers/parse-3d-tile-subtree.ts
|
|
1485
|
+
var SUBTREE_FILE_MAGIC = 1952609651;
|
|
1486
|
+
var SUBTREE_FILE_VERSION = 1;
|
|
1487
|
+
async function parse3DTilesSubtree(data, options, context) {
|
|
1488
|
+
const magic = new Uint32Array(data.slice(0, 4));
|
|
1489
|
+
if (magic[0] !== SUBTREE_FILE_MAGIC) {
|
|
1490
|
+
throw new Error("Wrong subtree file magic number");
|
|
1491
|
+
}
|
|
1492
|
+
const version = new Uint32Array(data.slice(4, 8));
|
|
1493
|
+
if (version[0] !== SUBTREE_FILE_VERSION) {
|
|
1494
|
+
throw new Error("Wrong subtree file verson, must be 1");
|
|
1495
|
+
}
|
|
1496
|
+
const jsonByteLength = parseUint64Value(data.slice(8, 16));
|
|
1497
|
+
const stringAttribute = new Uint8Array(data, 24, jsonByteLength);
|
|
1498
|
+
const textDecoder = new TextDecoder("utf8");
|
|
1499
|
+
const string = textDecoder.decode(stringAttribute);
|
|
1500
|
+
const subtree = JSON.parse(string);
|
|
1501
|
+
const binaryByteLength = parseUint64Value(data.slice(16, 24));
|
|
1502
|
+
let internalBinaryBuffer = new ArrayBuffer(0);
|
|
1503
|
+
if (binaryByteLength) {
|
|
1504
|
+
internalBinaryBuffer = data.slice(24 + jsonByteLength);
|
|
1505
|
+
}
|
|
1506
|
+
await loadExplicitBitstream(subtree, subtree.tileAvailability, internalBinaryBuffer, context);
|
|
1507
|
+
if (Array.isArray(subtree.contentAvailability)) {
|
|
1508
|
+
for (const contentAvailability of subtree.contentAvailability) {
|
|
1509
|
+
await loadExplicitBitstream(subtree, contentAvailability, internalBinaryBuffer, context);
|
|
1510
|
+
}
|
|
1511
|
+
} else {
|
|
1512
|
+
await loadExplicitBitstream(
|
|
1513
|
+
subtree,
|
|
1514
|
+
subtree.contentAvailability,
|
|
1515
|
+
internalBinaryBuffer,
|
|
1516
|
+
context
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
await loadExplicitBitstream(
|
|
1520
|
+
subtree,
|
|
1521
|
+
subtree.childSubtreeAvailability,
|
|
1522
|
+
internalBinaryBuffer,
|
|
1523
|
+
context
|
|
1524
|
+
);
|
|
1525
|
+
return subtree;
|
|
1526
|
+
}
|
|
1527
|
+
async function loadExplicitBitstream(subtree, availabilityObject, internalBinaryBuffer, context) {
|
|
1528
|
+
const bufferViewIndex = Number.isFinite(availabilityObject.bitstream) ? availabilityObject.bitstream : availabilityObject.bufferView;
|
|
1529
|
+
if (typeof bufferViewIndex !== "number") {
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
const bufferView = subtree.bufferViews[bufferViewIndex];
|
|
1533
|
+
const buffer = subtree.buffers[bufferView.buffer];
|
|
1534
|
+
if (!(context == null ? void 0 : context.baseUrl)) {
|
|
1535
|
+
throw new Error("Url is not provided");
|
|
1536
|
+
}
|
|
1537
|
+
if (!context.fetch) {
|
|
1538
|
+
throw new Error("fetch is not provided");
|
|
1539
|
+
}
|
|
1540
|
+
if (buffer.uri) {
|
|
1541
|
+
const bufferUri = `${(context == null ? void 0 : context.baseUrl) || ""}/${buffer.uri}`;
|
|
1542
|
+
const response = await context.fetch(bufferUri);
|
|
1543
|
+
const data = await response.arrayBuffer();
|
|
1544
|
+
availabilityObject.explicitBitstream = new Uint8Array(
|
|
1545
|
+
data,
|
|
1546
|
+
bufferView.byteOffset,
|
|
1547
|
+
bufferView.byteLength
|
|
1548
|
+
);
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
availabilityObject.explicitBitstream = new Uint8Array(
|
|
1552
|
+
internalBinaryBuffer,
|
|
1553
|
+
bufferView.byteOffset,
|
|
1554
|
+
bufferView.byteLength
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
function parseUint64Value(buffer) {
|
|
1558
|
+
const dataView = new DataView(buffer);
|
|
1559
|
+
const left = dataView.getUint32(0, true);
|
|
1560
|
+
const right = dataView.getUint32(4, true);
|
|
1561
|
+
return left + 2 ** 32 * right;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
// src/tile-3d-subtree-loader.ts
|
|
1565
|
+
var Tile3DSubtreeLoader = {
|
|
1566
|
+
id: "3d-tiles-subtree",
|
|
1567
|
+
name: "3D Tiles Subtree",
|
|
1568
|
+
module: "3d-tiles",
|
|
1569
|
+
version: VERSION,
|
|
1570
|
+
extensions: ["subtree"],
|
|
1571
|
+
mimeTypes: ["application/octet-stream"],
|
|
1572
|
+
tests: ["subtree"],
|
|
1573
|
+
parse: parse3DTilesSubtree,
|
|
1574
|
+
options: {}
|
|
1575
|
+
};
|
|
1576
|
+
|
|
1577
|
+
// src/lib/parsers/parse-3d-tile-header.ts
|
|
1578
|
+
var import_core8 = require("@loaders.gl/core");
|
|
1579
|
+
var import_tiles = require("@loaders.gl/tiles");
|
|
1580
|
+
|
|
1581
|
+
// src/lib/parsers/helpers/parse-3d-implicit-tiles.ts
|
|
1582
|
+
var import_core7 = require("@loaders.gl/core");
|
|
1583
|
+
var import_log = __toESM(require("@probe.gl/log"), 1);
|
|
1584
|
+
|
|
1585
|
+
// src/lib/utils/s2/s2-token-functions.ts
|
|
1586
|
+
var import_long = __toESM(require("long"), 1);
|
|
1587
|
+
var MAXIMUM_TOKEN_LENGTH = 16;
|
|
1588
|
+
function getS2CellIdFromToken(token) {
|
|
1589
|
+
if (token === "X") {
|
|
1590
|
+
token = "";
|
|
1591
|
+
}
|
|
1592
|
+
const paddedToken = token.padEnd(MAXIMUM_TOKEN_LENGTH, "0");
|
|
1593
|
+
return import_long.default.fromString(paddedToken, true, 16);
|
|
1594
|
+
}
|
|
1595
|
+
function getS2TokenFromCellId(cellId) {
|
|
1596
|
+
if (cellId.isZero()) {
|
|
1597
|
+
return "X";
|
|
1598
|
+
}
|
|
1599
|
+
let numZeroDigits = cellId.countTrailingZeros();
|
|
1600
|
+
const remainder = numZeroDigits % 4;
|
|
1601
|
+
numZeroDigits = (numZeroDigits - remainder) / 4;
|
|
1602
|
+
const trailingZeroHexChars = numZeroDigits;
|
|
1603
|
+
numZeroDigits *= 4;
|
|
1604
|
+
const x = cellId.shiftRightUnsigned(numZeroDigits);
|
|
1605
|
+
const hexString = x.toString(16).replace(/0+$/, "");
|
|
1606
|
+
const zeroString = Array(17 - trailingZeroHexChars - hexString.length).join("0");
|
|
1607
|
+
return zeroString + hexString;
|
|
1608
|
+
}
|
|
1609
|
+
function getS2ChildCellId(cellId, index) {
|
|
1610
|
+
const newLsb = lsb(cellId).shiftRightUnsigned(2);
|
|
1611
|
+
const childCellId = cellId.add(import_long.default.fromNumber(2 * index + 1 - 4).multiply(newLsb));
|
|
1612
|
+
return childCellId;
|
|
1613
|
+
}
|
|
1614
|
+
function lsb(cellId) {
|
|
1615
|
+
return cellId.and(cellId.not().add(1));
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
// src/lib/utils/s2/s2geometry/s2-geometry.ts
|
|
1619
|
+
var import_long2 = __toESM(require("long"), 1);
|
|
1620
|
+
var FACE_BITS = 3;
|
|
1621
|
+
var MAX_LEVEL = 30;
|
|
1622
|
+
var POS_BITS = 2 * MAX_LEVEL + 1;
|
|
1623
|
+
var RADIAN_TO_DEGREE = 180 / Math.PI;
|
|
1624
|
+
function getS2CellFromQuadKey(hilbertQuadkey) {
|
|
1625
|
+
if (hilbertQuadkey.length === 0) {
|
|
1626
|
+
throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
|
|
1627
|
+
}
|
|
1628
|
+
const parts = hilbertQuadkey.split("/");
|
|
1629
|
+
const face = parseInt(parts[0], 10);
|
|
1630
|
+
const position = parts[1];
|
|
1631
|
+
const maxLevel = position.length;
|
|
1632
|
+
let level = 0;
|
|
1633
|
+
const point = [0, 0];
|
|
1634
|
+
for (let i = maxLevel - 1; i >= 0; i--) {
|
|
1635
|
+
level = maxLevel - i;
|
|
1636
|
+
const bit = position[i];
|
|
1637
|
+
let rx = 0;
|
|
1638
|
+
let ry = 0;
|
|
1639
|
+
if (bit === "1") {
|
|
1640
|
+
ry = 1;
|
|
1641
|
+
} else if (bit === "2") {
|
|
1642
|
+
rx = 1;
|
|
1643
|
+
ry = 1;
|
|
1644
|
+
} else if (bit === "3") {
|
|
1645
|
+
rx = 1;
|
|
1646
|
+
}
|
|
1647
|
+
const val = Math.pow(2, level - 1);
|
|
1648
|
+
rotateAndFlipQuadrant(val, point, rx, ry);
|
|
1649
|
+
point[0] += val * rx;
|
|
1650
|
+
point[1] += val * ry;
|
|
1651
|
+
}
|
|
1652
|
+
if (face % 2 === 1) {
|
|
1653
|
+
const t = point[0];
|
|
1654
|
+
point[0] = point[1];
|
|
1655
|
+
point[1] = t;
|
|
1656
|
+
}
|
|
1657
|
+
return { face, ij: point, level };
|
|
1658
|
+
}
|
|
1659
|
+
function getS2QuadkeyFromCellId(cellId) {
|
|
1660
|
+
if (cellId.isZero()) {
|
|
1661
|
+
return "";
|
|
1662
|
+
}
|
|
1663
|
+
let bin = cellId.toString(2);
|
|
1664
|
+
while (bin.length < FACE_BITS + POS_BITS) {
|
|
1665
|
+
bin = "0" + bin;
|
|
1666
|
+
}
|
|
1667
|
+
const lsbIndex = bin.lastIndexOf("1");
|
|
1668
|
+
const faceB = bin.substring(0, 3);
|
|
1669
|
+
const posB = bin.substring(3, lsbIndex);
|
|
1670
|
+
const levelN = posB.length / 2;
|
|
1671
|
+
const faceS = import_long2.default.fromString(faceB, true, 2).toString(10);
|
|
1672
|
+
let posS = "";
|
|
1673
|
+
if (levelN !== 0) {
|
|
1674
|
+
posS = import_long2.default.fromString(posB, true, 2).toString(4);
|
|
1675
|
+
while (posS.length < levelN) {
|
|
1676
|
+
posS = "0" + posS;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return `${faceS}/${posS}`;
|
|
1680
|
+
}
|
|
1681
|
+
function IJToST(ij, level, offsets) {
|
|
1682
|
+
const maxSize = 1 << level;
|
|
1683
|
+
return [(ij[0] + offsets[0]) / maxSize, (ij[1] + offsets[1]) / maxSize];
|
|
1684
|
+
}
|
|
1685
|
+
function singleSTtoUV(st) {
|
|
1686
|
+
if (st >= 0.5) {
|
|
1687
|
+
return 1 / 3 * (4 * st * st - 1);
|
|
1688
|
+
}
|
|
1689
|
+
return 1 / 3 * (1 - 4 * (1 - st) * (1 - st));
|
|
1690
|
+
}
|
|
1691
|
+
function STToUV(st) {
|
|
1692
|
+
return [singleSTtoUV(st[0]), singleSTtoUV(st[1])];
|
|
1693
|
+
}
|
|
1694
|
+
function FaceUVToXYZ(face, [u, v]) {
|
|
1695
|
+
switch (face) {
|
|
1696
|
+
case 0:
|
|
1697
|
+
return [1, u, v];
|
|
1698
|
+
case 1:
|
|
1699
|
+
return [-u, 1, v];
|
|
1700
|
+
case 2:
|
|
1701
|
+
return [-u, -v, 1];
|
|
1702
|
+
case 3:
|
|
1703
|
+
return [-1, -v, -u];
|
|
1704
|
+
case 4:
|
|
1705
|
+
return [v, -1, -u];
|
|
1706
|
+
case 5:
|
|
1707
|
+
return [v, u, -1];
|
|
1708
|
+
default:
|
|
1709
|
+
throw new Error("Invalid face");
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
function XYZToLngLat([x, y, z]) {
|
|
1713
|
+
const lat = Math.atan2(z, Math.sqrt(x * x + y * y));
|
|
1714
|
+
const lng = Math.atan2(y, x);
|
|
1715
|
+
return [lng * RADIAN_TO_DEGREE, lat * RADIAN_TO_DEGREE];
|
|
1716
|
+
}
|
|
1717
|
+
function rotateAndFlipQuadrant(n, point, rx, ry) {
|
|
1718
|
+
if (ry === 0) {
|
|
1719
|
+
if (rx === 1) {
|
|
1720
|
+
point[0] = n - 1 - point[0];
|
|
1721
|
+
point[1] = n - 1 - point[1];
|
|
1722
|
+
}
|
|
1723
|
+
const x = point[0];
|
|
1724
|
+
point[0] = point[1];
|
|
1725
|
+
point[1] = x;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
function getS2LngLatFromS2Cell(s2Cell) {
|
|
1729
|
+
const st = IJToST(s2Cell.ij, s2Cell.level, [0.5, 0.5]);
|
|
1730
|
+
const uv = STToUV(st);
|
|
1731
|
+
const xyz = FaceUVToXYZ(s2Cell.face, uv);
|
|
1732
|
+
return XYZToLngLat(xyz);
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// src/lib/utils/s2/converters/s2-to-boundary.ts
|
|
1736
|
+
var MAX_RESOLUTION = 100;
|
|
1737
|
+
function getS2BoundaryFlatFromS2Cell(s2cell) {
|
|
1738
|
+
const { face, ij, level } = s2cell;
|
|
1739
|
+
const offsets = [
|
|
1740
|
+
[0, 0],
|
|
1741
|
+
[0, 1],
|
|
1742
|
+
[1, 1],
|
|
1743
|
+
[1, 0],
|
|
1744
|
+
[0, 0]
|
|
1745
|
+
];
|
|
1746
|
+
const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
|
|
1747
|
+
const result = new Float64Array(4 * resolution * 2 + 2);
|
|
1748
|
+
let ptIndex = 0;
|
|
1749
|
+
let prevLng = 0;
|
|
1750
|
+
for (let i = 0; i < 4; i++) {
|
|
1751
|
+
const offset = offsets[i].slice(0);
|
|
1752
|
+
const nextOffset = offsets[i + 1];
|
|
1753
|
+
const stepI = (nextOffset[0] - offset[0]) / resolution;
|
|
1754
|
+
const stepJ = (nextOffset[1] - offset[1]) / resolution;
|
|
1755
|
+
for (let j = 0; j < resolution; j++) {
|
|
1756
|
+
offset[0] += stepI;
|
|
1757
|
+
offset[1] += stepJ;
|
|
1758
|
+
const st = IJToST(ij, level, offset);
|
|
1759
|
+
const uv = STToUV(st);
|
|
1760
|
+
const xyz = FaceUVToXYZ(face, uv);
|
|
1761
|
+
const lngLat = XYZToLngLat(xyz);
|
|
1762
|
+
if (Math.abs(lngLat[1]) > 89.999) {
|
|
1763
|
+
lngLat[0] = prevLng;
|
|
1764
|
+
}
|
|
1765
|
+
const deltaLng = lngLat[0] - prevLng;
|
|
1766
|
+
lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
|
|
1767
|
+
result[ptIndex++] = lngLat[0];
|
|
1768
|
+
result[ptIndex++] = lngLat[1];
|
|
1769
|
+
prevLng = lngLat[0];
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
result[ptIndex++] = result[0];
|
|
1773
|
+
result[ptIndex++] = result[1];
|
|
1774
|
+
return result;
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
// src/lib/utils/s2/s2geometry/s2-cell-utils.ts
|
|
1778
|
+
function getS2Cell(tokenOrKey) {
|
|
1779
|
+
const key = getS2QuadKey(tokenOrKey);
|
|
1780
|
+
const s2cell = getS2CellFromQuadKey(key);
|
|
1781
|
+
return s2cell;
|
|
1782
|
+
}
|
|
1783
|
+
function getS2QuadKey(tokenOrKey) {
|
|
1784
|
+
if (tokenOrKey.indexOf("/") > 0) {
|
|
1785
|
+
return tokenOrKey;
|
|
1786
|
+
}
|
|
1787
|
+
const id = getS2CellIdFromToken(tokenOrKey);
|
|
1788
|
+
return getS2QuadkeyFromCellId(id);
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
// src/lib/utils/s2/s2-geometry-functions.ts
|
|
1792
|
+
function getS2LngLat(s2Token) {
|
|
1793
|
+
const s2cell = getS2Cell(s2Token);
|
|
1794
|
+
return getS2LngLatFromS2Cell(s2cell);
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
// src/lib/utils/s2/converters/s2-to-region.ts
|
|
1798
|
+
function getS2Region(s2cell) {
|
|
1799
|
+
let region;
|
|
1800
|
+
if (s2cell.face === 2 || s2cell.face === 5) {
|
|
1801
|
+
let corners = null;
|
|
1802
|
+
let len = 0;
|
|
1803
|
+
for (let i = 0; i < 4; i++) {
|
|
1804
|
+
const key = `${s2cell.face}/${i}`;
|
|
1805
|
+
const cell = getS2Cell(key);
|
|
1806
|
+
const corns = getS2BoundaryFlatFromS2Cell(cell);
|
|
1807
|
+
if (typeof corners === "undefined" || corners === null)
|
|
1808
|
+
corners = new Float64Array(4 * corns.length);
|
|
1809
|
+
corners.set(corns, len);
|
|
1810
|
+
len += corns.length;
|
|
1811
|
+
}
|
|
1812
|
+
region = get2DRegionFromS2Corners(corners);
|
|
1813
|
+
} else {
|
|
1814
|
+
const corners = getS2BoundaryFlatFromS2Cell(s2cell);
|
|
1815
|
+
region = get2DRegionFromS2Corners(corners);
|
|
1816
|
+
}
|
|
1817
|
+
return region;
|
|
1818
|
+
}
|
|
1819
|
+
function get2DRegionFromS2Corners(corners) {
|
|
1820
|
+
if (corners.length % 2 !== 0) {
|
|
1821
|
+
throw new Error("Invalid corners");
|
|
1822
|
+
}
|
|
1823
|
+
const longitudes = [];
|
|
1824
|
+
const latitudes = [];
|
|
1825
|
+
for (let i = 0; i < corners.length; i += 2) {
|
|
1826
|
+
longitudes.push(corners[i]);
|
|
1827
|
+
latitudes.push(corners[i + 1]);
|
|
1828
|
+
}
|
|
1829
|
+
longitudes.sort((a, b) => a - b);
|
|
1830
|
+
latitudes.sort((a, b) => a - b);
|
|
1831
|
+
return {
|
|
1832
|
+
west: longitudes[0],
|
|
1833
|
+
east: longitudes[longitudes.length - 1],
|
|
1834
|
+
north: latitudes[latitudes.length - 1],
|
|
1835
|
+
south: latitudes[0]
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
// src/lib/utils/s2/converters/s2-to-obb-points.ts
|
|
1840
|
+
var import_core5 = require("@math.gl/core");
|
|
1841
|
+
function getS2OrientedBoundingBoxCornerPoints(tokenOrKey, heightInfo) {
|
|
1842
|
+
const min = (heightInfo == null ? void 0 : heightInfo.minimumHeight) || 0;
|
|
1843
|
+
const max = (heightInfo == null ? void 0 : heightInfo.maximumHeight) || 0;
|
|
1844
|
+
const s2cell = getS2Cell(tokenOrKey);
|
|
1845
|
+
const region = getS2Region(s2cell);
|
|
1846
|
+
const W = region.west;
|
|
1847
|
+
const S = region.south;
|
|
1848
|
+
const E = region.east;
|
|
1849
|
+
const N = region.north;
|
|
1850
|
+
const points = [];
|
|
1851
|
+
points.push(new import_core5.Vector3(W, N, min));
|
|
1852
|
+
points.push(new import_core5.Vector3(E, N, min));
|
|
1853
|
+
points.push(new import_core5.Vector3(E, S, min));
|
|
1854
|
+
points.push(new import_core5.Vector3(W, S, min));
|
|
1855
|
+
points.push(new import_core5.Vector3(W, N, max));
|
|
1856
|
+
points.push(new import_core5.Vector3(E, N, max));
|
|
1857
|
+
points.push(new import_core5.Vector3(E, S, max));
|
|
1858
|
+
points.push(new import_core5.Vector3(W, S, max));
|
|
1859
|
+
return points;
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
// src/lib/utils/obb/s2-corners-to-obb.ts
|
|
1863
|
+
var import_core6 = require("@math.gl/core");
|
|
1864
|
+
var import_culling = require("@math.gl/culling");
|
|
1865
|
+
var import_geospatial2 = require("@math.gl/geospatial");
|
|
1866
|
+
function convertS2BoundingVolumetoOBB(s2VolumeInfo) {
|
|
1867
|
+
const token = s2VolumeInfo.token;
|
|
1868
|
+
const heightInfo = {
|
|
1869
|
+
minimumHeight: s2VolumeInfo.minimumHeight,
|
|
1870
|
+
maximumHeight: s2VolumeInfo.maximumHeight
|
|
1871
|
+
};
|
|
1872
|
+
const corners = getS2OrientedBoundingBoxCornerPoints(token, heightInfo);
|
|
1873
|
+
const center = getS2LngLat(token);
|
|
1874
|
+
const centerLng = center[0];
|
|
1875
|
+
const centerLat = center[1];
|
|
1876
|
+
const point = import_geospatial2.Ellipsoid.WGS84.cartographicToCartesian([
|
|
1877
|
+
centerLng,
|
|
1878
|
+
centerLat,
|
|
1879
|
+
heightInfo.maximumHeight
|
|
1880
|
+
]);
|
|
1881
|
+
const centerPointAdditional = new import_core6.Vector3(point[0], point[1], point[2]);
|
|
1882
|
+
corners.push(centerPointAdditional);
|
|
1883
|
+
const obb = (0, import_culling.makeOrientedBoundingBoxFromPoints)(corners);
|
|
1884
|
+
const box = [...obb.center, ...obb.halfAxes];
|
|
1885
|
+
return box;
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
// src/lib/parsers/helpers/parse-3d-implicit-tiles.ts
|
|
1889
|
+
var QUADTREE_DEVISION_COUNT = 4;
|
|
1890
|
+
var OCTREE_DEVISION_COUNT = 8;
|
|
1891
|
+
var SUBDIVISION_COUNT_MAP = {
|
|
1892
|
+
QUADTREE: QUADTREE_DEVISION_COUNT,
|
|
1893
|
+
OCTREE: OCTREE_DEVISION_COUNT
|
|
1894
|
+
};
|
|
1895
|
+
function getChildS2VolumeBox(s2VolumeBox, index, subdivisionScheme) {
|
|
1896
|
+
if (s2VolumeBox == null ? void 0 : s2VolumeBox.box) {
|
|
1897
|
+
const cellId = getS2CellIdFromToken(s2VolumeBox.s2VolumeInfo.token);
|
|
1898
|
+
const childCellId = getS2ChildCellId(cellId, index);
|
|
1899
|
+
const childToken = getS2TokenFromCellId(childCellId);
|
|
1900
|
+
const s2ChildVolumeInfo = { ...s2VolumeBox.s2VolumeInfo };
|
|
1901
|
+
s2ChildVolumeInfo.token = childToken;
|
|
1902
|
+
switch (subdivisionScheme) {
|
|
1903
|
+
case "OCTREE":
|
|
1904
|
+
const s2VolumeInfo = s2VolumeBox.s2VolumeInfo;
|
|
1905
|
+
const delta = s2VolumeInfo.maximumHeight - s2VolumeInfo.minimumHeight;
|
|
1906
|
+
const sizeZ = delta / 2;
|
|
1907
|
+
const midZ = s2VolumeInfo.minimumHeight + delta / 2;
|
|
1908
|
+
s2VolumeInfo.minimumHeight = midZ - sizeZ;
|
|
1909
|
+
s2VolumeInfo.maximumHeight = midZ + sizeZ;
|
|
1910
|
+
break;
|
|
1911
|
+
default:
|
|
1912
|
+
break;
|
|
1913
|
+
}
|
|
1914
|
+
const box = convertS2BoundingVolumetoOBB(s2ChildVolumeInfo);
|
|
1915
|
+
const childS2VolumeBox = {
|
|
1916
|
+
box,
|
|
1917
|
+
s2VolumeInfo: s2ChildVolumeInfo
|
|
1918
|
+
};
|
|
1919
|
+
return childS2VolumeBox;
|
|
1920
|
+
}
|
|
1921
|
+
return void 0;
|
|
1922
|
+
}
|
|
1923
|
+
async function parseImplicitTiles(params) {
|
|
1924
|
+
const {
|
|
1925
|
+
implicitOptions,
|
|
1926
|
+
parentData = {
|
|
1927
|
+
mortonIndex: 0,
|
|
1928
|
+
x: 0,
|
|
1929
|
+
y: 0,
|
|
1930
|
+
z: 0
|
|
1931
|
+
},
|
|
1932
|
+
childIndex = 0,
|
|
1933
|
+
globalData = {
|
|
1934
|
+
level: 0,
|
|
1935
|
+
mortonIndex: 0,
|
|
1936
|
+
x: 0,
|
|
1937
|
+
y: 0,
|
|
1938
|
+
z: 0
|
|
1939
|
+
},
|
|
1940
|
+
s2VolumeBox,
|
|
1941
|
+
loaderOptions
|
|
1942
|
+
} = params;
|
|
1943
|
+
let { subtree, level = 0 } = params;
|
|
1944
|
+
const {
|
|
1945
|
+
subdivisionScheme,
|
|
1946
|
+
subtreeLevels,
|
|
1947
|
+
maximumLevel,
|
|
1948
|
+
contentUrlTemplate,
|
|
1949
|
+
subtreesUriTemplate,
|
|
1950
|
+
basePath
|
|
1951
|
+
} = implicitOptions;
|
|
1952
|
+
const tile = { children: [], lodMetricValue: 0, contentUrl: "" };
|
|
1953
|
+
if (!maximumLevel) {
|
|
1954
|
+
import_log.default.once(
|
|
1955
|
+
`Missing 'maximumLevel' or 'availableLevels' property. The subtree ${contentUrlTemplate} won't be loaded...`
|
|
1956
|
+
);
|
|
1957
|
+
return tile;
|
|
1958
|
+
}
|
|
1959
|
+
const lev = level + globalData.level;
|
|
1960
|
+
if (lev > maximumLevel) {
|
|
1961
|
+
return tile;
|
|
1962
|
+
}
|
|
1963
|
+
const childrenPerTile = SUBDIVISION_COUNT_MAP[subdivisionScheme];
|
|
1964
|
+
const bitsPerTile = Math.log2(childrenPerTile);
|
|
1965
|
+
const childX = childIndex & 1;
|
|
1966
|
+
const childY = childIndex >> 1 & 1;
|
|
1967
|
+
const childZ = childIndex >> 2 & 1;
|
|
1968
|
+
const levelOffset = (childrenPerTile ** level - 1) / (childrenPerTile - 1);
|
|
1969
|
+
let childTileMortonIndex = concatBits(parentData.mortonIndex, childIndex, bitsPerTile);
|
|
1970
|
+
let tileAvailabilityIndex = levelOffset + childTileMortonIndex;
|
|
1971
|
+
let childTileX = concatBits(parentData.x, childX, 1);
|
|
1972
|
+
let childTileY = concatBits(parentData.y, childY, 1);
|
|
1973
|
+
let childTileZ = concatBits(parentData.z, childZ, 1);
|
|
1974
|
+
let isChildSubtreeAvailable = false;
|
|
1975
|
+
if (level >= subtreeLevels) {
|
|
1976
|
+
isChildSubtreeAvailable = getAvailabilityResult(
|
|
1977
|
+
subtree.childSubtreeAvailability,
|
|
1978
|
+
childTileMortonIndex
|
|
1979
|
+
);
|
|
1980
|
+
}
|
|
1981
|
+
const x = concatBits(globalData.x, childTileX, level * bitsPerTile);
|
|
1982
|
+
const y = concatBits(globalData.y, childTileY, level * bitsPerTile);
|
|
1983
|
+
const z = concatBits(globalData.z, childTileZ, level * bitsPerTile);
|
|
1984
|
+
if (isChildSubtreeAvailable) {
|
|
1985
|
+
const subtreePath = `${basePath}/${subtreesUriTemplate}`;
|
|
1986
|
+
const childSubtreeUrl = replaceContentUrlTemplate(subtreePath, lev, x, y, z);
|
|
1987
|
+
const childSubtree = await (0, import_core7.load)(childSubtreeUrl, Tile3DSubtreeLoader, loaderOptions);
|
|
1988
|
+
subtree = childSubtree;
|
|
1989
|
+
globalData.mortonIndex = childTileMortonIndex;
|
|
1990
|
+
globalData.x = childTileX;
|
|
1991
|
+
globalData.y = childTileY;
|
|
1992
|
+
globalData.z = childTileZ;
|
|
1993
|
+
globalData.level = level;
|
|
1994
|
+
childTileMortonIndex = 0;
|
|
1995
|
+
tileAvailabilityIndex = 0;
|
|
1996
|
+
childTileX = 0;
|
|
1997
|
+
childTileY = 0;
|
|
1998
|
+
childTileZ = 0;
|
|
1999
|
+
level = 0;
|
|
2000
|
+
}
|
|
2001
|
+
const isTileAvailable = getAvailabilityResult(subtree.tileAvailability, tileAvailabilityIndex);
|
|
2002
|
+
if (!isTileAvailable) {
|
|
2003
|
+
return tile;
|
|
2004
|
+
}
|
|
2005
|
+
const isContentAvailable = getAvailabilityResult(
|
|
2006
|
+
subtree.contentAvailability,
|
|
2007
|
+
tileAvailabilityIndex
|
|
2008
|
+
);
|
|
2009
|
+
if (isContentAvailable) {
|
|
2010
|
+
tile.contentUrl = replaceContentUrlTemplate(contentUrlTemplate, lev, x, y, z);
|
|
2011
|
+
}
|
|
2012
|
+
const childTileLevel = level + 1;
|
|
2013
|
+
const pData = { mortonIndex: childTileMortonIndex, x: childTileX, y: childTileY, z: childTileZ };
|
|
2014
|
+
for (let index = 0; index < childrenPerTile; index++) {
|
|
2015
|
+
const childS2VolumeBox = getChildS2VolumeBox(
|
|
2016
|
+
s2VolumeBox,
|
|
2017
|
+
index,
|
|
2018
|
+
subdivisionScheme
|
|
2019
|
+
);
|
|
2020
|
+
const childTileParsed = await parseImplicitTiles({
|
|
2021
|
+
subtree,
|
|
2022
|
+
implicitOptions,
|
|
2023
|
+
loaderOptions,
|
|
2024
|
+
parentData: pData,
|
|
2025
|
+
childIndex: index,
|
|
2026
|
+
level: childTileLevel,
|
|
2027
|
+
globalData: { ...globalData },
|
|
2028
|
+
s2VolumeBox: childS2VolumeBox
|
|
2029
|
+
});
|
|
2030
|
+
if (childTileParsed.contentUrl || childTileParsed.children.length) {
|
|
2031
|
+
const globalLevel = lev + 1;
|
|
2032
|
+
const childCoordinates = { childTileX, childTileY, childTileZ };
|
|
2033
|
+
const formattedTile = formatTileData(
|
|
2034
|
+
childTileParsed,
|
|
2035
|
+
globalLevel,
|
|
2036
|
+
childCoordinates,
|
|
2037
|
+
implicitOptions,
|
|
2038
|
+
s2VolumeBox
|
|
2039
|
+
);
|
|
2040
|
+
tile.children.push(formattedTile);
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
return tile;
|
|
2044
|
+
}
|
|
2045
|
+
function getAvailabilityResult(availabilityData, index) {
|
|
2046
|
+
let availabilityObject;
|
|
2047
|
+
if (Array.isArray(availabilityData)) {
|
|
2048
|
+
availabilityObject = availabilityData[0];
|
|
2049
|
+
if (availabilityData.length > 1) {
|
|
2050
|
+
import_log.default.once('Not supported extension "3DTILES_multiple_contents" has been detected');
|
|
2051
|
+
}
|
|
2052
|
+
} else {
|
|
2053
|
+
availabilityObject = availabilityData;
|
|
2054
|
+
}
|
|
2055
|
+
if ("constant" in availabilityObject) {
|
|
2056
|
+
return Boolean(availabilityObject.constant);
|
|
2057
|
+
}
|
|
2058
|
+
if (availabilityObject.explicitBitstream) {
|
|
2059
|
+
return getBooleanValueFromBitstream(index, availabilityObject.explicitBitstream);
|
|
2060
|
+
}
|
|
2061
|
+
return false;
|
|
2062
|
+
}
|
|
2063
|
+
function formatTileData(tile, level, childCoordinates, options, s2VolumeBox) {
|
|
2064
|
+
const {
|
|
2065
|
+
basePath,
|
|
2066
|
+
refine,
|
|
2067
|
+
getRefine: getRefine2,
|
|
2068
|
+
lodMetricType,
|
|
2069
|
+
getTileType: getTileType2,
|
|
2070
|
+
rootLodMetricValue,
|
|
2071
|
+
rootBoundingVolume
|
|
2072
|
+
} = options;
|
|
2073
|
+
const uri = tile.contentUrl && tile.contentUrl.replace(`${basePath}/`, "");
|
|
2074
|
+
const lodMetricValue = rootLodMetricValue / 2 ** level;
|
|
2075
|
+
const boundingVolume = (s2VolumeBox == null ? void 0 : s2VolumeBox.box) ? { box: s2VolumeBox.box } : rootBoundingVolume;
|
|
2076
|
+
const boundingVolumeForChildTile = calculateBoundingVolumeForChildTile(
|
|
2077
|
+
level,
|
|
2078
|
+
boundingVolume,
|
|
2079
|
+
childCoordinates
|
|
2080
|
+
);
|
|
2081
|
+
return {
|
|
2082
|
+
children: tile.children,
|
|
2083
|
+
contentUrl: tile.contentUrl,
|
|
2084
|
+
content: { uri },
|
|
2085
|
+
id: tile.contentUrl,
|
|
2086
|
+
refine: getRefine2(refine),
|
|
2087
|
+
type: getTileType2(tile),
|
|
2088
|
+
lodMetricType,
|
|
2089
|
+
lodMetricValue,
|
|
2090
|
+
geometricError: lodMetricValue,
|
|
2091
|
+
transform: tile.transform,
|
|
2092
|
+
boundingVolume: boundingVolumeForChildTile
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
function calculateBoundingVolumeForChildTile(level, rootBoundingVolume, childCoordinates) {
|
|
2096
|
+
if (rootBoundingVolume.region) {
|
|
2097
|
+
const { childTileX, childTileY, childTileZ } = childCoordinates;
|
|
2098
|
+
const [west, south, east, north, minimumHeight, maximumHeight] = rootBoundingVolume.region;
|
|
2099
|
+
const boundingVolumesCount = 2 ** level;
|
|
2100
|
+
const sizeX = (east - west) / boundingVolumesCount;
|
|
2101
|
+
const sizeY = (north - south) / boundingVolumesCount;
|
|
2102
|
+
const sizeZ = (maximumHeight - minimumHeight) / boundingVolumesCount;
|
|
2103
|
+
const [childWest, childEast] = [west + sizeX * childTileX, west + sizeX * (childTileX + 1)];
|
|
2104
|
+
const [childSouth, childNorth] = [south + sizeY * childTileY, south + sizeY * (childTileY + 1)];
|
|
2105
|
+
const [childMinimumHeight, childMaximumHeight] = [
|
|
2106
|
+
minimumHeight + sizeZ * childTileZ,
|
|
2107
|
+
minimumHeight + sizeZ * (childTileZ + 1)
|
|
2108
|
+
];
|
|
2109
|
+
return {
|
|
2110
|
+
region: [childWest, childSouth, childEast, childNorth, childMinimumHeight, childMaximumHeight]
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
if (rootBoundingVolume.box) {
|
|
2114
|
+
return rootBoundingVolume;
|
|
2115
|
+
}
|
|
2116
|
+
throw new Error(`Unsupported bounding volume type ${rootBoundingVolume}`);
|
|
2117
|
+
}
|
|
2118
|
+
function concatBits(higher, lower, shift) {
|
|
2119
|
+
return (higher << shift) + lower;
|
|
2120
|
+
}
|
|
2121
|
+
function replaceContentUrlTemplate(templateUrl, level, x, y, z) {
|
|
2122
|
+
const mapUrl = generateMapUrl({ level, x, y, z });
|
|
2123
|
+
return templateUrl.replace(/{level}|{x}|{y}|{z}/gi, (matched) => mapUrl[matched]);
|
|
2124
|
+
}
|
|
2125
|
+
function generateMapUrl(items) {
|
|
2126
|
+
const mapUrl = {};
|
|
2127
|
+
for (const key in items) {
|
|
2128
|
+
mapUrl[`{${key}}`] = items[key];
|
|
2129
|
+
}
|
|
2130
|
+
return mapUrl;
|
|
2131
|
+
}
|
|
2132
|
+
function getBooleanValueFromBitstream(availabilityIndex, availabilityBuffer) {
|
|
2133
|
+
const byteIndex = Math.floor(availabilityIndex / 8);
|
|
2134
|
+
const bitIndex = availabilityIndex % 8;
|
|
2135
|
+
const bitValue = availabilityBuffer[byteIndex] >> bitIndex & 1;
|
|
2136
|
+
return bitValue === 1;
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
// src/lib/parsers/parse-3d-tile-header.ts
|
|
2140
|
+
function getTileType(tile, tileContentUrl = "") {
|
|
2141
|
+
if (!tileContentUrl) {
|
|
2142
|
+
return import_tiles.TILE_TYPE.EMPTY;
|
|
2143
|
+
}
|
|
2144
|
+
const contentUrl = tileContentUrl.split("?")[0];
|
|
2145
|
+
const fileExtension = contentUrl.split(".").pop();
|
|
2146
|
+
switch (fileExtension) {
|
|
2147
|
+
case "pnts":
|
|
2148
|
+
return import_tiles.TILE_TYPE.POINTCLOUD;
|
|
2149
|
+
case "i3dm":
|
|
2150
|
+
case "b3dm":
|
|
2151
|
+
case "glb":
|
|
2152
|
+
case "gltf":
|
|
2153
|
+
return import_tiles.TILE_TYPE.SCENEGRAPH;
|
|
2154
|
+
default:
|
|
2155
|
+
return fileExtension || import_tiles.TILE_TYPE.EMPTY;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
function getRefine(refine) {
|
|
2159
|
+
switch (refine) {
|
|
2160
|
+
case "REPLACE":
|
|
2161
|
+
case "replace":
|
|
2162
|
+
return import_tiles.TILE_REFINEMENT.REPLACE;
|
|
2163
|
+
case "ADD":
|
|
2164
|
+
case "add":
|
|
2165
|
+
return import_tiles.TILE_REFINEMENT.ADD;
|
|
2166
|
+
default:
|
|
2167
|
+
return refine;
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
function resolveUri(uri = "", basePath) {
|
|
2171
|
+
const urlSchemeRegex = /^[a-z][0-9a-z+.-]*:/i;
|
|
2172
|
+
if (urlSchemeRegex.test(basePath)) {
|
|
2173
|
+
const url = new URL(uri, `${basePath}/`);
|
|
2174
|
+
return decodeURI(url.toString());
|
|
2175
|
+
} else if (uri.startsWith("/")) {
|
|
2176
|
+
return uri;
|
|
2177
|
+
}
|
|
2178
|
+
return import_loader_utils7.path.resolve(basePath, uri);
|
|
2179
|
+
}
|
|
2180
|
+
function normalizeTileData(tile, basePath) {
|
|
2181
|
+
var _a;
|
|
2182
|
+
if (!tile) {
|
|
2183
|
+
return null;
|
|
2184
|
+
}
|
|
2185
|
+
let tileContentUrl;
|
|
2186
|
+
if (tile.content) {
|
|
2187
|
+
const contentUri = tile.content.uri || ((_a = tile.content) == null ? void 0 : _a.url);
|
|
2188
|
+
tileContentUrl = resolveUri(contentUri, basePath);
|
|
2189
|
+
}
|
|
2190
|
+
const tilePostprocessed = {
|
|
2191
|
+
...tile,
|
|
2192
|
+
id: tileContentUrl,
|
|
2193
|
+
contentUrl: tileContentUrl,
|
|
2194
|
+
lodMetricType: import_tiles.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
|
|
2195
|
+
lodMetricValue: tile.geometricError,
|
|
2196
|
+
transformMatrix: tile.transform,
|
|
2197
|
+
type: getTileType(tile, tileContentUrl),
|
|
2198
|
+
refine: getRefine(tile.refine)
|
|
2199
|
+
};
|
|
2200
|
+
return tilePostprocessed;
|
|
2201
|
+
}
|
|
2202
|
+
async function normalizeTileHeaders(tileset, basePath, options) {
|
|
2203
|
+
let root = null;
|
|
2204
|
+
const rootImplicitTilingExtension = getImplicitTilingExtensionData(tileset.root);
|
|
2205
|
+
if (rootImplicitTilingExtension && tileset.root) {
|
|
2206
|
+
root = await normalizeImplicitTileHeaders(
|
|
2207
|
+
tileset.root,
|
|
2208
|
+
tileset,
|
|
2209
|
+
basePath,
|
|
2210
|
+
rootImplicitTilingExtension,
|
|
2211
|
+
options
|
|
2212
|
+
);
|
|
2213
|
+
} else {
|
|
2214
|
+
root = normalizeTileData(tileset.root, basePath);
|
|
2215
|
+
}
|
|
2216
|
+
const stack2 = [];
|
|
2217
|
+
stack2.push(root);
|
|
2218
|
+
while (stack2.length > 0) {
|
|
2219
|
+
const tile = stack2.pop() || {};
|
|
2220
|
+
const children = tile.children || [];
|
|
2221
|
+
const childrenPostprocessed = [];
|
|
2222
|
+
for (const childHeader of children) {
|
|
2223
|
+
const childImplicitTilingExtension = getImplicitTilingExtensionData(childHeader);
|
|
2224
|
+
let childHeaderPostprocessed;
|
|
2225
|
+
if (childImplicitTilingExtension) {
|
|
2226
|
+
childHeaderPostprocessed = await normalizeImplicitTileHeaders(
|
|
2227
|
+
childHeader,
|
|
2228
|
+
tileset,
|
|
2229
|
+
basePath,
|
|
2230
|
+
childImplicitTilingExtension,
|
|
2231
|
+
options
|
|
2232
|
+
);
|
|
2233
|
+
} else {
|
|
2234
|
+
childHeaderPostprocessed = normalizeTileData(childHeader, basePath);
|
|
2235
|
+
}
|
|
2236
|
+
if (childHeaderPostprocessed) {
|
|
2237
|
+
childrenPostprocessed.push(childHeaderPostprocessed);
|
|
2238
|
+
stack2.push(childHeaderPostprocessed);
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
tile.children = childrenPostprocessed;
|
|
2242
|
+
}
|
|
2243
|
+
return root;
|
|
2244
|
+
}
|
|
2245
|
+
async function normalizeImplicitTileHeaders(tile, tileset, basePath, implicitTilingExtension, options) {
|
|
2246
|
+
var _a, _b, _c;
|
|
2247
|
+
const {
|
|
2248
|
+
subdivisionScheme,
|
|
2249
|
+
maximumLevel,
|
|
2250
|
+
availableLevels,
|
|
2251
|
+
subtreeLevels,
|
|
2252
|
+
subtrees: { uri: subtreesUriTemplate }
|
|
2253
|
+
} = implicitTilingExtension;
|
|
2254
|
+
const replacedUrlTemplate = replaceContentUrlTemplate(subtreesUriTemplate, 0, 0, 0, 0);
|
|
2255
|
+
const subtreeUrl = resolveUri(replacedUrlTemplate, basePath);
|
|
2256
|
+
const subtree = await (0, import_core8.load)(subtreeUrl, Tile3DSubtreeLoader, options);
|
|
2257
|
+
const contentUrlTemplate = resolveUri((_a = tile.content) == null ? void 0 : _a.uri, basePath);
|
|
2258
|
+
const refine = (_b = tileset == null ? void 0 : tileset.root) == null ? void 0 : _b.refine;
|
|
2259
|
+
const rootLodMetricValue = tile.geometricError;
|
|
2260
|
+
const s2VolumeInfo = (_c = tile.boundingVolume.extensions) == null ? void 0 : _c["3DTILES_bounding_volume_S2"];
|
|
2261
|
+
if (s2VolumeInfo) {
|
|
2262
|
+
const box = convertS2BoundingVolumetoOBB(s2VolumeInfo);
|
|
2263
|
+
const s2VolumeBox = { box, s2VolumeInfo };
|
|
2264
|
+
tile.boundingVolume = s2VolumeBox;
|
|
2265
|
+
}
|
|
2266
|
+
const rootBoundingVolume = tile.boundingVolume;
|
|
2267
|
+
const implicitOptions = {
|
|
2268
|
+
contentUrlTemplate,
|
|
2269
|
+
subtreesUriTemplate,
|
|
2270
|
+
subdivisionScheme,
|
|
2271
|
+
subtreeLevels,
|
|
2272
|
+
maximumLevel: Number.isFinite(availableLevels) ? availableLevels - 1 : maximumLevel,
|
|
2273
|
+
refine,
|
|
2274
|
+
basePath,
|
|
2275
|
+
lodMetricType: import_tiles.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
|
|
2276
|
+
rootLodMetricValue,
|
|
2277
|
+
rootBoundingVolume,
|
|
2278
|
+
getTileType,
|
|
2279
|
+
getRefine
|
|
2280
|
+
};
|
|
2281
|
+
return await normalizeImplicitTileData(tile, basePath, subtree, implicitOptions, options);
|
|
2282
|
+
}
|
|
2283
|
+
async function normalizeImplicitTileData(tile, basePath, rootSubtree, implicitOptions, loaderOptions) {
|
|
2284
|
+
if (!tile) {
|
|
2285
|
+
return null;
|
|
2286
|
+
}
|
|
2287
|
+
const { children, contentUrl } = await parseImplicitTiles({
|
|
2288
|
+
subtree: rootSubtree,
|
|
2289
|
+
implicitOptions,
|
|
2290
|
+
loaderOptions
|
|
2291
|
+
});
|
|
2292
|
+
let tileContentUrl;
|
|
2293
|
+
let tileContent = null;
|
|
2294
|
+
if (contentUrl) {
|
|
2295
|
+
tileContentUrl = contentUrl;
|
|
2296
|
+
tileContent = { uri: contentUrl.replace(`${basePath}/`, "") };
|
|
2297
|
+
}
|
|
2298
|
+
const tilePostprocessed = {
|
|
2299
|
+
...tile,
|
|
2300
|
+
id: tileContentUrl,
|
|
2301
|
+
contentUrl: tileContentUrl,
|
|
2302
|
+
lodMetricType: import_tiles.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
|
|
2303
|
+
lodMetricValue: tile.geometricError,
|
|
2304
|
+
transformMatrix: tile.transform,
|
|
2305
|
+
type: getTileType(tile, tileContentUrl),
|
|
2306
|
+
refine: getRefine(tile.refine),
|
|
2307
|
+
content: tileContent || tile.content,
|
|
2308
|
+
children
|
|
2309
|
+
};
|
|
2310
|
+
return tilePostprocessed;
|
|
2311
|
+
}
|
|
2312
|
+
function getImplicitTilingExtensionData(tile) {
|
|
2313
|
+
var _a;
|
|
2314
|
+
return ((_a = tile == null ? void 0 : tile.extensions) == null ? void 0 : _a["3DTILES_implicit_tiling"]) || (tile == null ? void 0 : tile.implicitTiling);
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
// src/tiles-3d-loader.ts
|
|
2318
|
+
var Tiles3DLoader = {
|
|
2319
|
+
id: "3d-tiles",
|
|
2320
|
+
name: "3D Tiles",
|
|
2321
|
+
module: "3d-tiles",
|
|
2322
|
+
version: VERSION,
|
|
2323
|
+
extensions: ["cmpt", "pnts", "b3dm", "i3dm"],
|
|
2324
|
+
mimeTypes: ["application/octet-stream"],
|
|
2325
|
+
tests: ["cmpt", "pnts", "b3dm", "i3dm"],
|
|
2326
|
+
parse,
|
|
2327
|
+
options: {
|
|
2328
|
+
"3d-tiles": {
|
|
2329
|
+
loadGLTF: true,
|
|
2330
|
+
decodeQuantizedPositions: false,
|
|
2331
|
+
isTileset: "auto",
|
|
2332
|
+
assetGltfUpAxis: null
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
async function parse(data, options = {}, context) {
|
|
2337
|
+
const loaderOptions = options["3d-tiles"] || {};
|
|
2338
|
+
let isTileset;
|
|
2339
|
+
if (loaderOptions.isTileset === "auto") {
|
|
2340
|
+
isTileset = (context == null ? void 0 : context.url) && context.url.indexOf(".json") !== -1;
|
|
2341
|
+
} else {
|
|
2342
|
+
isTileset = loaderOptions.isTileset;
|
|
2343
|
+
}
|
|
2344
|
+
return isTileset ? parseTileset(data, options, context) : parseTile(data, options, context);
|
|
2345
|
+
}
|
|
2346
|
+
async function parseTileset(data, options, context) {
|
|
2347
|
+
var _a;
|
|
2348
|
+
const tilesetJson = JSON.parse(new TextDecoder().decode(data));
|
|
2349
|
+
const tilesetUrl = (context == null ? void 0 : context.url) || "";
|
|
2350
|
+
const basePath = getBaseUri(tilesetUrl);
|
|
2351
|
+
const normalizedRoot = await normalizeTileHeaders(tilesetJson, basePath, options || {});
|
|
2352
|
+
const tilesetJsonPostprocessed = {
|
|
2353
|
+
...tilesetJson,
|
|
2354
|
+
shape: "tileset3d",
|
|
2355
|
+
loader: Tiles3DLoader,
|
|
2356
|
+
url: tilesetUrl,
|
|
2357
|
+
queryString: (context == null ? void 0 : context.queryString) || "",
|
|
2358
|
+
basePath,
|
|
2359
|
+
root: normalizedRoot || tilesetJson.root,
|
|
2360
|
+
type: import_tiles2.TILESET_TYPE.TILES3D,
|
|
2361
|
+
lodMetricType: import_tiles2.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
|
|
2362
|
+
lodMetricValue: ((_a = tilesetJson.root) == null ? void 0 : _a.geometricError) || 0
|
|
2363
|
+
};
|
|
2364
|
+
return tilesetJsonPostprocessed;
|
|
2365
|
+
}
|
|
2366
|
+
async function parseTile(arrayBuffer, options, context) {
|
|
2367
|
+
const tile = {
|
|
2368
|
+
content: {
|
|
2369
|
+
shape: "tile3d",
|
|
2370
|
+
featureIds: null
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
const byteOffset = 0;
|
|
2374
|
+
await parse3DTile(arrayBuffer, byteOffset, options, context, tile.content);
|
|
2375
|
+
return tile.content;
|
|
2376
|
+
}
|
|
2377
|
+
function getBaseUri(tilesetUrl) {
|
|
2378
|
+
return import_loader_utils8.path.dirname(tilesetUrl);
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
// src/lib/ion/ion.ts
|
|
2382
|
+
var import_core9 = require("@loaders.gl/core");
|
|
2383
|
+
var import_loader_utils9 = require("@loaders.gl/loader-utils");
|
|
2384
|
+
var CESIUM_ION_URL = "https://api.cesium.com/v1/assets";
|
|
2385
|
+
async function getIonTilesetMetadata(accessToken, assetId) {
|
|
2386
|
+
if (!assetId) {
|
|
2387
|
+
const assets = await getIonAssets(accessToken);
|
|
2388
|
+
for (const item of assets.items) {
|
|
2389
|
+
if (item.type === "3DTILES") {
|
|
2390
|
+
assetId = item.id;
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
const ionAssetMetadata = await getIonAssetMetadata(accessToken, assetId);
|
|
2395
|
+
const { type, url } = ionAssetMetadata;
|
|
2396
|
+
(0, import_loader_utils9.assert)(type === "3DTILES" && url);
|
|
2397
|
+
ionAssetMetadata.headers = {
|
|
2398
|
+
Authorization: `Bearer ${ionAssetMetadata.accessToken}`
|
|
2399
|
+
};
|
|
2400
|
+
return ionAssetMetadata;
|
|
2401
|
+
}
|
|
2402
|
+
async function getIonAssets(accessToken) {
|
|
2403
|
+
(0, import_loader_utils9.assert)(accessToken);
|
|
2404
|
+
const url = CESIUM_ION_URL;
|
|
2405
|
+
const headers = { Authorization: `Bearer ${accessToken}` };
|
|
2406
|
+
const response = await (0, import_core9.fetchFile)(url, { headers });
|
|
2407
|
+
if (!response.ok) {
|
|
2408
|
+
throw new Error(response.statusText);
|
|
2409
|
+
}
|
|
2410
|
+
return await response.json();
|
|
2411
|
+
}
|
|
2412
|
+
async function getIonAssetMetadata(accessToken, assetId) {
|
|
2413
|
+
(0, import_loader_utils9.assert)(accessToken, assetId);
|
|
2414
|
+
const headers = { Authorization: `Bearer ${accessToken}` };
|
|
2415
|
+
const url = `${CESIUM_ION_URL}/${assetId}`;
|
|
2416
|
+
let response = await (0, import_core9.fetchFile)(`${url}`, { headers });
|
|
2417
|
+
if (!response.ok) {
|
|
2418
|
+
throw new Error(response.statusText);
|
|
2419
|
+
}
|
|
2420
|
+
let metadata = await response.json();
|
|
2421
|
+
response = await (0, import_core9.fetchFile)(`${url}/endpoint`, { headers });
|
|
2422
|
+
if (!response.ok) {
|
|
2423
|
+
throw new Error(response.statusText);
|
|
2424
|
+
}
|
|
2425
|
+
const tilesetInfo = await response.json();
|
|
2426
|
+
metadata = {
|
|
2427
|
+
...metadata,
|
|
2428
|
+
...tilesetInfo
|
|
2429
|
+
};
|
|
2430
|
+
return metadata;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
// src/cesium-ion-loader.ts
|
|
2434
|
+
async function preload(url, options = {}) {
|
|
2435
|
+
options = options["cesium-ion"] || {};
|
|
2436
|
+
const { accessToken } = options;
|
|
2437
|
+
let assetId = options.assetId;
|
|
2438
|
+
if (!Number.isFinite(assetId)) {
|
|
2439
|
+
const matched = url.match(/\/([0-9]+)\/tileset.json/);
|
|
2440
|
+
assetId = matched && matched[1];
|
|
2441
|
+
}
|
|
2442
|
+
return getIonTilesetMetadata(accessToken, assetId);
|
|
2443
|
+
}
|
|
2444
|
+
var CesiumIonLoader = {
|
|
2445
|
+
...Tiles3DLoader,
|
|
2446
|
+
id: "cesium-ion",
|
|
2447
|
+
name: "Cesium Ion",
|
|
2448
|
+
// @ts-ignore
|
|
2449
|
+
preload,
|
|
2450
|
+
parse: async (data, options, context) => {
|
|
2451
|
+
options = { ...options };
|
|
2452
|
+
options["3d-tiles"] = options["cesium-ion"];
|
|
2453
|
+
options.loader = CesiumIonLoader;
|
|
2454
|
+
return Tiles3DLoader.parse(data, options, context);
|
|
2455
|
+
},
|
|
2456
|
+
options: {
|
|
2457
|
+
"cesium-ion": {
|
|
2458
|
+
...Tiles3DLoader.options["3d-tiles"],
|
|
2459
|
+
accessToken: null
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
|
|
2464
|
+
// src/3d-tiles-archive-loader.ts
|
|
2465
|
+
var import_loader_utils10 = require("@loaders.gl/loader-utils");
|
|
2466
|
+
|
|
2467
|
+
// src/3d-tiles-archive/3d-tiles-archive-parser.ts
|
|
2468
|
+
var import_zip2 = require("@loaders.gl/zip");
|
|
2469
|
+
|
|
2470
|
+
// src/3d-tiles-archive/3d-tiles-archive-archive.ts
|
|
2471
|
+
var import_crypto = require("@loaders.gl/crypto");
|
|
2472
|
+
var import_compression = require("@loaders.gl/compression");
|
|
2473
|
+
var import_zip = require("@loaders.gl/zip");
|
|
2474
|
+
var COMPRESSION_METHODS = {
|
|
2475
|
+
/** No compression */
|
|
2476
|
+
0: (data) => new import_compression.NoCompression().decompress(data),
|
|
2477
|
+
/** Deflation */
|
|
2478
|
+
8: (data) => new import_compression.DeflateCompression({ raw: true }).decompress(data)
|
|
2479
|
+
};
|
|
2480
|
+
var Tiles3DArchive = class {
|
|
2481
|
+
/**
|
|
2482
|
+
* creates Tiles3DArchive handler
|
|
2483
|
+
* @param fileProvider - FileProvider with the whole file
|
|
2484
|
+
* @param hashTable - hash info
|
|
2485
|
+
*/
|
|
2486
|
+
constructor(fileProvider, hashTable) {
|
|
2487
|
+
this.fileProvider = fileProvider;
|
|
2488
|
+
this.hashTable = hashTable;
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* Returns file with the given path from 3tz archive
|
|
2492
|
+
* @param path - path inside the 3tz
|
|
2493
|
+
* @returns buffer with ready to use file
|
|
2494
|
+
*/
|
|
2495
|
+
async getFile(path3) {
|
|
2496
|
+
let data = await this.getFileBytes(path3.toLocaleLowerCase());
|
|
2497
|
+
if (!data) {
|
|
2498
|
+
data = await this.getFileBytes(path3);
|
|
2499
|
+
}
|
|
2500
|
+
if (!data) {
|
|
2501
|
+
throw new Error(`No such file in the archive: ${path3}`);
|
|
2502
|
+
}
|
|
2503
|
+
return data;
|
|
2504
|
+
}
|
|
2505
|
+
/**
|
|
2506
|
+
* Trying to get raw file data by adress
|
|
2507
|
+
* @param path - path inside the archive
|
|
2508
|
+
* @returns buffer with the raw file data
|
|
2509
|
+
*/
|
|
2510
|
+
async getFileBytes(path3) {
|
|
2511
|
+
const arrayBuffer = new TextEncoder().encode(path3).buffer;
|
|
2512
|
+
const nameHash = await new import_crypto.MD5Hash().hash(arrayBuffer, "hex");
|
|
2513
|
+
const byteOffset = this.hashTable[nameHash];
|
|
2514
|
+
if (byteOffset === void 0) {
|
|
2515
|
+
return null;
|
|
2516
|
+
}
|
|
2517
|
+
const localFileHeader = await (0, import_zip.parseZipLocalFileHeader)(byteOffset, this.fileProvider);
|
|
2518
|
+
if (!localFileHeader) {
|
|
2519
|
+
return null;
|
|
2520
|
+
}
|
|
2521
|
+
const compressedFile = await this.fileProvider.slice(
|
|
2522
|
+
localFileHeader.fileDataOffset,
|
|
2523
|
+
localFileHeader.fileDataOffset + localFileHeader.compressedSize
|
|
2524
|
+
);
|
|
2525
|
+
const compressionMethod = COMPRESSION_METHODS[localFileHeader.compressionMethod];
|
|
2526
|
+
if (!compressionMethod) {
|
|
2527
|
+
throw Error("Only Deflation compression is supported");
|
|
2528
|
+
}
|
|
2529
|
+
return compressionMethod(compressedFile);
|
|
2530
|
+
}
|
|
2531
|
+
};
|
|
2532
|
+
|
|
2533
|
+
// src/3d-tiles-archive/3d-tiles-archive-parser.ts
|
|
2534
|
+
var parse3DTilesArchive = async (fileProvider, cb) => {
|
|
2535
|
+
const hashCDOffset = await (0, import_zip2.searchFromTheEnd)(fileProvider, import_zip2.cdSignature);
|
|
2536
|
+
const cdFileHeader = await (0, import_zip2.parseZipCDFileHeader)(hashCDOffset, fileProvider);
|
|
2537
|
+
let hashTable;
|
|
2538
|
+
if ((cdFileHeader == null ? void 0 : cdFileHeader.fileName) !== "@3dtilesIndex1@") {
|
|
2539
|
+
hashTable = await (0, import_zip2.makeHashTableFromZipHeaders)(fileProvider);
|
|
2540
|
+
cb == null ? void 0 : cb(
|
|
2541
|
+
"3tz doesnt contain hash file, hash info has been composed according to zip archive headers"
|
|
2542
|
+
);
|
|
2543
|
+
} else {
|
|
2544
|
+
const localFileHeader = await (0, import_zip2.parseZipLocalFileHeader)(
|
|
2545
|
+
cdFileHeader.localHeaderOffset,
|
|
2546
|
+
fileProvider
|
|
2547
|
+
);
|
|
2548
|
+
if (!localFileHeader) {
|
|
2549
|
+
throw new Error("corrupted 3tz zip archive");
|
|
2550
|
+
}
|
|
2551
|
+
const fileDataOffset = localFileHeader.fileDataOffset;
|
|
2552
|
+
const hashFile = await fileProvider.slice(
|
|
2553
|
+
fileDataOffset,
|
|
2554
|
+
fileDataOffset + localFileHeader.compressedSize
|
|
2555
|
+
);
|
|
2556
|
+
hashTable = (0, import_zip2.parseHashTable)(hashFile);
|
|
2557
|
+
}
|
|
2558
|
+
return new Tiles3DArchive(fileProvider, hashTable);
|
|
2559
|
+
};
|
|
2560
|
+
|
|
2561
|
+
// src/3d-tiles-archive-loader.ts
|
|
2562
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2563
|
+
var Tiles3DArchiveFileLoader = {
|
|
2564
|
+
name: "3tz",
|
|
2565
|
+
id: "3tz",
|
|
2566
|
+
module: "3d-tiles",
|
|
2567
|
+
version: VERSION2,
|
|
2568
|
+
mimeTypes: ["application/octet-stream", "application/vnd.maxar.archive.3tz+zip"],
|
|
2569
|
+
parse: parse3DTilesArchive2,
|
|
2570
|
+
extensions: ["3tz"],
|
|
2571
|
+
options: {}
|
|
2572
|
+
};
|
|
2573
|
+
async function parse3DTilesArchive2(data, options = {}) {
|
|
2574
|
+
var _a;
|
|
2575
|
+
const archive = await parse3DTilesArchive(new import_loader_utils10.DataViewFile(new DataView(data)));
|
|
2576
|
+
return archive.getFile(((_a = options["3d-tiles-archive"]) == null ? void 0 : _a.path) ?? "");
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
// src/lib/filesystems/tiles-3d-archive-file-system.ts
|
|
2580
|
+
var import_zip3 = require("@loaders.gl/zip");
|
|
2581
|
+
var Tiles3DArchiveFileSystem = class extends import_zip3.ZipFileSystem {
|
|
2582
|
+
/**
|
|
2583
|
+
* Constructor
|
|
2584
|
+
* @param file - instance of FileProvider or file path string
|
|
2585
|
+
*/
|
|
2586
|
+
constructor(file) {
|
|
2587
|
+
super(file);
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Implementation of fetch against this file system.
|
|
2591
|
+
* It tries to take `@3dtilesIndex1@` file from the archive and use it
|
|
2592
|
+
* for faster access to archived files
|
|
2593
|
+
* @param filename - name of a file
|
|
2594
|
+
* @returns - Response with file data
|
|
2595
|
+
*/
|
|
2596
|
+
async fetch(filename) {
|
|
2597
|
+
const fileProvider = this.fileProvider;
|
|
2598
|
+
if (!fileProvider) {
|
|
2599
|
+
throw new Error("No data detected in the zip archive");
|
|
2600
|
+
}
|
|
2601
|
+
await this.parseHashTable();
|
|
2602
|
+
if (this.hashTable) {
|
|
2603
|
+
const archive = new Tiles3DArchive(fileProvider, this.hashTable);
|
|
2604
|
+
const fileData = await archive.getFile(filename);
|
|
2605
|
+
const response = new Response(fileData);
|
|
2606
|
+
Object.defineProperty(response, "url", { value: `${this.fileName || ""}/${filename}` });
|
|
2607
|
+
return response;
|
|
2608
|
+
}
|
|
2609
|
+
return super.fetch(filename);
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
* Try to get and parse '@3dtilesIndex1@' file, that allows to get direct access
|
|
2613
|
+
* to files inside the archive
|
|
2614
|
+
* @returns void
|
|
2615
|
+
*/
|
|
2616
|
+
async parseHashTable() {
|
|
2617
|
+
if (this.hashTable !== void 0) {
|
|
2618
|
+
return;
|
|
2619
|
+
}
|
|
2620
|
+
const fileProvider = this.fileProvider;
|
|
2621
|
+
if (!fileProvider) {
|
|
2622
|
+
throw new Error("No data detected in the zip archive");
|
|
2623
|
+
}
|
|
2624
|
+
const hashCDOffset = await (0, import_zip3.searchFromTheEnd)(fileProvider, import_zip3.cdSignature);
|
|
2625
|
+
const cdFileHeader = await (0, import_zip3.parseZipCDFileHeader)(hashCDOffset, fileProvider);
|
|
2626
|
+
if ((cdFileHeader == null ? void 0 : cdFileHeader.fileName) === "@3dtilesIndex1@") {
|
|
2627
|
+
const localFileHeader = await (0, import_zip3.parseZipLocalFileHeader)(
|
|
2628
|
+
cdFileHeader.localHeaderOffset,
|
|
2629
|
+
fileProvider
|
|
2630
|
+
);
|
|
2631
|
+
if (!localFileHeader) {
|
|
2632
|
+
throw new Error("corrupted 3tz");
|
|
2633
|
+
}
|
|
2634
|
+
const fileDataOffset = localFileHeader.fileDataOffset;
|
|
2635
|
+
const hashFile = await fileProvider.slice(
|
|
2636
|
+
fileDataOffset,
|
|
2637
|
+
fileDataOffset + localFileHeader.compressedSize
|
|
2638
|
+
);
|
|
2639
|
+
this.hashTable = (0, import_zip3.parseHashTable)(hashFile);
|
|
2640
|
+
} else {
|
|
2641
|
+
this.hashTable = null;
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
};
|
|
2645
|
+
|
|
2646
|
+
// src/lib/encoders/encode-3d-tile.ts
|
|
2647
|
+
var import_loader_utils15 = require("@loaders.gl/loader-utils");
|
|
2648
|
+
|
|
2649
|
+
// src/lib/encoders/helpers/encode-3d-tile-header.ts
|
|
2650
|
+
var import_loader_utils11 = require("@loaders.gl/loader-utils");
|
|
2651
|
+
function encode3DTileHeader(tile, dataView, byteOffset) {
|
|
2652
|
+
const HEADER_SIZE = 12;
|
|
2653
|
+
if (!dataView) {
|
|
2654
|
+
return byteOffset + HEADER_SIZE;
|
|
2655
|
+
}
|
|
2656
|
+
const { magic, version = 1, byteLength = 12 } = tile;
|
|
2657
|
+
(0, import_loader_utils11.assert)(Array.isArray(magic) && Number.isFinite(version) && Number.isFinite(byteLength));
|
|
2658
|
+
dataView.setUint8(byteOffset + 0, magic[0]);
|
|
2659
|
+
dataView.setUint8(byteOffset + 1, magic[1]);
|
|
2660
|
+
dataView.setUint8(byteOffset + 2, magic[2]);
|
|
2661
|
+
dataView.setUint8(byteOffset + 3, magic[3]);
|
|
2662
|
+
dataView.setUint32(byteOffset + 4, version, true);
|
|
2663
|
+
dataView.setUint32(byteOffset + 8, byteLength, true);
|
|
2664
|
+
byteOffset += HEADER_SIZE;
|
|
2665
|
+
return byteOffset;
|
|
2666
|
+
}
|
|
2667
|
+
function encode3DTileByteLength(dataView, byteOffsetTileStart, byteLength) {
|
|
2668
|
+
if (!dataView) {
|
|
2669
|
+
return;
|
|
2670
|
+
}
|
|
2671
|
+
dataView.setUint32(byteOffsetTileStart + 8, byteLength, true);
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2674
|
+
// src/lib/encoders/encode-3d-tile-composite.ts
|
|
2675
|
+
function encodeComposite3DTile(tile, dataView, byteOffset, options, encode3DTile2) {
|
|
2676
|
+
tile = { magic: MAGIC_ARRAY.COMPOSITE, tiles: [], ...tile };
|
|
2677
|
+
const byteOffsetStart = byteOffset;
|
|
2678
|
+
byteOffset += encode3DTileHeader(tile, dataView, byteOffset);
|
|
2679
|
+
if (dataView) {
|
|
2680
|
+
dataView.setUint32(byteOffset, tile.tiles.length, true);
|
|
2681
|
+
}
|
|
2682
|
+
byteOffset += 4;
|
|
2683
|
+
for (let i = 0; i < tile.tiles.length; ++i) {
|
|
2684
|
+
byteOffset += encode3DTile2(tile.tiles[i], dataView, byteOffset, options);
|
|
2685
|
+
}
|
|
2686
|
+
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
2687
|
+
return byteOffset;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
// src/lib/encoders/encode-3d-tile-batched-model.ts
|
|
2691
|
+
var import_loader_utils12 = require("@loaders.gl/loader-utils");
|
|
2692
|
+
function encodeBatchedModel3DTile(tile, dataView, byteOffset, options) {
|
|
2693
|
+
const { featuresLength = 0, batchTable } = tile;
|
|
2694
|
+
const featureTableJson = {
|
|
2695
|
+
BATCH_LENGTH: featuresLength
|
|
2696
|
+
};
|
|
2697
|
+
const featureTableJsonString = JSON.stringify(featureTableJson);
|
|
2698
|
+
const batchTableJsonString = batchTable ? JSON.stringify(batchTable) : "";
|
|
2699
|
+
const featureTableJsonByteLength = (0, import_loader_utils12.padToNBytes)(featureTableJsonString.length, 8);
|
|
2700
|
+
const batchTableJsonByteLength = batchTableJsonString ? (0, import_loader_utils12.padToNBytes)(batchTableJsonString.length, 8) : 0;
|
|
2701
|
+
tile = { magic: MAGIC_ARRAY.BATCHED_MODEL, ...tile };
|
|
2702
|
+
const byteOffsetStart = byteOffset;
|
|
2703
|
+
byteOffset = encode3DTileHeader(tile, dataView, byteOffset);
|
|
2704
|
+
if (dataView) {
|
|
2705
|
+
dataView.setUint32(12, featureTableJsonByteLength, true);
|
|
2706
|
+
dataView.setUint32(16, 0, true);
|
|
2707
|
+
dataView.setUint32(20, batchTableJsonByteLength, true);
|
|
2708
|
+
dataView.setUint32(24, 0, true);
|
|
2709
|
+
}
|
|
2710
|
+
byteOffset += 16;
|
|
2711
|
+
byteOffset = (0, import_loader_utils12.copyPaddedStringToDataView)(dataView, byteOffset, featureTableJsonString, 8);
|
|
2712
|
+
if (batchTable) {
|
|
2713
|
+
byteOffset = (0, import_loader_utils12.copyPaddedStringToDataView)(dataView, byteOffset, batchTableJsonString, 8);
|
|
2714
|
+
}
|
|
2715
|
+
const gltfEncoded = tile.gltfEncoded;
|
|
2716
|
+
if (gltfEncoded) {
|
|
2717
|
+
byteOffset = (0, import_loader_utils12.copyBinaryToDataView)(dataView, byteOffset, gltfEncoded, gltfEncoded.byteLength);
|
|
2718
|
+
}
|
|
2719
|
+
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
2720
|
+
return byteOffset;
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
// src/lib/encoders/encode-3d-tile-instanced-model.ts
|
|
2724
|
+
var import_loader_utils13 = require("@loaders.gl/loader-utils");
|
|
2725
|
+
function encodeInstancedModel3DTile(tile, dataView, byteOffset, options) {
|
|
2726
|
+
const { featuresLength = 1, gltfFormat = 1, gltfUri = "" } = tile;
|
|
2727
|
+
const gltfUriByteLength = gltfUri.length;
|
|
2728
|
+
const featureTableJson = {
|
|
2729
|
+
INSTANCES_LENGTH: featuresLength,
|
|
2730
|
+
POSITION: new Array(featuresLength * 3).fill(0)
|
|
2731
|
+
};
|
|
2732
|
+
const featureTableJsonString = JSON.stringify(featureTableJson);
|
|
2733
|
+
const featureTableJsonByteLength = featureTableJsonString.length;
|
|
2734
|
+
tile = { magic: MAGIC_ARRAY.INSTANCED_MODEL, ...tile };
|
|
2735
|
+
const byteOffsetStart = byteOffset;
|
|
2736
|
+
byteOffset = encode3DTileHeader(tile, dataView, 0);
|
|
2737
|
+
if (dataView) {
|
|
2738
|
+
dataView.setUint32(12, featureTableJsonByteLength, true);
|
|
2739
|
+
dataView.setUint32(16, 0, true);
|
|
2740
|
+
dataView.setUint32(20, 0, true);
|
|
2741
|
+
dataView.setUint32(24, 0, true);
|
|
2742
|
+
dataView.setUint32(28, gltfFormat, true);
|
|
2743
|
+
}
|
|
2744
|
+
byteOffset += 20;
|
|
2745
|
+
byteOffset += (0, import_loader_utils13.copyStringToDataView)(
|
|
2746
|
+
dataView,
|
|
2747
|
+
byteOffset,
|
|
2748
|
+
featureTableJsonString,
|
|
2749
|
+
featureTableJsonByteLength
|
|
2750
|
+
);
|
|
2751
|
+
byteOffset += (0, import_loader_utils13.copyStringToDataView)(dataView, byteOffset, gltfUri, gltfUriByteLength);
|
|
2752
|
+
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
2753
|
+
return byteOffset;
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
// src/lib/encoders/encode-3d-tile-point-cloud.ts
|
|
2757
|
+
var import_loader_utils14 = require("@loaders.gl/loader-utils");
|
|
2758
|
+
var DEFAULT_FEATURE_TABLE_JSON = {
|
|
2759
|
+
POINTS_LENGTH: 1,
|
|
2760
|
+
POSITIONS: {
|
|
2761
|
+
byteOffset: 0
|
|
2762
|
+
}
|
|
2763
|
+
};
|
|
2764
|
+
function encodePointCloud3DTile(tile, dataView, byteOffset, options) {
|
|
2765
|
+
const { featureTableJson = DEFAULT_FEATURE_TABLE_JSON } = tile;
|
|
2766
|
+
let featureTableJsonString = JSON.stringify(featureTableJson);
|
|
2767
|
+
featureTableJsonString = (0, import_loader_utils14.padStringToByteAlignment)(featureTableJsonString, 4);
|
|
2768
|
+
const { featureTableJsonByteLength = featureTableJsonString.length } = tile;
|
|
2769
|
+
const featureTableBinary = new ArrayBuffer(12);
|
|
2770
|
+
const featureTableBinaryByteLength = featureTableBinary.byteLength;
|
|
2771
|
+
tile = { magic: MAGIC_ARRAY.POINT_CLOUD, ...tile };
|
|
2772
|
+
const byteOffsetStart = byteOffset;
|
|
2773
|
+
byteOffset += encode3DTileHeader(tile, dataView, 0);
|
|
2774
|
+
if (dataView) {
|
|
2775
|
+
dataView.setUint32(byteOffset + 0, featureTableJsonByteLength, true);
|
|
2776
|
+
dataView.setUint32(byteOffset + 4, featureTableBinaryByteLength, true);
|
|
2777
|
+
dataView.setUint32(byteOffset + 8, 0, true);
|
|
2778
|
+
dataView.setUint32(byteOffset + 12, 0, true);
|
|
2779
|
+
}
|
|
2780
|
+
byteOffset += 16;
|
|
2781
|
+
byteOffset += (0, import_loader_utils14.copyStringToDataView)(
|
|
2782
|
+
dataView,
|
|
2783
|
+
byteOffset,
|
|
2784
|
+
featureTableJsonString,
|
|
2785
|
+
featureTableJsonByteLength
|
|
2786
|
+
);
|
|
2787
|
+
byteOffset += (0, import_loader_utils14.copyBinaryToDataView)(
|
|
2788
|
+
dataView,
|
|
2789
|
+
byteOffset,
|
|
2790
|
+
featureTableBinary,
|
|
2791
|
+
featureTableBinaryByteLength
|
|
2792
|
+
);
|
|
2793
|
+
encode3DTileByteLength(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
|
|
2794
|
+
return byteOffset;
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
// src/lib/encoders/encode-3d-tile.ts
|
|
2798
|
+
function encode3DTile(tile, options) {
|
|
2799
|
+
const byteLength = encode3DTileToDataView(tile, null, 0, options);
|
|
2800
|
+
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
2801
|
+
const dataView = new DataView(arrayBuffer);
|
|
2802
|
+
encode3DTileToDataView(tile, dataView, 0, options);
|
|
2803
|
+
return arrayBuffer;
|
|
2804
|
+
}
|
|
2805
|
+
function encode3DTileToDataView(tile, dataView, byteOffset, options) {
|
|
2806
|
+
(0, import_loader_utils15.assert)(typeof tile.type === "string");
|
|
2807
|
+
switch (tile.type) {
|
|
2808
|
+
case TILE3D_TYPE.COMPOSITE:
|
|
2809
|
+
return encodeComposite3DTile(tile, dataView, byteOffset, options, encode3DTileToDataView);
|
|
2810
|
+
case TILE3D_TYPE.POINT_CLOUD:
|
|
2811
|
+
return encodePointCloud3DTile(tile, dataView, byteOffset, options);
|
|
2812
|
+
case TILE3D_TYPE.BATCHED_3D_MODEL:
|
|
2813
|
+
return encodeBatchedModel3DTile(tile, dataView, byteOffset, options);
|
|
2814
|
+
case TILE3D_TYPE.INSTANCED_3D_MODEL:
|
|
2815
|
+
return encodeInstancedModel3DTile(tile, dataView, byteOffset, options);
|
|
2816
|
+
default:
|
|
2817
|
+
throw new Error("3D Tiles: unknown tile type");
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
// src/tile-3d-writer.ts
|
|
2822
|
+
var Tile3DWriter = {
|
|
2823
|
+
name: "3D Tile",
|
|
2824
|
+
id: "3d-tiles",
|
|
2825
|
+
module: "3d-tiles",
|
|
2826
|
+
version: VERSION,
|
|
2827
|
+
extensions: ["cmpt", "pnts", "b3dm", "i3dm"],
|
|
2828
|
+
mimeTypes: ["application/octet-stream"],
|
|
2829
|
+
encodeSync,
|
|
2830
|
+
binary: true,
|
|
2831
|
+
options: {
|
|
2832
|
+
["3d-tiles"]: {}
|
|
2833
|
+
}
|
|
2834
|
+
};
|
|
2835
|
+
function encodeSync(tile, options) {
|
|
2836
|
+
return encode3DTile(tile, options);
|
|
2837
|
+
}
|