我正在通过构建自定义的面来创建自定义几何体。我正在使用MeshNormalMaterial
作为材料,我想要彼此独立地定义面的颜色。但是,无论我设定什么颜色,我仍然会得到相同的效果。
我的代码如下:
var geometry = new THREE.Geometry();
for (var i = 0; i < length - 1; i++) {
for (var j = 0; j < length - 1; j++) {
geometry.vertices.push(new THREE.Vector3(x[i][j], y[i][j], z[i][j]));
geometry.vertices.push(new THREE.Vector3(x[i + 1][j], y[i + 1][j], z[i + 1][j]));
geometry.vertices.push(new THREE.Vector3(x[i + 1][j + 1], y[i + 1][j + 1], z[i + 1][j + 1]));
geometry.vertices.push(new THREE.Vector3(x[i][j + 1], y[i][j + 1], z[i][j + 1]));
var face = new THREE.Face4(index, index + 1, index + 2, index + 3);
face.color.setHex(color);
geometry.faces.push(face);
index += 4;
}
}
geometry.computeFaceNormals();
var object = new THREE.Mesh(geometry, new MeshNormalMaterial());
parent.add(object);
我应该更改上面的代码,例如我可以设置面部颜色并让它们实际显示我设置的颜色吗?
答案 0 :(得分:3)
AFAIK MeshNormalMaterial
将始终为您提供相同的颜色。
试试这个:
new MeshBasicMaterial({ vertexColors : THREE.VertexColors })