@loaders.gl/tiles 4.0.0-alpha.4 → 4.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/constants.d.ts +32 -0
  5. package/dist/constants.d.ts.map +1 -0
  6. package/dist/constants.js +30 -26
  7. package/dist/dist.min.js +8921 -0
  8. package/dist/es5/bundle.js +6 -0
  9. package/dist/es5/bundle.js.map +1 -0
  10. package/dist/es5/constants.js +44 -0
  11. package/dist/es5/constants.js.map +1 -0
  12. package/dist/es5/index.js +93 -0
  13. package/dist/es5/index.js.map +1 -0
  14. package/dist/es5/tileset/format-3d-tiles/tileset-3d-traverser.js +70 -0
  15. package/dist/es5/tileset/format-3d-tiles/tileset-3d-traverser.js.map +1 -0
  16. package/dist/es5/tileset/format-i3s/i3s-pending-tiles-register.js +45 -0
  17. package/dist/es5/tileset/format-i3s/i3s-pending-tiles-register.js.map +1 -0
  18. package/dist/es5/tileset/format-i3s/i3s-tile-manager.js +84 -0
  19. package/dist/es5/tileset/format-i3s/i3s-tile-manager.js.map +1 -0
  20. package/dist/es5/tileset/format-i3s/i3s-tileset-traverser.js +143 -0
  21. package/dist/es5/tileset/format-i3s/i3s-tileset-traverser.js.map +1 -0
  22. package/dist/es5/tileset/helpers/3d-tiles-options.js +12 -0
  23. package/dist/es5/tileset/helpers/3d-tiles-options.js.map +1 -0
  24. package/dist/es5/tileset/helpers/bounding-volume.js +176 -0
  25. package/dist/es5/tileset/helpers/bounding-volume.js.map +1 -0
  26. package/dist/es5/tileset/helpers/frame-state.js +129 -0
  27. package/dist/es5/tileset/helpers/frame-state.js.map +1 -0
  28. package/dist/es5/tileset/helpers/i3s-lod.js +60 -0
  29. package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -0
  30. package/dist/es5/tileset/helpers/tiles-3d-lod.js +103 -0
  31. package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +1 -0
  32. package/dist/es5/tileset/helpers/transform-utils.js +50 -0
  33. package/dist/es5/tileset/helpers/transform-utils.js.map +1 -0
  34. package/dist/es5/tileset/helpers/zoom.js +63 -0
  35. package/dist/es5/tileset/helpers/zoom.js.map +1 -0
  36. package/dist/es5/tileset/tile-3d.js +565 -0
  37. package/dist/es5/tileset/tile-3d.js.map +1 -0
  38. package/dist/es5/tileset/tileset-3d.js +890 -0
  39. package/dist/es5/tileset/tileset-3d.js.map +1 -0
  40. package/dist/es5/tileset/tileset-cache.js +85 -0
  41. package/dist/es5/tileset/tileset-cache.js.map +1 -0
  42. package/dist/es5/tileset/tileset-traverser.js +328 -0
  43. package/dist/es5/tileset/tileset-traverser.js.map +1 -0
  44. package/dist/es5/types.js +2 -0
  45. package/dist/es5/types.js.map +1 -0
  46. package/dist/es5/utils/doubly-linked-list-node.js +21 -0
  47. package/dist/es5/utils/doubly-linked-list-node.js.map +1 -0
  48. package/dist/es5/utils/doubly-linked-list.js +88 -0
  49. package/dist/es5/utils/doubly-linked-list.js.map +1 -0
  50. package/dist/es5/utils/managed-array.js +126 -0
  51. package/dist/es5/utils/managed-array.js.map +1 -0
  52. package/dist/esm/bundle.js +4 -0
  53. package/dist/esm/bundle.js.map +1 -0
  54. package/dist/esm/constants.js +32 -0
  55. package/dist/esm/constants.js.map +1 -0
  56. package/dist/esm/index.js +10 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/{tileset/traversers → esm/tileset/format-3d-tiles}/tileset-3d-traverser.js +2 -13
  59. package/dist/esm/tileset/format-3d-tiles/tileset-3d-traverser.js.map +1 -0
  60. package/dist/esm/tileset/format-i3s/i3s-pending-tiles-register.js +26 -0
  61. package/dist/esm/tileset/format-i3s/i3s-pending-tiles-register.js.map +1 -0
  62. package/dist/esm/tileset/format-i3s/i3s-tile-manager.js +79 -0
  63. package/dist/esm/tileset/format-i3s/i3s-tile-manager.js.map +1 -0
  64. package/dist/{tileset/traversers → esm/tileset/format-i3s}/i3s-tileset-traverser.js +16 -28
  65. package/dist/esm/tileset/format-i3s/i3s-tileset-traverser.js.map +1 -0
  66. package/dist/esm/tileset/helpers/3d-tiles-options.js +6 -0
  67. package/dist/esm/tileset/helpers/3d-tiles-options.js.map +1 -0
  68. package/dist/esm/tileset/helpers/bounding-volume.js +155 -0
  69. package/dist/esm/tileset/helpers/bounding-volume.js.map +1 -0
  70. package/dist/esm/tileset/helpers/frame-state.js +109 -0
  71. package/dist/esm/tileset/helpers/frame-state.js.map +1 -0
  72. package/dist/esm/tileset/helpers/i3s-lod.js +53 -0
  73. package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -0
  74. package/dist/esm/tileset/helpers/tiles-3d-lod.js +100 -0
  75. package/dist/{tileset → esm/tileset}/helpers/tiles-3d-lod.js.map +1 -1
  76. package/dist/esm/tileset/helpers/transform-utils.js +50 -0
  77. package/dist/esm/tileset/helpers/transform-utils.js.map +1 -0
  78. package/dist/esm/tileset/helpers/zoom.js +55 -0
  79. package/dist/esm/tileset/helpers/zoom.js.map +1 -0
  80. package/dist/esm/tileset/tile-3d.js +445 -0
  81. package/dist/esm/tileset/tile-3d.js.map +1 -0
  82. package/dist/esm/tileset/tileset-3d.js +637 -0
  83. package/dist/esm/tileset/tileset-3d.js.map +1 -0
  84. package/dist/esm/tileset/tileset-cache.js +60 -0
  85. package/dist/esm/tileset/tileset-cache.js.map +1 -0
  86. package/dist/{tileset/traversers → esm/tileset}/tileset-traverser.js +20 -72
  87. package/dist/esm/tileset/tileset-traverser.js.map +1 -0
  88. package/dist/esm/types.js +2 -0
  89. package/dist/esm/types.js.map +1 -0
  90. package/dist/esm/utils/doubly-linked-list-node.js +12 -0
  91. package/dist/esm/utils/doubly-linked-list-node.js.map +1 -0
  92. package/dist/esm/utils/doubly-linked-list.js +65 -0
  93. package/dist/esm/utils/doubly-linked-list.js.map +1 -0
  94. package/dist/esm/utils/managed-array.js +87 -0
  95. package/dist/esm/utils/managed-array.js.map +1 -0
  96. package/dist/index.d.ts +11 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +26 -9
  99. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts +7 -0
  100. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts.map +1 -0
  101. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +54 -0
  102. package/dist/tileset/format-i3s/i3s-pending-tiles-register.d.ts +27 -0
  103. package/dist/tileset/format-i3s/i3s-pending-tiles-register.d.ts.map +1 -0
  104. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +47 -0
  105. package/dist/tileset/format-i3s/i3s-tile-manager.d.ts +34 -0
  106. package/dist/tileset/format-i3s/i3s-tile-manager.d.ts.map +1 -0
  107. package/dist/tileset/format-i3s/i3s-tile-manager.js +80 -0
  108. package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts +25 -0
  109. package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts.map +1 -0
  110. package/dist/tileset/format-i3s/i3s-tileset-traverser.js +92 -0
  111. package/dist/tileset/helpers/3d-tiles-options.d.ts +4 -0
  112. package/dist/tileset/helpers/3d-tiles-options.d.ts.map +1 -0
  113. package/dist/tileset/helpers/3d-tiles-options.js +8 -5
  114. package/dist/tileset/helpers/bounding-volume.d.ts +19 -0
  115. package/dist/tileset/helpers/bounding-volume.d.ts.map +1 -0
  116. package/dist/tileset/helpers/bounding-volume.js +274 -69
  117. package/dist/tileset/helpers/frame-state.d.ts +28 -0
  118. package/dist/tileset/helpers/frame-state.d.ts.map +1 -0
  119. package/dist/tileset/helpers/frame-state.js +131 -49
  120. package/dist/tileset/helpers/i3s-lod.d.ts +20 -0
  121. package/dist/tileset/helpers/i3s-lod.d.ts.map +1 -0
  122. package/dist/tileset/helpers/i3s-lod.js +82 -105
  123. package/dist/tileset/helpers/tiles-3d-lod.d.ts +8 -0
  124. package/dist/tileset/helpers/tiles-3d-lod.d.ts.map +1 -0
  125. package/dist/tileset/helpers/tiles-3d-lod.js +112 -100
  126. package/dist/tileset/helpers/transform-utils.d.ts +2 -0
  127. package/dist/tileset/helpers/transform-utils.d.ts.map +1 -0
  128. package/dist/tileset/helpers/transform-utils.js +51 -56
  129. package/dist/tileset/helpers/zoom.d.ts +46 -0
  130. package/dist/tileset/helpers/zoom.d.ts.map +1 -0
  131. package/dist/tileset/helpers/zoom.js +83 -30
  132. package/dist/tileset/tile-3d.d.ts +206 -0
  133. package/dist/tileset/tile-3d.d.ts.map +1 -0
  134. package/dist/tileset/tile-3d.js +593 -531
  135. package/dist/tileset/tileset-3d.d.ts +217 -0
  136. package/dist/tileset/tileset-3d.d.ts.map +1 -0
  137. package/dist/tileset/tileset-3d.js +707 -648
  138. package/dist/tileset/tileset-cache.d.ts +18 -0
  139. package/dist/tileset/tileset-cache.d.ts.map +1 -0
  140. package/dist/tileset/tileset-cache.js +70 -71
  141. package/dist/tileset/tileset-traverser.d.ts +46 -0
  142. package/dist/tileset/tileset-traverser.d.ts.map +1 -0
  143. package/dist/tileset/tileset-traverser.js +309 -0
  144. package/dist/types.d.ts +34 -0
  145. package/dist/types.d.ts.map +1 -0
  146. package/dist/types.js +2 -0
  147. package/dist/utils/doubly-linked-list-node.d.ts +11 -0
  148. package/dist/utils/doubly-linked-list-node.d.ts.map +1 -0
  149. package/dist/utils/doubly-linked-list-node.js +17 -8
  150. package/dist/utils/doubly-linked-list.d.ts +30 -0
  151. package/dist/utils/doubly-linked-list.d.ts.map +1 -0
  152. package/dist/utils/doubly-linked-list.js +91 -72
  153. package/dist/utils/managed-array.d.ts +85 -0
  154. package/dist/utils/managed-array.d.ts.map +1 -0
  155. package/dist/utils/managed-array.js +144 -103
  156. package/package.json +10 -10
  157. package/src/constants.ts +2 -0
  158. package/src/index.ts +7 -4
  159. package/src/tileset/{traversers → format-3d-tiles}/tileset-3d-traverser.ts +4 -2
  160. package/src/tileset/format-i3s/i3s-pending-tiles-register.ts +44 -0
  161. package/src/tileset/format-i3s/i3s-tile-manager.ts +101 -0
  162. package/src/tileset/{traversers → format-i3s}/i3s-tileset-traverser.ts +27 -15
  163. package/src/tileset/helpers/bounding-volume.ts +136 -0
  164. package/src/tileset/helpers/frame-state.ts +102 -18
  165. package/src/tileset/helpers/i3s-lod.ts +75 -96
  166. package/src/tileset/helpers/tiles-3d-lod.ts +2 -0
  167. package/src/tileset/helpers/transform-utils.ts +2 -0
  168. package/src/tileset/helpers/zoom.ts +84 -9
  169. package/src/tileset/tile-3d.ts +77 -20
  170. package/src/tileset/tileset-3d.ts +205 -43
  171. package/src/tileset/tileset-cache.ts +6 -2
  172. package/src/tileset/{traversers/tileset-traverser.ts → tileset-traverser.ts} +29 -17
  173. package/src/types.ts +36 -0
  174. package/src/utils/{doubly-linked-list-node.js → doubly-linked-list-node.ts} +7 -2
  175. package/src/utils/{doubly-linked-list.js → doubly-linked-list.ts} +5 -8
  176. package/src/utils/{managed-array.js → managed-array.ts} +5 -2
  177. package/dist/bundle.js.map +0 -1
  178. package/dist/constants.js.map +0 -1
  179. package/dist/index.js.map +0 -1
  180. package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
  181. package/dist/tileset/helpers/bounding-volume.js.map +0 -1
  182. package/dist/tileset/helpers/frame-state.js.map +0 -1
  183. package/dist/tileset/helpers/i3s-lod.js.map +0 -1
  184. package/dist/tileset/helpers/transform-utils.js.map +0 -1
  185. package/dist/tileset/helpers/zoom.js.map +0 -1
  186. package/dist/tileset/tile-3d.js.map +0 -1
  187. package/dist/tileset/tileset-3d.js.map +0 -1
  188. package/dist/tileset/tileset-cache.js.map +0 -1
  189. package/dist/tileset/traversers/i3s-tile-manager.js +0 -45
  190. package/dist/tileset/traversers/i3s-tile-manager.js.map +0 -1
  191. package/dist/tileset/traversers/i3s-tileset-traverser.js.map +0 -1
  192. package/dist/tileset/traversers/tileset-3d-traverser.js.map +0 -1
  193. package/dist/tileset/traversers/tileset-traverser.js.map +0 -1
  194. package/dist/utils/doubly-linked-list-node.js.map +0 -1
  195. package/dist/utils/doubly-linked-list.js.map +0 -1
  196. package/dist/utils/managed-array.js.map +0 -1
  197. package/src/tileset/traversers/i3s-tile-manager.ts +0 -39
