@loaders.gl/tiles 3.1.3 → 4.0.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 (122) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/constants.js +26 -29
  4. package/dist/constants.js.map +1 -0
  5. package/dist/dist.min.js +45 -264
  6. package/dist/index.js +10 -28
  7. package/dist/index.js.map +1 -0
  8. package/dist/tileset/helpers/3d-tiles-options.js +5 -8
  9. package/dist/tileset/helpers/3d-tiles-options.js.map +1 -0
  10. package/dist/tileset/helpers/bounding-volume.js +70 -159
  11. package/dist/tileset/helpers/bounding-volume.js.map +1 -0
  12. package/dist/tileset/helpers/frame-state.js +48 -67
  13. package/dist/tileset/helpers/frame-state.js.map +1 -0
  14. package/dist/tileset/helpers/i3s-lod.js +64 -80
  15. package/dist/tileset/helpers/i3s-lod.js.map +1 -0
  16. package/dist/tileset/helpers/tiles-3d-lod.js +100 -111
  17. package/dist/tileset/helpers/tiles-3d-lod.js.map +1 -0
  18. package/dist/tileset/helpers/transform-utils.js +56 -50
  19. package/dist/tileset/helpers/transform-utils.js.map +1 -0
  20. package/dist/tileset/helpers/zoom.js +30 -36
  21. package/dist/tileset/helpers/zoom.js.map +1 -0
  22. package/dist/tileset/tile-3d.js +533 -551
  23. package/dist/tileset/tile-3d.js.map +1 -0
  24. package/dist/tileset/tileset-3d.js +649 -576
  25. package/dist/tileset/tileset-3d.js.map +1 -0
  26. package/dist/tileset/tileset-cache.js +71 -71
  27. package/dist/tileset/tileset-cache.js.map +1 -0
  28. package/dist/tileset/traversers/i3s-tile-manager.js +40 -31
  29. package/dist/tileset/traversers/i3s-tile-manager.js.map +1 -0
  30. package/dist/tileset/traversers/i3s-tileset-traverser.js +76 -81
  31. package/dist/tileset/traversers/i3s-tileset-traverser.js.map +1 -0
  32. package/dist/tileset/traversers/tileset-3d-traverser.js +49 -51
  33. package/dist/tileset/traversers/tileset-3d-traverser.js.map +1 -0
  34. package/dist/tileset/traversers/tileset-traverser.js +276 -274
  35. package/dist/tileset/traversers/tileset-traverser.js.map +1 -0
  36. package/dist/utils/doubly-linked-list-node.js +15 -16
  37. package/dist/utils/doubly-linked-list-node.js.map +1 -0
  38. package/dist/utils/doubly-linked-list.js +75 -94
  39. package/dist/utils/doubly-linked-list.js.map +1 -0
  40. package/dist/utils/managed-array.js +109 -143
  41. package/dist/utils/managed-array.js.map +1 -0
  42. package/package.json +7 -7
  43. package/dist/es5/bundle.js +0 -7
  44. package/dist/es5/bundle.js.map +0 -1
  45. package/dist/es5/constants.js +0 -44
  46. package/dist/es5/constants.js.map +0 -1
  47. package/dist/es5/index.js +0 -104
  48. package/dist/es5/index.js.map +0 -1
  49. package/dist/es5/tileset/helpers/3d-tiles-options.js +0 -13
  50. package/dist/es5/tileset/helpers/3d-tiles-options.js.map +0 -1
  51. package/dist/es5/tileset/helpers/bounding-volume.js +0 -114
  52. package/dist/es5/tileset/helpers/bounding-volume.js.map +0 -1
  53. package/dist/es5/tileset/helpers/frame-state.js +0 -65
  54. package/dist/es5/tileset/helpers/frame-state.js.map +0 -1
  55. package/dist/es5/tileset/helpers/i3s-lod.js +0 -86
  56. package/dist/es5/tileset/helpers/i3s-lod.js.map +0 -1
  57. package/dist/es5/tileset/helpers/tiles-3d-lod.js +0 -119
  58. package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +0 -1
  59. package/dist/es5/tileset/helpers/transform-utils.js +0 -65
  60. package/dist/es5/tileset/helpers/transform-utils.js.map +0 -1
  61. package/dist/es5/tileset/helpers/zoom.js +0 -43
  62. package/dist/es5/tileset/helpers/zoom.js.map +0 -1
  63. package/dist/es5/tileset/tile-3d.js +0 -605
  64. package/dist/es5/tileset/tile-3d.js.map +0 -1
  65. package/dist/es5/tileset/tileset-3d.js +0 -838
  66. package/dist/es5/tileset/tileset-3d.js.map +0 -1
  67. package/dist/es5/tileset/tileset-cache.js +0 -101
  68. package/dist/es5/tileset/tileset-cache.js.map +0 -1
  69. package/dist/es5/tileset/traversers/i3s-tile-manager.js +0 -69
  70. package/dist/es5/tileset/traversers/i3s-tile-manager.js.map +0 -1
  71. package/dist/es5/tileset/traversers/i3s-tileset-traverser.js +0 -185
  72. package/dist/es5/tileset/traversers/i3s-tileset-traverser.js.map +0 -1
  73. package/dist/es5/tileset/traversers/tileset-3d-traverser.js +0 -94
  74. package/dist/es5/tileset/traversers/tileset-3d-traverser.js.map +0 -1
  75. package/dist/es5/tileset/traversers/tileset-traverser.js +0 -377
  76. package/dist/es5/tileset/traversers/tileset-traverser.js.map +0 -1
  77. package/dist/es5/utils/doubly-linked-list-node.js +0 -25
  78. package/dist/es5/utils/doubly-linked-list-node.js.map +0 -1
  79. package/dist/es5/utils/doubly-linked-list.js +0 -104
  80. package/dist/es5/utils/doubly-linked-list.js.map +0 -1
  81. package/dist/es5/utils/managed-array.js +0 -147
  82. package/dist/es5/utils/managed-array.js.map +0 -1
  83. package/dist/esm/bundle.js +0 -5
  84. package/dist/esm/bundle.js.map +0 -1
  85. package/dist/esm/constants.js +0 -32
  86. package/dist/esm/constants.js.map +0 -1
  87. package/dist/esm/index.js +0 -10
  88. package/dist/esm/index.js.map +0 -1
  89. package/dist/esm/tileset/helpers/3d-tiles-options.js +0 -6
  90. package/dist/esm/tileset/helpers/3d-tiles-options.js.map +0 -1
  91. package/dist/esm/tileset/helpers/bounding-volume.js +0 -88
  92. package/dist/esm/tileset/helpers/bounding-volume.js.map +0 -1
  93. package/dist/esm/tileset/helpers/frame-state.js +0 -51
  94. package/dist/esm/tileset/helpers/frame-state.js.map +0 -1
  95. package/dist/esm/tileset/helpers/i3s-lod.js +0 -67
  96. package/dist/esm/tileset/helpers/i3s-lod.js.map +0 -1
  97. package/dist/esm/tileset/helpers/tiles-3d-lod.js +0 -105
  98. package/dist/esm/tileset/helpers/tiles-3d-lod.js.map +0 -1
  99. package/dist/esm/tileset/helpers/transform-utils.js +0 -58
  100. package/dist/esm/tileset/helpers/transform-utils.js.map +0 -1
  101. package/dist/esm/tileset/helpers/zoom.js +0 -36
  102. package/dist/esm/tileset/helpers/zoom.js.map +0 -1
  103. package/dist/esm/tileset/tile-3d.js +0 -537
  104. package/dist/esm/tileset/tile-3d.js.map +0 -1
  105. package/dist/esm/tileset/tileset-3d.js +0 -674
  106. package/dist/esm/tileset/tileset-3d.js.map +0 -1
  107. package/dist/esm/tileset/tileset-cache.js +0 -79
  108. package/dist/esm/tileset/tileset-cache.js.map +0 -1
  109. package/dist/esm/tileset/traversers/i3s-tile-manager.js +0 -45
  110. package/dist/esm/tileset/traversers/i3s-tile-manager.js.map +0 -1
  111. package/dist/esm/tileset/traversers/i3s-tileset-traverser.js +0 -80
  112. package/dist/esm/tileset/traversers/i3s-tileset-traverser.js.map +0 -1
  113. package/dist/esm/tileset/traversers/tileset-3d-traverser.js +0 -53
  114. package/dist/esm/tileset/traversers/tileset-3d-traverser.js.map +0 -1
  115. package/dist/esm/tileset/traversers/tileset-traverser.js +0 -296
  116. package/dist/esm/tileset/traversers/tileset-traverser.js.map +0 -1
  117. package/dist/esm/utils/doubly-linked-list-node.js +0 -16
  118. package/dist/esm/utils/doubly-linked-list-node.js.map +0 -1
  119. package/dist/esm/utils/doubly-linked-list.js +0 -81
  120. package/dist/esm/utils/doubly-linked-list.js.map +0 -1
  121. package/dist/esm/utils/managed-array.js +0 -117
  122. package/dist/esm/utils/managed-array.js.map +0 -1
