computeLineDistances method

  1. @override
LineSegments computeLineDistances()
override

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

@override
LineSegments computeLineDistances() {
  final geometry = this.geometry;

  if (geometry != null) {
    // we assume non-indexed geometry

    if (geometry.index == null) {
      final positionAttribute = geometry.attributes["position"];
      final lineDistances = Float32List(positionAttribute.count);

      for (int i = 0, l = positionAttribute.count; i < l; i += 2) {
        _lsstart.fromBuffer(positionAttribute, i);
        _lsend.fromBuffer(positionAttribute, i + 1);

        lineDistances[i] = (i == 0) ? 0 : lineDistances[i - 1];
        lineDistances[i + 1] = lineDistances[i] + _lsstart.distanceTo(_lsend);
      }

      geometry.setAttributeFromString('lineDistance', Float32BufferAttribute.fromList(lineDistances, 1, false));
    }
    else {
      console.info('LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
    }
  }
  // else if (geometry.isGeometry) {
  //   throw ('LineSegments.computeLineDistances() no longer supports Geometry. Use BufferGeometry instead.');
  // }

  return this;
}