A Dear ImGui backend for Python-based Panda3D projects with built-in utilities (based on DIRECT Tools).
This module will allow you to use and create Dear ImGui user interfaces within a Panda3D window, preferbly used to create content creation/debugging tools. (It uses Dear ImGui Bundle which contains not only the Python bindings for Dear ImGui, but with other goodies as well.
It is based on the C++ based project with the similar name. The difference that it is ported to Python for such users to use on their projects.
You can install the module through pip:
pip install panda3d-imgui
And you can import this module as p3dimgui
import p3dimguiIt has a helper method called init which you can easlily add in your ShowBase class. This will create a ImGuiBackend object into base.imgui
and initialize it, along side the built-in ultilities.
from direct.showbase.ShowBase import ShowBase
from imgui_bundle import imgui
import p3dimgui
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Install Dear ImGui
p3dimgui.init()Once initalized, it will send an event called imgui-new-frame every frame. You can accept this event whenever you want to draw with ImGui:
def draw(self):
# Show the demo window.
imgui.show_demo_window()
self.accept('imgui-new-frame', self.draw)Combine all this and you would have something like this, which will start up a new Panda3D window and shows the Dear ImGui demo window.
from direct.showbase.ShowBase import ShowBase
from imgui_bundle import imgui
import p3dimgui
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Install Dear ImGui
p3dimgui.init()
self.accept('imgui-new-frame', self.draw)
def draw(self):
# Show the demo window.
imgui.show_demo_window()
app = MyApp()
app.run()
For a more better demo which showcases all the built-in utilities aviliable (like the screenshot at the top), see the demo.py file.