My goal is update a Three JS scene (colors, camera position, material properties, etc.) based on state properties set by the timeline. My scene is rendered inside of the BlobScene component which accepts an intensity prop. In the sample below, I'd like to update the intensity as the timeline is scrubbed which then updates the light intensity of my scene.
In the pinned section, there are two columns: the left column contains text that will be translated into view and the right column contains the BlobScene. My ultimate goal is to change the color of the blob for each corresponding text section. So when the user scrolls from the red section to the green section, for example, the blob mesh would smoothly transition it's material color from red to green.
Am I going about this the wrong way? I can create a minimal demo if needed.
import React, { useState, useEffect } from "react"
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import BlobScene from '../components/blob-scene'
function Index() {
let [intensity, setIntensity] = useState({value: 1.5})
useEffect(() => {
gsap.registerPlugin(ScrollTrigger)
// Verticals Pinned Section Story
const tl = gsap.timeline()
tl.from(".red", {y: "100%"})
.from(".green", {y: "100%"})
.from(".blue", {y: "100%"});
// PROBLEM LINE
tl.to(intensity, { value: setIntensity(0.5) })
ScrollTrigger.create({
animation: tl,
trigger: "#verticals",
scroller: "#___gatsby",
start: "top top",
end: "+=4000",
scrub: true,
pin: true,
anticipatePin: 1
});
// each time the window updates, we should refresh ScrollTrigger and then update LocomotiveScroll.
ScrollTrigger.addEventListener('refresh', () => window.scroll.update())
ScrollTrigger.refresh()
}, [intensity]);
return (
<React.Fragment>
<div className="page">
<section id="verticals" className="h-screen flex items-center relative w-full overflow-hidden">
<div className="grid grid-cols-2 gap-6 h-full w-full">
{/* Grid Column 1 */}
<div className="flex items-center">
<div className="relative w-full overflow-hidden h-80">
<div className="panel absolute h-full w-full red bg-red-500 text-black">
<h2>Panel 1</h2>
</div>
<div className="panel absolute h-full w-full green bg-green-500">
<h2>Panel 2</h2>
</div>
<div className="panel absolute h-full w-full blue bg-blue-500">
<h2>Panel 3</h2>
</div>
</div>
</div>
{/* Grid Column 2 */}
<div className="flex items-center">
<BlobScene intensity={intensity.value}></BlobScene>
</div>
</div>
</section>
</div>
</React.Fragment>
)
}
export default Index