diff --git a/Source/Editor/SceneGraph/Actors/SplineNode.cs b/Source/Editor/SceneGraph/Actors/SplineNode.cs index 3ba1d14c3..75b86950c 100644 --- a/Source/Editor/SceneGraph/Actors/SplineNode.cs +++ b/Source/Editor/SceneGraph/Actors/SplineNode.cs @@ -12,6 +12,7 @@ using FlaxEditor.Modules; using FlaxEngine; using FlaxEngine.Json; using Object = FlaxEngine.Object; +using FlaxEditor.Viewport.Cameras; namespace FlaxEditor.SceneGraph.Actors { @@ -167,10 +168,11 @@ namespace FlaxEditor.SceneGraph.Actors public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal) { + normal = -ray.Ray.Direction; var actor = (Spline)_node.Actor; var pos = actor.GetSplinePoint(Index); - normal = -ray.Ray.Direction; - return new BoundingSphere(pos, 7.0f).Intersects(ref ray.Ray, out distance); + var nodeSize = NodeSizeByDistance(Transform.Translation, PointNodeSize); + return new BoundingSphere(pos, nodeSize).Intersects(ref ray.Ray, out distance); } public override void OnDebugDraw(ViewportDebugDrawData data) @@ -179,23 +181,26 @@ namespace FlaxEditor.SceneGraph.Actors var pos = actor.GetSplinePoint(Index); var tangentIn = actor.GetSplineTangent(Index, true).Translation; var tangentOut = actor.GetSplineTangent(Index, false).Translation; + var pointSize = NodeSizeByDistance(pos, PointNodeSize); + var tangentInSize = NodeSizeByDistance(tangentIn, TangentNodeSize); + var tangentOutSize = NodeSizeByDistance(tangentOut, TangentNodeSize); // Draw spline path ParentNode.OnDebugDraw(data); // Draw selected point highlight - DebugDraw.DrawSphere(new BoundingSphere(pos, 5.0f), Color.Yellow, 0, false); + DebugDraw.DrawSphere(new BoundingSphere(pos, pointSize), Color.Yellow, 0, false); // Draw tangent points if (tangentIn != pos) { DebugDraw.DrawLine(pos, tangentIn, Color.Blue.AlphaMultiplied(0.6f), 0, false); - DebugDraw.DrawWireSphere(new BoundingSphere(tangentIn, 4.0f), Color.Blue, 0, false); + DebugDraw.DrawWireSphere(new BoundingSphere(tangentIn, tangentInSize), Color.Blue, 0, false); } if (tangentOut != pos) { DebugDraw.DrawLine(pos, tangentOut, Color.Red.AlphaMultiplied(0.6f), 0, false); - DebugDraw.DrawWireSphere(new BoundingSphere(tangentOut, 4.0f), Color.Red, 0, false); + DebugDraw.DrawWireSphere(new BoundingSphere(tangentOut, tangentOutSize), Color.Red, 0, false); } } @@ -249,10 +254,11 @@ namespace FlaxEditor.SceneGraph.Actors public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal) { + normal = -ray.Ray.Direction; var actor = (Spline)_node.Actor; var pos = actor.GetSplineTangent(_index, _isIn).Translation; - normal = -ray.Ray.Direction; - return new BoundingSphere(pos, 7.0f).Intersects(ref ray.Ray, out distance); + var tangentSize = NodeSizeByDistance(Transform.Translation, TangentNodeSize); + return new BoundingSphere(pos, tangentSize).Intersects(ref ray.Ray, out distance); } public override void OnDebugDraw(ViewportDebugDrawData data) @@ -263,7 +269,8 @@ namespace FlaxEditor.SceneGraph.Actors // Draw selected tangent highlight var actor = (Spline)_node.Actor; var pos = actor.GetSplineTangent(_index, _isIn).Translation; - DebugDraw.DrawSphere(new BoundingSphere(pos, 5.0f), Color.YellowGreen, 0, false); + var tangentSize = NodeSizeByDistance(Transform.Translation, TangentNodeSize); + DebugDraw.DrawSphere(new BoundingSphere(pos, tangentSize), Color.YellowGreen, 0, false); } public override void OnContextMenu(ContextMenu contextMenu) @@ -279,6 +286,9 @@ namespace FlaxEditor.SceneGraph.Actors } } + private const float PointNodeSize = 2; + private const float TangentNodeSize = 1.6f; + /// public SplineNode(Actor actor) : base(actor) @@ -398,6 +408,14 @@ namespace FlaxEditor.SceneGraph.Actors } } + private static float NodeSizeByDistance(Vector3 nodePosition, float nodeSize) + { + var cameraTransform = Editor.Instance.Windows.EditWin.Viewport.ViewportCamera.Viewport.ViewTransform; + var distance = Vector3.Distance(cameraTransform.Translation, nodePosition) / 100; + return distance * nodeSize; + } + + /// public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal) {