Clear filters on model load, show no-match hints, support system clipboard and non-ASCII text input

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
gs5579andDevin AI committed 2026-11-27 10:05:36 +00:00
1 parent 462593571f
commit d4c34f8908
4 files changed
+65 -3

No files matched your search

+2 -1
View File
@@ -57,7 +57,8 @@ add_library(imgui STATIC
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends)
target_link_libraries(imgui PUBLIC OpenGL::GL)
if(APPLE)
target_compile_definitions(imgui PUBLIC GL_SILENCE_DEPRECATION)
target_compile_definitions(imgui PUBLIC GL_SILENCE_DEPRECATION IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS)
target_link_libraries(imgui PUBLIC "-framework ApplicationServices")
endif()
# --- Text encoding (Shift-JIS for PMD) -------------------------------------------
+3 -1
View File
@@ -45,12 +45,14 @@ cmake --build build
```sh
sudo apt install build-essential cmake ninja-build libopenscenegraph-dev libassimp-dev \
libgl1-mesa-dev fonts-noto-cjk
libgl1-mesa-dev fonts-noto-cjk xclip
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/model_renderer path/to/model.pmx
```
Copy/paste in text fields uses `xclip` or `xsel` on X11 and `wl-clipboard` on Wayland.
Fedora: `sudo dnf install cmake ninja-build gcc-c++ OpenSceneGraph-devel assimp-devel google-noto-sans-cjk-fonts`.
### Windows (Visual Studio 2022 + vcpkg)
+9
View File
@@ -59,6 +59,8 @@ bool App::loadModel(const std::string& path) {
modelNode_ = new ModelNode(model);
root_->addChild(modelNode_);
selectedBone_ = -1;
boneFilter_[0] = '\0';
morphFilter_[0] = '\0';
lightingModel_ = model->format == SourceFormat::Assimp ? 1 : 0;
applyViewSettings();
frameModel();
@@ -203,6 +205,7 @@ void App::drawBonesWindow() {
ImGui::InputTextWithHint("##bonefilter", "Filter bones", boneFilter_, sizeof(boneFilter_));
ImGui::Checkbox("Only visible / skinning bones", &onlyVisibleBones_);
ImGui::BeginChild("bonelist");
int shown = 0;
for (size_t i = 0; i < m.bones.size(); ++i) {
const Bone& b = m.bones[i];
if (onlyVisibleBones_ && !b.visible && !b.isSkinBone) continue;
@@ -210,6 +213,7 @@ void App::drawBonesWindow() {
int depth = 0;
for (int p = b.parent; p >= 0 && depth < 32; p = m.bones[p].parent) ++depth;
if (*boneFilter_) depth = 0;
++shown;
const bool posed = poses[i] != BonePose();
std::string label = std::string(static_cast<size_t>(std::min(depth, 12)) * 2, ' ') + (posed ? "* " : "") +
b.name + "##" + std::to_string(i);
@@ -218,6 +222,7 @@ void App::drawBonesWindow() {
modelNode_->setSelectedBone(selectedBone_);
}
}
if (shown == 0) ImGui::TextDisabled(*boneFilter_ ? "No bones match the filter." : "No bones to show.");
ImGui::EndChild();
ImGui::End();
}
@@ -232,6 +237,10 @@ void App::drawMorphsWindow() {
ImGui::SetNextItemWidth(-1);
ImGui::InputTextWithHint("##morphfilter", "Filter morphs", morphFilter_, sizeof(morphFilter_));
if (m.morphs.empty()) ImGui::TextDisabled("This model has no morphs.");
int shown = 0;
for (const auto& morph : m.morphs)
shown += containsCaseInsensitive(morph.name, morphFilter_) || containsCaseInsensitive(morph.nameEn, morphFilter_);
if (!m.morphs.empty() && shown == 0) ImGui::TextDisabled("No morphs match the filter.");
const MorphPanel order[] = {MorphPanel::Eye, MorphPanel::Mouth, MorphPanel::Eyebrow, MorphPanel::Other,
MorphPanel::System};
for (MorphPanel panel : order) {
+51 -1
View File
@@ -8,6 +8,8 @@
#include <osgDB/WriteFile>
#include <osgGA/GUIEventHandler>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <iostream>
@@ -42,6 +44,46 @@ ImGuiKey mapKey(int key) {
return ImGuiKey_None;
}
#if !defined(_WIN32) && !defined(__APPLE__)
// ImGui only has native clipboard support on Windows and macOS; on Linux use the standard CLI tools.
std::string g_clipboard;
const char* const* clipboardCommands(bool paste) {
static const char* const waylandPaste[] = {"wl-paste -n 2>/dev/null", nullptr};
static const char* const waylandCopy[] = {"wl-copy 2>/dev/null", nullptr};
static const char* const x11Paste[] = {"xclip -selection clipboard -o 2>/dev/null", "xsel -bo 2>/dev/null", nullptr};
static const char* const x11Copy[] = {"xclip -selection clipboard -i 2>/dev/null", "xsel -bi 2>/dev/null", nullptr};
const bool wayland = std::getenv("WAYLAND_DISPLAY") != nullptr;
return paste ? (wayland ? waylandPaste : x11Paste) : (wayland ? waylandCopy : x11Copy);
}
const char* getClipboardText(ImGuiContext*) {
for (const char* const* cmd = clipboardCommands(true); *cmd; ++cmd) {
FILE* pipe = popen(*cmd, "r");
if (!pipe) continue;
std::string text;
char buf[4096];
size_t n;
while ((n = fread(buf, 1, sizeof(buf), pipe)) > 0) text.append(buf, n);
if (pclose(pipe) == 0) {
g_clipboard = text;
break;
}
}
return g_clipboard.c_str();
}
void setClipboardText(ImGuiContext*, const char* text) {
g_clipboard = text ? text : "";
for (const char* const* cmd = clipboardCommands(false); *cmd; ++cmd) {
FILE* pipe = popen(*cmd, "w");
if (!pipe) continue;
fwrite(g_clipboard.data(), 1, g_clipboard.size(), pipe);
if (pclose(pipe) == 0) break;
}
}
#endif
class InitOperation : public osg::Operation {
public:
explicit InitOperation(ImGuiOsg* owner) : osg::Operation("ImGuiInit", false), owner_(owner) {}
@@ -132,8 +174,11 @@ public:
int key = ea.getUnmodifiedKey() ? ea.getUnmodifiedKey() : ea.getKey();
ImGuiKey imguiKey = mapKey(key);
if (imguiKey != ImGuiKey_None) io.AddKeyEvent(imguiKey, down);
// OSG reports special keys as X11-style keysyms in 0xFF00-0xFFFF; everything else is a character.
int ch = ea.getKey();
if (down && ch >= 32 && ch < 127) io.AddInputCharacter(static_cast<unsigned>(ch));
const bool ctrlOrSuper = (ea.getModKeyMask() & (E::MODKEY_CTRL | E::MODKEY_SUPER)) != 0;
if (down && !ctrlOrSuper && ch >= 32 && ch != 127 && !(ch >= 0xFF00 && ch <= 0xFFFF))
io.AddInputCharacter(static_cast<unsigned>(ch));
return io.WantCaptureKeyboard;
}
default: return false;
@@ -148,6 +193,11 @@ ImGuiOsg::ImGuiOsg(DrawFunction draw) : draw_(std::move(draw)) {
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = nullptr;
#if !defined(_WIN32) && !defined(__APPLE__)
ImGuiPlatformIO& platformIo = ImGui::GetPlatformIO();
platformIo.Platform_GetClipboardTextFn = getClipboardText;
platformIo.Platform_SetClipboardTextFn = setClipboardText;
#endif
ImGui::StyleColorsDark();
ImGui::GetStyle().WindowRounding = 4.f;
loadFonts();