Ejemplo n.º 1
0
 private static Vector3 GetLookAtDirection(IKSolverAim solver)
 {
     if (solver.transform == null)
     {
         return(Vector3.forward);
     }
     return(solver.IKPosition - solver.transform.position);
 }
		/// <summary>
		/// Draws the scene view helpers for IKSolverAim
		/// </summary>
		public static void AddScene(IKSolverAim solver, Color color, bool modifiable) {
			// Protect from null reference errors
			if (solver.transform == null) return;
			if (Application.isPlaying && !solver.initiated) return;

			if (!Application.isPlaying) {
				string message = string.Empty;
				if (!solver.IsValid(ref message)) return;
			}
			
			Handles.color = color;
			GUI.color = color;
			
			// Display the bones
			for (int i = 0; i < solver.bones.Length; i++) {
				IKSolver.Bone bone = solver.bones[i];

				if (i < solver.bones.Length - 1) Handles.DrawLine(bone.transform.position, solver.bones[i + 1].transform.position);
				Handles.SphereCap(0, solver.bones[i].transform.position, Quaternion.identity, GetHandleSize(solver.bones[i].transform.position));
			}
			
			if (solver.axis != Vector3.zero) Handles.ConeCap(0, solver.transform.position, Quaternion.LookRotation(solver.transform.rotation * solver.axis), GetHandleSize(solver.transform.position) * 2f);
			
			// Selecting joint and manipulating IKPosition
			if (Application.isPlaying && solver.IKPositionWeight > 0) {
				if (modifiable) {
					Handles.SphereCap(0, solver.IKPosition, Quaternion.identity, GetHandleSize(solver.IKPosition));
						
					// Manipulating position
					solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
				}
				
				// Draw a transparent line from transform to IKPosition
				Handles.color = new Color(color.r, color.g, color.b, color.a * solver.IKPositionWeight);
				Handles.DrawLine(solver.bones[solver.bones.Length - 1].transform.position, solver.transform.position);
				Handles.DrawLine(solver.transform.position, solver.IKPosition);
			}

			Handles.color = color;

			// Pole
			if (Application.isPlaying && solver.poleWeight > 0f) {
				if (modifiable) {
					Handles.SphereCap(0, solver.polePosition, Quaternion.identity, GetHandleSize(solver.IKPosition) * 0.5f);
					
					// Manipulating position
					solver.polePosition = Handles.PositionHandle(solver.polePosition, Quaternion.identity);
				}

				// Draw a transparent line from transform to polePosition
				Handles.color = new Color(color.r, color.g, color.b, color.a * solver.poleWeight);
				Handles.DrawLine(solver.transform.position, solver.polePosition);
			}
			
			Handles.color = Color.white;
			GUI.color = Color.white;
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Draws the scene view helpers for IKSolverAim
        /// </summary>
        public static void AddScene(IKSolverAim solver, Color color, bool modifiable)
        {
            // Protect from null reference errors
            if (!solver.IsValid(false))
            {
                return;
            }
            if (solver.transform == null)
            {
                return;
            }
            if (Application.isPlaying && !solver.initiated)
            {
                return;
            }

            Handles.color = color;
            GUI.color     = color;

            // Display the bones
            for (int i = 0; i < solver.bones.Length; i++)
            {
                IKSolver.Bone bone = solver.bones[i];

                if (i < solver.bones.Length - 1)
                {
                    Handles.DrawLine(bone.transform.position, solver.bones[i + 1].transform.position);
                }
                Handles.SphereCap(0, solver.bones[i].transform.position, Quaternion.identity, jointSize);
            }

            if (solver.axis != Vector3.zero)
            {
                Handles.ConeCap(0, solver.transform.position, Quaternion.LookRotation(solver.transform.rotation * solver.axis), jointSize * 2f);
            }

            // Selecting joint and manipulating IKPosition
            if (Application.isPlaying && solver.IKPositionWeight > 0)
            {
                if (modifiable)
                {
                    Handles.SphereCap(0, solver.IKPosition, Quaternion.identity, selectedSize);

                    // Manipulating position
                    solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
                }

                // Draw a transparent line from transform to IKPosition
                Handles.color = new Color(color.r, color.g, color.b, color.a * solver.IKPositionWeight);
                Handles.DrawLine(solver.bones[solver.bones.Length - 1].transform.position, solver.transform.position);
                Handles.DrawLine(solver.transform.position, solver.IKPosition);
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }
Ejemplo n.º 4
0
 protected override void OnDestroy()
 {
     base.OnDestroy();
     if (this.ik != null && this.initiated)
     {
         IKSolverFullBodyBiped solver = this.ik.solver;
         solver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(solver.OnPostUpdate, new IKSolver.UpdateDelegate(this.AfterFBBIK));
         if (this.aimIK != null)
         {
             IKSolverAim solver2 = this.aimIK.solver;
             solver2.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(solver2.OnPostUpdate, new IKSolver.UpdateDelegate(this.AfterAimIK));
         }
     }
 }
Ejemplo n.º 5
0
        protected override void OnModifyOffset()
        {
            if (this.aimIK != null)
            {
                this.aimIKAxis = this.aimIK.solver.axis;
            }
            if (Time.time >= this.endTime)
            {
                this.rotationOffset = Quaternion.identity;
                return;
            }
            if (!this.initiated && this.ik != null)
            {
                this.initiated = true;
                IKSolverFullBodyBiped solver = this.ik.solver;
                solver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(solver.OnPostUpdate, new IKSolver.UpdateDelegate(this.AfterFBBIK));
                if (this.aimIK != null)
                {
                    IKSolverAim solver2 = this.aimIK.solver;
                    solver2.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(solver2.OnPostUpdate, new IKSolver.UpdateDelegate(this.AfterAimIK));
                }
            }
            this.blendTime = Mathf.Max(this.blendTime, 0f);
            if (this.blendTime > 0f)
            {
                this.blendWeight = Mathf.Min(this.blendWeight + Time.deltaTime * (1f / this.blendTime), 1f);
            }
            else
            {
                this.blendWeight = 1f;
            }
            float b = this.recoilWeight.Evaluate(this.length - (this.endTime - Time.time)) * this.magnitudeMlp;

            this.w = Mathf.Lerp(this.w, b, this.blendWeight);
            Quaternion quaternion = (!(this.aimIK != null) || this.aimIKSolvedLast) ? this.ik.references.root.rotation : Quaternion.LookRotation(this.aimIK.solver.IKPosition - this.aimIK.solver.transform.position, this.ik.references.root.up);

            quaternion = this.randomRotation * quaternion;
            foreach (Recoil.RecoilOffset recoilOffset in this.offsets)
            {
                recoilOffset.Apply(this.ik.solver, quaternion, this.w, this.length, this.endTime - Time.time);
            }
            if (!this.handRotationsSet)
            {
                this.primaryHandRotation = this.primaryHand.rotation;
            }
            this.handRotationsSet = false;
            this.rotationOffset   = Quaternion.Lerp(Quaternion.identity, Quaternion.Euler(this.randomRotation * this.primaryHandRotation * this.handRotationOffset), this.w);
            this.handRotation     = this.rotationOffset * this.primaryHandRotation;
            if (this.twoHanded)
            {
                Vector3 point = Quaternion.Inverse(this.primaryHand.rotation) * (this.secondaryHand.position - this.primaryHand.position);
                this.secondaryHandRelativeRotation = Quaternion.Inverse(this.primaryHand.rotation) * this.secondaryHand.rotation;
                Vector3 a  = this.primaryHand.position + this.primaryHandEffector.positionOffset;
                Vector3 a2 = a + this.handRotation * point;
                this.secondaryHandEffector.positionOffset += a2 - (this.secondaryHand.position + this.secondaryHandEffector.positionOffset);
            }
            if (this.aimIK != null && this.aimIKSolvedLast)
            {
                this.aimIK.solver.axis = Quaternion.Inverse(this.ik.references.root.rotation) * Quaternion.Inverse(this.rotationOffset) * this.aimIKAxis;
            }
        }
        public override void Execute()
        {
            var aimIk = EntityView.GetComponent<AimIK>();

            Solver = aimIk.solver;
        }
 public override void Execute()
 {
     var bipedIK = EntityView.GetComponent<BipedIK>();
     Solver = bipedIK.solvers.aim;
 }
Ejemplo n.º 8
0
 private static Vector3 GetLookAtDirection(IKSolverAim solver)
 {
     if (solver.transform == null) return Vector3.forward;
     return solver.IKPosition - solver.transform.position;
 }
Ejemplo n.º 9
0
            public void Update(IKSolverAim solver)
            {
                weight.Value = Mathf.Clamp(weight.Value, 0f, 1f);
                clampWeight.Value = Mathf.Clamp(clampWeight.Value, 0f, 1f);
                poleWeight.Value = Mathf.Clamp(poleWeight.Value, 0f, 1f);

                solver.target = target.Value == null? null: target.Value.transform;
                solver.poleTarget = poleTarget.Value == null? null: poleTarget.Value.transform;
                solver.transform = aimTransform.Value == null? null: aimTransform.Value.transform;
                solver.axis = axis.Value;
                solver.poleAxis = poleAxis.Value;
                solver.IKPositionWeight = weight.Value;
                solver.poleWeight = poleWeight.Value;
                solver.IKPosition = position.Value;
                solver.clampWeight = clampWeight.Value;
            }