Camera Positioning Issue: Integrating Three.js MapControls with GSAP Animation for Precise Target Locations

Hello everyone,

I’m encountering a problem while animating my 3D model using GSAP and Three.js. Specifically, the issue occurs when I pan the model - the camera doesn’t move to the intended target position correctly.

I’m trying to replicate the functionality seen on the Canadian Dairy Farm website (Canadian Dairy Farm Discovery | Dairy Farmers of Canada). On that site, when you interact with the model by panning or rotating and then click a button, the camera smoothly transitions to the correct coordinates associated with that button.

I’d greatly appreciate any assistance in resolving this issue. If anyone has experience with similar implementations or can offer guidance, I’m open to connecting through any preferred communication medium to discuss this further.

Thank you in advance for your help!

I’ve included the code snippet below for your review. Please take a look and provide any assistance you can. The buttonData array contains objects that define interactive buttons in the 3D environment. Each object includes the button’s position and specifies where the camera should focus when the button is clicked. This array is used to control camera animation in the 3D scene.

const buttonData = [
    {
        position: new THREE.Vector3(7, 1, 5.5),
        targetPosition: new THREE.Vector3(8.5, 0.8, 6),
        title: "Construction of Large diameter Tunnels using Segmental linings",
        bsTarget: "#segmentalLiningCanvas",
        class: "segmental-lining-icon",
    },//Other button data similar as this one
]

buttonData.forEach((data) => {
    // ... (button creation code through css2drenderer and css2dobject)

    btn.addEventListener("click", (event) => {
        event.preventDefault();
        event.stopPropagation();

        // ... (other button click handling code)

        hideAllButtonsExcept(cPointBtn);

        controls.minDistance = (data.bsTarget === "#augerCanvas") ? 3 :
                               (data.bsTarget === "#rehabCanvas") ? 0 :
                               (data.bsTarget === "#microtunnelingCanvas") ? 6.4 : 7;

        gsap.to(camera.position, {
            duration: 4,
            x: data.targetPosition.x,
            y: data.targetPosition.y,
            z: data.targetPosition.z,
            ease: "power2.inOut",
            onUpdate: () => {
                const targetPosition = new THREE.Vector3(data.targetPosition.x, data.targetPosition.y, data.targetPosition.z);
                camera.lookAt(targetPosition);
            },
            onComplete: () => {
                restartAnimations();
            },
        });
    });
});

function resetCameraPosition() {
    gsap.to(camera.position, {
        duration: 2,
        x: targetPosition.x,
        y: targetPosition.y,
        z: targetPosition.z,
        ease: "power2.inOut",
        onUpdate: () => {
            camera.lookAt(scene.position);
            controls.update();
        },
        onComplete: () => {
            controls.minDistance = 7;
            controls.maxDistance = 12;
            controls.update();
            restartAnimations();
            setTimeout(showAllButtons, 100);
        }
    });
}

I think you’ll dramatically increase your chances of someone helping you when you post code that someone can examine…

I have a demo with similar controls to the linked website in the OP.
It uses JEasings though. The licence is much more permissive.

1 Like

I have updated my question with the code snippet please go through it.

Look at this.
But as for the formal circumstances regarding licensed use that seanwasere mentioned, you need to check the paperwork

I attempted the solution, but the issue persists when I pan. Could this be because I’m using a single 3D model with all the buttons set at different coordinates within the same GLB file? Should I create separate models for the targeted points to ensure they work properly, or is there another solution?

I don’t think so.
Basically, is a little bit unclear for me. So, you using single model, let say building, and camera doesn’t reset to previous position (after triggering gsap) before/after (?) pan, right?

I don’t think so… as well.

Could you make CodePen with that (and gsap implementation)?