@loaders.gl/3d-tiles
Version:
3D Tiles, an open standard for streaming massive heterogeneous 3D geospatial datasets.
36 lines (35 loc) • 1.4 kB
JavaScript
// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright vis.gl contributors
import { getS2Cell } from "../s2geometry/s2-cell-utils.js";
import { getS2Region } from "./s2-to-region.js";
import { Vector3 } from '@math.gl/core';
/**
* Converts S2HeightInfo to corner points of an oriented bounding box
* Can be used to constuct an OrientedBoundingBox instance
* @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
* @param heightInfo {S2HeightInfo} min and max height of the box
* @returns corner points of the oriented bounding box
*/
export function getS2OrientedBoundingBoxCornerPoints(tokenOrKey, // This can be an S2 key or token
heightInfo) {
const min = heightInfo?.minimumHeight || 0;
const max = heightInfo?.maximumHeight || 0;
const s2cell = getS2Cell(tokenOrKey);
const region = getS2Region(s2cell);
// region lng/lat are in degrees
const W = region.west;
const S = region.south;
const E = region.east;
const N = region.north;
const points = [];
points.push(new Vector3(W, N, min));
points.push(new Vector3(E, N, min));
points.push(new Vector3(E, S, min));
points.push(new Vector3(W, S, min));
points.push(new Vector3(W, N, max));
points.push(new Vector3(E, N, max));
points.push(new Vector3(E, S, max));
points.push(new Vector3(W, S, max));
return points;
}