function animateMeshAlongPath({ mesh, path, points }) {
const spline = new THREE.CatmullRomCurve3(points);
const startPoint = points[0];
const endPoint = points[points.length - 1];
const startQuat = calcMeshQuaterionAlongPath({
point: startPoint,
t: 0,
spline
});
const endQuat = calcMeshQuaterionAlongPath({ point: endPoint, t: 1, spline });
const startMatrix = new THREE.Matrix4().compose(
startPoint,
startQuat,
new THREE.Vector3(1, 1, 1)
);
const endMatrix = new THREE.Matrix4().compose(
endPoint,
endQuat,
new THREE.Vector3(1, 1, 1)
);
const interpolateMatrix = createSphereSpaceInterpolator({
startWorldMatrix: startMatrix,
endWorldMatrix: endMatrix
});
const tweenTarget = { t: 0 };
gsap.to(tweenTarget, {
t: 1,
duration: 5,
ease: "power1.inOut",
onUpdate: () => {
const t = tweenTarget.t;
const matrix = interpolateMatrix(t);
mesh.matrix.copy(matrix);
mesh.matrixAutoUpdate = false;
},
repeat: -1,
yoyo: true
});
}