It seems like a simple task, but I've been struggling with it for days.
How can I add objects to a scene with a pause between each addition?
Inside a loop{
I call the make_obj function()
then I call the wait function()
}
The issue is that the program doesn't display each added object with a pause; instead, it waits until the loop ends and then shows all the objects together on the screen after all pauses have been completed.
I've tried to explain this before
Three.js scene not reacting while program is running
but it seems too complicated, so I'm breaking it down here.
Thank you in advance.
Edit_1: Yes, I can. Please consider the scene and three as objects inserted by another class. These are standard instantiations.
test = function (scene, three){
this.scene = scene;
this.caller_inst = three;
var that= this;
var depth_mod=0;
this.start_loop=function(){
var i;
for(i = 0; i < 10; i++){
this.make_objects();
this.wait(1000);
}
};
this.wait = function(ms){
setTimeout(function(){ console.log("Wait!"); }, ms);
return;
console.log("wait start");
var start = new Date().getTime();
var end = start;
while(end < start + ms){
end = new Date().getTime();
}
console.log("wait ended");
};
this.make_objects = function(count_rows, count_columns){
var color = '#'+Math.floor(Math.random()*16777215).toString(16);
var sphere_geometry = new THREE.SphereGeometry(1);
var material1 = new THREE.MeshPhongMaterial({ color: color, specular: 0x555555 });
var sphere_mesh = new THREE.Mesh(sphere_geometry, material1);
this.scene.add(sphere_mesh);
sphere_mesh.position.copy(that.caller_inst.camera.position);
sphere_mesh.position.x = sphere_mesh.position.x+5+depth_mod;
sphere_mesh.position.z = sphere_mesh.position.z-15 + depth_mod;
that.caller_inst.renderer.render(that.caller_inst.scene, that.caller_inst.camera);
depth_mod = depth_mod-1;
};
};
I made a slight modification but got the same result.
this.start_loop=function(){
var i;
for(i = 0; i < 10; i++){
setTimeout(function(){ that.make_objects(); }, 1500);
}
};
Why doesn't manual waiting work like this:
var i;
for(i = 0; i < 10; i++){
this.object[i].visible = true;
this.wait(1000);
}
?