简体   繁体   中英

How to set time delay in adding mesh to scene in three.js

I need to add a mesh into the scene in a time delay . unfortunately setTimeout function doesn't work for me

var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshLambertMaterial({color: 0xFF0000, side: THREE.DoubleSide});
function addMesh(mesh)
{
    setTimeout(function()
    {
        Scene.add(mesh);
    },3000);
}

for (var i = 0; i < pointzz.length; i += 2) {
    var mesh = new THREE.Mesh(geometry, material);
    mesh.rotation.x = -Math.PI / 2;
    mesh.rotation.y = Math.PI;
    mesh.rotation.z = Math.PI;
    mesh.name = "mesh";
    mesh.position.set(pointzz[i], 0, pointzz[i + 1]);
    mesh.scale.set(15, 15, 15);
    addMesh(mesh);
}

here pointzz contains the x and z coordinates of the mesh . The code works fine. All the meshes are added to the scene but I need each mesh need to be added in a small time delay

setTimeout works fine in three.js .

See this fiddle here for a demo (adds mesh and wireframe after 2 seconds).

Why is setTimout not what you want? What do you want to achieve?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM