Exemple #1
0
        // Initiates the LimbIK solver
        public void Initiate(Transform hand, int index)
        {
            initiated = false;
            if (!IsValid(true, hand))
            {
                return;
            }

            solver = new IKSolverLimb();

            solver.IKPositionWeight   = weight;
            solver.bendModifier       = IKSolverLimb.BendModifier.Target;
            solver.bendModifierWeight = 1f;

            IKPosition = tip.position;
            IKRotation = tip.rotation;

            if (bone3 != null)
            {
                bone3RelativeToTarget     = Quaternion.Inverse(IKRotation) * bone3.rotation;
                bone3DefaultLocalPosition = bone3.localPosition;
                bone3DefaultLocalRotation = bone3.localRotation;
            }

            solver.SetChain(bone1, bone2, tip, hand);
            solver.Initiate(hand);

            initiated = true;
        }
        /*
         * Draws the scene view helpers for IKSolverLimb
         * */
        public static void AddScene(IKSolverLimb solver, Color color, bool modifiable)
        {
            if (!solver.IsValid(false))
            {
                return;
            }
            if (Application.isPlaying && !solver.initiated)
            {
                return;
            }

            if (solver.bendGoal != null && solver.bendModifierWeight > 0f)
            {
                Color c = color;
                c.a           = solver.bendModifierWeight;
                Handles.color = c;

                Handles.DrawLine(solver.bone2.transform.position, solver.bendGoal.position);
                Handles.SphereCap(0, solver.bendGoal.position, Quaternion.identity, GetHandleSize(solver.bendGoal.position) * 0.5f);

                Handles.color = Color.white;
            }

            IKSolverTrigonometricInspector.AddScene(solver as IKSolverTrigonometric, color, modifiable);
        }
Exemple #3
0
        // Set the IK position and weight for a limb
        private void SetLegIK(IKSolverLimb limb, int index)
        {
            footRotations[index] = feet[index].rotation;

            limb.IKPosition       = solver.legs[index].IKPosition;
            limb.IKPositionWeight = weight;
        }
 public override void Execute()
 {
     var bipedIK = EntityView.GetComponent<BipedIK>();
     LeftFoot = bipedIK.solvers.leftFoot;
     RightFoot = bipedIK.solvers.rightFoot;
     LeftArm = bipedIK.solvers.leftHand;
     RightArm = bipedIK.solvers.rightHand;
 }
Exemple #5
0
        /*
         * Draws the scene view helpers for IKSolverLimb
         * */
        public static void AddScene(IKSolverLimb solver, Color color, bool modifiable)
        {
            if (Application.isPlaying && !solver.initiated)
            {
                return;
            }

            IKSolverTrigonometricInspector.AddScene(solver as IKSolverTrigonometric, color, modifiable);
        }
Exemple #6
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));
     }
 }
 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));
     }
 }
Exemple #8
0
            public void Update(IKSolverLimb solver)
            {
                positionWeight.Value = Mathf.Clamp(positionWeight.Value, 0f, 1f);
                rotationWeight.Value = Mathf.Clamp(rotationWeight.Value, 0f, 1f);
                maintainRotationWeight.Value = Mathf.Clamp(maintainRotationWeight.Value, 0f, 1f);
                bendModifierWeight.Value = Mathf.Clamp(bendModifierWeight.Value, 0f, 1f);

                solver.target = target.Value == null? null: target.Value.transform;
                solver.IKPositionWeight = positionWeight.Value;
                solver.IKPosition = position.Value;
                solver.IKRotationWeight = rotationWeight.Value;
                solver.IKRotation = rotation.Value;
                solver.maintainRotationWeight = maintainRotationWeight.Value;
                solver.bendNormal = bendNormal.Value.normalized;
                solver.bendModifierWeight = bendModifierWeight.Value;
            }
Exemple #9
0
        // Initiates the LimbIK solver
        public void Initiate(Transform hand, int index)
        {
            initiated = false;

            string errorMessage = string.Empty;

            if (!IsValid(ref errorMessage))
            {
                Warning.Log(errorMessage, hand, false);
                return;
            }

            solver = new IKSolverLimb();

            solver.IKPositionWeight   = weight;
            solver.bendModifier       = IKSolverLimb.BendModifier.Target;
            solver.bendModifierWeight = 1f;
            defaultBendNormal         = -Vector3.Cross(tip.position - bone1.position, bone2.position - bone1.position).normalized;
            solver.bendNormal         = defaultBendNormal;

            Vector3 axisWorld = Vector3.Cross(bone2.position - bone1.position, tip.position - bone1.position);

            bone1Axis = Quaternion.Inverse(bone1.rotation) * axisWorld;
            tipAxis   = Quaternion.Inverse(tip.rotation) * axisWorld;

            Vector3 normal  = bone2.position - bone1.position;
            Vector3 tangent = -Vector3.Cross(tip.position - bone1.position, bone2.position - bone1.position);

            Vector3.OrthoNormalize(ref normal, ref tangent);
            bone1TwistAxis = Quaternion.Inverse(bone1.rotation) * tangent;

            IKPosition = tip.position;
            IKRotation = tip.rotation;

            if (bone3 != null)
            {
                bone3RelativeToTarget     = Quaternion.Inverse(IKRotation) * bone3.rotation;
                bone3DefaultLocalPosition = bone3.localPosition;
                bone3DefaultLocalRotation = bone3.localRotation;
            }

            solver.SetChain(bone1, bone2, tip, hand);
            solver.Initiate(hand);

            initiated = true;
        }
		/*
		 * Draws the scene view helpers for IKSolverLimb
		 * */
		public static void AddScene(IKSolverLimb solver, Color color, bool modifiable) {
			if (Application.isPlaying && !solver.initiated) return;
			if (!Application.isPlaying && !solver.IsValid()) return;

			if (solver.bendGoal != null && solver.bendModifierWeight > 0f) {
				Color c = color;
				c.a = solver.bendModifierWeight;
				Handles.color = c;

				Handles.DrawLine(solver.bone2.transform.position, solver.bendGoal.position);
				Handles.SphereCap(0, solver.bendGoal.position, Quaternion.identity, GetHandleSize(solver.bendGoal.position) * 0.5f);

				Handles.color = Color.white;
			}

			IKSolverTrigonometricInspector.AddScene(solver as IKSolverTrigonometric, color, modifiable);
		}
        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;
        }
