Ejemplo n.º 1
0
 public IK()
 {
     for (int i = 0; i < _transforms.Length; i++)
     {
         _transforms[i] = new IKTransform();
     }
 }
Ejemplo n.º 2
0
 public IKBone(Transform transform, float weight)
 {
     Transform = transform;
     Sibling   = null;
     Weight    = weight;
     Link      = null;
 }
Ejemplo n.º 3
0
 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;
         }
     }
 }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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);
        }