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(textureWidth * (textureHeight / 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 / textureWidth);
    var rowIndex = i % textureWidth;

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

  texture.needsUpdate = true;
}