After adding texture to my triangle geometry, I noticed that it was all one plain color based on the lightest value. Upon further research, I discovered that assigning UVs might help. However, I encountered the same issue with the darkest color of my texture (refer to the picture).
Below is the code snippet:
var material = new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader().load(texture), overdraw: true } );
var geometry = new THREE.Geometry();
// First step of 3 (30 degrees)
geometry.vertices.push(new THREE.Vector3(0.0, 0.0, 0.0));
geometry.vertices.push(new THREE.Vector3(totalLengthFactor, width, 0.0));
geometry.vertices.push(new THREE.Vector3(0.0, width, 0.0));
geometry.vertices.push(new THREE.Vector3(0.0, 0.0, -thickness));
geometry.vertices.push(new THREE.Vector3(totalLengthFactor, width, -thickness));
geometry.vertices.push(new THREE.Vector3(0.0, width, -thickness));
geometry.faces.push(new THREE.Face3(0, 1, 2)); // Top
geometry.faces.push(new THREE.Face3(5, 4, 3)); // Bottom
geometry.faces.push(new THREE.Face3(3, 1, 0)); // Long side
geometry.faces.push(new THREE.Face3(4, 1, 3)); // Long side
geometry.faces.push(new THREE.Face3(4, 2, 1)); // Short side
geometry.faces.push(new THREE.Face3(5, 2, 4)); // Short side
geometry.faces.push(new THREE.Face3(5, 0, 2)); // Medium side
geometry.faces.push(new THREE.Face3(3, 0, 5)); // Medium side
assignUVs(geometry);
... (snipped)...
function assignUVs(geometry) {
geometry.faceVertexUvs[0] = [];
geometry.faces.forEach(function(face) {
var components = ['x', 'y', 'z'].sort(function(a, b) {
return Math.abs(face.normal[a]) > Math.abs(face.normal[b]);
});
var v1 = geometry.vertices[face.a];
var v2 = geometry.vertices[face.b];
var v3 = geometry.vertices[face.c];
geometry.faceVertexUvs[0].push([
new THREE.Vector2(v1[components[0]], v1[components[1]]),
new THREE.Vector2(v2[components[0]], v2[components[1]]),
new THREE.Vector2(v3[components[0]], v3[components[1]])
]);
});
geometry.uvsNeedUpdate = true;
}
Here is the current outcome: