Skip to content

Commit 29cb9d2

Browse files
committed
add debug draw bounding box for render nodes
1 parent 79db698 commit 29cb9d2

5 files changed

Lines changed: 49 additions & 3 deletions

File tree

src/Application/gkNextRenderer/gkNextRenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ void NextRendererGameInstance::DrawSettings()
567567
ImGui::Checkbox(LOCTEXT("TickPhysics"), &userSetting.TickPhysics);
568568
ImGui::Checkbox(LOCTEXT("DebugDraw"), &userSetting.ShowVisualDebug);
569569
ImGui::Checkbox(LOCTEXT("DebugDraw_Lighting"), &userSetting.DebugDraw_Lighting);
570+
ImGui::Checkbox(LOCTEXT("DebugDraw_BoundingBox"), &userSetting.DebugDraw_BoundingBox);
570571
ImGui::Checkbox(LOCTEXT("DisableSpatialReuse"), &userSetting.DisableSpatialReuse);
571572

572573
ImGui::SliderFloat(LOCTEXT("Time Scaling"), &userSetting.HeatmapScale, 0.10f, 2.0f, "%.2f", ImGuiSliderFlags_Logarithmic);

src/Assets/Model.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ namespace Assets
141141
const std::vector<glm::uvec4>& CPUJoints() const { return joints_; }
142142
std::vector<glm::uvec4>& CPUJoints() { return joints_; }
143143

144-
glm::vec3 GetLocalAABBMin() {return local_aabb_min;}
145-
glm::vec3 GetLocalAABBMax() {return local_aabb_max;}
144+
glm::vec3 GetLocalAABBMin() const {return local_aabb_min;}
145+
glm::vec3 GetLocalAABBMax() const {return local_aabb_max;}
146146

147147
uint32_t NumberOfVertices() const { return verticeCount; }
148148
uint32_t NumberOfIndices() const { return indiceCount; }

src/Assets/Scene.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Runtime/Components/RenderComponent.h"
1515
#include "Runtime/Components/PhysicsComponent.h"
1616
#include "Runtime/Engine.hpp"
17+
#include "Runtime/NextEngineHelper.h"
1718
#include "Runtime/Components/SkinnedMeshComponent.h"
1819

1920
#include <spdlog/spdlog.h>
@@ -559,6 +560,48 @@ namespace Assets
559560
}
560561
}
561562

563+
if (NextEngine::GetInstance()->GetUserSettings().DebugDraw_BoundingBox)
564+
{
565+
for (auto& node : nodes_)
566+
{
567+
auto render = node->GetComponent<Runtime::RenderComponent>();
568+
if (!render || !render->IsVisible() || !render->IsDrawable())
569+
{
570+
continue;
571+
}
572+
573+
const Model* model = GetModel(render->GetModelId());
574+
if (!model)
575+
{
576+
continue;
577+
}
578+
579+
glm::vec3 localaabbMin = model->GetLocalAABBMin();
580+
glm::vec3 localaabbMax = model->GetLocalAABBMax();
581+
582+
const auto& worldMtx = node->WorldTransform();
583+
glm::vec3 corners[8];
584+
corners[0] = glm::vec3(worldMtx * glm::vec4(localaabbMin.x, localaabbMin.y, localaabbMin.z, 1.0f));
585+
corners[1] = glm::vec3(worldMtx * glm::vec4(localaabbMax.x, localaabbMin.y, localaabbMin.z, 1.0f));
586+
corners[2] = glm::vec3(worldMtx * glm::vec4(localaabbMin.x, localaabbMax.y, localaabbMin.z, 1.0f));
587+
corners[3] = glm::vec3(worldMtx * glm::vec4(localaabbMax.x, localaabbMax.y, localaabbMin.z, 1.0f));
588+
corners[4] = glm::vec3(worldMtx * glm::vec4(localaabbMin.x, localaabbMin.y, localaabbMax.z, 1.0f));
589+
corners[5] = glm::vec3(worldMtx * glm::vec4(localaabbMax.x, localaabbMin.y, localaabbMax.z, 1.0f));
590+
corners[6] = glm::vec3(worldMtx * glm::vec4(localaabbMin.x, localaabbMax.y, localaabbMax.z, 1.0f));
591+
corners[7] = glm::vec3(worldMtx * glm::vec4(localaabbMax.x, localaabbMax.y, localaabbMax.z, 1.0f));
592+
593+
glm::vec3 worldAABBMin = corners[0];
594+
glm::vec3 worldAABBMax = corners[0];
595+
for (int i = 1; i < 8; ++i)
596+
{
597+
worldAABBMin = glm::min(worldAABBMin, corners[i]);
598+
worldAABBMax = glm::max(worldAABBMax, corners[i]);
599+
}
600+
601+
NextEngineHelper::DrawAuxBox(worldAABBMin, worldAABBMax, glm::vec4(0.2f, 0.8f, 1.0f, 1.0f), 1.5f);
602+
}
603+
}
604+
562605
if ( NextEngine::GetInstance()->GetTotalFrames() % 10 == 0 )
563606
{
564607
// if (sceneDirtyForCpuAS_)
@@ -755,4 +798,4 @@ namespace Assets
755798
skinnedVerticesSimpleAddr_ = skinnedVerticesSimple;
756799
jointMatricesAddr_ = jointMatrices;
757800
}
758-
}
801+
}

src/Runtime/Engine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ UserSettings CreateUserSettings(const Options& options)
132132

133133
userSettings.ShowVisualDebug = false;
134134
userSettings.HeatmapScale = 1.0f;
135+
userSettings.DebugDraw_BoundingBox = false;
135136

136137
userSettings.UseCheckerBoardRendering = false;
137138
userSettings.TemporalFrames = options.Temporal;

src/Runtime/UserSettings.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct UserSettings final
2121
bool FastGather = false;
2222
bool FastInterpole = false;
2323
bool DebugDraw_Lighting = false;
24+
bool DebugDraw_BoundingBox = false;
2425
bool DisableSpatialReuse = false;
2526
uint32_t SuperResolution = 1;
2627
bool DLSS = false;

0 commit comments

Comments
 (0)