Skip to content

Commit c19e14f

Browse files
authored
Docs: Add more JSDoc. (#30641)
1 parent 03d90f4 commit c19e14f

14 files changed

+1740
-266
lines changed

examples/jsm/animation/AnimationClipCreator.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,21 @@ import {
77
VectorKeyframeTrack
88
} from 'three';
99

10+
/**
11+
* A utility class with factory methods for creating basic animation clips.
12+
*
13+
* @hideconstructor
14+
*/
1015
class AnimationClipCreator {
1116

17+
/**
18+
* Creates an animation clip that rotates a 3D object 360 degress
19+
* in the given period of time around the given axis.
20+
*
21+
* @param {number} period - The duration of the animation.
22+
* @param {('x'|'y'|'z')} [axis='x'] - The axis of rotation.
23+
* @return {AnimationClip} The created animation clip.
24+
*/
1225
static CreateRotationAnimation( period, axis = 'x' ) {
1326

1427
const times = [ 0, period ], values = [ 0, 360 ];
@@ -21,6 +34,14 @@ class AnimationClipCreator {
2134

2235
}
2336

37+
/**
38+
* Creates an animation clip that scales a 3D object from `0` to `1`
39+
* in the given period of time along the given axis.
40+
*
41+
* @param {number} period - The duration of the animation.
42+
* @param {('x'|'y'|'z')} [axis='x'] - The axis to scale the 3D object along.
43+
* @return {AnimationClip} The created animation clip.
44+
*/
2445
static CreateScaleAxisAnimation( period, axis = 'x' ) {
2546

2647
const times = [ 0, period ], values = [ 0, 1 ];
@@ -33,6 +54,14 @@ class AnimationClipCreator {
3354

3455
}
3556

57+
/**
58+
* Creates an animation clip that translates a 3D object in a shake pattern
59+
* in the given period.
60+
*
61+
* @param {number} duration - The duration of the animation.
62+
* @param {number} shakeScale - The scale of the shake.
63+
* @return {AnimationClip} The created animation clip.
64+
*/
3665
static CreateShakeAnimation( duration, shakeScale ) {
3766

3867
const times = [], values = [], tmp = new Vector3();
@@ -55,6 +84,14 @@ class AnimationClipCreator {
5584

5685
}
5786

87+
/**
88+
* Creates an animation clip that scales a 3D object in a pulse pattern
89+
* in the given period.
90+
*
91+
* @param {number} duration - The duration of the animation.
92+
* @param {number} pulseScale - The scale of the pulse.
93+
* @return {AnimationClip} The created animation clip.
94+
*/
5895
static CreatePulsationAnimation( duration, pulseScale ) {
5996

6097
const times = [], values = [], tmp = new Vector3();
@@ -77,6 +114,12 @@ class AnimationClipCreator {
77114

78115
}
79116

117+
/**
118+
* Creates an animation clip that toggles the visbility of a 3D object.
119+
*
120+
* @param {number} duration - The duration of the animation.
121+
* @return {AnimationClip} The created animation clip.
122+
*/
80123
static CreateVisibilityAnimation( duration ) {
81124

82125
const times = [ 0, duration / 2, duration ], values = [ true, false, true ];
@@ -89,6 +132,14 @@ class AnimationClipCreator {
89132

90133
}
91134

135+
/**
136+
* Creates an animation clip that animates the `color` property of a 3D object's
137+
* material.
138+
*
139+
* @param {number} duration - The duration of the animation.
140+
* @param {Array<Color>} colors - An array of colors that should be sequentially animated.
141+
* @return {AnimationClip} The created animation clip.
142+
*/
92143
static CreateMaterialColorAnimation( duration, colors ) {
93144

94145
const times = [], values = [],

examples/jsm/animation/CCDIKSolver.js

Lines changed: 93 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,31 @@ const _axis = new Vector3();
2525
const _vector = new Vector3();
2626
const _matrix = new Matrix4();
2727

28-
2928
/**
30-
* CCD Algorithm
31-
* - https://web.archive.org/web/20221206080850/https://sites.google.com/site/auraliusproject/ccd-algorithm
29+
* This class solves the Inverse Kinematics Problem with a [CCD Algorithm]{@link https://web.archive.org/web/20221206080850/https://sites.google.com/site/auraliusproject/ccd-algorithm}.
3230
*
33-
* // ik parameter example
34-
* //
35-
* // target, effector, index in links are bone index in skeleton.bones.
36-
* // the bones relation should be
37-
* // <-- parent child -->
38-
* // links[ n ], links[ n - 1 ], ..., links[ 0 ], effector
39-
* iks = [ {
40-
* target: 1,
41-
* effector: 2,
42-
* links: [ { index: 5, limitation: new Vector3( 1, 0, 0 ) }, { index: 4, enabled: false }, { index : 3 } ],
43-
* iteration: 10,
44-
* minAngle: 0.0,
45-
* maxAngle: 1.0,
46-
* } ];
31+
* `CCDIKSolver` is designed to work with instances of {@link SkinnedMesh}.
4732
*/
48-
4933
class CCDIKSolver {
5034

5135
/**
52-
* @param {THREE.SkinnedMesh} mesh
53-
* @param {Array<Object>} iks
36+
* @param {SkinnedMesh} mesh - The skinned mesh.
37+
* @param {Array<CCDIKSolver~IK>} [iks=[]] - The IK objects.
5438
*/
5539
constructor( mesh, iks = [] ) {
5640

41+
/**
42+
* The skinned mesh.
43+
*
44+
* @type {SkinnedMesh}
45+
*/
5746
this.mesh = mesh;
47+
48+
/**
49+
* The IK objects.
50+
*
51+
* @type {SkinnedMesh}
52+
*/
5853
this.iks = iks;
5954

6055
this._initialQuaternions = [];
@@ -78,10 +73,10 @@ class CCDIKSolver {
7873
}
7974

8075
/**
81-
* Update all IK bones.
76+
* Updates all IK bones by solving the CCD algorithm.
8277
*
8378
* @param {number} [globalBlendFactor=1.0] - Blend factor applied if an IK chain doesn't have its own .blendFactor.
84-
* @return {CCDIKSolver}
79+
* @return {CCDIKSolver} A reference to this instance.
8580
*/
8681
update( globalBlendFactor = 1.0 ) {
8782

@@ -98,11 +93,11 @@ class CCDIKSolver {
9893
}
9994

10095
/**
101-
* Update one IK bone
96+
* Updates one IK bone solving the CCD algorithm.
10297
*
103-
* @param {Object} ik parameter
104-
* @param {number} [overrideBlend=1.0] - If the ik object does not define .blendFactor, this value is used.
105-
* @return {CCDIKSolver}
98+
* @param {CCDIKSolver~IK} ik - The IK to update.
99+
* @param {number} [overrideBlend=1.0] - If the IK object does not define `blendFactor`, this value is used.
100+
* @return {CCDIKSolver} A reference to this instance.
106101
*/
107102
updateOne( ik, overrideBlend = 1.0 ) {
108103

@@ -258,10 +253,10 @@ class CCDIKSolver {
258253
}
259254

260255
/**
261-
* Creates Helper
256+
* Creates a helper for visualizing tehh CCDIK.
262257
*
263-
* @param {number} sphereSize
264-
* @return {CCDIKHelper}
258+
* @param {number} sphereSize - The sphere size.
259+
* @return {CCDIKHelper} The created helper.
265260
*/
266261
createHelper( sphereSize ) {
267262

@@ -324,48 +319,86 @@ function setPositionOfBoneToAttributeArray( array, index, bone, matrixWorldInv )
324319
}
325320

326321
/**
327-
* Visualize IK bones
322+
* Helper for visualizing IK bones.
323+
*
324+
* @augments Object3D
328325
*/
329326
class CCDIKHelper extends Object3D {
330327

331328
/**
332-
* @param {SkinnedMesh} mesh
333-
* @param {Array<Object>} [iks=[]]
334-
* @param {number} [sphereSize=0.25]
329+
* @param {SkinnedMesh} mesh - The skinned mesh.
330+
* @param {Array<CCDIKSolver~IK>} [iks=[]] - The IK objects.
331+
* @param {number} [sphereSize=0.25] - The sphere size.
335332
*/
336333
constructor( mesh, iks = [], sphereSize = 0.25 ) {
337334

338335
super();
339336

337+
/**
338+
* The skinned mesh this helper refers to.
339+
*
340+
* @type {SkinnedMesh}
341+
*/
340342
this.root = mesh;
343+
344+
/**
345+
* The IK objects.
346+
*
347+
* @type {Array<CCDIKSolver~IK>}
348+
*/
341349
this.iks = iks;
342350

343351
this.matrix.copy( mesh.matrixWorld );
344352
this.matrixAutoUpdate = false;
345353

354+
/**
355+
* The helpers sphere geometry.
356+
*
357+
* @type {SkinnedMesh}
358+
*/
346359
this.sphereGeometry = new SphereGeometry( sphereSize, 16, 8 );
347360

361+
/**
362+
* The material for the target spheres.
363+
*
364+
* @type {MeshBasicMaterial}
365+
*/
348366
this.targetSphereMaterial = new MeshBasicMaterial( {
349367
color: new Color( 0xff8888 ),
350368
depthTest: false,
351369
depthWrite: false,
352370
transparent: true
353371
} );
354372

373+
/**
374+
* The material for the effector spheres.
375+
*
376+
* @type {MeshBasicMaterial}
377+
*/
355378
this.effectorSphereMaterial = new MeshBasicMaterial( {
356379
color: new Color( 0x88ff88 ),
357380
depthTest: false,
358381
depthWrite: false,
359382
transparent: true
360383
} );
361384

385+
/**
386+
* The material for the link spheres.
387+
*
388+
* @type {MeshBasicMaterial}
389+
*/
362390
this.linkSphereMaterial = new MeshBasicMaterial( {
363391
color: new Color( 0x8888ff ),
364392
depthTest: false,
365393
depthWrite: false,
366394
transparent: true
367395
} );
368396

397+
/**
398+
* A global line matreial.
399+
*
400+
* @type {LineBasicMaterial}
401+
*/
369402
this.lineMaterial = new LineBasicMaterial( {
370403
color: new Color( 0xff0000 ),
371404
depthTest: false,
@@ -377,11 +410,6 @@ class CCDIKHelper extends Object3D {
377410

378411
}
379412

380-
/**
381-
* Updates IK bones visualization.
382-
*
383-
* @param {boolean} force
384-
*/
385413
updateMatrixWorld( force ) {
386414

387415
const mesh = this.root;
@@ -446,7 +474,8 @@ class CCDIKHelper extends Object3D {
446474
}
447475

448476
/**
449-
* Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
477+
* Frees the GPU-related resources allocated by this instance.
478+
* Call this method whenever this instance is no longer used in your app.
450479
*/
451480
dispose() {
452481

@@ -531,4 +560,29 @@ class CCDIKHelper extends Object3D {
531560

532561
}
533562

563+
/**
564+
* This type represents IK configuration objects.
565+
*
566+
* @typedef {Object} CCDIKSolver~IK
567+
* @property {number} target - The target bone index which refers to a bone in the `Skeleton.bones` array.
568+
* @property {number} effector - The effector bone index which refers to a bone in the `Skeleton.bones` array.
569+
* @property {Array<CCDIKSolver~BoneLink>} links - An array of bone links.
570+
* @property {number} [iteration=1] - Iteration number of calculation. Smaller is faster but less precise.
571+
* @property {number} [minAngle] - Minimum rotation angle in a step in radians.
572+
* @property {number} [maxAngle] - Minimum rotation angle in a step in radians.
573+
* @property {number} [blendFactor] - The blend factor.
574+
**/
575+
576+
/**
577+
* This type represents bone links.
578+
*
579+
* @typedef {Object} CCDIKSolver~BoneLink
580+
* @property {number} index - The index of a linked bone which refers to a bone in the `Skeleton.bones` array.
581+
* @property {number} [limitation] - Rotation axis.
582+
* @property {number} [rotationMin] - Rotation minimum limit.
583+
* @property {number} [rotationMax] - Rotation maximum limit.
584+
* @property {boolean} [enabled=true] - Whether the link is enabled or not.
585+
**/
586+
587+
534588
export { CCDIKSolver, CCDIKHelper };

examples/jsm/capabilities/WebGL.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
/**
2+
* A utility module with basic WebGL 2 capability testing.
3+
*
4+
* @hideconstructor
5+
*/
16
class WebGL {
27

8+
/**
9+
* Returns `true` if WebGL 2 is available.
10+
*
11+
* @return {boolean} Whether WebGL 2 is available or not.
12+
*/
313
static isWebGL2Available() {
414

515
try {
@@ -15,6 +25,13 @@ class WebGL {
1525

1626
}
1727

28+
/**
29+
* Returns `true` if the given color space is available. This method can only be used
30+
* if WebGL 2 is supported.
31+
*
32+
* @param {string} colorSpace - The color space to test.
33+
* @return {boolean} Whether the given color space is available or not.
34+
*/
1835
static isColorSpaceAvailable( colorSpace ) {
1936

2037
try {
@@ -32,13 +49,21 @@ class WebGL {
3249

3350
}
3451

52+
/**
53+
* Returns a `div` element representing a formatted error message that can be appended in
54+
* web sites if WebGL 2 isn't supported.
55+
*
56+
* @return {HTMLDivElement} A `div` element representing a formatted error message that WebGL 2 isn't supported.
57+
*/
3558
static getWebGL2ErrorMessage() {
3659

37-
return this.getErrorMessage( 2 );
60+
return this._getErrorMessage( 2 );
3861

3962
}
4063

41-
static getErrorMessage( version ) {
64+
// private
65+
66+
static _getErrorMessage( version ) {
4267

4368
const names = {
4469
1: 'WebGL',
@@ -105,7 +130,7 @@ class WebGL {
105130

106131
console.warn( 'getWebGLErrorMessage() has been deprecated and will be removed in r178. Use getWebGL2ErrorMessage() instead.' );
107132

108-
return this.getErrorMessage( 1 );
133+
return this._getErrorMessage( 1 );
109134

110135
}
111136

0 commit comments

Comments
 (0)