加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
transition.js 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
Jiulong Hu 提交于 2018-01-19 01:28 . init
import {
Math as _Math,
Vector3
} from 'three'
const origin = new Vector3();
function Transition( geometry, from, to, duration, camera, cameraFrom, cameraTo ) {
this.to = to;
this.from = from;
this.duration = duration;
this.progress = 0;
this.startAt = 0;
this.playing = false;
this.resetCamera = cameraFrom && cameraTo;
this.cameraFrom = cameraFrom;
this.cameraTo = cameraTo;
this.geometry = geometry;
this.start = () => {
this.playing = true;
this.startAt = Date.now();
}
this.stop = () => {
this.playing = false;
}
this.update = () => {
if ( !this.playing ) return;
this.progress = _Math.clamp( ( Date.now() - this.startAt ) / this.duration, 0, 1 );
this.geometry.vertices.map( ( v, i ) => {
const v1 = this.from[ i ];
const v2 = this.to[ i ];
v.lerpVectors( v1, v2, this.progress );
} )
this.geometry.verticesNeedUpdate = true;
if ( this.resetCamera ) {
camera.position.lerpVectors( this.cameraFrom, this.cameraTo, this.progress );
camera.lookAt( origin );
}
if ( this.progress === 1 ) {
this.playing = false;
}
}
}
export { Transition }
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化