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模型,具体详情大家可以自行研究

相关推荐
guoss19 小时前
实现渐变背景叠加渐变圆角边框
前端
枫,为落叶19 小时前
【vue】导出excel
前端·vue.js·excel
转转技术团队19 小时前
当 AI 走进前端开发:代理插件的全流程开发实践
前端·javascript·ai编程
慧一居士19 小时前
Quill 富文本编辑器 功能介绍,使用场景说明,使用示例演示
前端
FinClip19 小时前
100%关税与软件封锁下,信创为何是破局关键?
前端
晴殇i19 小时前
一行生成绝对唯一 ID:别再依赖 Date.now() 了!
前端·javascript·vue.js
哲此一生98419 小时前
SpringBoot3集成Mybatis(开启第一个集成Mybatis的后端接口)
java·spring boot·mybatis
浮游本尊20 小时前
Java学习第26天 - 微服务监控与运维实践
java
高山上有一只小老虎20 小时前
idea2025社区版设置打开的多个文件展示在工具栏下方
java·ide·intellij-idea
CrabXin20 小时前
前端如何用 CDN 加速网站性能全解析
前端