@loaders.gl/tiles 4.0.0-alpha.9 → 4.0.0-beta.1

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 (33) hide show
  1. package/dist/dist.min.js +144 -80
  2. package/dist/es5/tileset/tileset-3d.js.map +1 -1
  3. package/dist/es5/tileset/tileset-traverser.js +1 -1
  4. package/dist/es5/tileset/tileset-traverser.js.map +1 -1
  5. package/dist/esm/tileset/tileset-3d.js.map +1 -1
  6. package/dist/esm/tileset/tileset-traverser.js +1 -1
  7. package/dist/esm/tileset/tileset-traverser.js.map +1 -1
  8. package/dist/tileset/tileset-3d.d.ts.map +1 -1
  9. package/package.json +4 -4
  10. package/src/tileset/tileset-3d.ts +1 -0
  11. package/src/tileset/tileset-traverser.ts +1 -1
  12. package/dist/bundle.js +0 -5
  13. package/dist/constants.js +0 -39
  14. package/dist/index.js +0 -26
  15. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +0 -54
  16. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +0 -47
  17. package/dist/tileset/format-i3s/i3s-tile-manager.js +0 -80
  18. package/dist/tileset/format-i3s/i3s-tileset-traverser.js +0 -92
  19. package/dist/tileset/helpers/3d-tiles-options.js +0 -9
  20. package/dist/tileset/helpers/bounding-volume.js +0 -293
  21. package/dist/tileset/helpers/frame-state.js +0 -133
  22. package/dist/tileset/helpers/i3s-lod.js +0 -85
  23. package/dist/tileset/helpers/tiles-3d-lod.js +0 -117
  24. package/dist/tileset/helpers/transform-utils.js +0 -53
  25. package/dist/tileset/helpers/zoom.js +0 -89
  26. package/dist/tileset/tile-3d.js +0 -610
  27. package/dist/tileset/tileset-3d.js +0 -715
  28. package/dist/tileset/tileset-cache.js +0 -72
  29. package/dist/tileset/tileset-traverser.js +0 -300
  30. package/dist/types.js +0 -2
  31. package/dist/utils/doubly-linked-list-node.js +0 -18
  32. package/dist/utils/doubly-linked-list.js +0 -97
  33. package/dist/utils/managed-array.js +0 -152
