1、最近做核电站的镜头控制;产品要求切换镜头的时候要有个过渡动画;这种简单的东西也没啥好讲的;直接上效果由于做的核电站项目担心被公式起诉;所以搞了类似的东西展示效果;
图书馆(镜头切换)[link](http://3dmad.online.fr/WebGL/Library_Interactive_Map_Mtp/index.html)
2、核心代码
var speed1 = 45;
var speed2 = 45;
var frameCount = 200;
//Animation Camera position
var animateCameraToPosition = function(cam, speed, frameCount, newPos) {
var ease = new BABYLON.CubicEase();
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
BABYLON.Animation.CreateAndStartAnimation('at5', cam, 'position', speed, frameCount, cam.position, newPos, 0, ease);
}
animateCameraToPosition(camera, speed1, frameCount, new BABYLON.Vector3(5, 10, -0));
//Animation Camera target
var animateCameraTargetToPosition = function(cam, speed, frameCount, newPos) {
var ease = new BABYLON.CubicEase();
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
BABYLON.Animation.CreateAndStartAnimation('at5', cam, 'target', speed, frameCount, cam.target, newPos, 0, ease);
}
animateCameraTargetToPosition(camera, speed2, frameCount, new BABYLON.Vector3(11.4, 0, -0));
要控制镜头改变目标值就用targer 改变位置就用position
CubicEase表示一个缓动函数,该函数创建一个使用公式 f(t) = t3 进行加速和/或减速的动画。Babylonjs金主是微软所以也继承了他爸爸类具体解释
参考链接:
https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.media.animation.cubicease?view=net-5.0