computeLineDistances method

dynamic computeLineDistances()

Implementation

computeLineDistances() {
  // for backwards-compatability, but could be a method of LineSegmentsGeometry...

  var start = Vector3.init();
  var end = Vector3.init();

  var geometry = this.geometry!;

  var instanceStart = geometry.attributes["instanceStart"];
  var instanceEnd = geometry.attributes["instanceEnd"];
  var lineDistances = Float32Array((2 * instanceStart.data.count).toInt());

  for (var i = 0, j = 0, l = instanceStart.data.count; i < l; i++, j += 2) {
    start.fromBufferAttribute(instanceStart, i);
    end.fromBufferAttribute(instanceEnd, i);

    lineDistances[j] = (j == 0) ? 0.0 : lineDistances[j - 1];
    lineDistances[j + 1] = lineDistances[j] + start.distanceTo(end);
  }

  var instanceDistanceBuffer = InstancedInterleavedBuffer(lineDistances, 2, 1); // d0, d1

  geometry.setAttribute(
      'instanceDistanceStart', InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0, false)); // d0
  geometry.setAttribute('instanceDistanceEnd', InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1, false)); // d1

  return this;
}