UNPKG

1.77 kBTypeScriptView Raw
1import { Vector2 } from "../../math/Vector2.js";
2import { Curve } from "../core/Curve.js";
3
4/**
5 * Create a smooth **2D** spline curve from a series of points.
6 * @example
7 * ```typescript
8 * // Create a sine-like wave
9 * const curve = new THREE.SplineCurve([
10 * new THREE.Vector2(-10, 0),
11 * new THREE.Vector2(-5, 5),
12 * new THREE.Vector2(0, 0),
13 * new THREE.Vector2(5, -5),
14 * new THREE.Vector2(10, 0)]);
15 * const points = curve.getPoints(50);
16 * const geometry = new THREE.BufferGeometry().setFromPoints(points);
17 * const material = new THREE.LineBasicMaterial({
18 * color: 0xff0000
19 * });
20 * // Create the final object to add to the scene
21 * const splineObject = new THREE.Line(geometry, material);
22 * ```
23 * @see {@link https://threejs.org/docs/index.html#api/en/extras/curves/SplineCurve | Official Documentation}
24 * @see {@link https://github.com/mrdoob/three.js/blob/master/src/extras/curves/SplineCurve.js | Source}
25 */
26export class SplineCurve extends Curve<Vector2> {
27 /**
28 * This constructor creates a new {@link SplineCurve}.
29 * @param points An array of {@link THREE.Vector2 | Vector2} points that define the curve. Default `[]`
30 */
31 constructor(points?: Vector2[]);
32
33 /**
34 * Read-only flag to check if a given object is of type {@link SplineCurve}.
35 * @remarks This is a _constant_ value
36 * @defaultValue `true`
37 */
38 readonly isSplineCurve = true;
39
40 /**
41 * A Read-only _string_ to check if `this` object type.
42 * @remarks Sub-classes will update this value.
43 * @defaultValue `SplineCurve`
44 */
45 override readonly type: string | "SplineCurve";
46
47 /**
48 * The array of {@link THREE.Vector2 | Vector2} points that define the curve.
49 * @defaultValue `[]`
50 */
51 points: Vector2[];
52}