mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
WIP: introduce rank/dim/grade template parameters
This commit is contained in:
@@ -18,21 +18,25 @@
|
|||||||
#include <shaders.hpp>
|
#include <shaders.hpp>
|
||||||
|
|
||||||
namespace vis {
|
namespace vis {
|
||||||
template<int N>
|
template<int R_, int D_, int G_>
|
||||||
struct Structure {
|
struct Structure {
|
||||||
using Affine4f = Eigen::Transform<float, 4, Eigen::Affine>;
|
static constexpr auto Rank = R_;
|
||||||
|
static constexpr auto Dim = D_;
|
||||||
|
static constexpr auto Grade = G_;
|
||||||
|
|
||||||
using Vertex = Eigen::Vector<float, 4>;
|
using Affine = Eigen::Transform<float, Dim, Eigen::Affine>;
|
||||||
|
|
||||||
|
using Vertex = Eigen::Vector<float, Dim>;
|
||||||
using Color = Eigen::Vector<float, 3>;
|
using Color = Eigen::Vector<float, 3>;
|
||||||
using Cell = Eigen::Array<unsigned int, 4, 1>;
|
using Cell = Eigen::Array<unsigned int, Grade, 1>;
|
||||||
|
|
||||||
Points points;
|
Points points;
|
||||||
Hull<N> hull;
|
Hull <Grade> hull;
|
||||||
|
|
||||||
std::vector<char> enabled;
|
std::vector<char> enabled;
|
||||||
std::vector<Eigen::Vector3f> colors;
|
std::vector<Eigen::Vector3f> colors;
|
||||||
|
|
||||||
Affine4f transform = Affine4f::Identity();
|
Affine transform = Affine::Identity();
|
||||||
|
|
||||||
template<typename P, typename H>
|
template<typename P, typename H>
|
||||||
explicit Structure(P &&points_, H &&hull_, Color color_ = Color::Ones()):
|
explicit Structure(P &&points_, H &&hull_, Color color_ = Color::Ones()):
|
||||||
@@ -40,8 +44,7 @@ namespace vis {
|
|||||||
hull(std::forward<H>(hull_)),
|
hull(std::forward<H>(hull_)),
|
||||||
enabled(hull.tilings.size(), true),
|
enabled(hull.tilings.size(), true),
|
||||||
colors(hull.tilings.size(), color_),
|
colors(hull.tilings.size(), color_),
|
||||||
transform(Affine4f::Identity()) {
|
transform(Affine::Identity()) {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -55,15 +58,15 @@ namespace vis {
|
|||||||
unsigned int count, instanceCount, first, baseInstance;
|
unsigned int count, instanceCount, first, baseInstance;
|
||||||
};
|
};
|
||||||
|
|
||||||
cgl::Buffer<Structure<4>::Vertex> vertices;
|
cgl::Buffer<Structure<5, 4, 4>::Vertex> vertices;
|
||||||
cgl::Buffer<Structure<4>::Color> colors;
|
cgl::Buffer<Structure<5, 4, 4>::Color> colors;
|
||||||
cgl::Buffer<Structure<4>::Cell> indices;
|
cgl::Buffer<Structure<5, 4, 4>::Cell> indices;
|
||||||
cgl::Buffer<Uniform> uniform;
|
cgl::Buffer<Uniform> uniform;
|
||||||
cgl::Buffer<Command> commands;
|
cgl::Buffer<Command> commands;
|
||||||
};
|
};
|
||||||
|
|
||||||
void upload_structure(entt::registry ®istry) {
|
void upload_structure(entt::registry ®istry) {
|
||||||
auto view = registry.view<Structure<4>, VBOs>();
|
auto view = registry.view<Structure<5, 4, 4>, VBOs>();
|
||||||
|
|
||||||
for (auto [entity, structure, vbos]: view.each()) {
|
for (auto [entity, structure, vbos]: view.each()) {
|
||||||
auto vertices = structure.points.verts.colwise();
|
auto vertices = structure.points.verts.colwise();
|
||||||
@@ -75,7 +78,7 @@ namespace vis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void upload_uniforms(entt::registry ®istry) {
|
void upload_uniforms(entt::registry ®istry) {
|
||||||
auto view = registry.view<Structure<4>, VBOs>();
|
auto view = registry.view<Structure<5, 4, 4>, VBOs>();
|
||||||
|
|
||||||
for (auto [entity, structure, vbos]: view.each()) {
|
for (auto [entity, structure, vbos]: view.each()) {
|
||||||
auto colors = structure.colors;
|
auto colors = structure.colors;
|
||||||
@@ -90,7 +93,7 @@ namespace vis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void upload_commands(entt::registry ®istry) {
|
void upload_commands(entt::registry ®istry) {
|
||||||
auto view = registry.view<Structure<4>, VBOs>();
|
auto view = registry.view<Structure<5, 4, 4>, VBOs>();
|
||||||
|
|
||||||
for (auto [entity, structure, vbos]: view.each()) {
|
for (auto [entity, structure, vbos]: view.each()) {
|
||||||
const auto &tilings = structure.hull.tilings;
|
const auto &tilings = structure.hull.tilings;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ void show_overlay(State &state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void show_options(entt::registry ®istry) {
|
void show_options(entt::registry ®istry) {
|
||||||
auto view = registry.view<vis::Structure<4>>();
|
auto view = registry.view<vis::Structure<5, 4, 4>>();
|
||||||
|
|
||||||
for (auto [entity, structure]: view.each()) {
|
for (auto [entity, structure]: view.each()) {
|
||||||
ImGui::Begin("Structure View Options");
|
ImGui::Begin("Structure View Options");
|
||||||
@@ -153,16 +153,18 @@ int run(GLFWwindow* window, ImGuiContext* ctx) {
|
|||||||
auto ®istry = state.registry;
|
auto ®istry = state.registry;
|
||||||
state.dimension = 4;
|
state.dimension = 4;
|
||||||
|
|
||||||
|
using Slice = vis::Structure<5, 4, 4>;
|
||||||
|
|
||||||
auto entity = registry.create();
|
auto entity = registry.create();
|
||||||
{
|
{
|
||||||
// todo move symbol and root to structure
|
// todo move symbol and root to structure
|
||||||
// cache and recompute cells/points on frame (only if changed) in a system.
|
// cache and recompute cells/points on frame (only if changed) in a system.
|
||||||
|
|
||||||
tc::Group group = tc::schlafli({5, 3, 3, 2});
|
tc::Group group = tc::schlafli({5, 3, 3, 2});
|
||||||
Points points(group, vec5{0.80, 0.3, 0.15, 0.15, 0.03});
|
Points points(group, vec5{0.80, 0.09, 0.09, 0.09, 0.09});
|
||||||
Hull<4> hull(group);
|
Hull<4> hull(group);
|
||||||
|
|
||||||
auto& structure = registry.emplace<vis::Structure<4>>(entity, std::move(points), std::move(hull));
|
auto &structure = registry.emplace<Slice>(entity, std::move(points), std::move(hull));
|
||||||
registry.emplace<vis::VBOs>(entity);
|
registry.emplace<vis::VBOs>(entity);
|
||||||
|
|
||||||
structure.enabled[0] = false; // disable {0,1,2} cells
|
structure.enabled[0] = false; // disable {0,1,2} cells
|
||||||
@@ -199,7 +201,7 @@ int run(GLFWwindow* window, ImGuiContext* ctx) {
|
|||||||
ubo.put(build(window, state, ctx), GL_STREAM_DRAW);
|
ubo.put(build(window, state, ctx), GL_STREAM_DRAW);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto &tform = registry.get<vis::Structure<4>>(entity).transform;
|
auto &tform = registry.get<Slice>(entity).transform;
|
||||||
|
|
||||||
if (!io.KeysDown[GLFW_KEY_SPACE]) {
|
if (!io.KeysDown[GLFW_KEY_SPACE]) {
|
||||||
float speed = 1.0 / 8.0;
|
float speed = 1.0 / 8.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user