@@ -1,177 +1,88 @@
1
- "use strict";
2
- // This file is derived from the Cesium code base under Apache 2 license
3
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createBoundingVolume = void 0;
6
- /* eslint-disable */
7
- const core_1 = require("@math.gl/core");
8
- const culling_1 = require("@math.gl/culling");
9
- const geospatial_1 = require("@math.gl/geospatial");
10
- const loader_utils_1 = require("@loaders.gl/loader-utils");
11
- // const scratchProjectedBoundingSphere = new BoundingSphere();
1
+ import { Quaternion, Vector3, Matrix3, Matrix4, degrees } from '@math.gl/core';
2
+ import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
3
+ import { Ellipsoid } from '@math.gl/geospatial';
4
+ import { assert } from '@loaders.gl/loader-utils';
5
+
12
6
  function defined(x) {
13
- return x !== undefined && x !== null;
14
- }
15
- // const scratchMatrix = new Matrix3();
16
- const scratchScale = new core_1.Vector3();
17
- const scratchNorthWest = new core_1.Vector3();
18
- const scratchSouthEast = new core_1.Vector3();
19
- // const scratchRectangle = new Rectangle();
20
- // const scratchOrientedBoundingBox = new OrientedBoundingBox();
21
- // const scratchTransform = new Matrix4();
22
- /**
23
- * Create a bounding volume from the tile's bounding volume header.
24
- * @param {Object} boundingVolumeHeader The tile's bounding volume header.
25
- * @param {Matrix4} transform The transform to apply to the bounding volume.
26
- * @param [result] The object onto which to store the result.
27
- * @returns The modified result parameter or a new TileBoundingVolume instance if none was provided.
28
- */
29
- function createBoundingVolume(boundingVolumeHeader, transform, result) {
30
- (0, loader_utils_1.assert)(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
31
- // boundingVolume schema:
32
- // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json
33
- if (boundingVolumeHeader.box) {
34
- return createBox(boundingVolumeHeader.box, transform, result);
35
- }
36
- if (boundingVolumeHeader.region) {
37
- // [west, south, east, north, minimum height, maximum height]
38
- // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.
39
- // Heights are in meters above (or below) the WGS 84 ellipsoid.
40
- const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
41
- const northWest = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian([(0, core_1.degrees)(west), (0, core_1.degrees)(north), minHeight], scratchNorthWest);
42
- const southEast = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian([(0, core_1.degrees)(east), (0, core_1.degrees)(south), maxHeight], scratchSouthEast);
43
- const centerInCartesian = new core_1.Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);
44
- const radius = new core_1.Vector3().subVectors(northWest, southEast).len() / 2.0;
45
- // TODO improve region boundingVolume
46
- // for now, create a sphere as the boundingVolume instead of box
47
- return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new core_1.Matrix4());
48
- }
49
- if (boundingVolumeHeader.sphere) {
50
- return createSphere(boundingVolumeHeader.sphere, transform, result);
51
- }
52
- throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
7
+ return x !== undefined && x !== null;
53
8
  }
