|
- osg::ref_ptr<osg::Geode> ReadData()
- {
-
- osg::ref_ptr<osg::Geometry> geom3=new osg::Geometry;
- osg::ref_ptr<osg::Vec3Array> v=new osg::Vec3Array;
- geom3->setVertexArray(v.get());
- float x,y,z;
- char buffer[256];
- ifstream infile;
- infile.open("sg.txt");
- if(!infile)
- {
- cout << "Unable to open datafile";
- exit(1); // terminate with error
- }
- int i=0;
- while (!infile.eof() )
- {
- infile.getline(buffer,256);
- sscanf(buffer,"%f %f %f",&x,&y,&z);
- cout<<x<<" "<<y<<" "<<z<<endl;
- v->push_back(osg::Vec3(x,y,z));
- i++;
- }
- infile.close();
- osg::ref_ptr<osgUtil::DelaunayTriangulator> dt=new osgUtil::DelaunayTriangulator(v.get());
- dt->triangulate();
- geom3->addPrimitiveSet(dt->getTriangles());
- geom3->setNormalArray(dt->getOutputNormalArray());
- geom3->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
- osg::ref_ptr<osg::Geode> geode=new osg::Geode;
- geode->addDrawable(geom3.get());
- return geode.get();
- }
复制代码
程序截图
|
|