feat(physics): debug-draw character controller capsule

CharacterVirtual is not a registered body, so PhysicsSystem::DrawBodies
never renders it (Jolt provides no CharacterVirtual::DebugDraw either).
Add CharacterController::DebugDraw (shape wireframe at foot-origin +
shapeOffset, green) and drive it from CollectDebugData under the
colliders bit.
This commit is contained in:
2026-10-03 19:01:57 +08:00
parent 29c413579d
commit 134812dae3
3 changed files with 27 additions and 0 deletions
@@ -59,6 +59,10 @@ namespace Engine {
const Params& GetParams() const { return m_Params; } const Params& GetParams() const { return m_Params; }
// 调试渲染:非 body,PhysicsSystem::DrawBodies 画不到,须手动
// (脚本在物理位姿/脚底原点处画胶囊线框)
void DebugDraw(JPH::DebugRenderer& renderer) const;
private: private:
Params m_Params; Params m_Params;
JPH::Ref<JPH::CharacterVirtual> m_Character; JPH::Ref<JPH::CharacterVirtual> m_Character;
@@ -5,6 +5,10 @@
#include <Engine/Physics/CharacterController.h> #include <Engine/Physics/CharacterController.h>
#include <Jolt/Physics/Collision/Shape/CapsuleShape.h> #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
#include <Jolt/Physics/PhysicsSystem.h>
#include <Jolt/Physics/Body/Body.h>
#include <Jolt/Physics/Collision/Shape/Shape.h>
#include <Jolt/Renderer/DebugRenderer.h>
namespace Engine { namespace Engine {
@@ -85,4 +89,15 @@ namespace Engine {
JPH::RVec3(position.x, position.y, position.z)); JPH::RVec3(position.x, position.y, position.z));
} }
void CharacterController::DebugDraw(JPH::DebugRenderer &renderer) const {
// 胶囊中心 = 脚底原点 + shapeOffset(角色不旋转,纯平移)。
// CharacterVirtual 非 body,DrawBodies 永远画不到它——这是
// Jolt 层面的缺口(连 CharacterVirtual::DebugDraw 都没有)
const JPH::RMat44 t = JPH::RMat44::sTranslation(
m_Character->GetPosition() +
JPH::RVec3(m_Character->GetShapeOffset()));
m_Character->GetShape()->Draw(&renderer, t, JPH::Vec3::sOne(),
JPH::Color::sGreen, false, true);
}
} // namespace Engine } // namespace Engine
+8
View File
@@ -326,6 +326,14 @@ namespace Engine {
} }
} }
// 4) 角色控制器:CharacterVirtual 非 body,DrawBodies 画不到,
// 手动画胶囊线框(绿 = 与普通 collider 区分)
if ((m_DebugBits & kPhyDbgColliders) != 0) {
for (auto &[bits, entry] : m_Characters) {
entry.cc->DebugDraw(*m_DebugDraw);
}
}
// 释放上一帧缓存不再引用的通用几何 batch(DebugRenderer 内部池) // 释放上一帧缓存不再引用的通用几何 batch(DebugRenderer 内部池)
m_DebugDraw->NextFrame(); m_DebugDraw->NextFrame();
} }