示例#1
0
 // The custom constructor
 public Foot(IKSolver solver, Transform transform)
 {
     this.solver    = solver;
     this.transform = transform;
     this.leg       = null;
     rotation       = transform.rotation;
 }
示例#2
0
        /*
         * Initiating the chain.
         * */
        public void Initiate(IKSolver solver, FBIKChain[] chain)
        {
            initiated = false;

            foreach (IKSolver.Node node in nodes)
            {
                node.solverPosition = node.transform.position;
            }

            // Calculating bone lengths
            for (int i = 0; i < nodes.Length - 1; i++)
            {
                nodes[i].length = Vector3.Distance(nodes[i].transform.position, nodes[i + 1].transform.position);
                if (nodes[i].length == 0)
                {
                    return;
                }
            }

            for (int i = 0; i < children.Length; i++)
            {
                chain[children[i]].rootLength = (chain[children[i]].nodes[0].transform.position - nodes[nodes.Length - 1].transform.position).magnitude;
                if (chain[children[i]].rootLength == 0f)
                {
                    return;
                }
            }

            // Initiating child constraints
            InitiateConstraints(solver);

            initiated = true;
        }
示例#3
0
        public void Start()
        {
            this.animator             = base.GetComponent <Animator>();
            this.allIKComponents      = base.GetComponentsInChildren <IK>();
            this.disabledIKComponents = new bool[this.allIKComponents.Length];
            this.fixTransforms        = new bool[this.allIKComponents.Length];
            if (this.ik != null)
            {
                IKSolver iksolver = this.ik.GetIKSolver();
                iksolver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(iksolver.OnPostUpdate, new IKSolver.UpdateDelegate(this.AfterLastIK));
            }
            Rigidbody[] componentsInChildren = base.GetComponentsInChildren <Rigidbody>();
            int         num = (componentsInChildren[0].gameObject == base.gameObject) ? 1 : 0;

            this.rigidbones = new RagdollUtility.Rigidbone[(num == 0) ? componentsInChildren.Length : (componentsInChildren.Length - 1)];
            for (int i = 0; i < this.rigidbones.Length; i++)
            {
                this.rigidbones[i] = new RagdollUtility.Rigidbone(componentsInChildren[i + num]);
            }
            Transform[] componentsInChildren2 = base.GetComponentsInChildren <Transform>();
            this.children = new RagdollUtility.Child[componentsInChildren2.Length - 1];
            for (int j = 0; j < this.children.Length; j++)
            {
                this.children[j] = new RagdollUtility.Child(componentsInChildren2[j + 1]);
            }
        }
