Merge branch 'Tryibion-prefab-physics-draw'

This commit is contained in:
Wojtek Figat
2024-08-15 15:26:25 +02:00
4 changed files with 69 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ using FlaxEditor.Viewport.Previews;
using FlaxEditor.Windows.Assets; using FlaxEditor.Windows.Assets;
using FlaxEngine; using FlaxEngine;
using FlaxEngine.GUI; using FlaxEngine.GUI;
using Utils = FlaxEditor.Utilities.Utils;
namespace FlaxEditor.Viewport namespace FlaxEditor.Viewport
{ {
@@ -624,12 +625,37 @@ namespace FlaxEditor.Viewport
} }
} }
// Debug draw all actors in prefab // Debug draw all actors in prefab and collect actors
List<Actor> pActors = new List<Actor>();
foreach (var child in SceneGraphRoot.ChildNodes) foreach (var child in SceneGraphRoot.ChildNodes)
{ {
if (child is not ActorNode actorNode) if (child is not ActorNode actorNode)
continue; continue;
DebugDraw.DrawActorsTree(actorNode.Actor); var actor = actorNode.Actor;
Utils.GetActorsTree(pActors, actor);
DebugDraw.DrawActorsTree(actor);
}
// Draw physics debug
if ((Task.ViewFlags & ViewFlags.PhysicsDebug) != 0)
{
foreach (var actor in pActors)
{
if (actor is Collider c && c.IsActiveInHierarchy)
{
DebugDraw.DrawColliderDebugPhysics(c, renderContext.View);
}
}
}
// Draw lights debug
if ((Task.ViewFlags & ViewFlags.LightsDebug) != 0)
{
foreach (var actor in pActors)
{
if (actor is Light l && l.IsActiveInHierarchy)
DebugDraw.DrawLightDebug(l, renderContext.View);
}
} }
} }
} }

View File

@@ -27,6 +27,8 @@
#include "Engine/Render2D/FontAsset.h" #include "Engine/Render2D/FontAsset.h"
#if USE_EDITOR #if USE_EDITOR
#include "Editor/Editor.h" #include "Editor/Editor.h"
#include "Engine/Level/Actors/Light.h"
#include "Engine/Physics/Colliders/Collider.h"
#endif #endif
// Debug draw service configuration // Debug draw service configuration
@@ -950,6 +952,23 @@ void DebugDraw::DrawActorsTree(Actor* actor)
actor->TreeExecute(function); actor->TreeExecute(function);
} }
#if USE_EDITOR
void DebugDraw::DrawColliderDebugPhysics(Collider* collider, RenderView& view)
{
if (!collider)
return;
collider->DrawPhysicsDebug(view);
}
void DebugDraw::DrawLightDebug(Light* light, RenderView& view)
{
if (!light)
return;
light->DrawLightsDebug(view);
}
#endif
void DebugDraw::DrawAxisFromDirection(const Vector3& origin, const Vector3& direction, float size, float duration, bool depthTest) void DebugDraw::DrawAxisFromDirection(const Vector3& origin, const Vector3& direction, float size, float duration, bool depthTest)
{ {
CHECK_DEBUG(direction.IsNormalized()); CHECK_DEBUG(direction.IsNormalized());

View File

@@ -8,6 +8,9 @@
#include "Engine/Core/Math/Color.h" #include "Engine/Core/Math/Color.h"
#include "Engine/Core/Types/Span.h" #include "Engine/Core/Types/Span.h"
struct RenderView;
class Collider;
class Light;
struct RenderContext; struct RenderContext;
class GPUTextureView; class GPUTextureView;
class GPUContext; class GPUContext;
@@ -70,9 +73,23 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
/// <summary> /// <summary>
/// Draws the debug shapes for the given actor and the actor's children /// Draws the debug shapes for the given actor and the actor's children
/// </summary> /// </summary>
/// /// <param name="actor">The actor to start drawing at.</param> /// <param name="actor">The actor to start drawing at.</param>
API_FUNCTION() static void DrawActorsTree(Actor* actor); API_FUNCTION() static void DrawActorsTree(Actor* actor);
#if USE_EDITOR
/// <summary>
/// Draws the physics debug shapes for the given collider. Editor Only
/// </summary>
/// <param name="collider">The collider to draw.</param>
/// <param name="view">The render view to draw in.</param>
API_FUNCTION() static void DrawColliderDebugPhysics(Collider* collider, RenderView& view);
/// <summary>
/// Draws the light debug shapes for the given light. Editor Only
/// </summary>
/// <param name="light">The light debug to draw.</param>
/// <param name="view">The render view to draw in.</param>
API_FUNCTION() static void DrawLightDebug(Light* light, RenderView& view);
#endif
/// <summary> /// <summary>
/// Draws the lines axis from direction. /// Draws the lines axis from direction.
/// </summary> /// </summary>

View File

@@ -154,10 +154,6 @@ protected:
/// </summary> /// </summary>
void RemoveStaticActor(); void RemoveStaticActor();
#if USE_EDITOR
virtual void DrawPhysicsDebug(RenderView& view);
#endif
private: private:
void OnMaterialChanged(); void OnMaterialChanged();
@@ -169,6 +165,10 @@ public:
void ClosestPoint(const Vector3& point, Vector3& result) const final; void ClosestPoint(const Vector3& point, Vector3& result) const final;
bool ContainsPoint(const Vector3& point) const final; bool ContainsPoint(const Vector3& point) const final;
#if USE_EDITOR
virtual void DrawPhysicsDebug(RenderView& view);
#endif
protected: protected:
// [PhysicsColliderActor] // [PhysicsColliderActor]
void OnEnable() override; void OnEnable() override;