Cesium获取3dtileset的包围盒各顶点坐标

通过获取加载后的3dtileset对象从而通过计算得到相关的包围盒数据。

相关解释如下:

  1. 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.
  2. 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.
  3. 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);

相关资料来源:https://community.cesium.com/t/accurate-bounding-box-for-3d-tiles/5890/9

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值