leochocolat / three-msdf-text-utils

110 stars 6 forks source link

Deforming along a curve #4

Open mokargas opened 5 months ago

mokargas commented 5 months ago

Is it possible to have this deform or follow say a CatmullRom3 curve?

I'm unsure where to look to get this to work.

For instance, I can create a plane that deforms down a curve with something like so:

const newCurve = new CatmullRom3Curve(<points>)
    let spacedPoints = newCurve.getSpacedPoints(resolution);
    const geom = new PlaneGeometry(5, 5, resolution, 1);
    const frenetFrames = newCurve.computeFrenetFrames(resolution, false);

    const dimensions = [-1,1]

    let point = new Vector3()
    let normalShift = new Vector3()
    let finalPoints = []

    dimensions.forEach((dimension) => {
      for (let i = 0; i <= resolution; i++) {
        point = spacedPoints[i];
        normalShift.add(frenetFrames.normals[i]).multiplyScalar(dimension);
        finalPoints.push(new Vector3().copy(point).add(normalShift))
      }
    })

    geom.setFromPoints(finalPoints)

But I'm not sure how to apply this to the TextGeometry