@loaders.gl/tiles 4.4.5 → 5.0.0-alpha.2
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 +110 -1
- package/dist/dist.dev.js +6588 -2057
- package/dist/dist.min.js +1 -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 +6872 -2160
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +33 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -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 +131 -0
- package/dist/point-cloud/point-cloud-tileset.d.ts.map +1 -0
- package/dist/point-cloud/point-cloud-tileset.js +510 -0
- package/dist/point-cloud/point-cloud-tileset.js.map +1 -0
- package/dist/point-cloud/types.d.ts +64 -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 +113 -0
- package/dist/raster-set.d.ts.map +1 -0
- package/dist/raster-set.js +274 -0
- package/dist/raster-set.js.map +1 -0
- package/dist/tileset-2d/adapter.d.ts +38 -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 +201 -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 +125 -0
- package/dist/tileset-3d/common/indexed-archive-tileset-source.js.map +1 -0
- package/dist/{tileset → tileset-3d/common}/tile-3d.d.ts +133 -29
- package/dist/tileset-3d/common/tile-3d.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d/common}/tile-3d.js +282 -77
- package/dist/tileset-3d/common/tile-3d.js.map +1 -0
- package/dist/tileset-3d/common/tileset-3d.d.ts +317 -0
- package/dist/tileset-3d/common/tileset-3d.d.ts.map +1 -0
- package/dist/tileset-3d/common/tileset-3d.js +807 -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-source.d.ts +204 -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 +15 -2
- package/dist/tileset-3d/common/tileset-traverser.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d/common}/tileset-traverser.js +30 -3
- package/dist/tileset-3d/common/tileset-traverser.js.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts +111 -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 +340 -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 +189 -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 +510 -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 +43 -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 +119 -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 +99 -0
- package/dist/tileset-3d/format-i3s/i3s-source.d.ts.map +1 -0
- package/dist/tileset-3d/format-i3s/i3s-source.js +299 -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-3d/helpers/bounding-volume.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/bounding-volume.js +1 -0
- package/dist/tileset-3d/helpers/bounding-volume.js.map +1 -0
- package/dist/tileset-3d/helpers/frame-state.d.ts +86 -0
- package/dist/tileset-3d/helpers/frame-state.d.ts.map +1 -0
- package/dist/{tileset → tileset-3d}/helpers/frame-state.js +84 -9
- 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 +1 -1
- package/dist/tileset-3d/helpers/i3s-lod.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 +9 -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 +7 -6
- package/src/image-set.ts +328 -0
- package/src/index.ts +99 -9
- package/src/point-cloud/point-cloud-tile.ts +80 -0
- package/src/point-cloud/point-cloud-tileset.ts +713 -0
- package/src/point-cloud/types.ts +82 -0
- package/src/raster-set.ts +412 -0
- package/src/tileset-2d/adapter.ts +47 -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 +716 -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 → tileset-3d/common}/tile-3d.ts +348 -93
- package/src/tileset-3d/common/tileset-3d.ts +1087 -0
- package/src/{tileset → tileset-3d/common}/tileset-cache.ts +16 -8
- package/src/tileset-3d/common/tileset-source.ts +255 -0
- package/src/{tileset → tileset-3d/common}/tileset-traverser.ts +32 -4
- package/src/tileset-3d/format-3d-tiles/implicit-tiling.ts +534 -0
- package/src/tileset-3d/format-3d-tiles/tiles-3d-source.ts +632 -0
- package/src/tileset-3d/format-3d-tiles/tileset-3d-traverser.ts +140 -0
- package/src/{tileset → tileset-3d}/format-i3s/i3s-pending-tiles-register.ts +4 -0
- package/src/tileset-3d/format-i3s/i3s-source.ts +366 -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 +19 -24
- package/src/{tileset → tileset-3d}/helpers/3d-tiles-options.ts +5 -1
- package/src/{tileset → tileset-3d}/helpers/bounding-volume.ts +2 -0
- package/src/tileset-3d/helpers/frame-state.ts +311 -0
- package/src/{tileset → tileset-3d}/helpers/i3s-lod.ts +2 -2
- 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 +13 -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.map +0 -1
- 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/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/bounding-volume.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
|
@@ -0,0 +1,1087 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
6
|
+
|
|
7
|
+
import {Matrix4, Vector3} from '@math.gl/core';
|
|
8
|
+
import {Ellipsoid} from '@math.gl/geospatial';
|
|
9
|
+
import {Stats} from '@probe.gl/stats';
|
|
10
|
+
import {RequestScheduler, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
11
|
+
import {TilesetCache} from './tileset-cache';
|
|
12
|
+
import {calculateTransformProps} from '../helpers/transform-utils';
|
|
13
|
+
import {getFrameState, limitSelectedTiles, updateCameraMotionState} from '../helpers/frame-state';
|
|
14
|
+
import type {CameraMotionState, FrameState} from '../helpers/frame-state';
|
|
15
|
+
import {
|
|
16
|
+
calculateDynamicScreenSpaceErrorDensity,
|
|
17
|
+
updateRootTransformForDynamicScreenSpaceError
|
|
18
|
+
} from '../helpers/tiles-3d-lod';
|
|
19
|
+
import {interpolateLinearly} from '../helpers/tiles-3d-request-priority';
|
|
20
|
+
import type {FoveatedInterpolationCallback} from '../helpers/tiles-3d-request-priority';
|
|
21
|
+
|
|
22
|
+
import type {GeospatialViewport, Viewport} from '../../types';
|
|
23
|
+
import {Tile3D} from './tile-3d';
|
|
24
|
+
import {TILESET_TYPE} from '../../constants';
|
|
25
|
+
|
|
26
|
+
import {TilesetTraverser} from './tileset-traverser';
|
|
27
|
+
import {
|
|
28
|
+
isTileset3DSource,
|
|
29
|
+
TileContentLoadResult,
|
|
30
|
+
TilesetContentFormats,
|
|
31
|
+
TilesetJSON,
|
|
32
|
+
Tileset3DSource,
|
|
33
|
+
TilesetSourceMetadata
|
|
34
|
+
} from './tileset-source';
|
|
35
|
+
|
|
36
|
+
export type {TilesetJSON} from './tileset-source';
|
|
37
|
+
|
|
38
|
+
export type Tileset3DProps = {
|
|
39
|
+
throttleRequests?: boolean;
|
|
40
|
+
maxRequests?: number;
|
|
41
|
+
loadOptions?: LoaderOptions;
|
|
42
|
+
loadTiles?: boolean;
|
|
43
|
+
basePath?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Soft target, in bytes, for cached tile content that is not required by the current frame.
|
|
46
|
+
* The listed default applies to 3D Tiles; I3S retains its existing 32 MiB default.
|
|
47
|
+
* @default 536870912
|
|
48
|
+
*/
|
|
49
|
+
cacheBytes?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Additional bytes that the current-frame working set may use before memory-adjusted SSE rises.
|
|
52
|
+
* The listed default applies to 3D Tiles; I3S retains its existing 1 MiB default.
|
|
53
|
+
* @default 536870912
|
|
54
|
+
*/
|
|
55
|
+
maximumCacheOverflowBytes?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Soft cache target in mebibytes.
|
|
58
|
+
* @deprecated Use {@link Tileset3DProps.cacheBytes}; when both are supplied, `cacheBytes` wins.
|
|
59
|
+
*/
|
|
60
|
+
maximumMemoryUsage?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Cache overflow headroom in mebibytes.
|
|
63
|
+
* @deprecated Use {@link Tileset3DProps.maximumCacheOverflowBytes}; when both are supplied, the
|
|
64
|
+
* byte-native option wins.
|
|
65
|
+
*/
|
|
66
|
+
memoryCacheOverflow?: number;
|
|
67
|
+
maximumTilesSelected?: number;
|
|
68
|
+
debounceTime?: number;
|
|
69
|
+
|
|
70
|
+
description?: string;
|
|
71
|
+
attributions?: string[];
|
|
72
|
+
|
|
73
|
+
ellipsoid?: object;
|
|
74
|
+
modelMatrix?: Matrix4;
|
|
75
|
+
|
|
76
|
+
maximumScreenSpaceError?: number;
|
|
77
|
+
/** Enables perspective dynamic SSE to reduce distant, horizon-facing refinement. */
|
|
78
|
+
dynamicScreenSpaceError?: boolean;
|
|
79
|
+
/** Base dynamic SSE fog density in inverse meters. */
|
|
80
|
+
dynamicScreenSpaceErrorDensity?: number;
|
|
81
|
+
/** Maximum dynamic SSE reduction in logical/CSS pixels. */
|
|
82
|
+
dynamicScreenSpaceErrorFactor?: number;
|
|
83
|
+
/** Fraction of tileset height at which dynamic SSE begins to fade, clamped to `[0, 1]`. */
|
|
84
|
+
dynamicScreenSpaceErrorHeightFalloff?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Enables adaptive LOD reduction when estimated tile memory exceeds the overflow ceiling.
|
|
87
|
+
* Defaults to `true` for 3D Tiles and retains the existing `false` default for I3S.
|
|
88
|
+
*/
|
|
89
|
+
memoryAdjustedScreenSpaceError?: boolean;
|
|
90
|
+
viewportTraversersMap?: any;
|
|
91
|
+
updateTransforms?: boolean;
|
|
92
|
+
viewDistanceScale?: number;
|
|
93
|
+
/** Reduced viewport-height fraction used to prioritize coarse initial coverage; `0` disables it. */
|
|
94
|
+
progressiveResolutionHeightFraction?: number;
|
|
95
|
+
/** Whether requests nearer the center of a perspective viewport receive higher priority. */
|
|
96
|
+
foveatedScreenSpaceError?: boolean;
|
|
97
|
+
/** Fraction of the perspective field of view that receives no foveated SSE relaxation. */
|
|
98
|
+
foveatedConeSize?: number;
|
|
99
|
+
/** Minimum logical-pixel SSE relaxation immediately outside the foveated cone. */
|
|
100
|
+
foveatedMinimumScreenSpaceErrorRelaxation?: number;
|
|
101
|
+
/** Function that increases SSE relaxation from the foveated cone toward the viewport edge. */
|
|
102
|
+
foveatedInterpolationCallback?: FoveatedInterpolationCallback;
|
|
103
|
+
/** Seconds peripheral requests may wait after the camera moves. */
|
|
104
|
+
foveatedTimeDelay?: number;
|
|
105
|
+
|
|
106
|
+
onTileLoad?: (tile: Tile3D) => any;
|
|
107
|
+
onTileUnload?: (tile: Tile3D) => any;
|
|
108
|
+
onTileError?: (tile: Tile3D, message: string, url: string) => any;
|
|
109
|
+
/** Called when a format-specific source operation fails. */
|
|
110
|
+
onSourceError?: (error: Error, source: Tileset3DSource, tile?: Tile3D | null) => any;
|
|
111
|
+
/** Called when tileset initialization fails before traversal can begin. */
|
|
112
|
+
onTilesetError?: (error: Error, tileset: Tileset3D) => any;
|
|
113
|
+
contentLoader?: (tile: Tile3D) => Promise<void>;
|
|
114
|
+
onTraversalComplete?: (selectedTiles: Tile3D[]) => Tile3D[];
|
|
115
|
+
onUpdate?: () => void;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
type Props = {
|
|
119
|
+
description: string;
|
|
120
|
+
ellipsoid: object;
|
|
121
|
+
modelMatrix: Matrix4;
|
|
122
|
+
throttleRequests: boolean;
|
|
123
|
+
maxRequests: number;
|
|
124
|
+
/** Soft target, in bytes, for evictable cached tile content. */
|
|
125
|
+
cacheBytes: number;
|
|
126
|
+
/** Current-frame headroom, in bytes, before memory-adjusted SSE rises. */
|
|
127
|
+
maximumCacheOverflowBytes: number;
|
|
128
|
+
/** @deprecated Byte-native code should use `cacheBytes`. */
|
|
129
|
+
maximumMemoryUsage: number;
|
|
130
|
+
/** @deprecated Byte-native code should use `maximumCacheOverflowBytes`. */
|
|
131
|
+
memoryCacheOverflow: number;
|
|
132
|
+
maximumTilesSelected: number;
|
|
133
|
+
debounceTime: number;
|
|
134
|
+
onTileLoad: (tile: Tile3D) => void;
|
|
135
|
+
onTileUnload: (tile: Tile3D) => void;
|
|
136
|
+
onTileError: (tile: Tile3D, message: string, url: string) => void;
|
|
137
|
+
onSourceError: (error: Error, source: Tileset3DSource, tile?: Tile3D | null) => void;
|
|
138
|
+
onTilesetError: (error: Error, tileset: Tileset3D) => void;
|
|
139
|
+
onTraversalComplete: (selectedTiles: Tile3D[]) => Tile3D[];
|
|
140
|
+
onUpdate: () => void;
|
|
141
|
+
maximumScreenSpaceError: number;
|
|
142
|
+
/** Whether perspective dynamic SSE is enabled. */
|
|
143
|
+
dynamicScreenSpaceError: boolean;
|
|
144
|
+
/** Base dynamic SSE fog density in inverse meters. */
|
|
145
|
+
dynamicScreenSpaceErrorDensity: number;
|
|
146
|
+
/** Maximum dynamic SSE reduction in logical/CSS pixels. */
|
|
147
|
+
dynamicScreenSpaceErrorFactor: number;
|
|
148
|
+
/** Fraction of tileset height at which dynamic SSE begins to fade. */
|
|
149
|
+
dynamicScreenSpaceErrorHeightFalloff: number;
|
|
150
|
+
/** Whether cache pressure may adapt the active SSE threshold. */
|
|
151
|
+
memoryAdjustedScreenSpaceError: boolean;
|
|
152
|
+
viewportTraversersMap: Record<string, any> | null;
|
|
153
|
+
attributions: string[];
|
|
154
|
+
loadTiles: boolean;
|
|
155
|
+
loadOptions: LoaderOptions;
|
|
156
|
+
updateTransforms: boolean;
|
|
157
|
+
viewDistanceScale: number;
|
|
158
|
+
/** Reduced viewport-height fraction used to prioritize coarse initial coverage. */
|
|
159
|
+
progressiveResolutionHeightFraction: number;
|
|
160
|
+
/** Whether perspective requests are prioritized around the viewport center. */
|
|
161
|
+
foveatedScreenSpaceError: boolean;
|
|
162
|
+
/** Fraction of the perspective field of view with no foveated SSE relaxation. */
|
|
163
|
+
foveatedConeSize: number;
|
|
164
|
+
/** Minimum logical-pixel SSE relaxation outside the foveated cone. */
|
|
165
|
+
foveatedMinimumScreenSpaceErrorRelaxation: number;
|
|
166
|
+
/** Function used to interpolate foveated SSE relaxation. */
|
|
167
|
+
foveatedInterpolationCallback: FoveatedInterpolationCallback;
|
|
168
|
+
/** Seconds eligible peripheral requests wait after camera movement. */
|
|
169
|
+
foveatedTimeDelay: number;
|
|
170
|
+
basePath: string;
|
|
171
|
+
contentLoader?: (tile: Tile3D) => Promise<void>;
|
|
172
|
+
i3s: Record<string, any>;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const BYTES_PER_MEBIBYTE = 1024 * 1024;
|
|
176
|
+
const DEFAULT_CACHE_BYTES = 512 * BYTES_PER_MEBIBYTE;
|
|
177
|
+
const DEFAULT_MAXIMUM_CACHE_OVERFLOW_BYTES = 512 * BYTES_PER_MEBIBYTE;
|
|
178
|
+
const DEFAULT_I3S_CACHE_BYTES = 32 * BYTES_PER_MEBIBYTE;
|
|
179
|
+
const DEFAULT_I3S_MAXIMUM_CACHE_OVERFLOW_BYTES = BYTES_PER_MEBIBYTE;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Validates a byte-based tile-cache budget.
|
|
183
|
+
*
|
|
184
|
+
* Fractions are accepted because JavaScript memory estimates are numbers, but negative, infinite,
|
|
185
|
+
* and `NaN` values cannot define a stable cache threshold.
|
|
186
|
+
*
|
|
187
|
+
* @param value - Proposed cache budget in bytes.
|
|
188
|
+
* @param optionName - Public option name used in an actionable error message.
|
|
189
|
+
* @returns The validated byte budget.
|
|
190
|
+
*/
|
|
191
|
+
function validateCacheByteLength(value: number, optionName: string): number {
|
|
192
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
193
|
+
throw new Error(`${optionName} must be a finite number greater than or equal to 0`);
|
|
194
|
+
}
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Resolves the base cache target from byte-native or deprecated mebibyte options.
|
|
200
|
+
*
|
|
201
|
+
* The byte-native option takes precedence so mixed migration configurations are deterministic.
|
|
202
|
+
* The fallback is already expressed in bytes and is used for both construction and runtime updates.
|
|
203
|
+
*
|
|
204
|
+
* @param options - Options that may contain byte-native or deprecated cache values.
|
|
205
|
+
* @param fallbackCacheBytes - Existing or default cache target in bytes.
|
|
206
|
+
* @returns The resolved and validated cache target in bytes.
|
|
207
|
+
*/
|
|
208
|
+
function resolveCacheBytes(options: Tileset3DProps, fallbackCacheBytes: number): number {
|
|
209
|
+
const cacheBytes =
|
|
210
|
+
options.cacheBytes ??
|
|
211
|
+
(options.maximumMemoryUsage !== undefined
|
|
212
|
+
? options.maximumMemoryUsage * BYTES_PER_MEBIBYTE
|
|
213
|
+
: fallbackCacheBytes);
|
|
214
|
+
return validateCacheByteLength(cacheBytes, 'cacheBytes');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Resolves cache overflow headroom from byte-native or deprecated mebibyte options.
|
|
219
|
+
*
|
|
220
|
+
* The byte-native option takes precedence so callers can migrate the two cache controls
|
|
221
|
+
* independently without unit ambiguity.
|
|
222
|
+
*
|
|
223
|
+
* @param options - Options that may contain byte-native or deprecated overflow values.
|
|
224
|
+
* @param fallbackOverflowBytes - Existing or default overflow headroom in bytes.
|
|
225
|
+
* @returns The resolved and validated overflow headroom in bytes.
|
|
226
|
+
*/
|
|
227
|
+
function resolveMaximumCacheOverflowBytes(
|
|
228
|
+
options: Tileset3DProps,
|
|
229
|
+
fallbackOverflowBytes: number
|
|
230
|
+
): number {
|
|
231
|
+
const maximumCacheOverflowBytes =
|
|
232
|
+
options.maximumCacheOverflowBytes ??
|
|
233
|
+
(options.memoryCacheOverflow !== undefined
|
|
234
|
+
? options.memoryCacheOverflow * BYTES_PER_MEBIBYTE
|
|
235
|
+
: fallbackOverflowBytes);
|
|
236
|
+
return validateCacheByteLength(maximumCacheOverflowBytes, 'maximumCacheOverflowBytes');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const DEFAULT_PROPS: Props = {
|
|
240
|
+
description: '',
|
|
241
|
+
ellipsoid: Ellipsoid.WGS84,
|
|
242
|
+
modelMatrix: new Matrix4(),
|
|
243
|
+
throttleRequests: true,
|
|
244
|
+
maxRequests: 64,
|
|
245
|
+
cacheBytes: DEFAULT_CACHE_BYTES,
|
|
246
|
+
maximumCacheOverflowBytes: DEFAULT_MAXIMUM_CACHE_OVERFLOW_BYTES,
|
|
247
|
+
maximumMemoryUsage: DEFAULT_CACHE_BYTES / BYTES_PER_MEBIBYTE,
|
|
248
|
+
memoryCacheOverflow: DEFAULT_MAXIMUM_CACHE_OVERFLOW_BYTES / BYTES_PER_MEBIBYTE,
|
|
249
|
+
maximumTilesSelected: 0,
|
|
250
|
+
debounceTime: 0,
|
|
251
|
+
onTileLoad: () => {},
|
|
252
|
+
onTileUnload: () => {},
|
|
253
|
+
onTileError: () => {},
|
|
254
|
+
onSourceError: () => {},
|
|
255
|
+
onTilesetError: () => {},
|
|
256
|
+
onTraversalComplete: (selectedTiles: Tile3D[]) => selectedTiles,
|
|
257
|
+
onUpdate: () => {},
|
|
258
|
+
contentLoader: undefined,
|
|
259
|
+
viewDistanceScale: 1.0,
|
|
260
|
+
progressiveResolutionHeightFraction: 0.3,
|
|
261
|
+
foveatedScreenSpaceError: true,
|
|
262
|
+
foveatedConeSize: 0.1,
|
|
263
|
+
foveatedMinimumScreenSpaceErrorRelaxation: 0,
|
|
264
|
+
foveatedInterpolationCallback: interpolateLinearly,
|
|
265
|
+
foveatedTimeDelay: 0.2,
|
|
266
|
+
maximumScreenSpaceError: 8,
|
|
267
|
+
dynamicScreenSpaceError: true,
|
|
268
|
+
dynamicScreenSpaceErrorDensity: 2.0e-4,
|
|
269
|
+
dynamicScreenSpaceErrorFactor: 24,
|
|
270
|
+
dynamicScreenSpaceErrorHeightFalloff: 0.25,
|
|
271
|
+
memoryAdjustedScreenSpaceError: true,
|
|
272
|
+
loadTiles: true,
|
|
273
|
+
updateTransforms: true,
|
|
274
|
+
viewportTraversersMap: null,
|
|
275
|
+
loadOptions: {fetch: {}},
|
|
276
|
+
attributions: [],
|
|
277
|
+
basePath: '',
|
|
278
|
+
i3s: {}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const TILES_TOTAL = 'Tiles In Tileset(s)';
|
|
282
|
+
const TILES_IN_MEMORY = 'Tiles In Memory';
|
|
283
|
+
const TILES_IN_VIEW = 'Tiles In View';
|
|
284
|
+
const TILES_RENDERABLE = 'Tiles To Render';
|
|
285
|
+
const TILES_LOADED = 'Tiles Loaded';
|
|
286
|
+
const TILES_LOADING = 'Tiles Loading';
|
|
287
|
+
const TILES_UNLOADED = 'Tiles Unloaded';
|
|
288
|
+
const TILES_LOAD_FAILED = 'Failed Tile Loads';
|
|
289
|
+
const POINTS_COUNT = 'Points/Vertices';
|
|
290
|
+
const TILES_GPU_MEMORY = 'Tile Memory Use';
|
|
291
|
+
const MAXIMUM_SSE = 'Maximum Screen Space Error';
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Shared runtime for tile traversal, selection, cache management, and request scheduling.
|
|
295
|
+
*
|
|
296
|
+
* Format-specific loading behavior is delegated to a {@link Tileset3DSource} implementation.
|
|
297
|
+
*/
|
|
298
|
+
export class Tileset3D {
|
|
299
|
+
options: Props;
|
|
300
|
+
loadOptions: LoaderOptions;
|
|
301
|
+
/** Source implementation responsible for format-specific initialization and loading. */
|
|
302
|
+
source: Tileset3DSource;
|
|
303
|
+
|
|
304
|
+
type: TILESET_TYPE;
|
|
305
|
+
tileset: TilesetJSON | null;
|
|
306
|
+
loader: LoaderWithParser;
|
|
307
|
+
url: string;
|
|
308
|
+
basePath: string;
|
|
309
|
+
modelMatrix: Matrix4;
|
|
310
|
+
ellipsoid: any;
|
|
311
|
+
lodMetricType: string;
|
|
312
|
+
lodMetricValue: number;
|
|
313
|
+
refine: string;
|
|
314
|
+
root: Tile3D | null = null;
|
|
315
|
+
roots: Record<string, Tile3D> = {};
|
|
316
|
+
asset: Record<string, any> = {};
|
|
317
|
+
|
|
318
|
+
description = '';
|
|
319
|
+
properties: any;
|
|
320
|
+
extras: any = null;
|
|
321
|
+
attributions: any = {};
|
|
322
|
+
credits: any = {};
|
|
323
|
+
|
|
324
|
+
stats: Stats;
|
|
325
|
+
contentFormats: TilesetContentFormats;
|
|
326
|
+
|
|
327
|
+
cartographicCenter: Vector3 | null = null;
|
|
328
|
+
cartesianCenter: Vector3 | null = null;
|
|
329
|
+
zoom = 1;
|
|
330
|
+
boundingVolume: any = null;
|
|
331
|
+
|
|
332
|
+
/** Effective dynamic SSE density calculated for the most recently traversed viewport. */
|
|
333
|
+
dynamicScreenSpaceErrorComputedDensity = 0;
|
|
334
|
+
|
|
335
|
+
/** Estimated bytes currently retained by loaded tile content. */
|
|
336
|
+
gpuMemoryUsageInBytes = 0;
|
|
337
|
+
/** Active SSE threshold after optional cache-pressure adjustment, in logical/CSS pixels. */
|
|
338
|
+
memoryAdjustedScreenSpaceError = 0.0;
|
|
339
|
+
|
|
340
|
+
private _cacheBytes = DEFAULT_CACHE_BYTES;
|
|
341
|
+
private _maximumCacheOverflowBytes = DEFAULT_MAXIMUM_CACHE_OVERFLOW_BYTES;
|
|
342
|
+
|
|
343
|
+
_frameNumber = 0;
|
|
344
|
+
private _tiles: Record<string, Tile3D> = {};
|
|
345
|
+
private _pendingCount = 0;
|
|
346
|
+
|
|
347
|
+
selectedTiles: Tile3D[] = [];
|
|
348
|
+
|
|
349
|
+
traverseCounter = 0;
|
|
350
|
+
geometricError = 0;
|
|
351
|
+
private lastUpdatedVieports: Viewport[] | Viewport | null = null;
|
|
352
|
+
private _requestedTiles: Tile3D[] = [];
|
|
353
|
+
private _emptyTiles: Tile3D[] = [];
|
|
354
|
+
private frameStateData: any = {};
|
|
355
|
+
/** Last camera pose retained independently for each viewport. */
|
|
356
|
+
private _cameraMotionStates: Record<string, CameraMotionState> = {};
|
|
357
|
+
/** Pending traversal that releases requests after camera motion settles. */
|
|
358
|
+
private _deferredTraversalTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
359
|
+
|
|
360
|
+
_traverser: TilesetTraverser;
|
|
361
|
+
_cache = new TilesetCache();
|
|
362
|
+
_requestScheduler: RequestScheduler;
|
|
363
|
+
|
|
364
|
+
private _heldTiles: Set<string> = new Set();
|
|
365
|
+
private updatePromise: Promise<number> | null = null;
|
|
366
|
+
tilesetInitializationPromise: Promise<void>;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Creates a tileset runtime from an explicit source implementation.
|
|
370
|
+
* @param source Source-backed tileset implementation.
|
|
371
|
+
* @param options Traversal and runtime options.
|
|
372
|
+
*/
|
|
373
|
+
constructor(source: Tileset3DSource, options?: Tileset3DProps) {
|
|
374
|
+
if (!isTileset3DSource(source)) {
|
|
375
|
+
throw new Error('Tileset3D requires a Tileset3DSource instance');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const suppliedOptions = options || {};
|
|
379
|
+
const usesTiles3DCacheDefaults = source.type === TILESET_TYPE.TILES3D;
|
|
380
|
+
const defaultCacheBytes = usesTiles3DCacheDefaults
|
|
381
|
+
? DEFAULT_PROPS.cacheBytes
|
|
382
|
+
: DEFAULT_I3S_CACHE_BYTES;
|
|
383
|
+
const defaultMaximumCacheOverflowBytes = usesTiles3DCacheDefaults
|
|
384
|
+
? DEFAULT_PROPS.maximumCacheOverflowBytes
|
|
385
|
+
: DEFAULT_I3S_MAXIMUM_CACHE_OVERFLOW_BYTES;
|
|
386
|
+
const cacheBytes = resolveCacheBytes(suppliedOptions, defaultCacheBytes);
|
|
387
|
+
const maximumCacheOverflowBytes = resolveMaximumCacheOverflowBytes(
|
|
388
|
+
suppliedOptions,
|
|
389
|
+
defaultMaximumCacheOverflowBytes
|
|
390
|
+
);
|
|
391
|
+
this.options = {
|
|
392
|
+
...DEFAULT_PROPS,
|
|
393
|
+
...suppliedOptions,
|
|
394
|
+
cacheBytes,
|
|
395
|
+
maximumCacheOverflowBytes,
|
|
396
|
+
maximumMemoryUsage: cacheBytes / BYTES_PER_MEBIBYTE,
|
|
397
|
+
memoryCacheOverflow: maximumCacheOverflowBytes / BYTES_PER_MEBIBYTE,
|
|
398
|
+
memoryAdjustedScreenSpaceError:
|
|
399
|
+
suppliedOptions.memoryAdjustedScreenSpaceError ?? usesTiles3DCacheDefaults
|
|
400
|
+
};
|
|
401
|
+
this.loadOptions = this.options.loadOptions || {};
|
|
402
|
+
this.source = source;
|
|
403
|
+
|
|
404
|
+
this.tileset = null;
|
|
405
|
+
this.loader = this.source.loader;
|
|
406
|
+
this.type = this.source.type;
|
|
407
|
+
this.url = this.source.url;
|
|
408
|
+
this.basePath = this.source.basePath;
|
|
409
|
+
this.modelMatrix = this.options.modelMatrix;
|
|
410
|
+
this.ellipsoid = this.options.ellipsoid;
|
|
411
|
+
this.lodMetricType = '';
|
|
412
|
+
this.lodMetricValue = 0;
|
|
413
|
+
this.refine = '';
|
|
414
|
+
this.contentFormats = this.source.contentFormats;
|
|
415
|
+
|
|
416
|
+
this._traverser = this._initializeTraverser();
|
|
417
|
+
this._requestScheduler = new RequestScheduler({
|
|
418
|
+
throttleRequests: this.options.throttleRequests,
|
|
419
|
+
maxRequests: this.options.maxRequests
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
this.memoryAdjustedScreenSpaceError = this.options.maximumScreenSpaceError;
|
|
423
|
+
this._cacheBytes = cacheBytes;
|
|
424
|
+
this._maximumCacheOverflowBytes = maximumCacheOverflowBytes;
|
|
425
|
+
|
|
426
|
+
this.stats = new Stats({id: this.url});
|
|
427
|
+
this._initializeStats();
|
|
428
|
+
|
|
429
|
+
this.tilesetInitializationPromise = this._initializeTileSet();
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
destroy(): void {
|
|
433
|
+
this._clearDeferredTraversal();
|
|
434
|
+
this.source.destroy?.();
|
|
435
|
+
this._destroy();
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
isLoaded(): boolean {
|
|
439
|
+
return this._pendingCount === 0 && this._frameNumber !== 0 && this._requestedTiles.length === 0;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
get tiles(): object[] {
|
|
443
|
+
return Object.values(this._tiles);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
get frameNumber(): number {
|
|
447
|
+
return this._frameNumber;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Gets or sets the soft target, in bytes, for cached tile content not needed this frame.
|
|
452
|
+
*
|
|
453
|
+
* Current-frame tiles remain protected even when their estimated memory exceeds this target.
|
|
454
|
+
* Reducing the value makes unused least-recently-used tiles eligible for eviction on the next
|
|
455
|
+
* traversal.
|
|
456
|
+
* @default 536870912 for 3D Tiles; 33554432 for I3S
|
|
457
|
+
*/
|
|
458
|
+
get cacheBytes(): number {
|
|
459
|
+
return this._cacheBytes;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
set cacheBytes(value: number) {
|
|
463
|
+
this._cacheBytes = validateCacheByteLength(value, 'cacheBytes');
|
|
464
|
+
this.options.cacheBytes = this._cacheBytes;
|
|
465
|
+
this.options.maximumMemoryUsage = this._cacheBytes / BYTES_PER_MEBIBYTE;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Gets or sets the additional current-frame headroom, in bytes, before memory-adjusted SSE rises.
|
|
470
|
+
*
|
|
471
|
+
* The pressure ceiling is `cacheBytes + maximumCacheOverflowBytes`. This value does not change
|
|
472
|
+
* the base target used to evict tiles that were not touched in the current frame.
|
|
473
|
+
* @default 536870912 for 3D Tiles; 1048576 for I3S
|
|
474
|
+
*/
|
|
475
|
+
get maximumCacheOverflowBytes(): number {
|
|
476
|
+
return this._maximumCacheOverflowBytes;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
set maximumCacheOverflowBytes(value: number) {
|
|
480
|
+
this._maximumCacheOverflowBytes = validateCacheByteLength(value, 'maximumCacheOverflowBytes');
|
|
481
|
+
this.options.maximumCacheOverflowBytes = this._maximumCacheOverflowBytes;
|
|
482
|
+
this.options.memoryCacheOverflow = this._maximumCacheOverflowBytes / BYTES_PER_MEBIBYTE;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Gets or sets the soft cache target in mebibytes.
|
|
487
|
+
* @deprecated Use {@link Tileset3D.cacheBytes}. Assignments remain synchronized for compatibility.
|
|
488
|
+
*/
|
|
489
|
+
get maximumMemoryUsage(): number {
|
|
490
|
+
return this.cacheBytes / BYTES_PER_MEBIBYTE;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
set maximumMemoryUsage(value: number) {
|
|
494
|
+
this.cacheBytes = validateCacheByteLength(value * BYTES_PER_MEBIBYTE, 'maximumMemoryUsage');
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
get queryParams(): string {
|
|
498
|
+
const rootUrl = this.source.getTileUrl(this.url);
|
|
499
|
+
const queryIndex = rootUrl.indexOf('?');
|
|
500
|
+
return queryIndex >= 0 ? rootUrl.slice(queryIndex + 1) : '';
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Updates traversal and runtime options, synchronizing byte-native and deprecated cache values.
|
|
505
|
+
*
|
|
506
|
+
* For each budget, the byte-native option takes precedence when both unit forms are supplied.
|
|
507
|
+
* Unspecified budgets retain their current byte values, avoiding repeated MiB conversion.
|
|
508
|
+
*
|
|
509
|
+
* @param props - Partial runtime options to apply.
|
|
510
|
+
*/
|
|
511
|
+
setProps(props: Tileset3DProps): void {
|
|
512
|
+
const cacheBytes = resolveCacheBytes(props, this.cacheBytes);
|
|
513
|
+
const maximumCacheOverflowBytes = resolveMaximumCacheOverflowBytes(
|
|
514
|
+
props,
|
|
515
|
+
this.maximumCacheOverflowBytes
|
|
516
|
+
);
|
|
517
|
+
this.options = {
|
|
518
|
+
...this.options,
|
|
519
|
+
...props,
|
|
520
|
+
cacheBytes,
|
|
521
|
+
maximumCacheOverflowBytes,
|
|
522
|
+
maximumMemoryUsage: cacheBytes / BYTES_PER_MEBIBYTE,
|
|
523
|
+
memoryCacheOverflow: maximumCacheOverflowBytes / BYTES_PER_MEBIBYTE
|
|
524
|
+
};
|
|
525
|
+
this._cacheBytes = cacheBytes;
|
|
526
|
+
this._maximumCacheOverflowBytes = maximumCacheOverflowBytes;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
getTileUrl(tilePath: string): string {
|
|
530
|
+
return this.source.getTileUrl(tilePath);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
hasExtension(extensionName: string): boolean {
|
|
534
|
+
return Boolean(this.source.hasExtension?.(extensionName));
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
update(viewports: Viewport[] | Viewport | null = null): void {
|
|
538
|
+
this.tilesetInitializationPromise.then(() => {
|
|
539
|
+
if (!viewports && this.lastUpdatedVieports) {
|
|
540
|
+
viewports = this.lastUpdatedVieports;
|
|
541
|
+
} else {
|
|
542
|
+
this.lastUpdatedVieports = viewports;
|
|
543
|
+
}
|
|
544
|
+
if (viewports) {
|
|
545
|
+
this.doUpdate(viewports);
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
async selectTiles(viewports: Viewport[] | Viewport | null = null): Promise<number> {
|
|
551
|
+
await this.tilesetInitializationPromise;
|
|
552
|
+
if (viewports) {
|
|
553
|
+
this.lastUpdatedVieports = viewports;
|
|
554
|
+
}
|
|
555
|
+
if (!this.updatePromise) {
|
|
556
|
+
this.updatePromise = new Promise<number>(resolve => {
|
|
557
|
+
setTimeout(() => {
|
|
558
|
+
if (this.lastUpdatedVieports) {
|
|
559
|
+
this.doUpdate(this.lastUpdatedVieports);
|
|
560
|
+
}
|
|
561
|
+
resolve(this._frameNumber);
|
|
562
|
+
this.updatePromise = null;
|
|
563
|
+
}, this.options.debounceTime);
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
return this.updatePromise;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Moves the active LOD threshold toward the configured SSE or away from cache pressure.
|
|
571
|
+
*
|
|
572
|
+
* Usage below {@link Tileset3D.cacheBytes} restores quality in two-percent steps. Usage above
|
|
573
|
+
* `cacheBytes + maximumCacheOverflowBytes` reduces refinement in two-percent steps. Values in
|
|
574
|
+
* the overflow window leave the threshold unchanged, preventing rapid load/evict oscillation.
|
|
575
|
+
*/
|
|
576
|
+
adjustScreenSpaceError(): void {
|
|
577
|
+
if (this.gpuMemoryUsageInBytes < this.cacheBytes) {
|
|
578
|
+
this.memoryAdjustedScreenSpaceError = Math.max(
|
|
579
|
+
this.memoryAdjustedScreenSpaceError / 1.02,
|
|
580
|
+
this.options.maximumScreenSpaceError
|
|
581
|
+
);
|
|
582
|
+
} else if (this.gpuMemoryUsageInBytes > this.cacheBytes + this.maximumCacheOverflowBytes) {
|
|
583
|
+
this.memoryAdjustedScreenSpaceError *= 1.02;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
private doUpdate(viewports: Viewport[] | Viewport): void {
|
|
588
|
+
if ('loadTiles' in this.options && !this.options.loadTiles) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (this.traverseCounter > 0) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const preparedViewports = viewports instanceof Array ? viewports : [viewports];
|
|
595
|
+
|
|
596
|
+
this._cache.reset();
|
|
597
|
+
this._frameNumber++;
|
|
598
|
+
this.traverseCounter = preparedViewports.length;
|
|
599
|
+
const currentTime = Date.now();
|
|
600
|
+
let minimumDeferredTraversalDelay = Number.POSITIVE_INFINITY;
|
|
601
|
+
const viewportsToTraverse: string[] = [];
|
|
602
|
+
for (const viewport of preparedViewports) {
|
|
603
|
+
const id = viewport.id;
|
|
604
|
+
if (this._needTraverse(id)) {
|
|
605
|
+
viewportsToTraverse.push(id);
|
|
606
|
+
} else {
|
|
607
|
+
this.traverseCounter--;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
for (const viewport of preparedViewports) {
|
|
612
|
+
const id = viewport.id;
|
|
613
|
+
if (!this.roots[id]) {
|
|
614
|
+
this.roots[id] = this._initializeTileHeaders(this.tileset, null);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (!viewportsToTraverse.includes(id)) {
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
const frameState = getFrameState(viewport as GeospatialViewport, this._frameNumber);
|
|
621
|
+
const root = this.roots[id];
|
|
622
|
+
const cameraMotionUpdate = updateCameraMotionState(
|
|
623
|
+
this._cameraMotionStates[id],
|
|
624
|
+
frameState.camera.position,
|
|
625
|
+
frameState.camera.direction,
|
|
626
|
+
currentTime
|
|
627
|
+
);
|
|
628
|
+
this._cameraMotionStates[id] = cameraMotionUpdate.state;
|
|
629
|
+
frameState.camera.timeSinceMovement = cameraMotionUpdate.timeSinceMovement;
|
|
630
|
+
// Dynamic SSE reads the root's inverse computed transform before traversal updates tile
|
|
631
|
+
// visibility. Refresh it from the current tileset model matrix here so animated local
|
|
632
|
+
// box/sphere tilesets never calculate their height falloff one transform behind the frame.
|
|
633
|
+
updateRootTransformForDynamicScreenSpaceError(root, this.modelMatrix);
|
|
634
|
+
frameState.dynamicScreenSpaceErrorDensity =
|
|
635
|
+
this.type === TILESET_TYPE.TILES3D &&
|
|
636
|
+
this.options.dynamicScreenSpaceError &&
|
|
637
|
+
!frameState.viewport.orthographic
|
|
638
|
+
? calculateDynamicScreenSpaceErrorDensity(root, frameState, this.options)
|
|
639
|
+
: 0;
|
|
640
|
+
// Keep the legacy diagnostic field, but traversal reads the per-viewport frame value above.
|
|
641
|
+
this.dynamicScreenSpaceErrorComputedDensity = frameState.dynamicScreenSpaceErrorDensity;
|
|
642
|
+
this._traverser.traverse(root, frameState, this.options);
|
|
643
|
+
if (Object.keys(this._traverser.deferredTiles).length > 0) {
|
|
644
|
+
minimumDeferredTraversalDelay = Math.min(
|
|
645
|
+
minimumDeferredTraversalDelay,
|
|
646
|
+
Math.max(this.options.foveatedTimeDelay - cameraMotionUpdate.timeSinceMovement, 0)
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (Number.isFinite(minimumDeferredTraversalDelay)) {
|
|
652
|
+
this._scheduleDeferredTraversal(minimumDeferredTraversalDelay);
|
|
653
|
+
} else {
|
|
654
|
+
this._clearDeferredTraversal();
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Schedules one follow-up traversal when the moving-camera deferral window expires.
|
|
660
|
+
*
|
|
661
|
+
* Replacing an existing timer ensures continuing camera movement pushes the retry window forward
|
|
662
|
+
* instead of creating a queue of redundant traversals.
|
|
663
|
+
*
|
|
664
|
+
* @param delayInSeconds - Remaining stationary delay before deferred requests become eligible.
|
|
665
|
+
*/
|
|
666
|
+
private _scheduleDeferredTraversal(delayInSeconds: number): void {
|
|
667
|
+
this._clearDeferredTraversal();
|
|
668
|
+
this._deferredTraversalTimeout = setTimeout(
|
|
669
|
+
() => {
|
|
670
|
+
this._deferredTraversalTimeout = null;
|
|
671
|
+
this.selectTiles().catch((error: unknown) => {
|
|
672
|
+
const traversalError = error instanceof Error ? error : new Error(String(error));
|
|
673
|
+
this._onTilesetError(traversalError);
|
|
674
|
+
});
|
|
675
|
+
},
|
|
676
|
+
Math.max(delayInSeconds * 1000, 0)
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/** Clears a pending moving-camera follow-up traversal. */
|
|
681
|
+
private _clearDeferredTraversal(): void {
|
|
682
|
+
if (this._deferredTraversalTimeout !== null) {
|
|
683
|
+
clearTimeout(this._deferredTraversalTimeout);
|
|
684
|
+
this._deferredTraversalTimeout = null;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
_needTraverse(viewportId: string): boolean {
|
|
689
|
+
let traverserId = viewportId;
|
|
690
|
+
if (this.options.viewportTraversersMap) {
|
|
691
|
+
traverserId = this.options.viewportTraversersMap[viewportId];
|
|
692
|
+
}
|
|
693
|
+
return traverserId === viewportId;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
_onTraversalEnd(frameState: FrameState): void {
|
|
697
|
+
const id = frameState.viewport.id;
|
|
698
|
+
if (!this.frameStateData[id]) {
|
|
699
|
+
this.frameStateData[id] = {selectedTiles: [], _requestedTiles: [], _emptyTiles: []};
|
|
700
|
+
}
|
|
701
|
+
const currentFrameStateData = this.frameStateData[id];
|
|
702
|
+
const selectedTiles = Object.values(this._traverser.selectedTiles);
|
|
703
|
+
const [filteredSelectedTiles, unselectedTiles] = limitSelectedTiles(
|
|
704
|
+
selectedTiles,
|
|
705
|
+
frameState,
|
|
706
|
+
this.options.maximumTilesSelected
|
|
707
|
+
);
|
|
708
|
+
currentFrameStateData.selectedTiles = filteredSelectedTiles;
|
|
709
|
+
for (const tile of unselectedTiles) {
|
|
710
|
+
tile.unselect();
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
currentFrameStateData._requestedTiles = Object.values(this._traverser.requestedTiles);
|
|
714
|
+
currentFrameStateData._emptyTiles = Object.values(this._traverser.emptyTiles);
|
|
715
|
+
|
|
716
|
+
this.traverseCounter--;
|
|
717
|
+
if (this.traverseCounter > 0) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
this._updateTiles();
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
_updateTiles(): void {
|
|
725
|
+
const previousSelectedTiles = this.selectedTiles;
|
|
726
|
+
this.selectedTiles = [];
|
|
727
|
+
this._requestedTiles = [];
|
|
728
|
+
this._emptyTiles = [];
|
|
729
|
+
|
|
730
|
+
for (const frameStateKey in this.frameStateData) {
|
|
731
|
+
const frameStateDataValue = this.frameStateData[frameStateKey];
|
|
732
|
+
this.selectedTiles = this.selectedTiles.concat(frameStateDataValue.selectedTiles);
|
|
733
|
+
this._requestedTiles = this._requestedTiles.concat(frameStateDataValue._requestedTiles);
|
|
734
|
+
this._emptyTiles = this._emptyTiles.concat(frameStateDataValue._emptyTiles);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
this.selectedTiles = this.options.onTraversalComplete(this.selectedTiles);
|
|
738
|
+
|
|
739
|
+
const selectedIds = new Set(this.selectedTiles.map(tile => tile.id));
|
|
740
|
+
const hasUndrawnTiles = this.selectedTiles.some(tile => !tile.tileDrawn);
|
|
741
|
+
|
|
742
|
+
let heldBackCount = 0;
|
|
743
|
+
if (hasUndrawnTiles) {
|
|
744
|
+
for (const tileId of selectedIds) {
|
|
745
|
+
this._heldTiles.add(tileId);
|
|
746
|
+
}
|
|
747
|
+
for (const tileId of this._heldTiles) {
|
|
748
|
+
if (selectedIds.has(tileId)) continue;
|
|
749
|
+
|
|
750
|
+
const tile = this._tiles[tileId];
|
|
751
|
+
if (tile && tile.contentAvailable) {
|
|
752
|
+
tile._selectedFrame = this._frameNumber;
|
|
753
|
+
this.selectedTiles.push(tile);
|
|
754
|
+
heldBackCount++;
|
|
755
|
+
} else {
|
|
756
|
+
this._heldTiles.delete(tileId);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
} else {
|
|
760
|
+
this._heldTiles = selectedIds;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
if (heldBackCount > 0) {
|
|
764
|
+
setTimeout(() => {
|
|
765
|
+
this.selectTiles();
|
|
766
|
+
}, 0);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
for (const tile of this.selectedTiles) {
|
|
770
|
+
this._tiles[tile.id] = tile;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
this._loadTiles();
|
|
774
|
+
this._unloadTiles();
|
|
775
|
+
this._updateStats();
|
|
776
|
+
|
|
777
|
+
if (this._tilesChanged(previousSelectedTiles, this.selectedTiles)) {
|
|
778
|
+
this.options.onUpdate();
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
_tilesChanged(oldSelectedTiles: Tile3D[], selectedTiles: Tile3D[]): boolean {
|
|
783
|
+
if (oldSelectedTiles.length !== selectedTiles.length) {
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
const oldSet = new Set(oldSelectedTiles.map(tile => tile.id));
|
|
787
|
+
const newSet = new Set(selectedTiles.map(tile => tile.id));
|
|
788
|
+
let changed = oldSelectedTiles.some(tile => !newSet.has(tile.id));
|
|
789
|
+
changed = changed || selectedTiles.some(tile => !oldSet.has(tile.id));
|
|
790
|
+
return changed;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
_loadTiles(): void {
|
|
794
|
+
this._requestedTiles.sort((tileA, tileB) => tileA._priority - tileB._priority);
|
|
795
|
+
for (const tile of this._requestedTiles) {
|
|
796
|
+
if (tile.contentUnloaded) {
|
|
797
|
+
this._loadTile(tile);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
_unloadTiles(): void {
|
|
803
|
+
this._cache.unloadTiles(this, (tileset, tile) => tileset._unloadTile(tile));
|
|
804
|
+
if (this.options.memoryAdjustedScreenSpaceError) {
|
|
805
|
+
this.adjustScreenSpaceError();
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
_updateStats(): void {
|
|
810
|
+
let tilesRenderable = 0;
|
|
811
|
+
let pointsRenderable = 0;
|
|
812
|
+
for (const tile of this.selectedTiles) {
|
|
813
|
+
if (tile.contentAvailable && tile.content) {
|
|
814
|
+
tilesRenderable++;
|
|
815
|
+
if (tile.content.pointCount) {
|
|
816
|
+
pointsRenderable += tile.content.pointCount;
|
|
817
|
+
} else {
|
|
818
|
+
pointsRenderable += tile.content.vertexCount;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length;
|
|
824
|
+
this.stats.get(TILES_RENDERABLE).count = tilesRenderable;
|
|
825
|
+
this.stats.get(POINTS_COUNT).count = pointsRenderable;
|
|
826
|
+
this.stats.get(MAXIMUM_SSE).count = this.memoryAdjustedScreenSpaceError;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
async _initializeTileSet(): Promise<void> {
|
|
830
|
+
try {
|
|
831
|
+
const initializePromise = this.source.initialize();
|
|
832
|
+
const initialMetadata = this._getSourceMetadata();
|
|
833
|
+
if (initialMetadata) {
|
|
834
|
+
this._syncSourceState(initialMetadata);
|
|
835
|
+
}
|
|
836
|
+
if (
|
|
837
|
+
initialMetadata?.tileset?.root &&
|
|
838
|
+
typeof initialMetadata.tileset.root.then !== 'function'
|
|
839
|
+
) {
|
|
840
|
+
this.root = this._initializeTileHeaders(initialMetadata.tileset, null);
|
|
841
|
+
this._applyViewState();
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
await initializePromise;
|
|
845
|
+
const metadata = this.source.getMetadata();
|
|
846
|
+
this._syncSourceState(metadata);
|
|
847
|
+
if (!this.root) {
|
|
848
|
+
this.root = this._initializeTileHeaders(metadata.tileset, null);
|
|
849
|
+
}
|
|
850
|
+
this._applyViewState();
|
|
851
|
+
} catch (error: unknown) {
|
|
852
|
+
const sourceError = error instanceof Error ? error : new Error(String(error));
|
|
853
|
+
this._onSourceError(sourceError, this.root);
|
|
854
|
+
this._onTilesetError(sourceError);
|
|
855
|
+
throw sourceError;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
_initializeStats(): void {
|
|
860
|
+
this.stats.get(TILES_TOTAL);
|
|
861
|
+
this.stats.get(TILES_LOADING);
|
|
862
|
+
this.stats.get(TILES_IN_MEMORY);
|
|
863
|
+
this.stats.get(TILES_IN_VIEW);
|
|
864
|
+
this.stats.get(TILES_RENDERABLE);
|
|
865
|
+
this.stats.get(TILES_LOADED);
|
|
866
|
+
this.stats.get(TILES_UNLOADED);
|
|
867
|
+
this.stats.get(TILES_LOAD_FAILED);
|
|
868
|
+
this.stats.get(POINTS_COUNT);
|
|
869
|
+
this.stats.get(TILES_GPU_MEMORY, 'memory');
|
|
870
|
+
this.stats.get(MAXIMUM_SSE);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
_initializeTileHeaders(tilesetJson: TilesetJSON, parentTileHeader?: Tile3D | null): Tile3D {
|
|
874
|
+
return this.source.initializeTileHeaders(this, tilesetJson, parentTileHeader);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
_initializeTraverser(): TilesetTraverser {
|
|
878
|
+
return this.source.createTraverser({
|
|
879
|
+
basePath: this.basePath,
|
|
880
|
+
onTraversalEnd: this._onTraversalEnd.bind(this)
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
_destroyTileHeaders(parentTile: Tile3D): void {
|
|
885
|
+
this._destroySubtree(parentTile);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
async _loadTile(tile: Tile3D): Promise<void> {
|
|
889
|
+
let loadResult: TileContentLoadResult | null = null;
|
|
890
|
+
try {
|
|
891
|
+
this._onStartTileLoading();
|
|
892
|
+
loadResult = await tile.loadContent();
|
|
893
|
+
} catch (error: unknown) {
|
|
894
|
+
const tileError = error instanceof Error ? error : new Error('load failed');
|
|
895
|
+
this._onSourceError(tileError, tile);
|
|
896
|
+
this._onTileLoadError(tile, tileError);
|
|
897
|
+
} finally {
|
|
898
|
+
this._onEndTileLoading();
|
|
899
|
+
this._onTileLoad(tile, loadResult);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Loads a source-managed lazy child-header group and reports failures through tile callbacks.
|
|
905
|
+
*
|
|
906
|
+
* Subtree metadata shares the normal loading counters but is not reported as render content and
|
|
907
|
+
* is not added to the GPU cache. Traversal is notified separately after the promise settles.
|
|
908
|
+
*
|
|
909
|
+
* @param tile - Runtime tile that owns the lazy subtree reference.
|
|
910
|
+
* @param frameState - View state that made the subtree eligible for refinement.
|
|
911
|
+
*/
|
|
912
|
+
async _loadTileChildren(tile: Tile3D, frameState: FrameState): Promise<void> {
|
|
913
|
+
try {
|
|
914
|
+
this._onStartTileLoading();
|
|
915
|
+
await tile.loadChildren(frameState);
|
|
916
|
+
} catch (error: unknown) {
|
|
917
|
+
const tileError = error instanceof Error ? error : new Error('subtree load failed');
|
|
918
|
+
this._onSourceError(tileError, tile);
|
|
919
|
+
this._onTileLoadError(tile, tileError);
|
|
920
|
+
} finally {
|
|
921
|
+
this._onEndTileLoading();
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
_onTileLoadError(tile: Tile3D, error: Error): void {
|
|
926
|
+
this.stats.get(TILES_LOAD_FAILED).incrementCount();
|
|
927
|
+
|
|
928
|
+
const message = error.message || error.toString();
|
|
929
|
+
const url = tile.url;
|
|
930
|
+
console.error(`A 3D tile failed to load: ${tile.url} ${message}`);
|
|
931
|
+
this.options.onTileError(tile, message, url);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
_onSourceError(error: Error, tile: Tile3D | null = null): void {
|
|
935
|
+
this.options.onSourceError(error, this.source, tile);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
_onTilesetError(error: Error): void {
|
|
939
|
+
this.options.onTilesetError(error, this);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
_onTileLoad(tile: Tile3D, loadResult: TileContentLoadResult | null): void {
|
|
943
|
+
if (!loadResult?.loaded) {
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
if (tile.content) {
|
|
948
|
+
calculateTransformProps(tile, tile.content);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
this.source.onTileLoaded?.(this, tile, loadResult);
|
|
952
|
+
this._syncSourceState(this.source.getMetadata());
|
|
953
|
+
|
|
954
|
+
const totalTiles = this.source.getTilesTotalCount?.();
|
|
955
|
+
if (totalTiles) {
|
|
956
|
+
this.stats.get(TILES_TOTAL).reset();
|
|
957
|
+
this.stats.get(TILES_TOTAL).addCount(totalTiles);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
this._addTileToCache(tile);
|
|
961
|
+
this.options.onTileLoad(tile);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
_onStartTileLoading(): void {
|
|
965
|
+
this._pendingCount++;
|
|
966
|
+
this.stats.get(TILES_LOADING).incrementCount();
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
_onEndTileLoading(): void {
|
|
970
|
+
this._pendingCount--;
|
|
971
|
+
this.stats.get(TILES_LOADING).decrementCount();
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
_addTileToCache(tile: Tile3D): void {
|
|
975
|
+
this._cache.add(this, tile, tileset => tileset._updateCacheStats(tile));
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
_updateCacheStats(tile: Tile3D): void {
|
|
979
|
+
this.stats.get(TILES_LOADED).incrementCount();
|
|
980
|
+
this.stats.get(TILES_IN_MEMORY).incrementCount();
|
|
981
|
+
|
|
982
|
+
this.gpuMemoryUsageInBytes += tile.gpuMemoryUsageInBytes || 0;
|
|
983
|
+
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
|
|
984
|
+
|
|
985
|
+
if (this.options.memoryAdjustedScreenSpaceError) {
|
|
986
|
+
this.adjustScreenSpaceError();
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
_unloadTile(tile: Tile3D): void {
|
|
991
|
+
this.gpuMemoryUsageInBytes -= tile.gpuMemoryUsageInBytes || 0;
|
|
992
|
+
|
|
993
|
+
this.stats.get(TILES_IN_MEMORY).decrementCount();
|
|
994
|
+
this.stats.get(TILES_UNLOADED).incrementCount();
|
|
995
|
+
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
|
|
996
|
+
|
|
997
|
+
this.options.onTileUnload(tile);
|
|
998
|
+
tile.unloadContent();
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
_destroy(): void {
|
|
1002
|
+
const stack: Tile3D[] = [];
|
|
1003
|
+
|
|
1004
|
+
if (this.root) {
|
|
1005
|
+
stack.push(this.root);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
while (stack.length > 0) {
|
|
1009
|
+
const tile = stack.pop() as Tile3D;
|
|
1010
|
+
|
|
1011
|
+
for (const child of tile.children) {
|
|
1012
|
+
stack.push(child);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
this._destroyTile(tile);
|
|
1016
|
+
}
|
|
1017
|
+
this.root = null;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
_destroySubtree(tile: Tile3D): void {
|
|
1021
|
+
const rootTile = tile;
|
|
1022
|
+
const stack: Tile3D[] = [rootTile];
|
|
1023
|
+
while (stack.length > 0) {
|
|
1024
|
+
tile = stack.pop() as Tile3D;
|
|
1025
|
+
for (const child of tile.children) {
|
|
1026
|
+
stack.push(child);
|
|
1027
|
+
}
|
|
1028
|
+
if (tile !== rootTile) {
|
|
1029
|
+
this._destroyTile(tile);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
rootTile.children = [];
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
_destroyTile(tile: Tile3D): void {
|
|
1036
|
+
this._cache.unloadTile(this, tile);
|
|
1037
|
+
this._unloadTile(tile);
|
|
1038
|
+
tile.destroy();
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
private _syncSourceState(metadata: TilesetSourceMetadata): void {
|
|
1042
|
+
this.tileset = metadata.tileset;
|
|
1043
|
+
this.loader = metadata.loader;
|
|
1044
|
+
this.type = metadata.type;
|
|
1045
|
+
this.url = metadata.url;
|
|
1046
|
+
this.basePath = metadata.basePath;
|
|
1047
|
+
this.lodMetricType = metadata.lodMetricType;
|
|
1048
|
+
this.lodMetricValue = metadata.lodMetricValue;
|
|
1049
|
+
this.refine = metadata.refine;
|
|
1050
|
+
this.contentFormats = this.source.contentFormats;
|
|
1051
|
+
this.asset = this.source.asset || this.asset;
|
|
1052
|
+
this.properties = this.source.properties ?? this.properties;
|
|
1053
|
+
this.extras = this.source.extras ?? this.extras;
|
|
1054
|
+
if (this.options.attributions?.length) {
|
|
1055
|
+
this.credits = {attributions: this.options.attributions};
|
|
1056
|
+
} else {
|
|
1057
|
+
this.credits = this.source.credits || this.credits;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
private _applyViewState(): void {
|
|
1062
|
+
const viewState = this.source.getViewState(this.root);
|
|
1063
|
+
this.asset = viewState.asset || this.source.asset || {};
|
|
1064
|
+
this.properties = viewState.properties ?? this.source.properties;
|
|
1065
|
+
this.extras = viewState.extras ?? this.source.extras ?? null;
|
|
1066
|
+
this.credits = viewState.credits ||
|
|
1067
|
+
this.source.credits ||
|
|
1068
|
+
this.credits || {attributions: this.options.attributions || []};
|
|
1069
|
+
this.description = viewState.description || this.options.description || '';
|
|
1070
|
+
this.boundingVolume = viewState.boundingVolume || this.root?.boundingVolume || null;
|
|
1071
|
+
this.cartographicCenter = viewState.cartographicCenter || new Vector3();
|
|
1072
|
+
this.cartesianCenter = viewState.cartesianCenter || null;
|
|
1073
|
+
this.zoom = viewState.zoom || 1;
|
|
1074
|
+
this.geometricError = this.tileset?.geometricError || 0;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Returns normalized source metadata when initialization has already populated it.
|
|
1079
|
+
*/
|
|
1080
|
+
private _getSourceMetadata(): TilesetSourceMetadata | null {
|
|
1081
|
+
try {
|
|
1082
|
+
return this.source.getMetadata();
|
|
1083
|
+
} catch {
|
|
1084
|
+
return null;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|