3d中获取对象包围盒-位置的常用方法

36次阅读

共计 558 个字符,预计需要花费 2 分钟才能阅读完成。

// 获取对象的包围盒
getObjboundsById(objId){var box = new THREE.Box3();
    var bounds = new THREE.Box3();
    var instanceTree = viewer.model.getData().instanceTree;
    var fragList = viewer.model.getFragmentList();
    box.makeEmpty();
    bounds.makeEmpty();
    instanceTree.enumNodeFragments(objId, function (fragId) {fragList.getWorldBounds(fragId, box);
        bounds.union(box)
    }, true)

    return bounds
}
 // 获取中心位置
getObjPosition(dbId){var bound = vmethods.getObjboundsById(dbId);
    var posx = (bound.max.x + bound.min.x) / 2;
    var posy = (bound.max.y + bound.min.y) / 2;
    var posz = (bound.max.z + bound.min.z) / 2;
    var pos = {
        x:posx,
        y:posy,
        z:posz
    }
    return pos;
}

正文完
 0