I am aiming to create a customizable polygon with modifiable vertices represented by red circles. My goal is to dynamically construct the polygon.
When I initialize the geometry as
var geometry = new THREE.Geometry();
geometry.vertices.push(point);
geometry.vertices.push(point);
var line = new THREE.Line(geometry, new THREE.LineBasicMaterial({}));
It functions properly until the second click, creating a straight line between points 1 and 2 but failing to add a third line when another point is pushed to the array. It appears that buffered points are necessary in WebGL.
If I predefine vertices like this, I can draw two lines (after the third click)
var geometry = new THREE.Geometry();
for (var i = 0; i < 4; i++) {
geometry.vertices.push(point);
}
var line = new THREE.Line(geometry, new THREE.LineBasicMaterial({}));
However, this solution is not optimal since I do not know how many vertices the user intends to add, and it would be inefficient to assign a large number of loops multiple times.
Is there a workaround for this issue?