Add Physics Colliders debug view mode to display physical world shapes (solid)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<Vector3>(debugLines.Get(), debugLines.Count()), _transform.GetWorld(), Color::GreenYellow * 0.8f, 0, true);
|
||||
if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
|
||||
{
|
||||
Array<Vector3>* vertexBuffer;
|
||||
Array<int32>* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -227,18 +227,17 @@ const Array<Vector3>& CollisionData::GetDebugLines()
|
||||
ScopeLock lock(Locker);
|
||||
_hasMissingDebugLines = false;
|
||||
|
||||
Array<Vector3> vertexBuffer;
|
||||
Array<int32> 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<Vector3>& CollisionData::GetDebugLines()
|
||||
return _debugLines;
|
||||
}
|
||||
|
||||
void CollisionData::GetDebugTriangles(Array<Vector3>*& vertexBuffer, Array<int32>*& 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
|
||||
}
|
||||
|
||||
|
||||
@@ -251,8 +251,11 @@ public:
|
||||
private:
|
||||
bool _hasMissingDebugLines = true;
|
||||
Array<Vector3> _debugLines;
|
||||
Array<Vector3> _debugVertexBuffer;
|
||||
Array<int32> _debugIndexBuffer;
|
||||
public:
|
||||
const Array<Vector3>& GetDebugLines();
|
||||
void GetDebugTriangles(Array<Vector3>*& vertexBuffer, Array<int32>*& indexBuffer);
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user