/*
		 * Draws the scene view helpers for IKSolverLookAt
		 * */
		public static void AddScene(IKSolverLookAt solver, Color color, bool modifiable) {
			// Protect from null reference errors
			if (!solver.IsValid(false)) return;
			if (Application.isPlaying && !solver.initiated) return;
			
			// Display the Spine
			if (solver.spine.Length > 0) {
				Handles.color = color;
				GUI.color = color;
				
				for (int i = 0; i < solver.spine.Length; i++) {
					IKSolverLookAt.LookAtBone bone = solver.spine[i];
					
					if (i < solver.spine.Length - 1) Handles.DrawLine(bone.transform.position, solver.spine[i + 1].transform.position);
					Handles.SphereCap(0, bone.transform.position, Quaternion.identity, GetHandleSize(bone.transform.position));
				}
				
				// Draw a transparent line from last bone to IKPosition
				if (Application.isPlaying) {
					Handles.color = new Color(color.r, color.g, color.b, color.a * solver.IKPositionWeight * solver.bodyWeight);
					Handles.DrawLine(solver.spine[solver.spine.Length - 1].transform.position, solver.IKPosition);
				}
			}
			
			// Display the eyes
			if (solver.eyes.Length > 0) {
				for (int i = 0; i < solver.eyes.Length; i++) {
					DrawLookAtBoneInScene(solver.eyes[i], solver.IKPosition, color, solver.IKPositionWeight * solver.eyesWeight);
				}
			}
			
			// Display the head
			if (solver.head.transform != null) {
				DrawLookAtBoneInScene(solver.head, solver.IKPosition, color, solver.IKPositionWeight * solver.headWeight);
			}
			
			Handles.color = color;
			GUI.color = color;
			
			// 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
					if (solver.target == null) solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
				}
			}
			
			Handles.color = Color.white;
			GUI.color = Color.white;
		}
 private static Vector3 GetLookAtDirection(IKSolverLookAt solver)
 {
     if (solver.head.transform != null)
     {
         return(solver.IKPosition - solver.head.transform.position);
     }
     if (solver.spine.Length > 0)
     {
         for (int i = solver.spine.Length; i > 0; i--)
         {
             if (solver.spine[i].transform != null)
             {
                 return(solver.IKPosition - solver.spine[i].transform.position);
             }
         }
     }
     return(Vector3.forward);
 }
        /*
         * Draws the scene view helpers for IKSolverLookAt
         * */
        public static void AddScene(IKSolverLookAt solver, Color color, bool modifiable)
        {
            // Protect from null reference errors
            if (Application.isPlaying && !solver.initiated)
            {
                return;
            }
            if (!Application.isPlaying && !solver.IsValid())
            {
                return;
            }

            // Display the Spine
            if (solver.spine.Length > 0)
            {
                Handles.color = color;
                GUI.color     = color;

                for (int i = 0; i < solver.spine.Length; i++)
                {
                    IKSolverLookAt.LookAtBone bone = solver.spine[i];

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

                // Draw a transparent line from last bone to IKPosition
                if (Application.isPlaying)
                {
                    Handles.color = new Color(color.r, color.g, color.b, color.a * solver.IKPositionWeight * solver.bodyWeight);
                    Handles.DrawLine(solver.spine[solver.spine.Length - 1].transform.position, solver.IKPosition);
                }
            }

            // Display the eyes
            if (solver.eyes.Length > 0)
            {
                for (int i = 0; i < solver.eyes.Length; i++)
                {
                    DrawLookAtBoneInScene(solver.eyes[i], solver.IKPosition, color, solver.IKPositionWeight * solver.eyesWeight);
                }
            }

            // Display the head
            if (solver.head.transform != null)
            {
                DrawLookAtBoneInScene(solver.head, solver.IKPosition, color, solver.IKPositionWeight * solver.headWeight);
            }

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

            // 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
                    if (solver.target == null)
                    {
                        solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
                    }
                }
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }
		private static void DrawLookAtBoneInScene(IKSolverLookAt.LookAtBone bone, Vector3 IKPosition, Color color, float lineWeight) {
			Handles.color = color;
			GUI.color = color;
					
			Handles.SphereCap(0, bone.transform.position, Quaternion.identity, GetHandleSize(bone.transform.position));
			
			// Draw a transparent line from last bone to IKPosition
			if (Application.isPlaying && lineWeight > 0) {
				Handles.color = new Color(color.r, color.g, color.b, color.a * lineWeight);
				Handles.DrawLine(bone.transform.position, IKPosition);
			}
		}
 private static Vector3 GetLookAtDirection(IKSolverLookAt solver)
 {
     if (solver.head.transform != null) return solver.IKPosition - solver.head.transform.position;
     if (solver.spine.Length > 0) {
         for (int i = solver.spine.Length; i > 0; i--) {
             if (solver.spine[i].transform != null) return solver.IKPosition - solver.spine[i].transform.position;
         }
     }
     return Vector3.forward;
 }
Example #6
0
            public void Update(IKSolverLookAt solver)
            {
                weight.Value = Mathf.Clamp(weight.Value, 0f, 1f);
                bodyWeight.Value = Mathf.Clamp(bodyWeight.Value, 0f, 1f);
                headWeight.Value = Mathf.Clamp(headWeight.Value, 0f, 1f);
                eyesWeight.Value = Mathf.Clamp(eyesWeight.Value, 0f, 1f);
                clampWeight.Value = Mathf.Clamp(clampWeight.Value, 0f, 1f);
                clampWeightHead.Value = Mathf.Clamp(clampWeightHead.Value, 0f, 1f);
                clampWeightEyes.Value = Mathf.Clamp(clampWeightEyes.Value, 0f, 1f);

                solver.target = target.Value == null? null: target.Value.transform;
                solver.IKPositionWeight = weight.Value;
                solver.IKPosition = position.Value;
                solver.bodyWeight = bodyWeight.Value;
                solver.headWeight = headWeight.Value;
                solver.eyesWeight = eyesWeight.Value;
                solver.clampWeight = clampWeight.Value;
                solver.clampWeightHead = clampWeightHead.Value;
                solver.clampWeightEyes = clampWeightEyes.Value;
            }
 public override void Execute()
 {
     var ik = EntityView.GetComponent<LookAtIK>();
     Solver = ik.solver;
 }
 public override void Execute()
 {
     var bipedIk = EntityView.GetComponent<BipedIK>();
     Solver = bipedIk.solvers.lookAt;
 }