Skip to content
Snippets Groups Projects
Commit 432a3d01 authored by Philip Trettner's avatar Philip Trettner
Browse files

Merge branch 'feature/add-interactive-viewer' into 'develop'

Interactive viewer samples

See merge request Glow/glow-samples!9
parents 284395e5 497f8ce2
No related branches found
No related tags found
No related merge requests found
glow @ 20f6d1bf
Subproject commit 3349193c2c4b6b311616bec86b5345a780d0add5
Subproject commit 20f6d1bf4cf07ea9232c20b510f069b3e16eda54
glow-extras @ 58093524
Subproject commit 1ac889e244d8047c429b7c3a13cc9a6f562de8e0
Subproject commit 5809352490444801aa4da3911f9558e91a6c2417
polymesh @ 4d43aff5
Subproject commit 6c22fa0315f450b7dbd48b5555fbbff2a80c6bcd
Subproject commit 4d43aff5521c251531f67974b491efa860f9665e
typed-geometry @ b34be03e
Subproject commit 78c765799fea9fa305e9cb9eda0ba5cefedaefde
Subproject commit b34be03e5f3283b50e0962c9a5de83d6c8e9c1da
#include <iostream>
#include <random>
#include <imgui/imgui.h>
#include <glow/common/str_utils.hh>
#include <glow/data/TextureData.hh>
#include <glow/objects/TextureCubeMap.hh>
......@@ -16,8 +17,6 @@
#include <typed-geometry/tg.hh>
const bool sCustomSkybox = false;
int main()
{
std::string const dataPath = glow::util::pathOf(__FILE__) + "/../../../data/";
......@@ -25,16 +24,6 @@ int main()
// Create a context
glow::glfw::GlfwContext ctx;
if (sCustomSkybox)
{
// Load a skybox, init viewer
auto const skyboxPath = dataPath + "ibl/bell_park/skybox/skybox_";
auto skybox = glow::TextureCubeMap::createFromData(
glow::TextureData::createFromFileCube(skyboxPath + "posx.hdr", skyboxPath + "negx.hdr", skyboxPath + "posy.hdr", skyboxPath + "negy.hdr",
skyboxPath + "posz.hdr", skyboxPath + "negz.hdr", glow::ColorSpace::sRGB));
glow::viewer::Viewer::GlobalInit(skybox);
}
std::uniform_real_distribution<float> dis(0.0f, 1.0f);
std::default_random_engine rng;
......@@ -63,17 +52,32 @@ int main()
{
auto v = glow::viewer::grid();
// Scoped configuration
{
GLOW_VIEWER_CONFIG(glow::viewer::no_grid);
// ADL view
view(pos);
}
// smooth normals
view(polygons(pos).smooth_normals());
// Configuration nesting
{
GLOW_VIEWER_CONFIG(glow::viewer::print_mode);
// Colored faces
view(pos, fcolors);
{
GLOW_VIEWER_CONFIG(glow::viewer::no_shadow);
// Colored vertices
view(pos, vcolors);
}
}
// Mapped 1D vertex data
view(pos, mapping(vdata).linear({0, 0, 0}, {1, 0, 0}, 0.1f, 0.3f));
......@@ -110,7 +114,7 @@ int main()
v.view(polygons(pos).move({+1.5f, 0, 0}), glow::colors::color(0, 0, 1));
// or:
v.view(pos, scale(glm::vec3(0.5f, 1, 1.5f)), glow::colors::color(0, 1, 0));
v.view(pos, scaling(tg::size3(0.5f, 1, 1.5f)), glow::colors::color(0, 1, 0));
}
// Complex material
......@@ -149,14 +153,47 @@ int main()
// when out-of-scope, v immediately shows
}
// Interaction
// Picking
{
// TODO
}
}
// Picking
// Interactive
{
// TODO
auto v = glow::viewer::grid();
// Non-interactive
glow::viewer::view(pos);
// Interactive
{
// Creating renderables is expensive, cache them whenever possible, and capture by value!
auto r1 = glow::viewer::make_renderable(pos);
glow::viewer::interactive([r1](auto dt) {
static auto time = 0.f;
time += dt;
// Always a cleared view, resetting accumulation each frame
glow::viewer::view_cleared(r1, tg::translation(tg::vec3(tg::sin(tg::radians(time * .5f)) * .5f, 0.f, 0.f)));
});
// Using imgui in an interactive view
auto r2 = glow::viewer::make_renderable(pos);
glow::viewer::interactive([r2](auto) {
static float configurable = 0.f;
ImGui::Begin("Interactive viewer");
auto const input = ImGui::SliderFloat("Height", &configurable, -3.f, 3.f);
ImGui::End();
{
auto v = glow::viewer::view(r2, tg::translation(tg::vec3(0.f, configurable, 0.f)));
// Conditional clear
if (input)
glow::viewer::clear_accumulation();
}
});
}
}
......@@ -211,11 +248,6 @@ int main()
}
}
// Animation
{
// TODO
}
// Alternatively, output a single frame headlessly
// auto view = glow::viewer::view(pos);
// view->render()->bind().writeToFile("viewer_output.png");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment