@loaders.gl/tiles 4.0.0-alpha.4 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +30 -26
- package/dist/dist.min.js +8921 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/constants.js +44 -0
- package/dist/es5/constants.js.map +1 -0
- package/dist/es5/index.js +93 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/tileset/format-3d-tiles/tileset-3d-traverser.js +70 -0
- package/dist/es5/tileset/format-3d-tiles/tileset-3d-traverser.js.map +1 -0
- package/dist/es5/tileset/format-i3s/i3s-pending-tiles-register.js +45 -0
- package/dist/es5/tileset/format-i3s/i3s-pending-tiles-register.js.map +1 -0
- package/dist/es5/tileset/format-i3s/i3s-tile-manager.js +84 -0
- package/dist/es5/tileset/format-i3s/i3s-tile-manager.js.map +1 -0
- package/dist/es5/tileset/format-i3s/i3s-tileset-traverser.js +143 -0
- package/dist/es5/tileset/format-i3s/i3s-tileset-traverser.js.map +1 -0
- package/dist/es5/tileset/helpers/3d-tiles-options.js +12 -0
- package/dist/es5/tileset/helpers/3d-tiles-options.js.map +1 -0
- package/dist/es5/tileset/helpers/bounding-volume.js +176 -0
- package/dist/es5/tileset/helpers/bounding-volume.js.map +1 -0
- package/dist/es5/tileset/helpers/frame-state.js +129 -0
- package/dist/es5/tileset/helpers/frame-state.js.map +1 -0
- package/dist/es5/tileset/helpers/i3s-lod.js +60 -0
- package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -0
- package/dist/es5/tileset/helpers/tiles-3d-lod.js +103 -0
- package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +1 -0
- package/dist/es5/tileset/helpers/transform-utils.js +50 -0
- package/dist/es5/tileset/helpers/transform-utils.js.map +1 -0
- package/dist/es5/tileset/helpers/zoom.js +63 -0
- package/dist/es5/tileset/helpers/zoom.js.map +1 -0
- package/dist/es5/tileset/tile-3d.js +565 -0
- package/dist/es5/tileset/tile-3d.js.map +1 -0
- package/dist/es5/tileset/tileset-3d.js +890 -0
- package/dist/es5/tileset/tileset-3d.js.map +1 -0
- package/dist/es5/tileset/tileset-cache.js +85 -0
- package/dist/es5/tileset/tileset-cache.js.map +1 -0
- package/dist/es5/tileset/tileset-traverser.js +328 -0
- package/dist/es5/tileset/tileset-traverser.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/utils/doubly-linked-list-node.js +21 -0
- package/dist/es5/utils/doubly-linked-list-node.js.map +1 -0
- package/dist/es5/utils/doubly-linked-list.js +88 -0
- package/dist/es5/utils/doubly-linked-list.js.map +1 -0
- package/dist/es5/utils/managed-array.js +126 -0
- package/dist/es5/utils/managed-array.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/constants.js +32 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/{tileset/traversers → esm/tileset/format-3d-tiles}/tileset-3d-traverser.js +2 -13
- package/dist/esm/tileset/format-3d-tiles/tileset-3d-traverser.js.map +1 -0
- package/dist/esm/tileset/format-i3s/i3s-pending-tiles-register.js +26 -0
- package/dist/esm/tileset/format-i3s/i3s-pending-tiles-register.js.map +1 -0
- package/dist/esm/tileset/format-i3s/i3s-tile-manager.js +79 -0
- package/dist/esm/tileset/format-i3s/i3s-tile-manager.js.map +1 -0
- package/dist/{tileset/traversers → esm/tileset/format-i3s}/i3s-tileset-traverser.js +16 -28
- package/dist/esm/tileset/format-i3s/i3s-tileset-traverser.js.map +1 -0
- package/dist/esm/tileset/helpers/3d-tiles-options.js +6 -0
- package/dist/esm/tileset/helpers/3d-tiles-options.js.map +1 -0
- package/dist/esm/tileset/helpers/bounding-volume.js +155 -0
- package/dist/esm/tileset/helpers/bounding-volume.js.map +1 -0
- package/dist/esm/tileset/helpers/frame-state.js +109 -0
- package/dist/esm/tileset/helpers/frame-state.js.map +1 -0
- package/dist/esm/tileset/helpers/i3s-lod.js +53 -0
- package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -0
- package/dist/esm/tileset/helpers/tiles-3d-lod.js +100 -0
- package/dist/{tileset → esm/tileset}/helpers/tiles-3d-lod.js.map +1 -1
- package/dist/esm/tileset/helpers/transform-utils.js +50 -0
- package/dist/esm/tileset/helpers/transform-utils.js.map +1 -0
- package/dist/esm/tileset/helpers/zoom.js +55 -0
- package/dist/esm/tileset/helpers/zoom.js.map +1 -0
- package/dist/esm/tileset/tile-3d.js +445 -0
- package/dist/esm/tileset/tile-3d.js.map +1 -0
- package/dist/esm/tileset/tileset-3d.js +637 -0
- package/dist/esm/tileset/tileset-3d.js.map +1 -0
- package/dist/esm/tileset/tileset-cache.js +60 -0
- package/dist/esm/tileset/tileset-cache.js.map +1 -0
- package/dist/{tileset/traversers → esm/tileset}/tileset-traverser.js +20 -72
- package/dist/esm/tileset/tileset-traverser.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/doubly-linked-list-node.js +12 -0
- package/dist/esm/utils/doubly-linked-list-node.js.map +1 -0
- package/dist/esm/utils/doubly-linked-list.js +65 -0
- package/dist/esm/utils/doubly-linked-list.js.map +1 -0
- package/dist/esm/utils/managed-array.js +87 -0
- package/dist/esm/utils/managed-array.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -9
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts +7 -0
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts.map +1 -0
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +54 -0
- package/dist/tileset/format-i3s/i3s-pending-tiles-register.d.ts +27 -0
- package/dist/tileset/format-i3s/i3s-pending-tiles-register.d.ts.map +1 -0
- package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +47 -0
- package/dist/tileset/format-i3s/i3s-tile-manager.d.ts +34 -0
- package/dist/tileset/format-i3s/i3s-tile-manager.d.ts.map +1 -0
- package/dist/tileset/format-i3s/i3s-tile-manager.js +80 -0
- package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts +25 -0
- package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts.map +1 -0
- package/dist/tileset/format-i3s/i3s-tileset-traverser.js +92 -0
- package/dist/tileset/helpers/3d-tiles-options.d.ts +4 -0
- package/dist/tileset/helpers/3d-tiles-options.d.ts.map +1 -0
- package/dist/tileset/helpers/3d-tiles-options.js +8 -5
- package/dist/tileset/helpers/bounding-volume.d.ts +19 -0
- package/dist/tileset/helpers/bounding-volume.d.ts.map +1 -0
- package/dist/tileset/helpers/bounding-volume.js +274 -69
- package/dist/tileset/helpers/frame-state.d.ts +28 -0
- package/dist/tileset/helpers/frame-state.d.ts.map +1 -0
- package/dist/tileset/helpers/frame-state.js +131 -49
- package/dist/tileset/helpers/i3s-lod.d.ts +20 -0
- package/dist/tileset/helpers/i3s-lod.d.ts.map +1 -0
- package/dist/tileset/helpers/i3s-lod.js +82 -105
- package/dist/tileset/helpers/tiles-3d-lod.d.ts +8 -0
- package/dist/tileset/helpers/tiles-3d-lod.d.ts.map +1 -0
- package/dist/tileset/helpers/tiles-3d-lod.js +112 -100
- package/dist/tileset/helpers/transform-utils.d.ts +2 -0
- package/dist/tileset/helpers/transform-utils.d.ts.map +1 -0
- package/dist/tileset/helpers/transform-utils.js +51 -56
- package/dist/tileset/helpers/zoom.d.ts +46 -0
- package/dist/tileset/helpers/zoom.d.ts.map +1 -0
- package/dist/tileset/helpers/zoom.js +83 -30
- package/dist/tileset/tile-3d.d.ts +206 -0
- package/dist/tileset/tile-3d.d.ts.map +1 -0
- package/dist/tileset/tile-3d.js +593 -531
- package/dist/tileset/tileset-3d.d.ts +217 -0
- package/dist/tileset/tileset-3d.d.ts.map +1 -0
- package/dist/tileset/tileset-3d.js +707 -648
- package/dist/tileset/tileset-cache.d.ts +18 -0
- package/dist/tileset/tileset-cache.d.ts.map +1 -0
- package/dist/tileset/tileset-cache.js +70 -71
- package/dist/tileset/tileset-traverser.d.ts +46 -0
- package/dist/tileset/tileset-traverser.d.ts.map +1 -0
- package/dist/tileset/tileset-traverser.js +309 -0
- package/dist/types.d.ts +34 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/utils/doubly-linked-list-node.d.ts +11 -0
- package/dist/utils/doubly-linked-list-node.d.ts.map +1 -0
- package/dist/utils/doubly-linked-list-node.js +17 -8
- package/dist/utils/doubly-linked-list.d.ts +30 -0
- package/dist/utils/doubly-linked-list.d.ts.map +1 -0
- package/dist/utils/doubly-linked-list.js +91 -72
- package/dist/utils/managed-array.d.ts +85 -0
- package/dist/utils/managed-array.d.ts.map +1 -0
- package/dist/utils/managed-array.js +144 -103
- package/package.json +10 -10
- package/src/constants.ts +2 -0
- package/src/index.ts +7 -4
- package/src/tileset/{traversers → format-3d-tiles}/tileset-3d-traverser.ts +4 -2
- package/src/tileset/format-i3s/i3s-pending-tiles-register.ts +44 -0
- package/src/tileset/format-i3s/i3s-tile-manager.ts +101 -0
- package/src/tileset/{traversers → format-i3s}/i3s-tileset-traverser.ts +27 -15
- package/src/tileset/helpers/bounding-volume.ts +136 -0
- package/src/tileset/helpers/frame-state.ts +102 -18
- package/src/tileset/helpers/i3s-lod.ts +75 -96
- package/src/tileset/helpers/tiles-3d-lod.ts +2 -0
- package/src/tileset/helpers/transform-utils.ts +2 -0
- package/src/tileset/helpers/zoom.ts +84 -9
- package/src/tileset/tile-3d.ts +77 -20
- package/src/tileset/tileset-3d.ts +205 -43
- package/src/tileset/tileset-cache.ts +6 -2
- package/src/tileset/{traversers/tileset-traverser.ts → tileset-traverser.ts} +29 -17
- package/src/types.ts +36 -0
- package/src/utils/{doubly-linked-list-node.js → doubly-linked-list-node.ts} +7 -2
- package/src/utils/{doubly-linked-list.js → doubly-linked-list.ts} +5 -8
- package/src/utils/{managed-array.js → managed-array.ts} +5 -2
- package/dist/bundle.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
- package/dist/tileset/helpers/bounding-volume.js.map +0 -1
- package/dist/tileset/helpers/frame-state.js.map +0 -1
- package/dist/tileset/helpers/i3s-lod.js.map +0 -1
- package/dist/tileset/helpers/transform-utils.js.map +0 -1
- package/dist/tileset/helpers/zoom.js.map +0 -1
- package/dist/tileset/tile-3d.js.map +0 -1
- package/dist/tileset/tileset-3d.js.map +0 -1
- package/dist/tileset/tileset-cache.js.map +0 -1
- package/dist/tileset/traversers/i3s-tile-manager.js +0 -45
- package/dist/tileset/traversers/i3s-tile-manager.js.map +0 -1
- package/dist/tileset/traversers/i3s-tileset-traverser.js.map +0 -1
- package/dist/tileset/traversers/tileset-3d-traverser.js.map +0 -1
- package/dist/tileset/traversers/tileset-traverser.js.map +0 -1
- package/dist/utils/doubly-linked-list-node.js.map +0 -1
- package/dist/utils/doubly-linked-list.js.map +0 -1
- package/dist/utils/managed-array.js.map +0 -1
- package/src/tileset/traversers/i3s-tile-manager.ts +0 -39
|
@@ -1,42 +1,36 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { load } from '@loaders.gl/core';
|
|
3
|
-
import TilesetTraverser from '
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import I3STileManager from './i3s-tile-manager';
|
|
7
|
-
export
|
|
3
|
+
import { TilesetTraverser } from '../tileset-traverser';
|
|
4
|
+
import { getLodStatus } from '../helpers/i3s-lod';
|
|
5
|
+
import { Tile3D } from '../tile-3d';
|
|
6
|
+
import { I3STileManager } from './i3s-tile-manager';
|
|
7
|
+
export class I3STilesetTraverser extends TilesetTraverser {
|
|
8
8
|
constructor(options) {
|
|
9
9
|
super(options);
|
|
10
|
-
|
|
11
10
|
_defineProperty(this, "_tileManager", void 0);
|
|
12
|
-
|
|
13
11
|
this._tileManager = new I3STileManager();
|
|
14
12
|
}
|
|
15
|
-
|
|
13
|
+
traversalFinished(frameState) {
|
|
14
|
+
return !this._tileManager.hasPendingTiles(frameState.viewport.id, this._frameNumber || 0);
|
|
15
|
+
}
|
|
16
16
|
shouldRefine(tile, frameState) {
|
|
17
|
-
tile._lodJudge =
|
|
17
|
+
tile._lodJudge = getLodStatus(tile, frameState);
|
|
18
18
|
return tile._lodJudge === 'DIG';
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
updateChildTiles(tile, frameState) {
|
|
22
21
|
const children = tile.header.children || [];
|
|
23
22
|
const childTiles = tile.children;
|
|
24
23
|
const tileset = tile.tileset;
|
|
25
|
-
|
|
26
24
|
for (const child of children) {
|
|
27
25
|
const extendedId = "".concat(child.id, "-").concat(frameState.viewport.id);
|
|
28
26
|
const childTile = childTiles && childTiles.find(t => t.id === extendedId);
|
|
29
|
-
|
|
30
27
|
if (!childTile) {
|
|
31
28
|
let request = () => this._loadTile(child.id, tileset);
|
|
32
|
-
|
|
33
29
|
const cachedRequest = this._tileManager.find(extendedId);
|
|
34
|
-
|
|
35
30
|
if (!cachedRequest) {
|
|
36
31
|
if (tileset.tileset.nodePages) {
|
|
37
32
|
request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id);
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
this._tileManager.add(request, extendedId, header => this._onTileLoad(header, tile, extendedId), frameState);
|
|
41
35
|
} else {
|
|
42
36
|
this._tileManager.update(extendedId, frameState);
|
|
@@ -45,36 +39,30 @@ export default class I3STilesetTraverser extends TilesetTraverser {
|
|
|
45
39
|
this.updateTile(childTile, frameState);
|
|
46
40
|
}
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
return false;
|
|
50
43
|
}
|
|
51
|
-
|
|
52
44
|
async _loadTile(nodeId, tileset) {
|
|
53
45
|
const {
|
|
54
46
|
loader
|
|
55
47
|
} = tileset;
|
|
56
48
|
const nodeUrl = tileset.getTileUrl("".concat(tileset.url, "/nodes/").concat(nodeId));
|
|
57
|
-
const options = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
const options = {
|
|
50
|
+
...tileset.loadOptions,
|
|
51
|
+
i3s: {
|
|
52
|
+
...tileset.loadOptions.i3s,
|
|
53
|
+
isTileHeader: true
|
|
61
54
|
}
|
|
62
55
|
};
|
|
63
56
|
return await load(nodeUrl, loader, options);
|
|
64
57
|
}
|
|
65
|
-
|
|
66
58
|
_onTileLoad(header, tile, extendedId) {
|
|
67
|
-
const childTile = new
|
|
59
|
+
const childTile = new Tile3D(tile.tileset, header, tile, extendedId);
|
|
68
60
|
tile.children.push(childTile);
|
|
69
|
-
|
|
70
61
|
const frameState = this._tileManager.find(childTile.id).frameState;
|
|
71
|
-
|
|
72
62
|
this.updateTile(childTile, frameState);
|
|
73
|
-
|
|
74
|
-
if (this._frameNumber === frameState.frameNumber) {
|
|
63
|
+
if (this._frameNumber === frameState.frameNumber && (this.traversalFinished(frameState) || new Date().getTime() - this.lastUpdate > this.updateDebounceTime)) {
|
|
75
64
|
this.executeTraversal(childTile, frameState);
|
|
76
65
|
}
|
|
77
66
|
}
|
|
78
|
-
|
|
79
67
|
}
|
|
80
68
|
//# sourceMappingURL=i3s-tileset-traverser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i3s-tileset-traverser.js","names":["load","TilesetTraverser","getLodStatus","Tile3D","I3STileManager","I3STilesetTraverser","constructor","options","_defineProperty","_tileManager","traversalFinished","frameState","hasPendingTiles","viewport","id","_frameNumber","shouldRefine","tile","_lodJudge","updateChildTiles","children","header","childTiles","tileset","child","extendedId","concat","childTile","find","t","request","_loadTile","cachedRequest","nodePages","nodePagesTile","formTileFromNodePages","add","_onTileLoad","update","updateTile","nodeId","loader","nodeUrl","getTileUrl","url","loadOptions","i3s","isTileHeader","push","frameNumber","Date","getTime","lastUpdate","updateDebounceTime","executeTraversal"],"sources":["../../../../src/tileset/format-i3s/i3s-tileset-traverser.ts"],"sourcesContent":["import {load} from '@loaders.gl/core';\nimport {TilesetTraverser} from '../tileset-traverser';\n\nimport {getLodStatus} from '../helpers/i3s-lod';\nimport {Tile3D} from '../tile-3d';\nimport {I3STileManager} from './i3s-tile-manager';\nimport {FrameState} from '../helpers/frame-state';\n\nexport class I3STilesetTraverser extends TilesetTraverser {\n private _tileManager: I3STileManager;\n\n constructor(options) {\n super(options);\n this._tileManager = new I3STileManager();\n }\n\n /**\n * Check if there are no penging tile header requests,\n * that means the traversal is finished and we can call\n * following-up callbacks.\n */\n traversalFinished(frameState: FrameState): boolean {\n return !this._tileManager.hasPendingTiles(frameState.viewport.id, this._frameNumber || 0);\n }\n\n shouldRefine(tile, frameState: FrameState) {\n tile._lodJudge = getLodStatus(tile, frameState);\n return tile._lodJudge === 'DIG';\n }\n\n updateChildTiles(tile, frameState: FrameState): boolean {\n const children = tile.header.children || [];\n // children which are already fetched and constructed as Tile3D instances\n const childTiles = tile.children;\n const tileset = tile.tileset;\n\n for (const child of children) {\n const extendedId = `${child.id}-${frameState.viewport.id}`;\n // if child tile is not fetched\n const childTile = childTiles && childTiles.find((t) => t.id === extendedId);\n if (!childTile) {\n let request = () => this._loadTile(child.id, tileset);\n const cachedRequest = this._tileManager.find(extendedId);\n if (!cachedRequest) {\n // eslint-disable-next-line max-depth\n if (tileset.tileset.nodePages) {\n request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id);\n }\n this._tileManager.add(\n request,\n extendedId,\n (header) => this._onTileLoad(header, tile, extendedId),\n frameState\n );\n } else {\n // update frameNumber since it is still needed in current frame\n this._tileManager.update(extendedId, frameState);\n }\n } else if (childTile) {\n // if child tile is fetched and available\n this.updateTile(childTile, frameState);\n }\n }\n return false;\n }\n\n async _loadTile(nodeId, tileset) {\n const {loader} = tileset;\n const nodeUrl = tileset.getTileUrl(`${tileset.url}/nodes/${nodeId}`);\n // load metadata\n const options = {\n ...tileset.loadOptions,\n i3s: {\n ...tileset.loadOptions.i3s,\n isTileHeader: true\n }\n };\n\n return await load(nodeUrl, loader, options);\n }\n\n /**\n * The callback to init Tile3D instance after loading the tile JSON\n * @param {Object} header - the tile JSON from a dataset\n * @param {Tile3D} tile - the parent Tile3D instance\n * @param {string} extendedId - optional ID to separate copies of a tile for different viewports.\n * const extendedId = `${tile.id}-${frameState.viewport.id}`;\n * @return {void}\n */\n _onTileLoad(header, tile, extendedId) {\n // after child tile is fetched\n const childTile = new Tile3D(tile.tileset, header, tile, extendedId);\n tile.children.push(childTile);\n const frameState = this._tileManager.find(childTile.id).frameState;\n this.updateTile(childTile, frameState);\n\n // after tile fetched, resume traversal if still in current update/traversal frame\n if (\n this._frameNumber === frameState.frameNumber &&\n (this.traversalFinished(frameState) ||\n new Date().getTime() - this.lastUpdate > this.updateDebounceTime)\n ) {\n this.executeTraversal(childTile, frameState);\n }\n }\n}\n"],"mappings":";AAAA,SAAQA,IAAI,QAAO,kBAAkB;AACrC,SAAQC,gBAAgB,QAAO,sBAAsB;AAErD,SAAQC,YAAY,QAAO,oBAAoB;AAC/C,SAAQC,MAAM,QAAO,YAAY;AACjC,SAAQC,cAAc,QAAO,oBAAoB;AAGjD,OAAO,MAAMC,mBAAmB,SAASJ,gBAAgB,CAAC;EAGxDK,WAAWA,CAACC,OAAO,EAAE;IACnB,KAAK,CAACA,OAAO,CAAC;IAACC,eAAA;IACf,IAAI,CAACC,YAAY,GAAG,IAAIL,cAAc,CAAC,CAAC;EAC1C;EAOAM,iBAAiBA,CAACC,UAAsB,EAAW;IACjD,OAAO,CAAC,IAAI,CAACF,YAAY,CAACG,eAAe,CAACD,UAAU,CAACE,QAAQ,CAACC,EAAE,EAAE,IAAI,CAACC,YAAY,IAAI,CAAC,C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AACC,OAAO,CAAC,CAAC,GAAG,IAAI,CAACC,UAAU,GAAG,IAAI,CAACC,kBAAkB,CAAC,EACnE;MACA,IAAI,CAACC,gBAAgB,CAAC3B,SAAS,EAAEhB,UAAU,CAAC;IAC9C;EACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"3d-tiles-options.js","names":["get3dTilesOptions","tileset","assetGltfUpAxis","asset","gltfUpAxis"],"sources":["../../../../src/tileset/helpers/3d-tiles-options.ts"],"sourcesContent":["export function get3dTilesOptions(tileset) {\n return {\n assetGltfUpAxis: (tileset.asset && tileset.asset.gltfUpAxis) || 'Y'\n };\n}\n"],"mappings":"AAAA,OAAO,SAASA,iBAAiBA,CAACC,OAAO,EAAE;EACzC,OAAO;IACLC,eAAe,EAAGD,OAAO,CAACE,KAAK,IAAIF,OAAO,CAACE,KAAK,CAACC,UAAU,IAAK;EAClE,CAAC;AACH"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Quaternion, Vector3, Matrix3, Matrix4, degrees } from '@math.gl/core';
|
|
2
|
+
import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
|
|
3
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
4
|
+
import { assert } from '@loaders.gl/loader-utils';
|
|
5
|
+
function defined(x) {
|
|
6
|
+
return x !== undefined && x !== null;
|
|
7
|
+
}
|
|
8
|
+
const scratchPoint = new Vector3();
|
|
9
|
+
const scratchScale = new Vector3();
|
|
10
|
+
const scratchNorthWest = new Vector3();
|
|
11
|
+
const scratchSouthEast = new Vector3();
|
|
12
|
+
export function createBoundingVolume(boundingVolumeHeader, transform, result) {
|
|
13
|
+
assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
|
|
14
|
+
if (boundingVolumeHeader.box) {
|
|
15
|
+
return createBox(boundingVolumeHeader.box, transform, result);
|
|
16
|
+
}
|
|
17
|
+
if (boundingVolumeHeader.region) {
|
|
18
|
+
const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
|
|
19
|
+
const northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest);
|
|
20
|
+
const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast);
|
|
21
|
+
const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);
|
|
22
|
+
const radius = new Vector3().subVectors(northWest, southEast).len() / 2.0;
|
|
23
|
+
return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new Matrix4());
|
|
24
|
+
}
|
|
25
|
+
if (boundingVolumeHeader.sphere) {
|
|
26
|
+
return createSphere(boundingVolumeHeader.sphere, transform, result);
|
|
27
|
+
}
|
|
28
|
+
throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
|
|
29
|
+
}
|
|
30
|
+
export function getCartographicBounds(boundingVolumeHeader, boundingVolume) {
|
|
31
|
+
if (boundingVolumeHeader.box) {
|
|
32
|
+
return orientedBoundingBoxToCartographicBounds(boundingVolume);
|
|
33
|
+
}
|
|
34
|
+
if (boundingVolumeHeader.region) {
|
|
35
|
+
const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
|
|
36
|
+
return [[degrees(west), degrees(south), minHeight], [degrees(east), degrees(north), maxHeight]];
|
|
37
|
+
}
|
|
38
|
+
if (boundingVolumeHeader.sphere) {
|
|
39
|
+
return boundingSphereToCartographicBounds(boundingVolume);
|
|
40
|
+
}
|
|
41
|
+
throw new Error('Unkown boundingVolume type');
|
|
42
|
+
}
|
|
43
|
+
function createBox(box, transform, result) {
|
|
44
|
+
const center = new Vector3(box[0], box[1], box[2]);
|
|
45
|
+
transform.transform(center, center);
|
|
46
|
+
let origin = [];
|
|
47
|
+
if (box.length === 10) {
|
|
48
|
+
const halfSize = box.slice(3, 6);
|
|
49
|
+
const quaternion = new Quaternion();
|
|
50
|
+
quaternion.fromArray(box, 6);
|
|
51
|
+
const x = new Vector3([1, 0, 0]);
|
|
52
|
+
const y = new Vector3([0, 1, 0]);
|
|
53
|
+
const z = new Vector3([0, 0, 1]);
|
|
54
|
+
x.transformByQuaternion(quaternion);
|
|
55
|
+
x.scale(halfSize[0]);
|
|
56
|
+
y.transformByQuaternion(quaternion);
|
|
57
|
+
y.scale(halfSize[1]);
|
|
58
|
+
z.transformByQuaternion(quaternion);
|
|
59
|
+
z.scale(halfSize[2]);
|
|
60
|
+
origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];
|
|
61
|
+
} else {
|
|
62
|
+
origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];
|
|
63
|
+
}
|
|
64
|
+
const xAxis = transform.transformAsVector(origin.slice(0, 3));
|
|
65
|
+
const yAxis = transform.transformAsVector(origin.slice(3, 6));
|
|
66
|
+
const zAxis = transform.transformAsVector(origin.slice(6, 9));
|
|
67
|
+
const halfAxes = new Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]);
|
|
68
|
+
if (defined(result)) {
|
|
69
|
+
result.center = center;
|
|
70
|
+
result.halfAxes = halfAxes;
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
return new OrientedBoundingBox(center, halfAxes);
|
|
74
|
+
}
|
|
75
|
+
function createSphere(sphere, transform, result) {
|
|
76
|
+
const center = new Vector3(sphere[0], sphere[1], sphere[2]);
|
|
77
|
+
transform.transform(center, center);
|
|
78
|
+
const scale = transform.getScale(scratchScale);
|
|
79
|
+
const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);
|
|
80
|
+
const radius = sphere[3] * uniformScale;
|
|
81
|
+
if (defined(result)) {
|
|
82
|
+
result.center = center;
|
|
83
|
+
result.radius = radius;
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
return new BoundingSphere(center, radius);
|
|
87
|
+
}
|
|
88
|
+
function orientedBoundingBoxToCartographicBounds(boundingVolume) {
|
|
89
|
+
const result = emptyCartographicBounds();
|
|
90
|
+
const {
|
|
91
|
+
halfAxes
|
|
92
|
+
} = boundingVolume;
|
|
93
|
+
const xAxis = new Vector3(halfAxes.getColumn(0));
|
|
94
|
+
const yAxis = new Vector3(halfAxes.getColumn(1));
|
|
95
|
+
const zAxis = new Vector3(halfAxes.getColumn(2));
|
|
96
|
+
for (let x = 0; x < 2; x++) {
|
|
97
|
+
for (let y = 0; y < 2; y++) {
|
|
98
|
+
for (let z = 0; z < 2; z++) {
|
|
99
|
+
scratchPoint.copy(boundingVolume.center);
|
|
100
|
+
scratchPoint.add(xAxis);
|
|
101
|
+
scratchPoint.add(yAxis);
|
|
102
|
+
scratchPoint.add(zAxis);
|
|
103
|
+
addToCartographicBounds(result, scratchPoint);
|
|
104
|
+
zAxis.negate();
|
|
105
|
+
}
|
|
106
|
+
yAxis.negate();
|
|
107
|
+
}
|
|
108
|
+
xAxis.negate();
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
function boundingSphereToCartographicBounds(boundingVolume) {
|
|
113
|
+
const result = emptyCartographicBounds();
|
|
114
|
+
const {
|
|
115
|
+
center,
|
|
116
|
+
radius
|
|
117
|
+
} = boundingVolume;
|
|
118
|
+
const point = Ellipsoid.WGS84.scaleToGeodeticSurface(center, scratchPoint);
|
|
119
|
+
let zAxis;
|
|
120
|
+
if (point) {
|
|
121
|
+
zAxis = Ellipsoid.WGS84.geodeticSurfaceNormal(point);
|
|
122
|
+
} else {
|
|
123
|
+
zAxis = new Vector3(0, 0, 1);
|
|
124
|
+
}
|
|
125
|
+
let xAxis = new Vector3(zAxis[2], -zAxis[1], 0);
|
|
126
|
+
if (xAxis.len() > 0) {
|
|
127
|
+
xAxis.normalize();
|
|
128
|
+
} else {
|
|
129
|
+
xAxis = new Vector3(0, 1, 0);
|
|
130
|
+
}
|
|
131
|
+
const yAxis = xAxis.clone().cross(zAxis);
|
|
132
|
+
for (const axis of [xAxis, yAxis, zAxis]) {
|
|
133
|
+
scratchScale.copy(axis).scale(radius);
|
|
134
|
+
for (let dir = 0; dir < 2; dir++) {
|
|
135
|
+
scratchPoint.copy(center);
|
|
136
|
+
scratchPoint.add(scratchScale);
|
|
137
|
+
addToCartographicBounds(result, scratchPoint);
|
|
138
|
+
scratchScale.negate();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
function emptyCartographicBounds() {
|
|
144
|
+
return [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
|
|
145
|
+
}
|
|
146
|
+
function addToCartographicBounds(target, cartesian) {
|
|
147
|
+
Ellipsoid.WGS84.cartesianToCartographic(cartesian, scratchPoint);
|
|
148
|
+
target[0][0] = Math.min(target[0][0], scratchPoint[0]);
|
|
149
|
+
target[0][1] = Math.min(target[0][1], scratchPoint[1]);
|
|
150
|
+
target[0][2] = Math.min(target[0][2], scratchPoint[2]);
|
|
151
|
+
target[1][0] = Math.max(target[1][0], scratchPoint[0]);
|
|
152
|
+
target[1][1] = Math.max(target[1][1], scratchPoint[1]);
|
|
153
|
+
target[1][2] = Math.max(target[1][2], scratchPoint[2]);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=bounding-volume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounding-volume.js","names":["Quaternion","Vector3","Matrix3","Matrix4","degrees","BoundingSphere","OrientedBoundingBox","Ellipsoid","assert","defined","x","undefined","scratchPoint","scratchScale","scratchNorthWest","scratchSouthEast","createBoundingVolume","boundingVolumeHeader","transform","result","box","createBox","region","west","south","east","north","minHeight","maxHeight","northWest","WGS84","cartographicToCartesian","southEast","centerInCartesian","addVectors","multiplyScalar","radius","subVectors","len","createSphere","sphere","Error","getCartographicBounds","boundingVolume","orientedBoundingBoxToCartographicBounds","boundingSphereToCartographicBounds","center","origin","length","halfSize","slice","quaternion","fromArray","y","z","transformByQuaternion","scale","toArray","xAxis","transformAsVector","yAxis","zAxis","halfAxes","getScale","uniformScale","Math","max","emptyCartographicBounds","getColumn","copy","add","addToCartographicBounds","negate","point","scaleToGeodeticSurface","geodeticSurfaceNormal","normalize","clone","cross","axis","dir","Infinity","target","cartesian","cartesianToCartographic","min"],"sources":["../../../../src/tileset/helpers/bounding-volume.ts"],"sourcesContent":["// This file is derived from the Cesium code base under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Quaternion, Vector3, Matrix3, Matrix4, degrees} from '@math.gl/core';\nimport {BoundingSphere, OrientedBoundingBox} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {assert} from '@loaders.gl/loader-utils';\n\n// const scratchProjectedBoundingSphere = new BoundingSphere();\n\nfunction defined(x) {\n return x !== undefined && x !== null;\n}\n\n// const scratchMatrix = new Matrix3();\nconst scratchPoint = new Vector3();\nconst scratchScale = new Vector3();\nconst scratchNorthWest = new Vector3();\nconst scratchSouthEast = new Vector3();\n// const scratchRectangle = new Rectangle();\n// const scratchOrientedBoundingBox = new OrientedBoundingBox();\n// const scratchTransform = new Matrix4();\n\n/**\n * Create a bounding volume from the tile's bounding volume header.\n * @param {Object} boundingVolumeHeader The tile's bounding volume header.\n * @param {Matrix4} transform The transform to apply to the bounding volume.\n * @param [result] The object onto which to store the result.\n * @returns The modified result parameter or a new TileBoundingVolume instance if none was provided.\n */\nexport function createBoundingVolume(boundingVolumeHeader, transform, result) {\n assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');\n\n // boundingVolume schema:\n // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json\n if (boundingVolumeHeader.box) {\n return createBox(boundingVolumeHeader.box, transform, result);\n }\n if (boundingVolumeHeader.region) {\n // [west, south, east, north, minimum height, maximum height]\n // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.\n // Heights are in meters above (or below) the WGS 84 ellipsoid.\n const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;\n\n const northWest = Ellipsoid.WGS84.cartographicToCartesian(\n [degrees(west), degrees(north), minHeight],\n scratchNorthWest\n );\n const southEast = Ellipsoid.WGS84.cartographicToCartesian(\n [degrees(east), degrees(south), maxHeight],\n scratchSouthEast\n );\n const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);\n const radius = new Vector3().subVectors(northWest, southEast).len() / 2.0;\n\n // TODO improve region boundingVolume\n // for now, create a sphere as the boundingVolume instead of box\n return createSphere(\n [centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius],\n new Matrix4()\n );\n }\n\n if (boundingVolumeHeader.sphere) {\n return createSphere(boundingVolumeHeader.sphere, transform, result);\n }\n\n throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');\n}\n\n/** [min, max] each in [longitude, latitude, altitude] */\nexport type CartographicBounds = [min: number[], max: number[]];\n\n/**\n * Calculate the cartographic bounding box the tile's bounding volume.\n * @param {Object} boundingVolumeHeader The tile's bounding volume header.\n * @param {BoundingVolume} boundingVolume The bounding volume.\n * @returns {CartographicBounds}\n */\nexport function getCartographicBounds(\n boundingVolumeHeader,\n boundingVolume: OrientedBoundingBox | BoundingSphere\n): CartographicBounds {\n // boundingVolume schema:\n // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json\n if (boundingVolumeHeader.box) {\n return orientedBoundingBoxToCartographicBounds(boundingVolume as OrientedBoundingBox);\n }\n if (boundingVolumeHeader.region) {\n // [west, south, east, north, minimum height, maximum height]\n // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.\n // Heights are in meters above (or below) the WGS 84 ellipsoid.\n const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;\n\n return [\n [degrees(west), degrees(south), minHeight],\n [degrees(east), degrees(north), maxHeight]\n ];\n }\n\n if (boundingVolumeHeader.sphere) {\n return boundingSphereToCartographicBounds(boundingVolume as BoundingSphere);\n }\n\n throw new Error('Unkown boundingVolume type');\n}\n\nfunction createBox(box, transform, result) {\n // https://math.gl/modules/culling/docs/api-reference/oriented-bounding-box\n // 1. A half-axes based representation.\n // box: An array of 12 numbers that define an oriented bounding box.\n // The first three elements define the x, y, and z values for the center of the box.\n // The next three elements (with indices 3, 4, and 5) define the x axis direction and half-length.\n // The next three elements (indices 6, 7, and 8) define the y axis direction and half-length.\n // The last three elements (indices 9, 10, and 11) define the z axis direction and half-length.\n // 2. A half-size-quaternion based representation.\n // box: An array of 10 numbers that define an oriented bounding box.\n // The first three elements define the x, y, and z values for the center of the box in a right-handed 3-axis (x, y, z) Cartesian coordinate system where the z-axis is up.\n // The next three elements (with indices 3, 4, and 5) define the halfSize.\n // The last four elements (indices 6, 7, 8 and 10) define the quaternion.\n const center = new Vector3(box[0], box[1], box[2]);\n transform.transform(center, center);\n let origin: number[] = [];\n if (box.length === 10) {\n const halfSize = box.slice(3, 6);\n const quaternion = new Quaternion();\n quaternion.fromArray(box, 6);\n const x = new Vector3([1, 0, 0]);\n const y = new Vector3([0, 1, 0]);\n const z = new Vector3([0, 0, 1]);\n x.transformByQuaternion(quaternion);\n x.scale(halfSize[0]);\n y.transformByQuaternion(quaternion);\n y.scale(halfSize[1]);\n z.transformByQuaternion(quaternion);\n z.scale(halfSize[2]);\n origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];\n } else {\n origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];\n }\n const xAxis = transform.transformAsVector(origin.slice(0, 3));\n const yAxis = transform.transformAsVector(origin.slice(3, 6));\n const zAxis = transform.transformAsVector(origin.slice(6, 9));\n const halfAxes = new Matrix3([\n xAxis[0],\n xAxis[1],\n xAxis[2],\n yAxis[0],\n yAxis[1],\n yAxis[2],\n zAxis[0],\n zAxis[1],\n zAxis[2]\n ]);\n\n if (defined(result)) {\n result.center = center;\n result.halfAxes = halfAxes;\n return result;\n }\n\n return new OrientedBoundingBox(center, halfAxes);\n}\n\n/*\nfunction createBoxFromTransformedRegion(region, transform, initialTransform, result) {\n const rectangle = Rectangle.unpack(region, 0, scratchRectangle);\n const minimumHeight = region[4];\n const maximumHeight = region[5];\n\n const orientedBoundingBox = OrientedBoundingBox.fromRectangle(\n rectangle,\n minimumHeight,\n maximumHeight,\n Ellipsoid.WGS84,\n scratchOrientedBoundingBox\n );\n const center = orientedBoundingBox.center;\n const halfAxes = orientedBoundingBox.halfAxes;\n\n // A region bounding volume is not transformed by the transform in the tileset JSON,\n // but may be transformed by additional transforms applied in Cesium.\n // This is why the transform is calculated as the difference between the initial transform and the current transform.\n transform = Matrix4.multiplyTransformation(\n transform,\n Matrix4.inverseTransformation(initialTransform, scratchTransform),\n scratchTransform\n );\n center = Matrix4.multiplyByPoint(transform, center, center);\n const rotationScale = Matrix4.getRotation(transform, scratchMatrix);\n halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);\n\n if (defined(result) && result instanceof TileOrientedBoundingBox) {\n result.update(center, halfAxes);\n return result;\n }\n\n return new TileOrientedBoundingBox(center, halfAxes);\n}\n\nfunction createRegion(region, transform, initialTransform, result) {\n if (!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)) {\n return createBoxFromTransformedRegion(region, transform, initialTransform, result);\n }\n\n if (defined(result)) {\n return result;\n }\n\n const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);\n\n return new TileBoundingRegion({\n rectangle: rectangleRegion,\n minimumHeight: region[4],\n maximumHeight: region[5]\n });\n}\n*/\n\nfunction createSphere(sphere, transform, result?) {\n // Find the transformed center\n const center = new Vector3(sphere[0], sphere[1], sphere[2]);\n transform.transform(center, center);\n const scale = transform.getScale(scratchScale);\n\n const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);\n const radius = sphere[3] * uniformScale;\n\n if (defined(result)) {\n result.center = center;\n result.radius = radius;\n return result;\n }\n\n return new BoundingSphere(center, radius);\n}\n\n/**\n * Convert a bounding volume defined by OrientedBoundingBox to cartographic bounds\n * @returns {CartographicBounds}\n */\nfunction orientedBoundingBoxToCartographicBounds(\n boundingVolume: OrientedBoundingBox\n): CartographicBounds {\n const result = emptyCartographicBounds();\n\n const {halfAxes} = boundingVolume as OrientedBoundingBox;\n const xAxis = new Vector3(halfAxes.getColumn(0));\n const yAxis = new Vector3(halfAxes.getColumn(1));\n const zAxis = new Vector3(halfAxes.getColumn(2));\n\n // Test all 8 corners of the box\n for (let x = 0; x < 2; x++) {\n for (let y = 0; y < 2; y++) {\n for (let z = 0; z < 2; z++) {\n scratchPoint.copy(boundingVolume.center);\n scratchPoint.add(xAxis);\n scratchPoint.add(yAxis);\n scratchPoint.add(zAxis);\n\n addToCartographicBounds(result, scratchPoint);\n zAxis.negate();\n }\n yAxis.negate();\n }\n xAxis.negate();\n }\n return result;\n}\n\n/**\n * Convert a bounding volume defined by BoundingSphere to cartographic bounds\n * @returns {CartographicBounds}\n */\nfunction boundingSphereToCartographicBounds(boundingVolume: BoundingSphere): CartographicBounds {\n const result = emptyCartographicBounds();\n\n const {center, radius} = boundingVolume as BoundingSphere;\n const point = Ellipsoid.WGS84.scaleToGeodeticSurface(center, scratchPoint);\n\n let zAxis: Vector3;\n if (point) {\n zAxis = Ellipsoid.WGS84.geodeticSurfaceNormal(point) as Vector3;\n } else {\n zAxis = new Vector3(0, 0, 1);\n }\n let xAxis = new Vector3(zAxis[2], -zAxis[1], 0);\n if (xAxis.len() > 0) {\n xAxis.normalize();\n } else {\n xAxis = new Vector3(0, 1, 0);\n }\n const yAxis = xAxis.clone().cross(zAxis);\n\n // Test 6 end points of the 3 axes\n for (const axis of [xAxis, yAxis, zAxis]) {\n scratchScale.copy(axis).scale(radius);\n for (let dir = 0; dir < 2; dir++) {\n scratchPoint.copy(center);\n scratchPoint.add(scratchScale);\n addToCartographicBounds(result, scratchPoint);\n // Flip the axis\n scratchScale.negate();\n }\n }\n return result;\n}\n\n/**\n * Create a new cartographic bounds that contains no points\n * @returns {CartographicBounds}\n */\nfunction emptyCartographicBounds(): CartographicBounds {\n return [\n [Infinity, Infinity, Infinity],\n [-Infinity, -Infinity, -Infinity]\n ];\n}\n\n/**\n * Add a point to the target cartographic bounds\n * @param {CartographicBounds} target\n * @param {Vector3} cartesian coordinates of the point to add\n */\nfunction addToCartographicBounds(target: CartographicBounds, cartesian: Readonly<Vector3>) {\n Ellipsoid.WGS84.cartesianToCartographic(cartesian, scratchPoint);\n target[0][0] = Math.min(target[0][0], scratchPoint[0]);\n target[0][1] = Math.min(target[0][1], scratchPoint[1]);\n target[0][2] = Math.min(target[0][2], scratchPoint[2]);\n\n target[1][0] = Math.max(target[1][0], scratchPoint[0]);\n target[1][1] = Math.max(target[1][1], scratchPoint[1]);\n target[1][2] = Math.max(target[1][2], scratchPoint[2]);\n}\n"],"mappings":"AAIA,SAAQA,UAAU,EAAEC,OAAO,EAAEC,OAAO,EAAEC,OAAO,EAAEC,OAAO,QAAO,eAAe;AAC5E,SAAQC,cAAc,EAAEC,mBAAmB,QAAO,kBAAkB;AACpE,SAAQC,SAAS,QAAO,qBAAqB;AAC7C,SAAQC,MAAM,QAAO,0BAA0B;AAI/C,SAASC,OAAOA,CAACC,CAAC,EAAE;EAClB,OAAOA,CAAC,KAAKC,SAAS,IAAID,CAAC,KAAK,IAAI;AACtC;AAGA,MAAME,YAAY,GAAG,IAAIX,OAAO,CAAC,CAAC;AAClC,MAAMY,YAAY,GAAG,IAAIZ,OAAO,CAAC,CAAC;AAClC,MAAMa,gBAAgB,GAAG,IAAIb,OAAO,CAAC,CAAC;AACtC,MAAMc,gBAAgB,GAAG,IAAId,OAAO,CAAC,CAAC;AAYtC,OAAO,SAASe,oBAAoBA,CAACC,oBAAoB,EAAEC,SAAS,EAAEC,MAAM,EAAE;EAC5EX,MAAM,CAACS,oBAAoB,EAAE,yCAAyC,CAAC;EAIvE,IAAIA,oBAAoB,CAACG,GAAG,EAAE;IAC5B,OAAOC,SAAS,CAACJ,o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AI,CAACC,GAAG,CAACgB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEtE,YAAY,CAAC,CAAC,CAAC,CAAC;EACtDsE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGjB,IAAI,CAACC,GAAG,CAACgB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEtE,YAAY,CAAC,CAAC,CAAC,CAAC;AACxD"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Vector3 } from '@math.gl/core';
|
|
2
|
+
import { CullingVolume, Plane } from '@math.gl/culling';
|
|
3
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
4
|
+
const scratchVector = new Vector3();
|
|
5
|
+
const scratchPosition = new Vector3();
|
|
6
|
+
const cullingVolume = new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]);
|
|
7
|
+
export function getFrameState(viewport, frameNumber) {
|
|
8
|
+
const {
|
|
9
|
+
cameraDirection,
|
|
10
|
+
cameraUp,
|
|
11
|
+
height
|
|
12
|
+
} = viewport;
|
|
13
|
+
const {
|
|
14
|
+
metersPerUnit
|
|
15
|
+
} = viewport.distanceScales;
|
|
16
|
+
const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);
|
|
17
|
+
const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
|
|
18
|
+
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
19
|
+
const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
|
|
20
|
+
const cameraDirectionCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize();
|
|
21
|
+
const cameraUpCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize();
|
|
22
|
+
commonSpacePlanesToWGS84(viewport);
|
|
23
|
+
const ViewportClass = viewport.constructor;
|
|
24
|
+
const {
|
|
25
|
+
longitude,
|
|
26
|
+
latitude,
|
|
27
|
+
width,
|
|
28
|
+
bearing,
|
|
29
|
+
zoom
|
|
30
|
+
} = viewport;
|
|
31
|
+
const topDownViewport = new ViewportClass({
|
|
32
|
+
longitude,
|
|
33
|
+
latitude,
|
|
34
|
+
height,
|
|
35
|
+
width,
|
|
36
|
+
bearing,
|
|
37
|
+
zoom,
|
|
38
|
+
pitch: 0
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
camera: {
|
|
42
|
+
position: cameraPositionCartesian,
|
|
43
|
+
direction: cameraDirectionCartesian,
|
|
44
|
+
up: cameraUpCartesian
|
|
45
|
+
},
|
|
46
|
+
viewport,
|
|
47
|
+
topDownViewport,
|
|
48
|
+
height,
|
|
49
|
+
cullingVolume,
|
|
50
|
+
frameNumber,
|
|
51
|
+
sseDenominator: 1.15
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function limitSelectedTiles(tiles, frameState, maximumTilesSelected) {
|
|
55
|
+
if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {
|
|
56
|
+
return [tiles, []];
|
|
57
|
+
}
|
|
58
|
+
const tuples = [];
|
|
59
|
+
const {
|
|
60
|
+
longitude: viewportLongitude,
|
|
61
|
+
latitude: viewportLatitude
|
|
62
|
+
} = frameState.viewport;
|
|
63
|
+
for (const [index, tile] of tiles.entries()) {
|
|
64
|
+
const [longitude, latitude] = tile.header.mbs;
|
|
65
|
+
const deltaLon = Math.abs(viewportLongitude - longitude);
|
|
66
|
+
const deltaLat = Math.abs(viewportLatitude - latitude);
|
|
67
|
+
const distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);
|
|
68
|
+
tuples.push([index, distance]);
|
|
69
|
+
}
|
|
70
|
+
const tuplesSorted = tuples.sort((a, b) => a[1] - b[1]);
|
|
71
|
+
const selectedTiles = [];
|
|
72
|
+
for (let i = 0; i < maximumTilesSelected; i++) {
|
|
73
|
+
selectedTiles.push(tiles[tuplesSorted[i][0]]);
|
|
74
|
+
}
|
|
75
|
+
const unselectedTiles = [];
|
|
76
|
+
for (let i = maximumTilesSelected; i < tuplesSorted.length; i++) {
|
|
77
|
+
unselectedTiles.push(tiles[tuplesSorted[i][0]]);
|
|
78
|
+
}
|
|
79
|
+
return [selectedTiles, unselectedTiles];
|
|
80
|
+
}
|
|
81
|
+
function commonSpacePlanesToWGS84(viewport) {
|
|
82
|
+
const frustumPlanes = viewport.getFrustumPlanes();
|
|
83
|
+
const nearCenterCommon = closestPointOnPlane(frustumPlanes.near, viewport.cameraPosition);
|
|
84
|
+
const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);
|
|
85
|
+
const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition);
|
|
86
|
+
let i = 0;
|
|
87
|
+
cullingVolume.planes[i++].fromPointNormal(nearCenterCartesian, scratchVector.copy(nearCenterCartesian).subtract(cameraCartesian));
|
|
88
|
+
for (const dir in frustumPlanes) {
|
|
89
|
+
if (dir === 'near') {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const plane = frustumPlanes[dir];
|
|
93
|
+
const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition);
|
|
94
|
+
const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition);
|
|
95
|
+
cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector.copy(nearCenterCartesian).subtract(cartesianPos));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function closestPointOnPlane(plane, refPoint) {
|
|
99
|
+
let out = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Vector3();
|
|
100
|
+
const distanceToRef = plane.normal.dot(refPoint);
|
|
101
|
+
out.copy(plane.normal).scale(plane.distance - distanceToRef).add(refPoint);
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
function worldToCartesian(viewport, point) {
|
|
105
|
+
let out = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Vector3();
|
|
106
|
+
const cartographicPos = viewport.unprojectPosition(point);
|
|
107
|
+
return Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, out);
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=frame-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-state.js","names":["Vector3","CullingVolume","Plane","Ellipsoid","scratchVector","scratchPosition","cullingVolume","getFrameState","viewport","frameNumber","cameraDirection","cameraUp","height","metersPerUnit","distanceScales","viewportCenterCartesian","worldToCartesian","center","enuToFixedTransform","WGS84","eastNorthUpToFixedFrame","cameraPositionCartographic","unprojectPosition","cameraPosition","cameraPositionCartesian","cartographicToCartesian","cameraDirectionCartesian","transformAsVector","scale","normalize","cameraUpCartesian","commonSpacePlanesToWGS84","ViewportClass","constructor","longitude","latitude","width","bearing","zoom","topDownViewport","pitch","camera","position","direction","up","sseDenominator","limitSelectedTiles","tiles","frameState","maximumTilesSelected","length","tuples","viewportLongitude","viewportLatitude","index","tile","entries","header","mbs","deltaLon","Math","abs","deltaLat","distance","sqrt","push","tuplesSorted","sort","a","b","selectedTiles","i","unselectedTiles","frustumPlanes","getFrustumPlanes","nearCenterCommon","closestPointOnPlane","near","nearCenterCartesian","cameraCartesian","planes","fromPointNormal","copy","subtract","dir","plane","posCommon","cartesianPos","refPoint","out","arguments","undefined","distanceToRef","normal","dot","add","point","cartographicPos"],"sources":["../../../../src/tileset/helpers/frame-state.ts"],"sourcesContent":["import {Tile3D} from '@loaders.gl/tiles';\nimport {Vector3} from '@math.gl/core';\nimport {CullingVolume, Plane} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {GeospatialViewport, Viewport} from '../../types';\n\nexport type FrameState = {\n camera: {\n position: number[];\n direction: number[];\n up: number[];\n };\n viewport: GeospatialViewport;\n topDownViewport: GeospatialViewport; // Use it to calculate projected radius for a tile\n height: number;\n cullingVolume: CullingVolume;\n frameNumber: number; // TODO: This can be the same between updates, what number is unique for between updates?\n sseDenominator: number; // Assumes fovy = 60 degrees\n};\n\nconst scratchVector = new Vector3();\nconst scratchPosition = new Vector3();\nconst cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n]);\n\n// Extracts a frame state appropriate for tile culling from a deck.gl viewport\n// TODO - this could likely be generalized and merged back into deck.gl for other culling scenarios\nexport function getFrameState(viewport: GeospatialViewport, frameNumber: number): FrameState {\n // Traverse and and request. Update _selectedTiles so that we know what to render.\n // Traverse and and request. Update _selectedTiles so that we know what to render.\n const {cameraDirection, cameraUp, height} = viewport;\n const {metersPerUnit} = viewport.distanceScales;\n\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?\n const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);\n const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);\n\n const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);\n const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(\n cameraPositionCartographic,\n new Vector3()\n );\n\n // These should still be normalized as the transform has scale 1 (goes from meters to meters)\n const cameraDirectionCartesian = new Vector3(\n // @ts-ignore\n enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))\n ).normalize();\n const cameraUpCartesian = new Vector3(\n // @ts-ignore\n enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))\n ).normalize();\n\n commonSpacePlanesToWGS84(viewport);\n\n const ViewportClass = viewport.constructor;\n const {longitude, latitude, width, bearing, zoom} = viewport;\n // @ts-ignore\n const topDownViewport = new ViewportClass({\n longitude,\n latitude,\n height,\n width,\n bearing,\n zoom,\n pitch: 0\n });\n\n // TODO: make a file/class for frameState and document what needs to be attached to this so that traversal can function\n return {\n camera: {\n position: cameraPositionCartesian,\n direction: cameraDirectionCartesian,\n up: cameraUpCartesian\n },\n viewport,\n topDownViewport,\n height,\n cullingVolume,\n frameNumber, // TODO: This can be the same between updates, what number is unique for between updates?\n sseDenominator: 1.15 // Assumes fovy = 60 degrees\n };\n}\n\n/**\n * Limit `tiles` array length with `maximumTilesSelected` number.\n * The criteria for this filtering is distance of a tile center\n * to the `frameState.viewport`'s longitude and latitude\n * @param tiles - tiles array to filter\n * @param frameState - frameState to calculate distances\n * @param maximumTilesSelected - maximal amount of tiles in the output array\n * @returns new tiles array\n */\nexport function limitSelectedTiles(\n tiles: Tile3D[],\n frameState: FrameState,\n maximumTilesSelected: number\n): [Tile3D[], Tile3D[]] {\n if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {\n return [tiles, []];\n }\n // Accumulate distances in couples array: [tileIndex: number, distanceToViewport: number]\n const tuples: [number, number][] = [];\n const {longitude: viewportLongitude, latitude: viewportLatitude} = frameState.viewport;\n for (const [index, tile] of tiles.entries()) {\n const [longitude, latitude] = tile.header.mbs;\n const deltaLon = Math.abs(viewportLongitude - longitude);\n const deltaLat = Math.abs(viewportLatitude - latitude);\n const distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);\n tuples.push([index, distance]);\n }\n const tuplesSorted = tuples.sort((a, b) => a[1] - b[1]);\n const selectedTiles: Tile3D[] = [];\n for (let i = 0; i < maximumTilesSelected; i++) {\n selectedTiles.push(tiles[tuplesSorted[i][0]]);\n }\n const unselectedTiles: Tile3D[] = [];\n for (let i = maximumTilesSelected; i < tuplesSorted.length; i++) {\n unselectedTiles.push(tiles[tuplesSorted[i][0]]);\n }\n\n return [selectedTiles, unselectedTiles];\n}\n\nfunction commonSpacePlanesToWGS84(viewport) {\n // Extract frustum planes based on current view.\n const frustumPlanes = viewport.getFrustumPlanes();\n\n // Get the near/far plane centers\n const nearCenterCommon = closestPointOnPlane(frustumPlanes.near, viewport.cameraPosition);\n const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);\n const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition);\n\n let i = 0;\n cullingVolume.planes[i++].fromPointNormal(\n nearCenterCartesian,\n scratchVector.copy(nearCenterCartesian).subtract(cameraCartesian)\n );\n\n for (const dir in frustumPlanes) {\n if (dir === 'near') {\n continue; // eslint-disable-line no-continue\n }\n const plane = frustumPlanes[dir];\n const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition);\n const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition);\n\n cullingVolume.planes[i++].fromPointNormal(\n cartesianPos,\n // Want the normal to point into the frustum since that's what culling expects\n scratchVector.copy(nearCenterCartesian).subtract(cartesianPos)\n );\n }\n}\n\nfunction closestPointOnPlane(\n plane: {distance: number; normal: Vector3},\n refPoint: [number, number, number] | Vector3,\n out: Vector3 = new Vector3()\n): Vector3 {\n const distanceToRef = plane.normal.dot(refPoint);\n out\n .copy(plane.normal)\n .scale(plane.distance - distanceToRef)\n .add(refPoint);\n return out;\n}\n\nfunction worldToCartesian(\n viewport: Viewport,\n point: number[] | Vector3,\n out: Vector3 = new Vector3()\n): Vector3 {\n const cartographicPos = viewport.unprojectPosition(point);\n return Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, out);\n}\n"],"mappings":"AACA,SAAQA,OAAO,QAAO,eAAe;AACrC,SAAQC,aAAa,EAAEC,KAAK,QAAO,kBAAkB;AACrD,SAAQC,SAAS,QAAO,qBAAqB;AAiB7C,MAAMC,aAAa,GAAG,IAAIJ,OAAO,CAAC,CAAC;AACnC,MAAMK,eAAe,GAAG,IAAIL,OAAO,CAAC,CAAC;AACrC,MAAMM,aAAa,GAAG,IAAIL,aAAa,CAAC,CACtC,IAAIC,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK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|
|
|
1
|
+
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
2
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
3
|
+
const cameraPositionCartesian = new Vector3();
|
|
4
|
+
const toEye = new Vector3();
|
|
5
|
+
const cameraPositionEnu = new Vector3();
|
|
6
|
+
const extraVertexEnu = new Vector3();
|
|
7
|
+
const projectedOriginVector = new Vector3();
|
|
8
|
+
const enuToCartesianMatrix = new Matrix4();
|
|
9
|
+
const cartesianToEnuMatrix = new Matrix4();
|
|
10
|
+
export function getLodStatus(tile, frameState) {
|
|
11
|
+
if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
|
|
12
|
+
return 'DIG';
|
|
13
|
+
}
|
|
14
|
+
const screenSize = 2 * getProjectedRadius(tile, frameState);
|
|
15
|
+
if (screenSize < 2) {
|
|
16
|
+
return 'OUT';
|
|
17
|
+
}
|
|
18
|
+
if (!tile.header.children || screenSize <= tile.lodMetricValue) {
|
|
19
|
+
return 'DRAW';
|
|
20
|
+
} else if (tile.header.children) {
|
|
21
|
+
return 'DIG';
|
|
22
|
+
}
|
|
23
|
+
return 'OUT';
|
|
24
|
+
}
|
|
25
|
+
export function getProjectedRadius(tile, frameState) {
|
|
26
|
+
const {
|
|
27
|
+
topDownViewport: viewport
|
|
28
|
+
} = frameState;
|
|
29
|
+
const mbsLat = tile.header.mbs[1];
|
|
30
|
+
const mbsLon = tile.header.mbs[0];
|
|
31
|
+
const mbsZ = tile.header.mbs[2];
|
|
32
|
+
const mbsR = tile.header.mbs[3];
|
|
33
|
+
const mbsCenterCartesian = [...tile.boundingVolume.center];
|
|
34
|
+
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
35
|
+
Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);
|
|
36
|
+
toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
|
|
37
|
+
Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
|
|
38
|
+
cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();
|
|
39
|
+
cameraPositionEnu.copy(cameraPositionCartesian).transform(cartesianToEnuMatrix);
|
|
40
|
+
const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
|
|
41
|
+
const extraZ = projection * projection / cameraPositionEnu[2];
|
|
42
|
+
extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
|
|
43
|
+
const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
|
|
44
|
+
const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();
|
|
45
|
+
const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
|
|
46
|
+
const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);
|
|
47
|
+
const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
|
|
48
|
+
const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
|
|
49
|
+
const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
|
|
50
|
+
const projectedRadius = projectedOriginVector.copy(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
|
|
51
|
+
return projectedRadius;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=i3s-lod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i3s-lod.js","names":["Matrix4","Vector3","Ellipsoid","cameraPositionCartesian","toEye","cameraPositionEnu","extraVertexEnu","projectedOriginVector","enuToCartesianMatrix","cartesianToEnuMatrix","getLodStatus","tile","frameState","lodMetricValue","isNaN","screenSize","getProjectedRadius","header","children","topDownViewport","viewport","mbsLat","mbs","mbsLon","mbsZ","mbsR","mbsCenterCartesian","boundingVolume","center","cameraPositionCartographic","unprojectPosition","cameraPosition","WGS84","cartographicToCartesian","copy","subtract","normalize","eastNorthUpToFixedFrame","invert","transform","projection","Math","sqrt","extraZ","extraVertexCartesian","extraVectorCartesian","radiusVector","cross","scale","sphereMbsBorderVertexCartesian","add","sphereMbsBorderVertexCartographic","cartesianToCartographic","projectedOrigin","project","projectedMbsBorderVertex","projectedRadius","magnitude"],"sources":["../../../../src/tileset/helpers/i3s-lod.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {Tile3D} from '../tile-3d';\nimport {FrameState} from './frame-state';\n\nconst cameraPositionCartesian = new Vector3();\nconst toEye = new Vector3();\nconst cameraPositionEnu = new Vector3();\nconst extraVertexEnu = new Vector3();\nconst projectedOriginVector = new Vector3();\nconst enuToCartesianMatrix = new Matrix4();\nconst cartesianToEnuMatrix = new Matrix4();\n\n/**\n * For the maxScreenThreshold error metric, maxError means that you should replace the node with it's children\n as soon as the nodes bounding sphere has a screen radius larger than maxError pixels.\n In this sense a value of 0 means you should always load it's children,\n or if it's a leaf node, you should always display it.\n * @param tile \n * @param frameState \n * @returns \n */\nexport function getLodStatus(tile: Tile3D, frameState: FrameState): 'DIG' | 'OUT' | 'DRAW' {\n if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {\n return 'DIG';\n }\n const screenSize = 2 * getProjectedRadius(tile, frameState);\n if (screenSize < 2) {\n return 'OUT';\n }\n if (!tile.header.children || screenSize <= tile.lodMetricValue) {\n return 'DRAW';\n } else if (tile.header.children) {\n return 'DIG';\n }\n return 'OUT';\n}\n\n/**\n * Calculate size of MBS radius projected on the screen plane\n * @param tile\n * @param frameState\n * @returns\n */\n// eslint-disable-next-line max-statements\nexport function getProjectedRadius(tile: Tile3D, frameState: FrameState): number {\n const {topDownViewport: viewport} = frameState;\n const mbsLat = tile.header.mbs[1];\n const mbsLon = tile.header.mbs[0];\n const mbsZ = tile.header.mbs[2];\n const mbsR = tile.header.mbs[3];\n const mbsCenterCartesian = [...tile.boundingVolume.center];\n const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);\n Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);\n\n // ---------------------------\n // Calculate mbs border vertex\n // ---------------------------\n toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();\n // Add extra vector to form plane\n Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);\n cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();\n cameraPositionEnu.copy(cameraPositionCartesian).transform(cartesianToEnuMatrix);\n // Mean Proportionals in Right Triangles - Altitude rule\n // https://mathbitsnotebook.com/Geometry/RightTriangles/RTmeanRight.html\n const projection = Math.sqrt(\n cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]\n );\n const extraZ = (projection * projection) / cameraPositionEnu[2];\n extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);\n const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);\n const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();\n // We need radius vector orthogonal to toEye vector\n const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);\n const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);\n const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(\n sphereMbsBorderVertexCartesian\n );\n // ---------------------------\n\n // Project center vertex and border vertex and calculate projected radius of MBS\n const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);\n const projectedMbsBorderVertex = viewport.project(\n sphereMbsBorderVertexCartographic as [number, number, number]\n );\n const projectedRadius = projectedOriginVector\n .copy(projectedOrigin)\n .subtract(projectedMbsBorderVertex)\n .magnitude();\n return projectedRadius;\n}\n"],"mappings":"AAEA,SAAQA,OAAO,EAAEC,OAAO,QAAO,eAAe;AAC9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