Install
dotnet add package HelixToolkit.Nex.ImGui --version 1.3.0
| Product | Versions |
|---|---|
| .NET |
README
# HelixToolkit.Nex.ImGui
The `HelixToolkit.Nex.ImGui` package provides integration with the ImGui library, enabling developers to create rich, immediate-mode graphical user interfaces within the HelixToolkit.Nex 3D graphics engine. This package facilitates the rendering of ImGui elements using Vulkan, leveraging the HelixToolkit.Nex's rendering capabilities.
## Overview
`HelixToolkit.Nex.ImGui` serves as a bridge between the ImGui library and the HelixToolkit.Nex engine, allowing developers to render ImGui interfaces within their 3D applications. It manages the setup and rendering of ImGui contexts, including font management and shader compilation. The package is designed to work seamlessly with the HelixToolkit.Nex's rendering pipeline, utilizing its ECS architecture and render graph system.
## Key Types
| Type | Description |
|-----------------|-----------------------------------------------------------------------------|
| `ImGuiConfig` | Configuration class for setting up ImGui, including font path and size. |
| `ImGuiRenderer` | Main class responsible for rendering ImGui elements within the engine. |
| `Viewport` | Reusable 3D viewport region for ImGui-hosted demos, translating mouse input into camera-controller and picking operations. |
## Usage Examples
### Basic Setup
To use the `ImGuiRenderer`, you need to initialize it with a rendering context and configuration, then integrate it into your rendering loop.
```csharp
using HelixToolkit.Nex.ImGui;
using HelixToolkit.Nex.Graphics;
// Create an ImGui configuration
var config = new ImGuiConfig
{
FontPath = "path/to/font.ttf",
FontSizeInPixel = 18
};
// Initialize the ImGui renderer with a rendering context
var context = /* Obtain IContext from HelixToolkit.Nex */;
var imguiRenderer = new ImGuiRenderer(context, config);
// Initialize the renderer with the target format
imguiRenderer.Initialize(Format.RGBA_UN8);
// In your rendering loop
imguiRenderer.BeginFrame(new Vector2(windowWidth, windowHeight));
// ImGui commands go here
ImGuiNET.ImGui.Text("Hello, ImGui!");
imguiRenderer.EndFrame();
// Render ImGui
imguiRenderer.Render(commandBuffer, renderPass, framebuffer, dependencies);
Viewport Integration
To use the Viewport class, instantiate it with a render context and optionally a camera controller. Use the Draw method to render the viewport.
using HelixToolkit.Nex.ImGui;
using HelixToolkit.Nex.Rendering;
// Create a render context
var renderContext = /* Obtain RenderContext from HelixToolkit.Nex */;
var viewport = new Viewport(renderContext);
// In your rendering loop
viewport.Draw(offscreenTexture);
Architecture Notes
- Design Patterns: The
ImGuiRendererutilizes the IDisposable pattern to manage resources effectively, ensuring that Vulkan resources are properly released. - Dependencies: This package depends on the
HelixToolkit.Nex.GraphicsandHelixToolkit.Nex.Shaderspackages for rendering and shader management. - Integration: The renderer is designed to fit into the HelixToolkit.Nex's ECS and render graph architecture, allowing for efficient and organized rendering of ImGui elements alongside other 3D content.
Recent Changes
- Target Framework Update: The project now targets .NET 9.0, ensuring compatibility with the latest features and improvements.
- Depth State Binding: The
ImGuiRenderernow explicitly binds theDepthState.Disabledduring rendering, ensuring depth testing is disabled for ImGui elements. - Debug Group Label: The
ImGuiRendereruses a static byte array for the debug group label, improving performance by avoiding repeated string allocations. - Platform Configurations: The project includes additional build configurations for Linux (
LinuxDebugandLinuxRelease), enhancing cross-platform support.
Changes from Previous Version
v1.2.0v1.3.0
Added Frameworks
net9.0
Removed Frameworks
net8.0
Added Dependencies
HelixToolkit.Nex.Engine(net9.0)
HelixToolkit.Nex.Graphics(net9.0)
HelixToolkit.Nex.Rendering(net9.0)
HelixToolkit.Nex.Shaders(net9.0)
ImGui.NET(net9.0)
Removed Dependencies
HelixToolkit.Nex.Engine(net8.0)
HelixToolkit.Nex.Graphics(net8.0)
HelixToolkit.Nex.Rendering(net8.0)
HelixToolkit.Nex.Shaders(net8.0)
ImGui.NET(net8.0)
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Compatibility metadata lists 1 target framework; confirm the exact target used by your application.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.