PE: Added - Bounding Box Snapping, it dont matter what size objects are they will always snap perfectly.
This commit is contained in:
@@ -289,10 +289,29 @@ namespace FlaxEditor.Gizmo
|
||||
{
|
||||
float snapValue = isScaling ? ScaleSnapValue : TranslationSnapValue;
|
||||
_translationScaleSnapDelta += delta;
|
||||
delta = new Vector3(
|
||||
(int)(_translationScaleSnapDelta.X / snapValue) * snapValue,
|
||||
(int)(_translationScaleSnapDelta.Y / snapValue) * snapValue,
|
||||
(int)(_translationScaleSnapDelta.Z / snapValue) * snapValue);
|
||||
if (!isScaling && snapValue < 0)
|
||||
{
|
||||
//PE: Snap to object bounding box
|
||||
GetSelectedObjectsBounds(out var b, out _);
|
||||
float X, Y, Z;
|
||||
if (b.Minimum.X < 0) X = Math.Abs(b.Minimum.X) + b.Maximum.X;
|
||||
else X = b.Minimum.X - b.Maximum.X;
|
||||
if (b.Minimum.Y < 0) Y = Math.Abs(b.Minimum.Y) + b.Maximum.Y;
|
||||
else Y = b.Minimum.Y - b.Maximum.Y;
|
||||
if (b.Minimum.Z < 0) Z = Math.Abs(b.Minimum.Z) + b.Maximum.Z;
|
||||
else Z = b.Minimum.Z - b.Maximum.Z;
|
||||
delta = new Vector3(
|
||||
(int)(_translationScaleSnapDelta.X / X) * X,
|
||||
(int)(_translationScaleSnapDelta.Y / Y) * Y,
|
||||
(int)(_translationScaleSnapDelta.Z / Z) * Z);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = new Vector3(
|
||||
(int)(_translationScaleSnapDelta.X / snapValue) * snapValue,
|
||||
(int)(_translationScaleSnapDelta.Y / snapValue) * snapValue,
|
||||
(int)(_translationScaleSnapDelta.Z / snapValue) * snapValue);
|
||||
}
|
||||
_translationScaleSnapDelta -= delta;
|
||||
}
|
||||
|
||||
|
||||
@@ -310,6 +310,10 @@ namespace FlaxEditor.Viewport
|
||||
var button = translateSnappingCM.AddButton(v.ToString());
|
||||
button.Tag = v;
|
||||
}
|
||||
var buttonBB = translateSnappingCM.AddButton("Bounding Box");
|
||||
buttonBB.Tag = -1.0f;
|
||||
|
||||
|
||||
translateSnappingCM.ButtonClicked += OnWidgetTranslateSnapClick;
|
||||
translateSnappingCM.VisibleChanged += OnWidgetTranslateSnapShowHide;
|
||||
_translateSnapping.Parent = translateSnappingWidget;
|
||||
@@ -640,7 +644,10 @@ namespace FlaxEditor.Viewport
|
||||
{
|
||||
var v = (float)button.Tag;
|
||||
TransformGizmo.TranslationSnapValue = v;
|
||||
_translateSnapping.Text = v.ToString();
|
||||
if (v < 0.0f)
|
||||
_translateSnapping.Text = "Bounding Box";
|
||||
else
|
||||
_translateSnapping.Text = v.ToString();
|
||||
}
|
||||
|
||||
private void OnWidgetTranslateSnapShowHide(Control control)
|
||||
|
||||
Reference in New Issue
Block a user