@loaders.gl/tiles 4.2.0-alpha.3 → 4.2.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 (73) hide show
  1. package/dist/constants.js +34 -32
  2. package/dist/dist.dev.js +723 -342
  3. package/dist/dist.min.js +9 -0
  4. package/dist/index.cjs +98 -240
  5. package/dist/index.cjs.map +7 -0
  6. package/dist/index.d.ts +10 -10
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -1
  9. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts +1 -1
  10. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts.map +1 -1
  11. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +45 -35
  12. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +40 -22
  13. package/dist/tileset/format-i3s/i3s-tile-manager.d.ts +1 -1
  14. package/dist/tileset/format-i3s/i3s-tile-manager.d.ts.map +1 -1
  15. package/dist/tileset/format-i3s/i3s-tile-manager.js +67 -69
  16. package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts +2 -2
  17. package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts.map +1 -1
  18. package/dist/tileset/format-i3s/i3s-tileset-traverser.js +78 -57
  19. package/dist/tileset/helpers/3d-tiles-options.d.ts +1 -1
  20. package/dist/tileset/helpers/3d-tiles-options.d.ts.map +1 -1
  21. package/dist/tileset/helpers/3d-tiles-options.js +3 -4
  22. package/dist/tileset/helpers/bounding-volume.js +269 -128
  23. package/dist/tileset/helpers/frame-state.d.ts +1 -1
  24. package/dist/tileset/helpers/frame-state.d.ts.map +1 -1
  25. package/dist/tileset/helpers/frame-state.js +114 -95
  26. package/dist/tileset/helpers/i3s-lod.d.ts +2 -2
  27. package/dist/tileset/helpers/i3s-lod.d.ts.map +1 -1
  28. package/dist/tileset/helpers/i3s-lod.js +68 -39
  29. package/dist/tileset/helpers/tiles-3d-lod.js +97 -85
  30. package/dist/tileset/helpers/transform-utils.js +45 -44
  31. package/dist/tileset/helpers/zoom.d.ts +1 -1
  32. package/dist/tileset/helpers/zoom.d.ts.map +1 -1
  33. package/dist/tileset/helpers/zoom.js +70 -40
  34. package/dist/tileset/tile-3d.d.ts +5 -5
  35. package/dist/tileset/tile-3d.d.ts.map +1 -1
  36. package/dist/tileset/tile-3d.js +595 -399
  37. package/dist/tileset/tileset-3d.d.ts +5 -5
  38. package/dist/tileset/tileset-3d.d.ts.map +1 -1
  39. package/dist/tileset/tileset-3d.js +721 -597
  40. package/dist/tileset/tileset-cache.d.ts +2 -2
  41. package/dist/tileset/tileset-cache.d.ts.map +1 -1
  42. package/dist/tileset/tileset-cache.js +62 -48
  43. package/dist/tileset/tileset-traverser.d.ts +3 -3
  44. package/dist/tileset/tileset-traverser.d.ts.map +1 -1
  45. package/dist/tileset/tileset-traverser.js +281 -220
  46. package/dist/types.js +0 -1
  47. package/dist/utils/doubly-linked-list-node.js +14 -9
  48. package/dist/utils/doubly-linked-list.d.ts +1 -1
  49. package/dist/utils/doubly-linked-list.d.ts.map +1 -1
  50. package/dist/utils/doubly-linked-list.js +85 -56
  51. package/dist/utils/managed-array.js +138 -76
  52. package/package.json +10 -9
  53. package/dist/constants.js.map +0 -1
  54. package/dist/index.js.map +0 -1
  55. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js.map +0 -1
  56. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js.map +0 -1
  57. package/dist/tileset/format-i3s/i3s-tile-manager.js.map +0 -1
  58. package/dist/tileset/format-i3s/i3s-tileset-traverser.js.map +0 -1
  59. package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
  60. package/dist/tileset/helpers/bounding-volume.js.map +0 -1
  61. package/dist/tileset/helpers/frame-state.js.map +0 -1
  62. package/dist/tileset/helpers/i3s-lod.js.map +0 -1
  63. package/dist/tileset/helpers/tiles-3d-lod.js.map +0 -1
  64. package/dist/tileset/helpers/transform-utils.js.map +0 -1
  65. package/dist/tileset/helpers/zoom.js.map +0 -1
  66. package/dist/tileset/tile-3d.js.map +0 -1
  67. package/dist/tileset/tileset-3d.js.map +0 -1
  68. package/dist/tileset/tileset-cache.js.map +0 -1
  69. package/dist/tileset/tileset-traverser.js.map +0 -1
  70. package/dist/types.js.map +0 -1
  71. package/dist/utils/doubly-linked-list-node.js.map +0 -1
  72. package/dist/utils/doubly-linked-list.js.map +0 -1
  73. package/dist/utils/managed-array.js.map +0 -1
