Cesium 加载B3DM模型

一、引入Cesium,可以使用该链接下载cesium

链接: https://pan.baidu.com/s/1BRQyaFCkxO2xQQT5RzFUCw?pwd=kcv9 提取码: kcv9

在index.html文件中引入cesium

复制代码
<script type="text/javascript" src="/Cesium/Cesium.js"></script>

二、初始化cesium,cesium初始化参数可自行配置

复制代码
const cesiurView = ref();
const initCesiut = () => {
	Cesium.Ion.defaultAccessToken ='';
	cesiurView.value = new Cesium.Viewer(props.id, {
		animation: false, //是否显示动画控件
		shouldAnimate: true,
		homeButton: false, //是否显示Home按钮
		fullscreenButton: false, //是否显示全屏按钮
		baseLayerPicker: false, //是否显示图层选择控件
		geocoder: false, //是否显示地名查找控件
		timeline: false, //是否显示时间线控件
		sceneModePicker: false, //是否显示投影方式控件
		navigationHelpButton: false, //是否显示帮助信息控件
		infoBox: false, //是否显示点击要素之后显示的信息
		requestRenderMode: true, //启用请求渲染模式
		scene3DOnly: true, //仅渲染3D
		sceneMode: 3, //初始场景模式 1 2D模式 2 2D循环模式 3 3D模式  Cesium.SceneMode
		selectionIndicator: false,//不创建selectionIndicator小部件
		skyAtmosphere:false,//不显示天空
	});
	cesiurView.value._cesiumWidget._creditContainer.style.display = 'none';// 隐藏logo
	cesiurView.value.scene.screenSpaceCameraController.inertiaZoom = 0.5;
	cesiurView.value.scene.screenSpaceCameraController.enableTilt = true; // 禁止俯仰角
	cesiurView.value.scene.globe.depthTestAgainstTerrain = false; //关闭地形
	cesiurView.value.scene.globe.show = false;
	cesiurView.value.scene.sun.show = false; //是否显示太阳
	cesiurView.value.scene.moon.show = false; //是否显示有月亮
	cesiurView.value.scene.skyBox.show = false; //是否显示星空
	cesiurView.value.scene.backgroundColor = new Cesium.Color(0,0,0,1)
};

cesium内置token,容易因token过期造成cesium加载失败,可以在Cesium官网中注册账号,获取token,然后可使用Cesium.Ion.defaultAccessToken该方法替换内置token。

二、添加B3DM到cesium中

复制代码
const addB3DMModel = async () => {
	let tileset = await Cesium.Cesium3DTileset.fromUrl(``, {
		maximumScreenSpaceError: 2,//各级别最大误差
		show: true,
		skipLevels: 0,//加载图层是跳转的最小级别,0 不跳转
		immediatelyLoadDesiredLevelOfDetail: false,//只加载所需图块
		loadSiblings: false,//是否下载所有图块
		cullWithChildrenBounds: true,
	});
	cesiurView.value.scene.primitives.add(tileset, {
		disableDepthTestDistance: Number.POSITIVE_INFINITY,
	});
	cesiurView.value.zoomTo(tileset);//定位到当前模型
};

效果如下:

以上方法仅仅是记录使用cesium展示B3DM模型,具体详情大家可以自行研究

相关推荐
卓怡学长15 小时前
w272基于springboot便民医疗服务小程序
java·spring boot·spring·小程序·intellij-idea
一方~15 小时前
权限系统设计
java
随风一样自由15 小时前
【前端+跨端技术新格局】Tauri vs Electron 完整性能对比(2026实测数据+底层原理)
前端·javascript·electron
盐焗鹌鹑蛋15 小时前
【C++】多态
java·jvm·c++
rebibabo15 小时前
Java高并发底层原理(七)volatile 到底解决了什么问题
java·学习笔记·volatile·可见性·有序性·指令重排
L-影15 小时前
Pydantic 模型:为你的 Web 数据装上“安检系统”
前端
Reload.15 小时前
GJ航司,验证码网易易盾 JS逆向 纯算轨迹
开发语言·前端·javascript
L-影15 小时前
FastAPI 请求头与 Cookie:Web 世界的“身份证”与“通行证”
前端·fastapi
IT_陈寒15 小时前
Vue的响应式更新把我坑惨了,原来是这个原因
前端·人工智能·后端
名字还没想好☜16 小时前
Go 并发实战:用 channel 实现 worker pool
java·数据库·后端·golang·go