@loaders.gl/tiles 3.1.0-alpha.1 → 3.1.0-alpha.5

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.
Files changed (131) hide show
  1. package/dist/bundle.d.ts +1 -0
  2. package/dist/constants.d.ts +31 -0
  3. package/dist/dist.min.js +1 -1
  4. package/dist/dist.min.js.map +1 -1
  5. package/dist/es5/bundle.js +7 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/constants.js +44 -0
  8. package/dist/es5/constants.js.map +1 -0
  9. package/dist/es5/index.js +104 -0
  10. package/dist/es5/index.js.map +1 -0
  11. package/dist/es5/tileset/helpers/3d-tiles-options.js +13 -0
  12. package/dist/es5/tileset/helpers/3d-tiles-options.js.map +1 -0
  13. package/dist/es5/tileset/helpers/bounding-volume.js +102 -0
  14. package/dist/es5/tileset/helpers/bounding-volume.js.map +1 -0
  15. package/dist/es5/tileset/helpers/frame-state.js +69 -0
  16. package/dist/es5/tileset/helpers/frame-state.js.map +1 -0
  17. package/dist/es5/tileset/helpers/i3s-lod.js +84 -0
  18. package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -0
  19. package/dist/es5/tileset/helpers/tiles-3d-lod.js +123 -0
  20. package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +1 -0
  21. package/dist/es5/tileset/helpers/transform-utils.js +71 -0
  22. package/dist/es5/tileset/helpers/transform-utils.js.map +1 -0
  23. package/dist/es5/tileset/helpers/zoom.js +45 -0
  24. package/dist/es5/tileset/helpers/zoom.js.map +1 -0
  25. package/dist/es5/tileset/tile-3d.js +510 -0
  26. package/dist/es5/tileset/tile-3d.js.map +1 -0
  27. package/dist/es5/tileset/tileset-3d.js +656 -0
  28. package/dist/es5/tileset/tileset-3d.js.map +1 -0
  29. package/dist/es5/tileset/tileset-cache.js +88 -0
  30. package/dist/es5/tileset/tileset-cache.js.map +1 -0
  31. package/dist/es5/tileset/traversers/i3s-tile-manager.js +57 -0
  32. package/dist/es5/tileset/traversers/i3s-tile-manager.js.map +1 -0
  33. package/dist/es5/tileset/traversers/i3s-tileset-traverser.js +95 -0
  34. package/dist/es5/tileset/traversers/i3s-tileset-traverser.js.map +1 -0
  35. package/dist/es5/tileset/traversers/tileset-3d-traverser.js +66 -0
  36. package/dist/es5/tileset/traversers/tileset-3d-traverser.js.map +1 -0
  37. package/dist/es5/tileset/traversers/tileset-traverser.js +304 -0
  38. package/dist/es5/tileset/traversers/tileset-traverser.js.map +1 -0
  39. package/dist/es5/utils/doubly-linked-list-node.js +18 -0
  40. package/dist/es5/utils/doubly-linked-list-node.js.map +1 -0
  41. package/dist/es5/utils/doubly-linked-list.js +90 -0
  42. package/dist/es5/utils/doubly-linked-list.js.map +1 -0
  43. package/dist/es5/utils/managed-array.js +121 -0
  44. package/dist/es5/utils/managed-array.js.map +1 -0
  45. package/dist/esm/bundle.js +5 -0
  46. package/dist/esm/bundle.js.map +1 -0
  47. package/dist/{constants.js → esm/constants.js} +0 -0
  48. package/dist/esm/constants.js.map +1 -0
  49. package/dist/{index.js → esm/index.js} +1 -0
  50. package/dist/esm/index.js.map +1 -0
  51. package/dist/{tileset → esm/tileset}/helpers/3d-tiles-options.js +0 -0
  52. package/dist/esm/tileset/helpers/3d-tiles-options.js.map +1 -0
  53. package/dist/{tileset → esm/tileset}/helpers/bounding-volume.js +0 -0
  54. package/dist/esm/tileset/helpers/bounding-volume.js.map +1 -0
  55. package/dist/{tileset → esm/tileset}/helpers/frame-state.js +0 -0
  56. package/dist/esm/tileset/helpers/frame-state.js.map +1 -0
  57. package/dist/esm/tileset/helpers/i3s-lod.js +67 -0
  58. package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -0
  59. package/dist/{tileset → esm/tileset}/helpers/tiles-3d-lod.js +0 -0
  60. package/dist/esm/tileset/helpers/tiles-3d-lod.js.map +1 -0
  61. package/dist/{tileset → esm/tileset}/helpers/transform-utils.js +4 -1
  62. package/dist/esm/tileset/helpers/transform-utils.js.map +1 -0
  63. package/dist/{tileset → esm/tileset}/helpers/zoom.js +0 -0
  64. package/dist/esm/tileset/helpers/zoom.js.map +1 -0
  65. package/dist/{tileset → esm/tileset}/tile-3d.js +3 -3
  66. package/dist/esm/tileset/tile-3d.js.map +1 -0
  67. package/dist/{tileset → esm/tileset}/tileset-3d.js +5 -5
  68. package/dist/esm/tileset/tileset-3d.js.map +1 -0
  69. package/dist/{tileset → esm/tileset}/tileset-cache.js +0 -0
  70. package/dist/esm/tileset/tileset-cache.js.map +1 -0
  71. package/dist/{tileset → esm/tileset}/traversers/i3s-tile-manager.js +0 -0
  72. package/dist/esm/tileset/traversers/i3s-tile-manager.js.map +1 -0
  73. package/dist/{tileset → esm/tileset}/traversers/i3s-tileset-traverser.js +4 -4
  74. package/dist/esm/tileset/traversers/i3s-tileset-traverser.js.map +1 -0
  75. package/dist/{tileset → esm/tileset}/traversers/tileset-3d-traverser.js +0 -0
  76. package/dist/esm/tileset/traversers/tileset-3d-traverser.js.map +1 -0
  77. package/dist/{tileset → esm/tileset}/traversers/tileset-traverser.js +0 -0
  78. package/dist/esm/tileset/traversers/tileset-traverser.js.map +1 -0
  79. package/dist/{utils → esm/utils}/doubly-linked-list-node.js +0 -0
  80. package/dist/esm/utils/doubly-linked-list-node.js.map +1 -0
  81. package/dist/{utils → esm/utils}/doubly-linked-list.js +0 -0
  82. package/dist/esm/utils/doubly-linked-list.js.map +1 -0
  83. package/dist/{utils → esm/utils}/managed-array.js +0 -0
  84. package/dist/esm/utils/managed-array.js.map +1 -0
  85. package/dist/index.d.ts +10 -0
  86. package/dist/tileset/helpers/3d-tiles-options.d.ts +3 -0
  87. package/dist/tileset/helpers/bounding-volume.d.ts +8 -0
  88. package/dist/tileset/helpers/frame-state.d.ts +16 -0
  89. package/dist/tileset/helpers/i3s-lod.d.ts +19 -0
  90. package/dist/tileset/helpers/tiles-3d-lod.d.ts +7 -0
  91. package/dist/tileset/helpers/transform-utils.d.ts +1 -0
  92. package/dist/tileset/helpers/zoom.d.ts +6 -0
  93. package/dist/tileset/tile-3d.d.ts +173 -0
  94. package/dist/tileset/tileset-3d.d.ts +171 -0
  95. package/dist/tileset/tileset-cache.d.ts +17 -0
  96. package/dist/tileset/traversers/i3s-tile-manager.d.ts +7 -0
  97. package/dist/tileset/traversers/i3s-tileset-traverser.d.ts +17 -0
  98. package/dist/tileset/traversers/tileset-3d-traverser.d.ts +6 -0
  99. package/dist/tileset/traversers/tileset-traverser.d.ts +51 -0
  100. package/dist/utils/doubly-linked-list-node.d.ts +11 -0
  101. package/dist/utils/doubly-linked-list.d.ts +30 -0
  102. package/dist/utils/managed-array.d.ts +84 -0
  103. package/package.json +11 -8
  104. package/src/bundle.ts +2 -3
  105. package/src/index.ts +1 -0
  106. package/src/tileset/helpers/i3s-lod.ts +72 -96
  107. package/src/tileset/helpers/transform-utils.ts +3 -1
  108. package/src/tileset/tile-3d.ts +2 -2
  109. package/src/tileset/traversers/i3s-tileset-traverser.ts +2 -3
  110. package/dist/bundle.js +0 -7
  111. package/dist/bundle.js.map +0 -1
  112. package/dist/constants.js.map +0 -1
  113. package/dist/index.js.map +0 -1
  114. package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
  115. package/dist/tileset/helpers/bounding-volume.js.map +0 -1
  116. package/dist/tileset/helpers/frame-state.js.map +0 -1
  117. package/dist/tileset/helpers/i3s-lod.js +0 -108
  118. package/dist/tileset/helpers/i3s-lod.js.map +0 -1
  119. package/dist/tileset/helpers/tiles-3d-lod.js.map +0 -1
  120. package/dist/tileset/helpers/transform-utils.js.map +0 -1
  121. package/dist/tileset/helpers/zoom.js.map +0 -1
  122. package/dist/tileset/tile-3d.js.map +0 -1
  123. package/dist/tileset/tileset-3d.js.map +0 -1
  124. package/dist/tileset/tileset-cache.js.map +0 -1
  125. package/dist/tileset/traversers/i3s-tile-manager.js.map +0 -1
  126. package/dist/tileset/traversers/i3s-tileset-traverser.js.map +0 -1
  127. package/dist/tileset/traversers/tileset-3d-traverser.js.map +0 -1
  128. package/dist/tileset/traversers/tileset-traverser.js.map +0 -1
  129. package/dist/utils/doubly-linked-list-node.js.map +0 -1
  130. package/dist/utils/doubly-linked-list.js.map +0 -1
  131. package/dist/utils/managed-array.js.map +0 -1
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Doubly linked list
3
+ *
4
+ * @private
5
+ */
6
+ export default class DoublyLinkedList {
7
+ head: any;
8
+ tail: any;
9
+ _length: number;
10
+ get length(): number;
11
+ /**
12
+ * Adds the item to the end of the list
13
+ * @param {*} [item]
14
+ * @return {DoublyLinkedListNode}
15
+ */
16
+ add(item?: any): DoublyLinkedListNode;
17
+ /**
18
+ * Removes the given node from the list
19
+ * @param {DoublyLinkedListNode} node
20
+ */
21
+ remove(node: DoublyLinkedListNode): void;
22
+ /**
23
+ * Moves nextNode after node
24
+ * @param {DoublyLinkedListNode} node
25
+ * @param {DoublyLinkedListNode} nextNode
26
+ */
27
+ splice(node: DoublyLinkedListNode, nextNode: DoublyLinkedListNode): void;
28
+ _insert(node: any, nextNode: any): void;
29
+ }
30
+ import DoublyLinkedListNode from "../utils/doubly-linked-list-node";
@@ -0,0 +1,84 @@
1
+ /**
2
+ * A wrapper around arrays so that the internal length of the array can be manually managed.
3
+ *
4
+ * @alias ManagedArray
5
+ * @constructor
6
+ * @private
7
+ *
8
+ * @param {Number} [length=0] The initial length of the array.
9
+ */
10
+ export default class ManagedArray {
11
+ constructor(length?: number);
12
+ _array: any[];
13
+ _map: Map<any, any>;
14
+ _length: number;
15
+ set length(arg: number);
16
+ /**
17
+ * Gets or sets the length of the array.
18
+ * If the set length is greater than the length of the internal array, the internal array is resized.
19
+ *
20
+ * @memberof ManagedArray.prototype
21
+ * @type Number
22
+ */
23
+ get length(): number;
24
+ /**
25
+ * Gets the internal array.
26
+ *
27
+ * @memberof ManagedArray.prototype
28
+ * @type Array
29
+ * @readonly
30
+ */
31
+ readonly get values(): any[];
32
+ /**
33
+ * Gets the element at an index.
34
+ *
35
+ * @param {Number} index The index to get.
36
+ */
37
+ get(index: number): any;
38
+ /**
39
+ * Sets the element at an index. Resizes the array if index is greater than the length of the array.
40
+ *
41
+ * @param {Number} index The index to set.
42
+ * @param {*} element The element to set at index.
43
+ */
44
+ set(index: number, element: any): void;
45
+ delete(element: any): void;
46
+ /**
47
+ * Returns the last element in the array without modifying the array.
48
+ *
49
+ * @returns {*} The last element in the array.
50
+ */
51
+ peek(): any;
52
+ /**
53
+ * Push an element into the array.
54
+ *
55
+ * @param {*} element The element to push.
56
+ */
57
+ push(element: any): void;
58
+ /**
59
+ * Pop an element from the array.
60
+ *
61
+ * @returns {*} The last element in the array.
62
+ */
63
+ pop(): any;
64
+ /**
65
+ * Resize the internal array if length > _array.length.
66
+ *
67
+ * @param {Number} length The length.
68
+ */
69
+ reserve(length: number): void;
70
+ /**
71
+ * Resize the array.
72
+ *
73
+ * @param {Number} length The length.
74
+ */
75
+ resize(length: number): void;
76
+ /**
77
+ * Trim the internal array to the specified length. Defaults to the current length.
78
+ *
79
+ * @param {Number} [length] The length.
80
+ */
81
+ trim(length?: number | undefined): void;
82
+ reset(): void;
83
+ find(target: any): boolean;
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tiles",
3
- "version": "3.1.0-alpha.1",
3
+ "version": "3.1.0-alpha.5",
4
4
  "description": "Common components for different tiles loaders.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -19,9 +19,9 @@
19
19
  "point cloud",
20
20
  "pointcloud"
21
21
  ],
