|
将模型中(如第一张图所示)的法线信息读出,重新绘制,发现新生成的模型的外观与原模型差别非常大(如第二张图所示),应该是法线没有设置好。根据array的建议用了SmoothingVisitor,但发现生成的模型为黑色,而没有了设置的材质,跟踪到SmoothingVisitor,发现,所有的发现都为(0,0,0),不仅造成材质无效,还使得一些原有的特征也没有了,如比较小的孔,不知为什么。
代码如下: osg::Geode* newGeode = new osg::Geode;
osg::Vec4Array* color = new osg::Vec4Array;
color->push_back(osg::Vec4(1.0f,0.0f,1.0f,1.0f));
for (unsigned int i=0; i<Ge.m_numDrawables;i++)
{
osg::Geometry* newGeometry = new osg::Geometry;
newGeometry->setVertexArray(Ge.vertices);
newGeometry->setVertexIndices(Ge.vertices_index);
newGeometry->setColorArray(color);
newGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
/* newGeometry->setNormalArray( Ge.normals);
newGeometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);*/
newGeometry->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet::TRIANGLES,0,Ge.m_numofTriangles));
newGeode->addDrawable(newGeometry);
osgUtil::SmoothingVisitor::smooth(*newGeometry);
}
osg::StateSet* state;
state = newGeode->getOrCreateStateSet();
osg::Material* material = new osg::Material;
material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(0.298039f,0.298039f,0.0f,1.0f));
material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(0.8f,0.8f,0.0f,1.0f));
material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(0.34f,0.34f,0.34f,0.34f));
material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0f,0.0f,0.0f,1.0f));
material->setShininess(osg::Material::FRONT_AND_BACK,87.04f);
state->setAttribute(material,osg::StateAttribute::ON);
state->setMode( GL_LIGHTING, osg::StateAttribute::ON );
osg::PolygonMode* pm = new osg::PolygonMode(
osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL);
state->setAttributeAndModes( pm,
osg::StateAttribute::ON | osg::StateAttribute::PROTECTED );
[
[ 本帖最后由 ghczhaolei 于 2009-4-16 16:19 编辑 ] |
-
-
|