You can automate triangulation
For large polygons, it can be quite difficult to manually add faces. You can automate the process of adding faces to Mesh using the triangulateShape method in THREE.Shape.Utils as follows:
var vertices = [your vertices array] var holes = []; var triangles, mesh; var geometry = new THREE.Geometry(); var material = new THREE.MeshBasicMaterial(); geometry.vertices = vertices; triangles = THREE.Shape.Utils.triangulateShape ( vertices, holes ); for( var i = 0; i < triangles.length; i++ ){ geometry.faces.push( new THREE.Face3( triangles[i][0], triangles[i][1], triangles[i][2] )); } mesh = new THREE.Mesh( geometry, material );
Where vertices is your array of vertices and holes you can define holes in your polygon.
Note. Be careful if your polygon self-intersects, it throws an error. Make sure your vertex array represents a valid (disjoint) polygon.
source share