implement grid and heightmap with lambert shading

This commit is contained in:
2018-12-24 22:22:16 +01:00
parent 4d2706bfab
commit 52c87d9ec6
16 changed files with 297 additions and 101 deletions

View File

@@ -25,41 +25,73 @@ void NodePanelGrid::init()
void NodePanelGrid::init_controls()
{
m_groud_opacity = find<NodeSliderH>("grid-ground-opacity");
m_groud_scale = find<NodeSliderH>("grid-ground-scale");
m_groud_value = find<NodeSliderH>("grid-ground-value");
m_groud_height = find<NodeSliderH>("grid-ground-height");
//m_box_opacity = find<NodeSliderH>("grid-box-opacity");
//m_box_width = find<NodeSliderH>("grid-box-width");
//m_box_height = find<NodeSliderH>("grid-box-height");
//m_box_depth = find<NodeSliderH>("grid-box-depth");
auto update_hm = [this](Node* target, float v) {
m_hm_plane.create(1, 1, m_hm_image, -m_hm_height->get_value());
};
m_groud_resolution = find<NodeSliderH>("grid-ground-resolution");
m_groud_offset = find<NodeSliderH>("grid-ground-offset");
m_hm_preview = find<NodeImageTexture>("grid-heightmap-preview");
m_hm_load = find<NodeButton>("grid-heightmap-load");
m_hm_offset = find<NodeSliderH>("grid-heightmap-offset");
m_hm_clear = find<NodeButton>("grid-heightmap-clear");
m_hm_reload = find<NodeButton>("grid-heightmap-reload");
m_hm_wireframe = find<NodeSliderH>("grid-heightmap-wireframe");
m_hm_height = find<NodeSliderH>("grid-heightmap-height");
m_hm_lyaw = find<NodeSliderH>("grid-heightmap-lyaw");
m_hm_lpitch = find<NodeSliderH>("grid-heightmap-lpitch");
m_hm_height->on_value_changed = update_hm;
//m_hm_height->on_value_changed = update_hm;
m_groud_resolution->on_value_changed = [this](Node* target, float v) {
if (m_hm_image.data())
m_hm_plane.create(1, 1, m_hm_image, v * 5.f);
else
m_hm_plane.create(1, 1, 100 * v * 5.f);
LOG("resolution value %f", v);
};
m_hm_preview->SetHeight(0);
//m_hm_plane.create(1, 1);
m_hm_plane.create(1, 1, 100);
m_hm_load->on_click = [this](Node*) {
App::I.pick_image([this](std::string path) {
Image img;
async_start();
if (img.load_file(path))
{
m_file_path = path;
m_hm_image = img.resize(128, 128);
m_hm_preview->tex.create(m_hm_image);
m_hm_preview->tex.create_mipmaps();
auto sz = m_hm_preview->tex.size();
m_hm_preview->SetAspectRatio(sz.x / sz.y);
m_hm_plane.create(1, 1, m_hm_image, -m_hm_height->get_value());
m_hm_plane.create(1, 1, m_hm_image, m_groud_resolution->get_value() * 5.f);
m_hm_preview->SetHeight(100);
if (m_groud_opacity->get_value() == 0.f)
m_groud_opacity->set_value(1.f);
}
async_update();
async_end();
});
};
m_hm_clear->on_click = [this](Node*)
{
m_hm_plane.create(1, 1, 100 * m_groud_resolution->get_value() * 5.f);
m_hm_image.destroy();
m_hm_preview->tex.destroy();
m_hm_preview->SetHeight(0);
};
m_hm_reload->on_click = [this](Node*)
{
Image img;
if (img.load_file(m_file_path))
{
m_hm_image = img.resize(128, 128);
m_hm_preview->tex.create(m_hm_image);
m_hm_preview->tex.create_mipmaps();
auto sz = m_hm_preview->tex.size();
m_hm_preview->SetAspectRatio(sz.x / sz.y);
m_hm_plane.create(1, 1, m_hm_image, m_groud_resolution->get_value() * 5.f);
m_hm_preview->SetHeight(100);
}
};
}