@loaders.gl/tiles 3.1.0-alpha.4 → 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 (78) 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 +1 -1
  6. package/dist/es5/bundle.js.map +1 -1
  7. package/dist/es5/constants.js +6 -6
  8. package/dist/es5/constants.js.map +1 -1
  9. package/dist/es5/index.js +20 -12
  10. package/dist/es5/index.js.map +1 -1
  11. package/dist/es5/tileset/helpers/bounding-volume.js +25 -37
  12. package/dist/es5/tileset/helpers/bounding-volume.js.map +1 -1
  13. package/dist/es5/tileset/helpers/frame-state.js +29 -25
  14. package/dist/es5/tileset/helpers/frame-state.js.map +1 -1
  15. package/dist/es5/tileset/helpers/i3s-lod.js +57 -106
  16. package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -1
  17. package/dist/es5/tileset/helpers/tiles-3d-lod.js +51 -47
  18. package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +1 -1
  19. package/dist/es5/tileset/helpers/transform-utils.js +21 -12
  20. package/dist/es5/tileset/helpers/transform-utils.js.map +1 -1
  21. package/dist/es5/tileset/helpers/zoom.js +17 -15
  22. package/dist/es5/tileset/helpers/zoom.js.map +1 -1
  23. package/dist/es5/tileset/tile-3d.js +328 -421
  24. package/dist/es5/tileset/tile-3d.js.map +1 -1
  25. package/dist/es5/tileset/tileset-3d.js +381 -563
  26. package/dist/es5/tileset/tileset-3d.js.map +1 -1
  27. package/dist/es5/tileset/tileset-cache.js +50 -63
  28. package/dist/es5/tileset/tileset-cache.js.map +1 -1
  29. package/dist/es5/tileset/traversers/i3s-tile-manager.js +32 -44
  30. package/dist/es5/tileset/traversers/i3s-tile-manager.js.map +1 -1
  31. package/dist/es5/tileset/traversers/i3s-tileset-traverser.js +53 -143
  32. package/dist/es5/tileset/traversers/i3s-tileset-traverser.js.map +1 -1
  33. package/dist/es5/tileset/traversers/tileset-3d-traverser.js +34 -62
  34. package/dist/es5/tileset/traversers/tileset-3d-traverser.js.map +1 -1
  35. package/dist/es5/tileset/traversers/tileset-traverser.js +209 -282
  36. package/dist/es5/tileset/traversers/tileset-traverser.js.map +1 -1
  37. package/dist/es5/utils/doubly-linked-list-node.js +7 -9
  38. package/dist/es5/utils/doubly-linked-list-node.js.map +1 -1
  39. package/dist/es5/utils/doubly-linked-list.js +64 -76
  40. package/dist/es5/utils/doubly-linked-list.js.map +1 -1
  41. package/dist/es5/utils/managed-array.js +86 -108
  42. package/dist/es5/utils/managed-array.js.map +1 -1
  43. package/dist/esm/index.js +1 -0
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/tileset/helpers/i3s-lod.js +45 -86
  46. package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -1
  47. package/dist/esm/tileset/helpers/transform-utils.js +4 -1
  48. package/dist/esm/tileset/helpers/transform-utils.js.map +1 -1
  49. package/dist/esm/tileset/tile-3d.js +3 -3
  50. package/dist/esm/tileset/tile-3d.js.map +1 -1
  51. package/dist/esm/tileset/tileset-3d.js +5 -5
  52. package/dist/esm/tileset/tileset-3d.js.map +1 -1
  53. package/dist/esm/tileset/traversers/i3s-tileset-traverser.js +4 -4
  54. package/dist/esm/tileset/traversers/i3s-tileset-traverser.js.map +1 -1
  55. package/dist/index.d.ts +10 -0
  56. package/dist/tileset/helpers/3d-tiles-options.d.ts +3 -0
  57. package/dist/tileset/helpers/bounding-volume.d.ts +8 -0
  58. package/dist/tileset/helpers/frame-state.d.ts +16 -0
  59. package/dist/tileset/helpers/i3s-lod.d.ts +19 -0
  60. package/dist/tileset/helpers/tiles-3d-lod.d.ts +7 -0
  61. package/dist/tileset/helpers/transform-utils.d.ts +1 -0
  62. package/dist/tileset/helpers/zoom.d.ts +6 -0
  63. package/dist/tileset/tile-3d.d.ts +173 -0
  64. package/dist/tileset/tileset-3d.d.ts +171 -0
  65. package/dist/tileset/tileset-cache.d.ts +17 -0
  66. package/dist/tileset/traversers/i3s-tile-manager.d.ts +7 -0
  67. package/dist/tileset/traversers/i3s-tileset-traverser.d.ts +17 -0
  68. package/dist/tileset/traversers/tileset-3d-traverser.d.ts +6 -0
  69. package/dist/tileset/traversers/tileset-traverser.d.ts +51 -0
  70. package/dist/utils/doubly-linked-list-node.d.ts +11 -0
  71. package/dist/utils/doubly-linked-list.d.ts +30 -0
  72. package/dist/utils/managed-array.d.ts +84 -0
  73. package/package.json +9 -6
  74. package/src/index.ts +1 -0
  75. package/src/tileset/helpers/i3s-lod.ts +72 -96
  76. package/src/tileset/helpers/transform-utils.ts +3 -1
  77. package/src/tileset/tile-3d.ts +2 -2
  78. package/src/tileset/traversers/i3s-tileset-traverser.ts +2 -3
@@ -1,60 +1,23 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
- exports.lodJudge = lodJudge;
9
- exports.getI3ScreenSize = getI3ScreenSize;
10
-
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
6
+ exports.getLodStatus = getLodStatus;
7
+ exports.getProjectedRadius = getProjectedRadius;
12
8
 
13
9
  var _core = require("@math.gl/core");
14
10
 
15
- var WGS84_RADIUS_X = 6378137.0;
16
- var qualityFactor = Math.PI / 2;
17
-
18
- function lodJudge(tile, frameState) {
19
- var viewport = frameState.viewport;
20
- var metersPerPixel = viewport.metersPerPixel;
21
- var mbsLat = tile.header.mbs[1];
22
- var mbsLon = tile.header.mbs[0];
23
- var mbsZ = tile.header.mbs[2];
24
- var mbsR = tile.header.mbs[3];
25
- var height = viewport.height,
26
- width = viewport.width,
27
- latitude = viewport.latitude,
28
- longitude = viewport.longitude;
29
- var viewportCenter = [longitude, latitude];
30
- var mbsCenter = [mbsLon, mbsLat, mbsZ];
31
- var mbsLatProjected = [longitude, mbsLat];
32
- var mbsLonProjected = [mbsLon, latitude];
33
- var diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0];
34
- var distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter);
35
- var visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X;
36
- var visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X;
37
-
38
- if (distanceInMeters > diagonalInMeters + mbsR / WGS84_RADIUS_X) {
39
- return 'OUT';
40
- }
41
-
42
- if (getDistanceFromLatLon(viewportCenter, mbsLatProjected) > visibleHeight) {
43
- return 'OUT';
44
- }
45
-
46
- if (getDistanceFromLatLon(viewportCenter, mbsLonProjected) > visibleWidth) {
47
- return 'OUT';
48
- }
11
+ var _geospatial = require("@math.gl/geospatial");
49
12
 
