public IK() { for (int i = 0; i < _transforms.Length; i++) { _transforms[i] = new IKTransform(); } }
public IKBone(Transform transform, float weight) { Transform = transform; Sibling = null; Weight = weight; Link = null; }
private void findBone(IKTransform transform, ref int last) { for (int i = last - 1; i >= 0; i--) { if (transform.Link == Bones[i].Transform) { Bones[i].Link = transform; last = i; break; } } }
public void Reset(Transform link) { Change = Quaternion.identity; Link = link; SavedPosition = Link.position; SavedRotation = Link.rotation; SavedForward = Link.forward; if (link.parent != null) { SavedLocalPosition = Quaternion.Inverse(link.parent.rotation) * (link.parent.TransformPoint(link.localPosition) - link.parent.position); } Parent = null; Child = null; }
private bool prepareTransforms() { if (Bones.Length == 0 || Target == null) { return(false); } for (int i = 0; i < Bones.Length; i++) { Bones[i].Link = null; } var transformIndex = 0; _target = _transforms[transformIndex++]; _target.Reset(Target); int lastBone = Bones.Length; findBone(_target, ref lastBone); var transform = Target.parent; var current = _target; while (transform != null && lastBone > 0) { var parentNode = _transforms[transformIndex++]; parentNode.Reset(transform); findBone(parentNode, ref lastBone); current.Parent = parentNode; parentNode.Child = current; transform = transform.parent; current = parentNode; } current.Calc(); return(true); }