OSG Outline仅出现在几何体的一侧

问题描述 投票:0回答:1

我正在尝试在场景中的一个2D几何体周围显示轮廓。轮廓仅出现在几何体的一侧,我希望它出现在两侧。我假设有一个我需要指定的设置但是对OSG不熟悉我不知道这可能是什么;我也无法从文档或在线示例中辨别出来。

几何形状基本上是一个平面,由一堆较小的平面组成,其中一侧有茎秆。

enter image description here

What I currently have

What I currently have

// Initialize an outline
osg::ref_ptr<osgFX::Outline> vCellOutline = new osgFX::Outline;
mModel3D->addChild(vCellOutline); // Add it as a child of the grid so it appears in the scene
vCellOutline->setWidth(8); // Set some stuff so it appears
vCellOutline->setColor(osg::Vec4(1, 1, 0, 1));
osg::ref_ptr<osg::StateSet> vOutlineState = vCellOutline->getOrCreateStateSet();
vOutlineState->setMode(GL_LIGHTING, osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);

// Add the cell as a child of the outline
vCellOutline->addChild(vCellGeode);

我已经尝试增加宽度,因为我认为它可能没有显示,但它没有任何区别。当相机从“侧面开启”视角观察几何体时,轮廓消失。

我做了一些谷歌搜索,并尝试了各种各样的事情,如指定一个双面光模型(如果没有正确点亮),试图通过例如禁用剔除

vOutlineState->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
vCellOutline->setCullingActive(false);

但那没有做任何事情。当我看到默认情况下,osg概述cull their front-facing polys时,我以为我找到了解决方案,所以我尝试了:

osg::ref_ptr<osg::CullFace> cf = new osg::CullFace;
cf->setMode(osg::CullFace::FRONT);
vOutlineState->setAttributeAndModes(cf, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);

但同样,没有效果。有趣的是,我可以使用这种方法关闭背面的多边形。

openscenegraph
1个回答
1
投票

这样做有效:

osg::ref_ptr<osg::CullFace> cf = new osg::CullFace;
cf->setMode(osg::CullFace::FRONT);
vOutlineState->setAttributeAndModes(cf, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);

和:

osg::ref_ptr<osg::PolygonMode> polyMode = new osg::PolygonMode;
polyMode->setMode(osg::PolygonMode::FRONT, osg::PolygonMode::LINE);
vOutlineState->setAttributeAndModes(polyMode, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);

我猜是因为前面的东西没有在Outline类中明确设置;只有背面的东西是。


顺便说一句,我有一个问题,当从前面直接正面观看时,轮廓会消失。我仍然不知道为什么,但是我改变了我的“查看正面”代码以略微偏移透视图,这足以使轮廓恢复。

© www.soinside.com 2019 - 2024. All rights reserved.