50
- if (tile.lodMetricValue === 0) {
13
+ function getLodStatus(tile, frameState) {
14
+ if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
51
15
  return 'DIG';
52
16
  }
53
17
 
54
- var screenSize = getI3ScreenSize(tile, frameState);
55
- screenSize *= qualityFactor;
18
+ const screenSize = 2 * getProjectedRadius(tile, frameState);
56
19
 
57
- if (screenSize < 0.5) {
20
+ if (screenSize < 2) {
58
21
  return 'OUT';
59
22
  }
60
23
 
@@ -67,67 +30,55 @@ function lodJudge(tile, frameState) {
67
30
  return 'OUT';
68
31
  }
69
32
 
70
- function projectVertexToSphere(_ref) {
71
- var _ref2 = (0, _slicedToArray2.default)(_ref, 3),
72
- x = _ref2[0],
73
- y = _ref2[1],
74
- z = _ref2[2];
75
-
76
- var azim = (0, _core.toRadians)(x);
77
- var incl = (0, _core.toRadians)(y);
78
- var radius = 1.0 + z / WGS84_RADIUS_X;
79
- var radCosInc = radius * Math.cos(incl);
80
- x = radCosInc * Math.cos(azim);
81
- y = radCosInc * Math.sin(azim);
82
- z = radius * Math.sin(incl);
83
- return [x, y, z];
84
- }
85
-
86
- function getDistanceFromLatLon(observer, center) {
87
- var _observer = (0, _slicedToArray2.default)(observer, 3),
88
- observerLon = _observer[0],
89
- observerLat = _observer[1],
90
- _observer$ = _observer[2],
91
- observerZ = _observer$ === void 0 ? 0.0 : _observer$;
92
-
93
- var _center = (0, _slicedToArray2.default)(center, 3),
94
- centerLon = _center[0],
95
- centerLat = _center[1],
96
- _center$ = _center[2],
97
- centerZ = _center$ === void 0 ? 0.0 : _center$;
98
-
99
- var projectedCenter = projectVertexToSphere([centerLon, centerLat, centerZ]);
100
- var projectedObserver = projectVertexToSphere([observerLon, observerLat, observerZ]);
101
- var dx = projectedObserver[0] - projectedCenter[0];
102
- var dy = projectedObserver[1] - projectedCenter[1];
103
- var dz = projectedObserver[2] - projectedCenter[2];
104
- return dx * dx + dy * dy + dz * dz;
105
- }
106
-
107
- function getI3ScreenSize(tile, frameState) {
108
- var viewport = frameState.viewport;
109
- var mbsLat = tile.header.mbs[1];
110
- var mbsLon = tile.header.mbs[0];
111
- var mbsZ = tile.header.mbs[2];
112
- var mbsR = tile.header.mbs[3];
113
- var mbsCenter = [mbsLon, mbsLat, mbsZ];
114
- var cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
115
- var dSquared = getDistanceFromLatLon(cameraPositionCartographic, mbsCenter);
116
- var mbsRNormalized = mbsR / WGS84_RADIUS_X;
117
- var d = dSquared - mbsRNormalized * mbsRNormalized;
118
- var fltMax = 3.4028235e38;
119
-
120
- if (d <= 0.0) {
121
- return 0.5 * fltMax;
122
- }
123
-
124
- var screenSizeFactor = getTanOfHalfVFAngle(frameState) * mbsRNormalized / Math.sqrt(d) * 300;
125
- return screenSizeFactor;
126
- }
127
-
128
- function getTanOfHalfVFAngle(frameState) {
129
- var projectionMatrix = frameState.viewport.projectionMatrix;
130
- var t = projectionMatrix[5];
131
- return t;
33
+ function getProjectedRadius(tile, frameState) {
34
+ const originalViewport = frameState.viewport;
35
+ const ViewportClass = originalViewport.constructor;
36
+ const {
37
+ longitude,
38
+ latitude,
39
+ height,
40
+ width,
41
+ bearing,
42
+ zoom
43
+ } = originalViewport;
44
+ const viewport = new ViewportClass({
45
+ longitude,
46
+ latitude,
47
+ height,
48
+ width,
49
+ bearing,
50
+ zoom,
51
+ pitch: 0
52
+ });
53
+ const mbsLat = tile.header.mbs[1];
54
+ const mbsLon = tile.header.mbs[0];
55
+ const mbsZ = tile.header.mbs[2];
56
+ const mbsR = tile.header.mbs[3];
57
+ const mbsCenterCartesian = [...tile.boundingVolume.center];
58
+ const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
59
+
60
+ const cameraPositionCartesian = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new _core.Vector3());
61
+
62
+ const toEye = new _core.Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
63
+ const enuToCartesianMatrix = new _core.Matrix4();
64
+
65
+ _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
66
+
67
+ const cartesianToEnuMatrix = new _core.Matrix4(enuToCartesianMatrix).invert();
68
+ const cameraPositionEnu = new _core.Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);
69
+ const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
70
+ const extraZ = projection * projection / cameraPositionEnu[2];
71
+ const extraVertexEnu = new _core.Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
72
+ const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
73
+ const extraVectorCartesian = new _core.Vector3(extraVertexCartesian).subtract(mbsCenterCartesian).normalize();
74
+ const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
75
+ const sphereMbsBorderVertexCartesian = new _core.Vector3(mbsCenterCartesian).add(radiusVector);
76
+
77
+ const sphereMbsBorderVertexCartographic = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
78
+
79
+ const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
80
+ const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
81
+ const projectedRadius = new _core.Vector3(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
82
+ return projectedRadius;
132
83
  }
133
84
  //# sourceMappingURL=i3s-lod.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/tileset/helpers/i3s-lod.ts"],"names":["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;;AAEA,IAAMA,cAAc,GAAG,SAAvB;AAEA,IAAMC,aAAa,GAAGC,IAAI,CAACC,EAAL,GAAU,CAAhC;;AAEO,SAASC,QAAT,CAAkBC,IAAlB,EAAwBC,UAAxB,EAAoC;AACzC,MAAMC,QAAQ,GAAGD,UAAU,CAACC,QAA5B;AACA,MAAMC,cAAc,GAAGD,QAAQ,CAACC,cAAhC;AAEA,MAAMC,MAAM,GAAGJ,IAAI,CAACK,MAAL,CAAYC,GAAZ,CAAgB,CAAhB,CAAf;AACA,MAAMC,MAAM,GAAGP,IAAI,CAACK,MAAL,CAAYC,GAAZ,CAAgB,CAAhB,CAAf;AACA,MAAME,IAAI,GAAGR,IAAI,CAACK,MAAL,CAAYC,GAAZ,CAAgB,CA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AMC,QAAQ,GAAGjC,qBAAqB,CAAC8B,0BAAD,EAA6BpC,SAA7B,CAAtC;AACA,MAAMwC,cAAc,GAAG9C,IAAI,GAAGd,cAA9B;AACA,MAAM6D,CAAC,GAAGF,QAAQ,GAAGC,cAAc,GAAGA,cAAtC;AACA,MAAME,MAAM,GAAG,YAAf;;AACA,MAAID,CAAC,IAAI,GAAT,EAAc;AACZ,WAAO,MAAMC,MAAb;AACD;;AAKD,MAAMC,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,MAAO2D,gBAAP,GAA2B3D,UAAU,CAACC,QAAtC,CAAO0D,gBAAP;AACA,MAAMC,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"}
1
+ {"version":3,"sources":["../../../../src/tileset/helpers/i3s-lod.ts"],"names":["getLodStatus","tile","frameState","lodMetricValue","isNaN","screenSize","getProjectedRadius","header","children","originalViewport","viewport","ViewportClass","constructor","longitude","latitude","height","width","bearing","zoom","pitch","mbsLat","mbs","mbsLon","mbsZ","mbsR","mbsCenterCartesian","boundingVolume","center","cameraPositionCartographic","unprojectPosition","cameraPosition","cameraPositionCartesian","Ellipsoid","WGS84","cartographicToCartesian","Vector3","toEye","subtract","normalize","enuToCartesianMatrix","Matrix4","eastNorthUpToFixedFrame","cartesianToEnuMatrix","invert","cameraPositionEnu","transform","projection","Math","sqrt","extraZ","extraVertexEnu","extraVertexCartesian","extraVectorCartesian","radiusVector","cross","scale","sphereMbsBorderVertexCartesian","add","sphereMbsBorderVertexCartographic","cartesianToCartographic","projectedOrigin","project","projectedMbsBorderVertex","projectedRadius","magnitude"],"mappings":";;;;;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B,EAAuBA,iBAAiB,CAAC,CAAD,CAAxC,EAA6CK,MAA7C,CAAZ,CAAvB;AACA,QAAME,oBAAoB,GAAGD,cAAc,CAACL,SAAf,CAAyBN,oBAAzB,CAA7B;AACA,QAAMa,oBAAoB,GAAG,IAAIjB,aAAJ,CAAYgB,oBAAZ,EAC1Bd,QAD0B,CACjBZ,kBADiB,EAE1Ba,SAF0B,EAA7B;AAIA,QAAMe,YAAY,GAAGjB,KAAK,CAACkB,KAAN,CAAYF,oBAAZ,EAAkCd,SAAlC,GAA8CiB,KAA9C,CAAoD/B,IAApD,CAArB;AACA,QAAMgC,8BAA8B,GAAG,IAAIrB,aAAJ,CAAYV,kBAAZ,EAAgCgC,GAAhC,CAAoCJ,YAApC,CAAvC;;AACA,QAAMK,iCAAiC,GAAG1B,sBAAUC,KAAV,CAAgB0B,uBAAhB,CACxCH,8BADwC,CAA1C;;AAMA,QAAMI,eAAe,GAAGlD,QAAQ,CAACmD,OAAT,CAAiB,CAACvC,MAAD,EAASF,MAAT,EAAiBG,IAAjB,CAAjB,CAAxB;AACA,QAAMuC,wBAAwB,GAAGpD,QAAQ,CAACmD,OAAT,CAAiBH,iCAAjB,CAAjC;AACA,QAAMK,eAAe,GAAG,IAAI5B,aAAJ,CAAYyB,eAAZ,EACrBvB,QADqB,CACZyB,wBADY,EAErBE,SAFqB,EAAxB;AAGA,SAAOD,eAAP;AACD","sourcesContent":["import {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {Tile3D} from '../..';\nimport {FrameState} from './frame-state';\n\n/**\n * For the maxScreenThreshold error metric, maxError means that you should replace the node with it's children\n as soon as the nodes bounding sphere has a screen radius larger than maxError pixels.\n In this sense a value of 0 means you should always load it's children,\n or if it's a leaf node, you should always display it.\n * @param tile \n * @param frameState \n * @returns \n */\nexport function getLodStatus(tile: Tile3D, frameState: FrameState): 'DIG' | 'OUT' | 'DRAW' {\n if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {\n return 'DIG';\n }\n const screenSize = 2 * getProjectedRadius(tile, frameState);\n if (screenSize < 2) {\n return 'OUT';\n }\n if (!tile.header.children || screenSize <= tile.lodMetricValue) {\n return 'DRAW';\n } else if (tile.header.children) {\n return 'DIG';\n }\n return 'OUT';\n}\n\n/**\n * Calculate size of MBS radius projected on the screen plane\n * @param tile\n * @param frameState\n * @returns\n */\n// eslint-disable-next-line max-statements\nexport function getProjectedRadius(tile: Tile3D, frameState: FrameState): number {\n const originalViewport = frameState.viewport;\n const ViewportClass = originalViewport.constructor;\n const {longitude, latitude, height, width, bearing, zoom} = originalViewport;\n // @ts-ignore\n const viewport = new ViewportClass({longitude, latitude, height, width, bearing, zoom, pitch: 0});\n const mbsLat = tile.header.mbs[1];\n const mbsLon = tile.header.mbs[0];\n const mbsZ = tile.header.mbs[2];\n const mbsR = tile.header.mbs[3];\n const mbsCenterCartesian = [...tile.boundingVolume.center];\n const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);\n const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(\n cameraPositionCartographic,\n new Vector3()\n );\n\n // ---------------------------\n // Calculate mbs border vertex\n // ---------------------------\n const toEye = new Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();\n // Add extra vector to form plane\n const enuToCartesianMatrix = new Matrix4();\n Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);\n const cartesianToEnuMatrix = new Matrix4(enuToCartesianMatrix).invert();\n const cameraPositionEnu = new Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);\n // Mean Proportionals in Right Triangles - Altitude rule\n // https://mathbitsnotebook.com/Geometry/RightTriangles/RTmeanRight.html\n const projection = Math.sqrt(\n cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]\n );\n const extraZ = (projection * projection) / cameraPositionEnu[2];\n const extraVertexEnu = new Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);\n const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);\n const extraVectorCartesian = new Vector3(extraVertexCartesian)\n .subtract(mbsCenterCartesian)\n .normalize();\n // We need radius vector orthogonal to toEye vector\n const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);\n const sphereMbsBorderVertexCartesian = new Vector3(mbsCenterCartesian).add(radiusVector);\n const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(\n sphereMbsBorderVertexCartesian\n );\n // ---------------------------\n\n // Project center vertex and border vertex and calculate projected radius of MBS\n const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);\n const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);\n const projectedRadius = new Vector3(projectedOrigin)\n .subtract(projectedMbsBorderVertex)\n .magnitude();\n return projectedRadius;\n}\n"],"file":"i3s-lod.js"}
@@ -10,27 +10,27 @@ exports.getTiles3DScreenSpaceError = getTiles3DScreenSpaceError;
10
10
 
11
11
  var _core = require("@math.gl/core");
12
12
 
13
- var scratchPositionNormal = new _core.Vector3();
14
- var scratchCartographic = new _core.Vector3();
15
- var scratchMatrix = new _core.Matrix4();
16
- var scratchCenter = new _core.Vector3();
17
- var scratchPosition = new _core.Vector3();
18
- var scratchDirection = new _core.Vector3();
19
-
20
- function calculateDynamicScreenSpaceError(root, _ref) {
21
- var camera = _ref.camera,
22
- mapProjection = _ref.mapProjection;
23
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
24
- var _options$dynamicScree = options.dynamicScreenSpaceErrorHeightFalloff,
25
- dynamicScreenSpaceErrorHeightFalloff = _options$dynamicScree === void 0 ? 0.25 : _options$dynamicScree,
26
- _options$dynamicScree2 = options.dynamicScreenSpaceErrorDensity,
27
- dynamicScreenSpaceErrorDensity = _options$dynamicScree2 === void 0 ? 0.00278 : _options$dynamicScree2;
28
- var up;
29
- var direction;
30
- var height;
31
- var minimumHeight;
32
- var maximumHeight;
33
- var tileBoundingVolume = root.contentBoundingVolume;
13
+ const scratchPositionNormal = new _core.Vector3();
14
+ const scratchCartographic = new _core.Vector3();
15
+ const scratchMatrix = new _core.Matrix4();
16
+ const scratchCenter = new _core.Vector3();
17
+ const scratchPosition = new _core.Vector3();
18
+ const scratchDirection = new _core.Vector3();
19
+
20
+ function calculateDynamicScreenSpaceError(root, {
21
+ camera,
22
+ mapProjection
23
+ }, options = {}) {
24
+ const {
25
+ dynamicScreenSpaceErrorHeightFalloff = 0.25,
26
+ dynamicScreenSpaceErrorDensity = 0.00278
27
+ } = options;
28
+ let up;
29
+ let direction;
30
+ let height;
31
+ let minimumHeight;
32
+ let maximumHeight;
33
+ const tileBoundingVolume = root.contentBoundingVolume;
34
34
 
35
35
  if (tileBoundingVolume instanceof TileBoundingRegion) {
36
36
  up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
@@ -39,22 +39,22 @@ function calculateDynamicScreenSpaceError(root, _ref) {
39
39
  minimumHeight = tileBoundingVolume.minimumHeight;
40
40
  maximumHeight = tileBoundingVolume.maximumHeight;
41
41
  } else {
42
- var transformLocal = _core.Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);
42
+ const transformLocal = _core.Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);
43
43
 
44
- var ellipsoid = mapProjection.ellipsoid;
45
- var boundingVolume = tileBoundingVolume.boundingVolume;
44
+ const ellipsoid = mapProjection.ellipsoid;
45
+ const boundingVolume = tileBoundingVolume.boundingVolume;
46
46
 
47
- var centerLocal = _core.Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter);
47
+ const centerLocal = _core.Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter);
48
48
 
49
49
  if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {
50
- var centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic);
50
+ const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic);
51
51
  up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
52
52
  direction = camera.directionWC;
53
53
  height = camera.positionCartographic.height;
54
54
  minimumHeight = 0.0;
55
55
  maximumHeight = centerCartographic.height * 2.0;
56
56
  } else {
57
- var positionLocal = _core.Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition);
57
+ const positionLocal = _core.Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition);
58
58
 