@@ -1,10 +1,15 @@
1
+ // This file is derived from the Cesium code base under Apache 2 license
2
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
+ /* eslint-disable */
1
4
  import { Quaternion, Vector3, Matrix3, Matrix4, degrees } from '@math.gl/core';
2
5
  import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
3
6
  import { Ellipsoid } from '@math.gl/geospatial';
4
7
  import { assert } from '@loaders.gl/loader-utils';
8
+ // const scratchProjectedBoundingSphere = new BoundingSphere();
5
9
  function defined(x) {
6
- return x !== undefined && x !== null;
10
+ return x !== undefined && x !== null;
7
11
  }
12
+ // const scratchMatrix = new Matrix3();
8
13
  const scratchPoint = new Vector3();
9
14
  const scratchScale = new Vector3();
10
15
  const scratchNorthWest = new Vector3();
@@ -13,153 +18,289 @@ const scratchCenter = new Vector3();
13
18
  const scratchXAxis = new Vector3();
14
19
  const scratchYAxis = new Vector3();
15
20
  const scratchZAxis = new Vector3();
21
+ // const scratchRectangle = new Rectangle();
22
+ // const scratchOrientedBoundingBox = new OrientedBoundingBox();
23
+ // const scratchTransform = new Matrix4();
24
+ /**
25
+ * Create a bounding volume from the tile's bounding volume header.
26
+ * @param {Object} boundingVolumeHeader The tile's bounding volume header.
27
+ * @param {Matrix4} transform The transform to apply to the bounding volume.
28
+ * @param [result] The object onto which to store the result.
29
+ * @returns The modified result parameter or a new TileBoundingVolume instance if none was provided.
30
+ */
16
31
  export function createBoundingVolume(boundingVolumeHeader, transform, result) {
17
- assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
18
- if (boundingVolumeHeader.box) {
19
- return createBox(boundingVolumeHeader.box, transform, result);
20
- }
21
- if (boundingVolumeHeader.region) {
22
- return createObbFromRegion(boundingVolumeHeader.region);
23
- }
24
- if (boundingVolumeHeader.sphere) {
25
- return createSphere(boundingVolumeHeader.sphere, transform, result);
26
- }
27
- throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
32
+ assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
33
+ // boundingVolume schema:
34
+ // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json
35
+ if (boundingVolumeHeader.box) {
36
+ return createBox(boundingVolumeHeader.box, transform, result);
37
+ }
38
+ if (boundingVolumeHeader.region) {
39
+ return createObbFromRegion(boundingVolumeHeader.region);
40
+ }
41
+ if (boundingVolumeHeader.sphere) {
42
+ return createSphere(boundingVolumeHeader.sphere, transform, result);
43
+ }
44
+ throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
28
45
  }
46
+ /**
47
+ * Calculate the cartographic bounding box the tile's bounding volume.
48
+ * @param {Object} boundingVolumeHeader The tile's bounding volume header.
49
+ * @param {BoundingVolume} boundingVolume The bounding volume.
50
+ * @returns {CartographicBounds}
51
+ */
29
52
  export function getCartographicBounds(boundingVolumeHeader, boundingVolume) {
30
- if (boundingVolumeHeader.box) {
31
- return orientedBoundingBoxToCartographicBounds(boundingVolume);
32
- }
33
- if (boundingVolumeHeader.region) {
34
- const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
35
- return [[degrees(west), degrees(south), minHeight], [degrees(east), degrees(north), maxHeight]];
36
- }
37
- if (boundingVolumeHeader.sphere) {
38
- return boundingSphereToCartographicBounds(boundingVolume);
39
- }
40
- throw new Error('Unkown boundingVolume type');
53
+ // boundingVolume schema:
54
+ // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json
55
+ if (boundingVolumeHeader.box) {
56
+ return orientedBoundingBoxToCartographicBounds(boundingVolume);
57
+ }
58
+ if (boundingVolumeHeader.region) {
59
+ // [west, south, east, north, minimum height, maximum height]
60
+ // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.
61
+ // Heights are in meters above (or below) the WGS 84 ellipsoid.
62
+ const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
63
+ return [
64
+ [degrees(west), degrees(south), minHeight],
65
+ [degrees(east), degrees(north), maxHeight]
66
+ ];
67
+ }
68
+ if (boundingVolumeHeader.sphere) {
69
+ return boundingSphereToCartographicBounds(boundingVolume);
70
+ }
71
+ throw new Error('Unkown boundingVolume type');
41
72
  }
