|
楼主 |
发表于 2008-9-10 16:40:36
|
显示全部楼层
原帖由 array 于 2008-9-10 14:33 发表
比如自己动手用Geometry类画一个,或者从模型文件读入。
OSG的建模能力一直比较薄弱,这个也是不争的事实。况且Robert似乎对此不太关注,记得osg-users有一些提议,不过好像也没怎么响应~~也许以后会改善的,至 ...
我用Geometry类画了一个圆,但还是载入不了纹理啊:- osg::ref_ptr<osg::Node> CreateSphere()
- {
- //画表达式为x*x+z*z=1,y=0的圆
- osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
- for (float a=-1.0;a<=1.0;a+=0.04)
- {
- v->push_back(osg::Vec3(a,0.0f,sqrt(1-pow(a,2))+5.0));
- // v->push_back(osg::Vec3(a,0.0f,-1*sqrt(1-pow(a,2))+5.0));
- }
- for (float a=1.0;a>=-1.0;a-=0.04)
- {
- // v->push_back(osg::Vec3(a,0.0f,sqrt(1-pow(a,2))+5.0));
- v->push_back(osg::Vec3(a,0.0f,-1*sqrt(1-pow(a,2))+5.0));
- }
- //纹理坐标
- osg::ref_ptr<osg::Vec2Array> tc = new osg::Vec2Array;
- tc->push_back( osg::Vec2( 0.0f, 0.0f ) );
- tc->push_back( osg::Vec2(0.0f, 1.0f ) );
- tc->push_back( osg::Vec2( 1.0f, 0.0f ) );
- tc->push_back( osg::Vec2( 1.0f, 1.0f ) );
- osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
- c->push_back( osg::Vec4( 1.f, 0.f, 0.f, 1.f ) );
- osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
- geom->setVertexArray( v.get() );
- geom->setTexCoordArray( 0, tc.get() );
- geom->setColorArray( c.get() );
- geom->setColorBinding( osg::Geometry::BIND_OVERALL );
- geom->addPrimitiveSet(new osg::DrawArrays( osg::PrimitiveSet::POLYGON, 0,100) );
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- geode->addDrawable( geom.get() );
- // set up the texture state.
- osg::Texture2D* texture = new osg::Texture2D;
- texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
- // texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
- // texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
- texture->setImage(osgDB::readImageFile("instrument2.gif"));
- osg::StateSet* stateset = geode->getOrCreateStateSet();
- stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
- stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF |
- osg::StateAttribute::PROTECTED );
- return geode.get();
- }
复制代码 我想载入的纹理: |
-
|