Add Physics Colliders debug view mode to display physical world shapes (solid)
This commit is contained in:
@@ -1396,6 +1396,7 @@ namespace FlaxEditor.Viewport
|
|||||||
new ViewModeOptions(ViewMode.MotionVectors, "Motion Vectors"),
|
new ViewModeOptions(ViewMode.MotionVectors, "Motion Vectors"),
|
||||||
new ViewModeOptions(ViewMode.LightmapUVsDensity, "Lightmap UVs Density"),
|
new ViewModeOptions(ViewMode.LightmapUVsDensity, "Lightmap UVs Density"),
|
||||||
new ViewModeOptions(ViewMode.VertexColors, "Vertex Colors"),
|
new ViewModeOptions(ViewMode.VertexColors, "Vertex Colors"),
|
||||||
|
new ViewModeOptions(ViewMode.PhysicsColliders, "Physics Colliders"),
|
||||||
};
|
};
|
||||||
|
|
||||||
private void WidgetCamSpeedShowHide(Control cm)
|
private void WidgetCamSpeedShowHide(Control cm)
|
||||||
|
|||||||
@@ -797,6 +797,11 @@ API_ENUM() enum class ViewMode
|
|||||||
/// Draw meshes vertex colors
|
/// Draw meshes vertex colors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
VertexColors = 19,
|
VertexColors = 19,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draw physics colliders debug view
|
||||||
|
/// </summary>
|
||||||
|
PhysicsColliders = 20,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ protected:
|
|||||||
if (!_streamingTexture->GetOwner()->GetMipDataCustomPitch(absoluteMipIndex, rowPitch, slicePitch))
|
if (!_streamingTexture->GetOwner()->GetMipDataCustomPitch(absoluteMipIndex, rowPitch, slicePitch))
|
||||||
texture->ComputePitch(_mipIndex, rowPitch, slicePitch);
|
texture->ComputePitch(_mipIndex, rowPitch, slicePitch);
|
||||||
_data.Link(data);
|
_data.Link(data);
|
||||||
ASSERT(data.Length() >= slicePitch * arraySize);
|
ASSERT(data.Length() >= (int32)slicePitch * arraySize);
|
||||||
|
|
||||||
// Update all array slices
|
// Update all array slices
|
||||||
const byte* dataSource = data.Get();
|
const byte* dataSource = data.Get();
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ void SceneRendering::Draw(RenderContext& renderContext)
|
|||||||
if (view.Pass & DrawPass::GBuffer)
|
if (view.Pass & DrawPass::GBuffer)
|
||||||
{
|
{
|
||||||
// Draw physics shapes
|
// 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++)
|
for (int32 i = 0; i < PhysicsDebug.Count(); i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,11 +25,14 @@ void BoxCollider::SetSize(const Vector3& value)
|
|||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|
||||||
#include "Engine/Debug/DebugDraw.h"
|
#include "Engine/Debug/DebugDraw.h"
|
||||||
|
#include "Engine/Graphics/RenderView.h"
|
||||||
|
|
||||||
void BoxCollider::DrawPhysicsDebug(RenderView& view)
|
void BoxCollider::DrawPhysicsDebug(RenderView& view)
|
||||||
{
|
{
|
||||||
const Color color = Color::GreenYellow;
|
if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
|
||||||
DEBUG_DRAW_WIRE_BOX(_bounds, color * 0.8f, 0, true);
|
DebugDraw::DrawBox(_bounds, _staticActor ? Color::CornflowerBlue : Color::Orchid, 0, true);
|
||||||
|
else
|
||||||
|
DebugDraw::DrawWireBox(_bounds, Color::GreenYellow * 0.8f, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxCollider::OnDebugDraw()
|
void BoxCollider::OnDebugDraw()
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ void CapsuleCollider::SetHeight(const float value)
|
|||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|
||||||
#include "Engine/Debug/DebugDraw.h"
|
#include "Engine/Debug/DebugDraw.h"
|
||||||
|
#include "Engine/Graphics/RenderView.h"
|
||||||
|
|
||||||
void CapsuleCollider::DrawPhysicsDebug(RenderView& view)
|
void CapsuleCollider::DrawPhysicsDebug(RenderView& view)
|
||||||
{
|
{
|
||||||
@@ -46,7 +47,10 @@ void CapsuleCollider::DrawPhysicsDebug(RenderView& view)
|
|||||||
const float minSize = 0.001f;
|
const float minSize = 0.001f;
|
||||||
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
|
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
|
||||||
const float height = Math::Max(Math::Abs(_height) * 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()
|
void CapsuleCollider::OnDebugDrawSelected()
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ PxRigidDynamic* CharacterController::GetPhysXRigidActor() const
|
|||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|
||||||
#include "Engine/Debug/DebugDraw.h"
|
#include "Engine/Debug/DebugDraw.h"
|
||||||
|
#include "Engine/Graphics/RenderView.h"
|
||||||
|
|
||||||
void CharacterController::DrawPhysicsDebug(RenderView& view)
|
void CharacterController::DrawPhysicsDebug(RenderView& view)
|
||||||
{
|
{
|
||||||
@@ -191,7 +192,10 @@ void CharacterController::DrawPhysicsDebug(RenderView& view)
|
|||||||
const float minSize = 0.001f;
|
const float minSize = 0.001f;
|
||||||
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
|
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
|
||||||
const float height = Math::Max(Math::Abs(_height) * 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()
|
void CharacterController::OnDebugDrawSelected()
|
||||||
|
|||||||
@@ -63,13 +63,23 @@ bool MeshCollider::CanBeTrigger() const
|
|||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|
||||||
#include "Engine/Debug/DebugDraw.h"
|
#include "Engine/Debug/DebugDraw.h"
|
||||||
|
#include "Engine/Graphics/RenderView.h"
|
||||||
|
|
||||||
void MeshCollider::DrawPhysicsDebug(RenderView& view)
|
void MeshCollider::DrawPhysicsDebug(RenderView& view)
|
||||||
{
|
{
|
||||||
if (CollisionData && CollisionData->IsLoaded())
|
if (CollisionData && CollisionData->IsLoaded())
|
||||||
{
|
{
|
||||||
const auto& debugLines = CollisionData->GetDebugLines();
|
if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
|
||||||
DEBUG_DRAW_LINES(Span<Vector3>(debugLines.Get(), debugLines.Count()), _transform.GetWorld(), Color::GreenYellow * 0.8f, 0, true);
|
{
|
||||||
|
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
|
#if USE_EDITOR
|
||||||
|
|
||||||
#include "Engine/Debug/DebugDraw.h"
|
#include "Engine/Debug/DebugDraw.h"
|
||||||
|
#include "Engine/Graphics/RenderView.h"
|
||||||
|
|
||||||
void SphereCollider::DrawPhysicsDebug(RenderView& view)
|
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()
|
void SphereCollider::OnDebugDrawSelected()
|
||||||
|
|||||||
@@ -86,10 +86,14 @@ bool SplineCollider::CanBeTrigger() const
|
|||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|
||||||
#include "Engine/Debug/DebugDraw.h"
|
#include "Engine/Debug/DebugDraw.h"
|
||||||
|
#include "Engine/Graphics/RenderView.h"
|
||||||
|
|
||||||
void SplineCollider::DrawPhysicsDebug(RenderView& view)
|
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()
|
void SplineCollider::OnDebugDrawSelected()
|
||||||
|
|||||||
@@ -227,18 +227,17 @@ const Array<Vector3>& CollisionData::GetDebugLines()
|
|||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
_hasMissingDebugLines = false;
|
_hasMissingDebugLines = false;
|
||||||
|
|
||||||
Array<Vector3> vertexBuffer;
|
// Get triangles
|
||||||
Array<int32> indexBuffer;
|
ExtractGeometry(_debugVertexBuffer, _debugIndexBuffer);
|
||||||
ExtractGeometry(vertexBuffer, indexBuffer);
|
|
||||||
|
|
||||||
// Get lines
|
// Get lines
|
||||||
_debugLines.Resize(indexBuffer.Count() * 2);
|
_debugLines.Resize(_debugIndexBuffer.Count() * 2);
|
||||||
int32 lineIndex = 0;
|
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 a = _debugVertexBuffer[_debugIndexBuffer[i + 0]];
|
||||||
const auto b = vertexBuffer[indexBuffer[i + 1]];
|
const auto b = _debugVertexBuffer[_debugIndexBuffer[i + 1]];
|
||||||
const auto c = vertexBuffer[indexBuffer[i + 2]];
|
const auto c = _debugVertexBuffer[_debugIndexBuffer[i + 2]];
|
||||||
|
|
||||||
_debugLines[lineIndex++] = a;
|
_debugLines[lineIndex++] = a;
|
||||||
_debugLines[lineIndex++] = b;
|
_debugLines[lineIndex++] = b;
|
||||||
@@ -254,6 +253,13 @@ const Array<Vector3>& CollisionData::GetDebugLines()
|
|||||||
return _debugLines;
|
return _debugLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CollisionData::GetDebugTriangles(Array<Vector3>*& vertexBuffer, Array<int32>*& indexBuffer)
|
||||||
|
{
|
||||||
|
GetDebugLines();
|
||||||
|
vertexBuffer = &_debugVertexBuffer;
|
||||||
|
indexBuffer = &_debugIndexBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Asset::LoadResult CollisionData::load()
|
Asset::LoadResult CollisionData::load()
|
||||||
@@ -327,6 +333,8 @@ void CollisionData::unload(bool isReloading)
|
|||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
_hasMissingDebugLines = true;
|
_hasMissingDebugLines = true;
|
||||||
_debugLines.Resize(0);
|
_debugLines.Resize(0);
|
||||||
|
_debugVertexBuffer.Resize(0);
|
||||||
|
_debugIndexBuffer.Resize(0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -251,8 +251,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool _hasMissingDebugLines = true;
|
bool _hasMissingDebugLines = true;
|
||||||
Array<Vector3> _debugLines;
|
Array<Vector3> _debugLines;
|
||||||
|
Array<Vector3> _debugVertexBuffer;
|
||||||
|
Array<int32> _debugIndexBuffer;
|
||||||
public:
|
public:
|
||||||
const Array<Vector3>& GetDebugLines();
|
const Array<Vector3>& GetDebugLines();
|
||||||
|
void GetDebugTriangles(Array<Vector3>*& vertexBuffer, Array<int32>*& indexBuffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -175,6 +175,11 @@ void GBufferPass::Fill(RenderContext& renderContext, GPUTextureView* lightBuffer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (renderContext.View.Mode == ViewMode::PhysicsColliders)
|
||||||
|
{
|
||||||
|
context->ResetRenderTarget();
|
||||||
|
return;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Draw objects that can get decals
|
// Draw objects that can get decals
|
||||||
|
|||||||
Reference in New Issue
Block a user