2012-09-19 207 views
3

我正在通過構建自定義位置的面創建自定義幾何。我正在使用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); 

我應該改變上面的代碼,例如我可以設置臉部顏色,讓他們實際顯示我設置的顏色?

回答

3

AFAIK MeshNormalMaterial將永遠給你相同的顏色。

試試這個:

new MeshBasicMaterial({ vertexColors : THREE.VertexColors })