通过 CSS 设置容器背景,并隐藏 Cesium 的默认黑色背景:
// 初始化 Cesium 时禁用天空盒和背景
const viewer = new Cesium.Viewer('cesiumContainer', {
skyBox: false, // 禁用天空盒
skyAtmosphere: false, // 可选:禁用大气层
baseLayerPicker: false, // 可选:禁用底图选择器
sceneMode: Cesium.SceneMode.SCENE3D,
// 设置透明背景
contextOptions: {
webgl: {
alpha: true
}
}
});
// 启用透明背景
viewer.scene.backgroundColor = Cesium.Color.TRANSPARENT;
源码地址:https://gitee.com/duansamve/vue3-cesium1.95-model-update.git