computeLineDistances method

Line computeLineDistances()

Implementation

Line computeLineDistances() {
  var geometry = this.geometry;

  if (geometry is BufferGeometry) {
    // we assume non-indexed geometry

    if (geometry.index == null) {
      var positionAttribute = geometry.attributes["position"];

      // List<num> lineDistances = [ 0.0 ];
      var lineDistances = Float32Array(positionAttribute.count + 1);

      lineDistances[0] = 0.0;

      for (var i = 1, l = positionAttribute.count; i < l; i++) {
        _start.fromBufferAttribute(positionAttribute, i - 1);
        _end.fromBufferAttribute(positionAttribute, i);

        lineDistances[i] = lineDistances[i - 1];
        lineDistances[i] += _start.distanceTo(_end);
      }

      geometry.setAttribute(
          'lineDistance', Float32BufferAttribute(lineDistances, 1, false));
    }
    // else {
    //   print(
    //       'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
    // }
  }
  // else if (geometry.isGeometry) {
  //   throw ('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  // }

  return this;
}