More adjustments, still working with Model directly
This commit is contained in:
parent
6661967f9f
commit
ab260d005e
2 changed files with 21 additions and 35 deletions
|
@ -27,7 +27,6 @@ GLGizmoSimplify::GLGizmoSimplify(GLCanvas3D & parent,
|
||||||
// translation for GUI size
|
// translation for GUI size
|
||||||
, tr_mesh_name(_u8L("Mesh name"))
|
, tr_mesh_name(_u8L("Mesh name"))
|
||||||
, tr_triangles(_u8L("Triangles"))
|
, tr_triangles(_u8L("Triangles"))
|
||||||
, tr_preview(_u8L("Preview"))
|
|
||||||
, tr_detail_level(_u8L("Detail level"))
|
, tr_detail_level(_u8L("Detail level"))
|
||||||
, tr_decimate_ratio(_u8L("Decimate ratio"))
|
, tr_decimate_ratio(_u8L("Decimate ratio"))
|
||||||
{}
|
{}
|
||||||
|
@ -139,7 +138,7 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
|
||||||
m_is_valid_result = false;
|
m_is_valid_result = false;
|
||||||
m_exist_preview = false;
|
m_exist_preview = false;
|
||||||
init_model();
|
init_model();
|
||||||
live_preview();
|
process();
|
||||||
|
|
||||||
// set window position
|
// set window position
|
||||||
if (m_move_to_center && change_window_position) {
|
if (m_move_to_center && change_window_position) {
|
||||||
|
@ -185,20 +184,13 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
|
||||||
m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, tr_triangles + ":");
|
m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, tr_triangles + ":");
|
||||||
ImGui::SameLine(m_gui_cfg->top_left_width);
|
ImGui::SameLine(m_gui_cfg->top_left_width);
|
||||||
m_imgui->text(std::to_string(triangle_count));
|
m_imgui->text(std::to_string(triangle_count));
|
||||||
/*
|
|
||||||
m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, tr_preview + ":");
|
|
||||||
ImGui::SameLine(m_gui_cfg->top_left_width);
|
|
||||||
if (m_exist_preview) {
|
|
||||||
m_imgui->text(std::to_string(m_volume->mesh().its.indices.size()));
|
|
||||||
} else {
|
|
||||||
m_imgui->text("---");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
if(ImGui::RadioButton("##use_error", !m_configuration.use_count)) {
|
if(ImGui::RadioButton("##use_error", !m_configuration.use_count)) {
|
||||||
m_configuration.use_count = !m_configuration.use_count;
|
m_configuration.use_count = !m_configuration.use_count;
|
||||||
live_preview();
|
process();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
m_imgui->disabled_begin(m_configuration.use_count);
|
m_imgui->disabled_begin(m_configuration.use_count);
|
||||||
|
@ -223,13 +215,13 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
|
||||||
case 3: m_configuration.max_error = 0.5f; break;
|
case 3: m_configuration.max_error = 0.5f; break;
|
||||||
case 4: m_configuration.max_error = 1.f; break;
|
case 4: m_configuration.max_error = 1.f; break;
|
||||||
}
|
}
|
||||||
live_preview();
|
process();
|
||||||
}
|
}
|
||||||
m_imgui->disabled_end(); // !use_count
|
m_imgui->disabled_end(); // !use_count
|
||||||
|
|
||||||
if (ImGui::RadioButton("##use_count", m_configuration.use_count)) {
|
if (ImGui::RadioButton("##use_count", m_configuration.use_count)) {
|
||||||
m_configuration.use_count = !m_configuration.use_count;
|
m_configuration.use_count = !m_configuration.use_count;
|
||||||
live_preview();
|
process();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
@ -253,7 +245,7 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
|
||||||
if (m_configuration.decimate_ratio > 100.f)
|
if (m_configuration.decimate_ratio > 100.f)
|
||||||
m_configuration.decimate_ratio = 100.f;
|
m_configuration.decimate_ratio = 100.f;
|
||||||
m_configuration.fix_count_by_ratio(triangle_count);
|
m_configuration.fix_count_by_ratio(triangle_count);
|
||||||
live_preview();
|
process();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
|
@ -338,16 +330,6 @@ void GLGizmoSimplify::close() {
|
||||||
gizmos_mgr.open_gizmo(GLGizmosManager::EType::Simplify);
|
gizmos_mgr.open_gizmo(GLGizmosManager::EType::Simplify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoSimplify::live_preview() {
|
|
||||||
m_is_valid_result = false;
|
|
||||||
if (m_state.status != State::settings) {
|
|
||||||
// already canceling process
|
|
||||||
if (m_state.status == State::canceling) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state.status = State::preview;
|
|
||||||
process();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLGizmoSimplify::process()
|
void GLGizmoSimplify::process()
|
||||||
{
|
{
|
||||||
|
@ -383,28 +365,35 @@ void GLGizmoSimplify::process()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_state.progress = 0;
|
m_state.progress = 0;
|
||||||
if (m_worker.joinable()) m_worker.join();
|
if (m_worker.joinable())
|
||||||
|
m_worker.join();
|
||||||
|
|
||||||
m_worker = std::thread([this]() {
|
// Create a copy of current mesh to pass to the worker thread.
|
||||||
|
// Using unique_ptr instead of pass-by-value to avoid an extra
|
||||||
|
// copy (which would happen when passing to std::thread).
|
||||||
|
auto its = std::make_unique<indexed_triangle_set>(*m_original_its);
|
||||||
|
|
||||||
|
m_worker = std::thread([this](std::unique_ptr<indexed_triangle_set> its) {
|
||||||
|
|
||||||
// Checks that the UI thread did not request cancellation, throw if so.
|
// Checks that the UI thread did not request cancellation, throw if so.
|
||||||
std::function<void(void)> throw_on_cancel = [this]() {
|
std::function<void(void)> throw_on_cancel = [this]() {
|
||||||
|
std::lock_guard lk(m_state_mutex);
|
||||||
if (m_state.status == State::canceling)
|
if (m_state.status == State::canceling)
|
||||||
throw SimplifyCanceledException();
|
throw SimplifyCanceledException();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Called by worker thread,
|
// Called by worker thread,
|
||||||
std::function<void(int)> statusfn = [this](int percent) {
|
std::function<void(int)> statusfn = [this](int percent) {
|
||||||
|
std::lock_guard lk(m_state_mutex);
|
||||||
m_state.progress = percent;
|
m_state.progress = percent;
|
||||||
};
|
};
|
||||||
|
|
||||||
indexed_triangle_set collapsed = *m_original_its; // copy
|
|
||||||
uint32_t triangle_count = (m_configuration.use_count) ? m_configuration.wanted_count : 0;
|
uint32_t triangle_count = (m_configuration.use_count) ? m_configuration.wanted_count : 0;
|
||||||
float max_error = (!m_configuration.use_count) ? m_configuration.max_error : std::numeric_limits<float>::max();
|
float max_error = (!m_configuration.use_count) ? m_configuration.max_error : std::numeric_limits<float>::max();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
its_quadric_edge_collapse(collapsed, triangle_count, &max_error, throw_on_cancel, statusfn);
|
its_quadric_edge_collapse(*its, triangle_count, &max_error, throw_on_cancel, statusfn);
|
||||||
set_its(collapsed);
|
set_its(*its);
|
||||||
m_is_valid_result = true;
|
m_is_valid_result = true;
|
||||||
m_exist_preview = true;
|
m_exist_preview = true;
|
||||||
} catch (SimplifyCanceledException &) {
|
} catch (SimplifyCanceledException &) {
|
||||||
|
@ -413,7 +402,7 @@ void GLGizmoSimplify::process()
|
||||||
}
|
}
|
||||||
// need to render last status fn to change bar graph to buttons
|
// need to render last status fn to change bar graph to buttons
|
||||||
request_rerender();
|
request_rerender();
|
||||||
});
|
}, std::move(its));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoSimplify::set_its(const indexed_triangle_set &its) {
|
void GLGizmoSimplify::set_its(const indexed_triangle_set &its) {
|
||||||
|
|
|
@ -51,7 +51,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
void after_apply();
|
void after_apply();
|
||||||
void close();
|
void close();
|
||||||
void live_preview();
|
|
||||||
void process();
|
void process();
|
||||||
void set_its(const indexed_triangle_set &its);
|
void set_its(const indexed_triangle_set &its);
|
||||||
void create_gui_cfg();
|
void create_gui_cfg();
|
||||||
|
@ -80,9 +79,6 @@ private:
|
||||||
|
|
||||||
std::atomic<bool> m_need_reload; // after simplify, glReload must be on main thread
|
std::atomic<bool> m_need_reload; // after simplify, glReload must be on main thread
|
||||||
|
|
||||||
std::thread m_worker;
|
|
||||||
std::mutex m_state_mutex;
|
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
enum Status {
|
enum Status {
|
||||||
settings,
|
settings,
|
||||||
|
@ -96,6 +92,8 @@ private:
|
||||||
indexed_triangle_set result;
|
indexed_triangle_set result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::thread m_worker;
|
||||||
|
std::mutex m_state_mutex; // guards m_state
|
||||||
State m_state;
|
State m_state;
|
||||||
|
|
||||||
struct Configuration
|
struct Configuration
|
||||||
|
@ -144,7 +142,6 @@ private:
|
||||||
// translations used for calc window size
|
// translations used for calc window size
|
||||||
const std::string tr_mesh_name;
|
const std::string tr_mesh_name;
|
||||||
const std::string tr_triangles;
|
const std::string tr_triangles;
|
||||||
const std::string tr_preview;
|
|
||||||
const std::string tr_detail_level;
|
const std::string tr_detail_level;
|
||||||
const std::string tr_decimate_ratio;
|
const std::string tr_decimate_ratio;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue