102 lines
3.1 KiB
C++
102 lines
3.1 KiB
C++
#include "pch.h"
|
|
|
|
#include "legacy_grid_ui_services.h"
|
|
|
|
#include "app.h"
|
|
#include "canvas.h"
|
|
#include "image.h"
|
|
#include "node_panel_grid.h"
|
|
|
|
namespace pp::panopainter {
|
|
namespace {
|
|
|
|
class LegacyGridUiServices final : public pp::app::GridUiServices {
|
|
public:
|
|
explicit LegacyGridUiServices(NodePanelGrid& panel) noexcept
|
|
: panel_(panel)
|
|
{
|
|
}
|
|
|
|
void request_heightmap_pick() override
|
|
{
|
|
auto* panel = &panel_;
|
|
App::I->pick_image([panel](std::string path) {
|
|
panel->load_heightmap_file(path, true);
|
|
});
|
|
}
|
|
|
|
pp::foundation::Status load_heightmap(std::string_view path, bool raise_ground_opacity) override
|
|
{
|
|
Image img;
|
|
if (!img.load_file(std::string(path)))
|
|
return pp::foundation::Status::invalid_argument("heightmap image could not be loaded");
|
|
|
|
panel_.m_file_path = std::string(path);
|
|
panel_.m_hm_image = img.resize(128, 128);
|
|
panel_.m_hm_preview->tex = std::make_shared<Texture2D>();
|
|
panel_.m_hm_preview->tex->create(panel_.m_hm_image);
|
|
panel_.m_hm_preview->tex->create_mipmaps();
|
|
auto sz = panel_.m_hm_preview->tex->size();
|
|
panel_.m_hm_preview->SetAspectRatio(sz.x / sz.y);
|
|
panel_.m_hm_plane.create(1, 1, panel_.m_hm_image, panel_.get_resolution(), panel_.get_height());
|
|
panel_.m_hm_preview->SetHeight(100);
|
|
if (raise_ground_opacity && panel_.m_groud_opacity->get_value() == 0.f)
|
|
panel_.m_groud_opacity->set_value(1.f);
|
|
panel_.m_rt_dirty = true;
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
void clear_heightmap(bool updates_preview) override
|
|
{
|
|
panel_.m_hm_plane.create(1, 1, 100 * panel_.get_resolution());
|
|
panel_.m_hm_image.destroy();
|
|
panel_.m_hm_preview->tex.reset();
|
|
panel_.m_hm_preview->SetHeight(0);
|
|
}
|
|
|
|
void render_lightmap(bool shows_unsupported_message, bool renders_lightmap) override
|
|
{
|
|
if (shows_unsupported_message)
|
|
{
|
|
App::I->message_box("Rendering failed",
|
|
"Your hardware does not support lightmap rendering.");
|
|
return;
|
|
}
|
|
|
|
if (!renders_lightmap)
|
|
return;
|
|
|
|
auto* panel = &panel_;
|
|
std::thread([panel] {
|
|
BT_SetTerminate();
|
|
panel->bake_uvs();
|
|
panel->m_hm_shading->set_index(3);
|
|
panel->m_shade_mode = NodePanelGrid::ShadeMode::Textured;
|
|
}).detach();
|
|
}
|
|
|
|
void commit_heightmap(bool updates_ground_opacity) override
|
|
{
|
|
Canvas::I->draw_objects([this](const glm::mat4& camera, const glm::mat4& proj, int i) {
|
|
panel_.draw_heightmap(proj, camera, true);
|
|
}, Canvas::I->layer().m_frame_index, true);
|
|
if (updates_ground_opacity)
|
|
panel_.m_groud_opacity->set_value(0);
|
|
}
|
|
|
|
private:
|
|
NodePanelGrid& panel_;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
pp::foundation::Status execute_legacy_grid_ui_plan(
|
|
NodePanelGrid& panel,
|
|
const pp::app::GridUiPlan& plan)
|
|
{
|
|
LegacyGridUiServices services(panel);
|
|
return pp::app::execute_grid_ui_plan(plan, services);
|
|
}
|
|
|
|
} // namespace pp::panopainter
|