set spline points / tangents size by camera distance

This commit is contained in:
Ruan Lucas
2023-07-31 19:21:26 -04:00
parent 84bed5b1c9
commit b80682c97e

View File

@@ -12,6 +12,7 @@ using FlaxEditor.Modules;
using FlaxEngine; using FlaxEngine;
using FlaxEngine.Json; using FlaxEngine.Json;
using Object = FlaxEngine.Object; using Object = FlaxEngine.Object;
using FlaxEditor.Viewport.Cameras;
namespace FlaxEditor.SceneGraph.Actors 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) public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal)
{ {
normal = -ray.Ray.Direction;
var actor = (Spline)_node.Actor; var actor = (Spline)_node.Actor;
var pos = actor.GetSplinePoint(Index); var pos = actor.GetSplinePoint(Index);
normal = -ray.Ray.Direction; var nodeSize = NodeSizeByDistance(Transform.Translation, PointNodeSize);
return new BoundingSphere(pos, 7.0f).Intersects(ref ray.Ray, out distance); return new BoundingSphere(pos, nodeSize).Intersects(ref ray.Ray, out distance);
} }
public override void OnDebugDraw(ViewportDebugDrawData data) public override void OnDebugDraw(ViewportDebugDrawData data)
@@ -179,23 +181,26 @@ namespace FlaxEditor.SceneGraph.Actors
var pos = actor.GetSplinePoint(Index); var pos = actor.GetSplinePoint(Index);
var tangentIn = actor.GetSplineTangent(Index, true).Translation; var tangentIn = actor.GetSplineTangent(Index, true).Translation;
var tangentOut = actor.GetSplineTangent(Index, false).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 // Draw spline path
ParentNode.OnDebugDraw(data); ParentNode.OnDebugDraw(data);
// Draw selected point highlight // 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 // Draw tangent points
if (tangentIn != pos) if (tangentIn != pos)
{ {
DebugDraw.DrawLine(pos, tangentIn, Color.Blue.AlphaMultiplied(0.6f), 0, false); 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) if (tangentOut != pos)
{ {
DebugDraw.DrawLine(pos, tangentOut, Color.Red.AlphaMultiplied(0.6f), 0, false); 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) public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal)
{ {
normal = -ray.Ray.Direction;
var actor = (Spline)_node.Actor; var actor = (Spline)_node.Actor;
var pos = actor.GetSplineTangent(_index, _isIn).Translation; var pos = actor.GetSplineTangent(_index, _isIn).Translation;
normal = -ray.Ray.Direction; var tangentSize = NodeSizeByDistance(Transform.Translation, TangentNodeSize);
return new BoundingSphere(pos, 7.0f).Intersects(ref ray.Ray, out distance); return new BoundingSphere(pos, tangentSize).Intersects(ref ray.Ray, out distance);
} }
public override void OnDebugDraw(ViewportDebugDrawData data) public override void OnDebugDraw(ViewportDebugDrawData data)
@@ -263,7 +269,8 @@ namespace FlaxEditor.SceneGraph.Actors
// Draw selected tangent highlight // Draw selected tangent highlight
var actor = (Spline)_node.Actor; var actor = (Spline)_node.Actor;
var pos = actor.GetSplineTangent(_index, _isIn).Translation; 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) 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;
/// <inheritdoc /> /// <inheritdoc />
public SplineNode(Actor actor) public SplineNode(Actor actor)
: base(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;
}
/// <inheritdoc /> /// <inheritdoc />
public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal) public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal)
{ {