42
73
  function createBox(box, transform, result) {
43
- const center = new Vector3(box[0], box[1], box[2]);
44
- transform.transform(center, center);
45
- let origin = [];
46
- if (box.length === 10) {
47
- const halfSize = box.slice(3, 6);
48
- const quaternion = new Quaternion();
49
- quaternion.fromArray(box, 6);
50
- const x = new Vector3([1, 0, 0]);
51
- const y = new Vector3([0, 1, 0]);
52
- const z = new Vector3([0, 0, 1]);
53
- x.transformByQuaternion(quaternion);
54
- x.scale(halfSize[0]);
55
- y.transformByQuaternion(quaternion);
56
- y.scale(halfSize[1]);
57
- z.transformByQuaternion(quaternion);
58
- z.scale(halfSize[2]);
59
- origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];
60
- } else {
61
- origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];
62
- }
63
- const xAxis = transform.transformAsVector(origin.slice(0, 3));
64
- const yAxis = transform.transformAsVector(origin.slice(3, 6));
65
- const zAxis = transform.transformAsVector(origin.slice(6, 9));
66
- const halfAxes = new Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]);
67
- if (defined(result)) {
68
- result.center = center;
69
- result.halfAxes = halfAxes;
74
+ // https://math.gl/modules/culling/docs/api-reference/oriented-bounding-box
75
+ // 1. A half-axes based representation.
76
+ // box: An array of 12 numbers that define an oriented bounding box.
77
+ // The first three elements define the x, y, and z values for the center of the box.
78
+ // The next three elements (with indices 3, 4, and 5) define the x axis direction and half-length.
79
+ // The next three elements (indices 6, 7, and 8) define the y axis direction and half-length.
80
+ // The last three elements (indices 9, 10, and 11) define the z axis direction and half-length.
81
+ // 2. A half-size-quaternion based representation.
82
+ // box: An array of 10 numbers that define an oriented bounding box.
83
+ // 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.
84
+ // The next three elements (with indices 3, 4, and 5) define the halfSize.
85
+ // The last four elements (indices 6, 7, 8 and 10) define the quaternion.
86
+ const center = new Vector3(box[0], box[1], box[2]);
87
+ transform.transform(center, center);
88
+ let origin = [];
89
+ if (box.length === 10) {
90
+ const halfSize = box.slice(3, 6);
91
+ const quaternion = new Quaternion();
92
+ quaternion.fromArray(box, 6);
93
+ const x = new Vector3([1, 0, 0]);
94
+ const y = new Vector3([0, 1, 0]);
95
+ const z = new Vector3([0, 0, 1]);
96
+ x.transformByQuaternion(quaternion);
97
+ x.scale(halfSize[0]);
98
+ y.transformByQuaternion(quaternion);
99
+ y.scale(halfSize[1]);
100
+ z.transformByQuaternion(quaternion);
101
+ z.scale(halfSize[2]);
102
+ origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];
103
+ }
104
+ else {
105
+ origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];
106
+ }
107
+ const xAxis = transform.transformAsVector(origin.slice(0, 3));
108
+ const yAxis = transform.transformAsVector(origin.slice(3, 6));
109
+ const zAxis = transform.transformAsVector(origin.slice(6, 9));
110
+ const halfAxes = new Matrix3([
111
+ xAxis[0],
112
+ xAxis[1],
113
+ xAxis[2],
114
+ yAxis[0],
115
+ yAxis[1],
116
+ yAxis[2],
117
+ zAxis[0],
118
+ zAxis[1],
119
+ zAxis[2]
120
+ ]);
121
+ if (defined(result)) {
122
+ result.center = center;
123
+ result.halfAxes = halfAxes;
124
+ return result;
125
+ }
126
+ return new OrientedBoundingBox(center, halfAxes);
127
+ }
128
+ /*
129
+ function createBoxFromTransformedRegion(region, transform, initialTransform, result) {
130
+ const rectangle = Rectangle.unpack(region, 0, scratchRectangle);
131
+ const minimumHeight = region[4];
132
+ const maximumHeight = region[5];
133
+
134
+ const orientedBoundingBox = OrientedBoundingBox.fromRectangle(
135
+ rectangle,
136
+ minimumHeight,
137
+ maximumHeight,
138
+ Ellipsoid.WGS84,
139
+ scratchOrientedBoundingBox
140
+ );
141
+ const center = orientedBoundingBox.center;
142
+ const halfAxes = orientedBoundingBox.halfAxes;
143
+
144
+ // A region bounding volume is not transformed by the transform in the tileset JSON,
145
+ // but may be transformed by additional transforms applied in Cesium.
146
+ // This is why the transform is calculated as the difference between the initial transform and the current transform.
147
+ transform = Matrix4.multiplyTransformation(
148
+ transform,
149
+ Matrix4.inverseTransformation(initialTransform, scratchTransform),
150
+ scratchTransform
151
+ );
152
+ center = Matrix4.multiplyByPoint(transform, center, center);
153
+ const rotationScale = Matrix4.getRotation(transform, scratchMatrix);
154
+ halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
155
+
156
+ if (defined(result) && result instanceof TileOrientedBoundingBox) {
157
+ result.update(center, halfAxes);
70
158
  return result;
71
159
  }
72
- return new OrientedBoundingBox(center, halfAxes);
160
+
161
+ return new TileOrientedBoundingBox(center, halfAxes);
73
162
  }
74
- function createSphere(sphere, transform, result) {
75
- const center = new Vector3(sphere[0], sphere[1], sphere[2]);
76
- transform.transform(center, center);
77
- const scale = transform.getScale(scratchScale);
78
- const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);
79
- const radius = sphere[3] * uniformScale;
163
+
164
+ function createRegion(region, transform, initialTransform, result) {
165
+ if (!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)) {
166
+ return createBoxFromTransformedRegion(region, transform, initialTransform, result);
167
+ }
168
+
80
169
  if (defined(result)) {
81
- result.center = center;
82
- result.radius = radius;
83
170
  return result;
84
171
  }
85
- return new BoundingSphere(center, radius);
172
+
173
+ const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);
174
+
175
+ return new TileBoundingRegion({
176
+ rectangle: rectangleRegion,
177
+ minimumHeight: region[4],
178
+ maximumHeight: region[5]
179
+ });
86
180
  }
181
+ */
182
+ function createSphere(sphere, transform, result) {
183
+ // Find the transformed center
184
+ const center = new Vector3(sphere[0], sphere[1], sphere[2]);
185
+ transform.transform(center, center);
186
+ const scale = transform.getScale(scratchScale);
187
+ const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);
188
+ const radius = sphere[3] * uniformScale;
189
+ if (defined(result)) {
190
+ result.center = center;
191
+ result.radius = radius;
192
+ return result;
193
+ }
194
+ return new BoundingSphere(center, radius);
195
+ }
196
+ /**
197
+ * Create OrientedBoundingBox instance from region 3D tiles bounding volume
198
+ * @param region - region 3D tiles bounding volume
199
+ * @returns OrientedBoundingBox instance
200
+ */
87
201
  function createObbFromRegion(region) {
88
- const [west, south, east, north, minHeight, maxHeight] = region;
89
- const northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest);
90
- const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast);
91
- const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyByScalar(0.5);
92
- Ellipsoid.WGS84.cartesianToCartographic(centerInCartesian, scratchCenter);
93
- Ellipsoid.WGS84.cartographicToCartesian([degrees(east), scratchCenter[1], scratchCenter[2]], scratchXAxis);
94
- Ellipsoid.WGS84.cartographicToCartesian([scratchCenter[0], degrees(north), scratchCenter[2]], scratchYAxis);
95
- Ellipsoid.WGS84.cartographicToCartesian([scratchCenter[0], scratchCenter[1], maxHeight], scratchZAxis);
96
- return createBox([...centerInCartesian, ...scratchXAxis.subtract(centerInCartesian), ...scratchYAxis.subtract(centerInCartesian), ...scratchZAxis.subtract(centerInCartesian)], new Matrix4());
202
+ // [west, south, east, north, minimum height, maximum height]
203
+ // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.
204
+ // Heights are in meters above (or below) the WGS 84 ellipsoid.
205
+ const [west, south, east, north, minHeight, maxHeight] = region;
206
+ const northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest);
207
+ const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast);
208
+ const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyByScalar(0.5);
209
+ Ellipsoid.WGS84.cartesianToCartographic(centerInCartesian, scratchCenter);
210
+ Ellipsoid.WGS84.cartographicToCartesian([degrees(east), scratchCenter[1], scratchCenter[2]], scratchXAxis);
211
+ Ellipsoid.WGS84.cartographicToCartesian([scratchCenter[0], degrees(north), scratchCenter[2]], scratchYAxis);
212
+ Ellipsoid.WGS84.cartographicToCartesian([scratchCenter[0], scratchCenter[1], maxHeight], scratchZAxis);
213
+ return createBox([
214
+ ...centerInCartesian,
215
+ ...scratchXAxis.subtract(centerInCartesian),
216
+ ...scratchYAxis.subtract(centerInCartesian),
217
+ ...scratchZAxis.subtract(centerInCartesian)
218
+ ], new Matrix4());
97
219
  }
