我想创建多个对象。
var distance = 10;
var geometry = new THREE.BoxGeometry(10,10,10);
var material = new THREE.MeshBasicMaterial({color:0x00ff44});
for(var i = 0; i < 4;i++){
var mesh = new THREE.Mesh(geometry, material);
mesh.position.z = distance;
scene.add(mesh);
distance += 5;
};`
使用此代码我创建它,但只在一行中。我想在第一行的背面创建更多行。喜欢这张图片:
我想在 Red X 位置上添加更多立方体。
答案 0 :(得分:2)
var xDistance = 50;
var zDistance = 30;
var geometry = new THREE.BoxGeometry(10,10,10);
var material = new THREE.MeshBasicMaterial({color:0x00ff44});
//initial offset so does not start in middle.
var xOffset = -80;
for(var i = 0; i < 4; i++){
for(var j = 0; j < 3; j++){
var mesh = new THREE.Mesh(geometry, material);
mesh.position.x = (xDistance * i) + xOffset;
mesh.position.z = (zDistance * j);
scene.add(mesh);
}
};