More work on heightmap probing.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "render.h"
|
||||
#include "glm/gtx/quaternion.hpp"
|
||||
#include "nanogui/nanogui.h"
|
||||
#include "glm/gtc/matrix_inverse.hpp"
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
#include <glm/ext/quaternion_trigonometric.hpp>
|
||||
#include <glm/vec3.hpp> // glm::vec3
|
||||
@@ -68,7 +69,7 @@ public:
|
||||
float cam_zoom = 0;
|
||||
glm::quat cam_src_rotation = glm::quat(1.0, 0.0, 0.0, 0.0); // identity quaternion
|
||||
|
||||
Widget *info_layer;
|
||||
Widget *info_layer, *heightmap_layer;
|
||||
TabWidget *tab_widget;
|
||||
VScrollPanel *settings_vscroll;
|
||||
Widget *settings_layer;
|
||||
@@ -93,6 +94,7 @@ public:
|
||||
window->set_layout(new BoxLayout(nanogui::Orientation::Vertical));
|
||||
|
||||
tab_widget = window->add<TabWidget>();
|
||||
tab_widget->set_tabs_draggable(true);
|
||||
tab_widget->set_callback([&](int index) {
|
||||
tab_widget->set_selected_index(index);
|
||||
});
|
||||
@@ -107,8 +109,6 @@ public:
|
||||
probe_layer->set_layout(new GroupLayout(10, 20, 30, 0));
|
||||
probe_layer->add<Label>("");
|
||||
|
||||
tab_widget->append_tab("Probing", info_layer);
|
||||
|
||||
add_status_markup();
|
||||
add_dro_markup();
|
||||
add_program_extents();
|
||||
@@ -117,10 +117,17 @@ public:
|
||||
add_work_parameters_markup();
|
||||
add_z_probe_markup();
|
||||
|
||||
heightmap_layer = tab_widget->add<Widget>();
|
||||
heightmap_layer->set_layout(new GroupLayout(10, 20, 30, 0));
|
||||
heightmap_layer->add<Label>("");
|
||||
tab_widget->append_tab("Heightmap", heightmap_layer);
|
||||
add_heightmap_markup();
|
||||
|
||||
|
||||
perform_layout();
|
||||
|
||||
m_render_pass = new RenderPass({this});
|
||||
m_render_pass->set_clear_color(0, Color(0.3f, 0.3f, 0.32f, 1.f));
|
||||
m_render_pass->set_clear_color(0, Color(0.13f, 0.13f, 0.13f, 1.f));
|
||||
m_render_pass->set_depth_test(RenderPass::DepthTest::Always, true);
|
||||
m_render_pass->set_cull_mode(RenderPass::CullMode::Disabled);
|
||||
}
|
||||
@@ -187,6 +194,8 @@ public:
|
||||
if (pgm.load_from_file(path)) {
|
||||
init_program_geometry();
|
||||
set_program_extents();
|
||||
fill_heightmap_from_model();
|
||||
update_grid();
|
||||
} else {
|
||||
}
|
||||
});
|
||||
@@ -444,6 +453,97 @@ public:
|
||||
extents_max_z = extents_holder->add<TextBox>("");
|
||||
}
|
||||
|
||||
TextBox *txt_heightmap_from_x, *txt_heightmap_from_y;
|
||||
TextBox *txt_heightmap_to_x, *txt_heightmap_to_y;
|
||||
TextBox *txt_grid_res;
|
||||
|
||||
void add_heightmap_markup() {
|
||||
heightmap_layer->add<Label>("Grid definition", "sans-bold", 20);
|
||||
auto heightmap_params_holder = heightmap_layer->add<Widget>();
|
||||
heightmap_params_holder->set_layout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 4, 4));
|
||||
|
||||
// grid size
|
||||
auto grid_size_holder = heightmap_params_holder->add<Widget>();
|
||||
grid_size_holder->set_layout(new GridLayout(Orientation::Horizontal, 3, Alignment::Middle, 4, 4));
|
||||
|
||||
grid_size_holder->add<Label>("", "sans-bold", 20);
|
||||
grid_size_holder->add<Label>("X", "sans-bold", 20);
|
||||
grid_size_holder->add<Label>("Y", "sans-bold", 20);
|
||||
|
||||
grid_size_holder->add<Label>("From", "sans-bold", 20);
|
||||
txt_heightmap_from_x = grid_size_holder->add<TextBox>("");
|
||||
txt_heightmap_from_x->set_editable(true);
|
||||
txt_heightmap_from_x->set_fixed_width(150);
|
||||
txt_heightmap_from_y = grid_size_holder->add<TextBox>("");
|
||||
txt_heightmap_from_y->set_editable(true);
|
||||
txt_heightmap_from_y->set_fixed_width(150);
|
||||
|
||||
grid_size_holder->add<Label>("To", "sans-bold", 20);
|
||||
txt_heightmap_to_x = grid_size_holder->add<TextBox>("");
|
||||
txt_heightmap_to_x->set_editable(true);
|
||||
txt_heightmap_to_x->set_fixed_width(150);
|
||||
txt_heightmap_to_y = grid_size_holder->add<TextBox>("");
|
||||
txt_heightmap_to_y->set_editable(true);
|
||||
txt_heightmap_to_y->set_fixed_width(150);
|
||||
|
||||
grid_size_holder->add<Label>("");
|
||||
auto btn = grid_size_holder->add<Button>("Fetch from model");
|
||||
btn->set_callback([&]() {
|
||||
fill_heightmap_from_model();
|
||||
});
|
||||
grid_size_holder->add<Label>("");
|
||||
|
||||
txt_heightmap_from_x->set_callback([&](const std::string& new_value) {
|
||||
update_grid();
|
||||
return true;
|
||||
});
|
||||
txt_heightmap_from_y->set_callback([&](const std::string& new_value) {
|
||||
update_grid();
|
||||
return true;
|
||||
});
|
||||
|
||||
txt_heightmap_to_x->set_callback([&](const std::string& new_value) {
|
||||
update_grid();
|
||||
return true;
|
||||
});
|
||||
txt_heightmap_to_y->set_callback([&](const std::string& new_value) {
|
||||
update_grid();
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
// grid resolution
|
||||
auto grid_res_holder = heightmap_params_holder->add<Widget>();
|
||||
grid_res_holder->set_layout(new BoxLayout(nanogui::Orientation::Horizontal, Alignment::Middle, 4, 4));
|
||||
grid_res_holder->add<Label>("Grid resolution", "sans-bold", 20);
|
||||
txt_grid_res = grid_res_holder->add<TextBox>("5");
|
||||
txt_grid_res->set_editable(true);
|
||||
txt_grid_res->set_fixed_width(150);
|
||||
txt_grid_res->set_callback([&](const std::string& new_value) {
|
||||
update_grid();
|
||||
return true;
|
||||
});
|
||||
grid_res_holder->add<Label>("mm", "sans-bold", 20);
|
||||
}
|
||||
|
||||
void fill_heightmap_from_model() {
|
||||
auto min = renderer.get_extents_min();
|
||||
auto max = renderer.get_extents_max();
|
||||
txt_heightmap_from_x->set_value(std::to_string(min.x));
|
||||
txt_heightmap_from_y->set_value(std::to_string(min.y));
|
||||
txt_heightmap_to_x->set_value(std::to_string(max.x));
|
||||
txt_heightmap_to_y->set_value(std::to_string(max.y));
|
||||
}
|
||||
|
||||
void update_grid() {
|
||||
auto from_x = std::stof(txt_heightmap_from_x->value());
|
||||
auto from_y = std::stof(txt_heightmap_from_y->value());
|
||||
auto to_x = std::stof(txt_heightmap_to_x->value());
|
||||
auto to_y = std::stof(txt_heightmap_to_y->value());
|
||||
auto res = std::stoi(txt_grid_res->value());
|
||||
renderer.update_grid(from_x, from_y, to_x, to_y, res);
|
||||
}
|
||||
|
||||
void add_pins_markup() {
|
||||
// Pins
|
||||
info_layer->add<Label>("Pins", "sans-bold", 20);
|
||||
@@ -861,9 +961,8 @@ public:
|
||||
glm::translate(glm::mat4(1.0f), -cam_target);
|
||||
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
auto mvp = projection * view * model;
|
||||
|
||||
renderer.render(mvp, glm::vec2(fb_size.x(), fb_size.y()));
|
||||
glm::mat3 normal_mat = glm::inverseTranspose(glm::mat3(view * model));
|
||||
renderer.render(model, view, projection, normal_mat, glm::vec2(fb_size.x(), fb_size.y()));
|
||||
}
|
||||
|
||||
m_render_pass->end();
|
||||
|
||||
Reference in New Issue
Block a user