computeLineDistances method
Computes an array of distance values which are necessary for LineDashedMaterial. For each vertex in the geometry, the method calculates the cumulative length from the current point to the very beginning of the line.
Implementation
Line computeLineDistances() {
final geometry = this.geometry;
if (geometry is BufferGeometry) {
// we assume non-indexed geometry
if (geometry.index == null) {
final positionAttribute = geometry.attributes["position"];
// List<num> lineDistances = [ 0.0 ];
final lineDistances = Float32List(positionAttribute.count + 1);
lineDistances[0] = 0.0;
for (int i = 1, l = positionAttribute.count; i < l; i++) {
_start.fromBuffer(positionAttribute, i - 1);
_end.fromBuffer(positionAttribute, i);
lineDistances[i] = lineDistances[i - 1];
lineDistances[i] += _start.distanceTo(_end);
}
geometry.setAttributeFromString('lineDistance', Float32BufferAttribute.fromList(lineDistances, 1, false));
}
}
return this;
}