BABYLON.Curve3.CreateCatmullRomSpline

three.js/src/extras/curves/CatmullRomCurve3.js at master · mrdoob/three.js · GitHub I would like to enable BABYLON.Curve3.CreateCatmullRomSpline to have tension control, similar to how CatmullRomCurve3.js in threejs can be controlled. Is there a plan for integration or a similar extension plugin for BBL

I had been working on a more generic spline generator that would be an example of making Curve3 more generic as well. Mine uses a generator and input/ouput functions that don’t take up the space of an array and can generate number arrays, Vector3 objects or anything else defined by the user.

The core functionality is a basis matrix and a vector of t^n values.

I also created a generic matrix class for general use than the 4x4 Matrix that exists.

None of this is near final form nor fully tested nor well commented.

An example of Callmull-Rom with tension of [0,0.25,.5,0.75,1] is the green to yellow lines here:

In that example, I force the first and last points to be duplicated. Edit: that enables the calculation of the spline between all given points. Without duplication, catmull rom spline only outputs values between the second and third control points.

Edit: the use of a general matrix calculation means that the coded algorithm can apply equally well to 2d points and 3d points. I think the tension parameter is accomodated, but the alpha parameter is not. I can revisit it to clean it up and maybe incorporate alpha if desired. Let me know if this looks promising to you.

Your case seems quite complex. I can’t quite grasp it yet and don’t know how to apply it. Thank you very much for sharing

Agreed. It’s complex because it parameterizes tension, number of points, and the input/output formats. I need to work on making it easier to use.

If you want to try to use it, here’s how to get the output as a Vector3 array:

const splineInput = [
    BABYLON.Vector3.Zero(),
    new BABYLON.Vector3(30, 30, 40),
    new BABYLON.Vector3(-60, 50, -40),
    new BABYLON.Vector3(-30, 60, 30),
];
const nbPoints = 60;
for (var tension of [0,0.25,.5,0.75,1]) {

    // these two lines generate a Vector3 array based on splineInput points and the tension parameter
    const spline = Spline.GetCatmullRomSpline(tension,...Spline.EmitConsumeVector3);
    p = [...genAll(nbPoints,spline,splineInput)];

    // use Vector3 to generate lines mesh
    var splineMesh = BABYLON.Mesh.CreateLines("cr "+tension, p, scene);
    splineMesh.color = new BABYLON.Color3(tension, 0.6, 0);
}

Updated genAll to accept arbitrary number of points, but still uses cubic spline:

1 Like