mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
WIP: introduce Part component
This commit is contained in:
@@ -47,12 +47,17 @@ namespace vis {
|
|||||||
tc::Group group;
|
tc::Group group;
|
||||||
VectorRf root;
|
VectorRf root;
|
||||||
|
|
||||||
std::vector<typename Hull<Grade>::Tiling> tilings{};
|
|
||||||
std::vector<char> enabled{};
|
|
||||||
std::vector<Eigen::Vector3f> colors{};
|
|
||||||
|
|
||||||
Affine transform = Affine::Identity();
|
Affine transform = Affine::Identity();
|
||||||
|
|
||||||
|
struct Part {
|
||||||
|
GLuint first;
|
||||||
|
GLuint count;
|
||||||
|
Color color = Color::Ones();
|
||||||
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<entt::entity> parts{};
|
||||||
|
|
||||||
explicit Structure(
|
explicit Structure(
|
||||||
tc::Group group,
|
tc::Group group,
|
||||||
VectorRf root
|
VectorRf root
|
||||||
|
|||||||
@@ -110,16 +110,20 @@ void show_overlay(State &state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void show_options(entt::registry ®istry) {
|
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()) {
|
for (auto [entity, structure]: view.each()) {
|
||||||
ImGui::Begin("Structure View Options");
|
ImGui::Begin("Structure View Options");
|
||||||
|
|
||||||
for (int i = 0; i < structure.tilings.size(); ++i) {
|
for (int idx = 0; idx < structure.parts.size(); ++idx) {
|
||||||
std::string label = fmt::format("{}", i);
|
const auto &part_entity = structure.parts[idx];
|
||||||
|
auto &part = registry.get<Slice::Part>(part_entity);
|
||||||
|
|
||||||
ImGui::Checkbox(label.c_str(), (bool*) (&(structure.enabled[i])));
|
std::string label = fmt::format("{}", idx);
|
||||||
ImGui::ColorEdit3(label.c_str(), structure.colors[i].data(), ImGuiColorEditFlags_NoLabel);
|
|
||||||
|
ImGui::Checkbox(label.c_str(), (bool*) (&(part.enabled)));
|
||||||
|
ImGui::ColorEdit3(label.c_str(), part.color.data(), ImGuiColorEditFlags_NoLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
@@ -164,7 +168,10 @@ int run(GLFWwindow* window, ImGuiContext* ctx) {
|
|||||||
registry.emplace<vis::VBOs<Slice>>(entity);
|
registry.emplace<vis::VBOs<Slice>>(entity);
|
||||||
|
|
||||||
vis::upload_structure<Slice>(registry);
|
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>();
|
auto ubo = cgl::Buffer<Matrices>();
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
||||||
|
|||||||
@@ -27,15 +27,27 @@ namespace vis {
|
|||||||
Points points(structure.group, structure.root);
|
Points points(structure.group, structure.root);
|
||||||
Hull<Str::Grade> hull(structure.group);
|
Hull<Str::Grade> hull(structure.group);
|
||||||
|
|
||||||
auto vertices = points.verts.colwise();
|
registry.destroy(structure.parts.begin(), structure.parts.end());
|
||||||
auto indices = hull.inds.colwise();
|
structure.parts.clear();
|
||||||
|
|
||||||
structure.tilings = hull.tilings;
|
for (const auto &tiling: hull.tilings) {
|
||||||
structure.enabled.resize(hull.tilings.size(), true);
|
auto part_entity = registry.create();
|
||||||
structure.colors.resize(hull.tilings.size(), vec3::Ones());
|
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.vertices.put(
|
||||||
vbos.indices.put(indices.begin(), indices.end());
|
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>>();
|
auto view = registry.view<Str, VBOs<Str>>();
|
||||||
|
|
||||||
for (auto [entity, structure, vbos]: view.each()) {
|
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{
|
typename VBOs<Str>::Uniform uniform{
|
||||||
structure.transform.linear(),
|
structure.transform.linear(),
|
||||||
structure.transform.translation(),
|
structure.transform.translation(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vbos.colors.put(colors.begin(), colors.end());
|
|
||||||
vbos.uniform.put(uniform, GL_STREAM_DRAW);
|
vbos.uniform.put(uniform, GL_STREAM_DRAW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,14 +76,20 @@ namespace vis {
|
|||||||
auto view = registry.view<Str, VBOs<Str>>();
|
auto view = registry.view<Str, VBOs<Str>>();
|
||||||
|
|
||||||
for (auto [entity, structure, vbos]: view.each()) {
|
for (auto [entity, structure, vbos]: view.each()) {
|
||||||
const auto &tilings = structure.tilings;
|
|
||||||
|
|
||||||
std::vector<typename VBOs<Str>::Command> commands;
|
std::vector<typename VBOs<Str>::Command> commands;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tilings.size(); ++i) {
|
for (unsigned int idx = 0; idx < structure.parts.size(); idx++) {
|
||||||
if (structure.enabled[i]) {
|
const auto &part_entity = structure.parts[idx];
|
||||||
auto [first, count] = tilings[i];
|
const auto &part = registry.get<typename Str::Part>(part_entity);
|
||||||
commands.push_back({(unsigned int) count, 1, (unsigned int) first, i});
|
if (part.enabled) {
|
||||||
|
commands.push_back(
|
||||||
|
{
|
||||||
|
part.count,
|
||||||
|
1,
|
||||||
|
part.first,
|
||||||
|
idx
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user