一、功能设计
提供参数让二次开发用户可以在应用层实时修改模型是否朝着速度矢量方向,解决无人机在垂直上升时姿态的异常显示。
二、对数据和服务的要求
gltf数据
三、接口设计
提供参数-isSetModelPosture 默认为true
3.1、参数默认true,模型是朝着速度矢量方向
应用层提供路径坐标数组;
let positions = [
Cesium.Cartesian3.fromDegrees(106.3275423851136, 29.332291372123606, 294.43216228122810),
Cesium.Cartesian3.fromDegrees(106.3274449132526, 29.33218636728018, 296.4321622812281),
Cesium.Cartesian3.fromDegrees(106.32743456106668, 29.332086291515342, 296.4321622812281),
Cesium.Cartesian3.fromDegrees(106.32743569795478, 29.3320829466482, 273.1146622812281)
];
内部通过访问器接收;
positions: {
set: function (positions) {
this._positions = positions;
},
get: function () {
return this._positions;
}
}
通过内部函数_startRouteAnimation控制开启动画漫游,并将传入的路径点做一系列处理;
isSetModelPosture 默认为true ,内部函数_startRouteAnimation内设置模型参数:
var entityOption = {
orientation: that._isSetModelPosture? that._vop:undefined, // callbackVOP,
};
当前的模型orientation是that_vop,也就是当前时间点的速度矢量朝向
//sampPosition是带有时间戳的数据,此行代码计算当前时间点的速度矢量朝向
that._vop = new VelocityOrientationProperty(sampPosition);
因此模型始终朝向速度矢量方向:

3.1、参数修改为false,模型不朝着速度矢量方向
同理,当isSetModelPosture 设置为false,开始漫游函数执行,此时orientatio赋值为undefined,因此模型不朝着速度矢量方向
var entityOption = {
orientation: that._isSetModelPosture? that._vop:undefined, // callbackVOP,
};
模型姿态不改变

四、算法逻辑设计
4.1、在1.84版本上,二次开发用户可以在应用层修改模型朝向,现将该功能移植到1.59版本:
1.84相较于1.59版本,在AnimationTool.js漫游工具上,引入包的方式和漫游功能的设计上均有升级,迁移到1.59。
4.2、应用层onPositionCallback函数,根据不同的路段给模型设置不同的模型朝向
onPositionCallback: function (result) {
console.log('到达站点' + result.index + ',站点坐标:' + result.position);
//例如需要在模型运动到第二分段到第四分段上时,使模型运动方向不为速度矢量方向
if(result.index>=2&&result.index<=4){
//animation.animationModel.orientation=undefined;
animation.isSetModelPosture=false;
}else{
animation.isSetModelPosture=true;
};
},
4.3、设置模型的orientation属性
isSetModelPosture 并不能时刻调用,代码层面通过新建全局变量接收并替换orientation属性
if (this._isSetModelPosture) {
this._animationModel.orientation = this._vop;
} else {
this._animationModel.orientation = undefined;
}
4.4、orientation 属性作用原理
新建一个entityOption用来接收orientation
var entityOption = {
//position: sampPosition,
orientation: that._vop
},
设置为模型的参数生效
that._animationModel = new Entity(entityOption);
that._animationModel = that._viewer.entities.add(entityOption);
五、遗留问题
1.onPositionCallback回调函数抛出了三个参数供供应用层设置,分别是speed(速度),speedupFactor(加速因子,倍速),disfactor(距离精度),理论上可以实现实时回调拿到当前分段的索引,实际上只能在三个参数设置到合适的值才能产生回调。有解决方案,且已实现并备份,但是为保证兼容性未更改。
2.理想状态能实时控制无人机的姿态参数,如方位角,俯仰角;而非仅调整速度矢量朝向,需要优化--已完成(点击跳转)