From 3792d11ae82834f78ef416ac2fa36313e76897ef Mon Sep 17 00:00:00 2001 From: David Allemang Date: Sun, 12 Feb 2023 10:36:51 -0500 Subject: [PATCH] WIP: introduce Part component --- vis/src/components.hpp | 13 ++++++---- vis/src/main.cpp | 19 ++++++++++----- vis/src/systems.hpp | 54 +++++++++++++++++++++++++++++------------- 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/vis/src/components.hpp b/vis/src/components.hpp index 323fdfc..9b991e2 100644 --- a/vis/src/components.hpp +++ b/vis/src/components.hpp @@ -47,12 +47,17 @@ namespace vis { tc::Group group; VectorRf root; - std::vector::Tiling> tilings{}; - std::vector enabled{}; - std::vector colors{}; - Affine transform = Affine::Identity(); + struct Part { + GLuint first; + GLuint count; + Color color = Color::Ones(); + bool enabled = true; + }; + + std::vector parts{}; + explicit Structure( tc::Group group, VectorRf root diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 980c65d..52d8d62 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -110,16 +110,20 @@ void show_overlay(State &state) { } void show_options(entt::registry ®istry) { - auto view = registry.view>(); + using Slice = vis::Structure<5, 4, 4>; + auto view = registry.view(); for (auto [entity, structure]: view.each()) { ImGui::Begin("Structure View Options"); - for (int i = 0; i < structure.tilings.size(); ++i) { - std::string label = fmt::format("{}", i); + for (int idx = 0; idx < structure.parts.size(); ++idx) { + const auto &part_entity = structure.parts[idx]; + auto &part = registry.get(part_entity); - ImGui::Checkbox(label.c_str(), (bool*) (&(structure.enabled[i]))); - ImGui::ColorEdit3(label.c_str(), structure.colors[i].data(), ImGuiColorEditFlags_NoLabel); + std::string label = fmt::format("{}", idx); + + ImGui::Checkbox(label.c_str(), (bool*) (&(part.enabled))); + ImGui::ColorEdit3(label.c_str(), part.color.data(), ImGuiColorEditFlags_NoLabel); } ImGui::End(); @@ -164,7 +168,10 @@ int run(GLFWwindow* window, ImGuiContext* ctx) { registry.emplace>(entity); vis::upload_structure(registry); - registry.get(entity).enabled[0] = false; // disable {0,1,2} cells + registry.get( + registry.get(entity).parts[0] + ).enabled = false; +// registry.get(entity).enabled[0] = false; // disable {0,1,2} cells auto ubo = cgl::Buffer(); glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo); diff --git a/vis/src/systems.hpp b/vis/src/systems.hpp index 99c4f1d..5bf06df 100644 --- a/vis/src/systems.hpp +++ b/vis/src/systems.hpp @@ -27,15 +27,27 @@ namespace vis { Points points(structure.group, structure.root); Hull hull(structure.group); - auto vertices = points.verts.colwise(); - auto indices = hull.inds.colwise(); + registry.destroy(structure.parts.begin(), structure.parts.end()); + structure.parts.clear(); - structure.tilings = hull.tilings; - structure.enabled.resize(hull.tilings.size(), true); - structure.colors.resize(hull.tilings.size(), vec3::Ones()); + for (const auto &tiling: hull.tilings) { + auto part_entity = registry.create(); + registry.emplace( + part_entity, + tiling.first, + tiling.count + ); + structure.parts.push_back(part_entity); + } - vbos.vertices.put(vertices.begin(), vertices.end()); - vbos.indices.put(indices.begin(), indices.end()); + vbos.vertices.put( + points.verts.colwise().begin(), + points.verts.colwise().end() + ); + vbos.indices.put( + hull.inds.colwise().begin(), + hull.inds.colwise().end() + ); } } @@ -44,13 +56,17 @@ namespace vis { auto view = registry.view>(); for (auto [entity, structure, vbos]: view.each()) { - auto colors = structure.colors; + std::vector colors; + for (const auto &part_entity: structure.parts) { + const auto &part = registry.get(part_entity); + colors.push_back(part.color); + } + vbos.colors.put(colors.begin(), colors.end()); + typename VBOs::Uniform uniform{ structure.transform.linear(), structure.transform.translation(), }; - - vbos.colors.put(colors.begin(), colors.end()); vbos.uniform.put(uniform, GL_STREAM_DRAW); } } @@ -60,14 +76,20 @@ namespace vis { auto view = registry.view>(); for (auto [entity, structure, vbos]: view.each()) { - const auto &tilings = structure.tilings; - std::vector::Command> commands; - for (unsigned int i = 0; i < tilings.size(); ++i) { - if (structure.enabled[i]) { - auto [first, count] = tilings[i]; - commands.push_back({(unsigned int) count, 1, (unsigned int) first, i}); + for (unsigned int idx = 0; idx < structure.parts.size(); idx++) { + const auto &part_entity = structure.parts[idx]; + const auto &part = registry.get(part_entity); + if (part.enabled) { + commands.push_back( + { + part.count, + 1, + part.first, + idx + } + ); } }