Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
88002c3
initial skeleton for debug draw ex
keptsecret Jun 30, 2025
3df145b
use camera with lines
keptsecret Jul 1, 2025
ac56991
merge mesh_loaders
keptsecret Jul 1, 2025
6d5a495
fixes from mesh_loader merge
keptsecret Jul 1, 2025
c5dae98
removed unused files
keptsecret Jul 1, 2025
17b53a8
draw aabb from push constant
keptsecret Jul 1, 2025
a62cbed
move single aabb stuff into CDrawAABB
keptsecret Jul 1, 2025
00185f2
Merge branch 'master' into new_debug_draw
keptsecret Jul 2, 2025
5fa8874
default pipeline creation func
keptsecret Jul 2, 2025
704a0fb
got streaming buffer working and drawing
keptsecret Jul 3, 2025
a81e62f
draw with instances
keptsecret Jul 4, 2025
da63edf
minor bug fix in creating instances
keptsecret Jul 4, 2025
7469300
Merge branch 'master' into new_debug_draw
keptsecret Jul 4, 2025
9ae72f5
move handling instances to CDrawAABB
keptsecret Jul 4, 2025
7a22eef
moved most important streaming stuff to CDrawAABB
keptsecret Jul 4, 2025
f18bf38
moved most core func to CDrawAABB
keptsecret Jul 7, 2025
09ef478
handle streaming buffer overflow
keptsecret Jul 8, 2025
aee85b4
update example scene
keptsecret Jul 8, 2025
738269e
use debug draw extension
keptsecret Jul 8, 2025
c698bb7
Merge branch 'master' into new_debug_draw
keptsecret Jul 8, 2025
61b1c00
removed old mesh loaders
keptsecret Jul 8, 2025
4f1fabd
add debug aabb draws around mesh
keptsecret Jul 9, 2025
b31cfba
merge master, fix conflicts
keptsecret Aug 18, 2025
bfd286e
refactor debug_draw namespace
keptsecret Aug 18, 2025
8518c2b
refactor remove usage of legacy matrices
keptsecret Aug 19, 2025
323c782
refactor examples with latest DrawAabb changes
keptsecret Aug 20, 2025
f75dc21
use draw modes
keptsecret Aug 20, 2025
83a71a8
Merge branch 'master' into new_debug_draw
keptsecret Aug 21, 2025
fdd9b0c
Add Draw OBB to example 12
Sep 6, 2025
d35ab87
Add example 72
Sep 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion 12_MeshLoaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ endif()
# TODO; Arek I removed `NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET` from the last parameter here, doesn't this macro have 4 arguments anyway !?
nbl_create_executable_project("" "" "${NBL_INCLUDE_SERACH_DIRECTORIES}" "${NBL_LIBRARIES}")
# TODO: Arek temporarily disabled cause I haven't figured out how to make this target yet
# LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} nblExamplesGeometrySpirvBRD)
# LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} nblExamplesGeometrySpirvBRD)

if (NBL_BUILD_DEBUG_DRAW)
add_dependencies(${EXECUTABLE_NAME} ${NBL_EXT_DEBUG_DRAW_TARGET})
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${NBL_EXT_DEBUG_DRAW_TARGET})
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${NBL_EXT_DEBUG_DRAW_TARGET},INCLUDE_DIRECTORIES>)
endif()
94 changes: 88 additions & 6 deletions 12_MeshLoaders/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@
#include "nbl/ext/MitsubaLoader/CSerializedLoader.h"
#endif

#ifdef NBL_BUILD_DEBUG_DRAW
#include "nbl/ext/DebugDraw/CDrawAABB.h"
#endif

