As WestLangley's answer says, you can't do that. Here is the admittedly hacky workaround I have decided to use:
- Allocate more vertices than I need by filling geometry.vertices with the starting point of my line
- As new points come in that I want to add, shift the contents of the array to the left and write the new point in the last array entry of geometry.vertices
Code:
To create a new line:
function createNewLine(startingPoint){
var geometry = new THREE.Geometry();
for (i=0; i<MAX_LINE_POINTS; i++){
geometry.vertices.push(startingPoint.clone());
}
myLine = new THREE.Line(geometry, lineMaterial);
myLine.geometry.dynamic = true;
scene.add(myLine);
render();
}
To add a point to the line:
function addPoint(myPoint) {
myLine.geometry.vertices.push(myLine.geometry.vertices.shift()); //shift the array
myLine.geometry.vertices[maxLinePoints-1] = myPoint; //add the point to the end of the array
myLine.geometry.verticesNeedUpdate = true;
render();
}
What you end up with then is a Line that has a bunch of points piled up on top of each other followed by the points you actually want to render.
I submitted an issue on the three.js git repository for a simpler solution to this problem.
https://github.com/mrdoob/three.js/issues/4716