cesium 之三维场景展示篇(附源码下载)

前言

cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材。

内容概览

1.基于cesium 实现三维场景展示效果
2.源代码 demo 下载

本篇实现 cesium 三维场景展示,效果图如下:
三维模型.gltf场景展示

倾斜摄影场景展示

  1. 加载三维模型 gltf
  • cesium 三维模型格式数据转换
    cesium 支持加载三维模型的格式是 .gltf 或者 .glb,一般我们制作三维模型都是从 3dmax 软件,所以需要转换;官网开源有转换工具 obj2gltf,具体的见这里:https://github.com/AnalyticalGraphicsInc/obj2gltf,转换需要安装 node 环境,我这里加载三维模型就是从 obj 转换 gltf 来的;
  • cesium 加载 gltf 展示代码
*三维模型gltf配置信息*/
MapConfig.Obj3D = {
position:Cesium.Cartesian3.fromDegrees(111.828682, 21.579571,3000),
models:[
{
id:"3D_gltf",
name : "测试3D模型",
position : Cesium.Cartesian3.fromDegrees(111.828682, 21.579571),
uri :"http://localhost:8180/cesium/3DModel/test/gltf_zapo/Object02.gltf"
},
{
id:"3D_gltf",
name : "测试3D模型",
position : Cesium.Cartesian3.fromDegrees(111.828682, 21.579571),
uri :"http://localhost:8180/cesium/3DModel/test/gltf_zapo/Object03.gltf"
},
{
id:"3D_gltf",
name : "测试3D模型",
position : Cesium.Cartesian3.fromDegrees(111.828682, 21.579571),
uri :"http://localhost:8180/cesium/3DModel/test/gltf_zapo/ZP_DB_04.gltf"
}]
}

$("#cesium3DModel").click(function(){
if(cesium.cesiumViewer.entities.length>0){
cesium.cesiumViewer.entities.removeAll();//清空所有模型
}
cesium.add3DGlft(MapConfig.Obj3D);
});

/**

* 加载GLFT模型


* @method add3DGlft


* @param


* @return


*/


add3DGlft: function (obj) {


//加载3dModel


this.add3DEntityModels(obj.models);


//跳转位置


this.flyToPosition(obj.position);


},


/**
* 批量加载3D模型
* @method add3DEntityModels
* @param models 3D模型数组
* @return
*/
add3DEntityModels: function (models) {

if(models && models.length>0){

for(var i=0;i<models.length;i++){

var type = null;

if(models[i].type){

type = models[i].type;

}

var entity = this.cesiumViewer.entities.add({

name : models[i].name,
type : type,

position : models[i].position,

//orientation : orientation,

model : {

uri : models[i].uri,

}

});

}

}

}

加载倾斜摄影场景展示
我这里 cesium 加载倾斜摄影是用 3DTiles 形式,用 .b3dm 格式的数据:

更多的详情见GIS之家小专栏

文章尾部提供源代码下载,对本专栏感兴趣的话,可以关注一波

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现Cesium三维漫游飞行效果可以通过以下步骤实现: 1. 创建一个Cesium Viewer对象: ``` var viewer = new Cesium.Viewer('cesiumContainer'); ``` 2. 通过Camera控制视角和位置: ``` viewer.camera.setView({ destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height), orientation: { heading: Cesium.Math.toRadians(heading), pitch: Cesium.Math.toRadians(pitch), roll: Cesium.Math.toRadians(roll) } }); ``` 3. 为视角添加动画效果: ``` var duration = 5.0; // 动画时间,单位为秒 Cesium.CameraFlightPath.createAnimationCartographic(viewer.scene, { destination: Cesium.Cartographic.fromDegrees(longitude, latitude, height), orientation: { heading: Cesium.Math.toRadians(heading), pitch: Cesium.Math.toRadians(pitch), roll: Cesium.Math.toRadians(roll) }, duration: duration }); ``` 4. 添加键盘和鼠标事件: ``` // 飞行到指定位置 function flyTo(longitude, latitude, height, heading, pitch, roll) { viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height), orientation: { heading: Cesium.Math.toRadians(heading), pitch: Cesium.Math.toRadians(pitch), roll: Cesium.Math.toRadians(roll) } }); } // 监听键盘和鼠标事件 document.addEventListener('keydown', function(event) { switch (event.keyCode) { case 87: // W viewer.camera.moveForward(1000.0); break; case 83: // S viewer.camera.moveBackward(1000.0); break; case 65: // A viewer.camera.moveLeft(1000.0); break; case 68: // D viewer.camera.moveRight(1000.0); break; case 38: // Up arrow viewer.camera.lookUp(0.1); break; case 40: // Down arrow viewer.camera.lookDown(0.1); break; case 37: // Left arrow viewer.camera.lookLeft(0.1); break; case 39: // Right arrow viewer.camera.lookRight(0.1); break; default: return; } event.preventDefault(); }, false); ``` 通过以上步骤,即可实现Cesium三维漫游飞行效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值