|
本帖最后由 kingsteeve 于 2011-12-2 10:59 编辑
我把Geode复制一个后叫Geode1,改变Geode1的polyMode属性,然后把node1 add到node的父节点上,想使得Geode1显示线框而Geode的显示不变,为什么这时候Geode1把Geode覆盖看不见了?貌似是跟复制过来后的stateset有关系,我尝试了各种深度拷贝,如果复制过来的Geode1的stateset地址和父子关系跟Geode一样,则两者的代码谁放在后面谁就有覆盖作用。如果eode1的stateset地址和父子关系跟Geode不一样,则Geode1就无法显示,我不知道是为什么?我的代码如下:
osg::Geode *pGeode1 = dynamic_cast<osg::Geode*>(m_graphObject);
osg::Geode *pGeode = new osg::Geode(*pGeode1, osg::CopyOp:EEP_COPY_NODES);
pGeode1->getParent(0)->addChild(pGeode);
if (pGeode)
{
osg::StateSet *pStateSet1 = pGeode->getorCreateStateSet();
osg:olygonOffset* polyOffset = new osg::PolygonOffset;
polyOffset->setFactor(-1.0f);
polyOffset->setUnits(-1.0f);
osg::PolygonMode* polyMode = new osg::PolygonMode;
polyMode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode:INE);
pStateSet1->setAttributeAndModes(polyOffset, osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
pStateSet1->setAttributeAndModes(polyMode, osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
osg::Material* material = new osg::Material;
pStateSet1->setAttributeAndModes(material, osg::StateAttribute::ON); // switch glColor usage off
// turn all lighting off
material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f,0.0f,1.0f,1.0f));
material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f,0.0f,1.0f,1.0f));
material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f,0.0f,1.0f,1.0f));
// except emission... in which we set the color we desire
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f,0.0f,1.0f,1.0f));
pStateSet1->setAttributeAndModes(material,osg::StateAttribute::PROTECTED|osg::StateAttribute::ON);
pStateSet1->setMode(GL_LIGHTING,osg::StateAttribute::PROTECTED|osg::StateAttribute::OFF);
pStateSet1->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::PROTECTED|osg::StateAttribute::OFF);
} |
|