class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourcesApplication
{
using device_base_t = MonoWindowApplication;
using asset_base_t = BuiltinResourcesApplication;

enum DrawBoundingBoxMode
{
DBBM_NONE,
DBBM_AABB,
DBBM_OBB,
DBBM_COUNT
};

public:
inline MeshLoadersApp(const path& _localInputCWD, const path& _localOutputCWD, const path& _sharedInputCWD, const path& _sharedOutputCWD)
: IApplicationFramework(_localInputCWD, _localOutputCWD, _sharedInputCWD, _sharedOutputCWD),
Expand Down Expand Up @@ -48,6 +60,20 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
if (!m_renderer)
return logFail("Failed to create renderer!");

#ifdef NBL_BUILD_DEBUG_DRAW
{
auto* renderpass = scRes->getRenderpass();
ext::debug_draw::DrawAABB::SCreationParameters params = {};
params.assetManager = m_assetMgr;
params.transfer = getTransferUpQueue();
params.drawMode = ext::debug_draw::DrawAABB::ADM_DRAW_BATCH;
params.batchPipelineLayout = ext::debug_draw::DrawAABB::createDefaultPipelineLayout(m_device.get());
params.renderpass = smart_refctd_ptr<IGPURenderpass>(renderpass);
params.utilities = m_utils;
m_drawAABB = ext::debug_draw::DrawAABB::create(std::move(params));
}
#endif

//
if (!reloadModel())
return false;
Expand Down Expand Up @@ -109,8 +135,14 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
keyboard.consumeEvents([&](const IKeyboardEventChannel::range_t& events) -> void
{
for (const auto& event : events)
if (event.keyCode==E_KEY_CODE::EKC_R && event.action==SKeyboardEvent::ECA_RELEASED)
reload = true;
{
if (event.keyCode == E_KEY_CODE::EKC_R && event.action == SKeyboardEvent::ECA_RELEASED)
reload = true;
if (event.keyCode == E_KEY_CODE::EKC_B && event.action == SKeyboardEvent::ECA_RELEASED)
{
m_drawBBMode = DrawBoundingBoxMode((m_drawBBMode + 1) % DBBM_COUNT);
}
}
camera.keyboardProcess(events);
},
m_logger.get()
Expand All @@ -120,16 +152,23 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
reloadModel();
}
// draw scene
float32_t3x4 viewMatrix;
float32_t4x4 viewProjMatrix;
{
float32_t3x4 viewMatrix;
float32_t4x4 viewProjMatrix;
// TODO: get rid of legacy matrices
{
memcpy(&viewMatrix,camera.getViewMatrix().pointer(),sizeof(viewMatrix));
memcpy(&viewProjMatrix,camera.getConcatenatedMatrix().pointer(),sizeof(viewProjMatrix));
}
m_renderer->render(cb,CSimpleDebugRenderer::SViewParams(viewMatrix,viewProjMatrix));
}
#ifdef NBL_BUILD_DEBUG_DRAW
if (m_drawBBMode != DBBM_NONE)
{
const ISemaphore::SWaitInfo drawFinished = { .semaphore = m_semaphore.get(),.value = m_realFrameIx + 1u };
m_drawAABB->render(cb, drawFinished, m_drawBBMode == DBBM_OBB ? m_obbInstances : m_aabbInstances, viewProjMatrix);
}
#endif
cb->endRenderPass();
}
cb->end();
Expand Down Expand Up @@ -349,7 +388,7 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
return false;
}
}