22
- "types": "src/index.ts",
23
- "main": "dist/index.js",
24
- "module": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "main": "dist/es5/index.js",
24
+ "module": "dist/esm/index.js",
25
25
  "sideEffects": false,
26
26
  "files": [
27
27
  "src",
@@ -30,17 +30,20 @@
30
30
  ],
31
31
  "scripts": {
32
32
  "pre-build": "npm run build-bundle",
33
+ "post-build": "tsc",
33
34
  "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js"
34
35
  },
35
36
  "dependencies": {
36
- "@loaders.gl/core": "3.1.0-alpha.1",
37
- "@loaders.gl/loader-utils": "3.1.0-alpha.1",
38
- "@loaders.gl/math": "3.1.0-alpha.1",
37
+ "@loaders.gl/loader-utils": "3.1.0-alpha.5",
38
+ "@loaders.gl/math": "3.1.0-alpha.5",
39
39
  "@math.gl/core": "^3.5.1",
40
40
  "@math.gl/culling": "^3.5.1",
41
41
  "@math.gl/geospatial": "^3.5.1",
42
42
  "@math.gl/web-mercator": "^3.5.1",
43
43
  "@probe.gl/stats": "^3.4.0"
44
44
  },
45
- "gitHead": "725f6ceeb9d76dacff6305f01bc45873680f17d5"
45
+ "peerDependencies": {
46
+ "@loaders.gl/core": "^3.0.0"
47
+ },
48
+ "gitHead": "352241dd910a8c6307a235dadbe154ca915b885b"
46
49
  }
