Skip to content

Conversation

@kmichalikk
Copy link
Contributor

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

@kmichalikk kmichalikk requested a review from grzanka December 11, 2025 18:52
@kmichalikk kmichalikk self-assigned this Dec 11, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RemoveFigureCommand to 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.

Copy link
Contributor

@grzanka grzanka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@grzanka grzanka added this pull request to the merge queue Dec 13, 2025
Merged via the queue into master with commit 1bb298f Dec 13, 2025
11 checks passed
@grzanka grzanka deleted the @kmichalikk/figure-draw-fill branch December 13, 2025 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add visualisation of the geometry in the XY, YZ and XZ cross-sections

3 participants