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

相关推荐
前端摸鱼匠几秒前
Vue 3 的defineProps编译器宏:详解<script setup>中defineProps的使用
前端·javascript·vue.js·前端框架·ecmascript
木斯佳1 分钟前
前端八股文面经大全: 美团财务科技前端一面 (2026-04-09)·面经深度解析
前端·实习面经·前端初级
天外天-亮2 分钟前
Vue2.0 + jsmind:开发思维导图
javascript·vue.js·jsmind
LIO4 分钟前
React 零基础入门,一篇搞懂核心用法(适合新手)
前端·react.js
云烟成雨TD10 分钟前
Spring AI 1.x 系列【28】基于内存和 MySQL 的多轮对话实现案例
java·人工智能·spring
Lyyaoo.13 分钟前
【JAVA基础面经】String、StringBuffer、StringBuilder
java·开发语言
TeamDev19 分钟前
JxBrowser 8.18.2 版本发布啦!
java·前端·跨平台·桌面应用·web ui·jxbrowser·浏览器控件
netkiller-BG7NYT19 分钟前
yoloutils - Openclaw Agent Skill
前端·webpack·node.js
晴天sir23 分钟前
Redis 在业务中的几种典型用法
java·数据库·redis
北城笑笑24 分钟前
FPGA 51,基于 ZYNQ 7Z010 的 FPGA 高速路由转发加速系统架构设计(Xilinx ZYNQ-MINI 7Z010 CLG400 -1)
前端·fpga开发·系统架构·fpga