Hello again community. I would like to create camera movements that are related to the sprite points I have added on my model. I looked at this examples here and it’s a really good example of what I would like to achieve but I don’t want to use pre-defined positions for camera and .lookAt function SBEDIT : Online Code Editor.
I am doing a more general approach so that I can be able to upload any model and then have points on that model and still achieve the same outcome. On the screenshot provided, I would like to click on a point (indicated by the black arrow) and then my camera should zoom in to the relative position (indicated by the red rectangle) and then it should be displayed on my canvas. I would like to do that for each and every point I have on that model. You contribution would be highly appreciated.
I have this code so far, it’s almost doing what I want but it’s zooming on other parts of the model instead of the ones where the points actually are
let onPointerClick = () => {
raycaster.setFromCamera(pointer, camera);
const intersects = raycaster.intersectObjects(getPoints);
if (intersects.length > 0) {
const intersectedPoint = intersects[0].object;
const worldScale = new THREE.Vector3();
intersectedPoint.getWorldScale(worldScale);
const offset = new THREE.Vector3(worldScale.x * 10, worldScale.y * 10, worldScale.z * 10);
const newCameraPosition = intersectedPoint.position.clone().add(offset)
camera.position.set(intersectedPoint.position.x, intersectedPoint.position.y, intersectedPoint.position.z);
camera.position.copy(newCameraPosition);
camera.lookAt(intersectedPoint.position);
camera.zoom = 3;
camera.updateProjectionMatrix();
} else
console.log('No interceptions on this point');
const intersectedMapLevel = raycaster.intersectObjects(getMapLevels);
if (intersectedMapLevel.length > 0) {
const mapLevel = intersectedMapLevel[0].object;
} else
console.log('No Map Level Intersected');
}