Hello person, how are you?
I have a map with spherical assets
When I click on an asset it opens the canvas on the side and if I can focus on it with this function below
handlefocusOnObject(id: string) {
const item = this.scene.children.find((item) => item.userData.id === id);
const currentZoom = this.camera.zoom;
const currentTarget = this.controls.target.clone();
const currentRotation = this.camera.rotation.clone();
const currentPosition = this.camera.position.clone();
const verticalAngle = 45;
const horizontalAngle = 45;
const Objectsdistance = 10000;
const camera = this.camera;
const controls = this.controls;
if (item) {
const vector = new THREE.Vector3();
const box = new THREE.Box3();
box.setFromObject(item);
box.getCenter(vector);
this.camera.lookAt(vector);
this.controls.enableRotate = false;
new TWEEN.Tween({ zoom: currentZoom })
.to({ zoom: this.minZoom + 0.03 }, 1000)
.easing(TWEEN.Easing.Quadratic.InOut)
.onUpdate(({ zoom }) => {
this.camera.zoom = zoom;
this.camera.updateProjectionMatrix();
})
.onComplete(() => {
this.camera.position.copy(currentPosition);
this.controls.update();
})
.start();
new TWEEN.Tween(this.camera.position)
.to(currentPosition, 1000)
.easing(TWEEN.Easing.Quadratic.InOut)
.onUpdate(() => {
if (this.viewMode === '3D')
this.camera.lookAt(currentPosition);
})
.start();
new TWEEN.Tween(currentTarget)
.to(vector, 1000)
.easing(TWEEN.Easing.Quadratic.InOut)
.onUpdate(() => {
this.controls.target.copy(currentTarget);
this.camera.rotation.copy(currentRotation);
this.handleModelOrientation({ camera, controls, vertical: verticalAngle, horizontal: horizontalAngle, distance: Objectsdistance });
})
.onComplete(() => {
this.camera.position.set(currentPosition.x, currentPosition.y, 0);
this.controls.enableRotate = true;
this.camera.position.copy(currentPosition);
})
.start();
TWEEN.update();
}
this.camera.updateMatrixWorld();
this.controls.update();
}
The problem is that the map is rotating with I center the asset with focus.
Does anyone have any idea what it could be?