Skip to content

Commit 4ab13b4

Browse files
authored
Docs: More JSDoc. (#30662)
1 parent c399a18 commit 4ab13b4

11 files changed

+1216
-214
lines changed

examples/jsm/math/Capsule.js

+89-14
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,138 @@ import {
22
Vector3
33
} from 'three';
44

5+
/**
6+
* A capsule is essentially a cylinder with hemispherical caps at both ends.
7+
* It can be thought of as a swept sphere, where a sphere is moved along a line segment.
8+
*
9+
* Capsules are often used as bounding volumes (next to AABBs and bounding spheres).
10+
*/
511
class Capsule {
612

13+
/**
14+
* Constructs a new capsule.
15+
*
16+
* @param {Vector3} [start] - The start vector.
17+
* @param {Vector3} [end] - The end vector.
18+
* @param {number} [radius=1] - The capsule's radius.
19+
*/
720
constructor( start = new Vector3( 0, 0, 0 ), end = new Vector3( 0, 1, 0 ), radius = 1 ) {
821

22+
/**
23+
* The start vector.
24+
*
25+
* @type {Vector3}
26+
*/
927
this.start = start;
28+
29+
/**
30+
* The end vector.
31+
*
32+
* @type {Vector3}
33+
*/
1034
this.end = end;
35+
36+
/**
37+
* The capsule's radius.
38+
*
39+
* @type {number}
40+
* @default 1
41+
*/
1142
this.radius = radius;
1243

1344
}
1445

46+
/**
47+
* Returns a new capsule with copied values from this instance.
48+
*
49+
* @return {Capsule} A clone of this instance.
50+
*/
1551
clone() {
1652

17-
return new Capsule( this.start.clone(), this.end.clone(), this.radius );
53+
return new this.constructor().copy( this );
1854

1955
}
2056

57+
/**
58+
* Sets the capsule components to the given values.
59+
* Please note that this method only copies the values from the given objects.
60+
*
61+
* @param {Vector3} start - The start vector.
62+
* @param {Vector3} end - The end vector
63+
* @param {number} radius - The capsule's radius.
64+
* @return {Box2} A reference to this bounding box.
65+
*/
2166
set( start, end, radius ) {
2267

2368
this.start.copy( start );
2469
this.end.copy( end );
2570
this.radius = radius;
2671

72+
return this;
73+
2774
}
2875

76+
/**
77+
* Copies the values of the given capsule to this instance.
78+
*
79+
* @param {Capsule} capsule - The capsule to copy.
80+
* @return {Capsule} A reference to this capsule.
81+
*/
2982
copy( capsule ) {
3083

3184
this.start.copy( capsule.start );
3285
this.end.copy( capsule.end );
3386
this.radius = capsule.radius;
3487

88+
return this;
89+
3590
}
3691

92+
/**
93+
* Returns the center point of this capsule.
94+
*
95+
* @param {Vector3} target - The target vector that is used to store the method's result.
96+
* @return {Vector3} The center point.
97+
*/
3798
getCenter( target ) {
3899

39100
return target.copy( this.end ).add( this.start ).multiplyScalar( 0.5 );
40101

41102
}
42103

104+
/**
105+
* Adds the given offset to this capsule, effectively moving it in 3D space.
106+
*
107+
* @param {Vector3} v - The offset that should be used to translate the capsule.
108+
* @return {Capsule} A reference to this capsule.
109+
*/
43110
translate( v ) {
44111

45112
this.start.add( v );
46113
this.end.add( v );
47114

48-
}
49-
50-
checkAABBAxis( p1x, p1y, p2x, p2y, minx, maxx, miny, maxy, radius ) {
51-
52-
return (
53-
( minx - p1x < radius || minx - p2x < radius ) &&
54-
( p1x - maxx < radius || p2x - maxx < radius ) &&
55-
( miny - p1y < radius || miny - p2y < radius ) &&
56-
( p1y - maxy < radius || p2y - maxy < radius )
57-
);
115+
return this;
58116

59117
}
60118

119+
/**
120+
* Returns `true` if the given bounding box intersects with this capsule.
121+
*
122+
* @param {Box3} box - The bounding box to test.
123+
* @return {boolean} Whether the given bounding box intersects with this capsule.
124+
*/
61125
intersectsBox( box ) {
62126

63127
return (
64-
this.checkAABBAxis(
128+
checkAABBAxis(
65129
this.start.x, this.start.y, this.end.x, this.end.y,
66130
box.min.x, box.max.x, box.min.y, box.max.y,
67131
this.radius ) &&
68-
this.checkAABBAxis(
132+
checkAABBAxis(
69133
this.start.x, this.start.z, this.end.x, this.end.z,
70134
box.min.x, box.max.x, box.min.z, box.max.z,
71135
this.radius ) &&
72-
this.checkAABBAxis(
136+
checkAABBAxis(
73137
this.start.y, this.start.z, this.end.y, this.end.z,
74138
box.min.y, box.max.y, box.min.z, box.max.z,
75139
this.radius )
@@ -79,4 +143,15 @@ class Capsule {
79143

80144
}
81145

146+
function checkAABBAxis( p1x, p1y, p2x, p2y, minx, maxx, miny, maxy, radius ) {
147+
148+
return (
149+
( minx - p1x < radius || minx - p2x < radius ) &&
150+
( p1x - maxx < radius || p2x - maxx < radius ) &&
151+
( miny - p1y < radius || miny - p2y < radius ) &&
152+
( p1y - maxy < radius || p2y - maxy < radius )
153+
);
154+
155+
}
156+
82157
export { Capsule };

examples/jsm/math/ColorConverter.js

+21
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@ import { MathUtils } from 'three';
22

33
const _hsl = {};
44

5+
/**
6+
* A utility class with helper functions for color conversion.
7+
*
8+
* @hideconstructor
9+
*/
510
class ColorConverter {
611

12+
/**
13+
* Sets the given HSV color definition to the given color object.
14+
*
15+
* @param {Color} color - The color to set.
16+
* @param {number} h - The hue.
17+
* @param {number} s - The saturation.
18+
* @param {number} v - The value.
19+
* @return {Color} The update color.
20+
*/
721
static setHSV( color, h, s, v ) {
822

923
// https://gist.github.com/xpansive/1337890#file-index-js
@@ -16,6 +30,13 @@ class ColorConverter {
1630

1731
}
1832

33+
/**
34+
* Returns a HSV color representation of the given color object.
35+
*
36+
* @param {Color} color - The color to get HSV values from.
37+
* @param {{h:number,s:number,v:number}} target - The target object that is used to store the method's result.
38+
* @return {{h:number,s:number,v:number}} The HSV color.
39+
*/
1940
static getHSV( color, target ) {
2041

2142
color.getHSL( _hsl );

examples/jsm/math/ColorSpaces.js

+53
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { LinearTransfer, Matrix3, SRGBTransfer } from 'three';
22

3+
/** @module ColorSpaces */
4+
35
// Reference: http://www.russellcottrell.com/photo/matrixCalculator.htm
46

57
const P3_PRIMARIES = [ 0.680, 0.320, 0.265, 0.690, 0.150, 0.060 ];
@@ -24,9 +26,28 @@ const XYZ_TO_LINEAR_DISPLAY_P3 = /*@__PURE__*/ new Matrix3().set(
2426
0.0358458, - 0.0761724, 0.9568845
2527
);
2628

29+
/**
30+
* Display-P3 color space.
31+
*
32+
* @type {string}
33+
* @constant
34+
*/
2735
export const DisplayP3ColorSpace = 'display-p3';
36+
37+
/**
38+
* Display-P3-Linear color space.
39+
*
40+
* @type {string}
41+
* @constant
42+
*/
2843
export const LinearDisplayP3ColorSpace = 'display-p3-linear';
2944

45+
/**
46+
* Implementation object for the Display-P3 color space.
47+
*
48+
* @type {module:ColorSpaces~ColorSpaceImpl}
49+
* @constant
50+
*/
3051
export const DisplayP3ColorSpaceImpl = {
3152
primaries: P3_PRIMARIES,
3253
whitePoint: D65,
@@ -37,6 +58,12 @@ export const DisplayP3ColorSpaceImpl = {
3758
outputColorSpaceConfig: { drawingBufferColorSpace: DisplayP3ColorSpace }
3859
};
3960

61+
/**
62+
* Implementation object for the Display-P3-Linear color space.
63+
*
64+
* @type {module:ColorSpaces~ColorSpaceImpl}
65+
* @constant
66+
*/
4067
export const LinearDisplayP3ColorSpaceImpl = {
4168
primaries: P3_PRIMARIES,
4269
whitePoint: D65,
@@ -64,8 +91,20 @@ const XYZ_TO_LINEAR_REC2020 = /*@__PURE__*/ new Matrix3().set(
6491
0.0176399, - 0.0427706, 0.9421031
6592
);
6693

94+
/**
95+
* Rec2020-Linear color space.
96+
*
97+
* @type {string}
98+
* @constant
99+
*/
67100
export const LinearRec2020ColorSpace = 'rec2020-linear';
68101

102+
/**
103+
* Implementation object for the Rec2020-Linear color space.
104+
*
105+
* @type {module:ColorSpaces~ColorSpaceImpl}
106+
* @constant
107+
*/
69108
export const LinearRec2020ColorSpaceImpl = {
70109
primaries: REC2020_PRIMARIES,
71110
whitePoint: D65,
@@ -74,3 +113,17 @@ export const LinearRec2020ColorSpaceImpl = {
74113
fromXYZ: XYZ_TO_LINEAR_REC2020,
75114
luminanceCoefficients: REC2020_LUMINANCE_COEFFICIENTS,
76115
};
116+
117+
118+
/**
119+
* An object holding the color space implementation.
120+
*
121+
* @typedef {Object} module:ColorSpaces~ColorSpaceImpl
122+
* @property {Array<number>} primaries - The primaries.
123+
* @property {Array<number>} whitePoint - The white point.
124+
* @property {Matrix3} toXYZ - A color space conversion matrix, converting to CIE XYZ.
125+
* @property {Matrix3} fromXYZ - A color space conversion matrix, converting from CIE XYZ.
126+
* @property {Array<number>} luminanceCoefficients - The luminance coefficients.
127+
* @property {{unpackColorSpace:string}} [workingColorSpaceConfig] - The working color space config.
128+
* @property {{drawingBufferColorSpace:string}} [outputColorSpaceConfig] - The drawing buffer color space config.
129+
**/

0 commit comments

Comments
 (0)