i wonder if there is any way to be able to cap amount of times code is executed in useFrame.
for example if device renders scene in 120fps, it means that useFrame
will execute 120 times in a second, i have custom particle snow and i use useFrame
this way:
useFrame(() => {
for (let i = 0; i < count*3; i+=3) {
//x
particle.current.attributes.position.array[i] -= velocity[i];
//y
particle.current.attributes.position.array[i+1] -= velocity[i+1];
//z
particle.current.attributes.position.array[i+2] -= velocity[i+2];
// y<0
if (particle.current.attributes.position.array[i+1] <= -3.3) {
//x
particle.current.attributes.position.array[i] = Math.random()*20-10;
//y
particle.current.attributes.position.array[i+1] = Math.random()*13.2 -3.2;;
//z
particle.current.attributes.position.array[i+2] = Math.random()*20-10;
}
}
particle.current.attributes.position.needsUpdate = true;
})
obviously executing it at different fps gives different performance , so for 40 fps snow is quite slow and smooth , but for 120fps its too fast(just chaotic movement), i would like to cap useFrame() the way, that
doesn’t matter what the fps of scene is, it is executed only 40 times per second.