Centralize quick and grid UI bridges
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "app_core/grid_ui.h"
|
||||
#include "legacy_grid_ui_services.h"
|
||||
#include "log.h"
|
||||
#include "node_panel_grid.h"
|
||||
#include "canvas.h"
|
||||
@@ -79,22 +80,17 @@ void NodePanelGrid::init_controls()
|
||||
|
||||
m_hm_load->on_click = [this](Node*) {
|
||||
const auto plan = pp::app::plan_grid_heightmap_pick();
|
||||
if (!plan.opens_picker)
|
||||
return;
|
||||
App::I->pick_image([this](std::string path) {
|
||||
load_heightmap_file(path, true);
|
||||
});
|
||||
const auto status = pp::panopainter::execute_legacy_grid_ui_plan(*this, plan);
|
||||
if (!status.ok())
|
||||
LOG("Grid heightmap pick action failed: %s", status.message);
|
||||
};
|
||||
|
||||
m_hm_clear->on_click = [this](Node*)
|
||||
{
|
||||
const auto plan = pp::app::plan_grid_heightmap_clear(static_cast<bool>(m_hm_image.data()));
|
||||
if (!plan.clears_heightmap)
|
||||
return;
|
||||
m_hm_plane.create(1, 1, 100 * get_resolution());
|
||||
m_hm_image.destroy();
|
||||
m_hm_preview->tex.reset();
|
||||
m_hm_preview->SetHeight(0);
|
||||
const auto status = pp::panopainter::execute_legacy_grid_ui_plan(*this, plan);
|
||||
if (!status.ok())
|
||||
LOG("Grid heightmap clear action failed: %s", status.message);
|
||||
};
|
||||
|
||||
m_hm_reload->on_click = [this](Node*)
|
||||
@@ -112,32 +108,16 @@ void NodePanelGrid::init_controls()
|
||||
get_samples());
|
||||
if (!plan)
|
||||
return;
|
||||
if (plan.value().shows_unsupported_message)
|
||||
{
|
||||
App::I->message_box("Rendering failed",
|
||||
"Your hardware does not support lightmap rendering.");
|
||||
return;
|
||||
}
|
||||
if (plan.value().renders_lightmap)
|
||||
{
|
||||
std::thread([this] {
|
||||
BT_SetTerminate();
|
||||
bake_uvs();
|
||||
m_hm_shading->set_index(3);
|
||||
m_shade_mode = ShadeMode::Textured;
|
||||
}).detach();
|
||||
}
|
||||
const auto status = pp::panopainter::execute_legacy_grid_ui_plan(*this, plan.value());
|
||||
if (!status.ok())
|
||||
LOG("Grid lightmap render action failed: %s", status.message);
|
||||
};
|
||||
m_commit->on_click = [this](Node*)
|
||||
{
|
||||
const auto plan = pp::app::plan_grid_heightmap_commit(Canvas::I != nullptr);
|
||||
if (!plan.commits_heightmap)
|
||||
return;
|
||||
Canvas::I->draw_objects([this](const glm::mat4& camera, const glm::mat4& proj, int i) {
|
||||
draw_heightmap(proj, camera, true);
|
||||
}, Canvas::I->layer().m_frame_index, true);
|
||||
if (plan.updates_ground_opacity)
|
||||
m_groud_opacity->set_value(0);
|
||||
const auto status = pp::panopainter::execute_legacy_grid_ui_plan(*this, plan);
|
||||
if (!status.ok())
|
||||
LOG("Grid heightmap commit action failed: %s", status.message);
|
||||
};
|
||||
m_hm_texres->on_select = [this](Node*, int index) {
|
||||
int texres = get_texres();
|
||||
@@ -227,23 +207,10 @@ bool NodePanelGrid::load_heightmap_file(const std::string& path, bool raise_grou
|
||||
if (!plan)
|
||||
return false;
|
||||
|
||||
Image img;
|
||||
if (!img.load_file(plan.value().path))
|
||||
return false;
|
||||
|
||||
m_file_path = plan.value().path;
|
||||
m_hm_image = img.resize(128, 128);
|
||||
m_hm_preview->tex = std::make_shared<Texture2D>();
|
||||
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, get_resolution(), get_height());
|
||||
m_hm_preview->SetHeight(100);
|
||||
if (plan.value().updates_ground_opacity && m_groud_opacity->get_value() == 0.f)
|
||||
m_groud_opacity->set_value(1.f);
|
||||
m_rt_dirty = true;
|
||||
return true;
|
||||
const auto status = pp::panopainter::execute_legacy_grid_ui_plan(*this, plan.value());
|
||||
if (!status.ok())
|
||||
LOG("Grid heightmap load action failed: %s", status.message);
|
||||
return status.ok();
|
||||
}
|
||||
|
||||
void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camera, bool commit) const
|
||||
|
||||
Reference in New Issue
Block a user