Inheritance: RootMotion.FinalIK.IKSolverHeuristic
Example #1
0
        public void Stage1(FBIKChain[] chain)
        {
            for (int i = 0; i < this.children.Length; i++)
            {
                chain[this.children[i]].Stage1(chain);
            }
            if (this.children.Length == 0)
            {
                this.ForwardReach(this.nodes[this.nodes.Length - 1].solverPosition);
                return;
            }
            Vector3 a = this.nodes[this.nodes.Length - 1].solverPosition;

            this.SolveChildConstraints();
            for (int j = 0; j < this.children.Length; j++)
            {
                Vector3 a2 = chain[this.children[j]].nodes[0].solverPosition;
                if (chain[this.children[j]].rootLength > 0f)
                {
                    a2 = IKSolverFABRIK.SolveJoint(this.nodes[this.nodes.Length - 1].solverPosition, chain[this.children[j]].nodes[0].solverPosition, chain[this.children[j]].rootLength);
                }
                if (this.pullParentSum > 0f)
                {
                    a += (a2 - this.nodes[this.nodes.Length - 1].solverPosition) * (chain[this.children[j]].pull / this.pullParentSum);
                }
            }
            this.ForwardReach(Vector3.Lerp(a, this.nodes[this.nodes.Length - 1].solverPosition, this.pin));
        }
Example #2
0
 public void ForwardReach(Vector3 position)
 {
     this.nodes[this.nodes.Length - 1].solverPosition = position;
     for (int i = this.nodes.Length - 2; i > -1; i--)
     {
         this.nodes[i].solverPosition = IKSolverFABRIK.SolveJoint(this.nodes[i].solverPosition, this.nodes[i + 1].solverPosition, this.nodes[i].length);
     }
 }
Example #3
0
 private void BackwardReachUnlimited(Vector3 position)
 {
     this.bones[0].solverPosition = position;
     for (int i = 1; i < this.bones.Length; i++)
     {
         this.bones[i].solverPosition = IKSolverFABRIK.SolveJoint(this.bones[i].solverPosition, this.bones[i - 1].solverPosition, this.bones[i - 1].length);
     }
 }
Example #4
0
 private void BackwardReach(Vector3 position)
 {
     this.spine[0].ikPosition = position;
     for (int i = 1; i < this.spine.Length; i++)
     {
         this.spine[i].ikPosition = IKSolverFABRIK.SolveJoint(this.spine[i].ikPosition, this.spine[i - 1].ikPosition, this.spine[i - 1].length);
     }
 }
Example #5
0
 public void ForwardReach(Vector3 position)
 {
     this.spine[this.spineBones.Length - 1].ikPosition = position;
     for (int i = this.spine.Length - 2; i > -1; i--)
     {
         this.spine[i].ikPosition = IKSolverFABRIK.SolveJoint(this.spine[i].ikPosition, this.spine[i + 1].ikPosition, this.spine[i].length);
     }
 }
