【问题标题】:How to move multiple meshs in different directions with three.js?如何使用three.js在不同方向移动多个网格?
【发布时间】:2015-09-06 21:52:56
【问题描述】:

我有问题。使用 for 循环,我创建了 100 个网格。它们都有 0,0,0 的位置。但我希望这 100 个网格在所有不同方向上分开移动。

这是我创建 100 个网格的代码

for(var i = 0; i < 100; i++)
{
var geometry = new THREE.BoxGeometry(2, 2, 2);
var material = new THREE.MeshBasicMaterial( { color: 0x2194ce} );
mesh = new THREE.Mesh( geometry, material);

mesh.position.x = 0;
mesh.position.y = 0;
mesh.position.z = 0;    
scene.add(mesh);    
}

这是我如何移动 100 个网格的代码,但它只移动一个网格

function render(){
        requestAnimationFrame( render );
            mesh.position.x +=0.1;
            renderer.render(scene, camera); 

        }

【问题讨论】:

    标签: javascript object three.js mesh


    【解决方案1】:

    mesh 中只有最后一个网格 多变的。为了移动所有,您可以将它们存储在一个数组中,然后在渲染循环中迭代该数组并分配新位置。 mesh.position.z = 0; meshes.push( mesh );

    在渲染中:

     for( var i=0; i<meshes.length; i++){
          meshes[i].position.x += 0.1;
     }
    

    我没有测试过。

    【讨论】:

      猜你喜欢
      • 2017-09-25
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      • 2017-08-21
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      相关资源
      最近更新 更多