1 | import { Vector3 } from "../../math/Vector3.js";
|
2 | import { Curve } from "../core/Curve.js";
|
3 |
|
4 | export type CurveType = "centripetal" | "chordal" | "catmullrom";
|
5 |
|
6 | /**
|
7 | * Create a smooth **3D** spline curve from a series of points using the {@link https://en.wikipedia.org/wiki/Centripetal_Catmull-Rom_spline | Catmull-Rom} algorithm.
|
8 | * @example
|
9 | * ```typescript
|
10 | * //Create a closed wavey loop
|
11 | * const curve = new THREE.CatmullRomCurve3([
|
12 | * new THREE.Vector3(-10, 0, 10),
|
13 | * new THREE.Vector3(-5, 5, 5),
|
14 | * new THREE.Vector3(0, 0, 0),
|
15 | * new THREE.Vector3(5, -5, 5),
|
16 | * new THREE.Vector3(10, 0, 10)]);
|
17 | * const points = curve.getPoints(50);
|
18 | * const geometry = new THREE.BufferGeometry().setFromPoints(points);
|
19 | * const material = new THREE.LineBasicMaterial({
|
20 | * color: 0xff0000
|
21 | * });
|
22 | * // Create the final object to add to the scene
|
23 | * const curveObject = new THREE.Line(geometry, material);
|
24 | * ```
|
25 | * @see Example: {@link https://threejs.org/examples/#webgl_geometry_extrude_splines | WebGL / geometry / extrude / splines}
|
26 | * @see {@link https://threejs.org/docs/index.html#api/en/extras/curves/CatmullRomCurve3 | Official Documentation}
|
27 | * @see {@link https://github.com/mrdoob/three.js/blob/master/src/extras/curves/CatmullRomCurve3.js | Source}
|
28 | */
|
29 | export class CatmullRomCurve3 extends Curve<Vector3> {
|
30 | /**
|
31 | * This constructor creates a new {@link CatmullRomCurve3}.
|
32 | * @param points An array of {@link THREE.Vector3 | Vector3} points
|
33 | * @param closed Whether the curve is closed. Default `false`
|
34 | * @param curveType Type of the curve. Default `centripetal`
|
35 | * @param tension Tension of the curve. Expects a `Float`. Default `0.5`
|
36 | */
|
37 | constructor(points?: Vector3[], closed?: boolean, curveType?: CurveType, tension?: number);
|
38 |
|
39 | /**
|
40 | * Read-only flag to check if a given object is of type { CatmullRomCurve3}.
|
41 | * This is a _constant_ value
|
42 | * `true`
|
43 | */
|
44 | readonly isCatmullRomCurve3 = true;
|
45 |
|
46 | /**
|
47 | * A Read-only _string_ to check if `this` object type.
|
48 | * @remarks Sub-classes will update this value.
|
49 | * @defaultValue `CatmullRomCurve3`
|
50 | */
|
51 | override readonly type: string | "CatmullRomCurve3";
|
52 |
|
53 | /**
|
54 | * The curve will loop back onto itself when this is true.
|
55 | * @defaultValue `false`
|
56 | */
|
57 | closed: boolean;
|
58 |
|
59 | /**
|
60 | * The array of {@link THREE.Vector3 | Vector3} points that define the curve.
|
61 | * @remarks It needs at least two entries.
|
62 | * @defaultValue `[]`
|
63 | */
|
64 | points: Vector3[];
|
65 |
|
66 | /**
|
67 | * Possible values are `centripetal`, `chordal` and `catmullrom`.
|
68 | * @defaultValue `centripetal`
|
69 | */
|
70 | curveType: CurveType;
|
71 |
|
72 | /**
|
73 | * When {@link .curveType} is `catmullrom`, defines catmullrom's tension.
|
74 | * @remarks Expects a `Float`
|
75 | */
|
76 | tension: number;
|
77 | }
|