auto tmp = hlsl::float32_t4x3(
hlsl::float32_t3(1,0,0),
hlsl::float32_t3(0,1,0),
Expand All @@ -358,16 +397,51 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
);
core::vector<hlsl::float32_t3x4> worldTforms;
const auto& converted = reservation.getGPUObjects<ICPUPolygonGeometry>();
for (const auto& geom : converted)
m_aabbInstances.resize(converted.size());
m_obbInstances.resize(converted.size());
for (uint32_t i = 0; i < converted.size(); i++)
{
const auto& geom = converted[i];
const auto promoted = geom.value->getAABB<aabb_t>();
printAABB(promoted,"Geometry");
tmp[3].x += promoted.getExtent().x;
const auto promotedWorld = hlsl::float64_t3x4(worldTforms.emplace_back(hlsl::transpose(tmp)));
const auto transformed = hlsl::shapes::util::transform(promotedWorld,promoted);
printAABB(transformed,"Transformed");
bound = hlsl::shapes::util::union_(transformed,bound);
const auto tmpWorld = hlsl::float32_t3x4(promotedWorld);
const auto world4x4 = float32_t4x4{
tmpWorld[0],
tmpWorld[1],
tmpWorld[2],
float32_t4(0, 0, 0, 1)
};

#ifdef NBL_BUILD_DEBUG_DRAW

auto& aabbInst = m_aabbInstances[i];
const auto tmpAabb = shapes::AABB<3,float>(promoted.minVx, promoted.maxVx);
hlsl::float32_t4x4 aabbTransform = ext::debug_draw::DrawAABB::getTransformFromAABB(tmpAabb);
aabbInst.color = { 1,1,1,1 };
aabbInst.transform = hlsl::mul(world4x4, aabbTransform);

auto& obbInst = m_obbInstances[i];
const auto& cpuGeom = geometries[i].get();
const auto obb = CPolygonGeometryManipulator::calculateOBB({
.fetch = [geo = cpuGeom, &world4x4](size_t vertex_i) {
hlsl::float32_t3 pt;
geo->getPositionView().decodeElement(vertex_i, pt);
return pt;
},
.size = cpuGeom->getPositionView().getElementCount(),
});
obbInst.color = { 0, 0, 1, 1 };
const auto obbTransform = ext::debug_draw::DrawAABB::getTransformFromOBB(obb);
obbInst.transform = hlsl::mul(world4x4, obbTransform);

#endif
}

printAABB(bound,"Total");
if (!m_renderer->addGeometries({ &converted.front().get(),converted.size() }))
return false;
Expand Down Expand Up @@ -416,6 +490,14 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), core::matrix4SIMD());
// mutables
std::string m_modelPath;

DrawBoundingBoxMode m_drawBBMode;
#ifdef NBL_BUILD_DEBUG_DRAW
smart_refctd_ptr<ext::debug_draw::DrawAABB> m_drawAABB;
std::vector<ext::debug_draw::InstanceData> m_aabbInstances;
std::vector<ext::debug_draw::InstanceData> m_obbInstances;

#endif
};

NBL_MAIN_FUNC(MeshLoadersApp)
11 changes: 11 additions & 0 deletions 34_DebugDraw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if(NBL_BUILD_DEBUG_DRAW)
set(NBL_INCLUDE_SERACH_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)

nbl_create_executable_project("${NBL_EXTRA_SOURCES}" "" "${NBL_INCLUDE_SERACH_DIRECTORIES}" "" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}")

add_dependencies(${EXECUTABLE_NAME} ${NBL_EXT_DEBUG_DRAW_TARGET})
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${NBL_EXT_DEBUG_DRAW_TARGET})
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${NBL_EXT_DEBUG_DRAW_TARGET},INCLUDE_DIRECTORIES>)
endif()
28 changes: 28 additions & 0 deletions 34_DebugDraw/config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"enableParallelBuild": true,
"threadsPerBuildProcess" : 2,
"isExecuted": false,
"scriptPath": "",
"cmake": {
"configurations": [ "Release", "Debug", "RelWithDebInfo" ],
"buildModes": [],
"requiredOptions": []
},
"profiles": [
{
"backend": "vulkan",
"platform": "windows",
"buildModes": [],
"runConfiguration": "Release",
"gpuArchitectures": []
}
],
"dependencies": [],
"data": [
{
"dependencies": [],
"command": [""],
"outputs": []
}
]
}
23 changes: 23 additions & 0 deletions 34_DebugDraw/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef __NBL_THIS_EXAMPLE_COMMON_H_INCLUDED__
#define __NBL_THIS_EXAMPLE_COMMON_H_INCLUDED__

#include <nabla.h>

#include "nbl/examples/cameras/CCamera.hpp"
#include "nbl/examples/common/SimpleWindowedApplication.hpp"
#include "nbl/examples/common/CEventCallback.hpp"
#include "nbl/examples/examples.hpp"

//#include "nbl/CDrawAABB.h"
#include "nbl/ext/DebugDraw/CDrawAABB.h"

using namespace nbl;
using namespace core;
using namespace hlsl;
using namespace system;
using namespace asset;
using namespace ui;
using namespace video;
using namespace nbl::examples;

#endif // __NBL_THIS_EXAMPLE_COMMON_H_INCLUDED__
Loading