Kayon
Kayon

Reputation: 11

ThreeJS Globe Camera and OrbitControls issues on rotate

I'm working a 3D Globe to display some lovely fruits from all over the world. It's working nice but I have two main issues i can't resolve.

If a crazy webGL wizard comes around I would LOVE some help about those issues. Thanks a lot in advance !

Here's the link to the repo : https://github.com/Rakido/final-inte It's without package to integrate it later on Shopify, you can launch it with a simple http-server command line.

Thanks a lot ❤️

EDIT :

I kinda of manage the desired effect for the second issue. Here's the code I added in the rotateGlobe function. But it's glitchy when the camera is moving through the globe sometimes. How to handle properly the position to not have the glitch ?

const fruitIndex = fruits.indexOf(fruit) + 1;
const selectedPin = globeGroup.children[fruitIndex];
const pinPosition = new THREE.Vector3();
selectedPin.getWorldPosition(pinPosition); // Obtient la position mondiale du pin
const r_cam = camera.position.length(); // Utiliser la distance actuelle de la caméra
const phi = Math.acos(pinPosition.y / pinPosition.length());
const theta = Math.atan2(pinPosition.z, pinPosition.x);
const x_cam = r_cam * Math.sin(phi) * Math.cos(theta);
const y_cam = r_cam * Math.cos(phi);
const z_cam = r_cam * Math.sin(phi) * Math.sin(theta);
camera.lookAt(pinPosition);

gsap.to(camera.position, {
    x: x_cam,
    y: y_cam,
    z: z_cam,
    duration: 1,
    ease: "power4.inOut"
});

Upvotes: 0

Views: 43

Answers (0)

Related Questions