示例#1
0
    private void LateUpdate()
    {
        if (applyTransforms)
        {
            if (target == null)
            {
                return;
            }

            // Get the chain and assert that it is not broken
            Chain c = ChainManager.BuildChain(root);
            Debug.Assert(!c.IsBroken());

            List <Joint> joints = new List <Joint>();
            for (int i = 0; i < c.BoneCount; i++)
            {
                joints.Add(c.GetBone(i).Base);
            }
            joints.Add(c.EndEffector);

            Chain_FABRIK.Solve(c, target);
            ChainManager.ApplyJointTransforms(root, joints);

            visualizer.Show();
            visualizer.SetChain(c);
        }
    }
示例#2
0
    void LateUpdate()
    {
        if (runIK)
        {
            runIK = false;
            if (Target == null)
            {
                return;
            }

            // Get the chain and assert that it is not broken
            Chain chain = ChainManager.BuildChain(ChainRoot);
            Debug.Assert(!chain.IsBroken());

            var chainCopy = chain.Copy();
            chainCopy.Destroy();

            chain.Restore();
            Chain_FABRIK.Solve(chain, Target);
            ChainManager.ApplyJointTransforms(ChainRoot, chain.GetJoints());

            chain = ChainManager.BuildChain(ChainRoot);
            ConstraintsUtil.Constrain(chain, Target);
            ChainManager.ApplyJointTransforms(ChainRoot, chain.GetJoints());
        }

        if (Input.GetKeyDown(KeyCode.I))
        {
            runIK = false;
            Chain chain = ChainManager.BuildChain(ChainRoot);
            chain.Restore();
            Chain_FABRIK.Solve(chain, Target);
            ChainManager.ApplyJointTransforms(ChainRoot, chain.GetJoints());
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            runIK = false;
            Chain chain = ChainManager.BuildChain(ChainRoot);
            chain.Restore();
            ChainManager.ApplyJointTransforms(ChainRoot, chain.GetJoints());
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Chain chain = ChainManager.BuildChain(ChainRoot);
            ConstraintsUtil.Constrain(chain, Target);
            ChainManager.ApplyJointTransforms(ChainRoot, chain.GetJoints());
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            Chain chain = ChainManager.BuildChain(ChainRoot);
            DisplayChainInfo(chain);
        }
    }