in packages/common/src/math/curve3.ts [94:136]
public static CreateCatmullRomSpline(points: Vector3[], nbPoints: number, closed?: boolean): Curve3 {
const catmullRom = new Array<Vector3>();
const step = 1.0 / nbPoints;
let amount = 0.0;
if (closed) {
const pointsCount = points.length;
for (var i = 0; i < pointsCount; i++) {
amount = 0;
for (let c = 0; c < nbPoints; c++) {
catmullRom.push(Vector3.CatmullRom(
points[i % pointsCount],
points[(i + 1) % pointsCount],
points[(i + 2) % pointsCount],
points[(i + 3) % pointsCount], amount));
amount += step;
}
}
catmullRom.push(catmullRom[0]);
} else {
const totalPoints = new Array<Vector3>();
totalPoints.push(points[0].clone());
Array.prototype.push.apply(totalPoints, points);
totalPoints.push(points[points.length - 1].clone());
for (i = 0; i < totalPoints.length - 3; i++) {
amount = 0;
for (let c = 0; c < nbPoints; c++) {
catmullRom.push(Vector3.CatmullRom(
totalPoints[i],
totalPoints[i + 1],
totalPoints[i + 2],
totalPoints[i + 3], amount));
amount += step;
}
}
i--;
catmullRom.push(Vector3.CatmullRom(
totalPoints[i],
totalPoints[i + 1],
totalPoints[i + 2],
totalPoints[i + 3], amount));
}
return new Curve3(catmullRom);
}