@loaders.gl/tiles 4.2.0-alpha.4 → 4.2.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js +34 -32
- package/dist/dist.dev.js +679 -449
- package/dist/dist.min.js +9 -0
- package/dist/index.cjs +265 -326
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts +1 -1
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts.map +1 -1
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +45 -35
- package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +38 -22
- package/dist/tileset/format-i3s/i3s-tile-manager.d.ts +1 -1
- package/dist/tileset/format-i3s/i3s-tile-manager.d.ts.map +1 -1
- package/dist/tileset/format-i3s/i3s-tile-manager.js +68 -69
- package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts +2 -2
- package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts.map +1 -1
- package/dist/tileset/format-i3s/i3s-tileset-traverser.js +79 -57
- package/dist/tileset/helpers/3d-tiles-options.d.ts +1 -1
- package/dist/tileset/helpers/3d-tiles-options.d.ts.map +1 -1
- package/dist/tileset/helpers/3d-tiles-options.js +3 -4
- package/dist/tileset/helpers/bounding-volume.js +269 -128
- package/dist/tileset/helpers/frame-state.d.ts +1 -1
- package/dist/tileset/helpers/frame-state.d.ts.map +1 -1
- package/dist/tileset/helpers/frame-state.js +114 -95
- package/dist/tileset/helpers/i3s-lod.d.ts +2 -2
- package/dist/tileset/helpers/i3s-lod.d.ts.map +1 -1
- package/dist/tileset/helpers/i3s-lod.js +68 -39
- package/dist/tileset/helpers/tiles-3d-lod.js +97 -85
- package/dist/tileset/helpers/transform-utils.js +45 -44
- package/dist/tileset/helpers/zoom.d.ts +1 -1
- package/dist/tileset/helpers/zoom.d.ts.map +1 -1
- package/dist/tileset/helpers/zoom.js +70 -40
- package/dist/tileset/tile-3d.d.ts +7 -6
- package/dist/tileset/tile-3d.d.ts.map +1 -1
- package/dist/tileset/tile-3d.js +608 -399
- package/dist/tileset/tileset-3d.d.ts +7 -6
- package/dist/tileset/tileset-3d.d.ts.map +1 -1
- package/dist/tileset/tileset-3d.js +739 -597
- package/dist/tileset/tileset-cache.d.ts +2 -2
- package/dist/tileset/tileset-cache.d.ts.map +1 -1
- package/dist/tileset/tileset-cache.js +65 -48
- package/dist/tileset/tileset-traverser.d.ts +3 -3
- package/dist/tileset/tileset-traverser.d.ts.map +1 -1
- package/dist/tileset/tileset-traverser.js +282 -220
- package/dist/types.js +0 -1
- package/dist/utils/doubly-linked-list-node.js +17 -9
- package/dist/utils/doubly-linked-list.d.ts +1 -1
- package/dist/utils/doubly-linked-list.d.ts.map +1 -1
- package/dist/utils/doubly-linked-list.js +83 -56
- package/dist/utils/managed-array.js +140 -76
- package/package.json +10 -9
- package/src/tileset/tile-3d.ts +1 -1
- package/src/tileset/tileset-3d.ts +1 -1
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js.map +0 -1
- package/dist/tileset/format-i3s/i3s-pending-tiles-register.js.map +0 -1
- package/dist/tileset/format-i3s/i3s-tile-manager.js.map +0 -1
- package/dist/tileset/format-i3s/i3s-tileset-traverser.js.map +0 -1
- package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
- package/dist/tileset/helpers/bounding-volume.js.map +0 -1
- package/dist/tileset/helpers/frame-state.js.map +0 -1
- package/dist/tileset/helpers/i3s-lod.js.map +0 -1
- package/dist/tileset/helpers/tiles-3d-lod.js.map +0 -1
- package/dist/tileset/helpers/transform-utils.js.map +0 -1
- package/dist/tileset/helpers/zoom.js.map +0 -1
- package/dist/tileset/tile-3d.js.map +0 -1
- package/dist/tileset/tileset-3d.js.map +0 -1
- package/dist/tileset/tileset-cache.js.map +0 -1
- package/dist/tileset/tileset-traverser.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/doubly-linked-list-node.js.map +0 -1
- package/dist/utils/doubly-linked-list.js.map +0 -1
- 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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
160
|
+
|
|
161
|
+
return new TileOrientedBoundingBox(center, halfAxes);
|
|
73
162
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
halfAxes
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
center,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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 +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,
|
|
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"}
|