A solver for IK with CCD Algorithm.
[name] solves Inverse Kinematics Problem with CCD Algorithm.
[name] is designed to work with [page:SkinnedMesh] but also can be used with [page:MMDLoader] or [page:GLTFLoader] skeleton.
let ikSolver;
//
// Bones hierarchy:
//
// root
// ├── bone0
// │ └── bone1
// │ └── bone2
// │ └── bone3
// └── target
//
// Positioned as follow on the cylinder:
//
// o <- target (y = 20)
//
// +----o----+ <- bone3 (y = 12)
// | |
// | o | <- bone2 (y = 4)
// | |
// | o | <- bone1 (y = -4)
// | |
// +----oo---+ <- root, bone0 (y = -12)
//
let bones = []
// "root"
let rootBone = new Bone();
rootBone.position.y = -12;
bones.push( rootBone );
// "bone0"
let prevBone = new Bone();
prevBone.position.y = 0;
rootBone.add( prevBone );
bones.push( prevBone );
// "bone1", "bone2", "bone3"
for ( let i = 1; i <= 3; i ++ ) {
const bone = new Bone();
bone.position.y = 8;
bones.push( bone );
prevBone.add( bone );
prevBone = bone;
}
// "target"
const targetBone = new Bone();
targetBone.position.y = 24 + 8
rootBone.add( targetBone );
bones.push( targetBone );
//
// skinned mesh
//
const mesh = new SkinnedMesh( geometry, material );
const skeleton = new Skeleton( bones );
mesh.add( bones[ 0 ] ); // "root" bone
mesh.bind( skeleton );
//
// ikSolver
//
const iks = [
{
target: 5, // "target"
effector: 4, // "bone3"
links: [ { index: 3 }, { index: 2 }, { index: 1 } ] // "bone2", "bone1", "bone0"
}
];
ikSolver = new CCDIKSolver( mesh, iks );
function render() {
ikSolver?.update();
renderer.render( scene, camera );
}
[example:webgl_loader_mmd]
[example:webgl_loader_mmd_pose]
[example:webgl_loader_mmd_audio]
[page:SkinnedMesh mesh] — [page:SkinnedMesh] for which [name] solves IK problem.
[page:Array iks] — An array of [page:Object] specifying IK parameter. target, effector, and link-index are index integers in .skeleton.bones.
The bones relation should be "links[ n ], links[ n - 1 ], ..., links[ 0 ], effector" in order from parent to child.
Creates a new [name].
An array of IK parameter passed to the constructor.
[page:SkinnedMesh] passed to the constructor.
Return [page:CCDIKHelper]. You can visualize IK bones by adding the helper to scene.
Update IK bones quaternion by solving CCD algorithm.
Update an IK bone quaternion by solving CCD algorithm.
[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/animation/CCDIKSolver.js examples/jsm/animation/CCDIKSolver.js]