Attempting to construct a polygon in three.js and here is the code used for it.
function DeployZone(coordinatesList) {
// Forming the polygon Shape
{
var material = new THREE.MeshLambertMaterial({ color: 0x00ffcc });
var faces = [0, 1, 2, 3, 4];
var geometry = new THREE.Geometry();
for (var i = 0; i < coordinatesList.length; i++) {
geometry.vertices.push(new THREE.Vector3(
coordinatesList[i].x,
coordinatesList[i].z,
coordinatesList[i].y
));
}
for (var i = 0; i<faces.length; i++) {
for (var j = 1; j < faces.length - 1; j++) {
geometry.faces.push(new THREE.Face3(faces[0], faces[j], faces[j + 1]));
}
}
geometry.computeFaceNormals();
var zone = new THREE.Mesh(geometry, material);
scene.add(zone);
}
}
The following are the coordinates passed:
var coordinatesList = new List<Coordinates>() {
new Coordinates(X:0,Y:0,Z:0),
new Coordinates(X:0,Y:10,Z:0),
new Coordinates(X:5,Y:10,Z:0),
new Coordinates(X:2,Y:8,Z:0),
new Coordinates(X:5,Y:5,Z:0)
};
A polygon is created but it's not exactly as desired. The vertex at (x:2,y:8,z:0) seems to misplaced. The issue lies with defining the triangular faces properly. Seeking assistance to make the faces and vertices dynamic so that the generated geometry is correct.
Appreciate any help provided.
P.S. Attempted working with shape but no success there. Also included this reference in the code.