diff --git a/plugins/ui/source/ui/visualizer_drawer.cpp b/plugins/ui/source/ui/visualizer_drawer.cpp index 590b62c8b..212f8f6ce 100644 --- a/plugins/ui/source/ui/visualizer_drawer.cpp +++ b/plugins/ui/source/ui/visualizer_drawer.cpp @@ -27,8 +27,20 @@ namespace hex::ui { ImGui::TextUnformatted("hex.ui.pattern_drawer.visualizer.unknown"_lang); } - if (!m_lastVisualizerError.empty()) - ImGui::TextUnformatted(m_lastVisualizerError.c_str()); + if (!m_lastVisualizerError.empty()) { + auto windowWidth = ImGui::GetContentRegionAvail().x-2 * ImGuiStyleVar_WindowPadding; + auto errorMessageSize = ImGui::CalcTextSize(m_lastVisualizerError.c_str()); + if (errorMessageSize.x > windowWidth) + errorMessageSize.y *= 2; + auto errorMessageWindowSize = ImVec2(windowWidth, errorMessageSize.y); + if (ImGui::BeginChild("##error_message", errorMessageWindowSize, 0, ImGuiWindowFlags_HorizontalScrollbar)) { + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0F, 0.0F, 0.0F, 1.0F)); + ImGui::TextUnformatted(m_lastVisualizerError.c_str()); + ImGui::PopStyleColor(); + } + ImGui::EndChild(); + } + } } \ No newline at end of file diff --git a/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp b/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp index 8b6009dc5..807a7d67d 100644 --- a/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace hex::plugin::visualizers { @@ -97,7 +98,6 @@ namespace hex::plugin::visualizers { ImGuiExt::Texture s_texture; std::fs::path s_texturePath; - std::fs::path s_texturePathOld; u32 s_vertexCount; const auto isIndexInRange = [](auto index) { @@ -153,10 +153,10 @@ namespace hex::plugin::visualizers { if (minCamera[3] != 0) minCamera = minCamera * (1.0F / minCamera[3]); - float max_X = std::max(std::fabs(minCamera[0]), std::fabs(maxCamera[0])); - float max_Y = std::max(std::fabs(minCamera[1]), std::fabs(maxCamera[1])); + float maxX = std::max(std::fabs(minCamera[0]), std::fabs(maxCamera[0])); + float maxY = std::max(std::fabs(minCamera[1]), std::fabs(maxCamera[1])); - return std::max(max_X, max_Y); + return std::max(maxX, maxY); } void setDefaultUVs(std::vector &uv, size_t size) { @@ -376,27 +376,30 @@ namespace hex::plugin::visualizers { buffers.indices = gl::Buffer(gl::BufferType::Index, vectors.indices); if (validateVector(vectors.vertices, vertexCount, 3, "Positions", errorMessage)) { - if ((indexType == IndexType::Undefined || vectors.indices.empty()) && vertexCount % 3 != 0) - throw std::runtime_error("Without indices vertices must be a multiple of 3"); - else + if ((indexType == IndexType::Undefined || vectors.indices.empty()) && vertexCount % 3 != 0) { + throw std::runtime_error("Error: Vertex count must be a multiple of 3"); + } else buffers.vertices = gl::Buffer(gl::BufferType::Vertex, vectors.vertices); - } else + } else { throw std::runtime_error(errorMessage); + } if (validateVector(vectors.colors, vertexCount, 4, "Colors", errorMessage)) buffers.colors = gl::Buffer(gl::BufferType::Vertex, vectors.colors); - else + else { throw std::runtime_error(errorMessage); - + } if (validateVector(vectors.normals, vertexCount, 3, "Normals", errorMessage)) buffers.normals = gl::Buffer(gl::BufferType::Vertex, vectors.normals); - else + else { throw std::runtime_error(errorMessage); + } if (validateVector(vectors.uv, vertexCount, 2, "UV coordinates", errorMessage)) buffers.uv = gl::Buffer(gl::BufferType::Vertex, vectors.uv); - else + else { throw std::runtime_error(errorMessage); + } vertexArray.addBuffer(0, buffers.vertices); vertexArray.addBuffer(1, buffers.colors, 4); @@ -428,18 +431,18 @@ namespace hex::plugin::visualizers { lineBuffers.indices = gl::Buffer(gl::BufferType::Index, lineVectors.indices); if (validateVector(lineVectors.vertices, vertexCount, 3, "Positions", errorMessage)) { - if ((indexType == IndexType::Undefined || lineVectors.indices.empty()) && vertexCount % 3 != 0) - throw std::runtime_error("Without indices vertices must be a multiple of 3"); - else + if ((indexType == IndexType::Undefined || lineVectors.indices.empty()) && vertexCount % 3 != 0) { + throw std::runtime_error("Error: Vertex count must be a multiple of 3"); + } else lineBuffers.vertices = gl::Buffer(gl::BufferType::Vertex, lineVectors.vertices); - } else + } else { throw std::runtime_error(errorMessage); - + } if (validateVector(lineVectors.colors, vertexCount, 4, "Colors", errorMessage)) lineBuffers.colors = gl::Buffer(gl::BufferType::Vertex, lineVectors.colors); - else + else { throw std::runtime_error(errorMessage); - + } vertexArray.addBuffer(0, lineBuffers.vertices); vertexArray.addBuffer(1, lineBuffers.colors, 4); @@ -594,7 +597,7 @@ namespace hex::plugin::visualizers { ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); ImGui::SameLine(); - if (ImGuiExt::DimmedButton("hex.ui.common.reset"_lang, ImVec2(renderingWindowSize.x-ImGui::GetCursorPosX(), 0))) { + if (ImGuiExt::DimmedButton("hex.ui.common.reset"_lang, ImVec2(renderingWindowSize.x+5-ImGui::GetCursorPosX(), 0))) { s_translation = { { 0.0F, 0.0F, -3.0F } }; s_rotation = { { 0.0F, 0.0F, 0.0F } }; s_scaling = 1.0F; @@ -638,7 +641,6 @@ namespace hex::plugin::visualizers { if (s_shouldReset) { s_shouldReset = false; s_shouldUpdateLightSource = true; - if (s_drawMode == GL_TRIANGLES) { Vectors vectors; @@ -649,17 +651,17 @@ namespace hex::plugin::visualizers { s_badIndices.clear(); auto indexCount = vectors.indices.size(); if (indexCount < 3 || indexCount % 3 != 0) { - throw std::runtime_error("Index count must be a multiple of 3"); + throw std::runtime_error("Error: IndexCount must be a multiple of 3"); } auto booleans = std::views::transform(vectors.indices,isIndexInRange); if (!std::accumulate(std::begin(booleans), std::end(booleans), true, std::logical_and<>())) { - std::string badIndicesStr = "Invalid indices: "; + std::string errorMessage = "Error: indices must be between 0 and the number of vertices minus one. Invalid indices: "; for (auto badIndex : s_badIndices) - badIndicesStr += std::to_string(badIndex) + ", "; - badIndicesStr.pop_back(); - badIndicesStr.pop_back(); - badIndicesStr += hex::format(" for {} vertices",s_vertexCount); - throw std::runtime_error(badIndicesStr); + errorMessage += std::to_string(badIndex) + ", "; + errorMessage.pop_back(); + errorMessage.pop_back(); + errorMessage += hex::format(" for {} vertices",s_vertexCount); + throw std::runtime_error(errorMessage); } } @@ -682,17 +684,17 @@ namespace hex::plugin::visualizers { lineVectors.indices = patternToArray(indicesPattern.get()); auto indexCount = lineVectors.indices.size(); if (indexCount < 3 || indexCount % 3 != 0) { - throw std::runtime_error("Index count must be a multiple of 3"); + throw std::runtime_error("Error: IndexCount must be a multiple of 3"); } s_badIndices.clear(); if (!std::ranges::all_of(lineVectors.indices,isIndexInRange)) { - std::string badIndicesStr = "Invalid indices: "; + std::string errorMessage = "Error: indices must be between 0 and the number of vertices minus one. Invalid indices: "; for (auto badIndex : s_badIndices) - badIndicesStr += std::to_string(badIndex) + ", "; - badIndicesStr.pop_back(); - badIndicesStr.pop_back(); - badIndicesStr += hex::format(" for {} vertices",s_vertexCount); - throw std::runtime_error(badIndicesStr); + errorMessage += std::to_string(badIndex) + ", "; + errorMessage.pop_back(); + errorMessage.pop_back(); + errorMessage += hex::format(" for {} vertices",s_vertexCount); + throw std::runtime_error(errorMessage); } }