54
- exports.createBoundingVolume = createBoundingVolume;
55
- function createBox(box, transform, result) {
56
- // https://math.gl/modules/culling/docs/api-reference/oriented-bounding-box
57
- // 1. A half-axes based representation.
58
- // box: An array of 12 numbers that define an oriented bounding box.
59
- // The first three elements define the x, y, and z values for the center of the box.
60
- // The next three elements (with indices 3, 4, and 5) define the x axis direction and half-length.
61
- // The next three elements (indices 6, 7, and 8) define the y axis direction and half-length.
62
- // The last three elements (indices 9, 10, and 11) define the z axis direction and half-length.
63
- // 2. A half-size-quaternion based representation.
64
- // box: An array of 10 numbers that define an oriented bounding box.
65
- // The first three elements define the x, y, and z values for the center of the box in a right-handed 3-axis (x, y, z) Cartesian coordinate system where the z-axis is up.
66
- // The next three elements (with indices 3, 4, and 5) define the halfSize.
67
- // The last four elements (indices 6, 7, 8 and 10) define the quaternion.
68
- const center = new core_1.Vector3(box[0], box[1], box[2]);
69
- transform.transform(center, center);
70
- let origin = [];
71
- if (box.length === 10) {
72
- const halfSize = box.slice(3, 6);
73
- const quaternion = new core_1.Quaternion();
74
- quaternion.fromArray(box, 6);
75
- const x = new core_1.Vector3([1, 0, 0]);
76
- const y = new core_1.Vector3([0, 1, 0]);
77
- const z = new core_1.Vector3([0, 0, 1]);
78
- x.transformByQuaternion(quaternion);
79
- x.scale(halfSize[0]);
80
- y.transformByQuaternion(quaternion);
81
- y.scale(halfSize[1]);
82
- z.transformByQuaternion(quaternion);
83
- z.scale(halfSize[2]);
84
- origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];
85
- }
86
- else {
87
- origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];
88
- }
89
- const xAxis = transform.transformAsVector(origin.slice(0, 3));
90
- const yAxis = transform.transformAsVector(origin.slice(3, 6));
91
- const zAxis = transform.transformAsVector(origin.slice(6, 9));
92
- const halfAxes = new core_1.Matrix3([
93
- xAxis[0],
94
- xAxis[1],
95
- xAxis[2],
96
- yAxis[0],
97
- yAxis[1],
98
- yAxis[2],
99
- zAxis[0],
100
- zAxis[1],
101
- zAxis[2]
102
- ]);
103
- if (defined(result)) {
104
- result.center = center;
105
- result.halfAxes = halfAxes;
106
- return result;
107
- }
108
- return new culling_1.OrientedBoundingBox(center, halfAxes);
109
- }
110
- /*
111
- function createBoxFromTransformedRegion(region, transform, initialTransform, result) {
112
- const rectangle = Rectangle.unpack(region, 0, scratchRectangle);
113
- const minimumHeight = region[4];
114
- const maximumHeight = region[5];
115
9
 
116
- const orientedBoundingBox = OrientedBoundingBox.fromRectangle(
117
- rectangle,
118
- minimumHeight,
119
- maximumHeight,
120
- Ellipsoid.WGS84,
121
- scratchOrientedBoundingBox
122
- );
123
- const center = orientedBoundingBox.center;
124
- const halfAxes = orientedBoundingBox.halfAxes;
10
+ const scratchScale = new Vector3();
11
+ const scratchNorthWest = new Vector3();
12
+ const scratchSouthEast = new Vector3();
13
+ export function createBoundingVolume(boundingVolumeHeader, transform, result) {
14
+ assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
125
15
 
126
- // A region bounding volume is not transformed by the transform in the tileset JSON,
127
- // but may be transformed by additional transforms applied in Cesium.
128
- // This is why the transform is calculated as the difference between the initial transform and the current transform.
129
- transform = Matrix4.multiplyTransformation(
130
- transform,
131
- Matrix4.inverseTransformation(initialTransform, scratchTransform),
132
- scratchTransform
133
- );
134
- center = Matrix4.multiplyByPoint(transform, center, center);
135
- const rotationScale = Matrix4.getRotation(transform, scratchMatrix);
136
- halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
16
+ if (boundingVolumeHeader.box) {
17
+ return createBox(boundingVolumeHeader.box, transform, result);
18
+ }
137
19
 
138
- if (defined(result) && result instanceof TileOrientedBoundingBox) {
139
- result.update(center, halfAxes);
140
- return result;
20
+ if (boundingVolumeHeader.region) {
21
+ const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
22
+ const northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest);
23
+ const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast);
24
+ const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);
25
+ const radius = new Vector3().subVectors(northWest, southEast).len() / 2.0;
26
+ return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new Matrix4());
27
+ }
28
+
29
+ if (boundingVolumeHeader.sphere) {
30
+ return createSphere(boundingVolumeHeader.sphere, transform, result);
141
31
  }
142
32
 
143
- return new TileOrientedBoundingBox(center, halfAxes);
33
+ throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
144
34
  }
145
35
 
146
- function createRegion(region, transform, initialTransform, result) {
147
- if (!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)) {
148
- return createBoxFromTransformedRegion(region, transform, initialTransform, result);
36
+ function createBox(box, transform, result) {
37
+ const center = new Vector3(box[0], box[1], box[2]);
38
+ transform.transform(center, center);
39
+ let origin = [];
40
+
41
+ if (box.length === 10) {
42
+ const halfSize = box.slice(3, 6);
43
+ const quaternion = new Quaternion();
44
+ quaternion.fromArray(box, 6);
45
+ const x = new Vector3([1, 0, 0]);
46
+ const y = new Vector3([0, 1, 0]);
47
+ const z = new Vector3([0, 0, 1]);
48
+ x.transformByQuaternion(quaternion);
49
+ x.scale(halfSize[0]);
50
+ y.transformByQuaternion(quaternion);
51
+ y.scale(halfSize[1]);
52
+ z.transformByQuaternion(quaternion);
53
+ z.scale(halfSize[2]);
54
+ origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];
55
+ } else {
56
+ origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];
149
57
  }
150
58
 
59
+ const xAxis = transform.transformAsVector(origin.slice(0, 3));
60
+ const yAxis = transform.transformAsVector(origin.slice(3, 6));
61
+ const zAxis = transform.transformAsVector(origin.slice(6, 9));
62
+ const halfAxes = new Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]);
63
+
151
64
  if (defined(result)) {
65
+ result.center = center;
66
+ result.halfAxes = halfAxes;
152
67
  return result;
153
68
  }
154
69
 
155
- const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);
156
-
157
- return new TileBoundingRegion({
158
- rectangle: rectangleRegion,
159
- minimumHeight: region[4],
160
- maximumHeight: region[5]
161
- });
70
+ return new OrientedBoundingBox(center, halfAxes);
162
71
  }
163
- */
72
+
164
73
  function createSphere(sphere, transform, result) {
165
- // Find the transformed center
166
- const center = new core_1.Vector3(sphere[0], sphere[1], sphere[2]);
167
- transform.transform(center, center);
168
- const scale = transform.getScale(scratchScale);
169
- const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);
170
- const radius = sphere[3] * uniformScale;
171
- if (defined(result)) {
172
- result.center = center;
173
- result.radius = radius;
174
- return result;
175
- }
176
- return new culling_1.BoundingSphere(center, radius);
74
+ const center = new Vector3(sphere[0], sphere[1], sphere[2]);
75
+ transform.transform(center, center);
76
+ const scale = transform.getScale(scratchScale);
77
+ const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);
78
+ const radius = sphere[3] * uniformScale;
79
+
80
+ if (defined(result)) {
81
+ result.center = center;
82
+ result.radius = radius;
83
+ return result;
84
+ }
85
+
86
+ return new BoundingSphere(center, radius);
177
87
  }