@@ -1,54 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Tileset3DTraverser = void 0;
5
- // This file is derived from the Cesium code base under Apache 2 license
6
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
7
- const constants_1 = require("../../constants");
8
- const tileset_traverser_1 = require("../tileset-traverser");
9
- class Tileset3DTraverser extends tileset_traverser_1.TilesetTraverser {
10
- compareDistanceToCamera(a, b) {
11
- // Sort by farthest child first since this is going on a stack
12
- return b._distanceToCamera === 0 && a._distanceToCamera === 0
13
- ? b._centerZDepth - a._centerZDepth
14
- : b._distanceToCamera - a._distanceToCamera;
15
- }
16
- updateTileVisibility(tile, frameState) {
17
- super.updateTileVisibility(tile, frameState);
18
- // Optimization - if none of the tile's children are visible then this tile isn't visible
19
- if (!tile.isVisibleAndInRequestVolume) {
20
- return;
21
- }
22
- const hasChildren = tile.children.length > 0;
23
- if (tile.hasTilesetContent && hasChildren) {
24
- // Use the root tile's visibility instead of this tile's visibility.
25
- // The root tile may be culled by the children bounds optimization in which
26
- // case this tile should also be culled.
27
- const firstChild = tile.children[0];
28
- this.updateTileVisibility(firstChild, frameState);
29
- tile._visible = firstChild._visible;
30
- return;
31
- }
32
- if (this.meetsScreenSpaceErrorEarly(tile, frameState)) {
33
- tile._visible = false;
34
- return;
35
- }
36
- const replace = tile.refine === constants_1.TILE_REFINEMENT.REPLACE;
37
- const useOptimization = tile._optimChildrenWithinParent === constants_1.TILE3D_OPTIMIZATION_HINT.USE_OPTIMIZATION;
38
- if (replace && useOptimization && hasChildren) {
39
- if (!this.anyChildrenVisible(tile, frameState)) {
40
- tile._visible = false;
41
- return;
42
- }
43
- }
44
- }
45
- meetsScreenSpaceErrorEarly(tile, frameState) {
46
- const { parent } = tile;
47
- if (!parent || parent.hasTilesetContent || parent.refine !== constants_1.TILE_REFINEMENT.ADD) {
48
- return false;
49
- }
50
- // Use parent's geometric error with child's box to see if the tile already meet the SSE
51
- return !this.shouldRefine(tile, frameState, true);
52
- }
53
- }
54
- exports.Tileset3DTraverser = Tileset3DTraverser;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.I3SPendingTilesRegister = void 0;
4
- /**
5
- * Counter to register pending tile headers for the particular frameNumber
6
- * Until all tiles are loaded we won't call `onTraversalEnd` callback
7
- */
8
- class I3SPendingTilesRegister {
9
- constructor() {
10
- this.frameNumberMap = new Map();
11
- }
12
- /**
13
- * Register a new pending tile header for the particular frameNumber
14
- * @param viewportId
15
- * @param frameNumber
16
- */
17
- register(viewportId, frameNumber) {
18
- const viewportMap = this.frameNumberMap.get(viewportId) || new Map();
19
- const oldCount = viewportMap.get(frameNumber) || 0;
20
- viewportMap.set(frameNumber, oldCount + 1);
21
- this.frameNumberMap.set(viewportId, viewportMap);
22
- }
23
- /**
24
- * Deregister a pending tile header for the particular frameNumber
25
- * @param viewportId
26
- * @param frameNumber
27
- */
28
- deregister(viewportId, frameNumber) {
29
- const viewportMap = this.frameNumberMap.get(viewportId);
30
- if (!viewportMap) {
31
- return;
32
- }
33
- const oldCount = viewportMap.get(frameNumber) || 1;
34
- viewportMap.set(frameNumber, oldCount - 1);
35
- }
36
- /**
37
- * Check is there are no pending tile headers registered for the particular frameNumber
38
- * @param viewportId
39
- * @param frameNumber
40
- * @returns
41
- */
42
- isZero(viewportId, frameNumber) {
43
- const count = this.frameNumberMap.get(viewportId)?.get(frameNumber) || 0;
44
- return count === 0;
45
- }
46
- }
47
- exports.I3SPendingTilesRegister = I3SPendingTilesRegister;
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.I3STileManager = void 0;
4
- const i3s_pending_tiles_register_1 = require("./i3s-pending-tiles-register");
5
- const STATUS = {
6
- REQUESTED: 'REQUESTED',
7
- COMPLETED: 'COMPLETED',
8
- ERROR: 'ERROR'
9
- };
10
- // A helper class to manage tile metadata fetching
11
- class I3STileManager {
12
- constructor() {
13
- this.pendingTilesRegister = new i3s_pending_tiles_register_1.I3SPendingTilesRegister();
14
- this._statusMap = {};
15
- }
16
- /**
17
- * Add request to map
18
- * @param request - node metadata request
19
- * @param key - unique key
20
- * @param callback - callback after request completed
21
- * @param frameState - frameState data
22
- */
23
- add(request, key, callback, frameState) {
24
- if (!this._statusMap[key]) {
25
- const { frameNumber, viewport: { id } } = frameState;
26
- this._statusMap[key] = { request, callback, key, frameState, status: STATUS.REQUESTED };
27
- // Register pending request for the frameNumber
28
- this.pendingTilesRegister.register(id, frameNumber);
29
- request()
30
- .then((data) => {
31
- this._statusMap[key].status = STATUS.COMPLETED;
32
- const { frameNumber: actualFrameNumber, viewport: { id } } = this._statusMap[key].frameState;
33
- // Deregister pending request for the frameNumber
34
- this.pendingTilesRegister.deregister(id, actualFrameNumber);
35
- this._statusMap[key].callback(data, frameState);
36
- })
37
- .catch((error) => {
38
- this._statusMap[key].status = STATUS.ERROR;
39
- const { frameNumber: actualFrameNumber, viewport: { id } } = this._statusMap[key].frameState;
40
- // Deregister pending request for the frameNumber
41
- this.pendingTilesRegister.deregister(id, actualFrameNumber);
42
- callback(error);
43
- });
44
- }
45
- }
46
- /**
47
- * Update request if it is still actual for the new frameState
48
- * @param key - unique key
49
- * @param frameState - frameState data
50
- */
51
- update(key, frameState) {
52
- if (this._statusMap[key]) {
53
- // Deregister pending request for the old frameNumber
54
- const { frameNumber, viewport: { id } } = this._statusMap[key].frameState;
55
- this.pendingTilesRegister.deregister(id, frameNumber);
56
- // Register pending request for the new frameNumber
57
- const { frameNumber: newFrameNumber, viewport: { id: newViewportId } } = frameState;
58
- this.pendingTilesRegister.register(newViewportId, newFrameNumber);
59
- this._statusMap[key].frameState = frameState;
60
- }
61
- }
62
- /**
63
- * Find request in the map
64
- * @param key - unique key
65
- * @returns
66
- */
67
- find(key) {
68
- return this._statusMap[key];
69
- }
70
- /**
71
- * Check it there are pending tile headers for the particular frameNumber
72
- * @param viewportId
73
- * @param frameNumber
74
- * @returns
75
- */
76
- hasPendingTiles(viewportId, frameNumber) {
77
- return !this.pendingTilesRegister.isZero(viewportId, frameNumber);
78
- }
79
- }
80
- exports.I3STileManager = I3STileManager;
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.I3STilesetTraverser = void 0;
4
- const core_1 = require("@loaders.gl/core");
5
- const tileset_traverser_1 = require("../tileset-traverser");
6
- const i3s_lod_1 = require("../helpers/i3s-lod");
7
- const tile_3d_1 = require("../tile-3d");
8
- const i3s_tile_manager_1 = require("./i3s-tile-manager");
9
- class I3STilesetTraverser extends tileset_traverser_1.TilesetTraverser {
10
- constructor(options) {
11
- super(options);
12
- this._tileManager = new i3s_tile_manager_1.I3STileManager();
13
- }
14
- /**
15
- * Check if there are no penging tile header requests,
16
- * that means the traversal is finished and we can call
17
- * following-up callbacks.
18
- */
19
- traversalFinished(frameState) {
20
- return !this._tileManager.hasPendingTiles(frameState.viewport.id, this._frameNumber || 0);
21
- }
22
- shouldRefine(tile, frameState) {
23
- tile._lodJudge = (0, i3s_lod_1.getLodStatus)(tile, frameState);
24
- return tile._lodJudge === 'DIG';
25
- }
26
- updateChildTiles(tile, frameState) {
27
- const children = tile.header.children || [];
28
- // children which are already fetched and constructed as Tile3D instances
29
- const childTiles = tile.children;
30
- const tileset = tile.tileset;
31
- for (const child of children) {
32
- const extendedId = `${child.id}-${frameState.viewport.id}`;
33
- // if child tile is not fetched
34
- const childTile = childTiles && childTiles.find((t) => t.id === extendedId);
35
- if (!childTile) {
36
- let request = () => this._loadTile(child.id, tileset);
37
- const cachedRequest = this._tileManager.find(extendedId);
38
- if (!cachedRequest) {
39
- // eslint-disable-next-line max-depth
40
- if (tileset.tileset.nodePages) {
41
- request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id);
42
- }
43
- this._tileManager.add(request, extendedId, (header) => this._onTileLoad(header, tile, extendedId), frameState);
44
- }
45
- else {
46
- // update frameNumber since it is still needed in current frame
47
- this._tileManager.update(extendedId, frameState);
48
- }
49
- }
50
- else if (childTile) {
51
- // if child tile is fetched and available
52
- this.updateTile(childTile, frameState);
53
- }
54
- }
55
- return false;
56
- }
57
- async _loadTile(nodeId, tileset) {
58
- const { loader } = tileset;
59
- const nodeUrl = tileset.getTileUrl(`${tileset.url}/nodes/${nodeId}`);
60
- // load metadata
61
- const options = {
62
- ...tileset.loadOptions,
63
- i3s: {
64
- ...tileset.loadOptions.i3s,
65
- isTileHeader: true
66
- }
67
- };
68
- return await (0, core_1.load)(nodeUrl, loader, options);
69
- }
70
- /**
71
- * The callback to init Tile3D instance after loading the tile JSON
72
- * @param {Object} header - the tile JSON from a dataset
73
- * @param {Tile3D} tile - the parent Tile3D instance
74
- * @param {string} extendedId - optional ID to separate copies of a tile for different viewports.
75
- * const extendedId = `${tile.id}-${frameState.viewport.id}`;
76
- * @return {void}
77
- */
78
- _onTileLoad(header, tile, extendedId) {
79
- // after child tile is fetched
80
- const childTile = new tile_3d_1.Tile3D(tile.tileset, header, tile, extendedId);
81
- tile.children.push(childTile);
82
- const frameState = this._tileManager.find(childTile.id).frameState;
83
- this.updateTile(childTile, frameState);
84
- // after tile fetched, resume traversal if still in current update/traversal frame
85
- if (this._frameNumber === frameState.frameNumber &&
86
- (this.traversalFinished(frameState) ||
87
- new Date().getTime() - this.lastUpdate > this.updateDebounceTime)) {
88
- this.executeTraversal(childTile, frameState);
89
- }
90
- }
91
- }
92
- exports.I3STilesetTraverser = I3STilesetTraverser;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.get3dTilesOptions = void 0;
4
- function get3dTilesOptions(tileset) {
5
- return {
6
- assetGltfUpAxis: (tileset.asset && tileset.asset.gltfUpAxis) || 'Y'
7
- };
8
- }
9
- exports.get3dTilesOptions = get3dTilesOptions;
@@ -1,293 +0,0 @@
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.getCartographicBounds = 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();
12
- function defined(x) {
13
- return x !== undefined && x !== null;
14
- }
15
- // const scratchMatrix = new Matrix3();
16
- const scratchPoint = new core_1.Vector3();
17
- const scratchScale = new core_1.Vector3();
18
- const scratchNorthWest = new core_1.Vector3();
19
- const scratchSouthEast = new core_1.Vector3();
20
- // const scratchRectangle = new Rectangle();
21
- // const scratchOrientedBoundingBox = new OrientedBoundingBox();
22
- // const scratchTransform = new Matrix4();
23
- /**
24
- * Create a bounding volume from the tile's bounding volume header.
25
- * @param {Object} boundingVolumeHeader The tile's bounding volume header.
26
- * @param {Matrix4} transform The transform to apply to the bounding volume.
27
- * @param [result] The object onto which to store the result.
28
- * @returns The modified result parameter or a new TileBoundingVolume instance if none was provided.
29
- */
30
- function createBoundingVolume(boundingVolumeHeader, transform, result) {
31
- (0, loader_utils_1.assert)(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
32
- // boundingVolume schema:
33
- // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json
34
- if (boundingVolumeHeader.box) {
35
- return createBox(boundingVolumeHeader.box, transform, result);
36
- }
37
- if (boundingVolumeHeader.region) {
38
- // [west, south, east, north, minimum height, maximum height]
39
- // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.
40
- // Heights are in meters above (or below) the WGS 84 ellipsoid.
41
- const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
42
- const northWest = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian([(0, core_1.degrees)(west), (0, core_1.degrees)(north), minHeight], scratchNorthWest);
43
- const southEast = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian([(0, core_1.degrees)(east), (0, core_1.degrees)(south), maxHeight], scratchSouthEast);
44
- const centerInCartesian = new core_1.Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);
45
- const radius = new core_1.Vector3().subVectors(northWest, southEast).len() / 2.0;
46
- // TODO improve region boundingVolume
47
- // for now, create a sphere as the boundingVolume instead of box
48
- return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new core_1.Matrix4());
49
- }
50
- if (boundingVolumeHeader.sphere) {
51
- return createSphere(boundingVolumeHeader.sphere, transform, result);
52
- }
53
- throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
54
- }
55
- exports.createBoundingVolume = createBoundingVolume;
56
- /**
57
- * Calculate the cartographic bounding box the tile's bounding volume.
58
- * @param {Object} boundingVolumeHeader The tile's bounding volume header.
59
- * @param {BoundingVolume} boundingVolume The bounding volume.
60
- * @returns {CartographicBounds}
61
- */
62
- function getCartographicBounds(boundingVolumeHeader, boundingVolume) {
63
- // boundingVolume schema:
64
- // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json
65
- if (boundingVolumeHeader.box) {
66
- return orientedBoundingBoxToCartographicBounds(boundingVolume);
67
- }
68
- if (boundingVolumeHeader.region) {
69
- // [west, south, east, north, minimum height, maximum height]
70
- // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.
71
- // Heights are in meters above (or below) the WGS 84 ellipsoid.
72
- const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
73
- return [
74
- [(0, core_1.degrees)(west), (0, core_1.degrees)(south), minHeight],
75
- [(0, core_1.degrees)(east), (0, core_1.degrees)(north), maxHeight]
76
- ];
77
- }
78
- if (boundingVolumeHeader.sphere) {
79
- return boundingSphereToCartographicBounds(boundingVolume);
80
- }
81
- throw new Error('Unkown boundingVolume type');
82
- }
83
- exports.getCartographicBounds = getCartographicBounds;
84
- function createBox(box, transform, result) {
85
- // https://math.gl/modules/culling/docs/api-reference/oriented-bounding-box
86
- // 1. A half-axes based representation.
87
- // box: An array of 12 numbers that define an oriented bounding box.
88
- // The first three elements define the x, y, and z values for the center of the box.
89
- // The next three elements (with indices 3, 4, and 5) define the x axis direction and half-length.
90
- // The next three elements (indices 6, 7, and 8) define the y axis direction and half-length.
91
- // The last three elements (indices 9, 10, and 11) define the z axis direction and half-length.
92
- // 2. A half-size-quaternion based representation.
93
- // box: An array of 10 numbers that define an oriented bounding box.
94
- // 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.
95
- // The next three elements (with indices 3, 4, and 5) define the halfSize.
96
- // The last four elements (indices 6, 7, 8 and 10) define the quaternion.
97
- const center = new core_1.Vector3(box[0], box[1], box[2]);
98
- transform.transform(center, center);
99
- let origin = [];
100
- if (box.length === 10) {
101
- const halfSize = box.slice(3, 6);
102
- const quaternion = new core_1.Quaternion();
103
- quaternion.fromArray(box, 6);
104
- const x = new core_1.Vector3([1, 0, 0]);
105
- const y = new core_1.Vector3([0, 1, 0]);
106
- const z = new core_1.Vector3([0, 0, 1]);
107
- x.transformByQuaternion(quaternion);
108
- x.scale(halfSize[0]);
109
- y.transformByQuaternion(quaternion);
110
- y.scale(halfSize[1]);
111
- z.transformByQuaternion(quaternion);
112
- z.scale(halfSize[2]);
113
- origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];
114
- }
115
- else {
116
- origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];
117
- }
118
- const xAxis = transform.transformAsVector(origin.slice(0, 3));
119
- const yAxis = transform.transformAsVector(origin.slice(3, 6));
120
- const zAxis = transform.transformAsVector(origin.slice(6, 9));
121
- const halfAxes = new core_1.Matrix3([
122
- xAxis[0],
123
- xAxis[1],
124
- xAxis[2],
125
- yAxis[0],
126
- yAxis[1],
127
- yAxis[2],
128
- zAxis[0],
129
- zAxis[1],
130
- zAxis[2]
131
- ]);
132
- if (defined(result)) {
133
- result.center = center;
134
- result.halfAxes = halfAxes;
135
- return result;
136
- }
137
- return new culling_1.OrientedBoundingBox(center, halfAxes);
138
- }
139
- /*
140
- function createBoxFromTransformedRegion(region, transform, initialTransform, result) {
141
- const rectangle = Rectangle.unpack(region, 0, scratchRectangle);
142
- const minimumHeight = region[4];
143
- const maximumHeight = region[5];
144
-
145
- const orientedBoundingBox = OrientedBoundingBox.fromRectangle(
146
- rectangle,
147
- minimumHeight,
148
- maximumHeight,
149
- Ellipsoid.WGS84,
150
- scratchOrientedBoundingBox
151
- );
152
- const center = orientedBoundingBox.center;
153
- const halfAxes = orientedBoundingBox.halfAxes;
154
-
155
- // A region bounding volume is not transformed by the transform in the tileset JSON,
156
- // but may be transformed by additional transforms applied in Cesium.
157
- // This is why the transform is calculated as the difference between the initial transform and the current transform.
158
- transform = Matrix4.multiplyTransformation(
159
- transform,
160
- Matrix4.inverseTransformation(initialTransform, scratchTransform),
161
- scratchTransform
162
- );
163
- center = Matrix4.multiplyByPoint(transform, center, center);
164
- const rotationScale = Matrix4.getRotation(transform, scratchMatrix);
165
- halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
166
-
167
- if (defined(result) && result instanceof TileOrientedBoundingBox) {
168
- result.update(center, halfAxes);
169
- return result;
170
- }
171
-
172
- return new TileOrientedBoundingBox(center, halfAxes);
173
- }
174
-
175
- function createRegion(region, transform, initialTransform, result) {
176
- if (!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)) {
177
- return createBoxFromTransformedRegion(region, transform, initialTransform, result);
178
- }
179
-
180
- if (defined(result)) {
181
- return result;
182
- }
183
-
184
- const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);
185
-
186
- return new TileBoundingRegion({
187
- rectangle: rectangleRegion,
188
- minimumHeight: region[4],
189
- maximumHeight: region[5]
190
- });
191
- }
192
- */
193
- function createSphere(sphere, transform, result) {
194
- // Find the transformed center
195
- const center = new core_1.Vector3(sphere[0], sphere[1], sphere[2]);
196
- transform.transform(center, center);
197
- const scale = transform.getScale(scratchScale);
198
- const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);
199
- const radius = sphere[3] * uniformScale;
200
- if (defined(result)) {
201
- result.center = center;
202
- result.radius = radius;
203
- return result;
204
- }
205
- return new culling_1.BoundingSphere(center, radius);
206
- }
207
- /**
208
- * Convert a bounding volume defined by OrientedBoundingBox to cartographic bounds
209
- * @returns {CartographicBounds}
210
- */
211
- function orientedBoundingBoxToCartographicBounds(boundingVolume) {
212
- const result = emptyCartographicBounds();
213
- const { halfAxes } = boundingVolume;
214
- const xAxis = new core_1.Vector3(halfAxes.getColumn(0));
215
- const yAxis = new core_1.Vector3(halfAxes.getColumn(1));
216
- const zAxis = new core_1.Vector3(halfAxes.getColumn(2));
217
- // Test all 8 corners of the box
218
- for (let x = 0; x < 2; x++) {
219
- for (let y = 0; y < 2; y++) {
220
- for (let z = 0; z < 2; z++) {
221
- scratchPoint.copy(boundingVolume.center);
222
- scratchPoint.add(xAxis);
223
- scratchPoint.add(yAxis);
224
- scratchPoint.add(zAxis);
225
- addToCartographicBounds(result, scratchPoint);
226
- zAxis.negate();
227
- }
228
- yAxis.negate();
229
- }
230
- xAxis.negate();
231
- }
232
- return result;
233
- }
234
- /**
235
- * Convert a bounding volume defined by BoundingSphere to cartographic bounds
236
- * @returns {CartographicBounds}
237
- */
238
- function boundingSphereToCartographicBounds(boundingVolume) {
239
- const result = emptyCartographicBounds();
240
- const { center, radius } = boundingVolume;
241
- const point = geospatial_1.Ellipsoid.WGS84.scaleToGeodeticSurface(center, scratchPoint);
242
- let zAxis;
243
- if (point) {
244
- zAxis = geospatial_1.Ellipsoid.WGS84.geodeticSurfaceNormal(point);
245
- }
246
- else {
247
- zAxis = new core_1.Vector3(0, 0, 1);
248
- }
249
- let xAxis = new core_1.Vector3(zAxis[2], -zAxis[1], 0);
250
- if (xAxis.len() > 0) {
251
- xAxis.normalize();
252
- }
253
- else {
254
- xAxis = new core_1.Vector3(0, 1, 0);
255
- }
256
- const yAxis = xAxis.clone().cross(zAxis);
257
- // Test 6 end points of the 3 axes
258
- for (const axis of [xAxis, yAxis, zAxis]) {
259
- scratchScale.copy(axis).scale(radius);
260
- for (let dir = 0; dir < 2; dir++) {
261
- scratchPoint.copy(center);
262
- scratchPoint.add(scratchScale);
263
- addToCartographicBounds(result, scratchPoint);
264
- // Flip the axis
265
- scratchScale.negate();
266
- }
267
- }
268
- return result;
269
- }
270
- /**
271
- * Create a new cartographic bounds that contains no points
272
- * @returns {CartographicBounds}
273
- */
274
- function emptyCartographicBounds() {
275
- return [
276
- [Infinity, Infinity, Infinity],
277
- [-Infinity, -Infinity, -Infinity]
278
- ];
279
- }
280
- /**
281
- * Add a point to the target cartographic bounds
282
- * @param {CartographicBounds} target
283
- * @param {Vector3} cartesian coordinates of the point to add
284
- */
285
- function addToCartographicBounds(target, cartesian) {
286
- geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(cartesian, scratchPoint);
287
- target[0][0] = Math.min(target[0][0], scratchPoint[0]);
288
- target[0][1] = Math.min(target[0][1], scratchPoint[1]);
289
- target[0][2] = Math.min(target[0][2], scratchPoint[2]);
290
- target[1][0] = Math.max(target[1][0], scratchPoint[0]);
291
- target[1][1] = Math.max(target[1][1], scratchPoint[1]);
292
- target[1][2] = Math.max(target[1][2], scratchPoint[2]);
293
- }