Exemple #12
0
 protected override void InitiateSolver()
 {
     if (!BipedReferences.CheckSetupError(this.references, Application.isPlaying))
     {
         return;
     }
     this.solvers.AssignReferences(this.references);
     if (this.solvers.spine.bones.Length > 1)
     {
         this.solvers.spine.Initiate(base.transform);
     }
     this.solvers.lookAt.Initiate(base.transform);
     this.solvers.aim.Initiate(base.transform);
     IKSolverLimb[] limbs = this.solvers.limbs;
     for (int i = 0; i < limbs.Length; i++)
     {
         IKSolverLimb iKSolverLimb = limbs[i];
         iKSolverLimb.Initiate(base.transform);
     }
     this.solvers.pelvis.Initiate(this.references.pelvis);
 }
Exemple #13
0
 public void SetToDefaults()
 {
     IKSolverLimb[] limbs = this.solvers.limbs;
     for (int i = 0; i < limbs.Length; i++)
     {
         IKSolverLimb iKSolverLimb = limbs[i];
         iKSolverLimb.SetIKPositionWeight(0f);
         iKSolverLimb.SetIKRotationWeight(0f);
         iKSolverLimb.bendModifier       = IKSolverLimb.BendModifier.Animation;
         iKSolverLimb.bendModifierWeight = 1f;
     }
     this.solvers.leftHand.maintainRotationWeight  = 0f;
     this.solvers.rightHand.maintainRotationWeight = 0f;
     this.solvers.spine.SetIKPositionWeight(0f);
     this.solvers.spine.tolerance         = 0f;
     this.solvers.spine.maxIterations     = 2;
     this.solvers.spine.useRotationLimits = false;
     this.solvers.aim.SetIKPositionWeight(0f);
     this.solvers.aim.tolerance     = 0f;
     this.solvers.aim.maxIterations = 2;
     this.SetLookAtWeight(0f, 0.5f, 1f, 1f, 0.5f, 0.7f, 0.5f);
 }
 /*
  * Draws the scene view helpers for IKSolverLimb
  * */
 public static void AddScene(IKSolverLimb solver, Color color, bool modifiable)
 {
     IKSolverTrigonometricInspector.AddScene(solver as IKSolverTrigonometric, color, modifiable);
 }
		// Set the IK position and weight for a limb
		private void SetLegIK(IKSolverLimb limb, int index) {
			footRotations[index] = feet[index].rotation;

			limb.IKPosition = solver.legs[index].IKPosition;
			limb.IKPositionWeight = weight;
		}
Exemple #16
0
		// Initiates the LimbIK solver
		public void Initiate(Transform hand, int index) {
			initiated = false;

			string errorMessage = string.Empty;
			if (!IsValid(ref errorMessage)) {
				Warning.Log(errorMessage, hand, false);
				return;
			}

			solver = new IKSolverLimb();

			solver.IKPositionWeight = weight;
			solver.bendModifier = IKSolverLimb.BendModifier.Target;
			solver.bendModifierWeight = 1f;

			IKPosition = tip.position;
			IKRotation = tip.rotation;

			if (bone3 != null) {
				bone3RelativeToTarget = Quaternion.Inverse(IKRotation) * bone3.rotation;
				bone3DefaultLocalPosition = bone3.localPosition;
				bone3DefaultLocalRotation = bone3.localRotation;
			}

			solver.SetChain(bone1, bone2, tip, hand);
			solver.Initiate(hand);

			initiated = true;
		}
Exemple #17
0
        }                                        // 0x0000000180532920-0x0000000180533060

        private void SetLegIK(IKSolverLimb limb, int index)
        {
        }                                                              // 0x0000000180533160-0x0000000180533270
Exemple #18
0
 /*
  * Draws the scene view helpers for IKSolverLimb
  * */
 public static void AddScene(IKSolverLimb solver, Color color, bool modifiable)
 {
     IKSolverTrigonometricInspector.AddScene(solver as IKSolverTrigonometric, color, modifiable);
 }
 public override void Execute()
 {
     var ik = EntityView.GetComponent<LimbIK>();
     Solver = ik.solver;
 }