220
+ /**
221
+ * Convert a bounding volume defined by OrientedBoundingBox to cartographic bounds
222
+ * @returns {CartographicBounds}
223
+ */
98
224
  function orientedBoundingBoxToCartographicBounds(boundingVolume) {
99
- const result = emptyCartographicBounds();
100
- const {
101
- halfAxes
102
- } = boundingVolume;
103
- const xAxis = new Vector3(halfAxes.getColumn(0));
104
- const yAxis = new Vector3(halfAxes.getColumn(1));
105
- const zAxis = new Vector3(halfAxes.getColumn(2));
106
- for (let x = 0; x < 2; x++) {
107
- for (let y = 0; y < 2; y++) {
108
- for (let z = 0; z < 2; z++) {
109
- scratchPoint.copy(boundingVolume.center);
110
- scratchPoint.add(xAxis);
111
- scratchPoint.add(yAxis);
112
- scratchPoint.add(zAxis);
113
- addToCartographicBounds(result, scratchPoint);
114
- zAxis.negate();
115
- }
116
- yAxis.negate();
117
- }
118
- xAxis.negate();
119
- }
120
- return result;
225
+ const result = emptyCartographicBounds();
226
+ const { halfAxes } = boundingVolume;
227
+ const xAxis = new Vector3(halfAxes.getColumn(0));
228
+ const yAxis = new Vector3(halfAxes.getColumn(1));
229
+ const zAxis = new Vector3(halfAxes.getColumn(2));
230
+ // Test all 8 corners of the box
231
+ for (let x = 0; x < 2; x++) {
232
+ for (let y = 0; y < 2; y++) {
233
+ for (let z = 0; z < 2; z++) {
234
+ scratchPoint.copy(boundingVolume.center);
235
+ scratchPoint.add(xAxis);
236
+ scratchPoint.add(yAxis);
237
+ scratchPoint.add(zAxis);
238
+ addToCartographicBounds(result, scratchPoint);
239
+ zAxis.negate();
240
+ }
241
+ yAxis.negate();
242
+ }
243
+ xAxis.negate();
244
+ }
245
+ return result;
121
246
  }
