Calling requestAnimationFrame recomendations

Is it recomended call requestAnimationFrame without stoping if i want to animate my scene only when has mouse click. Or that is good practice fire it’ after event click and after that stop it ? I think that may overset declarative approach with imperative ?

In some rare cases it may be a good practice - if you have super-heavy rendering of complex static scenes - or when the updates of 3D scene are really infrequent and not the main part of the app.

In 99% of other cases stopping rendering could most likely be just an overoptimisation that will cause more trouble than help (it effectively prevents stuff like dynamic shaders, postprocessing, animations etc. from working.) If your rendering has poor performance, preventing frames from being rendered doesn’t really fix it - it just hides it and will cause stutter / poor user experience as soon as the user interacts with your scene.

1 Like

everything that @mjurczyk said and often the only reason you’d do on-demand in the first place is battery concerns. some devices just start to ramp up fans if webgl runs and on some landing page perhaps you might want to avoid that if things in your scene are allowed to come to rest. otherwise i would not worry and prefer a loop.

1 Like

@mjurczyk thank you for answer that is very helpful to understand usage recommendations of requestAnimationFrame

@drcmda Also thanks to mention one more detailed reason