예제 #1
0
파일: IK.cs 프로젝트: aksharamurda/ZmbV2
 public IK()
 {
     for (int i = 0; i < _transforms.Length; i++)
     {
         _transforms[i] = new IKTransform();
     }
 }
예제 #2
0
 public IKBone(Transform transform, float weight)
 {
     Transform = transform;
     Sibling   = null;
     Weight    = weight;
     Link      = null;
 }
예제 #3
0
파일: IK.cs 프로젝트: aksharamurda/ZmbV2
 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;
         }
     }
 }
예제 #4
0
파일: IK.cs 프로젝트: aksharamurda/ZmbV2
        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;
        }
예제 #5
0
파일: IK.cs 프로젝트: aksharamurda/ZmbV2
        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);
        }