@loaders.gl/tiles 3.4.14 → 3.4.15
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/dist.min.js +122 -338
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/constants.js +6 -6
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/index.js +13 -13
- package/dist/es5/tileset/format-3d-tiles/tileset-3d-traverser.js +32 -53
- package/dist/es5/tileset/format-3d-tiles/tileset-3d-traverser.js.map +1 -1
- package/dist/es5/tileset/format-i3s/i3s-pending-tiles-register.js +21 -32
- package/dist/es5/tileset/format-i3s/i3s-pending-tiles-register.js.map +1 -1
- package/dist/es5/tileset/format-i3s/i3s-tile-manager.js +66 -63
- package/dist/es5/tileset/format-i3s/i3s-tile-manager.js.map +1 -1
- package/dist/es5/tileset/format-i3s/i3s-tileset-traverser.js +54 -121
- package/dist/es5/tileset/format-i3s/i3s-tileset-traverser.js.map +1 -1
- package/dist/es5/tileset/helpers/bounding-volume.js +48 -62
- package/dist/es5/tileset/helpers/bounding-volume.js.map +1 -1
- package/dist/es5/tileset/helpers/frame-state.js +67 -80
- package/dist/es5/tileset/helpers/frame-state.js.map +1 -1
- package/dist/es5/tileset/helpers/i3s-lod.js +27 -27
- package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -1
- package/dist/es5/tileset/helpers/tiles-3d-lod.js +51 -45
- package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +1 -1
- package/dist/es5/tileset/helpers/transform-utils.js +17 -11
- package/dist/es5/tileset/helpers/transform-utils.js.map +1 -1
- package/dist/es5/tileset/helpers/zoom.js +28 -28
- package/dist/es5/tileset/helpers/zoom.js.map +1 -1
- package/dist/es5/tileset/tile-3d.js +316 -430
- package/dist/es5/tileset/tile-3d.js.map +1 -1
- package/dist/es5/tileset/tileset-3d.js +460 -701
- package/dist/es5/tileset/tileset-3d.js.map +1 -1
- package/dist/es5/tileset/tileset-cache.js +41 -58
- package/dist/es5/tileset/tileset-cache.js.map +1 -1
- package/dist/es5/tileset/tileset-traverser.js +189 -264
- package/dist/es5/tileset/tileset-traverser.js.map +1 -1
- package/dist/es5/utils/doubly-linked-list-node.js +10 -11
- package/dist/es5/utils/doubly-linked-list-node.js.map +1 -1
- package/dist/es5/utils/doubly-linked-list.js +53 -68
- package/dist/es5/utils/doubly-linked-list.js.map +1 -1
- package/dist/es5/utils/managed-array.js +69 -100
- package/dist/es5/utils/managed-array.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.getFrameState = getFrameState;
|
|
8
7
|
exports.limitSelectedTiles = limitSelectedTiles;
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
8
|
var _core = require("@math.gl/core");
|
|
11
9
|
var _culling = require("@math.gl/culling");
|
|
12
10
|
var _geospatial = require("@math.gl/geospatial");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var scratchVector = new _core.Vector3();
|
|
17
|
-
var scratchPosition = new _core.Vector3();
|
|
18
|
-
var cullingVolume = new _culling.CullingVolume([new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane()]);
|
|
11
|
+
const scratchVector = new _core.Vector3();
|
|
12
|
+
const scratchPosition = new _core.Vector3();
|
|
13
|
+
const cullingVolume = new _culling.CullingVolume([new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane()]);
|
|
19
14
|
function getFrameState(viewport, frameNumber) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
const {
|
|
16
|
+
cameraDirection,
|
|
17
|
+
cameraUp,
|
|
18
|
+
height
|
|
19
|
+
} = viewport;
|
|
20
|
+
const {
|
|
21
|
+
metersPerUnit
|
|
22
|
+
} = viewport.distanceScales;
|
|
23
|
+
const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);
|
|
24
|
+
const enuToFixedTransform = _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
|
|
25
|
+
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
26
|
+
const cameraPositionCartesian = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new _core.Vector3());
|
|
27
|
+
const cameraDirectionCartesian = new _core.Vector3(enuToFixedTransform.transformAsVector(new _core.Vector3(cameraDirection).scale(metersPerUnit))).normalize();
|
|
28
|
+
const cameraUpCartesian = new _core.Vector3(enuToFixedTransform.transformAsVector(new _core.Vector3(cameraUp).scale(metersPerUnit))).normalize();
|
|
30
29
|
commonSpacePlanesToWGS84(viewport);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
const ViewportClass = viewport.constructor;
|
|
31
|
+
const {
|
|
32
|
+
longitude,
|
|
33
|
+
latitude,
|
|
34
|
+
width,
|
|
35
|
+
bearing,
|
|
36
|
+
zoom
|
|
37
|
+
} = viewport;
|
|
38
|
+
const topDownViewport = new ViewportClass({
|
|
39
|
+
longitude,
|
|
40
|
+
latitude,
|
|
41
|
+
height,
|
|
42
|
+
width,
|
|
43
|
+
bearing,
|
|
44
|
+
zoom,
|
|
44
45
|
pitch: 0
|
|
45
46
|
});
|
|
46
47
|
return {
|
|
@@ -49,11 +50,11 @@ function getFrameState(viewport, frameNumber) {
|
|
|
49
50
|
direction: cameraDirectionCartesian,
|
|
50
51
|
up: cameraUpCartesian
|
|
51
52
|
},
|
|
52
|
-
viewport
|
|
53
|
-
topDownViewport
|
|
54
|
-
height
|
|
55
|
-
cullingVolume
|
|
56
|
-
frameNumber
|
|
53
|
+
viewport,
|
|
54
|
+
topDownViewport,
|
|
55
|
+
height,
|
|
56
|
+
cullingVolume,
|
|
57
|
+
frameNumber,
|
|
57
58
|
sseDenominator: 1.15
|
|
58
59
|
};
|
|
59
60
|
}
|
|
@@ -61,69 +62,55 @@ function limitSelectedTiles(tiles, frameState, maximumTilesSelected) {
|
|
|
61
62
|
if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {
|
|
62
63
|
return [tiles, []];
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
viewportLongitude
|
|
67
|
-
viewportLatitude
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var _tile$header$mbs = (0, _slicedToArray2.default)(tile.header.mbs, 2),
|
|
76
|
-
longitude = _tile$header$mbs[0],
|
|
77
|
-
latitude = _tile$header$mbs[1];
|
|
78
|
-
var deltaLon = Math.abs(viewportLongitude - longitude);
|
|
79
|
-
var deltaLat = Math.abs(viewportLatitude - latitude);
|
|
80
|
-
var distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);
|
|
81
|
-
tuples.push([index, distance]);
|
|
82
|
-
}
|
|
83
|
-
} catch (err) {
|
|
84
|
-
_iterator.e(err);
|
|
85
|
-
} finally {
|
|
86
|
-
_iterator.f();
|
|
65
|
+
const tuples = [];
|
|
66
|
+
const {
|
|
67
|
+
longitude: viewportLongitude,
|
|
68
|
+
latitude: viewportLatitude
|
|
69
|
+
} = frameState.viewport;
|
|
70
|
+
for (const [index, tile] of tiles.entries()) {
|
|
71
|
+
const [longitude, latitude] = tile.header.mbs;
|
|
72
|
+
const deltaLon = Math.abs(viewportLongitude - longitude);
|
|
73
|
+
const deltaLat = Math.abs(viewportLatitude - latitude);
|
|
74
|
+
const distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);
|
|
75
|
+
tuples.push([index, distance]);
|
|
87
76
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
var selectedTiles = [];
|
|
92
|
-
for (var i = 0; i < maximumTilesSelected; i++) {
|
|
77
|
+
const tuplesSorted = tuples.sort((a, b) => a[1] - b[1]);
|
|
78
|
+
const selectedTiles = [];
|
|
79
|
+
for (let i = 0; i < maximumTilesSelected; i++) {
|
|
93
80
|
selectedTiles.push(tiles[tuplesSorted[i][0]]);
|
|
94
81
|
}
|
|
95
|
-
|
|
96
|
-
for (
|
|
97
|
-
unselectedTiles.push(tiles[tuplesSorted[
|
|
82
|
+
const unselectedTiles = [];
|
|
83
|
+
for (let i = maximumTilesSelected; i < tuplesSorted.length; i++) {
|
|
84
|
+
unselectedTiles.push(tiles[tuplesSorted[i][0]]);
|
|
98
85
|
}
|
|
99
86
|
return [selectedTiles, unselectedTiles];
|
|
100
87
|
}
|
|
101
88
|
function commonSpacePlanesToWGS84(viewport) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
const frustumPlanes = viewport.getFrustumPlanes();
|
|
90
|
+
const nearCenterCommon = closestPointOnPlane(frustumPlanes.near, viewport.cameraPosition);
|
|
91
|
+
const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);
|
|
92
|
+
const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition);
|
|
93
|
+
let i = 0;
|
|
107
94
|
cullingVolume.planes[i++].fromPointNormal(nearCenterCartesian, scratchVector.copy(nearCenterCartesian).subtract(cameraCartesian));
|
|
108
|
-
for (
|
|
95
|
+
for (const dir in frustumPlanes) {
|
|
109
96
|
if (dir === 'near') {
|
|
110
97
|
continue;
|
|
111
98
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
99
|
+
const plane = frustumPlanes[dir];
|
|
100
|
+
const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition);
|
|
101
|
+
const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition);
|
|
115
102
|
cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector.copy(nearCenterCartesian).subtract(cartesianPos));
|
|
116
103
|
}
|
|
117
104
|
}
|
|
118
105
|
function closestPointOnPlane(plane, refPoint) {
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
let out = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new _core.Vector3();
|
|
107
|
+
const distanceToRef = plane.normal.dot(refPoint);
|
|
121
108
|
out.copy(plane.normal).scale(plane.distance - distanceToRef).add(refPoint);
|
|
122
109
|
return out;
|
|
123
110
|
}
|
|
124
111
|
function worldToCartesian(viewport, point) {
|
|
125
|
-
|
|
126
|
-
|
|
112
|
+
let out = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new _core.Vector3();
|
|
113
|
+
const cartographicPos = viewport.unprojectPosition(point);
|
|
127
114
|
return _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, out);
|
|
128
115
|
}
|
|
129
116
|
//# sourceMappingURL=frame-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame-state.js","names":["_core","require","_culling","_geospatial","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","scratchVector","Vector3","scratchPosition","cullingVolume","CullingVolume","Plane","getFrameState","viewport","frameNumber","cameraDirection","cameraUp","height","metersPerUnit","distanceScales","viewportCenterCartesian","worldToCartesian","center","enuToFixedTransform","Ellipsoid","WGS84","eastNorthUpToFixedFrame","cameraPositionCartographic","unprojectPosition","cameraPosition","cameraPositionCartesian","cartographicToCartesian","cameraDirectionCartesian","transformAsVector","scale","normalize","cameraUpCartesian","commonSpacePlanesToWGS84","ViewportClass","longitude","latitude","width","bearing","zoom","topDownViewport","pitch","camera","position","direction","up","sseDenominator","limitSelectedTiles","tiles","frameState","maximumTilesSelected","tuples","_frameState$viewport","viewportLongitude","viewportLatitude","_iterator","entries","_step","_step$value","_slicedToArray2","default","index","tile","_tile$header$mbs","header","mbs","deltaLon","Math","abs","deltaLat","distance","sqrt","push","tuplesSorted","sort","a","b","selectedTiles","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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAA8C,SAAAG,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,EAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAQ,MAAA,qBAAAN,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAO,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAT,CAAA,CAAAQ,MAAA,WAAAK,IAAA,mBAAAA,IAAA,SAAAC,KAAA,EAAAd,CAAA,CAAAS,CAAA,UAAAM,CAAA,WAAAA,EAAAC,EAAA,UAAAA,EAAA,KAAAC,CAAA,EAAAP,CAAA,gBAAAQ,SAAA,iJAAAC,gBAAA,SAAAC,MAAA,UAAAC,GAAA,WAA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,CAAC;IAC/E,IAAMyF,YAAY,GAAG5E,gBAAgB,CAACR,QAAQ,EAAEmF,SAAS,EAAExF,eAAe,CAAC;IAE3EC,aAAa,CAACiF,MAAM,CAACnH,CAAC,EAAE,CAAC,CAACoH,eAAe,CACvCM,YAAY,EAEZ3F,aAAa,CAACsF,IAAI,CAACJ,mBAAmB,CAAC,CAACK,QAAQ,CAACI,YAAY,CAC/D,CAAC;EACH;AACF;AAEA,SAASX,mBAAmBA,CAC1BS,KAA0C,EAC1CG,QAA4C,EAEnC;EAAA,IADTC,GAAY,GAAAC,SAAA,CAAA9H,MAAA,QAAA8H,SAAA,QAAAC,SAAA,GAAAD,SAAA,MAAG,IAAI7F,aAAO,CAAC,CAAC;EAE5B,IAAM+F,aAAa,GAAGP,KAAK,CAACQ,MAAM,CAACC,GAAG,CAACN,QAAQ,CAAC;EAChDC,GAAG,CACAP,IAAI,CAACG,KAAK,CAACQ,MAAM,CAAC,CAClBrE,KAAK,CAAC6D,KAAK,CAACrB,QAAQ,GAAG4B,aAAa,CAAC,CACrCG,GAAG,CAACP,QAAQ,CAAC;EAChB,OAAOC,GAAG;AACZ;AAEA,SAAS9E,gBAAgBA,CACvBR,QAAkB,EAClB6F,KAAyB,EAEhB;EAAA,IADTP,GAAY,GAAAC,SAAA,CAAA9H,MAAA,QAAA8H,SAAA,QAAAC,SAAA,GAAAD,SAAA,MAAG,IAAI7F,aAAO,CAAC,CAAC;EAE5B,IAAMoG,eAAe,GAAG9F,QAAQ,CAACe,iBAAiB,CAAC8E,KAAK,CAAC;EACzD,OAAOlF,qBAAS,CAACC,KAAK,CAACM,uBAAuB,CAAC4E,eAAe,EAAER,GAAG,CAAC;AACtE"}
|
|
1
|
+
{"version":3,"file":"frame-state.js","names":["_core","require","_culling","_geospatial","scratchVector","Vector3","scratchPosition","cullingVolume","CullingVolume","Plane","getFrameState","viewport","frameNumber","cameraDirection","cameraUp","height","metersPerUnit","distanceScales","viewportCenterCartesian","worldToCartesian","center","enuToFixedTransform","Ellipsoid","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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAiBA,MAAMG,aAAa,GAAG,IAAIC,aAAO,CAAC,CAAC;AACnC,MAAMC,eAAe,GAAG,IAAID,aAAO,CAAC,CAAC;AACrC,MAAME,aAAa,GAAG,IAAIC,sBAAa,CAAC,CACtC,IAAIC,cAAK,CAAC,CAAC,EACX,IAAIA,cAAK,CAAC,CAAC,EACX,IAAIA,cAAK,CAAC,CAAC,EACX,IAAIA,cAAK,CAAC,CAAC,EACX,IAAIA,cAAK,CAAC,CAAC,EACX,IAAIA,cAAK,CAAC,CAAC,CACZ,CAAC;AAIK,SAASC,aAAaA,CAACC,QAA4B,EAAEC,WAAmB,EAAc;EAG3F,MAAM;IAACC,eAAe;IAAEC,QAAQ;IAAEC;EAAM,CAAC,GAAGJ,QAAQ;EACpD,MAAM;IAACK;EAAa,CAAC,GAAGL,QAAQ,CAACM,cAAc;EAI/C,MAAMC,uBAAuB,GAAGC,gBAAgB,CAACR,QAAQ,EAAEA,QAAQ,CAACS,MAAM,CAAC;EAC3E,MAAMC,mBAAmB,GAAGC,qBAAS,CAACC,KAAK,CAACC,uBAAuB,CAACN,uBAAuB,CAAC;EA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AACK,QAAQ,CAACI,YAAY,CAC/D,CAAC;EACH;AACF;AAEA,SAASX,mBAAmBA,CAC1BS,KAA0C,EAC1CG,QAA4C,EAEnC;EAAA,IADTC,GAAY,GAAAC,SAAA,CAAAxC,MAAA,QAAAwC,SAAA,QAAAC,SAAA,GAAAD,SAAA,MAAG,IAAIzF,aAAO,CAAC,CAAC;EAE5B,MAAM2F,aAAa,GAAGP,KAAK,CAACQ,MAAM,CAACC,GAAG,CAACN,QAAQ,CAAC;EAChDC,GAAG,CACAP,IAAI,CAACG,KAAK,CAACQ,MAAM,CAAC,CAClBjE,KAAK,CAACyD,KAAK,CAACtB,QAAQ,GAAG6B,aAAa,CAAC,CACrCG,GAAG,CAACP,QAAQ,CAAC;EAChB,OAAOC,GAAG;AACZ;AAEA,SAAS1E,gBAAgBA,CACvBR,QAAkB,EAClByF,KAAyB,EAEhB;EAAA,IADTP,GAAY,GAAAC,SAAA,CAAAxC,MAAA,QAAAwC,SAAA,QAAAC,SAAA,GAAAD,SAAA,MAAG,IAAIzF,aAAO,CAAC,CAAC;EAE5B,MAAMgG,eAAe,GAAG1F,QAAQ,CAACe,iBAAiB,CAAC0E,KAAK,CAAC;EACzD,OAAO9E,qBAAS,CAACC,KAAK,CAACM,uBAAuB,CAACwE,eAAe,EAAER,GAAG,CAAC;AACtE"}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.getLodStatus = getLodStatus;
|
|
8
7
|
exports.getProjectedRadius = getProjectedRadius;
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
8
|
var _core = require("@math.gl/core");
|
|
11
9
|
var _geospatial = require("@math.gl/geospatial");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
const cameraPositionCartesian = new _core.Vector3();
|
|
11
|
+
const toEye = new _core.Vector3();
|
|
12
|
+
const cameraPositionEnu = new _core.Vector3();
|
|
13
|
+
const extraVertexEnu = new _core.Vector3();
|
|
14
|
+
const projectedOriginVector = new _core.Vector3();
|
|
15
|
+
const enuToCartesianMatrix = new _core.Matrix4();
|
|
16
|
+
const cartesianToEnuMatrix = new _core.Matrix4();
|
|
19
17
|
function getLodStatus(tile, frameState) {
|
|
20
18
|
if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
|
|
21
19
|
return 'DIG';
|
|
22
20
|
}
|
|
23
|
-
|
|
21
|
+
const screenSize = 2 * getProjectedRadius(tile, frameState);
|
|
24
22
|
if (screenSize < 2) {
|
|
25
23
|
return 'OUT';
|
|
26
24
|
}
|
|
@@ -32,29 +30,31 @@ function getLodStatus(tile, frameState) {
|
|
|
32
30
|
return 'OUT';
|
|
33
31
|
}
|
|
34
32
|
function getProjectedRadius(tile, frameState) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
const {
|
|
34
|
+
topDownViewport: viewport
|
|
35
|
+
} = frameState;
|
|
36
|
+
const mbsLat = tile.header.mbs[1];
|
|
37
|
+
const mbsLon = tile.header.mbs[0];
|
|
38
|
+
const mbsZ = tile.header.mbs[2];
|
|
39
|
+
const mbsR = tile.header.mbs[3];
|
|
40
|
+
const mbsCenterCartesian = [...tile.boundingVolume.center];
|
|
41
|
+
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
42
42
|
_geospatial.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);
|
|
43
43
|
toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
|
|
44
44
|
_geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
|
|
45
45
|
cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();
|
|
46
46
|
cameraPositionEnu.copy(cameraPositionCartesian).transform(cartesianToEnuMatrix);
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
|
|
48
|
+
const extraZ = projection * projection / cameraPositionEnu[2];
|
|
49
49
|
extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
|
|
51
|
+
const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();
|
|
52
|
+
const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
|
|
53
|
+
const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);
|
|
54
|
+
const sphereMbsBorderVertexCartographic = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
|
|
55
|
+
const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
|
|
56
|
+
const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
|
|
57
|
+
const projectedRadius = projectedOriginVector.copy(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
|
|
58
58
|
return projectedRadius;
|
|
59
59
|
}
|
|
60
60
|
//# sourceMappingURL=i3s-lod.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i3s-lod.js","names":["_core","require","_geospatial","cameraPositionCartesian","Vector3","toEye","cameraPositionEnu","extraVertexEnu","projectedOriginVector","enuToCartesianMatrix","Matrix4","cartesianToEnuMatrix","getLodStatus","tile","frameState","lodMetricValue","isNaN","screenSize","getProjectedRadius","header","children","
|
|
1
|
+
{"version":3,"file":"i3s-lod.js","names":["_core","require","_geospatial","cameraPositionCartesian","Vector3","toEye","cameraPositionEnu","extraVertexEnu","projectedOriginVector","enuToCartesianMatrix","Matrix4","cartesianToEnuMatrix","getLodStatus","tile","frameState","lodMetricValue","isNaN","screenSize","getProjectedRadius","header","children","topDownViewport","viewport","mbsLat","mbs","mbsLon","mbsZ","mbsR","mbsCenterCartesian","boundingVolume","center","cameraPositionCartographic","unprojectPosition","cameraPosition","Ellipsoid","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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAIA,MAAME,uBAAuB,GAAG,IAAIC,aAAO,CAAC,CAAC;AAC7C,MAAMC,KAAK,GAAG,IAAID,aAAO,CAAC,CAAC;AAC3B,MAAME,iBAAiB,GAAG,IAAIF,aAAO,CAAC,CAAC;AACvC,MAAMG,cAAc,GAAG,IAAIH,aAAO,CAAC,CAAC;AACpC,MAAMI,qBAAqB,GAAG,IAAIJ,aAAO,CAAC,CAAC;AAC3C,MAAMK,oBAAoB,GAAG,IAAIC,aAAO,CAAC,CAAC;AAC1C,MAAMC,oBAAoB,GAAG,IAAID,aAAO,CAAC,CAAC;AAWnC,SAASE,YAAYA,CAACC,IAAY,EAAEC,UAAsB,EAA0B;EACzF,IAAID,IAAI,CAACE,cAAc,KAAK,CAAC,IAAIC,KAAK,CAACH,IAAI,CAACE,cAAc,CAAC,EAAE;IAC3D,OAAO,KAAK;EACd;EACA,MAAME,UAAU,GAAG,CAAC,GAAGC,kBAAkB,CAACL,IAAI,EAAEC,UAAU,CAAC;EAC3D,IAAIG,UAAU,GAAG,CAAC,EAAE;IAClB,OAAO,KAAK;EACd;EACA,IAAI,CAACJ,IAAI,CAACM,MAAM,CAACC,QAAQ,IAAIH,UAAU,IAAIJ,IAAI,CAACE,cAAc,EAAE;IAC9D,OAAO,MAAM;EACf,CAAC,MAAM,IAAIF,IAAI,CAACM,MAAM,CAACC,QAAQ,EAAE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C,CAC1F,CAAC;EACD,MAAMwC,MAAM,GAAIH,UAAU,GAAGA,UAAU,GAAIrC,iBAAiB,CAAC,CAAC,CAAC;EAC/DC,cAAc,CAAC8B,IAAI,CAAC,CAAC/B,iBAAiB,CAAC,CAAC,CAAC,EAAEA,iBAAiB,CAAC,CAAC,CAAC,EAAEwC,MAAM,CAAC,CAAC;EACzE,MAAMC,oBAAoB,GAAGxC,cAAc,CAACmC,SAAS,CAACjC,oBAAoB,CAAC;EAC3E,MAAMuC,oBAAoB,GAAGD,oBAAoB,CAACT,QAAQ,CAACV,kBAAkB,CAAC,CAACW,SAAS,CAAC,CAAC;EAE1F,MAAMU,YAAY,GAAG5C,KAAK,CAAC6C,KAAK,CAACF,oBAAoB,CAAC,CAACT,SAAS,CAAC,CAAC,CAACY,KAAK,CAACxB,IAAI,CAAC;EAC9E,MAAMyB,8BAA8B,GAAGH,YAAY,CAACI,GAAG,CAACzB,kBAAkB,CAAC;EAC3E,MAAM0B,iCAAiC,GAAGpB,qBAAS,CAACC,KAAK,CAACoB,uBAAuB,CAC/EH,8BACF,CAAC;EAID,MAAMI,eAAe,GAAGlC,QAAQ,CAACmC,OAAO,CAAC,CAAChC,MAAM,EAAEF,MAAM,EAAEG,IAAI,CAAC,CAAC;EAChE,MAAMgC,wBAAwB,GAAGpC,QAAQ,CAACmC,OAAO,CAC/CH,iCACF,CAAC;EACD,MAAMK,eAAe,GAAGnD,qBAAqB,CAC1C6B,IAAI,CAACmB,eAAe,CAAC,CACrBlB,QAAQ,CAACoB,wBAAwB,CAAC,CAClCE,SAAS,CAAC,CAAC;EACd,OAAOD,eAAe;AACxB"}
|
|
@@ -8,26 +8,28 @@ exports.fog = fog;
|
|
|
8
8
|
exports.getDynamicScreenSpaceError = getDynamicScreenSpaceError;
|
|
9
9
|
exports.getTiles3DScreenSpaceError = getTiles3DScreenSpaceError;
|
|
10
10
|
var _core = require("@math.gl/core");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const scratchPositionNormal = new _core.Vector3();
|
|
12
|
+
const scratchCartographic = new _core.Vector3();
|
|
13
|
+
const scratchMatrix = new _core.Matrix4();
|
|
14
|
+
const scratchCenter = new _core.Vector3();
|
|
15
|
+
const scratchPosition = new _core.Vector3();
|
|
16
|
+
const scratchDirection = new _core.Vector3();
|
|
17
17
|
function calculateDynamicScreenSpaceError(root, _ref) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
let {
|
|
19
|
+
camera,
|
|
20
|
+
mapProjection
|
|
21
|
+
} = _ref;
|
|
22
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
23
|
+
const {
|
|
24
|
+
dynamicScreenSpaceErrorHeightFalloff = 0.25,
|
|
25
|
+
dynamicScreenSpaceErrorDensity = 0.00278
|
|
26
|
+
} = options;
|
|
27
|
+
let up;
|
|
28
|
+
let direction;
|
|
29
|
+
let height;
|
|
30
|
+
let minimumHeight;
|
|
31
|
+
let maximumHeight;
|
|
32
|
+
const tileBoundingVolume = root.contentBoundingVolume;
|
|
31
33
|
if (tileBoundingVolume instanceof TileBoundingRegion) {
|
|
32
34
|
up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
|
|
33
35
|
direction = camera.directionWC;
|
|
@@ -35,68 +37,72 @@ function calculateDynamicScreenSpaceError(root, _ref) {
|
|
|
35
37
|
minimumHeight = tileBoundingVolume.minimumHeight;
|
|
36
38
|
maximumHeight = tileBoundingVolume.maximumHeight;
|
|
37
39
|
} else {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const transformLocal = _core.Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);
|
|
41
|
+
const ellipsoid = mapProjection.ellipsoid;
|
|
42
|
+
const boundingVolume = tileBoundingVolume.boundingVolume;
|
|
43
|
+
const centerLocal = _core.Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter);
|
|
42
44
|
if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {
|
|
43
|
-
|
|
45
|
+
const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic);
|
|
44
46
|
up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
|
|
45
47
|
direction = camera.directionWC;
|
|
46
48
|
height = camera.positionCartographic.height;
|
|
47
49
|
minimumHeight = 0.0;
|
|
48
50
|
maximumHeight = centerCartographic.height * 2.0;
|
|
49
51
|
} else {
|
|
50
|
-
|
|
52
|
+
const positionLocal = _core.Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition);
|
|
51
53
|
up = Cartesian3.UNIT_Z;
|
|
52
54
|
direction = _core.Matrix4.multiplyByPointAsVector(transformLocal, camera.directionWC, scratchDirection);
|
|
53
55
|
direction = Cartesian3.normalize(direction, direction);
|
|
54
56
|
height = positionLocal.z;
|
|
55
57
|
if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
|
|
56
|
-
|
|
58
|
+
const boxHeight = root._header.boundingVolume.box[11];
|
|
57
59
|
minimumHeight = centerLocal.z - boxHeight;
|
|
58
60
|
maximumHeight = centerLocal.z + boxHeight;
|
|
59
61
|
} else if (tileBoundingVolume instanceof TileBoundingSphere) {
|
|
60
|
-
|
|
62
|
+
const radius = boundingVolume.radius;
|
|
61
63
|
minimumHeight = centerLocal.z - radius;
|
|
62
64
|
maximumHeight = centerLocal.z + radius;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
|
|
69
|
+
const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
|
|
70
|
+
const heightFar = maximumHeight;
|
|
71
|
+
const t = (0, _core.clamp)((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
|
|
72
|
+
const dot = Math.abs(Cartesian3.dot(direction, up));
|
|
73
|
+
let horizonFactor = 1.0 - dot;
|
|
72
74
|
horizonFactor = horizonFactor * (1.0 - t);
|
|
73
75
|
return dynamicScreenSpaceErrorDensity * horizonFactor;
|
|
74
76
|
}
|
|
75
77
|
function fog(distanceToCamera, density) {
|
|
76
|
-
|
|
78
|
+
const scalar = distanceToCamera * density;
|
|
77
79
|
return 1.0 - Math.exp(-(scalar * scalar));
|
|
78
80
|
}
|
|
79
81
|
function getDynamicScreenSpaceError(tileset, distanceToCamera) {
|
|
80
82
|
if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
const density = tileset.dynamicScreenSpaceErrorComputedDensity;
|
|
84
|
+
const factor = tileset.dynamicScreenSpaceErrorFactor;
|
|
85
|
+
const dynamicError = fog(distanceToCamera, density) * factor;
|
|
84
86
|
return dynamicError;
|
|
85
87
|
}
|
|
86
88
|
return 0;
|
|
87
89
|
}
|
|
88
90
|
function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
const tileset = tile.tileset;
|
|
92
|
+
const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue;
|
|
93
|
+
const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
|
|
92
94
|
if (lodMetricValue === 0.0) {
|
|
93
95
|
return 0.0;
|
|
94
96
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
const distance = Math.max(tile._distanceToCamera, 1e-7);
|
|
98
|
+
const {
|
|
99
|
+
height,
|
|
100
|
+
sseDenominator
|
|
101
|
+
} = frameState;
|
|
102
|
+
const {
|
|
103
|
+
viewDistanceScale
|
|
104
|
+
} = tileset.options;
|
|
105
|
+
let error = lodMetricValue * height * (viewDistanceScale || 1.0) / (distance * sseDenominator);
|
|
100
106
|
error -= getDynamicScreenSpaceError(tileset, distance);
|
|
101
107
|
return error;
|
|
102
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiles-3d-lod.js","names":["_core","require","scratchPositionNormal","Vector3","scratchCartographic","scratchMatrix","Matrix4","scratchCenter","scratchPosition","scratchDirection","calculateDynamicScreenSpaceError","root","_ref","camera","mapProjection","options","arguments","length","undefined","_options$dynamicScree","dynamicScreenSpaceErrorHeightFalloff","_options$dynamicScree2","dynamicScreenSpaceErrorDensity","up","direction","height","minimumHeight","maximumHeight","tileBoundingVolume","contentBoundingVolume","TileBoundingRegion","Cartesian3","normalize","positionWC","directionWC","positionCartographic","transformLocal","inverseTransformation","computedTransform","ellipsoid","boundingVolume","centerLocal","multiplyByPoint","center","magnitude","minimumRadius","centerCartographic","Cartographic","fromCartesian","positionLocal","UNIT_Z","multiplyByPointAsVector","z","TileOrientedBoundingBox","boxHeight","_header","box","TileBoundingSphere","radius","heightFalloff","heightClose","heightFar","t","clamp","dot","Math","abs","horizonFactor","fog","distanceToCamera","density","scalar","exp","getDynamicScreenSpaceError","tileset","dynamicScreenSpaceError","dynamicScreenSpaceErrorComputedDensity","factor","dynamicScreenSpaceErrorFactor","dynamicError","getTiles3DScreenSpaceError","tile","frameState","useParentLodMetric","parentLodMetricValue","parent","lodMetricValue","distance","max","_distanceToCamera","sseDenominator","viewDistanceScale","error"],"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n// 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// TODO - Dynamic screen space error provides an optimization when looking at\n// tilesets from above\n\n/* eslint-disable */\n// @ts-nocheck\nimport {Matrix4, Vector3, clamp} from '@math.gl/core';\n\nconst scratchPositionNormal = new Vector3();\nconst scratchCartographic = new Vector3();\nconst scratchMatrix = new Matrix4();\nconst scratchCenter = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchDirection = new Vector3();\n\n// eslint-disable-next-line max-statements, complexity\nexport function calculateDynamicScreenSpaceError(root, {camera, mapProjection}, options = {}) {\n const {dynamicScreenSpaceErrorHeightFalloff = 0.25, dynamicScreenSpaceErrorDensity = 0.00278} =\n options;\n\n let up;\n let direction;\n let height;\n let minimumHeight;\n let maximumHeight;\n\n const tileBoundingVolume = root.contentBoundingVolume;\n\n if (tileBoundingVolume instanceof TileBoundingRegion) {\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = tileBoundingVolume.minimumHeight;\n maximumHeight = tileBoundingVolume.maximumHeight;\n } else {\n // Transform camera position and direction into the local coordinate system of the tileset\n const transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);\n const ellipsoid = mapProjection.ellipsoid;\n const boundingVolume = tileBoundingVolume.boundingVolume;\n const centerLocal = Matrix4.multiplyByPoint(\n transformLocal,\n boundingVolume.center,\n scratchCenter\n );\n if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {\n // The tileset is defined in WGS84. Approximate the minimum and maximum height.\n const centerCartographic = Cartographic.fromCartesian(\n centerLocal,\n ellipsoid,\n scratchCartographic\n );\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = 0.0;\n maximumHeight = centerCartographic.height * 2.0;\n } else {\n // The tileset is defined in local coordinates (z-up)\n const positionLocal = Matrix4.multiplyByPoint(\n transformLocal,\n camera.positionWC,\n scratchPosition\n );\n up = Cartesian3.UNIT_Z;\n direction = Matrix4.multiplyByPointAsVector(\n transformLocal,\n camera.directionWC,\n scratchDirection\n );\n direction = Cartesian3.normalize(direction, direction);\n height = positionLocal.z;\n if (tileBoundingVolume instanceof TileOrientedBoundingBox) {\n // Assuming z-up, the last component stores the half-height of the box\n const boxHeight = root._header.boundingVolume.box[11];\n minimumHeight = centerLocal.z - boxHeight;\n maximumHeight = centerLocal.z + boxHeight;\n } else if (tileBoundingVolume instanceof TileBoundingSphere) {\n const radius = boundingVolume.radius;\n minimumHeight = centerLocal.z - radius;\n maximumHeight = centerLocal.z + radius;\n }\n }\n }\n\n // The range where the density starts to lessen. Start at the quarter height of the tileset.\n const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;\n const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;\n const heightFar = maximumHeight;\n\n const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);\n\n // Increase density as the camera tilts towards the horizon\n const dot = Math.abs(Cartesian3.dot(direction, up));\n\n let horizonFactor = 1.0 - dot;\n\n // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.\n // The goal is to increase density for the \"street view\", not when viewing the tileset from a distance.\n horizonFactor = horizonFactor * (1.0 - t);\n\n return dynamicScreenSpaceErrorDensity * horizonFactor;\n}\n\nexport function fog(distanceToCamera, density) {\n const scalar = distanceToCamera * density;\n return 1.0 - Math.exp(-(scalar * scalar));\n}\n\nexport function getDynamicScreenSpaceError(tileset, distanceToCamera) {\n if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {\n const density = tileset.dynamicScreenSpaceErrorComputedDensity;\n const factor = tileset.dynamicScreenSpaceErrorFactor;\n // TODO: Refined screen space error that minimizes tiles in non-first-person\n const dynamicError = fog(distanceToCamera, density) * factor;\n return dynamicError;\n }\n\n return 0;\n}\n\nexport function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {\n const tileset = tile.tileset;\n const parentLodMetricValue = (tile.parent && tile.parent.lodMetricValue) || tile.lodMetricValue;\n const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;\n\n // Leaf tiles do not have any error so save the computation\n if (lodMetricValue === 0.0) {\n return 0.0;\n }\n\n // TODO: Orthographic Frustum needs special treatment?\n // this._getOrthograhicScreenSpaceError();\n\n // Avoid divide by zero when viewer is inside the tile\n const distance = Math.max(tile._distanceToCamera, 1e-7);\n const {height, sseDenominator} = frameState;\n const {viewDistanceScale} = tileset.options;\n let error = (lodMetricValue * height * (viewDistanceScale || 1.0)) / (distance * sseDenominator);\n\n error -= getDynamicScreenSpaceError(tileset, distance);\n\n return error;\n}\n"],"mappings":";;;;;;;;;AAUA,IAAAA,KAAA,GAAAC,OAAA;AAEA,IAAMC,qBAAqB,GAAG,IAAIC,aAAO,CAAC,CAAC;AAC3C,IAAMC,mBAAmB,GAAG,IAAID,aAAO,CAAC,CAAC;AACzC,IAAME,aAAa,GAAG,IAAIC,aAAO,CAAC,CAAC;AACnC,IAAMC,aAAa,GAAG,IAAIJ,aAAO,CAAC,CAAC;AACnC,IAAMK,eAAe,GAAG,IAAIL,aAAO,CAAC,CAAC;AACrC,IAAMM,gBAAgB,GAAG,IAAIN,aAAO,CAAC,CAAC;AAG/B,SAASO,gCAAgCA,CAACC,IAAI,EAAAC,IAAA,EAAyC;EAAA,IAAtCC,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAEC,aAAa,GAAAF,IAAA,CAAbE,aAAa;EAAA,IAAGC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC1F,IAAAG,qBAAA,GACEJ,OAAO,CADFK,oCAAoC;IAApCA,oCAAoC,GAAAD,qBAAA,cAAG,IAAI,GAAAA,qBAAA;IAAAE,sBAAA,GAChDN,OAAO,CAD2CO,8BAA8B;IAA9BA,8BAA8B,GAAAD,sBAAA,cAAG,OAAO,GAAAA,sBAAA;EAG5F,IAAIE,EAAE;EACN,IAAIC,SAAS;EACb,IAAIC,MAAM;EACV,IAAIC,aAAa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AApC4E,iBAAiB;EACxB,IAAIC,KAAK,GAAIN,cAAc,GAAG7D,MAAM,IAAIkE,iBAAiB,IAAI,GAAG,CAAC,IAAKJ,QAAQ,GAAGG,cAAc,CAAC;EAEhGE,KAAK,IAAInB,0BAA0B,CAACC,OAAO,EAAEa,QAAQ,CAAC;EAEtD,OAAOK,KAAK;AACd"}
|
|
1
|
+
{"version":3,"file":"tiles-3d-lod.js","names":["_core","require","scratchPositionNormal","Vector3","scratchCartographic","scratchMatrix","Matrix4","scratchCenter","scratchPosition","scratchDirection","calculateDynamicScreenSpaceError","root","_ref","camera","mapProjection","options","arguments","length","undefined","dynamicScreenSpaceErrorHeightFalloff","dynamicScreenSpaceErrorDensity","up","direction","height","minimumHeight","maximumHeight","tileBoundingVolume","contentBoundingVolume","TileBoundingRegion","Cartesian3","normalize","positionWC","directionWC","positionCartographic","transformLocal","inverseTransformation","computedTransform","ellipsoid","boundingVolume","centerLocal","multiplyByPoint","center","magnitude","minimumRadius","centerCartographic","Cartographic","fromCartesian","positionLocal","UNIT_Z","multiplyByPointAsVector","z","TileOrientedBoundingBox","boxHeight","_header","box","TileBoundingSphere","radius","heightFalloff","heightClose","heightFar","t","clamp","dot","Math","abs","horizonFactor","fog","distanceToCamera","density","scalar","exp","getDynamicScreenSpaceError","tileset","dynamicScreenSpaceError","dynamicScreenSpaceErrorComputedDensity","factor","dynamicScreenSpaceErrorFactor","dynamicError","getTiles3DScreenSpaceError","tile","frameState","useParentLodMetric","parentLodMetricValue","parent","lodMetricValue","distance","max","_distanceToCamera","sseDenominator","viewDistanceScale","error"],"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n// 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// TODO - Dynamic screen space error provides an optimization when looking at\n// tilesets from above\n\n/* eslint-disable */\n// @ts-nocheck\nimport {Matrix4, Vector3, clamp} from '@math.gl/core';\n\nconst scratchPositionNormal = new Vector3();\nconst scratchCartographic = new Vector3();\nconst scratchMatrix = new Matrix4();\nconst scratchCenter = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchDirection = new Vector3();\n\n// eslint-disable-next-line max-statements, complexity\nexport function calculateDynamicScreenSpaceError(root, {camera, mapProjection}, options = {}) {\n const {dynamicScreenSpaceErrorHeightFalloff = 0.25, dynamicScreenSpaceErrorDensity = 0.00278} =\n options;\n\n let up;\n let direction;\n let height;\n let minimumHeight;\n let maximumHeight;\n\n const tileBoundingVolume = root.contentBoundingVolume;\n\n if (tileBoundingVolume instanceof TileBoundingRegion) {\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = tileBoundingVolume.minimumHeight;\n maximumHeight = tileBoundingVolume.maximumHeight;\n } else {\n // Transform camera position and direction into the local coordinate system of the tileset\n const transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);\n const ellipsoid = mapProjection.ellipsoid;\n const boundingVolume = tileBoundingVolume.boundingVolume;\n const centerLocal = Matrix4.multiplyByPoint(\n transformLocal,\n boundingVolume.center,\n scratchCenter\n );\n if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {\n // The tileset is defined in WGS84. Approximate the minimum and maximum height.\n const centerCartographic = Cartographic.fromCartesian(\n centerLocal,\n ellipsoid,\n scratchCartographic\n );\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = 0.0;\n maximumHeight = centerCartographic.height * 2.0;\n } else {\n // The tileset is defined in local coordinates (z-up)\n const positionLocal = Matrix4.multiplyByPoint(\n transformLocal,\n camera.positionWC,\n scratchPosition\n );\n up = Cartesian3.UNIT_Z;\n direction = Matrix4.multiplyByPointAsVector(\n transformLocal,\n camera.directionWC,\n scratchDirection\n );\n direction = Cartesian3.normalize(direction, direction);\n height = positionLocal.z;\n if (tileBoundingVolume instanceof TileOrientedBoundingBox) {\n // Assuming z-up, the last component stores the half-height of the box\n const boxHeight = root._header.boundingVolume.box[11];\n minimumHeight = centerLocal.z - boxHeight;\n maximumHeight = centerLocal.z + boxHeight;\n } else if (tileBoundingVolume instanceof TileBoundingSphere) {\n const radius = boundingVolume.radius;\n minimumHeight = centerLocal.z - radius;\n maximumHeight = centerLocal.z + radius;\n }\n }\n }\n\n // The range where the density starts to lessen. Start at the quarter height of the tileset.\n const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;\n const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;\n const heightFar = maximumHeight;\n\n const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);\n\n // Increase density as the camera tilts towards the horizon\n const dot = Math.abs(Cartesian3.dot(direction, up));\n\n let horizonFactor = 1.0 - dot;\n\n // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.\n // The goal is to increase density for the \"street view\", not when viewing the tileset from a distance.\n horizonFactor = horizonFactor * (1.0 - t);\n\n return dynamicScreenSpaceErrorDensity * horizonFactor;\n}\n\nexport function fog(distanceToCamera, density) {\n const scalar = distanceToCamera * density;\n return 1.0 - Math.exp(-(scalar * scalar));\n}\n\nexport function getDynamicScreenSpaceError(tileset, distanceToCamera) {\n if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {\n const density = tileset.dynamicScreenSpaceErrorComputedDensity;\n const factor = tileset.dynamicScreenSpaceErrorFactor;\n // TODO: Refined screen space error that minimizes tiles in non-first-person\n const dynamicError = fog(distanceToCamera, density) * factor;\n return dynamicError;\n }\n\n return 0;\n}\n\nexport function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {\n const tileset = tile.tileset;\n const parentLodMetricValue = (tile.parent && tile.parent.lodMetricValue) || tile.lodMetricValue;\n const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;\n\n // Leaf tiles do not have any error so save the computation\n if (lodMetricValue === 0.0) {\n return 0.0;\n }\n\n // TODO: Orthographic Frustum needs special treatment?\n // this._getOrthograhicScreenSpaceError();\n\n // Avoid divide by zero when viewer is inside the tile\n const distance = Math.max(tile._distanceToCamera, 1e-7);\n const {height, sseDenominator} = frameState;\n const {viewDistanceScale} = tileset.options;\n let error = (lodMetricValue * height * (viewDistanceScale || 1.0)) / (distance * sseDenominator);\n\n error -= getDynamicScreenSpaceError(tileset, distance);\n\n return error;\n}\n"],"mappings":";;;;;;;;;AAUA,IAAAA,KAAA,GAAAC,OAAA;AAEA,MAAMC,qBAAqB,GAAG,IAAIC,aAAO,CAAC,CAAC;AAC3C,MAAMC,mBAAmB,GAAG,IAAID,aAAO,CAAC,CAAC;AACzC,MAAME,aAAa,GAAG,IAAIC,aAAO,CAAC,CAAC;AACnC,MAAMC,aAAa,GAAG,IAAIJ,aAAO,CAAC,CAAC;AACnC,MAAMK,eAAe,GAAG,IAAIL,aAAO,CAAC,CAAC;AACrC,MAAMM,gBAAgB,GAAG,IAAIN,aAAO,CAAC,CAAC;AAG/B,SAASO,gCAAgCA,CAACC,IAAI,EAAAC,IAAA,EAAyC;EAAA,IAAvC;IAACC,MAAM;IAAEC;EAAa,CAAC,GAAAF,IAAA;EAAA,IAAEG,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC1F,MAAM;IAACG,oCAAoC,GAAG,IAAI;IAAEC,8BAA8B,GAAG;EAAO,CAAC,GAC3FL,OAAO;EAET,IAAIM,EAAE;EACN,IAAIC,SAAS;EACb,IAAIC,MAAM;EACV,IAAIC,aAAa;EACjB,IAAIC,aAAa;EAEjB,MAAMC,kBAAkB,GAAGf,IAAI,CAACgB,qBAAqB;EAErD,IAAID,kBAAkB,YAAYE,kBAAkB,EAAE;IACpDP,EAAE,GAAGQ,UAAU,CAACC,SAAS,CAACjB,MAAM,CAACkB,UAAU,EAAE7B,qBAAqB,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