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

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

            Vector3 bendPosition = solver.bone2.transform.position;
            Vector3 endPosition  = solver.bone3.transform.position;

            // Chain lines
            Handles.DrawLine(solver.bone1.transform.position, bendPosition);
            Handles.DrawLine(bendPosition, endPosition);

            // Joints
            Handles.SphereCap(0, solver.bone1.transform.position, Quaternion.identity, jointSize);
            Handles.SphereCap(0, bendPosition, Quaternion.identity, jointSize);
            Handles.SphereCap(0, endPosition, Quaternion.identity, jointSize);

            if (Application.isPlaying && (solver.IKPositionWeight > 0 || solver.IKRotationWeight > 0))
            {
                if (modifiable)
                {
                    Handles.CubeCap(0, solver.IKPosition, solver.IKRotation, selectedSize);

                    // Manipulating position and rotation
                    switch (Tools.current)
                    {
                    case Tool.Move:
                        solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
                        break;

                    case Tool.Rotate:
                        solver.IKRotation = Handles.RotationHandle(solver.IKRotation, solver.IKPosition);
                        break;
                    }
                }

                // Target
                Handles.color = new Color(color.r, color.g, color.b, color.a * Mathf.Max(solver.IKPositionWeight, solver.IKRotationWeight));
                Handles.DrawLine(endPosition, solver.IKPosition);
            }

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

			//float length = Vector3.Distance(solver.bone1.transform.position, solver.bone2.transform.position) + Vector3.Distance(solver.bone2.transform.position, solver.bone3.transform.position);
			//float size = length * 0.05f;

			Handles.color = color;
			GUI.color = color;
			
			Vector3 bendPosition = solver.bone2.transform.position;
			Vector3 endPosition = solver.bone3.transform.position;
			
			// Chain lines
			Handles.DrawLine(solver.bone1.transform.position, bendPosition);
			Handles.DrawLine(bendPosition, endPosition);
			
			// Joints
			Handles.SphereCap(0, solver.bone1.transform.position, Quaternion.identity, GetHandleSize(solver.bone1.transform.position));
			Handles.SphereCap(0, bendPosition, Quaternion.identity, GetHandleSize(bendPosition));
			Handles.SphereCap(0, endPosition, Quaternion.identity, GetHandleSize(endPosition));
			
			if (Application.isPlaying && (solver.IKPositionWeight > 0 || solver.IKRotationWeight > 0)) {
				if (modifiable) {
					Handles.CubeCap(0, solver.IKPosition, solver.IKRotation, GetHandleSize(solver.IKPosition));
						
					// Manipulating position and rotation
					switch(Tools.current) {
					case Tool.Move:
						if (solver.target == null) solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
						break;
					case Tool.Rotate:
						if (solver.target == null) solver.IKRotation = Handles.RotationHandle(solver.IKRotation, solver.IKPosition);
						break;
					}
				}
				
				// Target
				Handles.color = new Color(color.r, color.g, color.b, color.a * Mathf.Max(solver.IKPositionWeight, solver.IKRotationWeight));
				Handles.DrawLine(endPosition, solver.IKPosition);
			}
			
			Handles.color = Color.white;
			GUI.color = Color.white;
		}
Beispiel #3
0
        /*
         * Draws the scene view helpers for IKSolverTrigonometric
         * */
        public static void AddScene(IKSolverTrigonometric solver, Color color, bool modifiable)
        {
            if (Application.isPlaying && !solver.initiated)
            {
                return;
            }
            if (!Application.isPlaying && !solver.IsValid())
            {
                return;
            }

            //float length = Vector3.Distance(solver.bone1.transform.position, solver.bone2.transform.position) + Vector3.Distance(solver.bone2.transform.position, solver.bone3.transform.position);
            //float size = length * 0.05f;

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

            Vector3 bendPosition = solver.bone2.transform.position;
            Vector3 endPosition  = solver.bone3.transform.position;

            // Chain lines
            Handles.DrawLine(solver.bone1.transform.position, bendPosition);
            Handles.DrawLine(bendPosition, endPosition);

            // Joints
            Handles.SphereHandleCap(0, solver.bone1.transform.position, Quaternion.identity, GetHandleSize(solver.bone1.transform.position), EventType.Repaint);
            Handles.SphereHandleCap(0, bendPosition, Quaternion.identity, GetHandleSize(bendPosition), EventType.Repaint);
            Handles.SphereHandleCap(0, endPosition, Quaternion.identity, GetHandleSize(endPosition), EventType.Repaint);

            if (Application.isPlaying && (solver.IKPositionWeight > 0 || solver.IKRotationWeight > 0))
            {
                if (modifiable)
                {
                    Handles.CubeHandleCap(0, solver.IKPosition, solver.IKRotation, GetHandleSize(solver.IKPosition), EventType.Repaint);

                    // Manipulating position and rotation
                    switch (Tools.current)
                    {
                    case Tool.Move:
                        if (solver.target == null)
                        {
                            solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
                        }
                        break;

                    case Tool.Rotate:
                        if (solver.target == null)
                        {
                            solver.IKRotation = Handles.RotationHandle(solver.IKRotation, solver.IKPosition);
                        }
                        break;
                    }
                }

                // Target
                Handles.color = new Color(color.r, color.g, color.b, color.a * Mathf.Max(solver.IKPositionWeight, solver.IKRotationWeight));
                Handles.DrawLine(endPosition, solver.IKPosition);
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }