cesium加载 gltf模型
- 首先自己配置一个iis环境 :http://www.xitongcheng.com/jiaocheng/win10_article_60912.html,其他环境 比如 node 或者 内服务器就不用配置环境,直接写代码就行了
- 把iis路径设置到项目文件夹的位置
- 写代码
// 加载gltf模型
function createModel(url, height) {
viewer.entities.removeAll();var position = Cesium.Cartesian3.fromDegrees(
-123.0744619,
44.0503706,
height
);
//弧度的航向分量。
var heading = Cesium.Math.toRadians(135);
//弧度的螺距分量。
var pitch = 0;
//滚动分量(以弧度为单位)
var roll = 0;
//HeadingPitchRoll旋转表示为航向,俯仰和滚动。围绕Z轴。节距是绕负y轴的旋转。滚动是关于正x轴。
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(
position,
hpr
);
var entity = viewer.entities.add({
name: url,
position: position,
orientation: orientation,
model: {
uri: url,
//不管缩放如何,模型的最小最小像素大小。
minimumPixelSize: 128,
//模型的最大比例尺大小。 minimumPixelSize的上限。
maximumScale: 20000,
},
});
viewer.trackedEntity = entity;
// 获取或设置相机当前正在跟踪的Entity实例。
}
createModel("/model/untitled.gltf", 5000);
- 用的iis服务器,不添加.gltf是添加不上了gltf模型
- 设置添加.gltf模型
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210513200235945.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ4MjAzODI4,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210513200433183.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ4MjAzODI4,size_16,color_FFFFFF,t_70)
- 设置完以后就可以正常添加gltf模型了。