Let’s say I have a particle sim using a Points object with ~10,000 points.
animate() {
requestAnimationFrame(animate);
for(let i = 0; i < Particles.total; i++) {
//code goes here
this.points.geometry.getAttribute('position').needsUpdate = true;
this.points.geometry.getAttribute('color').needsUpdate = true;
},
}
So, that loop is always firing in order to visually update the particles.
But let’s say the colors only update periodically. Is it more efficient to write a function like
updateAllColors() {
for(let i = 0; i < Particles.total; i++) {
//change each point color here..
}
or to set a boolean like “needsColorUpdate = true”, and then inside my animation loop, whenever that flag is true, handle the color change there?
Basically, what’s better: adding a redundant iteration loop that only happens once in a while, OR, adding a boolean check that is constantly firing in the animation loop (even if the color update only happens once)?