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

finished sample rework

parent 57fde9d1
No related branches found
No related tags found
No related merge requests found
Pipeline #13913 failed
glow-extras @ 38ce73ea
Subproject commit d24f6bfa89995994ecec1b7fb7a4791b3de7fd7a
Subproject commit 38ce73ea211cc54f861caa10778d903f94f508b5
polymesh @ ee575532
Subproject commit 422b371894d4326a41d6dcc81ed5a998c7406b25
Subproject commit ee575532d0eba2da77b672219bbda8082638e657
......@@ -146,8 +146,77 @@ void advanced_objects(pm::vertex_attribute<tg::pos3> const& pos)
void advanced_visualization(pm::vertex_attribute<tg::pos3> const& pos)
{
// gv::opaque, gv::transparent
// colors, textures, mappings
// the args in gv::view(obj, args) do not only configure the viewer but also change how the renderable is visualized
pm::Mesh const& m = pos.mesh();
// RNG for creating some random sample values
tg::rng rng;
// colors
{
auto g = gv::grid();
// generate some random color attributes
pm::face_attribute<tg::color3> random_face_colors = m.faces().map([&](pm::face_handle) { return tg::uniform<tg::color3>(rng); });
pm::vertex_attribute<tg::color3> random_vertex_colors = m.vertices().map([&](pm::vertex_handle) { return tg::uniform<tg::color3>(rng); });
// map positions to colors
pm::vertex_attribute<tg::color3> vcolors = m.vertices().map([&](pm::vertex_handle v) { return tg::color3(pos[v] * 0.5f + 0.5f); });
gv::view(pos, tg::color3::red, "solid color for whole mesh");
gv::view(pos, random_face_colors, "random face colors");
gv::view(pos, random_vertex_colors, "random vertex colors");
gv::view(gv::points(pos), vcolors, "point cloud with xyz colors");
}
// data mapping
{
auto g = gv::grid();
// a scalar field consisting of vertex y coordinate
pm::vertex_attribute<float> vdata = pos.map([](tg::pos3 v) { return v.y; });
// a scalar field consisting of face areas
pm::face_attribute<float> fdata = m.faces().map([&](pm::face_handle f) { return pm::face_area(f, pos); });
// map vertex data to black-red, from 0.1 .. 0.3 (repeats outside)
gv::view(pos, gv::mapping(vdata).linear(tg::color3::black, tg::color3::red, 0.1f, 0.3f), "vertex data");
// map face data to red (small) to green (big) from 0.05 .. 0.5 (data outside this range is clamped)
gv::view(pos, gv::mapping(fdata).linear(tg::color3::red, tg::color3::green, 0.05f, 0.5f).clamped(), "face data");
}
// textures
{
auto g = gv::grid();
// taking xy as UV for now
// NOTE: halfedge attributes also work
pm::vertex_attribute<tg::pos2> uv = pos.map([](tg::pos3 v) { return tg::pos2(v.x, v.y); });
// textures can be loaded directly or async
// TODO: gv::textured with a filename (and color space)
glow::SharedTexture2D tex = glow::Texture2D::createFromFile(dataPath + "textures/tiles.color.png", glow::ColorSpace::sRGB);
glow::AsyncTexture2D atex = glow::AsyncTextureLoader::load2D(dataPath + "textures/tiles.color.png", glow::ColorSpace::sRGB);
gv::view(pos, gv::textured(uv, tex), "textured");
gv::view(pos, gv::textured(uv, atex), "textured (async)");
gv::view(pos, gv::textured(uv, tex).flip(), "flipped y axis");
gv::view(pos, gv::textured(uv, tex).transform(tg::scaling(3.0f, 0.5f)), "transformed UVs");
}
// transparency
{
auto g = gv::grid();
// if colors with alpha < 1 are provided, transparency is enabled
gv::view(pos, tg::color4(0, 0.4f, 0.3f, 0.2f), "transparency with fresnel");
gv::view(pos, tg::color4(0, 0.4f, 0.3f, 0.2f), gv::no_fresnel, "transparency without fresnel");
// it can be explicitly controlled via gv::transparent and gv::opaque
gv::view(pos, tg::color4(0.3f, 0.1f, 0.3f, 0.5f), gv::transparent, "explicitly transparent");
gv::view(pos, tg::color4(0.3f, 0.1f, 0.3f, 0.2f), gv::opaque, "transparent color but disabled transparency");
}
// TODO: complex material (e.g. PBR)
}
......@@ -431,30 +500,18 @@ void special_use_cases(pm::vertex_attribute<tg::pos3> const& pos)
int main()
{
// Create a context
// create a rendering context
glow::glfw::GlfwContext ctx;
tg::rng rng;
// Load a sample polymesh mesh
// load a sample polymesh mesh
pm::Mesh m;
auto pos = m.vertices().make_attribute<tg::pos3>();
load(dataPath + "suzanne.obj", m, pos);
normalize(pos); // make it -1..1
// prepare some data
pm::vertex_attribute<glm::vec2> uv = pos.map([](tg::pos3 v) { return glm::vec2(v.x, v.y); });
pm::vertex_attribute<float> vdata = pos.map([](tg::pos3 v) { return v.y; });
pm::vertex_attribute<tg::vec3> vnormals = vertex_normals_by_area(pos);
pm::face_attribute<float> fdata = m.faces().map([&](pm::face_handle f) { return f.vertices().avg(pos).z; });
glow::SharedTexture2D tex = glow::Texture2D::createFromFile(dataPath + "textures/tiles.color.png", glow::ColorSpace::sRGB);
glow::AsyncTexture2D atex = glow::AsyncTextureLoader::load2D(dataPath + "textures/tiles.color.png", glow::ColorSpace::sRGB);
pm::face_attribute<tg::color3> fcolors = m.faces().map([&](pm::face_handle) { return tg::uniform<tg::color3>(rng); });
pm::vertex_attribute<tg::color3> vcolors = attribute(m.vertices(), tg::color3(1, 0, 0));
pm::edge_attribute<float> edge_lengths = m.edges().map([&](pm::edge_handle e) { return edge_length(e, pos); });
pm::vertex_attribute<float> ptsize = m.vertices().map([&](pm::vertex_handle v) { return v.edges().avg(edge_lengths); });
// basics demos
// basic demos
{
simple_view(pos);
......@@ -487,38 +544,5 @@ int main()
headless_screenshot(pos);
}
// Grid of examples
{
// Configuration nesting
{
// Colored faces
gv::view(pos, fcolors, "colored faces");
{
// Colored vertices
gv::view(pos, vcolors, "colored vertices");
}
}
// Mapped 1D vertex data
gv::view(pos, gv::mapping(vdata).linear({0, 0, 0}, {1, 0, 0}, 0.1f, 0.3f), "vertex data");
// Mapped 1D face data
gv::view(pos, gv::mapping(fdata).linear({0, 1, 0}, {0, 0, 1}, -0.5f, 0.5f).clamped(), "face data");
// Textured mesh
gv::view(pos, gv::textured(uv, tex), "textured");
// Textured mesh (async texture)
gv::view(pos, gv::textured(uv, atex), "textured (async)");
// transparencies
gv::view(pos, tg::color4(0, 0.4f, 0.3f, 0.2f), "transparency with fresnel");
gv::view(pos, tg::color4(0, 0.4f, 0.3f, 0.2f), gv::no_fresnel, "transparency without fresnel");
{
}
}
return 0;
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment