Add absolute snapping
This commit is contained in:
@@ -40,6 +40,7 @@ namespace FlaxEditor.Gizmo
|
||||
private Vector3 _intersectPosition;
|
||||
private bool _isActive;
|
||||
private bool _isDuplicating;
|
||||
private bool _hasAbsoluteSnapped;
|
||||
|
||||
private bool _isTransforming;
|
||||
private Vector3 _lastIntersectionPosition;
|
||||
@@ -316,6 +317,7 @@ namespace FlaxEditor.Gizmo
|
||||
if ((isScaling ? ScaleSnapEnabled : TranslationSnapEnable) || Owner.UseSnapping)
|
||||
{
|
||||
var snapValue = new Vector3(isScaling ? ScaleSnapValue : TranslationSnapValue);
|
||||
|
||||
_translationScaleSnapDelta += delta;
|
||||
if (!isScaling && snapValue.X < 0.0f)
|
||||
{
|
||||
@@ -334,11 +336,29 @@ namespace FlaxEditor.Gizmo
|
||||
else
|
||||
snapValue.Z = (Real)b.Minimum.Z - b.Maximum.Z;
|
||||
}
|
||||
|
||||
Vector3 absoluteDelta = Vector3.Zero;
|
||||
if (!_hasAbsoluteSnapped && AbsoluteSnapEnabled)
|
||||
{
|
||||
_hasAbsoluteSnapped = true;
|
||||
|
||||
Vector3 currentTranslationScale = isScaling ? GetSelectedTransform(0).Scale : GetSelectedTransform(0).Translation;
|
||||
absoluteDelta = currentTranslationScale - new Vector3(
|
||||
Mathf.Round(currentTranslationScale.X / snapValue.X) * snapValue.X,
|
||||
Mathf.Round(currentTranslationScale.Y / snapValue.Y) * snapValue.Y,
|
||||
Mathf.Round(currentTranslationScale.Z / snapValue.Z) * snapValue.Z);
|
||||
}
|
||||
|
||||
delta = new Vector3(
|
||||
(int)(_translationScaleSnapDelta.X / snapValue.X) * snapValue.X,
|
||||
(int)(_translationScaleSnapDelta.Y / snapValue.Y) * snapValue.Y,
|
||||
(int)(_translationScaleSnapDelta.Z / snapValue.Z) * snapValue.Z);
|
||||
_translationScaleSnapDelta -= delta;
|
||||
delta -= absoluteDelta;
|
||||
}
|
||||
else
|
||||
{
|
||||
_hasAbsoluteSnapped = false;
|
||||
}
|
||||
|
||||
if (_activeMode == Mode.Translate)
|
||||
@@ -368,12 +388,34 @@ namespace FlaxEditor.Gizmo
|
||||
if (RotationSnapEnabled || Owner.UseSnapping)
|
||||
{
|
||||
float snapValue = RotationSnapValue * Mathf.DegreesToRadians;
|
||||
|
||||
float absoluteDelta = 0.0f;
|
||||
if (!_hasAbsoluteSnapped && AbsoluteSnapEnabled)
|
||||
{
|
||||
_hasAbsoluteSnapped = true;
|
||||
|
||||
float currentAngle = 0.0f;
|
||||
switch (_activeAxis)
|
||||
{
|
||||
case Axis.X: currentAngle = GetSelectedTransform(0).Orientation.EulerAngles.X; break;
|
||||
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);
|
||||
}
|
||||
|
||||
_rotationSnapDelta += delta;
|
||||
|
||||
float snapped = Mathf.Round(_rotationSnapDelta / snapValue) * snapValue;
|
||||
_rotationSnapDelta -= snapped;
|
||||
|
||||
delta = snapped;
|
||||
delta -= absoluteDelta * Mathf.DegreesToRadians;
|
||||
}
|
||||
else
|
||||
{
|
||||
_hasAbsoluteSnapped = false;
|
||||
}
|
||||
|
||||
switch (_activeAxis)
|
||||
|
||||
Reference in New Issue
Block a user