|
我加入了一个3ds模型,采用了两种方法:1、对其法向量进行了归一化,利用默认的光照 2、重新设定了一个光源,但不知为什么,总得不到原来三维建模软件中的效果,光照感觉特别暗,请高手指教
1:
osg::ref_ptr<osg::Node> spModelNode=osgDB::readNodeFile(m_filePathList[nSelectedID]);
osg::ref_ptr<osg::StateSet> stateset=new osg::StateSet;
stateset=spModelNode->getOrCreateStateSet ();
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
spGroup->addChild(spModelNode);
m_pOSG->getViewer()->setCameraManipulator(new osgGA::TrackballManipulator());
2:
osg::ref_ptr<osg::Node> spModelNode=osgDB::readNodeFile(m_filePathList[nSelectedID]);
spGroup->addChild(CreateLight(spModelNode));
osg::ref_ptr<osg::Group> CPointSymbolDlg::CreateLight(osg::ref_ptr<osg::Node> node)
{
osg::ref_ptr<osg::Group> lightRoot=new osg::Group();
lightRoot->addChild(node);
osg::ref_ptr<osg::StateSet> stateset=new osg::StateSet;
stateset=lightRoot->getOrCreateStateSet ();
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
stateset->setMode(GL_LIGHT0, osg::StateAttribute::ON);
stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
osg::BoundingSphere bs;
node->computeBound();
bs=node->getBound();
osg::ref_ptr<osg:ight> light=new osg::Light;
light->setLightNum(0);
light->setDirection(osg::Vec3(0.0f, 0.0f, 1.0f));
light->setPosition(osg::Vec4(bs.center().x(), bs.center().y(), bs.center().z()-bs.radius(), 1.0f));
light->setAmbient(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
light->setDiffuse(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
light->setSpecular(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
osg::ref_ptr<osg::LightSource> lightSource=new osg::LightSource;
lightSource->setLight(light.get());
lightRoot->addChild(lightSource);
return lightRoot.get();
} |
|