I have made some edits to this post for clarity.
My goal here is to create a tile made up of 8 different triangles, each capable of changing color independently.
https://i.sstatic.net/iFsWz.png
The issue I am facing is that when I change the color of one triangle, it also changes the color of the lines in between, as shown in the second image.
https://i.sstatic.net/eFM4I.png
This is the code used to create a tile:
var tile=[];
var n=0;
for(var i=0; i<4; i++){
for(var j=0; j<2; j++){
var triangle = new THREE.Object3D();
var lineMaterial = new THREE.LineBasicMaterial({color:0xffffff, transparent:true, opacity:0.5});
var triangleMaterial = new THREE.MeshPhongMaterial({color:COLOR_OFF ,emissive:EMISSIVE_OFF ,side:THREE.DoubleSide, shading:THREE.FlatShading});
var geometry = new THREE.Geometry();
geometry.vertices.push( triangleVectors[j][0], triangleVectors[j][1], triangleVectors[j][2] );
var face = new THREE.Face3(0, 1, 2);
geometry.faces.push(face);
triangle.add(new THREE.LineSegments(new THREE.Geometry(), lineMaterial));
triangle.add( new THREE.Mesh( new THREE.Geometry(), triangleMaterial));
triangle.children[ 0 ].geometry = new THREE.WireframeGeometry(geometry);
triangle.children[ 1 ].geometry = geometry;
triangle.rotation.z = Math.PI*i/2;
triangle.position.x = TILE_LENGTH*x;
triangle.position.y = TILE_LENGTH*y;
n++;
tile.push({'triangle':triangle,'number':n,'state':"OFF"});
scene.add(triangle);
}
}
To update the state of a triangle on the tile, I use the following code:
for(var j=0;j<tile.length; j++){
tile[j].triangle.children[0].material.color.set(COLOR_OFF);
tile[j].triangle.children[1].material.color.set(COLOR_OFF);
tile[j].state="OFF";
for(var k=0; k<pathUpdates[step].length; k++){
if(pathUpdates[step][k].number == tile[j].number){
tile[j].triangle.children[0].material.color.set(COLOR_ON);
tile[j].triangle.children[1].material.color.set(COLOR_ON);
floor[i].tile[j].state="ON";
}
}
}
Is this the correct way to modify a material?
I have simplified the code slightly to illustrate my issue better. The full code can be found in this repository https://github.com/tul1/Tile.git. If you'd like to see it in action, I have deployed it at .