package/src/bundle.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  // @ts-nocheck
2
2
  const moduleExports = require('./index');
3
- const _global = typeof window === 'undefined' ? global : window;
4
- _global.loaders = _global.loaders || {};
5
- module.exports = Object.assign(_global.loaders, moduleExports);
3
+ globalThis.loaders = globalThis.loaders || {};
4
+ module.exports = Object.assign(globalThis.loaders, moduleExports);
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export {createBoundingVolume} from './tileset/helpers/bounding-volume';
9
9
  export {calculateTransformProps} from './tileset/helpers/transform-utils';
10
10
 
11
11
  export {getFrameState} from './tileset/helpers/frame-state';
12
+ export {getLodStatus} from './tileset/helpers/i3s-lod';
12
13
 
13
14
  export {
14
15
  TILE_CONTENT_STATE,
@@ -1,52 +1,23 @@
1
- import {toRadians} from '@math.gl/core';
2
-
3
- const WGS84_RADIUS_X = 6378137.0;
4
- // use this to bias the lod switching (1+ results in increasing the LOD quality)
5
- const qualityFactor = Math.PI / 2; // empirical derived bias factor
6
- /* eslint-disable max-statements */
7
- export function lodJudge(tile, frameState) {
8
- const viewport = frameState.viewport;
9
- const metersPerPixel = viewport.metersPerPixel;
10
-
11
- const mbsLat = tile.header.mbs[1];
12
- const mbsLon = tile.header.mbs[0];
13
- const mbsZ = tile.header.mbs[2];
14
- const mbsR = tile.header.mbs[3];
15
-
16
- const {height, width, latitude, longitude} = viewport;
17
-
18
- const viewportCenter = [longitude, latitude];
19
- const mbsCenter = [mbsLon, mbsLat, mbsZ];
20
- const mbsLatProjected = [longitude, mbsLat];
21
- const mbsLonProjected = [mbsLon, latitude];
22
-
23
- const diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0];
24
- const distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter);
25
-
26
- const visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X;
27
- const visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X;
28
-
29
- if (distanceInMeters > diagonalInMeters + mbsR / WGS84_RADIUS_X) {
30
- return 'OUT';
31
- }
32
- if (getDistanceFromLatLon(viewportCenter, mbsLatProjected) > visibleHeight) {
33
- return 'OUT';
34
- }
35
- if (getDistanceFromLatLon(viewportCenter, mbsLonProjected) > visibleWidth) {
36
- return 'OUT';
37
- }
38
-
39
- if (tile.lodMetricValue === 0) {
1
+ import {Matrix4, Vector3} from '@math.gl/core';
2
+ import {Ellipsoid} from '@math.gl/geospatial';
3
+ import {Tile3D} from '../..';
4
+ import {FrameState} from './frame-state';
5
+
6
+ /**
7
+ * For the maxScreenThreshold error metric, maxError means that you should replace the node with it's children
8
+ as soon as the nodes bounding sphere has a screen radius larger than maxError pixels.
9
+ In this sense a value of 0 means you should always load it's children,
10
+ or if it's a leaf node, you should always display it.
11
+ * @param tile
12
+ * @param frameState
13
+ * @returns
14
+ */
15
+ export function getLodStatus(tile: Tile3D, frameState: FrameState): 'DIG' | 'OUT' | 'DRAW' {
16
+ if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
40
17
  return 'DIG';
41
18
  }
42
-
43
- // For the maxScreenThreshold error metric, maxError means that you should replace the node with it's children
44
- // as soon as the nodes bounding sphere has a screen radius larger than maxError pixels.
45
- // In this sense a value of 0 means you should always load it's children,
46
- // or if it's a leaf node, you should always display it.
47
- let screenSize = getI3ScreenSize(tile, frameState); // in pixels
48
- screenSize *= qualityFactor;
49
- if (screenSize < 0.5) {
19
+ const screenSize = 2 * getProjectedRadius(tile, frameState);
20
+ if (screenSize < 2) {
50
21
  return 'OUT';
51
22
  }
52
23
  if (!tile.header.children || screenSize <= tile.lodMetricValue) {
@@ -57,58 +28,63 @@ export function lodJudge(tile, frameState) {
57
28
  return 'OUT';
58
29
  }
59
30
 
60
- /* eslint-enable max-statements */
61
-
62
- function projectVertexToSphere([x, y, z]) {
63
- const azim = toRadians(x);
64
- const incl = toRadians(y);
65
- const radius = 1.0 + z / WGS84_RADIUS_X;
66
- const radCosInc = radius * Math.cos(incl);
67
- x = radCosInc * Math.cos(azim);
68
- y = radCosInc * Math.sin(azim);
69
- z = radius * Math.sin(incl);
70
- return [x, y, z];
71
- }
72
-
73
- function getDistanceFromLatLon(observer: number[], center: number[]) {
74
- const [observerLon, observerLat, observerZ = 0.0] = observer;
75
- const [centerLon, centerLat, centerZ = 0.0] = center;
76
-
77
- const projectedCenter = projectVertexToSphere([centerLon, centerLat, centerZ]);
78
- const projectedObserver = projectVertexToSphere([observerLon, observerLat, observerZ]);
79
- const dx = projectedObserver[0] - projectedCenter[0];
80
- const dy = projectedObserver[1] - projectedCenter[1];
81
- const dz = projectedObserver[2] - projectedCenter[2];
82
- return dx * dx + dy * dy + dz * dz;
83
- }
84
-
85
- export function getI3ScreenSize(tile, frameState) {
86
- const viewport = frameState.viewport;
31
+ /**
32
+ * Calculate size of MBS radius projected on the screen plane
33
+ * @param tile
34
+ * @param frameState
35
+ * @returns
36
+ */
37
+ // eslint-disable-next-line max-statements
38
+ export function getProjectedRadius(tile: Tile3D, frameState: FrameState): number {
39
+ const originalViewport = frameState.viewport;
40
+ const ViewportClass = originalViewport.constructor;
41
+ const {longitude, latitude, height, width, bearing, zoom} = originalViewport;
42
+ // @ts-ignore
43
+ const viewport = new ViewportClass({longitude, latitude, height, width, bearing, zoom, pitch: 0});
87
44
  const mbsLat = tile.header.mbs[1];
88
45
  const mbsLon = tile.header.mbs[0];
89
46
  const mbsZ = tile.header.mbs[2];
90
47
  const mbsR = tile.header.mbs[3];
91
-
92
- const mbsCenter = [mbsLon, mbsLat, mbsZ];
48
+ const mbsCenterCartesian = [...tile.boundingVolume.center];
93
49
  const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
94
- const dSquared = getDistanceFromLatLon(cameraPositionCartographic, mbsCenter);
95
- const mbsRNormalized = mbsR / WGS84_RADIUS_X;
96
- const d = dSquared - mbsRNormalized * mbsRNormalized;
97
- const fltMax = 3.4028235e38; // convert from 0x7f7fffff which is the maximum
98
- if (d <= 0.0) {
99
- return 0.5 * fltMax;
100
- }
101
- // https://stackoverflow.com/questions/21648630/radius-of-projected-sphere-in-screen-space
102
- // There is a formula there to calculate projected radius:
103
- // return 1.0 / Math.tan(fov) * r / Math.sqrt(d * d - r * r); // Right
104
- // Hack: 300 is a Magic number to get the correct LoD. Possibly, d and r are calculated in a wrong way.
105
- const screenSizeFactor =
106
- ((getTanOfHalfVFAngle(frameState) * mbsRNormalized) / Math.sqrt(d)) * 300;
107
- return screenSizeFactor;
108
- }
109
-
110
- function getTanOfHalfVFAngle(frameState) {
111
- const {projectionMatrix} = frameState.viewport;
112
- const t = projectionMatrix[5];
113
- return t;
50
+ const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(
51
+ cameraPositionCartographic,
52
+ new Vector3()
53
+ );
54
+
55
+ // ---------------------------
56
+ // Calculate mbs border vertex
57
+ // ---------------------------
58
+ const toEye = new Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
59
+ // Add extra vector to form plane
60
+ const enuToCartesianMatrix = new Matrix4();
61
+ Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
62
+ const cartesianToEnuMatrix = new Matrix4(enuToCartesianMatrix).invert();
63
+ const cameraPositionEnu = new Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);
64
+ // Mean Proportionals in Right Triangles - Altitude rule
65
+ // https://mathbitsnotebook.com/Geometry/RightTriangles/RTmeanRight.html
66
+ const projection = Math.sqrt(
67
+ cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]
68
+ );
69
+ const extraZ = (projection * projection) / cameraPositionEnu[2];
70
+ const extraVertexEnu = new Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
71
+ const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
72
+ const extraVectorCartesian = new Vector3(extraVertexCartesian)
73
+ .subtract(mbsCenterCartesian)
74
+ .normalize();
75
+ // We need radius vector orthogonal to toEye vector
76
+ const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
77
+ const sphereMbsBorderVertexCartesian = new Vector3(mbsCenterCartesian).add(radiusVector);
78
+ const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(
79
+ sphereMbsBorderVertexCartesian
80
+ );
81
+ // ---------------------------
82
+
83
+ // Project center vertex and border vertex and calculate projected radius of MBS
84
+ const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
85
+ const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
86
+ const projectedRadius = new Vector3(projectedOrigin)
87
+ .subtract(projectedMbsBorderVertex)
88
+ .magnitude();
89
+ return projectedRadius;
114
90
  }
@@ -59,5 +59,7 @@ export function calculateTransformProps(tileHeader, tile) {
59
59
  tile.cartographicOrigin = cartographicOrigin;
60
60
 
61
61
  // Deprecated, drop
62
- tile.modelMatrix = tile.cartographicModelMatrix;
62
+ if (!tile.coordinateSystem) {
63
+ tile.modelMatrix = tile.cartographicModelMatrix;
64
+ }
63
65
  }
@@ -9,7 +9,7 @@ import {TILE_REFINEMENT, TILE_CONTENT_STATE, TILESET_TYPE} from '../constants';
9
9
  import {FrameState} from './helpers/frame-state';
10
10
  import {createBoundingVolume} from './helpers/bounding-volume';
11
11
  import {getTiles3DScreenSpaceError} from './helpers/tiles-3d-lod';
12
- import {getI3ScreenSize} from './helpers/i3s-lod';
12
+ import {getProjectedRadius} from './helpers/i3s-lod';
13
13
  import {get3dTilesOptions} from './helpers/3d-tiles-options';
14
14
  import TilesetTraverser from './traversers/tileset-traverser';
15
15
 
@@ -287,7 +287,7 @@ export default class TileHeader {
287
287
  getScreenSpaceError(frameState, useParentLodMetric) {
288
288
  switch (this.tileset.type) {
289
289
  case TILESET_TYPE.I3S:
290
- return getI3ScreenSize(this, frameState);
290
+ return getProjectedRadius(this, frameState);
291
291
  case TILESET_TYPE.TILES3D:
292
292
  return getTiles3DScreenSpaceError(this, frameState, useParentLodMetric);
293
293
  default:
@@ -1,7 +1,7 @@
1
1
  import {load} from '@loaders.gl/core';
2
2
  import TilesetTraverser from './tileset-traverser';
3
3
 
4
- import {lodJudge} from '../helpers/i3s-lod';
4
+ import {getLodStatus} from '../helpers/i3s-lod';
5
5
  import TileHeader from '../tile-3d';
6
6
  import I3STileManager from './i3s-tile-manager';
7
7
 
@@ -14,8 +14,7 @@ export default class I3STilesetTraverser extends TilesetTraverser {
14
14
  }
15
15
 
16
16
  shouldRefine(tile, frameState) {
17
- // TODO refactor loaJudge
18
- tile._lodJudge = lodJudge(tile, frameState);
17
+ tile._lodJudge = getLodStatus(tile, frameState);
19
18
  return tile._lodJudge === 'DIG';
20
19
  }
21
20
 
package/dist/bundle.js DELETED
@@ -1,7 +0,0 @@
1
- const moduleExports = require('./index');
2
-
3
- const _global = typeof window === 'undefined' ? global : window;
4
-
5
- _global.loaders = _global.loaders || {};
6
- module.exports = Object.assign(_global.loaders, moduleExports);
7
- //# sourceMappingURL=bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","_global","window","global","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACA,MAAMC,OAAO,GAAG,OAAOC,MAAP,KAAkB,WAAlB,GAAgCC,MAAhC,GAAyCD,MAAzD;;AACAD,OAAO,CAACG,OAAR,GAAkBH,OAAO,CAACG,OAAR,IAAmB,EAArC;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcP,OAAO,CAACG,OAAtB,EAA+BL,aAA/B,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nconst _global = typeof window === 'undefined' ? global : window;\n_global.loaders = _global.loaders || {};\nmodule.exports = Object.assign(_global.loaders, moduleExports);\n"],"file":"bundle.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/constants.ts"],"names":["TILE_CONTENT_STATE","UNLOADED","LOADING","PROCESSING","READY","EXPIRED","FAILED","TILE_REFINEMENT","ADD","REPLACE","TILE_TYPE","EMPTY","SCENEGRAPH","POINTCLOUD","MESH","TILESET_TYPE","I3S","TILES3D","LOD_METRIC_TYPE","GEOMETRIC_ERROR","MAX_SCREEN_THRESHOLD","TILE3D_OPTIMIZATION_HINT","NOT_COMPUTED","USE_OPTIMIZATION","SKIP_OPTIMIZATION"],"mappings":"AAAA,OAAO,MAAMA,kBAAkB,GAAG;AAChCC,EAAAA,QAAQ,EAAE,CADsB;AAEhCC,EAAAA,OAAO,EAAE,CAFuB;AAGhCC,EAAAA,UAAU,EAAE,CAHoB;AAIhCC,EAAAA,KAAK,EAAE,CAJyB;AAKhCC,EAAAA,OAAO,EAAE,CALuB;AAMhCC,EAAAA,MAAM,EAAE;AANwB,CAA3B;AASP,OAAO,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,GAAG,EAAE,CADwB;AAE7BC,EAAAA,OAAO,EAAE;AAFoB,CAAxB;AAKP,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,KAAK,EAAE,OADgB;AAEvBC,EAAAA,UAAU,EAAE,YAFW;AAGvBC,EAAAA,UAAU,EAAE,YAHW;AAIvBC,EAAAA,IAAI,EAAE;AAJiB,CAAlB;AAOP,OAAO,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,GAAG,EAAE,KADqB;AAE1BC,EAAAA,OAAO,EAAE;AAFiB,CAArB;AAKP,OAAO,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,eAAe,EAAE,gBADY;AAE7BC,EAAAA,oBAAoB,EAAE;AAFO,CAAxB;AAMP,OAAO,MAAMC,wBAAwB,GAAG;AACtCC,EAAAA,YAAY,EAAE,CAAC,CADuB;AAEtCC,EAAAA,gBAAgB,EAAE,CAFoB;AAGtCC,EAAAA,iBAAiB,EAAE;AAHmB,CAAjC","sourcesContent":["export const TILE_CONTENT_STATE = {\n UNLOADED: 0, // Has never been requested\n LOADING: 1, // Is waiting on a pending request\n PROCESSING: 2, // Request received. Contents are being processed for rendering. Depending on the content, it might make its own requests for external data.\n READY: 3, // Ready to render.\n EXPIRED: 4, // Is expired and will be unloaded once new content is loaded.\n FAILED: 5 // Request failed.\n};\n\nexport const TILE_REFINEMENT = {\n ADD: 1, // Render tile and, if screen space error exceeded, also refine to its children.\n REPLACE: 2 // Render tile or, if screen space error exceeded, refine to its descendants instead.\n};\n\nexport const TILE_TYPE = {\n EMPTY: 'empty',\n SCENEGRAPH: 'scenegraph',\n POINTCLOUD: 'pointcloud',\n MESH: 'mesh'\n};\n\nexport const TILESET_TYPE = {\n I3S: 'I3S',\n TILES3D: 'TILES3D'\n};\n\nexport const LOD_METRIC_TYPE = {\n GEOMETRIC_ERROR: 'geometricError',\n MAX_SCREEN_THRESHOLD: 'maxScreenThreshold'\n};\n\n// Cesium 3D Tiles Specific\nexport const TILE3D_OPTIMIZATION_HINT = {\n NOT_COMPUTED: -1,\n USE_OPTIMIZATION: 1,\n SKIP_OPTIMIZATION: 0\n};\n"],"file":"constants.js"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["default","Tileset3D","Tile3D","TilesetTraverser","TilesetCache","createBoundingVolume","calculateTransformProps","getFrameState","TILE_CONTENT_STATE","TILE_REFINEMENT","TILE_TYPE","TILESET_TYPE","LOD_METRIC_TYPE"],"mappings":"AACA,SAAQA,OAAO,IAAIC,SAAnB,QAAmC,sBAAnC;AACA,SAAQD,OAAO,IAAIE,MAAnB,QAAgC,mBAAhC;AAEA,SAAQF,OAAO,IAAIG,gBAAnB,QAA0C,wCAA1C;AACA,SAAQH,OAAO,IAAII,YAAnB,QAAsC,yBAAtC;AAEA,SAAQC,oBAAR,QAAmC,mCAAnC;AACA,SAAQC,uBAAR,QAAsC,mCAAtC;AAEA,SAAQC,aAAR,QAA4B,+BAA5B;AAEA,SACEC,kBADF,EAEEC,eAFF,EAGEC,SAHF,EAIEC,YAJF,EAKEC,eALF,QAMO,aANP","sourcesContent":["export type {Tileset3DProps} from './tileset/tileset-3d';\nexport {default as Tileset3D} from './tileset/tileset-3d';\nexport {default as Tile3D} from './tileset/tile-3d';\n\nexport {default as TilesetTraverser} from './tileset/traversers/tileset-traverser';\nexport {default as TilesetCache} from './tileset/tileset-cache';\n\nexport {createBoundingVolume} from './tileset/helpers/bounding-volume';\nexport {calculateTransformProps} from './tileset/helpers/transform-utils';\n\nexport {getFrameState} from './tileset/helpers/frame-state';\n\nexport {\n TILE_CONTENT_STATE,\n TILE_REFINEMENT,\n TILE_TYPE,\n TILESET_TYPE,\n LOD_METRIC_TYPE\n} from './constants';\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/tileset/helpers/3d-tiles-options.ts"],"names":["get3dTilesOptions","tileset","assetGltfUpAxis","asset","gltfUpAxis"],"mappings":"AAAA,OAAO,SAASA,iBAAT,CAA2BC,OAA3B,EAAoC;AACzC,SAAO;AACLC,IAAAA,eAAe,EAAGD,OAAO,CAACE,KAAR,IAAiBF,OAAO,CAACE,KAAR,CAAcC,UAAhC,IAA+C;AAD3D,GAAP;AAGD","sourcesContent":["export function get3dTilesOptions(tileset) {\n return {\n assetGltfUpAxis: (tileset.asset && tileset.asset.gltfUpAxis) || 'Y'\n };\n}\n"],"file":"3d-tiles-options.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/tileset/helpers/bounding-volume.ts"],"names":["Quaternion","Vector3","Matrix3","Matrix4","degrees","BoundingSphere","OrientedBoundingBox","Ellipsoid","assert","defined","x","undefined","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","center","origin","length","halfSize","slice","quaternion","fromArray","y","z","transformByQuaternion","scale","toArray","xAxis","transformAsVector","yAxis","zAxis","halfAxes","getScale","uniformScale","Math","max"],"mappings":"AAIA,SAAQA,UAAR,EAAoBC,OAApB,EAA6BC,OAA7B,EAAsCC,OAAtC,EAA+CC,OAA/C,QAA6D,eAA7D;AACA,SAAQC,cAAR,EAAwBC,mBAAxB,QAAkD,kBAAlD;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SAAQC,MAAR,QAAqB,0BAArB;;AAIA,SAASC,OAAT,CAAiBC,CAAjB,EAAoB;AAClB,SAAOA,CAAC,KAAKC,SAAN,IAAmBD,CAAC,KAAK,IAAhC;AACD;;AAGD,MAAME,YAAY,GAAG,IAAIX,OAAJ,EAArB;AACA,MAAMY,gBAAgB,GAAG,IAAIZ,OAAJ,EAAzB;AACA,MAAMa,gBAAgB,GAAG,IAAIb,OAAJ,EAAzB;AAYA,OAAO,SAASc,oBAAT,CAA8BC,oBAA9B,EAAoDC,SAApD,EAA+DC,MAA/D,EAAuE;AAC5EV,EAAAA,MAAM,CAACQ,oBAAD,EAAuB,yCAAvB,CAAN;;AAIA,MAAIA,oBAAoB,CAACG,GAAzB,EAA8B;AAC5B,WAAOC,SAAS,CAACJ,oBAAoB,CAACG,GAAtB,EAA2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AAO,IAAIZ,mBAAJ,CAAwBmC,MAAxB,EAAgCgB,QAAhC,CAAP;AACD;;AAyDD,SAASnB,YAAT,CAAsBC,MAAtB,EAA8BtB,SAA9B,EAAyCC,MAAzC,EAAkD;AAEhD,QAAMuB,MAAM,GAAG,IAAIxC,OAAJ,CAAYsC,MAAM,CAAC,CAAD,CAAlB,EAAuBA,MAAM,CAAC,CAAD,CAA7B,EAAkCA,MAAM,CAAC,CAAD,CAAxC,CAAf;AACAtB,EAAAA,SAAS,CAACA,SAAV,CAAoBwB,MAApB,EAA4BA,MAA5B;AACA,QAAMU,KAAK,GAAGlC,SAAS,CAACyC,QAAV,CAAmB9C,YAAnB,CAAd;AAEA,QAAM+C,YAAY,GAAGC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACC,GAAL,CAASV,KAAK,CAAC,CAAD,CAAd,EAAmBA,KAAK,CAAC,CAAD,CAAxB,CAAT,EAAuCA,KAAK,CAAC,CAAD,CAA5C,CAArB;AACA,QAAMhB,MAAM,GAAGI,MAAM,CAAC,CAAD,CAAN,GAAYoB,YAA3B;;AAEA,MAAIlD,OAAO,CAACS,MAAD,CAAX,EAAqB;AACnBA,IAAAA,MAAM,CAACuB,MAAP,GAAgBA,MAAhB;AACAvB,IAAAA,MAAM,CAACiB,MAAP,GAAgBA,MAAhB;AACA,WAAOjB,MAAP;AACD;;AAED,SAAO,IAAIb,cAAJ,CAAmBoC,MAAnB,EAA2BN,MAA3B,CAAP;AACD","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 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\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"],"file":"bounding-volume.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/tileset/helpers/frame-state.ts"],"names":["Vector3","CullingVolume","Plane","Ellipsoid","scratchVector","scratchPosition","cullingVolume","getFrameState","viewport","frameNumber","cameraDirection","cameraUp","height","metersPerUnit","distanceScales","viewportCenterCartographic","longitude","latitude","viewportCenterCartesian","WGS84","cartographicToCartesian","enuToFixedTransform","eastNorthUpToFixedFrame","cameraPositionCartographic","unprojectPosition","cameraPosition","cameraPositionCartesian","cameraDirectionCartesian","transformAsVector","scale","normalize","cameraUpCartesian","commonSpacePlanesToWGS84","camera","position","direction","up","sseDenominator","frustumPlanes","getFrustumPlanes","i","dir","plane","distanceToCenter","normal","dot","center","copy","distance","add","cartographicPos","cartesianPos","planes","fromPointNormal","subtract"],"mappings":"AAAA,SAAQA,OAAR,QAAsB,eAAtB;AACA,SAAQC,aAAR,EAAuBC,KAAvB,QAAmC,kBAAnC;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAeA,MAAMC,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AACA,MAAMK,eAAe,GAAG,IAAIL,OAAJ,EAAxB;AACA,MAAMM,aAAa,GAAG,IAAIL,aAAJ,CAAkB,CACtC,IAAIC,KAAJ,EADsC,EAEtC,IAAIA,KAAJ,EAFsC,EAGtC,IAAIA,KAAJ,EAHsC,EAItC,IAAIA,KAAJ,EAJsC,EAKtC,IAAIA,KAAJ,EALsC,EAMtC,IAAIA,KAAJ,EANsC,CAAlB,CAAtB;AAWA,OAAO,SAASK,aAAT,CAAuBC,QAAvB,EAAiCC,WAAjC,EAAkE;AAEvE,QAAM;AAACC,IAAAA,eAAD;AAAkBC,IAAAA,QAAlB;AAA4BC,IAAAA;AAA5B,MAAsCJ,QAA5C;AACA,QAAM;AAACK,IAAAA;AAAD,MAAkBL,QAAQ,CAACM,cAAjC;AAEA,QAAMC,0BAA0B,GAAG,CAACP,QAAQ,CAACQ,SAAV,EAAqBR,QAAQ,CAACS,QAA9B,EAAwC,CAAxC,CAAnC;AAGA,QAAMC,uBAAuB,GAAGf,SAAS,CAACgB,KAAV,C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X,IAAkBH,aAAlB,EAAiC;AAC/B,UAAMI,KAAK,GAAGJ,aAAa,CAACG,GAAD,CAA3B;AACA,UAAME,gBAAgB,GAAGD,KAAK,CAACE,MAAN,CAAaC,GAAb,CAAiBrC,QAAQ,CAACsC,MAA1B,CAAzB;AACAzC,IAAAA,eAAe,CACZ0C,IADH,CACQL,KAAK,CAACE,MADd,EAEGf,KAFH,CAESa,KAAK,CAACM,QAAN,GAAiBL,gBAF1B,EAGGM,GAHH,CAGOzC,QAAQ,CAACsC,MAHhB;AAIA,UAAMI,eAAe,GAAG1C,QAAQ,CAACgB,iBAAT,CAA2BnB,eAA3B,CAAxB;AAEA,UAAM8C,YAAY,GAAGhD,SAAS,CAACgB,KAAV,CAAgBC,uBAAhB,CAAwC8B,eAAxC,EAAyD,IAAIlD,OAAJ,EAAzD,CAArB;AAEAM,IAAAA,aAAa,CAAC8C,MAAd,CAAqBZ,CAAC,EAAtB,EAA0Ba,eAA1B,CACEF,YADF,EAGE/C,aAAa,CAAC2C,IAAd,CAAmB7B,uBAAnB,EAA4CoC,QAA5C,CAAqDH,YAArD,CAHF;AAKD;AACF","sourcesContent":["import {Vector3} from '@math.gl/core';\nimport {CullingVolume, Plane} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nexport type FrameState = {\n camera: {\n position: number[];\n direction: number[];\n up: number[];\n };\n viewport: {[key: string]: any};\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, frameNumber: number): FrameState {\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 const viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0];\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?\n const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(\n viewportCenterCartographic,\n new Vector3()\n );\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, viewportCenterCartesian);\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 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\nfunction commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {\n // Extract frustum planes based on current view.\n const frustumPlanes = viewport.getFrustumPlanes();\n let i = 0;\n for (const dir in frustumPlanes) {\n const plane = frustumPlanes[dir];\n const distanceToCenter = plane.normal.dot(viewport.center);\n scratchPosition\n .copy(plane.normal)\n .scale(plane.distance - distanceToCenter)\n .add(viewport.center);\n const cartographicPos = viewport.unprojectPosition(scratchPosition);\n\n const cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3());\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(viewportCenterCartesian).subtract(cartesianPos)\n );\n }\n}\n"],"file":"frame-state.js"}
@@ -1,108 +0,0 @@
1
- import { toRadians } from '@math.gl/core';
2
- const WGS84_RADIUS_X = 6378137.0;
3
- const qualityFactor = Math.PI / 2;
4
- export function lodJudge(tile, frameState) {
5
- const viewport = frameState.viewport;
6
- const metersPerPixel = viewport.metersPerPixel;
7
- const mbsLat = tile.header.mbs[1];
8
- const mbsLon = tile.header.mbs[0];
9
- const mbsZ = tile.header.mbs[2];
10
- const mbsR = tile.header.mbs[3];
11
- const {
12
- height,
13
- width,
14
- latitude,
15
- longitude
16
- } = viewport;
17
- const viewportCenter = [longitude, latitude];
18
- const mbsCenter = [mbsLon, mbsLat, mbsZ];
19
- const mbsLatProjected = [longitude, mbsLat];
20
- const mbsLonProjected = [mbsLon, latitude];
21
- const diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0];
22
- const distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter);
23
- const visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X;
24
- const visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X;
25
-
26
- if (distanceInMeters > diagonalInMeters + mbsR / WGS84_RADIUS_X) {
27
- return 'OUT';
28
- }
29
-
30
- if (getDistanceFromLatLon(viewportCenter, mbsLatProjected) > visibleHeight) {
31
- return 'OUT';
32
- }
33
-
34
- if (getDistanceFromLatLon(viewportCenter, mbsLonProjected) > visibleWidth) {
35
- return 'OUT';
36
- }
37
-
38
- if (tile.lodMetricValue === 0) {
39
- return 'DIG';
40
- }
41
-
42
- let screenSize = getI3ScreenSize(tile, frameState);
43
- screenSize *= qualityFactor;
44
-
45
- if (screenSize < 0.5) {
46
- return 'OUT';
47
- }
48
-
49
- if (!tile.header.children || screenSize <= tile.lodMetricValue) {
50
- return 'DRAW';
51
- } else if (tile.header.children) {
52
- return 'DIG';
53
- }
54
-
55
- return 'OUT';
56
- }
57
-
58
- function projectVertexToSphere([x, y, z]) {
59
- const azim = toRadians(x);
60
- const incl = toRadians(y);
61
- const radius = 1.0 + z / WGS84_RADIUS_X;
62
- const radCosInc = radius * Math.cos(incl);
63
- x = radCosInc * Math.cos(azim);
64
- y = radCosInc * Math.sin(azim);
65
- z = radius * Math.sin(incl);
66
- return [x, y, z];
67
- }
68
-
69
- function getDistanceFromLatLon(observer, center) {
70
- const [observerLon, observerLat, observerZ = 0.0] = observer;
71
- const [centerLon, centerLat, centerZ = 0.0] = center;
72
- const projectedCenter = projectVertexToSphere([centerLon, centerLat, centerZ]);
73
- const projectedObserver = projectVertexToSphere([observerLon, observerLat, observerZ]);
74
- const dx = projectedObserver[0] - projectedCenter[0];
75
- const dy = projectedObserver[1] - projectedCenter[1];
76
- const dz = projectedObserver[2] - projectedCenter[2];
77
- return dx * dx + dy * dy + dz * dz;
78
- }
79
-
80
- export function getI3ScreenSize(tile, frameState) {
81
- const viewport = frameState.viewport;
82
- const mbsLat = tile.header.mbs[1];
83
- const mbsLon = tile.header.mbs[0];
84
- const mbsZ = tile.header.mbs[2];
85
- const mbsR = tile.header.mbs[3];
86
- const mbsCenter = [mbsLon, mbsLat, mbsZ];
87
- const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
88
- const dSquared = getDistanceFromLatLon(cameraPositionCartographic, mbsCenter);
89
- const mbsRNormalized = mbsR / WGS84_RADIUS_X;
90
- const d = dSquared - mbsRNormalized * mbsRNormalized;
91
- const fltMax = 3.4028235e38;
92
-
93
- if (d <= 0.0) {
94
- return 0.5 * fltMax;
95
- }
96
-
97
- const screenSizeFactor = getTanOfHalfVFAngle(frameState) * mbsRNormalized / Math.sqrt(d) * 300;
98
- return screenSizeFactor;
99
- }
100
-
101
- function getTanOfHalfVFAngle(frameState) {
102
- const {
103
- projectionMatrix
104
- } = frameState.viewport;
105
- const t = projectionMatrix[5];
106
- return t;
107
- }
108
- //# sourceMappingURL=i3s-lod.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/tileset/helpers/i3s-lod.ts"],"names":["toRadians","WGS84_RADIUS_X","qualityFactor","Math","PI","lodJudge","tile","frameState","viewport","metersPerPixel","mbsLat","header","mbs","mbsLon","mbsZ","mbsR","height","width","latitude","longitude","viewportCenter","mbsCenter","mbsLatProjected","mbsLonProjected","diagonalInMeters","sqrt","distanceInMeters","getDistanceFromLatLon","visibleHeight","visibleWidth","lodMetricValue","screenSize","getI3ScreenSize","children","projectVertexToSphere","x","y","z","azim","incl","radius","radCosInc","cos","sin","observer","center","observerLon","observerLat","observerZ","centerLon","centerLat","centerZ","projectedCenter","projectedObserver","dx","dy","dz","cameraPositionCartographic","unprojectPosition","cameraPosition","dSquared","mbsRNormalized","d","fltMax","screenSizeFactor","getTanOfHalfVFAngle","projectionMatrix","t"],"mappings":"AAAA,SAAQA,SAAR,QAAwB,eAAxB;AAEA,MAAMC,cAAc,GAAG,SAAvB;AAEA,MAAMC,aAAa,GAAGC,IAAI,CAACC,EAAL,GAAU,CAAhC;AAEA,OAAO,SAASC,QAAT,CAAkBC,IAAlB,EAAwBC,UAAxB,EAAoC;AACzC,QAAMC,QAAQ,GAAGD,UAAU,CAACC,QAA5B;AACA,QAAMC,cAAc,GAAGD,QAAQ,CAACC,cAAhC;AAEA,QAAMC,MAAM,GAAGJ,IAAI,CAACK,MAAL,CAAYC,GAAZ,CAAgB,CAAhB,CAAf;AACA,QAAMC,MAAM,GAAGP,IAAI,CAACK,MAAL,CAAYC,GAAZ,CAAgB,CAAhB,CAAf;AACA,QAAME,IAAI,GAAGR,IAAI,CAACK,MAAL,CAAYC,GAAZ,CAAgB,CAAhB,CAAb;AACA,QAAMG,IAAI,GAAGT,IAAI,CAACK,MAAL,CAAYC,GAAZ,CAAgB,CAAhB,CAAb;AAEA,QAAM;AAACI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AAc;AACZ,WAAO,MAAMC,MAAb;AACD;;AAKD,QAAMC,gBAAgB,GAClBC,mBAAmB,CAAC1D,UAAD,CAAnB,GAAkCsD,cAAnC,GAAqD1D,IAAI,CAACsB,IAAL,CAAUqC,CAAV,CAAtD,GAAsE,GADxE;AAEA,SAAOE,gBAAP;AACD;;AAED,SAASC,mBAAT,CAA6B1D,UAA7B,EAAyC;AACvC,QAAM;AAAC2D,IAAAA;AAAD,MAAqB3D,UAAU,CAACC,QAAtC;AACA,QAAM2D,CAAC,GAAGD,gBAAgB,CAAC,CAAD,CAA1B;AACA,SAAOC,CAAP;AACD","sourcesContent":["import {toRadians} from '@math.gl/core';\n\nconst WGS84_RADIUS_X = 6378137.0;\n// use this to bias the lod switching (1+ results in increasing the LOD quality)\nconst qualityFactor = Math.PI / 2; // empirical derived bias factor\n/* eslint-disable max-statements */\nexport function lodJudge(tile, frameState) {\n const viewport = frameState.viewport;\n const metersPerPixel = viewport.metersPerPixel;\n\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\n const {height, width, latitude, longitude} = viewport;\n\n const viewportCenter = [longitude, latitude];\n const mbsCenter = [mbsLon, mbsLat, mbsZ];\n const mbsLatProjected = [longitude, mbsLat];\n const mbsLonProjected = [mbsLon, latitude];\n\n const diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0];\n const distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter);\n\n const visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X;\n const visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X;\n\n if (distanceInMeters > diagonalInMeters + mbsR / WGS84_RADIUS_X) {\n return 'OUT';\n }\n if (getDistanceFromLatLon(viewportCenter, mbsLatProjected) > visibleHeight) {\n return 'OUT';\n }\n if (getDistanceFromLatLon(viewportCenter, mbsLonProjected) > visibleWidth) {\n return 'OUT';\n }\n\n if (tile.lodMetricValue === 0) {\n return 'DIG';\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 let screenSize = getI3ScreenSize(tile, frameState); // in pixels\n screenSize *= qualityFactor;\n if (screenSize < 0.5) {\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/* eslint-enable max-statements */\n\nfunction projectVertexToSphere([x, y, z]) {\n const azim = toRadians(x);\n const incl = toRadians(y);\n const radius = 1.0 + z / WGS84_RADIUS_X;\n const radCosInc = radius * Math.cos(incl);\n x = radCosInc * Math.cos(azim);\n y = radCosInc * Math.sin(azim);\n z = radius * Math.sin(incl);\n return [x, y, z];\n}\n\nfunction getDistanceFromLatLon(observer: number[], center: number[]) {\n const [observerLon, observerLat, observerZ = 0.0] = observer;\n const [centerLon, centerLat, centerZ = 0.0] = center;\n\n const projectedCenter = projectVertexToSphere([centerLon, centerLat, centerZ]);\n const projectedObserver = projectVertexToSphere([observerLon, observerLat, observerZ]);\n const dx = projectedObserver[0] - projectedCenter[0];\n const dy = projectedObserver[1] - projectedCenter[1];\n const dz = projectedObserver[2] - projectedCenter[2];\n return dx * dx + dy * dy + dz * dz;\n}\n\nexport function getI3ScreenSize(tile, frameState) {\n const viewport = frameState.viewport;\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\n const mbsCenter = [mbsLon, mbsLat, mbsZ];\n const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);\n const dSquared = getDistanceFromLatLon(cameraPositionCartographic, mbsCenter);\n const mbsRNormalized = mbsR / WGS84_RADIUS_X;\n const d = dSquared - mbsRNormalized * mbsRNormalized;\n const fltMax = 3.4028235e38; // convert from 0x7f7fffff which is the maximum\n if (d <= 0.0) {\n return 0.5 * fltMax;\n }\n // https://stackoverflow.com/questions/21648630/radius-of-projected-sphere-in-screen-space\n // There is a formula there to calculate projected radius:\n // return 1.0 / Math.tan(fov) * r / Math.sqrt(d * d - r * r); // Right\n // Hack: 300 is a Magic number to get the correct LoD. Possibly, d and r are calculated in a wrong way.\n const screenSizeFactor =\n ((getTanOfHalfVFAngle(frameState) * mbsRNormalized) / Math.sqrt(d)) * 300;\n return screenSizeFactor;\n}\n\nfunction getTanOfHalfVFAngle(frameState) {\n const {projectionMatrix} = frameState.viewport;\n const t = projectionMatrix[5];\n return t;\n}\n"],"file":"i3s-lod.js"}