diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs
index 9a9ae9d7d..bae4d31a8 100644
--- a/Source/Editor/Viewport/EditorViewport.cs
+++ b/Source/Editor/Viewport/EditorViewport.cs
@@ -1396,6 +1396,7 @@ namespace FlaxEditor.Viewport
new ViewModeOptions(ViewMode.MotionVectors, "Motion Vectors"),
new ViewModeOptions(ViewMode.LightmapUVsDensity, "Lightmap UVs Density"),
new ViewModeOptions(ViewMode.VertexColors, "Vertex Colors"),
+ new ViewModeOptions(ViewMode.PhysicsColliders, "Physics Colliders"),
};
private void WidgetCamSpeedShowHide(Control cm)
diff --git a/Source/Engine/Graphics/Enums.h b/Source/Engine/Graphics/Enums.h
index a5615ccfa..86b5e067d 100644
--- a/Source/Engine/Graphics/Enums.h
+++ b/Source/Engine/Graphics/Enums.h
@@ -797,6 +797,11 @@ API_ENUM() enum class ViewMode
/// Draw meshes vertex colors
///
VertexColors = 19,
+
+ ///
+ /// Draw physics colliders debug view
+ ///
+ PhysicsColliders = 20,
};
///
diff --git a/Source/Engine/Graphics/Textures/StreamingTexture.cpp b/Source/Engine/Graphics/Textures/StreamingTexture.cpp
index f5a2a2ed2..801b7a19b 100644
--- a/Source/Engine/Graphics/Textures/StreamingTexture.cpp
+++ b/Source/Engine/Graphics/Textures/StreamingTexture.cpp
@@ -361,7 +361,7 @@ protected:
if (!_streamingTexture->GetOwner()->GetMipDataCustomPitch(absoluteMipIndex, rowPitch, slicePitch))
texture->ComputePitch(_mipIndex, rowPitch, slicePitch);
_data.Link(data);
- ASSERT(data.Length() >= slicePitch * arraySize);
+ ASSERT(data.Length() >= (int32)slicePitch * arraySize);
// Update all array slices
const byte* dataSource = data.Get();
diff --git a/Source/Engine/Level/Scene/SceneRendering.cpp b/Source/Engine/Level/Scene/SceneRendering.cpp
index f9dc133d2..82c7a5020 100644
--- a/Source/Engine/Level/Scene/SceneRendering.cpp
+++ b/Source/Engine/Level/Scene/SceneRendering.cpp
@@ -371,7 +371,7 @@ void SceneRendering::Draw(RenderContext& renderContext)
if (view.Pass & DrawPass::GBuffer)
{
// Draw physics shapes
- if (view.Flags & ViewFlags::PhysicsDebug)
+ if (view.Flags & ViewFlags::PhysicsDebug || view.Mode == ViewMode::PhysicsColliders)
{
for (int32 i = 0; i < PhysicsDebug.Count(); i++)
{
diff --git a/Source/Engine/Physics/Colliders/BoxCollider.cpp b/Source/Engine/Physics/Colliders/BoxCollider.cpp
index 487059148..cdc431d86 100644
--- a/Source/Engine/Physics/Colliders/BoxCollider.cpp
+++ b/Source/Engine/Physics/Colliders/BoxCollider.cpp
@@ -25,11 +25,14 @@ void BoxCollider::SetSize(const Vector3& value)
#if USE_EDITOR
#include "Engine/Debug/DebugDraw.h"
+#include "Engine/Graphics/RenderView.h"
void BoxCollider::DrawPhysicsDebug(RenderView& view)
{
- const Color color = Color::GreenYellow;
- DEBUG_DRAW_WIRE_BOX(_bounds, color * 0.8f, 0, true);
+ if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
+ DebugDraw::DrawBox(_bounds, _staticActor ? Color::CornflowerBlue : Color::Orchid, 0, true);
+ else
+ DebugDraw::DrawWireBox(_bounds, Color::GreenYellow * 0.8f, 0, true);
}
void BoxCollider::OnDebugDraw()
diff --git a/Source/Engine/Physics/Colliders/CapsuleCollider.cpp b/Source/Engine/Physics/Colliders/CapsuleCollider.cpp
index d3bc4dc30..42ea9d492 100644
--- a/Source/Engine/Physics/Colliders/CapsuleCollider.cpp
+++ b/Source/Engine/Physics/Colliders/CapsuleCollider.cpp
@@ -37,6 +37,7 @@ void CapsuleCollider::SetHeight(const float value)
#if USE_EDITOR
#include "Engine/Debug/DebugDraw.h"
+#include "Engine/Graphics/RenderView.h"
void CapsuleCollider::DrawPhysicsDebug(RenderView& view)
{
@@ -46,7 +47,10 @@ void CapsuleCollider::DrawPhysicsDebug(RenderView& view)
const float minSize = 0.001f;
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
const float height = Math::Max(Math::Abs(_height) * scaling, minSize);
- DEBUG_DRAW_WIRE_TUBE(_transform.LocalToWorld(_center), rot, radius, height, Color::GreenYellow * 0.8f, 0, true);
+ if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
+ DebugDraw::DrawTube(_transform.LocalToWorld(_center), rot, radius, height, _staticActor ? Color::CornflowerBlue : Color::Orchid, 0, true);
+ else
+ DebugDraw::DrawWireTube(_transform.LocalToWorld(_center), rot, radius, height, Color::GreenYellow * 0.8f, 0, true);
}
void CapsuleCollider::OnDebugDrawSelected()
diff --git a/Source/Engine/Physics/Colliders/CharacterController.cpp b/Source/Engine/Physics/Colliders/CharacterController.cpp
index c5edb9bda..a2e8d868f 100644
--- a/Source/Engine/Physics/Colliders/CharacterController.cpp
+++ b/Source/Engine/Physics/Colliders/CharacterController.cpp
@@ -184,6 +184,7 @@ PxRigidDynamic* CharacterController::GetPhysXRigidActor() const
#if USE_EDITOR
#include "Engine/Debug/DebugDraw.h"
+#include "Engine/Graphics/RenderView.h"
void CharacterController::DrawPhysicsDebug(RenderView& view)
{
@@ -191,7 +192,10 @@ void CharacterController::DrawPhysicsDebug(RenderView& view)
const float minSize = 0.001f;
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
const float height = Math::Max(Math::Abs(_height) * scaling, minSize);
- DEBUG_DRAW_WIRE_TUBE(_transform.LocalToWorld(_center), Quaternion::Euler(90, 0, 0), radius, height, Color::GreenYellow * 0.8f, 0, true);
+ if (view.Mode == ViewMode::PhysicsColliders)
+ DebugDraw::DrawTube(_transform.LocalToWorld(_center), Quaternion::Euler(90, 0, 0), radius, height, Color::LightYellow, 0, true);
+ else
+ DebugDraw::DrawWireTube(_transform.LocalToWorld(_center), Quaternion::Euler(90, 0, 0), radius, height, Color::GreenYellow * 0.8f, 0, true);
}
void CharacterController::OnDebugDrawSelected()
diff --git a/Source/Engine/Physics/Colliders/MeshCollider.cpp b/Source/Engine/Physics/Colliders/MeshCollider.cpp
index 5ed8da92c..9e49e82b7 100644
--- a/Source/Engine/Physics/Colliders/MeshCollider.cpp
+++ b/Source/Engine/Physics/Colliders/MeshCollider.cpp
@@ -63,13 +63,23 @@ bool MeshCollider::CanBeTrigger() const
#if USE_EDITOR
#include "Engine/Debug/DebugDraw.h"
+#include "Engine/Graphics/RenderView.h"
void MeshCollider::DrawPhysicsDebug(RenderView& view)
{
if (CollisionData && CollisionData->IsLoaded())
{
- const auto& debugLines = CollisionData->GetDebugLines();
- DEBUG_DRAW_LINES(Span(debugLines.Get(), debugLines.Count()), _transform.GetWorld(), Color::GreenYellow * 0.8f, 0, true);
+ if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
+ {
+ Array* vertexBuffer;
+ Array* indexBuffer;
+ CollisionData->GetDebugTriangles(vertexBuffer, indexBuffer);
+ DebugDraw::DrawTriangles(*vertexBuffer, *indexBuffer, _transform.GetWorld(), _staticActor ? Color::CornflowerBlue : Color::Orchid, 0, true);
+ }
+ else
+ {
+ DebugDraw::DrawLines(CollisionData->GetDebugLines(), _transform.GetWorld(), Color::GreenYellow * 0.8f, 0, true);
+ }
}
}
diff --git a/Source/Engine/Physics/Colliders/SphereCollider.cpp b/Source/Engine/Physics/Colliders/SphereCollider.cpp
index b602b8f84..41983ec2c 100644
--- a/Source/Engine/Physics/Colliders/SphereCollider.cpp
+++ b/Source/Engine/Physics/Colliders/SphereCollider.cpp
@@ -25,10 +25,14 @@ void SphereCollider::SetRadius(const float value)
#if USE_EDITOR
#include "Engine/Debug/DebugDraw.h"
+#include "Engine/Graphics/RenderView.h"
void SphereCollider::DrawPhysicsDebug(RenderView& view)
{
- DEBUG_DRAW_WIRE_SPHERE(_sphere, Color::GreenYellow * 0.8f, 0, true);
+ if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
+ DebugDraw::DrawSphere(_sphere, _staticActor ? Color::CornflowerBlue : Color::Orchid, 0, true);
+ else
+ DebugDraw::DrawWireSphere(_sphere, Color::GreenYellow * 0.8f, 0, true);
}
void SphereCollider::OnDebugDrawSelected()
diff --git a/Source/Engine/Physics/Colliders/SplineCollider.cpp b/Source/Engine/Physics/Colliders/SplineCollider.cpp
index 98665aa05..e74b38c37 100644
--- a/Source/Engine/Physics/Colliders/SplineCollider.cpp
+++ b/Source/Engine/Physics/Colliders/SplineCollider.cpp
@@ -86,10 +86,14 @@ bool SplineCollider::CanBeTrigger() const
#if USE_EDITOR
#include "Engine/Debug/DebugDraw.h"
+#include "Engine/Graphics/RenderView.h"
void SplineCollider::DrawPhysicsDebug(RenderView& view)
{
- DEBUG_DRAW_WIRE_TRIANGLES_EX(_vertexBuffer, _indexBuffer, Color::GreenYellow * 0.8f, 0, true);
+ if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
+ DebugDraw::DrawTriangles(_vertexBuffer, _indexBuffer, Color::CornflowerBlue, 0, true);
+ else
+ DebugDraw::DrawWireTriangles(_vertexBuffer, _indexBuffer, Color::GreenYellow * 0.8f, 0, true);
}
void SplineCollider::OnDebugDrawSelected()
diff --git a/Source/Engine/Physics/CollisionData.cpp b/Source/Engine/Physics/CollisionData.cpp
index 5fd2eaed5..14396bf6a 100644
--- a/Source/Engine/Physics/CollisionData.cpp
+++ b/Source/Engine/Physics/CollisionData.cpp
@@ -227,18 +227,17 @@ const Array& CollisionData::GetDebugLines()
ScopeLock lock(Locker);
_hasMissingDebugLines = false;
- Array vertexBuffer;
- Array indexBuffer;
- ExtractGeometry(vertexBuffer, indexBuffer);
+ // Get triangles
+ ExtractGeometry(_debugVertexBuffer, _debugIndexBuffer);
// Get lines
- _debugLines.Resize(indexBuffer.Count() * 2);
+ _debugLines.Resize(_debugIndexBuffer.Count() * 2);
int32 lineIndex = 0;
- for (int32 i = 0; i < indexBuffer.Count(); i += 3)
+ for (int32 i = 0; i < _debugIndexBuffer.Count(); i += 3)
{
- const auto a = vertexBuffer[indexBuffer[i + 0]];
- const auto b = vertexBuffer[indexBuffer[i + 1]];
- const auto c = vertexBuffer[indexBuffer[i + 2]];
+ const auto a = _debugVertexBuffer[_debugIndexBuffer[i + 0]];
+ const auto b = _debugVertexBuffer[_debugIndexBuffer[i + 1]];
+ const auto c = _debugVertexBuffer[_debugIndexBuffer[i + 2]];
_debugLines[lineIndex++] = a;
_debugLines[lineIndex++] = b;
@@ -254,6 +253,13 @@ const Array& CollisionData::GetDebugLines()
return _debugLines;
}
+void CollisionData::GetDebugTriangles(Array*& vertexBuffer, Array*& indexBuffer)
+{
+ GetDebugLines();
+ vertexBuffer = &_debugVertexBuffer;
+ indexBuffer = &_debugIndexBuffer;
+}
+
#endif
Asset::LoadResult CollisionData::load()
@@ -327,6 +333,8 @@ void CollisionData::unload(bool isReloading)
#if USE_EDITOR
_hasMissingDebugLines = true;
_debugLines.Resize(0);
+ _debugVertexBuffer.Resize(0);
+ _debugIndexBuffer.Resize(0);
#endif
}
diff --git a/Source/Engine/Physics/CollisionData.h b/Source/Engine/Physics/CollisionData.h
index c2ff38815..9242b8203 100644
--- a/Source/Engine/Physics/CollisionData.h
+++ b/Source/Engine/Physics/CollisionData.h
@@ -251,8 +251,11 @@ public:
private:
bool _hasMissingDebugLines = true;
Array _debugLines;
+ Array _debugVertexBuffer;
+ Array _debugIndexBuffer;
public:
const Array& GetDebugLines();
+ void GetDebugTriangles(Array*& vertexBuffer, Array*& indexBuffer);
#endif
private:
diff --git a/Source/Engine/Renderer/GBufferPass.cpp b/Source/Engine/Renderer/GBufferPass.cpp
index 0791f1dc2..079ac9bbe 100644
--- a/Source/Engine/Renderer/GBufferPass.cpp
+++ b/Source/Engine/Renderer/GBufferPass.cpp
@@ -175,6 +175,11 @@ void GBufferPass::Fill(RenderContext& renderContext, GPUTextureView* lightBuffer
}
}
}
+ if (renderContext.View.Mode == ViewMode::PhysicsColliders)
+ {
+ context->ResetRenderTarget();
+ return;
+ }
#endif
// Draw objects that can get decals