@@ -1,108 +1,85 @@
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) {
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getProjectedRadius = exports.getLodStatus = void 0;
5
+ const core_1 = require("@math.gl/core");
6
+ const geospatial_1 = require("@math.gl/geospatial");
7
+ const cameraPositionCartesian = new core_1.Vector3();
8
+ const toEye = new core_1.Vector3();
9
+ const cameraPositionEnu = new core_1.Vector3();
10
+ const extraVertexEnu = new core_1.Vector3();
11
+ const projectedOriginVector = new core_1.Vector3();
12
+ const enuToCartesianMatrix = new core_1.Matrix4();
13
+ const cartesianToEnuMatrix = new core_1.Matrix4();
14
+ /**
15
+ * For the maxScreenThreshold error metric, maxError means that you should replace the node with it's children
16
+ as soon as the nodes bounding sphere has a screen radius larger than maxError pixels.
17
+ In this sense a value of 0 means you should always load it's children,
18
+ or if it's a leaf node, you should always display it.
19
+ * @param tile
20
+ * @param frameState
21
+ * @returns
22
+ */
23
+ function getLodStatus(tile, frameState) {
24
+ if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
25
+ return 'DIG';
26
+ }
27
+ const screenSize = 2 * getProjectedRadius(tile, frameState);
28
+ if (screenSize < 2) {
29
+ return 'OUT';
30
+ }
31
+ if (!tile.header.children || screenSize <= tile.lodMetricValue) {
32
+ return 'DRAW';
33
+ }
34
+ else if (tile.header.children) {
35
+ return 'DIG';
36
+ }
27
37
  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
38
  }
