@loaders.gl/3d-tiles 3.4.0-alpha.1 → 3.4.0-alpha.3
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/cesium-ion-loader.d.ts.map +1 -1
- package/dist/cesium-ion-loader.js +1 -0
- package/dist/dist.min.js +2517 -299
- package/dist/es5/cesium-ion-loader.js +23 -27
- package/dist/es5/cesium-ion-loader.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/classes/helpers/tile-3d-accessor-utils.js +0 -2
- package/dist/es5/lib/classes/helpers/tile-3d-accessor-utils.js.map +1 -1
- package/dist/es5/lib/classes/tile-3d-batch-table-hierarchy.js +0 -6
- package/dist/es5/lib/classes/tile-3d-batch-table-hierarchy.js.map +1 -1
- package/dist/es5/lib/classes/tile-3d-batch-table.js +2 -19
- package/dist/es5/lib/classes/tile-3d-batch-table.js.map +1 -1
- package/dist/es5/lib/classes/tile-3d-feature-table.js +1 -4
- package/dist/es5/lib/classes/tile-3d-feature-table.js.map +1 -1
- package/dist/es5/lib/constants.js +0 -2
- package/dist/es5/lib/constants.js.map +1 -1
- package/dist/es5/lib/encoders/encode-3d-tile-batched-model.js +0 -5
- package/dist/es5/lib/encoders/encode-3d-tile-batched-model.js.map +1 -1
- package/dist/es5/lib/encoders/encode-3d-tile-composite.js +0 -2
- package/dist/es5/lib/encoders/encode-3d-tile-composite.js.map +1 -1
- package/dist/es5/lib/encoders/encode-3d-tile-instanced-model.js +0 -3
- package/dist/es5/lib/encoders/encode-3d-tile-instanced-model.js.map +1 -1
- package/dist/es5/lib/encoders/encode-3d-tile-point-cloud.js +0 -3
- package/dist/es5/lib/encoders/encode-3d-tile-point-cloud.js.map +1 -1
- package/dist/es5/lib/encoders/encode-3d-tile.js +0 -1
- package/dist/es5/lib/encoders/encode-3d-tile.js.map +1 -1
- package/dist/es5/lib/encoders/helpers/encode-3d-tile-header.js +0 -3
- package/dist/es5/lib/encoders/helpers/encode-3d-tile-header.js.map +1 -1
- package/dist/es5/lib/ion/ion.js +109 -117
- package/dist/es5/lib/ion/ion.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -3
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -3
- package/dist/es5/lib/parsers/helpers/normalize-3d-tile-positions.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js +161 -131
- package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js +34 -42
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js +0 -3
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js +93 -100
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js +0 -5
- package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -1
- package/dist/es5/lib/parsers/helpers/parse-utils.js +0 -2
- package/dist/es5/lib/parsers/helpers/parse-utils.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js +14 -16
- package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-composite.js +24 -27
- package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +12 -14
- package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-header.js +152 -148
- package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js +10 -22
- package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js +111 -119
- package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile.js +41 -44
- package/dist/es5/lib/parsers/parse-3d-tile.js.map +1 -1
- package/dist/es5/lib/utils/obb/s2-corners-to-obb.js +30 -0
- package/dist/es5/lib/utils/obb/s2-corners-to-obb.js.map +1 -0
- package/dist/es5/lib/utils/s2/converters/s2-to-boundary.js +44 -0
- package/dist/es5/lib/utils/s2/converters/s2-to-boundary.js.map +1 -0
- package/dist/es5/lib/utils/s2/converters/s2-to-obb-points.js +30 -0
- package/dist/es5/lib/utils/s2/converters/s2-to-obb-points.js.map +1 -0
- package/dist/es5/lib/utils/s2/converters/s2-to-region.js +52 -0
- package/dist/es5/lib/utils/s2/converters/s2-to-region.js.map +1 -0
- package/dist/es5/lib/utils/s2/index.js +90 -0
- package/dist/es5/lib/utils/s2/index.js.map +1 -0
- package/dist/es5/lib/utils/s2/s2-geometry-functions.js +19 -0
- package/dist/es5/lib/utils/s2/s2-geometry-functions.js.map +1 -0
- package/dist/es5/lib/utils/s2/s2-token-functions.js +41 -0
- package/dist/es5/lib/utils/s2/s2-token-functions.js.map +1 -0
- package/dist/es5/lib/utils/s2/s2geometry/s2-cell-utils.js +22 -0
- package/dist/es5/lib/utils/s2/s2geometry/s2-cell-utils.js.map +1 -0
- package/dist/es5/lib/utils/s2/s2geometry/s2-geometry.js +207 -0
- package/dist/es5/lib/utils/s2/s2geometry/s2-geometry.js.map +1 -0
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
- package/dist/es5/tile-3d-writer.js.map +1 -1
- package/dist/es5/tiles-3d-loader.js +59 -65
- package/dist/es5/tiles-3d-loader.js.map +1 -1
- package/dist/esm/bundle.js +0 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/cesium-ion-loader.js +0 -2
- package/dist/esm/cesium-ion-loader.js.map +1 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/classes/helpers/tile-3d-accessor-utils.js +0 -1
- package/dist/esm/lib/classes/helpers/tile-3d-accessor-utils.js.map +1 -1
- package/dist/esm/lib/classes/tile-3d-batch-table-hierarchy.js +0 -7
- package/dist/esm/lib/classes/tile-3d-batch-table-hierarchy.js.map +1 -1
- package/dist/esm/lib/classes/tile-3d-batch-table.js +0 -13
- package/dist/esm/lib/classes/tile-3d-batch-table.js.map +1 -1
- package/dist/esm/lib/classes/tile-3d-feature-table.js +0 -3
- package/dist/esm/lib/classes/tile-3d-feature-table.js.map +1 -1
- package/dist/esm/lib/constants.js +0 -3
- package/dist/esm/lib/constants.js.map +1 -1
- package/dist/esm/lib/encoders/encode-3d-tile-batched-model.js +0 -8
- package/dist/esm/lib/encoders/encode-3d-tile-batched-model.js.map +1 -1
- package/dist/esm/lib/encoders/encode-3d-tile-composite.js +0 -4
- package/dist/esm/lib/encoders/encode-3d-tile-composite.js.map +1 -1
- package/dist/esm/lib/encoders/encode-3d-tile-instanced-model.js +0 -6
- package/dist/esm/lib/encoders/encode-3d-tile-instanced-model.js.map +1 -1
- package/dist/esm/lib/encoders/encode-3d-tile-point-cloud.js +0 -5
- package/dist/esm/lib/encoders/encode-3d-tile-point-cloud.js.map +1 -1
- package/dist/esm/lib/encoders/encode-3d-tile.js +0 -2
- package/dist/esm/lib/encoders/encode-3d-tile.js.map +1 -1
- package/dist/esm/lib/encoders/helpers/encode-3d-tile-header.js +0 -3
- package/dist/esm/lib/encoders/helpers/encode-3d-tile-header.js.map +1 -1
- package/dist/esm/lib/ion/ion.js +0 -9
- package/dist/esm/lib/ion/ion.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -4
- package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -4
- package/dist/esm/lib/parsers/helpers/normalize-3d-tile-positions.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js +50 -19
- package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js +1 -8
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-header.js +0 -4
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -6
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js +0 -6
- package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -1
- package/dist/esm/lib/parsers/helpers/parse-utils.js +0 -4
- package/dist/esm/lib/parsers/helpers/parse-utils.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-batched-model.js +0 -3
- package/dist/esm/lib/parsers/parse-3d-tile-batched-model.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-composite.js +0 -6
- package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-header.js +13 -6
- package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js +0 -12
- package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js +0 -6
- package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile.js +0 -4
- package/dist/esm/lib/parsers/parse-3d-tile.js.map +1 -1
- package/dist/esm/lib/utils/obb/s2-corners-to-obb.js +23 -0
- package/dist/esm/lib/utils/obb/s2-corners-to-obb.js.map +1 -0
- package/dist/esm/lib/utils/s2/converters/s2-to-boundary.js +40 -0
- package/dist/esm/lib/utils/s2/converters/s2-to-boundary.js.map +1 -0
- package/dist/esm/lib/utils/s2/converters/s2-to-obb-points.js +24 -0
- package/dist/esm/lib/utils/s2/converters/s2-to-obb-points.js.map +1 -0
- package/dist/esm/lib/utils/s2/converters/s2-to-region.js +42 -0
- package/dist/esm/lib/utils/s2/converters/s2-to-region.js.map +1 -0
- package/dist/esm/lib/utils/s2/index.js +7 -0
- package/dist/esm/lib/utils/s2/index.js.map +1 -0
- package/dist/esm/lib/utils/s2/s2-geometry-functions.js +12 -0
- package/dist/esm/lib/utils/s2/s2-geometry-functions.js.map +1 -0
- package/dist/esm/lib/utils/s2/s2-token-functions.js +32 -0
- package/dist/esm/lib/utils/s2/s2-token-functions.js.map +1 -0
- package/dist/esm/lib/utils/s2/s2geometry/s2-cell-utils.js +15 -0
- package/dist/esm/lib/utils/s2/s2geometry/s2-cell-utils.js.map +1 -0
- package/dist/esm/lib/utils/s2/s2geometry/s2-geometry.js +186 -0
- package/dist/esm/lib/utils/s2/s2geometry/s2-geometry.js.map +1 -0
- package/dist/esm/lib/utils/version.js +1 -2
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/esm/tile-3d-subtree-loader.js +0 -1
- package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
- package/dist/esm/tile-3d-writer.js +0 -1
- package/dist/esm/tile-3d-writer.js.map +1 -1
- package/dist/esm/tiles-3d-loader.js +0 -1
- package/dist/esm/tiles-3d-loader.js.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +11 -0
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +60 -11
- package/dist/lib/parsers/parse-3d-tile-batched-model.js +1 -1
- package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-header.js +13 -1
- package/dist/lib/utils/obb/s2-corners-to-obb.d.ts +15 -0
- package/dist/lib/utils/obb/s2-corners-to-obb.d.ts.map +1 -0
- package/dist/lib/utils/obb/s2-corners-to-obb.js +37 -0
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +9 -0
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -0
- package/dist/lib/utils/s2/converters/s2-to-boundary.js +61 -0
- package/dist/lib/utils/s2/converters/s2-to-obb-points.d.ts +15 -0
- package/dist/lib/utils/s2/converters/s2-to-obb-points.d.ts.map +1 -0
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js +36 -0
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts +13 -0
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -0
- package/dist/lib/utils/s2/converters/s2-to-region.js +59 -0
- package/dist/lib/utils/s2/index.d.ts +8 -0
- package/dist/lib/utils/s2/index.d.ts.map +1 -0
- package/dist/lib/utils/s2/index.js +23 -0
- package/dist/lib/utils/s2/s2-geometry-functions.d.ts +14 -0
- package/dist/lib/utils/s2/s2-geometry-functions.d.ts.map +1 -0
- package/dist/lib/utils/s2/s2-geometry-functions.js +29 -0
- package/dist/lib/utils/s2/s2-token-functions.d.ts +23 -0
- package/dist/lib/utils/s2/s2-token-functions.d.ts.map +1 -0
- package/dist/lib/utils/s2/s2-token-functions.js +68 -0
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +14 -0
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -0
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +32 -0
- package/dist/lib/utils/s2/s2geometry/s2-geometry.d.ts +52 -0
- package/dist/lib/utils/s2/s2geometry/s2-geometry.d.ts.map +1 -0
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js +260 -0
- package/package.json +9 -8
- package/src/cesium-ion-loader.ts +1 -0
- package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +102 -13
- package/src/lib/parsers/parse-3d-tile-header.ts +17 -1
- package/src/lib/utils/obb/s2-corners-to-obb.ts +51 -0
- package/src/lib/utils/s2/converters/s2-to-boundary.ts +67 -0
- package/src/lib/utils/s2/converters/s2-to-obb-points.ts +46 -0
- package/src/lib/utils/s2/converters/s2-to-region.ts +69 -0
- package/src/lib/utils/s2/index.ts +17 -0
- package/src/lib/utils/s2/s2-geometry-functions.ts +28 -0
- package/src/lib/utils/s2/s2-token-functions.ts +67 -0
- package/src/lib/utils/s2/s2geometry/s2-cell-utils.ts +33 -0
- package/src/lib/utils/s2/s2geometry/s2-geometry.ts +296 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// math.gl, MIT license
|
|
3
|
+
/*
|
|
4
|
+
Adapted from s2-geometry under ISC License (ISC)
|
|
5
|
+
Copyright (c) 2012-2016, Jon Atkins <github@jonatkins.com>
|
|
6
|
+
Copyright (c) 2016, AJ ONeal <aj@daplie.com>
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getCornerLngLats = exports.getS2LngLatFromS2Cell = exports.XYZToLngLat = exports.FaceUVToXYZ = exports.STToUV = exports.IJToST = exports.getS2CellIdFromQuadkey = exports.getS2QuadkeyFromCellId = exports.getS2CellFromQuadKey = void 0;
|
|
15
|
+
const long_1 = __importDefault(require("long"));
|
|
16
|
+
//
|
|
17
|
+
// Functional Style
|
|
18
|
+
//
|
|
19
|
+
const FACE_BITS = 3;
|
|
20
|
+
const MAX_LEVEL = 30;
|
|
21
|
+
const POS_BITS = 2 * MAX_LEVEL + 1; // 61 (60 bits of data, 1 bit lsb marker)
|
|
22
|
+
const RADIAN_TO_DEGREE = 180 / Math.PI;
|
|
23
|
+
/**
|
|
24
|
+
* Return the S2Cell
|
|
25
|
+
* @param hilbertQuadkey {string} A string that is the Hilbert quad key (containing /)
|
|
26
|
+
* @returns {@link S2Cell}
|
|
27
|
+
*/
|
|
28
|
+
// eslint-disable-next-line max-statements
|
|
29
|
+
function getS2CellFromQuadKey(hilbertQuadkey) {
|
|
30
|
+
if (hilbertQuadkey.length === 0) {
|
|
31
|
+
throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
|
|
32
|
+
}
|
|
33
|
+
const parts = hilbertQuadkey.split('/');
|
|
34
|
+
const face = parseInt(parts[0], 10); // face is in the range [0..5]
|
|
35
|
+
const position = parts[1]; // position is in the range [0..4**30-1]
|
|
36
|
+
const maxLevel = position.length;
|
|
37
|
+
let level = 0;
|
|
38
|
+
const point = [0, 0];
|
|
39
|
+
for (let i = maxLevel - 1; i >= 0; i--) {
|
|
40
|
+
level = maxLevel - i;
|
|
41
|
+
const bit = position[i];
|
|
42
|
+
let rx = 0;
|
|
43
|
+
let ry = 0;
|
|
44
|
+
if (bit === '1') {
|
|
45
|
+
ry = 1;
|
|
46
|
+
}
|
|
47
|
+
else if (bit === '2') {
|
|
48
|
+
rx = 1;
|
|
49
|
+
ry = 1;
|
|
50
|
+
}
|
|
51
|
+
else if (bit === '3') {
|
|
52
|
+
rx = 1;
|
|
53
|
+
}
|
|
54
|
+
const val = Math.pow(2, level - 1);
|
|
55
|
+
rotateAndFlipQuadrant(val, point, rx, ry);
|
|
56
|
+
point[0] += val * rx;
|
|
57
|
+
point[1] += val * ry;
|
|
58
|
+
}
|
|
59
|
+
if (face % 2 === 1) {
|
|
60
|
+
const t = point[0];
|
|
61
|
+
point[0] = point[1];
|
|
62
|
+
point[1] = t;
|
|
63
|
+
}
|
|
64
|
+
return { face, ij: point, level };
|
|
65
|
+
}
|
|
66
|
+
exports.getS2CellFromQuadKey = getS2CellFromQuadKey;
|
|
67
|
+
/**
|
|
68
|
+
* Convets S2 cell ID to the Hilbert quad key
|
|
69
|
+
* @param cellId {Long} Cell id that is a 64-bit encoding of a face and a Hilbert curve parameter on that face
|
|
70
|
+
* @returns {string} the Hilbert quad key (containing /) as a string in the format 'face/pos', where
|
|
71
|
+
* - face is a 10-base representation of the face number
|
|
72
|
+
* - pos is a 4-base representation of the position along the Hilbert curve. For example,
|
|
73
|
+
* pos == '13' means the following:
|
|
74
|
+
* The face is divided two times. After the first time the child cell with position 1 will be selected.
|
|
75
|
+
* Then, this cell will be divided the second time, and the child cell with position 3 will be selected.
|
|
76
|
+
*/
|
|
77
|
+
function getS2QuadkeyFromCellId(cellId) {
|
|
78
|
+
if (cellId.isZero()) {
|
|
79
|
+
// Invalid token
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
let bin = cellId.toString(2);
|
|
83
|
+
while (bin.length < FACE_BITS + POS_BITS) {
|
|
84
|
+
// eslint-disable-next-line prefer-template
|
|
85
|
+
bin = '0' + bin;
|
|
86
|
+
}
|
|
87
|
+
// MUST come AFTER binstr has been left-padded with '0's
|
|
88
|
+
const lsbIndex = bin.lastIndexOf('1');
|
|
89
|
+
// substring(start, end) // includes start, does not include end
|
|
90
|
+
const faceB = bin.substring(0, 3);
|
|
91
|
+
// posB will always be a multiple of 2 (or it's invalid)
|
|
92
|
+
const posB = bin.substring(3, lsbIndex);
|
|
93
|
+
const levelN = posB.length / 2;
|
|
94
|
+
const faceS = long_1.default.fromString(faceB, true, 2).toString(10);
|
|
95
|
+
/*
|
|
96
|
+
Here is a fix for the case when posB is an empty string that causes an exception in Long.fromString
|
|
97
|
+
*/
|
|
98
|
+
let posS = '';
|
|
99
|
+
if (levelN !== 0) {
|
|
100
|
+
// posB is not an empty string, because levelN !== 0
|
|
101
|
+
posS = long_1.default.fromString(posB, true, 2).toString(4);
|
|
102
|
+
while (posS.length < levelN) {
|
|
103
|
+
// eslint-disable-next-line prefer-template
|
|
104
|
+
posS = '0' + posS;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Note, posS will be "" for the level==0, which corresponds to the full face.
|
|
108
|
+
// Example: Full face 0 (No subdivision, so level==0): Returns "0/"
|
|
109
|
+
// TODO: Is it ok?
|
|
110
|
+
return `${faceS}/${posS}`;
|
|
111
|
+
}
|
|
112
|
+
exports.getS2QuadkeyFromCellId = getS2QuadkeyFromCellId;
|
|
113
|
+
/**
|
|
114
|
+
* Convets S2 the Hilbert quad key to cell ID.
|
|
115
|
+
* @param quadkey {string} The Hilbert quad key (containing /) as a string in the format 'face/pos'
|
|
116
|
+
* @returns {Long} Cell id that is a 64-bit encoding of a face and a Hilbert curve parameter on that face
|
|
117
|
+
*/
|
|
118
|
+
/* eslint complexity: ["error", { "max": 14 }] */
|
|
119
|
+
function getS2CellIdFromQuadkey(hilbertQuadkey) {
|
|
120
|
+
if (hilbertQuadkey.length === 0 || hilbertQuadkey.indexOf('/') !== 1) {
|
|
121
|
+
throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
|
|
122
|
+
}
|
|
123
|
+
let idS = '';
|
|
124
|
+
const faceS = hilbertQuadkey[0];
|
|
125
|
+
switch (faceS) {
|
|
126
|
+
case '0':
|
|
127
|
+
idS += '000';
|
|
128
|
+
break;
|
|
129
|
+
case '1':
|
|
130
|
+
idS += '001';
|
|
131
|
+
break;
|
|
132
|
+
case '2':
|
|
133
|
+
idS += '010';
|
|
134
|
+
break;
|
|
135
|
+
case '3':
|
|
136
|
+
idS += '011';
|
|
137
|
+
break;
|
|
138
|
+
case '4':
|
|
139
|
+
idS += '100';
|
|
140
|
+
break;
|
|
141
|
+
case '5':
|
|
142
|
+
idS += '101';
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
|
|
146
|
+
}
|
|
147
|
+
const maxLevel = hilbertQuadkey.length;
|
|
148
|
+
// Don't convert position to Long, because it can contain leading zeros, which makes you handle it later.
|
|
149
|
+
for (let i = 2; i < maxLevel; i++) {
|
|
150
|
+
// The first char is a face, the second char is '/'
|
|
151
|
+
const p = hilbertQuadkey[i];
|
|
152
|
+
switch (p) {
|
|
153
|
+
case '0':
|
|
154
|
+
idS += '00';
|
|
155
|
+
break;
|
|
156
|
+
case '1':
|
|
157
|
+
idS += '01';
|
|
158
|
+
break;
|
|
159
|
+
case '2':
|
|
160
|
+
idS += '10';
|
|
161
|
+
break;
|
|
162
|
+
case '3':
|
|
163
|
+
idS += '11';
|
|
164
|
+
break;
|
|
165
|
+
default:
|
|
166
|
+
throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Append the sentinel bit
|
|
170
|
+
idS += '1';
|
|
171
|
+
const paddedId = idS.padEnd(64, '0');
|
|
172
|
+
const id = long_1.default.fromString(paddedId, true, 2);
|
|
173
|
+
return id;
|
|
174
|
+
}
|
|
175
|
+
exports.getS2CellIdFromQuadkey = getS2CellIdFromQuadkey;
|
|
176
|
+
function IJToST(ij, level, offsets) {
|
|
177
|
+
const maxSize = 1 << level;
|
|
178
|
+
return [(ij[0] + offsets[0]) / maxSize, (ij[1] + offsets[1]) / maxSize];
|
|
179
|
+
}
|
|
180
|
+
exports.IJToST = IJToST;
|
|
181
|
+
function singleSTtoUV(st) {
|
|
182
|
+
if (st >= 0.5) {
|
|
183
|
+
return (1 / 3.0) * (4 * st * st - 1);
|
|
184
|
+
}
|
|
185
|
+
return (1 / 3.0) * (1 - 4 * (1 - st) * (1 - st));
|
|
186
|
+
}
|
|
187
|
+
function STToUV(st) {
|
|
188
|
+
return [singleSTtoUV(st[0]), singleSTtoUV(st[1])];
|
|
189
|
+
}
|
|
190
|
+
exports.STToUV = STToUV;
|
|
191
|
+
function FaceUVToXYZ(face, [u, v]) {
|
|
192
|
+
switch (face) {
|
|
193
|
+
case 0:
|
|
194
|
+
return [1, u, v];
|
|
195
|
+
case 1:
|
|
196
|
+
return [-u, 1, v];
|
|
197
|
+
case 2:
|
|
198
|
+
return [-u, -v, 1];
|
|
199
|
+
case 3:
|
|
200
|
+
return [-1, -v, -u];
|
|
201
|
+
case 4:
|
|
202
|
+
return [v, -1, -u];
|
|
203
|
+
case 5:
|
|
204
|
+
return [v, u, -1];
|
|
205
|
+
default:
|
|
206
|
+
throw new Error('Invalid face');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.FaceUVToXYZ = FaceUVToXYZ;
|
|
210
|
+
function XYZToLngLat([x, y, z]) {
|
|
211
|
+
const lat = Math.atan2(z, Math.sqrt(x * x + y * y));
|
|
212
|
+
const lng = Math.atan2(y, x);
|
|
213
|
+
return [lng * RADIAN_TO_DEGREE, lat * RADIAN_TO_DEGREE];
|
|
214
|
+
}
|
|
215
|
+
exports.XYZToLngLat = XYZToLngLat;
|
|
216
|
+
function rotateAndFlipQuadrant(n, point, rx, ry) {
|
|
217
|
+
if (ry === 0) {
|
|
218
|
+
if (rx === 1) {
|
|
219
|
+
point[0] = n - 1 - point[0];
|
|
220
|
+
point[1] = n - 1 - point[1];
|
|
221
|
+
}
|
|
222
|
+
const x = point[0];
|
|
223
|
+
point[0] = point[1];
|
|
224
|
+
point[1] = x;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Retrieve S2 geometry center
|
|
229
|
+
* @param s2cell {S2Cell} S2 cell
|
|
230
|
+
* @returns {[number, number]} Longitude and Latitude coordinates of the S2 cell's center
|
|
231
|
+
*/
|
|
232
|
+
function getS2LngLatFromS2Cell(s2Cell) {
|
|
233
|
+
const st = IJToST(s2Cell.ij, s2Cell.level, [0.5, 0.5]);
|
|
234
|
+
const uv = STToUV(st);
|
|
235
|
+
const xyz = FaceUVToXYZ(s2Cell.face, uv);
|
|
236
|
+
return XYZToLngLat(xyz);
|
|
237
|
+
}
|
|
238
|
+
exports.getS2LngLatFromS2Cell = getS2LngLatFromS2Cell;
|
|
239
|
+
/**
|
|
240
|
+
* Return longitude and latitude of four corners of the cell.
|
|
241
|
+
* @param s2Cell {S2Cell} S2 cell
|
|
242
|
+
* @returns {Array<[number, number]>} Array of longitude and latitude pairs (in degrees) for four corners of the cell.
|
|
243
|
+
*/
|
|
244
|
+
function getCornerLngLats(s2Cell) {
|
|
245
|
+
const result = [];
|
|
246
|
+
const offsets = [
|
|
247
|
+
[0.0, 0.0],
|
|
248
|
+
[0.0, 1.0],
|
|
249
|
+
[1.0, 1.0],
|
|
250
|
+
[1.0, 0.0]
|
|
251
|
+
];
|
|
252
|
+
for (let i = 0; i < 4; i++) {
|
|
253
|
+
const st = IJToST(s2Cell.ij, s2Cell.level, offsets[i]);
|
|
254
|
+
const uv = STToUV(st);
|
|
255
|
+
const xyz = FaceUVToXYZ(s2Cell.face, uv);
|
|
256
|
+
result.push(XYZToLngLat(xyz));
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
exports.getCornerLngLats = getCornerLngLats;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/3d-tiles",
|
|
3
|
-
"version": "3.4.0-alpha.
|
|
3
|
+
"version": "3.4.0-alpha.3",
|
|
4
4
|
"description": "3D Tiles, an open standard for streaming massive heterogeneous 3D geospatial datasets.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -34,16 +34,17 @@
|
|
|
34
34
|
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@loaders.gl/draco": "3.4.0-alpha.
|
|
38
|
-
"@loaders.gl/gltf": "3.4.0-alpha.
|
|
39
|
-
"@loaders.gl/loader-utils": "3.4.0-alpha.
|
|
40
|
-
"@loaders.gl/math": "3.4.0-alpha.
|
|
41
|
-
"@loaders.gl/tiles": "3.4.0-alpha.
|
|
37
|
+
"@loaders.gl/draco": "3.4.0-alpha.3",
|
|
38
|
+
"@loaders.gl/gltf": "3.4.0-alpha.3",
|
|
39
|
+
"@loaders.gl/loader-utils": "3.4.0-alpha.3",
|
|
40
|
+
"@loaders.gl/math": "3.4.0-alpha.3",
|
|
41
|
+
"@loaders.gl/tiles": "3.4.0-alpha.3",
|
|
42
42
|
"@math.gl/core": "^3.5.1",
|
|
43
|
-
"@math.gl/geospatial": "^3.5.1"
|
|
43
|
+
"@math.gl/geospatial": "^3.5.1",
|
|
44
|
+
"long": "^5.2.1"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"@loaders.gl/core": "^3.2.0"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a954528dd1d78a1f128d8f6b07e4baeb7a296924"
|
|
49
50
|
}
|
package/src/cesium-ion-loader.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type {Availability, BoundingVolume, Subtree} from '../../../types';
|
|
|
2
2
|
import {Tile3DSubtreeLoader} from '../../../tile-3d-subtree-loader';
|
|
3
3
|
import {load} from '@loaders.gl/core';
|
|
4
4
|
|
|
5
|
+
import {getS2CellIdFromToken, getS2ChildCellId, getS2TokenFromCellId} from '../../utils/s2/index';
|
|
6
|
+
import type {S2VolumeInfo} from '../../utils/obb/s2-corners-to-obb';
|
|
7
|
+
import {convertS2BoundingVolumetoOBB} from '../../utils/obb/s2-corners-to-obb';
|
|
8
|
+
import Long from 'long';
|
|
9
|
+
|
|
5
10
|
const QUADTREE_DEVISION_COUNT = 4;
|
|
6
11
|
const OCTREE_DEVISION_COUNT = 8;
|
|
7
12
|
|
|
@@ -10,6 +15,59 @@ const SUBDIVISION_COUNT_MAP = {
|
|
|
10
15
|
OCTREE: OCTREE_DEVISION_COUNT
|
|
11
16
|
};
|
|
12
17
|
|
|
18
|
+
/**
|
|
19
|
+
* S2VolumeBox is an extention of BoundingVolume of type "box"
|
|
20
|
+
*/
|
|
21
|
+
export type S2VolumeBox = {
|
|
22
|
+
/** BoundingVolume of type "box" has the "box" field. S2VolumeBox contains it as well. */
|
|
23
|
+
box: number[];
|
|
24
|
+
/** s2VolumeInfo provides additional info about the box - specifically the token, min and max height */
|
|
25
|
+
s2VolumeInfo: S2VolumeInfo;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function getChildS2VolumeBox(
|
|
29
|
+
s2VolumeBox: S2VolumeBox | undefined,
|
|
30
|
+
index: number,
|
|
31
|
+
subdivisionScheme: string
|
|
32
|
+
): S2VolumeBox | undefined {
|
|
33
|
+
if (s2VolumeBox?.box) {
|
|
34
|
+
// Check if the BoundingVolume is of type "box"
|
|
35
|
+
const cellId: Long = getS2CellIdFromToken(s2VolumeBox.s2VolumeInfo.token);
|
|
36
|
+
const childCellId = getS2ChildCellId(cellId, index);
|
|
37
|
+
const childToken = getS2TokenFromCellId(childCellId);
|
|
38
|
+
|
|
39
|
+
// Clone object. Note, s2VolumeInfo is a plain object that doesn't contain any nested object.
|
|
40
|
+
// So, we can use the Spread Operator to make a shallow copy of the object.
|
|
41
|
+
const s2ChildVolumeInfo: S2VolumeInfo = {...s2VolumeBox.s2VolumeInfo};
|
|
42
|
+
s2ChildVolumeInfo.token = childToken; // replace the token with the child's one
|
|
43
|
+
|
|
44
|
+
// In case of QUADTREE the sizeZ should NOT be changed!
|
|
45
|
+
// https://portal.ogc.org/files/102132
|
|
46
|
+
// A quadtree divides space only on the x and y dimensions.
|
|
47
|
+
// It divides each tile into 4 smaller tiles where the x and y dimensions are halved.
|
|
48
|
+
// The quadtree z minimum and maximum remain unchanged.
|
|
49
|
+
switch (subdivisionScheme) {
|
|
50
|
+
case 'OCTREE':
|
|
51
|
+
const s2VolumeInfo: S2VolumeInfo = s2VolumeBox.s2VolumeInfo;
|
|
52
|
+
const delta = s2VolumeInfo.maximumHeight - s2VolumeInfo.minimumHeight;
|
|
53
|
+
const sizeZ: number = delta / 2.0; // It's a next level (a child)
|
|
54
|
+
const midZ: number = s2VolumeInfo.minimumHeight + delta / 2.0;
|
|
55
|
+
s2VolumeInfo.minimumHeight = midZ - sizeZ;
|
|
56
|
+
s2VolumeInfo.maximumHeight = midZ + sizeZ;
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const box = convertS2BoundingVolumetoOBB(s2ChildVolumeInfo);
|
|
62
|
+
const childS2VolumeBox: S2VolumeBox = {
|
|
63
|
+
box,
|
|
64
|
+
s2VolumeInfo: s2ChildVolumeInfo
|
|
65
|
+
};
|
|
66
|
+
return childS2VolumeBox;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
13
71
|
/**
|
|
14
72
|
* Recursively parse implicit tiles tree
|
|
15
73
|
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling
|
|
@@ -30,6 +88,7 @@ export async function parseImplicitTiles(params: {
|
|
|
30
88
|
childIndex?: number;
|
|
31
89
|
level?: number;
|
|
32
90
|
globalData?: {level: number; mortonIndex: number; x: number; y: number; z: number};
|
|
91
|
+
s2VolumeBox?: S2VolumeBox;
|
|
33
92
|
}) {
|
|
34
93
|
const {
|
|
35
94
|
options,
|
|
@@ -46,7 +105,8 @@ export async function parseImplicitTiles(params: {
|
|
|
46
105
|
x: 0,
|
|
47
106
|
y: 0,
|
|
48
107
|
z: 0
|
|
49
|
-
}
|
|
108
|
+
},
|
|
109
|
+
s2VolumeBox
|
|
50
110
|
} = params;
|
|
51
111
|
let {subtree, level = 0} = params;
|
|
52
112
|
const {
|
|
@@ -129,19 +189,33 @@ export async function parseImplicitTiles(params: {
|
|
|
129
189
|
const pData = {mortonIndex: childTileMortonIndex, x: childTileX, y: childTileY, z: childTileZ};
|
|
130
190
|
|
|
131
191
|
for (let index = 0; index < childrenPerTile; index++) {
|
|
132
|
-
const
|
|
192
|
+
const childS2VolumeBox: S2VolumeBox | undefined = getChildS2VolumeBox(
|
|
193
|
+
s2VolumeBox,
|
|
194
|
+
index,
|
|
195
|
+
subdivisionScheme
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
// Recursive calling...
|
|
199
|
+
const childTileParsed = await parseImplicitTiles({
|
|
133
200
|
subtree,
|
|
134
201
|
options,
|
|
135
202
|
parentData: pData,
|
|
136
203
|
childIndex: index,
|
|
137
204
|
level: childTileLevel,
|
|
138
|
-
globalData
|
|
205
|
+
globalData,
|
|
206
|
+
s2VolumeBox: childS2VolumeBox
|
|
139
207
|
});
|
|
140
208
|
|
|
141
|
-
if (
|
|
209
|
+
if (childTileParsed.contentUrl || childTileParsed.children.length) {
|
|
142
210
|
const globalLevel = lev + 1;
|
|
143
211
|
const childCoordinates = {childTileX, childTileY, childTileZ};
|
|
144
|
-
const formattedTile = formatTileData(
|
|
212
|
+
const formattedTile = formatTileData(
|
|
213
|
+
childTileParsed,
|
|
214
|
+
globalLevel,
|
|
215
|
+
childCoordinates,
|
|
216
|
+
options,
|
|
217
|
+
s2VolumeBox
|
|
218
|
+
);
|
|
145
219
|
// @ts-ignore
|
|
146
220
|
tile.children.push(formattedTile);
|
|
147
221
|
}
|
|
@@ -174,7 +248,8 @@ function formatTileData(
|
|
|
174
248
|
tile,
|
|
175
249
|
level: number,
|
|
176
250
|
childCoordinates: {childTileX: number; childTileY: number; childTileZ: number},
|
|
177
|
-
options: any
|
|
251
|
+
options: any,
|
|
252
|
+
s2VolumeBox?: S2VolumeBox
|
|
178
253
|
) {
|
|
179
254
|
const {
|
|
180
255
|
basePath,
|
|
@@ -187,9 +262,14 @@ function formatTileData(
|
|
|
187
262
|
} = options;
|
|
188
263
|
const uri = tile.contentUrl && tile.contentUrl.replace(`${basePath}/`, '');
|
|
189
264
|
const lodMetricValue = rootLodMetricValue / 2 ** level;
|
|
190
|
-
|
|
265
|
+
|
|
266
|
+
const boundingVolume: BoundingVolume = s2VolumeBox?.box
|
|
267
|
+
? {box: s2VolumeBox.box}
|
|
268
|
+
: rootBoundingVolume;
|
|
269
|
+
|
|
270
|
+
const boundingVolumeForChildTile = calculateBoundingVolumeForChildTile(
|
|
191
271
|
level,
|
|
192
|
-
|
|
272
|
+
boundingVolume,
|
|
193
273
|
childCoordinates
|
|
194
274
|
);
|
|
195
275
|
|
|
@@ -204,7 +284,7 @@ function formatTileData(
|
|
|
204
284
|
lodMetricValue,
|
|
205
285
|
geometricError: lodMetricValue,
|
|
206
286
|
transform: tile.transform,
|
|
207
|
-
boundingVolume
|
|
287
|
+
boundingVolume: boundingVolumeForChildTile
|
|
208
288
|
};
|
|
209
289
|
}
|
|
210
290
|
|
|
@@ -219,7 +299,7 @@ function calculateBoundingVolumeForChildTile(
|
|
|
219
299
|
level: number,
|
|
220
300
|
rootBoundingVolume: BoundingVolume,
|
|
221
301
|
childCoordinates: {childTileX: number; childTileY: number; childTileZ: number}
|
|
222
|
-
): BoundingVolume
|
|
302
|
+
): BoundingVolume {
|
|
223
303
|
if (rootBoundingVolume.region) {
|
|
224
304
|
const {childTileX, childTileY, childTileZ} = childCoordinates;
|
|
225
305
|
const [west, south, east, north, minimumHeight, maximumHeight] = rootBoundingVolume.region;
|
|
@@ -227,6 +307,13 @@ function calculateBoundingVolumeForChildTile(
|
|
|
227
307
|
|
|
228
308
|
const sizeX = (east - west) / boundingVolumesCount;
|
|
229
309
|
const sizeY = (north - south) / boundingVolumesCount;
|
|
310
|
+
|
|
311
|
+
// TODO : Why is the subdivisionScheme not being checked here?
|
|
312
|
+
|
|
313
|
+
// In case of QUADTREE the sizeZ should NOT be changed!
|
|
314
|
+
// https://portal.ogc.org/files/102132
|
|
315
|
+
// A quadtree divides space only on the x and y dimensions. It divides each tile into 4 smaller tiles where the x and y dimensions are halved. The quadtree z minimum and maximum remain unchanged.
|
|
316
|
+
|
|
230
317
|
const sizeZ = (maximumHeight - minimumHeight) / boundingVolumesCount;
|
|
231
318
|
|
|
232
319
|
const [childWest, childEast] = [west + sizeX * childTileX, west + sizeX * (childTileX + 1)];
|
|
@@ -241,9 +328,11 @@ function calculateBoundingVolumeForChildTile(
|
|
|
241
328
|
};
|
|
242
329
|
}
|
|
243
330
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
331
|
+
if (rootBoundingVolume.box) {
|
|
332
|
+
return rootBoundingVolume;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
throw new Error(`Unsupported bounding volume type ${rootBoundingVolume}`);
|
|
247
336
|
}
|
|
248
337
|
|
|
249
338
|
/**
|
|
@@ -3,7 +3,10 @@ import {Tile3DSubtreeLoader} from '../../tile-3d-subtree-loader';
|
|
|
3
3
|
import {load} from '@loaders.gl/core';
|
|
4
4
|
import {Tileset3D, LOD_METRIC_TYPE, TILE_REFINEMENT, TILE_TYPE, Tile3D} from '@loaders.gl/tiles';
|
|
5
5
|
import {ImplicitTilingExtension, Subtree} from '../../types';
|
|
6
|
+
import type {S2VolumeBox} from './helpers/parse-3d-implicit-tiles';
|
|
6
7
|
import {parseImplicitTiles, replaceContentUrlTemplate} from './helpers/parse-3d-implicit-tiles';
|
|
8
|
+
import type {S2VolumeInfo} from '../utils/obb/s2-corners-to-obb';
|
|
9
|
+
import {convertS2BoundingVolumetoOBB} from '../utils/obb/s2-corners-to-obb';
|
|
7
10
|
|
|
8
11
|
function getTileType(tile) {
|
|
9
12
|
if (!tile.contentUrl) {
|
|
@@ -141,6 +144,15 @@ export async function normalizeImplicitTileHeaders(
|
|
|
141
144
|
const refine = tileset?.root?.refine;
|
|
142
145
|
// @ts-ignore
|
|
143
146
|
const rootLodMetricValue = tile.geometricError;
|
|
147
|
+
|
|
148
|
+
// Replace tile.boundingVolume with the the bounding volume specified by the extensions['3DTILES_bounding_volume_S2']
|
|
149
|
+
const s2VolumeInfo: S2VolumeInfo = tile.boundingVolume.extensions?.['3DTILES_bounding_volume_S2'];
|
|
150
|
+
if (s2VolumeInfo) {
|
|
151
|
+
const box = convertS2BoundingVolumetoOBB(s2VolumeInfo);
|
|
152
|
+
const s2VolumeBox: S2VolumeBox = {box, s2VolumeInfo};
|
|
153
|
+
tile.boundingVolume = s2VolumeBox;
|
|
154
|
+
}
|
|
155
|
+
|
|
144
156
|
const rootBoundingVolume = tile.boundingVolume;
|
|
145
157
|
|
|
146
158
|
const implicitOptions = {
|
|
@@ -177,7 +189,11 @@ export async function normalizeImplicitTileData(tile, rootSubtree: Subtree, opti
|
|
|
177
189
|
tile.lodMetricValue = tile.geometricError;
|
|
178
190
|
tile.transformMatrix = tile.transform;
|
|
179
191
|
|
|
180
|
-
const {children, contentUrl} = await parseImplicitTiles({
|
|
192
|
+
const {children, contentUrl} = await parseImplicitTiles({
|
|
193
|
+
subtree: rootSubtree,
|
|
194
|
+
options,
|
|
195
|
+
s2VolumeBox: tile
|
|
196
|
+
});
|
|
181
197
|
|
|
182
198
|
if (contentUrl) {
|
|
183
199
|
tile.contentUrl = contentUrl;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {Vector3} from '@math.gl/core';
|
|
2
|
+
import {OrientedBoundingBox, makeOrientedBoundingBoxFromPoints} from '@math.gl/culling';
|
|
3
|
+
|
|
4
|
+
import type {S2HeightInfo} from '../../utils/s2/index';
|
|
5
|
+
import {getS2OrientedBoundingBoxCornerPoints} from '../../utils/s2/index';
|
|
6
|
+
|
|
7
|
+
import {getS2LngLat} from '../../utils/s2/index';
|
|
8
|
+
import {Ellipsoid} from '@math.gl/geospatial';
|
|
9
|
+
|
|
10
|
+
export type S2VolumeInfo = {
|
|
11
|
+
/** S2 key or token */
|
|
12
|
+
token: string;
|
|
13
|
+
/** minimum height in meters */
|
|
14
|
+
minimumHeight: number;
|
|
15
|
+
/** maximum height in meters */
|
|
16
|
+
maximumHeight: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Converts S2VolumeInfo to OrientedBoundingBox
|
|
21
|
+
* @param {S2VolumeInfo} s2VolumeInfo - s2 volume to convert
|
|
22
|
+
* @returns Oriented Bounding Box of type Box
|
|
23
|
+
*/
|
|
24
|
+
export function convertS2BoundingVolumetoOBB(s2VolumeInfo: S2VolumeInfo): number[] {
|
|
25
|
+
const token: string = s2VolumeInfo.token;
|
|
26
|
+
const heightInfo: S2HeightInfo = {
|
|
27
|
+
minimumHeight: s2VolumeInfo.minimumHeight,
|
|
28
|
+
maximumHeight: s2VolumeInfo.maximumHeight
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const corners: Vector3[] = getS2OrientedBoundingBoxCornerPoints(token, heightInfo);
|
|
32
|
+
|
|
33
|
+
// Add a point that doesn't allow the box dive under the Earth
|
|
34
|
+
|
|
35
|
+
const center = getS2LngLat(token);
|
|
36
|
+
const centerLng: number = center[0];
|
|
37
|
+
const centerLat: number = center[1];
|
|
38
|
+
const point = Ellipsoid.WGS84.cartographicToCartesian([
|
|
39
|
+
centerLng,
|
|
40
|
+
centerLat,
|
|
41
|
+
heightInfo.maximumHeight
|
|
42
|
+
]);
|
|
43
|
+
const centerPointAdditional = new Vector3(point[0], point[1], point[2]);
|
|
44
|
+
corners.push(centerPointAdditional);
|
|
45
|
+
|
|
46
|
+
// corners should be an array of Vector3 (XYZ)
|
|
47
|
+
const obb: OrientedBoundingBox = makeOrientedBoundingBoxFromPoints(corners);
|
|
48
|
+
const box: number[] = [...obb.center, ...obb.halfAxes];
|
|
49
|
+
|
|
50
|
+
return box;
|
|
51
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {S2Cell} from '../s2geometry/s2-geometry';
|
|
2
|
+
import {IJToST, STToUV, FaceUVToXYZ, XYZToLngLat} from '../s2geometry/s2-geometry';
|
|
3
|
+
|
|
4
|
+
const MAX_RESOLUTION = 100;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get a polygon with corner coordinates for an S2 cell
|
|
8
|
+
* @param s2cell {S2Cell} S2 cell
|
|
9
|
+
* @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
|
|
10
|
+
* - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line max-statements
|
|
13
|
+
export function getS2BoundaryFlatFromS2Cell(s2cell: S2Cell): Float64Array {
|
|
14
|
+
const {face, ij, level} = s2cell;
|
|
15
|
+
const offsets = [
|
|
16
|
+
[0, 0],
|
|
17
|
+
[0, 1],
|
|
18
|
+
[1, 1],
|
|
19
|
+
[1, 0],
|
|
20
|
+
[0, 0]
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// The S2 cell edge is curved: http://s2geometry.io/
|
|
24
|
+
// This is more prominent at lower levels
|
|
25
|
+
// resolution is the number of segments to generate per edge.
|
|
26
|
+
// We exponentially reduce resolution as level increases so it doesn't affect perf
|
|
27
|
+
// when there are a large number of cells
|
|
28
|
+
const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
|
|
29
|
+
const result = new Float64Array(4 * resolution * 2 + 2);
|
|
30
|
+
let ptIndex = 0;
|
|
31
|
+
let prevLng = 0;
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < 4; i++) {
|
|
34
|
+
const offset = offsets[i].slice(0) as [number, number];
|
|
35
|
+
const nextOffset = offsets[i + 1];
|
|
36
|
+
const stepI = (nextOffset[0] - offset[0]) / resolution;
|
|
37
|
+
const stepJ = (nextOffset[1] - offset[1]) / resolution;
|
|
38
|
+
|
|
39
|
+
for (let j = 0; j < resolution; j++) {
|
|
40
|
+
offset[0] += stepI;
|
|
41
|
+
offset[1] += stepJ;
|
|
42
|
+
// Cell can be represented by coordinates IJ, ST, UV, XYZ
|
|
43
|
+
// http://s2geometry.io/devguide/s2cell_hierarchy#coordinate-systems
|
|
44
|
+
const st = IJToST(ij, level, offset);
|
|
45
|
+
const uv = STToUV(st);
|
|
46
|
+
const xyz = FaceUVToXYZ(face, uv);
|
|
47
|
+
const lngLat = XYZToLngLat(xyz);
|
|
48
|
+
|
|
49
|
+
// Adjust longitude for Web Mercator projection
|
|
50
|
+
|
|
51
|
+
if (Math.abs(lngLat[1]) > 89.999) {
|
|
52
|
+
lngLat[0] = prevLng;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const deltaLng = lngLat[0] - prevLng;
|
|
56
|
+
lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
|
|
57
|
+
|
|
58
|
+
result[ptIndex++] = lngLat[0];
|
|
59
|
+
result[ptIndex++] = lngLat[1];
|
|
60
|
+
prevLng = lngLat[0];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// close the loop
|
|
64
|
+
result[ptIndex++] = result[0];
|
|
65
|
+
result[ptIndex++] = result[1];
|
|
66
|
+
return result;
|
|
67
|
+
}
|