I am looking to dynamically add and remove objects in a continuous stream. Imagine having an array of 50 objects, and I want to cycle through them with a period, essentially creating an object stream. I initially attempted using setTimeout and setInterval functions, but unfortunately, they did not yield the desired results both inside and outside the render function. So, I experimented with the following approach:
function render(){
controls.update(clock.getDelta());
renderer.render( scene, camera);
i = i+1;
if (i % 2 == 0){
if (i % 300 == 0){
remove(lights);
}
else
{ scene.add(lights[(i/2)]);
}
}
}
While this code does work, it does not initiate the adding process with the first object. I also attempted utilizing getElapsedTime() instead of iterating through i, but unfortunately, it only added the initial object. Are there any more efficient time-controlled methods that I can utilize for this task?
Thank you in advance.