mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
WIP (broken): Refactor components
This commit is contained in:
@@ -18,56 +18,46 @@
|
||||
#include <shaders.hpp>
|
||||
|
||||
namespace vis {
|
||||
using Color = Eigen::Vector<float, 3>;
|
||||
|
||||
template<int R_, int D_, int G_>
|
||||
struct Structure {
|
||||
static constexpr auto Rank = R_;
|
||||
static constexpr auto Dim = D_;
|
||||
static constexpr auto Grade = G_;
|
||||
|
||||
using Affine = Eigen::Transform<float, Dim, Eigen::Affine>;
|
||||
using AffineDf = Eigen::Transform<float, Dim, Eigen::Affine>;
|
||||
|
||||
using VectorRf = Eigen::Vector<float, Rank>;
|
||||
using MatrixRXf = Eigen::Matrix<float, Rank, Eigen::Dynamic>;
|
||||
using VectorDf = Eigen::Vector<float, Dim>;
|
||||
using MatrixDXf = Eigen::Matrix<float, Dim, Eigen::Dynamic>;
|
||||
using VectorGf = Eigen::Vector<float, Grade>;
|
||||
using MatrixGXf = Eigen::Matrix<float, Grade, Eigen::Dynamic>;
|
||||
|
||||
using ArrayRui = Eigen::Array<GLuint, Rank, 1>;
|
||||
using ArrayRXui = Eigen::Array<GLuint, Rank, Eigen::Dynamic>;
|
||||
using ArrayDui = Eigen::Array<GLuint, Dim, 1>;
|
||||
using ArrayDXui = Eigen::Array<GLuint, Dim, Eigen::Dynamic>;
|
||||
using ArrayGui = Eigen::Array<GLuint, Grade, 1>;
|
||||
using ArrayGXui = Eigen::Array<GLuint, Grade, Eigen::Dynamic>;
|
||||
|
||||
using Color = Eigen::Vector<float, 3>; // todo global typedef
|
||||
|
||||
// todo cache and recompute cells/points on frame (only if changed) in a system.
|
||||
|
||||
tc::Group group;
|
||||
VectorRf root;
|
||||
|
||||
Affine transform = Affine::Identity();
|
||||
AffineDf transform = AffineDf::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
|
||||
) :
|
||||
group(group),
|
||||
root(root),
|
||||
transform(Affine::Identity()) {
|
||||
explicit Structure(tc::Group const &group, VectorRf root) :
|
||||
group(group), root(root), transform(AffineDf::Identity()) {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Str_>
|
||||
struct Part {
|
||||
using Str = Str_;
|
||||
|
||||
entt::entity parent;
|
||||
|
||||
GLuint first;
|
||||
GLuint count;
|
||||
Color color = Color::Ones();
|
||||
bool enabled = true;
|
||||
};
|
||||
|
||||
struct Command {
|
||||
unsigned int count, instanceCount, first, baseInstance;
|
||||
};
|
||||
|
||||
template<typename Str_>
|
||||
struct VBOs {
|
||||
using Str = Str_;
|
||||
@@ -81,10 +71,6 @@ namespace vis {
|
||||
Eigen::Vector4f translation;
|
||||
};
|
||||
|
||||
struct Command {
|
||||
unsigned int count, instanceCount, first, baseInstance;
|
||||
};
|
||||
|
||||
cgl::Buffer<VectorDf> vertices;
|
||||
cgl::Buffer<Color> colors;
|
||||
cgl::Buffer<ArrayGui> indices;
|
||||
|
||||
@@ -21,39 +21,42 @@
|
||||
namespace vis {
|
||||
template<typename Str>
|
||||
void upload_structure(entt::registry ®istry) {
|
||||
{
|
||||
auto parts = registry.view<Part<Str>>();
|
||||
registry.destroy(parts.begin(), parts.end());
|
||||
}
|
||||
|
||||
auto view = registry.view<Str, VBOs<Str>>();
|
||||
|
||||
for (auto [entity, structure, vbos]: view.each()) {
|
||||
Points points(structure.group, structure.root);
|
||||
Hull<Str::Grade> hull(structure.group);
|
||||
|
||||
registry.destroy(structure.parts.begin(), structure.parts.end());
|
||||
structure.parts.clear();
|
||||
auto &&vertices = points.verts.colwise();
|
||||
auto &&indices = hull.inds.colwise();
|
||||
|
||||
vbos.vertices.put(vertices.begin(), vertices.end());
|
||||
vbos.indices.put(indices.begin(), indices.end());
|
||||
|
||||
for (const auto &tiling: hull.tilings) {
|
||||
auto part_entity = registry.create();
|
||||
registry.emplace<typename Str::Part>(
|
||||
registry.emplace<Part<Str>>(
|
||||
part_entity,
|
||||
entity,
|
||||
tiling.first,
|
||||
tiling.count
|
||||
);
|
||||
structure.parts.push_back(part_entity);
|
||||
}
|
||||
|
||||
vbos.vertices.put(
|
||||
points.verts.colwise().begin(),
|
||||
points.verts.colwise().end()
|
||||
);
|
||||
vbos.indices.put(
|
||||
hull.inds.colwise().begin(),
|
||||
hull.inds.colwise().end()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Str>
|
||||
void upload_uniforms(entt::registry ®istry) {
|
||||
auto view = registry.view<Str, VBOs<Str>>();
|
||||
auto view = registry.view<Part<Str>>();
|
||||
|
||||
for (auto [entity, part]: view.each()) {
|
||||
auto &vbos = registry.get<VBOs<Str>>(part.parent);
|
||||
}
|
||||
|
||||
for (auto [entity, structure, vbos]: view.each()) {
|
||||
std::vector<typename Str::Color> colors;
|
||||
@@ -73,6 +76,11 @@ namespace vis {
|
||||
|
||||
template<typename Str>
|
||||
void upload_commands(entt::registry ®istry) {
|
||||
auto view = registry.view<Part<Str>>();
|
||||
for (auto [entity, part]: view.each()) {
|
||||
Command comm(part.count, 1, part.first, )
|
||||
}
|
||||
|
||||
auto view = registry.view<Str, VBOs<Str>>();
|
||||
|
||||
for (auto [entity, structure, vbos]: view.each()) {
|
||||
|
||||
Reference in New Issue
Block a user