@@ -25,36 +25,31 @@ const _axis = new Vector3();
25
25
const _vector = new Vector3 ( ) ;
26
26
const _matrix = new Matrix4 ( ) ;
27
27
28
-
29
28
/**
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}.
32
30
*
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}.
47
32
*/
48
-
49
33
class CCDIKSolver {
50
34
51
35
/**
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.
54
38
*/
55
39
constructor ( mesh , iks = [ ] ) {
56
40
41
+ /**
42
+ * The skinned mesh.
43
+ *
44
+ * @type {SkinnedMesh }
45
+ */
57
46
this . mesh = mesh ;
47
+
48
+ /**
49
+ * The IK objects.
50
+ *
51
+ * @type {SkinnedMesh }
52
+ */
58
53
this . iks = iks ;
59
54
60
55
this . _initialQuaternions = [ ] ;
@@ -78,10 +73,10 @@ class CCDIKSolver {
78
73
}
79
74
80
75
/**
81
- * Update all IK bones.
76
+ * Updates all IK bones by solving the CCD algorithm .
82
77
*
83
78
* @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.
85
80
*/
86
81
update ( globalBlendFactor = 1.0 ) {
87
82
@@ -98,11 +93,11 @@ class CCDIKSolver {
98
93
}
99
94
100
95
/**
101
- * Update one IK bone
96
+ * Updates one IK bone solving the CCD algorithm.
102
97
*
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.
106
101
*/
107
102
updateOne ( ik , overrideBlend = 1.0 ) {
108
103
@@ -258,10 +253,10 @@ class CCDIKSolver {
258
253
}
259
254
260
255
/**
261
- * Creates Helper
256
+ * Creates a helper for visualizing tehh CCDIK.
262
257
*
263
- * @param {number } sphereSize
264
- * @return {CCDIKHelper }
258
+ * @param {number } sphereSize - The sphere size.
259
+ * @return {CCDIKHelper } The created helper.
265
260
*/
266
261
createHelper ( sphereSize ) {
267
262
@@ -324,48 +319,86 @@ function setPositionOfBoneToAttributeArray( array, index, bone, matrixWorldInv )
324
319
}
325
320
326
321
/**
327
- * Visualize IK bones
322
+ * Helper for visualizing IK bones.
323
+ *
324
+ * @augments Object3D
328
325
*/
329
326
class CCDIKHelper extends Object3D {
330
327
331
328
/**
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.
335
332
*/
336
333
constructor ( mesh , iks = [ ] , sphereSize = 0.25 ) {
337
334
338
335
super ( ) ;
339
336
337
+ /**
338
+ * The skinned mesh this helper refers to.
339
+ *
340
+ * @type {SkinnedMesh }
341
+ */
340
342
this . root = mesh ;
343
+
344
+ /**
345
+ * The IK objects.
346
+ *
347
+ * @type {Array<CCDIKSolver~IK> }
348
+ */
341
349
this . iks = iks ;
342
350
343
351
this . matrix . copy ( mesh . matrixWorld ) ;
344
352
this . matrixAutoUpdate = false ;
345
353
354
+ /**
355
+ * The helpers sphere geometry.
356
+ *
357
+ * @type {SkinnedMesh }
358
+ */
346
359
this . sphereGeometry = new SphereGeometry ( sphereSize , 16 , 8 ) ;
347
360
361
+ /**
362
+ * The material for the target spheres.
363
+ *
364
+ * @type {MeshBasicMaterial }
365
+ */
348
366
this . targetSphereMaterial = new MeshBasicMaterial ( {
349
367
color : new Color ( 0xff8888 ) ,
350
368
depthTest : false ,
351
369
depthWrite : false ,
352
370
transparent : true
353
371
} ) ;
354
372
373
+ /**
374
+ * The material for the effector spheres.
375
+ *
376
+ * @type {MeshBasicMaterial }
377
+ */
355
378
this . effectorSphereMaterial = new MeshBasicMaterial ( {
356
379
color : new Color ( 0x88ff88 ) ,
357
380
depthTest : false ,
358
381
depthWrite : false ,
359
382
transparent : true
360
383
} ) ;
361
384
385
+ /**
386
+ * The material for the link spheres.
387
+ *
388
+ * @type {MeshBasicMaterial }
389
+ */
362
390
this . linkSphereMaterial = new MeshBasicMaterial ( {
363
391
color : new Color ( 0x8888ff ) ,
364
392
depthTest : false ,
365
393
depthWrite : false ,
366
394
transparent : true
367
395
} ) ;
368
396
397
+ /**
398
+ * A global line matreial.
399
+ *
400
+ * @type {LineBasicMaterial }
401
+ */
369
402
this . lineMaterial = new LineBasicMaterial ( {
370
403
color : new Color ( 0xff0000 ) ,
371
404
depthTest : false ,
@@ -377,11 +410,6 @@ class CCDIKHelper extends Object3D {
377
410
378
411
}
379
412
380
- /**
381
- * Updates IK bones visualization.
382
- *
383
- * @param {boolean } force
384
- */
385
413
updateMatrixWorld ( force ) {
386
414
387
415
const mesh = this . root ;
@@ -446,7 +474,8 @@ class CCDIKHelper extends Object3D {
446
474
}
447
475
448
476
/**
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.
450
479
*/
451
480
dispose ( ) {
452
481
@@ -531,4 +560,29 @@ class CCDIKHelper extends Object3D {
531
560
532
561
}
533
562
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
+
534
588
export { CCDIKSolver , CCDIKHelper } ;
0 commit comments