Heightmaps can now be saved.
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
#include <glm/ext/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale
|
#include <glm/ext/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale
|
||||||
#include <glm/ext/matrix_clip_space.hpp> // glm::perspective
|
#include <glm/ext/matrix_clip_space.hpp> // glm::perspective
|
||||||
#include <glm/ext/scalar_constants.hpp> // glm::pi
|
#include <glm/ext/scalar_constants.hpp> // glm::pi
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
using namespace nanogui;
|
using namespace nanogui;
|
||||||
|
|
||||||
@@ -461,6 +462,21 @@ public:
|
|||||||
TextBox *txt_grid_res;
|
TextBox *txt_grid_res;
|
||||||
TextBox *txt_clearance_height, *txt_start_probing_at, *txt_max_negative_z, *txt_final_z_height;
|
TextBox *txt_clearance_height, *txt_start_probing_at, *txt_max_negative_z, *txt_final_z_height;
|
||||||
|
|
||||||
|
void save_heightmap(const grbl::heightmap& grid, std::string path) {
|
||||||
|
std::ofstream out(path);
|
||||||
|
if (out) {
|
||||||
|
out << "from_x:" << grid.from_x << std::endl;
|
||||||
|
out << "from_y:" << grid.from_y << std::endl;
|
||||||
|
out << "to_x:" << grid.to_x << std::endl;
|
||||||
|
out << "to_y:" << grid.to_y << std::endl;
|
||||||
|
out << "resolution:" << grid.resolution << std::endl;
|
||||||
|
out << "probes:" << grid.vertices.size() << std::endl;
|
||||||
|
for (auto& v: grid.vertices) {
|
||||||
|
out << v.x << ":" << v.y << ":" << v.z << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void add_heightmap_markup() {
|
void add_heightmap_markup() {
|
||||||
heightmap_layer->add<Label>("Grid definition", "sans-bold", 20);
|
heightmap_layer->add<Label>("Grid definition", "sans-bold", 20);
|
||||||
auto heightmap_params_holder = heightmap_layer->add<Widget>();
|
auto heightmap_params_holder = heightmap_layer->add<Widget>();
|
||||||
@@ -558,7 +574,15 @@ public:
|
|||||||
btn_start_probing->set_callback([&]() {
|
btn_start_probing->set_callback([&]() {
|
||||||
cnc.probe_heightmap(heightmap_grid);
|
cnc.probe_heightmap(heightmap_grid);
|
||||||
});
|
});
|
||||||
heightmap_business_holder->add<Label>("", "sans-bold");
|
auto btn_save_heightmap = heightmap_business_holder->add<Button>("Save heightmap");
|
||||||
|
btn_save_heightmap->set_callback([&]() {
|
||||||
|
auto path = file_dialog(
|
||||||
|
{{"hmap", "Heightmap files"}
|
||||||
|
}, true);
|
||||||
|
if (!path.empty()) {
|
||||||
|
save_heightmap(heightmap_grid, path);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_heightmap_from_model() {
|
void fill_heightmap_from_model() {
|
||||||
|
|||||||
Reference in New Issue
Block a user