I was surprised to find I hadn’t posted this project previously but I wanted to share my closed-chain-ik-js project from a couple years ago to implement an Inverse Kinematics solution in Javascript. While it includes built-in support for mapping to three.js the IK solver and system definition itself is defined independently so it can adapted for any engine. Like many of my other projects, this one is inspired by my work on robotics operations at JPL and collaborating with many incredibly knowledgeable people in this space.
The project uses a Damped Least Squares solver based on this paper by Samuel Buss, which works by calculating the impact of reducing error to goals by moving a joint, and then solve a system of equations using matrices to determine a final joint state. The project supports translation and rotation “joints” (called “degrees of freedom”) allowing you to model and solve for any type of joint configuration.
Parallel Kinematics
With a generic system that aims to solve error between an “end effector” and a “goal” you can fairly easily model parallel kinematic systems - systems with linkages that close a loop - by creating “closures” between links. This 6-axis hexapod robot by PI USA is a good example of such a system. All piston states are solved to match the goal transformation of the top platform. The red lines and shapes represent the underlying IK structure used to solve the robotic system.
Full Body Motion
One particularly exciting result of support for arbitrary joint configurations and parallel solves is that the anchor point for the IK system does not need to part of the geometry. Using this six-legged ATHLETE model from JPL, the body of the robot is modeled as a “free” joint with translation and rotation being able to float freely in order to accommodate the rest of the specified goals. In this video you can see that this leads to some fairly complex movement as all the legs adjust so one leg can reach downward.
And of course more simple kinematic arms are also supported:
Demos
The demos above and many others are available at the repository if you’d like to check out it out. While the demos in the project are focused on robotics, specifically integration with URDF files, there is no reason these approaches can’t be used for other types of skeletal animation models (in fact Blender provides a DLS solver for its IK system, too) and perhaps a demo will be added in the future, though the solvers are not quite as fast as some other more simple solutions.
There’s still quite a bit I’d like to add the project - if there were more time! I recently picked it back up after 5 or 6 years and improved performance quite a bit. I’ll have to see if I can keep chipping at it when I get a chance. It’s quite a satisfying problem to work on.
