3D Viewer & Coin3D Scene Graph
Relevant source files
The following files were used as context for generating this wiki page:
The 3D Viewer system in Parashell serves as the primary graphical interface for interacting with 3D models. It is built upon the Coin3D library, an Open Inventor-compatible scene graph API, and uses the Quarter library to bridge the gap between Coin3D and the Qt framework.
At its core, the viewer manages a hierarchical scene graph composed of nodes that represent geometry, lighting, cameras, and interactive elements. It provides functionalities for navigation, picking (selection), and rendering through specialized classes that handle user input events and translate them into modifications of the scene graph or view parameters.
Core Architecture
The architecture is layered, starting from a Qt-based widget that integrates with the application's windowing system and extending down to specialized Open Inventor nodes that handle Parashell-specific selection and rendering logic.
Component Relationship
The following diagram illustrates the relationship between the primary classes involved in the 3D viewing system.
The QuarterWidget provides the basic OpenGL context and event handling. View3DInventorViewer extends this to provide Parashell-specific viewing features, and View3DInventor wraps the viewer to integrate it into the document architecture.
Sources: Gui/View3DInventor.cpp, Gui/Quarter/QuarterWidget.cpp, Gui/View3DInventorViewer.cpp
Quarter Integration
The QuarterWidget class is the central point of integration between Qt and Coin3D. It handles the mapping of Qt events (mouse, keyboard, wheel) to Open Inventor events using a SoQtDevice-like mechanism.
| Feature | Description |
|---|---|
| Render Manager | Uses SoRenderManager to handle scene graph traversal and OpenGL rendering. |
| Event Mapping | Translates QMouseEvent and QKeyEvent into SoEvent objects for the scene graph. |
| Navigation | Supports different navigation modes (e.g., Examine, Plane, Walk) via NavigationMode plugins. |
| Background | Manages clear colors and background styles through SoQtBackground nodes. |
Sources: Gui/Quarter/QuarterWidget.cpp:115-180, Gui/Quarter/QuarterWidget.cpp:450-480
Scene Graph Management
The system manages several specialized nodes within the scene graph to provide a rich interactive experience.
Selection and Highlighting
Selection logic is primarily handled by the SoFCSelection node. This node sits at a high level in the scene graph and intercepts events to manage object highlighting and selection states.
The selection mechanism uses a context system (SoFCSelectionContext) to track which objects or sub-elements (faces, edges, vertices) are currently under the cursor or selected.
Sources: Gui/SoFCSelection.cpp:145-200, Gui/SoFCSelectionContext.cpp
Interaction Flow
The following sequence diagram shows how a mouse click is processed to select an item in the 3D view.
Viewer Customization
The View3DInventorViewer provides methods to configure the visual appearance and interaction style of the 3D view.
View Configuration Options
The viewer supports various rendering and navigation settings stored in the application's parameter system.
| Parameter | Type | Default Value | Description |
|---|---|---|---|
| RenderingMode | Enumeration | AS_IS | Defines how geometry is drawn (Wireframe, Points, Shaded, etc.). |
| Transparency | Float | 0.0 | Global transparency override for objects in the view. |
| ShowSelection | Boolean | True | Toggles whether the selection highlight is visible. |
| Backlight | Boolean | False | Enables a secondary light source for better visibility of dark areas. |
Sources: Gui/View3DInventorViewer.cpp:150-250
Advanced Rendering Nodes
The system uses several specialized Coin3D nodes to enhance the visual output:
- SoFCColorGradient: Renders background color gradients.
- SoText2: Used for on-screen annotations and info text.
- SoDirectionalLight: Provides scene illumination; managed dynamically based on camera position.
- SoCamera: Supports both perspective and orthographic projection.
Sources: Gui/View3DInventorViewer.cpp:800-850, Gui/Quarter/QuarterWidget.cpp:1000-1050
Conclusion
The 3D Viewer system effectively leverages Coin3D's scene graph capabilities and Quarter's Qt integration to provide a high-performance, interactive 3D environment. By using specialized nodes like SoFCSelection, Parashell extends the standard Open Inventor behavior to meet complex CAD selection requirements while maintaining a clean separation between the rendering engine and application logic.