@loaders.gl/tiles 4.5.3 → 5.0.0-alpha.10
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/LICENSE +14 -3
- package/README.md +136 -1
- package/dist/dist.dev.js +22570 -4947
- package/dist/dist.min.js +3 -1
- package/dist/image-set.d.ts +94 -0
- package/dist/image-set.d.ts.map +1 -0
- package/dist/image-set.js +243 -0
- package/dist/image-set.js.map +1 -0
- package/dist/index.cjs +10171 -2117
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +50 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/dist/point-cloud/point-cloud-tile.d.ts +47 -0
- package/dist/point-cloud/point-cloud-tile.d.ts.map +1 -0
- package/dist/point-cloud/point-cloud-tile.js +70 -0
- package/dist/point-cloud/point-cloud-tile.js.map +1 -0
- package/dist/point-cloud/point-cloud-tileset.d.ts +135 -0
- package/dist/point-cloud/point-cloud-tileset.d.ts.map +1 -0
- package/dist/point-cloud/point-cloud-tileset.js +549 -0
- package/dist/point-cloud/point-cloud-tileset.js.map +1 -0
- package/dist/point-cloud/types.d.ts +81 -0
- package/dist/point-cloud/types.d.ts.map +1 -0
- package/dist/point-cloud/types.js +5 -0
- package/dist/point-cloud/types.js.map +1 -0
- package/dist/raster-set.d.ts +124 -0
- package/dist/raster-set.d.ts.map +1 -0
- package/dist/raster-set.js +348 -0
- package/dist/raster-set.js.map +1 -0
- package/dist/spatial/format-spatial-reference.d.ts +68 -0
- package/dist/spatial/format-spatial-reference.d.ts.map +1 -0
- package/dist/spatial/format-spatial-reference.js +291 -0
- package/dist/spatial/format-spatial-reference.js.map +1 -0
- package/dist/spatial/get-spatial-coordinate-frame.d.ts +20 -0
- package/dist/spatial/get-spatial-coordinate-frame.d.ts.map +1 -0
- package/dist/spatial/get-spatial-coordinate-frame.js +139 -0
- package/dist/spatial/get-spatial-coordinate-frame.js.map +1 -0
- package/dist/spatial/i3s-elevation.d.ts +20 -0
- package/dist/spatial/i3s-elevation.d.ts.map +1 -0
- package/dist/spatial/i3s-elevation.js +90 -0
- package/dist/spatial/i3s-elevation.js.map +1 -0
- package/dist/spatial/i3s-spatial-transformer.d.ts +189 -0
- package/dist/spatial/i3s-spatial-transformer.d.ts.map +1 -0
- package/dist/spatial/i3s-spatial-transformer.js +686 -0
- package/dist/spatial/i3s-spatial-transformer.js.map +1 -0
- package/dist/spatial/normalize-crs-identifier.d.ts +15 -0
- package/dist/spatial/normalize-crs-identifier.d.ts.map +1 -0
- package/dist/spatial/normalize-crs-identifier.js +22 -0
- package/dist/spatial/normalize-crs-identifier.js.map +1 -0
- package/dist/spatial/spatial-coordinate-transformer.d.ts +52 -0
- package/dist/spatial/spatial-coordinate-transformer.d.ts.map +1 -0
- package/dist/spatial/spatial-coordinate-transformer.js +295 -0
- package/dist/spatial/spatial-coordinate-transformer.js.map +1 -0
- package/dist/spatial/spatial-resource-registry.d.ts +44 -0
- package/dist/spatial/spatial-resource-registry.d.ts.map +1 -0
- package/dist/spatial/spatial-resource-registry.js +67 -0
- package/dist/spatial/spatial-resource-registry.js.map +1 -0
- package/dist/spatial/spatial-types.d.ts +190 -0
- package/dist/spatial/spatial-types.d.ts.map +1 -0
- package/dist/spatial/spatial-types.js +192 -0
- package/dist/spatial/spatial-types.js.map +1 -0
- package/dist/spatial/tiles-3d-spatial-transformer.d.ts +32 -0
- package/dist/spatial/tiles-3d-spatial-transformer.d.ts.map +1 -0
- package/dist/spatial/tiles-3d-spatial-transformer.js +175 -0
- package/dist/spatial/tiles-3d-spatial-transformer.js.map +1 -0
- package/dist/tileset-2d/adapter.d.ts +37 -0
- package/dist/tileset-2d/adapter.d.ts.map +1 -0
- package/dist/tileset-2d/adapter.js +5 -0
- package/dist/tileset-2d/adapter.js.map +1 -0
- package/dist/tileset-2d/index.d.ts +7 -0
- package/dist/tileset-2d/index.d.ts.map +1 -0
- package/dist/tileset-2d/index.js +6 -0
- package/dist/tileset-2d/index.js.map +1 -0
- package/dist/tileset-2d/tile-2d-header.d.ts +68 -0
- package/dist/tileset-2d/tile-2d-header.d.ts.map +1 -0
- package/dist/tileset-2d/tile-2d-header.js +181 -0
- package/dist/tileset-2d/tile-2d-header.js.map +1 -0
- package/dist/tileset-2d/tileset-2d.d.ts +200 -0
- package/dist/tileset-2d/tileset-2d.d.ts.map +1 -0
- package/dist/tileset-2d/tileset-2d.js +532 -0
- package/dist/tileset-2d/tileset-2d.js.map +1 -0
- package/dist/tileset-2d/types.d.ts +44 -0
- package/dist/tileset-2d/types.d.ts.map +1 -0
- package/dist/tileset-2d/types.js +5 -0
- package/dist/tileset-2d/types.js.map +1 -0
- package/dist/tileset-2d.d.ts +2 -0
- package/dist/tileset-2d.d.ts.map +1 -0
- package/dist/tileset-2d.js +5 -0
- package/dist/tileset-2d.js.map +1 -0
- package/dist/tileset-3d/common/indexed-archive-tileset-source.d.ts +60 -0
- package/dist/tileset-3d/common/indexed-archive-tileset-source.d.ts.map +1 -0
- package/dist/tileset-3d/common/indexed-archive-tileset-source.js +130 -0
- package/dist/tileset-3d/common/indexed-archive-tileset-source.js.map +1 -0
- package/dist/tileset-3d/common/tile-3d-contracts.d.ts +63 -0
- package/dist/tileset-3d/common/tile-3d-contracts.d.ts.map +1 -0
- package/dist/tileset-3d/common/tile-3d-contracts.js +51 -0
- package/dist/tileset-3d/common/tile-3d-contracts.js.map +1 -0
- package/dist/tileset-3d/common/tile-3d.d.ts +410 -0
- package/dist/tileset-3d/common/tile-3d.d.ts.map +1 -0
- package/dist/tileset-3d/common/tile-3d.js +1056 -0
- package/dist/tileset-3d/common/tile-3d.js.map +1 -0
- package/dist/tileset-3d/common/tileset-3d.d.ts +360 -0
- package/dist/tileset-3d/common/tileset-3d.d.ts.map +1 -0
- package/dist/tileset-3d/common/tileset-3d.js +846 -0
- package/dist/tileset-3d/common/tileset-3d.js.map +1 -0
- package/dist/tileset-3d/common/tileset-cache.d.ts +29 -0
- package/dist/tileset-3d/common/tileset-cache.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d/common}/tileset-cache.js +12 -4
- package/dist/tileset-3d/common/tileset-cache.js.map +1 -0
- package/dist/tileset-3d/common/tileset-content-traversal.d.ts +37 -0
- package/dist/tileset-3d/common/tileset-content-traversal.d.ts.map +1 -0
- package/dist/tileset-3d/common/tileset-content-traversal.js +80 -0
- package/dist/tileset-3d/common/tileset-content-traversal.js.map +1 -0
- package/dist/tileset-3d/common/tileset-observability.d.ts +60 -0
- package/dist/tileset-3d/common/tileset-observability.d.ts.map +1 -0
- package/dist/tileset-3d/common/tileset-observability.js +39 -0
- package/dist/tileset-3d/common/tileset-observability.js.map +1 -0
- package/dist/tileset-3d/common/tileset-source.d.ts +228 -0
- package/dist/tileset-3d/common/tileset-source.d.ts.map +1 -0
- package/dist/tileset-3d/common/tileset-source.js +17 -0
- package/dist/tileset-3d/common/tileset-source.js.map +1 -0
- package/dist/{tileset → tileset-3d/common}/tileset-traverser.d.ts +35 -3
- package/dist/tileset-3d/common/tileset-traverser.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d/common}/tileset-traverser.js +61 -13
- package/dist/tileset-3d/common/tileset-traverser.js.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts +182 -0
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.js +681 -0
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.js.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.d.ts +221 -0
- package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.d.ts.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.js +770 -0
- package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.js.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.d.ts +110 -0
- package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.d.ts.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.js +331 -0
- package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.js.map +1 -0
- package/dist/tileset-3d/format-i3s/i3s-pending-tiles-register.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/format-i3s/i3s-pending-tiles-register.js +3 -0
- package/dist/tileset-3d/format-i3s/i3s-pending-tiles-register.js.map +1 -0
- package/dist/tileset-3d/format-i3s/i3s-source.d.ts +116 -0
- package/dist/tileset-3d/format-i3s/i3s-source.d.ts.map +1 -0
- package/dist/tileset-3d/format-i3s/i3s-source.js +450 -0
- package/dist/tileset-3d/format-i3s/i3s-source.js.map +1 -0
- package/dist/tileset-3d/format-i3s/i3s-tile-manager.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/format-i3s/i3s-tile-manager.js +5 -2
- package/dist/tileset-3d/format-i3s/i3s-tile-manager.js.map +1 -0
- package/dist/{tileset → tileset-3d}/format-i3s/i3s-tileset-traverser.d.ts +2 -2
- package/dist/tileset-3d/format-i3s/i3s-tileset-traverser.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/format-i3s/i3s-tileset-traverser.js +17 -23
- package/dist/tileset-3d/format-i3s/i3s-tileset-traverser.js.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/3d-tiles-options.d.ts +1 -1
- package/dist/tileset-3d/helpers/3d-tiles-options.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/3d-tiles-options.js +3 -0
- package/dist/tileset-3d/helpers/3d-tiles-options.js.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/bounding-volume.d.ts +7 -3
- package/dist/tileset-3d/helpers/bounding-volume.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/bounding-volume.js +20 -91
- package/dist/tileset-3d/helpers/bounding-volume.js.map +1 -0
- package/dist/tileset-3d/helpers/frame-state.d.ts +93 -0
- package/dist/tileset-3d/helpers/frame-state.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/frame-state.js +92 -10
- package/dist/tileset-3d/helpers/frame-state.js.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/i3s-lod.d.ts +1 -1
- package/dist/tileset-3d/helpers/i3s-lod.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/i3s-lod.js +21 -9
- package/dist/tileset-3d/helpers/i3s-lod.js.map +1 -0
- package/dist/tileset-3d/helpers/s2-bounding-volume.d.ts +17 -0
- package/dist/tileset-3d/helpers/s2-bounding-volume.d.ts.map +1 -0
- package/dist/tileset-3d/helpers/s2-bounding-volume.js +20 -0
- package/dist/tileset-3d/helpers/s2-bounding-volume.js.map +1 -0
- package/dist/tileset-3d/helpers/tiles-3d-lod.d.ts +72 -0
- package/dist/tileset-3d/helpers/tiles-3d-lod.d.ts.map +1 -0
- package/dist/tileset-3d/helpers/tiles-3d-lod.js +257 -0
- package/dist/tileset-3d/helpers/tiles-3d-lod.js.map +1 -0
- package/dist/tileset-3d/helpers/tiles-3d-request-priority.d.ts +134 -0
- package/dist/tileset-3d/helpers/tiles-3d-request-priority.d.ts.map +1 -0
- package/dist/tileset-3d/helpers/tiles-3d-request-priority.js +179 -0
- package/dist/tileset-3d/helpers/tiles-3d-request-priority.js.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/transform-utils.d.ts +1 -1
- package/dist/tileset-3d/helpers/transform-utils.d.ts.map +1 -0
- package/dist/tileset-3d/helpers/transform-utils.js.map +1 -0
- package/dist/tileset-3d/helpers/zoom.d.ts.map +1 -0
- package/dist/tileset-3d/helpers/zoom.js.map +1 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/doubly-linked-list.d.ts.map +1 -1
- package/dist/utils/doubly-linked-list.js +1 -0
- package/dist/utils/doubly-linked-list.js.map +1 -1
- package/dist/utils/managed-array.d.ts.map +1 -1
- package/dist/utils/managed-array.js +1 -0
- package/dist/utils/managed-array.js.map +1 -1
- package/package.json +12 -9
- package/src/image-set.ts +328 -0
- package/src/index.ts +157 -9
- package/src/point-cloud/point-cloud-tile.ts +80 -0
- package/src/point-cloud/point-cloud-tileset.ts +767 -0
- package/src/point-cloud/types.ts +99 -0
- package/src/raster-set.ts +504 -0
- package/src/spatial/format-spatial-reference.ts +385 -0
- package/src/spatial/get-spatial-coordinate-frame.ts +169 -0
- package/src/spatial/i3s-elevation.ts +96 -0
- package/src/spatial/i3s-spatial-transformer.ts +957 -0
- package/src/spatial/normalize-crs-identifier.ts +26 -0
- package/src/spatial/spatial-coordinate-transformer.ts +376 -0
- package/src/spatial/spatial-resource-registry.ts +79 -0
- package/src/spatial/spatial-types.ts +422 -0
- package/src/spatial/tiles-3d-spatial-transformer.ts +206 -0
- package/src/tileset-2d/adapter.ts +46 -0
- package/src/tileset-2d/index.ts +33 -0
- package/src/tileset-2d/tile-2d-header.ts +224 -0
- package/src/tileset-2d/tileset-2d.ts +715 -0
- package/src/tileset-2d/types.ts +39 -0
- package/src/tileset-2d.ts +5 -0
- package/src/tileset-3d/common/indexed-archive-tileset-source.ts +205 -0
- package/src/tileset-3d/common/tile-3d-contracts.ts +115 -0
- package/src/tileset-3d/common/tile-3d.ts +1310 -0
- package/src/tileset-3d/common/tileset-3d.ts +1166 -0
- package/src/{tileset → tileset-3d/common}/tileset-cache.ts +16 -8
- package/src/tileset-3d/common/tileset-content-traversal.ts +114 -0
- package/src/tileset-3d/common/tileset-observability.ts +100 -0
- package/src/tileset-3d/common/tileset-source.ts +284 -0
- package/src/{tileset → tileset-3d/common}/tileset-traverser.ts +74 -14
- package/src/tileset-3d/format-3d-tiles/implicit-tiling.ts +1059 -0
- package/src/tileset-3d/format-3d-tiles/tiles-3d-source.ts +1025 -0
- package/src/tileset-3d/format-3d-tiles/tileset-3d-traverser.ts +379 -0
- package/src/{tileset → tileset-3d}/format-i3s/i3s-pending-tiles-register.ts +4 -0
- package/src/tileset-3d/format-i3s/i3s-source.ts +557 -0
- package/src/{tileset → tileset-3d}/format-i3s/i3s-tile-manager.ts +6 -2
- package/src/{tileset → tileset-3d}/format-i3s/i3s-tileset-traverser.ts +20 -24
- package/src/{tileset → tileset-3d}/helpers/3d-tiles-options.ts +5 -1
- package/src/{tileset → tileset-3d}/helpers/bounding-volume.ts +31 -114
- package/src/tileset-3d/helpers/frame-state.ts +322 -0
- package/src/{tileset → tileset-3d}/helpers/i3s-lod.ts +24 -10
- package/src/tileset-3d/helpers/s2-bounding-volume.ts +35 -0
- package/src/tileset-3d/helpers/tiles-3d-lod.ts +370 -0
- package/src/tileset-3d/helpers/tiles-3d-request-priority.ts +301 -0
- package/src/{tileset → tileset-3d}/helpers/transform-utils.ts +1 -1
- package/src/types.ts +18 -0
- package/src/utils/doubly-linked-list.ts +2 -0
- package/src/utils/managed-array.ts +2 -0
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts +0 -7
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts.map +0 -1
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +0 -53
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js.map +0 -1
- package/dist/tileset/format-i3s/i3s-pending-tiles-register.d.ts.map +0 -1
- package/dist/tileset/format-i3s/i3s-pending-tiles-register.js.map +0 -1
- package/dist/tileset/format-i3s/i3s-tile-manager.d.ts.map +0 -1
- package/dist/tileset/format-i3s/i3s-tile-manager.js.map +0 -1
- package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts.map +0 -1
- package/dist/tileset/format-i3s/i3s-tileset-traverser.js.map +0 -1
- package/dist/tileset/helpers/3d-tiles-options.d.ts.map +0 -1
- package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
- package/dist/tileset/helpers/bounding-volume.d.ts.map +0 -1
- package/dist/tileset/helpers/bounding-volume.js.map +0 -1
- package/dist/tileset/helpers/frame-state.d.ts +0 -28
- package/dist/tileset/helpers/frame-state.d.ts.map +0 -1
- package/dist/tileset/helpers/frame-state.js.map +0 -1
- package/dist/tileset/helpers/i3s-lod.d.ts.map +0 -1
- package/dist/tileset/helpers/i3s-lod.js.map +0 -1
- package/dist/tileset/helpers/tiles-3d-lod.d.ts +0 -8
- package/dist/tileset/helpers/tiles-3d-lod.d.ts.map +0 -1
- package/dist/tileset/helpers/tiles-3d-lod.js +0 -113
- package/dist/tileset/helpers/tiles-3d-lod.js.map +0 -1
- package/dist/tileset/helpers/transform-utils.d.ts.map +0 -1
- package/dist/tileset/helpers/transform-utils.js.map +0 -1
- package/dist/tileset/helpers/zoom.d.ts.map +0 -1
- package/dist/tileset/helpers/zoom.js.map +0 -1
- package/dist/tileset/tile-3d.d.ts +0 -230
- package/dist/tileset/tile-3d.d.ts.map +0 -1
- package/dist/tileset/tile-3d.js +0 -631
- package/dist/tileset/tile-3d.js.map +0 -1
- package/dist/tileset/tileset-3d.d.ts +0 -284
- package/dist/tileset/tileset-3d.d.ts.map +0 -1
- package/dist/tileset/tileset-3d.js +0 -814
- package/dist/tileset/tileset-3d.js.map +0 -1
- package/dist/tileset/tileset-cache.d.ts +0 -19
- package/dist/tileset/tileset-cache.d.ts.map +0 -1
- package/dist/tileset/tileset-cache.js.map +0 -1
- package/dist/tileset/tileset-traverser.d.ts.map +0 -1
- package/dist/tileset/tileset-traverser.js.map +0 -1
- package/src/tileset/format-3d-tiles/tileset-3d-traverser.ts +0 -63
- package/src/tileset/helpers/frame-state.ts +0 -183
- package/src/tileset/helpers/tiles-3d-lod.ts +0 -149
- package/src/tileset/tile-3d.ts +0 -788
- package/src/tileset/tileset-3d.ts +0 -1037
- /package/dist/{tileset → tileset-3d}/format-i3s/i3s-pending-tiles-register.d.ts +0 -0
- /package/dist/{tileset → tileset-3d}/format-i3s/i3s-tile-manager.d.ts +0 -0
- /package/dist/{tileset → tileset-3d}/helpers/transform-utils.js +0 -0
- /package/dist/{tileset → tileset-3d}/helpers/zoom.d.ts +0 -0
- /package/dist/{tileset → tileset-3d}/helpers/zoom.js +0 -0
- /package/src/{tileset → tileset-3d}/helpers/zoom.ts +0 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
1
3
|
// This file is derived from the Cesium code base under Apache 2 license
|
|
2
4
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
5
|
|
|
4
6
|
/* eslint-disable */
|
|
5
7
|
import {Quaternion, Vector3, Matrix3, Matrix4, degrees} from '@math.gl/core';
|
|
6
8
|
import {BoundingSphere, OrientedBoundingBox} from '@math.gl/culling';
|
|
7
|
-
import {Ellipsoid} from '@math.gl/geospatial';
|
|
9
|
+
import {Ellipsoid, makeOBBFromRegion} from '@math.gl/geospatial';
|
|
8
10
|
import {assert} from '@loaders.gl/loader-utils';
|
|
9
11
|
|
|
10
12
|
// const scratchProjectedBoundingSphere = new BoundingSphere();
|
|
@@ -16,12 +18,7 @@ function defined(x) {
|
|
|
16
18
|
// const scratchMatrix = new Matrix3();
|
|
17
19
|
const scratchPoint = new Vector3();
|
|
18
20
|
const scratchScale = new Vector3();
|
|
19
|
-
const
|
|
20
|
-
const scratchSouthEast = new Vector3();
|
|
21
|
-
const scratchCenter = new Vector3();
|
|
22
|
-
const scratchXAxis = new Vector3();
|
|
23
|
-
const scratchYAxis = new Vector3();
|
|
24
|
-
const scratchZAxis = new Vector3();
|
|
21
|
+
const identityTransform = new Matrix4();
|
|
25
22
|
// const scratchRectangle = new Rectangle();
|
|
26
23
|
// const scratchOrientedBoundingBox = new OrientedBoundingBox();
|
|
27
24
|
// const scratchTransform = new Matrix4();
|
|
@@ -29,20 +26,39 @@ const scratchZAxis = new Vector3();
|
|
|
29
26
|
/**
|
|
30
27
|
* Create a bounding volume from the tile's bounding volume header.
|
|
31
28
|
* @param {Object} boundingVolumeHeader The tile's bounding volume header.
|
|
32
|
-
* @param {Matrix4} transform The
|
|
29
|
+
* @param {Matrix4} transform The current computed tile transform, including application transforms.
|
|
33
30
|
* @param [result] The object onto which to store the result.
|
|
31
|
+
* @param initialTransform The accumulated JSON tile transform, excluded from region transforms.
|
|
32
|
+
* Defaults to transform so callers without application transforms keep geospatial regions fixed.
|
|
34
33
|
* @returns The modified result parameter or a new TileBoundingVolume instance if none was provided.
|
|
35
34
|
*/
|
|
36
|
-
export function createBoundingVolume(
|
|
35
|
+
export function createBoundingVolume(
|
|
36
|
+
boundingVolumeHeader,
|
|
37
|
+
transform: Matrix4,
|
|
38
|
+
result?,
|
|
39
|
+
initialTransform: Matrix4 = transform
|
|
40
|
+
) {
|
|
37
41
|
assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
|
|
38
42
|
|
|
39
43
|
// boundingVolume schema:
|
|
40
44
|
// https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json
|
|
41
45
|
if (boundingVolumeHeader.box) {
|
|
42
|
-
|
|
46
|
+
// S2 cells and regions are geospatially anchored. Their conservative ECEF boxes are already
|
|
47
|
+
// world-space volumes and must not receive the tile/node transform a second time.
|
|
48
|
+
const boxTransform = boundingVolumeHeader.s2VolumeInfo ? identityTransform : transform;
|
|
49
|
+
return createBox(boundingVolumeHeader.box, boxTransform, result);
|
|
43
50
|
}
|
|
44
51
|
if (boundingVolumeHeader.region) {
|
|
45
|
-
|
|
52
|
+
const boundingVolume = makeOBBFromRegion(boundingVolumeHeader.region);
|
|
53
|
+
// Regions are already in world coordinates. Apply only the change from the JSON transform.
|
|
54
|
+
const regionTransform = transform.equals(initialTransform)
|
|
55
|
+
? identityTransform
|
|
56
|
+
: transform.clone().multiplyRight(initialTransform.clone().invert());
|
|
57
|
+
return createBox(
|
|
58
|
+
[...boundingVolume.center, ...boundingVolume.halfAxes],
|
|
59
|
+
regionTransform,
|
|
60
|
+
result
|
|
61
|
+
);
|
|
46
62
|
}
|
|
47
63
|
|
|
48
64
|
if (boundingVolumeHeader.sphere) {
|
|
@@ -59,15 +75,17 @@ export type CartographicBounds = [min: number[], max: number[]];
|
|
|
59
75
|
* Calculate the cartographic bounding box the tile's bounding volume.
|
|
60
76
|
* @param {Object} boundingVolumeHeader The tile's bounding volume header.
|
|
61
77
|
* @param {BoundingVolume} boundingVolume The bounding volume.
|
|
78
|
+
* @param isRegionTransformed Whether application transforms moved the region from its JSON bounds.
|
|
62
79
|
* @returns {CartographicBounds}
|
|
63
80
|
*/
|
|
64
81
|
export function getCartographicBounds(
|
|
65
82
|
boundingVolumeHeader,
|
|
66
|
-
boundingVolume: OrientedBoundingBox | BoundingSphere
|
|
83
|
+
boundingVolume: OrientedBoundingBox | BoundingSphere,
|
|
84
|
+
isRegionTransformed = false
|
|
67
85
|
): CartographicBounds {
|
|
68
86
|
// boundingVolume schema:
|
|
69
87
|
// https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json
|
|
70
|
-
if (boundingVolumeHeader.box) {
|
|
88
|
+
if (boundingVolumeHeader.box || (boundingVolumeHeader.region && isRegionTransformed)) {
|
|
71
89
|
return orientedBoundingBoxToCartographicBounds(boundingVolume as OrientedBoundingBox);
|
|
72
90
|
}
|
|
73
91
|
if (boundingVolumeHeader.region) {
|
|
@@ -146,61 +164,6 @@ function createBox(box, transform, result?) {
|
|
|
146
164
|
return new OrientedBoundingBox(center, halfAxes);
|
|
147
165
|
}
|
|
148
166
|
|
|
149
|
-
/*
|
|
150
|
-
function createBoxFromTransformedRegion(region, transform, initialTransform, result) {
|
|
151
|
-
const rectangle = Rectangle.unpack(region, 0, scratchRectangle);
|
|
152
|
-
const minimumHeight = region[4];
|
|
153
|
-
const maximumHeight = region[5];
|
|
154
|
-
|
|
155
|
-
const orientedBoundingBox = OrientedBoundingBox.fromRectangle(
|
|
156
|
-
rectangle,
|
|
157
|
-
minimumHeight,
|
|
158
|
-
maximumHeight,
|
|
159
|
-
Ellipsoid.WGS84,
|
|
160
|
-
scratchOrientedBoundingBox
|
|
161
|
-
);
|
|
162
|
-
const center = orientedBoundingBox.center;
|
|
163
|
-
const halfAxes = orientedBoundingBox.halfAxes;
|
|
164
|
-
|
|
165
|
-
// A region bounding volume is not transformed by the transform in the tileset JSON,
|
|
166
|
-
// but may be transformed by additional transforms applied in Cesium.
|
|
167
|
-
// This is why the transform is calculated as the difference between the initial transform and the current transform.
|
|
168
|
-
transform = Matrix4.multiplyTransformation(
|
|
169
|
-
transform,
|
|
170
|
-
Matrix4.inverseTransformation(initialTransform, scratchTransform),
|
|
171
|
-
scratchTransform
|
|
172
|
-
);
|
|
173
|
-
center = Matrix4.multiplyByPoint(transform, center, center);
|
|
174
|
-
const rotationScale = Matrix4.getRotation(transform, scratchMatrix);
|
|
175
|
-
halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
|
|
176
|
-
|
|
177
|
-
if (defined(result) && result instanceof TileOrientedBoundingBox) {
|
|
178
|
-
result.update(center, halfAxes);
|
|
179
|
-
return result;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return new TileOrientedBoundingBox(center, halfAxes);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function createRegion(region, transform, initialTransform, result) {
|
|
186
|
-
if (!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)) {
|
|
187
|
-
return createBoxFromTransformedRegion(region, transform, initialTransform, result);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (defined(result)) {
|
|
191
|
-
return result;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);
|
|
195
|
-
|
|
196
|
-
return new TileBoundingRegion({
|
|
197
|
-
rectangle: rectangleRegion,
|
|
198
|
-
minimumHeight: region[4],
|
|
199
|
-
maximumHeight: region[5]
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
*/
|
|
203
|
-
|
|
204
167
|
function createSphere(sphere, transform, result?) {
|
|
205
168
|
// Find the transformed center
|
|
206
169
|
const center = new Vector3(sphere[0], sphere[1], sphere[2]);
|
|
@@ -219,52 +182,6 @@ function createSphere(sphere, transform, result?) {
|
|
|
219
182
|
return new BoundingSphere(center, radius);
|
|
220
183
|
}
|
|
221
184
|
|
|
222
|
-
/**
|
|
223
|
-
* Create OrientedBoundingBox instance from region 3D tiles bounding volume
|
|
224
|
-
* @param region - region 3D tiles bounding volume
|
|
225
|
-
* @returns OrientedBoundingBox instance
|
|
226
|
-
*/
|
|
227
|
-
function createObbFromRegion(region: number[]): OrientedBoundingBox {
|
|
228
|
-
// [west, south, east, north, minimum height, maximum height]
|
|
229
|
-
// Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.
|
|
230
|
-
// Heights are in meters above (or below) the WGS 84 ellipsoid.
|
|
231
|
-
const [west, south, east, north, minHeight, maxHeight] = region;
|
|
232
|
-
|
|
233
|
-
const northWest = Ellipsoid.WGS84.cartographicToCartesian(
|
|
234
|
-
[degrees(west), degrees(north), minHeight],
|
|
235
|
-
scratchNorthWest
|
|
236
|
-
);
|
|
237
|
-
const southEast = Ellipsoid.WGS84.cartographicToCartesian(
|
|
238
|
-
[degrees(east), degrees(south), maxHeight],
|
|
239
|
-
scratchSouthEast
|
|
240
|
-
);
|
|
241
|
-
const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyByScalar(0.5);
|
|
242
|
-
Ellipsoid.WGS84.cartesianToCartographic(centerInCartesian, scratchCenter);
|
|
243
|
-
|
|
244
|
-
Ellipsoid.WGS84.cartographicToCartesian(
|
|
245
|
-
[degrees(east), scratchCenter[1], scratchCenter[2]],
|
|
246
|
-
scratchXAxis
|
|
247
|
-
);
|
|
248
|
-
Ellipsoid.WGS84.cartographicToCartesian(
|
|
249
|
-
[scratchCenter[0], degrees(north), scratchCenter[2]],
|
|
250
|
-
scratchYAxis
|
|
251
|
-
);
|
|
252
|
-
Ellipsoid.WGS84.cartographicToCartesian(
|
|
253
|
-
[scratchCenter[0], scratchCenter[1], maxHeight],
|
|
254
|
-
scratchZAxis
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
return createBox(
|
|
258
|
-
[
|
|
259
|
-
...centerInCartesian,
|
|
260
|
-
...scratchXAxis.subtract(centerInCartesian),
|
|
261
|
-
...scratchYAxis.subtract(centerInCartesian),
|
|
262
|
-
...scratchZAxis.subtract(centerInCartesian)
|
|
263
|
-
],
|
|
264
|
-
new Matrix4()
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
185
|
/**
|
|
269
186
|
* Convert a bounding volume defined by OrientedBoundingBox to cartographic bounds
|
|
270
187
|
* @returns {CartographicBounds}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {Tile3D} from '../common/tile-3d';
|
|
6
|
+
import {Vector3} from '@math.gl/core';
|
|
7
|
+
import {CullingVolume, Plane} from '@math.gl/culling';
|
|
8
|
+
import {Ellipsoid} from '@math.gl/geospatial';
|
|
9
|
+
import {GeospatialViewport, Viewport} from '../../types';
|
|
10
|
+
|
|
11
|
+
export type FrameState = {
|
|
12
|
+
camera: {
|
|
13
|
+
/** Camera position in WGS84 Cartesian meters. */
|
|
14
|
+
position: number[];
|
|
15
|
+
/** Normalized camera direction in WGS84 Cartesian coordinates. */
|
|
16
|
+
direction: number[];
|
|
17
|
+
/** Normalized camera up direction in WGS84 Cartesian coordinates. */
|
|
18
|
+
up: number[];
|
|
19
|
+
/** Camera position as `[longitude, latitude, height]`, with height in meters. */
|
|
20
|
+
cartographicPosition: [number, number, number];
|
|
21
|
+
/** Perspective vertical field of view in radians. */
|
|
22
|
+
verticalFieldOfView: number;
|
|
23
|
+
/** Elapsed seconds since camera position or direction last changed. */
|
|
24
|
+
timeSinceMovement: number;
|
|
25
|
+
};
|
|
26
|
+
viewport: GeospatialViewport;
|
|
27
|
+
topDownViewport: GeospatialViewport; // Use it to calculate projected radius for a tile
|
|
28
|
+
height: number;
|
|
29
|
+
cullingVolume: CullingVolume;
|
|
30
|
+
/** Optional world-space clipping planes applied to render-content culling. */
|
|
31
|
+
clippingPlanes?: Plane[];
|
|
32
|
+
frameNumber: number; // TODO: This can be the same between updates, what number is unique for between updates?
|
|
33
|
+
/** Perspective projection factor: twice the tangent of half the vertical field of view. */
|
|
34
|
+
sseDenominator: number;
|
|
35
|
+
/** View-dependent density used by perspective dynamic screen-space error for this traversal. */
|
|
36
|
+
dynamicScreenSpaceErrorDensity: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Optional camera and projection measurements supplied when constructing a frame state. */
|
|
40
|
+
export type GetFrameStateOptions = {
|
|
41
|
+
/** Elapsed seconds since camera position or direction last changed. */
|
|
42
|
+
timeSinceCameraMovement?: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Camera pose and timestamp retained between traversal frames. */
|
|
46
|
+
export type CameraMotionState = {
|
|
47
|
+
/** Last observed Earth-centered, Earth-fixed camera position. */
|
|
48
|
+
position: number[];
|
|
49
|
+
/** Last observed normalized Earth-centered, Earth-fixed camera direction. */
|
|
50
|
+
direction: number[];
|
|
51
|
+
/** Timestamp in milliseconds of the last observed pose change. */
|
|
52
|
+
lastMovementTime: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Updated camera state and elapsed stationary time for a traversal frame. */
|
|
56
|
+
export type CameraMotionUpdate = {
|
|
57
|
+
/** Camera pose to retain for the next traversal. */
|
|
58
|
+
state: CameraMotionState;
|
|
59
|
+
/** Elapsed seconds since the camera pose last changed. */
|
|
60
|
+
timeSinceMovement: number;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const scratchVector = new Vector3();
|
|
64
|
+
const scratchPosition = new Vector3();
|
|
65
|
+
const CAMERA_POSITION_EPSILON = 1e-5;
|
|
66
|
+
const CAMERA_DIRECTION_EPSILON = 1e-7;
|
|
67
|
+
const cullingVolume = new CullingVolume([
|
|
68
|
+
new Plane(),
|
|
69
|
+
new Plane(),
|
|
70
|
+
new Plane(),
|
|
71
|
+
new Plane(),
|
|
72
|
+
new Plane(),
|
|
73
|
+
new Plane()
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Extracts a frame state appropriate for tile culling from a structural deck.gl viewport.
|
|
78
|
+
*
|
|
79
|
+
* The viewport must describe the render camera, including its elevation. Geographic heights
|
|
80
|
+
* returned by `unprojectPosition` are used directly; adding a terrain offset only to traversal
|
|
81
|
+
* would make visibility, camera distances, and screen-space error disagree with rendering.
|
|
82
|
+
*
|
|
83
|
+
* `options.timeSinceCameraMovement` can be supplied by a caller that retains camera pose across
|
|
84
|
+
* calls. It defaults to a stationary camera so standalone callers do not defer requests.
|
|
85
|
+
*
|
|
86
|
+
* @param viewport - Geospatial viewport supplying camera and projection measurements.
|
|
87
|
+
* @param frameNumber - Current tileset traversal frame number.
|
|
88
|
+
* @param options - Additional camera and projection measurements for traversal.
|
|
89
|
+
* @returns Frame state used for visibility, SSE, and request-priority calculations.
|
|
90
|
+
*/
|
|
91
|
+
export function getFrameState(
|
|
92
|
+
viewport: GeospatialViewport,
|
|
93
|
+
frameNumber: number,
|
|
94
|
+
options: GetFrameStateOptions = {}
|
|
95
|
+
): FrameState {
|
|
96
|
+
// Traverse and and request. Update _selectedTiles so that we know what to render.
|
|
97
|
+
// Traverse and and request. Update _selectedTiles so that we know what to render.
|
|
98
|
+
const {cameraUp, height} = viewport;
|
|
99
|
+
const cameraDirection = viewport.cameraDirection as number[] | undefined;
|
|
100
|
+
const {metersPerUnit} = viewport.distanceScales;
|
|
101
|
+
|
|
102
|
+
// TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.
|
|
103
|
+
// TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?
|
|
104
|
+
const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);
|
|
105
|
+
const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
|
|
106
|
+
|
|
107
|
+
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
108
|
+
const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(
|
|
109
|
+
cameraPositionCartographic,
|
|
110
|
+
new Vector3()
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// These should still be normalized as the transform has scale 1 (goes from meters to meters)
|
|
114
|
+
let cameraDirectionCartesian: Vector3;
|
|
115
|
+
if (cameraDirection) {
|
|
116
|
+
cameraDirectionCartesian = new Vector3(
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))
|
|
119
|
+
).normalize();
|
|
120
|
+
} else {
|
|
121
|
+
// Concrete deck.gl viewports do not expose the legacy structural cameraDirection field.
|
|
122
|
+
// The near-plane center is on the view axis, so its world-space direction is equivalent and
|
|
123
|
+
// works for perspective foveation without coupling loaders.gl to deck.gl internals.
|
|
124
|
+
// getFrustumPlanes is required by traversal but omitted from the minimal structural Viewport
|
|
125
|
+
// type for compatibility with existing application-side declarations.
|
|
126
|
+
// @ts-expect-error Runtime geospatial viewports provide getFrustumPlanes.
|
|
127
|
+
const nearPlane = viewport.getFrustumPlanes().near;
|
|
128
|
+
const nearCenterCommon = closestPointOnPlane(nearPlane, viewport.cameraPosition);
|
|
129
|
+
const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);
|
|
130
|
+
cameraDirectionCartesian = new Vector3(nearCenterCartesian)
|
|
131
|
+
.subtract(cameraPositionCartesian)
|
|
132
|
+
.normalize();
|
|
133
|
+
}
|
|
134
|
+
const cameraUpCartesian = new Vector3(
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))
|
|
137
|
+
).normalize();
|
|
138
|
+
|
|
139
|
+
commonSpacePlanesToWGS84(viewport);
|
|
140
|
+
|
|
141
|
+
const ViewportClass = viewport.constructor;
|
|
142
|
+
const {longitude, latitude, width, bearing, zoom, position} = viewport;
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
const topDownViewport = new ViewportClass({
|
|
145
|
+
longitude,
|
|
146
|
+
latitude,
|
|
147
|
+
height,
|
|
148
|
+
width,
|
|
149
|
+
bearing,
|
|
150
|
+
zoom,
|
|
151
|
+
position,
|
|
152
|
+
pitch: 0
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const verticalFieldOfView =
|
|
156
|
+
Number.isFinite(viewport.fovy) && Number(viewport.fovy) > 0 && Number(viewport.fovy) < 180
|
|
157
|
+
? (Number(viewport.fovy) * Math.PI) / 180
|
|
158
|
+
: Math.PI / 3;
|
|
159
|
+
|
|
160
|
+
// TODO: make a file/class for frameState and document what needs to be attached to this so that traversal can function
|
|
161
|
+
return {
|
|
162
|
+
camera: {
|
|
163
|
+
position: cameraPositionCartesian,
|
|
164
|
+
direction: cameraDirectionCartesian,
|
|
165
|
+
up: cameraUpCartesian,
|
|
166
|
+
cartographicPosition: cameraPositionCartographic,
|
|
167
|
+
verticalFieldOfView,
|
|
168
|
+
timeSinceMovement: options.timeSinceCameraMovement ?? Number.POSITIVE_INFINITY
|
|
169
|
+
},
|
|
170
|
+
viewport,
|
|
171
|
+
topDownViewport,
|
|
172
|
+
height,
|
|
173
|
+
cullingVolume,
|
|
174
|
+
clippingPlanes: viewport.clippingPlanes,
|
|
175
|
+
frameNumber, // TODO: This can be the same between updates, what number is unique for between updates?
|
|
176
|
+
sseDenominator: 2 * Math.tan(verticalFieldOfView / 2),
|
|
177
|
+
// Tileset3D fills this immediately before traversal because it depends on the root volume.
|
|
178
|
+
dynamicScreenSpaceErrorDensity: 0
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Updates retained camera motion state and calculates how long the current pose has been stable.
|
|
184
|
+
*
|
|
185
|
+
* The first observation is treated as stationary so initial tileset loading is never delayed.
|
|
186
|
+
* Position and direction are both compared because orbiting in place changes request relevance
|
|
187
|
+
* without necessarily changing the viewport's camera position.
|
|
188
|
+
*
|
|
189
|
+
* @param previousState - Pose retained from the preceding traversal for this viewport.
|
|
190
|
+
* @param position - Current Earth-centered, Earth-fixed camera position.
|
|
191
|
+
* @param direction - Current normalized Earth-centered, Earth-fixed camera direction.
|
|
192
|
+
* @param currentTime - Current monotonic-enough wall-clock time in milliseconds.
|
|
193
|
+
* @returns Updated pose and elapsed stationary time.
|
|
194
|
+
*/
|
|
195
|
+
export function updateCameraMotionState(
|
|
196
|
+
previousState: CameraMotionState | undefined,
|
|
197
|
+
position: number[] | Vector3,
|
|
198
|
+
direction: number[] | Vector3,
|
|
199
|
+
currentTime: number
|
|
200
|
+
): CameraMotionUpdate {
|
|
201
|
+
const positionArray = Array.from(position);
|
|
202
|
+
const directionArray = Array.from(direction);
|
|
203
|
+
const positionChanged = previousState
|
|
204
|
+
? positionArray.length !== previousState.position.length ||
|
|
205
|
+
positionArray.some(
|
|
206
|
+
(value, index) => Math.abs(value - previousState.position[index]) > CAMERA_POSITION_EPSILON
|
|
207
|
+
)
|
|
208
|
+
: false;
|
|
209
|
+
const directionChanged = previousState
|
|
210
|
+
? directionArray.length !== previousState.direction.length ||
|
|
211
|
+
directionArray.some(
|
|
212
|
+
(value, index) =>
|
|
213
|
+
Math.abs(value - previousState.direction[index]) > CAMERA_DIRECTION_EPSILON
|
|
214
|
+
)
|
|
215
|
+
: false;
|
|
216
|
+
const lastMovementTime =
|
|
217
|
+
positionChanged || directionChanged
|
|
218
|
+
? currentTime
|
|
219
|
+
: (previousState?.lastMovementTime ?? Number.NEGATIVE_INFINITY);
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
state: {
|
|
223
|
+
position: positionArray,
|
|
224
|
+
direction: directionArray,
|
|
225
|
+
lastMovementTime
|
|
226
|
+
},
|
|
227
|
+
timeSinceMovement: Math.max((currentTime - lastMovementTime) / 1000, 0)
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Limit `tiles` array length with `maximumTilesSelected` number.
|
|
233
|
+
* The criteria for this filtering is distance of a tile center
|
|
234
|
+
* to the `frameState.viewport`'s longitude and latitude
|
|
235
|
+
* @param tiles - tiles array to filter
|
|
236
|
+
* @param frameState - frameState to calculate distances
|
|
237
|
+
* @param maximumTilesSelected - maximal amount of tiles in the output array
|
|
238
|
+
* @returns new tiles array
|
|
239
|
+
*/
|
|
240
|
+
export function limitSelectedTiles(
|
|
241
|
+
tiles: Tile3D[],
|
|
242
|
+
frameState: FrameState,
|
|
243
|
+
maximumTilesSelected: number
|
|
244
|
+
): [Tile3D[], Tile3D[]] {
|
|
245
|
+
if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {
|
|
246
|
+
return [tiles, []];
|
|
247
|
+
}
|
|
248
|
+
// Accumulate distances in couples array: [tileIndex: number, distanceToViewport: number]
|
|
249
|
+
const tuples: [number, number][] = [];
|
|
250
|
+
const {longitude: viewportLongitude, latitude: viewportLatitude} = frameState.viewport;
|
|
251
|
+
for (const [index, tile] of tiles.entries()) {
|
|
252
|
+
const [longitude, latitude] = tile.header.mbs;
|
|
253
|
+
const deltaLon = Math.abs(viewportLongitude - longitude);
|
|
254
|
+
const deltaLat = Math.abs(viewportLatitude - latitude);
|
|
255
|
+
const distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);
|
|
256
|
+
tuples.push([index, distance]);
|
|
257
|
+
}
|
|
258
|
+
const tuplesSorted = tuples.sort((a, b) => a[1] - b[1]);
|
|
259
|
+
const selectedTiles: Tile3D[] = [];
|
|
260
|
+
for (let i = 0; i < maximumTilesSelected; i++) {
|
|
261
|
+
selectedTiles.push(tiles[tuplesSorted[i][0]]);
|
|
262
|
+
}
|
|
263
|
+
const unselectedTiles: Tile3D[] = [];
|
|
264
|
+
for (let i = maximumTilesSelected; i < tuplesSorted.length; i++) {
|
|
265
|
+
unselectedTiles.push(tiles[tuplesSorted[i][0]]);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return [selectedTiles, unselectedTiles];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function commonSpacePlanesToWGS84(viewport) {
|
|
272
|
+
// Extract frustum planes based on current view.
|
|
273
|
+
const frustumPlanes = viewport.getFrustumPlanes();
|
|
274
|
+
|
|
275
|
+
// Get the near/far plane centers
|
|
276
|
+
const nearCenterCommon = closestPointOnPlane(frustumPlanes.near, viewport.cameraPosition);
|
|
277
|
+
const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);
|
|
278
|
+
const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition);
|
|
279
|
+
|
|
280
|
+
let i = 0;
|
|
281
|
+
cullingVolume.planes[i++].fromPointNormal(
|
|
282
|
+
nearCenterCartesian,
|
|
283
|
+
scratchVector.copy(nearCenterCartesian).subtract(cameraCartesian)
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
for (const dir in frustumPlanes) {
|
|
287
|
+
if (dir === 'near') {
|
|
288
|
+
continue; // eslint-disable-line no-continue
|
|
289
|
+
}
|
|
290
|
+
const plane = frustumPlanes[dir];
|
|
291
|
+
const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition);
|
|
292
|
+
const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition);
|
|
293
|
+
|
|
294
|
+
cullingVolume.planes[i++].fromPointNormal(
|
|
295
|
+
cartesianPos,
|
|
296
|
+
// Want the normal to point into the frustum since that's what culling expects
|
|
297
|
+
scratchVector.copy(nearCenterCartesian).subtract(cartesianPos)
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function closestPointOnPlane(
|
|
303
|
+
plane: {distance: number; normal: Vector3},
|
|
304
|
+
refPoint: number[] | Vector3,
|
|
305
|
+
out: Vector3 = new Vector3()
|
|
306
|
+
): Vector3 {
|
|
307
|
+
const distanceToRef = plane.normal.dot(refPoint);
|
|
308
|
+
out
|
|
309
|
+
.copy(plane.normal)
|
|
310
|
+
.scale(plane.distance - distanceToRef)
|
|
311
|
+
.add(refPoint);
|
|
312
|
+
return out;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function worldToCartesian(
|
|
316
|
+
viewport: Viewport,
|
|
317
|
+
point: number[] | Vector3,
|
|
318
|
+
out: Vector3 = new Vector3()
|
|
319
|
+
): Vector3 {
|
|
320
|
+
const cartographicPos = viewport.unprojectPosition(point);
|
|
321
|
+
return Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, out);
|
|
322
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import {Matrix4, Vector3} from '@math.gl/core';
|
|
6
6
|
import {Ellipsoid} from '@math.gl/geospatial';
|
|
7
|
-
import {Tile3D} from '../tile-3d';
|
|
7
|
+
import {Tile3D} from '../common/tile-3d';
|
|
8
8
|
import {FrameState} from './frame-state';
|
|
9
9
|
|
|
10
10
|
const cameraPositionCartesian = new Vector3();
|
|
@@ -25,19 +25,32 @@ const cartesianToEnuMatrix = new Matrix4();
|
|
|
25
25
|
* @returns
|
|
26
26
|
*/
|
|
27
27
|
export function getLodStatus(tile: Tile3D, frameState: FrameState): 'DIG' | 'OUT' | 'DRAW' {
|
|
28
|
-
if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
|
|
28
|
+
if (tile.lodMetricValue === 0 || Number.isNaN(tile.lodMetricValue)) {
|
|
29
29
|
return 'DIG';
|
|
30
30
|
}
|
|
31
31
|
const screenSize = 2 * getProjectedRadius(tile, frameState);
|
|
32
32
|
if (screenSize < 2) {
|
|
33
33
|
return 'OUT';
|
|
34
34
|
}
|
|
35
|
-
if (!tile.header.children
|
|
35
|
+
if (!tile.header.children) {
|
|
36
36
|
return 'DRAW';
|
|
37
|
-
} else if (tile.header.children) {
|
|
38
|
-
return 'DIG';
|
|
39
37
|
}
|
|
40
|
-
|
|
38
|
+
|
|
39
|
+
switch (tile.lodMetricType) {
|
|
40
|
+
case 'screenSpaceRelative': {
|
|
41
|
+
const viewportHeight = frameState.topDownViewport.height || 1;
|
|
42
|
+
return screenSize / viewportHeight <= tile.lodMetricValue ? 'DRAW' : 'DIG';
|
|
43
|
+
}
|
|
44
|
+
case 'distanceRangeFromDefaultCamera':
|
|
45
|
+
return tile.distanceToTile(frameState) >= tile.lodMetricValue ? 'DRAW' : 'DIG';
|
|
46
|
+
case 'maxScreenThresholdSQ': {
|
|
47
|
+
const diameterThreshold = Math.sqrt(tile.lodMetricValue / (Math.PI * 0.25));
|
|
48
|
+
return screenSize <= diameterThreshold ? 'DRAW' : 'DIG';
|
|
49
|
+
}
|
|
50
|
+
case 'maxScreenThreshold':
|
|
51
|
+
default:
|
|
52
|
+
return screenSize <= tile.lodMetricValue ? 'DRAW' : 'DIG';
|
|
53
|
+
}
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
/**
|
|
@@ -49,10 +62,11 @@ export function getLodStatus(tile: Tile3D, frameState: FrameState): 'DIG' | 'OUT
|
|
|
49
62
|
// eslint-disable-next-line max-statements
|
|
50
63
|
export function getProjectedRadius(tile: Tile3D, frameState: FrameState): number {
|
|
51
64
|
const {topDownViewport: viewport} = frameState;
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
65
|
+
const mbs = tile.header.i3sLodMbs || tile.header.mbs;
|
|
66
|
+
const mbsLat = mbs[1];
|
|
67
|
+
const mbsLon = mbs[0];
|
|
68
|
+
const mbsZ = mbs[2];
|
|
69
|
+
const mbsR = mbs[3];
|
|
56
70
|
const mbsCenterCartesian = [...tile.boundingVolume.center];
|
|
57
71
|
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
58
72
|
Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
5
|
+
// TypeScript's legacy `node` resolution does not inspect package `exports`, but this public
|
|
6
|
+
// subpath is resolved by the package at runtime and avoids loading unrelated DGGS decoders.
|
|
7
|
+
// @ts-expect-error Conditional package subpath exports require a modern module resolver.
|
|
8
|
+
import {getS2Bounds} from '@math.gl/dggs/s2';
|
|
9
|
+
import {Ellipsoid, makeOBBFromRegion} from '@math.gl/geospatial';
|
|
10
|
+
|
|
11
|
+
/** Serialized S2 cell metadata used by 3D Tiles bounding-volume extensions. */
|
|
12
|
+
export type S2VolumeInfo = {
|
|
13
|
+
/** S2 key or token. */
|
|
14
|
+
token: string;
|
|
15
|
+
/** Minimum height in meters. */
|
|
16
|
+
minimumHeight: number;
|
|
17
|
+
/** Maximum height in meters. */
|
|
18
|
+
maximumHeight: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Converts an S2 cell and its vertical range to the runtime oriented-box representation.
|
|
23
|
+
*
|
|
24
|
+
* @param s2VolumeInfo - S2 cell token and height range.
|
|
25
|
+
* @returns A twelve-component center/half-axis oriented bounding box.
|
|
26
|
+
*/
|
|
27
|
+
export function convertS2BoundingVolumeToOBB(s2VolumeInfo: S2VolumeInfo): number[] {
|
|
28
|
+
const [[west, south], [east, north]] = getS2Bounds(s2VolumeInfo.token);
|
|
29
|
+
const orientedBoundingBox = makeOBBFromRegion(
|
|
30
|
+
[west, south, east, north, s2VolumeInfo.minimumHeight, s2VolumeInfo.maximumHeight],
|
|
31
|
+
Ellipsoid.WGS84,
|
|
32
|
+
{units: 'degrees'}
|
|
33
|
+
);
|
|
34
|
+
return [...orientedBoundingBox.center, ...orientedBoundingBox.halfAxes];
|
|
35
|
+
}
|