I am trying to animate the size of a React 3 Fiber drei Box component using useFrame. The geometry works fine up until I add the useFrame function, which causes the browser to throw a THREE.WebGLRenderr: Context Lost
error and prevents any re-renders.
import React, {useRef} from 'react';
import { Box } from '@react-three/drei';
import { useFrame } from '@react-three/fiber';
export default function BarGraph() {
const purpleColor = "#5b21b6";
const barRef1 = useRef();
useFrame(
(state) => {
barRef1.current.parameters.depth = Math.sin(state.clock.elapsedTime) + 3;
}
)
return (
<mesh position={[0,1,1]} scale={0.5}>
<Box args={[1,1,3]} position={[1,3,2]} ref={barRef1}>
<meshStandardMaterial color={purpleColor}/>
</Box>
</mesh>
)
I have also tried to replace the contents of the useFrame with barRef1.current.args = [1,1,Math.sin(state.clock.elapsedTime) + 3]
but it produced the same result.
I understand I am overloading the browser's graphics capabilities, but I do not know exactly why or how to throttle it within the useFrame.
UPDATE:
I was able to access and modify the components of the scale
property and achieve the desired results.
useFrame(
(state) => {
barRef1.current.scale.y = Math.sin(state.clock.elapsedTime) + 3;
}
)