Hey guys, new to react and gsap here, also haven't used codepen before so I don't know how to import my models and use react there - thus the code looks messy and doesn't display anything but just putting it there for you guys to better visualise the problem
I tried Scroll Trigger with 2d elements and they work fine, however when I try it with 3d elements it displays the usual error I see around about the missing plugin. I've tried searching for similar threads/problems but all those are for 2d elements and have not worked to solve my issue.
My code with gsap.to works, but the scroll trigger afterwards doesn't work. I assume the problem is related to scroll trigger for 3d models? I wrapped it in a <Canvas> element.
Error:
Invalid property markers set to true Missing plugin? gsap.registerPlugin()
Here is the code again in case codepen doesn't work:
import React, { useEffect, useRef } from 'react';
import { useGLTF, PerspectiveCamera } from '@react-three/drei';
import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import { useControls } from 'leva';
import { useSound } from 'use-sound';
import * as THREE from 'three';
import { useFrame } from '@react-three/fiber';
import { OrbitControls, Html } from '@react-three/drei';
export default function BoxTest(props) {
const { nodes, materials } = useGLTF('./models/box.glb')
const ref = useRef();
const tl = useRef();
const { scale, rotation, position } = useControls({
scale: 0.8,
rotation: [4.5, 6.5, 3],
position: [-0.6, -1.4, -1]
});
useEffect(() => {
gsap.registerPlugin(ScrollTrigger);
tl.current = gsap.timeline();
tl.current.to(ref.current.position, {y: 5, markers: true, ScrollTrigger: {
trigger: tl.current,
scrub: true,
}})
}, []);
return (
<>
<ambientLight intensity={1} />
<OrbitControls enableZoom={false} />
<group dispose={null}>
<group {...props} dispose={null}>
<PerspectiveCamera makeDefault={false} far={100} near={0.1} fov={22.895} position={[7.359, 4.958, 6.926]} rotation={[-0.627, 0.71, 0.441]} />
<mesh
ref={ref}
scale={scale}
position={position}
rotation={rotation}
geometry={nodes.Cube.geometry}
material={materials.Material} />
</group>
</group>
</>
);
}
useGLTF.preload('./models/box.glb');