Fix selected spline points to be drawn relative to the view for greater readability

#2595
This commit is contained in:
Wojtek Figat
2025-01-31 21:01:26 +01:00
parent 42fc62eb68
commit 24f3dfe264
3 changed files with 21 additions and 6 deletions

View File

@@ -741,6 +741,11 @@ void DebugDraw::SetContext(void* context)
#endif
Vector3 DebugDraw::GetViewPos()
{
return Context->LastViewPos;
}
void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTextureView* depthBuffer, bool enableDepthTest)
{
PROFILE_GPU_CPU("Debug Draw");

View File

@@ -39,7 +39,7 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
#if USE_EDITOR
/// <summary>
/// Allocates the context for Debug Drawing. Can be use to redirect debug shapes collecting to a separate container (instead of global state).
/// Allocates the context for Debug Drawing. Can be used to redirect debug shapes collecting to a separate container (instead of global state).
/// </summary>
/// <returns>The context object. Release it wil FreeContext. Returns null if failed.</returns>
API_FUNCTION() static void* AllocateContext();
@@ -64,6 +64,9 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
API_FUNCTION() static void SetContext(void* context);
#endif
// Gets the last view position when rendering the current context. Can be sued for custom culling or LODing when drawing more complex shapes.
static Vector3 GetViewPos();
/// <summary>
/// Draws the collected debug shapes to the output.
/// </summary>
@@ -717,7 +720,7 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
API_FUNCTION() static void Clear(void* context = nullptr);
};
#define DEBUG_DRAW_AXIS_FROM_DIRECTION(origin, direction, size, duration, depthTest) DebugDraw::DrawAxisFromDirection(origin, direction, size, duration, depthTest);
#define DEBUG_DRAW_AXIS_FROM_DIRECTION(origin, direction, size, duration, depthTest) DebugDraw::DrawAxisFromDirection(origin, direction, size, duration, depthTest);
#define DEBUG_DRAW_DIRECTION(origin, direction, color, duration, depthTest) DebugDraw::DrawDirection(origin, direction, color, duration, depthTest);
#define DEBUG_DRAW_RAY(origin, direction, color, length, duration, depthTest) DebugDraw::DrawRay(origin, direction, color, length, duration, depthTest);
#define DEBUG_DRAW_RAY(ray, color, length, duration, depthTest) DebugDraw::DrawRay(ray, color, length, duration, depthTest);

View File

@@ -490,19 +490,26 @@ void Spline::SetKeyframes(MArray* data, int32 keySize)
namespace
{
void DrawSpline(Spline* spline, const Color& color, const Transform& transform, bool depthTest)
FORCE_INLINE float NodeSizeByDistance(const Vector3& nodePosition, bool scaleByDistance)
{
if (scaleByDistance)
return (float)(Vector3::Distance(DebugDraw::GetViewPos(), nodePosition) / 100);
return 5.0f;
}
void DrawSpline(Spline* spline, const Color& color, const Transform& transform, bool depthTest, bool scaleByDistance = false)
{
const int32 count = spline->Curve.GetKeyframes().Count();
if (count == 0)
return;
Spline::Keyframe* prev = spline->Curve.GetKeyframes().Get();
Vector3 prevPos = transform.LocalToWorld(prev->Value.Translation);
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(prevPos, 5.0f), color, 0.0f, depthTest);
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(prevPos, NodeSizeByDistance(prevPos, scaleByDistance)), color, 0.0f, depthTest);
for (int32 i = 1; i < count; i++)
{
Spline::Keyframe* next = prev + 1;
Vector3 nextPos = transform.LocalToWorld(next->Value.Translation);
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(nextPos, 5.0f), color, 0.0f, depthTest);
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(nextPos, NodeSizeByDistance(nextPos, scaleByDistance)), color, 0.0f, depthTest);
const float d = (next->Time - prev->Time) / 3.0f;
DEBUG_DRAW_BEZIER(prevPos, prevPos + prev->TangentOut.Translation * d, nextPos + next->TangentIn.Translation * d, nextPos, color, 0.0f, depthTest);
prev = next;
@@ -521,7 +528,7 @@ void Spline::OnDebugDraw()
void Spline::OnDebugDrawSelected()
{
DrawSpline(this, Color::White, _transform, false);
DrawSpline(this, Color::White, _transform, false, true);
// Base
Actor::OnDebugDrawSelected();