Skip to content

Commit 7e9df0d

Browse files
authored
Merge pull request #89 from Simple-Robotics/next
Improvements to GUI reporting and interactivity for debug elements
2 parents eaa1180 + 1239139 commit 7e9df0d

18 files changed

+157
-77
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- bindings/python : add expose-debug.cpp, expose DebugMeshComponent
13+
1014
### Changed
1115

1216
- slightly rework file dialog GUI
17+
- core/DebugScene : make setupPipelines() private, do not use optional
18+
- multibody/Visualizer/GUI : display info for robot debug frames
1319

1420
### Fixed
1521

bindings/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ find_package(eigenpy 3.2.0 REQUIRED)
77

88
set(
99
pycandlewick_SOURCES
10+
src/expose-debug.cpp
1011
src/expose-mesh-data.cpp
1112
src/expose-renderer.cpp
1213
src/module.cpp
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "fwd.hpp"
2+
#include "candlewick/core/DebugScene.h"
3+
4+
#include <eigenpy/std-vector.hpp>
5+
6+
using namespace candlewick;
7+
8+
void exposeDebug() {
9+
#define _c(name) value(#name, DebugPipelines::name)
10+
bp::enum_<DebugPipelines>("DebugPipelines")
11+
._c(TRIANGLE_FILL)
12+
._c(TRIANGLE_LINE);
13+
#undef _c
14+
15+
bp::class_<DebugMeshComponent, boost::noncopyable>("DebugMeshComponent",
16+
bp::no_init)
17+
.def_readwrite("pipeline_type", &DebugMeshComponent::pipeline_type)
18+
.def_readonly("colors", &DebugMeshComponent::colors)
19+
.def_readonly("enable", &DebugMeshComponent::enable)
20+
.def_readwrite("scale", &DebugMeshComponent::scale, "Debug model scale.");
21+
22+
eigenpy::StdVectorPythonVisitor<std::vector<Float4>>::expose("StdVec_Vec4");
23+
}

bindings/python/src/expose-renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(adfs_overloads,
99
void exposeRenderer() {
1010
bp::class_<Device, boost::noncopyable>("Device", bp::no_init)
1111
.def("driverName", &Device::driverName, ("self"_a))
12-
.def("shaderFormats", &Device::shaderFormats);
12+
.def("shaderFormats", &Device::shaderFormats, ("self"_a));
1313

1414
bp::def("get_num_gpu_drivers", SDL_GetNumGPUDrivers,
1515
"Get number of available GPU drivers.");

bindings/python/src/expose-visualizer.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
#include <pinocchio/multibody/model.hpp>
99
#include <pinocchio/multibody/geometry.hpp>
1010

11+
using namespace candlewick;
1112
using namespace candlewick::multibody;
1213

1314
#define DEF_PROP_PROXY(name) \
1415
add_property(#name, bp::make_function( \
1516
+[](Visualizer &v) -> auto & { return v.name(); }, \
1617
bp::return_internal_reference<>()))
1718

19+
static auto visualizer_get_frame_debugs(Visualizer &viz) {
20+
auto view = viz.registry.view<DebugMeshComponent, const PinFrameComponent>();
21+
bp::list out;
22+
view.each([&](auto &dmc, auto) { out.append(boost::ref(dmc)); });
23+
return out;
24+
}
25+
1826
void exposeVisualizer() {
1927
using pinocchio::python::VisualizerPythonVisitor;
2028

@@ -34,9 +42,7 @@ void exposeVisualizer() {
3442
.def(VisualizerPythonVisitor<Visualizer>{})
3543
.def_readonly("renderer", &Visualizer::renderer)
3644
.def_readwrite("worldSceneBounds", &Visualizer::worldSceneBounds)
37-
.add_property("device",
38-
bp::make_function(&Visualizer::device,
39-
bp::return_internal_reference<>()))
45+
.DEF_PROP_PROXY(device)
4046
.def(
4147
"takeScreenshot",
4248
+[](Visualizer &viz, const std::string &filename) {
@@ -69,6 +75,9 @@ void exposeVisualizer() {
6975
"by ID.")
7076
.def("removeFramesViz", &Visualizer::removeFramesViz, ("self"_a),
7177
"Remove visualization for all frames.")
78+
.def("getDebugFrames", &visualizer_get_frame_debugs, ("self"_a),
79+
"Get the DebugMeshComponent objects associated with the current "
80+
"debug frames.")
7281
// fix for Pinocchio 3.5.0
7382
#if PINOCCHIO_VERSION_AT_MOST(3, 5, 0)
7483
.DEF_PROP_PROXY(model)

bindings/python/src/module.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using namespace candlewick;
88

99
void exposeMeshData();
1010
void exposeRenderer();
11+
void exposeDebug();
1112
#ifdef CANDLEWICK_WITH_FFMPEG_SUPPORT
1213
void exposeVideoRecorder();
1314
#endif
@@ -40,6 +41,7 @@ BOOST_PYTHON_MODULE(pycandlewick) {
4041

4142
exposeMeshData();
4243
exposeRenderer();
44+
exposeDebug();
4345
#ifdef CANDLEWICK_WITH_FFMPEG_SUPPORT
4446
exposeVideoRecorder();
4547
#endif

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ add_library(
1111
candlewick/core/Device.cpp
1212
candlewick/core/math_util.cpp
1313
candlewick/core/errors.cpp
14-
candlewick/core/FileDialogGui.cpp
14+
candlewick/core/file_dialog_gui.cpp
1515
candlewick/core/GuiSystem.cpp
1616
candlewick/core/Mesh.cpp
1717
candlewick/core/RenderContext.cpp

src/candlewick/core/DebugScene.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,30 @@ DebugScene::DebugScene(DebugScene &&other)
2727
std::tuple<entt::entity, DebugMeshComponent &>
2828
DebugScene::addTriad(const Float3 &scale) {
2929
auto triad_datas = loadTriadSolid();
30-
std::vector<GpuVec4> triad_colors(3);
30+
std::vector<Float4> triad_colors(3);
3131
Mesh triad = createMeshFromBatch(device(), triad_datas, true);
3232
for (size_t i = 0; i < 3; i++) {
3333
triad_colors[i] = triad_datas[i].material.baseColor;
3434
}
3535
setupPipelines(triad.layout());
36-
auto entity = m_registry.create();
36+
entt::entity entity = m_registry.create();
3737
auto &item = m_registry.emplace<DebugMeshComponent>(
38-
entity, DebugPipelines::TRIANGLE_FILL, std::move(triad), triad_colors);
39-
item.scale = scale;
38+
entity, DebugPipelines::TRIANGLE_FILL, std::move(triad), triad_colors,
39+
true, scale);
4040
m_registry.emplace<TransformComponent>(entity, Mat4f::Identity());
4141
return {entity, item};
4242
}
4343

4444
std::tuple<entt::entity, DebugMeshComponent &>
45-
DebugScene::addLineGrid(std::optional<Float4> color) {
45+
DebugScene::addLineGrid(const Float4 &color) {
4646
auto grid_data = loadGrid(20);
4747
Mesh grid = createMesh(device(), grid_data, true);
48-
GpuVec4 grid_color = color.value_or(grid_data.material.baseColor);
4948

5049
setupPipelines(grid.layout());
5150
auto entity = m_registry.create();
5251
auto &item = m_registry.emplace<DebugMeshComponent>(
53-
entity, DebugPipelines::LINE, std::move(grid), std::vector{grid_color});
52+
entity, DebugPipelines::TRIANGLE_LINE, std::move(grid),
53+
std::vector{color});
5454
m_registry.emplace<TransformComponent>(entity, Mat4f::Identity());
5555
return {entity, item};
5656
}
@@ -124,7 +124,7 @@ void DebugScene::render(CommandBuffer &cmdBuf, const Camera &camera) const {
124124
case DebugPipelines::TRIANGLE_FILL:
125125
SDL_BindGPUGraphicsPipeline(render_pass, m_trianglePipeline);
126126
break;
127-
case DebugPipelines::LINE:
127+
case DebugPipelines::TRIANGLE_LINE:
128128
SDL_BindGPUGraphicsPipeline(render_pass, m_linePipeline);
129129
break;
130130
}

src/candlewick/core/DebugScene.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
#include "RenderContext.h"
66
#include "math_types.h"
77

8-
#include <optional>
98
#include <entt/entity/registry.hpp>
109
#include <entt/signal/sigh.hpp>
1110

1211
namespace candlewick {
1312

1413
enum class DebugPipelines {
1514
TRIANGLE_FILL,
16-
LINE,
15+
TRIANGLE_LINE,
1716
};
1817

1918
class DebugScene;
@@ -33,21 +32,26 @@ struct IDebugSubSystem {
3332
struct DebugMeshComponent {
3433
DebugPipelines pipeline_type;
3534
Mesh mesh;
36-
std::vector<GpuVec4> colors;
35+
std::vector<Float4> colors;
3736
bool enable = true;
3837
Float3 scale = Float3::Ones();
3938
};
4039

4140
/// \brief %Scene for organizing debug entities and render systems.
4241
///
4342
/// This implements a basic render system for DebugMeshComponent.
43+
///
44+
/// This scene and all subsystems are assumed to use the same shaders and
45+
/// pipelines.
4446
class DebugScene {
4547
entt::registry &m_registry;
4648
const RenderContext &m_renderer;
4749
SDL_GPUGraphicsPipeline *m_trianglePipeline{nullptr};
4850
SDL_GPUGraphicsPipeline *m_linePipeline{nullptr};
4951
std::vector<std::unique_ptr<IDebugSubSystem>> m_subsystems;
5052

53+
void setupPipelines(const MeshLayout &layout);
54+
5155
public:
5256
enum { TRANSFORM_SLOT = 0 };
5357
enum { COLOR_SLOT = 0 };
@@ -70,15 +74,14 @@ class DebugScene {
7074
return static_cast<System &>(*p);
7175
}
7276

73-
/// \brief Setup pipelines; this will only have an effect **ONCE**.
74-
void setupPipelines(const MeshLayout &layout);
75-
7677
/// \brief Just the basic 3D triad.
7778
std::tuple<entt::entity, DebugMeshComponent &>
7879
addTriad(const Float3 &scale = Float3::Ones());
80+
7981
/// \brief Add a basic line grid.
82+
/// \param color Grid color.
8083
std::tuple<entt::entity, DebugMeshComponent &>
81-
addLineGrid(std::optional<Float4> color = std::nullopt);
84+
addLineGrid(const Float4 &color = Float4::Ones());
8285

8386
void update() {
8487
for (auto &system : m_subsystems) {

src/candlewick/core/DepthAndShadowPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ ShadowMapPass::ShadowMapPass(const Device &device, const MeshLayout &layout,
153153
.props = 0,
154154
};
155155

156+
shadowMap = Texture(device, texInfo, "Shadow atlas");
156157
this->configureAtlasRegions(config);
157158

158-
shadowMap = Texture(device, texInfo, "Shadow atlas");
159159
pipeline = create_depth_pass_pipeline(device, layout, format,
160160
{
161161
SDL_GPU_CULLMODE_FRONT,

0 commit comments

Comments
 (0)