59
59
  up = Cartesian3.UNIT_Z;
60
60
  direction = _core.Matrix4.multiplyByPointAsVector(transformLocal, camera.directionWC, scratchDirection);
@@ -62,37 +62,37 @@ function calculateDynamicScreenSpaceError(root, _ref) {
62
62
  height = positionLocal.z;
63
63
 
64
64
  if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
65
- var boxHeight = root._header.boundingVolume.box[11];
65
+ const boxHeight = root._header.boundingVolume.box[11];
66
66
  minimumHeight = centerLocal.z - boxHeight;
67
67
  maximumHeight = centerLocal.z + boxHeight;
68
68
  } else if (tileBoundingVolume instanceof TileBoundingSphere) {
69
- var radius = boundingVolume.radius;
69
+ const radius = boundingVolume.radius;
70
70
  minimumHeight = centerLocal.z - radius;
71
71
  maximumHeight = centerLocal.z + radius;
72
72
  }
73
73
  }
74
74
  }
75
75
 
76
- var heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
77
- var heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
78
- var heightFar = maximumHeight;
79
- var t = (0, _core.clamp)((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
80
- var dot = Math.abs(Cartesian3.dot(direction, up));
81
- var horizonFactor = 1.0 - dot;
76
+ const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
77
+ const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
78
+ const heightFar = maximumHeight;
79
+ const t = (0, _core.clamp)((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
80
+ const dot = Math.abs(Cartesian3.dot(direction, up));
81
+ let horizonFactor = 1.0 - dot;
82
82
  horizonFactor = horizonFactor * (1.0 - t);
83
83
  return dynamicScreenSpaceErrorDensity * horizonFactor;
84
84
  }
85
85
 
86
86
  function fog(distanceToCamera, density) {
87
- var scalar = distanceToCamera * density;
87
+ const scalar = distanceToCamera * density;
88
88
  return 1.0 - Math.exp(-(scalar * scalar));
89
89
  }
90
90
 
91
91
  function getDynamicScreenSpaceError(tileset, distanceToCamera) {
92
92
  if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {
93
- var density = tileset.dynamicScreenSpaceErrorComputedDensity;
94
- var factor = tileset.dynamicScreenSpaceErrorFactor;
95
- var dynamicError = fog(distanceToCamera, density) * factor;
93
+ const density = tileset.dynamicScreenSpaceErrorComputedDensity;
94
+ const factor = tileset.dynamicScreenSpaceErrorFactor;
95
+ const dynamicError = fog(distanceToCamera, density) * factor;
96
96
  return dynamicError;
97
97
  }
98
98
 
@@ -100,19 +100,23 @@ function getDynamicScreenSpaceError(tileset, distanceToCamera) {
100
100
  }
101
101
 
102
102
  function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {
103
- var tileset = tile.tileset;
104
- var parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue;
105
- var lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
103
+ const tileset = tile.tileset;
104
+ const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue;
105
+ const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
106
106
 
107
107
  if (lodMetricValue === 0.0) {
108
108
  return 0.0;
109
109
  }
110
110
 
111
- var distance = Math.max(tile._distanceToCamera, 1e-7);
112
- var height = frameState.height,
113
- sseDenominator = frameState.sseDenominator;
114
- var viewDistanceScale = tileset.options.viewDistanceScale;
115
- var error = lodMetricValue * height * (viewDistanceScale || 1.0) / (distance * sseDenominator);
111
+ const distance = Math.max(tile._distanceToCamera, 1e-7);
112
+ const {
113
+ height,
114
+ sseDenominator
115
+ } = frameState;
116
+ const {
117
+ viewDistanceScale
118
+ } = tileset.options;
119
+ let error = lodMetricValue * height * (viewDistanceScale || 1.0) / (distance * sseDenominator);
116
120
  error -= getDynamicScreenSpaceError(tileset, distance);
117
121
  return error;
118
122
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"names":["scratchPositionNormal","Vector3","scratchCartographic","scratchMatrix","Matrix4","scratchCenter","scratchPosition","scratchDirection","calculateDynamicScreenSpaceError","root","camera","mapProjection","options","dynamicScreenSpaceErrorHeightFalloff","dynamicScreenSpaceErrorDensity","up","direction","height","minimumHeight","maximumHeight","tileBoundingVolume","contentBoundingVolume","TileBoundingRegion","Cartesian3","normalize","positionWC","directionWC","positionCartographic","transformLocal","inverseTransformation","computedTransform","ellipsoid","boundingVolume","centerLocal","multiplyByPoint","center","magnitude","minimumRadius","centerCartographic","Cartographic","fromCartesian","positionLocal","UNIT_Z","multiplyByPointAsVector","z","TileOrientedBoundingBox","boxHeight","_header","box","TileBoundingSphere","radius","heightFalloff","heightClose","heightFar","t","dot","Math","abs","horizonFactor","fog","distanceToCamera","density","scalar","exp","getDynamicScreenSpaceError","tileset","dynamicScreenSpaceError","dynamicScreenSpaceErrorComputedDensity","factor","dynamicScreenSpaceErrorFactor","dynamicError","getTiles3DScreenSpaceError","tile","frameState","useParentLodMetric","parentLodMetricValue","parent","lodMetricValue","distance","max","_distanceToCamera","sseDenominator","viewDistanceScale","error"],"mappings":";;;;;;;;;;AAQA;;AAEA,IAAMA,qBAAqB,GAAG,IAAIC,aAAJ,EAA9B;AACA,IAAMC,mBAAmB,GAAG,IAAID,aAAJ,EAA5B;AACA,IAAME,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAIJ,aAAJ,EAAtB;AACA,IAAMK,eAAe,GAAG,IAAIL,aAAJ,EAAxB;AACA,IAAMM,gBAAgB,GAAG,I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0E;AAC/E,MAAMT,OAAO,GAAGO,IAAI,CAACP,OAArB;AACA,MAAMU,oBAAoB,GAAIH,IAAI,CAACI,MAAL,IAAeJ,IAAI,CAACI,MAAL,CAAYC,cAA5B,IAA+CL,IAAI,CAACK,cAAjF;AACA,MAAMA,cAAc,GAAGH,kBAAkB,GAAGC,oBAAH,GAA0BH,IAAI,CAACK,cAAxE;;AAGA,MAAIA,cAAc,KAAK,GAAvB,EAA4B;AAC1B,WAAO,GAAP;AACD;;AAMD,MAAMC,QAAQ,GAAGtB,IAAI,CAACuB,GAAL,CAASP,IAAI,CAACQ,iBAAd,EAAiC,IAAjC,CAAjB;AACA,MAAO/D,MAAP,GAAiCwD,UAAjC,CAAOxD,MAAP;AAAA,MAAegE,cAAf,GAAiCR,UAAjC,CAAeQ,cAAf;AACA,MAAOC,iBAAP,GAA4BjB,OAAO,CAACrD,OAApC,CAAOsE,iBAAP;AACA,MAAIC,KAAK,GAAIN,cAAc,GAAG5D,MAAjB,IAA2BiE,iBAAiB,IAAI,GAAhD,CAAD,IAA0DJ,QAAQ,GAAGG,cAArE,CAAZ;AAEAE,EAAAA,KAAK,IAAInB,0BAA0B,CAACC,OAAD,EAAUa,QAAV,CAAnC;AAEA,SAAOK,KAAP;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// TODO - Dynamic screen space error provides an optimization when looking at\n// tilesets from above\n\n/* eslint-disable */\n// @ts-nocheck\nimport {Matrix4, Vector3, clamp} from '@math.gl/core';\n\nconst scratchPositionNormal = new Vector3();\nconst scratchCartographic = new Vector3();\nconst scratchMatrix = new Matrix4();\nconst scratchCenter = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchDirection = new Vector3();\n\n// eslint-disable-next-line max-statements, complexity\nexport function calculateDynamicScreenSpaceError(root, {camera, mapProjection}, options = {}) {\n const {dynamicScreenSpaceErrorHeightFalloff = 0.25, dynamicScreenSpaceErrorDensity = 0.00278} =\n options;\n\n let up;\n let direction;\n let height;\n let minimumHeight;\n let maximumHeight;\n\n const tileBoundingVolume = root.contentBoundingVolume;\n\n if (tileBoundingVolume instanceof TileBoundingRegion) {\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = tileBoundingVolume.minimumHeight;\n maximumHeight = tileBoundingVolume.maximumHeight;\n } else {\n // Transform camera position and direction into the local coordinate system of the tileset\n const transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);\n const ellipsoid = mapProjection.ellipsoid;\n const boundingVolume = tileBoundingVolume.boundingVolume;\n const centerLocal = Matrix4.multiplyByPoint(\n transformLocal,\n boundingVolume.center,\n scratchCenter\n );\n if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {\n // The tileset is defined in WGS84. Approximate the minimum and maximum height.\n const centerCartographic = Cartographic.fromCartesian(\n centerLocal,\n ellipsoid,\n scratchCartographic\n );\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = 0.0;\n maximumHeight = centerCartographic.height * 2.0;\n } else {\n // The tileset is defined in local coordinates (z-up)\n const positionLocal = Matrix4.multiplyByPoint(\n transformLocal,\n camera.positionWC,\n scratchPosition\n );\n up = Cartesian3.UNIT_Z;\n direction = Matrix4.multiplyByPointAsVector(\n transformLocal,\n camera.directionWC,\n scratchDirection\n );\n direction = Cartesian3.normalize(direction, direction);\n height = positionLocal.z;\n if (tileBoundingVolume instanceof TileOrientedBoundingBox) {\n // Assuming z-up, the last component stores the half-height of the box\n const boxHeight = root._header.boundingVolume.box[11];\n minimumHeight = centerLocal.z - boxHeight;\n maximumHeight = centerLocal.z + boxHeight;\n } else if (tileBoundingVolume instanceof TileBoundingSphere) {\n const radius = boundingVolume.radius;\n minimumHeight = centerLocal.z - radius;\n maximumHeight = centerLocal.z + radius;\n }\n }\n }\n\n // The range where the density starts to lessen. Start at the quarter height of the tileset.\n const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;\n const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;\n const heightFar = maximumHeight;\n\n const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);\n\n // Increase density as the camera tilts towards the horizon\n const dot = Math.abs(Cartesian3.dot(direction, up));\n\n let horizonFactor = 1.0 - dot;\n\n // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.\n // The goal is to increase density for the \"street view\", not when viewing the tileset from a distance.\n horizonFactor = horizonFactor * (1.0 - t);\n\n return dynamicScreenSpaceErrorDensity * horizonFactor;\n}\n\nexport function fog(distanceToCamera, density) {\n const scalar = distanceToCamera * density;\n return 1.0 - Math.exp(-(scalar * scalar));\n}\n\nexport function getDynamicScreenSpaceError(tileset, distanceToCamera) {\n if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {\n const density = tileset.dynamicScreenSpaceErrorComputedDensity;\n const factor = tileset.dynamicScreenSpaceErrorFactor;\n // TODO: Refined screen space error that minimizes tiles in non-first-person\n const dynamicError = fog(distanceToCamera, density) * factor;\n return dynamicError;\n }\n\n return 0;\n}\n\nexport function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {\n const tileset = tile.tileset;\n const parentLodMetricValue = (tile.parent && tile.parent.lodMetricValue) || tile.lodMetricValue;\n const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;\n\n // Leaf tiles do not have any error so save the computation\n if (lodMetricValue === 0.0) {\n return 0.0;\n }\n\n // TODO: Orthographic Frustum needs special treatment?\n // this._getOrthograhicScreenSpaceError();\n\n // Avoid divide by zero when viewer is inside the tile\n const distance = Math.max(tile._distanceToCamera, 1e-7);\n const {height, sseDenominator} = frameState;\n const {viewDistanceScale} = tileset.options;\n let error = (lodMetricValue * height * (viewDistanceScale || 1.0)) / (distance * sseDenominator);\n\n error -= getDynamicScreenSpaceError(tileset, distance);\n\n return error;\n}\n"],"file":"tiles-3d-lod.js"}
1
+ {"version":3,"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"names":["scratchPositionNormal","Vector3","scratchCartographic","scratchMatrix","Matrix4","scratchCenter","scratchPosition","scratchDirection","calculateDynamicScreenSpaceError","root","camera","mapProjection","options","dynamicScreenSpaceErrorHeightFalloff","dynamicScreenSpaceErrorDensity","up","direction","height","minimumHeight","maximumHeight","tileBoundingVolume","contentBoundingVolume","TileBoundingRegion","Cartesian3","normalize","positionWC","directionWC","positionCartographic","transformLocal","inverseTransformation","computedTransform","ellipsoid","boundingVolume","centerLocal","multiplyByPoint","center","magnitude","minimumRadius","centerCartographic","Cartographic","fromCartesian","positionLocal","UNIT_Z","multiplyByPointAsVector","z","TileOrientedBoundingBox","boxHeight","_header","box","TileBoundingSphere","radius","heightFalloff","heightClose","heightFar","t","dot","Math","abs","horizonFactor","fog","distanceToCamera","density","scalar","exp","getDynamicScreenSpaceError","tileset","dynamicScreenSpaceError","dynamicScreenSpaceErrorComputedDensity","factor","dynamicScreenSpaceErrorFactor","dynamicError","getTiles3DScreenSpaceError","tile","frameState","useParentLodMetric","parentLodMetricValue","parent","lodMetricValue","distance","max","_distanceToCamera","sseDenominator","viewDistanceScale","error"],"mappings":";;;;;;;;;;AAQA;;AAEA,MAAMA,qBAAqB,GAAG,IAAIC,aAAJ,EAA9B;AACA,MAAMC,mBAAmB,GAAG,IAAID,aAAJ,EAA5B;AACA,MAAME,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,MAAMC,aAAa,GAAG,IAAIJ,aAAJ,EAAtB;AACA,MAAMK,eAAe,GAAG,IAAIL,aAAJ,EAAxB;AACA,MAAMM,gBAAgB,GAAG,IAAIN,aAAJ,EAAzB;;AAGO,SAASO,gCAAT,CAA0CC,IAA1C,EAAgD;AAACC,EAAAA,MAAD;AAASC,EAAAA;AAAT,CAAhD,EAAyEC,OAAO,GAAG,EAAnF,EAA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,GAA0BH,IAAI,CAACK,cAAxE;;AAGA,MAAIA,cAAc,KAAK,GAAvB,EAA4B;AAC1B,WAAO,GAAP;AACD;;AAMD,QAAMC,QAAQ,GAAGtB,IAAI,CAACuB,GAAL,CAASP,IAAI,CAACQ,iBAAd,EAAiC,IAAjC,CAAjB;AACA,QAAM;AAAC/D,IAAAA,MAAD;AAASgE,IAAAA;AAAT,MAA2BR,UAAjC;AACA,QAAM;AAACS,IAAAA;AAAD,MAAsBjB,OAAO,CAACrD,OAApC;AACA,MAAIuE,KAAK,GAAIN,cAAc,GAAG5D,MAAjB,IAA2BiE,iBAAiB,IAAI,GAAhD,CAAD,IAA0DJ,QAAQ,GAAGG,cAArE,CAAZ;AAEAE,EAAAA,KAAK,IAAInB,0BAA0B,CAACC,OAAD,EAAUa,QAAV,CAAnC;AAEA,SAAOK,KAAP;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// TODO - Dynamic screen space error provides an optimization when looking at\n// tilesets from above\n\n/* eslint-disable */\n// @ts-nocheck\nimport {Matrix4, Vector3, clamp} from '@math.gl/core';\n\nconst scratchPositionNormal = new Vector3();\nconst scratchCartographic = new Vector3();\nconst scratchMatrix = new Matrix4();\nconst scratchCenter = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchDirection = new Vector3();\n\n// eslint-disable-next-line max-statements, complexity\nexport function calculateDynamicScreenSpaceError(root, {camera, mapProjection}, options = {}) {\n const {dynamicScreenSpaceErrorHeightFalloff = 0.25, dynamicScreenSpaceErrorDensity = 0.00278} =\n options;\n\n let up;\n let direction;\n let height;\n let minimumHeight;\n let maximumHeight;\n\n const tileBoundingVolume = root.contentBoundingVolume;\n\n if (tileBoundingVolume instanceof TileBoundingRegion) {\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = tileBoundingVolume.minimumHeight;\n maximumHeight = tileBoundingVolume.maximumHeight;\n } else {\n // Transform camera position and direction into the local coordinate system of the tileset\n const transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);\n const ellipsoid = mapProjection.ellipsoid;\n const boundingVolume = tileBoundingVolume.boundingVolume;\n const centerLocal = Matrix4.multiplyByPoint(\n transformLocal,\n boundingVolume.center,\n scratchCenter\n );\n if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {\n // The tileset is defined in WGS84. Approximate the minimum and maximum height.\n const centerCartographic = Cartographic.fromCartesian(\n centerLocal,\n ellipsoid,\n scratchCartographic\n );\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = 0.0;\n maximumHeight = centerCartographic.height * 2.0;\n } else {\n // The tileset is defined in local coordinates (z-up)\n const positionLocal = Matrix4.multiplyByPoint(\n transformLocal,\n camera.positionWC,\n scratchPosition\n );\n up = Cartesian3.UNIT_Z;\n direction = Matrix4.multiplyByPointAsVector(\n transformLocal,\n camera.directionWC,\n scratchDirection\n );\n direction = Cartesian3.normalize(direction, direction);\n height = positionLocal.z;\n if (tileBoundingVolume instanceof TileOrientedBoundingBox) {\n // Assuming z-up, the last component stores the half-height of the box\n const boxHeight = root._header.boundingVolume.box[11];\n minimumHeight = centerLocal.z - boxHeight;\n maximumHeight = centerLocal.z + boxHeight;\n } else if (tileBoundingVolume instanceof TileBoundingSphere) {\n const radius = boundingVolume.radius;\n minimumHeight = centerLocal.z - radius;\n maximumHeight = centerLocal.z + radius;\n }\n }\n }\n\n // The range where the density starts to lessen. Start at the quarter height of the tileset.\n const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;\n const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;\n const heightFar = maximumHeight;\n\n const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);\n\n // Increase density as the camera tilts towards the horizon\n const dot = Math.abs(Cartesian3.dot(direction, up));\n\n let horizonFactor = 1.0 - dot;\n\n // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.\n // The goal is to increase density for the \"street view\", not when viewing the tileset from a distance.\n horizonFactor = horizonFactor * (1.0 - t);\n\n return dynamicScreenSpaceErrorDensity * horizonFactor;\n}\n\nexport function fog(distanceToCamera, density) {\n const scalar = distanceToCamera * density;\n return 1.0 - Math.exp(-(scalar * scalar));\n}\n\nexport function getDynamicScreenSpaceError(tileset, distanceToCamera) {\n if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {\n const density = tileset.dynamicScreenSpaceErrorComputedDensity;\n const factor = tileset.dynamicScreenSpaceErrorFactor;\n // TODO: Refined screen space error that minimizes tiles in non-first-person\n const dynamicError = fog(distanceToCamera, density) * factor;\n return dynamicError;\n }\n\n return 0;\n}\n\nexport function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {\n const tileset = tile.tileset;\n const parentLodMetricValue = (tile.parent && tile.parent.lodMetricValue) || tile.lodMetricValue;\n const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;\n\n // Leaf tiles do not have any error so save the computation\n if (lodMetricValue === 0.0) {\n return 0.0;\n }\n\n // TODO: Orthographic Frustum needs special treatment?\n // this._getOrthograhicScreenSpaceError();\n\n // Avoid divide by zero when viewer is inside the tile\n const distance = Math.max(tile._distanceToCamera, 1e-7);\n const {height, sseDenominator} = frameState;\n const {viewDistanceScale} = tileset.options;\n let error = (lodMetricValue * height * (viewDistanceScale || 1.0)) / (distance * sseDenominator);\n\n error -= getDynamicScreenSpaceError(tileset, distance);\n\n return error;\n}\n"],"file":"tiles-3d-lod.js"}
@@ -14,11 +14,17 @@ var _loaderUtils = require("@loaders.gl/loader-utils");
14
14
  function calculateTransformProps(tileHeader, tile) {
15
15
  (0, _loaderUtils.assert)(tileHeader);
16
16
  (0, _loaderUtils.assert)(tile);
17
- var rtcCenter = tile.rtcCenter,
18
- gltfUpAxis = tile.gltfUpAxis;
19
- var computedTransform = tileHeader.computedTransform,
20
- center = tileHeader.boundingVolume.center;
21
- var modelMatrix = new _core.Matrix4(computedTransform);
17
+ const {
18
+ rtcCenter,
19
+ gltfUpAxis
20
+ } = tile;
21
+ const {
22
+ computedTransform,
23
+ boundingVolume: {
24
+ center
25
+ }
26
+ } = tileHeader;
27
+ let modelMatrix = new _core.Matrix4(computedTransform);
22
28
 
23
29
  if (rtcCenter) {
24
30
  modelMatrix.translate(rtcCenter);
@@ -29,12 +35,12 @@ function calculateTransformProps(tileHeader, tile) {
29
35
  break;
30
36
 
31
37
  case 'Y':
32
- var rotationY = new _core.Matrix4().rotateX(Math.PI / 2);
38
+ const rotationY = new _core.Matrix4().rotateX(Math.PI / 2);
33
39
  modelMatrix = modelMatrix.multiplyRight(rotationY);
34
40
  break;
35
41
 
36
42
  case 'X':
37
- var rotationX = new _core.Matrix4().rotateY(-Math.PI / 2);
43
+ const rotationX = new _core.Matrix4().rotateY(-Math.PI / 2);
38
44
  modelMatrix = modelMatrix.multiplyRight(rotationX);
39
45
  break;
40
46
 
@@ -46,17 +52,20 @@ function calculateTransformProps(tileHeader, tile) {
46
52
  modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);
47
53
  }
48
54
 
49
- var cartesianOrigin = new _core.Vector3(center);
55
+ const cartesianOrigin = new _core.Vector3(center);
50
56
  tile.cartesianModelMatrix = modelMatrix;
51
57
  tile.cartesianOrigin = cartesianOrigin;
52
58
 
53
- var cartographicOrigin = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new _core.Vector3());
59
+ const cartographicOrigin = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new _core.Vector3());
54
60
 
55
- var fromFixedFrameMatrix = _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
61
+ const fromFixedFrameMatrix = _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
56
62
 
57
- var toFixedFrameMatrix = fromFixedFrameMatrix.invert();
63
+ const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
58
64
  tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
59
65
  tile.cartographicOrigin = cartographicOrigin;
60
- tile.modelMatrix = tile.cartographicModelMatrix;
66
+
67
+ if (!tile.coordinateSystem) {
68
+ tile.modelMatrix = tile.cartographicModelMatrix;
69
+ }
61
70
  }
62
71
  //# sourceMappingURL=transform-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/tileset/helpers/transform-utils.ts"],"names":["calculateTransformProps","tileHeader","tile","rtcCenter","gltfUpAxis","computedTransform","center","boundingVolume","modelMatrix","Matrix4","translate","rotationY","rotateX","Math","PI","multiplyRight","rotationX","rotateY","isQuantized","quantizedVolumeOffset","scale","quantizedVolumeScale","cartesianOrigin","Vector3","cartesianModelMatrix","cartographicOrigin","Ellipsoid","WGS84","cartesianToCartographic","fromFixedFrameMatrix","eastNorthUpToFixedFrame","toFixedFrameMatrix","invert","cartographicModelMatrix"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEO,SAASA,uBAAT,CAAiCC,UAAjC,EAA6CC,IAA7C,EAAmD;AACxD,2BAAOD,UAAP;AACA,2BAAOC,IAAP;AAEA,MAAOC,SAAP,GAAgCD,IAAhC,CAAOC,SAAP;AAAA,MAAkBC,UAAlB,GAAgCF,IAAhC,CAAkBE,UAAlB;AACA,MACEC,iBADF,GAGIJ,UAHJ,CACEI,iBADF;AAAA,MAEmBC,MAFnB,GAGIL,UAHJ,CAEEM,cAFF,CAEmBD,MAFnB;AAKA,MAAIE,WAAW,GAAG,IAAIC,aAAJ,CAAYJ,iBAAZ,CAAlB;;AAGA,MAAIF,SAAJ,EAAe;AACbK,IAAAA,WAAW,CAACE,SAAZ,CAAsBP,SAAtB;AACD;;AAID,UAAQC,UAAR;AACE,SAAK,GAAL;AACE;;AACF,SAAK,GAAL;AACE,UAAMO,S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assert} from '@loaders.gl/loader-utils';\n\nexport function calculateTransformProps(tileHeader, tile) {\n assert(tileHeader);\n assert(tile);\n\n const {rtcCenter, gltfUpAxis} = tile;\n const {\n computedTransform,\n boundingVolume: {center}\n } = tileHeader;\n\n let modelMatrix = new Matrix4(computedTransform);\n\n // Translate if appropriate\n if (rtcCenter) {\n modelMatrix.translate(rtcCenter);\n }\n\n // glTF models need to be rotated from Y to Z up\n // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up\n switch (gltfUpAxis) {\n case 'Z':\n break;\n case 'Y':\n const rotationY = new Matrix4().rotateX(Math.PI / 2);\n modelMatrix = modelMatrix.multiplyRight(rotationY);\n break;\n case 'X':\n const rotationX = new Matrix4().rotateY(-Math.PI / 2);\n modelMatrix = modelMatrix.multiplyRight(rotationX);\n break;\n default:\n break;\n }\n\n // Scale/offset positions if normalized integers\n if (tile.isQuantized) {\n modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);\n }\n\n // Option 1: Cartesian matrix and origin\n const cartesianOrigin = new Vector3(center);\n\n tile.cartesianModelMatrix = modelMatrix;\n tile.cartesianOrigin = cartesianOrigin;\n\n // Option 2: Cartographic matrix and origin\n const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(\n cartesianOrigin,\n new Vector3()\n );\n const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);\n const toFixedFrameMatrix = fromFixedFrameMatrix.invert();\n\n tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);\n tile.cartographicOrigin = cartographicOrigin;\n\n // Deprecated, drop\n tile.modelMatrix = tile.cartographicModelMatrix;\n}\n"],"file":"transform-utils.js"}
1
+ {"version":3,"sources":["../../../../src/tileset/helpers/transform-utils.ts"],"names":["calculateTransformProps","tileHeader","tile","rtcCenter","gltfUpAxis","computedTransform","boundingVolume","center","modelMatrix","Matrix4","translate","rotationY","rotateX","Math","PI","multiplyRight","rotationX","rotateY","isQuantized","quantizedVolumeOffset","scale","quantizedVolumeScale","cartesianOrigin","Vector3","cartesianModelMatrix","cartographicOrigin","Ellipsoid","WGS84","cartesianToCartographic","fromFixedFrameMatrix","eastNorthUpToFixedFrame","toFixedFrameMatrix","invert","cartographicModelMatrix","coordinateSystem"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEO,SAASA,uBAAT,CAAiCC,UAAjC,EAA6CC,IAA7C,EAAmD;AACxD,2BAAOD,UAAP;AACA,2BAAOC,IAAP;AAEA,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA;AAAZ,MAA0BF,IAAhC;AACA,QAAM;AACJG,IAAAA,iBADI;AAEJC,IAAAA,cAAc,EAAE;AAACC,MAAAA;AAAD;AAFZ,MAGFN,UAHJ;AAKA,MAAIO,WAAW,GAAG,IAAIC,aAAJ,CAAYJ,iBAAZ,CAAlB;;AAGA,MAAIF,SAAJ,EAAe;AACbK,IAAAA,WAAW,CAACE,SAAZ,CAAsBP,SAAtB;AACD;;AAID,UAAQC,UAAR;AACE,SAAK,GAAL;AACE;;AACF,SAAK,GAAL;AACE,YAAMO,SAAS,GAAG,IAAIF,aAAJ,GAAcG,OAAd,CAAsBC,IAAI,CAACC,EAAL,GAAU,CAAhC,CAAlB;AACAN,MAAAA,WAAW,GAAGA,WAAW,CAACO,aAAZ,CAA0BJ,SAA1B,CAAd;AACA;;AACF,SAAK,GAAL;AACE,YAAMK,SAAS,GAAG,IAAIP,aAAJ,GAAcQ,OAAd,CAAsB,CAACJ,IAAI,CAACC,EAAN,GAAW,CAAjC,CAAlB;AACAN,MAAAA,WAAW,GAAGA,WAAW,CAACO,aAAZ,CAA0BC,SAA1B,CAAd;AACA;;AACF;AACE;AAZJ;;AAgBA,MAAId,IAAI,CAACgB,WAAT,EAAsB;AACpBV,IAAAA,WAAW,CAACE,SAAZ,CAAsBR,IAAI,CAACiB,qBAA3B,EAAkDC,KAAlD,CAAwDlB,IAAI,CAACmB,oBAA7D;AACD;;AAGD,QAAMC,eAAe,GAAG,IAAIC,aAAJ,CAAYhB,MAAZ,CAAxB;AAEAL,EAAAA,IAAI,CAACsB,oBAAL,GAA4BhB,WAA5B;AACAN,EAAAA,IAAI,CAACoB,eAAL,GAAuBA,eAAvB;;AAGA,QAAMG,kBAAkB,GAAGC,sBAAUC,KAAV,CAAgBC,uBAAhB,CACzBN,eADyB,EAEzB,IAAIC,aAAJ,EAFyB,CAA3B;;AAIA,QAAMM,oBAAoB,GAAGH,sBAAUC,KAAV,CAAgBG,uBAAhB,CAAwCR,eAAxC,CAA7B;;AACA,QAAMS,kBAAkB,GAAGF,oBAAoB,CAACG,MAArB,EAA3B;AAEA9B,EAAAA,IAAI,CAAC+B,uBAAL,GAA+BF,kBAAkB,CAAChB,aAAnB,CAAiCP,WAAjC,CAA/B;AACAN,EAAAA,IAAI,CAACuB,kBAAL,GAA0BA,kBAA1B;;AAGA,MAAI,CAACvB,IAAI,CAACgC,gBAAV,EAA4B;AAC1BhC,IAAAA,IAAI,CAACM,WAAL,GAAmBN,IAAI,CAAC+B,uBAAxB;AACD;AACF","sourcesContent":["import {Ellipsoid} from '@math.gl/geospatial';\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {assert} from '@loaders.gl/loader-utils';\n\nexport function calculateTransformProps(tileHeader, tile) {\n assert(tileHeader);\n assert(tile);\n\n const {rtcCenter, gltfUpAxis} = tile;\n const {\n computedTransform,\n boundingVolume: {center}\n } = tileHeader;\n\n let modelMatrix = new Matrix4(computedTransform);\n\n // Translate if appropriate\n if (rtcCenter) {\n modelMatrix.translate(rtcCenter);\n }\n\n // glTF models need to be rotated from Y to Z up\n // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up\n switch (gltfUpAxis) {\n case 'Z':\n break;\n case 'Y':\n const rotationY = new Matrix4().rotateX(Math.PI / 2);\n modelMatrix = modelMatrix.multiplyRight(rotationY);\n break;\n case 'X':\n const rotationX = new Matrix4().rotateY(-Math.PI / 2);\n modelMatrix = modelMatrix.multiplyRight(rotationX);\n break;\n default:\n break;\n }\n\n // Scale/offset positions if normalized integers\n if (tile.isQuantized) {\n modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);\n }\n\n // Option 1: Cartesian matrix and origin\n const cartesianOrigin = new Vector3(center);\n\n tile.cartesianModelMatrix = modelMatrix;\n tile.cartesianOrigin = cartesianOrigin;\n\n // Option 2: Cartographic matrix and origin\n const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(\n cartesianOrigin,\n new Vector3()\n );\n const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);\n const toFixedFrameMatrix = fromFixedFrameMatrix.invert();\n\n tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);\n tile.cartographicOrigin = cartographicOrigin;\n\n // Deprecated, drop\n if (!tile.coordinateSystem) {\n tile.modelMatrix = tile.cartographicModelMatrix;\n }\n}\n"],"file":"transform-utils.js"}
@@ -7,25 +7,27 @@ exports.getZoomFromBoundingVolume = getZoomFromBoundingVolume;
7
7
 
8
8
  var _core = require("@math.gl/core");
9
9
 
10
- var WGS84_RADIUS_X = 6378137.0;
11
- var WGS84_RADIUS_Y = 6378137.0;
12
- var WGS84_RADIUS_Z = 6356752.3142451793;
13
- var scratchVector = new _core.Vector3();
10
+ const WGS84_RADIUS_X = 6378137.0;
11
+ const WGS84_RADIUS_Y = 6378137.0;
12
+ const WGS84_RADIUS_Z = 6356752.3142451793;
13
+ const scratchVector = new _core.Vector3();
14
14
 
15
15
  function getZoomFromBoundingVolume(boundingVolume) {
16
- var halfAxes = boundingVolume.halfAxes,
17
- radius = boundingVolume.radius,
18
- width = boundingVolume.width,
19
- height = boundingVolume.height;
16
+ const {
17
+ halfAxes,
18
+ radius,
19
+ width,
20
+ height
21
+ } = boundingVolume;
20
22
 
21
23
  if (halfAxes) {
22
- var obbSize = getObbSize(halfAxes);
24
+ const obbSize = getObbSize(halfAxes);
23
25
  return Math.log2(WGS84_RADIUS_Z / obbSize);
24
26
  } else if (radius) {
25
27
  return Math.log2(WGS84_RADIUS_Z / radius);
26
28
  } else if (height && width) {
27
- var zoomX = Math.log2(WGS84_RADIUS_X / width);
28
- var zoomY = Math.log2(WGS84_RADIUS_Y / height);
29
+ const zoomX = Math.log2(WGS84_RADIUS_X / width);
30
+ const zoomY = Math.log2(WGS84_RADIUS_Y / height);
29
31
  return (zoomX + zoomY) / 2;
30
32
  }
31
33
 
@@ -34,10 +36,10 @@ function getZoomFromBoundingVolume(boundingVolume) {
34
36
 
35
37
  function getObbSize(halfAxes) {
36
38
  halfAxes.getColumn(0, scratchVector);
37
- var axeY = halfAxes.getColumn(1);
38
- var axeZ = halfAxes.getColumn(2);
39
- var farthestVertex = scratchVector.add(axeY).add(axeZ);
40
- var size = farthestVertex.len();
39
+ const axeY = halfAxes.getColumn(1);
40
+ const axeZ = halfAxes.getColumn(2);
41
+ const farthestVertex = scratchVector.add(axeY).add(axeZ);
42
+ const size = farthestVertex.len();
41
43
  return size;
42
44
  }
43
45
  //# sourceMappingURL=zoom.js.map