@@ -76,7 +76,7 @@ namespace FlaxEditor.Gizmo
|
||||
public bool ScaleSnapEnabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// True if enable absolute grid snapping
|
||||
/// True if enable absolute grid snapping (snaps objects to world-space grid, not the one relative to gizmo location)
|
||||
/// </summary>
|
||||
public bool AbsoluteSnapEnabled = false;
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
#if USE_LARGE_WORLDS
|
||||
using Real = System.Double;
|
||||
using Mathr = FlaxEngine.Mathd;
|
||||
#else
|
||||
using Real = System.Single;
|
||||
using Mathr = FlaxEngine.Mathf;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
@@ -390,13 +392,13 @@ namespace FlaxEditor.Gizmo
|
||||
Vector3 absoluteDelta = Vector3.Zero;
|
||||
if (!_hasAbsoluteSnapped && AbsoluteSnapEnabled && ActiveTransformSpace == TransformSpace.World)
|
||||
{
|
||||
// Remove delta to offset local-space grid into the world-space grid
|
||||
_hasAbsoluteSnapped = true;
|
||||
|
||||
Vector3 currentTranslationScale = isScaling ? GetSelectedTransform(0).Scale : GetSelectedTransform(0).Translation;
|
||||
absoluteDelta = currentTranslationScale - new Vector3(
|
||||
(Real)Math.Round(currentTranslationScale.X / snapValue.X) * snapValue.X,
|
||||
(Real)Math.Round(currentTranslationScale.Y / snapValue.Y) * snapValue.Y,
|
||||
(Real)Math.Round(currentTranslationScale.Z / snapValue.Z) * snapValue.Z);
|
||||
Mathr.Round(currentTranslationScale.X / snapValue.X) * snapValue.X,
|
||||
Mathr.Round(currentTranslationScale.Y / snapValue.Y) * snapValue.Y,
|
||||
Mathr.Round(currentTranslationScale.Z / snapValue.Z) * snapValue.Z);
|
||||
}
|
||||
|
||||
delta = new Vector3(
|
||||
@@ -442,8 +444,8 @@ namespace FlaxEditor.Gizmo
|
||||
float absoluteDelta = 0.0f;
|
||||
if (!_hasAbsoluteSnapped && AbsoluteSnapEnabled && ActiveTransformSpace == TransformSpace.World)
|
||||
{
|
||||
// Remove delta to offset world-space grid into the local-space grid
|
||||
_hasAbsoluteSnapped = true;
|
||||
|
||||
float currentAngle = 0.0f;
|
||||
switch (_activeAxis)
|
||||
{
|
||||
@@ -451,7 +453,6 @@ namespace FlaxEditor.Gizmo
|
||||
case Axis.Y: currentAngle = GetSelectedTransform(0).Orientation.EulerAngles.Y; break;
|
||||
case Axis.Z: currentAngle = GetSelectedTransform(0).Orientation.EulerAngles.Z; break;
|
||||
}
|
||||
|
||||
absoluteDelta = currentAngle - (Mathf.Round(currentAngle / RotationSnapValue) * RotationSnapValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,30 +164,32 @@ namespace FlaxEditor.Viewport
|
||||
TooltipText = $"Gizmo transform space (world or local) ({inputOptions.ToggleTransformSpace})",
|
||||
Parent = transformSpaceWidget
|
||||
};
|
||||
transformSpaceToggle.Toggled += _ =>
|
||||
{
|
||||
transformGizmo.ToggleTransformSpace();
|
||||
if (useProjectCache)
|
||||
editor.ProjectCache.SetCustomData("TransformSpaceState", transformGizmo.ActiveTransformSpace.ToString());
|
||||
};
|
||||
transformSpaceWidget.Parent = viewport;
|
||||
|
||||
// Absolute snapping widget
|
||||
var absoluteSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
|
||||
var enableAbsoluteSnapping = new ViewportWidgetButton("A", SpriteHandle.Default, null, true)
|
||||
var enableAbsoluteSnapping = new ViewportWidgetButton("A", SpriteHandle.Invalid, null, true)
|
||||
{
|
||||
Checked = transformGizmo.AbsoluteSnapEnabled,
|
||||
TooltipText = "Enable absolute snapping",
|
||||
TooltipText = "Enable absolute grid snapping (world-space absolute grid, rather than object-relative grid)",
|
||||
Parent = absoluteSnappingWidget
|
||||
};
|
||||
enableAbsoluteSnapping.Toggled += _ =>
|
||||
{
|
||||
transformGizmo.AbsoluteSnapEnabled = !transformGizmo.AbsoluteSnapEnabled;
|
||||
if (useProjectCache)
|
||||
editor.ProjectCache.SetCustomData("AbsoluteSnapState", transformGizmo.AbsoluteSnapEnabled);
|
||||
editor.ProjectCache.SetCustomData("AbsoluteSnapState", transformGizmo.AbsoluteSnapEnabled);
|
||||
};
|
||||
absoluteSnappingWidget.Parent = viewport;
|
||||
|
||||
transformSpaceToggle.Toggled += _ =>
|
||||
{
|
||||
transformGizmo.ToggleTransformSpace();
|
||||
if (useProjectCache)
|
||||
editor.ProjectCache.SetCustomData("TransformSpaceState", transformGizmo.ActiveTransformSpace.ToString());
|
||||
absoluteSnappingWidget.Visible = transformGizmo.ActiveTransformSpace == TransformGizmoBase.TransformSpace.World;
|
||||
};
|
||||
|
||||
// Scale snapping widget
|
||||
var scaleSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
|
||||
var enableScaleSnapping = new ViewportWidgetButton(string.Empty, editor.Icons.ScaleSnap32, null, true)
|
||||
@@ -401,17 +403,17 @@ namespace FlaxEditor.Viewport
|
||||
gizmoModeRotate.Checked = mode == TransformGizmoBase.Mode.Rotate;
|
||||
gizmoModeScale.Checked = mode == TransformGizmoBase.Mode.Scale;
|
||||
};
|
||||
|
||||
|
||||
// Setup input actions
|
||||
viewport.InputActions.Add(options => options.TranslateMode, () =>
|
||||
viewport.InputActions.Add(options => options.TranslateMode, () =>
|
||||
{
|
||||
viewport.GetInput(out var input);
|
||||
if (input.IsMouseRightDown)
|
||||
return;
|
||||
|
||||
|
||||
transformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate;
|
||||
});
|
||||
viewport.InputActions.Add(options => options.RotateMode, () =>
|
||||
viewport.InputActions.Add(options => options.RotateMode, () =>
|
||||
{
|
||||
viewport.GetInput(out var input);
|
||||
if (input.IsMouseRightDown)
|
||||
|
||||
Reference in New Issue
Block a user