pkdawson / imgui-godot

Dear ImGui plugin for Godot 4
MIT License
318 stars 18 forks source link

3D rendering panels/framebuffers #54

Closed Aman-Anas closed 1 month ago

Aman-Anas commented 2 months ago

Howdy, I was wondering if you had any advice on making an imgui panel that renders in 3D space (similar to the 3D Gui example in the godot examples repo).

I've done this before in another game engine by modifying the imgui renderer to render the frame to an FBO, and then I can use that framebuffer as the source for a texture. In my experience it works really well, and I can just give each panel its own context if needed. Maybe multi-viewports is better though, but I have not used it before. I also am not super familiar with godot's rendering abstraction, it's a little different from directly calling OpenGL to make framebuffers.

Another approach might be to render imgui in another scene, and then render that scene to texture to display in-game? I don't know how this would affect performance (I have not done this before), would it be the easiest solution?

My usecase is that a) I like using imgui :D and b) it makes it easy to implement dynamic UI for in-game panels. I think this would also be very useful for debugging in VR/XR setups, similar to how Desktop+ uses imgui for its settings menu.

Would it be better to wait until the GDExtension work has progressed more? I'd be interested in contributing to docs and other things if needed.

pkdawson commented 2 months ago

This is a feature I can add. Rendering to a different SubViewport is easy enough. After considering the design issues, I think it'd be best to let users of this plugin select a main viewport, and then decide how they want to push inputs to that viewport. I think that will work, but we'll see how the implementation goes.

Would it be better to wait until the GDExtension work has progressed more?

Yeah, but only because I want to finish that first before working on new features. Then I can comfortably maintain parallel C# and C++ implementations. I'm trying to finish that very soon.

pkdawson commented 1 month ago

Implemented ImGuiGD.SetMainViewport() in v5.1.0

https://github.com/pkdawson/imgui-godot/blob/a9217944e6e660084ebf32b702d2f6301b299c9a/src/ThirdNode.cs#L11-L12

I borrowed the gui_in_3d demo scene and made only some cosmetic changes, the GDScript for handling input is identical.