示例#4
0
 private void Initiate()
 {
     this.feet          = new Transform[this.legs.Length];
     this.footRotations = new Quaternion[this.legs.Length];
     for (int i = 0; i < this.feet.Length; i++)
     {
         this.footRotations[i] = Quaternion.identity;
     }
     for (int j = 0; j < this.legs.Length; j++)
     {
         IKSolver.Point[] points = this.legs[j].GetIKSolver().GetPoints();
         this.feet[j] = points[points.Length - 1].transform;
         IKSolver iksolver = this.legs[j].GetIKSolver();
         iksolver.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(iksolver.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
         IKSolver iksolver2 = this.legs[j].GetIKSolver();
         iksolver2.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(iksolver2.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
     }
     this.animatedPelvisLocalPosition = this.pelvis.localPosition;
     this.solver.Initiate(base.transform, this.feet);
     for (int k = 0; k < this.legs.Length; k++)
     {
         if (this.legs[k] is LegIK)
         {
             this.solver.legs[k].invertFootCenter = true;
         }
     }
     this.initiated = true;
 }
            public Grounding.Leg leg;           // 0x20

            // Constructors
            public Foot(IKSolver solver, Transform transform)
            {
                this.solver    = default;
                this.transform = default;
                rotation       = default;
                leg            = default;
            }             // 0x0000000180044650-0x00000001800446E0
示例#6
0
        /*
         * Initiating the chain.
         * */
        public void Initiate(IKSolver solver, FBIKChain[] chain)
        {
            initiated = false;

            foreach (IKSolver.Node node in nodes)
            {
                node.solverPosition = node.transform.position;
            }

            // Calculating bone lengths
            CalculateBoneLengths(chain);

            // Initiating child constraints
            foreach (ChildConstraint c in childConstraints)
            {
                c.Initiate(solver as IKSolverFullBody);
            }

            // Initiating the bend constraint
            if (nodes.Length == 3)
            {
                bendConstraint.SetBones(nodes[0].transform, nodes[1].transform, nodes[2].transform);
                bendConstraint.Initiate(solver as IKSolverFullBody);
            }

            crossFades = new float[children.Length];

            initiated = true;
        }
示例#7
0
 /*
  * Initiating child constraints
  * */
 public void InitiateConstraints(IKSolver solver)
 {
     foreach (ChildConstraint c in childConstraints)
     {
         c.Initiate(solver as IKSolverFullBody);
     }
 }
		/// <summary>
		/// Determines whether this IKMappingSpine is valid
		/// </summary>
		public override bool IsValid(IKSolver solver, Warning.Logger logger) {
			if (!base.IsValid(solver, logger)) return false;
			
			foreach (Transform spineBone in spineBones) if (spineBone == null) {
				if (logger != null) logger("Spine bones contains a null reference.");
				return false;
			}
			
			int nodes = 0;
			for (int i = 0; i < spineBones.Length; i++) {
				if (solver.GetPoint(spineBones[i]) != null) nodes ++;
			}
			
			if (nodes == 0) {
				if (logger != null) logger("IKMappingSpine does not contain any nodes.");
				return false;
			}
			
			if (leftUpperArmBone == null) {
				if (logger != null) logger("IKMappingSpine is missing the left upper arm bone.");
				return false;
			}
			
			if (rightUpperArmBone == null) {
				if (logger != null) logger("IKMappingSpine is missing the right upper arm bone.");
				return false;
			}
			
			if (leftThighBone == null) {
				if (logger != null) logger("IKMappingSpine is missing the left thigh bone.");
				return false;
			}
			
			if (rightThighBone == null) {
				if (logger != null) logger("IKMappingSpine is missing the right thigh bone.");
				return false;
			}
			
			if (solver.GetPoint(leftUpperArmBone) == null) {
				if (logger != null) logger("Full Body IK is missing the left upper arm node.");
				return false;
			}
			
			if (solver.GetPoint(rightUpperArmBone) == null) {
				if (logger != null) logger("Full Body IK is missing the right upper arm node.");
				return false;
			}
			
			if (solver.GetPoint(leftThighBone) == null) {
				if (logger != null) logger("Full Body IK is missing the left thigh node.");
				return false;
			}
			
			if (solver.GetPoint(rightThighBone) == null) {
				if (logger != null) logger("Full Body IK is missing the right thigh node.");
				return false;
			}
			return true;
		}
示例#9
0
 private void OnDestroy()
 {
     if (this.ik != null)
     {
         IKSolver iksolver = this.ik.GetIKSolver();
         iksolver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(iksolver.OnPostUpdate, new IKSolver.UpdateDelegate(this.AfterLastIK));
     }
 }
示例#10
0
 public void Initiate(Transform transform, IKSolver solver)
 {
     this.transform = transform;
     IKSolver.Point point = solver.GetPoint(transform);
     if (point != null)
     {
         this.node = (point as IKSolver.Node);
     }
 }
示例#11
0
		public float weight = 1f; // Added in 0.2
		
		/// <summary>
		/// Determines whether this IKMappingLimb is valid
		/// </summary>
		public override bool IsValid(IKSolver solver, Warning.Logger logger = null) {
			if (!base.IsValid(solver, logger)) return false;
			
			if (!BoneIsValid(bone1, solver, logger)) return false;
			if (!BoneIsValid(bone2, solver, logger)) return false;
			if (!BoneIsValid(bone3, solver, logger)) return false;
			
			return true;
		}
示例#12
0
		public float weight = 1f; // Added in 0.2
		
		/// <summary>
		/// Determines whether this IKMappingLimb is valid
		/// </summary>
		public override bool IsValid(IKSolver solver, ref string message) {
			if (!base.IsValid(solver, ref message)) return false;
			
			if (!BoneIsValid(bone1, solver, ref message)) return false;
			if (!BoneIsValid(bone2, solver, ref message)) return false;
			if (!BoneIsValid(bone3, solver, ref message)) return false;
			
			return true;
		}
示例#13
0
        public override bool IsValid(bool log)
        {
            if (!this.spineIsValid)
            {
                if (log)
                {
                    base.LogWarning("IKSolverLookAt spine setup is invalid. Can't initiate solver.");
                }
                return(false);
            }
            if (!this.headIsValid)
            {
                if (log)
                {
                    base.LogWarning("IKSolverLookAt head transform is null. Can't initiate solver.");
                }
                return(false);
            }
            if (!this.eyesIsValid)
            {
                if (log)
                {
                    base.LogWarning("IKSolverLookAt eyes setup is invalid. Can't initiate solver.");
                }
                return(false);
            }
            if (this.spineIsEmpty && this.headIsEmpty && this.eyesIsEmpty)
            {
                if (log)
                {
                    base.LogWarning("IKSolverLookAt spine, head and eyes are empty. There is nothing for the solver to solve.");
                }
                return(false);
            }
            Transform transform = IKSolver.ContainsDuplicateBone(this.spine);

            if (transform != null)
            {
                if (log)
                {
                    base.LogWarning(transform.name + " is represented multiple times in a single IK chain. Can't initiate solver.");
                }
                return(false);
            }
            Transform transform2 = IKSolver.ContainsDuplicateBone(this.eyes);

            if (transform2 != null)
            {
                if (log)
                {
                    base.LogWarning(transform2.name + " is represented multiple times in a single IK chain. Can't initiate solver.");
                }
                return(false);
            }
            return(true);
        }
示例#14
0
		/// <summary>
		/// Determines whether this IKMappingBone is valid.
		/// </summary>
		public override bool IsValid(IKSolver solver, Warning.Logger logger) {
			if (!base.IsValid(solver, logger)) return false;
			
			if (bone == null) {
				if (logger != null) logger("IKMappingBone's bone is null.");
				return false;
			}

			return true;
		}
示例#15
0
 /*
  * Make sure the bones are in valid Hierarchy
  * */
 public static bool HierarchyIsValid(IKSolver.Bone[] bones)
 {
     for (int i = 1; i < bones.Length; i++) {
         // If parent bone is not an ancestor of bone, the hierarchy is invalid
         if (!Hierarchy.IsAncestor(bones[i].transform, bones[i - 1].transform)) {
             return false;
         }
     }
     return true;
 }
示例#16
0
		/// <summary>
		/// Determines whether this IKMappingBone is valid.
		/// </summary>
		public override bool IsValid(IKSolver solver, ref string message) {
			if (!base.IsValid(solver, ref message)) return false;
			
			if (bone == null) {
				message = "IKMappingBone's bone is null.";
				return false;
			}

			return true;
		}
示例#17
0
        /*
         * Add points to array
         * */
        public static IKSolver.Point[] AddPoints(ref IKSolver.Point[] array, IKSolver.Point[] addPoints)
        {
            Array.Resize(ref array, array.Length + addPoints.Length);

            int added = 0;
            for (int i = array.Length - addPoints.Length; i < array.Length; i++) {
                array[i] = addPoints[added];
                added ++;
            }

            return array;
        }
示例#18
0
 protected bool BoneIsValid(Transform bone, IKSolver solver, Warning.Logger logger = null)
 {
     if (bone == null) {
         if (logger != null) logger("IKMappingLimb contains a null reference.");
         return false;
     }
     if (solver.GetPoint(bone) == null) {
         if (logger != null) logger("IKMappingLimb is referencing to a bone '" + bone.name + "' that does not excist in the Node Chain.");
         return false;
     }
     return true;
 }
示例#19
0
        /*
         * Determines whether this IKEffector is valid or not.
         * */
        public bool IsValid(IKSolver solver, ref string message)
        {
            if (bone == null)
            {
                message = "IK Effector bone is null.";
                return(false);
            }

            if (solver.GetPoint(bone) == null)
            {
                message = "IK Effector is referencing to a bone '" + bone.name + "' that does not excist in the Node Chain.";
                return(false);
            }

            foreach (Transform b in childBones)
            {
                if (b == null)
                {
                    message = "IK Effector contains a null reference.";
                    return(false);
                }
            }

            foreach (Transform b in childBones)
            {
                if (solver.GetPoint(b) == null)
                {
                    message = "IK Effector is referencing to a bone '" + b.name + "' that does not excist in the Node Chain.";
                    return(false);
                }
            }

            if (planeBone1 != null && solver.GetPoint(planeBone1) == null)
            {
                message = "IK Effector is referencing to a bone '" + planeBone1.name + "' that does not excist in the Node Chain.";
                return(false);
            }

            if (planeBone2 != null && solver.GetPoint(planeBone2) == null)
            {
                message = "IK Effector is referencing to a bone '" + planeBone2.name + "' that does not excist in the Node Chain.";
                return(false);
            }

            if (planeBone3 != null && solver.GetPoint(planeBone3) == null)
            {
                message = "IK Effector is referencing to a bone '" + planeBone3.name + "' that does not excist in the Node Chain.";
                return(false);
            }

            return(true);
        }
 private void DestroyLegs(IK[] ikComponents)
 {
     foreach (IK ik in ikComponents)
     {
         if (ik != null)
         {
             IKSolver iksolver = ik.GetIKSolver();
             iksolver.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(iksolver.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
             IKSolver iksolver2 = ik.GetIKSolver();
             iksolver2.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(iksolver2.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
         }
     }
 }
示例#21
0
 public override bool IsValid(IKSolver solver, ref string message)
 {
     if (!base.IsValid(solver, ref message))
     {
         return(false);
     }
     if (this.bone == null)
     {
         message = "IKMappingBone's bone is null.";
         return(false);
     }
     return(true);
 }
示例#22
0
        /*
         * Initiate the effector, set default values
         * */
        public void Initiate(IKSolver solver)
        {
            this.solver           = solver;
            position              = bone.position;
            rotation              = bone.rotation;
            animatedPlaneRotation = Quaternion.identity;

            // Getting the node
            node = solver.GetPoint(bone) as IKSolver.Node;

            // Child nodes
            if (childNodes == null || childNodes.Length != childBones.Length)
            {
                childNodes = new IKSolver.Node[childBones.Length];
            }

            for (int i = 0; i < childBones.Length; i++)
            {
                childNodes[i] = solver.GetPoint(childBones[i]) as IKSolver.Node;
            }

            if (localPositions == null || localPositions.Length != childBones.Length)
            {
                localPositions = new Vector3[childBones.Length];
            }

            // Plane nodes
            usePlaneNodes = false;

            if (planeBone1 != null)
            {
                planeNode1 = solver.GetPoint(planeBone1) as IKSolver.Node;

                if (planeBone2 != null)
                {
                    planeNode2 = solver.GetPoint(planeBone2) as IKSolver.Node;

                    if (planeBone3 != null)
                    {
                        planeNode3    = solver.GetPoint(planeBone3) as IKSolver.Node;
                        usePlaneNodes = true;
                    }
                }

                isEndEffector = true;
            }
            else
            {
                isEndEffector = false;
            }
        }
 private void DestroyLegs(IK[] ikComponents)
 {
     for (int i = 0; i < ikComponents.Length; i++)
     {
         IK iK = ikComponents[i];
         if (iK != null)
         {
             IKSolver expr_1F = iK.GetIKSolver();
             expr_1F.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_1F.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
             IKSolver expr_46 = iK.GetIKSolver();
             expr_46.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_46.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
         }
     }
 }
示例#24
0
		protected virtual void AddWarningBox(IKSolver solver) {
			EditorGUILayout.Space();
			EditorGUILayout.BeginHorizontal("Box");
			
			EditorGUILayout.LabelField("Invalid/incomplete setup, can't initiate solver.");
			
			if (GUILayout.Button("What's wrong?")) {
				Warning.logged = false;
				solver.IsValid(true);
			}
			
			EditorGUILayout.EndHorizontal();
			EditorGUILayout.Space();
		}
 private Transform[] InitiateFeet(IK[] ikComponents, ref GrounderQuadruped.Foot[] f, int indexOffset)
 {
     Transform[] array = new Transform[ikComponents.Length];
     for (int i = 0; i < ikComponents.Length; i++)
     {
         IKSolver.Point[] points = ikComponents[i].GetIKSolver().GetPoints();
         f[i + indexOffset] = new GrounderQuadruped.Foot(ikComponents[i].GetIKSolver(), points[points.Length - 1].transform);
         array[i]           = f[i + indexOffset].transform;
         IKSolver solver = f[i + indexOffset].solver;
         solver.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(solver.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
         IKSolver solver2 = f[i + indexOffset].solver;
         solver2.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(solver2.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
     }
     return(array);
 }
示例#26
0
        /*
         * Initiating the chain.
         * */
        public void Initiate(IKSolver solver, FBIKChain[] chain)
        {
            initiated = false;

            foreach (IKSolver.Node node in nodes)
            {
                node.solverPosition = node.transform.position;
            }

            // Calculating bone lengths
            length = 0f;

            for (int i = 0; i < nodes.Length - 1; i++)
            {
                nodes[i].length = Vector3.Distance(nodes[i].transform.position, nodes[i + 1].transform.position);
                length         += nodes[i].length;
                if (nodes[i].length == 0)
                {
                    return;
                }
            }

            for (int i = 0; i < children.Length; i++)
            {
                chain[children[i]].rootLength = (chain[children[i]].nodes[0].transform.position - nodes[nodes.Length - 1].transform.position).magnitude;
                if (chain[children[i]].rootLength == 0f)
                {
                    return;
                }
            }

            // Initiating child constraints
            foreach (ChildConstraint c in childConstraints)
            {
                c.Initiate(solver as IKSolverFullBody);
            }

            // Initiating the bend constraint
            if (nodes.Length == 3)
            {
                bendConstraint.SetBones(nodes[0].transform, nodes[1].transform, nodes[2].transform);
                bendConstraint.Initiate(solver as IKSolverFullBody);
            }

            crossFades = new float[children.Length];

            initiated = true;
        }
示例#27
0
 private void OnDestroy()
 {
     if (this.initiated)
     {
         foreach (IK ik in this.legs)
         {
             if (ik != null)
             {
                 IKSolver iksolver = ik.GetIKSolver();
                 iksolver.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(iksolver.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
                 IKSolver iksolver2 = ik.GetIKSolver();
                 iksolver2.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(iksolver2.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
             }
         }
     }
 }
示例#28
0
 public override bool IsValid(IKSolver solver, Warning.Logger logger = null)
 {
     if (!base.IsValid(solver, logger))
     {
         return(false);
     }
     if (this.bone == null)
     {
         if (logger != null)
         {
             logger("IKMappingBone's bone is null.");
         }
         return(false);
     }
     return(true);
 }
示例#29
0
        // Override the default warning box
        protected override void AddWarningBox(IKSolver solver)
        {
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal("Box");

            EditorGUILayout.LabelField("Invalid/incomplete setup, can't initiate solver.");

            if (GUILayout.Button("What's wrong?"))
            {
                Warning.logged = false;
                IsValidAndInitiated(true);
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }
示例#30
0
 public bool IsValid(IKSolver solver, ref string message)
 {
     if (this.bone == null)
     {
         message = "IK Effector bone is null.";
         return(false);
     }
     if (solver.GetPoint(this.bone) == null)
     {
         message = "IK Effector is referencing to a bone '" + this.bone.name + "' that does not excist in the Node Chain.";
         return(false);
     }
     Transform[] array = this.childBones;
     for (int i = 0; i < array.Length; i++)
     {
         if (array[i] == null)
         {
             message = "IK Effector contains a null reference.";
             return(false);
         }
     }
     foreach (Transform transform in this.childBones)
     {
         if (solver.GetPoint(transform) == null)
         {
             message = "IK Effector is referencing to a bone '" + transform.name + "' that does not excist in the Node Chain.";
             return(false);
         }
     }
     if (this.planeBone1 != null && solver.GetPoint(this.planeBone1) == null)
     {
         message = "IK Effector is referencing to a bone '" + this.planeBone1.name + "' that does not excist in the Node Chain.";
         return(false);
     }
     if (this.planeBone2 != null && solver.GetPoint(this.planeBone2) == null)
     {
         message = "IK Effector is referencing to a bone '" + this.planeBone2.name + "' that does not excist in the Node Chain.";
         return(false);
     }
     if (this.planeBone3 != null && solver.GetPoint(this.planeBone3) == null)
     {
         message = "IK Effector is referencing to a bone '" + this.planeBone3.name + "' that does not excist in the Node Chain.";
         return(false);
     }
     return(true);
 }
        public override bool IsValid(ref string message)
        {
            if (this.bones.Length == 0)
            {
                message = "IK chain has no Bones.";
                return(false);
            }
            if (this.bones.Length < this.minBones)
            {
                message = "IK chain has less than " + this.minBones + " Bones.";
                return(false);
            }
            IKSolver.Bone[] array = this.bones;
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].transform == null)
                {
                    message = "One of the Bones is null.";
                    return(false);
                }
            }
            Transform transform = IKSolver.ContainsDuplicateBone(this.bones);

            if (transform != null)
            {
                message = transform.name + " is represented multiple times in the Bones.";
                return(false);
            }
            if (!this.allowCommonParent && !IKSolver.HierarchyIsValid(this.bones))
            {
                message = "Invalid bone hierarchy detected. IK requires for it's bones to be parented to each other in descending order.";
                return(false);
            }
            if (!this.boneLengthCanBeZero)
            {
                for (int j = 0; j < this.bones.Length - 1; j++)
                {
                    if ((this.bones[j].transform.position - this.bones[j + 1].transform.position).magnitude == 0f)
                    {
                        message = "Bone " + j + " length is zero.";
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#32
0
 private void OnDestroy()
 {
     if (this.initiated)
     {
         IK[] array = this.legs;
         for (int i = 0; i < array.Length; i++)
         {
             IK iK = array[i];
             if (iK != null)
             {
                 IKSolver expr_2F = iK.GetIKSolver();
                 expr_2F.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_2F.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
                 IKSolver expr_56 = iK.GetIKSolver();
                 expr_56.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_56.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
             }
         }
     }
 }
示例#33
0
 protected bool BoneIsValid(Transform bone, IKSolver solver, Warning.Logger logger = null)
 {
     if (bone == null)
     {
         if (logger != null)
         {
             logger("IKMappingLimb contains a null reference.");
         }
         return(false);
     }
     if (solver.GetPoint(bone) == null)
     {
         if (logger != null)
         {
             logger("IKMappingLimb is referencing to a bone '" + bone.name + "' that does not excist in the Node Chain.");
         }
         return(false);
     }
     return(true);
 }
示例#34
0
        public override bool IsValid(ref string message)
        {
            if (!this.spineIsValid)
            {
                message = "IKSolverLookAt spine setup is invalid. Can't initiate solver.";
                return(false);
            }
            if (!this.headIsValid)
            {
                message = "IKSolverLookAt head transform is null. Can't initiate solver.";
                return(false);
            }
            if (!this.eyesIsValid)
            {
                message = "IKSolverLookAt eyes setup is invalid. Can't initiate solver.";
                return(false);
            }
            if (this.spineIsEmpty && this.headIsEmpty && this.eyesIsEmpty)
            {
                message = "IKSolverLookAt eyes setup is invalid. Can't initiate solver.";
                return(false);
            }
            IKSolver.Bone[] bones     = this.spine;
            Transform       transform = IKSolver.ContainsDuplicateBone(bones);

            if (transform != null)
            {
                message = transform.name + " is represented multiple times in a single IK chain. Can't initiate solver.";
                return(false);
            }
            bones = this.eyes;
            Transform transform2 = IKSolver.ContainsDuplicateBone(bones);

            if (transform2 != null)
            {
                message = transform2.name + " is represented multiple times in a single IK chain. Can't initiate solver.";
                return(false);
            }
            return(true);
        }
示例#35
0
        public float weight = 1f;         // Added in 0.2

        /// <summary>
        /// Determines whether this IKMappingLimb is valid
        /// </summary>
        public override bool IsValid(IKSolver solver, Warning.Logger logger = null)
        {
            if (!base.IsValid(solver, logger))
            {
                return(false);
            }

            if (!BoneIsValid(bone1, solver, logger))
            {
                return(false);
            }
            if (!BoneIsValid(bone2, solver, logger))
            {
                return(false);
            }
            if (!BoneIsValid(bone3, solver, logger))
            {
                return(false);
            }

            return(true);
        }
示例#36
0
 public void Initiate(IKSolver solver)
 {
     this.solver   = solver;
     this.position = this.bone.position;
     this.rotation = this.bone.rotation;
     this.animatedPlaneRotation = Quaternion.identity;
     this.node = (solver.GetPoint(this.bone) as IKSolver.Node);
     if (this.childNodes == null || this.childNodes.Length != this.childBones.Length)
     {
         this.childNodes = new IKSolver.Node[this.childBones.Length];
     }
     for (int i = 0; i < this.childBones.Length; i++)
     {
         this.childNodes[i] = (solver.GetPoint(this.childBones[i]) as IKSolver.Node);
     }
     if (this.localPositions == null || this.localPositions.Length != this.childBones.Length)
     {
         this.localPositions = new Vector3[this.childBones.Length];
     }
     this.usePlaneNodes = false;
     if (this.planeBone1 != null)
     {
         this.planeNode1 = (solver.GetPoint(this.planeBone1) as IKSolver.Node);
         if (this.planeBone2 != null)
         {
             this.planeNode2 = (solver.GetPoint(this.planeBone2) as IKSolver.Node);
             if (this.planeBone3 != null)
             {
                 this.planeNode3    = (solver.GetPoint(this.planeBone3) as IKSolver.Node);
                 this.usePlaneNodes = true;
             }
         }
         this.isEndEffector = true;
     }
     else
     {
         this.isEndEffector = false;
     }
 }
示例#37
0
文件: IKSolverCCD.cs 项目: zrrz/RPGXD
        // Solves a 3D CCD iteration virtually using solverPosition/solverRotation without considering rotation limits.
        public static void SolveVirtual(IKSolver.Bone[] bones, Vector3 targetPosition, float weight)
        {
            for (int i = bones.Length - 2; i > -1; i--)
            {
                float w = bones[i].weight * weight;

                if (w > 0f)
                {
                    Vector3 toLastBone = bones[bones.Length - 1].solverPosition - bones[i].solverPosition;
                    Vector3 toTarget   = targetPosition - bones[i].solverPosition;

                    // Get the rotation to direct the last bone to the target
                    Quaternion r = Quaternion.FromToRotation(toLastBone, toTarget);
                    if (w < 1f)
                    {
                        r = Quaternion.Lerp(Quaternion.identity, r, w);
                    }

                    IKSolver.SolverRotateBonesAroundPoint(bones, i, bones[i].solverPosition, r);
                }
            }
        }
示例#38
0
        public float weight = 1f;         // Added in 0.2

        /// <summary>
        /// Determines whether this IKMappingLimb is valid
        /// </summary>
        public override bool IsValid(IKSolver solver, ref string message)
        {
            if (!base.IsValid(solver, ref message))
            {
                return(false);
            }

            if (!BoneIsValid(bone1, solver, ref message))
            {
                return(false);
            }
            if (!BoneIsValid(bone2, solver, ref message))
            {
                return(false);
            }
            if (!BoneIsValid(bone3, solver, ref message))
            {
                return(false);
            }

            return(true);
        }
示例#39
0
 public void Initiate(IKSolver solver, FBIKChain[] chain)
 {
     this.initiated = false;
     IKSolver.Node[] array = this.nodes;
     for (int i = 0; i < array.Length; i++)
     {
         IKSolver.Node node = array[i];
         node.solverPosition = node.transform.position;
     }
     this.CalculateBoneLengths(chain);
     FBIKChain.ChildConstraint[] array2 = this.childConstraints;
     for (int j = 0; j < array2.Length; j++)
     {
         FBIKChain.ChildConstraint childConstraint = array2[j];
         childConstraint.Initiate(solver as IKSolverFullBody);
     }
     if (this.nodes.Length == 3)
     {
         this.bendConstraint.SetBones(this.nodes[0].transform, this.nodes[1].transform, this.nodes[2].transform);
         this.bendConstraint.Initiate(solver as IKSolverFullBody);
     }
     this.crossFades = new float[this.children.Length];
     this.initiated  = true;
 }
示例#40
0
		/*
		 * Initiate the effector, set default values
		 * */
		public void Initiate(IKSolver solver) {
			this.solver = solver;
			position = bone.position;
			rotation = bone.rotation;
			animatedPlaneRotation = Quaternion.identity;

			// Getting the node
			node = solver.GetPoint(bone) as IKSolver.Node;

			// Child nodes
			if (childNodes == null || childNodes.Length != childBones.Length) childNodes = new IKSolver.Node[childBones.Length];

			for (int i = 0; i < childBones.Length; i++) {
				childNodes[i] = solver.GetPoint(childBones[i]) as IKSolver.Node;
			}

			if (localPositions == null || localPositions.Length != childBones.Length) localPositions = new Vector3[childBones.Length];

			// Plane nodes
			usePlaneNodes = false;

			if (planeBone1 != null) {
				planeNode1 = solver.GetPoint(planeBone1) as IKSolver.Node;

				if (planeBone2 != null) {
					planeNode2 = solver.GetPoint(planeBone2) as IKSolver.Node;

					if (planeBone3 != null) {
						planeNode3 = solver.GetPoint(planeBone3) as IKSolver.Node;
						usePlaneNodes = true;
					}
				}

				isEndEffector = true;
			} else isEndEffector = false;
		}
示例#41
0
		/*
		 * Solve simple linear constraint
		 * */
		private void SolveLinearConstraint(IKSolver.Node node1, IKSolver.Node node2, float crossFade, float distance) {
			Vector3 dir = node2.solverPosition - node1.solverPosition;

			float mag = dir.magnitude;

			if (distance == mag) return;
			if (mag == 0f) return;

			Vector3 offset = dir * (1f - distance / mag);
			
			node1.solverPosition += offset * crossFade;
			node2.solverPosition -= offset * (1f - crossFade);
		}
示例#42
0
			public void Initiate(Transform transform, IKSolver solver) {
				this.transform = transform;

				IKSolver.Point point = solver.GetPoint(transform);
				if (point != null) this.node = point as IKSolver.Node;
			}
示例#43
0
		/*
		 * Determines whether this IKEffector is valid or not.
		 * */
		public bool IsValid(IKSolver solver, Warning.Logger logger) {
			if (bone == null) {
				if (logger != null) logger("IK Effector bone is null.");
				return false;
			}
			
			if (solver.GetPoint(bone) == null) {
				if (logger != null) logger("IK Effector is referencing to a bone '" + bone.name + "' that does not excist in the Node Chain.");
				return false;
			}

			foreach (Transform b in childBones) {
				if (b == null) {
					if (logger != null) logger("IK Effector contains a null reference.");
					return false;
				}
			}
			
			foreach (Transform b in childBones) {
				if (solver.GetPoint(b) == null) {
					if (logger != null) logger("IK Effector is referencing to a bone '" + b.name + "' that does not excist in the Node Chain.");
					return false;
				}
			}

			if (planeBone1 != null && solver.GetPoint(planeBone1) == null) {
				if (logger != null) logger("IK Effector is referencing to a bone '" + planeBone1.name + "' that does not excist in the Node Chain.");
				return false;
			}

			if (planeBone2 != null && solver.GetPoint(planeBone2) == null) {
				if (logger != null) logger("IK Effector is referencing to a bone '" + planeBone2.name + "' that does not excist in the Node Chain.");
				return false;
			}

			if (planeBone3 != null && solver.GetPoint(planeBone3) == null) {
				if (logger != null) logger("IK Effector is referencing to a bone '" + planeBone3.name + "' that does not excist in the Node Chain.");
				return false;
			}

			return true;
		}
示例#44
0
		/// <summary>
		/// Determines whether this IKMapping is valid.
		/// </summary>
		public virtual bool IsValid(IKSolver solver, Warning.Logger logger) {
			return true;
		}
示例#45
0
		public void Initiate(IKSolver solver) {
			this.solver = solver;
			
			OnInitiate();
		}
示例#46
0
			/*
			 * Sets the 3 points defining a plane for this bone
			 * */
			public void SetPlane(IKSolver.Node planeNode1, IKSolver.Node planeNode2, IKSolver.Node planeNode3) {
				this.planeNode1 = planeNode1;
				this.planeNode2 = planeNode2;
				this.planeNode3 = planeNode3;
				
				UpdatePlane(true, true);
			}
示例#47
0
			/*
			 * Moves the bone to the solver position of it's node
			 * */
			public void FixToNode(float weight, IKSolver.Node fixNode) {
				if (fixNode == null) fixNode = node;

				if (weight >= 1f) {
					transform.position = fixNode.solverPosition;
					return;
				}

				transform.position = Vector3.Lerp(transform.position, fixNode.solverPosition, weight);
			}
示例#48
0
        /*
         * Solve simple linear constraint
         * */
        private static void SolveLinearConstraint(IKSolver.Node node1, IKSolver.Node node2, float crossFade, float distance)
        {
            float currentDistance = Vector3.Distance(node1.solverPosition, node2.solverPosition);

            float force = 1f - distance / currentDistance;
            if (force == 0) return;

            Vector3 offset = (node2.solverPosition - node1.solverPosition) * force;

            node1.solverPosition += offset * crossFade;
            node2.solverPosition -= offset * (1f - crossFade);
        }
示例#49
0
        /*
         * Calculates the bend direction based on the law of cosines (from IKSolverTrigonometric).
         * */
        protected Vector3 GetBendDirection(Vector3 direction, float directionMagnitude, IKSolver.Node node1, IKSolver.Node node2)
        {
            float sqrMag1 = node1.length * node1.length;
            float sqrMag2 = node2.length * node2.length;

            float x = ((directionMagnitude * directionMagnitude) + sqrMag1 - sqrMag2) / 2f / directionMagnitude;
            float y = (float)Math.Sqrt(Mathf.Clamp(sqrMag1 - x * x, 0, Mathf.Infinity));

            return Quaternion.LookRotation(direction) * new Vector3(0f, y, x);
        }
示例#50
0
        /*
         * Initiating the chain.
         * */
        public void Initiate(IKSolver solver, FBIKChain[] chain)
        {
            initiated = false;

            foreach (IKSolver.Node node in nodes) {
                node.solverPosition = node.transform.position;
            }

            // Calculating bone lengths
            for (int i = 0; i < nodes.Length - 1; i++) {
                nodes[i].length = Vector3.Distance(nodes[i].transform.position, nodes[i + 1].transform.position);
                if (nodes[i].length == 0) return;
            }

            for (int i = 0; i < children.Length; i++) {
                chain[children[i]].rootLength = (chain[children[i]].nodes[0].transform.position - nodes[nodes.Length - 1].transform.position).magnitude;
                if (chain[children[i]].rootLength == 0f) return;
            }

            // Initiating child constraints
            InitiateConstraints(solver);

            initiated = true;
        }
示例#51
0
        /*
         * Rotating bone to get transform aim closer to target
         * */
        private void RotateToTarget(Vector3 targetPosition, IKSolver.Bone bone, float weight)
        {
            Quaternion rotationOffset = Quaternion.FromToRotation(transformAxis, targetPosition - transform.position);
            bone.transform.rotation = Quaternion.Lerp(Quaternion.identity, rotationOffset, weight) * bone.transform.rotation;

            if (useRotationLimits && bone.rotationLimit != null) bone.rotationLimit.Apply();
        }
示例#52
0
		/*
		 * Rotating bone to get transform aim closer to target
		 * */
		private void RotateToTarget(Vector3 targetPosition, IKSolver.Bone bone, float weight) {
			// Swing
			if (XY) {
				/*
				if (weight >= 0f) {
					Vector3 dir = transformAxis;
					Vector3 targetDir = targetPosition - transform.position;

					float angleDir = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
					float angleTarget = Mathf.Atan2(targetDir.x, targetDir.y) * Mathf.Rad2Deg;

					bone.transform.rotation = Quaternion.AngleAxis((angleTarget - angleDir) * weight, Vector3.back) * bone.transform.rotation;
				}
				*/

				if (weight >= 0f) {
					Vector3 dir = transformAxis;
					Vector3 targetDir = targetPosition - transform.position;
					
					float angleDir = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
					float angleTarget = Mathf.Atan2(targetDir.x, targetDir.y) * Mathf.Rad2Deg;

					bone.transform.rotation = Quaternion.AngleAxis(Mathf.DeltaAngle(angleDir, angleTarget), Vector3.back) * bone.transform.rotation;
				}
			} else {
				if (weight >= 0f) {
					Quaternion rotationOffset = Quaternion.FromToRotation(transformAxis, targetPosition - transform.position);

					if (weight >= 1f) {
						bone.transform.rotation = rotationOffset * bone.transform.rotation;
					} else {
						bone.transform.rotation = Quaternion.Lerp(Quaternion.identity, rotationOffset, weight) * bone.transform.rotation;
					}
				}

				// Pole
				if (poleWeight > 0f) {
					Vector3 poleDirection = polePosition - transform.position;

					// Ortho-normalize to transform axis to make this a twisting only operation
					Vector3 poleDirOrtho = poleDirection;
					Vector3 normal = transformAxis;
					Vector3.OrthoNormalize(ref normal, ref poleDirOrtho);

					Quaternion toPole = Quaternion.FromToRotation(transformPoleAxis, poleDirOrtho);
					bone.transform.rotation = Quaternion.Lerp(Quaternion.identity, toPole, weight * poleWeight) * bone.transform.rotation;
				}
			}

			if (useRotationLimits && bone.rotationLimit != null) bone.rotationLimit.Apply();
		}
示例#53
0
		/*
		 * Initiating the chain.
		 * */
		public void Initiate(IKSolver solver, FBIKChain[] chain) {
			initiated = false;
			
			foreach (IKSolver.Node node in nodes) {
				node.solverPosition = node.transform.position;
			}
			
			// Calculating bone lengths
			CalculateBoneLengths(chain);
			
			// Initiating child constraints
			foreach (ChildConstraint c in childConstraints) c.Initiate(solver as IKSolverFullBody);

			// Initiating the bend constraint
			if (nodes.Length == 3) {
				bendConstraint.SetBones(nodes[0].transform, nodes[1].transform, nodes[2].transform);
				bendConstraint.Initiate(solver as IKSolverFullBody);
			}

			crossFades = new float[children.Length];

			initiated = true;
		}
示例#54
0
		/*
		 * Rotating bone to get transform aim closer to target
		 * */
		private void RotateToTarget(Vector3 targetPosition, IKSolver.Bone bone, float weight) {
			// Swing
			if (weight >= 0f) {
				Quaternion rotationOffset = Quaternion.FromToRotation(transformAxis, targetPosition - transform.position);
				bone.transform.rotation = Quaternion.Lerp(Quaternion.identity, rotationOffset, weight) * bone.transform.rotation;
			}

			// Pole
			if (poleWeight > 0f) {
				Vector3 poleDirection = polePosition - transform.position;

				// Ortho-normalize to transform axis to make this a twisting only operation
				Vector3 poleDirOrtho = poleDirection;
				Vector3 normal = transformAxis;
				Vector3.OrthoNormalize(ref normal, ref poleDirOrtho);

				Quaternion toPole = Quaternion.FromToRotation(transformPoleAxis, poleDirOrtho);
				bone.transform.rotation = Quaternion.Lerp(Quaternion.identity, toPole, weight * poleWeight) * bone.transform.rotation;
			}

			if (useRotationLimits && bone.rotationLimit != null) bone.rotationLimit.Apply();
		}
		private static Vector3 GetNodePosition(IKSolver.Node node) {
			if (Application.isPlaying) return node.solverPosition;
			return node.transform.position;
		}
示例#56
0
 /*
  * Moves the bone to the solver position of it's node
  * */
 public void FixToNode(float weight, IKSolver.Node fixNode = null)
 {
     if (fixNode == null) fixNode = node;
     transform.position = Vector3.Lerp(transform.position, fixNode.solverPosition, weight);
 }
示例#57
0
        private void AddPointsToArray(ref IKSolver.Point[] array, FABRIKChain chain)
        {
            IKSolver.Point[] chainArray = chain.ik.solver.GetPoints();
            Array.Resize(ref array, array.Length + chainArray.Length);

            int a = 0;
            for (int i = array.Length - chainArray.Length; i < array.Length; i++) {
                array[i] = chainArray[a];
                a++;
            }
        }
示例#58
0
 /*
  * Initiating child constraints
  * */
 public void InitiateConstraints(IKSolver solver)
 {
     foreach (ChildConstraint c in childConstraints) c.Initiate(solver as IKSolverFullBody);
 }
示例#59
0
			// The custom constructor
			public Foot (IKSolver solver, Transform transform) {
				this.solver = solver;
				this.transform = transform;
				this.leg = null;
				rotation = transform.rotation;
			}
示例#60
0
		/// <summary>
		/// Determines whether this IKMapping is valid.
		/// </summary>
		public virtual bool IsValid(IKSolver solver, ref string message) {
			return true;
		}