通过获取加载后的3dtileset对象从而通过计算得到相关的包围盒数据。
相关解释如下:
- Identify the three axes in obb.halfAxes. The local x-axis is the first column, i.e. Matrix3.getColumn(obb.halfAxes, 0, new Cartesian3()). The local y-axis is the second column, and so on. We will call these xaxis, yaxis, and zaxis respectively.
- To calculate the “backmost, bottom-left” corner (i.e. the corner with (-X, -Y, -Z) in local space), you would need to do obb.center - xaxis - yaxis - zaxis.
- To calculate the “frontmost, bottom-right” corner (i.e. (X, -Y, Z)) you need to do obb.center + xaxis - yaxis + zaxis.
And so on.
相关代码如下:
可以在模型的包围盒的两个角点和中心点得到红色的点位标记。
注意:如下代码需要在3dtileset加载完毕后再执行才能成功获取相关数据,或者使用tileset.allTilesLoaded.addEventListener()的写法也同样可行
var a = daYanTaTileset._root._boundingVolume._orientedBoundingBox.halfAxes;
var center = daYanTaTileset._root._boundingVolume._orientedBoundingBox.center;
var x = new Cesium.Cartesian3();
var y = new Cesium.Cartesian3();
var z = new Cesium.Cartesian3();
Cesium.Matrix3.getColumn(a, 0, x);
Cesium.Matrix3.getColumn(a, 1, y);
Cesium.Matrix3.getColumn(a, 2, z);
var temp1 = new Cesium.Cartesian3();
var temp2 = new Cesium.Cartesian3();
var temp3 = new Cesium.Cartesian3();
Cesium.Cartesian3.subtract(center, x, temp1)
Cesium.Cartesian3.subtract(temp1, y, temp2)
Cesium.Cartesian3.subtract(temp2, z, temp3)
console.log('temp3为:',temp3);
let originPoint2 = new Cesium.Entity({
id:'ceshi2',
position: temp3,
point: {
color: Cesium.Color.RED,
pixelSize: 35
}});
viewer.entities.add(originPoint2);
var temp4 = new Cesium.Cartesian3();
var temp5 = new Cesium.Cartesian3();
var temp6 = new Cesium.Cartesian3();
Cesium.Cartesian3.add(center, x, temp4)
Cesium.Cartesian3.add(temp4, y, temp5)
Cesium.Cartesian3.add(temp5, z, temp6)
console.log('temp6:',temp6);
let originPoint3 = new Cesium.Entity({
id:'ceshi3',
position: temp6,
point: {
color: Cesium.Color.RED,
pixelSize: 35
}});
viewer.entities.add(originPoint3);