Skip to content

Commit 108e792

Browse files
authored
Docs: More JSDoc. (mrdoob#30642)
1 parent c19e14f commit 108e792

File tree

11 files changed

+616
-205
lines changed

11 files changed

+616
-205
lines changed

examples/jsm/curves/CurveExtras.js

+289-31
Large diffs are not rendered by default.

examples/jsm/curves/NURBSCurve.js

+57-14
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,63 @@ import {
66
import * as NURBSUtils from '../curves/NURBSUtils.js';
77

88
/**
9-
* NURBS curve object
9+
* This class represents a NURBS curve.
1010
*
11-
* Derives from Curve, overriding getPoint and getTangent.
11+
* Implementation is based on `(x, y [, z=0 [, w=1]])` control points with `w=weight`.
1212
*
13-
* Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.
14-
*
15-
**/
16-
13+
* @augments Curve
14+
*/
1715
class NURBSCurve extends Curve {
1816

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 ) {
2627

2728
super();
2829

2930
const knotsLength = knots ? knots.length - 1 : 0;
3031
const pointsLength = controlPoints ? controlPoints.length : 0;
3132

33+
/**
34+
* The NURBS degree.
35+
*
36+
* @type {number}
37+
*/
3238
this.degree = degree;
39+
40+
/**
41+
* The knots as a flat array of numbers.
42+
*
43+
* @type {Array<number>}
44+
*/
3345
this.knots = knots;
46+
47+
/**
48+
* An array of control points.
49+
*
50+
* @type {Array<Vector4>}
51+
*/
3452
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+
*/
3659
this.startKnot = startKnot || 0;
60+
61+
/**
62+
* Index of the end knot into the `knots` array.
63+
*
64+
* @type {number}
65+
*/
3766
this.endKnot = endKnot || knotsLength;
3867

3968
for ( let i = 0; i < pointsLength; ++ i ) {
@@ -46,6 +75,13 @@ class NURBSCurve extends Curve {
4675

4776
}
4877

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+
*/
4985
getPoint( t, optionalTarget = new Vector3() ) {
5086

5187
const point = optionalTarget;
@@ -66,6 +102,13 @@ class NURBSCurve extends Curve {
66102

67103
}
68104

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+
*/
69112
getTangent( t, optionalTarget = new Vector3() ) {
70113

71114
const tangent = optionalTarget;

examples/jsm/curves/NURBSSurface.js

+50-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,56 @@ import {
44
import * as NURBSUtils from '../curves/NURBSUtils.js';
55

66
/**
7-
* NURBS surface object
7+
* This class represents a NURBS surface.
88
*
9-
* Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.
10-
**/
11-
9+
* Implementation is based on `(x, y [, z=0 [, w=1]])` control points with `w=weight`.
10+
*/
1211
class NURBSSurface {
1312

14-
constructor( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */ ) {
15-
13+
/**
14+
* Constructs a new NURBS surface.
15+
*
16+
* @param {number} degree1 - The first NURBS degree.
17+
* @param {number} degree2 - The second NURBS degree.
18+
* @param {Array<number>} knots1 - The first knots as a flat array of numbers.
19+
* @param {Array<number>} knots2 - The second knots as a flat array of numbers.
20+
* @param {Array<Array<Vector2|Vector3|Vector4>>} controlPoints - An array^2 holding control points.
21+
*/
22+
constructor( degree1, degree2, knots1, knots2, controlPoints ) {
23+
24+
/**
25+
* The first NURBS degree.
26+
*
27+
* @type {number}
28+
*/
1629
this.degree1 = degree1;
30+
31+
/**
32+
* The second NURBS degree.
33+
*
34+
* @type {number}
35+
*/
1736
this.degree2 = degree2;
37+
38+
/**
39+
* The first knots as a flat array of numbers.
40+
*
41+
* @type {Array<number>}
42+
*/
1843
this.knots1 = knots1;
44+
45+
/**
46+
* The second knots as a flat array of numbers.
47+
*
48+
* @type {Array<number>}
49+
*/
1950
this.knots2 = knots2;
51+
52+
/**
53+
* An array holding arrays of control points.
54+
*
55+
* @type {Array<Array<Vector2|Vector3|Vector4>>}
56+
*/
2057
this.controlPoints = [];
2158

2259
const len1 = knots1.length - degree1 - 1;
@@ -38,6 +75,13 @@ class NURBSSurface {
3875

3976
}
4077

78+
/**
79+
* This method returns a vector in 3D space for the given interpolation factor. This vector lies on the NURBS surface.
80+
*
81+
* @param {number} t1 - The first interpolation factor representing the `u` position on the surface. Must be in the range `[0,1]`.
82+
* @param {number} t2 - The second interpolation factor representing the `v` position on the surface. Must be in the range `[0,1]`.
83+
* @param {Vector3} target - The target vector the result is written to.
84+
*/
4185
getPoint( t1, t2, target ) {
4286

4387
const u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u

0 commit comments

Comments
 (0)