diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 0df8fabdb..58e115e62 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 0df8fabdbf2ef22bcae2cbb717454245d8fa44ba +Subproject commit 58e115e621687506a822378529f83deb773005fa diff --git a/lib/libimhex/include/hex/helpers/opengl.hpp b/lib/libimhex/include/hex/helpers/opengl.hpp index 6a7a80eaf..1f8eb8c85 100644 --- a/lib/libimhex/include/hex/helpers/opengl.hpp +++ b/lib/libimhex/include/hex/helpers/opengl.hpp @@ -75,6 +75,13 @@ namespace hex::gl { return copy; } + auto operator==(const Vector& other) { + for (size_t i = 0; i < Size; i++) + if (this->m_data[i] != other[i]) + return false; + return true; + } + private: std::array m_data; }; diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 6bd453939..4ab8fed4e 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -54,6 +54,7 @@ "hex.builtin.common.range.entire_data": "Entire Data", "hex.builtin.common.range.selection": "Selection", "hex.builtin.common.region": "Region", + "hex.builtin.common.reset": "Reset", "hex.builtin.common.set": "Set", "hex.builtin.common.size": "Size", "hex.builtin.common.type": "Type", @@ -344,6 +345,8 @@ "hex.builtin.pattern_drawer.var_name": "Name", "hex.builtin.pattern_drawer.visualizer.unknown": "Unknown visualizer", "hex.builtin.pattern_drawer.visualizer.invalid_parameter_count": "Invalid parameter count", + "hex.builtin.pl_visualizer.3d.rotation": "Rotation", + "hex.builtin.pl_visualizer.3d.scale": "Scale", "hex.builtin.popup.close_provider.desc": "There are unsaved changes made to this Provider\nthat haven't been saved to a Project yet.\n\nAre you sure you want to close it?", "hex.builtin.popup.close_provider.title": "Close Provider?", "hex.builtin.popup.error.create": "Failed to create new file!", diff --git a/plugins/builtin/source/content/pl_visualizers.cpp b/plugins/builtin/source/content/pl_visualizers.cpp index b47c05f7e..764d5334e 100644 --- a/plugins/builtin/source/content/pl_visualizers.cpp +++ b/plugins/builtin/source/content/pl_visualizers.cpp @@ -184,11 +184,14 @@ namespace hex::plugin::builtin { auto indicesPattern = arguments[1].toPattern(); static ImGui::Texture texture; - static float scaling = 0.5F; - static gl::Vector rotation = { { 1.0F, -1.0F, 0.0F } }; + static gl::Vector translation; + static gl::Vector rotation = { { 1.0F, -1.0F, 0.0F } }; + static float scaling = 0.1F; + static std::vector vertices, normals; static std::vector indices; + static gl::Shader shader; static gl::VertexArray vertexArray; static gl::Buffer vertexBuffer, normalBuffer; @@ -264,7 +267,7 @@ namespace hex::plugin::builtin { { gl::FrameBuffer frameBuffer; - gl::Texture renderTexture(512, 512); + gl::Texture renderTexture(400_scaled, 400_scaled); frameBuffer.attachTexture(renderTexture); frameBuffer.bind(); @@ -298,7 +301,54 @@ namespace hex::plugin::builtin { texture = ImGui::Texture(renderTexture.release(), renderTexture.getWidth(), renderTexture.getHeight()); } - ImGui::Image(texture, texture.getSize(), ImVec2(0, 1), ImVec2(1, 0)); + auto textureSize = texture.getSize(); + + if (ImGui::BeginTable("##3DVisualizer", 2, ImGuiTableFlags_SizingFixedFit)) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + if (ImGui::BeginChild("##image", textureSize, true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { + ImGui::Image(texture, textureSize, ImVec2(0, 1), ImVec2(1, 0)); + } + ImGui::EndChild(); + ImGui::PopStyleVar(); + + ImGui::TableNextColumn(); + ImGui::TextUnformatted("hex.builtin.pl_visualizer.3d.rotation"_lang); + ImGui::VSliderFloat("##X", ImVec2(18_scaled, textureSize.y), &rotation.data()[0], 0, std::numbers::pi * 2, "", ImGuiSliderFlags_AlwaysClamp); + ImGui::SameLine(); + ImGui::VSliderFloat("##Y", ImVec2(18_scaled, textureSize.y), &rotation.data()[1], 0, std::numbers::pi * 2, "", ImGuiSliderFlags_AlwaysClamp); + ImGui::SameLine(); + ImGui::VSliderFloat("##Z", ImVec2(18_scaled, textureSize.y), &rotation.data()[2], 0, std::numbers::pi * 2, "", ImGuiSliderFlags_AlwaysClamp); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + + ImGui::TextUnformatted("hex.builtin.pl_visualizer.3d.scale"_lang); + ImGui::SameLine(); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::SliderFloat("##Scale", &scaling, 0.0001F, 0.2F, ""); + ImGui::PopItemWidth(); + + for (u8 i = 0; i < 3; i++) { + while (rotation.data()[i] > std::numbers::pi * 2) + rotation.data()[i] -= std::numbers::pi * 2; + while (rotation.data()[i] < 0) + rotation.data()[i] += std::numbers::pi * 2; + } + + ImGui::TableNextColumn(); + + if (ImGui::Button("hex.builtin.common.reset"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) { + translation = gl::Vector({ 0.0F, 0.0F, 0.0F }); + rotation = gl::Vector({ 0.0F, 0.0F, 0.0F }); + scaling = 0.1F; + } + + ImGui::EndTable(); + } + + } void drawSoundVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) {