Viewer components are a set of helpful tools to implement a custom viewer. In this article we will give access to a simple example to show you how you can create your own viewer, based on Open Inventor viewers components, and customize them with Dear ImGui, the bloat-free graphical user interface library developed by Omar Cornut.
Note: This simple example comes with a script to generate a solution to be loaded by Visual Studio under Windows. Some modifications have to be done if you want to test it on another platform supported by Open Inventor.
- First thing first, in order to be able to launch the demonstrator you will need a valid installation of Open Inventor 10.9 C++ for Windows (please refer to Download Page). In the following document, the folder where Open Inventor 10.9 is installed will be referred as OIVHOME.
- Once Open Inventor 10.9 is installed on your computer, download the Demo Package from here. It is a zip archive with the following content
- setup-build.bat : a simple batch file which will simplify the generation of Visual Studio Solution
- README.txt: text file with general informations
- LICENSE.txt: the license attached to Dear ImGui library
- CMakeList.txt: the top CMakeLists used to generate the Visual Studio Solution
- libs : folder containing source of the used libs
- HelloConeDearImGui: the folder containing sources for the example
- Open the file setup-build.bat with a text editor to set the value defining your configuration
- set the OIVHOME value to point to the folder where is installed Open Inventor 10.9 on your system
- set the Qt5HOME value to point to the folder where is installed you Qt5 (make sure inside this folder you can find a lib\cmake\Qt5 subfolder)
- Optionnal : this setup will generate a solution to be loaded with Visual Studio 2019. If you want to use another version of Visual Studio please take a look at line 22 (cmake call) and line 28 to change the path to your Visual Studio. Eventually if you did not download a Visual Studio 2017 version of Open Inventor, change the OIVARCH variable so it matches your configuration
Once the script file matches your configuration simply double click on it. It will run cmake configuration, cmake generation and open the generated solution with Open Visual Studio 2019.
Once the solution is loaded in Visual Studio, simply choose Debug or Release configuration and run the default project. Note this is higly recommended to use Release to get better performances.
The example consists of a simple SoAlgebraicCone and the Dear ImGui interface to manipulate some of the nodes.
Some interesting points regarding the source code
- How the interface is implemented can be understood by looking the scenegraph.cxx source file (located in HelloConeDearImGui folder) in the function
- Scene interactor (
SceneOrbiter) is passed as parameter to the scene manager via the call
scene::ImguiSceneManager* sceneManager = new scene::ImguiSceneManager(orbiter);in
HelloConeImgui::run(int argc, char** argv) method of app.cxx
- The SceneManager is defined by the class
and associated to the viewer via the call to
renderWidget = new viewer::RenderWidget( sceneManager ); done in
HelloConeImgui::run at the startup of the application.
This simple design allows to use whatever scene interactor you want with one design of scene manager. In the same way, the viewer can use any scene manager without redefining anything.
As simple as this example is, it shows how easy it can be to provide a useful interface to see how a scene reacts to any change in the scene graph. Dear ImGui comes with lots of widgets (input boxes, labels, buttons, progress bars, trees, sliders and much more) allowing to interact with all fields available in Open Inventor.