88
+ //# sourceMappingURL=bounding-volume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/tileset/helpers/bounding-volume.ts"],"names":["Quaternion","Vector3","Matrix3","Matrix4","degrees","BoundingSphere","OrientedBoundingBox","Ellipsoid","assert","defined","x","undefined","scratchScale","scratchNorthWest","scratchSouthEast","createBoundingVolume","boundingVolumeHeader","transform","result","box","createBox","region","west","south","east","north","minHeight","maxHeight","northWest","WGS84","cartographicToCartesian","southEast","centerInCartesian","addVectors","multiplyScalar","radius","subVectors","len","createSphere","sphere","Error","center","origin","length","halfSize","slice","quaternion","fromArray","y","z","transformByQuaternion","scale","toArray","xAxis","transformAsVector","yAxis","zAxis","halfAxes","getScale","uniformScale","Math","max"],"mappings":"AAIA,SAAQA,UAAR,EAAoBC,OAApB,EAA6BC,OAA7B,EAAsCC,OAAtC,EAA+CC,OAA/C,QAA6D,eAA7D;AACA,SAAQC,cAAR,EAAwBC,mBAAxB,QAAkD,kBAAlD;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SAAQC,MAAR,QAAqB,0BAArB;;AAIA,SAASC,OAAT,CAAiBC,CAAjB,EAAoB;AAClB,SAAOA,CAAC,KAAKC,SAAN,IAAmBD,CAAC,KAAK,IAAhC;AACD;;AAGD,MAAME,YAAY,GAAG,IAAIX,OAAJ,EAArB;AACA,MAAMY,gBAAgB,GAAG,IAAIZ,OAAJ,EAAzB;AACA,MAAMa,gBAAgB,GAAG,IAAIb,OAAJ,EAAzB;AAYA,OAAO,SAASc,oBAAT,CAA8BC,oBAA9B,EAAoDC,SAApD,EAA+DC,MAA/D,EAAuE;AAC5EV,EAAAA,MAAM,CAACQ,oBAAD,EAAuB,yCAAvB,CAAN;;AAIA,MAAIA,oBAAoB,CAACG,GAAzB,EAA8B;AAC5B,WAAOC,SAAS,CAACJ,oBAAoB,CAACG,GAAtB,EAA2BF,SAA3B,EAAsCC,MAAtC,CAAhB;AACD;;AACD,MAAIF,oBAAoB,CAACK,MAAzB,EAAiC;AAI/B,UAAM,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C,MAAtB,EAA8BtB,SAA9B,EAAyCC,MAAzC,EAAkD;AAEhD,QAAMuB,MAAM,GAAG,IAAIxC,OAAJ,CAAYsC,MAAM,CAAC,CAAD,CAAlB,EAAuBA,MAAM,CAAC,CAAD,CAA7B,EAAkCA,MAAM,CAAC,CAAD,CAAxC,CAAf;AACAtB,EAAAA,SAAS,CAACA,SAAV,CAAoBwB,MAApB,EAA4BA,MAA5B;AACA,QAAMU,KAAK,GAAGlC,SAAS,CAACyC,QAAV,CAAmB9C,YAAnB,CAAd;AAEA,QAAM+C,YAAY,GAAGC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACC,GAAL,CAASV,KAAK,CAAC,CAAD,CAAd,EAAmBA,KAAK,CAAC,CAAD,CAAxB,CAAT,EAAuCA,KAAK,CAAC,CAAD,CAA5C,CAArB;AACA,QAAMhB,MAAM,GAAGI,MAAM,CAAC,CAAD,CAAN,GAAYoB,YAA3B;;AAEA,MAAIlD,OAAO,CAACS,MAAD,CAAX,EAAqB;AACnBA,IAAAA,MAAM,CAACuB,MAAP,GAAgBA,MAAhB;AACAvB,IAAAA,MAAM,CAACiB,MAAP,GAAgBA,MAAhB;AACA,WAAOjB,MAAP;AACD;;AAED,SAAO,IAAIb,cAAJ,CAAmBoC,MAAnB,EAA2BN,MAA3B,CAAP;AACD","sourcesContent":["// This file is derived from the Cesium code base under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Quaternion, Vector3, Matrix3, Matrix4, degrees} from '@math.gl/core';\nimport {BoundingSphere, OrientedBoundingBox} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {assert} from '@loaders.gl/loader-utils';\n\n// const scratchProjectedBoundingSphere = new BoundingSphere();\n\nfunction defined(x) {\n return x !== undefined && x !== null;\n}\n\n// const scratchMatrix = new Matrix3();\nconst scratchScale = new Vector3();\nconst scratchNorthWest = new Vector3();\nconst scratchSouthEast = new Vector3();\n// const scratchRectangle = new Rectangle();\n// const scratchOrientedBoundingBox = new OrientedBoundingBox();\n// const scratchTransform = new Matrix4();\n\n/**\n * Create a bounding volume from the tile's bounding volume header.\n * @param {Object} boundingVolumeHeader The tile's bounding volume header.\n * @param {Matrix4} transform The transform to apply to the bounding volume.\n * @param [result] The object onto which to store the result.\n * @returns The modified result parameter or a new TileBoundingVolume instance if none was provided.\n */\nexport function createBoundingVolume(boundingVolumeHeader, transform, result) {\n assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');\n\n // boundingVolume schema:\n // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json\n if (boundingVolumeHeader.box) {\n return createBox(boundingVolumeHeader.box, transform, result);\n }\n if (boundingVolumeHeader.region) {\n // [west, south, east, north, minimum height, maximum height]\n // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.\n // Heights are in meters above (or below) the WGS 84 ellipsoid.\n const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;\n\n const northWest = Ellipsoid.WGS84.cartographicToCartesian(\n [degrees(west), degrees(north), minHeight],\n scratchNorthWest\n );\n const southEast = Ellipsoid.WGS84.cartographicToCartesian(\n [degrees(east), degrees(south), maxHeight],\n scratchSouthEast\n );\n const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);\n const radius = new Vector3().subVectors(northWest, southEast).len() / 2.0;\n\n // TODO improve region boundingVolume\n // for now, create a sphere as the boundingVolume instead of box\n return createSphere(\n [centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius],\n new Matrix4()\n );\n }\n\n if (boundingVolumeHeader.sphere) {\n return createSphere(boundingVolumeHeader.sphere, transform, result);\n }\n\n throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');\n}\n\nfunction createBox(box, transform, result) {\n // https://math.gl/modules/culling/docs/api-reference/oriented-bounding-box\n // 1. A half-axes based representation.\n // box: An array of 12 numbers that define an oriented bounding box.\n // The first three elements define the x, y, and z values for the center of the box.\n // The next three elements (with indices 3, 4, and 5) define the x axis direction and half-length.\n // The next three elements (indices 6, 7, and 8) define the y axis direction and half-length.\n // The last three elements (indices 9, 10, and 11) define the z axis direction and half-length.\n // 2. A half-size-quaternion based representation.\n // box: An array of 10 numbers that define an oriented bounding box.\n // The first three elements define the x, y, and z values for the center of the box in a right-handed 3-axis (x, y, z) Cartesian coordinate system where the z-axis is up.\n // The next three elements (with indices 3, 4, and 5) define the halfSize.\n // The last four elements (indices 6, 7, 8 and 10) define the quaternion.\n const center = new Vector3(box[0], box[1], box[2]);\n transform.transform(center, center);\n let origin: number[] = [];\n if (box.length === 10) {\n const halfSize = box.slice(3, 6);\n const quaternion = new Quaternion();\n quaternion.fromArray(box, 6);\n const x = new Vector3([1, 0, 0]);\n const y = new Vector3([0, 1, 0]);\n const z = new Vector3([0, 0, 1]);\n x.transformByQuaternion(quaternion);\n x.scale(halfSize[0]);\n y.transformByQuaternion(quaternion);\n y.scale(halfSize[1]);\n z.transformByQuaternion(quaternion);\n z.scale(halfSize[2]);\n origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];\n } else {\n origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];\n }\n const xAxis = transform.transformAsVector(origin.slice(0, 3));\n const yAxis = transform.transformAsVector(origin.slice(3, 6));\n const zAxis = transform.transformAsVector(origin.slice(6, 9));\n const halfAxes = new Matrix3([\n xAxis[0],\n xAxis[1],\n xAxis[2],\n yAxis[0],\n yAxis[1],\n yAxis[2],\n zAxis[0],\n zAxis[1],\n zAxis[2]\n ]);\n\n if (defined(result)) {\n result.center = center;\n result.halfAxes = halfAxes;\n return result;\n }\n\n return new OrientedBoundingBox(center, halfAxes);\n}\n\n/*\nfunction createBoxFromTransformedRegion(region, transform, initialTransform, result) {\n const rectangle = Rectangle.unpack(region, 0, scratchRectangle);\n const minimumHeight = region[4];\n const maximumHeight = region[5];\n\n const orientedBoundingBox = OrientedBoundingBox.fromRectangle(\n rectangle,\n minimumHeight,\n maximumHeight,\n Ellipsoid.WGS84,\n scratchOrientedBoundingBox\n );\n const center = orientedBoundingBox.center;\n const halfAxes = orientedBoundingBox.halfAxes;\n\n // A region bounding volume is not transformed by the transform in the tileset JSON,\n // but may be transformed by additional transforms applied in Cesium.\n // This is why the transform is calculated as the difference between the initial transform and the current transform.\n transform = Matrix4.multiplyTransformation(\n transform,\n Matrix4.inverseTransformation(initialTransform, scratchTransform),\n scratchTransform\n );\n center = Matrix4.multiplyByPoint(transform, center, center);\n const rotationScale = Matrix4.getRotation(transform, scratchMatrix);\n halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);\n\n if (defined(result) && result instanceof TileOrientedBoundingBox) {\n result.update(center, halfAxes);\n return result;\n }\n\n return new TileOrientedBoundingBox(center, halfAxes);\n}\n\nfunction createRegion(region, transform, initialTransform, result) {\n if (!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)) {\n return createBoxFromTransformedRegion(region, transform, initialTransform, result);\n }\n\n if (defined(result)) {\n return result;\n }\n\n const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);\n\n return new TileBoundingRegion({\n rectangle: rectangleRegion,\n minimumHeight: region[4],\n maximumHeight: region[5]\n });\n}\n*/\n\nfunction createSphere(sphere, transform, result?) {\n // Find the transformed center\n const center = new Vector3(sphere[0], sphere[1], sphere[2]);\n transform.transform(center, center);\n const scale = transform.getScale(scratchScale);\n\n const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);\n const radius = sphere[3] * uniformScale;\n\n if (defined(result)) {\n result.center = center;\n result.radius = radius;\n return result;\n }\n\n return new BoundingSphere(center, radius);\n}\n"],"file":"bounding-volume.js"}
@@ -1,70 +1,51 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFrameState = void 0;
4
- const core_1 = require("@math.gl/core");
5
- const culling_1 = require("@math.gl/culling");
6
- const geospatial_1 = require("@math.gl/geospatial");
7
- const scratchVector = new core_1.Vector3();
8
- const scratchPosition = new core_1.Vector3();
9
- const cullingVolume = new culling_1.CullingVolume([
10
- new culling_1.Plane(),
11
- new culling_1.Plane(),
12
- new culling_1.Plane(),
13
- new culling_1.Plane(),
14
- new culling_1.Plane(),
15
- new culling_1.Plane()
16
- ]);
17
- // Extracts a frame state appropriate for tile culling from a deck.gl viewport
18
- // TODO - this could likely be generalized and merged back into deck.gl for other culling scenarios
19
- function getFrameState(viewport, frameNumber) {
20
- // Traverse and and request. Update _selectedTiles so that we know what to render.
21
- const { cameraDirection, cameraUp, height } = viewport;
22
- const { metersPerUnit } = viewport.distanceScales;
23
- const viewportCenterCartographic = viewport.unprojectPosition(viewport.center);
24
- // TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.
25
- // TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?
26
- const viewportCenterCartesian = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new core_1.Vector3());
27
- const enuToFixedTransform = geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
28
- const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
29
- const cameraPositionCartesian = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new core_1.Vector3());
30
- // These should still be normalized as the transform has scale 1 (goes from meters to meters)
31
- const cameraDirectionCartesian = new core_1.Vector3(
32
- // @ts-ignore
33
- enuToFixedTransform.transformAsVector(new core_1.Vector3(cameraDirection).scale(metersPerUnit))).normalize();
34
- const cameraUpCartesian = new core_1.Vector3(
35
- // @ts-ignore
36
- enuToFixedTransform.transformAsVector(new core_1.Vector3(cameraUp).scale(metersPerUnit))).normalize();
37
- commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);
38
- // TODO: make a file/class for frameState and document what needs to be attached to this so that traversal can function
39
- return {
40
- camera: {
41
- position: cameraPositionCartesian,
42
- direction: cameraDirectionCartesian,
43
- up: cameraUpCartesian
44
- },
45
- viewport,
46
- height,
47
- cullingVolume,
48
- frameNumber,
49
- sseDenominator: 1.15 // Assumes fovy = 60 degrees
50
- };
1
+ import { Vector3 } from '@math.gl/core';
2
+ import { CullingVolume, Plane } from '@math.gl/culling';
3
+ import { Ellipsoid } from '@math.gl/geospatial';
4
+ const scratchVector = new Vector3();
5
+ const scratchPosition = new Vector3();
6
+ const cullingVolume = new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]);
7
+ export function getFrameState(viewport, frameNumber) {
8
+ const {
9
+ cameraDirection,
10
+ cameraUp,
11
+ height
12
+ } = viewport;
13
+ const {
14
+ metersPerUnit
15
+ } = viewport.distanceScales;
16
+ const viewportCenterCartographic = viewport.unprojectPosition(viewport.center);
17
+ const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new Vector3());
18
+ const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
19
+ const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
20
+ const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
21
+ const cameraDirectionCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize();
22
+ const cameraUpCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize();
23
+ commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);
24
+ return {
25
+ camera: {
26
+ position: cameraPositionCartesian,
27
+ direction: cameraDirectionCartesian,
28
+ up: cameraUpCartesian
29
+ },
30
+ viewport,
31
+ height,
32
+ cullingVolume,
33
+ frameNumber,
34
+ sseDenominator: 1.15
35
+ };
51
36
  }
