Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit44fd9e59bd

README.md

ik

The inverse kinematics library behind the IKChain, IKLimb, IKLookAt, IKAim, and IKRig components. Require this module when you are driving a chain from a script, or writing a solver of your own; the components are the normal way in.

Exports

  • chain — resolve a root-to-tip bone run from a rig, run forward kinematics over it, and move it between pose buffers. Everything else operates on a chain.
  • solvers — twoBone, ccd, fabrik, aim, lookAt, plus byName and names for looking one up from a component field. The five are also lifted onto this module directly.
  • limits — cone and hinge rotation limits, measured from a bone's rest pose.
  • grounding — foot probes, slope-clamped surface alignment, pelvis drop, and the framerate-independent smoothing that keeps a foot from popping at a step edge.
  • bind — the component-side plumbing: find a body, get an IK node onto the graph driving it, and convert between world and model space.
  • ikNode, basePose — the animation nodes IK runs through.

Usage

local ik = require("systems.ik.ik")

local rig = ik.bind.rigOf(bodyId)
local c = ik.chain.fromRole(rig.bones, rig.roles, "rightarm")
ik.chain.forward(c)
ik.twoBone.solve(c, { target = modelSpaceTarget, pole = elbowHint, weight = 1 })

A chain solves in the rig's own model space. bind.worldToModel and bind.modelToWorld convert a world-space point into and out of it, scale included — a target handed to a solver in world space will be wrong by whatever the body is scaled by.

Notes

  • chain.forward runs forward kinematics over the chain's own bones; chain.forwardBase runs it over the bones above the chain's root, which is what puts an arm at its shoulder rather than at the character's origin. A solver needs both to have run.
  • Solvers rewrite chain.lRot in place and leave translations alone. Call chain.forward after a solve to see the result in gPos / gRot.
  • weight 0 is an exact pass-through on every solver and short-circuits before any work happens.
  • Every solver tolerates a target it cannot reach: the chain extends toward it rather than producing a degenerate pose or NaN.