Example #6
0
        /*
         * Stage 2 of the FABRIK algorithm
         * */
        private void BackwardReach(Vector3 position)
        {
            spine[0].ikPosition = position;

            // Finding joint positions
            for (int i = 1; i < spine.Length; i++)
            {
                spine[i].ikPosition = IKSolverFABRIK.SolveJoint(spine[i].ikPosition, spine[i - 1].ikPosition, spine[i - 1].length);
            }
        }
 private void OnDestroy()
 {
     if (this.initiated && this.ik != null)
     {
         IKSolverFABRIK spine = this.ik.solvers.spine;
         spine.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(spine.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
         IKSolverLimb rightFoot = this.ik.solvers.rightFoot;
         rightFoot.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(rightFoot.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
     }
 }
Example #8
0
 private void OnDestroy()
 {
     if (this.initiated && this.ik != null)
     {
         IKSolverFABRIK expr_2C = this.ik.solvers.spine;
         expr_2C.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_2C.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
         IKSolverLimb expr_5D = this.ik.solvers.rightFoot;
         expr_5D.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_5D.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
     }
 }
Example #9
0
        /*
         * FABRIK Forward reach
         * */
        public void ForwardReach(Vector3 position)
        {
            // Lerp last node's solverPosition to position
            nodes[nodes.Length - 1].solverPosition = position;

            for (int i = nodes.Length - 2; i > -1; i--)
            {
                // Finding joint positions
                nodes[i].solverPosition = IKSolverFABRIK.SolveJoint(nodes[i].solverPosition, nodes[i + 1].solverPosition, nodes[i].length);
            }
        }
Example #10
0
        /*
         * Stage 1 of the FABRIK algorithm.
         * */
        public void ForwardReach(Vector3 position)
        {
            // Lerp last bone's ikPosition to position
            spine[spineBones.Length - 1].ikPosition = position;

            for (int i = spine.Length - 2; i > -1; i--)
            {
                // Finding joint positions
                spine[i].ikPosition = IKSolverFABRIK.SolveJoint(spine[i].ikPosition, spine[i + 1].ikPosition, spine[i].length);
            }
        }
Example #11
0
 private void BackwardReach(Vector3 position)
 {
     if (this.rootLength > 0f)
     {
         position = IKSolverFABRIK.SolveJoint(this.nodes[0].solverPosition, position, this.rootLength);
     }
     this.nodes[0].solverPosition = position;
     for (int i = 1; i < this.nodes.Length; i++)
     {
         this.nodes[i].solverPosition = IKSolverFABRIK.SolveJoint(this.nodes[i].solverPosition, this.nodes[i - 1].solverPosition, this.nodes[i - 1].length);
     }
 }
Example #12
0
 private void ForwardReach(Vector3 position)
 {
     this.bones[this.bones.Length - 1].solverPosition = Vector3.Lerp(this.bones[this.bones.Length - 1].solverPosition, position, this.IKPositionWeight);
     for (int i = 0; i < this.limitedBones.Length; i++)
     {
         this.limitedBones[i] = false;
     }
     for (int j = this.bones.Length - 2; j > -1; j--)
     {
         this.bones[j].solverPosition = IKSolverFABRIK.SolveJoint(this.bones[j].solverPosition, this.bones[j + 1].solverPosition, this.bones[j].length);
         this.LimitForward(j, j + 1);
     }
     this.LimitForward(0, 0);
 }
Example #13
0
        /*
         * FABRIK Backward reach
         * */
        private void BackwardReach(Vector3 position)
        {
            // Solve forst node only if it already hasn't been solved in SolveConstraintSystems
            if (rootLength > 0)
            {
                position = IKSolverFABRIK.SolveJoint(nodes[0].solverPosition, position, rootLength);
            }
            nodes[0].solverPosition = position;

            // Finding joint positions
            for (int i = 1; i < nodes.Length; i++)
            {
                nodes[i].solverPosition = IKSolverFABRIK.SolveJoint(nodes[i].solverPosition, nodes[i - 1].solverPosition, nodes[i - 1].length);
            }
        }
Example #14
0
        /*
         * Stage 1 of the FABRIK algorithm
         * */
        public void Stage1(FBIKChain[] chain)
        {
            // Stage 1
            for (int i = 0; i < children.Length; i++)
            {
                chain[children[i]].Stage1(chain);
            }

            // If is the last chain in this hierarchy, solve immediatelly and return
            if (children.Length == 0)
            {
                ForwardReach(nodes[nodes.Length - 1].solverPosition);
                return;
            }

            // Finding the total pull force by all child chains
            float pullParentSum = 0f;

            for (int i = 0; i < children.Length; i++)
            {
                pullParentSum += chain[children[i]].pull;
            }
            Vector3 centroid = nodes[nodes.Length - 1].solverPosition;

            // Satisfying child constraints
            SolveChildConstraints();

            // Finding the centroid position of all child chains according to their individual pull weights
            for (int i = 0; i < children.Length; i++)
            {
                Vector3 childPosition = chain[children[i]].nodes[0].solverPosition;

                if (chain[children[i]].rootLength > 0)
                {
                    childPosition = IKSolverFABRIK.SolveJoint(nodes[nodes.Length - 1].solverPosition, chain[children[i]].nodes[0].solverPosition, chain[children[i]].rootLength);
                }

                if (pullParentSum > 0)
                {
                    centroid += (childPosition - nodes[nodes.Length - 1].solverPosition) * (chain[children[i]].pull / Mathf.Clamp(pullParentSum, 1f, Mathf.Infinity));
                }
            }

            // Forward reach to the centroid (unless pinned)
            ForwardReach(Vector3.Lerp(centroid, nodes[nodes.Length - 1].solverPosition, pin));
        }
        private void Initiate()
        {
            this.feet             = new Transform[2];
            this.footRotations    = new Quaternion[2];
            this.feet[0]          = this.ik.references.leftFoot;
            this.feet[1]          = this.ik.references.rightFoot;
            this.footRotations[0] = Quaternion.identity;
            this.footRotations[1] = Quaternion.identity;
            IKSolverFABRIK spine = this.ik.solvers.spine;

            spine.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(spine.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
            IKSolverLimb rightFoot = this.ik.solvers.rightFoot;

            rightFoot.OnPostUpdate           = (IKSolver.UpdateDelegate)Delegate.Combine(rightFoot.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
            this.animatedPelvisLocalPosition = this.ik.references.pelvis.localPosition;
            this.solver.Initiate(this.ik.references.root, this.feet);
            this.initiated = true;
        }
Example #16
0
 private void BackwardReachLimited(Vector3 position)
 {
     this.bones[0].solverPosition = position;
     for (int i = 0; i < this.bones.Length - 1; i++)
     {
         Vector3    a          = IKSolverFABRIK.SolveJoint(this.bones[i + 1].solverPosition, this.bones[i].solverPosition, this.bones[i].length);
         Quaternion lhs        = Quaternion.FromToRotation(this.bones[i].solverRotation * this.bones[i].axis, a - this.bones[i].solverPosition);
         Quaternion quaternion = lhs * this.bones[i].solverRotation;
         if (this.bones[i].rotationLimit != null)
         {
             bool flag = false;
             quaternion = this.GetLimitedRotation(i, quaternion, out flag);
         }
         Quaternion rotation = QuaTools.FromToRotation(this.bones[i].solverRotation, quaternion);
         this.bones[i].solverRotation = quaternion;
         this.SolverRotateChildren(i, rotation);
         this.bones[i + 1].solverPosition = this.bones[i].solverPosition + this.bones[i].solverRotation * this.solverLocalPositions[i + 1];
     }
     for (int j = 0; j < this.bones.Length; j++)
     {
         this.bones[j].solverRotation = Quaternion.LookRotation(this.bones[j].solverRotation * Vector3.forward, this.bones[j].solverRotation * Vector3.up);
     }
 }
 public override void Execute()
 {
     var bipedIK = EntityView.GetComponent<BipedIK>();
     Solvers = bipedIK.solvers.spine;
 }
 public override void Execute()
 {
     var fabrIK = EntityView.GetComponent<FABRIK>();
     Solver = fabrIK.solver;
 }