@@ -6,34 +6,63 @@ import {
6
6
import * as NURBSUtils from '../curves/NURBSUtils.js' ;
7
7
8
8
/**
9
- * NURBS curve object
9
+ * This class represents a NURBS curve.
10
10
*
11
- * Derives from Curve, overriding getPoint and getTangent .
11
+ * Implementation is based on `(x, y [, z=0 [, w=1]])` control points with `w=weight` .
12
12
*
13
- * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.
14
- *
15
- **/
16
-
13
+ * @augments Curve
14
+ */
17
15
class NURBSCurve extends Curve {
18
16
19
- constructor (
20
- degree ,
21
- knots /* array of reals */ ,
22
- controlPoints /* array of Vector(2|3|4) */ ,
23
- startKnot /* index in knots */ ,
24
- endKnot /* index in knots */
25
- ) {
17
+ /**
18
+ * Constructs a new NURBS curve.
19
+ *
20
+ * @param {number } degree - The NURBS degree.
21
+ * @param {Array<number> } knots - The knots as a flat array of numbers.
22
+ * @param {Array<Vector2|Vector3|Vector4> } controlPoints - An array holding control points.
23
+ * @param {number } [startKnot] - Index of the start knot into the `knots` array.
24
+ * @param {number } [endKnot] - Index of the end knot into the `knots` array.
25
+ */
26
+ constructor ( degree , knots , controlPoints , startKnot , endKnot ) {
26
27
27
28
super ( ) ;
28
29
29
30
const knotsLength = knots ? knots . length - 1 : 0 ;
30
31
const pointsLength = controlPoints ? controlPoints . length : 0 ;
31
32
33
+ /**
34
+ * The NURBS degree.
35
+ *
36
+ * @type {number }
37
+ */
32
38
this . degree = degree ;
39
+
40
+ /**
41
+ * The knots as a flat array of numbers.
42
+ *
43
+ * @type {Array<number> }
44
+ */
33
45
this . knots = knots ;
46
+
47
+ /**
48
+ * An array of control points.
49
+ *
50
+ * @type {Array<Vector4> }
51
+ */
34
52
this . controlPoints = [ ] ;
35
- // Used by periodic NURBS to remove hidden spans
53
+
54
+ /**
55
+ * Index of the start knot into the `knots` array.
56
+ *
57
+ * @type {number }
58
+ */
36
59
this . startKnot = startKnot || 0 ;
60
+
61
+ /**
62
+ * Index of the end knot into the `knots` array.
63
+ *
64
+ * @type {number }
65
+ */
37
66
this . endKnot = endKnot || knotsLength ;
38
67
39
68
for ( let i = 0 ; i < pointsLength ; ++ i ) {
@@ -46,6 +75,13 @@ class NURBSCurve extends Curve {
46
75
47
76
}
48
77
78
+ /**
79
+ * This method returns a vector in 3D space for the given interpolation factor.
80
+ *
81
+ * @param {number } t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
82
+ * @param {Vector3 } [optionalTarget] - The optional target vector the result is written to.
83
+ * @return {Vector3 } The position on the curve.
84
+ */
49
85
getPoint ( t , optionalTarget = new Vector3 ( ) ) {
50
86
51
87
const point = optionalTarget ;
@@ -66,6 +102,13 @@ class NURBSCurve extends Curve {
66
102
67
103
}
68
104
105
+ /**
106
+ * Returns a unit vector tangent for the given interpolation factor.
107
+ *
108
+ * @param {number } t - The interpolation factor.
109
+ * @param {Vector3 } [optionalTarget] - The optional target vector the result is written to.
110
+ * @return {Vector3 } The tangent vector.
111
+ */
69
112
getTangent ( t , optionalTarget = new Vector3 ( ) ) {
70
113
71
114
const tangent = optionalTarget ;
0 commit comments