makes more easy select a spline point or spline tangent

This commit is contained in:
Ruan Lucas
2023-07-31 22:05:13 -04:00
parent b80682c97e
commit 2b7b80ad38
2 changed files with 10 additions and 8 deletions

View File

@@ -706,9 +706,10 @@ namespace FlaxEditor.CustomEditors.Dedicated
// auto smooth tangent if's linear
if (keyframe.TangentIn.Translation.Length == 0)
{
var smoothRange = SplineNode.NodeSizeByDistance(spline.GetSplineTangent(index, false).Translation, 10f);
var previousKeyframe = spline.GetSplineKeyframe(index - 1);
var tangentDirection = keyframe.Value.WorldToLocalVector(previousKeyframe.Value.Translation - keyframe.Value.Translation);
tangentDirection = tangentDirection.Normalized * 100f;
tangentDirection = tangentDirection.Normalized * smoothRange;
keyframe.TangentIn.Translation = tangentDirection;
}
@@ -724,9 +725,10 @@ namespace FlaxEditor.CustomEditors.Dedicated
// auto smooth tangent if's linear
if (keyframe.TangentOut.Translation.Length == 0)
{
var smoothRange = SplineNode.NodeSizeByDistance(spline.GetSplineTangent(index, false).Translation, 10f);
var nextKeyframe = spline.GetSplineKeyframe(index + 1);
var tangentDirection = keyframe.Value.WorldToLocalVector(nextKeyframe.Value.Translation - keyframe.Value.Translation);
tangentDirection = tangentDirection.Normalized * 100f;
tangentDirection = tangentDirection.Normalized * smoothRange;
keyframe.TangentOut.Translation = tangentDirection;
}
@@ -744,10 +746,11 @@ namespace FlaxEditor.CustomEditors.Dedicated
var isLastKeyframe = index >= spline.SplinePointsCount - 1;
var isFirstKeyframe = index <= 0;
var smoothRange = SplineNode.NodeSizeByDistance(spline.GetSplinePoint(index), 10f);
// force smooth it's linear point
if (tangentInSize == 0f) tangentInSize = 100;
if (tangentOutSize == 0f) tangentOutSize = 100;
if (tangentInSize == 0f) tangentInSize = smoothRange;
if (tangentOutSize == 0f) tangentOutSize = smoothRange;
// try get next / last keyframe
var nextKeyframe = !isLastKeyframe ? spline.GetSplineKeyframe(index + 1) : keyframe;

View File

@@ -286,8 +286,8 @@ namespace FlaxEditor.SceneGraph.Actors
}
}
private const float PointNodeSize = 2;
private const float TangentNodeSize = 1.6f;
private const float PointNodeSize = 1.5f;
private const float TangentNodeSize = 1.0f;
/// <inheritdoc />
public SplineNode(Actor actor)
@@ -408,14 +408,13 @@ namespace FlaxEditor.SceneGraph.Actors
}
}
private static float NodeSizeByDistance(Vector3 nodePosition, float nodeSize)
internal 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 />
public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal)
{