diff --git a/Content/Editor/Gizmo/Axis.flax b/Content/Editor/Gizmo/Axis.flax deleted file mode 100644 index c2b0a30f0..000000000 --- a/Content/Editor/Gizmo/Axis.flax +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f32f2401c2c6eb05d1674f98950f4d9ff0a9508d42fa25413eba3a49a0be9363 -size 11800 diff --git a/Content/Editor/Gizmo/MaterialSphere.flax b/Content/Editor/Gizmo/MaterialSphere.flax new file mode 100644 index 000000000..bf110acfb --- /dev/null +++ b/Content/Editor/Gizmo/MaterialSphere.flax @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf88f48c5de6b8fb8c7effbbdded9e6f115b1a3ac262d60785987c8f24107dfb +size 567 diff --git a/Content/Editor/Gizmo/RotationAxis.flax b/Content/Editor/Gizmo/RotationAxis.flax new file mode 100644 index 000000000..a743e30a6 --- /dev/null +++ b/Content/Editor/Gizmo/RotationAxis.flax @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d8f319dcd39842cb991a4e8e67e4823c7159a493a1aec757232077e5d56ad9f +size 41685 diff --git a/Content/Editor/Gizmo/ScaleAxis.flax b/Content/Editor/Gizmo/ScaleAxis.flax index 150b1e1dd..8f774c883 100644 --- a/Content/Editor/Gizmo/ScaleAxis.flax +++ b/Content/Editor/Gizmo/ScaleAxis.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:feb61724fc4fd620de5e3cedf6f74485d38aea4f3a88bf44ecdc186424d14b04 -size 3933 +oid sha256:8743967dc27d5839b88dfa1e599cbc9b290427afd6b65b2424ffa5218b330beb +size 40754 diff --git a/Content/Editor/Gizmo/TranslateAxis.flax b/Content/Editor/Gizmo/TranslateAxis.flax deleted file mode 100644 index a97bbc780..000000000 --- a/Content/Editor/Gizmo/TranslateAxis.flax +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:011c8be02f11017c28b300601b19f12c8750b256d0aabe060c519794c4578d41 -size 7757 diff --git a/Content/Editor/Gizmo/TranslationAxis.flax b/Content/Editor/Gizmo/TranslationAxis.flax new file mode 100644 index 000000000..f91e2b18a --- /dev/null +++ b/Content/Editor/Gizmo/TranslationAxis.flax @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6096ef866920a861ec91f0660999a9ea07b2fbd26bcf52ba2c0112ba5e02336 +size 8915 diff --git a/Content/Editor/Gizmo/WireCircle.flax b/Content/Editor/Gizmo/WireCircle.flax deleted file mode 100644 index 1378ea4f6..000000000 --- a/Content/Editor/Gizmo/WireCircle.flax +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:901ae5ba301bf22697e4f7ced101f97dfe6ef38771f940c0c38e43125157d080 -size 139269 diff --git a/Flax.flaxproj b/Flax.flaxproj index 2553a3727..c3c825910 100644 --- a/Flax.flaxproj +++ b/Flax.flaxproj @@ -3,7 +3,7 @@ "Version": { "Major": 1, "Minor": 5, - "Build": 6336 + "Build": 6337 }, "Company": "Flax", "Copyright": "Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.", diff --git a/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs b/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs index 77a9cb017..0d421a17e 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs @@ -6,44 +6,48 @@ namespace FlaxEditor.Gizmo { public partial class TransformGizmoBase { - private Model _modelTranslateAxis; + // Models + private Model _modelTranslationAxis; private Model _modelScaleAxis; - private Model _modelBox; - private Model _modelCircle; + private Model _modelRotationAxis; + private Model _modelSphere; + private Model _modelCube; + + // Materials private MaterialInstance _materialAxisX; private MaterialInstance _materialAxisY; private MaterialInstance _materialAxisZ; private MaterialInstance _materialAxisFocus; - private MaterialBase _materialWire; - private MaterialBase _materialWireFocus; + private MaterialBase _materialSphere; private void InitDrawing() { - // Load content (but async - don't wait and don't block execution) - _modelTranslateAxis = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/TranslateAxis"); + // Axis Models + _modelTranslationAxis = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/TranslationAxis"); _modelScaleAxis = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/ScaleAxis"); - _modelBox = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/WireBox"); - _modelCircle = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/WireCircle"); + _modelRotationAxis = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/RotationAxis"); + _modelSphere = FlaxEngine.Content.LoadAsyncInternal("Editor/Primitives/Sphere"); + _modelCube = FlaxEngine.Content.LoadAsyncInternal("Editor/Primitives/Cube"); + + // Axis Materials _materialAxisX = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/MaterialAxisX"); _materialAxisY = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/MaterialAxisY"); _materialAxisZ = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/MaterialAxisZ"); _materialAxisFocus = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/MaterialAxisFocus"); - _materialWire = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/MaterialWire"); - _materialWireFocus = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/MaterialWireFocus"); + _materialSphere = FlaxEngine.Content.LoadAsyncInternal("Editor/Gizmo/MaterialSphere"); // Ensure that every asset was loaded - if (_modelTranslateAxis == null || + if (_modelTranslationAxis == null || _modelScaleAxis == null || - _modelBox == null || - _modelCircle == null || + _modelRotationAxis == null || + _modelSphere == null || + _modelCube == null || _materialAxisX == null || _materialAxisY == null || _materialAxisZ == null || _materialAxisFocus == null || - _materialWire == null || - _materialWireFocus == null) + _materialSphere == null) { - // Error Platform.Fatal("Failed to load transform gizmo resources."); } } @@ -58,6 +62,8 @@ namespace FlaxEditor.Gizmo // https://github.com/FlaxEngine/FlaxEngine/issues/680 Matrix m1, m2, m3, mx1; + float boxScale = 300f; + float boxSize = 0.085f; bool isXAxis = _activeAxis == Axis.X || _activeAxis == Axis.XY || _activeAxis == Axis.ZX; bool isYAxis = _activeAxis == Axis.Y || _activeAxis == Axis.XY || _activeAxis == Axis.YZ; bool isZAxis = _activeAxis == Axis.Z || _activeAxis == Axis.YZ || _activeAxis == Axis.ZX; @@ -65,114 +71,137 @@ namespace FlaxEditor.Gizmo renderContext.View.GetWorldMatrix(ref _gizmoWorld, out Matrix world); const float gizmoModelsScale2RealGizmoSize = 0.075f; + Mesh sphereMesh, cubeMesh; switch (_activeMode) { case Mode.Translate: { - if (!_modelTranslateAxis || !_modelTranslateAxis.IsLoaded || !_modelBox || !_modelBox.IsLoaded) + if (!_modelTranslationAxis || !_modelTranslationAxis.IsLoaded || !_modelCube || !_modelCube.IsLoaded || !_modelSphere || !_modelSphere.IsLoaded) break; + var transAxisMesh = _modelTranslationAxis.LODs[0].Meshes[0]; + cubeMesh = _modelCube.LODs[0].Meshes[0]; + sphereMesh = _modelSphere.LODs[0].Meshes[0]; Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m3); Matrix.Multiply(ref m3, ref world, out m1); mx1 = m1; mx1.M41 += 0.05f; - var axisMesh = _modelTranslateAxis.LODs[0].Meshes[0]; - var boxMesh = _modelBox.LODs[0].Meshes[0]; - var boxSize = 10.0f; - - // XY plane - m2 = Matrix.Transformation(new Vector3(boxSize, 1.0f, boxSize), Quaternion.RotationX(Mathf.PiOverTwo), new Vector3(boxSize * 0.5f, boxSize * 0.5f, 0.0f)); - Matrix.Multiply(ref m2, ref m1, out m3); - boxMesh.Draw(ref renderContext, _activeAxis == Axis.XY ? _materialWireFocus : _materialWire, ref m3); - - // ZX plane - m2 = Matrix.Transformation(new Vector3(boxSize, 1.0f, boxSize), Quaternion.Identity, new Vector3(boxSize * 0.5f, 0.0f, boxSize * 0.5f)); - Matrix.Multiply(ref m2, ref m1, out m3); - boxMesh.Draw(ref renderContext, _activeAxis == Axis.ZX ? _materialWireFocus : _materialWire, ref m3); - - // YZ plane - m2 = Matrix.Transformation(new Vector3(boxSize, 1.0f, boxSize), Quaternion.RotationZ(Mathf.PiOverTwo), new Vector3(0.0f, boxSize * 0.5f, boxSize * 0.5f)); - Matrix.Multiply(ref m2, ref m1, out m3); - boxMesh.Draw(ref renderContext, _activeAxis == Axis.YZ ? _materialWireFocus : _materialWire, ref m3); // X axis - axisMesh.Draw(ref renderContext, isXAxis ? _materialAxisFocus : _materialAxisX, ref mx1); - - // Y axis - Matrix.RotationZ(Mathf.PiOverTwo, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); - axisMesh.Draw(ref renderContext, isYAxis ? _materialAxisFocus : _materialAxisY, ref m3); - - // Z axis Matrix.RotationY(-Mathf.PiOverTwo, out m2); Matrix.Multiply(ref m2, ref m1, out m3); - axisMesh.Draw(ref renderContext, isZAxis ? _materialAxisFocus : _materialAxisZ, ref m3); + transAxisMesh.Draw(ref renderContext, isXAxis ? _materialAxisFocus : _materialAxisX, ref m3); + + // Y axis + Matrix.RotationX(Mathf.PiOverTwo, out m2); + Matrix.Multiply(ref m2, ref m1, out m3); + transAxisMesh.Draw(ref renderContext, isYAxis ? _materialAxisFocus : _materialAxisY, ref m3); + + // Z axis + Matrix.RotationX(Mathf.Pi, out m2); + Matrix.Multiply(ref m2, ref m1, out m3); + transAxisMesh.Draw(ref renderContext, isZAxis ? _materialAxisFocus : _materialAxisZ, ref m3); + + // XY plane + m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.RotationX(Mathf.PiOverTwo), new Vector3(boxSize * boxScale, boxSize * boxScale, 0.0f)); + Matrix.Multiply(ref m2, ref m1, out m3); + cubeMesh.Draw(ref renderContext, _activeAxis == Axis.XY ? _materialAxisFocus : _materialAxisX, ref m3); + + // ZX plane + m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.Identity, new Vector3(boxSize * boxScale, 0.0f, boxSize * boxScale)); + Matrix.Multiply(ref m2, ref m1, out m3); + cubeMesh.Draw(ref renderContext, _activeAxis == Axis.ZX ? _materialAxisFocus : _materialAxisZ, ref m3); + + // YZ plane + m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.RotationZ(Mathf.PiOverTwo), new Vector3(0.0f, boxSize * boxScale, boxSize * boxScale)); + Matrix.Multiply(ref m2, ref m1, out m3); + cubeMesh.Draw(ref renderContext, _activeAxis == Axis.YZ ? _materialAxisFocus : _materialAxisY, ref m3); + + // Center sphere + Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m2); + Matrix.Multiply(ref m2, ref m1, out m3); + sphereMesh.Draw(ref renderContext, isCenter ? _materialAxisFocus : _materialSphere, ref m3); break; } case Mode.Rotate: { - if (!_modelCircle || !_modelCircle.IsLoaded || !_modelBox || !_modelBox.IsLoaded) + if (!_modelRotationAxis || !_modelRotationAxis.IsLoaded || !_modelSphere || !_modelSphere.IsLoaded) break; - var circleMesh = _modelCircle.LODs[0].Meshes[0]; - var boxMesh = _modelBox.LODs[0].Meshes[0]; - Matrix.Scaling(8.0f, out m3); + var rotationAxisMesh = _modelRotationAxis.LODs[0].Meshes[0]; + sphereMesh = _modelSphere.LODs[0].Meshes[0]; + Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m3); Matrix.Multiply(ref m3, ref world, out m1); + mx1 = m1; + mx1.M41 += 0.05f; // X axis Matrix.RotationZ(Mathf.PiOverTwo, out m2); Matrix.Multiply(ref m2, ref m1, out m3); - circleMesh.Draw(ref renderContext, isXAxis ? _materialAxisFocus : _materialAxisX, ref m3); + rotationAxisMesh.Draw(ref renderContext, isXAxis ? _materialAxisFocus : _materialAxisX, ref m3); // Y axis - circleMesh.Draw(ref renderContext, isYAxis ? _materialAxisFocus : _materialAxisY, ref m1); + rotationAxisMesh.Draw(ref renderContext, isYAxis ? _materialAxisFocus : _materialAxisY, ref m1); // Z axis Matrix.RotationX(-Mathf.PiOverTwo, out m2); Matrix.Multiply(ref m2, ref m1, out m3); - circleMesh.Draw(ref renderContext, isZAxis ? _materialAxisFocus : _materialAxisZ, ref m3); + rotationAxisMesh.Draw(ref renderContext, isZAxis ? _materialAxisFocus : _materialAxisZ, ref m3); // Center box - Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m3); - Matrix.Multiply(ref m3, ref world, out m1); - Matrix.Scaling(1.0f, out m2); + Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m2); Matrix.Multiply(ref m2, ref m1, out m3); - boxMesh.Draw(ref renderContext, isCenter ? _materialWireFocus : _materialWire, ref m3); + sphereMesh.Draw(ref renderContext, isCenter ? _materialAxisFocus : _materialSphere, ref m3); break; } case Mode.Scale: { - if (!_modelScaleAxis || !_modelScaleAxis.IsLoaded || !_modelBox || !_modelBox.IsLoaded) + if (!_modelScaleAxis || !_modelScaleAxis.IsLoaded || !_modelCube || !_modelCube.IsLoaded || !_modelSphere || !_modelSphere.IsLoaded) break; + var scaleAxisMesh = _modelScaleAxis.LODs[0].Meshes[0]; + cubeMesh = _modelCube.LODs[0].Meshes[0]; + sphereMesh = _modelSphere.LODs[0].Meshes[0]; Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m3); Matrix.Multiply(ref m3, ref world, out m1); mx1 = m1; mx1.M41 -= 0.05f; - var axisMesh = _modelScaleAxis.LODs[0].Meshes[0]; - var boxMesh = _modelBox.LODs[0].Meshes[0]; - // X axis Matrix.RotationY(-Mathf.PiOverTwo, out m2); Matrix.Multiply(ref m2, ref mx1, out m3); - axisMesh.Draw(ref renderContext, isXAxis ? _materialAxisFocus : _materialAxisX, ref m3); + scaleAxisMesh.Draw(ref renderContext, isXAxis ? _materialAxisFocus : _materialAxisX, ref m3); // Y axis Matrix.RotationX(Mathf.PiOverTwo, out m2); Matrix.Multiply(ref m2, ref m1, out m3); - axisMesh.Draw(ref renderContext, isYAxis ? _materialAxisFocus : _materialAxisY, ref m3); + scaleAxisMesh.Draw(ref renderContext, isYAxis ? _materialAxisFocus : _materialAxisY, ref m3); // Z axis Matrix.RotationX(Mathf.Pi, out m2); Matrix.Multiply(ref m2, ref m1, out m3); - axisMesh.Draw(ref renderContext, isZAxis ? _materialAxisFocus : _materialAxisZ, ref m3); + scaleAxisMesh.Draw(ref renderContext, isZAxis ? _materialAxisFocus : _materialAxisZ, ref m3); + + // XY plane + m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.RotationX(Mathf.PiOverTwo), new Vector3(boxSize * boxScale, boxSize * boxScale, 0.0f)); + Matrix.Multiply(ref m2, ref m1, out m3); + cubeMesh.Draw(ref renderContext, _activeAxis == Axis.XY ? _materialAxisFocus : _materialAxisX, ref m3); + + // ZX plane + m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.Identity, new Vector3(boxSize * boxScale, 0.0f, boxSize * boxScale)); + Matrix.Multiply(ref m2, ref m1, out m3); + cubeMesh.Draw(ref renderContext, _activeAxis == Axis.ZX ? _materialAxisFocus : _materialAxisZ, ref m3); + + // YZ plane + m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.RotationZ(Mathf.PiOverTwo), new Vector3(0.0f, boxSize * boxScale, boxSize * boxScale)); + Matrix.Multiply(ref m2, ref m1, out m3); + cubeMesh.Draw(ref renderContext, _activeAxis == Axis.YZ ? _materialAxisFocus : _materialAxisY, ref m3); // Center box - Matrix.Scaling(10.0f, out m2); + Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m2); Matrix.Multiply(ref m2, ref m1, out m3); - boxMesh.Draw(ref renderContext, isCenter ? _materialWireFocus : _materialWire, ref m3); + sphereMesh.Draw(ref renderContext, isCenter ? _materialAxisFocus : _materialSphere, ref m3); break; } diff --git a/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs b/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs index 513178f40..86c0a6afe 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs @@ -102,9 +102,15 @@ namespace FlaxEditor.Gizmo closestIntersection = intersection; } + /*// Center + if (CenterBoxRaw.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + { + _activeAxis = Axis.Center; + closestIntersection = intersection; + }*/ + break; } - case Mode.Rotate: { // Circles @@ -124,41 +130,53 @@ namespace FlaxEditor.Gizmo closestIntersection = intersection; } - // Center - /*if (CenterSphere.Intersects(ref ray, out intersection) && intersection < closestintersection) - { - _activeAxis = Axis.Center; - closestintersection = intersection; - }*/ - break; } - case Mode.Scale: { - // Spheres collision - if (ScaleXSphere.Intersects(ref ray, out intersection) && intersection < closestIntersection) + // Boxes collision + if (XAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.X; closestIntersection = intersection; } - if (ScaleYSphere.Intersects(ref ray, out intersection) && intersection < closestIntersection) + if (YAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.Y; closestIntersection = intersection; } - if (ScaleZSphere.Intersects(ref ray, out intersection) && intersection < closestIntersection) + if (ZAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.Z; closestIntersection = intersection; } - // Center - if (CenterBox.Intersects(ref ray, out intersection) && intersection < closestIntersection) + // Quad planes collision + if (closestIntersection >= float.MaxValue) + closestIntersection = float.MinValue; + + if (XYBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + { + _activeAxis = Axis.XY; + closestIntersection = intersection; + } + if (XZBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + { + _activeAxis = Axis.ZX; + closestIntersection = intersection; + } + if (YZBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + { + _activeAxis = Axis.YZ; + closestIntersection = intersection; + } + + /*// Center + if (CenterBoxRaw.Intersects(ref localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.Center; closestIntersection = intersection; - } + }*/ break; } diff --git a/Source/Editor/Gizmo/TransformGizmoBase.Settings.cs b/Source/Editor/Gizmo/TransformGizmoBase.Settings.cs index ec9423475..8415beac3 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.Settings.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.Settings.cs @@ -7,56 +7,53 @@ namespace FlaxEditor.Gizmo { public partial class TransformGizmoBase { - private const float GizmoScaleFactor = 18; - private const float LineLength = 3.0f; - private const float LineOffset = 1.0f; - private const float MultiAxisThickness = 0.05f; - private const float SingleAxisThickness = 0.3f; - private const float ScaleSpheresRadius = 0.7f; - private const float CenterBoxSize = 0.8f; - private const float CenterSphereRadius = 0.1f; - private const float HalfLineOffset = LineOffset / 2; + /// + /// Scale of the gizmo itself + /// + private const float GizmoScaleFactor = 24; - private readonly Vector3[] _translationLineVertices = - { - // -- X Axis -- // index 0 - 5 - new Vector3(HalfLineOffset, 0, 0), - new Vector3(LineLength, 0, 0), - new Vector3(LineOffset, 0, 0), - new Vector3(LineOffset, LineOffset, 0), - new Vector3(LineOffset, 0, 0), - new Vector3(LineOffset, 0, LineOffset), + /// + /// The length of each axis (outwards) + /// + private const float AxisLength = 3.5f; - // -- Y Axis -- // index 6 - 11 - new Vector3(0, HalfLineOffset, 0), - new Vector3(0, LineLength, 0), - new Vector3(0, LineOffset, 0), - new Vector3(LineOffset, LineOffset, 0), - new Vector3(0, LineOffset, 0), - new Vector3(0, LineOffset, LineOffset), + /// + /// Offset to move axis away from center + /// + private const float AxisOffset = 0.8f; - // -- Z Axis -- // index 12 - 17 - new Vector3(0, 0, HalfLineOffset), - new Vector3(0, 0, LineLength), - new Vector3(0, 0, LineOffset), - new Vector3(LineOffset, 0, LineOffset), - new Vector3(0, 0, LineOffset), - new Vector3(0, LineOffset, LineOffset) - }; + /// + /// How thick the axis should be + /// + private const float AxisThickness = 0.3f; - private BoundingBox XAxisBox = new BoundingBox(new Vector3(LineOffset, -SingleAxisThickness, -SingleAxisThickness), new Vector3(LineOffset + LineLength, SingleAxisThickness, SingleAxisThickness)); - private BoundingBox YAxisBox = new BoundingBox(new Vector3(-SingleAxisThickness, LineOffset, -SingleAxisThickness), new Vector3(SingleAxisThickness, LineOffset + LineLength, SingleAxisThickness)); - private BoundingBox ZAxisBox = new BoundingBox(new Vector3(-SingleAxisThickness, -SingleAxisThickness, LineOffset), new Vector3(SingleAxisThickness, SingleAxisThickness, LineOffset + LineLength)); - private BoundingBox XZBox = new BoundingBox(Vector3.Zero, new Vector3(LineOffset, MultiAxisThickness, LineOffset)); - private BoundingBox XYBox = new BoundingBox(Vector3.Zero, new Vector3(LineOffset, LineOffset, MultiAxisThickness)); - private BoundingBox YZBox = new BoundingBox(Vector3.Zero, new Vector3(MultiAxisThickness, LineOffset, LineOffset)); - private BoundingBox CenterBoxRaw = new BoundingBox(new Vector3(-0.5f * CenterBoxSize), new Vector3(0.5f * CenterBoxSize)); - private float RotateRadiusRaw = 4.0f; + /// + /// Center box scale + /// + private const float CenterBoxScale = 0.8f; - private BoundingSphere ScaleXSphere => new BoundingSphere(Vector3.Transform(_translationLineVertices[1], _gizmoWorld), ScaleSpheresRadius * _screenScale); - private BoundingSphere ScaleYSphere => new BoundingSphere(Vector3.Transform(_translationLineVertices[7], _gizmoWorld), ScaleSpheresRadius * _screenScale); - private BoundingSphere ScaleZSphere => new BoundingSphere(Vector3.Transform(_translationLineVertices[13], _gizmoWorld), ScaleSpheresRadius * _screenScale); + /// + /// The inner minimum of the multiscale + /// + private const float InnerExtend = AxisOffset + 0.5f; + + /// + /// The outer maximum of the multiscale + /// + private const float OuterExtend = AxisOffset * 3.5f; + + // Cube with the size AxisThickness, then moves it along the axis (AxisThickness) and finally makes it really long (AxisLength) + private BoundingBox XAxisBox = new BoundingBox(new Vector3(-AxisThickness), new Vector3(AxisThickness)).MakeOffsetted(AxisOffset * Vector3.UnitX).Merge(AxisLength * Vector3.UnitX); + private BoundingBox YAxisBox = new BoundingBox(new Vector3(-AxisThickness), new Vector3(AxisThickness)).MakeOffsetted(AxisOffset * Vector3.UnitY).Merge(AxisLength * Vector3.UnitY); + private BoundingBox ZAxisBox = new BoundingBox(new Vector3(-AxisThickness), new Vector3(AxisThickness)).MakeOffsetted(AxisOffset * Vector3.UnitZ).Merge(AxisLength * Vector3.UnitZ); + + private BoundingBox XZBox = new BoundingBox(new Vector3(InnerExtend, 0, InnerExtend), new Vector3(OuterExtend, 0, OuterExtend)); + private BoundingBox XYBox = new BoundingBox(new Vector3(InnerExtend, InnerExtend, 0), new Vector3(OuterExtend, OuterExtend, 0)); + private BoundingBox YZBox = new BoundingBox(new Vector3(0, InnerExtend, InnerExtend), new Vector3(0, OuterExtend, OuterExtend)); + + private BoundingBox CenterBoxRaw = new BoundingBox(new Vector3(-0.5f * CenterBoxScale), new Vector3(0.5f * CenterBoxScale)); private OrientedBoundingBox CenterBox => new OrientedBoundingBox(CenterBoxRaw) * _gizmoWorld; + private const float RotateRadiusRaw = 4.0f; private Mode _activeMode = Mode.Translate; private Axis _activeAxis = Axis.None; diff --git a/Source/Engine/Core/Math/BoundingBox.cs b/Source/Engine/Core/Math/BoundingBox.cs index da3a2c863..51225d775 100644 --- a/Source/Engine/Core/Math/BoundingBox.cs +++ b/Source/Engine/Core/Math/BoundingBox.cs @@ -419,6 +419,31 @@ namespace FlaxEngine return box; } + /// + /// Constructs a that is as large as the box and point. + /// + /// The box to merge. + /// The point to merge. + /// When the method completes, contains the newly constructed bounding box. + public static void Merge(ref BoundingBox value1, ref Vector3 value2, out BoundingBox result) + { + Vector3.Min(ref value1.Minimum, ref value2, out result.Minimum); + Vector3.Max(ref value1.Maximum, ref value2, out result.Maximum); + } + + /// + /// Constructs a that is as large as the box and point. + /// + /// The point to merge. + /// The newly constructed bounding box. + public BoundingBox Merge(Vector3 value2) + { + BoundingBox result; + Vector3.Min(ref Minimum, ref value2, out result.Minimum); + Vector3.Max(ref Maximum, ref value2, out result.Maximum); + return result; + } + /// /// Transforms bounding box using the given transformation matrix. /// @@ -498,6 +523,19 @@ namespace FlaxEngine result = new BoundingBox(min, max); } + /// + /// Creates the bounding box that is offseted by the given vector. Adds the offset value to minimum and maximum points. + /// + /// The bounds offset. + /// The offsetted bounds. + public BoundingBox MakeOffsetted(Vector3 offset) + { + BoundingBox result; + Vector3.Add(ref Minimum, ref offset, out result.Minimum); + Vector3.Add(ref Maximum, ref offset, out result.Maximum); + return result; + } + /// /// Creates the bounding box that is offseted by the given vector. Adds the offset value to minimum and maximum points. /// diff --git a/Source/FlaxEngine.Gen.cs b/Source/FlaxEngine.Gen.cs index 8b5988063..c068b93b8 100644 --- a/Source/FlaxEngine.Gen.cs +++ b/Source/FlaxEngine.Gen.cs @@ -13,5 +13,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("b8442186-4a70-7c85-704a-857c68060f38")] -[assembly: AssemblyVersion("1.5.6336")] -[assembly: AssemblyFileVersion("1.5.6336")] +[assembly: AssemblyVersion("1.5.6337")] +[assembly: AssemblyFileVersion("1.5.6337")] diff --git a/Source/FlaxEngine.Gen.h b/Source/FlaxEngine.Gen.h index 35a86fa53..897384d9c 100644 --- a/Source/FlaxEngine.Gen.h +++ b/Source/FlaxEngine.Gen.h @@ -3,11 +3,11 @@ #pragma once #define FLAXENGINE_NAME "FlaxEngine" -#define FLAXENGINE_VERSION Version(1, 5, 6336) -#define FLAXENGINE_VERSION_TEXT "1.5.6336" +#define FLAXENGINE_VERSION Version(1, 5, 6337) +#define FLAXENGINE_VERSION_TEXT "1.5.6337" #define FLAXENGINE_VERSION_MAJOR 1 #define FLAXENGINE_VERSION_MINOR 5 -#define FLAXENGINE_VERSION_BUILD 6336 +#define FLAXENGINE_VERSION_BUILD 6337 #define FLAXENGINE_COMPANY "Flax" #define FLAXENGINE_COPYRIGHT "Copyright (c) 2012-2023 Wojciech Figat. All rights reserved."