如果模型文件类型不是gltf或者glb,可以参考: obj文件批量转换为gltf/glb
添加模型代码示例:
// 添加模型
this.addModel('cat', 114.055641, 22.53415, 0, { scale: 0.2 });
// 方法定义
addModel(name, lon, lat, h, options = {}) {
const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(lon, lat, h)
);
const model = Cesium.Model.fromGltf({
url: `/models/Output/${name}.gltf`,
modelMatrix: modelMatrix,
maximumScreenSpaceError: 16,
maximumScale: 10,
minimumPixelSize: 20,
scale: 1,
...options
})
this.viewer.scene.primitives.add(
model
);
return model;
}
如果需要移除模型:
// 移除
this.viewer.scene.primitives.remove(model);