Skip to content

ex using new debug draw aabb + added draw mesh obb in ex 12 #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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()
58 changes: 55 additions & 3 deletions 12_MeshLoaders/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#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;
Expand Down Expand Up @@ -48,6 +52,18 @@ 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::debugdraw::DrawAABB::SCreationParameters params = {};
params.assetManager = m_assetMgr;
params.pipelineLayout = ext::debugdraw::DrawAABB::createDefaultPipelineLayout(m_device.get());
params.renderpass = smart_refctd_ptr<IGPURenderpass>(renderpass);
params.utilities = m_utils;
drawAABB = ext::debugdraw::DrawAABB::create(std::move(params));
}
#endif

//
if (!reloadModel())
return false;
Expand Down Expand Up @@ -109,8 +125,12 @@ 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_drawBBs = !m_drawBBs;
}
camera.keyboardProcess(events);
},
m_logger.get()
Expand All @@ -130,6 +150,24 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
}
m_renderer->render(cb,CSimpleDebugRenderer::SViewParams(viewMatrix,viewProjMatrix));
}
#ifdef NBL_BUILD_DEBUG_DRAW
if (m_drawBBs)
{
core::matrix4SIMD modelViewProjectionMatrix;
{
const auto viewMatrix = camera.getViewMatrix();
const auto projectionMatrix = camera.getProjectionMatrix();
const auto viewProjectionMatrix = camera.getConcatenatedMatrix();

core::matrix3x4SIMD modelMatrix;
modelMatrix.setTranslation(nbl::core::vectorSIMDf(0, 0, 0, 0));
modelMatrix.setRotation(quaternion(0, 0, 0));
modelViewProjectionMatrix = core::concatenateBFollowedByA(viewProjectionMatrix, modelMatrix);
}
const ISemaphore::SWaitInfo drawFinished = { .semaphore = m_semaphore.get(),.value = m_realFrameIx + 1u };
drawAABB->render(cb, drawFinished, modelViewProjectionMatrix.pointer());
}
#endif
cb->endRenderPass();
}
cb->end();
Expand Down Expand Up @@ -349,7 +387,10 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
return false;
}
}


#ifdef NBL_BUILD_DEBUG_DRAW
drawAABB->clearAABBs();
#endif
auto tmp = hlsl::float32_t4x3(
hlsl::float32_t3(1,0,0),
hlsl::float32_t3(0,1,0),
Expand All @@ -367,6 +408,12 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
const auto transformed = hlsl::shapes::util::transform(promotedWorld,promoted);
printAABB(transformed,"Transformed");
bound = hlsl::shapes::util::union_(transformed,bound);

#ifdef NBL_BUILD_DEBUG_DRAW
const auto tmpAabb = shapes::AABB<3,float>(promoted.minVx, promoted.maxVx);
const auto tmpWorld = hlsl::float32_t3x4(promotedWorld);
drawAABB->addOBB(tmpAabb, tmpWorld, hlsl::float32_t4{ 1,1,1,1 });
#endif
}
printAABB(bound,"Total");
if (!m_renderer->addGeometries({ &converted.front().get(),converted.size() }))
Expand Down Expand Up @@ -416,6 +463,11 @@ 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;

bool m_drawBBs = true;
#ifdef NBL_BUILD_DEBUG_DRAW
smart_refctd_ptr<nbl::ext::debugdraw::DrawAABB> drawAABB;
#endif
};

NBL_MAIN_FUNC(MeshLoadersApp)
Loading