Пример #1
0
        public static bool MovePoints(IEditablePoint points, Transform cloudTransform, List <int> selection)
        {
            bool result;

            if (selection.Count == 0)
            {
                result = false;
            }
            else
            {
                if (Camera.current)
                {
                    Vector3 vector = Vector3.zero;
                    vector = ((Tools.pivotMode != PivotMode.Pivot) ? (selection.Aggregate(vector, (Vector3 current, int index) => current + points.GetPosition(index)) / (float)selection.Count) : points.GetPosition(selection[0]));
                    vector = cloudTransform.TransformPoint(vector);
                    Vector3 position = Handles.PositionHandle(vector, (Tools.pivotRotation != PivotRotation.Local) ? Quaternion.identity : cloudTransform.rotation);
                    if (GUI.changed)
                    {
                        Vector3 b = cloudTransform.InverseTransformPoint(position) - cloudTransform.InverseTransformPoint(vector);
                        foreach (int current2 in selection)
                        {
                            points.SetPosition(current2, points.GetPosition(current2) + b);
                        }
                        result = true;
                        return(result);
                    }
                }
                result = false;
            }
            return(result);
        }
Пример #2
0
        /// Move the selected points using standard handles. returns true if point moved
        public static bool MovePoints(IEditablePoint points, Transform cloudTransform, List <int> selection)
        {
            if (selection.Count == 0)
            {
                return(false);
            }

            // Editing for the case where we're in a 3D sceneview
            if (Camera.current)
            {
                var handlePos = Vector3.zero;
                handlePos = Tools.pivotMode == PivotMode.Pivot ?
                            points.GetPosition(selection[0]) :
                            selection.Aggregate(handlePos, (current, index) => current + points.GetPosition(index)) / selection.Count;

                handlePos = cloudTransform.TransformPoint(handlePos);


                var newPos = Handles.PositionHandle(handlePos,
                                                    Tools.pivotRotation == PivotRotation.Local ? cloudTransform.rotation : Quaternion.identity);
                if (GUI.changed)
                {
                    Vector3 delta = cloudTransform.InverseTransformPoint(newPos) - cloudTransform.InverseTransformPoint(handlePos);
                    foreach (int i in selection)
                    {
                        points.SetPosition(i, points.GetPosition(i) + delta);
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
        public static bool MovePoints(IEditablePoint points, Transform cloudTransform, List <int> selection)
        {
            if (selection.Count == 0)
            {
                return(false);
            }
            if (Event.current.type == EventType.MouseUp)
            {
                PointEditor.s_EditingScale    = Vector3.one;
                PointEditor.s_EditingRotation = Quaternion.identity;
            }
            if (Camera.current)
            {
                Vector3 vector = Vector3.zero;
                vector = ((Tools.pivotMode != PivotMode.Pivot) ? (selection.Aggregate(vector, (Vector3 current, int index) => current + points.GetPosition(index)) / (float)selection.Count) : points.GetPosition(selection[0]));
                vector = cloudTransform.TransformPoint(vector);
                switch (Tools.current)
                {
                case Tool.Move:
                {
                    Vector3 position = Handles.PositionHandle(vector, (Tools.pivotRotation != PivotRotation.Local) ? Quaternion.identity : cloudTransform.rotation);
                    if (GUI.changed)
                    {
                        Vector3 b = cloudTransform.InverseTransformPoint(position) - cloudTransform.InverseTransformPoint(vector);
                        foreach (int current4 in selection)
                        {
                            points.SetPosition(current4, points.GetPosition(current4) + b);
                        }
                        return(true);
                    }
                    break;
                }

                case Tool.Rotate:
                {
                    Quaternion rotation = Handles.RotationHandle(PointEditor.s_EditingRotation, vector);
                    if (GUI.changed)
                    {
                        Vector3 b2 = cloudTransform.InverseTransformPoint(vector);
                        foreach (int current2 in selection)
                        {
                            Vector3 vector2 = points.GetPosition(current2) - b2;
                            vector2  = Quaternion.Inverse(PointEditor.s_EditingRotation) * vector2;
                            vector2  = rotation * vector2;
                            vector2 += b2;
                            points.SetPosition(current2, vector2);
                        }
                        PointEditor.s_EditingRotation = rotation;
                        return(true);
                    }
                    break;
                }

                case Tool.Scale:
                {
                    Vector3 vector3 = Handles.ScaleHandle(PointEditor.s_EditingScale, vector, Quaternion.identity, HandleUtility.GetHandleSize(vector));
                    if (GUI.changed)
                    {
                        Vector3 b3 = cloudTransform.InverseTransformPoint(vector);
                        foreach (int current3 in selection)
                        {
                            Vector3 vector4 = points.GetPosition(current3) - b3;
                            vector4.x /= PointEditor.s_EditingScale.x;
                            vector4.y /= PointEditor.s_EditingScale.y;
                            vector4.z /= PointEditor.s_EditingScale.z;
                            vector4.x *= vector3.x;
                            vector4.y *= vector3.y;
                            vector4.z *= vector3.z;
                            vector4   += b3;
                            points.SetPosition(current3, vector4);
                        }
                        PointEditor.s_EditingScale = vector3;
                        return(true);
                    }
                    break;
                }
                }
            }
            return(false);
        }
Пример #4
0
		public static bool MovePoints(IEditablePoint points, Transform cloudTransform, List<int> selection)
		{
			if (selection.Count == 0)
			{
				return false;
			}
			if (Event.current.type == EventType.MouseUp)
			{
				PointEditor.s_EditingScale = Vector3.one;
				PointEditor.s_EditingRotation = Quaternion.identity;
			}
			if (Camera.current)
			{
				Vector3 vector = Vector3.zero;
				vector = ((Tools.pivotMode != PivotMode.Pivot) ? (selection.Aggregate(vector, (Vector3 current, int index) => current + points.GetPosition(index)) / (float)selection.Count) : points.GetPosition(selection[0]));
				vector = cloudTransform.TransformPoint(vector);
				switch (Tools.current)
				{
				case Tool.Move:
				{
					Vector3 position = Handles.PositionHandle(vector, (Tools.pivotRotation != PivotRotation.Local) ? Quaternion.identity : cloudTransform.rotation);
					if (GUI.changed)
					{
						Vector3 b = cloudTransform.InverseTransformPoint(position) - cloudTransform.InverseTransformPoint(vector);
						foreach (int current4 in selection)
						{
							points.SetPosition(current4, points.GetPosition(current4) + b);
						}
						return true;
					}
					break;
				}
				case Tool.Rotate:
				{
					Quaternion rotation = Handles.RotationHandle(PointEditor.s_EditingRotation, vector);
					if (GUI.changed)
					{
						Vector3 b2 = cloudTransform.InverseTransformPoint(vector);
						foreach (int current2 in selection)
						{
							Vector3 vector2 = points.GetPosition(current2) - b2;
							vector2 = Quaternion.Inverse(PointEditor.s_EditingRotation) * vector2;
							vector2 = rotation * vector2;
							vector2 += b2;
							points.SetPosition(current2, vector2);
						}
						PointEditor.s_EditingRotation = rotation;
						return true;
					}
					break;
				}
				case Tool.Scale:
				{
					Vector3 vector3 = Handles.ScaleHandle(PointEditor.s_EditingScale, vector, Quaternion.identity, HandleUtility.GetHandleSize(vector));
					if (GUI.changed)
					{
						Vector3 b3 = cloudTransform.InverseTransformPoint(vector);
						foreach (int current3 in selection)
						{
							Vector3 vector4 = points.GetPosition(current3) - b3;
							vector4.x /= PointEditor.s_EditingScale.x;
							vector4.y /= PointEditor.s_EditingScale.y;
							vector4.z /= PointEditor.s_EditingScale.z;
							vector4.x *= vector3.x;
							vector4.y *= vector3.y;
							vector4.z *= vector3.z;
							vector4 += b3;
							points.SetPosition(current3, vector4);
						}
						PointEditor.s_EditingScale = vector3;
						return true;
					}
					break;
				}
				}
			}
			return false;
		}