如何设置在three.js中添加网格到场景的时间延迟

时间:2016-04-06 10:52:36

标签: javascript three.js

我需要在时间延迟中将网格添加到场景中。遗憾的是setTimeout功能对我不起作用

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);
}

此处pointzz包含x的{​​{1}}和z坐标。代码工作正常。所有网格都添加到mesh但我需要在很短的时间内添加每个网格

1 个答案:

答案 0 :(得分:0)

#home { background: url(http://webneel.com/wallpaper/sites/default/files/images/01-2014/23-animation-wallpaper.preview.jpg) no-repeat center 0 fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; height: 1000px; margin: 0 auto; width: 100%; max-width: auto; position: relative; } setTimeout中工作正常。

请参阅 this fiddle here 了解演示(2秒后添加网格和线框)。

为什么three.js不是你想要的?你想要达到什么目标?