Add support for Geant4 geometry in Viewport.ClippedViewCSG#2305
Merged
Add support for Geant4 geometry in Viewport.ClippedViewCSG#2305
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for visualizing Geant4 geometry in the ClippedViewCSG viewport system. Unlike the original CSG (Constructive Solid Geometry) assumption where figures don't intersect, Geant4 geometry consists of nested figures where children are fully contained within their parents. The solution employs a rendering heuristic using renderOrder with disabled depthTest to ensure child figures are drawn on top of their parents, preventing z-fighting artifacts.
Key changes:
- Introduced dynamic viewport configuration that switches between zone-based signals (non-Geant4) and figure-based signals (Geant4) when the simulator type changes
- Added recursive handling for nested Geant4 figures in the ClippedViewCSG system with renderOrder calculation based on hierarchy depth
- Implemented
RemoveFigureCommandto properly dispatch removal signals for nested figure hierarchies
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util/hooks/useKeyboardEditorControls.ts | Routes BasicFigure deletion through new RemoveFigureCommand for proper nested signal handling |
| src/services/StoreService.tsx | Dispatches simulatorChanged signal when simulator type changes to trigger viewport reconfiguration |
| src/ThreeEditor/js/viewport/Viewport.js | Implements dynamic viewport setup that switches signal listeners based on simulator type (zones vs figures) |
| src/ThreeEditor/js/viewport/Viewport.ClippedViewCSG.ts | Adds recursive child handling, renderOrder calculation for Geant4, and detachSignals cleanup method |
| src/ThreeEditor/js/commands/RemoveFigureCommand.ts | New command that recursively dispatches figureRemoved/figureAdded signals for nested Geant4 geometry |
| src/ThreeEditor/js/YaptideEditor.js | Adds simulatorChanged signal definition and dispatches it during project loading |
| src/ThreeEditor/Simulation/Zones/BooleanZone.ts | Dispatches zoneAdded signal during deserialization for viewport initialization |
| src/ThreeEditor/Simulation/Figures/FigureManager.ts | Updates to dispatch figureAdded/figureRemoved signals and notify viewports during deserialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2217
This PR forces ClippedViewCSG to work with Geant4 geometry.
The class has been originally written to display the constructive solid geometry that has no intersecting parts.
In Geant4 case all figures are nested inside each other, so this is the exact opposite to the prior assumption.
However, since the cameras in the viewports are fixed to look directly at the slices, and each Geant4 figure is either a) fully within its parent or b) to the side of its sibling, with no intersection, we can employ a simple heuristic to draw children always on top of its parents. We can use renderOrder with depthTest disabled to force the renderer to paint the children after the parent. This gets rid of z-fighting and seems to be working reliably provided that the hierarchy is valid (no intersections).
Since the example has all materials set to black, you need to change them in order to see each view