THREE.IK
Inverse kinematics for three.js.
A work in progress, THREE.IK supports multiple chains with multiple effectors, solved via FABRIK iterative solver, and a ball-joint constraint. Best way to see how this works for now is to check out the demo, examples, and the docs.
⚠️ work in progress/request for feedback ⚠️
There are many open issues regarding axis alignment, new constraints, alternative solvers, and an API overhaul. Discussion and solutions are welcome! There will be breaking changes between versions as an API is settled on.
Installation
$ npm install --save three three-ik
or include the build at build/three-ik.js:
Usage
You can use ES6 importing like so:
;
And here's a full example if included via script tag, with THREE.IK classes
defined on THREE
.
// Set up scene, camera, rendererconst scene = ;const camera = 45 windowinnerWidth / windowinnerHeight 001 100;camerapositionz = 5;const renderer = ;renderer;renderer;documentbody; const ik = ; const chain = ;const constraints = 90;const bones = ; // Create a target that the IK's effector will reach// for.const movingTarget = 01 color: 0xff0000 ;movingTargetpositionz = 2;const pivot = ;pivot;scene; // Create a chain of THREE.Bone's, each wrapped as an IKJoint// and added to the IKChainfor let i = 0; i < 10; i++ const bone = ; bonepositiony = i === 0 ? 0 : 05; if bonesi - 1 bonesi - 1; bones; // The last IKJoint must be added with a `target` as an end effector. const target = i === 9 ? movingTarget : null; chain; // Add the chain to the IK systemik; // Ensure the root bone is added somewhere in the scenescene; // Create a helper and add to the scene so we can visualize// the bonesconst helper = ik;scene; { pivotrotationx += 001; pivotrotationy += 001; pivotrotationz += 001; ik; renderer; ;}
Documentation
Full API documentation can be found at https://jsantell.github.io/THREE.IK/docs.
Build
$ npm run build
Logo
The logo and artwork was created by Caitlyn Crites.
IK Resources
- FABRIK: a fast, iterative solver for the inverse kinematics problem
- Roblox Inverse Kinematics FABRIK
- Create your own IK in Unity - Luis Bermudez
- CCD Algorithm
- Inverse Kinematics with Quaternion Joint Limits - Jonathan Blow
- fullik: JS port of Caliko, Java implementation of FABRIK
- webIK: JS port of VRIK
- fabrik-2d: JS 2D FABRIK
- fabrik: Unity component
License
MIT License, Copyright © 2018 Jordan Santell