Replies: 2 comments
-
I would probably use setState for this and tie it up to the view |
Beta Was this translation helpful? Give feedback.
0 replies
-
I solve this with this code const Box: React.FC = (props) => {
const meshEl = React.useRef<Mesh>(null);
let prevTime = 0, currTime
useFrame(({clock}) => {
currTime = clock.getElapsedTime()
if(currTime - prevTime > 60){
meshEl.current.position.set(someHeavyComputations());
prevTime = clock.getElapsedTime()
}
meshEl.current.rotation.x = meshEl.current.rotation.y += 0.01;
});
return (
<mesh ref={meshEl} material={defaultMaterial}>
<boxBufferGeometry args={[3, 3, 3]} />
</mesh>
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
According to the document,
useFrame
allows us to execute code on every frame rendered. However, there are cases that we don't want to put in every 1/60 seconds. What is the recommended way of doing this?For example, I have a mesh, which:
rotation.y
on each frame.What I'm doing right now is:
Any better way to achieve this?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions