我正在尝试一次编写大量对象,并且希望颜色褪色。但是,在使用 制作字符串后.toString(16)
,它不会在代码中读取它所说的,new THREE.MeshBasicMaterial({ color: '0x' + color, wireframe: false, opacity: 0.5 });
这是当前的代码:
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
for (var k = 0; k < 10; k++) {
geometry = new THREE.CubeGeometry(50, 50, 50);
colorr = 254 / 10 * k;
colorr = Math.round(colorr);
colorr = colorr.toString(16);
colorg = 254 / 10 * k;
colorg = Math.round(colorg);
colorg = colorg.toString(16);
colorb = 254 / 10 * k;
colorb = Math.round(colorb);
colorb = colorb.toString(16);
color = '0x' + colorr + colorg + colorb;
material[i] = new THREE.MeshBasicMaterial({ color: color, wireframe: false, opacity: 0.5 });
mesh[i] = new THREE.Mesh(geometry, material[i]);
mesh[i].position.x = -500 + (k * 100);
mesh[i].position.y = -500 + (j * 100);
mesh[i].position.z = -500 + (i * 100);
scene.add(mesh[i]);
objects.push(mesh[i]);
}
}
}
但是,它只会产生灰黑色。