diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 42077a8f2..f4e2097a1 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -872,6 +872,8 @@ void DebugDraw::DrawLine(const Vector3& start, const Vector3& end, const Color& void DebugDraw::DrawLines(const Span& 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& lines, const Matrix& transform, c } } +void DebugDraw::DrawLines(const Array& lines, const Matrix& transform, const Color& color, float duration, bool depthTest) +{ + DrawLines(Span(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& 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& vertices, const Color& color void DebugDraw::DrawTriangles(const Span& vertices, const Span& 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& vertices, const Span& } } +void DebugDraw::DrawTriangles(const Span& vertices, const Span& 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* 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& vertices, const Array& indices, const Color& color, float duration, bool depthTest) { DrawTriangles(Span(vertices.Get(), vertices.Count()), Span(indices.Get(), indices.Count()), color, duration, depthTest); } +void DebugDraw::DrawTriangles(const Array& vertices, const Array& indices, const Matrix& transform, const Color& color, float duration, bool depthTest) +{ + DrawTriangles(Span(vertices.Get(), vertices.Count()), Span(indices.Get(), indices.Count()), transform, color, duration, depthTest); +} + void DebugDraw::DrawWireTriangles(const Span& 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& vertices, const Color& c void DebugDraw::DrawWireTriangles(const Span& vertices, const Span& indices, const Color& color, float duration, bool depthTest) { - ASSERT(indices.Length() % 3 == 0); + CHECK(indices.Length() % 3 == 0); DebugTriangle t; t.Color = Color32(color); diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index 41f03adc7..520b688ec 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -90,6 +90,16 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); /// If set to true depth test will be performed, otherwise depth will be ignored. API_FUNCTION() static void DrawLines(const Span& lines, const Matrix& transform, const Color& color, float duration = 0.0f, bool depthTest = true); + /// + /// Draws the lines. Line positions are located one after another (e.g. l0.start, l0.end, l1.start, l1.end,...). + /// + /// The list of vertices for lines (must have multiple of 2 elements). + /// The custom matrix used to transform all line vertices. + /// The color. + /// The duration (in seconds). Use 0 to draw it only once. + /// If set to true depth test will be performed, otherwise depth will be ignored. + static void DrawLines(const Array& lines, const Matrix& transform, const Color& color, float duration = 0.0f, bool depthTest = true); + /// /// Draws a Bezier curve. /// @@ -163,6 +173,17 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); /// If set to true depth test will be performed, otherwise depth will be ignored. API_FUNCTION() static void DrawTriangles(const Span& vertices, const Span& indices, const Color& color, float duration = 0.0f, bool depthTest = true); + /// + /// Draws the triangles using the given index buffer. + /// + /// The triangle vertices list. + /// The triangle indices list (must have multiple of 3 elements). + /// The custom matrix used to transform all line vertices. + /// The color. + /// The duration (in seconds). Use 0 to draw it only once. + /// If set to true depth test will be performed, otherwise depth will be ignored. + API_FUNCTION() static void DrawTriangles(const Span& vertices, const Span& indices, const Matrix& transform, const Color& color, float duration = 0.0f, bool depthTest = true); + /// /// Draws the triangles using the given index buffer. /// @@ -173,6 +194,17 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); /// If set to true depth test will be performed, otherwise depth will be ignored. static void DrawTriangles(const Array& vertices, const Array& indices, const Color& color, float duration = 0.0f, bool depthTest = true); + /// + /// Draws the triangles using the given index buffer. + /// + /// The triangle vertices list. + /// The triangle indices list (must have multiple of 3 elements). + /// The custom matrix used to transform all line vertices. + /// The color. + /// The duration (in seconds). Use 0 to draw it only once. + /// If set to true depth test will be performed, otherwise depth will be ignored. + static void DrawTriangles(const Array& vertices, const Array& indices, const Matrix& transform, const Color& color, float duration = 0.0f, bool depthTest = true); + /// /// Draws the wireframe triangles. ///