Add support for debug shapes preview in prefab editor window
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "EditorScene.h"
|
#include "EditorScene.h"
|
||||||
|
|
||||||
|
#include "Engine/Debug/DebugDraw.h"
|
||||||
|
|
||||||
EditorScene::EditorScene(const SpawnParams& params)
|
EditorScene::EditorScene(const SpawnParams& params)
|
||||||
: Scene(params)
|
: Scene(params)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ namespace FlaxEditor.Viewport
|
|||||||
{
|
{
|
||||||
fixed (IntPtr* actors = _debugDrawData.ActorsPtrs)
|
fixed (IntPtr* actors = _debugDrawData.ActorsPtrs)
|
||||||
{
|
{
|
||||||
DebugDraw.DrawActors(new IntPtr(actors), _debugDrawData.ActorsCount);
|
DebugDraw.DrawActors(new IntPtr(actors), _debugDrawData.ActorsCount, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ namespace FlaxEditor.Viewport
|
|||||||
private ViewportWidgetButton _rotateSnapping;
|
private ViewportWidgetButton _rotateSnapping;
|
||||||
private ViewportWidgetButton _scaleSnapping;
|
private ViewportWidgetButton _scaleSnapping;
|
||||||
|
|
||||||
|
private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32);
|
||||||
|
private IntPtr _debugDrawContext;
|
||||||
private readonly DragAssets _dragAssets = new DragAssets(ValidateDragItem);
|
private readonly DragAssets _dragAssets = new DragAssets(ValidateDragItem);
|
||||||
private readonly DragActorType _dragActorType = new DragActorType(ValidateDragActorType);
|
private readonly DragActorType _dragActorType = new DragActorType(ValidateDragActorType);
|
||||||
private readonly DragHandlers _dragHandlers = new DragHandlers();
|
private readonly DragHandlers _dragHandlers = new DragHandlers();
|
||||||
@@ -56,6 +58,11 @@ namespace FlaxEditor.Viewport
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public EditorPrimitives EditorPrimitives;
|
public EditorPrimitives EditorPrimitives;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether draw <see cref="DebugDraw"/> shapes.
|
||||||
|
/// </summary>
|
||||||
|
public bool DrawDebugDraw = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PrefabWindowViewport"/> class.
|
/// Initializes a new instance of the <see cref="PrefabWindowViewport"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -67,10 +74,13 @@ namespace FlaxEditor.Viewport
|
|||||||
_window.SelectionChanged += OnSelectionChanged;
|
_window.SelectionChanged += OnSelectionChanged;
|
||||||
Undo = window.Undo;
|
Undo = window.Undo;
|
||||||
ViewportCamera = new FPSCamera();
|
ViewportCamera = new FPSCamera();
|
||||||
|
_debugDrawContext = DebugDraw.AllocateContext();
|
||||||
|
|
||||||
// Prepare rendering task
|
// Prepare rendering task
|
||||||
Task.ActorsSource = ActorsSources.CustomActors;
|
Task.ActorsSource = ActorsSources.CustomActors;
|
||||||
Task.ViewFlags = ViewFlags.DefaultEditor & ~ViewFlags.EditorSprites;
|
Task.ViewFlags = ViewFlags.DefaultEditor & ~ViewFlags.EditorSprites;
|
||||||
|
Task.Begin += OnBegin;
|
||||||
|
Task.CollectDrawCalls += OnCollectDrawCalls;
|
||||||
Task.PostRender += OnPostRender;
|
Task.PostRender += OnPostRender;
|
||||||
|
|
||||||
// Create post effects
|
// Create post effects
|
||||||
@@ -214,6 +224,27 @@ namespace FlaxEditor.Viewport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnBegin(RenderTask task, GPUContext context)
|
||||||
|
{
|
||||||
|
_debugDrawData.Clear();
|
||||||
|
|
||||||
|
// Collect selected objects debug shapes and visuals
|
||||||
|
var selectedParents = TransformGizmo.SelectedParents;
|
||||||
|
if (selectedParents.Count > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < selectedParents.Count; i++)
|
||||||
|
{
|
||||||
|
if (selectedParents[i].IsActiveInHierarchy)
|
||||||
|
selectedParents[i].OnDebugDraw(_debugDrawData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCollectDrawCalls(RenderContext renderContext)
|
||||||
|
{
|
||||||
|
_debugDrawData.OnDraw(ref renderContext);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnPostRender(GPUContext context, RenderContext renderContext)
|
private void OnPostRender(GPUContext context, RenderContext renderContext)
|
||||||
{
|
{
|
||||||
if (renderContext.View.Mode != ViewMode.Default)
|
if (renderContext.View.Mode != ViewMode.Default)
|
||||||
@@ -222,7 +253,24 @@ namespace FlaxEditor.Viewport
|
|||||||
|
|
||||||
// Render editor primitives, gizmo and debug shapes in debug view modes
|
// Render editor primitives, gizmo and debug shapes in debug view modes
|
||||||
// Note: can use Output buffer as both input and output because EditorPrimitives is using a intermediate buffers
|
// Note: can use Output buffer as both input and output because EditorPrimitives is using a intermediate buffers
|
||||||
EditorPrimitives.Render(context, ref renderContext, task.Output, task.Output);
|
if (EditorPrimitives && EditorPrimitives.CanRender)
|
||||||
|
{
|
||||||
|
EditorPrimitives.Render(context, ref renderContext, task.Output, task.Output);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render selection outline
|
||||||
|
if (SelectionOutline && SelectionOutline.CanRender)
|
||||||
|
{
|
||||||
|
// Use temporary intermediate buffer
|
||||||
|
var desc = task.Output.Description;
|
||||||
|
var temp = RenderTargetPool.Get(ref desc);
|
||||||
|
SelectionOutline.Render(context, ref renderContext, task.Output, temp);
|
||||||
|
|
||||||
|
// Copy the results back to the output
|
||||||
|
context.CopyTexture(task.Output, 0, 0, 0, 0, temp, 0);
|
||||||
|
|
||||||
|
RenderTargetPool.Release(temp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,6 +848,11 @@ namespace FlaxEditor.Viewport
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
{
|
{
|
||||||
|
if (_debugDrawContext != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
DebugDraw.FreeContext(_debugDrawContext);
|
||||||
|
_debugDrawContext = IntPtr.Zero;
|
||||||
|
}
|
||||||
FlaxEngine.Object.Destroy(ref SelectionOutline);
|
FlaxEngine.Object.Destroy(ref SelectionOutline);
|
||||||
FlaxEngine.Object.Destroy(ref EditorPrimitives);
|
FlaxEngine.Object.Destroy(ref EditorPrimitives);
|
||||||
|
|
||||||
@@ -809,6 +862,21 @@ namespace FlaxEditor.Viewport
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void DrawEditorPrimitives(GPUContext context, ref RenderContext renderContext, GPUTexture target, GPUTexture targetDepth)
|
public void DrawEditorPrimitives(GPUContext context, ref RenderContext renderContext, GPUTexture target, GPUTexture targetDepth)
|
||||||
{
|
{
|
||||||
|
// Draw selected objects debug shapes and visuals
|
||||||
|
if (DrawDebugDraw && (renderContext.View.Flags & ViewFlags.DebugDraw) == ViewFlags.DebugDraw)
|
||||||
|
{
|
||||||
|
DebugDraw.SetContext(_debugDrawContext);
|
||||||
|
DebugDraw.UpdateContext(_debugDrawContext, 1.0f / Engine.FramesPerSecond);
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
fixed (IntPtr* actors = _debugDrawData.ActorsPtrs)
|
||||||
|
{
|
||||||
|
DebugDraw.DrawActors(new IntPtr(actors), _debugDrawData.ActorsCount, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DebugDraw.Draw(ref renderContext, target.View(), targetDepth.View(), true);
|
||||||
|
DebugDraw.SetContext(IntPtr.Zero);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using FlaxEditor.SceneGraph;
|
|||||||
using FlaxEditor.Viewport;
|
using FlaxEditor.Viewport;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
|
using Object = FlaxEngine.Object;
|
||||||
|
|
||||||
namespace FlaxEditor.Windows.Assets
|
namespace FlaxEditor.Windows.Assets
|
||||||
{
|
{
|
||||||
@@ -22,7 +23,7 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
{
|
{
|
||||||
private readonly SplitPanel _split1;
|
private readonly SplitPanel _split1;
|
||||||
private readonly SplitPanel _split2;
|
private readonly SplitPanel _split2;
|
||||||
private TextBox _searchBox;
|
private readonly TextBox _searchBox;
|
||||||
private readonly PrefabTree _tree;
|
private readonly PrefabTree _tree;
|
||||||
private readonly PrefabWindowViewport _viewport;
|
private readonly PrefabWindowViewport _viewport;
|
||||||
private readonly CustomEditorPresenter _propertiesEditor;
|
private readonly CustomEditorPresenter _propertiesEditor;
|
||||||
|
|||||||
@@ -205,20 +205,30 @@ struct DebugDrawData
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
DebugDrawData DebugDrawDefault;
|
struct DebugDrawContext
|
||||||
DebugDrawData DebugDrawDepthTest;
|
{
|
||||||
AssetReference<Shader> DebugDrawShader;
|
DebugDrawData DebugDrawDefault;
|
||||||
PsData DebugDrawPsLinesDefault;
|
DebugDrawData DebugDrawDepthTest;
|
||||||
PsData DebugDrawPsLinesDepthTest;
|
};
|
||||||
PsData DebugDrawPsWireTrianglesDefault;
|
|
||||||
PsData DebugDrawPsWireTrianglesDepthTest;
|
namespace
|
||||||
PsData DebugDrawPsTrianglesDefault;
|
{
|
||||||
PsData DebugDrawPsTrianglesDepthTest;
|
DebugDrawContext GlobalContext;
|
||||||
DynamicVertexBuffer* DebugDrawVB = nullptr;
|
DebugDrawContext* Context;
|
||||||
Vector3 SphereCache[DEBUG_DRAW_SPHERE_VERTICES];
|
AssetReference<Shader> DebugDrawShader;
|
||||||
Vector3 CircleCache[DEBUG_DRAW_CIRCLE_VERTICES];
|
PsData DebugDrawPsLinesDefault;
|
||||||
Vector3 CylinderCache[DEBUG_DRAW_CYLINDER_VERTICES];
|
PsData DebugDrawPsLinesDepthTest;
|
||||||
Array<Vector3> SphereTriangleCache;
|
PsData DebugDrawPsWireTrianglesDefault;
|
||||||
|
PsData DebugDrawPsWireTrianglesDepthTest;
|
||||||
|
PsData DebugDrawPsTrianglesDefault;
|
||||||
|
PsData DebugDrawPsTrianglesDepthTest;
|
||||||
|
DynamicVertexBuffer* DebugDrawVB = nullptr;
|
||||||
|
Vector3 SphereCache[DEBUG_DRAW_SPHERE_VERTICES];
|
||||||
|
Vector3 CircleCache[DEBUG_DRAW_CIRCLE_VERTICES];
|
||||||
|
Vector3 CylinderCache[DEBUG_DRAW_CYLINDER_VERTICES];
|
||||||
|
Array<Vector3> SphereTriangleCache;
|
||||||
|
};
|
||||||
|
|
||||||
extern int32 BoxTrianglesIndicesCache[];
|
extern int32 BoxTrianglesIndicesCache[];
|
||||||
|
|
||||||
struct DebugDrawCall
|
struct DebugDrawCall
|
||||||
@@ -307,6 +317,8 @@ DebugDrawService DebugDrawServiceInstance;
|
|||||||
|
|
||||||
bool DebugDrawService::Init()
|
bool DebugDrawService::Init()
|
||||||
{
|
{
|
||||||
|
Context = &GlobalContext;
|
||||||
|
|
||||||
// Init wireframe sphere cache
|
// Init wireframe sphere cache
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
float step = TWO_PI / DEBUG_DRAW_SPHERE_RESOLUTION;
|
float step = TWO_PI / DEBUG_DRAW_SPHERE_RESOLUTION;
|
||||||
@@ -436,8 +448,8 @@ void DebugDrawService::Update()
|
|||||||
// Special case for Null renderer
|
// Special case for Null renderer
|
||||||
if (GPUDevice::Instance->GetRendererType() == RendererType::Null)
|
if (GPUDevice::Instance->GetRendererType() == RendererType::Null)
|
||||||
{
|
{
|
||||||
DebugDrawDefault.Clear();
|
GlobalContext.DebugDrawDefault.Clear();
|
||||||
DebugDrawDepthTest.Clear();
|
GlobalContext.DebugDrawDepthTest.Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,8 +457,8 @@ void DebugDrawService::Update()
|
|||||||
|
|
||||||
// Update lists
|
// Update lists
|
||||||
const float deltaTime = Time::Update.DeltaTime.GetTotalSeconds();
|
const float deltaTime = Time::Update.DeltaTime.GetTotalSeconds();
|
||||||
DebugDrawDefault.Update(deltaTime);
|
GlobalContext.DebugDrawDefault.Update(deltaTime);
|
||||||
DebugDrawDepthTest.Update(deltaTime);
|
GlobalContext.DebugDrawDepthTest.Update(deltaTime);
|
||||||
|
|
||||||
// Check if need to setup a resources
|
// Check if need to setup a resources
|
||||||
if (DebugDrawShader == nullptr)
|
if (DebugDrawShader == nullptr)
|
||||||
@@ -501,8 +513,8 @@ void DebugDrawService::Update()
|
|||||||
void DebugDrawService::Dispose()
|
void DebugDrawService::Dispose()
|
||||||
{
|
{
|
||||||
// Clear lists
|
// Clear lists
|
||||||
DebugDrawDefault.Release();
|
GlobalContext.DebugDrawDefault.Release();
|
||||||
DebugDrawDepthTest.Release();
|
GlobalContext.DebugDrawDepthTest.Release();
|
||||||
|
|
||||||
// Release resources
|
// Release resources
|
||||||
SphereTriangleCache.Resize(0);
|
SphereTriangleCache.Resize(0);
|
||||||
@@ -516,13 +528,41 @@ void DebugDrawService::Dispose()
|
|||||||
DebugDrawShader = nullptr;
|
DebugDrawShader = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_EDITOR
|
||||||
|
|
||||||
|
void* DebugDraw::AllocateContext()
|
||||||
|
{
|
||||||
|
auto context = (DebugDrawContext*)Allocator::Allocate(sizeof(DebugDrawContext));
|
||||||
|
Memory::ConstructItem(context);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDraw::FreeContext(void* context)
|
||||||
|
{
|
||||||
|
Memory::DestructItem((DebugDrawContext*)context);
|
||||||
|
Allocator::Free(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDraw::UpdateContext(void* context, float deltaTime)
|
||||||
|
{
|
||||||
|
((DebugDrawContext*)context)->DebugDrawDefault.Update(deltaTime);
|
||||||
|
((DebugDrawContext*)context)->DebugDrawDepthTest.Update(deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDraw::SetContext(void* context)
|
||||||
|
{
|
||||||
|
Context = context ? (DebugDrawContext*)context : &GlobalContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTextureView* depthBuffer, bool enableDepthTest)
|
void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTextureView* depthBuffer, bool enableDepthTest)
|
||||||
{
|
{
|
||||||
PROFILE_GPU_CPU("Debug Draw");
|
PROFILE_GPU_CPU("Debug Draw");
|
||||||
|
|
||||||
// Ensure to have shader loaded and any lines to render
|
// Ensure to have shader loaded and any lines to render
|
||||||
const int32 debugDrawDepthTestCount = DebugDrawDepthTest.Count();
|
const int32 debugDrawDepthTestCount = Context->DebugDrawDepthTest.Count();
|
||||||
const int32 debugDrawDefaultCount = DebugDrawDefault.Count();
|
const int32 debugDrawDefaultCount = Context->DebugDrawDefault.Count();
|
||||||
if (DebugDrawShader == nullptr || !DebugDrawShader->IsLoaded() || debugDrawDepthTestCount + debugDrawDefaultCount == 0)
|
if (DebugDrawShader == nullptr || !DebugDrawShader->IsLoaded() || debugDrawDepthTestCount + debugDrawDefaultCount == 0)
|
||||||
return;
|
return;
|
||||||
if (renderContext.Buffers == nullptr || !DebugDrawVB)
|
if (renderContext.Buffers == nullptr || !DebugDrawVB)
|
||||||
@@ -539,12 +579,12 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
|
|||||||
#endif
|
#endif
|
||||||
DebugDrawVB->Clear();
|
DebugDrawVB->Clear();
|
||||||
int32 vertexCounter = 0;
|
int32 vertexCounter = 0;
|
||||||
const DebugDrawCall depthTestLines = WriteLists(vertexCounter, DebugDrawDepthTest.DefaultLines, DebugDrawDepthTest.OneFrameLines);
|
const DebugDrawCall depthTestLines = WriteLists(vertexCounter, Context->DebugDrawDepthTest.DefaultLines, Context->DebugDrawDepthTest.OneFrameLines);
|
||||||
const DebugDrawCall defaultLines = WriteLists(vertexCounter, DebugDrawDefault.DefaultLines, DebugDrawDefault.OneFrameLines);
|
const DebugDrawCall defaultLines = WriteLists(vertexCounter, Context->DebugDrawDefault.DefaultLines, Context->DebugDrawDefault.OneFrameLines);
|
||||||
const DebugDrawCall depthTestTriangles = WriteLists(vertexCounter, DebugDrawDepthTest.DefaultTriangles, DebugDrawDepthTest.OneFrameTriangles);
|
const DebugDrawCall depthTestTriangles = WriteLists(vertexCounter, Context->DebugDrawDepthTest.DefaultTriangles, Context->DebugDrawDepthTest.OneFrameTriangles);
|
||||||
const DebugDrawCall defaultTriangles = WriteLists(vertexCounter, DebugDrawDefault.DefaultTriangles, DebugDrawDefault.OneFrameTriangles);
|
const DebugDrawCall defaultTriangles = WriteLists(vertexCounter, Context->DebugDrawDefault.DefaultTriangles, Context->DebugDrawDefault.OneFrameTriangles);
|
||||||
const DebugDrawCall depthTestWireTriangles = WriteLists(vertexCounter, DebugDrawDepthTest.DefaultWireTriangles, DebugDrawDepthTest.OneFrameWireTriangles);
|
const DebugDrawCall depthTestWireTriangles = WriteLists(vertexCounter, Context->DebugDrawDepthTest.DefaultWireTriangles, Context->DebugDrawDepthTest.OneFrameWireTriangles);
|
||||||
const DebugDrawCall defaultWireTriangles = WriteLists(vertexCounter, DebugDrawDefault.DefaultWireTriangles, DebugDrawDefault.OneFrameWireTriangles);
|
const DebugDrawCall defaultWireTriangles = WriteLists(vertexCounter, Context->DebugDrawDefault.DefaultWireTriangles, Context->DebugDrawDefault.OneFrameWireTriangles);
|
||||||
DebugDrawVB->Flush(context);
|
DebugDrawVB->Flush(context);
|
||||||
#if COMPILE_WITH_PROFILER
|
#if COMPILE_WITH_PROFILER
|
||||||
ProfilerCPU::EndEvent(updateBufferProfileKey);
|
ProfilerCPU::EndEvent(updateBufferProfileKey);
|
||||||
@@ -636,9 +676,10 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
|
|||||||
#undef DRAW
|
#undef DRAW
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugDraw::DrawActors(Actor** selectedActors, int32 selectedActorsCount)
|
void DebugDraw::DrawActors(Actor** selectedActors, int32 selectedActorsCount, bool drawScenes)
|
||||||
{
|
{
|
||||||
PROFILE_CPU();
|
PROFILE_CPU();
|
||||||
|
|
||||||
if (selectedActors)
|
if (selectedActors)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < selectedActorsCount; i++)
|
for (int32 i = 0; i < selectedActorsCount; i++)
|
||||||
@@ -649,16 +690,19 @@ void DebugDraw::DrawActors(Actor** selectedActors, int32 selectedActorsCount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function<bool(Actor*)> function = [](Actor* actor)-> bool
|
if (drawScenes)
|
||||||
{
|
{
|
||||||
if (actor->IsActiveInHierarchy())
|
Function<bool(Actor*)> function = [](Actor* actor)-> bool
|
||||||
{
|
{
|
||||||
actor->OnDebugDraw();
|
if (actor->IsActiveInHierarchy())
|
||||||
return true;
|
{
|
||||||
}
|
actor->OnDebugDraw();
|
||||||
return false;
|
return true;
|
||||||
};
|
}
|
||||||
SceneQuery::TreeExecute(function);
|
return false;
|
||||||
|
};
|
||||||
|
SceneQuery::TreeExecute(function);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugDraw::DrawLine(const Vector3& start, const Vector3& end, const Color& color, float duration, bool depthTest)
|
void DebugDraw::DrawLine(const Vector3& start, const Vector3& end, const Color& color, float duration, bool depthTest)
|
||||||
@@ -668,9 +712,9 @@ void DebugDraw::DrawLine(const Vector3& start, const Vector3& end, const Color&
|
|||||||
|
|
||||||
// Add line
|
// Add line
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
DebugDrawDepthTest.Add(l);
|
Context->DebugDrawDepthTest.Add(l);
|
||||||
else
|
else
|
||||||
DebugDrawDefault.Add(l);
|
Context->DebugDrawDefault.Add(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugDraw::DrawLines(const Span<Vector3>& lines, const Matrix& transform, const Color& color, float duration, bool depthTest)
|
void DebugDraw::DrawLines(const Span<Vector3>& lines, const Matrix& transform, const Color& color, float duration, bool depthTest)
|
||||||
@@ -689,9 +733,9 @@ void DebugDraw::DrawLines(const Span<Vector3>& lines, const Matrix& transform, c
|
|||||||
Array<DebugLine>* list;
|
Array<DebugLine>* list;
|
||||||
|
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultLines : &DebugDrawDepthTest.OneFrameLines;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultLines : &Context->DebugDrawDepthTest.OneFrameLines;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultLines : &DebugDrawDefault.OneFrameLines;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultLines : &Context->DebugDrawDefault.OneFrameLines;
|
||||||
|
|
||||||
list->EnsureCapacity(list->Count() + lines.Length());
|
list->EnsureCapacity(list->Count() + lines.Length());
|
||||||
for (int32 i = 0; i < lines.Length(); i += 2)
|
for (int32 i = 0; i < lines.Length(); i += 2)
|
||||||
@@ -707,9 +751,9 @@ void DebugDraw::DrawBezier(const Vector3& p1, const Vector3& p2, const Vector3&
|
|||||||
// Create draw call entry
|
// Create draw call entry
|
||||||
Array<DebugLine>* list;
|
Array<DebugLine>* list;
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultLines : &DebugDrawDepthTest.OneFrameLines;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultLines : &Context->DebugDrawDepthTest.OneFrameLines;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultLines : &DebugDrawDefault.OneFrameLines;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultLines : &Context->DebugDrawDefault.OneFrameLines;
|
||||||
DebugLine l = { p1, Vector3::Zero, Color32(color), duration };
|
DebugLine l = { p1, Vector3::Zero, Color32(color), duration };
|
||||||
|
|
||||||
// Find amount of segments to use
|
// Find amount of segments to use
|
||||||
@@ -731,7 +775,7 @@ void DebugDraw::DrawBezier(const Vector3& p1, const Vector3& p2, const Vector3&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DRAW_WIRE_BOX_LINE(i0, i1, list) l.Start = corners[i0]; l.End = corners[i1]; list.Add(l)
|
#define DRAW_WIRE_BOX_LINE(i0, i1, list) l.Start = corners[i0]; l.End = corners[i1]; Context->list.Add(l)
|
||||||
#define DRAW_WIRE_BOX(list) \
|
#define DRAW_WIRE_BOX(list) \
|
||||||
DRAW_WIRE_BOX_LINE(0, 1, list); \
|
DRAW_WIRE_BOX_LINE(0, 1, list); \
|
||||||
DRAW_WIRE_BOX_LINE(0, 3, list); \
|
DRAW_WIRE_BOX_LINE(0, 3, list); \
|
||||||
@@ -818,7 +862,7 @@ void DebugDraw::DrawWireSphere(const BoundingSphere& sphere, const Color& color,
|
|||||||
{
|
{
|
||||||
l.Start = sphere.Center + SphereCache[i++] * sphere.Radius;
|
l.Start = sphere.Center + SphereCache[i++] * sphere.Radius;
|
||||||
l.End = sphere.Center + SphereCache[i++] * sphere.Radius;
|
l.End = sphere.Center + SphereCache[i++] * sphere.Radius;
|
||||||
DebugDrawDepthTest.Add(l);
|
Context->DebugDrawDepthTest.Add(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -827,7 +871,7 @@ void DebugDraw::DrawWireSphere(const BoundingSphere& sphere, const Color& color,
|
|||||||
{
|
{
|
||||||
l.Start = sphere.Center + SphereCache[i++] * sphere.Radius;
|
l.Start = sphere.Center + SphereCache[i++] * sphere.Radius;
|
||||||
l.End = sphere.Center + SphereCache[i++] * sphere.Radius;
|
l.End = sphere.Center + SphereCache[i++] * sphere.Radius;
|
||||||
DebugDrawDefault.Add(l);
|
Context->DebugDrawDefault.Add(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -840,9 +884,9 @@ void DebugDraw::DrawSphere(const BoundingSphere& sphere, const Color& color, flo
|
|||||||
|
|
||||||
Array<DebugTriangle>* list;
|
Array<DebugTriangle>* list;
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultTriangles : &Context->DebugDrawDepthTest.OneFrameTriangles;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultTriangles : &Context->DebugDrawDefault.OneFrameTriangles;
|
||||||
list->EnsureCapacity(list->Count() + SphereTriangleCache.Count());
|
list->EnsureCapacity(list->Count() + SphereTriangleCache.Count());
|
||||||
|
|
||||||
for (int32 i = 0; i < SphereTriangleCache.Count();)
|
for (int32 i = 0; i < SphereTriangleCache.Count();)
|
||||||
@@ -899,11 +943,11 @@ void DebugDraw::DrawTriangle(const Vector3& v0, const Vector3& v1, const Vector3
|
|||||||
|
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
{
|
{
|
||||||
DebugDrawDepthTest.Add(t);
|
Context->DebugDrawDepthTest.Add(t);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DebugDrawDefault.Add(t);
|
Context->DebugDrawDefault.Add(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -917,9 +961,9 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Color& color,
|
|||||||
|
|
||||||
Array<DebugTriangle>* list;
|
Array<DebugTriangle>* list;
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultTriangles : &Context->DebugDrawDepthTest.OneFrameTriangles;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultTriangles : &Context->DebugDrawDefault.OneFrameTriangles;
|
||||||
list->EnsureCapacity(list->Count() + vertices.Length() / 3);
|
list->EnsureCapacity(list->Count() + vertices.Length() / 3);
|
||||||
|
|
||||||
for (int32 i = 0; i < vertices.Length();)
|
for (int32 i = 0; i < vertices.Length();)
|
||||||
@@ -946,9 +990,9 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>&
|
|||||||
|
|
||||||
Array<DebugTriangle>* list;
|
Array<DebugTriangle>* list;
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultTriangles : &Context->DebugDrawDepthTest.OneFrameTriangles;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultTriangles : &Context->DebugDrawDefault.OneFrameTriangles;
|
||||||
list->EnsureCapacity(list->Count() + indices.Length() / 3);
|
list->EnsureCapacity(list->Count() + indices.Length() / 3);
|
||||||
|
|
||||||
for (int32 i = 0; i < indices.Length();)
|
for (int32 i = 0; i < indices.Length();)
|
||||||
@@ -975,9 +1019,9 @@ void DebugDraw::DrawWireTriangles(const Span<Vector3>& vertices, const Color& co
|
|||||||
|
|
||||||
Array<DebugTriangle>* list;
|
Array<DebugTriangle>* list;
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultWireTriangles : &DebugDrawDepthTest.OneFrameWireTriangles;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultWireTriangles : &Context->DebugDrawDepthTest.OneFrameWireTriangles;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultWireTriangles : &DebugDrawDefault.OneFrameWireTriangles;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultWireTriangles : &Context->DebugDrawDefault.OneFrameWireTriangles;
|
||||||
list->EnsureCapacity(list->Count() + vertices.Length() / 3);
|
list->EnsureCapacity(list->Count() + vertices.Length() / 3);
|
||||||
|
|
||||||
for (int32 i = 0; i < vertices.Length();)
|
for (int32 i = 0; i < vertices.Length();)
|
||||||
@@ -1004,9 +1048,9 @@ void DebugDraw::DrawWireTriangles(const Span<Vector3>& vertices, const Span<int3
|
|||||||
|
|
||||||
Array<DebugTriangle>* list;
|
Array<DebugTriangle>* list;
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultWireTriangles : &DebugDrawDepthTest.OneFrameWireTriangles;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultWireTriangles : &Context->DebugDrawDepthTest.OneFrameWireTriangles;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultWireTriangles : &DebugDrawDefault.OneFrameWireTriangles;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultWireTriangles : &Context->DebugDrawDefault.OneFrameWireTriangles;
|
||||||
list->EnsureCapacity(list->Count() + indices.Length() / 3);
|
list->EnsureCapacity(list->Count() + indices.Length() / 3);
|
||||||
|
|
||||||
for (int32 i = 0; i < indices.Length();)
|
for (int32 i = 0; i < indices.Length();)
|
||||||
@@ -1192,9 +1236,9 @@ void DebugDraw::DrawBox(const BoundingBox& box, const Color& color, float durati
|
|||||||
t.TimeLeft = duration;
|
t.TimeLeft = duration;
|
||||||
Array<DebugTriangle>* list;
|
Array<DebugTriangle>* list;
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultTriangles : &Context->DebugDrawDepthTest.OneFrameTriangles;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultTriangles : &Context->DebugDrawDefault.OneFrameTriangles;
|
||||||
list->EnsureCapacity(list->Count() + 36);
|
list->EnsureCapacity(list->Count() + 36);
|
||||||
for (int i0 = 0; i0 < 36;)
|
for (int i0 = 0; i0 < 36;)
|
||||||
{
|
{
|
||||||
@@ -1218,9 +1262,9 @@ void DebugDraw::DrawBox(const OrientedBoundingBox& box, const Color& color, floa
|
|||||||
t.TimeLeft = duration;
|
t.TimeLeft = duration;
|
||||||
Array<DebugTriangle>* list;
|
Array<DebugTriangle>* list;
|
||||||
if (depthTest)
|
if (depthTest)
|
||||||
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultTriangles : &Context->DebugDrawDepthTest.OneFrameTriangles;
|
||||||
else
|
else
|
||||||
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
|
list = duration > 0 ? &Context->DebugDrawDefault.DefaultTriangles : &Context->DebugDrawDefault.OneFrameTriangles;
|
||||||
list->EnsureCapacity(list->Count() + 36);
|
list->EnsureCapacity(list->Count() + 36);
|
||||||
for (int i0 = 0; i0 < 36;)
|
for (int i0 = 0; i0 < 36;)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,6 +23,35 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
|
|||||||
{
|
{
|
||||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
|
DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
|
||||||
|
|
||||||
|
#if USE_EDITOR
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allocates the context for Debug Drawing. Can be use to redirect debug shapes collecting to a separate container (instead of global state).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The context object. Release it wil FreeContext. Returns null if failed.</returns>
|
||||||
|
API_FUNCTION() static void* AllocateContext();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Frees the context for Debug Drawing.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">The context.</param>
|
||||||
|
API_FUNCTION() static void FreeContext(void* context);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the context for Debug Drawing.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">The context.</param>
|
||||||
|
/// <param name="deltaTime">The update delta time (in seconds).</param>
|
||||||
|
API_FUNCTION() static void UpdateContext(void* context, float deltaTime);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the context for Debug Drawing to a custom or null to use global default.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">The context or null.</param>
|
||||||
|
API_FUNCTION() static void SetContext(void* context);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draws the collected debug shapes to the output.
|
/// Draws the collected debug shapes to the output.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -37,7 +66,8 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="selectedActors">The list of actors to draw.</param>
|
/// <param name="selectedActors">The list of actors to draw.</param>
|
||||||
/// <param name="selectedActorsCount">The size of the list of actors.</param>
|
/// <param name="selectedActorsCount">The size of the list of actors.</param>
|
||||||
API_FUNCTION() static void DrawActors(Actor** selectedActors, int32 selectedActorsCount);
|
/// <param name="drawScenes">True if draw all debug shapes from scenes too or false if draw just from specified actor list.</param>
|
||||||
|
API_FUNCTION() static void DrawActors(Actor** selectedActors, int32 selectedActorsCount, bool drawScenes);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draws the line.
|
/// Draws the line.
|
||||||
|
|||||||
Reference in New Issue
Block a user