Extract grid UI operation planning

This commit is contained in:
2026-06-03 10:52:51 +02:00
parent a487b0ba48
commit 73fac0f8e4
9 changed files with 522 additions and 37 deletions

View File

@@ -1,4 +1,5 @@
#include "pch.h"
#include "app_core/grid_ui.h"
#include "log.h"
#include "node_panel_grid.h"
#include "canvas.h"
@@ -77,28 +78,19 @@ 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) {
Image img;
if (img.load_file(path))
{
m_file_path = 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 (m_groud_opacity->get_value() == 0.f)
m_groud_opacity->set_value(1.f);
m_rt_dirty = true;
}
load_heightmap_file(path, true);
});
};
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();
@@ -107,24 +99,26 @@ void NodePanelGrid::init_controls()
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 = 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);
m_rt_dirty = true;
}
load_heightmap_file(m_file_path, false);
};
m_render->on_click = [this](Node*)
{
if (ShaderManager::ext_float32 || ShaderManager::ext_float16)
const auto plan = pp::app::plan_grid_lightmap_render(
static_cast<bool>(m_hm_image.data()),
ShaderManager::ext_float32,
ShaderManager::ext_float16,
get_texres(),
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();
@@ -133,18 +127,17 @@ void NodePanelGrid::init_controls()
m_shade_mode = ShadeMode::Textured;
}).detach();
}
else
{
App::I->message_box("Rendering failed",
"Your hardware does not support lightmap rendering.");
}
};
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);
m_groud_opacity->set_value(0);
if (plan.updates_ground_opacity)
m_groud_opacity->set_value(0);
};
m_hm_texres->on_select = [this](Node*, int index) {
int texres = get_texres();
@@ -226,6 +219,33 @@ float NodePanelGrid::get_offset() const
return glm::pow(m_groud_offset->get_value() - 0.5f, 3);
}
bool NodePanelGrid::load_heightmap_file(const std::string& path, bool raise_ground_opacity)
{
const auto plan = raise_ground_opacity
? pp::app::plan_grid_heightmap_load(path)
: pp::app::plan_grid_heightmap_reload(path);
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;
}
void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camera, bool commit) const
{
assert(App::I->is_render_thread());