52
- exports.getFrameState = getFrameState;
37
+
53
38
  function commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {
54
- // Extract frustum planes based on current view.
55
- const frustumPlanes = viewport.getFrustumPlanes();
56
- let i = 0;
57
- for (const dir in frustumPlanes) {
58
- const plane = frustumPlanes[dir];
59
- const distanceToCenter = plane.normal.dot(viewport.center);
60
- scratchPosition
61
- .copy(plane.normal)
62
- .scale(plane.distance - distanceToCenter)
63
- .add(viewport.center);
64
- const cartographicPos = viewport.unprojectPosition(scratchPosition);
65
- const cartesianPos = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new core_1.Vector3());
66
- cullingVolume.planes[i++].fromPointNormal(cartesianPos,
67
- // Want the normal to point into the frustum since that's what culling expects
68
- scratchVector.copy(viewportCenterCartesian).subtract(cartesianPos));
69
- }
39
+ const frustumPlanes = viewport.getFrustumPlanes();
40
+ let i = 0;
41
+
42
+ for (const dir in frustumPlanes) {
43
+ const plane = frustumPlanes[dir];
44
+ const distanceToCenter = plane.normal.dot(viewport.center);
45
+ scratchPosition.copy(plane.normal).scale(plane.distance - distanceToCenter).add(viewport.center);
46
+ const cartographicPos = viewport.unprojectPosition(scratchPosition);
47
+ const cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3());
48
+ cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector.copy(viewportCenterCartesian).subtract(cartesianPos));
49
+ }
70
50
  }
