var position = Cesium.Cartesian3.fromDegrees(obj.position[0], obj.position[1], obj.position[2]); //数据加载位置
var heading = Cesium.Math.toRadians(obj.heading);
var pitch = Cesium.Math.toRadians(obj.pitch);
var roll = Cesium.Math.toRadians(obj.roll);
var hpRoll = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var converter = Cesium.Transforms.eastNorthUpToFixedFrame;
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter);
//添加三维模型
var tileset = this.viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: obj.url, //模型数据url
show: obj.show, //确定是否显示图块集
asset: {
id: obj.id
},
})
);
tileset.readyPromise.then(function () {
//请求模型后执行
tileset._root.transform = modelMatrix; //模型位置
tileset.asset.id = obj.id;
Object.assign(tileset.asset, obj.option);
}).otherwise(function (error) {
throw error
})
return tileset;
效果如下图: