remotion-spline
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRemotion Spline Skill
Remotion Spline 技能
Use the package's standalone spline functions to create smooth path animations in Remotion compositions.
remotion-spline使用包中的独立样条函数,在Remotion合成内容中创建流畅的路径动画。
remotion-splineAvailable Functions
可用函数
typescript
import {
evaluateLinearSpline,
linearSplineToSVGPath,
evaluateCatmullRom,
catmullRomToSVGPath,
type Point2D,
} from "remotion-spline";typescript
import {
evaluateLinearSpline,
linearSplineToSVGPath,
evaluateCatmullRom,
catmullRomToSVGPath,
type Point2D,
} from "remotion-spline";Point2D
Point2D
typescript
interface Point2D {
readonly x: number;
readonly y: number;
}typescript
interface Point2D {
readonly x: number;
readonly y: number;
}Linear Spline
线性样条
- — Evaluate position at parameter
evaluateLinearSpline(points: Point2D[], t: number): [number, number](clamped to [0,1]) along a piecewise-linear path throught.points - — Convert points to an SVG
linearSplineToSVGPath(points: Point2D[]): stringpath string.M ... L ...
- — 根据参数
evaluateLinearSpline(points: Point2D[], t: number): [number, number](自动限制在[0,1]范围内),计算沿t构成的分段线性路径上的位置。points - — 将点集转换为SVG的
linearSplineToSVGPath(points: Point2D[]): string路径字符串。M ... L ...
Catmull-Rom Spline
Catmull-Rom 样条
- — Evaluate position at parameter
evaluateCatmullRom(points: Point2D[], t: number): [number, number](clamped to [0,1]) along a centripetal Catmull-Rom spline throught. Produces a smooth curve that passes through all control points.points - — Convert points to an SVG cubic Bezier path (
catmullRomToSVGPath(points: Point2D[]): string) that matches the Catmull-Rom curve.M ... C ...
All functions require at least 2 points.
- — 根据参数
evaluateCatmullRom(points: Point2D[], t: number): [number, number](自动限制在[0,1]范围内),计算沿t构成的向心Catmull-Rom样条曲线上的位置。该样条会生成一条穿过所有控制点的平滑曲线。points - — 将点集转换为与Catmull-Rom曲线匹配的SVG三次贝塞尔路径(
catmullRomToSVGPath(points: Point2D[]): string)字符串。M ... C ...
所有函数都要求至少传入2个点。
Pattern: Animated Position Along a Spline
实现模式:沿样条路径的位置动画
tsx
import { useCurrentFrame, useVideoConfig } from "remotion";
import { evaluateCatmullRom, catmullRomToSVGPath, type Point2D } from "remotion-spline";
const points: Point2D[] = [
{ x: 100, y: 500 },
{ x: 300, y: 200 },
{ x: 600, y: 400 },
];
export const MyAnimation: React.FC = () => {
const frame = useCurrentFrame();
const { durationInFrames } = useVideoConfig();
const t = frame / (durationInFrames - 1);
const [x, y] = evaluateCatmullRom(points, t);
const pathD = catmullRomToSVGPath(points);
return (
<svg viewBox="0 0 800 800">
{/* Static path */}
<path d={pathD} stroke="blue" strokeWidth="2" fill="none" />
{/* Animated dot */}
<circle cx={x} cy={y} r="10" fill="red" />
</svg>
);
};tsx
import { useCurrentFrame, useVideoConfig } from "remotion";
import { evaluateCatmullRom, catmullRomToSVGPath, type Point2D } from "remotion-spline";
const points: Point2D[] = [
{ x: 100, y: 500 },
{ x: 300, y: 200 },
{ x: 600, y: 400 },
];
export const MyAnimation: React.FC = () => {
const frame = useCurrentFrame();
const { durationInFrames } = useVideoConfig();
const t = frame / (durationInFrames - 1);
const [x, y] = evaluateCatmullRom(points, t);
const pathD = catmullRomToSVGPath(points);
return (
<svg viewBox="0 0 800 800">
{/* Static path */}
<path d={pathD} stroke="blue" strokeWidth="2" fill="none" />
{/* Animated dot */}
<circle cx={x} cy={y} r="10" fill="red" />
</svg>
);
};Tips
提示
- returns the first point,
t=0returns the last point.t=1 - Values outside [0,1] are clamped automatically.
- Catmull-Rom splines produce smooth curves through all control points — no need to manually compute Bezier handles.
- Use /
linearSplineToSVGPathfor static path rendering (racing lines, trails, guides).catmullRomToSVGPath - Use /
evaluateLinearSplinewith a time-varyingevaluateCatmullRomfor animated position.t
- 当时返回第一个点,
t=0时返回最后一个点。t=1 - [0,1]范围外的参数值会被自动限制在该区间内。
- Catmull-Rom样条可生成穿过所有控制点的平滑曲线——无需手动计算贝塞尔手柄。
- 使用/
linearSplineToSVGPath渲染静态路径(如赛道线、轨迹、参考线)。catmullRomToSVGPath - 结合随时间变化的参数,使用
t/evaluateLinearSpline实现位置动画。evaluateCatmullRom