From 3958a4740f6b388e16e7f2fac474b0528d893897 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 14 Feb 2024 12:36:04 +0100 Subject: [PATCH] Add option to enable Depth Test on cloth painting debug preview (enabled by default) --- Source/Editor/Tools/ClothPainting.cs | 15 +++++++++++++++ Source/Engine/Physics/Actors/Cloth.cpp | 6 +++--- Source/Engine/Physics/Actors/Cloth.h | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Tools/ClothPainting.cs b/Source/Editor/Tools/ClothPainting.cs index 28536ea83..6a98a3b5f 100644 --- a/Source/Editor/Tools/ClothPainting.cs +++ b/Source/Editor/Tools/ClothPainting.cs @@ -43,6 +43,19 @@ namespace FlaxEngine.Tools /// Enables continuous painting, otherwise single paint on click. /// public bool ContinuousPaint; + + /// + /// Enables drawing cloth paint debugging with Depth Test enabled (skips occluded vertices). + /// + public bool DebugDrawDepthTest + { + get => Gizmo.Cloth?.DebugDrawDepthTest ?? true; + set + { + if (Gizmo.Cloth != null) + Gizmo.Cloth.DebugDrawDepthTest = value; + } + } #pragma warning restore CS0649 public override void Init(IGizmoOwner owner) @@ -62,6 +75,7 @@ namespace FlaxEngine.Tools public override void Dispose() { Owner.Gizmos.Remove(Gizmo); + Gizmo = null; base.Dispose(); } @@ -83,6 +97,7 @@ namespace FlaxEngine.Tools private EditClothPaintAction _undoAction; public bool IsPainting => _isPainting; + public Cloth Cloth => _cloth; public ClothPaintingGizmo(IGizmoOwner owner, ClothPaintingGizmoMode mode) : base(owner) diff --git a/Source/Engine/Physics/Actors/Cloth.cpp b/Source/Engine/Physics/Actors/Cloth.cpp index b2db80b0b..a35acb066 100644 --- a/Source/Engine/Physics/Actors/Cloth.cpp +++ b/Source/Engine/Physics/Actors/Cloth.cpp @@ -415,9 +415,9 @@ void Cloth::OnDebugDrawSelected() c1 = Color::Lerp(Color::Red, Color::White, _paint[i1]); c2 = Color::Lerp(Color::Red, Color::White, _paint[i2]); } - DebugDraw::DrawLine(v0, v1, c0, c1, 0, false); - DebugDraw::DrawLine(v1, v2, c1, c2, 0, false); - DebugDraw::DrawLine(v2, v0, c2, c0, 0, false); + DebugDraw::DrawLine(v0, v1, c0, c1, 0, DebugDrawDepthTest); + DebugDraw::DrawLine(v1, v2, c1, c2, 0, DebugDrawDepthTest); + DebugDraw::DrawLine(v2, v0, c2, c0, 0, DebugDrawDepthTest); } PhysicsBackend::UnlockClothParticles(_cloth); } diff --git a/Source/Engine/Physics/Actors/Cloth.h b/Source/Engine/Physics/Actors/Cloth.h index 6137ec3b6..1b97330e0 100644 --- a/Source/Engine/Physics/Actors/Cloth.h +++ b/Source/Engine/Physics/Actors/Cloth.h @@ -332,6 +332,11 @@ public: bool OnPreUpdate(); void OnPostUpdate(); +private: +#if USE_EDITOR + API_FIELD(Internal) bool DebugDrawDepthTest = true; +#endif + public: // [Actor] void Draw(RenderContext& renderContext) override;