updateSplineTexture function

dynamic updateSplineTexture(
  1. dynamic texture,
  2. dynamic splineCurve, {
  3. dynamic offset = 0,
})

Write the curve description to the data texture

@param { DataTexture } texture The DataTexture to write to @param { Curve } splineCurve The curve to describe @param { number } offset Which curve slot to write to

Implementation

updateSplineTexture(texture, splineCurve, {offset = 0}) {
  var numberOfPoints = Math.floor(TEXTURE_WIDTH * (TEXTURE_HEIGHT / 4));
  splineCurve.arcLengthDivisions = numberOfPoints / 2;
  splineCurve.updateArcLengths();
  var points = splineCurve.getSpacedPoints(numberOfPoints);
  var frenetFrames = splineCurve.computeFrenetFrames(numberOfPoints, true);

  for (var i = 0; i < numberOfPoints; i++) {
    var rowOffset = Math.floor(i / TEXTURE_WIDTH);
    var rowIndex = i % TEXTURE_WIDTH;

    var pt = points[i];
    setTextureValue(texture, rowIndex, pt.x, pt.y, pt.z,
        0 + rowOffset + (TEXTURE_HEIGHT * offset));
    pt = frenetFrames.tangents[i];
    setTextureValue(texture, rowIndex, pt.x, pt.y, pt.z,
        1 + rowOffset + (TEXTURE_HEIGHT * offset));
    pt = frenetFrames.normals[i];
    setTextureValue(texture, rowIndex, pt.x, pt.y, pt.z,
        2 + rowOffset + (TEXTURE_HEIGHT * offset));
    pt = frenetFrames.binormals[i];
    setTextureValue(texture, rowIndex, pt.x, pt.y, pt.z,
        3 + rowOffset + (TEXTURE_HEIGHT * offset));
  }

  texture.needsUpdate = true;
}