js
复制代码
/**
* 获取 3dtileset的包围盒各顶点坐标, z 方向取高度最低的位置
* @param {*} tileset
* @param {*} options
* @returns
* @ref https://blog.csdn.net/STANDBYF/article/details/135012273
* @ref https://community.cesium.com/t/accurate-bounding-box-for-3d-tiles/5890/10
*/
export function getTilesetBoudingBoxPoints(tileset, options = {}) {
const { center, halfAxes } = tileset._root._boundingVolume._orientedBoundingBox;
const pointsVec3 = [];
// 获取三个轴的位置
const x = new Cartesian3();
const y = new Cartesian3();
const z = new Cartesian3();
Matrix3.getColumn(halfAxes, 0, x);
Matrix3.getColumn(halfAxes, 1, y);
Matrix3.getColumn(halfAxes, 2, z);
const halfXNegative = new Cartesian3();
const halfXPositive = new Cartesian3();
Cartesian3.subtract(center, x, halfXNegative)
Cartesian3.add(center, x, halfXPositive)
Cartesian3.subtract(halfXNegative, z, halfXNegative)
Cartesian3.subtract(halfXPositive, z, halfXPositive)
pointsVec3.push(Cartesian3.add(halfXNegative, y, new Cartesian3()))
pointsVec3.push(Cartesian3.subtract(halfXNegative, y, new Cartesian3()))
pointsVec3.push(Cartesian3.subtract(halfXPositive, y, new Cartesian3()))
pointsVec3.push(Cartesian3.add(halfXPositive, y, new Cartesian3()))
const pointsLL = [];
pointsVec3.forEach(item=>{
const ll = Cartographic.fromCartesian(item);
pointsLL.push(
Math.toDegrees(ll.longitude),
Math.toDegrees(ll.latitude),
)
})
return pointsLL;
}