247
+ /**
248
+ * Convert a bounding volume defined by BoundingSphere to cartographic bounds
249
+ * @returns {CartographicBounds}
250
+ */
122
251
  function boundingSphereToCartographicBounds(boundingVolume) {
123
- const result = emptyCartographicBounds();
124
- const {
125
- center,
126
- radius
127
- } = boundingVolume;
128
- const point = Ellipsoid.WGS84.scaleToGeodeticSurface(center, scratchPoint);
129
- let zAxis;
130
- if (point) {
131
- zAxis = Ellipsoid.WGS84.geodeticSurfaceNormal(point);
132
- } else {
133
- zAxis = new Vector3(0, 0, 1);
134
- }
135
- let xAxis = new Vector3(zAxis[2], -zAxis[1], 0);
136
- if (xAxis.len() > 0) {
137
- xAxis.normalize();
138
- } else {
139
- xAxis = new Vector3(0, 1, 0);
140
- }
141
- const yAxis = xAxis.clone().cross(zAxis);
142
- for (const axis of [xAxis, yAxis, zAxis]) {
143
- scratchScale.copy(axis).scale(radius);
144
- for (let dir = 0; dir < 2; dir++) {
145
- scratchPoint.copy(center);
146
- scratchPoint.add(scratchScale);
147
- addToCartographicBounds(result, scratchPoint);
148
- scratchScale.negate();
252
+ const result = emptyCartographicBounds();
253
+ const { center, radius } = boundingVolume;
254
+ const point = Ellipsoid.WGS84.scaleToGeodeticSurface(center, scratchPoint);
255
+ let zAxis;
256
+ if (point) {
257
+ zAxis = Ellipsoid.WGS84.geodeticSurfaceNormal(point);
149
258
  }
150
- }
151
- return result;
259
+ else {
260
+ zAxis = new Vector3(0, 0, 1);
261
+ }
262
+ let xAxis = new Vector3(zAxis[2], -zAxis[1], 0);
263
+ if (xAxis.len() > 0) {
264
+ xAxis.normalize();
265
+ }
266
+ else {
267
+ xAxis = new Vector3(0, 1, 0);
268
+ }
269
+ const yAxis = xAxis.clone().cross(zAxis);
270
+ // Test 6 end points of the 3 axes
271
+ for (const axis of [xAxis, yAxis, zAxis]) {
272
+ scratchScale.copy(axis).scale(radius);
273
+ for (let dir = 0; dir < 2; dir++) {
274
+ scratchPoint.copy(center);
275
+ scratchPoint.add(scratchScale);
276
+ addToCartographicBounds(result, scratchPoint);
277
+ // Flip the axis
278
+ scratchScale.negate();
279
+ }
280
+ }
281
+ return result;
152
282
  }
283
+ /**
284
+ * Create a new cartographic bounds that contains no points
285
+ * @returns {CartographicBounds}
286
+ */
153
287
  function emptyCartographicBounds() {
154
- return [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
288
+ return [
289
+ [Infinity, Infinity, Infinity],
290
+ [-Infinity, -Infinity, -Infinity]
291
+ ];
155
292
  }
293
+ /**
294
+ * Add a point to the target cartographic bounds
295
+ * @param {CartographicBounds} target
296
+ * @param {Vector3} cartesian coordinates of the point to add
297
+ */
156
298
  function addToCartographicBounds(target, cartesian) {
157
- Ellipsoid.WGS84.cartesianToCartographic(cartesian, scratchPoint);
158
- target[0][0] = Math.min(target[0][0], scratchPoint[0]);
159
- target[0][1] = Math.min(target[0][1], scratchPoint[1]);
160
- target[0][2] = Math.min(target[0][2], scratchPoint[2]);
161
- target[1][0] = Math.max(target[1][0], scratchPoint[0]);
162
- target[1][1] = Math.max(target[1][1], scratchPoint[1]);
163
- target[1][2] = Math.max(target[1][2], scratchPoint[2]);
299
+ Ellipsoid.WGS84.cartesianToCartographic(cartesian, scratchPoint);
300
+ target[0][0] = Math.min(target[0][0], scratchPoint[0]);
301
+ target[0][1] = Math.min(target[0][1], scratchPoint[1]);
302
+ target[0][2] = Math.min(target[0][2], scratchPoint[2]);
303
+ target[1][0] = Math.max(target[1][0], scratchPoint[0]);
304
+ target[1][1] = Math.max(target[1][1], scratchPoint[1]);
305
+ target[1][2] = Math.max(target[1][2], scratchPoint[2]);
164
306
  }
165
- //# sourceMappingURL=bounding-volume.js.map
@@ -1,6 +1,6 @@
1
1
  import { Tile3D } from '@loaders.gl/tiles';
2
2
  import { CullingVolume } from '@math.gl/culling';
3
- import { GeospatialViewport } from '../../types';
3
+ import { GeospatialViewport } from "../../types.js";
4
4
  export type FrameState = {
5
5
  camera: {
6
6
  position: number[];
@@ -1 +1 @@
1
- {"version":3,"file":"frame-state.d.ts","sourceRoot":"","sources":["../../../src/tileset/helpers/frame-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAC,aAAa,EAAQ,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAC,kBAAkB,EAAW,MAAM,aAAa,CAAC;AAEzD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,EAAE,EAAE,MAAM,EAAE,CAAC;KACd,CAAC;IACF,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,eAAe,EAAE,kBAAkB,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAeF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CAwD3F;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,MAAM,GAC3B,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAyBtB"}
1
+ {"version":3,"file":"frame-state.d.ts","sourceRoot":"","sources":["../../../src/tileset/helpers/frame-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAC,aAAa,EAAQ,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAC,kBAAkB,EAAW,uBAAoB;AAEzD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,EAAE,EAAE,MAAM,EAAE,CAAC;KACd,CAAC;IACF,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,eAAe,EAAE,kBAAkB,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAeF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CAwD3F;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,MAAM,GAC3B,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAyBtB"}