100
-
101
- function getTanOfHalfVFAngle(frameState) {
102
- const {
103
- projectionMatrix
104
- } = frameState.viewport;
105
- const t = projectionMatrix[5];
106
- return t;
39
+ exports.getLodStatus = getLodStatus;
40
+ /**
41
+ * Calculate size of MBS radius projected on the screen plane
42
+ * @param tile
43
+ * @param frameState
44
+ * @returns
45
+ */
46
+ // eslint-disable-next-line max-statements
47
+ function getProjectedRadius(tile, frameState) {
48
+ const { topDownViewport: viewport } = frameState;
49
+ const mbsLat = tile.header.mbs[1];
50
+ const mbsLon = tile.header.mbs[0];
51
+ const mbsZ = tile.header.mbs[2];
52
+ const mbsR = tile.header.mbs[3];
53
+ const mbsCenterCartesian = [...tile.boundingVolume.center];
54
+ const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
55
+ geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);
56
+ // ---------------------------
57
+ // Calculate mbs border vertex
58
+ // ---------------------------
59
+ toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
60
+ // Add extra vector to form plane
61
+ geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
62
+ cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();
63
+ cameraPositionEnu.copy(cameraPositionCartesian).transform(cartesianToEnuMatrix);
64
+ // Mean Proportionals in Right Triangles - Altitude rule
65
+ // https://mathbitsnotebook.com/Geometry/RightTriangles/RTmeanRight.html
66
+ const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
67
+ const extraZ = (projection * projection) / cameraPositionEnu[2];
68
+ extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
69
+ const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
70
+ const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();
71
+ // We need radius vector orthogonal to toEye vector
72
+ const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
73
+ const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);
74
+ const sphereMbsBorderVertexCartographic = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
75
+ // ---------------------------
76
+ // Project center vertex and border vertex and calculate projected radius of MBS
77
+ const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
78
+ const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
79
+ const projectedRadius = projectedOriginVector
80
+ .copy(projectedOrigin)
81
+ .subtract(projectedMbsBorderVertex)
82
+ .magnitude();
83
+ return projectedRadius;
107
84
  }
