mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
WIP: introduce Part component
This commit is contained in:
@@ -47,12 +47,17 @@ namespace vis {
|
||||
tc::Group group;
|
||||
VectorRf root;
|
||||
|
||||
std::vector<typename Hull<Grade>::Tiling> tilings{};
|
||||
std::vector<char> enabled{};
|
||||
std::vector<Eigen::Vector3f> colors{};
|
||||
|
||||
Affine transform = Affine::Identity();
|
||||
|
||||
struct Part {
|
||||
GLuint first;
|
||||
GLuint count;
|
||||
Color color = Color::Ones();
|
||||
bool enabled = true;
|
||||
};
|
||||
|
||||
std::vector<entt::entity> parts{};
|
||||
|
||||
explicit Structure(
|
||||
tc::Group group,
|
||||
VectorRf root
|
||||
|
||||
@@ -110,16 +110,20 @@ void show_overlay(State &state) {
|
||||
}
|
||||
|
||||
void show_options(entt::registry ®istry) {
|
||||
auto view = registry.view<vis::Structure<5, 4, 4>>();
|
||||
using Slice = vis::Structure<5, 4, 4>;
|
||||
auto view = registry.view<Slice>();
|
||||
|
||||
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<Slice::Part>(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<vis::VBOs<Slice>>(entity);
|
||||
|
||||
vis::upload_structure<Slice>(registry);
|
||||
registry.get<Slice>(entity).enabled[0] = false; // disable {0,1,2} cells
|
||||
registry.get<Slice::Part>(
|
||||
registry.get<Slice>(entity).parts[0]
|
||||
).enabled = false;
|
||||
// registry.get<Slice>(entity).enabled[0] = false; // disable {0,1,2} cells
|
||||
|
||||
auto ubo = cgl::Buffer<Matrices>();
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
||||
|
||||
@@ -27,15 +27,27 @@ namespace vis {
|
||||
Points points(structure.group, structure.root);
|
||||
Hull<Str::Grade> 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<typename Str::Part>(
|
||||
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<Str, VBOs<Str>>();
|
||||
|
||||
for (auto [entity, structure, vbos]: view.each()) {
|
||||
auto colors = structure.colors;
|
||||
std::vector<typename Str::Color> colors;
|
||||
for (const auto &part_entity: structure.parts) {
|
||||
const auto &part = registry.get<typename Str::Part>(part_entity);
|
||||
colors.push_back(part.color);
|
||||
}
|
||||
vbos.colors.put(colors.begin(), colors.end());
|
||||
|
||||
typename VBOs<Str>::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<Str, VBOs<Str>>();
|
||||
|
||||
for (auto [entity, structure, vbos]: view.each()) {
|
||||
const auto &tilings = structure.tilings;
|
||||
|
||||
std::vector<typename VBOs<Str>::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<typename Str::Part>(part_entity);
|
||||
if (part.enabled) {
|
||||
commands.push_back(
|
||||
{
|
||||
part.count,
|
||||
1,
|
||||
part.first,
|
||||
idx
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user