Skip to content

Commit 3f49f3f

Browse files
authored
Gui: Add hidden anchor object to root for transparency (FreeCAD#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`.
1 parent d944df0 commit 3f49f3f

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/Gui/View3DInventorViewer.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,23 @@ void View3DInventorViewer::init()
548548
pcViewProviderRoot->addChild(threePointLightingSeparator);
549549
pcViewProviderRoot->addChild(environment);
550550

551+
// add a global hidden anchor object to ensure transparent objects work correctly
552+
// in empty scenes - OpenInventor's two-pass transparency rendering requires at least
553+
// one opaque object to properly initialize the depth buffer. so this fixes transparency
554+
// issues for image planes, planes, and other transparent geometry.
555+
// wrap in SoSkipBoundingGroup to exclude from bounding box calculations
556+
// check #15192 #24003
557+
auto hiddenAnchor = new SoSkipBoundingGroup();
558+
hiddenAnchor->mode = SoSkipBoundingGroup::EXCLUDE_BBOX;
559+
auto hiddenSep = new SoSeparator();
560+
auto hiddenScale = new SoScale();
561+
hiddenScale->scaleFactor = SbVec3f(0, 0, 0);
562+
auto hiddenCube = new SoCube();
563+
hiddenSep->addChild(hiddenScale);
564+
hiddenSep->addChild(hiddenCube);
565+
hiddenAnchor->addChild(hiddenSep);
566+
pcViewProviderRoot->addChild(hiddenAnchor);
567+
551568
// increase refcount before passing it to setScenegraph(), to avoid
552569
// premature destruction
553570
pcViewProviderRoot->ref();
@@ -1530,15 +1547,6 @@ void View3DInventorViewer::showRotationCenter(bool show)
15301547
rotationCenterGroup = new SoSkipBoundingGroup();
15311548

15321549
auto sphere = new SoSphere();
1533-
1534-
// There needs to be a non-transparent object to ensure the transparent sphere works
1535-
// when opening an new empty document
1536-
auto hidden = new SoSeparator();
1537-
auto hiddenScale = new SoScale();
1538-
hiddenScale->scaleFactor = SbVec3f(0, 0, 0);
1539-
hidden->addChild(hiddenScale);
1540-
hidden->addChild(sphere);
1541-
15421550
auto complexity = new SoComplexity();
15431551
complexity->value = 1;
15441552

@@ -1561,7 +1569,6 @@ void View3DInventorViewer::showRotationCenter(bool show)
15611569
scaledSphere->scaleFactor = size;
15621570

15631571
rotationCenterGroup->addChild(translation);
1564-
rotationCenterGroup->addChild(hidden);
15651572
rotationCenterGroup->addChild(scaledSphere);
15661573

15671574
sep->addChild(rotationCenterGroup);

0 commit comments

Comments
 (0)