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

1
.idea/misc.xml generated
View File

@@ -5,6 +5,7 @@
<sourceRoots> <sourceRoots>
<file path="$PROJECT_DIR$/examples" /> <file path="$PROJECT_DIR$/examples" />
<file path="$PROJECT_DIR$/vis/include" /> <file path="$PROJECT_DIR$/vis/include" />
<file path="$PROJECT_DIR$/vis/presets" />
<file path="$PROJECT_DIR$/vis/shaders" /> <file path="$PROJECT_DIR$/vis/shaders" />
<file path="$PROJECT_DIR$/vis/src" /> <file path="$PROJECT_DIR$/vis/src" />
</sourceRoots> </sourceRoots>

View File

@@ -5,13 +5,24 @@ add_custom_command(
COMMENT "copied shaders" 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) add_library(vis-util INTERFACE)
target_include_directories(vis-util INTERFACE include) target_include_directories(vis-util INTERFACE include)
add_executable(vis src/main.cpp) add_executable(vis src/main.cpp)
target_include_directories(vis PRIVATE include) target_include_directories(vis PRIVATE include)
target_link_libraries(vis PRIVATE tc glad glm glfw) target_link_libraries(vis PRIVATE tc glad glm glfw yaml-cpp)
add_dependencies(vis shaders) add_dependencies(vis shaders presets)
add_executable(ctest src/combotest.cpp) add_executable(ctest src/combotest.cpp)
target_link_libraries(ctest PRIVATE yaml-cpp)
target_include_directories(ctest PRIVATE include) 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). * 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::vector<int> g_gens(context.ngens);
std::iota(g_gens.begin(), g_gens.end(), 0); std::iota(g_gens.begin(), g_gens.end(), 0);
return g_gens; return g_gens;
@@ -194,9 +194,9 @@ std::vector<std::vector<Primitive<N>>> each_tile(
const auto table = solve(context, g_gens, {}); const auto table = solve(context, g_gens, {});
const auto path = solve(context, g_gens, sg_gens).path; 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); 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 #version 430
layout(location=2) uniform vec4 col; layout(location=2) uniform vec3 col;
layout(location=0) in vec3 pos; layout(location=0) in vec3 pos;
layout(location=2) in vec3 normal; layout(location=2) in vec3 normal;
@@ -12,6 +12,6 @@ void main() {
float bright = abs(dot(normal, normalize(vec3(-0.6, 1, 2)))); float bright = abs(dot(normal, normalize(vec3(-0.6, 1, 2))));
bright = .6 + .3 * bright * depth; bright = .6 + .3 * bright * depth;
color = col; color = vec4(col, 1);
color.xyz *= bright; color.xyz *= bright;
} }

View File

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

View File

@@ -17,6 +17,7 @@
#include <random> #include <random>
#include <chrono> #include <chrono>
#include <yaml-cpp/yaml.h>
#ifdef _WIN32 #ifdef _WIN32
extern "C" { extern "C" {
@@ -54,11 +55,19 @@ Matrices build(GLFWwindow *window, float st) {
} }
template<unsigned N, class T> 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; std::vector<std::vector<Primitive<N>>> parts;
auto g_gens = gens(group); auto g_gens = generators(group);
while (begin != end) { for (const std::vector<int> &sg_gens : all_sg_gens) {
const auto &sg_gens = *(++begin); 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 &base = triangulate<N>(group, sg_gens);
const auto &tiles = each_tile(base, group, g_gens, sg_gens); const auto &tiles = each_tile(base, group, g_gens, sg_gens);
for (const auto &tile : tiles) { for (const auto &tile : tiles) {
@@ -108,12 +117,12 @@ public:
template<unsigned N> template<unsigned N>
struct Slice { struct Slice {
GLenum mode; GLenum mode;
vec4 color; vec3 color;
cgl::VertexArray vao; cgl::VertexArray vao;
cgl::Buffer<vec4> vbo; cgl::Buffer<vec4> vbo;
cgl::Buffer<Primitive<N>> ibo; 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; Slice(Slice &) = delete;
@@ -126,11 +135,12 @@ struct Slice {
} }
template<class T, class C> 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); Slice<N> res(GL_POINTS, color);
res.vbo.put(points(g, coords)); 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); res.vao.ipointer(0, res.ibo, 4, GL_UNSIGNED_INT);
return res; return res;
@@ -156,24 +166,39 @@ void run(GLFWwindow *window) {
.stage(sh.slice) .stage(sh.slice)
.stage(sh.solid); .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 = { if (group_info["slices"].IsDefined()) {
Slice<4>::build( for (const auto &slice_info : group_info["slices"]) {
group, auto root = slice_info["root"].as<vec5>();
coord * 0.3, auto color = slice_info["color"].as<vec3>();
{0.9f, 0.3f, 0.3f, 1.0f}, auto exclude = std::vector<std::vector<int>>();
combos.begin(), combos.end()),
Slice<4>::build( if (slice_info["exclude"].IsDefined()) {
group, exclude = slice_info["exclude"].as<std::vector<std::vector<int>>>();
coord, }
{0.3f, 0.3f, 0.3f, 1.0f},
combos.begin()++, combos.end()), 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>(); auto ubo = cgl::Buffer<Matrices>();
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo); glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
@@ -194,7 +219,7 @@ void run(GLFWwindow *window) {
slice_pipe.bound([&]() { slice_pipe.bound([&]() {
for (const auto &slice : slices) { for (const auto &slice : slices) {
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, slice.vbo); 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(); slice.draw();
} }
}); });