108
- //# sourceMappingURL=i3s-lod.js.map
85
+ exports.getProjectedRadius = getProjectedRadius;
@@ -0,0 +1,8 @@
1
+ export declare function calculateDynamicScreenSpaceError(root: any, { camera, mapProjection }: {
2
+ camera: any;
3
+ mapProjection: any;
4
+ }, options?: {}): number;
5
+ export declare function fog(distanceToCamera: any, density: any): number;
6
+ export declare function getDynamicScreenSpaceError(tileset: any, distanceToCamera: any): number;
7
+ export declare function getTiles3DScreenSpaceError(tile: any, frameState: any, useParentLodMetric: any): number;
8
+ //# sourceMappingURL=tiles-3d-lod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiles-3d-lod.d.ts","sourceRoot":"","sources":["../../../src/tileset/helpers/tiles-3d-lod.ts"],"names":[],"mappings":"AAoBA,wBAAgB,gCAAgC,CAAC,IAAI,KAAA,EAAE,EAAC,MAAM,EAAE,aAAa,EAAC;;;CAAA,EAAE,OAAO,KAAK,UAqF3F;AAED,wBAAgB,GAAG,CAAC,gBAAgB,KAAA,EAAE,OAAO,KAAA,UAG5C;AAED,wBAAgB,0BAA0B,CAAC,OAAO,KAAA,EAAE,gBAAgB,KAAA,UAUnE;AAED,wBAAgB,0BAA0B,CAAC,IAAI,KAAA,EAAE,UAAU,KAAA,EAAE,kBAAkB,KAAA,UAsB9E"}
@@ -1,105 +1,117 @@
1
- import { Matrix4, Vector3, clamp } from '@math.gl/core';
2
- const scratchPositionNormal = new Vector3();
3
- const scratchCartographic = new Vector3();
4
- const scratchMatrix = new Matrix4();
5
- const scratchCenter = new Vector3();
6
- const scratchPosition = new Vector3();
7
- const scratchDirection = new Vector3();
8
- export function calculateDynamicScreenSpaceError(root, {
9
- camera,
10
- mapProjection
11
- }, options = {}) {
12
- const {
13
- dynamicScreenSpaceErrorHeightFalloff = 0.25,
14
- dynamicScreenSpaceErrorDensity = 0.00278
15
- } = options;
16
- let up;
17
- let direction;
18
- let height;
19
- let minimumHeight;
20
- let maximumHeight;
21
- const tileBoundingVolume = root.contentBoundingVolume;
22
-
23
- if (tileBoundingVolume instanceof TileBoundingRegion) {
24
- up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
25
- direction = camera.directionWC;
26
- height = camera.positionCartographic.height;
27
- minimumHeight = tileBoundingVolume.minimumHeight;
28
- maximumHeight = tileBoundingVolume.maximumHeight;
29
- } else {
30
- const transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);
31
- const ellipsoid = mapProjection.ellipsoid;
32
- const boundingVolume = tileBoundingVolume.boundingVolume;
33
- const centerLocal = Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter);
34
-
35
- if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {
36
- const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic);
37
- up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
38
- direction = camera.directionWC;
39
- height = camera.positionCartographic.height;
40
- minimumHeight = 0.0;
41
- maximumHeight = centerCartographic.height * 2.0;
42
- } else {
43
- const positionLocal = Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition);
44
- up = Cartesian3.UNIT_Z;
45
- direction = Matrix4.multiplyByPointAsVector(transformLocal, camera.directionWC, scratchDirection);
46
- direction = Cartesian3.normalize(direction, direction);
47
- height = positionLocal.z;
48
-
49
- if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
50
- const boxHeight = root._header.boundingVolume.box[11];
51
- minimumHeight = centerLocal.z - boxHeight;
52
- maximumHeight = centerLocal.z + boxHeight;
53
- } else if (tileBoundingVolume instanceof TileBoundingSphere) {
54
- const radius = boundingVolume.radius;
55
- minimumHeight = centerLocal.z - radius;
56
- maximumHeight = centerLocal.z + radius;
57
- }
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getTiles3DScreenSpaceError = exports.getDynamicScreenSpaceError = exports.fog = exports.calculateDynamicScreenSpaceError = void 0;
5
+ // This file is derived from the Cesium code base under Apache 2 license
6
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
7
+ // TODO - Dynamic screen space error provides an optimization when looking at
8
+ // tilesets from above
9
+ /* eslint-disable */
10
+ // @ts-nocheck
11
+ const core_1 = require("@math.gl/core");
12
+ const scratchPositionNormal = new core_1.Vector3();
13
+ const scratchCartographic = new core_1.Vector3();
14
+ const scratchMatrix = new core_1.Matrix4();
15
+ const scratchCenter = new core_1.Vector3();
16
+ const scratchPosition = new core_1.Vector3();
17
+ const scratchDirection = new core_1.Vector3();
18
+ // eslint-disable-next-line max-statements, complexity
19
+ function calculateDynamicScreenSpaceError(root, { camera, mapProjection }, options = {}) {
20
+ const { dynamicScreenSpaceErrorHeightFalloff = 0.25, dynamicScreenSpaceErrorDensity = 0.00278 } = options;
21
+ let up;
22
+ let direction;
23
+ let height;
24
+ let minimumHeight;
25
+ let maximumHeight;
26
+ const tileBoundingVolume = root.contentBoundingVolume;
27
+ if (tileBoundingVolume instanceof TileBoundingRegion) {
28
+ up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
29
+ direction = camera.directionWC;
30
+ height = camera.positionCartographic.height;
31
+ minimumHeight = tileBoundingVolume.minimumHeight;
32
+ maximumHeight = tileBoundingVolume.maximumHeight;
58
33
  }
59
- }
60
-
61
- const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
62
- const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
63
- const heightFar = maximumHeight;
64
- const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
65
- const dot = Math.abs(Cartesian3.dot(direction, up));
66
- let horizonFactor = 1.0 - dot;
67
- horizonFactor = horizonFactor * (1.0 - t);
68
- return dynamicScreenSpaceErrorDensity * horizonFactor;
34
+ else {
35
+ // Transform camera position and direction into the local coordinate system of the tileset
36
+ const transformLocal = core_1.Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);
37
+ const ellipsoid = mapProjection.ellipsoid;
38
+ const boundingVolume = tileBoundingVolume.boundingVolume;
39
+ const centerLocal = core_1.Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter);
40
+ if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {
41
+ // The tileset is defined in WGS84. Approximate the minimum and maximum height.
42
+ const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic);
43
+ up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
44
+ direction = camera.directionWC;
45
+ height = camera.positionCartographic.height;
46
+ minimumHeight = 0.0;
47
+ maximumHeight = centerCartographic.height * 2.0;
48
+ }
49
+ else {
50
+ // The tileset is defined in local coordinates (z-up)
51
+ const positionLocal = core_1.Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition);
52
+ up = Cartesian3.UNIT_Z;
53
+ direction = core_1.Matrix4.multiplyByPointAsVector(transformLocal, camera.directionWC, scratchDirection);
54
+ direction = Cartesian3.normalize(direction, direction);
55
+ height = positionLocal.z;
56
+ if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
57
+ // Assuming z-up, the last component stores the half-height of the box
58
+ const boxHeight = root._header.boundingVolume.box[11];
59
+ minimumHeight = centerLocal.z - boxHeight;
60
+ maximumHeight = centerLocal.z + boxHeight;
61
+ }
62
+ else if (tileBoundingVolume instanceof TileBoundingSphere) {
63
+ const radius = boundingVolume.radius;
64
+ minimumHeight = centerLocal.z - radius;
65
+ maximumHeight = centerLocal.z + radius;
66
+ }
67
+ }
68
+ }
69
+ // The range where the density starts to lessen. Start at the quarter height of the tileset.
70
+ const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
71
+ const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
72
+ const heightFar = maximumHeight;
73
+ const t = (0, core_1.clamp)((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
74
+ // Increase density as the camera tilts towards the horizon
75
+ const dot = Math.abs(Cartesian3.dot(direction, up));
76
+ let horizonFactor = 1.0 - dot;
77
+ // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.
78
+ // The goal is to increase density for the "street view", not when viewing the tileset from a distance.
79
+ horizonFactor = horizonFactor * (1.0 - t);
80
+ return dynamicScreenSpaceErrorDensity * horizonFactor;
69
81
  }
70
- export function fog(distanceToCamera, density) {
71
- const scalar = distanceToCamera * density;
72
- return 1.0 - Math.exp(-(scalar * scalar));
82
+ exports.calculateDynamicScreenSpaceError = calculateDynamicScreenSpaceError;
83
+ function fog(distanceToCamera, density) {
84
+ const scalar = distanceToCamera * density;
85
+ return 1.0 - Math.exp(-(scalar * scalar));
73
86
  }
74
- export function getDynamicScreenSpaceError(tileset, distanceToCamera) {
75
- if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {
76
- const density = tileset.dynamicScreenSpaceErrorComputedDensity;
77
- const factor = tileset.dynamicScreenSpaceErrorFactor;
78
- const dynamicError = fog(distanceToCamera, density) * factor;
79
- return dynamicError;
80
- }
81
-
82
- return 0;
87
+ exports.fog = fog;
88
+ function getDynamicScreenSpaceError(tileset, distanceToCamera) {
89
+ if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {
90
+ const density = tileset.dynamicScreenSpaceErrorComputedDensity;
91
+ const factor = tileset.dynamicScreenSpaceErrorFactor;
92
+ // TODO: Refined screen space error that minimizes tiles in non-first-person
93
+ const dynamicError = fog(distanceToCamera, density) * factor;
94
+ return dynamicError;
95
+ }
96
+ return 0;
83
97
  }
84
- export function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {
85
- const tileset = tile.tileset;
86
- const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue;
87
- const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
88
-
89
- if (lodMetricValue === 0.0) {
90
- return 0.0;
91
- }
92
-
93
- const distance = Math.max(tile._distanceToCamera, 1e-7);
94
- const {
95
- height,
96
- sseDenominator
97
- } = frameState;
98
- const {
99
- viewDistanceScale
100
- } = tileset.options;
101
- let error = lodMetricValue * height * (viewDistanceScale || 1.0) / (distance * sseDenominator);
102
- error -= getDynamicScreenSpaceError(tileset, distance);
103
- return error;
98
+ exports.getDynamicScreenSpaceError = getDynamicScreenSpaceError;
99
+ function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {
100
+ const tileset = tile.tileset;
101
+ const parentLodMetricValue = (tile.parent && tile.parent.lodMetricValue) || tile.lodMetricValue;
102
+ const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
103
+ // Leaf tiles do not have any error so save the computation
104
+ if (lodMetricValue === 0.0) {
105
+ return 0.0;
106
+ }
107
+ // TODO: Orthographic Frustum needs special treatment?
108
+ // this._getOrthograhicScreenSpaceError();
109
+ // Avoid divide by zero when viewer is inside the tile
110
+ const distance = Math.max(tile._distanceToCamera, 1e-7);
111
+ const { height, sseDenominator } = frameState;
112
+ const { viewDistanceScale } = tileset.options;
113
+ let error = (lodMetricValue * height * (viewDistanceScale || 1.0)) / (distance * sseDenominator);
114
+ error -= getDynamicScreenSpaceError(tileset, distance);
115
+ return error;
104
116
  }
105
- //# sourceMappingURL=tiles-3d-lod.js.map
117
+ exports.getTiles3DScreenSpaceError = getTiles3DScreenSpaceError;
@@ -0,0 +1,2 @@
1
+ export declare function calculateTransformProps(tileHeader: any, tile: any): void;
2
+ //# sourceMappingURL=transform-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-utils.d.ts","sourceRoot":"","sources":["../../../src/tileset/helpers/transform-utils.ts"],"names":[],"mappings":"AAMA,wBAAgB,uBAAuB,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,QA4DvD"}
@@ -1,58 +1,53 @@
1
- import { Ellipsoid } from '@math.gl/geospatial';
2
- import { Matrix4, Vector3 } from '@math.gl/core';
3
- import { assert } from '@loaders.gl/loader-utils';
4
- export function calculateTransformProps(tileHeader, tile) {
5
- assert(tileHeader);
6
- assert(tile);
7
- const {
8
- rtcCenter,
9
- gltfUpAxis
10
- } = tile;
11
- const {
12
- computedTransform,
13
- boundingVolume: {
14
- center
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.calculateTransformProps = void 0;
5
+ const geospatial_1 = require("@math.gl/geospatial");
6
+ const core_1 = require("@math.gl/core");
7
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
8
+ function calculateTransformProps(tileHeader, tile) {
9
+ (0, loader_utils_1.assert)(tileHeader);
10
+ (0, loader_utils_1.assert)(tile);
11
+ const { rtcCenter, gltfUpAxis } = tile;
12
+ const { computedTransform, boundingVolume: { center } } = tileHeader;
13
+ let modelMatrix = new core_1.Matrix4(computedTransform);
14
+ // Translate if appropriate
15
+ if (rtcCenter) {
16
+ modelMatrix.translate(rtcCenter);
17
+ }
18
+ // glTF models need to be rotated from Y to Z up
19
+ // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
20
+ switch (gltfUpAxis) {
21
+ case 'Z':
22
+ break;
23
+ case 'Y':
24
+ const rotationY = new core_1.Matrix4().rotateX(Math.PI / 2);
25
+ modelMatrix = modelMatrix.multiplyRight(rotationY);
26
+ break;
27
+ case 'X':
28
+ const rotationX = new core_1.Matrix4().rotateY(-Math.PI / 2);
29
+ modelMatrix = modelMatrix.multiplyRight(rotationX);
30
+ break;
31
+ default:
32
+ break;
33
+ }
34
+ // Scale/offset positions if normalized integers
35
+ if (tile.isQuantized) {
36
+ modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);
37
+ }
38
+ // Option 1: Cartesian matrix and origin
39
+ const cartesianOrigin = new core_1.Vector3(center);
40
+ tile.cartesianModelMatrix = modelMatrix;
41
+ tile.cartesianOrigin = cartesianOrigin;
42
+ // Option 2: Cartographic matrix and origin
43
+ const cartographicOrigin = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new core_1.Vector3());
44
+ const fromFixedFrameMatrix = geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
45
+ const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
46
+ tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
47
+ tile.cartographicOrigin = cartographicOrigin;
48
+ // Deprecated, drop
49
+ if (!tile.coordinateSystem) {
50
+ tile.modelMatrix = tile.cartographicModelMatrix;
15
51
  }
16
- } = tileHeader;
17
- let modelMatrix = new Matrix4(computedTransform);
18
-
19
- if (rtcCenter) {
20
- modelMatrix.translate(rtcCenter);
21
- }
22
-
23
- switch (gltfUpAxis) {
24
- case 'Z':
25
- break;
26
-
27
- case 'Y':
28
- const rotationY = new Matrix4().rotateX(Math.PI / 2);
29
- modelMatrix = modelMatrix.multiplyRight(rotationY);
30
- break;
31
-
32
- case 'X':
33
- const rotationX = new Matrix4().rotateY(-Math.PI / 2);
34
- modelMatrix = modelMatrix.multiplyRight(rotationX);
35
- break;
36
-
37
- default:
38
- break;
39
- }
40
-
41
- if (tile.isQuantized) {
42
- modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);
43
- }
44
-
45
- const cartesianOrigin = new Vector3(center);
46
- tile.cartesianModelMatrix = modelMatrix;
47
- tile.cartesianOrigin = cartesianOrigin;
48
- const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3());
49
- const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
50
- const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
51
- tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
52
- tile.cartographicOrigin = cartographicOrigin;
53
-
54
- if (!tile.coordinateSystem) {
55
- tile.modelMatrix = tile.cartographicModelMatrix;
56
- }
57
52
  }
58
- //# sourceMappingURL=transform-utils.js.map
53
+ exports.calculateTransformProps = calculateTransformProps;
@@ -0,0 +1,46 @@
1
+ import { Vector3 } from '@math.gl/core';
2
+ import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
3
+ import { BoundingRectangle } from '../../types';
4
+ /**
5
+ * Calculate appropriate zoom value for a particular boundingVolume
6
+ * @param boundingVolume - the instance of bounding volume
7
+ * @param cartorgraphicCenter - cartographic center of the bounding volume
8
+ * @returns {number} - zoom value
9
+ */
10
+ export declare function getZoomFromBoundingVolume(boundingVolume: BoundingSphere | OrientedBoundingBox | BoundingRectangle, cartorgraphicCenter: Vector3): number;
11
+ /**
12
+ * Calculate initial zoom for the tileset from 3D `fullExtent` defined in
13
+ * the tileset metadata
14
+ * @param fullExtent - 3D extent of the tileset
15
+ * @param fullExtent.xmin - minimal longitude in decimal degrees
16
+ * @param fullExtent.xmax - maximal longitude in decimal degrees
17
+ * @param fullExtent.ymin - minimal latitude in decimal degrees
18
+ * @param fullExtent.ymax - maximal latitude in decimal degrees
19
+ * @param fullExtent.zmin - minimal elevation in meters
20
+ * @param fullExtent.zmax - maximal elevation in meters
21
+ * @param cartorgraphicCenter - tileset center in cartographic coordinate system
22
+ * @param cartesianCenter - tileset center in cartesian coordinate system
23
+ * @returns - initial zoom for the tileset
24
+ */
25
+ export declare function getZoomFromFullExtent(fullExtent: {
26
+ xmin: number;
27
+ xmax: number;
28
+ ymin: number;
29
+ ymax: number;
30
+ zmin: number;
31
+ zmax: number;
32
+ }, cartorgraphicCenter: Vector3, cartesianCenter: Vector3): number;
33
+ /**
34
+ * Calculate initial zoom for the tileset from 2D `extent` defined in
35
+ * the tileset metadata
36
+ * @param extent - 2D extent of the tileset. It is array of 4 elements [xmin, ymin, xmax, ymax]
37
+ * @param extent[0] - minimal longitude in decimal degrees
38
+ * @param extent[1] - minimal latitude in decimal degrees
39
+ * @param extent[2] - maximal longitude in decimal degrees
40
+ * @param extent[3] - maximal latitude in decimal degrees
41
+ * @param cartorgraphicCenter - tileset center in cartographic coordinate system
42
+ * @param cartesianCenter - tileset center in cartesian coordinate system
43
+ * @returns - initial zoom for the tileset
44
+ */
45
+ export declare function getZoomFromExtent(extent: [number, number, number, number], cartorgraphicCenter: Vector3, cartesianCenter: Vector3): number;
46
+ //# sourceMappingURL=zoom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zoom.d.ts","sourceRoot":"","sources":["../../../src/tileset/helpers/zoom.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAQ9C;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,cAAc,GAAG,mBAAmB,GAAG,iBAAiB,EACxE,mBAAmB,EAAE,OAAO,UAwB7B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE;IACV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,EACD,mBAAmB,EAAE,OAAO,EAC5B,eAAe,EAAE,OAAO,UAYzB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACxC,mBAAmB,EAAE,OAAO,EAC5B,eAAe,EAAE,OAAO,UAQzB"}