load wireframes from files

This commit is contained in:
2020-03-18 17:29:12 -04:00
parent acdc19bbb9
commit 33501650b2
8 changed files with 93 additions and 39 deletions

View File

@@ -5,13 +5,24 @@ add_custom_command(
COMMENT "copied shaders"
)
add_custom_target(presets ALL DEPENDS preset_output)
add_custom_command(
OUTPUT preset_output
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/presets ${CMAKE_CURRENT_BINARY_DIR}/presets
COMMENT "copied preses"
)
find_package(yaml-cpp REQUIRED)
add_library(vis-util INTERFACE)
target_include_directories(vis-util INTERFACE include)
add_executable(vis src/main.cpp)
target_include_directories(vis PRIVATE include)
target_link_libraries(vis PRIVATE tc glad glm glfw)
add_dependencies(vis shaders)
target_link_libraries(vis PRIVATE tc glad glm glfw yaml-cpp)
add_dependencies(vis shaders presets)
add_executable(ctest src/combotest.cpp)
target_link_libraries(ctest PRIVATE yaml-cpp)
target_include_directories(ctest PRIVATE include)
add_dependencies(ctest presets)

View File

@@ -43,7 +43,7 @@ struct Primitive {
/**
* Produce a list of all generators for the group context. The range [0..group.ngens).
*/
std::vector<int> gens(const tc::Group &context) {
std::vector<int> generators(const tc::Group &context) {
std::vector<int> g_gens(context.ngens);
std::iota(g_gens.begin(), g_gens.end(), 0);
return g_gens;
@@ -194,9 +194,9 @@ std::vector<std::vector<Primitive<N>>> each_tile(
const auto table = solve(context, g_gens, {});
const auto path = solve(context, g_gens, sg_gens).path;
auto _gens = gens(context);
auto _gens = generators(context);
auto res = path.walk<std::vector<Primitive<N>>, int>(base, gens(context), [&](auto from, auto gen) {
auto res = path.walk<std::vector<Primitive<N>>, int>(base, generators(context), [&](auto from, auto gen) {
return apply(from, table, gen);
});

View File

@@ -0,0 +1,9 @@
groups:
- symbol: [3, 4, 3, 2]
slices:
- root: [0.30, 0.03, 0.03, 0.03, 0.01]
color: [0.9, 0.3, 0.3]
- root: [1.00, 0.10, 0.10, 0.10, 0.02]
color: [0.3, 0.3, 0.3]
exclude:
- [0, 1, 2]

9
vis/presets/default.yaml Normal file
View File

@@ -0,0 +1,9 @@
groups:
- symbol: [3, 4, 3, 2]
slices:
- root: [0.30, 0.03, 0.03, 0.03, 0.01]
color: [0.9, 0.3, 0.3]
- root: [1.00, 0.10, 0.10, 0.10, 0.02]
color: [0.3, 0.3, 0.3]
exclude:
- [0, 1, 2]

View File

@@ -1,6 +1,6 @@
#version 430
layout(location=2) uniform vec4 col;
layout(location=2) uniform vec3 col;
layout(location=0) in vec3 pos;
layout(location=2) in vec3 normal;
@@ -12,6 +12,6 @@ void main() {
float bright = abs(dot(normal, normalize(vec3(-0.6, 1, 2))));
bright = .6 + .3 * bright * depth;
color = col;
color = vec4(col, 1);
color.xyz *= bright;
}

View File

@@ -1,15 +1,14 @@
#include <combo_iterator.hpp>
#include <iostream>
#include <yaml-cpp/yaml.h>
#include <string>
int main() {
auto cs = Combos<int>({7, 2, 3}, 2);
auto cfg = YAML::LoadFile("presets/default.yaml");
auto beg = cs.begin();
auto end = cs.end();
while (beg != end) {
const auto &c = *(++beg);
for (const auto &e : c) std::cout << e << " ";
for (const auto &group : cfg["groups"]) {
// std::cout << group["symbol"] << std::endl;
auto s = group["symbol"].as<std::vector<int>>();
for (const auto e : s) std::cout << e << " ";
std::cout << std::endl;
}
}

View File

@@ -17,6 +17,7 @@
#include <random>
#include <chrono>
#include <yaml-cpp/yaml.h>
#ifdef _WIN32
extern "C" {
@@ -54,11 +55,19 @@ Matrices build(GLFWwindow *window, float st) {
}
template<unsigned N, class T>
auto hull(const tc::Group &group, T begin, T end) {
auto hull(const tc::Group &group, T all_sg_gens, const std::vector<std::vector<int>> &exclude) {
std::vector<std::vector<Primitive<N>>> parts;
auto g_gens = gens(group);
while (begin != end) {
const auto &sg_gens = *(++begin);
auto g_gens = generators(group);
for (const std::vector<int> &sg_gens : all_sg_gens) {
bool excluded = false;
for (const auto &test : exclude) {
if (sg_gens == test) {
excluded = true;
break;
}
}
if (excluded) continue;
const auto &base = triangulate<N>(group, sg_gens);
const auto &tiles = each_tile(base, group, g_gens, sg_gens);
for (const auto &tile : tiles) {
@@ -108,12 +117,12 @@ public:
template<unsigned N>
struct Slice {
GLenum mode;
vec4 color;
vec3 color;
cgl::VertexArray vao;
cgl::Buffer<vec4> vbo;
cgl::Buffer<Primitive<N>> ibo;
Slice(GLenum mode, vec4 color) : mode(mode), color(color), vao(), ibo(), vbo() {}
Slice(GLenum mode, vec3 color) : mode(mode), color(color), vao(), ibo(), vbo() {}
Slice(Slice &) = delete;
@@ -126,11 +135,12 @@ struct Slice {
}
template<class T, class C>
static Slice<N> build(const tc::Group &g, const C &coords, vec4 color, T begin, T end) {
static Slice<N> build(const tc::Group &g, const C &coords, vec3 color, T all_sg_gens,
const std::vector<std::vector<int>> &exclude) {
Slice<N> res(GL_POINTS, color);
res.vbo.put(points(g, coords));
res.ibo.put(merge<N>(hull<N>(g, begin, end)));
res.ibo.put(merge<N>(hull<N>(g, all_sg_gens, exclude)));
res.vao.ipointer(0, res.ibo, 4, GL_UNSIGNED_INT);
return res;
@@ -156,24 +166,39 @@ void run(GLFWwindow *window) {
.stage(sh.slice)
.stage(sh.solid);
auto group = tc::schlafli({5, 3, 3, 2});
auto scene = YAML::LoadFile("presets/default.yaml");
const auto combos = Combos<int>({0, 1, 2, 3, 4}, 3);
auto slices = std::vector<Slice<4>>();
const auto coord = (vec5) {1.0, 0.1, 0.1, 0.1, 0.025};
for (const auto &group_info : scene["groups"]) {
auto symbol = group_info["symbol"].as<std::vector<int>>();
auto group = tc::schlafli(symbol);
auto gens = generators(group);
auto slices = {
Slice<4>::build(
group,
coord * 0.3,
{0.9f, 0.3f, 0.3f, 1.0f},
combos.begin(), combos.end()),
Slice<4>::build(
group,
coord,
{0.3f, 0.3f, 0.3f, 1.0f},
combos.begin()++, combos.end()),
};
if (group_info["slices"].IsDefined()) {
for (const auto &slice_info : group_info["slices"]) {
auto root = slice_info["root"].as<vec5>();
auto color = slice_info["color"].as<vec3>();
auto exclude = std::vector<std::vector<int>>();
if (slice_info["exclude"].IsDefined()) {
exclude = slice_info["exclude"].as<std::vector<std::vector<int>>>();
}
if (slice_info["subgroups"].IsDefined()) {
auto subgroups = slice_info["subgroups"].as<std::vector<std::vector<int>>>();
slices.push_back(Slice<4>::build(
group, root, color, subgroups, exclude
));
} else {
auto combos = Combos<int>(gens, 3);
slices.push_back(Slice<4>::build(
group, root, color, combos, exclude
));
}
}
}
}
auto ubo = cgl::Buffer<Matrices>();
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
@@ -194,7 +219,7 @@ void run(GLFWwindow *window) {
slice_pipe.bound([&]() {
for (const auto &slice : slices) {
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, slice.vbo);
glProgramUniform4fv(sh.solid, 2, 1, &slice.color.front());
glProgramUniform3fv(sh.solid, 2, 1, &slice.color.front());
slice.draw();
}
});