51
+ //# sourceMappingURL=frame-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/tileset/helpers/frame-state.ts"],"names":["Vector3","CullingVolume","Plane","Ellipsoid","scratchVector","scratchPosition","cullingVolume","getFrameState","viewport","frameNumber","cameraDirection","cameraUp","height","metersPerUnit","distanceScales","viewportCenterCartographic","unprojectPosition","center","viewportCenterCartesian","WGS84","cartographicToCartesian","enuToFixedTransform","eastNorthUpToFixedFrame","cameraPositionCartographic","cameraPosition","cameraPositionCartesian","cameraDirectionCartesian","transformAsVector","scale","normalize","cameraUpCartesian","commonSpacePlanesToWGS84","camera","position","direction","up","sseDenominator","frustumPlanes","getFrustumPlanes","i","d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Q,iBAAT,CAA2BX,eAA3B,CAAxB;AAEA,UAAM4C,YAAY,GAAG9C,SAAS,CAACgB,KAAV,CAAgBC,uBAAhB,CAAwC4B,eAAxC,EAAyD,IAAIhD,OAAJ,EAAzD,CAArB;AAEAM,IAAAA,aAAa,CAAC4C,MAAd,CAAqBX,CAAC,EAAtB,EAA0BY,eAA1B,CACEF,YADF,EAGE7C,aAAa,CAACyC,IAAd,CAAmB3B,uBAAnB,EAA4CkC,QAA5C,CAAqDH,YAArD,CAHF;AAKD;AACF","sourcesContent":["import {Vector3} from '@math.gl/core';\nimport {CullingVolume, Plane} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nexport type FrameState = {\n camera: {\n position: number[];\n direction: number[];\n up: number[];\n };\n viewport: {[key: string]: any};\n height: number;\n cullingVolume: CullingVolume;\n frameNumber: number; // TODO: This can be the same between updates, what number is unique for between updates?\n sseDenominator: number; // Assumes fovy = 60 degrees\n};\n\nconst scratchVector = new Vector3();\nconst scratchPosition = new Vector3();\nconst cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n]);\n\n// Extracts a frame state appropriate for tile culling from a deck.gl viewport\n// TODO - this could likely be generalized and merged back into deck.gl for other culling scenarios\nexport function getFrameState(viewport, frameNumber: number): FrameState {\n // Traverse and and request. Update _selectedTiles so that we know what to render.\n const {cameraDirection, cameraUp, height} = viewport;\n const {metersPerUnit} = viewport.distanceScales;\n\n const viewportCenterCartographic = viewport.unprojectPosition(viewport.center);\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?\n const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(\n viewportCenterCartographic,\n new Vector3()\n );\n const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);\n\n const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);\n const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(\n cameraPositionCartographic,\n new Vector3()\n );\n\n // These should still be normalized as the transform has scale 1 (goes from meters to meters)\n const cameraDirectionCartesian = new Vector3(\n // @ts-ignore\n enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))\n ).normalize();\n const cameraUpCartesian = new Vector3(\n // @ts-ignore\n enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))\n ).normalize();\n\n commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);\n\n // TODO: make a file/class for frameState and document what needs to be attached to this so that traversal can function\n return {\n camera: {\n position: cameraPositionCartesian,\n direction: cameraDirectionCartesian,\n up: cameraUpCartesian\n },\n viewport,\n height,\n cullingVolume,\n frameNumber, // TODO: This can be the same between updates, what number is unique for between updates?\n sseDenominator: 1.15 // Assumes fovy = 60 degrees\n };\n}\n\nfunction commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {\n // Extract frustum planes based on current view.\n const frustumPlanes = viewport.getFrustumPlanes();\n let i = 0;\n for (const dir in frustumPlanes) {\n const plane = frustumPlanes[dir];\n const distanceToCenter = plane.normal.dot(viewport.center);\n scratchPosition\n .copy(plane.normal)\n .scale(plane.distance - distanceToCenter)\n .add(viewport.center);\n const cartographicPos = viewport.unprojectPosition(scratchPosition);\n\n const cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3());\n\n cullingVolume.planes[i++].fromPointNormal(\n cartesianPos,\n // Want the normal to point into the frustum since that's what culling expects\n scratchVector.copy(viewportCenterCartesian).subtract(cartesianPos)\n );\n }\n}\n"],"file":"frame-state.js"}
@@ -1,83 +1,67 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProjectedRadius = exports.getLodStatus = void 0;
4
- const core_1 = require("@math.gl/core");
5
- const geospatial_1 = require("@math.gl/geospatial");
6
- /**
7
- * For the maxScreenThreshold error metric, maxError means that you should replace the node with it's children
8
- as soon as the nodes bounding sphere has a screen radius larger than maxError pixels.
9
- In this sense a value of 0 means you should always load it's children,
10
- or if it's a leaf node, you should always display it.
11
- * @param tile
12
- * @param frameState
13
- * @returns
14
- */
15
- function getLodStatus(tile, frameState) {
16
- if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
17
- return 'DIG';
18
- }
19
- const screenSize = 2 * getProjectedRadius(tile, frameState);
20
- if (screenSize < 2) {
21
- return 'OUT';
22
- }
23
- if (!tile.header.children || screenSize <= tile.lodMetricValue) {
24
- return 'DRAW';
25
- }
26
- else if (tile.header.children) {
27
- return 'DIG';
28
- }
1
+ import { Matrix4, Vector3 } from '@math.gl/core';
2
+ import { Ellipsoid } from '@math.gl/geospatial';
3
+ export function getLodStatus(tile, frameState) {
4
+ if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
5
+ return 'DIG';
6
+ }
7
+
8
+ const screenSize = 2 * getProjectedRadius(tile, frameState);
9
+
10
+ if (screenSize < 2) {
29
11
  return 'OUT';
12
+ }
13
+
14
+ if (!tile.header.children || screenSize <= tile.lodMetricValue) {
15
+ return 'DRAW';
16
+ } else if (tile.header.children) {
17
+ return 'DIG';
18
+ }
19
+
20
+ return 'OUT';
30
21
  }
