function createTween (params) {
new TWEEN.Tween(params.object)
.to(params.to, params.duration)
.onComplete(() => onComplete())
.onUpdate(params.onUpdate)
.easing(params.easing)
.start()
}
function onComplete() {
console.log("onComplete")
}
var tweenParams = {
targetTweenDuration: 2500,
posTweenDuration: 2500,
upTweenDuration: 2500,
targetTweenEasing: {
id: TWEEN.Easing.Quadratic.Out,
name: 'Linear'
},
posTweenEasing: {
id: TWEEN.Easing.Quadratic.Out,
name: 'Linear'
},
upTweenEasing: {
id: TWEEN.Easing.Quadratic.Out,
name: 'Linear'
},
configManager: null,
showLoader: true
}
function tweenCameraTo (state, immediate) {
immediate = false;
const targetEnd = new THREE.Vector3(
state.viewport.target[0],
state.viewport.target[1],
state.viewport.target[2])
const posEnd = new THREE.Vector3(
state.viewport.eye[0],
state.viewport.eye[1],
state.viewport.eye[2])
const upEnd = new THREE.Vector3(
state.viewport.up[0],
state.viewport.up[1],
state.viewport.up[2])
const nav = viewer.navigation
const target = new THREE.Vector3().copy(
nav.getTarget())
const pos = new THREE.Vector3().copy(
nav.getPosition())
const up = new THREE.Vector3().copy(
nav.getCameraUpVector())
const targetTween = createTween({
easing: tweenParams.targetTweenEasing.id,
onUpdate: (v) => {
nav.setTarget(v)
},
duration: immediate ? 0 : tweenParams.targetTweenDuration,
object: target,
to: targetEnd
})
const posTween = this.createTween({
easing: tweenParams.posTweenEasing.id,
onUpdate: (v) => {
nav.setPosition(v)
},
duration: immediate ? 0 :tweenParams.posTweenDuration,
object: pos,
to: posEnd
})
const upTween = this.createTween({
easing: tweenParams.upTweenEasing.id,
onUpdate: (v) => {
nav.setCameraUpVector(v)
},
duration: immediate ? 0 : tweenParams.upTweenDuration,
object: up,
to: upEnd
})
Promise.all([
targetTween,
posTween,
upTween]).then(() => {
animate = false
console.log(11111)
})
}
// function animate(time) {
// requestAnimationFrame(animate);
// TWEEN.update(time);
// console.log(1)
// }
// requestAnimationFrame(animate);
function runAnimation (start) {
if (start || animate) {
this.animId = window.requestAnimationFrame(
runAnimation)
Tween.update()
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。