Gui: Add hidden anchor object to root for transparency (#26590)

* Gui: Add hidden anchor object to the root for transparency

Image planes with transparency failed to render correctly in empty scenes
because OpenInventor's two-pass transparency rendering requires at least
one opaque object to properly initialize the depth buffer.

The fix adds a zero-scaled cube with no material node (making it use
OpenGL's default opaque material) to each image plane's scene graph.
This hidden object:
- Acts as a depth buffer anchor for transparent rendering
- Is invisible (scaled to 0,0,0)
- Has negligible performance impact

This matches the workaround already used in the rotation center indicator
and resolves the issue where image transparency only worked when the
rotation center, grid, or other opaque objects were visible.

* Gui: Exclude hidden anchor from bounding box calculations

Prevents the hidden anchor from affecting "fit all" and other bounding box
operations by wrapping it in `SoSkipBoundingGroup`.
This commit is contained in:
tetektoza
2026-01-03 05:06:26 +01:00
committed by GitHub
parent d944df04e1
commit 3f49f3f059

View File

@@ -548,6 +548,23 @@ void View3DInventorViewer::init()
pcViewProviderRoot->addChild(threePointLightingSeparator);
pcViewProviderRoot->addChild(environment);
// add a global hidden anchor object to ensure transparent objects work correctly
// in empty scenes - OpenInventor's two-pass transparency rendering requires at least
// one opaque object to properly initialize the depth buffer. so this fixes transparency
// issues for image planes, planes, and other transparent geometry.
// wrap in SoSkipBoundingGroup to exclude from bounding box calculations
// check #15192 #24003
auto hiddenAnchor = new SoSkipBoundingGroup();
hiddenAnchor->mode = SoSkipBoundingGroup::EXCLUDE_BBOX;
auto hiddenSep = new SoSeparator();
auto hiddenScale = new SoScale();
hiddenScale->scaleFactor = SbVec3f(0, 0, 0);
auto hiddenCube = new SoCube();
hiddenSep->addChild(hiddenScale);
hiddenSep->addChild(hiddenCube);
hiddenAnchor->addChild(hiddenSep);
pcViewProviderRoot->addChild(hiddenAnchor);
// increase refcount before passing it to setScenegraph(), to avoid
// premature destruction
pcViewProviderRoot->ref();
@@ -1530,15 +1547,6 @@ void View3DInventorViewer::showRotationCenter(bool show)
rotationCenterGroup = new SoSkipBoundingGroup();
auto sphere = new SoSphere();
// There needs to be a non-transparent object to ensure the transparent sphere works
// when opening an new empty document
auto hidden = new SoSeparator();
auto hiddenScale = new SoScale();
hiddenScale->scaleFactor = SbVec3f(0, 0, 0);
hidden->addChild(hiddenScale);
hidden->addChild(sphere);
auto complexity = new SoComplexity();
complexity->value = 1;
@@ -1561,7 +1569,6 @@ void View3DInventorViewer::showRotationCenter(bool show)
scaledSphere->scaleFactor = size;
rotationCenterGroup->addChild(translation);
rotationCenterGroup->addChild(hidden);
rotationCenterGroup->addChild(scaledSphere);
sep->addChild(rotationCenterGroup);