gpt4 book ai didi

javascript - Three.js 创建多个对象

转载 作者:行者123 更新时间:2023-12-02 13:46:43 25 4
gpt4 key购买 nike

我想创建多个对象。

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

使用这段代码我创建了它,但只在一行中。我想在第一行的背面创建更多行。就像这张图片:

What i want to create - Image

我想要在Red X位置上放置更多立方体。

最佳答案

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

See this fiddle

关于javascript - Three.js 创建多个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41338474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com