/// <summary> /// Changes the transform pivot point to the specified value. /// </summary> private void ChangeTransformPivotPoint(TransformPivotPoint transformPivotPoint) { // Store the new pivot point _transformPivotPoint = transformPivotPoint; // Set the pivot point for each gizmo //_translationGizmo.TransformPivotPoint = _transformPivotPoint; _rotationGizmo.TransformPivotPoint = _transformPivotPoint; //_scaleGizmo.TransformPivotPoint = _transformPivotPoint; // Establish the position of the active gizmo EstablishActiveGizmoPosition(); }
private void Update() { if (_activateTranslationGizmoShortcut.IsActiveInCurrentFrame()) { ChangeActiveGizmo(GizmoType.Translation); } else if (_activateRotationGizmoShortcut.IsActiveInCurrentFrame()) { ChangeActiveGizmo(GizmoType.Rotation); } else if (_activateScaleGizmoShortcut.IsActiveInCurrentFrame()) { ChangeActiveGizmo(GizmoType.Scale); } else if (_activateVolumeScaleGizmoShortcut.IsActiveInCurrentFrame()) { ChangeActiveGizmo(GizmoType.VolumeScale); } if (_activateGlobalTransformShortcut.IsActiveInCurrentFrame()) { ChangeTransformSpace(TransformSpace.Global); } else if (_activateLocalTransformShortcut.IsActiveInCurrentFrame()) { ChangeTransformSpace(TransformSpace.Local); } if (_turnOffGizmosShortcut.IsActiveInCurrentFrame()) { TurnOffGizmos(); } else if (_togglePivotShortcut.IsActiveInCurrentFrame()) { TransformPivotPoint newPivotPoint = _transformPivotPoint == TransformPivotPoint.Center ? TransformPivotPoint.MeshPivot : TransformPivotPoint.Center; ChangeTransformPivotPoint(newPivotPoint); } }
private void Update() { // added by me if (_activateTranslationGizmoShortcut.IsActiveInCurrentFrame()) { if (IsGizmoTypeAvailable(GizmoType.Translation)) { toolBarController.ButtonMoveOnClick(); } } else if (_activateRotationGizmoShortcut.IsActiveInCurrentFrame()) { if (IsGizmoTypeAvailable(GizmoType.Rotation)) { toolBarController.ButtonRotateOnClick(); } } else if (_activateScaleGizmoShortcut.IsActiveInCurrentFrame()) { if (IsGizmoTypeAvailable(GizmoType.Scale)) { toolBarController.ButtonScaleOnClick(); } } else if (_activateVolumeScaleGizmoShortcut.IsActiveInCurrentFrame()) { if (IsGizmoTypeAvailable(GizmoType.VolumeScale)) { toolBarController.ButtonVolumeScaleOnClick(); } } if (toolBarController.isMoving) { ChangeActiveGizmo(GizmoType.Translation); toolBarController.isMoving = false; } else if (toolBarController.isRotating) { ChangeActiveGizmo(GizmoType.Rotation); toolBarController.isRotating = false; } else if (toolBarController.isScaling) { ChangeActiveGizmo(GizmoType.Scale); toolBarController.isScaling = false; } else if (toolBarController.isVolumeScaling) { ChangeActiveGizmo(GizmoType.VolumeScale); toolBarController.isVolumeScaling = false; } if (_activateGlobalTransformShortcut.IsActiveInCurrentFrame()) { toolBarController.SetGlobal(true); } else if (_activateLocalTransformShortcut.IsActiveInCurrentFrame()) { toolBarController.SetGlobal(false); } if (toolBarController.isGlobal) { ChangeTransformSpace(TransformSpace.Global); } else { ChangeTransformSpace(TransformSpace.Local); } if (_turnOffGizmosShortcut.IsActiveInCurrentFrame() || !toolBarController.CanSelectObject()) { TurnOffGizmos(); } else if (_togglePivotShortcut.IsActiveInCurrentFrame()) { TransformPivotPoint newPivotPoint = _transformPivotPoint == TransformPivotPoint.Center ? TransformPivotPoint.MeshPivot : TransformPivotPoint.Center; ChangeTransformPivotPoint(newPivotPoint); } // //if (_activateTranslationGizmoShortcut.IsActiveInCurrentFrame()) ChangeActiveGizmo(GizmoType.Translation); //else //if (_activateRotationGizmoShortcut.IsActiveInCurrentFrame()) ChangeActiveGizmo(GizmoType.Rotation); //else //if (_activateScaleGizmoShortcut.IsActiveInCurrentFrame()) ChangeActiveGizmo(GizmoType.Scale); //else //if (_activateVolumeScaleGizmoShortcut.IsActiveInCurrentFrame()) ChangeActiveGizmo(GizmoType.VolumeScale); //if (_activateGlobalTransformShortcut.IsActiveInCurrentFrame()) ChangeTransformSpace(TransformSpace.Global); //else if (_activateLocalTransformShortcut.IsActiveInCurrentFrame()) ChangeTransformSpace(TransformSpace.Local); //if (_turnOffGizmosShortcut.IsActiveInCurrentFrame()) TurnOffGizmos(); //else //if (_togglePivotShortcut.IsActiveInCurrentFrame()) //{ // TransformPivotPoint newPivotPoint = _transformPivotPoint == TransformPivotPoint.Center ? TransformPivotPoint.MeshPivot : TransformPivotPoint.Center; // ChangeTransformPivotPoint(newPivotPoint); //} }
/// <summary> /// Constructor. /// </summary> /// <param name="oldPivotPoint"> /// This is the pivot point that is active before the action is executed. /// </param> /// <param name="newPivotPoint"> /// This is the new pivot point. /// </param> public TransformPivotPointChangeAction(TransformPivotPoint oldPivotPoint, TransformPivotPoint newPivotPoint) { _oldPivotPoint = oldPivotPoint; _newPivotPoint = newPivotPoint; }
/// <summary> /// This method handles the shortcut keys which are related to the gizmo system. /// </summary> private void HandleEditorGizmoSystemKeys() { EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; // Check which shortcut key was pressed and execute the corresponding action if (Input.GetKeyDown(KeyCode.W) && !Input.GetMouseButton((int)MouseButton.Right)) { var action = new ActiveGizmoTypeChangeAction(gizmoSystem.ActiveGizmoType, GizmoType.Translation); action.Execute(); } else if (Input.GetKeyDown(KeyCode.E) && !Input.GetMouseButton((int)MouseButton.Right)) { var action = new ActiveGizmoTypeChangeAction(gizmoSystem.ActiveGizmoType, GizmoType.Rotation); action.Execute(); } else if (Input.GetKeyDown(KeyCode.R)) { var action = new ActiveGizmoTypeChangeAction(gizmoSystem.ActiveGizmoType, GizmoType.Scale); action.Execute(); } else if (Input.GetKeyDown(KeyCode.G)) { EditorGizmoSystem.Instance.TransformSpace = TransformSpace.Global; } else if (Input.GetKeyDown(KeyCode.L)) { EditorGizmoSystem.Instance.TransformSpace = TransformSpace.Local; } else if (Input.GetKeyDown(KeyCode.Q) && !Input.GetMouseButton((int)MouseButton.Right)) { var action = new GizmosTurnOffAction(gizmoSystem.ActiveGizmoType); action.Execute(); } else if (Input.GetKeyDown(KeyCode.P)) { // Toggle the pivot point and execute the action TransformPivotPoint newTransformPivotPoint = gizmoSystem.TransformPivotPoint == TransformPivotPoint.Center ? TransformPivotPoint.MeshPivot : TransformPivotPoint.Center; EditorGizmoSystem.Instance.TransformPivotPoint = newTransformPivotPoint; } // Check if any gizmo shorcut keys were pressed. We will do this based on which type of // gizmo is currently active. GizmoType activeGizmoType = gizmoSystem.ActiveGizmoType; if (activeGizmoType == GizmoType.Translation) { // // If the SHIFT key is pressed, we will activate translation along the camera right and up axes // TranslationGizmo translationGizmo = gizmoSystem.TranslationGizmo; // bool isShiftPressed = InputHelper.IsAnyShiftKeyPressed(); // if (isShiftPressed) translationGizmo.TranslateAlongCameraRightAndUpAxes = true; // else translationGizmo.TranslateAlongCameraRightAndUpAxes = false; // // // If the CTRL/COMMAND key is pressed, we will activate step snapping // bool isCtrlOrCommandPressed = InputHelper.IsAnyCtrlOrCommandKeyPressed(); // if (isCtrlOrCommandPressed) translationGizmo.SnapSettings.IsStepSnappingEnabled = true; // else translationGizmo.SnapSettings.IsStepSnappingEnabled = false; // // // If the 'V' key was pressed in the current frame, we will activate vertex snapping. When // // the 'V' key is released in the current frame, we will deactivate vertex snapping. // if (Input.GetKeyDown(KeyCode.V)) // { // translationGizmo.SnapSettings.IsVertexSnappingEnabled = true; // VertexSnappingEnabledMessage.SendToInterestedListeners(); // } // if (Input.GetKeyUp(KeyCode.V)) // { // translationGizmo.SnapSettings.IsVertexSnappingEnabled = false; // VertexSnappingDisabledMessage.SendToInterestedListeners(); // } // // if (Input.GetKeyDown(KeyCode.Space)) translationGizmo.PlaceObjectsOnSurface = true; // // Axis alignmentAxis = Axis.Y; // if (Input.GetKey(KeyCode.X)) alignmentAxis = Axis.X; // else if (Input.GetKey(KeyCode.Z)) alignmentAxis = Axis.Z; // translationGizmo.SurfaceAlignmentAxis = alignmentAxis; // // if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) translationGizmo.AlignObjectAxisToSurface = false; // else translationGizmo.AlignObjectAxisToSurface = true; // // if (Input.GetKeyUp(KeyCode.Space)) translationGizmo.PlaceObjectsOnSurface = false; } else if (activeGizmoType == GizmoType.Rotation) { // If the CTRL/COMMAND key is pressed, we will activate snapping RotationGizmo rotationGizmo = gizmoSystem.RotationGizmo; bool isCtrlOrCommandPressed = InputHelper.IsAnyCtrlOrCommandKeyPressed(); if (isCtrlOrCommandPressed) { rotationGizmo.SnapSettings.IsSnappingEnabled = true; } else { rotationGizmo.SnapSettings.IsSnappingEnabled = false; } } else if (activeGizmoType == GizmoType.Scale) { // If the shift key is pressed, we will activate scaling along all axes at once // ScaleGizmo scaleGizmo = gizmoSystem.ScaleGizmo; // bool isShiftPressed = InputHelper.IsAnyShiftKeyPressed(); // if (isShiftPressed) scaleGizmo.ScaleAlongAllAxes = true; // else scaleGizmo.ScaleAlongAllAxes = false; // // // If the CTRL/COMMAND key is pressed, we will activate snapping // bool isCtrlOrCommandPressed = InputHelper.IsAnyCtrlOrCommandKeyPressed(); // if (isCtrlOrCommandPressed) scaleGizmo.SnapSettings.IsSnappingEnabled = true; // else scaleGizmo.SnapSettings.IsSnappingEnabled = false; } }
/// <summary> /// Convenience function for sending a transform pivot point changed message to /// all interested listeners. /// </summary> /// <param name="oldPivotPoint"> /// This is the old pivot point before it was changed. /// </param> /// <param name="newPivotPoint"> /// This is the new pivot point. /// </param> public static void SendToInterestedListeners(TransformPivotPoint oldPivotPoint, TransformPivotPoint newPivotPoint) { var message = new TransformPivotPointChangedMessage(oldPivotPoint, newPivotPoint); MessageListenerDatabase.Instance.SendMessageToInterestedListeners(message); }
/// <summary> /// Constructor. /// </summary> /// <param name="oldPivotPoint"> /// This is the old pivot point before it was changed. /// </param> /// <param name="newPivotPoint"> /// This is the new pivot point. /// </param> public TransformPivotPointChangedMessage(TransformPivotPoint oldPivotPoint, TransformPivotPoint newPivotPoint) : base(MessageType.TransformPivotPointChanged) { _oldPivotPoint = oldPivotPoint; _newPivotPoint = newPivotPoint; }