From 9fafb47abbb311b1495c7623773e6ce29f0bd128 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 29 Aug 2025 21:03:44 +0200 Subject: [PATCH] Fix debug drawing wheeled vehicle in prefab viewport #3591 --- .../Editor/Viewport/PrefabWindowViewport.cs | 5 +- Source/Engine/Debug/DebugDraw.cpp | 8 +-- Source/Engine/Debug/DebugDraw.h | 6 +-- Source/Engine/Level/Scene/SceneRendering.cpp | 5 +- Source/Engine/Level/Scene/SceneRendering.h | 18 +++---- Source/Engine/Physics/Actors/Cloth.cpp | 4 +- Source/Engine/Physics/Actors/Cloth.h | 8 +-- Source/Engine/Physics/Actors/IPhysicsDebug.h | 18 +++++++ .../Engine/Physics/Actors/WheeledVehicle.cpp | 53 ++++++++++--------- Source/Engine/Physics/Actors/WheeledVehicle.h | 10 ++-- Source/Engine/Physics/Colliders/BoxCollider.h | 4 +- .../Physics/Colliders/CapsuleCollider.h | 4 +- .../Physics/Colliders/CharacterController.h | 4 +- Source/Engine/Physics/Colliders/Collider.cpp | 12 +---- Source/Engine/Physics/Colliders/Collider.h | 7 +-- .../Engine/Physics/Colliders/MeshCollider.h | 4 +- .../Engine/Physics/Colliders/SphereCollider.h | 4 +- .../Engine/Physics/Colliders/SplineCollider.h | 4 +- Source/Engine/Physics/Joints/Joint.cpp | 4 +- Source/Engine/Physics/Joints/Joint.h | 8 +-- Source/Engine/Terrain/Terrain.cpp | 4 +- Source/Engine/Terrain/Terrain.h | 8 +-- 22 files changed, 102 insertions(+), 100 deletions(-) create mode 100644 Source/Engine/Physics/Actors/IPhysicsDebug.h diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index 8b508eedf..a982f6447 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -663,10 +663,7 @@ namespace FlaxEditor.Viewport if ((view.Flags & ViewFlags.PhysicsDebug) != 0 || view.Mode == ViewMode.PhysicsColliders) { foreach (var actor in _debugDrawActors) - { - if (actor is Collider c && c.IsActiveInHierarchy) - DebugDraw.DrawColliderDebugPhysics(c, renderContext.View); - } + DebugDraw.DrawDebugPhysics(actor, renderContext.View); } // Draw lights debug diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 2bb921f70..a6709fab3 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -30,6 +30,7 @@ #include "Editor/Editor.h" #include "Engine/Level/Actors/Light.h" #include "Engine/Physics/Colliders/Collider.h" +#include "Engine/Physics/Actors/IPhysicsDebug.h" #endif // Debug draw service configuration @@ -1027,11 +1028,12 @@ void DebugDraw::DrawActorsTree(Actor* actor) #if USE_EDITOR -void DebugDraw::DrawColliderDebugPhysics(Collider* collider, RenderView& view) +void DebugDraw::DrawDebugPhysics(Actor* actor, RenderView& view) { - if (!collider) + if (!actor || !actor->IsActiveInHierarchy()) return; - collider->DrawPhysicsDebug(view); + if (auto* physicsDebug = dynamic_cast(actor)) + physicsDebug->DrawPhysicsDebug(view); } void DebugDraw::DrawLightDebug(Light* light, RenderView& view) diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index 3b51c0e13..6ddbbaf39 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -102,11 +102,11 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw #if USE_EDITOR /// - /// Draws the physics debug shapes for the given collider. Editor Only + /// Draws the physics debug shapes for the given actor. Editor Only /// - /// The collider to draw. + /// The actor to draw. /// The render view to draw in. - API_FUNCTION() static void DrawColliderDebugPhysics(Collider* collider, RenderView& view); + API_FUNCTION() static void DrawDebugPhysics(Actor* actor, RenderView& view); /// /// Draws the light debug shapes for the given light. Editor Only diff --git a/Source/Engine/Level/Scene/SceneRendering.cpp b/Source/Engine/Level/Scene/SceneRendering.cpp index 445447cd1..8261a39cc 100644 --- a/Source/Engine/Level/Scene/SceneRendering.cpp +++ b/Source/Engine/Level/Scene/SceneRendering.cpp @@ -9,6 +9,7 @@ #include "Engine/Threading/JobSystem.h" #include "Engine/Threading/Threading.h" #include "Engine/Profiler/ProfilerCPU.h" +#include "Engine/Physics/Actors/IPhysicsDebug.h" ISceneRenderingListener::~ISceneRenderingListener() { @@ -91,10 +92,10 @@ void SceneRendering::Draw(RenderContextBatch& renderContextBatch, DrawCategory c if (EnumHasAnyFlags(view.Flags, ViewFlags::PhysicsDebug) || view.Mode == ViewMode::PhysicsColliders) { PROFILE_CPU_NAMED("PhysicsDebug"); - const PhysicsDebugCallback* physicsDebugData = PhysicsDebug.Get(); + const auto* physicsDebugData = PhysicsDebug.Get(); for (int32 i = 0; i < PhysicsDebug.Count(); i++) { - physicsDebugData[i](view); + physicsDebugData[i]->DrawPhysicsDebug(view); } } diff --git a/Source/Engine/Level/Scene/SceneRendering.h b/Source/Engine/Level/Scene/SceneRendering.h index 043f5079e..cab16c450 100644 --- a/Source/Engine/Level/Scene/SceneRendering.h +++ b/Source/Engine/Level/Scene/SceneRendering.h @@ -11,6 +11,7 @@ class SceneRenderTask; class SceneRendering; +class IPhysicsDebug; struct PostProcessSettings; struct RenderContext; struct RenderContextBatch; @@ -74,7 +75,6 @@ public: class FLAXENGINE_API SceneRendering { #if USE_EDITOR - typedef Function PhysicsDebugCallback; typedef Function LightsDebugCallback; friend class ViewportIconsRendererService; #endif @@ -105,7 +105,7 @@ public: private: #if USE_EDITOR - Array PhysicsDebug; + Array PhysicsDebug; Array LightsDebug; Array ViewportIcons; #endif @@ -149,20 +149,14 @@ public: } #if USE_EDITOR - template - FORCE_INLINE void AddPhysicsDebug(T* obj) + FORCE_INLINE void AddPhysicsDebug(IPhysicsDebug* obj) { - PhysicsDebugCallback f; - f.Bind(obj); - PhysicsDebug.Add(f); + PhysicsDebug.Add(obj); } - template - void RemovePhysicsDebug(T* obj) + FORCE_INLINE void RemovePhysicsDebug(IPhysicsDebug* obj) { - PhysicsDebugCallback f; - f.Bind(obj); - PhysicsDebug.Remove(f); + PhysicsDebug.Remove(obj); } template diff --git a/Source/Engine/Physics/Actors/Cloth.cpp b/Source/Engine/Physics/Actors/Cloth.cpp index b184bfbda..48db20065 100644 --- a/Source/Engine/Physics/Actors/Cloth.cpp +++ b/Source/Engine/Physics/Actors/Cloth.cpp @@ -457,7 +457,7 @@ void Cloth::OnEnable() { GetSceneRendering()->AddActor(this, _sceneRenderingKey); #if USE_EDITOR - GetSceneRendering()->AddPhysicsDebug(this); + GetSceneRendering()->AddPhysicsDebug(this); #endif #if WITH_CLOTH if (_cloth) @@ -476,7 +476,7 @@ void Cloth::OnDisable() PhysicsBackend::RemoveCloth(GetPhysicsScene()->GetPhysicsScene(), _cloth); #endif #if USE_EDITOR - GetSceneRendering()->RemovePhysicsDebug(this); + GetSceneRendering()->RemovePhysicsDebug(this); #endif GetSceneRendering()->RemoveActor(this, _sceneRenderingKey); } diff --git a/Source/Engine/Physics/Actors/Cloth.h b/Source/Engine/Physics/Actors/Cloth.h index d10c18fea..f83f1c499 100644 --- a/Source/Engine/Physics/Actors/Cloth.h +++ b/Source/Engine/Physics/Actors/Cloth.h @@ -4,6 +4,7 @@ #include "Engine/Level/Actor.h" #include "Engine/Level/Actors/ModelInstanceActor.h" +#include "IPhysicsDebug.h" // Used internally to validate cloth data against invalid nan/inf values #define USE_CLOTH_SANITY_CHECKS 0 @@ -12,6 +13,9 @@ /// Physical simulation actor for cloth objects made of vertices that are simulated as cloth particles with physical properties, forces, and constraints to affect cloth behavior. /// API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Cloth\"), ActorToolbox(\"Physics\")") class FLAXENGINE_API Cloth : public Actor +#if USE_EDITOR + , public IPhysicsDebug +#endif { DECLARE_SCENE_OBJECT(Cloth); @@ -364,9 +368,7 @@ protected: void OnPhysicsSceneChanged(PhysicsScene* previous) override; private: -#if USE_EDITOR - void DrawPhysicsDebug(RenderView& view); -#endif + ImplementPhysicsDebug; bool CreateCloth(); void DestroyCloth(); void CalculateInvMasses(Array& invMasses); diff --git a/Source/Engine/Physics/Actors/IPhysicsDebug.h b/Source/Engine/Physics/Actors/IPhysicsDebug.h new file mode 100644 index 000000000..cedd3d822 --- /dev/null +++ b/Source/Engine/Physics/Actors/IPhysicsDebug.h @@ -0,0 +1,18 @@ +// Copyright (c) Wojciech Figat. All rights reserved. + +#pragma once + +#include "Engine/Core/Types/BaseTypes.h" + +#if USE_EDITOR +class FLAXENGINE_API IPhysicsDebug +{ +public: + virtual void DrawPhysicsDebug(struct RenderView& view) + { + } +}; +#define ImplementPhysicsDebug void DrawPhysicsDebug(RenderView& view) +#else +#define ImplementPhysicsDebug +#endif diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.cpp b/Source/Engine/Physics/Actors/WheeledVehicle.cpp index 28808be17..35f78f39f 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.cpp +++ b/Source/Engine/Physics/Actors/WheeledVehicle.cpp @@ -356,19 +356,19 @@ void WheeledVehicle::Setup() void WheeledVehicle::DrawPhysicsDebug(RenderView& view) { // Wheels shapes - for (const auto& data : _wheelsData) + for (const auto& wheel : _wheels) { - int32 wheelIndex = 0; - for (; wheelIndex < _wheels.Count(); wheelIndex++) - { - if (_wheels[wheelIndex].Collider == data.Collider) - break; - } - if (wheelIndex == _wheels.Count()) - break; - const auto& wheel = _wheels[wheelIndex]; if (wheel.Collider && wheel.Collider->GetParent() == this && !wheel.Collider->GetIsTrigger()) { + WheelData data = { wheel.Collider, wheel.Collider->GetLocalOrientation() }; + for (auto& e : _wheelsData) + { + if (e.Collider == data.Collider) + { + data = e; + break; + } + } const Vector3 currentPos = wheel.Collider->GetPosition(); const Vector3 basePos = currentPos - Vector3(0, data.State.SuspensionOffset, 0); const Quaternion wheelDebugOrientation = GetOrientation() * Quaternion::Euler(-data.State.RotationAngle, data.State.SteerAngle, 0) * Quaternion::Euler(90, 0, 90); @@ -387,25 +387,28 @@ void WheeledVehicle::DrawPhysicsDebug(RenderView& view) void WheeledVehicle::OnDebugDrawSelected() { // Wheels shapes - for (const auto& data : _wheelsData) + for (const auto& wheel : _wheels) { - int32 wheelIndex = 0; - for (; wheelIndex < _wheels.Count(); wheelIndex++) - { - if (_wheels[wheelIndex].Collider == data.Collider) - break; - } - if (wheelIndex == _wheels.Count()) - break; - const auto& wheel = _wheels[wheelIndex]; if (wheel.Collider && wheel.Collider->GetParent() == this && !wheel.Collider->GetIsTrigger()) { + WheelData data = { wheel.Collider, wheel.Collider->GetLocalOrientation() }; + for (auto& e : _wheelsData) + { + if (e.Collider == data.Collider) + { + data = e; + break; + } + } const Vector3 currentPos = wheel.Collider->GetPosition(); const Vector3 basePos = currentPos - Vector3(0, data.State.SuspensionOffset, 0); const Quaternion wheelDebugOrientation = GetOrientation() * Quaternion::Euler(-data.State.RotationAngle, data.State.SteerAngle, 0) * Quaternion::Euler(90, 0, 90); - Transform actorPose = Transform::Identity, shapePose = Transform::Identity; - PhysicsBackend::GetRigidActorPose(_actor, actorPose.Translation, actorPose.Orientation); - PhysicsBackend::GetShapeLocalPose(wheel.Collider->GetPhysicsShape(), shapePose.Translation, shapePose.Orientation); + Transform actorPose = GetTransform(), shapePose = wheel.Collider->GetLocalTransform(); + actorPose.Scale = Float3::One; + if (_actor) + PhysicsBackend::GetRigidActorPose(_actor, actorPose.Translation, actorPose.Orientation); + if (wheel.Collider->GetPhysicsShape()) + PhysicsBackend::GetShapeLocalPose(wheel.Collider->GetPhysicsShape(), shapePose.Translation, shapePose.Orientation); DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(basePos, wheel.Radius * 0.07f), Color::Blue * 0.3f, 0, false); DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(currentPos, wheel.Radius * 0.08f), Color::Blue * 0.8f, 0, false); DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(actorPose.LocalToWorld(shapePose.Translation), wheel.Radius * 0.11f), Color::OrangeRed * 0.8f, 0, false); @@ -561,14 +564,14 @@ void WheeledVehicle::BeginPlay(SceneBeginData* data) #endif #if USE_EDITOR - GetSceneRendering()->AddPhysicsDebug(this); + GetSceneRendering()->AddPhysicsDebug(this); #endif } void WheeledVehicle::EndPlay() { #if USE_EDITOR - GetSceneRendering()->RemovePhysicsDebug(this); + GetSceneRendering()->RemovePhysicsDebug(this); #endif #if WITH_VEHICLE diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.h b/Source/Engine/Physics/Actors/WheeledVehicle.h index 037157158..390c0e24a 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.h +++ b/Source/Engine/Physics/Actors/WheeledVehicle.h @@ -5,12 +5,16 @@ #include "Engine/Physics/Actors/RigidBody.h" #include "Engine/Physics/Colliders/Collider.h" #include "Engine/Scripting/ScriptingObjectReference.h" +#include "IPhysicsDebug.h" /// /// Representation of the car vehicle that uses wheels. Built on top of the RigidBody with collider representing its chassis shape and wheels. /// /// API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Wheeled Vehicle\"), ActorToolbox(\"Physics\")") class FLAXENGINE_API WheeledVehicle : public RigidBody +#if USE_EDITOR + , public IPhysicsDebug +#endif { friend class PhysicsBackend; friend struct ScenePhysX; @@ -644,13 +648,9 @@ public: /// API_FUNCTION() void Setup(); -private: -#if USE_EDITOR - void DrawPhysicsDebug(RenderView& view); -#endif - public: // [Vehicle] + ImplementPhysicsDebug; #if USE_EDITOR void OnDebugDrawSelected() override; #endif diff --git a/Source/Engine/Physics/Colliders/BoxCollider.h b/Source/Engine/Physics/Colliders/BoxCollider.h index 9b9b964a1..c0eeaea5c 100644 --- a/Source/Engine/Physics/Colliders/BoxCollider.h +++ b/Source/Engine/Physics/Colliders/BoxCollider.h @@ -58,9 +58,7 @@ public: protected: // [Collider] + ImplementPhysicsDebug; void UpdateBounds() override; void GetGeometry(CollisionShape& collision) override; -#if USE_EDITOR - void DrawPhysicsDebug(RenderView& view) override; -#endif }; diff --git a/Source/Engine/Physics/Colliders/CapsuleCollider.h b/Source/Engine/Physics/Colliders/CapsuleCollider.h index 9275b99e1..234916f87 100644 --- a/Source/Engine/Physics/Colliders/CapsuleCollider.h +++ b/Source/Engine/Physics/Colliders/CapsuleCollider.h @@ -62,9 +62,7 @@ public: protected: // [Collider] + ImplementPhysicsDebug; void UpdateBounds() override; void GetGeometry(CollisionShape& collision) override; -#if USE_EDITOR - void DrawPhysicsDebug(RenderView& view) override; -#endif }; diff --git a/Source/Engine/Physics/Colliders/CharacterController.h b/Source/Engine/Physics/Colliders/CharacterController.h index 918f5beb9..367b87df1 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.h +++ b/Source/Engine/Physics/Colliders/CharacterController.h @@ -267,13 +267,11 @@ public: protected: // [PhysicsActor] + ImplementPhysicsDebug; void UpdateGeometry() override; void GetGeometry(CollisionShape& collision) override; void BeginPlay(SceneBeginData* data) override; void EndPlay() override; -#if USE_EDITOR - void DrawPhysicsDebug(RenderView& view) override; -#endif void OnActiveInTreeChanged() override; void OnEnable() override; void OnDisable() override; diff --git a/Source/Engine/Physics/Colliders/Collider.cpp b/Source/Engine/Physics/Colliders/Collider.cpp index 0ff51e8e6..8249577c2 100644 --- a/Source/Engine/Physics/Colliders/Collider.cpp +++ b/Source/Engine/Physics/Colliders/Collider.cpp @@ -147,7 +147,7 @@ void Collider::OnEnable() if (EnumHasAnyFlags(_staticFlags, StaticFlags::Navigation) && !_isTrigger) GetScene()->Navigation.Actors.Add(this); #if USE_EDITOR - GetSceneRendering()->AddPhysicsDebug(this); + GetSceneRendering()->AddPhysicsDebug(this); #endif PhysicsColliderActor::OnEnable(); @@ -160,7 +160,7 @@ void Collider::OnDisable() if (EnumHasAnyFlags(_staticFlags, StaticFlags::Navigation) && !_isTrigger) GetScene()->Navigation.Actors.Remove(this); #if USE_EDITOR - GetSceneRendering()->RemovePhysicsDebug(this); + GetSceneRendering()->RemovePhysicsDebug(this); #endif } @@ -286,14 +286,6 @@ void Collider::RemoveStaticActor() _staticActor = nullptr; } -#if USE_EDITOR - -void Collider::DrawPhysicsDebug(RenderView& view) -{ -} - -#endif - void Collider::OnMaterialChanged() { // Update the shape material diff --git a/Source/Engine/Physics/Colliders/Collider.h b/Source/Engine/Physics/Colliders/Collider.h index 835d89a22..5fd34f187 100644 --- a/Source/Engine/Physics/Colliders/Collider.h +++ b/Source/Engine/Physics/Colliders/Collider.h @@ -6,6 +6,7 @@ #include "Engine/Content/JsonAsset.h" #include "Engine/Content/JsonAssetReference.h" #include "Engine/Physics/Actors/PhysicsColliderActor.h" +#include "Engine/Physics/Actors/IPhysicsDebug.h" struct RayCastHit; class RigidBody; @@ -16,6 +17,9 @@ class RigidBody; /// /// API_CLASS(Abstract) class FLAXENGINE_API Collider : public PhysicsColliderActor +#if USE_EDITOR + , public IPhysicsDebug +#endif { API_AUTO_SERIALIZATION(); DECLARE_SCENE_OBJECT_ABSTRACT(Collider); @@ -165,9 +169,6 @@ public: void ClosestPoint(const Vector3& point, Vector3& result) const final; bool ContainsPoint(const Vector3& point) const final; -#if USE_EDITOR - virtual void DrawPhysicsDebug(RenderView& view); -#endif protected: // [PhysicsColliderActor] diff --git a/Source/Engine/Physics/Colliders/MeshCollider.h b/Source/Engine/Physics/Colliders/MeshCollider.h index e6b1b7a82..99f2980f6 100644 --- a/Source/Engine/Physics/Colliders/MeshCollider.h +++ b/Source/Engine/Physics/Colliders/MeshCollider.h @@ -37,9 +37,7 @@ public: protected: // [Collider] -#if USE_EDITOR - void DrawPhysicsDebug(RenderView& view) override; -#endif + ImplementPhysicsDebug; void UpdateBounds() override; void GetGeometry(CollisionShape& collision) override; }; diff --git a/Source/Engine/Physics/Colliders/SphereCollider.h b/Source/Engine/Physics/Colliders/SphereCollider.h index 3d9df79b3..67addf17b 100644 --- a/Source/Engine/Physics/Colliders/SphereCollider.h +++ b/Source/Engine/Physics/Colliders/SphereCollider.h @@ -42,9 +42,7 @@ public: protected: // [Collider] -#if USE_EDITOR - void DrawPhysicsDebug(RenderView& view) override; -#endif + ImplementPhysicsDebug; void UpdateBounds() override; void GetGeometry(CollisionShape& collision) override; }; diff --git a/Source/Engine/Physics/Colliders/SplineCollider.h b/Source/Engine/Physics/Colliders/SplineCollider.h index cb8f1d5ee..1e41802e5 100644 --- a/Source/Engine/Physics/Colliders/SplineCollider.h +++ b/Source/Engine/Physics/Colliders/SplineCollider.h @@ -67,9 +67,7 @@ public: protected: // [Collider] -#if USE_EDITOR - void DrawPhysicsDebug(RenderView& view) override; -#endif + ImplementPhysicsDebug; void UpdateBounds() override; void GetGeometry(CollisionShape& collision) override; }; diff --git a/Source/Engine/Physics/Joints/Joint.cpp b/Source/Engine/Physics/Joints/Joint.cpp index 950f2d146..902a58796 100644 --- a/Source/Engine/Physics/Joints/Joint.cpp +++ b/Source/Engine/Physics/Joints/Joint.cpp @@ -298,7 +298,7 @@ void Joint::EndPlay() void Joint::OnEnable() { - GetSceneRendering()->AddPhysicsDebug(this); + GetSceneRendering()->AddPhysicsDebug(this); // Base Actor::OnEnable(); @@ -306,7 +306,7 @@ void Joint::OnEnable() void Joint::OnDisable() { - GetSceneRendering()->RemovePhysicsDebug(this); + GetSceneRendering()->RemovePhysicsDebug(this); // Base Actor::OnDisable(); diff --git a/Source/Engine/Physics/Joints/Joint.h b/Source/Engine/Physics/Joints/Joint.h index 7583e449d..299a66f9e 100644 --- a/Source/Engine/Physics/Joints/Joint.h +++ b/Source/Engine/Physics/Joints/Joint.h @@ -5,6 +5,7 @@ #include "Engine/Level/Actor.h" #include "Engine/Physics/Types.h" #include "Engine/Scripting/ScriptingObjectReference.h" +#include "Engine/Physics/Actors/IPhysicsDebug.h" class IPhysicsActor; @@ -17,6 +18,9 @@ class IPhysicsActor; /// /// API_CLASS(Abstract) class FLAXENGINE_API Joint : public Actor +#if USE_EDITOR + , public IPhysicsDebug +#endif { DECLARE_SCENE_OBJECT_ABSTRACT(Joint); protected: @@ -174,9 +178,7 @@ protected: Vector3 GetTargetPosition() const; Quaternion GetTargetOrientation() const; virtual void* CreateJoint(const struct PhysicsJointDesc& desc) = 0; -#if USE_EDITOR - virtual void DrawPhysicsDebug(RenderView& view); -#endif + ImplementPhysicsDebug; private: void Delete(); diff --git a/Source/Engine/Terrain/Terrain.cpp b/Source/Engine/Terrain/Terrain.cpp index ebbfd70e6..f13d3bcc4 100644 --- a/Source/Engine/Terrain/Terrain.cpp +++ b/Source/Engine/Terrain/Terrain.cpp @@ -845,7 +845,7 @@ void Terrain::OnEnable() GetScene()->Navigation.Actors.Add(this); GetSceneRendering()->AddActor(this, _sceneRenderingKey); #if TERRAIN_USE_PHYSICS_DEBUG - GetSceneRendering()->AddPhysicsDebug(this); + GetSceneRendering()->AddPhysicsDebug(this); #endif void* scene = GetPhysicsScene()->GetPhysicsScene(); for (int32 i = 0; i < _patches.Count(); i++) @@ -866,7 +866,7 @@ void Terrain::OnDisable() GetScene()->Navigation.Actors.Remove(this); GetSceneRendering()->RemoveActor(this, _sceneRenderingKey); #if TERRAIN_USE_PHYSICS_DEBUG - GetSceneRendering()->RemovePhysicsDebug(this); + GetSceneRendering()->RemovePhysicsDebug(this); #endif void* scene = GetPhysicsScene()->GetPhysicsScene(); for (int32 i = 0; i < _patches.Count(); i++) diff --git a/Source/Engine/Terrain/Terrain.h b/Source/Engine/Terrain/Terrain.h index 0b72cd668..5c671629d 100644 --- a/Source/Engine/Terrain/Terrain.h +++ b/Source/Engine/Terrain/Terrain.h @@ -5,6 +5,7 @@ #include "Engine/Content/JsonAssetReference.h" #include "Engine/Content/Assets/MaterialBase.h" #include "Engine/Physics/Actors/PhysicsColliderActor.h" +#include "Engine/Physics/Actors/IPhysicsDebug.h" class Terrain; class TerrainChunk; @@ -38,6 +39,9 @@ struct RenderView; /// /// API_CLASS(Sealed) class FLAXENGINE_API Terrain : public PhysicsColliderActor +#if USE_EDITOR + , public IPhysicsDebug +#endif { DECLARE_SCENE_OBJECT(Terrain); friend Terrain; @@ -441,9 +445,7 @@ public: API_FUNCTION() void DrawChunk(API_PARAM(Ref) const RenderContext& renderContext, API_PARAM(Ref) const Int2& patchCoord, API_PARAM(Ref) const Int2& chunkCoord, MaterialBase* material, int32 lodIndex = 0) const; private: -#if TERRAIN_USE_PHYSICS_DEBUG - void DrawPhysicsDebug(RenderView& view); -#endif + ImplementPhysicsDebug; bool DrawSetup(RenderContext& renderContext); void DrawImpl(RenderContext& renderContext, HashSet& drawnChunks);