31
- exports.getLodStatus = getLodStatus;
32
- /**
33
- * Calculate size of MBS radius projected on the screen plane
34
- * @param tile
35
- * @param frameState
36
- * @returns
37
- */
38
- // eslint-disable-next-line max-statements
39
- function getProjectedRadius(tile, frameState) {
40
- const originalViewport = frameState.viewport;
41
- const ViewportClass = originalViewport.constructor;
42
- const { longitude, latitude, height, width, bearing, zoom } = originalViewport;
43
- // @ts-ignore
44
- const viewport = new ViewportClass({ longitude, latitude, height, width, bearing, zoom, pitch: 0 });
45
- const mbsLat = tile.header.mbs[1];
46
- const mbsLon = tile.header.mbs[0];
47
- const mbsZ = tile.header.mbs[2];
48
- const mbsR = tile.header.mbs[3];
49
- const mbsCenterCartesian = [...tile.boundingVolume.center];
50
- const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
51
- const cameraPositionCartesian = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new core_1.Vector3());
52
- // ---------------------------
53
- // Calculate mbs border vertex
54
- // ---------------------------
55
- const toEye = new core_1.Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
56
- // Add extra vector to form plane
57
- const enuToCartesianMatrix = new core_1.Matrix4();
58
- geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
59
- const cartesianToEnuMatrix = new core_1.Matrix4(enuToCartesianMatrix).invert();
60
- const cameraPositionEnu = new core_1.Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);
61
- // Mean Proportionals in Right Triangles - Altitude rule
62
- // https://mathbitsnotebook.com/Geometry/RightTriangles/RTmeanRight.html
63
- const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
64
- const extraZ = (projection * projection) / cameraPositionEnu[2];
65
- const extraVertexEnu = new core_1.Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
66
- const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
67
- const extraVectorCartesian = new core_1.Vector3(extraVertexCartesian)
68
- .subtract(mbsCenterCartesian)
69
- .normalize();
70
- // We need radius vector orthogonal to toEye vector
71
- const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
72
- const sphereMbsBorderVertexCartesian = new core_1.Vector3(mbsCenterCartesian).add(radiusVector);
73
- const sphereMbsBorderVertexCartographic = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
74
- // ---------------------------
75
- // Project center vertex and border vertex and calculate projected radius of MBS
76
- const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
77
- const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
78
- const projectedRadius = new core_1.Vector3(projectedOrigin)
79
- .subtract(projectedMbsBorderVertex)
80
- .magnitude();
81
- return projectedRadius;
22
+ export function getProjectedRadius(tile, frameState) {
23
+ const originalViewport = frameState.viewport;
24
+ const ViewportClass = originalViewport.constructor;
25
+ const {
26
+ longitude,
27
+ latitude,
28
+ height,
29
+ width,
30
+ bearing,
31
+ zoom
32
+ } = originalViewport;
33
+ const viewport = new ViewportClass({
34
+ longitude,
35
+ latitude,
36
+ height,
37
+ width,
38
+ bearing,
39
+ zoom,
40
+ pitch: 0
41
+ });
42
+ const mbsLat = tile.header.mbs[1];
43
+ const mbsLon = tile.header.mbs[0];
44
+ const mbsZ = tile.header.mbs[2];
45
+ const mbsR = tile.header.mbs[3];
46
+ const mbsCenterCartesian = [...tile.boundingVolume.center];
47
+ const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
48
+ const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
49
+ const toEye = new Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
50
+ const enuToCartesianMatrix = new Matrix4();
51
+ Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
52
+ const cartesianToEnuMatrix = new Matrix4(enuToCartesianMatrix).invert();
53
+ const cameraPositionEnu = new Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);
54
+ const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
55
+ const extraZ = projection * projection / cameraPositionEnu[2];
56
+ const extraVertexEnu = new Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
57
+ const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
58
+ const extraVectorCartesian = new Vector3(extraVertexCartesian).subtract(mbsCenterCartesian).normalize();
59
+ const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
60
+ const sphereMbsBorderVertexCartesian = new Vector3(mbsCenterCartesian).add(radiusVector);
61
+ const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
62
+ const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
63
+ const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
64
+ const projectedRadius = new Vector3(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
65
+ return projectedRadius;
82
66
  }
