Add more helper methods for batched debug shapes drawing

This commit is contained in:
Wojtek Figat
2021-07-14 13:40:58 +02:00
parent 4fc55f4849
commit 151b478a97
2 changed files with 72 additions and 4 deletions

View File

@@ -872,6 +872,8 @@ void DebugDraw::DrawLine(const Vector3& start, const Vector3& end, const Color&
void DebugDraw::DrawLines(const Span<Vector3>& lines, const Matrix& transform, const Color& color, float duration, bool depthTest)
{
if (lines.Length() == 0)
return;
if (lines.Length() % 2 != 0)
{
DebugLog::ThrowException("Cannot draw debug lines with uneven amount of items in array");
@@ -906,6 +908,11 @@ void DebugDraw::DrawLines(const Span<Vector3>& lines, const Matrix& transform, c
}
}
void DebugDraw::DrawLines(const Array<Vector3>& lines, const Matrix& transform, const Color& color, float duration, bool depthTest)
{
DrawLines(Span<Vector3>(lines.Get(), lines.Count()), transform, color, duration, depthTest);
}
void DebugDraw::DrawBezier(const Vector3& p1, const Vector3& p2, const Vector3& p3, const Vector3& p4, const Color& color, float duration, bool depthTest)
{
// Find amount of segments to use
@@ -1155,7 +1162,7 @@ void DebugDraw::DrawTriangle(const Vector3& v0, const Vector3& v1, const Vector3
void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Color& color, float duration, bool depthTest)
{
ASSERT(vertices.Length() % 3 == 0);
CHECK(vertices.Length() % 3 == 0);
DebugTriangle t;
t.Color = Color32(color);
@@ -1184,7 +1191,7 @@ void DebugDraw::DrawTriangles(const Array<Vector3>& vertices, const Color& color
void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Color& color, float duration, bool depthTest)
{
ASSERT(indices.Length() % 3 == 0);
CHECK(indices.Length() % 3 == 0);
DebugTriangle t;
t.Color = Color32(color);
@@ -1206,14 +1213,43 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>&
}
}
void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Matrix& transform, const Color& color, float duration, bool depthTest)
{
CHECK(indices.Length() % 3 == 0);
DebugTriangle t;
t.Color = Color32(color);
t.TimeLeft = duration;
Array<DebugTriangle>* list;
if (depthTest)
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultTriangles : &Context->DebugDrawDepthTest.OneFrameTriangles;
else
list = duration > 0 ? &Context->DebugDrawDefault.DefaultTriangles : &Context->DebugDrawDefault.OneFrameTriangles;
list->EnsureCapacity(list->Count() + indices.Length() / 3);
for (int32 i = 0; i < indices.Length();)
{
Vector3::Transform(vertices[indices[i++]], transform, t.V0);
Vector3::Transform(vertices[indices[i++]], transform, t.V1);
Vector3::Transform(vertices[indices[i++]], transform, t.V2);
list->Add(t);
}
}
void DebugDraw::DrawTriangles(const Array<Vector3>& vertices, const Array<int32, HeapAllocation>& indices, const Color& color, float duration, bool depthTest)
{
DrawTriangles(Span<Vector3>(vertices.Get(), vertices.Count()), Span<int32>(indices.Get(), indices.Count()), color, duration, depthTest);
}
void DebugDraw::DrawTriangles(const Array<Vector3>& vertices, const Array<int32, HeapAllocation>& indices, const Matrix& transform, const Color& color, float duration, bool depthTest)
{
DrawTriangles(Span<Vector3>(vertices.Get(), vertices.Count()), Span<int32>(indices.Get(), indices.Count()), transform, color, duration, depthTest);
}
void DebugDraw::DrawWireTriangles(const Span<Vector3>& vertices, const Color& color, float duration, bool depthTest)
{
ASSERT(vertices.Length() % 3 == 0);
CHECK(vertices.Length() % 3 == 0);
DebugTriangle t;
t.Color = Color32(color);
@@ -1242,7 +1278,7 @@ void DebugDraw::DrawWireTriangles(const Array<Vector3>& vertices, const Color& c
void DebugDraw::DrawWireTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Color& color, float duration, bool depthTest)
{
ASSERT(indices.Length() % 3 == 0);
CHECK(indices.Length() % 3 == 0);
DebugTriangle t;
t.Color = Color32(color);

View File

@@ -90,6 +90,16 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
API_FUNCTION() static void DrawLines(const Span<Vector3>& lines, const Matrix& transform, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the lines. Line positions are located one after another (e.g. l0.start, l0.end, l1.start, l1.end,...).
/// </summary>
/// <param name="lines">The list of vertices for lines (must have multiple of 2 elements).</param>
/// <param name="transform">The custom matrix used to transform all line vertices.</param>
/// <param name="color">The color.</param>
/// <param name="duration">The duration (in seconds). Use 0 to draw it only once.</param>
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
static void DrawLines(const Array<Vector3, HeapAllocation>& lines, const Matrix& transform, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws a Bezier curve.
/// </summary>
@@ -163,6 +173,17 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
API_FUNCTION() static void DrawTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the triangles using the given index buffer.
/// </summary>
/// <param name="vertices">The triangle vertices list.</param>
/// <param name="indices">The triangle indices list (must have multiple of 3 elements).</param>
/// <param name="transform">The custom matrix used to transform all line vertices.</param>
/// <param name="color">The color.</param>
/// <param name="duration">The duration (in seconds). Use 0 to draw it only once.</param>
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
API_FUNCTION() static void DrawTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Matrix& transform, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the triangles using the given index buffer.
/// </summary>
@@ -173,6 +194,17 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
static void DrawTriangles(const Array<Vector3, HeapAllocation>& vertices, const Array<int32, HeapAllocation>& indices, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the triangles using the given index buffer.
/// </summary>
/// <param name="vertices">The triangle vertices list.</param>
/// <param name="indices">The triangle indices list (must have multiple of 3 elements).</param>
/// <param name="transform">The custom matrix used to transform all line vertices.</param>
/// <param name="color">The color.</param>
/// <param name="duration">The duration (in seconds). Use 0 to draw it only once.</param>
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
static void DrawTriangles(const Array<Vector3, HeapAllocation>& vertices, const Array<int32, HeapAllocation>& indices, const Matrix& transform, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the wireframe triangles.
/// </summary>