admin管理员组文章数量:1122832
gsap.registerPlugin(ScrollTrigger, useGSAP);
const Scene = () => {
const creamTubeRef = useRef<Group>(null);
useGSAP(() => {
const scrollTl = gsap.timeline({
defaults: {
duration: 2,
},
scrollTrigger: {
trigger: ".hero",
start: "top top",
end: "bottom bottom",
scrub: 1.5,
markers: true,
},
});
if (creamTubeRef.current) {
console.log("e");
scrollTl
.to(creamTubeRef.current.rotation, { y: Math.PI * 2 })
.to(creamTubeRef.current.position, { x: -5.2, y: -0.7, z: -2 }, 0);
}
});
return (
<View className=" border-4 pointer-events-none sticky top-0 z-50 -mt-[100vh] h-screen w-full md:block">
{/* <gridHelper /> */}
<group position:{[0,0,0]} ref={creamTubeRef}>
<OneCreamtube />
</group>
</View>
);
};
export default Scene;
<OneCreamTube />
is a regular 3D model that renders fine.
I tried to animate the position of the <OneCreamTube />
component using GSAP. However, I got an issue where the useRef
hook initially returned null for the reference, and it failed to update even after the component was successfully rendered and the reference should no longer be null
. How can I fix this?
Thanks in advance!
版权声明:本文标题:reactjs - Why got null in useRef with 3dModel ReactThreeFiber GSAP? and how i can update it - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311875a1934897.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论