83
- exports.getProjectedRadius = getProjectedRadius;
67
+ //# sourceMappingURL=i3s-lod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/tileset/helpers/i3s-lod.ts"],"names":["Matrix4","Vector3","Ellipsoid","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","WGS84","cartographicToCartesian","toEye","subtract","normalize","enuToCartesianMatrix","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":"AAAA,SAAQA,OAAR,EAAiBC,OAAjB,QAA+B,eAA/B;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAaA,OAAO,SAASC,YAAT,CAAsBC,IAAtB,EAAoCC,UAApC,EAAoF;AACzF,MAAID,IAAI,CAACE,cAAL,KAAwB,CAAxB,IAA6BC,KAAK,CAACH,IAAI,CAACE,cAAN,CAAtC,EAA6D;AAC3D,WAAO,KAAP;AACD;;AACD,QAAME,UAAU,GA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BAAZ,EAC1Bb,QAD0B,CACjBV,kBADiB,EAE1BW,SAF0B,EAA7B;AAIA,QAAMc,YAAY,GAAGhB,KAAK,CAACiB,KAAN,CAAYF,oBAAZ,EAAkCb,SAAlC,GAA8CgB,KAA9C,CAAoD5B,IAApD,CAArB;AACA,QAAM6B,8BAA8B,GAAG,IAAIvD,OAAJ,CAAY2B,kBAAZ,EAAgC6B,GAAhC,CAAoCJ,YAApC,CAAvC;AACA,QAAMK,iCAAiC,GAAGxD,SAAS,CAACiC,KAAV,CAAgBwB,uBAAhB,CACxCH,8BADwC,CAA1C;AAMA,QAAMI,eAAe,GAAG/C,QAAQ,CAACgD,OAAT,CAAiB,CAACpC,MAAD,EAASF,MAAT,EAAiBG,IAAjB,CAAjB,CAAxB;AACA,QAAMoC,wBAAwB,GAAGjD,QAAQ,CAACgD,OAAT,CAAiBH,iCAAjB,CAAjC;AACA,QAAMK,eAAe,GAAG,IAAI9D,OAAJ,CAAY2D,eAAZ,EACrBtB,QADqB,CACZwB,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 '../tile-3d';\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"}