Hi,
I have a tween function (please see code below) to pan camera to certain area. It works well, but mouse became really heavy to scroll in and out after tween. After some research I found the cause is it has really close cords with camera position and target position:
cameraPosition: [-20472.681897165796, 4480.34211787887, 7362.555231241536],
controlTarget:[-20464.22315037777, 3922.34212359485,6859.2531328649775]
I find these two cords from orbit control event listener
this.#controls.addEventListener("change", (e) => {
console.log(e);
})
To fix the issue, I tried:
- tween camera without target control
- correct control target after tween is finished
Result:
- I can’t tween to this area correctly without target position, is there a way to do this?
- I tried to put this.#control.target.set(0,0,0) inside onComplete() before control.update() but doesn’t work, target inside control object is not overwritten
Please give me some hints on how to fix the mouse issue or how to avoid finding a position have close camera position and target? Thank you!!
Here is my tween function which tween both camera and target:
tweenCameraTo = (to) => {
TWEEN.removeAll()
const [toX, toY, toZ] = to.cameraPosition
const [targetX, targetY, targetZ] = to.controlTarget
return new Promise((resolve) => {
new TWEEN.Tween(this.#camera.position)
.to({
x: toX,
y: toY,
z: toZ,
}, 3000)
.easing(TWEEN.Easing.Quadratic.InOut)
.onStart((_) => {
this.#controls.enabled = false
new TWEEN.Tween(this.#controls.target)
.to( {
x: targetX,
y: targetY,
z: targetZ,
}, 3000)
.easing(TWEEN.Easing.Quadratic.InOut)
.onUpdate((_) => { this.#controls.update() })
.start()
})
.onComplete((_) => {
this.#camera.updateProjectionMatrix()
this.#camera.updateMatrix()
this.#controls.enabled = true
this.#controls.update()
resolve(to)
}) .start()
})
}