Is there a way to dynamically change the color of a face without pre-creating a materials palette and then assigning based on vertex value? Here is my current code:
var materials = [];
materials.push([..] //add all the materials here.
var geometry = new THREE.PlaneGeometry(gs, gs, size, size);
$.getJSON('http://localhost:5000', function (data) {
for (var i = 0, l = geometry.vertices.length; i < l; i++) {
geometry.vertices[i].z = data.map[i] / 255;
if (geometry.vertices[i].z > 1) {
geometry.faces[i].materialIndex = 1;
} else {
geometry.faces[i].materialIndex = 0;
}
}
var plane = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
scene.add(plane);
});
I would like something along the lines of:
[..]
$.getJSON('http://localhost:5000', function (data) {
for (var i = 0, l = geometry.vertices.length; i < l; i++) {
geometry.vertices[i].z = data.map[i] / 255;
if (geometry.vertices[i].z > 1) {
geometry.faces[i].setrgb(i*128, i*2, i*96);
} else {
geometry.faces[i].setrgb(i*12, i*2, i*96);
}
}
[..]
Thank you!